/* -------------------------------------------------------------------------------- ------------- Ċ Ġ* Ġ ĠCopyright Ġ( c ) ĠMicrosoft ĠCorporation . ĠAll Ġrights Ġreserved . Ċ Ġ* Ġ ĠLicensed Ġunder Ġthe ĠMIT ĠLicense . ĠSee ĠLicense . txt Ġin Ġthe Ġproject Ġroot Ġfor Ġlicense Ġinformation . Ċ Ġ* -------------------------------------------------------------------------------- ------------ */ Ċ Ċ package Ġcom . microsoft . did . sdk . credential . service . prot ector s Ċ Ċ import Ġcom . microsoft . did . sdk . credential . service . Iss u ance Response Ċ import Ġcom . microsoft . did . sdk . credential . service . Requested Id Token Map Ċ import Ġcom . microsoft . did . sdk . credential . service . Requested Self At tested Claim Map Ċ import Ġcom . microsoft . did . sdk . credential . service . Requested Vc Map Ċ import Ġcom . microsoft . did . sdk . credential . service . models . oidc . At testation Claim Model Ċ import Ġcom . microsoft . did . sdk . credential . service . models . oidc . Iss u ance Response Claims Ċ import Ġcom . microsoft . did . sdk . crypto . key Store . Encrypted KeyStore Ċ import Ġcom . microsoft . did . sdk . identifier . models . Identifier Ċ import Ġkotlinx . serialization . json . Json Ċ import Ġjava . util . UUID Ċ import Ġjavax . inject . Inject Ċ import Ġjavax . inject . Singleton Ċ Ċ @ Singleton Ċ class ĠIss u ance Response Formatter Ġ@ Inject Ġconstructor ( ĊĠĠĠ Ġprivate Ġval Ġserializer : ĠJson , ĊĠĠĠ Ġprivate Ġval Ġver ifiable Presentation Formatter : ĠVer ifiable Presentation Formatter , ĊĠĠĠ Ġprivate Ġval Ġsigner : ĠToken Signer , ĊĠĠĠ Ġprivate Ġval Ġkey Store : ĠEn crypted KeyStore Ċ ) Ġ{ ĊĊĠĠĠ Ġfun Ġformat Response ( ĊĠĠĠĠĠĠĠ Ġrequested Vc Map : ĠRequest ed Vc Map Ġ= Ġmutable Map Of (), ĊĠĠĠĠĠĠĠ Ġiss u ance Response : ĠIss u ance Response , ĊĠĠĠĠĠĠĠ Ġresponder : ĠIdentifier , ĊĠĠĠĠĠĠĠ Ġexpiry InSeconds : ĠInt ĊĠĠĠ Ġ): ĠString Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġ( iss ued Time , Ġexpiry Time ) Ġ= Ġcreate Iss ued And Expiry Time ( expiry InSeconds ) ĊĠĠĠĠĠĠĠ Ġval Ġresponse Id Ġ= ĠUUID . randomUUID (). toString () ĊĠĠĠĠĠĠĠ Ġval Ġat testation Response Ġ= Ġthis . create At testation Claim Model ( ĊĠĠĠĠĠĠĠĠĠĠĠ Ġrequested Vc Map , ĊĠĠĠĠĠĠĠĠĠĠĠ Ġiss u ance Response . requested Id Token Map , ĊĠĠĠĠĠĠĠĠĠĠĠ Ġiss u ance Response . requested Self At tested Claim Map , ĊĠĠĠĠĠĠĠĠĠĠĠ Ġiss u ance Response . request . entity Identifier , ĊĠĠĠĠĠĠĠĠĠĠĠ Ġresponder ĊĠĠĠĠĠĠĠ Ġ) ĊĠĠĠĠĠĠĠ Ġreturn Ġcreate And Sign Oid c Response Content ( iss u ance Response , Ġresponder , Ġissued Time , Ġexpiry Time , Ġresponse Id , Ġat testation Response ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġprivate Ġfun Ġcreate And Sign Oid c Response Content ( ĊĠĠĠĠĠĠĠ Ġiss u ance Response : ĠIss u ance Response , ĊĠĠĠĠĠĠĠ Ġresponder : ĠIdentifier , ĊĠĠĠĠĠĠĠ Ġissued Time : ĠLong , ĊĠĠĠĠĠĠĠ Ġexpiry Time : ĠLong , ĊĠĠĠĠĠĠĠ Ġresponse Id : ĠString , ĊĠĠĠĠĠĠĠ Ġat testation Response : ĠAt testation Claim Model ĊĠĠĠ Ġ): ĠString Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġkey Ġ= Ġkey Store . getKey ( responder . signature Key Reference ) ĊĠĠĠĠĠĠĠ Ġval Ġcontents Ġ= ĠIss u ance Response Claims ( iss u ance Response . request . contract Url , Ġat testation Response ). apply Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ ĠpublicKey Thumb Print Ġ= Ġkey . compute Thumb print (). toString () ĊĠĠĠĠĠĠĠĠĠĠĠ Ġaudience Ġ= Ġiss u ance Response . audience ĊĠĠĠĠĠĠĠĠĠĠĠ Ġdid Ġ= Ġresponder . id ĊĠĠĠĠĠĠĠĠĠĠĠ ĠpublicKey J wk Ġ= Ġkey . to Public J WK () ĊĠĠĠĠĠĠĠĠĠĠĠ Ġresponse Creation Time Ġ= Ġissued Time ĊĠĠĠĠĠĠĠĠĠĠĠ Ġresponse Expiration Time Ġ= Ġexpiry Time ĊĠĠĠĠĠĠĠĠĠĠĠ Ġthis . response Id Ġ= Ġresponse Id ĊĠĠĠĠĠĠĠ Ġ} ĊĠĠĠĠĠĠĠ Ġreturn Ġsign Contents ( contents , Ġresponder ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġprivate Ġfun Ġsign Contents ( contents : ĠIss u ance Response Claims , Ġresponder : ĠIdentifier ): ĠString Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġserialized Response Content Ġ= Ġserializer . encode ToString ( Iss u ance Response Claims . serializer (), Ġcontents ) ĊĠĠĠĠĠĠĠ Ġreturn Ġsigner . sign With Identifier ( serialized Response Content , Ġresponder ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġprivate Ġfun Ġcreate At testation Claim Model ( ĊĠĠĠĠĠĠĠ Ġrequested Vc Map : ĠRequest ed Vc Map , ĊĠĠĠĠĠĠĠ Ġrequested Id Token Map : ĠRequest ed Id Token Map , ĊĠĠĠĠĠĠĠ Ġrequested Self At tested Claim Map : ĠRequest ed Self At tested Claim Map , ĊĠĠĠĠĠĠĠ Ġpresent ations Audience : ĠString , ĊĠĠĠĠĠĠĠ Ġresponder : ĠIdentifier ĊĠĠĠ Ġ): ĠAt testation Claim Model Ġ{ ĊĠĠĠĠĠĠĠ Ġif Ġ( are No Collected Claims ( requested Vc Map , Ġrequested Id Token Map , Ġrequested Self At tested Claim Map )) Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ Ġreturn ĠAt testation Claim Model () ĊĠĠĠĠĠĠĠ Ġ} ĊĠĠĠĠĠĠĠ Ġval Ġpresentation At test ations Ġ= Ġcreate Present ations ( requested Vc Map , Ġpresent ations Audience , Ġresponder ) ĊĠĠĠĠĠĠĠ Ġreturn ĠAt testation Claim Model ( requested Self At tested Claim Map , Ġrequested Id Token Map , Ġpresentation At test ations ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġprivate Ġfun Ġcreate Present ations ( requested Vc Map : ĠRequest ed Vc Map , Ġaudience : ĠString , Ġresponder : ĠIdentifier ): ĠMap < String , ĠString > Ġ{ ĊĠĠĠĠĠĠĠ Ġreturn Ġrequested Vc Map . map Ġ{ Ġ( input Descriptor , Ġvc ) Ġ-> ĊĠĠĠĠĠĠĠĠĠĠĠ Ġinput Descriptor . credential Type Ġto Ġver ifiable Presentation Formatter . create Presentation ( ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġvc , ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġinput Descriptor . validity Interval , ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġaudience , ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġresponder ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ) ĊĠĠĠĠĠĠĠ Ġ}. toMap () ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġprivate Ġfun Ġare No Collected Claims ( ĊĠĠĠĠĠĠĠ Ġrequested Vc Map : ĠRequest ed Vc Map , ĊĠĠĠĠĠĠĠ Ġrequested Id Token Map : ĠRequest ed Id Token Map , ĊĠĠĠĠĠĠĠ Ġrequested Self At tested Claim Map : ĠRequest ed Self At tested Claim Map ĊĠĠĠ Ġ): ĠBoolean Ġ{ ĊĠĠĠĠĠĠĠ Ġreturn Ġ( requested Vc Map . isNull OrEmpty () Ġ&& Ġrequested Id Token Map . isNull OrEmpty () Ġ&& Ġrequested Self At tested Claim Map . isNull OrEmpty ()) ĊĠĠĠ Ġ} Ċ }