@rhinestone/sdk 1.0.0-alpha.8 → 1.0.0-beta.38

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (153) hide show
  1. package/dist/src/accounts/error.d.ts +38 -3
  2. package/dist/src/accounts/error.d.ts.map +1 -1
  3. package/dist/src/accounts/error.js +57 -7
  4. package/dist/src/accounts/index.d.ts +30 -15
  5. package/dist/src/accounts/index.d.ts.map +1 -1
  6. package/dist/src/accounts/index.js +304 -138
  7. package/dist/src/accounts/index.test.js +3 -5
  8. package/dist/src/accounts/json-rpc/index.d.ts +5 -0
  9. package/dist/src/accounts/json-rpc/index.d.ts.map +1 -0
  10. package/dist/src/accounts/json-rpc/index.js +16 -0
  11. package/dist/src/accounts/json-rpc/index.test.d.ts.map +1 -0
  12. package/dist/src/accounts/json-rpc/index.test.js +16 -0
  13. package/dist/src/accounts/json-rpc/providers.d.ts +4 -0
  14. package/dist/src/accounts/json-rpc/providers.d.ts.map +1 -0
  15. package/dist/src/accounts/json-rpc/providers.js +14 -0
  16. package/dist/src/accounts/json-rpc/providers.test.d.ts +2 -0
  17. package/dist/src/accounts/json-rpc/providers.test.d.ts.map +1 -0
  18. package/dist/src/accounts/json-rpc/providers.test.js +15 -0
  19. package/dist/src/accounts/kernel.d.ts +4 -3
  20. package/dist/src/accounts/kernel.d.ts.map +1 -1
  21. package/dist/src/accounts/kernel.js +32 -6
  22. package/dist/src/accounts/kernel.test.js +41 -19
  23. package/dist/src/accounts/nexus.d.ts +14 -7
  24. package/dist/src/accounts/nexus.d.ts.map +1 -1
  25. package/dist/src/accounts/nexus.js +191 -34
  26. package/dist/src/accounts/nexus.test.js +44 -18
  27. package/dist/src/accounts/safe.d.ts +2 -2
  28. package/dist/src/accounts/safe.d.ts.map +1 -1
  29. package/dist/src/accounts/safe.js +88 -58
  30. package/dist/src/accounts/safe.test.js +40 -14
  31. package/dist/src/accounts/signing/common.d.ts +27 -0
  32. package/dist/src/accounts/signing/common.d.ts.map +1 -0
  33. package/dist/src/accounts/signing/common.js +145 -0
  34. package/dist/src/accounts/signing/message.d.ts +5 -0
  35. package/dist/src/accounts/signing/message.d.ts.map +1 -0
  36. package/dist/src/accounts/signing/message.js +47 -0
  37. package/dist/src/accounts/signing/passkeys.d.ts +36 -0
  38. package/dist/src/accounts/signing/passkeys.d.ts.map +1 -0
  39. package/dist/src/accounts/signing/passkeys.js +125 -0
  40. package/dist/src/accounts/signing/passkeys.test.d.ts +2 -0
  41. package/dist/src/accounts/signing/passkeys.test.d.ts.map +1 -0
  42. package/dist/src/accounts/signing/passkeys.test.js +88 -0
  43. package/dist/src/accounts/signing/typedData.d.ts +5 -0
  44. package/dist/src/accounts/signing/typedData.d.ts.map +1 -0
  45. package/dist/src/accounts/signing/typedData.js +35 -0
  46. package/dist/src/accounts/startale.d.ts +20 -0
  47. package/dist/src/accounts/startale.d.ts.map +1 -0
  48. package/dist/src/accounts/startale.js +100 -0
  49. package/dist/src/accounts/startale.test.d.ts +2 -0
  50. package/dist/src/accounts/startale.test.d.ts.map +1 -0
  51. package/dist/src/accounts/startale.test.js +92 -0
  52. package/dist/src/accounts/utils.d.ts +4 -4
  53. package/dist/src/accounts/utils.d.ts.map +1 -1
  54. package/dist/src/accounts/utils.js +3 -40
  55. package/dist/src/accounts/walletClient.d.ts +7 -0
  56. package/dist/src/accounts/walletClient.d.ts.map +1 -0
  57. package/dist/src/accounts/walletClient.js +38 -0
  58. package/dist/src/actions/compact.d.ts +13 -0
  59. package/dist/src/actions/compact.d.ts.map +1 -0
  60. package/dist/src/actions/compact.js +210 -0
  61. package/dist/src/actions/ecdsa.d.ts +35 -0
  62. package/dist/src/actions/ecdsa.d.ts.map +1 -0
  63. package/dist/src/actions/ecdsa.js +114 -0
  64. package/dist/src/actions/ecdsa.test.d.ts +2 -0
  65. package/dist/src/actions/ecdsa.test.d.ts.map +1 -0
  66. package/dist/src/actions/ecdsa.test.js +99 -0
  67. package/dist/src/actions/index.d.ts +23 -38
  68. package/dist/src/actions/index.d.ts.map +1 -1
  69. package/dist/src/actions/index.js +29 -294
  70. package/dist/src/actions/mfa.d.ts +37 -0
  71. package/dist/src/actions/mfa.d.ts.map +1 -0
  72. package/dist/src/actions/mfa.js +133 -0
  73. package/dist/src/actions/passkeys.d.ts +37 -0
  74. package/dist/src/actions/passkeys.d.ts.map +1 -0
  75. package/dist/src/actions/passkeys.js +129 -0
  76. package/dist/src/actions/passkeys.test.d.ts +2 -0
  77. package/dist/src/actions/passkeys.test.d.ts.map +1 -0
  78. package/dist/src/actions/passkeys.test.js +54 -0
  79. package/dist/src/actions/recovery.d.ts +33 -0
  80. package/dist/src/actions/recovery.d.ts.map +1 -0
  81. package/dist/src/actions/recovery.js +193 -0
  82. package/dist/src/actions/recovery.test.d.ts +2 -0
  83. package/dist/src/actions/recovery.test.d.ts.map +1 -0
  84. package/dist/src/actions/recovery.test.js +168 -0
  85. package/dist/src/actions/smart-session.d.ts +6 -0
  86. package/dist/src/actions/smart-session.d.ts.map +1 -1
  87. package/dist/src/actions/smart-session.js +6 -0
  88. package/dist/src/errors/index.d.ts +5 -0
  89. package/dist/src/errors/index.d.ts.map +1 -0
  90. package/dist/src/errors/index.js +35 -0
  91. package/dist/src/execution/compact.d.ts +150 -7
  92. package/dist/src/execution/compact.d.ts.map +1 -1
  93. package/dist/src/execution/compact.js +112 -95
  94. package/dist/src/execution/error.d.ts +2 -9
  95. package/dist/src/execution/error.d.ts.map +1 -1
  96. package/dist/src/execution/error.js +4 -13
  97. package/dist/src/execution/index.d.ts +34 -22
  98. package/dist/src/execution/index.d.ts.map +1 -1
  99. package/dist/src/execution/index.js +62 -43
  100. package/dist/src/execution/permit2.d.ts +148 -0
  101. package/dist/src/execution/permit2.d.ts.map +1 -0
  102. package/dist/src/execution/permit2.js +282 -0
  103. package/dist/src/execution/smart-session.d.ts +3 -3
  104. package/dist/src/execution/smart-session.d.ts.map +1 -1
  105. package/dist/src/execution/types.d.ts +35 -0
  106. package/dist/src/execution/types.d.ts.map +1 -0
  107. package/dist/src/execution/types.js +2 -0
  108. package/dist/src/execution/utils.d.ts +36 -27
  109. package/dist/src/execution/utils.d.ts.map +1 -1
  110. package/dist/src/execution/utils.js +357 -103
  111. package/dist/src/index.d.ts +41 -22
  112. package/dist/src/index.d.ts.map +1 -1
  113. package/dist/src/index.js +199 -65
  114. package/dist/src/modules/common.d.ts +10 -4
  115. package/dist/src/modules/common.d.ts.map +1 -1
  116. package/dist/src/modules/common.js +22 -1
  117. package/dist/src/modules/index.d.ts +4 -18
  118. package/dist/src/modules/index.d.ts.map +1 -1
  119. package/dist/src/modules/index.js +15 -63
  120. package/dist/src/modules/index.test.js +9 -26
  121. package/dist/src/modules/omni-account.d.ts +2 -1
  122. package/dist/src/modules/omni-account.d.ts.map +1 -1
  123. package/dist/src/modules/omni-account.js +3 -1
  124. package/dist/src/modules/read.d.ts.map +1 -1
  125. package/dist/src/modules/read.js +5 -0
  126. package/dist/src/modules/validators/core.d.ts +5 -3
  127. package/dist/src/modules/validators/core.d.ts.map +1 -1
  128. package/dist/src/modules/validators/core.js +64 -41
  129. package/dist/src/modules/validators/core.test.js +7 -7
  130. package/dist/src/modules/validators/smart-sessions.js +3 -3
  131. package/dist/src/modules/validators/smart-sessions.test.js +4 -7
  132. package/dist/src/orchestrator/client.d.ts +4 -4
  133. package/dist/src/orchestrator/client.d.ts.map +1 -1
  134. package/dist/src/orchestrator/client.js +30 -15
  135. package/dist/src/orchestrator/index.d.ts +2 -3
  136. package/dist/src/orchestrator/index.d.ts.map +1 -1
  137. package/dist/src/orchestrator/index.js +1 -3
  138. package/dist/src/orchestrator/registry.d.ts +1 -23
  139. package/dist/src/orchestrator/registry.d.ts.map +1 -1
  140. package/dist/src/orchestrator/registry.js +37 -33
  141. package/dist/src/orchestrator/registry.test.js +7 -7
  142. package/dist/src/orchestrator/types.d.ts +97 -29
  143. package/dist/src/orchestrator/types.d.ts.map +1 -1
  144. package/dist/src/orchestrator/utils.d.ts +1 -3
  145. package/dist/src/orchestrator/utils.d.ts.map +1 -1
  146. package/dist/src/orchestrator/utils.js +0 -102
  147. package/dist/src/types.d.ts +74 -10
  148. package/dist/src/types.d.ts.map +1 -1
  149. package/package.json +72 -1
  150. package/dist/src/actions/index.test.d.ts.map +0 -1
  151. package/dist/src/actions/index.test.js +0 -302
  152. package/dist/src/orchestrator/registry.json +0 -365
  153. /package/dist/src/{actions → accounts/json-rpc}/index.test.d.ts +0 -0
@@ -2,13 +2,22 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.prepareTransaction = prepareTransaction;
4
4
  exports.signTransaction = signTransaction;
5
+ exports.signAuthorizations = signAuthorizations;
6
+ exports.signAuthorizationsInternal = signAuthorizationsInternal;
7
+ exports.signMessage = signMessage;
8
+ exports.signTypedData = signTypedData;
5
9
  exports.submitTransaction = submitTransaction;
10
+ exports.prepareUserOperation = prepareUserOperation;
11
+ exports.signUserOperation = signUserOperation;
12
+ exports.submitUserOperation = submitUserOperation;
6
13
  exports.getOrchestratorByChain = getOrchestratorByChain;
7
14
  exports.signIntent = signIntent;
8
15
  exports.prepareTransactionAsIntent = prepareTransactionAsIntent;
9
16
  exports.submitIntentInternal = submitIntentInternal;
10
17
  exports.getValidatorAccount = getValidatorAccount;
11
18
  exports.parseCalls = parseCalls;
19
+ exports.getTokenRequests = getTokenRequests;
20
+ exports.resolveCallInputs = resolveCallInputs;
12
21
  const viem_1 = require("viem");
13
22
  const account_abstraction_1 = require("viem/account-abstraction");
14
23
  const accounts_1 = require("../accounts");
@@ -18,93 +27,196 @@ const core_1 = require("../modules/validators/core");
18
27
  const orchestrator_1 = require("../orchestrator");
19
28
  const consts_1 = require("../orchestrator/consts");
20
29
  const registry_1 = require("../orchestrator/registry");
30
+ const compact_1 = require("./compact");
21
31
  const error_1 = require("./error");
32
+ const permit2_1 = require("./permit2");
22
33
  async function prepareTransaction(config, transaction) {
23
- const { sourceChains, targetChain, tokenRequests, signers } = getTransactionParams(transaction);
34
+ const { sourceChains, targetChain, tokenRequests, signers, sponsored, eip7702InitSignature, settlementLayers, sourceAssets, feeAsset, lockFunds, } = getTransactionParams(transaction);
24
35
  const accountAddress = (0, accounts_1.getAddress)(config);
25
- let data;
26
- const asUserOp = signers?.type === 'guardians' || signers?.type === 'session';
27
- if (asUserOp) {
28
- if (sourceChains && sourceChains.length > 0) {
29
- throw new error_1.SourceChainsNotAvailableForUserOpFlowError();
30
- }
31
- // Smart sessions require a UserOp flow
32
- data = await prepareTransactionAsUserOp(config, targetChain, transaction.calls, signers);
33
- }
34
- else {
35
- data = await prepareTransactionAsIntent(config, sourceChains, targetChain, transaction.calls, transaction.gasLimit, tokenRequests, accountAddress);
36
+ const isUserOpSigner = signers?.type === 'guardians' || signers?.type === 'session';
37
+ if (isUserOpSigner) {
38
+ throw new error_1.SignerNotSupportedError();
36
39
  }
40
+ const intentRoute = await prepareTransactionAsIntent(config, sourceChains, targetChain, await resolveCallInputs(transaction.calls, config, targetChain, accountAddress), transaction.gasLimit, tokenRequests, accountAddress, sponsored ?? false, eip7702InitSignature, settlementLayers, sourceAssets, feeAsset, lockFunds);
37
41
  return {
38
- data,
42
+ intentRoute,
39
43
  transaction,
40
44
  };
41
45
  }
42
- async function signTransaction(config, preparedTransaction) {
43
- const { targetChain, signers } = getTransactionParams(preparedTransaction.transaction);
44
- const data = preparedTransaction.data;
45
- const asUserOp = data.type === 'userop';
46
- let signature;
47
- if (asUserOp) {
48
- const chain = targetChain;
49
- const userOp = data.userOp;
50
- if (!userOp) {
51
- throw new error_1.UserOperationRequiredForSmartSessionsError();
46
+ async function prepareUserOperation(config, transaction) {
47
+ const chain = transaction.chain;
48
+ const signers = transaction.signers;
49
+ const accountAddress = (0, accounts_1.getAddress)(config);
50
+ const data = await prepareTransactionAsUserOp(config, chain, await resolveCallInputs(transaction.calls, config, chain, accountAddress), signers, transaction.gasLimit);
51
+ return {
52
+ userOperation: data.userOp,
53
+ hash: data.hash,
54
+ transaction,
55
+ };
56
+ }
57
+ async function resolveCallInputs(inputs, config, chain, accountAddress) {
58
+ const resolved = [];
59
+ for (const intent of inputs) {
60
+ if ('resolve' in intent) {
61
+ const result = await intent.resolve({ config, chain, accountAddress });
62
+ if (Array.isArray(result)) {
63
+ resolved.push(...result);
64
+ }
65
+ else if (result) {
66
+ resolved.push(result);
67
+ }
68
+ }
69
+ else {
70
+ resolved.push(intent);
52
71
  }
53
- // Smart sessions require a UserOp flow
54
- signature = await signUserOp(config, chain, signers, userOp);
55
- }
56
- else {
57
- signature = await signIntent(config, targetChain, data.hash, signers);
58
72
  }
73
+ return resolved;
74
+ }
75
+ async function signTransaction(config, preparedTransaction) {
76
+ const { targetChain, signers } = getTransactionParams(preparedTransaction.transaction);
77
+ const intentRoute = preparedTransaction.intentRoute;
78
+ const signature = await signIntent(config, targetChain, intentRoute.intentOp, signers);
59
79
  return {
60
- data,
80
+ intentRoute,
61
81
  transaction: preparedTransaction.transaction,
62
82
  signature,
63
83
  };
64
84
  }
65
- async function submitTransaction(config, signedTransaction) {
66
- const { data, transaction, signature } = signedTransaction;
67
- const { sourceChains, targetChain } = getTransactionParams(transaction);
68
- const asUserOp = data.type === 'userop';
69
- if (asUserOp) {
70
- const chain = targetChain;
71
- const userOp = data.userOp;
72
- if (!userOp) {
73
- throw new error_1.UserOperationRequiredForSmartSessionsError();
74
- }
75
- // Smart sessions require a UserOp flow
76
- return await submitUserOp(config, chain, userOp, signature);
85
+ async function signUserOperation(config, preparedUserOperation) {
86
+ const chain = preparedUserOperation.transaction.chain;
87
+ const userOp = preparedUserOperation.userOperation;
88
+ const signers = preparedUserOperation.transaction.signers;
89
+ // Smart sessions require a UserOp flow
90
+ const signature = await signUserOp(config, chain, signers, userOp);
91
+ return {
92
+ userOperation: preparedUserOperation.userOperation,
93
+ hash: preparedUserOperation.hash,
94
+ transaction: preparedUserOperation.transaction,
95
+ signature,
96
+ };
97
+ }
98
+ async function signAuthorizations(config, preparedTransaction) {
99
+ return await signAuthorizationsInternal(config, preparedTransaction.intentRoute);
100
+ }
101
+ async function signMessage(config, message, chain, signers) {
102
+ const validator = getValidator(config, signers);
103
+ if (!validator) {
104
+ throw new Error('Validator not available');
77
105
  }
78
- else {
79
- const intentOp = data.intentRoute.intentOp;
80
- if (!intentOp) {
81
- throw new error_1.OrderPathRequiredForIntentsError();
106
+ const ownerValidator = (0, validators_1.getOwnerValidator)(config);
107
+ const isRoot = validator.address === ownerValidator.address;
108
+ const hash = (0, viem_1.hashMessage)(message);
109
+ const signature = await (0, accounts_1.getPackedSignature)(config, signers, chain, {
110
+ address: validator.address,
111
+ isRoot,
112
+ }, hash);
113
+ return await (0, accounts_1.toErc6492Signature)(config, signature, chain);
114
+ }
115
+ async function signTypedData(config, parameters, chain, signers) {
116
+ const validator = getValidator(config, signers);
117
+ if (!validator) {
118
+ throw new Error('Validator not available');
119
+ }
120
+ const ownerValidator = (0, validators_1.getOwnerValidator)(config);
121
+ const isRoot = validator.address === ownerValidator.address;
122
+ const signature = await (0, accounts_1.getTypedDataPackedSignature)(config, signers, chain, {
123
+ address: validator.address,
124
+ isRoot,
125
+ }, parameters);
126
+ return await (0, accounts_1.toErc6492Signature)(config, signature, chain);
127
+ }
128
+ async function signAuthorizationsInternal(config, data) {
129
+ const eoa = config.eoa;
130
+ if (!eoa) {
131
+ throw new Error('EIP-7702 initialization is required for EOA accounts');
132
+ }
133
+ const accountAddress = (0, accounts_1.getAddress)(config);
134
+ const requiredDelegations = 'intentOp' in data
135
+ ? data.intentOp.signedMetadata.account.requiredDelegations || {}
136
+ : {};
137
+ const authorizations = [];
138
+ for (const chainId in requiredDelegations) {
139
+ const delegation = requiredDelegations[chainId];
140
+ const chain = (0, registry_1.getChainById)(Number(chainId));
141
+ const walletClient = (0, viem_1.createWalletClient)({
142
+ chain,
143
+ account: eoa,
144
+ transport: (0, utils_1.createTransport)(chain, config.provider),
145
+ }).extend(viem_1.publicActions);
146
+ const code = await walletClient.getCode({
147
+ address: accountAddress,
148
+ });
149
+ const isDelegated = code === (0, viem_1.concat)(['0xef0100', delegation.contract.toLowerCase()]);
150
+ if (isDelegated) {
151
+ continue;
82
152
  }
83
- return await submitIntent(config, sourceChains, targetChain, intentOp, signature);
153
+ const authorization = await walletClient.signAuthorization({
154
+ contractAddress: delegation.contract,
155
+ chainId: Number(chainId),
156
+ });
157
+ authorizations.push(authorization);
84
158
  }
159
+ return authorizations;
160
+ }
161
+ async function submitTransaction(config, signedTransaction, authorizations, dryRun = false) {
162
+ const { intentRoute, transaction, signature } = signedTransaction;
163
+ const { sourceChains, targetChain } = getTransactionParams(transaction);
164
+ const intentOp = intentRoute.intentOp;
165
+ return await submitIntent(config, sourceChains, targetChain, intentOp, signature, authorizations, dryRun);
166
+ }
167
+ async function submitUserOperation(config, signedUserOperation) {
168
+ const chain = signedUserOperation.transaction.chain;
169
+ const userOp = signedUserOperation.userOperation;
170
+ const signature = signedUserOperation.signature;
171
+ // Smart sessions require a UserOp flow
172
+ return await submitUserOp(config, chain, userOp, signature);
85
173
  }
86
174
  function getTransactionParams(transaction) {
87
175
  const sourceChains = 'chain' in transaction ? [transaction.chain] : transaction.sourceChains;
88
176
  const targetChain = 'chain' in transaction ? transaction.chain : transaction.targetChain;
89
177
  const initialTokenRequests = transaction.tokenRequests;
90
178
  const signers = transaction.signers;
91
- // Across requires passing some value to repay the solvers
92
- const tokenRequests = !initialTokenRequests || initialTokenRequests.length === 0
93
- ? [
94
- {
95
- address: viem_1.zeroAddress,
96
- amount: 1n,
97
- },
98
- ]
99
- : initialTokenRequests;
179
+ const eip7702InitSignature = transaction.eip7702InitSignature;
180
+ const sponsored = transaction.sponsored;
181
+ const gasLimit = transaction.gasLimit;
182
+ const settlementLayers = transaction.settlementLayers;
183
+ const sourceAssets = transaction.sourceAssets;
184
+ const feeAsset = transaction.feeAsset;
185
+ const lockFunds = transaction.lockFunds;
186
+ const tokenRequests = getTokenRequests(sourceChains || [], targetChain, initialTokenRequests, settlementLayers);
100
187
  return {
101
188
  sourceChains,
102
189
  targetChain,
103
190
  tokenRequests,
104
191
  signers,
192
+ sponsored,
193
+ eip7702InitSignature,
194
+ gasLimit,
195
+ settlementLayers,
196
+ sourceAssets,
197
+ feeAsset,
198
+ lockFunds,
105
199
  };
106
200
  }
107
- async function prepareTransactionAsUserOp(config, chain, callInputs, signers) {
201
+ function getTokenRequests(sourceChains, targetChain, initialTokenRequests, settlementLayers) {
202
+ if (initialTokenRequests) {
203
+ validateTokenSymbols(targetChain, initialTokenRequests.map((tokenRequest) => tokenRequest.address));
204
+ }
205
+ // Across requires passing some value to repay the solvers
206
+ const defaultTokenRequest = {
207
+ address: viem_1.zeroAddress,
208
+ amount: 1n,
209
+ };
210
+ const isSameChain = (settlementLayers?.length === 1 && settlementLayers[0] === 'SAME_CHAIN') ||
211
+ (sourceChains.length === 1 && sourceChains[0].id === targetChain.id);
212
+ const tokenRequests = !initialTokenRequests || initialTokenRequests.length === 0
213
+ ? isSameChain
214
+ ? []
215
+ : [defaultTokenRequest]
216
+ : initialTokenRequests;
217
+ return tokenRequests;
218
+ }
219
+ async function prepareTransactionAsUserOp(config, chain, callInputs, signers, gasLimit) {
108
220
  const publicClient = (0, viem_1.createPublicClient)({
109
221
  chain,
110
222
  transport: (0, utils_1.createTransport)(chain, config.provider),
@@ -118,9 +230,9 @@ async function prepareTransactionAsUserOp(config, chain, callInputs, signers) {
118
230
  const userOp = await bundlerClient.prepareUserOperation({
119
231
  account: validatorAccount,
120
232
  calls,
233
+ callGasLimit: gasLimit,
121
234
  });
122
235
  return {
123
- type: 'userop',
124
236
  userOp,
125
237
  hash: (0, account_abstraction_1.getUserOperationHash)({
126
238
  userOperation: userOp,
@@ -130,14 +242,19 @@ async function prepareTransactionAsUserOp(config, chain, callInputs, signers) {
130
242
  }),
131
243
  };
132
244
  }
133
- async function prepareTransactionAsIntent(config, sourceChains, targetChain, callInputs, gasLimit, tokenRequests, accountAddress) {
134
- const initCode = (0, accounts_1.getInitCode)(config);
245
+ async function prepareTransactionAsIntent(config, sourceChains, targetChain, callInputs, gasLimit, tokenRequests, accountAddress, isSponsored, eip7702InitSignature, settlementLayers, sourceAssets, feeAsset, lockFunds) {
135
246
  const calls = parseCalls(callInputs, targetChain.id);
136
- const accountAccessList = sourceChains && sourceChains.length > 0
137
- ? {
138
- chainIds: sourceChains.map((chain) => chain.id),
247
+ const accountAccessList = createAccountAccessList(sourceChains, sourceAssets);
248
+ const { setupOps, delegations } = await getSetupOperationsAndDelegations(config, targetChain, accountAddress, eip7702InitSignature);
249
+ const getAccountType = (config) => {
250
+ if (config.account?.type === 'eoa') {
251
+ return 'EOA';
252
+ }
253
+ else {
254
+ return 'ERC7579';
139
255
  }
140
- : undefined;
256
+ };
257
+ const accountType = getAccountType(config);
141
258
  const metaIntent = {
142
259
  destinationChainId: targetChain.id,
143
260
  tokenTransfers: tokenRequests.map((tokenRequest) => ({
@@ -146,46 +263,87 @@ async function prepareTransactionAsIntent(config, sourceChains, targetChain, cal
146
263
  })),
147
264
  account: {
148
265
  address: accountAddress,
149
- accountType: 'ERC7579',
150
- setupOps: initCode
151
- ? [
152
- {
153
- to: initCode.factory,
154
- data: initCode.factoryData,
155
- },
156
- ]
157
- : [
158
- {
159
- to: viem_1.zeroAddress,
160
- data: '0x',
161
- },
162
- ],
266
+ accountType: accountType,
267
+ setupOps,
268
+ delegations,
163
269
  },
164
270
  destinationExecutions: calls,
165
271
  destinationGasUnits: gasLimit,
166
272
  accountAccessList,
273
+ options: {
274
+ topupCompact: lockFunds ?? false,
275
+ feeToken: feeAsset,
276
+ sponsorSettings: {
277
+ gasSponsored: isSponsored,
278
+ bridgeFeesSponsored: isSponsored,
279
+ swapFeesSponsored: isSponsored,
280
+ },
281
+ settlementLayers,
282
+ },
167
283
  };
168
- const orchestrator = getOrchestratorByChain(targetChain.id, config.rhinestoneApiKey);
284
+ const orchestrator = getOrchestratorByChain(targetChain.id, config.apiKey, config.endpointUrl);
169
285
  const intentRoute = await orchestrator.getIntentRoute(metaIntent);
170
- const intentHash = (0, orchestrator_1.getIntentOpHash)(intentRoute.intentOp);
171
- return {
172
- type: 'intent',
173
- intentRoute,
174
- hash: intentHash,
175
- };
286
+ return intentRoute;
176
287
  }
177
- async function signIntent(config, targetChain, intentHash, signers) {
288
+ async function signIntent(config, targetChain, intentOp, signers) {
289
+ if (config.account?.type === 'eoa') {
290
+ let signature;
291
+ let digest;
292
+ if (config.eoa?.signTypedData) {
293
+ const typedData = (0, permit2_1.getTypedData)(intentOp);
294
+ signature = await config.eoa.signTypedData(typedData);
295
+ }
296
+ else if (config.eoa?.sign) {
297
+ digest = (0, compact_1.getPermit2Digest)(intentOp);
298
+ signature = await config.eoa.sign({ hash: digest });
299
+ }
300
+ else if (config.eoa?.signMessage) {
301
+ digest = (0, compact_1.getPermit2Digest)(intentOp);
302
+ signature = await config.eoa.signMessage({
303
+ message: { raw: digest },
304
+ });
305
+ }
306
+ else {
307
+ throw new accounts_1.EoaSigningMethodNotConfiguredError('signTypedData, sign, or signMessage');
308
+ }
309
+ return signature;
310
+ }
178
311
  const validator = getValidator(config, signers);
179
312
  if (!validator) {
180
313
  throw new Error('Validator not available');
181
314
  }
182
315
  const ownerValidator = (0, validators_1.getOwnerValidator)(config);
183
316
  const isRoot = validator.address === ownerValidator.address;
184
- const signature = await (0, accounts_1.getPackedSignature)(config, signers, targetChain, {
317
+ const signature = await getIntentSignature(config, intentOp, signers, targetChain, validator, isRoot);
318
+ return signature;
319
+ }
320
+ async function getIntentSignature(config, intentOp, signers, targetChain, validator, isRoot) {
321
+ const withJitFlow = intentOp.elements.some((element) => element.mandate.qualifier.settlementContext?.usingJIT);
322
+ if (withJitFlow) {
323
+ return await getPermit2Signature(config, intentOp, signers, targetChain, validator, isRoot);
324
+ }
325
+ return await getCompactSignature(config, intentOp, signers, targetChain, validator, isRoot);
326
+ }
327
+ async function getPermit2Signature(config, intentOp, signers, targetChain, validator, isRoot) {
328
+ const typedData = (0, permit2_1.getTypedData)(intentOp);
329
+ return await signIntentTypedData(config, signers, targetChain, validator, isRoot, typedData);
330
+ }
331
+ async function getCompactSignature(config, intentOp, signers, targetChain, validator, isRoot) {
332
+ const typedData = (0, compact_1.getCompactTypedData)(intentOp);
333
+ return await signIntentTypedData(config, signers, targetChain, validator, isRoot, typedData);
334
+ }
335
+ async function signIntentTypedData(config, signers, targetChain, validator, isRoot, parameters) {
336
+ if ((0, core_1.supportsEip712)(validator)) {
337
+ return await (0, accounts_1.getTypedDataPackedSignature)(config, signers, targetChain, {
338
+ address: validator.address,
339
+ isRoot,
340
+ }, parameters);
341
+ }
342
+ const hash = (0, viem_1.hashTypedData)(parameters);
343
+ return await (0, accounts_1.getPackedSignature)(config, signers, targetChain, {
185
344
  address: validator.address,
186
345
  isRoot,
187
- }, intentHash);
188
- return signature;
346
+ }, hash);
189
347
  }
190
348
  async function signUserOp(config, chain, signers, userOp) {
191
349
  const validator = getValidator(config, signers);
@@ -241,23 +399,39 @@ async function submitUserOp(config, chain, userOp, signature) {
241
399
  chain: chain.id,
242
400
  };
243
401
  }
244
- async function submitIntent(config, sourceChains, targetChain, intentOp, signature) {
245
- return submitIntentInternal(config, sourceChains, targetChain, intentOp, signature);
402
+ async function submitIntent(config, sourceChains, targetChain, intentOp, signature, authorizations, dryRun) {
403
+ return submitIntentInternal(config, sourceChains, targetChain, intentOp, signature, authorizations, dryRun);
246
404
  }
247
- function getOrchestratorByChain(chainId, apiKey) {
248
- const orchestratorUrl = (0, registry_1.isTestnet)(chainId)
405
+ function getOrchestratorByChain(chainId, apiKey, orchestratorUrl) {
406
+ if (orchestratorUrl) {
407
+ return (0, orchestrator_1.getOrchestrator)(apiKey, orchestratorUrl);
408
+ }
409
+ const defaultOrchestratorUrl = (0, registry_1.isTestnet)(chainId)
249
410
  ? consts_1.STAGING_ORCHESTRATOR_URL
250
411
  : consts_1.PROD_ORCHESTRATOR_URL;
251
- return (0, orchestrator_1.getOrchestrator)(apiKey, orchestratorUrl);
412
+ return (0, orchestrator_1.getOrchestrator)(apiKey, defaultOrchestratorUrl);
252
413
  }
253
- async function submitIntentInternal(config, sourceChains, targetChain, intentOp, signature) {
254
- const signedIntentOp = {
414
+ function createSignedIntentOp(intentOp, signature, authorizations) {
415
+ return {
255
416
  ...intentOp,
256
417
  originSignatures: Array(intentOp.elements.length).fill(signature),
257
418
  destinationSignature: signature,
419
+ signedAuthorizations: authorizations.length > 0
420
+ ? authorizations.map((authorization) => ({
421
+ chainId: authorization.chainId,
422
+ address: authorization.address,
423
+ nonce: authorization.nonce,
424
+ yParity: authorization.yParity ?? 0,
425
+ r: authorization.r,
426
+ s: authorization.s,
427
+ }))
428
+ : undefined,
258
429
  };
259
- const orchestrator = getOrchestratorByChain(targetChain.id, config.rhinestoneApiKey);
260
- const intentResults = await orchestrator.submitIntent(signedIntentOp);
430
+ }
431
+ async function submitIntentInternal(config, sourceChains, targetChain, intentOp, signature, authorizations, dryRun) {
432
+ const signedIntentOp = createSignedIntentOp(intentOp, signature, authorizations);
433
+ const orchestrator = getOrchestratorByChain(targetChain.id, config.apiKey, config.endpointUrl);
434
+ const intentResults = await orchestrator.submitIntent(signedIntentOp, dryRun);
261
435
  return {
262
436
  type: 'intent',
263
437
  id: BigInt(intentResults.result.id),
@@ -267,7 +441,7 @@ async function submitIntentInternal(config, sourceChains, targetChain, intentOp,
267
441
  }
268
442
  async function getValidatorAccount(config, signers, publicClient, chain) {
269
443
  if (!signers) {
270
- return undefined;
444
+ return (0, accounts_1.getSmartAccount)(config, publicClient, chain);
271
445
  }
272
446
  // Owners
273
447
  const withOwner = signers.type === 'owner' ? signers : null;
@@ -298,11 +472,10 @@ function getValidator(config, signers) {
298
472
  }
299
473
  // Passkeys (WebAuthn)
300
474
  if (withOwner.kind === 'passkey') {
301
- const passkeyAccount = withOwner.account;
302
- return (0, core_1.getWebAuthnValidator)({
303
- pubKey: passkeyAccount.publicKey,
304
- authenticatorId: passkeyAccount.id,
305
- });
475
+ return (0, core_1.getWebAuthnValidator)(1, withOwner.accounts.map((account) => ({
476
+ pubKey: account.publicKey,
477
+ authenticatorId: account.id,
478
+ })));
306
479
  }
307
480
  // Multi-factor
308
481
  if (withOwner.kind === 'multi-factor') {
@@ -329,3 +502,84 @@ function parseCalls(calls, chainId) {
329
502
  to: (0, registry_1.resolveTokenAddress)(call.to, chainId),
330
503
  }));
331
504
  }
505
+ function createAccountAccessList(sourceChains, sourceAssets) {
506
+ if (!sourceChains && !sourceAssets)
507
+ return undefined;
508
+ const chainIds = sourceChains?.map((chain) => chain.id);
509
+ if (!sourceAssets) {
510
+ return { chainIds };
511
+ }
512
+ if (Array.isArray(sourceAssets)) {
513
+ return chainIds
514
+ ? { chainIds, tokens: sourceAssets }
515
+ : { tokens: sourceAssets };
516
+ }
517
+ return { chainTokens: sourceAssets };
518
+ }
519
+ async function getSetupOperationsAndDelegations(config, chain, accountAddress, eip7702InitSignature) {
520
+ const initCode = (0, accounts_1.getInitCode)(config);
521
+ if (config.account?.type === 'eoa') {
522
+ return {
523
+ setupOps: [],
524
+ };
525
+ }
526
+ else if ((0, accounts_1.is7702)(config)) {
527
+ // EIP-7702 initialization is only needed for EOA accounts
528
+ if (!eip7702InitSignature || eip7702InitSignature === '0x') {
529
+ throw new Error('EIP-7702 initialization signature is required for EOA accounts');
530
+ }
531
+ const { initData: eip7702InitData, contract: eip7702Contract } = await (0, accounts_1.getEip7702InitCall)(config, eip7702InitSignature);
532
+ return {
533
+ setupOps: [
534
+ {
535
+ to: accountAddress,
536
+ data: eip7702InitData,
537
+ },
538
+ ],
539
+ delegations: {
540
+ 0: {
541
+ contract: eip7702Contract,
542
+ },
543
+ },
544
+ };
545
+ }
546
+ else if (initCode) {
547
+ const isAccountDeployed = await (0, accounts_1.isDeployed)(config, chain);
548
+ if (isAccountDeployed) {
549
+ return {
550
+ setupOps: [],
551
+ };
552
+ }
553
+ // Contract account with init code
554
+ return {
555
+ setupOps: [
556
+ {
557
+ to: initCode.factory,
558
+ data: initCode.factoryData,
559
+ },
560
+ ],
561
+ };
562
+ }
563
+ else {
564
+ // Already deployed contract account
565
+ return {
566
+ setupOps: [],
567
+ };
568
+ }
569
+ }
570
+ function validateTokenSymbols(chain, tokenAddressOrSymbols) {
571
+ function validateTokenSymbol(chain, addressOrSymbol) {
572
+ // Address
573
+ if ((0, viem_1.isAddress)(addressOrSymbol, { strict: false })) {
574
+ return true;
575
+ }
576
+ // Token symbol
577
+ const address = (0, registry_1.getTokenAddress)(addressOrSymbol, chain.id);
578
+ return (0, viem_1.isAddress)(address, { strict: false });
579
+ }
580
+ for (const addressOrSymbol of tokenAddressOrSymbols) {
581
+ if (!validateTokenSymbol(chain, addressOrSymbol)) {
582
+ throw new Error(`Invalid token symbol: ${addressOrSymbol}`);
583
+ }
584
+ }
585
+ }