@@ -188,10 +188,15 @@ func CreateAnyAddressSubdigestTree(calls []*v3.CallsPayload) ([]v3.WalletConfigT
188188
189189// `CreateIntentTree` creates a tree from a list of intent operations and a main signer address.
190190func CreateIntentTree (mainSigner common.Address , calls []* v3.CallsPayload , sapientSignerLeafNode v3.WalletConfigTree ) (* v3.WalletConfigTree , error ) {
191- // Create the subdigest leaves from the batched transactions.
192- leaves , err := CreateAnyAddressSubdigestTree (calls )
193- if err != nil {
194- return nil , err
191+ var leaves []v3.WalletConfigTree
192+
193+ if len (calls ) > 0 {
194+ // Create the subdigest leaves from the batched transactions.
195+ subdigestLeaves , err := CreateAnyAddressSubdigestTree (calls )
196+ if err != nil {
197+ return nil , err
198+ }
199+ leaves = append (leaves , subdigestLeaves ... )
195200 }
196201
197202 // If the sapient signer leaf is not nil, add it to the leaves.
@@ -205,6 +210,10 @@ func CreateIntentTree(mainSigner common.Address, calls []*v3.CallsPayload, sapie
205210 Address : mainSigner ,
206211 }
207212
213+ if len (leaves ) == 0 {
214+ return nil , fmt .Errorf ("no leaves to create tree from" )
215+ }
216+
208217 // If the length of the leaves is 1
209218 if len (leaves ) == 1 {
210219 tree := v3 .WalletConfigTreeNodes (mainSignerLeaf , leaves [0 ])
@@ -221,7 +230,7 @@ func CreateIntentTree(mainSigner common.Address, calls []*v3.CallsPayload, sapie
221230}
222231
223232// `CreateIntentConfiguration` creates a wallet configuration where the intent's transaction batches are grouped into the initial subdigest.
224- func CreateIntentConfiguration (mainSigner common.Address , calls []* v3.CallsPayload , sapientSignerLeafNode v3.WalletConfigTree ) (* v3.WalletConfig , error ) {
233+ func CreateIntentConfiguration (mainSigner common.Address , calls []* v3.CallsPayload , sapientSignerLeafNode v3.WalletConfigTree , checkpoint uint64 ) (* v3.WalletConfig , error ) {
225234 // Create the subdigest leaves from the batched transactions.
226235 tree , err := CreateIntentTree (mainSigner , calls , sapientSignerLeafNode )
227236 if err != nil {
@@ -231,37 +240,41 @@ func CreateIntentConfiguration(mainSigner common.Address, calls []*v3.CallsPaylo
231240 // Construct the new wallet config using:
232241 config := & v3.WalletConfig {
233242 Threshold_ : 1 ,
234- Checkpoint_ : 0 ,
243+ Checkpoint_ : checkpoint ,
235244 Tree : * tree ,
236245 }
237246
238247 return config , nil
239248}
240249
250+ type SignerSignature struct {
251+ Address common.Address
252+ Signature []byte
253+ Type core.SignerSignatureType
254+ }
255+
241256// `GetIntentConfigurationSignature` creates a signature for the intent configuration that can be used to bypass chain ID validation.
242- // The signature is based on the transaction bundle digests only .
257+ // `SignerSignatures` can be nil when executing a preapproved static payload .
243258func GetIntentConfigurationSignature (
244- mainSigner common.Address ,
245- calls []* v3.CallsPayload ,
259+ ctx context.Context ,
260+ config * v3.WalletConfig ,
261+ signerSignatures []* SignerSignature ,
246262) ([]byte , error ) {
247- // Default case without any sapient signer
248- config , err := CreateIntentConfiguration (mainSigner , calls , nil )
249- if err != nil {
250- return nil , err
251- }
252-
253263 // spew.Dump(config)
254264 // spew.Dump(config.Tree)
255265
256266 signingFunc := func (ctx context.Context , signer core.Signer , _ []core.SignerSignature ) (core.SignerSignatureType , []byte , error ) {
257- // For mainSigner or other signers, we don't provide a signature here.
258- // This will result in an AddressLeaf or NodeLeaf in the signature tree.
267+ for _ , signerSignature := range signerSignatures {
268+ if signer .Address == signerSignature .Address {
269+ return signerSignature .Type , signerSignature .Signature , nil
270+ }
271+ }
259272 return 0 , nil , nil
260273 }
261274
262275 // Build the signature using BuildNoChainIDSignature, which allows us to inject custom signatures via SigningFunction.
263276 // Set validateSigningPower to false, as we are not necessarily providing signatures for all parts of the config.
264- sig , err := config .BuildRegularSignature (context . Background () , signingFunc , false )
277+ sig , err := config .BuildRegularSignature (ctx , signingFunc , false )
265278 if err != nil {
266279 return nil , fmt .Errorf ("failed to build regular signature: %w" , err )
267280 }
@@ -301,42 +314,3 @@ func GetIntentConfigurationSignature(
301314
302315 return data , nil
303316}
304-
305- // // replaceSapientSignerWithNodeInConfigTree recursively traverses the WalletConfigTree.
306- // func replaceSapientSignerWithNodeInConfigTree(tree v3.WalletConfigTree) v3.WalletConfigTree {
307- // if tree == nil {
308- // return nil
309- // }
310-
311- // switch node := tree.(type) {
312- // case *v3.WalletConfigTreeNode:
313- // // Recursively call on left and right children
314- // left := replaceSapientSignerWithNodeInConfigTree(node.Left)
315- // right := replaceSapientSignerWithNodeInConfigTree(node.Right)
316-
317- // if left == node.Left && right == node.Right {
318- // return node
319- // }
320- // return &v3.WalletConfigTreeNode{Left: left, Right: right}
321-
322- // case *v3.WalletConfigTreeNestedLeaf:
323- // // Recursively call on the inner tree
324- // innerTree := replaceSapientSignerWithNodeInConfigTree(node.Tree)
325-
326- // if innerTree == node.Tree { // Check for pointer equality
327- // return node // No change, return original
328- // }
329- // return &v3.WalletConfigTreeNestedLeaf{
330- // Weight: node.Weight,
331- // Threshold: node.Threshold,
332- // Tree: innerTree,
333- // }
334-
335- // case *v3.WalletConfigTreeSapientSignerLeaf:
336- // // This is the target node type to replace
337- // return &v3.WalletConfigTreeNodeLeaf{Node: node.ImageHash()}
338-
339- // default:
340- // return tree
341- // }
342- // }
0 commit comments