sequenceDiagram
Title: DID Registration
  autonumber
  participant Subject as DID Subject
  participant App as API-Appnet
  participant SDK as DID JS SDK
  participant HSDK as Hashgraph JS SDK
  participant HCS as Hedera Consensus Service
  participant HMN as Hedera Mirror Node
  participant DB as Database

note over Subject,DB: Register a DID
Subject->>App: Send public key to endpoint
App ->> HSDK: Build Client (Set account that will pay for transaction)
App ->> HSDK: Generate DID Private Key (DPK)
App ->> SDK: Register DID with DPK
SDK ->> HSDK: Build Topic Create Transaction <br> By setting Transaction Fees <br> AdminKey, SubmitKey <br> singed by DPK
SDK ->> HSDK: Execute above transaction with Client <br> (responsible for transaction payment)
HSDK ->> HCS: Create Private Topic
HCS ->> HMN: Propagate Topic
SDK ->> HSDK: Request Receipt for Transaction
HSDK --> SDK: Send receipt with Topic ID
SDK ->> SDK: Build did identifier with topic id
SDK ->> SDK: Create DID owner Event <br> with identifier
SDK ->> HSDK: Build DID owner Event Transaction  <br> signed with DPK
SDK ->> HSDK: Execute above transaction with Client <br> (responsible for transaction payment)
HSDK ->> HCS: Submit message to Topic
HCS ->> HMN: Propagate Message <br> to Topic
App ->> App: Create DidKeypair
App ->> DB: Save DidKeypair to DB
App ->> SDK: Add Verification Relationship
SDK ->> SDK: Create Verification Relationship event
SDK ->> HSDK: Create the transaction
SDK ->> HSDK: Execute the transaction
App ->> DB: Write all the messages to DB
SDK ->> App: Send DID Identifier <br> e.g. (did:hedera:testnet:z6Mk.._0.0.2..)
App->> Subject: Return DID
end