@@ -186,17 +186,17 @@ func CreateAnyAddressSubdigestTree(calls []*v3.CallsPayload) ([]v3.WalletConfigT
186186 return leaves , nil
187187}
188188
189- // `CreateIntentTree` creates a tree from a list of intent operations and a main signer address.
190- func CreateIntentTree (mainSigner common.Address , calls []* v3.CallsPayload , sapientSignerLeafNode v3.WalletConfigTree ) (* v3.WalletConfigTree , error ) {
189+ func createIntentTree (mainSigner common.Address , calls []* v3.CallsPayload , additionalLeaves ... v3.WalletConfigTree ) (* v3.WalletConfigTree , error ) {
191190 // Create the subdigest leaves from the batched transactions.
192191 leaves , err := CreateAnyAddressSubdigestTree (calls )
193192 if err != nil {
194193 return nil , err
195194 }
196195
197- // If the sapient signer leaf is not nil, add it to the leaves.
198- if sapientSignerLeafNode != nil {
199- leaves = append (leaves , sapientSignerLeafNode )
196+ for _ , leaf := range additionalLeaves {
197+ if leaf != nil {
198+ leaves = append (leaves , leaf )
199+ }
200200 }
201201
202202 // Create the main signer leaf (with weight 1).
@@ -220,39 +220,36 @@ func CreateIntentTree(mainSigner common.Address, calls []*v3.CallsPayload, sapie
220220 return & fullTree , nil
221221}
222222
223- // `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 ) {
225- // Create the subdigest leaves from the batched transactions.
226- tree , err := CreateIntentTree (mainSigner , calls , sapientSignerLeafNode )
223+ // `CreateIntentTree` creates a tree from a list of intent operations and a main signer address.
224+ func CreateIntentTree (mainSigner common.Address , calls []* v3.CallsPayload , sapientSignerLeafNode v3.WalletConfigTree ) (* v3.WalletConfigTree , error ) {
225+ return createIntentTree (mainSigner , calls , sapientSignerLeafNode )
226+ }
227+
228+ func createIntentConfiguration (mainSigner common.Address , calls []* v3.CallsPayload , additionalLeaves ... v3.WalletConfigTree ) (* v3.WalletConfig , error ) {
229+ tree , err := createIntentTree (mainSigner , calls , additionalLeaves ... )
227230 if err != nil {
228231 return nil , err
229232 }
230233
231- // Construct the new wallet config using:
232- config := & v3.WalletConfig {
234+ return & v3.WalletConfig {
233235 Threshold_ : 1 ,
234236 Checkpoint_ : 0 ,
235237 Tree : * tree ,
236- }
238+ }, nil
239+ }
237240
238- return config , nil
241+ // `CreateIntentConfiguration` creates a wallet configuration where the intent's transaction batches are grouped into the initial subdigest.
242+ func CreateIntentConfiguration (mainSigner common.Address , calls []* v3.CallsPayload , sapientSignerLeafNode v3.WalletConfigTree ) (* v3.WalletConfig , error ) {
243+ return createIntentConfiguration (mainSigner , calls , sapientSignerLeafNode )
239244}
240245
241- // `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.
243- func GetIntentConfigurationSignature (
244- mainSigner common.Address ,
245- calls []* v3.CallsPayload ,
246- ) ([]byte , error ) {
247- // Default case without any sapient signer
248- config , err := CreateIntentConfiguration (mainSigner , calls , nil )
249- if err != nil {
250- return nil , err
246+ // `BuildIntentConfigurationSignature` creates a signature for an already-built intent configuration
247+ // that can be used to bypass chain ID validation.
248+ func BuildIntentConfigurationSignature (config * v3.WalletConfig ) ([]byte , error ) {
249+ if config == nil {
250+ return nil , fmt .Errorf ("intent configuration is nil" )
251251 }
252252
253- // spew.Dump(config)
254- // spew.Dump(config.Tree)
255-
256253 signingFunc := func (ctx context.Context , signer core.Signer , _ []core.SignerSignature ) (core.SignerSignatureType , []byte , error ) {
257254 // For mainSigner or other signers, we don't provide a signature here.
258255 // This will result in an AddressLeaf or NodeLeaf in the signature tree.
@@ -266,30 +263,6 @@ func GetIntentConfigurationSignature(
266263 return nil , fmt .Errorf ("failed to build regular signature: %w" , err )
267264 }
268265
269- // spew.Dump(sig)
270-
271- if regularSig , ok := sig .(* v3.RegularSignature ); ok {
272- if regularSig .Signature != nil {
273- signatureTree := regularSig .Signature .Tree
274- _ = signatureTree
275- // fmt.Println("Accessing sig.Signature.Tree:")
276- // spew.Dump(signatureTree)
277- } else {
278- // fmt.Println("sig.Signature is nil")
279- }
280- } else if noChainIdSig , ok := sig .(* v3.NoChainIDSignature ); ok {
281- if noChainIdSig .Signature != nil {
282- signatureTree := noChainIdSig .Signature .Tree
283- _ = signatureTree
284- // fmt.Println("Accessing sig.Signature.Tree (NoChainID):")
285- // spew.Dump(signatureTree)
286- } else {
287- // fmt.Println("sig.Signature is nil for NoChainIDSignature")
288- }
289- } else {
290- // fmt.Printf("sig is not of type *v3.RegularSignature or *v3.NoChainIDSignature, it is %T\n", sig)
291- }
292-
293266 // Get the signature data
294267 data , err := sig .Data ()
295268 if err != nil {
@@ -302,6 +275,20 @@ func GetIntentConfigurationSignature(
302275 return data , nil
303276}
304277
278+ // `GetIntentConfigurationSignature` creates a signature for the intent configuration that can be used to bypass chain ID validation.
279+ // The signature is based on the transaction bundle digests only.
280+ func GetIntentConfigurationSignature (
281+ mainSigner common.Address ,
282+ calls []* v3.CallsPayload ,
283+ ) ([]byte , error ) {
284+ config , err := CreateIntentConfiguration (mainSigner , calls , nil )
285+ if err != nil {
286+ return nil , err
287+ }
288+
289+ return BuildIntentConfigurationSignature (config )
290+ }
291+
305292// // replaceSapientSignerWithNodeInConfigTree recursively traverses the WalletConfigTree.
306293// func replaceSapientSignerWithNodeInConfigTree(tree v3.WalletConfigTree) v3.WalletConfigTree {
307294// if tree == nil {
0 commit comments