package Ġnet . cord a . conf idential Ċ Ċ import Ġco . parallel universe . fib ers . Suspend able Ċ import Ġnet . cord a . core . C ord a Internal Ċ import Ġnet . cord a . core . crypto . Digital Signature Ċ import Ġnet . cord a . core . crypto . verify Ċ import Ġnet . cord a . core . flows .* Ċ import Ġnet . cord a . core . identity . Anonymous Party Ċ 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 . identity . Party And Certificate Ċ import Ġnet . cord a . core . internal . Visible ForTesting Ċ import Ġnet . cord a . core . internal . cord app . C ord app Resolver Ċ import Ġnet . cord a . core . internal . warn Once Ċ import Ġnet . cord a . core . node . Service Hub Ċ import Ġnet . cord a . core . serialization . C ord a Serializable Ċ import Ġnet . cord a . core . serialization . Serialized Bytes Ċ import Ġnet . cord a . core . serialization . deserialize Ċ import Ġnet . cord a . core . serialization . serialize Ċ import Ġnet . cord a . core . utilities . Progress Tracker Ċ import Ġnet . cord a . core . utilities . unwrap Ċ import Ġjava . security . PublicKey Ċ import Ġjava . security . Signature Exception Ċ import Ġjava . util .* Ċ Ċ /** Ċ Ġ* ĠVery Ġbasic Ġflow Ġwhich Ġgenerates Ġnew Ġconf idential Ġident ities Ġfor Ġparties Ġin Ġa Ġtransaction Ġand Ġex changes Ġthe Ġtransaction Ċ Ġ* Ġkey Ġand Ġcertificate Ġpaths Ġbetween Ġthe Ġparties . ĠThis Ġis Ġintended Ġfor Ġuse Ġas Ġa Ġsub - flow Ġof Ġanother Ġflow Ġwhich Ġbuilds Ġa Ċ Ġ* Ġtransaction . ĠThe Ġflow Ġrunning Ġon Ġthe Ġother Ġside Ġmust Ġalso Ġcall Ġthis Ġflow Ġat Ġthe Ġcorrect Ġlocation . Ċ Ġ* Ċ Ġ* ĠNOTE : ĠThis Ġis Ġan Ġin lined Ġflow Ġbut Ġfor Ġbackwards Ġcompatibility Ġis Ġannotated Ġwith Ġ[ Initi ating Flow ]. Ċ Ġ*/ Ċ @ Initi ating Flow Ċ class ĠSwap Id entities Flow Ċ private Ġconstructor ( private Ġval Ġother Side Session : ĠFlow Session ?, ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġprivate Ġval Ġother Party : ĠParty ?, ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġoverride Ġval Ġprogress Tracker : ĠProgress Tracker ) Ġ: ĠFlow Logic < Linked HashMap < Party , ĠAn onymous Party >>() Ġ{ ĊĊĠĠĠ Ġ@ Jvm Over loads ĊĠĠĠ Ġconstructor ( other Side Session : ĠFlow Session , Ġprogress Tracker : ĠProgress Tracker Ġ= Ġtracker ()) Ġ: Ġthis ( other Side Session , Ġnull , Ġprogress Tracker ) ĊĊĠĠĠ Ġ@ Deprecated (" It Ġis Ġunsafe Ġto Ġuse Ġthis Ġconstructor Ġas Ġit Ġrequires Ġnodes Ġto Ġautomatically Ġv end Ġanonymous Ġident ities Ġwithout Ġfirst Ġ" Ġ+ ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ" checking Ġif Ġthey Ġshould . ĠInstead , Ġuse Ġthe Ġconstructor Ġthat Ġtakes Ġin Ġan Ġexisting ĠFlow Session .") ĊĠĠĠ Ġconstructor ( other Party : ĠParty , Ġrev ocation Enabled : ĠBoolean , Ġprogress Tracker : ĠProgress Tracker ) Ġ: Ġthis ( null , Ġother Party , Ġprogress Tracker ) ĊĊĠĠĠ Ġ@ Deprecated (" It Ġis Ġunsafe Ġto Ġuse Ġthis Ġconstructor Ġas Ġit Ġrequires Ġnodes Ġto Ġautomatically Ġv end Ġanonymous Ġident ities Ġwithout Ġfirst Ġ" Ġ+ ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ" checking Ġif Ġthey Ġshould . ĠInstead , Ġuse Ġthe Ġconstructor Ġthat Ġtakes Ġin Ġan Ġexisting ĠFlow Session .") ĊĠĠĠ Ġconstructor ( other Party : ĠParty ) Ġ: Ġthis ( null , Ġother Party , Ġtracker ()) ĊĊĠĠĠ Ġcompanion Ġobject Ġ{ ĊĠĠĠĠĠĠĠ Ġobject ĠGENER ATING _ IDENTITY Ġ: ĠProgress Tracker . Step (" Generating Ġour Ġanonymous Ġidentity ") ĊĠĠĠĠĠĠĠ Ġobject ĠSIGN ING _ IDENTITY Ġ: ĠProgress Tracker . Step (" Signing Ġour Ġanonymous Ġidentity ") ĊĠĠĠĠĠĠĠ Ġobject ĠA WAIT ING _ IDENTITY Ġ: ĠProgress Tracker . Step (" Await ing Ġcounter party 's Ġanonymous Ġidentity ") ĊĠĠĠĠĠĠĠ Ġobject ĠVERIFY ING _ IDENTITY Ġ: ĠProgress Tracker . Step (" Verify ing Ġcounter party 's Ġanonymous Ġidentity ") ĊĊĠĠĠĠĠĠĠ Ġ@ Jvm Static ĊĠĠĠĠĠĠĠ Ġfun Ġtracker (): ĠProgress Tracker Ġ= ĠProgress Tracker ( GENER ATING _ IDENTITY , ĠSIGN ING _ IDENTITY , ĠA WAIT ING _ IDENTITY , ĠVERIFY ING _ IDENTITY ) ĊĊĠĠĠĠĠĠĠ Ġ/** ĊĠĠĠĠĠĠĠĠ Ġ* ĠGenerate Ġthe Ġdeterministic Ġdata Ġblob Ġthe Ġconf idential Ġidentity 's Ġkey Ġholder Ġsigns Ġto Ġindicate Ġthey Ġwant Ġto ĊĠĠĠĠĠĠĠĠ Ġ* Ġrepresent Ġthe Ġsubject Ġnamed Ġin Ġthe ĠX . 5 0 9 Ġcertificate . ĠNote Ġthat Ġthis Ġis Ġnever Ġactually Ġsent Ġbetween Ġnodes , ĊĠĠĠĠĠĠĠĠ Ġ* Ġbut Ġonly Ġthe Ġsignature Ġis Ġsent . ĠThe Ġblob Ġis Ġbuilt Ġindependently Ġon Ġeach Ġnode Ġand Ġthe Ġreceived Ġsignature ĊĠĠĠĠĠĠĠĠ Ġ* Ġverified Ġagainst Ġthe Ġexpected Ġblob , Ġrather Ġthan Ġex changing Ġthe Ġblob . ĊĠĠĠĠĠĠĠĠ Ġ*/ ĊĠĠĠĠĠĠĠ Ġ@ C ord a Internal ĊĠĠĠĠĠĠĠ Ġ@ Visible ForTesting ĊĠĠĠĠĠĠĠ Ġinternal Ġfun Ġbuild DataTo Sign ( identity : ĠParty And Certificate ): ĠByteArray Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ Ġreturn ĠCertificate Ownership Assertion ( identity . name , Ġidentity . own ing Key ). serialize (). bytes ĊĠĠĠĠĠĠĠ Ġ} ĊĊĠĠĠĠĠĠĠ Ġ@ C ord a Internal ĊĠĠĠĠĠĠĠ Ġ@ Visible ForTesting ĊĠĠĠĠĠĠĠ Ġinternal Ġfun Ġvalidate And Register Identity ( service Hub : ĠService Hub , ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġother Side : ĠParty , ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġtheir Anonymous Identity : ĠParty And Certificate , ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġsignature : ĠDigital Signature ): ĠParty And Certificate Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ Ġif Ġ( their Anonymous Identity . name Ġ!= Ġother Side . name ) Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġthrow ĠSwap Id entities Exception (" Certificate Ġsubject Ġmust Ġmatch Ġcounter party 's Ġwell Ġknown Ġidentity .") ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ} ĊĠĠĠĠĠĠĠĠĠĠĠ Ġtry Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġtheir Anonymous Identity . own ing Key . verify ( build DataTo Sign ( their Anonymous Identity ), Ġsignature ) ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ} Ġcatch Ġ( ex : ĠSignature Exception ) Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġthrow ĠSwap Id entities Exception (" Signature Ġdoes Ġnot Ġmatch Ġthe Ġexpected Ġidentity Ġownership Ġassertion .", Ġex ) ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ} ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ// ĠValidate Ġthen Ġstore Ġtheir Ġidentity Ġso Ġthat Ġwe Ġcan Ġprove Ġthe Ġkey Ġin Ġthe Ġtransaction Ġis Ġowned Ġby Ġthe Ġcounter party . ĊĠĠĠĠĠĠĠĠĠĠĠ Ġservice Hub . identity Service . verify And Register Identity ( their Anonymous Identity ) ĊĠĠĠĠĠĠĠĠĠĠĠ Ġreturn Ġtheir Anonymous Identity ĊĠĠĠĠĠĠĠ Ġ} ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Suspend able ĊĠĠĠ Ġoverride Ġfun Ġcall (): ĠLinkedHashMap < Party , ĠAn onymous Party > Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġsession Ġ= Ġother Side Session Ġ?: Ġrun Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ Ġlogger . warn Once (" The Ġcurrent Ġusage Ġof ĠSwap Id entities Flow Ġis Ġunsafe . ĠPlease Ġconsider Ġupgrading Ġyour ĠCor D app Ġto Ġuse Ġ" Ġ+ ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ" Swap Id entities Flow Ġwith ĠFlow Sessions . Ġ(${ C ord app Resolver . current C ord app ?. info }) ") ĊĠĠĠĠĠĠĠĠĠĠĠ Ġinitiate Flow ( other Party !! ) ĊĠĠĠĠĠĠĠ Ġ} ĊĠĠĠĠĠĠĠ Ġprogress Tracker . current Step Ġ= ĠGENER ATING _ IDENTITY ĊĠĠĠĠĠĠĠ Ġval Ġour Anonymous Identity Ġ= Ġservice Hub . key Management Service . fresh Key And Cert ( our Identity And Cert , Ġfalse ) ĊĠĠĠĠĠĠĠ Ġval Ġdata Ġ= Ġbuild DataTo Sign ( our Anonymous Identity ) ĊĠĠĠĠĠĠĠ Ġprogress Tracker . current Step Ġ= ĠSIGN ING _ IDENTITY ĊĠĠĠĠĠĠĠ Ġval Ġsignature Ġ= Ġservice Hub . key Management Service . sign ( data , Ġour Anonymous Identity . own ing Key ). without Key () ĊĠĠĠĠĠĠĠ Ġval Ġour Ident With Sig Ġ= ĠIdentity With Signature ( our Anonymous Identity . serialize (), Ġsignature ) ĊĠĠĠĠĠĠĠ Ġprogress Tracker . current Step Ġ= ĠA WAIT ING _ IDENTITY ĊĠĠĠĠĠĠĠ Ġval Ġtheir Anonymous Identity Ġ= Ġsession . send And Receive < Identity With Signature >( our Ident With Sig ). unwrap Ġ{ Ġtheir Ident With Sig Ġ-> ĊĠĠĠĠĠĠĠĠĠĠĠ Ġprogress Tracker . current Step Ġ= ĠVERIFY ING _ IDENTITY ĊĠĠĠĠĠĠĠĠĠĠĠ Ġvalidate And Register Identity ( service Hub , Ġsession . counter party , Ġtheir Ident With Sig . identity . deserialize (), Ġtheir Ident With Sig . signature ) ĊĠĠĠĠĠĠĠ Ġ} ĊĊĠĠĠĠĠĠĠ Ġval Ġident ities Ġ= ĠLinkedHashMap < Party , ĠAn onymous Party >() ĊĠĠĠĠĠĠĠ Ġident ities [ our Identity ] Ġ= Ġour Anonymous Identity . party . anon ym ise () ĊĠĠĠĠĠĠĠ Ġident ities [ session . counter party ] Ġ= Ġtheir Anonymous Identity . party . anon ym ise () ĊĠĠĠĠĠĠĠ Ġreturn Ġident ities ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ C ord a Serializable ĊĠĠĠ Ġdata Ġclass ĠIdentity With Signature ( val Ġidentity : ĠSerialized Bytes < Party And Certificate >, Ġval Ġsignature : ĠDigital Signature ) Ċ } Ċ Ċ // ĠData Ġclass Ġused Ġonly Ġin Ġthe Ġcontext Ġof Ġassert ing Ġthat Ġthe Ġowner Ġof Ġthe Ġprivate Ġkey Ġfor Ġthe Ġlisted Ġkey Ġwants Ġto Ġuse Ġit Ċ // Ġto Ġrepresent Ġthe Ġnamed Ġentity . ĠThis Ġis Ġpaired Ġwith Ġan ĠX . 5 0 9 Ġcertificate Ġ( which Ġassert s Ġthe Ġsigning Ġidentity Ġsays Ċ // Ġthe Ġkey Ġrepresents Ġthe Ġnamed Ġentity ) Ġand Ġprotect s Ġagainst Ġa Ġm alic ious Ġparty Ġincorrectly Ġclaim ing Ġothers ' Ċ // Ġkeys . Ċ @ C ord a Serializable Ċ data Ġclass ĠCertificate Ownership Assertion ( val Ġx 5 0 0 Name : ĠC ord a X 5 0 0 Name , Ġval ĠpublicKey : ĠPublicKey ) Ċ Ċ open Ġclass ĠSwap Id entities Exception Ġ@ Jvm Over loads Ġconstructor ( message : ĠString , Ġcause : ĠThrowable ? Ġ= Ġnull ) Ġ: ĠFlow Exception ( message , Ġcause )