@@ -141,6 +141,8 @@ public ResolveResult resolve(DID identifier, Map<String, Object> resolutionOptio
141141 // Resolution maintains the following state while building the DID document:
142142
143143 List <Map .Entry <Block , Map .Entry <Tx , BTCR2Update >>> updates = new ArrayList <>();
144+ Map <Block , Map <Tx , CASAnnouncement >> casAnnouncements = new LinkedHashMap <>();
145+ Map <Block , Map <Tx , SMTProof >> smtProofs = new LinkedHashMap <>();
144146 int current_version_id = 1 ;
145147 List <BytesArray > update_hash_history = new ArrayList <>();
146148 Integer block_confirmations = null ;
@@ -175,13 +177,13 @@ public ResolveResult resolve(DID identifier, Map<String, Object> resolutionOptio
175177 // Hash each CAS Announcement (data structure) in sidecar.casUpdates with the JSON Document Hashing algorithm
176178 // and build a map from hash to announcement (cas_lookup_table).
177179
178- List <CASAnnouncement > sidecarCasUpdates = sidecar == null ? null : sidecar .getCasUpdates ();
179- Map <BytesArray , CASAnnouncement > cas_lookup_table = sidecarCasUpdates == null ? null : sidecarCasUpdates .stream ().collect (Collectors .toMap (casAnnouncement -> BytesArray .bytesArray (JSONDocumentHashing .jsonDocumentHashing (casAnnouncement )), casAnnouncement -> casAnnouncement ));
180+ List <CASAnnouncement > sidecarCasAnnouncements = sidecar == null ? null : sidecar .getCasUpdates ();
181+ Map <BytesArray , CASAnnouncement > cas_lookup_table = sidecarCasAnnouncements == null ? null : sidecarCasAnnouncements .stream ().collect (Collectors .toMap (casAnnouncement -> BytesArray .bytesArray (JSONDocumentHashing .jsonDocumentHashing (casAnnouncement )), casAnnouncement -> casAnnouncement ));
180182
181183 // Build a map from sidecar.smtProofs keyed by proof id (smt_lookup_table).
182184
183- List <SMTProof > smtProofs = sidecar == null ? null : sidecar .getSmtProofs ();
184- Map <BytesArray , SMTProof > smt_lookup_table = smtProofs == null ? null : smtProofs .stream ().collect (Collectors .toMap (smtProof -> BytesArray .bytesArray (Base64 .getUrlDecoder ().decode (smtProof .getId ())), smtProof -> smtProof ));
185+ List <SMTProof > sidecarSmtProofs = sidecar == null ? null : sidecar .getSmtProofs ();
186+ Map <BytesArray , SMTProof > smt_lookup_table = sidecarSmtProofs == null ? null : sidecarSmtProofs .stream ().collect (Collectors .toMap (smtProof -> BytesArray .bytesArray (Base64 .getUrlDecoder ().decode (smtProof .getId ())), smtProof -> smtProof ));
185187
186188 // If genesis_bytes is a SHA-256 hash, hash sidecar.genesisDocument with the JSON Document Hashing algorithm.
187189 // Raise an INVALID_DID error if the computed hash does not match genesis_bytes.
@@ -389,11 +391,15 @@ public ResolveResult resolve(DID identifier, Map<String, Object> resolutionOptio
389391
390392 case BeaconType .CAS ->
391393 // use Process CAS Beacon.
392- processCASBeacon (this .getIpfsConnection (), beaconSignalBytes , identifier , cas_lookup_table , casAnnouncementCid -> casAnnouncementCids .computeIfAbsent (beaconBlock , x -> new LinkedHashMap <>()).put (beaconTransaction , casAnnouncementCid ));
394+ processCASBeacon (this .getIpfsConnection (), beaconSignalBytes , identifier , cas_lookup_table ,
395+ casAnnouncement -> casAnnouncements .computeIfAbsent (beaconBlock , x -> new LinkedHashMap <>()).put (beaconTransaction , casAnnouncement ),
396+ casAnnouncementCid -> casAnnouncementCids .computeIfAbsent (beaconBlock , x -> new LinkedHashMap <>()).put (beaconTransaction , casAnnouncementCid ));
393397
394398 case BeaconType .SMT ->
395399 // use Process SMT Beacon.
396- processSMTBeacon (this .getIpfsConnection (), beaconSignalBytes , smt_lookup_table , smtProofCid -> smtProofCids .computeIfAbsent (beaconBlock , x -> new LinkedHashMap <>()).put (beaconTransaction , smtProofCid ));
400+ processSMTBeacon (this .getIpfsConnection (), beaconSignalBytes , smt_lookup_table ,
401+ smtProof -> smtProofs .computeIfAbsent (beaconBlock , x -> new LinkedHashMap <>()).put (beaconTransaction , smtProof ),
402+ smtProofCid -> smtProofCids .computeIfAbsent (beaconBlock , x -> new LinkedHashMap <>()).put (beaconTransaction , smtProofCid ));
397403 };
398404
399405 if (update_hash == null ) {
@@ -546,8 +552,19 @@ public ResolveResult resolve(DID identifier, Map<String, Object> resolutionOptio
546552 "txId" , x .getValue ().getKey ().txId (),
547553 "targetVersionId" , x .getValue ().getValue ().getTargetVersionId (),
548554 "sourceHash" , x .getValue ().getValue ().getSourceHash (),
549- "targetHash" , x .getValue ().getValue ().getTargetHash ()
555+ "targetHash" , x .getValue ().getValue ().getTargetHash (),
556+ "updateHash" , Base64 .getUrlEncoder ().withoutPadding ().encodeToString (JSONDocumentHashing .jsonDocumentHashing (x .getValue ().getValue ()))
550557 )).toList ());
558+ if (! casAnnouncements .isEmpty ()) didDocumentMetadata .put ("casAnnouncements" , casAnnouncements .entrySet ().stream ().collect (Collectors .toMap (
559+ x -> x .getKey ().blockHeight (), x -> x .getValue ().entrySet ().stream ().collect (Collectors .toMap (
560+ y -> y .getKey ().txId (), y -> y .getValue ()
561+ ))
562+ )));
563+ if (! smtProofCids .isEmpty ()) didDocumentMetadata .put ("smtProofs" , smtProofs .entrySet ().stream ().collect (Collectors .toMap (
564+ x -> x .getKey ().blockHeight (), x -> x .getValue ().entrySet ().stream ().collect (Collectors .toMap (
565+ y -> y .getKey ().txId (), y -> jsonMapper .convertValue (y .getValue (), Map .class )
566+ ))
567+ )));
551568
552569 // done
553570
@@ -560,7 +577,7 @@ public ResolveResult resolve(DID identifier, Map<String, Object> resolutionOptio
560577 * Process CAS Beacon
561578 * See https://dcdpr.github.io/did-btcr2/operations/resolve.html#process-cas-beacon
562579 */
563- private static byte [] processCASBeacon (IPFSConnection ipfsConnection , byte [] signalBytes , DID did , Map <BytesArray , CASAnnouncement > cas_lookup_table , Consumer <Cid > casAnnouncementCidConsumer ) throws ResolutionException {
580+ private static byte [] processCASBeacon (IPFSConnection ipfsConnection , byte [] signalBytes , DID did , Map <BytesArray , CASAnnouncement > cas_lookup_table , Consumer <CASAnnouncement > casAnnouncementConsumer , Consumer < Cid > casAnnouncementCidConsumer ) throws ResolutionException {
564581
565582 // Treat Signal Bytes as map_update_hash.
566583
@@ -586,6 +603,7 @@ private static byte[] processCASBeacon(IPFSConnection ipfsConnection, byte[] sig
586603 if (casAnnouncementCid != null ) casAnnouncementCidConsumer .accept (casAnnouncementCid );
587604
588605 if (casAnnouncement == null ) throw new ResolutionException (ResolutionException .ERROR_INVALID_DID_DOCUMENT , "No CAS Announcement found for map_update_hash " + Base64 .getUrlEncoder ().withoutPadding ().encodeToString (map_update_hash ));
606+ casAnnouncementConsumer .accept (casAnnouncement );
589607
590608 // and read update_hash from the announcement entry keyed by did.
591609
@@ -603,7 +621,7 @@ private static byte[] processCASBeacon(IPFSConnection ipfsConnection, byte[] sig
603621 * Process SMT Beacon
604622 * See https://dcdpr.github.io/did-btcr2/operations/resolve.html#process-smt-beacon
605623 */
606- private static byte [] processSMTBeacon (IPFSConnection ipfsConnection , byte [] signalBytes , Map <BytesArray , SMTProof > smt_lookup_table , Consumer <Cid > smtProofCidConsumer ) throws ResolutionException {
624+ private static byte [] processSMTBeacon (IPFSConnection ipfsConnection , byte [] signalBytes , Map <BytesArray , SMTProof > smt_lookup_table , Consumer <SMTProof > smtProofConsumer , Consumer < Cid > smtProofCidConsumer ) throws ResolutionException {
607625
608626 // Treat Signal Bytes as smt_root.
609627
@@ -629,6 +647,7 @@ private static byte[] processSMTBeacon(IPFSConnection ipfsConnection, byte[] sig
629647 if (smtProofCid != null ) smtProofCidConsumer .accept (smtProofCid );
630648
631649 if (smtProof == null ) throw new ResolutionException (ResolutionException .ERROR_INVALID_DID_DOCUMENT , "No SMT Proof found for smt_root " + Base64 .getUrlEncoder ().withoutPadding ().encodeToString (smt_root ));
650+ smtProofConsumer .accept (smtProof );
632651
633652 // Validate the proof with the SMT Proof Verification algorithm.
634653
0 commit comments