package Ġcom . persistent . did . w itness . flows Ċ Ċ import Ġco . parallel universe . fib ers . Suspend able Ċ import Ġcom . nat pr y ce . map Ċ import Ġcom . nat pr y ce . on Failure Ċ import Ġcom . persistent . did . contract . Did Contract Ċ import Ġcom . persistent . did . state . Did State Ċ import Ġcom . persistent . did . state . Did Status Ċ import Ġcom . persistent . did . utils . DID Already Exist Exception Ċ import Ġcom . persistent . did . utils . Invalid DID Exception Ċ import Ġcom . persistent . did . utils . check If Did Exist Ċ import Ġcom . persistent . did . utils . get Not ary From Config Ċ import Ġnet . cord a . core . contracts . Command Ċ import Ġnet . cord a . core . contracts . Unique Identifier Ċ import Ġnet . cord a . core . flows . Final ity Flow Ċ import Ġnet . cord a . core . flows . Flow Logic Ċ import Ġnet . cord a . core . flows . Flow Session Ċ import Ġnet . cord a . core . flows . Initi ated By Ċ import Ġnet . cord a . core . flows . Initi ating Flow Ċ import Ġnet . cord a . core . flows . Receive Final ity Flow Ċ import Ġnet . cord a . core . flows . Start able By RPC Ċ import Ġnet . cord a . core . identity . C ord a X 5 0 0 Name Ċ import Ġnet . cord a . core . identity . Party Ċ import Ġnet . cord a . core . transactions . Signed Transaction Ċ import Ġnet . cord a . core . transactions . Transaction Builder Ċ import Ġnet . cord a . core . utilities . Progress Tracker Ċ import Ġnet . cord a . did . Did Envelope Ċ Ċ /** Ċ Ġ* ĠInit i ating Ġflow Ġto ĠCREATE Ġa ĠD ID Ġon Ġledger Ġas Ġspecified Ġin Ġthe Ġw 3 Ġspecification . Ċ Ġ* ĠRef : Ġhttps :// w 3 c - cc g . github . io / did - spec /# create Ċ Ġ* ĠThe Ġdid Ġwill Ġbe Ġcreated Ġon Ġthe Ġ[ Did State . origin ator ] Ġand Ġ[ Did State . wit nesses ] Ġnodes . Ċ Ġ* Ċ Ġ* Ġ@ property Ġenvelope Ġthe Ġ[ Did Envelope ] Ġobject . Ċ Ġ* Ġ@ property Ġprogress Tracker Ġtracks Ġthe Ġprogress Ġin Ġthe Ġvarious Ġstages Ġof Ġtransaction Ċ Ġ*/ Ċ @ Initi ating Flow Ċ @ Start able By RPC Ċ Ċ class ĠCreate Did Flow ( val Ġenvelope : ĠDid Envelope ) Ġ: ĠFlow Logic < Signed Transaction >() Ġ{ ĊĊ ĉ @ Suppress (" ClassName ") Ċ ĉ comp anion Ġobject Ġ{ Ċĉ ĉ object ĠGENER ATING _ TRANSACTION Ġ: ĠProgress Tracker . Step (" Generating Ġtransaction Ġbased Ġon Ġnew ĠDid State .") Ċĉ ĉ object ĠVERIFY ING _ TRANSACTION Ġ: ĠProgress Tracker . Step (" Verify ing Ġcontract Ġconstraints .") Ċĉ ĉ object ĠSIGN ING _ TRANSACTION Ġ: ĠProgress Tracker . Step (" Signing Ġtransaction Ġwith Ġour Ġprivate Ġkey .") Ċĉ ĉ object ĠFIN AL ISING _ TRANSACTION Ġ: ĠProgress Tracker . Step (" Ob t aining Ġnot ary Ġsignature Ġand Ġrecording Ġtransaction .") Ġ{ Ċĉĉ ĉ override Ġfun Ġchild Progress Tracker () Ġ= ĠFinal ity Flow . tracker () Ċĉ ĉ } ĊĊĉ ĉ fun Ġtracker () Ġ= ĠProgress Tracker ( Ċĉĉĉ ĉ GENER ATING _ TRANSACTION , Ċĉĉĉ ĉ VERIFY ING _ TRANSACTION , Ċĉĉĉ ĉ SIGN ING _ TRANSACTION , Ċĉĉĉ ĉ FINAL ISING _ TRANSACTION Ċĉ ĉ ) Ċ ĉ } ĊĊ ĉ override Ġval Ġprogress Tracker Ġ= Ġtracker () ĊĊ ĉ /** Ċĉ Ġ* ĠThe Ġflow Ġlogic Ġis Ġencaps ulated Ġwithin Ġthe Ġcall () Ġmethod . Ċĉ Ġ*/ Ċ ĉ @ Suspend able Ċ ĉ override Ġfun Ġcall (): ĠSigned Transaction Ġ{ ĊĊĉ ĉ // Ġquery Ġthe Ġledger Ġif Ġdid Ġexist Ġor Ġnot Ċĉ ĉ val Ġdid Ġ= Ġenvelope . document . id (). on Failure Ġ{ Ġthrow ĠInvalid DID Exception (" Invalid ĠD ID Ġpassed ") Ġ} ĊĊĉ ĉ envelope . document . id (). map Ġ{ Ċĉĉ ĉ if Ġ( service Hub . check If Did Exist ( Unique Identifier ( null , Ġit . uuid ))) Ġ{ Ċĉĉĉ ĉ throw ĠD ID Already Exist Exception (" DID Ġwith Ġid Ġ${ did . to External Form ()} Ġalready Ġexist ") Ċĉĉ ĉ } Ċĉ ĉ } ĊĊĉ ĉ val Ġnot ary Ġ= Ġservice Hub . get Not ary From Config () ĊĊĉ ĉ // ĠStage Ġ 1 . Ċĉ ĉ progress Tracker . current Step Ġ= ĠGENER ATING _ TRANSACTION ĊĊĉ ĉ val Ġconfig Ġ= Ġservice Hub . get AppContext (). config Ċĉ ĉ val Ġnetwork Type Ġ= Ġconfig . get (" network ") Ġas ĠString Ċĉ ĉ val Ġnodes Ġ= Ġconfig . get (" nodes ") Ġas ĠArrayList < *> ĊĊĉ ĉ val Ġw itness Nodes List Ġ= Ġarray ListOf < Party >() Ċĉ ĉ nodes . map Ġ{ Ċĉĉ ĉ w itness Nodes List . add ( service Hub . network Map Cache . get Peer By Legal Name ( C ord a X 5 0 0 Name . parse ( it . toString ())) !! ) Ċĉ ĉ } Ċĉ ĉ val Ġdid State Ġ= ĠDid State ( envelope , Ġservice Hub . my Info . legal Id entities . first (), Ġw itness Nodes List . toSet (), ĠDid Status . ACTIVE , ĠUnique Identifier ( null , Ġdid . uuid )) ĊĊĉ ĉ // ĠGenerate Ġan Ġunsigned Ġtransaction . Ċĉ ĉ val Ġtx Command Ġ= ĠCommand ( Did Contract . Commands . Create ( network Type ), ĠlistOf ( our Identity . own ing Key )) Ċĉ ĉ val Ġtx Builder Ġ= ĠTransaction Builder ( not ary ) Ċĉĉĉ ĉ . add Output State ( did State , ĠDid Contract . DID _ CONTRACT _ ID ) Ċĉĉĉ ĉ . add Command ( tx Command ) ĊĊĉ ĉ // ĠStage Ġ 2 . Ċĉ ĉ progress Tracker . current Step Ġ= ĠVERIFY ING _ TRANSACTION Ċĉ ĉ // ĠVerify Ġthat Ġthe Ġtransaction Ġis Ġvalid . Ċĉ ĉ tx Builder . verify ( service Hub ) ĊĊĉ ĉ // ĠStage Ġ 3 . Ċĉ ĉ progress Tracker . current Step Ġ= ĠSIGN ING _ TRANSACTION Ċĉ ĉ // ĠSign Ġthe Ġtransaction . Ċĉ ĉ val Ġsigned Tx Ġ= Ġservice Hub . sign Initial Transaction ( tx Builder ) ĊĊĉ ĉ // ĠStage Ġ 4 . Ċĉ ĉ progress Tracker . current Step Ġ= ĠFIN AL ISING _ TRANSACTION ĊĊĉ ĉ val Ġother Party Session Ġ= Ġdid State . wit nesses . minus ( our Identity ). map Ġ{ Ġinitiate Flow ( it ) Ġ}. toSet () ĊĊĉ ĉ // ĠNot ar ise Ġand Ġrecord Ġthe Ġtransaction Ġin Ġw itness Ġparties ' Ġvault s . Ċĉ ĉ return Ġsub Flow ( Final ity Flow ( signed Tx , Ġother Party Session , ĠFIN AL ISING _ TRANSACTION . child Progress Tracker ())) Ċ ĉ } Ċ } Ċ Ċ /** Ċ Ġ* ĠReceiver Ġfinal ity Ġflow Ġfor Ġ[ Create Did Flow ] Ċ Ġ* Ġ@ property [ other Party Session ] ĠFlow Session Ċ Ġ* Ċ Ġ*/ Ċ @ Initi ated By ( Create Did Flow :: class ) Ċ class ĠCreate Did Final ity Flow Responder ( private Ġval Ġother Party Session : ĠFlow Session ) Ġ: ĠFlow Logic < Unit >() Ġ{ Ċ ĉ @ Suspend able Ċ ĉ override Ġfun Ġcall () Ġ{ Ċĉ ĉ sub Flow ( Receive Final ity Flow ( other Party Session )) Ċ ĉ } Ċ }