@@ -22,6 +22,26 @@ type TimedRefundIntentConfigurationSigner struct {
2222 Weight uint8
2323}
2424
25+ // TimedRefundSapientImageHashPreimage is the typed preimage for a timed-refund sapient signer.
26+ // It preserves the refund destination and unlock timestamp alongside the irreversible hash.
27+ type TimedRefundSapientImageHashPreimage struct {
28+ Destination common.Address
29+ UnlockTimestamp uint64
30+ }
31+
32+ func (p * TimedRefundSapientImageHashPreimage ) ImageHash () core.ImageHash {
33+ if p == nil {
34+ return core.ImageHash {}
35+ }
36+
37+ imageHash , err := TimedRefundSapientImageHash (p .Destination , p .UnlockTimestamp )
38+ if err != nil {
39+ panic (fmt .Errorf ("timed refund sapient image hash preimage: %w" , err ))
40+ }
41+
42+ return imageHash
43+ }
44+
2545// CreateIntentConfigurationWithTimedRefundSapient creates an intent configuration that includes
2646// a timed-refund sapient signer leaf in addition to the default any-address subdigests.
2747func CreateIntentConfigurationWithTimedRefundSapient (
@@ -51,7 +71,7 @@ func createTimedRefundSapientSignerLeaf(signer TimedRefundIntentConfigurationSig
5171 return nil , fmt .Errorf ("timed refund sapient signer weight is zero" )
5272 }
5373
54- imageHash , err := timedRefundSapientImageHash (signer .Destination , signer .UnlockTimestamp )
74+ imageHash , err := TimedRefundSapientImageHash (signer .Destination , signer .UnlockTimestamp )
5575 if err != nil {
5676 return nil , err
5777 }
@@ -86,7 +106,9 @@ func mustTimedRefundSapientImageHashArguments() abi.Arguments {
86106 }
87107}
88108
89- func timedRefundSapientImageHash (destination common.Address , unlockTimestamp uint64 ) (core.ImageHash , error ) {
109+ // TimedRefundSapientImageHash computes the image hash for a timed-refund sapient signer and
110+ // includes the recoverable typed preimage in the returned core.ImageHash.
111+ func TimedRefundSapientImageHash (destination common.Address , unlockTimestamp uint64 ) (core.ImageHash , error ) {
90112 encoded , err := timedRefundSapientImageHashArguments .Pack (
91113 "timed-refund" ,
92114 destination ,
@@ -96,5 +118,13 @@ func timedRefundSapientImageHash(destination common.Address, unlockTimestamp uin
96118 return core.ImageHash {}, fmt .Errorf ("failed to ABI pack timed refund sapient image hash: %w" , err )
97119 }
98120
99- return core.ImageHash {Hash : crypto .Keccak256Hash (encoded )}, nil
121+ preimage := & TimedRefundSapientImageHashPreimage {
122+ Destination : destination ,
123+ UnlockTimestamp : unlockTimestamp ,
124+ }
125+
126+ return core.ImageHash {
127+ Hash : crypto .Keccak256Hash (encoded ),
128+ Preimage : preimage ,
129+ }, nil
100130}
0 commit comments