@@ -45,49 +45,57 @@ func VerifyOwner(senderRawOwner []byte, outRawOwner []byte) (*hashescrow.Script,
4545}
4646
4747// MetadataClaimKeyCheck validates claim metadata and returns the matched metadata key.
48- func MetadataClaimKeyCheck (action Action , script * hashescrow.Script , sig []byte ) (string , error ) {
48+ func MetadataClaimKeyCheck (action Action , script * hashescrow.Script , sig []byte ) (string , [] byte , error ) {
4949 claim := & hashescrow.ClaimSignature {}
5050 if err := json .Unmarshal (sig , claim ); err != nil {
51- return "" , errors .Wrapf (err , "failed unmarshalling claim signature [%s]" , string (sig ))
51+ return "" , nil , errors .Wrapf (err , "failed unmarshalling claim signature [%s]" , string (sig ))
5252 }
53- if len (claim .Preimage ) == 0 || len (claim .ClaimantSignature ) == 0 {
54- return "" , errors .New ("expected a valid claim preImage and claimant signature" )
53+ if len (claim .Preimage ) == 0 {
54+ return "" , nil , errors .New ("expected a valid claim preImage" )
55+ }
56+ resolvedOwner , image , err := script .ResolveRecipientForPreImage (claim .Preimage )
57+ if err != nil {
58+ return "" , nil , errors .Wrap (err , "failed resolving recipient from preimage" )
5559 }
5660
5761 metadata := action .GetMetadata ()
5862 if len (metadata ) == 0 {
59- return "" , errors .New ("cannot find hash escrow pre-image, no metadata" )
60- }
61- image , err := script .HashInfo .Image (claim .Preimage )
62- if err != nil {
63- return "" , errors .Wrapf (err , "failed to compute image of [%x]" , claim .Preimage )
63+ return "" , nil , errors .New ("cannot find hash escrow pre-image, no metadata" )
6464 }
6565 key := hashescrow .ClaimKey (image )
6666 value , ok := metadata [key ]
6767 if ! ok {
68- return "" , errors .New ("cannot find hash escrow pre-image, missing metadata entry" )
68+ return "" , nil , errors .New ("cannot find hash escrow pre-image, missing metadata entry" )
6969 }
7070 if ! bytes .Equal (value , claim .Preimage ) {
71- return "" , errors .Errorf ("invalid action, cannot match hash escrow pre-image with metadata [%x]!=[%x]" , value , claim .Preimage )
71+ return "" , nil , errors .Errorf ("invalid action, cannot match hash escrow pre-image with metadata [%x]!=[%x]" , value , claim .Preimage )
7272 }
7373
74- return key , nil
74+ return key , resolvedOwner , nil
7575}
7676
7777// MetadataLockKeyCheck validates lock metadata and returns the lock metadata key.
78- func MetadataLockKeyCheck (action Action , script * hashescrow.Script ) (string , error ) {
78+ func MetadataLockKeyCheck (action Action , script * hashescrow.Script ) ([] string , error ) {
7979 metadata := action .GetMetadata ()
8080 if len (metadata ) == 0 {
81- return "" , errors .New ("cannot find hash escrow lock, no metadata" )
81+ return nil , errors .New ("cannot find hash escrow lock, no metadata" )
8282 }
83- key := hashescrow .LockKey (script .HashInfo .Hash )
84- value , ok := metadata [key ]
83+ recipientKey := hashescrow .LockKey (script .RecipientHashInfo .Hash )
84+ recipientValue , ok := metadata [recipientKey ]
85+ if ! ok {
86+ return nil , errors .New ("cannot find recipient hash escrow lock, missing metadata entry" )
87+ }
88+ if ! bytes .Equal (recipientValue , hashescrow .LockValue (script .RecipientHashInfo .Hash )) {
89+ return nil , errors .Errorf ("invalid action, cannot match recipient hash escrow lock with metadata [%x]!=[%x]" , recipientValue , script .RecipientHashInfo .Hash )
90+ }
91+ senderKey := hashescrow .LockKey (script .SenderHashInfo .Hash )
92+ senderValue , ok := metadata [senderKey ]
8593 if ! ok {
86- return "" , errors .New ("cannot find hash escrow lock, missing metadata entry" )
94+ return nil , errors .New ("cannot find sender hash escrow lock, missing metadata entry" )
8795 }
88- if ! bytes .Equal (value , hashescrow .LockValue (script .HashInfo .Hash )) {
89- return "" , errors .Errorf ("invalid action, cannot match hash escrow lock with metadata [%x]!=[%x]" , value , script .HashInfo .Hash )
96+ if ! bytes .Equal (senderValue , hashescrow .LockValue (script .SenderHashInfo .Hash )) {
97+ return nil , errors .Errorf ("invalid action, cannot match sender hash escrow lock with metadata [%x]!=[%x]" , senderValue , script .SenderHashInfo .Hash )
9098 }
9199
92- return key , nil
100+ return [] string { recipientKey , senderKey } , nil
93101}
0 commit comments