@account-kit/smart-contracts 4.0.0-alpha.5 → 4.0.0-alpha.7
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/cjs/src/index.d.ts +1 -1
- package/dist/cjs/src/index.js +2 -2
- package/dist/cjs/src/index.js.map +1 -1
- package/dist/cjs/src/light-account/accounts/account.d.ts +5 -6
- package/dist/cjs/src/light-account/accounts/account.js +3 -2
- package/dist/cjs/src/light-account/accounts/account.js.map +1 -1
- package/dist/cjs/src/light-account/accounts/base.d.ts +7 -6
- package/dist/cjs/src/light-account/accounts/base.js +8 -8
- package/dist/cjs/src/light-account/accounts/base.js.map +1 -1
- package/dist/cjs/src/light-account/accounts/multiOwner.d.ts +5 -5
- package/dist/cjs/src/light-account/accounts/multiOwner.js +3 -2
- package/dist/cjs/src/light-account/accounts/multiOwner.js.map +1 -1
- package/dist/cjs/src/light-account/clients/multiOwnerAlchemyClient.d.ts +1 -1
- package/dist/cjs/src/light-account/clients/multiOwnerAlchemyClient.js.map +1 -1
- package/dist/cjs/src/light-account/types.d.ts +23 -31
- package/dist/cjs/src/light-account/types.js.map +1 -1
- package/dist/cjs/src/light-account/utils.d.ts +7 -10
- package/dist/cjs/src/light-account/utils.js +59 -88
- package/dist/cjs/src/light-account/utils.js.map +1 -1
- package/dist/cjs/src/msca/plugins/multisig/middleware.js.map +1 -1
- package/dist/cjs/src/msca/plugins/multisig/utils/formatSignatures.js.map +1 -1
- package/dist/cjs/src/msca/plugins/multisig/utils/splitAggregatedSignature.d.ts +3 -2
- package/dist/cjs/src/msca/plugins/multisig/utils/splitAggregatedSignature.js.map +1 -1
- package/dist/cjs/src/msca/plugins/session-key/permissions.js.map +1 -1
- package/dist/cjs/src/msca/plugins/session-key/signer.js.map +1 -1
- package/dist/cjs/src/msca/utils.js.map +1 -1
- package/dist/esm/src/index.d.ts +1 -1
- package/dist/esm/src/index.js +1 -1
- package/dist/esm/src/index.js.map +1 -1
- package/dist/esm/src/light-account/accounts/account.d.ts +5 -6
- package/dist/esm/src/light-account/accounts/account.js +3 -2
- package/dist/esm/src/light-account/accounts/account.js.map +1 -1
- package/dist/esm/src/light-account/accounts/base.d.ts +7 -6
- package/dist/esm/src/light-account/accounts/base.js +8 -8
- package/dist/esm/src/light-account/accounts/base.js.map +1 -1
- package/dist/esm/src/light-account/accounts/multiOwner.d.ts +5 -5
- package/dist/esm/src/light-account/accounts/multiOwner.js +4 -3
- package/dist/esm/src/light-account/accounts/multiOwner.js.map +1 -1
- package/dist/esm/src/light-account/clients/multiOwnerAlchemyClient.d.ts +1 -1
- package/dist/esm/src/light-account/clients/multiOwnerAlchemyClient.js.map +1 -1
- package/dist/esm/src/light-account/types.d.ts +23 -31
- package/dist/esm/src/light-account/types.js.map +1 -1
- package/dist/esm/src/light-account/utils.d.ts +7 -10
- package/dist/esm/src/light-account/utils.js +57 -85
- package/dist/esm/src/light-account/utils.js.map +1 -1
- package/dist/esm/src/msca/plugins/multisig/middleware.js.map +1 -1
- package/dist/esm/src/msca/plugins/multisig/utils/formatSignatures.js.map +1 -1
- package/dist/esm/src/msca/plugins/multisig/utils/splitAggregatedSignature.d.ts +3 -2
- package/dist/esm/src/msca/plugins/multisig/utils/splitAggregatedSignature.js.map +1 -1
- package/dist/esm/src/msca/plugins/session-key/permissions.js.map +1 -1
- package/dist/esm/src/msca/plugins/session-key/signer.js.map +1 -1
- package/dist/esm/src/msca/utils.js.map +1 -1
- package/dist/types/src/index.d.ts +1 -1
- package/dist/types/src/index.d.ts.map +1 -1
- package/dist/types/src/light-account/accounts/account.d.ts +5 -6
- package/dist/types/src/light-account/accounts/account.d.ts.map +1 -1
- package/dist/types/src/light-account/accounts/base.d.ts +7 -6
- package/dist/types/src/light-account/accounts/base.d.ts.map +1 -1
- package/dist/types/src/light-account/accounts/multiOwner.d.ts +5 -5
- package/dist/types/src/light-account/accounts/multiOwner.d.ts.map +1 -1
- package/dist/types/src/light-account/clients/multiOwnerAlchemyClient.d.ts +1 -1
- package/dist/types/src/light-account/clients/multiOwnerAlchemyClient.d.ts.map +1 -1
- package/dist/types/src/light-account/types.d.ts +23 -118
- package/dist/types/src/light-account/types.d.ts.map +1 -1
- package/dist/types/src/light-account/utils.d.ts +19 -48
- package/dist/types/src/light-account/utils.d.ts.map +1 -1
- package/dist/types/src/msca/plugins/multisig/middleware.d.ts +6 -6
- package/dist/types/src/msca/plugins/multisig/utils/formatSignatures.d.ts +3 -3
- package/dist/types/src/msca/plugins/multisig/utils/splitAggregatedSignature.d.ts +13 -12
- package/dist/types/src/msca/plugins/multisig/utils/splitAggregatedSignature.d.ts.map +1 -1
- package/dist/types/src/msca/plugins/session-key/permissions.d.ts +147 -1
- package/dist/types/src/msca/plugins/session-key/permissions.d.ts.map +1 -1
- package/dist/types/src/msca/plugins/session-key/signer.d.ts +71 -1
- package/dist/types/src/msca/plugins/session-key/signer.d.ts.map +1 -1
- package/dist/types/src/msca/utils.d.ts +6 -6
- package/package.json +6 -5
- package/src/index.ts +1 -1
- package/src/light-account/accounts/account.ts +24 -45
- package/src/light-account/accounts/base.ts +39 -68
- package/src/light-account/accounts/multiOwner.ts +29 -43
- package/src/light-account/clients/multiOwnerAlchemyClient.ts +1 -1
- package/src/light-account/types.ts +31 -188
- package/src/light-account/utils.ts +91 -245
- package/src/msca/plugins/multisig/middleware.ts +6 -6
- package/src/msca/plugins/multisig/utils/formatSignatures.ts +3 -3
- package/src/msca/plugins/multisig/utils/splitAggregatedSignature.ts +15 -12
- package/src/msca/plugins/session-key/permissions.ts +147 -1
- package/src/msca/plugins/session-key/signer.ts +71 -1
- package/src/msca/utils.ts +6 -6
- package/dist/cjs/src/light-account/schema.d.ts +0 -21
- package/dist/cjs/src/light-account/schema.js +0 -30
- package/dist/cjs/src/light-account/schema.js.map +0 -1
- package/dist/esm/src/light-account/schema.d.ts +0 -21
- package/dist/esm/src/light-account/schema.js +0 -27
- package/dist/esm/src/light-account/schema.js.map +0 -1
- package/dist/types/src/light-account/schema.d.ts +0 -22
- package/dist/types/src/light-account/schema.d.ts.map +0 -1
- package/src/light-account/schema.ts +0 -39
|
@@ -1,120 +1,95 @@
|
|
|
1
|
-
import { DefaultFactoryNotDefinedError, toRecord } from "@aa-sdk/core";
|
|
2
|
-
import { arbitrum, arbitrumGoerli, arbitrumSepolia, base, baseGoerli, baseSepolia, fraxtal, fraxtalSepolia, goerli, mainnet, optimism, optimismGoerli, optimismSepolia, polygon, polygonAmoy, polygonMumbai, sepolia, zora, zoraSepolia, } from "@account-kit/infra";
|
|
3
1
|
import { fromHex } from "viem";
|
|
4
|
-
export const supportedChains = [
|
|
5
|
-
mainnet,
|
|
6
|
-
sepolia,
|
|
7
|
-
goerli,
|
|
8
|
-
polygon,
|
|
9
|
-
polygonAmoy,
|
|
10
|
-
polygonMumbai,
|
|
11
|
-
optimism,
|
|
12
|
-
optimismGoerli,
|
|
13
|
-
optimismSepolia,
|
|
14
|
-
arbitrum,
|
|
15
|
-
arbitrumGoerli,
|
|
16
|
-
arbitrumSepolia,
|
|
17
|
-
base,
|
|
18
|
-
baseGoerli,
|
|
19
|
-
baseSepolia,
|
|
20
|
-
fraxtal,
|
|
21
|
-
fraxtalSepolia,
|
|
22
|
-
zora,
|
|
23
|
-
zoraSepolia,
|
|
24
|
-
];
|
|
25
2
|
export const AccountVersionRegistry = {
|
|
26
3
|
LightAccount: {
|
|
27
4
|
"v1.0.1": {
|
|
28
|
-
type: "LightAccount",
|
|
29
|
-
version: "v1.0.1",
|
|
30
|
-
address: toRecord(supportedChains, "id", () => ({
|
|
31
|
-
factory: "0x000000893A26168158fbeaDD9335Be5bC96592E2".toLowerCase(),
|
|
32
|
-
impl: "0xc1b2fc4197c9187853243e6e4eb5a4af8879a1c0".toLowerCase(),
|
|
33
|
-
})),
|
|
34
5
|
entryPointVersion: "0.6.0",
|
|
6
|
+
addresses: {
|
|
7
|
+
default: {
|
|
8
|
+
factory: "0x000000893A26168158fbeaDD9335Be5bC96592E2".toLowerCase(),
|
|
9
|
+
impl: "0xc1b2fc4197c9187853243e6e4eb5a4af8879a1c0".toLowerCase(),
|
|
10
|
+
},
|
|
11
|
+
},
|
|
35
12
|
},
|
|
36
13
|
"v1.0.2": {
|
|
37
|
-
type: "LightAccount",
|
|
38
|
-
version: "v1.0.2",
|
|
39
|
-
address: toRecord(supportedChains, "id", () => ({
|
|
40
|
-
factory: "0x00000055C0b4fA41dde26A74435ff03692292FBD".toLowerCase(),
|
|
41
|
-
impl: "0x5467b1947F47d0646704EB801E075e72aeAe8113".toLowerCase(),
|
|
42
|
-
})),
|
|
43
14
|
entryPointVersion: "0.6.0",
|
|
15
|
+
addresses: {
|
|
16
|
+
default: {
|
|
17
|
+
factory: "0x00000055C0b4fA41dde26A74435ff03692292FBD".toLowerCase(),
|
|
18
|
+
impl: "0x5467b1947F47d0646704EB801E075e72aeAe8113".toLowerCase(),
|
|
19
|
+
},
|
|
20
|
+
},
|
|
44
21
|
},
|
|
45
22
|
"v1.1.0": {
|
|
46
|
-
type: "LightAccount",
|
|
47
|
-
version: "v1.1.0",
|
|
48
|
-
address: toRecord(supportedChains, "id", () => ({
|
|
49
|
-
factory: "0x00004EC70002a32400f8ae005A26081065620D20".toLowerCase(),
|
|
50
|
-
impl: "0xae8c656ad28F2B59a196AB61815C16A0AE1c3cba".toLowerCase(),
|
|
51
|
-
})),
|
|
52
23
|
entryPointVersion: "0.6.0",
|
|
24
|
+
addresses: {
|
|
25
|
+
default: {
|
|
26
|
+
factory: "0x00004EC70002a32400f8ae005A26081065620D20".toLowerCase(),
|
|
27
|
+
impl: "0xae8c656ad28F2B59a196AB61815C16A0AE1c3cba".toLowerCase(),
|
|
28
|
+
},
|
|
29
|
+
},
|
|
53
30
|
},
|
|
54
31
|
"v2.0.0": {
|
|
55
|
-
type: "LightAccount",
|
|
56
|
-
version: "v2.0.0",
|
|
57
|
-
address: toRecord(supportedChains, "id", () => ({
|
|
58
|
-
factory: "0x0000000000400CdFef5E2714E63d8040b700BC24".toLowerCase(),
|
|
59
|
-
impl: "0x8E8e658E22B12ada97B402fF0b044D6A325013C7".toLowerCase(),
|
|
60
|
-
})),
|
|
61
32
|
entryPointVersion: "0.7.0",
|
|
33
|
+
addresses: {
|
|
34
|
+
default: {
|
|
35
|
+
factory: "0x0000000000400CdFef5E2714E63d8040b700BC24".toLowerCase(),
|
|
36
|
+
impl: "0x8E8e658E22B12ada97B402fF0b044D6A325013C7".toLowerCase(),
|
|
37
|
+
},
|
|
38
|
+
},
|
|
62
39
|
},
|
|
63
40
|
},
|
|
64
41
|
MultiOwnerLightAccount: {
|
|
65
42
|
"v2.0.0": {
|
|
66
|
-
type: "MultiOwnerLightAccount",
|
|
67
|
-
version: "v2.0.0",
|
|
68
|
-
address: toRecord(supportedChains, "id", () => ({
|
|
69
|
-
factory: "0x000000000019d2Ee9F2729A65AfE20bb0020AefC".toLowerCase(),
|
|
70
|
-
impl: "0xd2c27F9eE8E4355f71915ffD5568cB3433b6823D".toLowerCase(),
|
|
71
|
-
})),
|
|
72
43
|
entryPointVersion: "0.7.0",
|
|
44
|
+
addresses: {
|
|
45
|
+
default: {
|
|
46
|
+
factory: "0x000000000019d2Ee9F2729A65AfE20bb0020AefC".toLowerCase(),
|
|
47
|
+
impl: "0xd2c27F9eE8E4355f71915ffD5568cB3433b6823D".toLowerCase(),
|
|
48
|
+
},
|
|
49
|
+
},
|
|
73
50
|
},
|
|
74
51
|
},
|
|
75
52
|
};
|
|
76
|
-
export const defaultLightAccountVersion = (
|
|
77
|
-
? "v1.1.0"
|
|
78
|
-
: "v2.0.0");
|
|
53
|
+
export const defaultLightAccountVersion = () => "v2.0.0";
|
|
79
54
|
export const getDefaultLightAccountFactoryAddress = (chain, version) => {
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
throw new DefaultFactoryNotDefinedError("LightAccount", chain, "0.6.0");
|
|
84
|
-
return address.factory;
|
|
55
|
+
return (AccountVersionRegistry.LightAccount[version].addresses.overrides?.[chain.id]
|
|
56
|
+
?.factory ??
|
|
57
|
+
AccountVersionRegistry.LightAccount[version].addresses.default.factory);
|
|
85
58
|
};
|
|
86
59
|
export const getDefaultMultiOwnerLightAccountFactoryAddress = (chain, version) => {
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
return address.factory;
|
|
60
|
+
return (AccountVersionRegistry.MultiOwnerLightAccount[version].addresses
|
|
61
|
+
.overrides?.[chain.id]?.factory ??
|
|
62
|
+
AccountVersionRegistry.MultiOwnerLightAccount[version].addresses.default
|
|
63
|
+
.factory);
|
|
92
64
|
};
|
|
93
65
|
export const LightAccountUnsupported1271Impls = [
|
|
94
66
|
AccountVersionRegistry.LightAccount["v1.0.1"],
|
|
95
67
|
AccountVersionRegistry.LightAccount["v1.0.2"],
|
|
96
68
|
];
|
|
97
|
-
export const LightAccountUnsupported1271Factories = new Set(LightAccountUnsupported1271Impls.map((x) =>
|
|
98
|
-
|
|
69
|
+
export const LightAccountUnsupported1271Factories = new Set(LightAccountUnsupported1271Impls.map((x) => [
|
|
70
|
+
x.addresses.default.factory,
|
|
71
|
+
...Object.values(x.addresses.overrides ?? {}).map((z) => z.factory),
|
|
72
|
+
]).flat());
|
|
73
|
+
export async function getLightAccountVersionForAccount(account, chain) {
|
|
99
74
|
const accountType = account.source;
|
|
100
75
|
const factoryAddress = await account.getFactoryAddress();
|
|
101
76
|
const implAddress = await account.getImplementationAddress();
|
|
102
|
-
const implToVersion = new Map(Object.entries(AccountVersionRegistry[accountType])
|
|
103
|
-
.map((pair) => {
|
|
77
|
+
const implToVersion = new Map(Object.entries(AccountVersionRegistry[accountType]).map((pair) => {
|
|
104
78
|
const [version, def] = pair;
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
.
|
|
110
|
-
|
|
111
|
-
|
|
79
|
+
if (def.addresses.overrides != null &&
|
|
80
|
+
chain.id in def.addresses.overrides) {
|
|
81
|
+
return [def.addresses.overrides[chain.id].impl, version];
|
|
82
|
+
}
|
|
83
|
+
return [def.addresses.default.impl, version];
|
|
84
|
+
}));
|
|
85
|
+
const factoryToVersion = new Map(Object.entries(AccountVersionRegistry[accountType]).map((pair) => {
|
|
112
86
|
const [version, def] = pair;
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
.
|
|
87
|
+
if (def.addresses.overrides != null &&
|
|
88
|
+
chain.id in def.addresses.overrides) {
|
|
89
|
+
return [def.addresses.overrides[chain.id].factory, version];
|
|
90
|
+
}
|
|
91
|
+
return [def.addresses.default.factory, version];
|
|
92
|
+
}));
|
|
118
93
|
const version = fromHex(implAddress, "bigint") === 0n
|
|
119
94
|
? factoryToVersion.get(factoryAddress.toLowerCase())
|
|
120
95
|
: implToVersion.get(implAddress.toLowerCase());
|
|
@@ -123,7 +98,4 @@ export async function getLightAccountVersionDef(account, chain) {
|
|
|
123
98
|
}
|
|
124
99
|
return AccountVersionRegistry[accountType][version];
|
|
125
100
|
}
|
|
126
|
-
export async function getLightAccountVersion(account, chain = supportedChains[0]) {
|
|
127
|
-
return (await getLightAccountVersionDef(account, chain)).version;
|
|
128
|
-
}
|
|
129
101
|
//# sourceMappingURL=utils.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../../../../src/light-account/utils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,6BAA6B,EAAE,QAAQ,EAAE,MAAM,cAAc,CAAC;AACvE,OAAO,EACL,QAAQ,EACR,cAAc,EACd,eAAe,EACf,IAAI,EACJ,UAAU,EACV,WAAW,EACX,OAAO,EACP,cAAc,EACd,MAAM,EACN,OAAO,EACP,QAAQ,EACR,cAAc,EACd,eAAe,EACf,OAAO,EACP,WAAW,EACX,aAAa,EACb,OAAO,EACP,IAAI,EACJ,WAAW,GACZ,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EAAE,OAAO,EAA4B,MAAM,MAAM,CAAC;AAiBzD,MAAM,C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AE,CAAC;QACb,MAAM,IAAI,KAAK,CACb,uBAAuB,OAAO,CAAC,MAAM,sBAAsB,KAAK,CAAC,EAAE,EAAE,CACtE,CAAC;IACJ,CAAC;IAED,OAAO,sBAAsB,CAAC,WAAW,CAAC,CAAC,OAAO,CAAC,CAAC;AACtD,CAAC;AA4BD,MAAM,CAAC,KAAK,UAAU,sBAAsB,CAC1C,OAAyB,EACzB,QAAe,eAAe,CAAC,CAAC,CAAC;IAEjC,OAAO,CAAC,MAAM,yBAAyB,CAAC,OAAO,EAAE,KAAK,CAAC,CAAC,CAAC,OAAO,CAAC;AACnE,CAAC","sourcesContent":["import { DefaultFactoryNotDefinedError, toRecord } from \"@aa-sdk/core\";\nimport {\n arbitrum,\n arbitrumGoerli,\n arbitrumSepolia,\n base,\n baseGoerli,\n baseSepolia,\n fraxtal,\n fraxtalSepolia,\n goerli,\n mainnet,\n optimism,\n optimismGoerli,\n optimismSepolia,\n polygon,\n polygonAmoy,\n polygonMumbai,\n sepolia,\n zora,\n zoraSepolia,\n} from \"@account-kit/infra\";\nimport { fromHex, type Address, type Chain } from \"viem\";\nimport type { LightAccountBase } from \"./accounts/base\";\nimport type {\n AccountVersionDef,\n GetLightAccountType,\n GetLightAccountVersion,\n GetLightAccountVersionFromAccount,\n IAccountVersionRegistry,\n LightAccountType,\n LightAccountVersion,\n LightAccountVersionDef,\n} from \"./types\";\n\n/**\n * Light account deployed chains\n *\n */\nexport const supportedChains: Chain[] = [\n mainnet,\n sepolia,\n goerli,\n polygon,\n polygonAmoy,\n polygonMumbai,\n optimism,\n optimismGoerli,\n optimismSepolia,\n arbitrum,\n arbitrumGoerli,\n arbitrumSepolia,\n base,\n baseGoerli,\n baseSepolia,\n fraxtal,\n fraxtalSepolia,\n zora,\n zoraSepolia,\n];\n\n/**\n * Account version registry interface that defines the light account versions\n * and the version definition for each light account type\n *\n */\nexport const AccountVersionRegistry: IAccountVersionRegistry = {\n LightAccount: {\n \"v1.0.1\": {\n type: \"LightAccount\",\n version: \"v1.0.1\",\n address: toRecord<Chain, \"id\", { factory: Address; impl: Address }>(\n supportedChains,\n \"id\",\n () => ({\n factory:\n \"0x000000893A26168158fbeaDD9335Be5bC96592E2\".toLowerCase() as Address,\n impl: \"0xc1b2fc4197c9187853243e6e4eb5a4af8879a1c0\".toLowerCase() as Address,\n })\n ),\n entryPointVersion: \"0.6.0\",\n },\n \"v1.0.2\": {\n type: \"LightAccount\",\n version: \"v1.0.2\",\n address: toRecord<Chain, \"id\", { factory: Address; impl: Address }>(\n supportedChains,\n \"id\",\n () => ({\n factory:\n \"0x00000055C0b4fA41dde26A74435ff03692292FBD\".toLowerCase() as Address,\n impl: \"0x5467b1947F47d0646704EB801E075e72aeAe8113\".toLowerCase() as Address,\n })\n ),\n entryPointVersion: \"0.6.0\",\n },\n \"v1.1.0\": {\n type: \"LightAccount\",\n version: \"v1.1.0\",\n address: toRecord<Chain, \"id\", { factory: Address; impl: Address }>(\n supportedChains,\n \"id\",\n () => ({\n factory:\n \"0x00004EC70002a32400f8ae005A26081065620D20\".toLowerCase() as Address,\n impl: \"0xae8c656ad28F2B59a196AB61815C16A0AE1c3cba\".toLowerCase() as Address,\n })\n ),\n entryPointVersion: \"0.6.0\",\n },\n \"v2.0.0\": {\n type: \"LightAccount\",\n version: \"v2.0.0\",\n address: toRecord<Chain, \"id\", { factory: Address; impl: Address }>(\n supportedChains,\n \"id\",\n () => ({\n factory:\n \"0x0000000000400CdFef5E2714E63d8040b700BC24\".toLowerCase() as Address,\n impl: \"0x8E8e658E22B12ada97B402fF0b044D6A325013C7\".toLowerCase() as Address,\n })\n ),\n entryPointVersion: \"0.7.0\",\n },\n },\n MultiOwnerLightAccount: {\n \"v2.0.0\": {\n type: \"MultiOwnerLightAccount\",\n version: \"v2.0.0\",\n address: toRecord<Chain, \"id\", { factory: Address; impl: Address }>(\n supportedChains,\n \"id\",\n () => ({\n factory:\n \"0x000000000019d2Ee9F2729A65AfE20bb0020AefC\".toLowerCase() as Address,\n impl: \"0xd2c27F9eE8E4355f71915ffD5568cB3433b6823D\".toLowerCase() as Address,\n })\n ),\n entryPointVersion: \"0.7.0\",\n },\n },\n};\n\n/**\n * Get the default light account version for the given light account type\n *\n * @template {LightAccountType} TLightAccountType\n * @param type - the light account type to get the default version for\n * @returns the default version for the given light account type\n */\nexport const defaultLightAccountVersion = <\n TLightAccountType extends LightAccountType\n>(\n type: TLightAccountType\n): GetLightAccountVersion<TLightAccountType> =>\n (type === \"LightAccount\"\n ? \"v1.1.0\"\n : \"v2.0.0\") as GetLightAccountVersion<TLightAccountType>;\n\n/**\n * Utility method returning the default light account factory address given a {@link Chain} object\n *\n * @param chain - a {@link Chain} object\n * @param version - the version of the light account to get the factory address for\n * @returns a {@link Address} for the given chain\n * @throws if the chain doesn't have an address currently deployed\n */\nexport const getDefaultLightAccountFactoryAddress = (\n chain: Chain,\n version: GetLightAccountVersion<\"LightAccount\">\n): Address => {\n const address =\n AccountVersionRegistry.LightAccount[version].address[chain.id] ??\n AccountVersionRegistry.LightAccount[version].address[supportedChains[0].id];\n if (!address)\n throw new DefaultFactoryNotDefinedError(\"LightAccount\", chain, \"0.6.0\");\n return address.factory;\n};\n\n/**\n * Utility method returning the default multi owner light account factory address given a {@link Chain} object\n *\n * @param chain - a {@link Chain} object\n * @param version - the version of the light account to get the factory address for\n * @returns a {@link Address} for the given chain\n * @throws if the chain doesn't have an address currently deployed\n */\nexport const getDefaultMultiOwnerLightAccountFactoryAddress = (\n chain: Chain,\n version: GetLightAccountVersion<\"MultiOwnerLightAccount\">\n) => {\n const address =\n AccountVersionRegistry.LightAccount[version].address[chain.id] ??\n AccountVersionRegistry.LightAccount[version].address[supportedChains[0].id];\n if (!address)\n throw new DefaultFactoryNotDefinedError(\n \"MultiOwnerLightAccount\",\n chain,\n \"0.7.0\"\n );\n return address.factory;\n};\n\n/**\n * Can be used to check if the account with one of the following implementation addresses\n * to not support 1271 signing.\n *\n * Light accounts with versions v1.0.1 and v1.0.2 do not support 1271 signing.\n */\nexport const LightAccountUnsupported1271Impls = [\n AccountVersionRegistry.LightAccount[\"v1.0.1\"],\n AccountVersionRegistry.LightAccount[\"v1.0.2\"],\n];\n\n/**\n * Can be used to check if the account with one of the following factory addresses\n * to not support 1271 signing.\n *\n * Light accounts with versions v1.0.1 and v1.0.2 do not support 1271 signing.\n */\nexport const LightAccountUnsupported1271Factories = new Set(\n LightAccountUnsupported1271Impls.map((x) =>\n Object.values(x.address).map((addr) => addr.factory)\n ).flat()\n);\n\n/**\n * Get the light account version definition for the given light account and chain\n *\n * @template {LightAccountBase} TAccount\n * @template {GetLightAccountType<TAccount>} TLightAccountType\n * @template {GetLightAccountVersion<TLightAccountType>} TLightAccountVersion\n * @param account - the light account to get the version for\n * @param chain - the chain to get the version for\n * @returns the light account version definition for the given light account and chain\n */\nexport async function getLightAccountVersionDef<\n TAccount extends LightAccountBase,\n TLightAccountType extends GetLightAccountType<TAccount> = GetLightAccountType<TAccount>,\n TLightAccountVersion extends GetLightAccountVersion<TLightAccountType> = GetLightAccountVersion<TLightAccountType>\n>(\n account: TAccount,\n chain: Chain\n): Promise<LightAccountVersionDef<TLightAccountType, TLightAccountVersion>>;\n\n/**\n * Get the light account version definition for the given light account and chain\n *\n * @template {LightAccountBase} TAccount\n * @template {GetLightAccountType<TAccount>} TLightAccountType\n * @param account - the light account to get the version for\n * @param chain - the chain to get the version for\n * @returns the light account version definition for the given light account and chain\n */\nexport async function getLightAccountVersionDef<\n TAccount extends LightAccountBase,\n TLightAccountType extends GetLightAccountType<TAccount> = GetLightAccountType<TAccount>\n>(\n account: TAccount,\n chain: Chain\n): Promise<\n AccountVersionDef<\n TLightAccountType,\n GetLightAccountVersion<TLightAccountType>\n >\n>;\n\n/**\n * Get the light account version definition for the given light account and chain\n *\n * @template {LightAccountBase} TAccount\n * @param account - the light account to get the version for\n * @param chain - the chain to get the version for\n * @returns the light account version definition for the given light account and chain\n */\nexport async function getLightAccountVersionDef<\n TAccount extends LightAccountBase\n>(account: TAccount, chain: Chain): Promise<AccountVersionDef> {\n const accountType = account.source as LightAccountType;\n const factoryAddress = await account.getFactoryAddress();\n const implAddress = await account.getImplementationAddress();\n const implToVersion = new Map(\n Object.entries(AccountVersionRegistry[accountType])\n .map((pair) => {\n const [version, def] = pair as [\n GetLightAccountVersionFromAccount<TAccount>,\n LightAccountVersionDef\n ];\n return chain.id in def.address\n ? [def.address[chain.id].impl, version]\n : [def.address[supportedChains[0].id].impl, version];\n })\n .filter(([impl]) => impl !== null) as [\n Address,\n keyof IAccountVersionRegistry[typeof accountType]\n ][]\n );\n\n const factoryToVersion = new Map(\n Object.entries(AccountVersionRegistry[accountType])\n .map((pair) => {\n const [version, def] = pair as [\n keyof IAccountVersionRegistry[typeof accountType],\n LightAccountVersionDef\n ];\n return chain.id in def.address\n ? [def.address[chain.id].factory, version]\n : [def.address[supportedChains[0].id].factory, version];\n })\n .filter(([impl]) => impl !== null) as [\n Address,\n keyof IAccountVersionRegistry[typeof accountType]\n ][]\n );\n\n const version =\n fromHex(implAddress, \"bigint\") === 0n\n ? factoryToVersion.get(factoryAddress.toLowerCase() as Address)\n : implToVersion.get(implAddress.toLowerCase() as Address);\n\n if (!version) {\n throw new Error(\n `Could not determine ${account.source} version for chain ${chain.id}`\n );\n }\n\n return AccountVersionRegistry[accountType][version];\n}\n\n/**\n * @param account - the light account to get the version for\n * @param chain - the chain to get the version for\n *\n * @deprecated don't use this function as this function is replaced with getLightAccountVersionDef.\n * Migrate to using getLightAccountVersionDef instead\n *\n * @returns the light account version for the given light account and chain\n */\nexport async function getLightAccountVersion<\n TAccount extends LightAccountBase,\n TLightAccountType extends GetLightAccountType<TAccount> = GetLightAccountType<TAccount>\n>(\n account: TAccount,\n chain?: Chain\n): Promise<GetLightAccountVersion<TLightAccountType>>;\n\n/**\n * Get the light account version for the given light account and chain\n *\n * @deprecated don't use this function as this function is replaced with getLightAccountVersionDef.\n *\n * @param account - the light account to get the version for\n * @param chain - the chain to get the version for\n * @returns the light account version for the given light account and chain\n */\nexport async function getLightAccountVersion(\n account: LightAccountBase,\n chain: Chain = supportedChains[0]\n): Promise<LightAccountVersion> {\n return (await getLightAccountVersionDef(account, chain)).version;\n}\n"]}
|
|
1
|
+
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../../../../src/light-account/utils.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,OAAO,EAA4B,MAAM,MAAM,CAAC;AAczD,MAAM,CAAC,MAAM,sBAAsB,GAA+B;IAChE,YAAY,EAAE;QACZ,QAAQ,EAAE;YACR,iBAAiB,EAAE,OAAO;YAC1B,SAAS,EAAE;gBACT,OAAO,EAAE;oBACP,OAAO,EACL,4CAA4C,CAAC,WAAW,EAAa;oBACvE,IAAI,EAAE,4CAA4C,CAAC,WAAW,EAAa;iBAC5E;aACF;SACF;QACD,QAAQ,EAAE;YACR,iBAAiB,EAAE,OAAO;YAC1B,SAAS,EAAE;gBACT,OAAO,EAAE;oBACP,OAAO,EACL,4CAA4C,CAAC,WAAW,EAAa;oBACvE,IAAI,EAAE,4CAA4C,CAAC,WAAW,EAAa;iBAC5E;aACF;SACF;QACD,QAAQ,EAAE;YACR,iBAAiB,EAAE,OAAO;YAC1B,SAAS,EAAE;gBACT,OAAO,EAAE;oBACP,OAAO,EACL,4CAA4C,CAAC,WAAW,EAAa;oBACvE,IAAI,EAAE,4CAA4C,CAAC,WAAW,EAAa;iBAC5E;aACF;SACF;QACD,QAAQ,EAAE;YACR,iBAAiB,EAAE,OAAO;YAC1B,SAAS,EAAE;gBACT,OAAO,EAAE;oBACP,OAAO,EACL,4CAA4C,CAAC,WAAW,EAAa;oBACvE,IAAI,EAAE,4CAA4C,CAAC,WAAW,EAAa;iBAC5E;aACF;SACF;KACF;IACD,sBAAsB,EAAE;QACtB,QAAQ,EAAE;YACR,iBAAiB,EAAE,OAAO;YAC1B,SAAS,EAAE;gBACT,OAAO,EAAE;oBACP,OAAO,EACL,4CAA4C,CAAC,WAAW,EAAa;oBACvE,IAAI,EAAE,4CAA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AC,KAAK,CAAC,EAAE,CAAC,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC;QAC9D,CAAC;QAED,OAAO,CAAC,GAAG,CAAC,SAAS,CAAC,OAAO,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC;IAClD,CAAC,CAAC,CACH,CAAC;IAEF,MAAM,OAAO,GACX,OAAO,CAAC,WAAW,EAAE,QAAQ,CAAC,KAAK,EAAE;QACnC,CAAC,CAAC,gBAAgB,CAAC,GAAG,CAAC,cAAc,CAAC,WAAW,EAAa,CAAC;QAC/D,CAAC,CAAC,aAAa,CAAC,GAAG,CAAC,WAAW,CAAC,WAAW,EAAa,CAAC,CAAC;IAE9D,IAAI,CAAC,OAAO,EAAE,CAAC;QACb,MAAM,IAAI,KAAK,CACb,uBAAuB,OAAO,CAAC,MAAM,sBAAsB,KAAK,CAAC,EAAE,EAAE,CACtE,CAAC;IACJ,CAAC;IAED,OAAO,sBAAsB,CAAC,WAAW,CAAC,CAAC,OAAO,CAAC,CAAC;AACtD,CAAC","sourcesContent":["import type { GetEntryPointFromAccount } from \"@aa-sdk/core\";\nimport { fromHex, type Address, type Chain } from \"viem\";\nimport type { LightAccountBase } from \"./accounts/base\";\nimport type {\n LightAccountType,\n LightAccountVersion,\n LightAccountVersionConfig,\n LightAccountVersionConfigs,\n} from \"./types\";\n\n/**\n * Account version registry interface that defines the light account versions\n * and the version definition for each light account type\n *\n */\nexport const AccountVersionRegistry: LightAccountVersionConfigs = {\n LightAccount: {\n \"v1.0.1\": {\n entryPointVersion: \"0.6.0\",\n addresses: {\n default: {\n factory:\n \"0x000000893A26168158fbeaDD9335Be5bC96592E2\".toLowerCase() as Address,\n impl: \"0xc1b2fc4197c9187853243e6e4eb5a4af8879a1c0\".toLowerCase() as Address,\n },\n },\n },\n \"v1.0.2\": {\n entryPointVersion: \"0.6.0\",\n addresses: {\n default: {\n factory:\n \"0x00000055C0b4fA41dde26A74435ff03692292FBD\".toLowerCase() as Address,\n impl: \"0x5467b1947F47d0646704EB801E075e72aeAe8113\".toLowerCase() as Address,\n },\n },\n },\n \"v1.1.0\": {\n entryPointVersion: \"0.6.0\",\n addresses: {\n default: {\n factory:\n \"0x00004EC70002a32400f8ae005A26081065620D20\".toLowerCase() as Address,\n impl: \"0xae8c656ad28F2B59a196AB61815C16A0AE1c3cba\".toLowerCase() as Address,\n },\n },\n },\n \"v2.0.0\": {\n entryPointVersion: \"0.7.0\",\n addresses: {\n default: {\n factory:\n \"0x0000000000400CdFef5E2714E63d8040b700BC24\".toLowerCase() as Address,\n impl: \"0x8E8e658E22B12ada97B402fF0b044D6A325013C7\".toLowerCase() as Address,\n },\n },\n },\n },\n MultiOwnerLightAccount: {\n \"v2.0.0\": {\n entryPointVersion: \"0.7.0\",\n addresses: {\n default: {\n factory:\n \"0x000000000019d2Ee9F2729A65AfE20bb0020AefC\".toLowerCase() as Address,\n impl: \"0xd2c27F9eE8E4355f71915ffD5568cB3433b6823D\".toLowerCase() as Address,\n },\n },\n },\n },\n};\n\n/**\n * Get the default light account version for the given light account type\n *\n * @template {LightAccountType} TLightAccountType\n * @returns {LightAccountVersion<TLightAccountType>} the default version for the given light account type\n */\nexport const defaultLightAccountVersion = <\n TLightAccountType extends LightAccountType\n>(): LightAccountVersion<TLightAccountType> => \"v2.0.0\";\n\n/**\n * Utility method returning the default light account factory address given a Chain object\n *\n * @param {Chain} chain - a Chain object\n * @param {LightAccountVersion} version - the version of the light account to get the factory address for\n * @returns {Address} an for the given chain\n * @throws if the chain doesn't have an address currently deployed\n */\nexport const getDefaultLightAccountFactoryAddress = (\n chain: Chain,\n version: LightAccountVersion<\"LightAccount\">\n): Address => {\n return (\n AccountVersionRegistry.LightAccount[version].addresses.overrides?.[chain.id]\n ?.factory ??\n AccountVersionRegistry.LightAccount[version].addresses.default.factory\n );\n};\n\n/**\n * Utility method returning the default multi owner light account factory address given a Chain object\n *\n * @param {Chain} chain - a Chain object\n * @param {string} version - the version of the light account to get the factory address for\n * @returns {Address} an Address for the given chain\n */\nexport const getDefaultMultiOwnerLightAccountFactoryAddress = (\n chain: Chain,\n version: LightAccountVersion<\"MultiOwnerLightAccount\">\n) => {\n return (\n AccountVersionRegistry.MultiOwnerLightAccount[version].addresses\n .overrides?.[chain.id]?.factory ??\n AccountVersionRegistry.MultiOwnerLightAccount[version].addresses.default\n .factory\n );\n};\n\n/**\n * Can be used to check if the account with one of the following implementation addresses\n * to not support 1271 signing.\n *\n * Light accounts with versions v1.0.1 and v1.0.2 do not support 1271 signing.\n */\nexport const LightAccountUnsupported1271Impls = [\n AccountVersionRegistry.LightAccount[\"v1.0.1\"],\n AccountVersionRegistry.LightAccount[\"v1.0.2\"],\n];\n\n/**\n * Can be used to check if the account with one of the following factory addresses\n * to not support 1271 signing.\n *\n * Light accounts with versions v1.0.1 and v1.0.2 do not support 1271 signing.\n */\nexport const LightAccountUnsupported1271Factories = new Set(\n LightAccountUnsupported1271Impls.map((x) => [\n x.addresses.default.factory,\n ...Object.values(x.addresses.overrides ?? {}).map((z) => z.factory),\n ]).flat()\n);\n\n/**\n * Get the light account version definition for the given light account and chain\n *\n * @template {LightAccountBase} TAccount\n * @param {LightAccountBase} account the light account to get the version for\n * @param {Chain} chain - the chain to get the version for\n * @returns {Promise<LightAccountVersionConfig>} the light account version definition for the given light account and chain\n */\nexport async function getLightAccountVersionForAccount<\n TAccount extends LightAccountBase\n>(account: TAccount, chain: Chain): Promise<LightAccountVersionConfig> {\n const accountType = account.source as LightAccountType;\n const factoryAddress = await account.getFactoryAddress();\n const implAddress = await account.getImplementationAddress();\n const implToVersion = new Map(\n Object.entries(AccountVersionRegistry[accountType]).map((pair) => {\n const [version, def] = pair as [\n LightAccountVersion<LightAccountType>,\n LightAccountVersionConfig<GetEntryPointFromAccount<TAccount>>\n ];\n\n if (\n def.addresses.overrides != null &&\n chain.id in def.addresses.overrides!\n ) {\n return [def.addresses.overrides[chain.id].impl, version];\n }\n\n return [def.addresses.default.impl, version];\n })\n );\n\n const factoryToVersion = new Map(\n Object.entries(AccountVersionRegistry[accountType]).map((pair) => {\n const [version, def] = pair as [\n LightAccountVersion<LightAccountType>,\n LightAccountVersionConfig<GetEntryPointFromAccount<TAccount>>\n ];\n\n if (\n def.addresses.overrides != null &&\n chain.id in def.addresses.overrides!\n ) {\n return [def.addresses.overrides[chain.id].factory, version];\n }\n\n return [def.addresses.default.factory, version];\n })\n );\n\n const version =\n fromHex(implAddress, \"bigint\") === 0n\n ? factoryToVersion.get(factoryAddress.toLowerCase() as Address)\n : implToVersion.get(implAddress.toLowerCase() as Address);\n\n if (!version) {\n throw new Error(\n `Could not determine ${account.source} version for chain ${chain.id}`\n );\n }\n\n return AccountVersionRegistry[accountType][version];\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"middleware.js","sourceRoot":"","sources":["../../../../../../src/msca/plugins/multisig/middleware.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,yBAAyB,EACzB,mCAAmC,EACnC,WAAW,EACX,wBAAwB,EACxB,cAAc,EACd,iBAAiB,GAIlB,MAAM,cAAc,CAAC;AACtB,OAAO,EAAY,MAAM,MAAM,CAAC;AAChC,OAAO,EAAE,wBAAwB,EAAE,MAAM,kCAAkC,CAAC;AAC5E,OAAO,EACL,4BAA4B,EAC5B,4BAA4B,GAC7B,MAAM,iBAAiB,CAAC;AACzB,OAAO,EAAqC,MAAM,YAAY,CAAC;AAC/D,OAAO,EACL,iBAAiB,EACjB,aAAa,EACb,wBAAwB,GACzB,MAAM,kBAAkB,CAAC;AAc1B,MAAM,CAAC,MAAM,2BAA2B,GAEpC,KAAK,EAAE,MAAM,EAAE,EAAE,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,EAAE,EAAE;IAEjD,IACE,CAAC,OAAO;QACR,CAAC,OAAO,CAAC,mBAAmB,KAAK,QAAQ;YACvC,CAAC,OAAO,CAAC,UAAU;YACnB,CAAC,OAAO,CAAC,mBAAmB,CAAC,EAC/B,CAAC;QACD,MAAM,IAAI,4BAA4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;IACf,CAAC;IAED,IACE,MAAM,CAAC,OAAO,CAAC,oBAAoB,CAAC;QACpC,MAAM,CAAC,WAAW,CAAC,8BAA8B,CAAC,EAClD,CAAC;QACD,OAAO,KAAK,CAAC;IACf,CAAC;IAED,OAAO,IAAI,CAAC;AACd,CAAC,CAAC","sourcesContent":["import {\n InvalidUserOperationError,\n SmartAccountWithSignerRequiredError,\n deepHexlify,\n isSmartAccountWithSigner,\n isValidRequest,\n resolveProperties,\n type ClientMiddlewareFn,\n type UserOperationRequest_v6,\n type UserOperationRequest_v7,\n} from \"@aa-sdk/core\";\nimport { type Hex } from \"viem\";\nimport { isMultisigModularAccount } from \"../../account/multisigAccount.js\";\nimport {\n InvalidContextSignatureError,\n MultisigAccountExpectedError,\n} from \"../../errors.js\";\nimport { type MultisigUserOperationContext } from \"./types.js\";\nimport {\n combineSignatures,\n getSignerType,\n splitAggregatedSignature,\n} from \"./utils/index.js\";\n\n/**\n * A signer middleware to be used with Multisig Account Clients.\n * This middleware handles correctly aggregating signatures passed through\n * as context when sending UserOperations, proposing UserOperations, or adding signatures to a UserOperation.\n *\n * @param struct the user operation struct to be signed\n * @param
|
|
1
|
+
{"version":3,"file":"middleware.js","sourceRoot":"","sources":["../../../../../../src/msca/plugins/multisig/middleware.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,yBAAyB,EACzB,mCAAmC,EACnC,WAAW,EACX,wBAAwB,EACxB,cAAc,EACd,iBAAiB,GAIlB,MAAM,cAAc,CAAC;AACtB,OAAO,EAAY,MAAM,MAAM,CAAC;AAChC,OAAO,EAAE,wBAAwB,EAAE,MAAM,kCAAkC,CAAC;AAC5E,OAAO,EACL,4BAA4B,EAC5B,4BAA4B,GAC7B,MAAM,iBAAiB,CAAC;AACzB,OAAO,EAAqC,MAAM,YAAY,CAAC;AAC/D,OAAO,EACL,iBAAiB,EACjB,aAAa,EACb,wBAAwB,GACzB,MAAM,kBAAkB,CAAC;AAc1B,MAAM,CAAC,MAAM,2BAA2B,GA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IACE,MAAM,CAAC,OAAO,CAAC,kBAAkB,CAAC,KAAK,MAAM,CAAC,WAAW,CAAC,aAAa,CAAC,EACxE,CAAC;QACD,OAAO,KAAK,CAAC;IACf,CAAC;IAED,IACE,MAAM,CAAC,OAAO,CAAC,YAAY,CAAC,KAAK,MAAM,CAAC,WAAW,CAAC,sBAAsB,CAAC,EAC3E,CAAC;QACD,OAAO,KAAK,CAAC;IACf,CAAC;IAED,IACE,MAAM,CAAC,OAAO,CAAC,oBAAoB,CAAC;QACpC,MAAM,CAAC,WAAW,CAAC,8BAA8B,CAAC,EAClD,CAAC;QACD,OAAO,KAAK,CAAC;IACf,CAAC;IAED,OAAO,IAAI,CAAC;AACd,CAAC,CAAC","sourcesContent":["import {\n InvalidUserOperationError,\n SmartAccountWithSignerRequiredError,\n deepHexlify,\n isSmartAccountWithSigner,\n isValidRequest,\n resolveProperties,\n type ClientMiddlewareFn,\n type UserOperationRequest_v6,\n type UserOperationRequest_v7,\n} from \"@aa-sdk/core\";\nimport { type Hex } from \"viem\";\nimport { isMultisigModularAccount } from \"../../account/multisigAccount.js\";\nimport {\n InvalidContextSignatureError,\n MultisigAccountExpectedError,\n} from \"../../errors.js\";\nimport { type MultisigUserOperationContext } from \"./types.js\";\nimport {\n combineSignatures,\n getSignerType,\n splitAggregatedSignature,\n} from \"./utils/index.js\";\n\n/**\n * A signer middleware to be used with Multisig Account Clients.\n * This middleware handles correctly aggregating signatures passed through\n * as context when sending UserOperations, proposing UserOperations, or adding signatures to a UserOperation.\n *\n * @param {Deferrable<UserOperationStruct<TEntryPointVersion>>} struct the user operation struct to be signed\n * @param {ClientMiddlewareArgs<TAccount, C, TContext, TEntryPointVersion>} args the parameters to be passed to the middleware\n * @param {UserOperationOverrides<TEntryPointVersion>} args.account the account to be used for signing\n * @param {MiddlewareClient} args.client the smart account client that will be used for RPC requests\n * @param {MultisigUserOperationContext} args.context the context object containing the signatures to be aggregated MultisigUserOperationContext\n * @returns {Promise<Deferrable<UserOperationStruct<TEntryPointVersion>>>} a Promise containing a UserOperation with an aggregated signature in the `signature` field\n */\nexport const multisigSignatureMiddleware: ClientMiddlewareFn<\n MultisigUserOperationContext\n> = async (struct, { account, client, context }) => {\n // if the signature is not present, this has to be UPPERLIMIT because it's likely a propose operation\n if (\n !context ||\n (context.userOpSignatureType === \"ACTUAL\" &&\n !context.signatures &&\n !context.aggregatedSignature)\n ) {\n throw new InvalidContextSignatureError();\n }\n\n if (!isSmartAccountWithSigner(account)) {\n throw new SmartAccountWithSignerRequiredError();\n }\n\n if (!isMultisigModularAccount(account)) {\n throw new MultisigAccountExpectedError();\n }\n\n const resolvedStruct = await resolveProperties(struct);\n\n const request = deepHexlify(resolvedStruct);\n if (!isValidRequest(request)) {\n throw new InvalidUserOperationError(resolvedStruct);\n }\n\n const signature = await account.signUserOperationHash(\n account.getEntryPoint().getUserOperationHash(request)\n );\n\n const signerType = await getSignerType({\n client,\n signature: signature,\n signer: account.getSigner(),\n });\n\n // then this is a propose operation\n if (\n context.userOpSignatureType === \"UPPERLIMIT\" &&\n context?.signatures?.length == null &&\n context?.aggregatedSignature == null\n ) {\n return {\n ...resolvedStruct,\n signature: combineSignatures({\n signatures: [\n {\n signature,\n signer: await account.getSigner().getAddress(),\n signerType,\n userOpSigType: context.userOpSignatureType,\n },\n ],\n upperLimitMaxFeePerGas: request.maxFeePerGas,\n upperLimitMaxPriorityFeePerGas: request.maxPriorityFeePerGas,\n upperLimitPvg: request.preVerificationGas,\n usingMaxValues: false,\n }),\n };\n }\n\n if (context.aggregatedSignature == null || context.signatures == null) {\n throw new InvalidContextSignatureError();\n }\n\n // otherwise this is a sign operation\n const {\n upperLimitPvg,\n upperLimitMaxFeePerGas,\n upperLimitMaxPriorityFeePerGas,\n } = await splitAggregatedSignature({\n aggregatedSignature: context.aggregatedSignature,\n threshold: context.signatures.length + 1,\n account,\n request,\n });\n\n const finalSignature = combineSignatures({\n signatures: context.signatures.concat({\n userOpSigType: context.userOpSignatureType,\n signerType,\n signature,\n signer: await account.getSigner().getAddress(),\n }),\n upperLimitPvg,\n upperLimitMaxFeePerGas,\n upperLimitMaxPriorityFeePerGas,\n usingMaxValues: isUsingMaxValues(request, {\n upperLimitPvg,\n upperLimitMaxFeePerGas,\n upperLimitMaxPriorityFeePerGas,\n }),\n });\n\n return {\n ...resolvedStruct,\n signature: finalSignature,\n };\n};\n\nconst isUsingMaxValues = (\n request: UserOperationRequest_v6 | UserOperationRequest_v7,\n upperLimits: {\n upperLimitPvg: Hex;\n upperLimitMaxFeePerGas: Hex;\n upperLimitMaxPriorityFeePerGas: Hex;\n }\n): boolean => {\n if (\n BigInt(request.preVerificationGas) !== BigInt(upperLimits.upperLimitPvg)\n ) {\n return false;\n }\n\n if (\n BigInt(request.maxFeePerGas) !== BigInt(upperLimits.upperLimitMaxFeePerGas)\n ) {\n return false;\n }\n\n if (\n BigInt(request.maxPriorityFeePerGas) !==\n BigInt(upperLimits.upperLimitMaxPriorityFeePerGas)\n ) {\n return false;\n }\n\n return true;\n};\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"formatSignatures.js","sourceRoot":"","sources":["../../../../../../../src/msca/plugins/multisig/utils/formatSignatures.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AACzC,OAAO,EAAE,MAAM,EAAE,WAAW,EAAE,GAAG,EAAE,KAAK,EAAE,MAAM,MAAM,CAAC;AAavD,MAAM,CAAC,MAAM,gBAAgB,GAAG,CAC9B,UAAuB,EACvB,iBAA0B,KAAK,EAC/B,EAAE;IACF,IAAI,OAAO,GAAW,EAAE,CAAC;IACzB,IAAI,YAAY,GAAW,EAAE,CAAC;IAC9B,IAAI,MAAM,GAAW,MAAM,CAAC,EAAE,GAAG,UAAU,CAAC,MAAM,CAAC,CAAC;IACpD,UAAU;SACP,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE;QACb,MAAM,OAAO,GAAG,WAAW,CAAC,C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,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;YACZ,YAAY,IAAI,MAAM,CAAC;gBACrB,KAAK,CAAC,MAAM,EAAE,EAAE,IAAI,EAAE,EAAE,EAAE,CAAC;gBAC3B,GAAG,CAAC,SAAS;aACd,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;YACZ,MAAM,IAAI,MAAM,CAAC;QACnB,CAAC;IACH,CAAC,CAAC,CAAC;IACL,OAAO,CAAC,IAAI,GAAG,OAAO,GAAG,YAAY,CAAkB,CAAC;AAC1D,CAAC,CAAC","sourcesContent":["import { takeBytes } from \"@aa-sdk/core\";\nimport { concat, hexToBigInt, pad, toHex } from \"viem\";\nimport type { Signature } from \"../types\";\n\n/**\n * Formats a collection of Signature objects into a single aggregated signature.\n * The format is in the form of EOA_SIGS | CONTRACT_SIG_DATAS. The signatures are ordered\n * by signer address. The EOA SIGS contain the 65 signautre data for EOA signers and 65 bytes containing SIGNER | OFFSET | V for contract signers.\n * The OFFSET is used to fetch the signature data from the CONTRACT_SIG_DATAS.\n *\n * @param signatures the array of
|
|
1
|
+
{"version":3,"file":"formatSignatures.js","sourceRoot":"","sources":["../../../../../../../src/msca/plugins/multisig/utils/formatSignatures.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AACzC,OAAO,EAAE,MAAM,EAAE,WAAW,EAAE,GAAG,EAAE,KAAK,EAAE,MAAM,MAAM,CAAC;AAavD,MAAM,CAAC,MAAM,gBAAgB,GAAG,CAC9B,UAAuB,EACvB,iBAA0B,KAAK,EAC/B,EAAE;IACF,IAAI,OAAO,GAAW,EAAE,CAAC;IACzB,IAAI,YAAY,GAAW,EAAE,CAAC;IAC9B,IAAI,MAAM,GAAW,MAAM,CAAC,EAAE,GAAG,UAAU,CAAC,MAAM,CAAC,CAAC;IACpD,UAAU;SACP,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE;QACb,MAAM,OAAO,GAAG,W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;aACzB,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;YACZ,YAAY,IAAI,MAAM,CAAC;gBACrB,KAAK,CAAC,MAAM,EAAE,EAAE,IAAI,EAAE,EAAE,EAAE,CAAC;gBAC3B,GAAG,CAAC,SAAS;aACd,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;YACZ,MAAM,IAAI,MAAM,CAAC;QACnB,CAAC;IACH,CAAC,CAAC,CAAC;IACL,OAAO,CAAC,IAAI,GAAG,OAAO,GAAG,YAAY,CAAkB,CAAC;AAC1D,CAAC,CAAC","sourcesContent":["import { takeBytes } from \"@aa-sdk/core\";\nimport { concat, hexToBigInt, pad, toHex } from \"viem\";\nimport type { Signature } from \"../types\";\n\n/**\n * Formats a collection of Signature objects into a single aggregated signature.\n * The format is in the form of EOA_SIGS | CONTRACT_SIG_DATAS. The signatures are ordered\n * by signer address. The EOA SIGS contain the 65 signautre data for EOA signers and 65 bytes containing SIGNER | OFFSET | V for contract signers.\n * The OFFSET is used to fetch the signature data from the CONTRACT_SIG_DATAS.\n *\n * @param {Signature[]} signatures the array of Signature objects to combine into the correct aggregated signature format excluding the upper limits\n * @param {boolean} usingMaxValues a boolean indicating wether or not the UserOperation is using the UPPER_LIMIT for the gas and fee values\n * @returns {Hex} the Hex representation of the signature\n */\nexport const formatSignatures = (\n signatures: Signature[],\n usingMaxValues: boolean = false\n) => {\n let eoaSigs: string = \"\";\n let contractSigs: string = \"\";\n let offset: bigint = BigInt(65 * signatures.length);\n signatures\n .sort((a, b) => {\n const bigintA = hexToBigInt(a.signer);\n const bigintB = hexToBigInt(b.signer);\n\n return bigintA < bigintB ? -1 : bigintA > bigintB ? 1 : 0;\n })\n .forEach((sig) => {\n // add 32 to v if the signature covers the actual gas values\n const addV = sig.userOpSigType === \"ACTUAL\" && !usingMaxValues ? 32 : 0;\n\n if (sig.signerType === \"EOA\") {\n let v =\n parseInt(takeBytes(sig.signature, { count: 1, offset: 64 })) + addV;\n eoaSigs += concat([\n takeBytes(sig.signature, { count: 64 }),\n toHex(v, { size: 1 }),\n ]).slice(2);\n } else {\n const sigLen = BigInt(sig.signature.slice(2).length / 2);\n eoaSigs += concat([\n pad(sig.signer),\n toHex(offset, { size: 32 }),\n toHex(addV, { size: 1 }),\n ]).slice(2);\n contractSigs += concat([\n toHex(sigLen, { size: 32 }),\n sig.signature,\n ]).slice(2);\n offset += sigLen;\n }\n });\n return (\"0x\" + eoaSigs + contractSigs) as `0x${string}`;\n};\n"]}
|
|
@@ -7,9 +7,10 @@ export type SplitAggregateSignatureParams<TAccount extends SmartContractAccount
|
|
|
7
7
|
account: SmartContractAccount;
|
|
8
8
|
request: UserOperationRequest<TEntryPointVersion>;
|
|
9
9
|
};
|
|
10
|
-
export
|
|
10
|
+
export type SplitAggregateSignatureResult = {
|
|
11
11
|
upperLimitPvg: Hex;
|
|
12
12
|
upperLimitMaxFeePerGas: Hex;
|
|
13
13
|
upperLimitMaxPriorityFeePerGas: Hex;
|
|
14
14
|
signatures: Signature[];
|
|
15
|
-
}
|
|
15
|
+
};
|
|
16
|
+
export declare const splitAggregatedSignature: <TAccount extends SmartContractAccount | undefined = SmartContractAccount | undefined>(args: SplitAggregateSignatureParams<TAccount, GetEntryPointFromAccount<TAccount, SmartContractAccount<string, keyof import("@aa-sdk/core").EntryPointRegistryBase<unknown>>>>) => Promise<SplitAggregateSignatureResult>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"splitAggregatedSignature.js","sourceRoot":"","sources":["../../../../../../../src/msca/plugins/multisig/utils/splitAggregatedSignature.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,SAAS,GAIV,MAAM,cAAc,CAAC;AACtB,OAAO,EAAE,OAAO,EAAE,WAAW,EAAE,cAAc,EAAY,MAAM,MAAM,CAAC;AACtE,OAAO,EAAE,+BAA+B,EAAE,MAAM,oBAAoB,CAAC;
|
|
1
|
+
{"version":3,"file":"splitAggregatedSignature.js","sourceRoot":"","sources":["../../../../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G,OAAO,CAC7B,SAAS,CAAC,iBAAiB,EAAE,EAAE,KAAK,EAAE,EAAE,EAAE,MAAM,EAAE,CAAC,EACnD,QAAQ,CACT,CAAC;QAEF,OAAO;YACL,MAAM;YACN,UAAU;YACV,aAAa,EAAE,YAAY;YAC3B,SAAS,EAAE,SAAS,CAAC,iBAAiB,EAAE;gBACtC,KAAK,EAAE,eAAe;gBACtB,MAAM,EAAE,MAAM,GAAG,EAAE;aACpB,CAAC;SACH,CAAC;IACJ,CAAC,CACF,CAAC;IAEF,OAAO;QACL,aAAa,EAAE,GAAG;QAClB,sBAAsB,EAAE,YAAY;QACpC,8BAA8B,EAAE,oBAAoB;QACpD,UAAU,EAAE,MAAM,OAAO,CAAC,GAAG,CAAC,UAAU,CAAC;KAC1C,CAAC;AACJ,CAAC,CAAC","sourcesContent":["import {\n takeBytes,\n type GetEntryPointFromAccount,\n type SmartContractAccount,\n type UserOperationRequest,\n} from \"@aa-sdk/core\";\nimport { fromHex, hashMessage, recoverAddress, type Hex } from \"viem\";\nimport { InvalidAggregatedSignatureError } from \"../../../errors.js\";\nimport type { Signature } from \"../types.js\";\n\nexport type SplitAggregateSignatureParams<\n TAccount extends SmartContractAccount | undefined =\n | SmartContractAccount\n | undefined,\n TEntryPointVersion extends GetEntryPointFromAccount<TAccount> = GetEntryPointFromAccount<TAccount>\n> = {\n aggregatedSignature: Hex;\n threshold: number;\n account: SmartContractAccount;\n request: UserOperationRequest<TEntryPointVersion>;\n};\n\nexport type SplitAggregateSignatureResult = {\n upperLimitPvg: Hex;\n upperLimitMaxFeePerGas: Hex;\n upperLimitMaxPriorityFeePerGas: Hex;\n signatures: Signature[];\n};\n\n/**\n * Takes an aggregated signature and threshold and splits it into its components\n *\n * @param {SplitAggregateSignatureParams<TAccount>} args - the arguments for the split\n * @param {Hex} args.aggregateSignature - the aggregated signature to split\n * @param {number} args.threshold - the threshold for the signature\n * @param {SmartContractAccount} args.account - the account which the signature is valid for\n * @param {UserOperationRequest<TEntryPointVersion>} args.request - the user operation request that the signature is for\n * @returns {Promise<SplitAggregateSignatureResult>} the signature split into its upper limits and current signatures\n */\nexport const splitAggregatedSignature = async <\n TAccount extends SmartContractAccount | undefined =\n | SmartContractAccount\n | undefined\n>(\n args: SplitAggregateSignatureParams<TAccount>\n): Promise<SplitAggregateSignatureResult> => {\n const { aggregatedSignature, threshold, account, request } = args;\n if (aggregatedSignature.length < 192 + (65 * threshold - 1)) {\n throw new InvalidAggregatedSignatureError();\n }\n\n // UserOp.sig format:\n // 0-32: upperLimitPreVerificationGas\n // 32-64: upperLimitMaxFeePerGas\n // 64-96: upperLimitMaxPriorityFeePerGas\n // 96-96+n: k signatures, each sig is 65 bytes each (so n = 65 * k)\n // 96+n-: contract signatures if any\n const pvg = takeBytes(aggregatedSignature, { count: 32 });\n const maxFeePerGas = takeBytes(aggregatedSignature, {\n count: 32,\n offset: 32,\n });\n const maxPriorityFeePerGas = takeBytes(aggregatedSignature, {\n count: 32,\n offset: 64,\n });\n const signaturesAndData = takeBytes(aggregatedSignature, {\n offset: 96,\n });\n\n const signatureHexes = (() => {\n const signatureStr = takeBytes(signaturesAndData, {\n count: 65 * threshold - 1,\n });\n const signatures: Hex[] = [];\n for (let i = 0; i < threshold - 1; i++) {\n signatures.push(takeBytes(signatureStr, { count: 65, offset: i * 65 }));\n }\n\n return signatures;\n })();\n\n const signatures: Promise<Signature>[] = signatureHexes.map(\n async (signature): Promise<Signature> => {\n // in RSV, v is the last byte of a 65 byte signature\n const v = BigInt(takeBytes(signature, { count: 1, offset: 64 }));\n const signerType = v === 0n ? \"CONTRACT\" : \"EOA\";\n if (signerType === \"EOA\") {\n // To recover the signer from just the user op and the raw EOA signature, we need to perform an EC recover. The input hash to recover from should be the original user op hash, with the upper limit gas values, wrapped in the standard EIP-191 wrapper format.\n const hash = hashMessage({\n raw: account.getEntryPoint().getUserOperationHash({\n ...request,\n preVerificationGas: pvg,\n maxFeePerGas,\n maxPriorityFeePerGas,\n }),\n });\n\n return {\n // the signer doesn't get used here for EOAs\n // TODO: nope. this needs to actually do an ec recover\n signer: await recoverAddress({ hash, signature }),\n signature,\n signerType,\n userOpSigType: \"UPPERLIMIT\",\n };\n }\n\n const signer = takeBytes(signature, { count: 20, offset: 12 });\n const offset = fromHex(\n takeBytes(signature, { count: 32, offset: 32 }),\n \"number\"\n );\n const signatureLength = fromHex(\n takeBytes(signaturesAndData, { count: 32, offset }),\n \"number\"\n );\n\n return {\n signer,\n signerType,\n userOpSigType: \"UPPERLIMIT\",\n signature: takeBytes(signaturesAndData, {\n count: signatureLength,\n offset: offset + 32,\n }),\n };\n }\n );\n\n return {\n upperLimitPvg: pvg,\n upperLimitMaxFeePerGas: maxFeePerGas,\n upperLimitMaxPriorityFeePerGas: maxPriorityFeePerGas,\n signatures: await Promise.all(signatures),\n };\n};\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"permissions.js","sourceRoot":"","sources":["../../../../../../src/msca/plugins/session-key/permissions.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAA0B,MAAM,MAAM,CAAC;AAClE,OAAO,EAAE,+BAA+B,EAAE,MAAM,sCAAsC,CAAC;AAEvF,MAAM,CAAN,IAAY,wBAIX;AAJD,WAAY,wBAAwB;IAClC,iFAAa,CAAA;IACb,+EAAY,CAAA;IACZ,+FAAoB,CAAA;AACtB,CAAC,EAJW,wBAAwB,KAAxB,wBAAwB,QAInC;AAsDD,MAAM,OAAO,4BAA4B;IAAzC;QACU;;;;mBACN,wBAAwB,CAAC,SAAS;WAAC;QAC7B;;;;mBAAsD,EAAE;WAAC;QACzD;;;;mBAAqD,EAAE;WAAC;QACxD;;;;;WAAuB;QACvB;;;;;WAA0C;QAC1C;;;;mBAA4C,EAAE;WAAC;QAC/C;;;;;WAA+B;QAC/B;;;;;WAA6B;IAyHvC,CAAC;IAvHQ,4BAA4B,CAAC,OAAiC;QACnE,IAAI,CAAC,0BAA0B,GAAG,OAAO,CAAC;QAC1C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AI,EAAE,CAAC,UAAU,CAAC,UAAU,EAAE,UAAU,CAAC,eAAe,IAAI,CAAC,CAAC;aAC/D,CAAC,EACJ,IAAI,CAAC,cAAc,CACpB;YACD,IAAI,CAAC,eAAe,CAClB,CAAC,SAAS,EAAE,EAAE,CACZ,kBAAkB,CAAC;gBACjB,GAAG,EAAE,+BAA+B;gBACpC,YAAY,EAAE,sBAAsB;gBACpC,IAAI,EAAE,CAAC,SAAS,CAAC;aAClB,CAAC,EACJ,IAAI,CAAC,kBAAkB,CACxB;SACF,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,KAAK,IAAI,CAAC,CAAC;IAC9B,CAAC;IAEO,eAAe,CAAI,MAAyB,EAAE,KAAS;QAC7D,IAAI,CAAC,KAAK;YAAE,OAAO,IAAI,CAAC;QAExB,OAAO,MAAM,CAAC,KAAK,CAAC,CAAC;IACvB,CAAC;CACF","sourcesContent":["import { encodeFunctionData, type Address, type Hex } from \"viem\";\nimport { SessionKeyPermissionsUpdatesAbi } from \"./SessionKeyPermissionsUpdatesAbi.js\";\n\nexport enum SessionKeyAccessListType {\n ALLOWLIST = 0,\n DENYLIST = 1,\n ALLOW_ALL_ACCESS = 2,\n}\n\nexport type ContractAccessEntry = {\n // The contract address to add or remove.\n contractAddress: Address;\n // Whether the contract address should be on the list.\n isOnList: boolean;\n // Whether to check selectors for the contract address.\n checkSelectors: boolean;\n};\n\nexport type ContractMethodEntry = {\n // The contract address to add or remove.\n contractAddress: Address;\n // The function selector to add or remove.\n methodSelector: Hex;\n // Whether the function selector should be on the list.\n isOnList: boolean;\n};\n\nexport type TimeRange = {\n validFrom: number;\n validUntil: number;\n};\n\nexport type NativeTokenLimit = {\n spendLimit: bigint;\n // The time interval over which the spend limit is enforced. If unset, there is no time\n /// interval by which the limit is refreshed.\n refreshInterval?: number;\n};\n\nexport type Erc20TokenLimit = {\n tokenAddress: Address;\n spendLimit: bigint;\n // The time interval over which the spend limit is enforced. If unset, there is no time\n /// interval by which the limit is refreshed.\n refreshInterval?: number;\n};\n\n// uint256 spendLimit, uint48 refreshInterval\nexport type GasSpendLimit = {\n // The amount, in wei, of native tokens that a session key can spend on gas.\n // Note that this is not the same as the gas limit for a user operation, which is measured in units of gas.\n // This tracks gas units * gas price.\n spendLimit: bigint;\n // The time interval over which the spend limit is enforced. If unset, there is no time\n /// interval by which the limit is refreshed.\n refreshInterval?: number;\n};\n\n/**\n * A builder for creating the hex-encoded data for updating session key permissions.\n */\nexport class SessionKeyPermissionsBuilder {\n private _contractAccessControlType: SessionKeyAccessListType =\n SessionKeyAccessListType.ALLOWLIST;\n private _contractAddressAccessEntrys: ContractAccessEntry[] = [];\n private _contractMethodAccessEntrys: ContractMethodEntry[] = [];\n private _timeRange?: TimeRange;\n private _nativeTokenSpendLimit?: NativeTokenLimit;\n private _erc20TokenSpendLimits: Erc20TokenLimit[] = [];\n private _gasSpendLimit?: GasSpendLimit;\n private _requiredPaymaster?: Address;\n\n public setContractAccessControlType(aclType: SessionKeyAccessListType) {\n this._contractAccessControlType = aclType;\n return this;\n }\n\n public addContractAddressAccessEntry(entry: ContractAccessEntry) {\n this._contractAddressAccessEntrys.push(entry);\n return this;\n }\n\n public addContractFunctionAccessEntry(entry: ContractMethodEntry) {\n this._contractMethodAccessEntrys.push(entry);\n return this;\n }\n\n public setTimeRange(timeRange: TimeRange) {\n this._timeRange = timeRange;\n return this;\n }\n\n public setNativeTokenSpendLimit(limit: NativeTokenLimit) {\n this._nativeTokenSpendLimit = limit;\n return this;\n }\n\n public addErc20TokenSpendLimit(limit: Erc20TokenLimit) {\n this._erc20TokenSpendLimits.push(limit);\n return this;\n }\n\n public setGasSpendLimit(limit: GasSpendLimit) {\n this._gasSpendLimit = limit;\n return this;\n }\n\n public setRequiredPaymaster(paymaster: Address) {\n this._requiredPaymaster = paymaster;\n return this;\n }\n\n public encode(): Hex[] {\n return [\n encodeFunctionData({\n abi: SessionKeyPermissionsUpdatesAbi,\n functionName: \"setAccessListType\",\n args: [this._contractAccessControlType],\n }),\n ...this._contractAddressAccessEntrys.map((entry) =>\n encodeFunctionData({\n abi: SessionKeyPermissionsUpdatesAbi,\n functionName: \"updateAccessListAddressEntry\",\n args: [entry.contractAddress, entry.isOnList, entry.checkSelectors],\n })\n ),\n ...this._contractMethodAccessEntrys.map((entry) =>\n encodeFunctionData({\n abi: SessionKeyPermissionsUpdatesAbi,\n functionName: \"updateAccessListFunctionEntry\",\n args: [entry.contractAddress, entry.methodSelector, entry.isOnList],\n })\n ),\n this.encodeIfDefined(\n (timeRange) =>\n encodeFunctionData({\n abi: SessionKeyPermissionsUpdatesAbi,\n functionName: \"updateTimeRange\",\n args: [timeRange.validFrom, timeRange.validUntil],\n }),\n this._timeRange\n ),\n this.encodeIfDefined(\n (nativeSpendLimit) =>\n encodeFunctionData({\n abi: SessionKeyPermissionsUpdatesAbi,\n functionName: \"setNativeTokenSpendLimit\",\n args: [\n nativeSpendLimit.spendLimit,\n nativeSpendLimit.refreshInterval ?? 0,\n ],\n }),\n this._nativeTokenSpendLimit\n ),\n ...this._erc20TokenSpendLimits.map((erc20SpendLimit) =>\n encodeFunctionData({\n abi: SessionKeyPermissionsUpdatesAbi,\n functionName: \"setERC20SpendLimit\",\n args: [\n erc20SpendLimit.tokenAddress,\n erc20SpendLimit.spendLimit,\n erc20SpendLimit.refreshInterval ?? 0,\n ],\n })\n ),\n this.encodeIfDefined(\n (spendLimit) =>\n encodeFunctionData({\n abi: SessionKeyPermissionsUpdatesAbi,\n functionName: \"setGasSpendLimit\",\n args: [spendLimit.spendLimit, spendLimit.refreshInterval ?? 0],\n }),\n this._gasSpendLimit\n ),\n this.encodeIfDefined(\n (paymaster) =>\n encodeFunctionData({\n abi: SessionKeyPermissionsUpdatesAbi,\n functionName: \"setRequiredPaymaster\",\n args: [paymaster],\n }),\n this._requiredPaymaster\n ),\n ].filter((x) => x !== \"0x\");\n }\n\n private encodeIfDefined<T>(encode: (param: T) => Hex, param?: T): Hex {\n if (!param) return \"0x\";\n\n return encode(param);\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"permissions.js","sourceRoot":"","sources":["../../../../../../src/msca/plugins/session-key/permissions.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAA0B,MAAM,MAAM,CAAC;AAClE,OAAO,EAAE,+BAA+B,EAAE,MAAM,sCAAsC,CAAC;AAEvF,MAAM,CAAN,IAAY,wBAIX;AAJD,WAAY,wBAAwB;IAClC,iFAAa,CAAA;IACb,+EAAY,CAAA;IACZ,+FAAoB,CAAA;AACtB,CAAC,EAJW,wBAAwB,KAAxB,wBAAwB,QAInC;AAsDD,MAAM,OAAO,4BAA4B;IAAzC;QACU;;;;mBACN,wBAAwB,CAAC,SAAS;WAAC;QAC7B;;;;mBAAsD,EAAE;WAAC;QACzD;;;;mBAAqD,EAAE;WAAC;QACxD;;;;;WAAuB;QACvB;;;;;WAA0C;QAC1C;;;;mBAA4C,EAAE;WAAC;QAC/C;;;;;WAA+B;QAC/B;;;;;WAA6B;IA2QvC,CAAC;IA3PQ,4BAA4B,CAAC,OAAiC;QACnE,IAAI,CAAC,0BAA0B,GAAG,OAAO,CAAC;QAC1C,OAAO,IAAI,CAAC;IACd,CAAC;IAoBM,6BAA6B,CAAC,KAA0B;QAC7D,IAAI,CAAC,4BAA4B,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;QAC9C,OAAO,IAAI,CAAC;IACd,CAAC;IAoBM,8BAA8B,CAAC,KAA0B;QAC9D,IAAI,CAAC,2BAA2B,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;QAC7C,OAAO,IAAI,CAAC;IACd,CAAC;IAmBM,YAAY,CAAC,SAAoB;QACtC,IAAI,CAAC,UAAU,GAAG,SAAS,CAAC;QAC5B,OAAO,IAAI,CAAC;IACd,CAAC;IAmBM,wBAAwB,CAAC,KAAuB;QACrD,IAAI,CAAC,sBAAsB,GAAG,KAAK,CAAC;QACpC,OAAO,IAAI,CAAC;IACd,CAAC;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AE,OAAO,IAAI,CAAC;QAExB,OAAO,MAAM,CAAC,KAAK,CAAC,CAAC;IACvB,CAAC;CACF","sourcesContent":["import { encodeFunctionData, type Address, type Hex } from \"viem\";\nimport { SessionKeyPermissionsUpdatesAbi } from \"./SessionKeyPermissionsUpdatesAbi.js\";\n\nexport enum SessionKeyAccessListType {\n ALLOWLIST = 0,\n DENYLIST = 1,\n ALLOW_ALL_ACCESS = 2,\n}\n\nexport type ContractAccessEntry = {\n // The contract address to add or remove.\n contractAddress: Address;\n // Whether the contract address should be on the list.\n isOnList: boolean;\n // Whether to check selectors for the contract address.\n checkSelectors: boolean;\n};\n\nexport type ContractMethodEntry = {\n // The contract address to add or remove.\n contractAddress: Address;\n // The function selector to add or remove.\n methodSelector: Hex;\n // Whether the function selector should be on the list.\n isOnList: boolean;\n};\n\nexport type TimeRange = {\n validFrom: number;\n validUntil: number;\n};\n\nexport type NativeTokenLimit = {\n spendLimit: bigint;\n // The time interval over which the spend limit is enforced. If unset, there is no time\n /// interval by which the limit is refreshed.\n refreshInterval?: number;\n};\n\nexport type Erc20TokenLimit = {\n tokenAddress: Address;\n spendLimit: bigint;\n // The time interval over which the spend limit is enforced. If unset, there is no time\n /// interval by which the limit is refreshed.\n refreshInterval?: number;\n};\n\n// uint256 spendLimit, uint48 refreshInterval\nexport type GasSpendLimit = {\n // The amount, in wei, of native tokens that a session key can spend on gas.\n // Note that this is not the same as the gas limit for a user operation, which is measured in units of gas.\n // This tracks gas units * gas price.\n spendLimit: bigint;\n // The time interval over which the spend limit is enforced. If unset, there is no time\n /// interval by which the limit is refreshed.\n refreshInterval?: number;\n};\n\n/**\n * A builder for creating the hex-encoded data for updating session key permissions.\n */\nexport class SessionKeyPermissionsBuilder {\n private _contractAccessControlType: SessionKeyAccessListType =\n SessionKeyAccessListType.ALLOWLIST;\n private _contractAddressAccessEntrys: ContractAccessEntry[] = [];\n private _contractMethodAccessEntrys: ContractMethodEntry[] = [];\n private _timeRange?: TimeRange;\n private _nativeTokenSpendLimit?: NativeTokenLimit;\n private _erc20TokenSpendLimits: Erc20TokenLimit[] = [];\n private _gasSpendLimit?: GasSpendLimit;\n private _requiredPaymaster?: Address;\n\n /**\n * Sets the access control type for the contract and returns the current instance for method chaining.\n *\n * @example\n * ```ts\n * import { SessionKeyPermissionsBuilder } from \"@account-kit/smart-contracts\";\n *\n * const builder = new SessionKeyPermissionsBuilder();\n * builder.setContractAccessControlType(SessionKeyAccessListType.ALLOWLIST);\n * ```\n *\n * @param {SessionKeyAccessListType} aclType The access control type for the session key\n * @returns {SessionKeyPermissionsBuilder} The current instance for method chaining\n */\n public setContractAccessControlType(aclType: SessionKeyAccessListType) {\n this._contractAccessControlType = aclType;\n return this;\n }\n\n /**\n * Adds a contract access entry to the internal list of contract address access entries.\n *\n * @example\n * ```ts\n * import { SessionKeyPermissionsBuilder } from \"@account-kit/smart-contracts\";\n *\n * const builder = new SessionKeyPermissionsBuilder();\n * builder.addContractAddressAccessEntry({\n * contractAddress: \"0x1234\",\n * isOnList: true,\n * checkSelectors: true,\n * });\n * ```\n *\n * @param {ContractAccessEntry} entry the contract access entry to be added\n * @returns {SessionKeyPermissionsBuilder} the instance of the current class for chaining\n */\n public addContractAddressAccessEntry(entry: ContractAccessEntry) {\n this._contractAddressAccessEntrys.push(entry);\n return this;\n }\n\n /**\n * Adds a contract method entry to the `_contractMethodAccessEntrys` array.\n *\n * @example\n * ```ts\n * import { SessionKeyPermissionsBuilder } from \"@account-kit/smart-contracts\";\n *\n * const builder = new SessionKeyPermissionsBuilder();\n * builder.addContractAddressAccessEntry({\n * contractAddress: \"0x1234\",\n * methodSelector: \"0x45678\",\n * isOnList: true,\n * });\n * ```\n *\n * @param {ContractMethodEntry} entry The contract method entry to be added\n * @returns {SessionKeyPermissionsBuilder} The instance of the class for method chaining\n */\n public addContractFunctionAccessEntry(entry: ContractMethodEntry) {\n this._contractMethodAccessEntrys.push(entry);\n return this;\n }\n\n /**\n * Sets the time range for an object and returns the object itself for chaining.\n *\n * @example\n * ```ts\n * import { SessionKeyPermissionsBuilder } from \"@account-kit/smart-contracts\";\n *\n * const builder = new SessionKeyPermissionsBuilder();\n * builder.setTimeRange({\n * validFrom: Date.now(),\n * validUntil: Date.now() + (15 * 60 * 1000),\n * });\n * ```\n *\n * @param {TimeRange} timeRange The time range to be set\n * @returns {SessionKeyPermissionsBuilder} The current object for method chaining\n */\n public setTimeRange(timeRange: TimeRange) {\n this._timeRange = timeRange;\n return this;\n }\n\n /**\n * Sets the native token spend limit and returns the instance for chaining.\n *\n * @example\n * ```ts\n * import { SessionKeyPermissionsBuilder } from \"@account-kit/smart-contracts\";\n *\n * const builder = new SessionKeyPermissionsBuilder();\n * builder.setNativeTokenSpendLimit({\n * spendLimit: 1000000000000000000n,\n * refreshInterval: 3600,\n * });\n * ```\n *\n * @param {NativeTokenLimit} limit The limit to set for native token spending\n * @returns {SessionKeyPermissionsBuilder} The instance for chaining\n */\n public setNativeTokenSpendLimit(limit: NativeTokenLimit) {\n this._nativeTokenSpendLimit = limit;\n return this;\n }\n\n /**\n * Adds an ERC20 token spend limit to the list of limits and returns the updated object.\n *\n * @example\n * ```ts\n * import { SessionKeyPermissionsBuilder } from \"@account-kit/smart-contracts\";\n *\n * const builder = new SessionKeyPermissionsBuilder();\n * builder.addErc20TokenSpendLimit({\n * tokenAddress: \"0x1234\",\n * spendLimit: 1000000000000000000n,\n * refreshInterval: 3600,\n * });\n * ```\n *\n * @param {Erc20TokenLimit} limit The ERC20 token spend limit to be added\n * @returns {object} The updated object with the new ERC20 token spend limit\n */\n public addErc20TokenSpendLimit(limit: Erc20TokenLimit) {\n this._erc20TokenSpendLimits.push(limit);\n return this;\n }\n\n /**\n * Sets the gas spend limit and returns the current instance for method chaining.\n *\n * @example\n * ```ts\n * import { SessionKeyPermissionsBuilder } from \"@account-kit/smart-contracts\";\n *\n * const builder = new SessionKeyPermissionsBuilder();\n * builder.setGasSpendLimit({\n * spendLimit: 1000000000000000000n,\n * refreshInterval: 3600,\n * });\n * ```\n *\n * @param {GasSpendLimit} limit - The gas spend limit to be set\n * @returns {SessionKeyPermissionsBuilder} The current instance for chaining\n */ public setGasSpendLimit(limit: GasSpendLimit) {\n this._gasSpendLimit = limit;\n return this;\n }\n\n /**\n * Sets the required paymaster address.\n *\n * @example\n * ```ts\n * import { SessionKeyPermissionsBuilder } from \"@account-kit/smart-contracts\";\n *\n * const builder = new SessionKeyPermissionsBuilder();\n * builder.setRequiredPaymaster(\"0x1234\");\n * ```\n *\n * @param {Address} paymaster the address of the paymaster to be set\n * @returns {SessionKeyPermissionsBuilder} the current instance for method chaining\n */\n public setRequiredPaymaster(paymaster: Address) {\n this._requiredPaymaster = paymaster;\n return this;\n }\n\n /**\n * Encodes various function calls into an array of hexadecimal strings based on the provided permissions and limits.\n *\n * @example\n * ```ts\n * import { SessionKeyPermissionsBuilder } from \"@account-kit/smart-contracts\";\n *\n * const builder = new SessionKeyPermissionsBuilder();\n * builder.setRequiredPaymaster(\"0x1234\");\n * const encoded = builder.encode();\n * ```\n *\n * @returns {Hex[]} An array of encoded hexadecimal strings representing the function calls for setting access control, permissions, and limits.\n */\n public encode(): Hex[] {\n return [\n encodeFunctionData({\n abi: SessionKeyPermissionsUpdatesAbi,\n functionName: \"setAccessListType\",\n args: [this._contractAccessControlType],\n }),\n ...this._contractAddressAccessEntrys.map((entry) =>\n encodeFunctionData({\n abi: SessionKeyPermissionsUpdatesAbi,\n functionName: \"updateAccessListAddressEntry\",\n args: [entry.contractAddress, entry.isOnList, entry.checkSelectors],\n })\n ),\n ...this._contractMethodAccessEntrys.map((entry) =>\n encodeFunctionData({\n abi: SessionKeyPermissionsUpdatesAbi,\n functionName: \"updateAccessListFunctionEntry\",\n args: [entry.contractAddress, entry.methodSelector, entry.isOnList],\n })\n ),\n this.encodeIfDefined(\n (timeRange) =>\n encodeFunctionData({\n abi: SessionKeyPermissionsUpdatesAbi,\n functionName: \"updateTimeRange\",\n args: [timeRange.validFrom, timeRange.validUntil],\n }),\n this._timeRange\n ),\n this.encodeIfDefined(\n (nativeSpendLimit) =>\n encodeFunctionData({\n abi: SessionKeyPermissionsUpdatesAbi,\n functionName: \"setNativeTokenSpendLimit\",\n args: [\n nativeSpendLimit.spendLimit,\n nativeSpendLimit.refreshInterval ?? 0,\n ],\n }),\n this._nativeTokenSpendLimit\n ),\n ...this._erc20TokenSpendLimits.map((erc20SpendLimit) =>\n encodeFunctionData({\n abi: SessionKeyPermissionsUpdatesAbi,\n functionName: \"setERC20SpendLimit\",\n args: [\n erc20SpendLimit.tokenAddress,\n erc20SpendLimit.spendLimit,\n erc20SpendLimit.refreshInterval ?? 0,\n ],\n })\n ),\n this.encodeIfDefined(\n (spendLimit) =>\n encodeFunctionData({\n abi: SessionKeyPermissionsUpdatesAbi,\n functionName: \"setGasSpendLimit\",\n args: [spendLimit.spendLimit, spendLimit.refreshInterval ?? 0],\n }),\n this._gasSpendLimit\n ),\n this.encodeIfDefined(\n (paymaster) =>\n encodeFunctionData({\n abi: SessionKeyPermissionsUpdatesAbi,\n functionName: \"setRequiredPaymaster\",\n args: [paymaster],\n }),\n this._requiredPaymaster\n ),\n ].filter((x) => x !== \"0x\");\n }\n\n private encodeIfDefined<T>(encode: (param: T) => Hex, param?: T): Hex {\n if (!param) return \"0x\";\n\n return encode(param);\n }\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"signer.js","sourceRoot":"","sources":["../../../../../../src/msca/plugins/session-key/signer.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAA2B,MAAM,cAAc,CAAC;AAQ3E,OAAO,EAAE,kBAAkB,EAAE,MAAM,eAAe,CAAC;AACnD,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,MAAM,CAAC,MAAM,sBAAsB,GAAG,CAAC,CAAC,MAAM,CAAC;IAC7C,WAAW,EAAE,CAAC;SACX,KAAK,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,eAAe,CAAC,EAAE,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C;YAE7C,IAAI,GAAG,EAAE,CAAC;gBACR,OAAO,GAAG,CAAC;YACb,CAAC;iBAAM,CAAC;gBACN,MAAM,MAAM,GAAG,kBAAkB,EAAE,CAAC;gBACpC,OAAO,CAAC,OAAO,CAAC,IAAI,CAAC,UAAU,EAAE,MAAM,CAAC,CAAC;gBACzC,OAAO,MAAM,CAAC;YAChB,CAAC;QACH,CAAC,CAAC,EAAS,CAAC;QAEZ,IAAI,CAAC,KAAK,GAAG,kBAAkB,CAAC,yBAAyB,CAAC,UAAU,CAAC,CAAC;IACxE,CAAC;CA8FF","sourcesContent":["import { LocalAccountSigner, type SmartAccountSigner } from \"@aa-sdk/core\";\nimport type {\n Hex,\n PrivateKeyAccount,\n SignableMessage,\n TypedData,\n TypedDataDefinition,\n} from \"viem\";\nimport { generatePrivateKey } from \"viem/accounts\";\nimport { z } from \"zod\";\n\nexport const SessionKeySignerSchema = z.object({\n storageType: z\n .union([z.literal(\"local-storage\"), z.literal(\"session-storage\")])\n .or(z.custom<Storage>())\n .default(\"local-storage\"),\n storageKey: z.string().default(\"session-key-signer:session-key\"),\n});\n\nexport type SessionKeySignerConfig = z.input<typeof SessionKeySignerSchema>;\nexport const SESSION_KEY_SIGNER_TYPE_PFX = \"alchemy:session-key\";\n\n/**\n * A simple session key signer that uses localStorage or sessionStorage to store\n * a private key. If the key is not found, it will generate a new one and store\n * it in the storage.\n */\nexport class SessionKeySigner\n implements SmartAccountSigner<LocalAccountSigner<PrivateKeyAccount>>\n{\n signerType: string;\n inner: LocalAccountSigner<PrivateKeyAccount>;\n private storageType: \"local-storage\" | \"session-storage\" | Storage;\n private storageKey: string;\n\n /**\n * Initializes a new instance of a session key signer with the provided configuration. This will set the `signerType`, `storageKey`, and `storageType`. It will also manage the session key, either fetching it from storage or generating a new one if it doesn't exist.\n *\n * @example\n * ```ts\n * import { SessionKeySigner } from \"@account-kit/smart-contracts\";\n *\n * const signer = new SessionKeySigner();\n * ```\n *\n * @param {SessionKeySignerConfig} config_ the configuration for initializing the session key signer\n */\n constructor(config_: SessionKeySignerConfig = {}) {\n const config = SessionKeySignerSchema.parse(config_);\n this.signerType = `${SESSION_KEY_SIGNER_TYPE_PFX}`;\n this.storageKey = config.storageKey;\n this.storageType = config.storageType;\n\n const sessionKey = (() => {\n const storage =\n typeof this.storageType !== \"string\"\n ? this.storageType\n : this.storageType === \"session-storage\"\n ? sessionStorage\n : localStorage;\n const key = storage.getItem(this.storageKey);\n\n if (key) {\n return key;\n } else {\n const newKey = generatePrivateKey();\n storage.setItem(this.storageKey, newKey);\n return newKey;\n }\n })() as Hex;\n\n this.inner = LocalAccountSigner.privateKeyToAccountSigner(sessionKey);\n }\n\n /**\n * An async function that retrieves the address using the inner object's `getAddress` method.\n *\n * @example\n * ```ts\n * import { SessionKeySigner } from \"@account-kit/smart-contracts\";\n *\n * const signer = new SessionKeySigner();\n * const sessionKeyAddress = await signer.getAddress();\n * ```\n *\n * @returns {Promise<string>} A promise that resolves to the address as a string\n */\n getAddress: () => Promise<`0x${string}`> = async () => {\n return this.inner.getAddress();\n };\n\n /**\n * Signs a message using the inner signer.\n *\n * @example\n * ```ts\n * import { SessionKeySigner } from \"@account-kit/smart-contracts\";\n *\n * const signer = new SessionKeySigner();\n * const sessionKeyAddress = await signer.signMessage(\"hello\");\n * ```\n *\n * @param {SignableMessage} msg The message to sign\n * @returns {Promise<Hex>} A promise that resolves to the signed message\n */\n signMessage: (msg: SignableMessage) => Promise<`0x${string}`> = async (\n msg\n ) => {\n return this.inner.signMessage(msg);\n };\n\n /**\n * Signs the provided typed data using the inner signer.\n *\n * @example\n * ```ts\n * import { SessionKeySigner } from \"@account-kit/smart-contracts\";\n *\n * const signer = new SessionKeySigner();\n * console.log(await signer.signTypedData({\n * types: {\n * \"Message\": [{ name: \"content\", type: \"string\" }]\n * },\n * primaryType: \"Message\",\n * message: { content: \"Hello\" },\n * }));\n * ```\n *\n * @template TTypedData - The typed data type, which extends `TypedData` or a record of unknown keys to unknown values.\n * @template TPrimaryType - The primary type of the typed data.\n *\n * @param {TypedDataDefinition<TTypedData, TPrimaryType>} params The parameters containing the typed data definition and primary type.\n * @returns {Promise<string>} A promise that resolves to the signed typed data as a string.\n */\n signTypedData = async <\n const TTypedData extends TypedData | { [key: string]: unknown },\n TPrimaryType extends string = string\n >(\n params: TypedDataDefinition<TTypedData, TPrimaryType>\n ) => {\n return this.inner.signTypedData(params);\n };\n\n /**\n * Generates a new private key and stores it in the storage.\n *\n * @example\n * ```ts\n * import { SessionKeySigner } from \"@account-kit/smart-contracts\";\n *\n * const signer = new SessionKeySigner();\n * const newSessionKey = signer.generateNewKey();\n * ```\n *\n * @returns {Address} The public address of the new key.\n */\n generateNewKey = () => {\n const storage =\n this.storageType === \"session-storage\" ? sessionStorage : localStorage;\n\n const newKey = generatePrivateKey();\n storage.setItem(this.storageKey, newKey);\n this.inner = LocalAccountSigner.privateKeyToAccountSigner(newKey);\n\n return this.inner.inner.address;\n };\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../../../../src/msca/utils.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,oBAAoB,EACpB,kBAAkB,GAOnB,MAAM,cAAc,CAAC;AACtB,OAAO,EACL,QAAQ,EACR,eAAe,EACf,IAAI,EACJ,WAAW,EACX,OAAO,EACP,QAAQ,EACR,eAAe,EACf,OAAO,EACP,WAAW,EACX,OAAO,GACR,MAAM,oBAAoB,CAAC;AAE5B,OAAO,EACL,MAAM,EACN,mBAAmB,EACnB,kBAAkB,EAClB,oBAAoB,EACpB,SAAS,EACT,kBAAkB,GACnB,MAAM,MAAM,CAAC;AACd,OAAO,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;AAC/C,OAAO,EAAE,kCAAkC,EAAE,MAAM,2CAA2C,CAAC;AAC/F,OAAO,EAAE,4BAA4B,EAAE,MAAM,qCAAqC,CAAC;AACnF,OAAO,EACL,8BAA8B,GAE/B,MAAM,gCAA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E,UAAU;QACf,YAAY,EAAE,gBAAgB;QAC9B,MAAM,EAAE,gBAAgB;KACzB,CAAC,CACH,CAAC;IAEF,MAAM,YAAY,GAAG,mBAAmB,CACtC,kBAAkB,CAAC,WAAW,CAAC,EAC/B,KAAK,CAAC,OAAO,CAAC,aAAa,CAAC,CAAC,CAAC,CAAC,CAAC,aAAa,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,aAAa,CAAC,CAAC,CACnE,CAAC;IAEF,MAAM,qBAAqB,GAAG,mBAAmB,CAC/C,kBAAkB,CAAC,oBAAoB,CAAC,EACxC,CAAC,CAAC,8BAA8B,CAAC,EAAE,CAAC,YAAY,CAAC,CAAC,CACnD,CAAC;IAEF,MAAM,yBAAyB,GAAG,kBAAkB,CAAC;QACnD,GAAG,EAAE,4BAA4B;QACjC,YAAY,EAAE,YAAY;QAC1B,IAAI,EAAE,CAAC,CAAC,iBAAiB,CAAC,EAAE,qBAAqB,CAAC;KACnD,CAAC,CAAC;IAEH,OAAO;QACL,WAAW;QACX,kBAAkB,EAAE,yBAAyB;KAC9C,CAAC;AACJ,CAAC","sourcesContent":["import {\n AccountNotFoundError,\n ChainNotFoundError,\n type GetAccountParameter,\n type SmartAccountClient,\n type SmartAccountSigner,\n type SmartContractAccount,\n type SmartContractAccountWithSigner,\n type UpgradeToData,\n} from \"@aa-sdk/core\";\nimport {\n arbitrum,\n arbitrumSepolia,\n base,\n baseSepolia,\n mainnet,\n optimism,\n optimismSepolia,\n polygon,\n polygonAmoy,\n sepolia,\n} from \"@account-kit/infra\";\nimport type { Address, Chain, Transport } from \"viem\";\nimport {\n custom,\n encodeAbiParameters,\n encodeFunctionData,\n encodeFunctionResult,\n keccak256,\n parseAbiParameters,\n} from \"viem\";\nimport { IPluginAbi } from \"./abis/IPlugin.js\";\nimport { MultiOwnerModularAccountFactoryAbi } from \"./abis/MultiOwnerModularAccountFactory.js\";\nimport { UpgradeableModularAccountAbi } from \"./abis/UpgradeableModularAccount.js\";\nimport {\n createMultiOwnerModularAccount,\n type MultiOwnerModularAccount,\n} from \"./account/multiOwnerAccount.js\";\nimport { MultiOwnerPlugin } from \"./plugins/multi-owner/plugin.js\";\n\n/**\n * Utility method returning the default multi sig msca factory address given a {@link Chain} object\n *\n * @param chain a {@link Chain} object\n * @returns a {@link Address} for the given chain\n * @throws if the chain doesn't have an address currently deployed\n */\nexport const getDefaultMultisigModularAccountFactoryAddress = (\n chain: Chain\n): Address => {\n switch (chain.id) {\n case sepolia.id:\n case baseSepolia.id:\n case polygon.id:\n case mainnet.id:\n case polygonAmoy.id:\n case optimism.id:\n case optimismSepolia.id:\n case arbitrum.id:\n case arbitrumSepolia.id:\n case base.id:\n default:\n return \"0x000000000000204327E6669f00901a57CE15aE15\";\n }\n};\n\n/**\n * Utility method returning the default multi owner msca factory address given a {@link Chain} object\n *\n * @param chain - a {@link Chain} object\n * @returns a {@link Address} for the given chain\n * @throws if the chain doesn't have an address currently deployed\n */\nexport const getDefaultMultiOwnerModularAccountFactoryAddress = (\n chain: Chain\n): Address => {\n switch (chain.id) {\n default:\n return \"0x000000e92D78D90000007F0082006FDA09BD5f11\";\n }\n};\n\nexport type GetMSCAUpgradeToData<\n TSigner extends SmartAccountSigner = SmartAccountSigner,\n TAccount extends\n | SmartContractAccountWithSigner<string, TSigner>\n | undefined = SmartContractAccountWithSigner<string, TSigner> | undefined\n> = {\n multiOwnerPluginAddress?: Address;\n} & GetAccountParameter<TAccount>;\n\n/**\n * Retrieves the data necessary to upgrade to a Multi-Signature Contract Account (MSCA) and provides a method to create a Multi-Owner Modular Account.\n *\n * @example\n * ```ts\n * import { createLightAccountClient, getMSCAUpgradeToData } from \"@account-kit/smart-contracts\";\n *\n * const client = createLightAccountClient(...);\n * const upgradeData = await getMSCAUpgradeToData(client, {});\n * ```\n *\n * @param {SmartAccountClient<TTransport, TChain, TAccount>} client The smart account client\n * @param {GetMSCAUpgradeToData<TSigner, TAccount>} args The arguments required for the upgrade\n * @returns {Promise<UpgradeToData & { createMAAccount: () => Promise<MultiOwnerModularAccount<TSigner>>}>} A promise that resolves to upgrade data augmented with a function to create a Multi-Owner Modular Account\n */\nexport async function getMSCAUpgradeToData<\n TTransport extends Transport = Transport,\n TChain extends Chain | undefined = Chain | undefined,\n TSigner extends SmartAccountSigner = SmartAccountSigner,\n TAccount extends\n | SmartContractAccountWithSigner<string, TSigner>\n | undefined = SmartContractAccountWithSigner<string, TSigner> | undefined\n>(\n client: SmartAccountClient<TTransport, TChain, TAccount>,\n args: GetMSCAUpgradeToData<TSigner, TAccount>\n): Promise<\n UpgradeToData & {\n createMAAccount: () => Promise<MultiOwnerModularAccount<TSigner>>;\n }\n> {\n const { account: account_ = client.account, multiOwnerPluginAddress } = args;\n\n if (!account_) {\n throw new AccountNotFoundError();\n }\n const account = account_ as SmartContractAccountWithSigner<string, TSigner>;\n\n const chain = client.chain;\n if (!chain) {\n throw new ChainNotFoundError();\n }\n\n const initData = await getMAInitializationData({\n client,\n multiOwnerPluginAddress,\n signerAddress: await account.getSigner().getAddress(),\n });\n\n return {\n ...initData,\n createMAAccount: async () =>\n createMultiOwnerModularAccount({\n transport: custom(client.transport),\n chain: chain as Chain,\n signer: account.getSigner(),\n accountAddress: account.address,\n }),\n };\n}\n\nexport type GetMAInitializationDataParams<\n TTransport extends Transport = Transport,\n TChain extends Chain | undefined = Chain | undefined,\n TAccount extends SmartContractAccount | undefined =\n | SmartContractAccount\n | undefined\n> = {\n multiOwnerPluginAddress?: Address;\n client: SmartAccountClient<TTransport, TChain, TAccount>;\n signerAddress: Address | Address[];\n};\n\n/**\n * Retrieves the initialization data for a multi-owner modular account. Throws an error if the client's chain is not found or if the multi-owner plugin address is not retrievable.\n *\n * @example\n * ```ts\n * import { getMAInitializationData } from \"@account-kit/smart-contracts\";\n * import { createSmartAccountClient } from \"@aa-sdk/core\";\n *\n * const client = createSmartAccountClient(...);\n * const initializationData = await getMAInitializationData({\n * client,\n * signerAddress: \"0x...\", // or array of signers\n * });\n * ```\n *\n * @param {GetMAInitializationDataParams<TTransport, TChain, TAccount>} params the parameters for getting initialization data\n * @param {SmartAccountClient<TTransport, TChain, TAccount>} params.client the smart account client\n * @param {Address | Address[]} params.signerAddress the address of the signer or an array of signer addresses\n * @param {Address} [params.multiOwnerPluginAddress] optional address of the multi-owner plugin\n * @returns {Promise<UpgradeToData>} a promise that resolves to the initialization data required for upgrading to a multi-owner modular account\n */\nexport async function getMAInitializationData<\n TTransport extends Transport = Transport,\n TChain extends Chain | undefined = Chain | undefined,\n TAccount extends SmartContractAccount | undefined =\n | SmartContractAccount\n | undefined\n>({\n client,\n multiOwnerPluginAddress,\n signerAddress,\n}: GetMAInitializationDataParams<\n TTransport,\n TChain,\n TAccount\n>): Promise<UpgradeToData> {\n if (!client.chain) {\n throw new ChainNotFoundError();\n }\n\n const factoryAddress = getDefaultMultiOwnerModularAccountFactoryAddress(\n client.chain\n );\n\n const implAddress = await client.readContract({\n abi: MultiOwnerModularAccountFactoryAbi,\n address: factoryAddress,\n functionName: \"IMPL\",\n });\n\n const multiOwnerAddress =\n multiOwnerPluginAddress ?? MultiOwnerPlugin.meta.addresses[client.chain.id];\n\n if (!multiOwnerAddress) {\n throw new Error(\"could not get multi owner plugin address\");\n }\n\n const moPluginManifest = await client.readContract({\n abi: IPluginAbi,\n address: multiOwnerAddress,\n functionName: \"pluginManifest\",\n });\n\n const hashedMultiOwnerPluginManifest = keccak256(\n encodeFunctionResult({\n abi: IPluginAbi,\n functionName: \"pluginManifest\",\n result: moPluginManifest,\n })\n );\n\n const encodedOwner = encodeAbiParameters(\n parseAbiParameters(\"address[]\"),\n Array.isArray(signerAddress) ? [signerAddress] : [[signerAddress]]\n );\n\n const encodedPluginInitData = encodeAbiParameters(\n parseAbiParameters(\"bytes32[], bytes[]\"),\n [[hashedMultiOwnerPluginManifest], [encodedOwner]]\n );\n\n const encodedMSCAInitializeData = encodeFunctionData({\n abi: UpgradeableModularAccountAbi,\n functionName: \"initialize\",\n args: [[multiOwnerAddress], encodedPluginInitData],\n });\n\n return {\n implAddress,\n initializationData: encodedMSCAInitializeData,\n };\n}\n"]}
|
|
1
|
+
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../../../../src/msca/utils.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,oBAAoB,EACpB,kBAAkB,GAOnB,MAAM,cAAc,CAAC;AACtB,OAAO,EACL,QAAQ,EACR,eAAe,EACf,IAAI,EACJ,WAAW,EACX,OAAO,EACP,QAAQ,EACR,eAAe,EACf,OAAO,EACP,WAAW,EACX,OAAO,GACR,MAAM,oBAAoB,CAAC;AAE5B,OAAO,EACL,MAAM,EACN,mBAAmB,EACnB,kBAAkB,EAClB,oBAAoB,EACpB,SAAS,EACT,kBAAkB,GACnB,MAAM,MAAM,CAAC;AACd,OAAO,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;AAC/C,OAAO,EAAE,kCAAkC,EAAE,MAAM,2CAA2C,CAAC;AAC/F,OAAO,EAAE,4BAA4B,EAAE,MAAM,qCAAqC,CAAC;AACnF,OAAO,EACL,8BAA8B,GAE/B,MAAM,gCAAgC,CAAC;AACxC,OAAO,EAAE,gBAAgB,EAAE,MAAM,iCAAiC,CAAC;AASnE,MAAM,CAAC,MAAM,8CAA8C,GAAG,CAC5D,KAAY,EACH,EAAE;IACX,QAAQ,KAAK,CAAC,EAAE,EAAE,CAAC;QACjB,KAAK,OAAO,CAAC,EAAE,CAAC;QAChB,KAAK,WAAW,CAAC,EAAE,CAAC;QACpB,KAAK,OAAO,CAAC,EAAE,CAAC;QAChB,KAAK,OAAO,CAAC,EAAE,CAAC;QAChB,KAAK,WAAW,CAAC,EAAE,CAAC;QACpB,KAAK,QAAQ,CAAC,EAAE,CAAC;QACjB,KAAK,eAAe,CAAC,EAAE,CAAC;QACxB,KAAK,QAAQ,CAAC,EAAE,CAAC;QACjB,KAAK,eAAe,CAAC,EAAE,CAAC;QACxB,KAAK,IAAI,CAAC,EAAE,CAAC;QACb;YACE,OAAO,4CAA4C,CAAC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AAiB,CAAC,EAAE,qBAAqB,CAAC;KACnD,CAAC,CAAC;IAEH,OAAO;QACL,WAAW;QACX,kBAAkB,EAAE,yBAAyB;KAC9C,CAAC;AACJ,CAAC","sourcesContent":["import {\n AccountNotFoundError,\n ChainNotFoundError,\n type GetAccountParameter,\n type SmartAccountClient,\n type SmartAccountSigner,\n type SmartContractAccount,\n type SmartContractAccountWithSigner,\n type UpgradeToData,\n} from \"@aa-sdk/core\";\nimport {\n arbitrum,\n arbitrumSepolia,\n base,\n baseSepolia,\n mainnet,\n optimism,\n optimismSepolia,\n polygon,\n polygonAmoy,\n sepolia,\n} from \"@account-kit/infra\";\nimport type { Address, Chain, Transport } from \"viem\";\nimport {\n custom,\n encodeAbiParameters,\n encodeFunctionData,\n encodeFunctionResult,\n keccak256,\n parseAbiParameters,\n} from \"viem\";\nimport { IPluginAbi } from \"./abis/IPlugin.js\";\nimport { MultiOwnerModularAccountFactoryAbi } from \"./abis/MultiOwnerModularAccountFactory.js\";\nimport { UpgradeableModularAccountAbi } from \"./abis/UpgradeableModularAccount.js\";\nimport {\n createMultiOwnerModularAccount,\n type MultiOwnerModularAccount,\n} from \"./account/multiOwnerAccount.js\";\nimport { MultiOwnerPlugin } from \"./plugins/multi-owner/plugin.js\";\n\n/**\n * Utility method returning the default multi sig msca factory address given a chain\n *\n * @param {Chain} chain the chain object for which to get the address\n * @returns {Address} the address for the given chain\n * @throws if the chain doesn't have an address currently deployed\n */\nexport const getDefaultMultisigModularAccountFactoryAddress = (\n chain: Chain\n): Address => {\n switch (chain.id) {\n case sepolia.id:\n case baseSepolia.id:\n case polygon.id:\n case mainnet.id:\n case polygonAmoy.id:\n case optimism.id:\n case optimismSepolia.id:\n case arbitrum.id:\n case arbitrumSepolia.id:\n case base.id:\n default:\n return \"0x000000000000204327E6669f00901a57CE15aE15\";\n }\n};\n\n/**\n * Utility method returning the default multi owner msca factory address given a chain\n *\n * @param {Chain} chain the chain object for which to get the address\n * @returns {Address} the address for the given chain\n * @throws if the chain doesn't have an address currently deployed\n */\nexport const getDefaultMultiOwnerModularAccountFactoryAddress = (\n chain: Chain\n): Address => {\n switch (chain.id) {\n default:\n return \"0x000000e92D78D90000007F0082006FDA09BD5f11\";\n }\n};\n\nexport type GetMSCAUpgradeToData<\n TSigner extends SmartAccountSigner = SmartAccountSigner,\n TAccount extends\n | SmartContractAccountWithSigner<string, TSigner>\n | undefined = SmartContractAccountWithSigner<string, TSigner> | undefined\n> = {\n multiOwnerPluginAddress?: Address;\n} & GetAccountParameter<TAccount>;\n\n/**\n * Retrieves the data necessary to upgrade to a Multi-Signature Contract Account (MSCA) and provides a method to create a Multi-Owner Modular Account.\n *\n * @example\n * ```ts\n * import { createLightAccountClient, getMSCAUpgradeToData } from \"@account-kit/smart-contracts\";\n *\n * const client = createLightAccountClient(...);\n * const upgradeData = await getMSCAUpgradeToData(client, {});\n * ```\n *\n * @param {SmartAccountClient<TTransport, TChain, TAccount>} client The smart account client\n * @param {GetMSCAUpgradeToData<TSigner, TAccount>} args The arguments required for the upgrade\n * @returns {Promise<UpgradeToData & { createMAAccount: () => Promise<MultiOwnerModularAccount<TSigner>>}>} A promise that resolves to upgrade data augmented with a function to create a Multi-Owner Modular Account\n */\nexport async function getMSCAUpgradeToData<\n TTransport extends Transport = Transport,\n TChain extends Chain | undefined = Chain | undefined,\n TSigner extends SmartAccountSigner = SmartAccountSigner,\n TAccount extends\n | SmartContractAccountWithSigner<string, TSigner>\n | undefined = SmartContractAccountWithSigner<string, TSigner> | undefined\n>(\n client: SmartAccountClient<TTransport, TChain, TAccount>,\n args: GetMSCAUpgradeToData<TSigner, TAccount>\n): Promise<\n UpgradeToData & {\n createMAAccount: () => Promise<MultiOwnerModularAccount<TSigner>>;\n }\n> {\n const { account: account_ = client.account, multiOwnerPluginAddress } = args;\n\n if (!account_) {\n throw new AccountNotFoundError();\n }\n const account = account_ as SmartContractAccountWithSigner<string, TSigner>;\n\n const chain = client.chain;\n if (!chain) {\n throw new ChainNotFoundError();\n }\n\n const initData = await getMAInitializationData({\n client,\n multiOwnerPluginAddress,\n signerAddress: await account.getSigner().getAddress(),\n });\n\n return {\n ...initData,\n createMAAccount: async () =>\n createMultiOwnerModularAccount({\n transport: custom(client.transport),\n chain: chain as Chain,\n signer: account.getSigner(),\n accountAddress: account.address,\n }),\n };\n}\n\nexport type GetMAInitializationDataParams<\n TTransport extends Transport = Transport,\n TChain extends Chain | undefined = Chain | undefined,\n TAccount extends SmartContractAccount | undefined =\n | SmartContractAccount\n | undefined\n> = {\n multiOwnerPluginAddress?: Address;\n client: SmartAccountClient<TTransport, TChain, TAccount>;\n signerAddress: Address | Address[];\n};\n\n/**\n * Retrieves the initialization data for a multi-owner modular account. Throws an error if the client's chain is not found or if the multi-owner plugin address is not retrievable.\n *\n * @example\n * ```ts\n * import { getMAInitializationData } from \"@account-kit/smart-contracts\";\n * import { createSmartAccountClient } from \"@aa-sdk/core\";\n *\n * const client = createSmartAccountClient(...);\n * const initializationData = await getMAInitializationData({\n * client,\n * signerAddress: \"0x...\", // or array of signers\n * });\n * ```\n *\n * @param {GetMAInitializationDataParams<TTransport, TChain, TAccount>} params the parameters for getting initialization data\n * @param {SmartAccountClient<TTransport, TChain, TAccount>} params.client the smart account client\n * @param {Address | Address[]} params.signerAddress the address of the signer or an array of signer addresses\n * @param {Address} [params.multiOwnerPluginAddress] optional address of the multi-owner plugin\n * @returns {Promise<UpgradeToData>} a promise that resolves to the initialization data required for upgrading to a multi-owner modular account\n */\nexport async function getMAInitializationData<\n TTransport extends Transport = Transport,\n TChain extends Chain | undefined = Chain | undefined,\n TAccount extends SmartContractAccount | undefined =\n | SmartContractAccount\n | undefined\n>({\n client,\n multiOwnerPluginAddress,\n signerAddress,\n}: GetMAInitializationDataParams<\n TTransport,\n TChain,\n TAccount\n>): Promise<UpgradeToData> {\n if (!client.chain) {\n throw new ChainNotFoundError();\n }\n\n const factoryAddress = getDefaultMultiOwnerModularAccountFactoryAddress(\n client.chain\n );\n\n const implAddress = await client.readContract({\n abi: MultiOwnerModularAccountFactoryAbi,\n address: factoryAddress,\n functionName: \"IMPL\",\n });\n\n const multiOwnerAddress =\n multiOwnerPluginAddress ?? MultiOwnerPlugin.meta.addresses[client.chain.id];\n\n if (!multiOwnerAddress) {\n throw new Error(\"could not get multi owner plugin address\");\n }\n\n const moPluginManifest = await client.readContract({\n abi: IPluginAbi,\n address: multiOwnerAddress,\n functionName: \"pluginManifest\",\n });\n\n const hashedMultiOwnerPluginManifest = keccak256(\n encodeFunctionResult({\n abi: IPluginAbi,\n functionName: \"pluginManifest\",\n result: moPluginManifest,\n })\n );\n\n const encodedOwner = encodeAbiParameters(\n parseAbiParameters(\"address[]\"),\n Array.isArray(signerAddress) ? [signerAddress] : [[signerAddress]]\n );\n\n const encodedPluginInitData = encodeAbiParameters(\n parseAbiParameters(\"bytes32[], bytes[]\"),\n [[hashedMultiOwnerPluginManifest], [encodedOwner]]\n );\n\n const encodedMSCAInitializeData = encodeFunctionData({\n abi: UpgradeableModularAccountAbi,\n functionName: \"initialize\",\n args: [[multiOwnerAddress], encodedPluginInitData],\n });\n\n return {\n implAddress,\n initializationData: encodedMSCAInitializeData,\n };\n}\n"]}
|
|
@@ -7,7 +7,7 @@ export { createMultiOwnerLightAccountAlchemyClient, type AlchemyMultiOwnerLightA
|
|
|
7
7
|
export type * from "./light-account/decorators/lightAccount.js";
|
|
8
8
|
export { lightAccountClientActions } from "./light-account/decorators/lightAccount.js";
|
|
9
9
|
export type * from "./light-account/types.js";
|
|
10
|
-
export { AccountVersionRegistry, LightAccountUnsupported1271Factories, LightAccountUnsupported1271Impls, defaultLightAccountVersion, getDefaultLightAccountFactoryAddress,
|
|
10
|
+
export { AccountVersionRegistry, LightAccountUnsupported1271Factories, LightAccountUnsupported1271Impls, defaultLightAccountVersion, getDefaultLightAccountFactoryAddress, getLightAccountVersionForAccount, } from "./light-account/utils.js";
|
|
11
11
|
export type * from "./light-account/accounts/multiOwner.js";
|
|
12
12
|
export { createMultiOwnerLightAccount } from "./light-account/accounts/multiOwner.js";
|
|
13
13
|
export { updateOwners as updateMultiOwnerLightAccountOwners } from "./light-account/actions/updateOwners.js";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/index.ts"],"names":[],"mappings":"AAIA,mBAAmB,qCAAqC,CAAC;AACzD,OAAO,EAAE,kBAAkB,EAAE,MAAM,qCAAqC,CAAC;AACzE,OAAO,EAAE,iBAAiB,IAAI,6BAA6B,EAAE,MAAM,8CAA8C,CAAC;AAClH,OAAO,EACL,+BAA+B,EAC/B,KAAK,+BAA+B,GACrC,MAAM,0CAA0C,CAAC;AAClD,OAAO,EAAE,wBAAwB,EAAE,MAAM,mCAAmC,CAAC;AAC7E,OAAO,EACL,yCAAyC,EACzC,KAAK,yCAAyC,GAC/C,MAAM,oDAAoD,CAAC;AAC5D,mBAAmB,4CAA4C,CAAC;AAChE,OAAO,EAAE,yBAAyB,EAAE,MAAM,4CAA4C,CAAC;AACvF,mBAAmB,0BAA0B,CAAC;AAE9C,OAAO,EACL,sBAAsB,EACtB,oCAAoC,EACpC,gCAAgC,EAChC,0BAA0B,EAC1B,oCAAoC,EACpC,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/index.ts"],"names":[],"mappings":"AAIA,mBAAmB,qCAAqC,CAAC;AACzD,OAAO,EAAE,kBAAkB,EAAE,MAAM,qCAAqC,CAAC;AACzE,OAAO,EAAE,iBAAiB,IAAI,6BAA6B,EAAE,MAAM,8CAA8C,CAAC;AAClH,OAAO,EACL,+BAA+B,EAC/B,KAAK,+BAA+B,GACrC,MAAM,0CAA0C,CAAC;AAClD,OAAO,EAAE,wBAAwB,EAAE,MAAM,mCAAmC,CAAC;AAC7E,OAAO,EACL,yCAAyC,EACzC,KAAK,yCAAyC,GAC/C,MAAM,oDAAoD,CAAC;AAC5D,mBAAmB,4CAA4C,CAAC;AAChE,OAAO,EAAE,yBAAyB,EAA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,GACrB,MAAM,iBAAiB,CAAC"}
|
|
@@ -1,19 +1,18 @@
|
|
|
1
1
|
import { type Address, type EntryPointDef, type SmartAccountSigner } from "@aa-sdk/core";
|
|
2
2
|
import { type Chain, type Hex, type Transport } from "viem";
|
|
3
|
-
import type {
|
|
3
|
+
import type { LightAccountEntryPointVersion, LightAccountVersion } from "../types.js";
|
|
4
4
|
import { type CreateLightAccountBaseParams, type LightAccountBase } from "./base.js";
|
|
5
|
-
export type LightAccount<TSigner extends SmartAccountSigner = SmartAccountSigner, TLightAccountVersion extends
|
|
5
|
+
export type LightAccount<TSigner extends SmartAccountSigner = SmartAccountSigner, TLightAccountVersion extends LightAccountVersion<"LightAccount"> = LightAccountVersion<"LightAccount">> = LightAccountBase<TSigner, "LightAccount", TLightAccountVersion> & {
|
|
6
6
|
encodeTransferOwnership: (newOwner: Address) => Hex;
|
|
7
7
|
getOwnerAddress: () => Promise<Address>;
|
|
8
8
|
};
|
|
9
|
-
export type CreateLightAccountParams<TTransport extends Transport = Transport, TSigner extends SmartAccountSigner = SmartAccountSigner, TLightAccountVersion extends
|
|
9
|
+
export type CreateLightAccountParams<TTransport extends Transport = Transport, TSigner extends SmartAccountSigner = SmartAccountSigner, TLightAccountVersion extends LightAccountVersion<"LightAccount"> = LightAccountVersion<"LightAccount">> = Omit<CreateLightAccountBaseParams<"LightAccount", TLightAccountVersion, TTransport, TSigner>, "getAccountInitCode" | "entryPoint" | "version" | "abi" | "accountAddress" | "type"> & {
|
|
10
10
|
salt?: bigint;
|
|
11
11
|
initCode?: Hex;
|
|
12
12
|
accountAddress?: Address;
|
|
13
13
|
factoryAddress?: Address;
|
|
14
14
|
version?: TLightAccountVersion;
|
|
15
|
-
entryPoint?: EntryPointDef<
|
|
15
|
+
entryPoint?: EntryPointDef<LightAccountEntryPointVersion<"LightAccount", TLightAccountVersion>, Chain>;
|
|
16
16
|
};
|
|
17
|
-
export declare function createLightAccount<TTransport extends Transport = Transport, TSigner extends SmartAccountSigner = SmartAccountSigner, TLightAccountVersion extends
|
|
18
|
-
export declare function createLightAccount<TTransport extends Transport = Transport, TSigner extends SmartAccountSigner = SmartAccountSigner, TLightAccountVersion extends GetLightAccountVersion<"LightAccount"> = GetLightAccountVersion<"LightAccount">, TEntryPointVersion extends GetEntryPointForLightAccountVersion<"LightAccount", TLightAccountVersion> = GetEntryPointForLightAccountVersion<"LightAccount", TLightAccountVersion>>(config: CreateLightAccountParams<TTransport, TSigner, TLightAccountVersion, TEntryPointVersion>): Promise<LightAccount<TSigner, TLightAccountVersion, TEntryPointVersion>>;
|
|
17
|
+
export declare function createLightAccount<TTransport extends Transport = Transport, TSigner extends SmartAccountSigner = SmartAccountSigner, TLightAccountVersion extends LightAccountVersion<"LightAccount"> = "v2.0.0">(config: CreateLightAccountParams<TTransport, TSigner, TLightAccountVersion>): Promise<LightAccount<TSigner, TLightAccountVersion>>;
|
|
19
18
|
//# sourceMappingURL=account.d.ts.map
|