@aspect-wallet/sdk 0.1.0
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/CHANGELOG.md +24 -0
- package/LICENSE +21 -0
- package/README.md +708 -0
- package/dist/audit/history.d.ts +44 -0
- package/dist/audit/history.d.ts.map +1 -0
- package/dist/audit/history.js +80 -0
- package/dist/audit/history.js.map +1 -0
- package/dist/auth/email.d.ts +52 -0
- package/dist/auth/email.d.ts.map +1 -0
- package/dist/auth/email.js +66 -0
- package/dist/auth/email.js.map +1 -0
- package/dist/auth/oauth.d.ts +47 -0
- package/dist/auth/oauth.d.ts.map +1 -0
- package/dist/auth/oauth.js +103 -0
- package/dist/auth/oauth.js.map +1 -0
- package/dist/auth/passkey-auth.d.ts +39 -0
- package/dist/auth/passkey-auth.d.ts.map +1 -0
- package/dist/auth/passkey-auth.js +108 -0
- package/dist/auth/passkey-auth.js.map +1 -0
- package/dist/auth/session.d.ts +30 -0
- package/dist/auth/session.d.ts.map +1 -0
- package/dist/auth/session.js +61 -0
- package/dist/auth/session.js.map +1 -0
- package/dist/chain/registry.d.ts +25 -0
- package/dist/chain/registry.d.ts.map +1 -0
- package/dist/chain/registry.js +46 -0
- package/dist/chain/registry.js.map +1 -0
- package/dist/core/client.d.ts +78 -0
- package/dist/core/client.d.ts.map +1 -0
- package/dist/core/client.js +129 -0
- package/dist/core/client.js.map +1 -0
- package/dist/core/config.d.ts +22 -0
- package/dist/core/config.d.ts.map +1 -0
- package/dist/core/config.js +91 -0
- package/dist/core/config.js.map +1 -0
- package/dist/core/errors.d.ts +32 -0
- package/dist/core/errors.d.ts.map +1 -0
- package/dist/core/errors.js +95 -0
- package/dist/core/errors.js.map +1 -0
- package/dist/index.d.ts +55 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +64 -0
- package/dist/index.js.map +1 -0
- package/dist/mfa/guardian.d.ts +27 -0
- package/dist/mfa/guardian.d.ts.map +1 -0
- package/dist/mfa/guardian.js +37 -0
- package/dist/mfa/guardian.js.map +1 -0
- package/dist/mfa/multisig.d.ts +28 -0
- package/dist/mfa/multisig.d.ts.map +1 -0
- package/dist/mfa/multisig.js +40 -0
- package/dist/mfa/multisig.js.map +1 -0
- package/dist/mfa/tiers.d.ts +34 -0
- package/dist/mfa/tiers.d.ts.map +1 -0
- package/dist/mfa/tiers.js +66 -0
- package/dist/mfa/tiers.js.map +1 -0
- package/dist/mfa/timelock.d.ts +32 -0
- package/dist/mfa/timelock.d.ts.map +1 -0
- package/dist/mfa/timelock.js +47 -0
- package/dist/mfa/timelock.js.map +1 -0
- package/dist/recovery/devices.d.ts +31 -0
- package/dist/recovery/devices.d.ts.map +1 -0
- package/dist/recovery/devices.js +33 -0
- package/dist/recovery/devices.js.map +1 -0
- package/dist/recovery/export.d.ts +33 -0
- package/dist/recovery/export.d.ts.map +1 -0
- package/dist/recovery/export.js +44 -0
- package/dist/recovery/export.js.map +1 -0
- package/dist/recovery/rotation.d.ts +26 -0
- package/dist/recovery/rotation.d.ts.map +1 -0
- package/dist/recovery/rotation.js +31 -0
- package/dist/recovery/rotation.js.map +1 -0
- package/dist/recovery/social.d.ts +33 -0
- package/dist/recovery/social.d.ts.map +1 -0
- package/dist/recovery/social.js +36 -0
- package/dist/recovery/social.js.map +1 -0
- package/dist/security/freeze.d.ts +34 -0
- package/dist/security/freeze.d.ts.map +1 -0
- package/dist/security/freeze.js +42 -0
- package/dist/security/freeze.js.map +1 -0
- package/dist/security/revoke.d.ts +27 -0
- package/dist/security/revoke.d.ts.map +1 -0
- package/dist/security/revoke.js +27 -0
- package/dist/security/revoke.js.map +1 -0
- package/dist/security/watchtower.d.ts +34 -0
- package/dist/security/watchtower.d.ts.map +1 -0
- package/dist/security/watchtower.js +38 -0
- package/dist/security/watchtower.js.map +1 -0
- package/dist/session-keys/manager.d.ts +40 -0
- package/dist/session-keys/manager.d.ts.map +1 -0
- package/dist/session-keys/manager.js +65 -0
- package/dist/session-keys/manager.js.map +1 -0
- package/dist/session-keys/permissions.d.ts +44 -0
- package/dist/session-keys/permissions.d.ts.map +1 -0
- package/dist/session-keys/permissions.js +63 -0
- package/dist/session-keys/permissions.js.map +1 -0
- package/dist/session-keys/templates.d.ts +49 -0
- package/dist/session-keys/templates.d.ts.map +1 -0
- package/dist/session-keys/templates.js +65 -0
- package/dist/session-keys/templates.js.map +1 -0
- package/dist/signer/eoa.d.ts +24 -0
- package/dist/signer/eoa.d.ts.map +1 -0
- package/dist/signer/eoa.js +32 -0
- package/dist/signer/eoa.js.map +1 -0
- package/dist/signer/interface.d.ts +60 -0
- package/dist/signer/interface.d.ts.map +1 -0
- package/dist/signer/interface.js +47 -0
- package/dist/signer/interface.js.map +1 -0
- package/dist/signer/multisig.d.ts +38 -0
- package/dist/signer/multisig.d.ts.map +1 -0
- package/dist/signer/multisig.js +56 -0
- package/dist/signer/multisig.js.map +1 -0
- package/dist/signer/passkey.d.ts +35 -0
- package/dist/signer/passkey.d.ts.map +1 -0
- package/dist/signer/passkey.js +112 -0
- package/dist/signer/passkey.js.map +1 -0
- package/dist/signer/session.d.ts +24 -0
- package/dist/signer/session.d.ts.map +1 -0
- package/dist/signer/session.js +32 -0
- package/dist/signer/session.js.map +1 -0
- package/dist/sponsor/paymaster.d.ts +27 -0
- package/dist/sponsor/paymaster.d.ts.map +1 -0
- package/dist/sponsor/paymaster.js +43 -0
- package/dist/sponsor/paymaster.js.map +1 -0
- package/dist/transport/api.d.ts +25 -0
- package/dist/transport/api.d.ts.map +1 -0
- package/dist/transport/api.js +79 -0
- package/dist/transport/api.js.map +1 -0
- package/dist/transport/bundler.d.ts +52 -0
- package/dist/transport/bundler.d.ts.map +1 -0
- package/dist/transport/bundler.js +109 -0
- package/dist/transport/bundler.js.map +1 -0
- package/dist/transport/iframe.d.ts +33 -0
- package/dist/transport/iframe.d.ts.map +1 -0
- package/dist/transport/iframe.js +131 -0
- package/dist/transport/iframe.js.map +1 -0
- package/dist/types.d.ts +366 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +6 -0
- package/dist/types.js.map +1 -0
- package/dist/userop/builder.d.ts +75 -0
- package/dist/userop/builder.d.ts.map +1 -0
- package/dist/userop/builder.js +150 -0
- package/dist/userop/builder.js.map +1 -0
- package/dist/userop/encoding.d.ts +44 -0
- package/dist/userop/encoding.d.ts.map +1 -0
- package/dist/userop/encoding.js +99 -0
- package/dist/userop/encoding.js.map +1 -0
- package/dist/userop/gas.d.ts +35 -0
- package/dist/userop/gas.d.ts.map +1 -0
- package/dist/userop/gas.js +53 -0
- package/dist/userop/gas.js.map +1 -0
- package/dist/userop/hash.d.ts +34 -0
- package/dist/userop/hash.d.ts.map +1 -0
- package/dist/userop/hash.js +55 -0
- package/dist/userop/hash.js.map +1 -0
- package/dist/userop/nonce.d.ts +53 -0
- package/dist/userop/nonce.d.ts.map +1 -0
- package/dist/userop/nonce.js +79 -0
- package/dist/userop/nonce.js.map +1 -0
- package/dist/wallet/factory.d.ts +63 -0
- package/dist/wallet/factory.d.ts.map +1 -0
- package/dist/wallet/factory.js +63 -0
- package/dist/wallet/factory.js.map +1 -0
- package/package.json +70 -0
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* UserOperation callData and initCode encoding.
|
|
3
|
+
* Corresponds to SPEC-013 Sections 4-5, SPEC-002.
|
|
4
|
+
*/
|
|
5
|
+
import { encodeFunctionData, concat, } from 'viem';
|
|
6
|
+
/** Smart Account execute function ABI */
|
|
7
|
+
const EXECUTE_ABI = [
|
|
8
|
+
{
|
|
9
|
+
name: 'execute',
|
|
10
|
+
type: 'function',
|
|
11
|
+
inputs: [
|
|
12
|
+
{ name: 'target', type: 'address' },
|
|
13
|
+
{ name: 'value', type: 'uint256' },
|
|
14
|
+
{ name: 'data', type: 'bytes' },
|
|
15
|
+
],
|
|
16
|
+
outputs: [],
|
|
17
|
+
stateMutability: 'payable',
|
|
18
|
+
},
|
|
19
|
+
];
|
|
20
|
+
/** Smart Account executeBatch function ABI */
|
|
21
|
+
const EXECUTE_BATCH_ABI = [
|
|
22
|
+
{
|
|
23
|
+
name: 'executeBatch',
|
|
24
|
+
type: 'function',
|
|
25
|
+
inputs: [
|
|
26
|
+
{
|
|
27
|
+
name: 'calls',
|
|
28
|
+
type: 'tuple[]',
|
|
29
|
+
components: [
|
|
30
|
+
{ name: 'target', type: 'address' },
|
|
31
|
+
{ name: 'value', type: 'uint256' },
|
|
32
|
+
{ name: 'data', type: 'bytes' },
|
|
33
|
+
],
|
|
34
|
+
},
|
|
35
|
+
],
|
|
36
|
+
outputs: [],
|
|
37
|
+
stateMutability: 'payable',
|
|
38
|
+
},
|
|
39
|
+
];
|
|
40
|
+
/** Factory createAccount function ABI */
|
|
41
|
+
const CREATE_ACCOUNT_ABI = [
|
|
42
|
+
{
|
|
43
|
+
name: 'createAccount',
|
|
44
|
+
type: 'function',
|
|
45
|
+
inputs: [
|
|
46
|
+
{ name: 'owner', type: 'address' },
|
|
47
|
+
{ name: 'salt', type: 'uint256' },
|
|
48
|
+
],
|
|
49
|
+
outputs: [{ name: '', type: 'address' }],
|
|
50
|
+
stateMutability: 'nonpayable',
|
|
51
|
+
},
|
|
52
|
+
];
|
|
53
|
+
/**
|
|
54
|
+
* Encode callData for a single execute call on the smart account.
|
|
55
|
+
*/
|
|
56
|
+
export function encodeCallData(params) {
|
|
57
|
+
return encodeFunctionData({
|
|
58
|
+
abi: EXECUTE_ABI,
|
|
59
|
+
functionName: 'execute',
|
|
60
|
+
args: [params.target, params.value, params.data],
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Encode callData for a batch execute call on the smart account.
|
|
65
|
+
*/
|
|
66
|
+
export function encodeBatchCallData(calls) {
|
|
67
|
+
return encodeFunctionData({
|
|
68
|
+
abi: EXECUTE_BATCH_ABI,
|
|
69
|
+
functionName: 'executeBatch',
|
|
70
|
+
args: [calls],
|
|
71
|
+
});
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* Encode initCode for first-time account deployment.
|
|
75
|
+
* Format: factory address (20 bytes) + factory.createAccount(owner, salt) calldata
|
|
76
|
+
*
|
|
77
|
+
* @param factory - The factory contract address
|
|
78
|
+
* @param owner - The initial owner/signer address
|
|
79
|
+
* @param salt - Deployment salt for CREATE2
|
|
80
|
+
*/
|
|
81
|
+
export function encodeInitCode(params) {
|
|
82
|
+
const createAccountData = encodeFunctionData({
|
|
83
|
+
abi: CREATE_ACCOUNT_ABI,
|
|
84
|
+
functionName: 'createAccount',
|
|
85
|
+
args: [params.owner, params.salt],
|
|
86
|
+
});
|
|
87
|
+
return concat([params.factory, createAccountData]);
|
|
88
|
+
}
|
|
89
|
+
/**
|
|
90
|
+
* Encode arbitrary function call data using an ABI.
|
|
91
|
+
*/
|
|
92
|
+
export function encodeCall(params) {
|
|
93
|
+
return encodeFunctionData({
|
|
94
|
+
abi: params.abi,
|
|
95
|
+
functionName: params.functionName,
|
|
96
|
+
args: params.args ?? [],
|
|
97
|
+
});
|
|
98
|
+
}
|
|
99
|
+
//# sourceMappingURL=encoding.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"encoding.js","sourceRoot":"","sources":["../../src/userop/encoding.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EACL,kBAAkB,EAElB,MAAM,GAEP,MAAM,MAAM,CAAC;AAGd,yCAAyC;AACzC,MAAM,WAAW,GAAG;IAClB;QACE,IAAI,EAAE,SAAS;QACf,IAAI,EAAE,UAAU;QAChB,MAAM,EAAE;YACN,EAAE,IAAI,EAAE,QAAQ,EAAE,IAAI,EAAE,SAAS,EAAE;YACnC,EAAE,IAAI,EAAE,OAAO,EAAE,IAAI,EAAE,SAAS,EAAE;YAClC,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,OAAO,EAAE;SAChC;QACD,OAAO,EAAE,EAAE;QACX,eAAe,EAAE,SAAS;KAC3B;CACO,CAAC;AAEX,8CAA8C;AAC9C,MAAM,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;;;;GAOG;AACH,MAAM,UAAU,cAAc,CAAC,MAI9B;IACC,MAAM,iBAAiB,GAAG,kBAAkB,CAAC;QAC3C,GAAG,EAAE,kBAAkB;QACvB,YAAY,EAAE,eAAe;QAC7B,IAAI,EAAE,CAAC,MAAM,CAAC,KAAK,EAAE,MAAM,CAAC,IAAI,CAAC;KAClC,CAAC,CAAC;IAEH,OAAO,MAAM,CAAC,CAAC,MAAM,CAAC,OAAO,EAAE,iBAAiB,CAAC,CAAC,CAAC;AACrD,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,UAAU,CAAC,MAI1B;IACC,OAAO,kBAAkB,CAAC;QACxB,GAAG,EAAE,MAAM,CAAC,GAAG;QACf,YAAY,EAAE,MAAM,CAAC,YAAY;QACjC,IAAI,EAAE,MAAM,CAAC,IAAI,IAAI,EAAE;KACxB,CAAC,CAAC;AACL,CAAC"}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Gas estimation with safety margins.
|
|
3
|
+
* Corresponds to SPEC-013 Section 5.2, CLAUDE.md critical constants.
|
|
4
|
+
*
|
|
5
|
+
* Safety margins: 130% on gas limits, 120% on fee estimates.
|
|
6
|
+
*/
|
|
7
|
+
import type { UserOperation, Hex } from '../types.js';
|
|
8
|
+
import { BundlerClient } from '../transport/bundler.js';
|
|
9
|
+
/**
|
|
10
|
+
* Apply the 130% gas safety margin to a value.
|
|
11
|
+
*/
|
|
12
|
+
export declare function applyGasSafetyMargin(value: bigint): bigint;
|
|
13
|
+
/**
|
|
14
|
+
* Apply the 120% fee safety margin to a value.
|
|
15
|
+
*/
|
|
16
|
+
export declare function applyFeeSafetyMargin(value: bigint): bigint;
|
|
17
|
+
/**
|
|
18
|
+
* Estimate gas for a UserOperation using the bundler,
|
|
19
|
+
* then apply safety margins.
|
|
20
|
+
*
|
|
21
|
+
* @param bundler - Bundler RPC client
|
|
22
|
+
* @param userOp - The UserOperation to estimate (can have zero gas fields)
|
|
23
|
+
* @returns UserOperation with gas fields populated and safety margins applied
|
|
24
|
+
*/
|
|
25
|
+
export declare function estimateGas(bundler: BundlerClient, userOp: UserOperation): Promise<UserOperation>;
|
|
26
|
+
/**
|
|
27
|
+
* Estimate current gas fees (maxFeePerGas, maxPriorityFeePerGas)
|
|
28
|
+
* using eth_maxPriorityFeePerGas and eth_gasPrice.
|
|
29
|
+
* Applies 120% fee safety margin.
|
|
30
|
+
*/
|
|
31
|
+
export declare function estimateFees(rpcCall: (method: string, params: unknown[]) => Promise<Hex>): Promise<{
|
|
32
|
+
maxFeePerGas: bigint;
|
|
33
|
+
maxPriorityFeePerGas: bigint;
|
|
34
|
+
}>;
|
|
35
|
+
//# sourceMappingURL=gas.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"gas.d.ts","sourceRoot":"","sources":["../../src/userop/gas.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAGH,OAAO,KAAK,EAAE,aAAa,EAAE,GAAG,EAAE,MAAM,aAAa,CAAC;AACtD,OAAO,EAAE,aAAa,EAAE,MAAM,yBAAyB,CAAC;AAQxD;;GAEG;AACH,wBAAgB,oBAAoB,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAE1D;AAED;;GAEG;AACH,wBAAgB,oBAAoB,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAE1D;AAED;;;;;;;GAOG;AACH,wBAAsB,WAAW,CAC/B,OAAO,EAAE,aAAa,EACtB,MAAM,EAAE,aAAa,GACpB,OAAO,CAAC,aAAa,CAAC,CASxB;AAED;;;;GAIG;AACH,wBAAsB,YAAY,CAChC,OAAO,EAAE,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,KAAK,OAAO,CAAC,GAAG,CAAC,GAC3D,OAAO,CAAC;IAAE,YAAY,EAAE,MAAM,CAAC;IAAC,oBAAoB,EAAE,MAAM,CAAA;CAAE,CAAC,CAajE"}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Gas estimation with safety margins.
|
|
3
|
+
* Corresponds to SPEC-013 Section 5.2, CLAUDE.md critical constants.
|
|
4
|
+
*
|
|
5
|
+
* Safety margins: 130% on gas limits, 120% on fee estimates.
|
|
6
|
+
*/
|
|
7
|
+
/**
|
|
8
|
+
* Apply the 130% gas safety margin to a value.
|
|
9
|
+
*/
|
|
10
|
+
export function applyGasSafetyMargin(value) {
|
|
11
|
+
return (value * 130n) / 100n;
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Apply the 120% fee safety margin to a value.
|
|
15
|
+
*/
|
|
16
|
+
export function applyFeeSafetyMargin(value) {
|
|
17
|
+
return (value * 120n) / 100n;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Estimate gas for a UserOperation using the bundler,
|
|
21
|
+
* then apply safety margins.
|
|
22
|
+
*
|
|
23
|
+
* @param bundler - Bundler RPC client
|
|
24
|
+
* @param userOp - The UserOperation to estimate (can have zero gas fields)
|
|
25
|
+
* @returns UserOperation with gas fields populated and safety margins applied
|
|
26
|
+
*/
|
|
27
|
+
export async function estimateGas(bundler, userOp) {
|
|
28
|
+
const estimate = await bundler.estimateUserOperationGas(userOp);
|
|
29
|
+
return {
|
|
30
|
+
...userOp,
|
|
31
|
+
preVerificationGas: applyGasSafetyMargin(BigInt(estimate.preVerificationGas)),
|
|
32
|
+
verificationGasLimit: applyGasSafetyMargin(BigInt(estimate.verificationGasLimit)),
|
|
33
|
+
callGasLimit: applyGasSafetyMargin(BigInt(estimate.callGasLimit)),
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Estimate current gas fees (maxFeePerGas, maxPriorityFeePerGas)
|
|
38
|
+
* using eth_maxPriorityFeePerGas and eth_gasPrice.
|
|
39
|
+
* Applies 120% fee safety margin.
|
|
40
|
+
*/
|
|
41
|
+
export async function estimateFees(rpcCall) {
|
|
42
|
+
const [gasPriceHex, priorityFeeHex] = await Promise.all([
|
|
43
|
+
rpcCall('eth_gasPrice', []),
|
|
44
|
+
rpcCall('eth_maxPriorityFeePerGas', []).catch(() => '0x0'),
|
|
45
|
+
]);
|
|
46
|
+
const gasPrice = BigInt(gasPriceHex);
|
|
47
|
+
const priorityFee = BigInt(priorityFeeHex);
|
|
48
|
+
return {
|
|
49
|
+
maxFeePerGas: applyFeeSafetyMargin(gasPrice),
|
|
50
|
+
maxPriorityFeePerGas: applyFeeSafetyMargin(priorityFee),
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
//# sourceMappingURL=gas.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"gas.js","sourceRoot":"","sources":["../../src/userop/gas.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAYH;;GAEG;AACH,MAAM,UAAU,oBAAoB,CAAC,KAAa;IAChD,OAAO,CAAC,KAAK,GAAG,IAAI,CAAC,GAAG,IAAI,CAAC;AAC/B,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,oBAAoB,CAAC,KAAa;IAChD,OAAO,CAAC,KAAK,GAAG,IAAI,CAAC,GAAG,IAAI,CAAC;AAC/B,CAAC;AAED;;;;;;;GAOG;AACH,MAAM,CAAC,KAAK,UAAU,WAAW,CAC/B,OAAsB,EACtB,MAAqB;IAErB,MAAM,QAAQ,GAAG,MAAM,OAAO,CAAC,wBAAwB,CAAC,MAAM,CAAC,CAAC;IAEhE,OAAO;QACL,GAAG,MAAM;QACT,kBAAkB,EAAE,oBAAoB,CAAC,MAAM,CAAC,QAAQ,CAAC,kBAAkB,CAAC,CAAC;QAC7E,oBAAoB,EAAE,oBAAoB,CAAC,MAAM,CAAC,QAAQ,CAAC,oBAAoB,CAAC,CAAC;QACjF,YAAY,EAAE,oBAAoB,CAAC,MAAM,CAAC,QAAQ,CAAC,YAAY,CAAC,CAAC;KAClE,CAAC;AACJ,CAAC;AAED;;;;GAIG;AACH,MAAM,CAAC,KAAK,UAAU,YAAY,CAChC,OAA4D;IAE5D,MAAM,CAAC,WAAW,EAAE,cAAc,CAAC,GAAG,MAAM,OAAO,CAAC,GAAG,CAAC;QACtD,OAAO,CAAC,cAAc,EAAE,EAAE,CAAC;QAC3B,OAAO,CAAC,0BAA0B,EAAE,EAAE,CAAC,CAAC,KAAK,CAAC,GAAG,EAAE,CAAC,KAAY,CAAC;KAClE,CAAC,CAAC;IAEH,MAAM,QAAQ,GAAG,MAAM,CAAC,WAAW,CAAC,CAAC;IACrC,MAAM,WAAW,GAAG,MAAM,CAAC,cAAc,CAAC,CAAC;IAE3C,OAAO;QACL,YAAY,EAAE,oBAAoB,CAAC,QAAQ,CAAC;QAC5C,oBAAoB,EAAE,oBAAoB,CAAC,WAAW,CAAC;KACxD,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* UserOperation hash computation.
|
|
3
|
+
* CRITICAL: Must match EntryPoint.getUserOpHash() exactly.
|
|
4
|
+
*
|
|
5
|
+
* Corresponds to SPEC-013 Section 5.3, SPEC-002, SPEC-004.
|
|
6
|
+
*
|
|
7
|
+
* Algorithm:
|
|
8
|
+
* 1. Pack all fields except signature
|
|
9
|
+
* 2. Hash variable-length fields individually: keccak256(initCode), keccak256(callData), keccak256(paymasterAndData)
|
|
10
|
+
* 3. keccak256(packed) -> innerHash
|
|
11
|
+
* 4. keccak256(abi.encode(innerHash, entryPoint, chainId)) -> userOpHash
|
|
12
|
+
*/
|
|
13
|
+
import type { Address, Hex, UserOperation } from '../types.js';
|
|
14
|
+
/**
|
|
15
|
+
* Pack a UserOperation for hashing (step 1-2).
|
|
16
|
+
* Variable-length fields (initCode, callData, paymasterAndData) are individually hashed.
|
|
17
|
+
* All other fields are ABI-encoded directly.
|
|
18
|
+
*/
|
|
19
|
+
export declare function packUserOp(userOp: UserOperation): Hex;
|
|
20
|
+
/**
|
|
21
|
+
* Compute the UserOperation hash exactly as EntryPoint.getUserOpHash() does.
|
|
22
|
+
*
|
|
23
|
+
* @param userOp - The UserOperation to hash (signature field is ignored)
|
|
24
|
+
* @param entryPoint - The EntryPoint contract address
|
|
25
|
+
* @param chainId - The numeric chain ID
|
|
26
|
+
* @returns The 32-byte hash that signers must sign
|
|
27
|
+
*
|
|
28
|
+
* @example
|
|
29
|
+
* ```ts
|
|
30
|
+
* const hash = getUserOpHash(userOp, ENTRYPOINT_V06, 42161n);
|
|
31
|
+
* ```
|
|
32
|
+
*/
|
|
33
|
+
export declare function getUserOpHash(userOp: UserOperation, entryPoint: Address, chainId: bigint): Hex;
|
|
34
|
+
//# sourceMappingURL=hash.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"hash.d.ts","sourceRoot":"","sources":["../../src/userop/hash.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAOH,OAAO,KAAK,EAAE,OAAO,EAAE,GAAG,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAE/D;;;;GAIG;AACH,wBAAgB,UAAU,CAAC,MAAM,EAAE,aAAa,GAAG,GAAG,CAkBrD;AAED;;;;;;;;;;;;GAYG;AACH,wBAAgB,aAAa,CAC3B,MAAM,EAAE,aAAa,EACrB,UAAU,EAAE,OAAO,EACnB,OAAO,EAAE,MAAM,GACd,GAAG,CAcL"}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* UserOperation hash computation.
|
|
3
|
+
* CRITICAL: Must match EntryPoint.getUserOpHash() exactly.
|
|
4
|
+
*
|
|
5
|
+
* Corresponds to SPEC-013 Section 5.3, SPEC-002, SPEC-004.
|
|
6
|
+
*
|
|
7
|
+
* Algorithm:
|
|
8
|
+
* 1. Pack all fields except signature
|
|
9
|
+
* 2. Hash variable-length fields individually: keccak256(initCode), keccak256(callData), keccak256(paymasterAndData)
|
|
10
|
+
* 3. keccak256(packed) -> innerHash
|
|
11
|
+
* 4. keccak256(abi.encode(innerHash, entryPoint, chainId)) -> userOpHash
|
|
12
|
+
*/
|
|
13
|
+
import { keccak256, encodeAbiParameters, parseAbiParameters, } from 'viem';
|
|
14
|
+
/**
|
|
15
|
+
* Pack a UserOperation for hashing (step 1-2).
|
|
16
|
+
* Variable-length fields (initCode, callData, paymasterAndData) are individually hashed.
|
|
17
|
+
* All other fields are ABI-encoded directly.
|
|
18
|
+
*/
|
|
19
|
+
export function packUserOp(userOp) {
|
|
20
|
+
return encodeAbiParameters(parseAbiParameters('address, uint256, bytes32, bytes32, uint256, uint256, uint256, uint256, uint256, bytes32'), [
|
|
21
|
+
userOp.sender,
|
|
22
|
+
userOp.nonce,
|
|
23
|
+
keccak256(userOp.initCode), // hash variable-length initCode
|
|
24
|
+
keccak256(userOp.callData), // hash variable-length callData
|
|
25
|
+
userOp.callGasLimit,
|
|
26
|
+
userOp.verificationGasLimit,
|
|
27
|
+
userOp.preVerificationGas,
|
|
28
|
+
userOp.maxFeePerGas,
|
|
29
|
+
userOp.maxPriorityFeePerGas,
|
|
30
|
+
keccak256(userOp.paymasterAndData), // hash variable-length paymasterAndData
|
|
31
|
+
]);
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Compute the UserOperation hash exactly as EntryPoint.getUserOpHash() does.
|
|
35
|
+
*
|
|
36
|
+
* @param userOp - The UserOperation to hash (signature field is ignored)
|
|
37
|
+
* @param entryPoint - The EntryPoint contract address
|
|
38
|
+
* @param chainId - The numeric chain ID
|
|
39
|
+
* @returns The 32-byte hash that signers must sign
|
|
40
|
+
*
|
|
41
|
+
* @example
|
|
42
|
+
* ```ts
|
|
43
|
+
* const hash = getUserOpHash(userOp, ENTRYPOINT_V06, 42161n);
|
|
44
|
+
* ```
|
|
45
|
+
*/
|
|
46
|
+
export function getUserOpHash(userOp, entryPoint, chainId) {
|
|
47
|
+
// Step 1-2: Pack with individually-hashed variable-length fields
|
|
48
|
+
const packed = packUserOp(userOp);
|
|
49
|
+
// Step 3: Hash the packed data
|
|
50
|
+
const innerHash = keccak256(packed);
|
|
51
|
+
// Step 4: Encode with entryPoint and chainId, then hash again
|
|
52
|
+
const encoded = encodeAbiParameters(parseAbiParameters('bytes32, address, uint256'), [innerHash, entryPoint, chainId]);
|
|
53
|
+
return keccak256(encoded);
|
|
54
|
+
}
|
|
55
|
+
//# sourceMappingURL=hash.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"hash.js","sourceRoot":"","sources":["../../src/userop/hash.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAEH,OAAO,EACL,SAAS,EACT,mBAAmB,EACnB,kBAAkB,GACnB,MAAM,MAAM,CAAC;AAGd;;;;GAIG;AACH,MAAM,UAAU,UAAU,CAAC,MAAqB;IAC9C,OAAO,mBAAmB,CACxB,kBAAkB,CAChB,0FAA0F,CAC3F,EACD;QACE,MAAM,CAAC,MAAM;QACb,MAAM,CAAC,KAAK;QACZ,SAAS,CAAC,MAAM,CAAC,QAAQ,CAAC,EAAY,gCAAgC;QACtE,SAAS,CAAC,MAAM,CAAC,QAAQ,CAAC,EAAa,gCAAgC;QACvE,MAAM,CAAC,YAAY;QACnB,MAAM,CAAC,oBAAoB;QAC3B,MAAM,CAAC,kBAAkB;QACzB,MAAM,CAAC,YAAY;QACnB,MAAM,CAAC,oBAAoB;QAC3B,SAAS,CAAC,MAAM,CAAC,gBAAgB,CAAC,EAAK,wCAAwC;KAChF,CACF,CAAC;AACJ,CAAC;AAED;;;;;;;;;;;;GAYG;AACH,MAAM,UAAU,aAAa,CAC3B,MAAqB,EACrB,UAAmB,EACnB,OAAe;IAEf,iEAAiE;IACjE,MAAM,MAAM,GAAG,UAAU,CAAC,MAAM,CAAC,CAAC;IAElC,+BAA+B;IAC/B,MAAM,SAAS,GAAG,SAAS,CAAC,MAAM,CAAC,CAAC;IAEpC,8DAA8D;IAC9D,MAAM,OAAO,GAAG,mBAAmB,CACjC,kBAAkB,CAAC,2BAA2B,CAAC,EAC/C,CAAC,SAAS,EAAE,UAAU,EAAE,OAAO,CAAC,CACjC,CAAC;IAEF,OAAO,SAAS,CAAC,OAAO,CAAC,CAAC;AAC5B,CAAC"}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 2D nonce management for parallel transaction streams.
|
|
3
|
+
* Corresponds to SPEC-013 Section 5.5.
|
|
4
|
+
*
|
|
5
|
+
* Nonce encoding: uint256 nonce = (uint256(key) << 64) | sequence
|
|
6
|
+
* - key=0: user transactions (default)
|
|
7
|
+
* - key=1+: session keys and parallel streams
|
|
8
|
+
* Each key has an independent sequential counter.
|
|
9
|
+
*/
|
|
10
|
+
import type { Address, Hex } from '../types.js';
|
|
11
|
+
/**
|
|
12
|
+
* Manages 2D nonces for parallel UserOp streams.
|
|
13
|
+
* Each nonce key has an independent sequence counter, allowing
|
|
14
|
+
* multiple parallel transaction streams without blocking.
|
|
15
|
+
*/
|
|
16
|
+
export declare class NonceManager {
|
|
17
|
+
private readonly entryPoint;
|
|
18
|
+
private readonly rpcCall;
|
|
19
|
+
private cache;
|
|
20
|
+
constructor(entryPoint: Address, rpcCall: (method: string, params: unknown[]) => Promise<Hex>);
|
|
21
|
+
/**
|
|
22
|
+
* Get the next nonce for a wallet address and nonce key.
|
|
23
|
+
*
|
|
24
|
+
* @param sender - The smart wallet address
|
|
25
|
+
* @param key - The nonce key (0 = default user txs, 1+ = session keys)
|
|
26
|
+
* @returns The full 256-bit nonce (key << 64 | sequence)
|
|
27
|
+
*/
|
|
28
|
+
get(sender: Address, key?: bigint): Promise<bigint>;
|
|
29
|
+
/**
|
|
30
|
+
* Encode a 2D nonce from key and sequence.
|
|
31
|
+
* nonce = (key << 64) | sequence
|
|
32
|
+
*/
|
|
33
|
+
static encode(key: bigint, sequence: bigint): bigint;
|
|
34
|
+
/**
|
|
35
|
+
* Decode a 2D nonce into key and sequence.
|
|
36
|
+
*/
|
|
37
|
+
static decode(nonce: bigint): {
|
|
38
|
+
key: bigint;
|
|
39
|
+
sequence: bigint;
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Encode a 2D nonce: (key << 64) | sequence
|
|
44
|
+
*/
|
|
45
|
+
export declare function encodeNonce(key: bigint, sequence: bigint): bigint;
|
|
46
|
+
/**
|
|
47
|
+
* Decode a 2D nonce into key and sequence components.
|
|
48
|
+
*/
|
|
49
|
+
export declare function decodeNonce(nonce: bigint): {
|
|
50
|
+
key: bigint;
|
|
51
|
+
sequence: bigint;
|
|
52
|
+
};
|
|
53
|
+
//# sourceMappingURL=nonce.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"nonce.d.ts","sourceRoot":"","sources":["../../src/userop/nonce.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,KAAK,EAAE,OAAO,EAAE,GAAG,EAAE,MAAM,aAAa,CAAC;AAGhD;;;;GAIG;AACH,qBAAa,YAAY;IAIrB,OAAO,CAAC,QAAQ,CAAC,UAAU;IAC3B,OAAO,CAAC,QAAQ,CAAC,OAAO;IAJ1B,OAAO,CAAC,KAAK,CAA6B;gBAGvB,UAAU,EAAE,OAAO,EACnB,OAAO,EAAE,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,KAAK,OAAO,CAAC,GAAG,CAAC;IAG/E;;;;;;OAMG;IACG,GAAG,CAAC,MAAM,EAAE,OAAO,EAAE,GAAG,GAAE,MAAW,GAAG,OAAO,CAAC,MAAM,CAAC;IAa7D;;;OAGG;IACH,MAAM,CAAC,MAAM,CAAC,GAAG,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,GAAG,MAAM;IAIpD;;OAEG;IACH,MAAM,CAAC,MAAM,CAAC,KAAK,EAAE,MAAM,GAAG;QAAE,GAAG,EAAE,MAAM,CAAC;QAAC,QAAQ,EAAE,MAAM,CAAA;KAAE;CAGhE;AAED;;GAEG;AACH,wBAAgB,WAAW,CAAC,GAAG,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,GAAG,MAAM,CAEjE;AAED;;GAEG;AACH,wBAAgB,WAAW,CAAC,KAAK,EAAE,MAAM,GAAG;IAAE,GAAG,EAAE,MAAM,CAAC;IAAC,QAAQ,EAAE,MAAM,CAAA;CAAE,CAK5E"}
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 2D nonce management for parallel transaction streams.
|
|
3
|
+
* Corresponds to SPEC-013 Section 5.5.
|
|
4
|
+
*
|
|
5
|
+
* Nonce encoding: uint256 nonce = (uint256(key) << 64) | sequence
|
|
6
|
+
* - key=0: user transactions (default)
|
|
7
|
+
* - key=1+: session keys and parallel streams
|
|
8
|
+
* Each key has an independent sequential counter.
|
|
9
|
+
*/
|
|
10
|
+
/**
|
|
11
|
+
* Manages 2D nonces for parallel UserOp streams.
|
|
12
|
+
* Each nonce key has an independent sequence counter, allowing
|
|
13
|
+
* multiple parallel transaction streams without blocking.
|
|
14
|
+
*/
|
|
15
|
+
export class NonceManager {
|
|
16
|
+
entryPoint;
|
|
17
|
+
rpcCall;
|
|
18
|
+
cache = new Map();
|
|
19
|
+
constructor(entryPoint, rpcCall) {
|
|
20
|
+
this.entryPoint = entryPoint;
|
|
21
|
+
this.rpcCall = rpcCall;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Get the next nonce for a wallet address and nonce key.
|
|
25
|
+
*
|
|
26
|
+
* @param sender - The smart wallet address
|
|
27
|
+
* @param key - The nonce key (0 = default user txs, 1+ = session keys)
|
|
28
|
+
* @returns The full 256-bit nonce (key << 64 | sequence)
|
|
29
|
+
*/
|
|
30
|
+
async get(sender, key = 0n) {
|
|
31
|
+
const nonceHex = await this.rpcCall('eth_call', [
|
|
32
|
+
{
|
|
33
|
+
to: this.entryPoint,
|
|
34
|
+
data: encodeGetNonce(sender, key),
|
|
35
|
+
},
|
|
36
|
+
'latest',
|
|
37
|
+
]);
|
|
38
|
+
const sequence = BigInt(nonceHex);
|
|
39
|
+
return encodeNonce(key, sequence);
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Encode a 2D nonce from key and sequence.
|
|
43
|
+
* nonce = (key << 64) | sequence
|
|
44
|
+
*/
|
|
45
|
+
static encode(key, sequence) {
|
|
46
|
+
return encodeNonce(key, sequence);
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Decode a 2D nonce into key and sequence.
|
|
50
|
+
*/
|
|
51
|
+
static decode(nonce) {
|
|
52
|
+
return decodeNonce(nonce);
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* Encode a 2D nonce: (key << 64) | sequence
|
|
57
|
+
*/
|
|
58
|
+
export function encodeNonce(key, sequence) {
|
|
59
|
+
return (key << 64n) | (sequence & 0xffffffffffffffffn);
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* Decode a 2D nonce into key and sequence components.
|
|
63
|
+
*/
|
|
64
|
+
export function decodeNonce(nonce) {
|
|
65
|
+
return {
|
|
66
|
+
key: nonce >> 64n,
|
|
67
|
+
sequence: nonce & 0xffffffffffffffffn,
|
|
68
|
+
};
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* Encode the EntryPoint.getNonce(sender, key) call.
|
|
72
|
+
* Selector: 0x35567e1a
|
|
73
|
+
*/
|
|
74
|
+
function encodeGetNonce(sender, key) {
|
|
75
|
+
const senderPadded = sender.slice(2).padStart(64, '0');
|
|
76
|
+
const keyPadded = key.toString(16).padStart(64, '0');
|
|
77
|
+
return `0x35567e1a${senderPadded}${keyPadded}`;
|
|
78
|
+
}
|
|
79
|
+
//# sourceMappingURL=nonce.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"nonce.js","sourceRoot":"","sources":["../../src/userop/nonce.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAKH;;;;GAIG;AACH,MAAM,OAAO,YAAY;IAIJ;IACA;IAJX,KAAK,GAAG,IAAI,GAAG,EAAkB,CAAC;IAE1C,YACmB,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G,GAAG,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC,QAAQ,CAAC,EAAE,EAAE,GAAG,CAAC,CAAC;IACrD,OAAO,aAAa,YAAY,GAAG,SAAS,EAAE,CAAC;AACjD,CAAC"}
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Wallet factory -- address computation and account deployment.
|
|
3
|
+
* Corresponds to SPEC-013 Section 4, SPEC-001.
|
|
4
|
+
*/
|
|
5
|
+
import type { Address, WalletInfo, ChainId } from '../types.js';
|
|
6
|
+
import { ApiClient } from '../transport/api.js';
|
|
7
|
+
/**
|
|
8
|
+
* Computes the counterfactual wallet address using CREATE2 deterministic deployment.
|
|
9
|
+
*
|
|
10
|
+
* address = keccak256(0xff || factory || combinedSalt || keccak256(initCode))[12:]
|
|
11
|
+
* combinedSalt = keccak256(abi.encode(owner, salt))
|
|
12
|
+
*/
|
|
13
|
+
export declare function computeWalletAddress(factory: Address, implementation: Address, owner: Address, salt: bigint): Address;
|
|
14
|
+
/**
|
|
15
|
+
* Wallet factory module.
|
|
16
|
+
* Handles counterfactual address generation and account state queries.
|
|
17
|
+
*/
|
|
18
|
+
export declare class WalletFactory {
|
|
19
|
+
private readonly api;
|
|
20
|
+
private readonly chain;
|
|
21
|
+
constructor(api: ApiClient, chain: ChainId);
|
|
22
|
+
/**
|
|
23
|
+
* Get or compute wallet address for an owner.
|
|
24
|
+
* If the wallet exists on the platform, returns full info including deployment status.
|
|
25
|
+
*/
|
|
26
|
+
getAddress(params: {
|
|
27
|
+
owner: Address;
|
|
28
|
+
salt?: bigint;
|
|
29
|
+
}): Promise<WalletInfo>;
|
|
30
|
+
/**
|
|
31
|
+
* Get the on-chain state of a deployed wallet.
|
|
32
|
+
*/
|
|
33
|
+
getState(address: Address): Promise<{
|
|
34
|
+
address: Address;
|
|
35
|
+
deployed: boolean;
|
|
36
|
+
owner: Address;
|
|
37
|
+
balance: string;
|
|
38
|
+
entryPointDeposit: string;
|
|
39
|
+
nonce: {
|
|
40
|
+
key: string;
|
|
41
|
+
sequence: string;
|
|
42
|
+
};
|
|
43
|
+
modules: Array<{
|
|
44
|
+
moduleId: number;
|
|
45
|
+
type: string;
|
|
46
|
+
signer: Address;
|
|
47
|
+
installedAt: number;
|
|
48
|
+
expiresAt?: number;
|
|
49
|
+
}>;
|
|
50
|
+
frozen: boolean;
|
|
51
|
+
}>;
|
|
52
|
+
/**
|
|
53
|
+
* List installed validation modules on a wallet.
|
|
54
|
+
*/
|
|
55
|
+
getModules(address: Address): Promise<{
|
|
56
|
+
moduleId: number;
|
|
57
|
+
type: string;
|
|
58
|
+
signer: Address;
|
|
59
|
+
installedAt: number;
|
|
60
|
+
expiresAt?: number;
|
|
61
|
+
}[]>;
|
|
62
|
+
}
|
|
63
|
+
//# sourceMappingURL=factory.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"factory.d.ts","sourceRoot":"","sources":["../../src/wallet/factory.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAWH,OAAO,KAAK,EAAE,OAAO,EAAO,UAAU,EAAE,OAAO,EAAE,MAAM,aAAa,CAAC;AACrE,OAAO,EAAE,SAAS,EAAE,MAAM,qBAAqB,CAAC;AAEhD;;;;;GAKG;AACH,wBAAgB,oBAAoB,CAClC,OAAO,EAAE,OAAO,EAChB,cAAc,EAAE,OAAO,EACvB,KAAK,EAAE,OAAO,EACd,IAAI,EAAE,MAAM,GACX,OAAO,CAqBT;AAED;;;GAGG;AACH,qBAAa,aAAa;IAEtB,OAAO,CAAC,QAAQ,CAAC,GAAG;IACpB,OAAO,CAAC,QAAQ,CAAC,KAAK;gBADL,GAAG,EAAE,SAAS,EACd,KAAK,EAAE,OAAO;IAGjC;;;OAGG;IACG,UAAU,CAAC,MAAM,EAAE;QAAE,KAAK,EAAE,OAAO,CAAC;QAAC,IAAI,CAAC,EAAE,MAAM,CAAA;KAAE,GAAG,OAAO,CAAC,UAAU,CAAC;IAShF;;OAEG;IACG,QAAQ,CAAC,OAAO,EAAE,OAAO;iBAElB,OAAO;kBACN,OAAO;eACV,OAAO;iBACL,MAAM;2BACI,MAAM;eAClB;YAAE,GAAG,EAAE,MAAM,CAAC;YAAC,QAAQ,EAAE,MAAM,CAAA;SAAE;iBAC/B,KAAK,CAAC;YACb,QAAQ,EAAE,MAAM,CAAC;YACjB,IAAI,EAAE,MAAM,CAAC;YACb,MAAM,EAAE,OAAO,CAAC;YAChB,WAAW,EAAE,MAAM,CAAC;YACpB,SAAS,CAAC,EAAE,MAAM,CAAC;SACpB,CAAC;gBACM,OAAO;;IAInB;;OAEG;IACG,UAAU,CAAC,OAAO,EAAE,OAAO;kBAGjB,MAAM;cACV,MAAM;gBACJ,OAAO;qBACF,MAAM;oBACP,MAAM;;CAIzB"}
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Wallet factory -- address computation and account deployment.
|
|
3
|
+
* Corresponds to SPEC-013 Section 4, SPEC-001.
|
|
4
|
+
*/
|
|
5
|
+
import { keccak256, encodePacked, encodeAbiParameters, getContractAddress, parseAbiParameters, } from 'viem';
|
|
6
|
+
/**
|
|
7
|
+
* Computes the counterfactual wallet address using CREATE2 deterministic deployment.
|
|
8
|
+
*
|
|
9
|
+
* address = keccak256(0xff || factory || combinedSalt || keccak256(initCode))[12:]
|
|
10
|
+
* combinedSalt = keccak256(abi.encode(owner, salt))
|
|
11
|
+
*/
|
|
12
|
+
export function computeWalletAddress(factory, implementation, owner, salt) {
|
|
13
|
+
const combinedSalt = keccak256(encodeAbiParameters(parseAbiParameters('address, uint256'), [owner, salt]));
|
|
14
|
+
// Minimal proxy initCode (ERC-1167 clone pointing to implementation)
|
|
15
|
+
const proxyBytecode = encodePacked(['bytes', 'bytes20', 'bytes'], [
|
|
16
|
+
'0x3d602d80600a3d3981f3363d3d373d3d3d363d73',
|
|
17
|
+
implementation,
|
|
18
|
+
'0x5af43d82803e903d91602b57fd5bf3',
|
|
19
|
+
]);
|
|
20
|
+
return getContractAddress({
|
|
21
|
+
bytecode: proxyBytecode,
|
|
22
|
+
from: factory,
|
|
23
|
+
opcode: 'CREATE2',
|
|
24
|
+
salt: combinedSalt,
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Wallet factory module.
|
|
29
|
+
* Handles counterfactual address generation and account state queries.
|
|
30
|
+
*/
|
|
31
|
+
export class WalletFactory {
|
|
32
|
+
api;
|
|
33
|
+
chain;
|
|
34
|
+
constructor(api, chain) {
|
|
35
|
+
this.api = api;
|
|
36
|
+
this.chain = chain;
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Get or compute wallet address for an owner.
|
|
40
|
+
* If the wallet exists on the platform, returns full info including deployment status.
|
|
41
|
+
*/
|
|
42
|
+
async getAddress(params) {
|
|
43
|
+
const result = await this.api.post('/wallets', {
|
|
44
|
+
owner: params.owner,
|
|
45
|
+
salt: (params.salt ?? 0n).toString(),
|
|
46
|
+
chain: this.chain,
|
|
47
|
+
});
|
|
48
|
+
return result;
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Get the on-chain state of a deployed wallet.
|
|
52
|
+
*/
|
|
53
|
+
async getState(address) {
|
|
54
|
+
return this.api.get(`/wallets/${address}`);
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* List installed validation modules on a wallet.
|
|
58
|
+
*/
|
|
59
|
+
async getModules(address) {
|
|
60
|
+
return this.api.get(`/wallets/${address}/modules`);
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
//# sourceMappingURL=factory.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"factory.js","sourceRoot":"","sources":["../../src/wallet/factory.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EACL,SAAS,EACT,YAAY,EACZ,mBAAmB,EACnB,kBAAkB,EAClB,kBAAkB,GAGnB,MAAM,MAAM,CAAC;AAId;;;;;GAKG;AACH,MAAM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AQjB,YAAY,OAAO,UAAU,CAAC,CAAC;IACnC,CAAC;CACF"}
|
package/package.json
ADDED
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@aspect-wallet/sdk",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "TypeScript SDK for ERC-4337 Account Abstraction smart wallets. Gasless transactions, social logins, passkeys, session keys, multi-factor auth, and account recovery.",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "./dist/index.js",
|
|
7
|
+
"types": "./dist/index.d.ts",
|
|
8
|
+
"exports": {
|
|
9
|
+
".": {
|
|
10
|
+
"import": "./dist/index.js",
|
|
11
|
+
"types": "./dist/index.d.ts"
|
|
12
|
+
},
|
|
13
|
+
"./types": {
|
|
14
|
+
"import": "./dist/types.js",
|
|
15
|
+
"types": "./dist/types.d.ts"
|
|
16
|
+
}
|
|
17
|
+
},
|
|
18
|
+
"files": [
|
|
19
|
+
"dist",
|
|
20
|
+
"README.md",
|
|
21
|
+
"LICENSE",
|
|
22
|
+
"CHANGELOG.md"
|
|
23
|
+
],
|
|
24
|
+
"scripts": {
|
|
25
|
+
"build": "tsc",
|
|
26
|
+
"lint": "eslint src/ --ext .ts",
|
|
27
|
+
"test": "vitest run",
|
|
28
|
+
"test:watch": "vitest",
|
|
29
|
+
"prepublishOnly": "npm run build",
|
|
30
|
+
"prepack": "npm run build"
|
|
31
|
+
},
|
|
32
|
+
"keywords": [
|
|
33
|
+
"erc-4337",
|
|
34
|
+
"account-abstraction",
|
|
35
|
+
"smart-wallet",
|
|
36
|
+
"gasless",
|
|
37
|
+
"paymaster",
|
|
38
|
+
"bundler",
|
|
39
|
+
"useroperation",
|
|
40
|
+
"passkeys",
|
|
41
|
+
"webauthn",
|
|
42
|
+
"session-keys",
|
|
43
|
+
"social-login",
|
|
44
|
+
"turnkey",
|
|
45
|
+
"ethereum",
|
|
46
|
+
"arbitrum",
|
|
47
|
+
"web3"
|
|
48
|
+
],
|
|
49
|
+
"author": "Future CX Lanka",
|
|
50
|
+
"homepage": "https://docs.aspectwallet.com",
|
|
51
|
+
"dependencies": {
|
|
52
|
+
"viem": "^2.21.0"
|
|
53
|
+
},
|
|
54
|
+
"peerDependencies": {
|
|
55
|
+
"viem": "^2.0.0"
|
|
56
|
+
},
|
|
57
|
+
"devDependencies": {
|
|
58
|
+
"@types/node": "^22.0.0",
|
|
59
|
+
"eslint": "^9.0.0",
|
|
60
|
+
"typescript": "^5.6.0",
|
|
61
|
+
"vitest": "^2.1.0"
|
|
62
|
+
},
|
|
63
|
+
"engines": {
|
|
64
|
+
"node": ">=18.0.0"
|
|
65
|
+
},
|
|
66
|
+
"license": "MIT",
|
|
67
|
+
"publishConfig": {
|
|
68
|
+
"access": "public"
|
|
69
|
+
}
|
|
70
|
+
}
|