@account-kit/smart-contracts 4.23.1 → 4.24.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/esm/src/ma-v2/account/common/modularAccountV2Base.d.ts +1 -0
- package/dist/esm/src/ma-v2/account/common/modularAccountV2Base.js +38 -11
- package/dist/esm/src/ma-v2/account/common/modularAccountV2Base.js.map +1 -1
- package/dist/esm/src/ma-v2/account/modularAccountV2.d.ts +1 -0
- package/dist/esm/src/ma-v2/account/modularAccountV2.js +2 -1
- package/dist/esm/src/ma-v2/account/modularAccountV2.js.map +1 -1
- package/dist/esm/src/ma-v2/account/nativeSMASigner.d.ts +2 -2
- package/dist/esm/src/ma-v2/account/nativeSMASigner.js +11 -8
- package/dist/esm/src/ma-v2/account/nativeSMASigner.js.map +1 -1
- package/dist/esm/src/ma-v2/actions/deferralActions.d.ts +9 -7
- package/dist/esm/src/ma-v2/actions/deferralActions.js +21 -35
- package/dist/esm/src/ma-v2/actions/deferralActions.js.map +1 -1
- package/dist/esm/src/ma-v2/index.d.ts +4 -0
- package/dist/esm/src/ma-v2/index.js +2 -0
- package/dist/esm/src/ma-v2/index.js.map +1 -1
- package/dist/esm/src/ma-v2/modules/single-signer-validation/signer.d.ts +2 -1
- package/dist/esm/src/ma-v2/modules/single-signer-validation/signer.js +10 -6
- package/dist/esm/src/ma-v2/modules/single-signer-validation/signer.js.map +1 -1
- package/dist/esm/src/ma-v2/permissionBuilder.d.ts +115 -0
- package/dist/esm/src/ma-v2/permissionBuilder.js +485 -0
- package/dist/esm/src/ma-v2/permissionBuilder.js.map +1 -0
- package/dist/esm/src/ma-v2/utils.d.ts +37 -0
- package/dist/esm/src/ma-v2/utils.js +7 -1
- package/dist/esm/src/ma-v2/utils.js.map +1 -1
- package/dist/types/src/ma-v2/account/common/modularAccountV2Base.d.ts +1 -0
- package/dist/types/src/ma-v2/account/common/modularAccountV2Base.d.ts.map +1 -1
- package/dist/types/src/ma-v2/account/modularAccountV2.d.ts +1 -0
- package/dist/types/src/ma-v2/account/modularAccountV2.d.ts.map +1 -1
- package/dist/types/src/ma-v2/account/nativeSMASigner.d.ts +2 -2
- package/dist/types/src/ma-v2/account/nativeSMASigner.d.ts.map +1 -1
- package/dist/types/src/ma-v2/actions/deferralActions.d.ts +9 -7
- package/dist/types/src/ma-v2/actions/deferralActions.d.ts.map +1 -1
- package/dist/types/src/ma-v2/index.d.ts +4 -0
- package/dist/types/src/ma-v2/index.d.ts.map +1 -1
- package/dist/types/src/ma-v2/modules/single-signer-validation/signer.d.ts +2 -1
- package/dist/types/src/ma-v2/modules/single-signer-validation/signer.d.ts.map +1 -1
- package/dist/types/src/ma-v2/permissionBuilder.d.ts +116 -0
- package/dist/types/src/ma-v2/permissionBuilder.d.ts.map +1 -0
- package/dist/types/src/ma-v2/utils.d.ts +37 -0
- package/dist/types/src/ma-v2/utils.d.ts.map +1 -1
- package/package.json +6 -5
- package/src/ma-v2/account/common/modularAccountV2Base.ts +52 -10
- package/src/ma-v2/account/modularAccountV2.ts +3 -0
- package/src/ma-v2/account/nativeSMASigner.ts +20 -14
- package/src/ma-v2/actions/deferralActions.ts +38 -51
- package/src/ma-v2/index.ts +4 -0
- package/src/ma-v2/modules/single-signer-validation/signer.ts +19 -13
- package/src/ma-v2/permissionBuilder.ts +724 -0
- package/src/ma-v2/utils.ts +10 -0
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../../../src/ma-v2/utils.ts"],"names":[],"mappings":"AAAA,OAAO,EAKL,KAAK,GAAG,EACR,KAAK,KAAK,EACV,KAAK,OAAO,EACZ,KAAK,SAAS,
|
|
1
|
+
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../../../src/ma-v2/utils.ts"],"names":[],"mappings":"AAAA,OAAO,EAKL,KAAK,GAAG,EACR,KAAK,KAAK,EACV,KAAK,OAAO,EACZ,KAAK,SAAS,EAEf,MAAM,MAAM,CAAC;AAcd,OAAO,EAAE,KAAK,gBAAgB,EAAE,MAAM,0CAA0C,CAAC;AAEjF,OAAO,EAGL,KAAK,mBAAmB,EACxB,KAAK,kBAAkB,EACvB,KAAK,kBAAkB,EACvB,KAAK,8BAA8B,EACnC,KAAK,aAAa,EACnB,MAAM,cAAc,CAAC;AAEtB,eAAO,MAAM,uBAAuB,IAAI,CAAC;AAEzC,MAAM,MAAM,qBAAqB,GAAG;IAElC,mBAAmB,EAAE,GAAG,CAAC;CAC1B,CAAC;AAGF,MAAM,MAAM,uBAAuB,GAAG;IACpC,mBAAmB,EAAE,GAAG,CAAC;IACzB,QAAQ,EAAE,MAAM,CAAC;CAClB,CAAC;AAGF,eAAO,MAAM,eAAe,6BAGzB,qBAAqB,KAAG,GAE1B,CAAC;AAGF,eAAO,MAAM,iBAAiB,uCAG3B,uBAAuB,KAAG,GAQ5B,CAAC;AAEF,eAAO,MAAM,4BAA4B,UAAW,KAAK,KAAG,OAgB3D,CAAC;AAEF,eAAO,MAAM,8BAA8B,UAAW,KAAK,KAAG,OAgB7D,CAAC;AAEF,eAAO,MAAM,6BAA6B,UAAW,KAAK,KAAG,OAgB5D,CAAC;AAEF,eAAO,MAAM,0BAA0B,UAAW,KAAK,KAAG,OAgBzD,CAAC;AAEF,eAAO,MAAM,qBAAqB,UAAW,KAAK,KAAG,OAgBpD,CAAC;AAEF,MAAM,MAAM,oBAAoB,CAC9B,OAAO,SAAS,kBAAkB,GAAG,kBAAkB,EACvD,QAAQ,SACJ,8BAA8B,CAAC,MAAM,EAAE,OAAO,CAAC,GAC/C,SAAS,GAAG,8BAA8B,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,SAAS,IACzE,mBAAmB,CAAC,QAAQ,CAAC,CAAC;AAElC;;;;;;;;;;;;;;;GAeG;AACH,wBAAsB,oBAAoB,CACxC,UAAU,SAAS,SAAS,GAAG,SAAS,EACxC,MAAM,SAAS,KAAK,GAAG,SAAS,GAAG,KAAK,GAAG,SAAS,EACpD,OAAO,SAAS,kBAAkB,GAAG,kBAAkB,EACvD,QAAQ,SACJ,8BAA8B,CAAC,MAAM,EAAE,OAAO,CAAC,GAC/C,SAAS,GAAG,8BAA8B,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,SAAS,EAE3E,MAAM,EAAE,kBAAkB,CAAC,UAAU,EAAE,MAAM,EAAE,QAAQ,CAAC,EACxD,IAAI,EAAE,oBAAoB,CAAC,OAAO,EAAE,QAAQ,CAAC,GAC5C,OAAO,CACR,aAAa,GAAG;IACd,kCAAkC,EAAE,MAAM,OAAO,CAC/C,gBAAgB,CAAC,OAAO,CAAC,CAC1B,CAAC;CACH,CACF,CA8BA;AAED,eAAO,MAAM,8BAA8B,y+EAC67E,CAAC;AAEz+E,eAAO,MAAM,qBAAqB,6hJAC0/I,CAAC;AAE7hJ,eAAO,MAAM,gBAAgB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAI3B,CAAC;AAEH,MAAM,MAAM,gBAAgB,GAAG;IAC7B,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,kBAAkB,CAAC,EAAE,OAAO,CAAC;IAC7B,gBAAgB,CAAC,EAAE,OAAO,CAAC;IAC3B,sBAAsB,CAAC,EAAE,OAAO,CAAC;CAClC,CAAC;AAEF,eAAO,MAAM,iBAAiB,kEAK3B,gBAAgB,KAAG,MAOrB,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@account-kit/smart-contracts",
|
|
3
|
-
"version": "4.
|
|
3
|
+
"version": "4.24.0",
|
|
4
4
|
"description": "aa-sdk compatible interfaces for Alchemy Smart Accounts",
|
|
5
5
|
"author": "Alchemy",
|
|
6
6
|
"license": "MIT",
|
|
@@ -47,12 +47,13 @@
|
|
|
47
47
|
"build:esm": "tsc --project tsconfig.build.json --outDir ./dist/esm",
|
|
48
48
|
"build:types": "tsc --project tsconfig.build.json --declarationDir ./dist/types --emitDeclarationOnly --declaration --declarationMap",
|
|
49
49
|
"docs:gen": "node ../../doc-gen/dist/esm/cli.js generate --in ./src/index.ts --out ../../site/pages/reference/account-kit/smart-contracts",
|
|
50
|
+
"fern:gen": "node ../../doc-gen/dist/esm/cli.js generate --in ./src/index.ts --out ../../docs/pages/reference/account-kit/smart-contracts --fern",
|
|
50
51
|
"clean": "rm -rf ./dist",
|
|
51
52
|
"test": "vitest",
|
|
52
53
|
"test:run": "vitest run"
|
|
53
54
|
},
|
|
54
55
|
"devDependencies": {
|
|
55
|
-
"@account-kit/plugingen": "^4.
|
|
56
|
+
"@account-kit/plugingen": "^4.24.0",
|
|
56
57
|
"change-case": "^5.1.2",
|
|
57
58
|
"dedent": "^1.5.1",
|
|
58
59
|
"dotenv": "^16.3.1",
|
|
@@ -72,10 +73,10 @@
|
|
|
72
73
|
"url": "https://github.com/alchemyplatform/aa-sdk/issues"
|
|
73
74
|
},
|
|
74
75
|
"homepage": "https://github.com/alchemyplatform/aa-sdk#readme",
|
|
75
|
-
"gitHead": "
|
|
76
|
+
"gitHead": "2038e3681098bb5e8c2e871c7d64ee1169216706",
|
|
76
77
|
"dependencies": {
|
|
77
|
-
"@aa-sdk/core": "^4.
|
|
78
|
-
"@account-kit/infra": "^4.
|
|
78
|
+
"@aa-sdk/core": "^4.24.0",
|
|
79
|
+
"@account-kit/infra": "^4.24.0"
|
|
79
80
|
},
|
|
80
81
|
"peerDependencies": {
|
|
81
82
|
"viem": "^2.22.6"
|
|
@@ -3,6 +3,8 @@ import {
|
|
|
3
3
|
getEntryPoint,
|
|
4
4
|
InvalidEntityIdError,
|
|
5
5
|
InvalidNonceKeyError,
|
|
6
|
+
InvalidDeferredActionNonce,
|
|
7
|
+
InvalidDeferredActionMode,
|
|
6
8
|
toSmartContractAccount,
|
|
7
9
|
type AccountOp,
|
|
8
10
|
type SmartAccountSigner,
|
|
@@ -85,6 +87,7 @@ export type CreateMAV2BaseParams<
|
|
|
85
87
|
signer: TSigner;
|
|
86
88
|
signerEntity?: SignerEntity;
|
|
87
89
|
accountAddress: Address;
|
|
90
|
+
deferredAction?: Hex;
|
|
88
91
|
};
|
|
89
92
|
|
|
90
93
|
export type CreateMAV2BaseReturnType<
|
|
@@ -108,6 +111,7 @@ export async function createMAv2Base<
|
|
|
108
111
|
entityId = DEFAULT_OWNER_ENTITY_ID,
|
|
109
112
|
} = {},
|
|
110
113
|
accountAddress,
|
|
114
|
+
deferredAction,
|
|
111
115
|
...remainingToSmartContractAccountParams
|
|
112
116
|
} = config;
|
|
113
117
|
|
|
@@ -120,6 +124,39 @@ export async function createMAv2Base<
|
|
|
120
124
|
chain,
|
|
121
125
|
});
|
|
122
126
|
|
|
127
|
+
const entryPointContract = getContract({
|
|
128
|
+
address: entryPoint.address,
|
|
129
|
+
abi: entryPoint.abi,
|
|
130
|
+
client,
|
|
131
|
+
});
|
|
132
|
+
|
|
133
|
+
let useDeferredAction: boolean = false;
|
|
134
|
+
let nonce: bigint = 0n;
|
|
135
|
+
let deferredActionData: Hex = "0x";
|
|
136
|
+
let hasAssociatedExecHooks: boolean = false;
|
|
137
|
+
|
|
138
|
+
if (deferredAction) {
|
|
139
|
+
if (deferredAction.slice(2, 4) !== "00") {
|
|
140
|
+
throw new InvalidDeferredActionMode();
|
|
141
|
+
}
|
|
142
|
+
// Set these values if the deferred action has not been consumed. We check this with the EP
|
|
143
|
+
const nextNonceForDeferredAction: bigint =
|
|
144
|
+
(await entryPointContract.read.getNonce([
|
|
145
|
+
accountAddress,
|
|
146
|
+
nonce >> 64n,
|
|
147
|
+
])) as bigint;
|
|
148
|
+
|
|
149
|
+
// we only add the deferred action in if the nonce has not been consumed
|
|
150
|
+
if (nonce === nextNonceForDeferredAction) {
|
|
151
|
+
nonce = BigInt(`0x${deferredAction.slice(6, 70)}`);
|
|
152
|
+
useDeferredAction = true;
|
|
153
|
+
deferredActionData = `0x${deferredAction.slice(70)}`;
|
|
154
|
+
hasAssociatedExecHooks = deferredAction[5] === "1";
|
|
155
|
+
} else if (nonce > nextNonceForDeferredAction) {
|
|
156
|
+
throw new InvalidDeferredActionNonce();
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
|
|
123
160
|
const encodeExecute: (tx: AccountOp) => Promise<Hex> = async ({
|
|
124
161
|
target,
|
|
125
162
|
data,
|
|
@@ -150,18 +187,16 @@ export async function createMAv2Base<
|
|
|
150
187
|
|
|
151
188
|
const isAccountDeployed: () => Promise<boolean> = async () =>
|
|
152
189
|
!!(await client.getCode({ address: accountAddress }));
|
|
153
|
-
|
|
190
|
+
|
|
154
191
|
const getNonce = async (nonceKey: bigint = 0n): Promise<bigint> => {
|
|
192
|
+
if (useDeferredAction) {
|
|
193
|
+
return nonce;
|
|
194
|
+
}
|
|
195
|
+
|
|
155
196
|
if (nonceKey > maxUint152) {
|
|
156
197
|
throw new InvalidNonceKeyError(nonceKey);
|
|
157
198
|
}
|
|
158
199
|
|
|
159
|
-
const entryPointContract = getContract({
|
|
160
|
-
address: entryPoint.address,
|
|
161
|
-
abi: entryPoint.abi,
|
|
162
|
-
client,
|
|
163
|
-
});
|
|
164
|
-
|
|
165
200
|
const fullNonceKey: bigint =
|
|
166
201
|
(nonceKey << 40n) +
|
|
167
202
|
(BigInt(entityId) << 8n) +
|
|
@@ -216,7 +251,8 @@ export async function createMAv2Base<
|
|
|
216
251
|
entityId: Number(entityId),
|
|
217
252
|
});
|
|
218
253
|
|
|
219
|
-
return
|
|
254
|
+
return (useDeferredAction && hasAssociatedExecHooks) ||
|
|
255
|
+
validationData.executionHooks.length
|
|
220
256
|
? concatHex([executeUserOpSelector, callData])
|
|
221
257
|
: callData;
|
|
222
258
|
};
|
|
@@ -231,8 +267,14 @@ export async function createMAv2Base<
|
|
|
231
267
|
encodeBatchExecute,
|
|
232
268
|
getNonce,
|
|
233
269
|
...(entityId === DEFAULT_OWNER_ENTITY_ID
|
|
234
|
-
? nativeSMASigner(signer, chain, accountAddress)
|
|
235
|
-
: singleSignerMessageSigner(
|
|
270
|
+
? nativeSMASigner(signer, chain, accountAddress, deferredActionData)
|
|
271
|
+
: singleSignerMessageSigner(
|
|
272
|
+
signer,
|
|
273
|
+
chain,
|
|
274
|
+
accountAddress,
|
|
275
|
+
entityId,
|
|
276
|
+
deferredActionData
|
|
277
|
+
)),
|
|
236
278
|
});
|
|
237
279
|
|
|
238
280
|
return {
|
|
@@ -36,6 +36,7 @@ export type CreateModularAccountV2Params<
|
|
|
36
36
|
> & {
|
|
37
37
|
signer: TSigner;
|
|
38
38
|
entryPoint?: EntryPointDef<"0.7.0", Chain>;
|
|
39
|
+
deferredAction?: Hex;
|
|
39
40
|
signerEntity?: SignerEntity;
|
|
40
41
|
}) &
|
|
41
42
|
(
|
|
@@ -103,6 +104,7 @@ export async function createModularAccountV2(
|
|
|
103
104
|
entityId: DEFAULT_OWNER_ENTITY_ID,
|
|
104
105
|
},
|
|
105
106
|
signerEntity: { entityId = DEFAULT_OWNER_ENTITY_ID } = {},
|
|
107
|
+
deferredAction,
|
|
106
108
|
} = config;
|
|
107
109
|
|
|
108
110
|
const client = createBundlerClient({
|
|
@@ -183,6 +185,7 @@ export async function createModularAccountV2(
|
|
|
183
185
|
signer,
|
|
184
186
|
entryPoint,
|
|
185
187
|
signerEntity,
|
|
188
|
+
deferredAction,
|
|
186
189
|
...accountFunctions,
|
|
187
190
|
});
|
|
188
191
|
}
|
|
@@ -9,6 +9,7 @@ import {
|
|
|
9
9
|
type Chain,
|
|
10
10
|
type Address,
|
|
11
11
|
concat,
|
|
12
|
+
concatHex,
|
|
12
13
|
} from "viem";
|
|
13
14
|
|
|
14
15
|
import {
|
|
@@ -23,7 +24,6 @@ import { SignatureType } from "../modules/utils.js";
|
|
|
23
24
|
* @example
|
|
24
25
|
* ```ts
|
|
25
26
|
* import { nativeSMASigner } from "@account-kit/smart-contracts";
|
|
26
|
-
|
|
27
27
|
* import { LocalAccountSigner } from "@aa-sdk/core";
|
|
28
28
|
*
|
|
29
29
|
* const MNEMONIC = "...":
|
|
@@ -38,31 +38,37 @@ import { SignatureType } from "../modules/utils.js";
|
|
|
38
38
|
* @param {SmartAccountSigner} signer Signer to use for signing operations
|
|
39
39
|
* @param {Chain} chain Chain object for the signer
|
|
40
40
|
* @param {Address} accountAddress address of the smart account using this signer
|
|
41
|
+
* @param {Hex} deferredActionData optional deferred action data to prepend to the uo signatures
|
|
41
42
|
* @returns {object} an object with methods for signing operations and managing signatures
|
|
42
43
|
*/
|
|
43
44
|
export const nativeSMASigner = (
|
|
44
45
|
signer: SmartAccountSigner,
|
|
45
46
|
chain: Chain,
|
|
46
|
-
accountAddress: Address
|
|
47
|
+
accountAddress: Address,
|
|
48
|
+
deferredActionData?: Hex
|
|
47
49
|
) => {
|
|
48
50
|
return {
|
|
49
51
|
getDummySignature: (): Hex => {
|
|
50
|
-
const
|
|
51
|
-
"0xfffffffffffffffffffffffffffffff0000000000000000000000000000000007aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa1c";
|
|
52
|
-
|
|
53
|
-
return packUOSignature({
|
|
52
|
+
const sig = packUOSignature({
|
|
54
53
|
// orderedHookData: [],
|
|
55
|
-
validationSignature:
|
|
54
|
+
validationSignature:
|
|
55
|
+
"0xfffffffffffffffffffffffffffffff0000000000000000000000000000000007aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa1c",
|
|
56
56
|
});
|
|
57
|
+
|
|
58
|
+
return deferredActionData ? concatHex([deferredActionData, sig]) : sig;
|
|
57
59
|
},
|
|
58
60
|
|
|
59
|
-
signUserOperationHash: (uoHash: Hex): Promise<Hex> => {
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
61
|
+
signUserOperationHash: async (uoHash: Hex): Promise<Hex> => {
|
|
62
|
+
const sig = await signer
|
|
63
|
+
.signMessage({ raw: uoHash })
|
|
64
|
+
.then((signature: Hex) =>
|
|
65
|
+
packUOSignature({
|
|
66
|
+
// orderedHookData: [],
|
|
67
|
+
validationSignature: signature,
|
|
68
|
+
})
|
|
69
|
+
);
|
|
70
|
+
|
|
71
|
+
return deferredActionData ? concatHex([deferredActionData, sig]) : sig;
|
|
66
72
|
},
|
|
67
73
|
|
|
68
74
|
// we apply the expected 1271 packing here since the account contract will expect it
|
|
@@ -11,7 +11,6 @@ import {
|
|
|
11
11
|
type Hex,
|
|
12
12
|
concatHex,
|
|
13
13
|
maxUint152,
|
|
14
|
-
getContract,
|
|
15
14
|
encodePacked,
|
|
16
15
|
size,
|
|
17
16
|
toHex,
|
|
@@ -44,22 +43,23 @@ export type DeferredActionTypedData = {
|
|
|
44
43
|
|
|
45
44
|
export type DeferredActionReturnData = {
|
|
46
45
|
typedData: DeferredActionTypedData;
|
|
47
|
-
nonceOverride: bigint;
|
|
48
46
|
};
|
|
49
47
|
|
|
50
48
|
export type CreateDeferredActionTypedDataParams = {
|
|
51
49
|
callData: Hex;
|
|
52
50
|
deadline: number;
|
|
53
|
-
|
|
54
|
-
isGlobalValidation: boolean;
|
|
55
|
-
nonceKeyOverride?: bigint;
|
|
51
|
+
nonce: bigint;
|
|
56
52
|
};
|
|
57
53
|
|
|
58
54
|
export type BuildDeferredActionDigestParams = {
|
|
59
|
-
|
|
55
|
+
fullPreSignatureDeferredActionDigest: Hex;
|
|
60
56
|
sig: Hex;
|
|
61
57
|
};
|
|
62
58
|
|
|
59
|
+
export type BuildPreSignatureDeferredActionDigestParams = {
|
|
60
|
+
typedData: DeferredActionTypedData;
|
|
61
|
+
};
|
|
62
|
+
|
|
63
63
|
export type BuildUserOperationWithDeferredActionParams = {
|
|
64
64
|
uo: UserOperationCallData | BatchUserOperationCallData;
|
|
65
65
|
signaturePrepend: Hex;
|
|
@@ -67,9 +67,10 @@ export type BuildUserOperationWithDeferredActionParams = {
|
|
|
67
67
|
};
|
|
68
68
|
|
|
69
69
|
export type EntityIdAndNonceParams = {
|
|
70
|
-
entityId
|
|
71
|
-
nonceKey
|
|
70
|
+
entityId?: number;
|
|
71
|
+
nonceKey?: bigint;
|
|
72
72
|
isGlobalValidation: boolean;
|
|
73
|
+
isDeferredAction?: boolean;
|
|
73
74
|
};
|
|
74
75
|
|
|
75
76
|
export type DeferralActions = {
|
|
@@ -77,6 +78,9 @@ export type DeferralActions = {
|
|
|
77
78
|
args: CreateDeferredActionTypedDataParams
|
|
78
79
|
) => Promise<DeferredActionReturnData>;
|
|
79
80
|
buildDeferredActionDigest: (args: BuildDeferredActionDigestParams) => Hex;
|
|
81
|
+
buildPreSignatureDeferredActionDigest: (
|
|
82
|
+
args: BuildPreSignatureDeferredActionDigestParams
|
|
83
|
+
) => Hex;
|
|
80
84
|
buildUserOperationWithDeferredAction: (
|
|
81
85
|
args: BuildUserOperationWithDeferredActionParams
|
|
82
86
|
) => Promise<UserOperationRequest_v7>;
|
|
@@ -97,43 +101,17 @@ export const deferralActions: (
|
|
|
97
101
|
const createDeferredActionTypedDataObject = async ({
|
|
98
102
|
callData,
|
|
99
103
|
deadline,
|
|
100
|
-
|
|
101
|
-
isGlobalValidation,
|
|
102
|
-
nonceKeyOverride = 0n,
|
|
104
|
+
nonce,
|
|
103
105
|
}: CreateDeferredActionTypedDataParams): Promise<DeferredActionReturnData> => {
|
|
104
106
|
if (!client.account) {
|
|
105
107
|
throw new AccountNotFoundError();
|
|
106
108
|
}
|
|
107
109
|
|
|
108
|
-
if (nonceKeyOverride > maxUint152) {
|
|
109
|
-
throw new InvalidNonceKeyError(nonceKeyOverride);
|
|
110
|
-
}
|
|
111
|
-
|
|
112
110
|
const entryPoint = client.account.getEntryPoint();
|
|
113
111
|
if (entryPoint === undefined) {
|
|
114
112
|
throw new EntryPointNotFoundError(client.chain, "0.7.0");
|
|
115
113
|
}
|
|
116
114
|
|
|
117
|
-
const entryPointContract = getContract({
|
|
118
|
-
address: entryPoint.address,
|
|
119
|
-
abi: entryPoint.abi,
|
|
120
|
-
client: client,
|
|
121
|
-
});
|
|
122
|
-
|
|
123
|
-
// 2 = deferred action flags 0b10
|
|
124
|
-
// 1 = isGlobal validation flag 0b01
|
|
125
|
-
const fullNonceKey: bigint = buildFullNonceKey({
|
|
126
|
-
nonceKey: nonceKeyOverride,
|
|
127
|
-
entityId,
|
|
128
|
-
isGlobalValidation,
|
|
129
|
-
isDeferredAction: true,
|
|
130
|
-
});
|
|
131
|
-
|
|
132
|
-
const nonceOverride = (await entryPointContract.read.getNonce([
|
|
133
|
-
client.account.address,
|
|
134
|
-
fullNonceKey,
|
|
135
|
-
])) as bigint;
|
|
136
|
-
|
|
137
115
|
return {
|
|
138
116
|
typedData: {
|
|
139
117
|
domain: {
|
|
@@ -149,12 +127,11 @@ export const deferralActions: (
|
|
|
149
127
|
},
|
|
150
128
|
primaryType: "DeferredAction",
|
|
151
129
|
message: {
|
|
152
|
-
nonce:
|
|
130
|
+
nonce: nonce,
|
|
153
131
|
deadline: deadline,
|
|
154
132
|
call: callData,
|
|
155
133
|
},
|
|
156
134
|
},
|
|
157
|
-
nonceOverride: nonceOverride,
|
|
158
135
|
};
|
|
159
136
|
};
|
|
160
137
|
|
|
@@ -164,34 +141,42 @@ export const deferralActions: (
|
|
|
164
141
|
* Assumption: The client this extends is used to sign the typed data.
|
|
165
142
|
*
|
|
166
143
|
* @param {object} args The argument object containing the following:
|
|
167
|
-
* @param {
|
|
144
|
+
* @param {Hex} args.fullPreSignatureDeferredActionDigest The The data to append the signature and length to
|
|
168
145
|
* @param {Hex} args.sig The signature to include in the digest
|
|
169
146
|
* @returns {Hex} The encoded digest to be prepended to the userOp signature
|
|
170
147
|
*/
|
|
171
148
|
const buildDeferredActionDigest = ({
|
|
172
|
-
|
|
149
|
+
fullPreSignatureDeferredActionDigest,
|
|
173
150
|
sig,
|
|
174
151
|
}: BuildDeferredActionDigestParams): Hex => {
|
|
152
|
+
const sigLength = size(sig);
|
|
153
|
+
|
|
154
|
+
const encodedData = concatHex([
|
|
155
|
+
fullPreSignatureDeferredActionDigest,
|
|
156
|
+
toHex(sigLength, { size: 4 }),
|
|
157
|
+
sig,
|
|
158
|
+
]);
|
|
159
|
+
return encodedData;
|
|
160
|
+
};
|
|
161
|
+
|
|
162
|
+
const buildPreSignatureDeferredActionDigest = ({
|
|
163
|
+
typedData,
|
|
164
|
+
}: BuildPreSignatureDeferredActionDigestParams): Hex => {
|
|
175
165
|
const signerEntity = client.account.signerEntity;
|
|
176
166
|
const validationLocator =
|
|
177
167
|
(BigInt(signerEntity.entityId) << 8n) |
|
|
178
168
|
(signerEntity.isGlobalValidation ? 1n : 0n);
|
|
179
169
|
|
|
180
|
-
|
|
170
|
+
const encodedCallData = encodePacked(
|
|
181
171
|
["uint168", "uint48", "bytes"],
|
|
182
172
|
[validationLocator, typedData.message.deadline, typedData.message.call]
|
|
183
173
|
);
|
|
184
174
|
|
|
185
|
-
const encodedDataLength = size(
|
|
186
|
-
const
|
|
187
|
-
|
|
188
|
-
encodedData = concatHex([
|
|
175
|
+
const encodedDataLength = size(encodedCallData);
|
|
176
|
+
const encodedData = concatHex([
|
|
189
177
|
toHex(encodedDataLength, { size: 4 }),
|
|
190
|
-
|
|
191
|
-
toHex(sigLength, { size: 4 }),
|
|
192
|
-
sig,
|
|
178
|
+
encodedCallData,
|
|
193
179
|
]);
|
|
194
|
-
|
|
195
180
|
return encodedData;
|
|
196
181
|
};
|
|
197
182
|
|
|
@@ -239,9 +224,10 @@ export const deferralActions: (
|
|
|
239
224
|
};
|
|
240
225
|
|
|
241
226
|
const getEntityIdAndNonce = async ({
|
|
242
|
-
entityId,
|
|
243
|
-
nonceKey,
|
|
227
|
+
entityId = 1,
|
|
228
|
+
nonceKey = 0n,
|
|
244
229
|
isGlobalValidation,
|
|
230
|
+
isDeferredAction = true,
|
|
245
231
|
}: EntityIdAndNonceParams) => {
|
|
246
232
|
if (!client.account) {
|
|
247
233
|
throw new AccountNotFoundError();
|
|
@@ -266,7 +252,7 @@ export const deferralActions: (
|
|
|
266
252
|
nonceKey,
|
|
267
253
|
entityId,
|
|
268
254
|
isGlobalValidation,
|
|
269
|
-
isDeferredAction
|
|
255
|
+
isDeferredAction,
|
|
270
256
|
}),
|
|
271
257
|
],
|
|
272
258
|
});
|
|
@@ -285,6 +271,7 @@ export const deferralActions: (
|
|
|
285
271
|
return {
|
|
286
272
|
createDeferredActionTypedDataObject,
|
|
287
273
|
buildDeferredActionDigest,
|
|
274
|
+
buildPreSignatureDeferredActionDigest,
|
|
288
275
|
buildUserOperationWithDeferredAction,
|
|
289
276
|
getEntityIdAndNonce,
|
|
290
277
|
};
|
package/src/ma-v2/index.ts
CHANGED
|
@@ -20,6 +20,10 @@ export {
|
|
|
20
20
|
} from "./actions/common/utils.js";
|
|
21
21
|
export type * from "./actions/install-validation/installValidation.js";
|
|
22
22
|
export { installValidationActions } from "./actions/install-validation/installValidation.js";
|
|
23
|
+
export type * from "./actions/deferralActions.js";
|
|
24
|
+
export { deferralActions } from "./actions/deferralActions.js";
|
|
25
|
+
export type * from "./permissionBuilder.js";
|
|
26
|
+
export { PermissionBuilder, PermissionType } from "./permissionBuilder.js";
|
|
23
27
|
|
|
24
28
|
export {
|
|
25
29
|
getDefaultAllowlistModuleAddress,
|
|
@@ -39,32 +39,38 @@ import { packUOSignature, pack1271Signature } from "../../utils.js";
|
|
|
39
39
|
* @param {Chain} chain Chain object for the signer
|
|
40
40
|
* @param {Address} accountAddress address of the smart account using this signer
|
|
41
41
|
* @param {number} entityId the entity id of the signing validation
|
|
42
|
+
* @param {Hex} deferredActionData optional deferred action data to prepend to the uo signatures
|
|
42
43
|
* @returns {object} an object with methods for signing operations and managing signatures
|
|
43
44
|
*/
|
|
44
45
|
export const singleSignerMessageSigner = (
|
|
45
46
|
signer: SmartAccountSigner,
|
|
46
47
|
chain: Chain,
|
|
47
48
|
accountAddress: Address,
|
|
48
|
-
entityId: number
|
|
49
|
+
entityId: number,
|
|
50
|
+
deferredActionData?: Hex
|
|
49
51
|
) => {
|
|
50
52
|
return {
|
|
51
53
|
getDummySignature: (): Hex => {
|
|
52
|
-
const
|
|
53
|
-
"0xfffffffffffffffffffffffffffffff0000000000000000000000000000000007aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa1c";
|
|
54
|
-
|
|
55
|
-
return packUOSignature({
|
|
54
|
+
const sig = packUOSignature({
|
|
56
55
|
// orderedHookData: [],
|
|
57
|
-
validationSignature:
|
|
56
|
+
validationSignature:
|
|
57
|
+
"0xfffffffffffffffffffffffffffffff0000000000000000000000000000000007aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa1c",
|
|
58
58
|
});
|
|
59
|
+
|
|
60
|
+
return deferredActionData ? concatHex([deferredActionData, sig]) : sig;
|
|
59
61
|
},
|
|
60
62
|
|
|
61
|
-
signUserOperationHash: (uoHash: Hex): Promise<Hex> => {
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
63
|
+
signUserOperationHash: async (uoHash: Hex): Promise<Hex> => {
|
|
64
|
+
const sig = await signer
|
|
65
|
+
.signMessage({ raw: uoHash })
|
|
66
|
+
.then((signature: Hex) =>
|
|
67
|
+
packUOSignature({
|
|
68
|
+
// orderedHookData: [],
|
|
69
|
+
validationSignature: signature,
|
|
70
|
+
})
|
|
71
|
+
);
|
|
72
|
+
|
|
73
|
+
return deferredActionData ? concatHex([deferredActionData, sig]) : sig;
|
|
68
74
|
},
|
|
69
75
|
|
|
70
76
|
// we apply the expected 1271 packing here since the account contract will expect it
|