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