@rhinestone/sdk 1.5.1 → 2.0.0-beta.1
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.
- package/README.md +1 -1
- package/dist/src/accounts/error.d.ts +1 -1
- package/dist/src/accounts/error.js +1 -19
- package/dist/src/accounts/index.d.ts +5 -5
- package/dist/src/accounts/index.js +121 -157
- package/dist/src/accounts/json-rpc/index.d.ts +1 -1
- package/dist/src/accounts/json-rpc/index.js +8 -10
- package/dist/src/accounts/json-rpc/providers.d.ts +1 -1
- package/dist/src/accounts/json-rpc/providers.d.ts.map +1 -1
- package/dist/src/accounts/json-rpc/providers.js +7 -9
- package/dist/src/accounts/kernel.d.ts +3 -3
- package/dist/src/accounts/kernel.js +66 -75
- package/dist/src/accounts/nexus.d.ts +3 -3
- package/dist/src/accounts/nexus.js +62 -73
- package/dist/src/accounts/passport.d.ts +3 -3
- package/dist/src/accounts/passport.js +9 -13
- package/dist/src/accounts/safe.d.ts +3 -3
- package/dist/src/accounts/safe.js +54 -63
- package/dist/src/accounts/signing/common.d.ts +2 -2
- package/dist/src/accounts/signing/common.js +30 -36
- package/dist/src/accounts/signing/message.d.ts +2 -2
- package/dist/src/accounts/signing/message.js +10 -12
- package/dist/src/accounts/signing/passkeys.js +11 -17
- package/dist/src/accounts/signing/typedData.d.ts +1 -1
- package/dist/src/accounts/signing/typedData.js +6 -8
- package/dist/src/accounts/startale.d.ts +3 -3
- package/dist/src/accounts/startale.js +37 -47
- package/dist/src/accounts/utils.d.ts +2 -2
- package/dist/src/accounts/utils.js +22 -28
- package/dist/src/accounts/walletClient.js +4 -8
- package/dist/src/actions/compact.d.ts +1 -1
- package/dist/src/actions/compact.js +22 -35
- package/dist/src/actions/deployment.d.ts +1 -1
- package/dist/src/actions/deployment.js +11 -13
- package/dist/src/actions/ecdsa.d.ts +1 -1
- package/dist/src/actions/ecdsa.js +14 -20
- package/dist/src/actions/index.d.ts +2 -2
- package/dist/src/actions/index.js +6 -10
- package/dist/src/actions/mfa.d.ts +1 -1
- package/dist/src/actions/mfa.js +18 -24
- package/dist/src/actions/passkeys.d.ts +2 -2
- package/dist/src/actions/passkeys.js +14 -20
- package/dist/src/actions/recovery.d.ts +1 -1
- package/dist/src/actions/recovery.js +25 -29
- package/dist/src/actions/smart-sessions.d.ts +1 -1
- package/dist/src/actions/smart-sessions.js +8 -12
- package/dist/src/auth/provider.d.ts +1 -1
- package/dist/src/auth/provider.js +1 -4
- package/dist/src/errors/index.d.ts +4 -4
- package/dist/src/errors/index.d.ts.map +1 -1
- package/dist/src/errors/index.js +12 -54
- package/dist/src/execution/compact.d.ts +1 -144
- package/dist/src/execution/compact.d.ts.map +1 -1
- package/dist/src/execution/compact.js +1 -117
- package/dist/src/execution/error.d.ts +10 -1
- package/dist/src/execution/error.d.ts.map +1 -1
- package/dist/src/execution/error.js +9 -11
- package/dist/src/execution/index.d.ts +10 -11
- package/dist/src/execution/index.d.ts.map +1 -1
- package/dist/src/execution/index.js +64 -75
- package/dist/src/execution/permit2.d.ts +2 -138
- package/dist/src/execution/permit2.d.ts.map +1 -1
- package/dist/src/execution/permit2.js +5 -239
- package/dist/src/execution/utils.d.ts +31 -15
- package/dist/src/execution/utils.d.ts.map +1 -1
- package/dist/src/execution/utils.js +283 -256
- package/dist/src/index.d.ts +15 -14
- package/dist/src/index.d.ts.map +1 -1
- package/dist/src/index.js +57 -68
- package/dist/src/jwt-server/digest.js +3 -6
- package/dist/src/jwt-server/express.d.ts +1 -1
- package/dist/src/jwt-server/express.d.ts.map +1 -1
- package/dist/src/jwt-server/express.js +6 -7
- package/dist/src/jwt-server/handlers.d.ts +1 -1
- package/dist/src/jwt-server/handlers.js +7 -11
- package/dist/src/jwt-server/index.d.ts +7 -7
- package/dist/src/jwt-server/index.js +6 -17
- package/dist/src/jwt-server/jcs.js +1 -4
- package/dist/src/jwt-server/signer.d.ts +1 -1
- package/dist/src/jwt-server/signer.js +10 -13
- package/dist/src/jwt-server/sponsorship.js +2 -7
- package/dist/src/jwt-server/web.d.ts +1 -1
- package/dist/src/jwt-server/web.js +5 -9
- package/dist/src/modules/abi/smart-session-emissary.js +1 -3
- package/dist/src/modules/abi/smart-sessions.js +1 -4
- package/dist/src/modules/chain-abstraction.js +1 -5
- package/dist/src/modules/common.d.ts +1 -1
- package/dist/src/modules/common.js +1 -13
- package/dist/src/modules/index.d.ts +5 -5
- package/dist/src/modules/index.js +35 -50
- package/dist/src/modules/legacy.d.ts +2 -2
- package/dist/src/modules/legacy.js +11 -14
- package/dist/src/modules/read.d.ts +1 -1
- package/dist/src/modules/read.js +11 -15
- package/dist/src/modules/validators/core.d.ts +2 -2
- package/dist/src/modules/validators/core.js +26 -44
- package/dist/src/modules/validators/index.d.ts +2 -2
- package/dist/src/modules/validators/index.js +3 -19
- package/dist/src/modules/validators/policies/claim/permit2.d.ts +1 -1
- package/dist/src/modules/validators/policies/claim/permit2.js +39 -44
- package/dist/src/modules/validators/policies/claim/types.js +11 -14
- package/dist/src/modules/validators/smart-sessions.d.ts +3 -3
- package/dist/src/modules/validators/smart-sessions.js +65 -94
- package/dist/src/orchestrator/caip2.d.ts +7 -0
- package/dist/src/orchestrator/caip2.d.ts.map +1 -0
- package/dist/src/orchestrator/caip2.js +17 -0
- package/dist/src/orchestrator/client.d.ts +12 -12
- package/dist/src/orchestrator/client.d.ts.map +1 -1
- package/dist/src/orchestrator/client.js +199 -305
- package/dist/src/orchestrator/consts.d.ts +2 -2
- package/dist/src/orchestrator/consts.d.ts.map +1 -1
- package/dist/src/orchestrator/consts.js +3 -9
- package/dist/src/orchestrator/error.d.ts +72 -217
- package/dist/src/orchestrator/error.d.ts.map +1 -1
- package/dist/src/orchestrator/error.js +117 -227
- package/dist/src/orchestrator/index.d.ts +9 -9
- package/dist/src/orchestrator/index.d.ts.map +1 -1
- package/dist/src/orchestrator/index.js +7 -56
- package/dist/src/orchestrator/registry.d.ts +2 -2
- package/dist/src/orchestrator/registry.js +19 -33
- package/dist/src/orchestrator/types.d.ts +97 -232
- package/dist/src/orchestrator/types.d.ts.map +1 -1
- package/dist/src/orchestrator/types.js +1 -17
- package/dist/src/orchestrator/utils.js +1 -3
- package/dist/src/types.d.ts +5 -7
- package/dist/src/types.d.ts.map +1 -1
- package/dist/src/types.js +1 -2
- package/dist/src/utils/index.d.ts +2 -2
- package/dist/src/utils/index.js +9 -15
- package/package.json +15 -98
- package/dist/src/execution/singleChainOps.d.ts +0 -41
- package/dist/src/execution/singleChainOps.d.ts.map +0 -1
- package/dist/src/execution/singleChainOps.js +0 -44
- package/dist/src/execution/types.d.ts +0 -36
- package/dist/src/execution/types.d.ts.map +0 -1
- package/dist/src/execution/types.js +0 -2
|
@@ -1,47 +1,19 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
exports.getValidatorAccount = getValidatorAccount;
|
|
18
|
-
exports.parseCalls = parseCalls;
|
|
19
|
-
exports.getTokenRequests = getTokenRequests;
|
|
20
|
-
exports.resolveCallInputs = resolveCallInputs;
|
|
21
|
-
exports.getIntentAccount = getIntentAccount;
|
|
22
|
-
exports.getTargetExecutionSignature = getTargetExecutionSignature;
|
|
23
|
-
exports.hashErc7739TypedDataForSolady = hashErc7739TypedDataForSolady;
|
|
24
|
-
exports.resolveSessionForChain = resolveSessionForChain;
|
|
25
|
-
const viem_1 = require("viem");
|
|
26
|
-
const account_abstraction_1 = require("viem/account-abstraction");
|
|
27
|
-
const erc7739_1 = require("viem/experimental/erc7739");
|
|
28
|
-
const accounts_1 = require("../accounts");
|
|
29
|
-
const common_1 = require("../accounts/signing/common");
|
|
30
|
-
const startale_1 = require("../accounts/startale");
|
|
31
|
-
const utils_1 = require("../accounts/utils");
|
|
32
|
-
const provider_1 = require("../auth/provider");
|
|
33
|
-
const modules_1 = require("../modules");
|
|
34
|
-
const validators_1 = require("../modules/validators");
|
|
35
|
-
const core_1 = require("../modules/validators/core");
|
|
36
|
-
const permit2_1 = require("../modules/validators/policies/claim/permit2");
|
|
37
|
-
const orchestrator_1 = require("../orchestrator");
|
|
38
|
-
const registry_1 = require("../orchestrator/registry");
|
|
39
|
-
const types_1 = require("../orchestrator/types");
|
|
40
|
-
const utils_2 = require("../orchestrator/utils");
|
|
41
|
-
const compact_1 = require("./compact");
|
|
42
|
-
const error_1 = require("./error");
|
|
43
|
-
const permit2_2 = require("./permit2");
|
|
44
|
-
const singleChainOps_1 = require("./singleChainOps");
|
|
1
|
+
import { concat, createPublicClient, createWalletClient, encodeAbiParameters, encodePacked, hashDomain, hashMessage, hashStruct, hashTypedData, isAddress, keccak256, publicActions, toHex, } from 'viem';
|
|
2
|
+
import { entryPoint07Address, getUserOperationHash, } from 'viem/account-abstraction';
|
|
3
|
+
import { wrapTypedDataSignature } from 'viem/experimental/erc7739';
|
|
4
|
+
import { EoaAccountMustHaveAccountError, EoaSigningMethodNotConfiguredError, FactoryArgsNotAvailableError, getAccountProvider, getAddress, getEip712Domain, getEip1271Signature, getEip7702InitCall, getEmissarySignature, getGuardianSmartAccount, getInitCode, getSmartAccount, getTypedDataPackedSignature, is7702, toErc6492Signature, } from '../accounts/index.js';
|
|
5
|
+
import { convertOwnerSetToSignerSet } from '../accounts/signing/common.js';
|
|
6
|
+
import { K1_DEFAULT_VALIDATOR_ADDRESS } from '../accounts/startale.js';
|
|
7
|
+
import { createTransport, getBundlerClient, } from '../accounts/utils.js';
|
|
8
|
+
import { createAuthProvider } from '../auth/provider.js';
|
|
9
|
+
import { buildMockSignature, DUMMY_PRECLAIMOP_SELECTOR, DUMMY_PRECLAIMOP_TARGET, getOwnerValidator, getPermissionId, getSmartSessionValidator, isSessionEnabled, } from '../modules/validators/index.js';
|
|
10
|
+
import { getMultiFactorValidator, getSocialRecoveryValidator, getWebAuthnValidator, supportsEip712, } from '../modules/validators/core.js';
|
|
11
|
+
import { buildPermit2ClaimPolicyCalldata } from '../modules/validators/policies/claim/permit2.js';
|
|
12
|
+
import { getOrchestrator, } from '../orchestrator/index.js';
|
|
13
|
+
import { getChainById, getTokenAddress, resolveTokenAddress, } from '../orchestrator/registry.js';
|
|
14
|
+
import { SIG_MODE_EMISSARY_EXECUTION_ERC1271, SIG_MODE_ERC1271_EMISSARY, } from '../orchestrator/types.js';
|
|
15
|
+
import { convertBigIntFields } from '../orchestrator/utils.js';
|
|
16
|
+
import { Eip7702InitSignatureRequiredError, QuoteNotInPreparedTransactionError, SignerNotSupportedError, } from './error.js';
|
|
45
17
|
function isResolvedSessionSignerSet(signers) {
|
|
46
18
|
return (signers?.type === 'experimental_session' && 'verifyExecutions' in signers);
|
|
47
19
|
}
|
|
@@ -50,7 +22,7 @@ async function resolveSignersForChain(config, signers, chainId) {
|
|
|
50
22
|
return signers;
|
|
51
23
|
}
|
|
52
24
|
const resolved = resolveSessionForChain(signers, chainId);
|
|
53
|
-
const enabled = await
|
|
25
|
+
const enabled = await isSessionEnabled(getAddress(config), config.provider, resolved.session, config.useDevContracts);
|
|
54
26
|
const enableData = enabled ? undefined : resolved.enableData;
|
|
55
27
|
const hasExplicitActions = !!resolved.session.actions?.length;
|
|
56
28
|
const verifyExecutions = resolved.verifyExecutions ?? signers.verifyExecutions ?? hasExplicitActions;
|
|
@@ -72,15 +44,15 @@ function resolveSessionForChain(signers, chainId) {
|
|
|
72
44
|
return { session: signers.session, enableData: signers.enableData };
|
|
73
45
|
}
|
|
74
46
|
async function prepareTransaction(config, transaction) {
|
|
75
|
-
const { sourceChains, targetChain, tokenRequests, signers, sponsored, eip7702InitSignature, settlementLayers, sourceAssets, feeAsset,
|
|
76
|
-
const accountAddress =
|
|
47
|
+
const { sourceChains, targetChain, tokenRequests, signers, sponsored, eip7702InitSignature, settlementLayers, sourceAssets, feeAsset, auxiliaryFunds, account, recipient, } = getTransactionParams(transaction);
|
|
48
|
+
const accountAddress = getAddress(config);
|
|
77
49
|
const isUserOpSigner = signers?.type === 'guardians';
|
|
78
50
|
if (isUserOpSigner) {
|
|
79
|
-
throw new
|
|
51
|
+
throw new SignerNotSupportedError();
|
|
80
52
|
}
|
|
81
|
-
const prepared = await prepareTransactionAsIntent(config, sourceChains, targetChain, await resolveCallInputs(transaction.calls, config, targetChain, accountAddress), transaction.gasLimit, tokenRequests, recipient, sponsored, eip7702InitSignature, settlementLayers, sourceAssets, feeAsset,
|
|
53
|
+
const prepared = await prepareTransactionAsIntent(config, sourceChains, targetChain, await resolveCallInputs(transaction.calls, config, targetChain, accountAddress), transaction.gasLimit, tokenRequests, recipient, sponsored, eip7702InitSignature, settlementLayers, sourceAssets, feeAsset, auxiliaryFunds, account, signers);
|
|
82
54
|
return {
|
|
83
|
-
|
|
55
|
+
quotes: prepared.quotes,
|
|
84
56
|
intentInput: prepared.intentInput,
|
|
85
57
|
transaction,
|
|
86
58
|
};
|
|
@@ -88,7 +60,7 @@ async function prepareTransaction(config, transaction) {
|
|
|
88
60
|
async function prepareUserOperation(config, transaction) {
|
|
89
61
|
const chain = transaction.chain;
|
|
90
62
|
const signers = transaction.signers;
|
|
91
|
-
const accountAddress =
|
|
63
|
+
const accountAddress = getAddress(config);
|
|
92
64
|
const data = await prepareTransactionAsUserOp(config, chain, await resolveCallInputs(transaction.calls, config, chain, accountAddress), signers, transaction.gasLimit);
|
|
93
65
|
return {
|
|
94
66
|
userOperation: data.userOp,
|
|
@@ -117,19 +89,21 @@ async function resolveCallInputs(inputs, config, chain, accountAddress) {
|
|
|
117
89
|
}
|
|
118
90
|
return resolved;
|
|
119
91
|
}
|
|
120
|
-
function getTransactionMessages(
|
|
121
|
-
|
|
92
|
+
function getTransactionMessages(_config, preparedTransaction, options) {
|
|
93
|
+
const quote = resolveQuote(preparedTransaction.quotes, options);
|
|
94
|
+
return getIntentMessages(quote.signData);
|
|
122
95
|
}
|
|
123
|
-
async function signTransaction(config, preparedTransaction) {
|
|
96
|
+
async function signTransaction(config, preparedTransaction, options) {
|
|
124
97
|
const { signers } = getTransactionParams(preparedTransaction.transaction);
|
|
125
|
-
const
|
|
98
|
+
const quote = resolveQuote(preparedTransaction.quotes, options);
|
|
126
99
|
const targetChain = 'targetChain' in preparedTransaction.transaction
|
|
127
100
|
? preparedTransaction.transaction.targetChain
|
|
128
101
|
: preparedTransaction.transaction.chain;
|
|
129
|
-
const { originSignatures, destinationSignature } = await signIntent(config,
|
|
130
|
-
const targetExecutionSignature = await getTargetExecutionSignature(config,
|
|
102
|
+
const { originSignatures, destinationSignature } = await signIntent(config, quote.signData, targetChain, signers, false);
|
|
103
|
+
const targetExecutionSignature = await getTargetExecutionSignature(config, quote.signData, targetChain, signers);
|
|
131
104
|
return {
|
|
132
|
-
|
|
105
|
+
quote,
|
|
106
|
+
quotes: preparedTransaction.quotes,
|
|
133
107
|
intentInput: preparedTransaction.intentInput,
|
|
134
108
|
transaction: preparedTransaction.transaction,
|
|
135
109
|
originSignatures,
|
|
@@ -137,13 +111,22 @@ async function signTransaction(config, preparedTransaction) {
|
|
|
137
111
|
targetExecutionSignature,
|
|
138
112
|
};
|
|
139
113
|
}
|
|
140
|
-
|
|
114
|
+
function resolveQuote(quotes, options) {
|
|
115
|
+
if (!options)
|
|
116
|
+
return quotes.best;
|
|
117
|
+
const match = quotes.all.find((q) => q.intentId === options.intentId);
|
|
118
|
+
if (!match) {
|
|
119
|
+
throw new QuoteNotInPreparedTransactionError({
|
|
120
|
+
context: { intentId: options.intentId },
|
|
121
|
+
});
|
|
122
|
+
}
|
|
123
|
+
return match;
|
|
124
|
+
}
|
|
125
|
+
async function getTargetExecutionSignature(config, signData, targetChain, signers) {
|
|
141
126
|
if (signers?.type !== 'experimental_session') {
|
|
142
127
|
return undefined;
|
|
143
128
|
}
|
|
144
|
-
|
|
145
|
-
const hasIntentExecutorOps = settlementLayers.some((l) => l === 'INTENT_EXECUTOR' || l === 'SAME_CHAIN');
|
|
146
|
-
if (!hasIntentExecutorOps) {
|
|
129
|
+
if (!signData.targetExecution) {
|
|
147
130
|
return undefined;
|
|
148
131
|
}
|
|
149
132
|
const resolvedSigners = await resolveSignersForChain(config, signers, targetChain.id);
|
|
@@ -151,13 +134,13 @@ async function getTargetExecutionSignature(config, intentOp, targetChain, signer
|
|
|
151
134
|
!resolvedSigners.verifyExecutions) {
|
|
152
135
|
return undefined;
|
|
153
136
|
}
|
|
154
|
-
const destination = getTargetExecutionMessage(config, intentOp);
|
|
155
137
|
const validator = getValidator(config, signers);
|
|
156
138
|
if (!validator) {
|
|
157
139
|
throw new Error('Validator not available');
|
|
158
140
|
}
|
|
159
|
-
const ownerValidator =
|
|
141
|
+
const ownerValidator = getOwnerValidator(config);
|
|
160
142
|
const isRoot = validator.address === ownerValidator.address;
|
|
143
|
+
const destination = prepareTypedData(signData.targetExecution);
|
|
161
144
|
const signature = await getDestinationSignature(config, resolvedSigners, validator, isRoot, targetChain, destination, [], true);
|
|
162
145
|
return signature;
|
|
163
146
|
}
|
|
@@ -175,28 +158,35 @@ async function signUserOperation(config, preparedUserOperation) {
|
|
|
175
158
|
};
|
|
176
159
|
}
|
|
177
160
|
async function signAuthorizations(config, preparedTransaction) {
|
|
178
|
-
|
|
161
|
+
const transaction = preparedTransaction.transaction;
|
|
162
|
+
const sourceChains = 'chain' in transaction ? [transaction.chain] : transaction.sourceChains;
|
|
163
|
+
const targetChain = 'chain' in transaction ? transaction.chain : transaction.targetChain;
|
|
164
|
+
return await signAuthorizationsInternal(config, {
|
|
165
|
+
sourceChains,
|
|
166
|
+
targetChain,
|
|
167
|
+
eip7702InitSignature: transaction.eip7702InitSignature,
|
|
168
|
+
});
|
|
179
169
|
}
|
|
180
170
|
async function signMessage(config, message, chain, signers) {
|
|
181
171
|
const validator = getValidator(config, signers);
|
|
182
172
|
if (!validator) {
|
|
183
173
|
throw new Error('Validator not available');
|
|
184
174
|
}
|
|
185
|
-
const ownerValidator =
|
|
175
|
+
const ownerValidator = getOwnerValidator(config);
|
|
186
176
|
const isRoot = validator.address === ownerValidator.address;
|
|
187
|
-
const hash =
|
|
188
|
-
const signature = await
|
|
177
|
+
const hash = hashMessage(message);
|
|
178
|
+
const signature = await getEip1271Signature(config, signers, chain, {
|
|
189
179
|
address: validator.address,
|
|
190
180
|
isRoot,
|
|
191
181
|
}, hash);
|
|
192
|
-
return await
|
|
182
|
+
return await toErc6492Signature(config, signature, chain);
|
|
193
183
|
}
|
|
194
184
|
async function signTypedData(config, parameters, chain, signers, options) {
|
|
195
185
|
const validator = getValidator(config, signers);
|
|
196
186
|
if (!validator) {
|
|
197
187
|
throw new Error('Validator not available');
|
|
198
188
|
}
|
|
199
|
-
const ownerValidator =
|
|
189
|
+
const ownerValidator = getOwnerValidator(config);
|
|
200
190
|
const isRoot = validator.address === ownerValidator.address;
|
|
201
191
|
if (signers?.type === 'experimental_session') {
|
|
202
192
|
const resolved = resolveSessionForChain(signers, chain.id);
|
|
@@ -205,31 +195,31 @@ async function signTypedData(config, parameters, chain, signers, options) {
|
|
|
205
195
|
isRoot,
|
|
206
196
|
}, resolved.session, parameters);
|
|
207
197
|
}
|
|
208
|
-
const account =
|
|
209
|
-
if (account.type === 'startale' &&
|
|
198
|
+
const account = getAccountProvider(config);
|
|
199
|
+
if (account.type === 'startale' && supportsEip712(validator)) {
|
|
210
200
|
const isK1 = validator.address.toLowerCase() ===
|
|
211
|
-
|
|
201
|
+
K1_DEFAULT_VALIDATOR_ADDRESS.toLowerCase();
|
|
212
202
|
if (isK1) {
|
|
213
203
|
const sig = await signErc7739TypedData(config, signers, validator, isRoot, parameters, chain);
|
|
214
204
|
if (!options?.skipErc6492) {
|
|
215
|
-
return await
|
|
205
|
+
return await toErc6492Signature(config, sig, chain);
|
|
216
206
|
}
|
|
217
207
|
return sig;
|
|
218
208
|
}
|
|
219
209
|
}
|
|
220
|
-
const signature = await
|
|
210
|
+
const signature = await getTypedDataPackedSignature(config, signers, chain, {
|
|
221
211
|
address: validator.address,
|
|
222
212
|
isRoot,
|
|
223
213
|
}, parameters);
|
|
224
214
|
if (!options?.skipErc6492) {
|
|
225
|
-
return await
|
|
215
|
+
return await toErc6492Signature(config, signature, chain);
|
|
226
216
|
}
|
|
227
217
|
return signature;
|
|
228
218
|
}
|
|
229
219
|
async function signTypedDataWithSession(config, chain, validator, session, parameters) {
|
|
230
|
-
const { name, version, chainId, verifyingContract, salt } =
|
|
231
|
-
const signers =
|
|
232
|
-
const signature = await
|
|
220
|
+
const { name, version, chainId, verifyingContract, salt } = getEip712Domain(config, chain);
|
|
221
|
+
const signers = convertOwnerSetToSignerSet(session.owners);
|
|
222
|
+
const signature = await getTypedDataPackedSignature(config, signers, chain, validator, {
|
|
233
223
|
domain: parameters.domain,
|
|
234
224
|
primaryType: 'TypedDataSign',
|
|
235
225
|
types: {
|
|
@@ -252,55 +242,58 @@ async function signTypedDataWithSession(config, chain, validator, session, param
|
|
|
252
242
|
salt,
|
|
253
243
|
},
|
|
254
244
|
}, (signature) => {
|
|
255
|
-
const erc7739Signature =
|
|
245
|
+
const erc7739Signature = wrapTypedDataSignature({
|
|
256
246
|
domain: parameters.domain,
|
|
257
247
|
primaryType: parameters.primaryType,
|
|
258
248
|
types: parameters.types,
|
|
259
249
|
message: parameters.message,
|
|
260
250
|
signature,
|
|
261
251
|
});
|
|
262
|
-
return
|
|
252
|
+
return encodePacked(['bytes32', 'bytes'], [getPermissionId(session), erc7739Signature]);
|
|
263
253
|
});
|
|
264
|
-
return await
|
|
254
|
+
return await toErc6492Signature(config, signature, chain);
|
|
265
255
|
}
|
|
266
|
-
async function signAuthorizationsInternal(config,
|
|
256
|
+
async function signAuthorizationsInternal(config, context) {
|
|
267
257
|
const eoa = config.eoa;
|
|
268
258
|
if (!eoa) {
|
|
269
259
|
throw new Error('EIP-7702 initialization is required for EOA accounts');
|
|
270
260
|
}
|
|
271
|
-
const
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
261
|
+
const eip7702InitSignature = context.eip7702InitSignature;
|
|
262
|
+
if (!eip7702InitSignature) {
|
|
263
|
+
return [];
|
|
264
|
+
}
|
|
265
|
+
const accountAddress = getAddress(config);
|
|
266
|
+
const { contract: eip7702Contract } = getEip7702InitCall(config, eip7702InitSignature);
|
|
267
|
+
const chains = new Map();
|
|
268
|
+
for (const chain of [...(context.sourceChains ?? []), context.targetChain]) {
|
|
269
|
+
chains.set(chain.id, chain);
|
|
270
|
+
}
|
|
275
271
|
const authorizations = [];
|
|
276
|
-
for (const
|
|
277
|
-
const
|
|
278
|
-
const chain = (0, registry_1.getChainById)(Number(chainId));
|
|
279
|
-
const walletClient = (0, viem_1.createWalletClient)({
|
|
272
|
+
for (const chain of chains.values()) {
|
|
273
|
+
const walletClient = createWalletClient({
|
|
280
274
|
chain,
|
|
281
275
|
account: eoa,
|
|
282
|
-
transport:
|
|
283
|
-
}).extend(
|
|
276
|
+
transport: createTransport(chain, config.provider),
|
|
277
|
+
}).extend(publicActions);
|
|
284
278
|
const code = await walletClient.getCode({
|
|
285
279
|
address: accountAddress,
|
|
286
280
|
});
|
|
287
|
-
const isDelegated = code ===
|
|
281
|
+
const isDelegated = code === concat(['0xef0100', eip7702Contract.toLowerCase()]);
|
|
288
282
|
if (isDelegated) {
|
|
289
283
|
continue;
|
|
290
284
|
}
|
|
291
285
|
const authorization = await walletClient.signAuthorization({
|
|
292
|
-
contractAddress:
|
|
293
|
-
chainId:
|
|
286
|
+
contractAddress: eip7702Contract,
|
|
287
|
+
chainId: chain.id,
|
|
294
288
|
});
|
|
295
289
|
authorizations.push(authorization);
|
|
296
290
|
}
|
|
297
291
|
return authorizations;
|
|
298
292
|
}
|
|
299
293
|
async function submitTransaction(config, signedTransaction, authorizations, dryRun = false) {
|
|
300
|
-
const {
|
|
294
|
+
const { quote, intentInput, transaction, originSignatures, destinationSignature, targetExecutionSignature, } = signedTransaction;
|
|
301
295
|
const { sourceChains, targetChain } = getTransactionParams(transaction);
|
|
302
|
-
|
|
303
|
-
return await submitIntent(config, sourceChains, targetChain, intentOp, originSignatures, destinationSignature, targetExecutionSignature, authorizations, dryRun, intentInput);
|
|
296
|
+
return await submitIntentInternal(config, sourceChains, targetChain, quote, originSignatures, destinationSignature, targetExecutionSignature, authorizations, dryRun, intentInput);
|
|
304
297
|
}
|
|
305
298
|
async function submitUserOperation(config, signedUserOperation) {
|
|
306
299
|
const chain = signedUserOperation.transaction.chain;
|
|
@@ -320,7 +313,6 @@ function getTransactionParams(transaction) {
|
|
|
320
313
|
const settlementLayers = transaction.settlementLayers;
|
|
321
314
|
const sourceAssets = transaction.sourceAssets;
|
|
322
315
|
const feeAsset = transaction.feeAsset;
|
|
323
|
-
const lockFunds = transaction.lockFunds;
|
|
324
316
|
const auxiliaryFunds = transaction.auxiliaryFunds;
|
|
325
317
|
const account = transaction.experimental_accountOverride;
|
|
326
318
|
const recipient = transaction.recipient;
|
|
@@ -336,7 +328,6 @@ function getTransactionParams(transaction) {
|
|
|
336
328
|
settlementLayers,
|
|
337
329
|
sourceAssets,
|
|
338
330
|
feeAsset,
|
|
339
|
-
lockFunds,
|
|
340
331
|
auxiliaryFunds,
|
|
341
332
|
account,
|
|
342
333
|
recipient,
|
|
@@ -349,15 +340,15 @@ function getTokenRequests(targetChain, initialTokenRequests) {
|
|
|
349
340
|
return initialTokenRequests ?? [];
|
|
350
341
|
}
|
|
351
342
|
async function prepareTransactionAsUserOp(config, chain, callInputs, signers, gasLimit) {
|
|
352
|
-
const publicClient =
|
|
343
|
+
const publicClient = createPublicClient({
|
|
353
344
|
chain,
|
|
354
|
-
transport:
|
|
345
|
+
transport: createTransport(chain, config.provider),
|
|
355
346
|
});
|
|
356
347
|
const validatorAccount = await getValidatorAccount(config, signers, publicClient, chain);
|
|
357
348
|
if (!validatorAccount) {
|
|
358
349
|
throw new Error('No validator account found');
|
|
359
350
|
}
|
|
360
|
-
const bundlerClient =
|
|
351
|
+
const bundlerClient = getBundlerClient(config, publicClient);
|
|
361
352
|
const calls = parseCalls(callInputs, chain.id);
|
|
362
353
|
const userOp = await bundlerClient.prepareUserOperation({
|
|
363
354
|
account: validatorAccount,
|
|
@@ -366,10 +357,10 @@ async function prepareTransactionAsUserOp(config, chain, callInputs, signers, ga
|
|
|
366
357
|
});
|
|
367
358
|
return {
|
|
368
359
|
userOp,
|
|
369
|
-
hash:
|
|
360
|
+
hash: getUserOperationHash({
|
|
370
361
|
userOperation: userOp,
|
|
371
362
|
chainId: chain.id,
|
|
372
|
-
entryPointAddress:
|
|
363
|
+
entryPointAddress: entryPoint07Address,
|
|
373
364
|
entryPointVersion: '0.7',
|
|
374
365
|
}),
|
|
375
366
|
};
|
|
@@ -383,7 +374,7 @@ function getAccountType(accountConfig) {
|
|
|
383
374
|
}
|
|
384
375
|
}
|
|
385
376
|
function getIntentAccount(config, eip7702InitSignature, account) {
|
|
386
|
-
const accountAddress =
|
|
377
|
+
const accountAddress = getAddress(config);
|
|
387
378
|
const accountType = getAccountType(config.account);
|
|
388
379
|
const { setupOps, delegations } = getSetupOperationsAndDelegations(config, accountAddress, eip7702InitSignature);
|
|
389
380
|
return {
|
|
@@ -393,7 +384,7 @@ function getIntentAccount(config, eip7702InitSignature, account) {
|
|
|
393
384
|
delegations,
|
|
394
385
|
};
|
|
395
386
|
}
|
|
396
|
-
async function prepareTransactionAsIntent(config, sourceChains, targetChain, callInputs, gasLimit, tokenRequests, recipientInput, sponsored, eip7702InitSignature, settlementLayers, sourceAssets, feeAsset,
|
|
387
|
+
async function prepareTransactionAsIntent(config, sourceChains, targetChain, callInputs, gasLimit, tokenRequests, recipientInput, sponsored, eip7702InitSignature, settlementLayers, sourceAssets, feeAsset, auxiliaryFunds, account, signers) {
|
|
397
388
|
const calls = parseCalls(callInputs, targetChain.id);
|
|
398
389
|
const accountAccessList = createAccountAccessList(sourceChains, sourceAssets);
|
|
399
390
|
function getRecipient(recipient) {
|
|
@@ -414,8 +405,6 @@ async function prepareTransactionAsIntent(config, sourceChains, targetChain, cal
|
|
|
414
405
|
const intentAccount = {
|
|
415
406
|
...getIntentAccount(config, eip7702InitSignature, account),
|
|
416
407
|
...(signers?.type === 'experimental_session' && {
|
|
417
|
-
// Global fallback: target-chain sig for backward-compat with older orchestrators
|
|
418
|
-
mockSignature: (0, validators_1.buildMockSignature)(resolveSessionForChain(signers, targetChain.id).session, config.useDevContracts, sourceChains?.length ?? 1),
|
|
419
408
|
// Per-chain map: enables accurate per-chain session validation gas simulation
|
|
420
409
|
mockSignatures: Object.fromEntries([
|
|
421
410
|
...new Set([
|
|
@@ -424,14 +413,14 @@ async function prepareTransactionAsIntent(config, sourceChains, targetChain, cal
|
|
|
424
413
|
]),
|
|
425
414
|
].map((chainId) => [
|
|
426
415
|
String(chainId),
|
|
427
|
-
|
|
416
|
+
buildMockSignature(resolveSessionForChain(signers, chainId).session, config.useDevContracts, sourceChains?.length ?? 1, chainId),
|
|
428
417
|
])),
|
|
429
418
|
}),
|
|
430
419
|
};
|
|
431
420
|
const recipient = getRecipient(recipientInput);
|
|
432
421
|
const signatureMode = signers?.type === 'experimental_session'
|
|
433
|
-
?
|
|
434
|
-
:
|
|
422
|
+
? SIG_MODE_EMISSARY_EXECUTION_ERC1271
|
|
423
|
+
: SIG_MODE_ERC1271_EMISSARY;
|
|
435
424
|
// For session signers that need enabling, pass a dummy preclaimop per source chain
|
|
436
425
|
// so the orchestrator bakes it into the bundle before computing its HMAC. The filler
|
|
437
426
|
// executes the op via verifyExecution in ENABLE mode, enabling the session on-chain
|
|
@@ -451,9 +440,9 @@ async function prepareTransactionAsIntent(config, sourceChains, targetChain, cal
|
|
|
451
440
|
continue;
|
|
452
441
|
preClaimExecutions[chainId] = [
|
|
453
442
|
{
|
|
454
|
-
to:
|
|
443
|
+
to: DUMMY_PRECLAIMOP_TARGET,
|
|
455
444
|
value: 0n,
|
|
456
|
-
data:
|
|
445
|
+
data: DUMMY_PRECLAIMOP_SELECTOR,
|
|
457
446
|
},
|
|
458
447
|
];
|
|
459
448
|
}
|
|
@@ -461,7 +450,7 @@ async function prepareTransactionAsIntent(config, sourceChains, targetChain, cal
|
|
|
461
450
|
const metaIntent = {
|
|
462
451
|
destinationChainId: targetChain.id,
|
|
463
452
|
tokenRequests: tokenRequests.map((tokenRequest) => ({
|
|
464
|
-
tokenAddress:
|
|
453
|
+
tokenAddress: resolveTokenAddress(tokenRequest.address, targetChain.id),
|
|
465
454
|
amount: tokenRequest.amount,
|
|
466
455
|
})),
|
|
467
456
|
recipient,
|
|
@@ -470,19 +459,18 @@ async function prepareTransactionAsIntent(config, sourceChains, targetChain, cal
|
|
|
470
459
|
destinationGasUnits: gasLimit,
|
|
471
460
|
accountAccessList,
|
|
472
461
|
options: {
|
|
473
|
-
topupCompact: lockFunds ?? false,
|
|
474
462
|
feeToken: feeAsset,
|
|
475
463
|
sponsorSettings: sponsored
|
|
476
464
|
? typeof sponsored === 'object'
|
|
477
465
|
? {
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
466
|
+
gas: sponsored.gas,
|
|
467
|
+
bridgeFees: sponsored.bridging,
|
|
468
|
+
swapFees: sponsored.swaps,
|
|
481
469
|
}
|
|
482
470
|
: {
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
471
|
+
gas: sponsored,
|
|
472
|
+
bridgeFees: sponsored,
|
|
473
|
+
swapFees: sponsored,
|
|
486
474
|
}
|
|
487
475
|
: undefined,
|
|
488
476
|
settlementLayers,
|
|
@@ -491,17 +479,24 @@ async function prepareTransactionAsIntent(config, sourceChains, targetChain, cal
|
|
|
491
479
|
},
|
|
492
480
|
...(Object.keys(preClaimExecutions).length > 0 && { preClaimExecutions }),
|
|
493
481
|
};
|
|
494
|
-
const serializedIntent =
|
|
495
|
-
const orchestrator =
|
|
496
|
-
const
|
|
497
|
-
|
|
482
|
+
const serializedIntent = convertBigIntFields(metaIntent);
|
|
483
|
+
const orchestrator = getOrchestrator(config._authProvider ?? createAuthProvider(config), config.endpointUrl, config.headers);
|
|
484
|
+
const { routes } = await orchestrator.createQuote(metaIntent);
|
|
485
|
+
const best = routes[0];
|
|
486
|
+
if (!best) {
|
|
487
|
+
throw new Error('Orchestrator returned no quote');
|
|
488
|
+
}
|
|
489
|
+
return {
|
|
490
|
+
quotes: { best, all: routes },
|
|
491
|
+
intentInput: serializedIntent,
|
|
492
|
+
};
|
|
498
493
|
}
|
|
499
|
-
async function signIntent(config,
|
|
500
|
-
const { origin, destination } = getIntentMessages(
|
|
494
|
+
async function signIntent(config, signData, targetChain, signers, targetExecution) {
|
|
495
|
+
const { origin, destination } = getIntentMessages(signData);
|
|
501
496
|
if (config.account?.type === 'eoa') {
|
|
502
497
|
const eoa = config.eoa;
|
|
503
498
|
if (!eoa) {
|
|
504
|
-
throw new
|
|
499
|
+
throw new EoaAccountMustHaveAccountError();
|
|
505
500
|
}
|
|
506
501
|
const originSignatures = [];
|
|
507
502
|
for (const typedData of origin) {
|
|
@@ -510,7 +505,7 @@ async function signIntent(config, intentOp, targetChain, signers, targetExecutio
|
|
|
510
505
|
originSignatures.push(signature);
|
|
511
506
|
}
|
|
512
507
|
else {
|
|
513
|
-
throw new
|
|
508
|
+
throw new EoaSigningMethodNotConfiguredError('signTypedData');
|
|
514
509
|
}
|
|
515
510
|
}
|
|
516
511
|
const destinationSignature = originSignatures.at(-1);
|
|
@@ -523,11 +518,11 @@ async function signIntent(config, intentOp, targetChain, signers, targetExecutio
|
|
|
523
518
|
if (!validator) {
|
|
524
519
|
throw new Error('Validator not available');
|
|
525
520
|
}
|
|
526
|
-
const ownerValidator =
|
|
521
|
+
const ownerValidator = getOwnerValidator(config);
|
|
527
522
|
const isRoot = validator.address === ownerValidator.address;
|
|
528
523
|
const originSignatures = [];
|
|
529
524
|
for (const typedData of origin) {
|
|
530
|
-
const chain =
|
|
525
|
+
const chain = getChainById(typedData.domain?.chainId);
|
|
531
526
|
const originSigners = await resolveSignersForChain(config, signers, chain.id);
|
|
532
527
|
const signature = await signIntentTypedData(config, originSigners, validator, isRoot, typedData, chain, targetExecution ?? false);
|
|
533
528
|
originSignatures.push(signature);
|
|
@@ -549,8 +544,8 @@ async function getDestinationSignature(config, signers, validator, isRoot, targe
|
|
|
549
544
|
// the account's eip712Domain() returns the target chain's chainId, which differs
|
|
550
545
|
// from the origin chain used for the last origin signature
|
|
551
546
|
const isK1Validator = validator.address.toLowerCase() ===
|
|
552
|
-
|
|
553
|
-
if (isK1Validator &&
|
|
547
|
+
K1_DEFAULT_VALIDATOR_ADDRESS.toLowerCase();
|
|
548
|
+
if (isK1Validator && supportsEip712(validator)) {
|
|
554
549
|
return await signDestinationSeparately(config, signers, validator, isRoot, targetChain, destination, targetExecution);
|
|
555
550
|
}
|
|
556
551
|
const lastOriginSignature = originSignatures.at(-1);
|
|
@@ -559,50 +554,63 @@ async function getDestinationSignature(config, signers, validator, isRoot, targe
|
|
|
559
554
|
: (lastOriginSignature ?? '0x');
|
|
560
555
|
}
|
|
561
556
|
async function signDestinationSeparately(config, signers, validator, isRoot, targetChain, destination, targetExecution) {
|
|
562
|
-
const destinationChain =
|
|
557
|
+
const destinationChain = getChainById(targetChain.id);
|
|
563
558
|
const destinationSignatures = await signIntentTypedData(config, signers, validator, isRoot, destination, destinationChain, targetExecution);
|
|
564
559
|
return typeof destinationSignatures === 'object'
|
|
565
560
|
? destinationSignatures.preClaimSig
|
|
566
561
|
: (destinationSignatures ?? '0x');
|
|
567
562
|
}
|
|
568
|
-
function getIntentMessages(
|
|
569
|
-
const address = (0, accounts_1.getAddress)(config);
|
|
570
|
-
const intentExecutor = (0, modules_1.getIntentExecutor)(config);
|
|
571
|
-
const withPermit2 = intentOp.elements.some((element) => element.mandate.qualifier.settlementContext.fundingMethod === 'PERMIT2');
|
|
572
|
-
const withIntentExecutorOps = intentOp.elements.some((element) => element.mandate.qualifier.settlementContext.settlementLayer ===
|
|
573
|
-
'INTENT_EXECUTOR');
|
|
574
|
-
const origin = [];
|
|
575
|
-
for (const element of intentOp.elements) {
|
|
576
|
-
if (withIntentExecutorOps) {
|
|
577
|
-
const typedData = (0, singleChainOps_1.getTypedData)(address, intentExecutor.address, element, BigInt(intentOp.nonce));
|
|
578
|
-
origin.push(typedData);
|
|
579
|
-
}
|
|
580
|
-
else if (withPermit2) {
|
|
581
|
-
const typedData = (0, permit2_2.getTypedData)(element, BigInt(intentOp.nonce), BigInt(intentOp.expires));
|
|
582
|
-
origin.push(typedData);
|
|
583
|
-
}
|
|
584
|
-
else {
|
|
585
|
-
const typedData = (0, compact_1.getCompactTypedData)(intentOp);
|
|
586
|
-
origin.push(typedData);
|
|
587
|
-
}
|
|
588
|
-
}
|
|
589
|
-
const destination = origin.at(-1);
|
|
563
|
+
function getIntentMessages(signData) {
|
|
590
564
|
return {
|
|
591
|
-
origin,
|
|
592
|
-
destination,
|
|
565
|
+
origin: signData.origin.map(prepareTypedData),
|
|
566
|
+
destination: prepareTypedData(signData.destination),
|
|
567
|
+
targetExecution: signData.targetExecution
|
|
568
|
+
? prepareTypedData(signData.targetExecution)
|
|
569
|
+
: undefined,
|
|
593
570
|
};
|
|
594
571
|
}
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
const
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
overhead: 0n,
|
|
572
|
+
// Server emits uint*/int* values as decimal strings; viem's hashTypedData
|
|
573
|
+
// expects bigint. Walk the message tree against the type schema and coerce
|
|
574
|
+
// numeric fields back to bigint before signing.
|
|
575
|
+
function prepareTypedData(td) {
|
|
576
|
+
const types = td.types;
|
|
577
|
+
return {
|
|
578
|
+
...td,
|
|
579
|
+
message: coerceTypedDataMessage(types, td.primaryType, td.message),
|
|
604
580
|
};
|
|
605
|
-
|
|
581
|
+
}
|
|
582
|
+
function coerceTypedDataMessage(types, primaryType, message) {
|
|
583
|
+
const fields = types[primaryType];
|
|
584
|
+
if (!fields)
|
|
585
|
+
return message;
|
|
586
|
+
const result = { ...message };
|
|
587
|
+
for (const { name, type } of fields) {
|
|
588
|
+
if (name in message) {
|
|
589
|
+
result[name] = coerceTypedDataValue(types, type, message[name]);
|
|
590
|
+
}
|
|
591
|
+
}
|
|
592
|
+
return result;
|
|
593
|
+
}
|
|
594
|
+
function coerceTypedDataValue(types, type, value) {
|
|
595
|
+
if (value === null || value === undefined)
|
|
596
|
+
return value;
|
|
597
|
+
const arrayMatch = type.match(/^(.+)\[\d*\]$/);
|
|
598
|
+
if (arrayMatch) {
|
|
599
|
+
const elementType = arrayMatch[1];
|
|
600
|
+
if (!Array.isArray(value))
|
|
601
|
+
return value;
|
|
602
|
+
return value.map((v) => coerceTypedDataValue(types, elementType, v));
|
|
603
|
+
}
|
|
604
|
+
if (/^u?int\d*$/.test(type)) {
|
|
605
|
+
if (typeof value === 'string' || typeof value === 'number') {
|
|
606
|
+
return BigInt(value);
|
|
607
|
+
}
|
|
608
|
+
return value;
|
|
609
|
+
}
|
|
610
|
+
if (types[type]) {
|
|
611
|
+
return coerceTypedDataMessage(types, type, value);
|
|
612
|
+
}
|
|
613
|
+
return value;
|
|
606
614
|
}
|
|
607
615
|
/** Computes claim policy calldata when parameters are Permit2 typed data with claim policies. */
|
|
608
616
|
function resolveClaimPolicyData(signers, parameters) {
|
|
@@ -618,21 +626,21 @@ function resolveClaimPolicyData(signers, parameters) {
|
|
|
618
626
|
typeof msg.deadline !== 'bigint') {
|
|
619
627
|
return undefined;
|
|
620
628
|
}
|
|
621
|
-
return
|
|
629
|
+
return buildPermit2ClaimPolicyCalldata(signers.session.claimPolicies[0], parameters.message);
|
|
622
630
|
}
|
|
623
631
|
async function signIntentTypedData(config, signers, validator, isRoot, parameters, chain, targetExecution) {
|
|
624
|
-
if (
|
|
632
|
+
if (supportsEip712(validator)) {
|
|
625
633
|
const isK1Validator = validator.address.toLowerCase() ===
|
|
626
|
-
|
|
634
|
+
K1_DEFAULT_VALIDATOR_ADDRESS.toLowerCase();
|
|
627
635
|
if (isK1Validator) {
|
|
628
636
|
return await signErc7739TypedData(config, signers, validator, isRoot, parameters, chain);
|
|
629
637
|
}
|
|
630
|
-
return await
|
|
638
|
+
return await getTypedDataPackedSignature(config, signers, chain, {
|
|
631
639
|
address: validator.address,
|
|
632
640
|
isRoot,
|
|
633
641
|
}, parameters);
|
|
634
642
|
}
|
|
635
|
-
const hash =
|
|
643
|
+
const hash = hashTypedData(parameters);
|
|
636
644
|
if (isResolvedSessionSignerSet(signers) && signers.verifyExecutions) {
|
|
637
645
|
if (targetExecution) {
|
|
638
646
|
const targetSigners = {
|
|
@@ -643,7 +651,7 @@ async function signIntentTypedData(config, signers, validator, isRoot, parameter
|
|
|
643
651
|
};
|
|
644
652
|
// signWithSession (called inside getEmissarySignature) already calls packSignature
|
|
645
653
|
// internally, so no transform is needed here
|
|
646
|
-
return await
|
|
654
|
+
return await getEmissarySignature(config, targetSigners, chain, hash);
|
|
647
655
|
}
|
|
648
656
|
const claimPolicyData = resolveClaimPolicyData(signers, parameters);
|
|
649
657
|
const sessionSignersForEip1271 = {
|
|
@@ -653,11 +661,11 @@ async function signIntentTypedData(config, signers, validator, isRoot, parameter
|
|
|
653
661
|
enableData: signers.enableData,
|
|
654
662
|
claimPolicyData,
|
|
655
663
|
};
|
|
656
|
-
const eip1271Signature = await
|
|
664
|
+
const eip1271Signature = await getEip1271Signature(config, sessionSignersForEip1271, chain, {
|
|
657
665
|
address: validator.address,
|
|
658
666
|
isRoot,
|
|
659
667
|
}, hash);
|
|
660
|
-
const emissarySignature = await
|
|
668
|
+
const emissarySignature = await getEmissarySignature(config, {
|
|
661
669
|
type: 'experimental_session',
|
|
662
670
|
session: signers.session,
|
|
663
671
|
verifyExecutions: true,
|
|
@@ -670,12 +678,12 @@ async function signIntentTypedData(config, signers, validator, isRoot, parameter
|
|
|
670
678
|
}
|
|
671
679
|
if (isResolvedSessionSignerSet(signers)) {
|
|
672
680
|
const claimPolicyData = resolveClaimPolicyData(signers, parameters);
|
|
673
|
-
return await
|
|
681
|
+
return await getEip1271Signature(config, claimPolicyData !== undefined ? { ...signers, claimPolicyData } : signers, chain, {
|
|
674
682
|
address: validator.address,
|
|
675
683
|
isRoot,
|
|
676
684
|
}, hash);
|
|
677
685
|
}
|
|
678
|
-
return await
|
|
686
|
+
return await getEip1271Signature(config, signers, chain, {
|
|
679
687
|
address: validator.address,
|
|
680
688
|
isRoot,
|
|
681
689
|
}, hash);
|
|
@@ -685,9 +693,9 @@ async function signUserOp(config, chain, signers, userOp) {
|
|
|
685
693
|
if (!validator) {
|
|
686
694
|
throw new Error('Validator not available');
|
|
687
695
|
}
|
|
688
|
-
const publicClient =
|
|
696
|
+
const publicClient = createPublicClient({
|
|
689
697
|
chain,
|
|
690
|
-
transport:
|
|
698
|
+
transport: createTransport(chain, config.provider),
|
|
691
699
|
});
|
|
692
700
|
const account = await getValidatorAccount(config, signers, publicClient, chain);
|
|
693
701
|
if (!account) {
|
|
@@ -696,36 +704,36 @@ async function signUserOp(config, chain, signers, userOp) {
|
|
|
696
704
|
return await account.signUserOperation(userOp);
|
|
697
705
|
}
|
|
698
706
|
async function submitUserOp(config, chain, userOp, signature) {
|
|
699
|
-
const publicClient =
|
|
707
|
+
const publicClient = createPublicClient({
|
|
700
708
|
chain,
|
|
701
|
-
transport:
|
|
709
|
+
transport: createTransport(chain, config.provider),
|
|
702
710
|
});
|
|
703
|
-
const bundlerClient =
|
|
711
|
+
const bundlerClient = getBundlerClient(config, publicClient);
|
|
704
712
|
const hash = await bundlerClient.request({
|
|
705
713
|
method: 'eth_sendUserOperation',
|
|
706
714
|
params: [
|
|
707
715
|
{
|
|
708
716
|
sender: userOp.sender,
|
|
709
|
-
nonce:
|
|
717
|
+
nonce: toHex(userOp.nonce),
|
|
710
718
|
factory: userOp.factory,
|
|
711
719
|
factoryData: userOp.factoryData,
|
|
712
720
|
callData: userOp.callData,
|
|
713
|
-
callGasLimit:
|
|
714
|
-
verificationGasLimit:
|
|
715
|
-
preVerificationGas:
|
|
716
|
-
maxPriorityFeePerGas:
|
|
717
|
-
maxFeePerGas:
|
|
721
|
+
callGasLimit: toHex(userOp.callGasLimit),
|
|
722
|
+
verificationGasLimit: toHex(userOp.verificationGasLimit),
|
|
723
|
+
preVerificationGas: toHex(userOp.preVerificationGas),
|
|
724
|
+
maxPriorityFeePerGas: toHex(userOp.maxPriorityFeePerGas),
|
|
725
|
+
maxFeePerGas: toHex(userOp.maxFeePerGas),
|
|
718
726
|
paymaster: userOp.paymaster,
|
|
719
727
|
paymasterVerificationGasLimit: userOp.paymasterVerificationGasLimit
|
|
720
|
-
?
|
|
728
|
+
? toHex(userOp.paymasterVerificationGasLimit)
|
|
721
729
|
: undefined,
|
|
722
730
|
paymasterPostOpGasLimit: userOp.paymasterPostOpGasLimit
|
|
723
|
-
?
|
|
731
|
+
? toHex(userOp.paymasterPostOpGasLimit)
|
|
724
732
|
: undefined,
|
|
725
733
|
paymasterData: userOp.paymasterData,
|
|
726
734
|
signature,
|
|
727
735
|
},
|
|
728
|
-
|
|
736
|
+
entryPoint07Address,
|
|
729
737
|
],
|
|
730
738
|
});
|
|
731
739
|
return {
|
|
@@ -734,54 +742,52 @@ async function submitUserOp(config, chain, userOp, signature) {
|
|
|
734
742
|
chain: chain.id,
|
|
735
743
|
};
|
|
736
744
|
}
|
|
737
|
-
async function
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
|
|
745
|
+
async function submitIntentInternal(config, sourceChains, targetChain, quote, originSignatures, destinationSignature, targetExecutionSignature, authorizations, dryRun, intentInput) {
|
|
746
|
+
const request = {
|
|
747
|
+
intentId: quote.intentId,
|
|
748
|
+
signatures: {
|
|
749
|
+
origin: originSignatures,
|
|
750
|
+
destination: destinationSignature,
|
|
751
|
+
...(targetExecutionSignature !== undefined && {
|
|
752
|
+
targetExecution: targetExecutionSignature,
|
|
753
|
+
}),
|
|
754
|
+
},
|
|
755
|
+
...(authorizations.length > 0 && {
|
|
756
|
+
authorizations: {
|
|
757
|
+
sponsor: authorizations.map((authorization) => ({
|
|
758
|
+
chainId: authorization.chainId,
|
|
759
|
+
address: authorization.address,
|
|
760
|
+
nonce: authorization.nonce,
|
|
761
|
+
yParity: authorization.yParity ?? 0,
|
|
762
|
+
r: authorization.r,
|
|
763
|
+
s: authorization.s,
|
|
764
|
+
})),
|
|
765
|
+
},
|
|
766
|
+
}),
|
|
767
|
+
...(dryRun && { options: { dryRun: true } }),
|
|
756
768
|
};
|
|
757
|
-
}
|
|
758
|
-
async function submitIntentInternal(config, sourceChains, targetChain, intentOp, originSignatures, destinationSignature, targetExecutionSignature, authorizations, dryRun, intentInput) {
|
|
759
|
-
const signedIntentOp = createSignedIntentOp(intentOp, originSignatures, destinationSignature, targetExecutionSignature, authorizations);
|
|
760
769
|
const isSponsored = !!intentInput?.options?.sponsorSettings;
|
|
761
|
-
const orchestrator =
|
|
762
|
-
const
|
|
763
|
-
// Some settlement paths (e.g. SAME_CHAIN) may not return a result.id — fall
|
|
764
|
-
// back to the nonce which the orchestrator also accepts as an intent identifier.
|
|
765
|
-
const intentId = intentResults.result.id ?? intentOp.nonce;
|
|
770
|
+
const orchestrator = getOrchestrator(config._authProvider ?? createAuthProvider(config), config.endpointUrl, config.headers);
|
|
771
|
+
const response = await orchestrator.createIntent(request, intentInput ? { intentInput, isSponsored } : undefined);
|
|
766
772
|
return {
|
|
767
773
|
type: 'intent',
|
|
768
|
-
id:
|
|
774
|
+
id: response.intentId,
|
|
769
775
|
sourceChains: sourceChains?.map((chain) => chain.id),
|
|
770
776
|
targetChain: targetChain.id,
|
|
771
777
|
};
|
|
772
778
|
}
|
|
773
779
|
async function getValidatorAccount(config, signers, publicClient, chain) {
|
|
774
780
|
if (!signers) {
|
|
775
|
-
return
|
|
781
|
+
return getSmartAccount(config, publicClient, chain);
|
|
776
782
|
}
|
|
777
783
|
// Owners
|
|
778
784
|
const withOwner = signers.type === 'owner' ? signers : null;
|
|
779
785
|
if (withOwner) {
|
|
780
|
-
return
|
|
786
|
+
return getSmartAccount(config, publicClient, chain);
|
|
781
787
|
}
|
|
782
788
|
const withGuardians = signers.type === 'guardians' ? signers : null;
|
|
783
789
|
return withGuardians
|
|
784
|
-
? await
|
|
790
|
+
? await getGuardianSmartAccount(config, publicClient, chain, {
|
|
785
791
|
type: 'ecdsa',
|
|
786
792
|
accounts: withGuardians.guardians,
|
|
787
793
|
})
|
|
@@ -789,7 +795,7 @@ async function getValidatorAccount(config, signers, publicClient, chain) {
|
|
|
789
795
|
}
|
|
790
796
|
function getValidator(config, signers) {
|
|
791
797
|
if (!signers) {
|
|
792
|
-
return
|
|
798
|
+
return getOwnerValidator(config);
|
|
793
799
|
}
|
|
794
800
|
// Owners
|
|
795
801
|
const withOwner = signers.type === 'owner' ? signers : null;
|
|
@@ -797,29 +803,29 @@ function getValidator(config, signers) {
|
|
|
797
803
|
// ECDSA
|
|
798
804
|
if (withOwner.kind === 'ecdsa') {
|
|
799
805
|
// Use the configured owner validator (e.g., ENS) rather than forcing Ownable
|
|
800
|
-
return
|
|
806
|
+
return getOwnerValidator(config);
|
|
801
807
|
}
|
|
802
808
|
// Passkeys (WebAuthn)
|
|
803
809
|
if (withOwner.kind === 'passkey') {
|
|
804
|
-
return
|
|
810
|
+
return getWebAuthnValidator(1, withOwner.accounts.map((account) => ({
|
|
805
811
|
pubKey: account.publicKey,
|
|
806
812
|
authenticatorId: account.id,
|
|
807
813
|
})));
|
|
808
814
|
}
|
|
809
815
|
// Multi-factor
|
|
810
816
|
if (withOwner.kind === 'multi-factor') {
|
|
811
|
-
return
|
|
817
|
+
return getMultiFactorValidator(1, withOwner.validators);
|
|
812
818
|
}
|
|
813
819
|
}
|
|
814
820
|
// Smart sessions
|
|
815
821
|
const withSession = signers.type === 'experimental_session';
|
|
816
822
|
if (withSession) {
|
|
817
|
-
return
|
|
823
|
+
return getSmartSessionValidator(config);
|
|
818
824
|
}
|
|
819
825
|
// Guardians (social recovery)
|
|
820
826
|
const withGuardians = signers.type === 'guardians' ? signers : null;
|
|
821
827
|
if (withGuardians) {
|
|
822
|
-
return
|
|
828
|
+
return getSocialRecoveryValidator(withGuardians.guardians);
|
|
823
829
|
}
|
|
824
830
|
// Fallback
|
|
825
831
|
return undefined;
|
|
@@ -828,7 +834,7 @@ function parseCalls(calls, chainId) {
|
|
|
828
834
|
return calls.map((call) => ({
|
|
829
835
|
data: call.data ?? '0x',
|
|
830
836
|
value: call.value ?? 0n,
|
|
831
|
-
to:
|
|
837
|
+
to: resolveTokenAddress(call.to, chainId),
|
|
832
838
|
}));
|
|
833
839
|
}
|
|
834
840
|
function createAccountAccessList(sourceChains, sourceAssets) {
|
|
@@ -840,12 +846,32 @@ function createAccountAccessList(sourceChains, sourceAssets) {
|
|
|
840
846
|
if (Array.isArray(sourceAssets)) {
|
|
841
847
|
const isExactConfig = sourceAssets.length > 0 && typeof sourceAssets[0] !== 'string';
|
|
842
848
|
if (isExactConfig) {
|
|
843
|
-
const
|
|
844
|
-
|
|
845
|
-
|
|
846
|
-
|
|
847
|
-
|
|
848
|
-
|
|
849
|
+
const chainTokens = {};
|
|
850
|
+
const chainTokenAmounts = {};
|
|
851
|
+
for (const config of sourceAssets) {
|
|
852
|
+
const chainId = config.chain.id;
|
|
853
|
+
const tokenAddress = resolveTokenAddress(config.address, config.chain.id);
|
|
854
|
+
if (config.amount !== undefined) {
|
|
855
|
+
if (!chainTokenAmounts[chainId])
|
|
856
|
+
chainTokenAmounts[chainId] = {};
|
|
857
|
+
chainTokenAmounts[chainId][tokenAddress] = config.amount;
|
|
858
|
+
}
|
|
859
|
+
else {
|
|
860
|
+
if (!chainTokens[chainId])
|
|
861
|
+
chainTokens[chainId] = [];
|
|
862
|
+
chainTokens[chainId].push(tokenAddress);
|
|
863
|
+
}
|
|
864
|
+
}
|
|
865
|
+
const out = {};
|
|
866
|
+
if (Object.keys(chainTokens).length > 0) {
|
|
867
|
+
out.chainTokens =
|
|
868
|
+
chainTokens;
|
|
869
|
+
}
|
|
870
|
+
if (Object.keys(chainTokenAmounts).length > 0) {
|
|
871
|
+
out.chainTokenAmounts =
|
|
872
|
+
chainTokenAmounts;
|
|
873
|
+
}
|
|
874
|
+
return out;
|
|
849
875
|
}
|
|
850
876
|
return chainIds
|
|
851
877
|
? { chainIds, tokens: sourceAssets }
|
|
@@ -854,18 +880,18 @@ function createAccountAccessList(sourceChains, sourceAssets) {
|
|
|
854
880
|
return { chainTokens: sourceAssets };
|
|
855
881
|
}
|
|
856
882
|
function getSetupOperationsAndDelegations(config, accountAddress, eip7702InitSignature) {
|
|
857
|
-
const initCode =
|
|
883
|
+
const initCode = getInitCode(config);
|
|
858
884
|
if (config.account?.type === 'eoa') {
|
|
859
885
|
return {
|
|
860
886
|
setupOps: [],
|
|
861
887
|
};
|
|
862
888
|
}
|
|
863
|
-
else if (
|
|
889
|
+
else if (is7702(config)) {
|
|
864
890
|
// EIP-7702 initialization is only needed for EOA accounts
|
|
865
891
|
if (!eip7702InitSignature || eip7702InitSignature === '0x') {
|
|
866
|
-
throw new
|
|
892
|
+
throw new Eip7702InitSignatureRequiredError();
|
|
867
893
|
}
|
|
868
|
-
const { initData: eip7702InitData, contract: eip7702Contract } =
|
|
894
|
+
const { initData: eip7702InitData, contract: eip7702Contract } = getEip7702InitCall(config, eip7702InitSignature);
|
|
869
895
|
return {
|
|
870
896
|
setupOps: [
|
|
871
897
|
{
|
|
@@ -891,7 +917,7 @@ function getSetupOperationsAndDelegations(config, accountAddress, eip7702InitSig
|
|
|
891
917
|
setupOps: [],
|
|
892
918
|
};
|
|
893
919
|
}
|
|
894
|
-
throw new
|
|
920
|
+
throw new FactoryArgsNotAvailableError();
|
|
895
921
|
}
|
|
896
922
|
// Contract account with init code
|
|
897
923
|
return {
|
|
@@ -913,12 +939,12 @@ function getSetupOperationsAndDelegations(config, accountAddress, eip7702InitSig
|
|
|
913
939
|
function validateTokenSymbols(chain, tokenAddressOrSymbols) {
|
|
914
940
|
function validateTokenSymbol(chain, addressOrSymbol) {
|
|
915
941
|
// Address
|
|
916
|
-
if (
|
|
942
|
+
if (isAddress(addressOrSymbol, { strict: false })) {
|
|
917
943
|
return true;
|
|
918
944
|
}
|
|
919
945
|
// Token symbol
|
|
920
|
-
const address =
|
|
921
|
-
return
|
|
946
|
+
const address = getTokenAddress(addressOrSymbol, chain.id);
|
|
947
|
+
return isAddress(address, { strict: false });
|
|
922
948
|
}
|
|
923
949
|
for (const addressOrSymbol of tokenAddressOrSymbols) {
|
|
924
950
|
if (!validateTokenSymbol(chain, addressOrSymbol)) {
|
|
@@ -930,7 +956,7 @@ function validateTokenSymbols(chain, tokenAddressOrSymbols) {
|
|
|
930
956
|
// Uses a Solady-compatible TypedDataSign hash and wraps the signature with
|
|
931
957
|
// the app domain separator and contents hash for on-chain verification.
|
|
932
958
|
async function signErc7739TypedData(config, signers, validator, isRoot, parameters, chain) {
|
|
933
|
-
const verifierDomain =
|
|
959
|
+
const verifierDomain = getEip712Domain(config, chain);
|
|
934
960
|
const hash = hashErc7739TypedDataForSolady({
|
|
935
961
|
domain: parameters.domain,
|
|
936
962
|
types: parameters.types,
|
|
@@ -938,10 +964,10 @@ async function signErc7739TypedData(config, signers, validator, isRoot, paramete
|
|
|
938
964
|
message: parameters.message,
|
|
939
965
|
verifierDomain,
|
|
940
966
|
});
|
|
941
|
-
return await
|
|
967
|
+
return await getEip1271Signature(config, signers, chain, {
|
|
942
968
|
address: validator.address,
|
|
943
969
|
isRoot,
|
|
944
|
-
}, hash, (signature) =>
|
|
970
|
+
}, hash, (signature) => wrapTypedDataSignature({
|
|
945
971
|
domain: parameters.domain,
|
|
946
972
|
primaryType: parameters.primaryType,
|
|
947
973
|
types: parameters.types,
|
|
@@ -979,15 +1005,15 @@ function hashErc7739TypedDataForSolady({ domain, types, primaryType, message, ve
|
|
|
979
1005
|
// Construct TypedDataSign type string matching Solady's on-chain encoding:
|
|
980
1006
|
// TypedDataSign(<contentsName> contents,...salt) + contentsType
|
|
981
1007
|
const typedDataSignTypeString = `TypedDataSign(${contentsName} contents,string name,string version,uint256 chainId,address verifyingContract,bytes32 salt)${contentsType}`;
|
|
982
|
-
const typedDataSignTypeHash =
|
|
1008
|
+
const typedDataSignTypeHash = keccak256(toHex(typedDataSignTypeString));
|
|
983
1009
|
// Hash the original content struct
|
|
984
|
-
const contentsHash =
|
|
1010
|
+
const contentsHash = hashStruct({
|
|
985
1011
|
data: message,
|
|
986
1012
|
primaryType,
|
|
987
1013
|
types: types,
|
|
988
1014
|
});
|
|
989
1015
|
// Compute the TypedDataSign struct hash
|
|
990
|
-
const structHash =
|
|
1016
|
+
const structHash = keccak256(encodeAbiParameters([
|
|
991
1017
|
{ type: 'bytes32' },
|
|
992
1018
|
{ type: 'bytes32' },
|
|
993
1019
|
{ type: 'bytes32' },
|
|
@@ -998,8 +1024,8 @@ function hashErc7739TypedDataForSolady({ domain, types, primaryType, message, ve
|
|
|
998
1024
|
], [
|
|
999
1025
|
typedDataSignTypeHash,
|
|
1000
1026
|
contentsHash,
|
|
1001
|
-
|
|
1002
|
-
|
|
1027
|
+
keccak256(toHex(verifierDomain.name)),
|
|
1028
|
+
keccak256(toHex(verifierDomain.version)),
|
|
1003
1029
|
BigInt(verifierDomain.chainId),
|
|
1004
1030
|
verifierDomain.verifyingContract,
|
|
1005
1031
|
verifierDomain.salt,
|
|
@@ -1016,10 +1042,11 @@ function hashErc7739TypedDataForSolady({ domain, types, primaryType, message, ve
|
|
|
1016
1042
|
domainTypes.push({ name: 'verifyingContract', type: 'address' });
|
|
1017
1043
|
if (domain.salt)
|
|
1018
1044
|
domainTypes.push({ name: 'salt', type: 'bytes32' });
|
|
1019
|
-
const appDomainSeparator =
|
|
1045
|
+
const appDomainSeparator = hashDomain({
|
|
1020
1046
|
domain,
|
|
1021
1047
|
types: { EIP712Domain: domainTypes },
|
|
1022
1048
|
});
|
|
1023
1049
|
// Final hash: keccak256("\x19\x01" || appDomainSep || structHash)
|
|
1024
|
-
return
|
|
1050
|
+
return keccak256(concat(['0x1901', appDomainSeparator, structHash]));
|
|
1025
1051
|
}
|
|
1052
|
+
export { prepareTransaction, getTransactionMessages, signTransaction, signAuthorizations, signAuthorizationsInternal, signMessage, signTypedData, submitTransaction, prepareUserOperation, signUserOperation, submitUserOperation, signIntent, prepareTransactionAsIntent, submitIntentInternal, getValidatorAccount, parseCalls, getTokenRequests, resolveCallInputs, getIntentAccount, getTargetExecutionSignature, hashErc7739TypedDataForSolady, resolveSessionForChain, };
|