@rhinestone/sdk 1.0.41-alpha.0 → 1.0.41

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 (208) hide show
  1. package/dist/src/accounts/error.d.ts +114 -0
  2. package/dist/src/accounts/error.d.ts.map +1 -0
  3. package/dist/src/accounts/error.js +174 -0
  4. package/dist/src/accounts/index.d.ts +50 -0
  5. package/dist/src/accounts/index.d.ts.map +1 -0
  6. package/dist/src/accounts/index.js +669 -0
  7. package/dist/src/accounts/index.test.d.ts +2 -0
  8. package/dist/src/accounts/index.test.d.ts.map +1 -0
  9. package/dist/src/accounts/index.test.js +33 -0
  10. package/dist/src/accounts/json-rpc/index.d.ts +5 -0
  11. package/dist/src/accounts/json-rpc/index.d.ts.map +1 -0
  12. package/dist/src/accounts/json-rpc/index.js +20 -0
  13. package/dist/src/accounts/json-rpc/index.test.d.ts +2 -0
  14. package/dist/src/accounts/json-rpc/index.test.d.ts.map +1 -0
  15. package/dist/src/accounts/json-rpc/index.test.js +33 -0
  16. package/dist/src/accounts/json-rpc/providers.d.ts +5 -0
  17. package/dist/src/accounts/json-rpc/providers.d.ts.map +1 -0
  18. package/dist/src/accounts/json-rpc/providers.js +22 -0
  19. package/dist/src/accounts/json-rpc/providers.test.d.ts +2 -0
  20. package/dist/src/accounts/json-rpc/providers.test.d.ts.map +1 -0
  21. package/dist/src/accounts/json-rpc/providers.test.js +43 -0
  22. package/dist/src/accounts/kernel.d.ts +29 -0
  23. package/dist/src/accounts/kernel.d.ts.map +1 -0
  24. package/dist/src/accounts/kernel.js +297 -0
  25. package/dist/src/accounts/kernel.test.d.ts +2 -0
  26. package/dist/src/accounts/kernel.test.d.ts.map +1 -0
  27. package/dist/src/accounts/kernel.test.js +132 -0
  28. package/dist/src/accounts/nexus.d.ts +35 -0
  29. package/dist/src/accounts/nexus.d.ts.map +1 -0
  30. package/dist/src/accounts/nexus.js +471 -0
  31. package/dist/src/accounts/nexus.test.d.ts +2 -0
  32. package/dist/src/accounts/nexus.test.d.ts.map +1 -0
  33. package/dist/src/accounts/nexus.test.js +118 -0
  34. package/dist/src/accounts/passport.d.ts +12 -0
  35. package/dist/src/accounts/passport.d.ts.map +1 -0
  36. package/dist/src/accounts/passport.js +173 -0
  37. package/dist/src/accounts/safe.d.ts +35 -0
  38. package/dist/src/accounts/safe.d.ts.map +1 -0
  39. package/dist/src/accounts/safe.js +365 -0
  40. package/dist/src/accounts/safe.test.d.ts +2 -0
  41. package/dist/src/accounts/safe.test.d.ts.map +1 -0
  42. package/dist/src/accounts/safe.test.js +118 -0
  43. package/dist/src/accounts/signing/common.d.ts +27 -0
  44. package/dist/src/accounts/signing/common.d.ts.map +1 -0
  45. package/dist/src/accounts/signing/common.js +183 -0
  46. package/dist/src/accounts/signing/message.d.ts +5 -0
  47. package/dist/src/accounts/signing/message.d.ts.map +1 -0
  48. package/dist/src/accounts/signing/message.js +47 -0
  49. package/dist/src/accounts/signing/passkeys.d.ts +36 -0
  50. package/dist/src/accounts/signing/passkeys.d.ts.map +1 -0
  51. package/dist/src/accounts/signing/passkeys.js +125 -0
  52. package/dist/src/accounts/signing/passkeys.test.d.ts +2 -0
  53. package/dist/src/accounts/signing/passkeys.test.d.ts.map +1 -0
  54. package/dist/src/accounts/signing/passkeys.test.js +88 -0
  55. package/dist/src/accounts/signing/typedData.d.ts +5 -0
  56. package/dist/src/accounts/signing/typedData.d.ts.map +1 -0
  57. package/dist/src/accounts/signing/typedData.js +35 -0
  58. package/dist/src/accounts/startale.d.ts +27 -0
  59. package/dist/src/accounts/startale.d.ts.map +1 -0
  60. package/dist/src/accounts/startale.js +116 -0
  61. package/dist/src/accounts/startale.test.d.ts +2 -0
  62. package/dist/src/accounts/startale.test.d.ts.map +1 -0
  63. package/dist/src/accounts/startale.test.js +92 -0
  64. package/dist/src/accounts/utils.d.ts +33 -0
  65. package/dist/src/accounts/utils.d.ts.map +1 -0
  66. package/dist/src/accounts/utils.js +208 -0
  67. package/dist/src/accounts/utils.test.d.ts +2 -0
  68. package/dist/src/accounts/utils.test.d.ts.map +1 -0
  69. package/dist/src/accounts/utils.test.js +49 -0
  70. package/dist/src/accounts/walletClient.d.ts +34 -0
  71. package/dist/src/accounts/walletClient.d.ts.map +1 -0
  72. package/dist/src/accounts/walletClient.js +121 -0
  73. package/dist/src/actions/compact.d.ts +13 -0
  74. package/dist/src/actions/compact.d.ts.map +1 -0
  75. package/dist/src/actions/compact.js +210 -0
  76. package/dist/src/actions/deployment.d.ts +19 -0
  77. package/dist/src/actions/deployment.d.ts.map +1 -0
  78. package/dist/src/actions/deployment.js +78 -0
  79. package/dist/src/actions/ecdsa.d.ts +35 -0
  80. package/dist/src/actions/ecdsa.d.ts.map +1 -0
  81. package/dist/src/actions/ecdsa.js +114 -0
  82. package/dist/src/actions/ecdsa.test.d.ts +2 -0
  83. package/dist/src/actions/ecdsa.test.d.ts.map +1 -0
  84. package/dist/src/actions/ecdsa.test.js +99 -0
  85. package/dist/src/actions/index.d.ts +17 -0
  86. package/dist/src/actions/index.d.ts.map +1 -0
  87. package/dist/src/actions/index.js +53 -0
  88. package/dist/src/actions/mfa.d.ts +37 -0
  89. package/dist/src/actions/mfa.d.ts.map +1 -0
  90. package/dist/src/actions/mfa.js +133 -0
  91. package/dist/src/actions/passkeys.d.ts +37 -0
  92. package/dist/src/actions/passkeys.d.ts.map +1 -0
  93. package/dist/src/actions/passkeys.js +129 -0
  94. package/dist/src/actions/passkeys.test.d.ts +2 -0
  95. package/dist/src/actions/passkeys.test.d.ts.map +1 -0
  96. package/dist/src/actions/passkeys.test.js +54 -0
  97. package/dist/src/actions/recovery.d.ts +33 -0
  98. package/dist/src/actions/recovery.d.ts.map +1 -0
  99. package/dist/src/actions/recovery.js +193 -0
  100. package/dist/src/actions/recovery.test.d.ts +2 -0
  101. package/dist/src/actions/recovery.test.d.ts.map +1 -0
  102. package/dist/src/actions/recovery.test.js +168 -0
  103. package/dist/src/actions/smart-sessions.d.ts +14 -0
  104. package/dist/src/actions/smart-sessions.d.ts.map +1 -0
  105. package/dist/src/actions/smart-sessions.js +16 -0
  106. package/dist/src/errors/index.d.ts +5 -0
  107. package/dist/src/errors/index.d.ts.map +1 -0
  108. package/dist/src/errors/index.js +53 -0
  109. package/dist/src/execution/compact.d.ts +151 -0
  110. package/dist/src/execution/compact.d.ts.map +1 -0
  111. package/dist/src/execution/compact.js +122 -0
  112. package/dist/src/execution/error.d.ts +61 -0
  113. package/dist/src/execution/error.d.ts.map +1 -0
  114. package/dist/src/execution/error.js +87 -0
  115. package/dist/src/execution/index.d.ts +41 -0
  116. package/dist/src/execution/index.d.ts.map +1 -0
  117. package/dist/src/execution/index.js +233 -0
  118. package/dist/src/execution/permit2.d.ts +148 -0
  119. package/dist/src/execution/permit2.d.ts.map +1 -0
  120. package/dist/src/execution/permit2.js +291 -0
  121. package/dist/src/execution/singleChainOps.d.ts +28 -0
  122. package/dist/src/execution/singleChainOps.d.ts.map +1 -0
  123. package/dist/src/execution/singleChainOps.js +32 -0
  124. package/dist/src/execution/smart-session.d.ts +13 -0
  125. package/dist/src/execution/smart-session.d.ts.map +1 -0
  126. package/dist/src/execution/smart-session.js +178 -0
  127. package/dist/src/execution/types.d.ts +36 -0
  128. package/dist/src/execution/types.d.ts.map +1 -0
  129. package/dist/src/execution/types.js +2 -0
  130. package/dist/src/execution/utils.d.ts +83 -0
  131. package/dist/src/execution/utils.d.ts.map +1 -0
  132. package/dist/src/execution/utils.js +705 -0
  133. package/dist/src/index.d.ts +74 -0
  134. package/dist/src/index.d.ts.map +1 -0
  135. package/dist/src/index.js +317 -0
  136. package/dist/src/modules/abi/smart-sessions.d.ts +104 -0
  137. package/dist/src/modules/abi/smart-sessions.d.ts.map +1 -0
  138. package/dist/src/modules/abi/smart-sessions.js +131 -0
  139. package/dist/src/modules/chain-abstraction.d.ts +5 -0
  140. package/dist/src/modules/chain-abstraction.d.ts.map +1 -0
  141. package/dist/src/modules/chain-abstraction.js +7 -0
  142. package/dist/src/modules/common.d.ts +30 -0
  143. package/dist/src/modules/common.d.ts.map +1 -0
  144. package/dist/src/modules/common.js +42 -0
  145. package/dist/src/modules/index.d.ts +10 -0
  146. package/dist/src/modules/index.d.ts.map +1 -0
  147. package/dist/src/modules/index.js +94 -0
  148. package/dist/src/modules/index.test.d.ts +2 -0
  149. package/dist/src/modules/index.test.d.ts.map +1 -0
  150. package/dist/src/modules/index.test.js +81 -0
  151. package/dist/src/modules/legacy.d.ts +10 -0
  152. package/dist/src/modules/legacy.d.ts.map +1 -0
  153. package/dist/src/modules/legacy.js +65 -0
  154. package/dist/src/modules/read.d.ts +9 -0
  155. package/dist/src/modules/read.d.ts.map +1 -0
  156. package/dist/src/modules/read.js +125 -0
  157. package/dist/src/modules/validators/core.d.ts +29 -0
  158. package/dist/src/modules/validators/core.d.ts.map +1 -0
  159. package/dist/src/modules/validators/core.js +278 -0
  160. package/dist/src/modules/validators/core.test.d.ts +2 -0
  161. package/dist/src/modules/validators/core.test.d.ts.map +1 -0
  162. package/dist/src/modules/validators/core.test.js +101 -0
  163. package/dist/src/modules/validators/index.d.ts +4 -0
  164. package/dist/src/modules/validators/index.d.ts.map +1 -0
  165. package/dist/src/modules/validators/index.js +15 -0
  166. package/dist/src/modules/validators/smart-sessions.d.ts +96 -0
  167. package/dist/src/modules/validators/smart-sessions.d.ts.map +1 -0
  168. package/dist/src/modules/validators/smart-sessions.js +497 -0
  169. package/dist/src/modules/validators/smart-sessions.test.d.ts +2 -0
  170. package/dist/src/modules/validators/smart-sessions.test.d.ts.map +1 -0
  171. package/dist/src/modules/validators/smart-sessions.test.js +219 -0
  172. package/dist/src/orchestrator/client.d.ts +27 -0
  173. package/dist/src/orchestrator/client.d.ts.map +1 -0
  174. package/dist/src/orchestrator/client.js +354 -0
  175. package/dist/src/orchestrator/consts.d.ts +5 -0
  176. package/dist/src/orchestrator/consts.d.ts.map +1 -0
  177. package/dist/src/orchestrator/consts.js +9 -0
  178. package/dist/src/orchestrator/error.d.ts +232 -0
  179. package/dist/src/orchestrator/error.d.ts.map +1 -0
  180. package/dist/src/orchestrator/error.js +268 -0
  181. package/dist/src/orchestrator/index.d.ts +10 -0
  182. package/dist/src/orchestrator/index.d.ts.map +1 -0
  183. package/dist/src/orchestrator/index.js +57 -0
  184. package/dist/src/orchestrator/registry.d.ts +22 -0
  185. package/dist/src/orchestrator/registry.d.ts.map +1 -0
  186. package/dist/src/orchestrator/registry.js +121 -0
  187. package/dist/src/orchestrator/registry.test.d.ts +2 -0
  188. package/dist/src/orchestrator/registry.test.d.ts.map +1 -0
  189. package/dist/src/orchestrator/registry.test.js +150 -0
  190. package/dist/src/orchestrator/types.d.ts +295 -0
  191. package/dist/src/orchestrator/types.d.ts.map +1 -0
  192. package/dist/src/orchestrator/types.js +17 -0
  193. package/dist/src/orchestrator/utils.d.ts +3 -0
  194. package/dist/src/orchestrator/utils.d.ts.map +1 -0
  195. package/dist/src/orchestrator/utils.js +24 -0
  196. package/dist/src/types.d.ts +284 -0
  197. package/dist/src/types.d.ts.map +1 -0
  198. package/dist/src/types.js +2 -0
  199. package/dist/src/utils/index.d.ts +26 -0
  200. package/dist/src/utils/index.d.ts.map +1 -0
  201. package/dist/src/utils/index.js +63 -0
  202. package/dist/test/consts.d.ts +10 -0
  203. package/dist/test/consts.d.ts.map +1 -0
  204. package/dist/test/consts.js +22 -0
  205. package/dist/test/utils/utils.d.ts +5 -0
  206. package/dist/test/utils/utils.d.ts.map +1 -0
  207. package/dist/test/utils/utils.js +20 -0
  208. package/package.json +1 -1
@@ -0,0 +1,705 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.prepareTransaction = prepareTransaction;
4
+ exports.getTransactionMessages = getTransactionMessages;
5
+ exports.signTransaction = signTransaction;
6
+ exports.signAuthorizations = signAuthorizations;
7
+ exports.signAuthorizationsInternal = signAuthorizationsInternal;
8
+ exports.signMessage = signMessage;
9
+ exports.signTypedData = signTypedData;
10
+ exports.submitTransaction = submitTransaction;
11
+ exports.prepareUserOperation = prepareUserOperation;
12
+ exports.signUserOperation = signUserOperation;
13
+ exports.submitUserOperation = submitUserOperation;
14
+ exports.getOrchestratorByChain = getOrchestratorByChain;
15
+ exports.signIntent = signIntent;
16
+ exports.prepareTransactionAsIntent = prepareTransactionAsIntent;
17
+ exports.submitIntentInternal = submitIntentInternal;
18
+ exports.getValidatorAccount = getValidatorAccount;
19
+ exports.parseCalls = parseCalls;
20
+ exports.getTokenRequests = getTokenRequests;
21
+ exports.resolveCallInputs = resolveCallInputs;
22
+ exports.getIntentAccount = getIntentAccount;
23
+ const viem_1 = require("viem");
24
+ const account_abstraction_1 = require("viem/account-abstraction");
25
+ const erc7739_1 = require("viem/experimental/erc7739");
26
+ const accounts_1 = require("../accounts");
27
+ const utils_1 = require("../accounts/utils");
28
+ const modules_1 = require("../modules");
29
+ const validators_1 = require("../modules/validators");
30
+ const core_1 = require("../modules/validators/core");
31
+ const orchestrator_1 = require("../orchestrator");
32
+ const consts_1 = require("../orchestrator/consts");
33
+ const registry_1 = require("../orchestrator/registry");
34
+ const compact_1 = require("./compact");
35
+ const error_1 = require("./error");
36
+ const permit2_1 = require("./permit2");
37
+ const singleChainOps_1 = require("./singleChainOps");
38
+ async function prepareTransaction(config, transaction) {
39
+ const { sourceChains, targetChain, tokenRequests, signers, sponsored, eip7702InitSignature, settlementLayers, sourceAssets, feeAsset, lockFunds, account, recipient, } = getTransactionParams(transaction);
40
+ const accountAddress = (0, accounts_1.getAddress)(config);
41
+ const isUserOpSigner = signers?.type === 'guardians' || signers?.type === 'session';
42
+ if (isUserOpSigner) {
43
+ throw new error_1.SignerNotSupportedError();
44
+ }
45
+ const intentRoute = await prepareTransactionAsIntent(config, sourceChains, targetChain, await resolveCallInputs(transaction.calls, config, targetChain, accountAddress), transaction.gasLimit, tokenRequests, recipient, sponsored, eip7702InitSignature, settlementLayers, sourceAssets, feeAsset, lockFunds, account);
46
+ return {
47
+ intentRoute,
48
+ transaction,
49
+ };
50
+ }
51
+ async function prepareUserOperation(config, transaction) {
52
+ const chain = transaction.chain;
53
+ const signers = transaction.signers;
54
+ const accountAddress = (0, accounts_1.getAddress)(config);
55
+ const data = await prepareTransactionAsUserOp(config, chain, await resolveCallInputs(transaction.calls, config, chain, accountAddress), signers, transaction.gasLimit);
56
+ return {
57
+ userOperation: data.userOp,
58
+ hash: data.hash,
59
+ transaction,
60
+ };
61
+ }
62
+ async function resolveCallInputs(inputs, config, chain, accountAddress) {
63
+ const resolved = [];
64
+ if (!inputs) {
65
+ return resolved;
66
+ }
67
+ for (const intent of inputs) {
68
+ if ('resolve' in intent) {
69
+ const result = await intent.resolve({ config, chain, accountAddress });
70
+ if (Array.isArray(result)) {
71
+ resolved.push(...result);
72
+ }
73
+ else if (result) {
74
+ resolved.push(result);
75
+ }
76
+ }
77
+ else {
78
+ resolved.push(intent);
79
+ }
80
+ }
81
+ return resolved;
82
+ }
83
+ function getTransactionMessages(config, preparedTransaction) {
84
+ return getIntentMessages(config, preparedTransaction.intentRoute.intentOp);
85
+ }
86
+ async function signTransaction(config, preparedTransaction) {
87
+ const { signers } = getTransactionParams(preparedTransaction.transaction);
88
+ const intentRoute = preparedTransaction.intentRoute;
89
+ const { originSignatures, destinationSignature } = await signIntent(config, intentRoute.intentOp, signers);
90
+ return {
91
+ intentRoute,
92
+ transaction: preparedTransaction.transaction,
93
+ originSignatures,
94
+ destinationSignature,
95
+ };
96
+ }
97
+ async function signUserOperation(config, preparedUserOperation) {
98
+ const chain = preparedUserOperation.transaction.chain;
99
+ const userOp = preparedUserOperation.userOperation;
100
+ const signers = preparedUserOperation.transaction.signers;
101
+ // Smart sessions require a UserOp flow
102
+ const signature = await signUserOp(config, chain, signers, userOp);
103
+ return {
104
+ userOperation: preparedUserOperation.userOperation,
105
+ hash: preparedUserOperation.hash,
106
+ transaction: preparedUserOperation.transaction,
107
+ signature,
108
+ };
109
+ }
110
+ async function signAuthorizations(config, preparedTransaction) {
111
+ return await signAuthorizationsInternal(config, preparedTransaction.intentRoute);
112
+ }
113
+ async function signMessage(config, message, chain, signers) {
114
+ const validator = getValidator(config, signers);
115
+ if (!validator) {
116
+ throw new Error('Validator not available');
117
+ }
118
+ const ownerValidator = (0, validators_1.getOwnerValidator)(config);
119
+ const isRoot = validator.address === ownerValidator.address;
120
+ const hash = (0, viem_1.hashMessage)(message);
121
+ const signature = await (0, accounts_1.getPackedSignature)(config, signers, chain, {
122
+ address: validator.address,
123
+ isRoot,
124
+ }, hash);
125
+ return await (0, accounts_1.toErc6492Signature)(config, signature, chain);
126
+ }
127
+ async function signTypedData(config, parameters, chain, signers) {
128
+ const validator = getValidator(config, signers);
129
+ if (!validator) {
130
+ throw new Error('Validator not available');
131
+ }
132
+ const ownerValidator = (0, validators_1.getOwnerValidator)(config);
133
+ const isRoot = validator.address === ownerValidator.address;
134
+ if (signers?.type === 'session') {
135
+ return await signTypedDataWithSession(config, chain, {
136
+ address: validator.address,
137
+ isRoot,
138
+ }, signers, parameters);
139
+ }
140
+ const signature = await (0, accounts_1.getTypedDataPackedSignature)(config, signers, chain, {
141
+ address: validator.address,
142
+ isRoot,
143
+ }, parameters);
144
+ return await (0, accounts_1.toErc6492Signature)(config, signature, chain);
145
+ }
146
+ async function signTypedDataWithSession(config, chain, validator, signers, parameters) {
147
+ const { name, version, chainId, verifyingContract, salt } = (0, accounts_1.getEip712Domain)(config, chain);
148
+ const signature = await (0, accounts_1.getTypedDataPackedSignature)(config, signers, chain, validator, {
149
+ domain: parameters.domain,
150
+ primaryType: 'TypedDataSign',
151
+ types: {
152
+ ...parameters.types,
153
+ TypedDataSign: [
154
+ { name: 'contents', type: parameters.primaryType },
155
+ { name: 'name', type: 'string' },
156
+ { name: 'version', type: 'string' },
157
+ { name: 'chainId', type: 'uint256' },
158
+ { name: 'verifyingContract', type: 'address' },
159
+ { name: 'salt', type: 'bytes32' },
160
+ ],
161
+ },
162
+ message: {
163
+ contents: parameters.message,
164
+ name,
165
+ version,
166
+ chainId,
167
+ verifyingContract,
168
+ salt,
169
+ },
170
+ }, (signature) => {
171
+ const erc7739Signature = (0, erc7739_1.wrapTypedDataSignature)({
172
+ domain: parameters.domain,
173
+ primaryType: parameters.primaryType,
174
+ types: parameters.types,
175
+ message: parameters.message,
176
+ signature,
177
+ });
178
+ return (0, viem_1.encodePacked)(['bytes32', 'bytes'], [(0, validators_1.getPermissionId)(signers.session), erc7739Signature]);
179
+ });
180
+ return await (0, accounts_1.toErc6492Signature)(config, signature, chain);
181
+ }
182
+ async function signAuthorizationsInternal(config, data) {
183
+ const eoa = config.eoa;
184
+ if (!eoa) {
185
+ throw new Error('EIP-7702 initialization is required for EOA accounts');
186
+ }
187
+ const accountAddress = (0, accounts_1.getAddress)(config);
188
+ const requiredDelegations = 'intentOp' in data
189
+ ? data.intentOp.signedMetadata.account.requiredDelegations || {}
190
+ : {};
191
+ const authorizations = [];
192
+ for (const chainId in requiredDelegations) {
193
+ const delegation = requiredDelegations[chainId];
194
+ const chain = (0, registry_1.getChainById)(Number(chainId));
195
+ const walletClient = (0, viem_1.createWalletClient)({
196
+ chain,
197
+ account: eoa,
198
+ transport: (0, utils_1.createTransport)(chain, config.provider),
199
+ }).extend(viem_1.publicActions);
200
+ const code = await walletClient.getCode({
201
+ address: accountAddress,
202
+ });
203
+ const isDelegated = code === (0, viem_1.concat)(['0xef0100', delegation.contract.toLowerCase()]);
204
+ if (isDelegated) {
205
+ continue;
206
+ }
207
+ const authorization = await walletClient.signAuthorization({
208
+ contractAddress: delegation.contract,
209
+ chainId: Number(chainId),
210
+ });
211
+ authorizations.push(authorization);
212
+ }
213
+ return authorizations;
214
+ }
215
+ async function submitTransaction(config, signedTransaction, authorizations, dryRun = false) {
216
+ const { intentRoute, transaction, originSignatures, destinationSignature } = signedTransaction;
217
+ const { sourceChains, targetChain } = getTransactionParams(transaction);
218
+ const intentOp = intentRoute.intentOp;
219
+ return await submitIntent(config, sourceChains, targetChain, intentOp, originSignatures, destinationSignature, authorizations, dryRun);
220
+ }
221
+ async function submitUserOperation(config, signedUserOperation) {
222
+ const chain = signedUserOperation.transaction.chain;
223
+ const userOp = signedUserOperation.userOperation;
224
+ const signature = signedUserOperation.signature;
225
+ // Smart sessions require a UserOp flow
226
+ return await submitUserOp(config, chain, userOp, signature);
227
+ }
228
+ function getTransactionParams(transaction) {
229
+ const sourceChains = 'chain' in transaction ? [transaction.chain] : transaction.sourceChains;
230
+ const targetChain = 'chain' in transaction ? transaction.chain : transaction.targetChain;
231
+ const initialTokenRequests = transaction.tokenRequests;
232
+ const signers = transaction.signers;
233
+ const eip7702InitSignature = transaction.eip7702InitSignature;
234
+ const sponsored = transaction.sponsored;
235
+ const gasLimit = transaction.gasLimit;
236
+ const settlementLayers = transaction.settlementLayers;
237
+ const sourceAssets = transaction.sourceAssets;
238
+ const feeAsset = transaction.feeAsset;
239
+ const lockFunds = transaction.lockFunds;
240
+ const account = transaction.experimental_accountOverride;
241
+ const recipient = transaction.recipient;
242
+ const tokenRequests = getTokenRequests(sourceChains || [], targetChain, initialTokenRequests, settlementLayers);
243
+ return {
244
+ sourceChains,
245
+ targetChain,
246
+ tokenRequests,
247
+ signers,
248
+ sponsored,
249
+ eip7702InitSignature,
250
+ gasLimit,
251
+ settlementLayers,
252
+ sourceAssets,
253
+ feeAsset,
254
+ lockFunds,
255
+ account,
256
+ recipient,
257
+ };
258
+ }
259
+ function getTokenRequests(sourceChains, targetChain, initialTokenRequests, settlementLayers) {
260
+ if (initialTokenRequests) {
261
+ validateTokenSymbols(targetChain, initialTokenRequests.map((tokenRequest) => tokenRequest.address));
262
+ }
263
+ // Across requires passing some value to repay the solvers
264
+ const defaultTokenRequest = {
265
+ address: viem_1.zeroAddress,
266
+ amount: 1n,
267
+ };
268
+ const isSameChain = (settlementLayers?.length === 1 && settlementLayers[0] === 'SAME_CHAIN') ||
269
+ (sourceChains &&
270
+ sourceChains.length === 1 &&
271
+ sourceChains[0].id === targetChain.id);
272
+ const tokenRequests = !initialTokenRequests || initialTokenRequests.length === 0
273
+ ? isSameChain
274
+ ? []
275
+ : [defaultTokenRequest]
276
+ : initialTokenRequests;
277
+ return tokenRequests;
278
+ }
279
+ async function prepareTransactionAsUserOp(config, chain, callInputs, signers, gasLimit) {
280
+ const publicClient = (0, viem_1.createPublicClient)({
281
+ chain,
282
+ transport: (0, utils_1.createTransport)(chain, config.provider),
283
+ });
284
+ const validatorAccount = await getValidatorAccount(config, signers, publicClient, chain);
285
+ if (!validatorAccount) {
286
+ throw new Error('No validator account found');
287
+ }
288
+ const bundlerClient = (0, utils_1.getBundlerClient)(config, publicClient);
289
+ const calls = parseCalls(callInputs, chain.id);
290
+ const userOp = await bundlerClient.prepareUserOperation({
291
+ account: validatorAccount,
292
+ calls,
293
+ callGasLimit: gasLimit,
294
+ });
295
+ return {
296
+ userOp,
297
+ hash: (0, account_abstraction_1.getUserOperationHash)({
298
+ userOperation: userOp,
299
+ chainId: chain.id,
300
+ entryPointAddress: account_abstraction_1.entryPoint07Address,
301
+ entryPointVersion: '0.7',
302
+ }),
303
+ };
304
+ }
305
+ function getAccountType(accountConfig) {
306
+ if (accountConfig?.type === 'eoa') {
307
+ return 'EOA';
308
+ }
309
+ else {
310
+ return 'ERC7579';
311
+ }
312
+ }
313
+ function getIntentAccount(config, eip7702InitSignature, account) {
314
+ const accountAddress = (0, accounts_1.getAddress)(config);
315
+ const accountType = getAccountType(config.account);
316
+ const { setupOps, delegations } = getSetupOperationsAndDelegations(config, accountAddress, eip7702InitSignature);
317
+ return {
318
+ address: accountAddress,
319
+ accountType: accountType,
320
+ setupOps: account?.setupOps ?? setupOps,
321
+ delegations,
322
+ };
323
+ }
324
+ async function prepareTransactionAsIntent(config, sourceChains, targetChain, callInputs, gasLimit, tokenRequests, recipientInput, sponsored, eip7702InitSignature, settlementLayers, sourceAssets, feeAsset, lockFunds, account) {
325
+ if (config.account?.type === 'eoa') {
326
+ if (callInputs.length > 0) {
327
+ throw new error_1.CallsNotSupportedError();
328
+ }
329
+ }
330
+ const calls = parseCalls(callInputs, targetChain.id);
331
+ const accountAccessList = createAccountAccessList(sourceChains, sourceAssets);
332
+ function getRecipient(recipient) {
333
+ if (typeof recipient === 'string') {
334
+ // Passed as an address, assume it's an EOA
335
+ return {
336
+ address: recipient,
337
+ accountType: 'EOA',
338
+ setupOps: [],
339
+ delegations: undefined,
340
+ };
341
+ }
342
+ if (!recipient) {
343
+ return undefined;
344
+ }
345
+ return getIntentAccount(recipient, eip7702InitSignature, account);
346
+ }
347
+ const intentAccount = getIntentAccount(config, eip7702InitSignature, account);
348
+ const recipient = getRecipient(recipientInput);
349
+ const metaIntent = {
350
+ destinationChainId: targetChain.id,
351
+ tokenRequests: tokenRequests.map((tokenRequest) => ({
352
+ tokenAddress: (0, registry_1.resolveTokenAddress)(tokenRequest.address, targetChain.id),
353
+ amount: tokenRequest.amount,
354
+ })),
355
+ recipient,
356
+ account: intentAccount,
357
+ destinationExecutions: calls.map((call) => ({
358
+ to: call.to,
359
+ value: call.value.toString(),
360
+ data: call.data,
361
+ })),
362
+ destinationGasUnits: gasLimit,
363
+ accountAccessList,
364
+ options: {
365
+ topupCompact: lockFunds ?? false,
366
+ feeToken: feeAsset,
367
+ sponsorSettings: sponsored
368
+ ? typeof sponsored === 'object'
369
+ ? {
370
+ gasSponsored: sponsored.gas,
371
+ bridgeFeesSponsored: sponsored.bridging,
372
+ swapFeesSponsored: sponsored.swaps,
373
+ }
374
+ : {
375
+ gasSponsored: sponsored,
376
+ bridgeFeesSponsored: sponsored,
377
+ swapFeesSponsored: sponsored,
378
+ }
379
+ : undefined,
380
+ settlementLayers,
381
+ },
382
+ };
383
+ const orchestrator = getOrchestratorByChain(targetChain.id, config.apiKey, config.endpointUrl);
384
+ const intentRoute = await orchestrator.getIntentRoute(metaIntent);
385
+ return intentRoute;
386
+ }
387
+ async function signIntent(config, intentOp, signers) {
388
+ const { origin } = getIntentMessages(config, intentOp);
389
+ if (config.account?.type === 'eoa') {
390
+ const eoa = config.eoa;
391
+ if (!eoa) {
392
+ throw new accounts_1.EoaAccountMustHaveAccountError();
393
+ }
394
+ const originSignatures = [];
395
+ for (const typedData of origin) {
396
+ if (eoa.signTypedData) {
397
+ const signature = await eoa.signTypedData(typedData);
398
+ originSignatures.push(signature);
399
+ }
400
+ else {
401
+ throw new accounts_1.EoaSigningMethodNotConfiguredError('signTypedData');
402
+ }
403
+ }
404
+ const destinationSignature = originSignatures.at(-1);
405
+ return {
406
+ originSignatures,
407
+ destinationSignature,
408
+ };
409
+ }
410
+ const validator = getValidator(config, signers);
411
+ if (!validator) {
412
+ throw new Error('Validator not available');
413
+ }
414
+ const ownerValidator = (0, validators_1.getOwnerValidator)(config);
415
+ const isRoot = validator.address === ownerValidator.address;
416
+ const originSignatures = [];
417
+ for (const typedData of origin) {
418
+ const chain = (0, registry_1.getChainById)(typedData.domain?.chainId);
419
+ const signature = await signIntentTypedData(config, signers, validator, isRoot, typedData, chain);
420
+ originSignatures.push(signature);
421
+ }
422
+ const destinationSignature = originSignatures.at(-1);
423
+ return {
424
+ originSignatures,
425
+ destinationSignature,
426
+ };
427
+ }
428
+ function getIntentMessages(config, intentOp) {
429
+ const address = (0, accounts_1.getAddress)(config);
430
+ const intentExecutor = (0, modules_1.getIntentExecutor)(config);
431
+ const withPermit2 = intentOp.elements.some((element) => element.mandate.qualifier.settlementContext.fundingMethod === 'PERMIT2');
432
+ const withIntentExecutorOps = intentOp.elements.some((element) => element.mandate.qualifier.settlementContext.settlementLayer ===
433
+ 'INTENT_EXECUTOR');
434
+ const origin = [];
435
+ for (const element of intentOp.elements) {
436
+ if (withIntentExecutorOps) {
437
+ const typedData = (0, singleChainOps_1.getTypedData)(address, intentExecutor.address, element, BigInt(intentOp.nonce));
438
+ origin.push(typedData);
439
+ }
440
+ else if (withPermit2) {
441
+ const typedData = (0, permit2_1.getTypedData)(element, BigInt(intentOp.nonce), BigInt(intentOp.expires));
442
+ origin.push(typedData);
443
+ }
444
+ else {
445
+ const typedData = (0, compact_1.getCompactTypedData)(intentOp);
446
+ origin.push(typedData);
447
+ }
448
+ }
449
+ const destination = origin.at(-1);
450
+ return {
451
+ origin,
452
+ destination,
453
+ };
454
+ }
455
+ async function signIntentTypedData(config, signers, validator, isRoot, parameters, chain) {
456
+ if ((0, core_1.supportsEip712)(validator)) {
457
+ return await (0, accounts_1.getTypedDataPackedSignature)(config, signers, chain, {
458
+ address: validator.address,
459
+ isRoot,
460
+ }, parameters);
461
+ }
462
+ const hash = (0, viem_1.hashTypedData)(parameters);
463
+ return await (0, accounts_1.getPackedSignature)(config, signers, chain, {
464
+ address: validator.address,
465
+ isRoot,
466
+ }, hash);
467
+ }
468
+ async function signUserOp(config, chain, signers, userOp) {
469
+ const validator = getValidator(config, signers);
470
+ if (!validator) {
471
+ throw new Error('Validator not available');
472
+ }
473
+ const publicClient = (0, viem_1.createPublicClient)({
474
+ chain,
475
+ transport: (0, utils_1.createTransport)(chain, config.provider),
476
+ });
477
+ const account = await getValidatorAccount(config, signers, publicClient, chain);
478
+ if (!account) {
479
+ throw new Error('No account found');
480
+ }
481
+ return await account.signUserOperation(userOp);
482
+ }
483
+ async function submitUserOp(config, chain, userOp, signature) {
484
+ const publicClient = (0, viem_1.createPublicClient)({
485
+ chain,
486
+ transport: (0, utils_1.createTransport)(chain, config.provider),
487
+ });
488
+ const bundlerClient = (0, utils_1.getBundlerClient)(config, publicClient);
489
+ const hash = await bundlerClient.request({
490
+ method: 'eth_sendUserOperation',
491
+ params: [
492
+ {
493
+ sender: userOp.sender,
494
+ nonce: (0, viem_1.toHex)(userOp.nonce),
495
+ factory: userOp.factory,
496
+ factoryData: userOp.factoryData,
497
+ callData: userOp.callData,
498
+ callGasLimit: (0, viem_1.toHex)(userOp.callGasLimit),
499
+ verificationGasLimit: (0, viem_1.toHex)(userOp.verificationGasLimit),
500
+ preVerificationGas: (0, viem_1.toHex)(userOp.preVerificationGas),
501
+ maxPriorityFeePerGas: (0, viem_1.toHex)(userOp.maxPriorityFeePerGas),
502
+ maxFeePerGas: (0, viem_1.toHex)(userOp.maxFeePerGas),
503
+ paymaster: userOp.paymaster,
504
+ paymasterVerificationGasLimit: userOp.paymasterVerificationGasLimit
505
+ ? (0, viem_1.toHex)(userOp.paymasterVerificationGasLimit)
506
+ : undefined,
507
+ paymasterPostOpGasLimit: userOp.paymasterPostOpGasLimit
508
+ ? (0, viem_1.toHex)(userOp.paymasterPostOpGasLimit)
509
+ : undefined,
510
+ paymasterData: userOp.paymasterData,
511
+ signature,
512
+ },
513
+ account_abstraction_1.entryPoint07Address,
514
+ ],
515
+ });
516
+ return {
517
+ type: 'userop',
518
+ hash,
519
+ chain: chain.id,
520
+ };
521
+ }
522
+ async function submitIntent(config, sourceChains, targetChain, intentOp, originSignatures, destinationSignature, authorizations, dryRun) {
523
+ return submitIntentInternal(config, sourceChains, targetChain, intentOp, originSignatures, destinationSignature, authorizations, dryRun);
524
+ }
525
+ function getOrchestratorByChain(chainId, apiKey, orchestratorUrl) {
526
+ if (orchestratorUrl) {
527
+ return (0, orchestrator_1.getOrchestrator)(apiKey, orchestratorUrl);
528
+ }
529
+ const defaultOrchestratorUrl = (0, registry_1.isTestnet)(chainId)
530
+ ? consts_1.STAGING_ORCHESTRATOR_URL
531
+ : consts_1.PROD_ORCHESTRATOR_URL;
532
+ return (0, orchestrator_1.getOrchestrator)(apiKey, defaultOrchestratorUrl);
533
+ }
534
+ function createSignedIntentOp(intentOp, originSignatures, destinationSignature, authorizations) {
535
+ return {
536
+ ...intentOp,
537
+ originSignatures,
538
+ destinationSignature,
539
+ signedAuthorizations: authorizations.length > 0
540
+ ? authorizations.map((authorization) => ({
541
+ chainId: authorization.chainId,
542
+ address: authorization.address,
543
+ nonce: authorization.nonce,
544
+ yParity: authorization.yParity ?? 0,
545
+ r: authorization.r,
546
+ s: authorization.s,
547
+ }))
548
+ : undefined,
549
+ };
550
+ }
551
+ async function submitIntentInternal(config, sourceChains, targetChain, intentOp, originSignatures, destinationSignature, authorizations, dryRun) {
552
+ const signedIntentOp = createSignedIntentOp(intentOp, originSignatures, destinationSignature, authorizations);
553
+ const orchestrator = getOrchestratorByChain(targetChain.id, config.apiKey, config.endpointUrl);
554
+ const intentResults = await orchestrator.submitIntent(signedIntentOp, dryRun);
555
+ return {
556
+ type: 'intent',
557
+ id: BigInt(intentResults.result.id),
558
+ sourceChains: sourceChains?.map((chain) => chain.id),
559
+ targetChain: targetChain.id,
560
+ };
561
+ }
562
+ async function getValidatorAccount(config, signers, publicClient, chain) {
563
+ if (!signers) {
564
+ return (0, accounts_1.getSmartAccount)(config, publicClient, chain);
565
+ }
566
+ // Owners
567
+ const withOwner = signers.type === 'owner' ? signers : null;
568
+ if (withOwner) {
569
+ return (0, accounts_1.getSmartAccount)(config, publicClient, chain);
570
+ }
571
+ const withSession = signers.type === 'session' ? signers : null;
572
+ const withGuardians = signers.type === 'guardians' ? signers : null;
573
+ return withSession
574
+ ? await (0, accounts_1.getSmartSessionSmartAccount)(config, publicClient, chain, withSession.session, withSession.enableData || null)
575
+ : withGuardians
576
+ ? await (0, accounts_1.getGuardianSmartAccount)(config, publicClient, chain, {
577
+ type: 'ecdsa',
578
+ accounts: withGuardians.guardians,
579
+ })
580
+ : null;
581
+ }
582
+ function getValidator(config, signers) {
583
+ if (!signers) {
584
+ return (0, validators_1.getOwnerValidator)(config);
585
+ }
586
+ // Owners
587
+ const withOwner = signers.type === 'owner' ? signers : null;
588
+ if (withOwner) {
589
+ // ECDSA
590
+ if (withOwner.kind === 'ecdsa') {
591
+ // Use the configured owner validator (e.g., ENS) rather than forcing Ownable
592
+ return (0, validators_1.getOwnerValidator)(config);
593
+ }
594
+ // Passkeys (WebAuthn)
595
+ if (withOwner.kind === 'passkey') {
596
+ return (0, core_1.getWebAuthnValidator)(1, withOwner.accounts.map((account) => ({
597
+ pubKey: account.publicKey,
598
+ authenticatorId: account.id,
599
+ })));
600
+ }
601
+ // Multi-factor
602
+ if (withOwner.kind === 'multi-factor') {
603
+ return (0, core_1.getMultiFactorValidator)(1, withOwner.validators);
604
+ }
605
+ }
606
+ // Smart sessions
607
+ const withSession = signers.type === 'session' ? signers.session : null;
608
+ if (withSession) {
609
+ return (0, validators_1.getSmartSessionValidator)(config);
610
+ }
611
+ // Guardians (social recovery)
612
+ const withGuardians = signers.type === 'guardians' ? signers : null;
613
+ if (withGuardians) {
614
+ return (0, core_1.getSocialRecoveryValidator)(withGuardians.guardians);
615
+ }
616
+ // Fallback
617
+ return undefined;
618
+ }
619
+ function parseCalls(calls, chainId) {
620
+ return calls.map((call) => ({
621
+ data: call.data ?? '0x',
622
+ value: call.value ?? 0n,
623
+ to: (0, registry_1.resolveTokenAddress)(call.to, chainId),
624
+ }));
625
+ }
626
+ function createAccountAccessList(sourceChains, sourceAssets) {
627
+ if (!sourceChains && !sourceAssets)
628
+ return undefined;
629
+ const chainIds = sourceChains?.map((chain) => chain.id);
630
+ if (!sourceAssets) {
631
+ return { chainIds };
632
+ }
633
+ if (Array.isArray(sourceAssets)) {
634
+ return chainIds
635
+ ? { chainIds, tokens: sourceAssets }
636
+ : { tokens: sourceAssets };
637
+ }
638
+ return { chainTokens: sourceAssets };
639
+ }
640
+ function getSetupOperationsAndDelegations(config, accountAddress, eip7702InitSignature) {
641
+ const initCode = (0, accounts_1.getInitCode)(config);
642
+ if (config.account?.type === 'eoa') {
643
+ return {
644
+ setupOps: [],
645
+ };
646
+ }
647
+ else if ((0, accounts_1.is7702)(config)) {
648
+ // EIP-7702 initialization is only needed for EOA accounts
649
+ if (!eip7702InitSignature || eip7702InitSignature === '0x') {
650
+ throw new Error('EIP-7702 initialization signature is required for EOA accounts');
651
+ }
652
+ const { initData: eip7702InitData, contract: eip7702Contract } = (0, accounts_1.getEip7702InitCall)(config, eip7702InitSignature);
653
+ return {
654
+ setupOps: [
655
+ {
656
+ to: accountAddress,
657
+ data: eip7702InitData,
658
+ },
659
+ ],
660
+ delegations: {
661
+ 0: {
662
+ contract: eip7702Contract,
663
+ },
664
+ },
665
+ };
666
+ }
667
+ else if (initCode) {
668
+ const to = 'factory' in initCode ? initCode.factory : undefined;
669
+ const data = 'factory' in initCode ? initCode.factoryData : undefined;
670
+ if (!to || !data) {
671
+ throw new accounts_1.FactoryArgsNotAvailableError();
672
+ }
673
+ // Contract account with init code
674
+ return {
675
+ setupOps: [
676
+ {
677
+ to,
678
+ data,
679
+ },
680
+ ],
681
+ };
682
+ }
683
+ else {
684
+ // Already deployed contract account
685
+ return {
686
+ setupOps: [],
687
+ };
688
+ }
689
+ }
690
+ function validateTokenSymbols(chain, tokenAddressOrSymbols) {
691
+ function validateTokenSymbol(chain, addressOrSymbol) {
692
+ // Address
693
+ if ((0, viem_1.isAddress)(addressOrSymbol, { strict: false })) {
694
+ return true;
695
+ }
696
+ // Token symbol
697
+ const address = (0, registry_1.getTokenAddress)(addressOrSymbol, chain.id);
698
+ return (0, viem_1.isAddress)(address, { strict: false });
699
+ }
700
+ for (const addressOrSymbol of tokenAddressOrSymbols) {
701
+ if (!validateTokenSymbol(chain, addressOrSymbol)) {
702
+ throw new Error(`Invalid token symbol: ${addressOrSymbol}`);
703
+ }
704
+ }
705
+ }