@account-kit/smart-contracts 4.18.0-alpha.3 → 4.18.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.
@@ -1,5 +1,6 @@
1
- import { hashMessage, hashTypedData, } from "viem";
1
+ import { hashMessage, hashTypedData, concat, } from "viem";
2
2
  import { packUOSignature, pack1271Signature, DEFAULT_OWNER_ENTITY_ID, } from "../utils.js";
3
+ import { SignatureType } from "../modules/utils.js";
3
4
  /**
4
5
  * Creates an object with methods for generating a dummy signature, signing user operation hashes, signing messages, and signing typed data.
5
6
  *
@@ -65,7 +66,10 @@ export const nativeSMASigner = (signer, chain, accountAddress) => {
65
66
  const isDeferredAction = typedDataDefinition?.primaryType === "DeferredAction" &&
66
67
  typedDataDefinition?.domain?.verifyingContract === accountAddress;
67
68
  return isDeferredAction
68
- ? signer.signTypedData(typedDataDefinition)
69
+ ? concat([
70
+ SignatureType.EOA,
71
+ await signer.signTypedData(typedDataDefinition),
72
+ ])
69
73
  : pack1271Signature({
70
74
  validationSignature: await signer.signTypedData({
71
75
  domain: {
@@ -1 +1 @@
1
- {"version":3,"file":"nativeSMASigner.js","sourceRoot":"","sources":["../../../../../src/ma-v2/account/nativeSMASigner.ts"],"names":[],"mappings":"AACA,OAAO,EACL,WAAW,EACX,aAAa,GAOd,MAAM,MAAM,CAAC;AAEd,OAAO,EACL,eAAe,EACf,iBAAiB,EACjB,uBAAuB,GACxB,MAAM,aAAa,CAAC;AACrB;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,MAAM,CAAC,MAAM,eAAe,GAAG,CAC7B,MAA0B,EAC1B,KAAY,EACZ,cAAuB,EACvB,EAAE;IACF,OAAO;QACL,iBAAiB,EAAE,GAAQ,EAAE;YAC3B,MAAM,mBAAmB,GACvB,sIAAsI,CAAC;YAEzI,OAAO,eAAe,CAAC;gBACrB,uBAAuB;gBACvB,mBAAmB,EAAE,mBAAmB;aACzC,CAAC,CAAC;QACL,CAAC;Q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,KAAK,CAAC,EAAE,CAAC;4BACzB,iBAAiB,EAAE,cAAc;yBAClC;wBACD,KAAK,EAAE;4BACL,cAAc,EAAE,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,SAAS,EAAE,CAAC;yBACpD;wBACD,OAAO,EAAE;4BACP,IAAI,EAAE,MAAM,aAAa,CAAC,mBAAmB,CAAC;yBAC/C;wBACD,WAAW,EAAE,gBAAgB;qBAC9B,CAAC;oBACF,QAAQ,EAAE,uBAAuB;iBAClC,CAAC,CAAC;QACT,CAAC;KACF,CAAC;AACJ,CAAC,CAAC","sourcesContent":["import type { SmartAccountSigner } from \"@aa-sdk/core\";\nimport {\n hashMessage,\n hashTypedData,\n type Hex,\n type SignableMessage,\n type TypedData,\n type TypedDataDefinition,\n type Chain,\n type Address,\n} from \"viem\";\n\nimport {\n packUOSignature,\n pack1271Signature,\n DEFAULT_OWNER_ENTITY_ID,\n} from \"../utils.js\";\n/**\n * Creates an object with methods for generating a dummy signature, signing user operation hashes, signing messages, and signing typed data.\n *\n * @example\n * ```ts\n * import { nativeSMASigner } from \"@account-kit/smart-contracts\";\n \n * import { LocalAccountSigner } from \"@aa-sdk/core\";\n *\n * const MNEMONIC = \"...\":\n *\n * const account = createModularAccountV2({ config });\n *\n * const signer = LocalAccountSigner.mnemonicToAccountSigner(MNEMONIC);\n *\n * const messageSigner = nativeSMASigner(signer, chain, account.address);\n * ```\n *\n * @param {SmartAccountSigner} signer Signer to use for signing operations\n * @param {Chain} chain Chain object for the signer\n * @param {Address} accountAddress address of the smart account using this signer\n * @returns {object} an object with methods for signing operations and managing signatures\n */\nexport const nativeSMASigner = (\n signer: SmartAccountSigner,\n chain: Chain,\n accountAddress: Address\n) => {\n return {\n getDummySignature: (): Hex => {\n const dummyEcdsaSignature =\n \"0xfffffffffffffffffffffffffffffff0000000000000000000000000000000007aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa1c\";\n\n return packUOSignature({\n // orderedHookData: [],\n validationSignature: dummyEcdsaSignature,\n });\n },\n\n signUserOperationHash: (uoHash: Hex): Promise<Hex> => {\n return signer.signMessage({ raw: uoHash }).then((signature: Hex) =>\n packUOSignature({\n // orderedHookData: [],\n validationSignature: signature,\n })\n );\n },\n\n // we apply the expected 1271 packing here since the account contract will expect it\n async signMessage({ message }: { message: SignableMessage }): Promise<Hex> {\n const hash = hashMessage(message);\n\n return pack1271Signature({\n validationSignature: await signer.signTypedData({\n domain: {\n chainId: Number(chain.id),\n verifyingContract: accountAddress,\n },\n types: {\n ReplaySafeHash: [{ name: \"hash\", type: \"bytes32\" }],\n },\n message: {\n hash,\n },\n primaryType: \"ReplaySafeHash\",\n }),\n entityId: DEFAULT_OWNER_ENTITY_ID,\n });\n },\n\n // TODO: maybe move \"sign deferred actions\" to a separate function?\n // we don't apply the expected 1271 packing since deferred sigs use typed data sigs and don't expect the 1271 packing\n signTypedData: async <\n const typedData extends TypedData | Record<string, unknown>,\n primaryType extends keyof typedData | \"EIP712Domain\" = keyof typedData\n >(\n typedDataDefinition: TypedDataDefinition<typedData, primaryType>\n ): Promise<Hex> => {\n // the accounts domain already gives replay protection across accounts for deferred actions, so we don't need to apply another wrapping\n const isDeferredAction =\n typedDataDefinition?.primaryType === \"DeferredAction\" &&\n typedDataDefinition?.domain?.verifyingContract === accountAddress;\n\n return isDeferredAction\n ? signer.signTypedData(typedDataDefinition)\n : pack1271Signature({\n validationSignature: await signer.signTypedData({\n domain: {\n chainId: Number(chain.id),\n verifyingContract: accountAddress,\n },\n types: {\n ReplaySafeHash: [{ name: \"hash\", type: \"bytes32\" }],\n },\n message: {\n hash: await hashTypedData(typedDataDefinition),\n },\n primaryType: \"ReplaySafeHash\",\n }),\n entityId: DEFAULT_OWNER_ENTITY_ID,\n });\n },\n };\n};\n"]}
1
+ {"version":3,"file":"nativeSMASigner.js","sourceRoot":"","sources":["../../../../../src/ma-v2/account/nativeSMASigner.ts"],"names":[],"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,gBAAgB;iBAC9B,CAAC;gBACF,QAAQ,EAAE,uBAAuB;aAClC,CAAC,CAAC;QACL,CAAC;QAED,mEAAmE;QACnE,qHAAqH;QACrH,aAAa,EAAE,KAAK,EAIlB,mBAAgE,EAClD,EAAE;YAChB,uIAAuI;YACvI,MAAM,gBAAgB,GACpB,mBAAmB,EAAE,WAAW,KAAK,gBAAgB;gBACrD,mBAAmB,EAAE,MAAM,EAAE,iBAAiB,KAAK,cAAc,CAAC;YAEpE,OAAO,gBAAgB;gBACrB,CAAC,CAAC,MAAM,CAAC;oBACL,aAAa,CAAC,GAAG;oBACjB,MAAM,MAAM,CAAC,aAAa,CAAC,mBAAmB,CAAC;iBAChD,CAAC;gBACJ,CAAC,CAAC,iBAAiB,CAAC;oBAChB,mBAAmB,EAAE,MAAM,MAAM,CAAC,aAAa,CAAC;wBAC9C,MAAM,EAAE;4BACN,OAAO,EAAE,MAAM,CAAC,KAAK,CAAC,EAAE,CAAC;4BACzB,iBAAiB,EAAE,cAAc;yBAClC;wBACD,KAAK,EAAE;4BACL,cAAc,EAAE,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,SAAS,EAAE,CAAC;yBACpD;wBACD,OAAO,EAAE;4BACP,IAAI,EAAE,MAAM,aAAa,CAAC,mBAAmB,CAAC;yBAC/C;wBACD,WAAW,EAAE,gBAAgB;qBAC9B,CAAC;oBACF,QAAQ,EAAE,uBAAuB;iBAClC,CAAC,CAAC;QACT,CAAC;KACF,CAAC;AACJ,CAAC,CAAC","sourcesContent":["import type { SmartAccountSigner } from \"@aa-sdk/core\";\nimport {\n hashMessage,\n hashTypedData,\n type Hex,\n type SignableMessage,\n type TypedData,\n type TypedDataDefinition,\n type Chain,\n type Address,\n concat,\n} from \"viem\";\n\nimport {\n packUOSignature,\n pack1271Signature,\n DEFAULT_OWNER_ENTITY_ID,\n} from \"../utils.js\";\nimport { SignatureType } from \"../modules/utils.js\";\n/**\n * Creates an object with methods for generating a dummy signature, signing user operation hashes, signing messages, and signing typed data.\n *\n * @example\n * ```ts\n * import { nativeSMASigner } from \"@account-kit/smart-contracts\";\n \n * import { LocalAccountSigner } from \"@aa-sdk/core\";\n *\n * const MNEMONIC = \"...\":\n *\n * const account = createModularAccountV2({ config });\n *\n * const signer = LocalAccountSigner.mnemonicToAccountSigner(MNEMONIC);\n *\n * const messageSigner = nativeSMASigner(signer, chain, account.address);\n * ```\n *\n * @param {SmartAccountSigner} signer Signer to use for signing operations\n * @param {Chain} chain Chain object for the signer\n * @param {Address} accountAddress address of the smart account using this signer\n * @returns {object} an object with methods for signing operations and managing signatures\n */\nexport const nativeSMASigner = (\n signer: SmartAccountSigner,\n chain: Chain,\n accountAddress: Address\n) => {\n return {\n getDummySignature: (): Hex => {\n const dummyEcdsaSignature =\n \"0xfffffffffffffffffffffffffffffff0000000000000000000000000000000007aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa1c\";\n\n return packUOSignature({\n // orderedHookData: [],\n validationSignature: dummyEcdsaSignature,\n });\n },\n\n signUserOperationHash: (uoHash: Hex): Promise<Hex> => {\n return signer.signMessage({ raw: uoHash }).then((signature: Hex) =>\n packUOSignature({\n // orderedHookData: [],\n validationSignature: signature,\n })\n );\n },\n\n // we apply the expected 1271 packing here since the account contract will expect it\n async signMessage({ message }: { message: SignableMessage }): Promise<Hex> {\n const hash = hashMessage(message);\n\n return pack1271Signature({\n validationSignature: await signer.signTypedData({\n domain: {\n chainId: Number(chain.id),\n verifyingContract: accountAddress,\n },\n types: {\n ReplaySafeHash: [{ name: \"hash\", type: \"bytes32\" }],\n },\n message: {\n hash,\n },\n primaryType: \"ReplaySafeHash\",\n }),\n entityId: DEFAULT_OWNER_ENTITY_ID,\n });\n },\n\n // TODO: maybe move \"sign deferred actions\" to a separate function?\n // we don't apply the expected 1271 packing since deferred sigs use typed data sigs and don't expect the 1271 packing\n signTypedData: async <\n const typedData extends TypedData | Record<string, unknown>,\n primaryType extends keyof typedData | \"EIP712Domain\" = keyof typedData\n >(\n typedDataDefinition: TypedDataDefinition<typedData, primaryType>\n ): Promise<Hex> => {\n // the accounts domain already gives replay protection across accounts for deferred actions, so we don't need to apply another wrapping\n const isDeferredAction =\n typedDataDefinition?.primaryType === \"DeferredAction\" &&\n typedDataDefinition?.domain?.verifyingContract === accountAddress;\n\n return isDeferredAction\n ? concat([\n SignatureType.EOA,\n await signer.signTypedData(typedDataDefinition),\n ])\n : pack1271Signature({\n validationSignature: await signer.signTypedData({\n domain: {\n chainId: Number(chain.id),\n verifyingContract: accountAddress,\n },\n types: {\n ReplaySafeHash: [{ name: \"hash\", type: \"bytes32\" }],\n },\n message: {\n hash: await hashTypedData(typedDataDefinition),\n },\n primaryType: \"ReplaySafeHash\",\n }),\n entityId: DEFAULT_OWNER_ENTITY_ID,\n });\n },\n };\n};\n"]}
@@ -0,0 +1,63 @@
1
+ import { type UserOperationCallData, type BatchUserOperationCallData, type UserOperationRequest_v7 } from "@aa-sdk/core";
2
+ import { type Address, type Hex } from "viem";
3
+ import type { ModularAccountV2Client } from "../client/client.js";
4
+ export type DeferredActionTypedData = {
5
+ domain: {
6
+ chainId: number;
7
+ verifyingContract: Address;
8
+ };
9
+ types: {
10
+ DeferredAction: [
11
+ {
12
+ name: "nonce";
13
+ type: "uint256";
14
+ },
15
+ {
16
+ name: "deadline";
17
+ type: "uint48";
18
+ },
19
+ {
20
+ name: "call";
21
+ type: "bytes";
22
+ }
23
+ ];
24
+ };
25
+ primaryType: "DeferredAction";
26
+ message: {
27
+ nonce: bigint;
28
+ deadline: number;
29
+ call: Hex;
30
+ };
31
+ };
32
+ export type DeferredActionReturnData = {
33
+ typedData: DeferredActionTypedData;
34
+ nonceOverride: bigint;
35
+ };
36
+ export type CreateDeferredActionTypedDataParams = {
37
+ callData: Hex;
38
+ deadline: number;
39
+ entityId: number;
40
+ isGlobalValidation: boolean;
41
+ nonceKeyOverride?: bigint;
42
+ };
43
+ export type BuildDeferredActionDigestParams = {
44
+ typedData: DeferredActionTypedData;
45
+ sig: Hex;
46
+ };
47
+ export type BuildUserOperationWithDeferredActionParams = {
48
+ uo: UserOperationCallData | BatchUserOperationCallData;
49
+ signaturePrepend: Hex;
50
+ nonceOverride: bigint;
51
+ };
52
+ export type DeferralActions = {
53
+ createDeferredActionTypedDataObject: (args: CreateDeferredActionTypedDataParams) => Promise<DeferredActionReturnData>;
54
+ buildDeferredActionDigest: (args: BuildDeferredActionDigestParams) => Hex;
55
+ buildUserOperationWithDeferredAction: (args: BuildUserOperationWithDeferredActionParams) => Promise<UserOperationRequest_v7>;
56
+ };
57
+ /**
58
+ * Provides deferred action functionalities for a MA v2 client, ensuring compatibility with `SmartAccountClient`.
59
+ *
60
+ * @param {ModularAccountV2Client} client - The client instance which provides account and sendUserOperation functionality.
61
+ * @returns {object} - An object containing three methods: `createDeferredActionTypedDataObject`, `buildDeferredActionDigest`, and `buildUserOperationWithDeferredAction`.
62
+ */
63
+ export declare const deferralActions: (client: ModularAccountV2Client) => DeferralActions;
@@ -0,0 +1,122 @@
1
+ import { AccountNotFoundError, InvalidNonceKeyError, EntryPointNotFoundError, } from "@aa-sdk/core";
2
+ import { concatHex, maxUint152, getContract, encodePacked, size, toHex, } from "viem";
3
+ /**
4
+ * Provides deferred action functionalities for a MA v2 client, ensuring compatibility with `SmartAccountClient`.
5
+ *
6
+ * @param {ModularAccountV2Client} client - The client instance which provides account and sendUserOperation functionality.
7
+ * @returns {object} - An object containing three methods: `createDeferredActionTypedDataObject`, `buildDeferredActionDigest`, and `buildUserOperationWithDeferredAction`.
8
+ */
9
+ export const deferralActions = (client) => {
10
+ const createDeferredActionTypedDataObject = async ({ callData, deadline, entityId, isGlobalValidation, nonceKeyOverride, }) => {
11
+ if (!client.account) {
12
+ throw new AccountNotFoundError();
13
+ }
14
+ const baseNonceKey = nonceKeyOverride || 0n;
15
+ if (baseNonceKey > maxUint152) {
16
+ throw new InvalidNonceKeyError(baseNonceKey);
17
+ }
18
+ const entryPoint = client.account.getEntryPoint();
19
+ if (entryPoint === undefined) {
20
+ throw new EntryPointNotFoundError(client.chain, "0.7.0");
21
+ }
22
+ const entryPointContract = getContract({
23
+ address: entryPoint.address,
24
+ abi: entryPoint.abi,
25
+ client: client,
26
+ });
27
+ // 2 = deferred action flags 0b10
28
+ // 1 = isGlobal validation flag 0b01
29
+ const fullNonceKey = ((baseNonceKey << 40n) + (BigInt(entityId) << 8n)) |
30
+ 2n |
31
+ (isGlobalValidation ? 1n : 0n);
32
+ const nonceOverride = (await entryPointContract.read.getNonce([
33
+ client.account.address,
34
+ fullNonceKey,
35
+ ]));
36
+ return {
37
+ typedData: {
38
+ domain: {
39
+ chainId: await client.getChainId(),
40
+ verifyingContract: client.account.address,
41
+ },
42
+ types: {
43
+ DeferredAction: [
44
+ { name: "nonce", type: "uint256" },
45
+ { name: "deadline", type: "uint48" },
46
+ { name: "call", type: "bytes" },
47
+ ],
48
+ },
49
+ primaryType: "DeferredAction",
50
+ message: {
51
+ nonce: nonceOverride,
52
+ deadline: deadline,
53
+ call: callData,
54
+ },
55
+ },
56
+ nonceOverride: nonceOverride,
57
+ };
58
+ };
59
+ /**
60
+ * Creates the digest which must be prepended to the userOp signature.
61
+ *
62
+ * Assumption: The client this extends is used to sign the typed data.
63
+ *
64
+ * @param {object} args The argument object containing the following:
65
+ * @param {DeferredActionTypedData} args.typedData The typed data object for the deferred action
66
+ * @param {Hex} args.sig The signature to include in the digest
67
+ * @returns {Hex} The encoded digest to be prepended to the userOp signature
68
+ */
69
+ const buildDeferredActionDigest = ({ typedData, sig, }) => {
70
+ const signerEntity = client.account.signerEntity;
71
+ const validationLocator = (BigInt(signerEntity.entityId) << 8n) |
72
+ (signerEntity.isGlobalValidation ? 1n : 0n);
73
+ let encodedData = encodePacked(["uint168", "uint48", "bytes"], [validationLocator, typedData.message.deadline, typedData.message.call]);
74
+ const encodedDataLength = size(encodedData);
75
+ const sigLength = size(sig);
76
+ encodedData = concatHex([
77
+ toHex(encodedDataLength, { size: 4 }),
78
+ encodedData,
79
+ toHex(sigLength, { size: 4 }),
80
+ sig,
81
+ ]);
82
+ return encodedData;
83
+ };
84
+ /**
85
+ * Builds a user operation with a deferred action by wrapping buildUserOperation() with a dummy signature override.
86
+ *
87
+ * @param {object} args The argument object containing the following:
88
+ * @param {UserOperationCallData | BatchUserOperationCallData} args.uo The user operation call data to build
89
+ * @param {Hex} args.signaturePrepend The signature data to prepend to the dummy signature
90
+ * @param {bigint} args.nonceOverride The nonce to override in the user operation, generally given from the typed data builder
91
+ * @returns {Promise<UserOperationRequest_v7>} The unsigned user operation request with the deferred action
92
+ */
93
+ const buildUserOperationWithDeferredAction = async ({ uo, signaturePrepend, nonceOverride, }) => {
94
+ // Check if client.account is defined
95
+ if (client.account === undefined) {
96
+ throw new AccountNotFoundError();
97
+ }
98
+ // Pre-fetch the dummy sig so we can override `client.account.getDummySignature()`
99
+ const dummySig = await client.account.getDummySignature();
100
+ // Cache the previous dummy signature getter
101
+ const previousDummySigGetter = client.account.getDummySignature;
102
+ // Override client.account.getDummySignature() so `client.buildUserOperation()` uses the prepended hex and the dummy signature during gas estimation
103
+ client.account.getDummySignature = () => {
104
+ return concatHex([signaturePrepend, dummySig]);
105
+ };
106
+ const unsignedUo = (await client.buildUserOperation({
107
+ uo: uo,
108
+ overrides: {
109
+ nonce: nonceOverride,
110
+ },
111
+ }));
112
+ // Restore the dummy signature getter
113
+ client.account.getDummySignature = previousDummySigGetter;
114
+ return unsignedUo;
115
+ };
116
+ return {
117
+ createDeferredActionTypedDataObject,
118
+ buildDeferredActionDigest,
119
+ buildUserOperationWithDeferredAction,
120
+ };
121
+ };
122
+ //# sourceMappingURL=DeferralActions.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"DeferralActions.js","sourceRoot":"","sources":["../../../../../src/ma-v2/actions/DeferralActions.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,oBAAoB,EACpB,oBAAoB,EACpB,uBAAuB,GAIxB,MAA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ACJ,CAAC,CAAC","sourcesContent":["import {\n AccountNotFoundError,\n InvalidNonceKeyError,\n EntryPointNotFoundError,\n type UserOperationCallData,\n type BatchUserOperationCallData,\n type UserOperationRequest_v7,\n} from \"@aa-sdk/core\";\nimport {\n type Address,\n type Hex,\n concatHex,\n maxUint152,\n getContract,\n encodePacked,\n size,\n toHex,\n} from \"viem\";\nimport type { ModularAccountV2Client } from \"../client/client.js\";\n\nexport type DeferredActionTypedData = {\n domain: {\n chainId: number;\n verifyingContract: Address;\n };\n types: {\n DeferredAction: [\n { name: \"nonce\"; type: \"uint256\" },\n { name: \"deadline\"; type: \"uint48\" },\n { name: \"call\"; type: \"bytes\" }\n ];\n };\n primaryType: \"DeferredAction\";\n message: {\n nonce: bigint;\n deadline: number;\n call: Hex;\n };\n};\n\nexport type DeferredActionReturnData = {\n typedData: DeferredActionTypedData;\n nonceOverride: bigint;\n};\n\nexport type CreateDeferredActionTypedDataParams = {\n callData: Hex;\n deadline: number;\n entityId: number;\n isGlobalValidation: boolean;\n nonceKeyOverride?: bigint;\n};\n\nexport type BuildDeferredActionDigestParams = {\n typedData: DeferredActionTypedData;\n sig: Hex;\n};\n\nexport type BuildUserOperationWithDeferredActionParams = {\n uo: UserOperationCallData | BatchUserOperationCallData;\n signaturePrepend: Hex;\n nonceOverride: bigint;\n};\n\nexport type DeferralActions = {\n createDeferredActionTypedDataObject: (\n args: CreateDeferredActionTypedDataParams\n ) => Promise<DeferredActionReturnData>;\n buildDeferredActionDigest: (args: BuildDeferredActionDigestParams) => Hex;\n buildUserOperationWithDeferredAction: (\n args: BuildUserOperationWithDeferredActionParams\n ) => Promise<UserOperationRequest_v7>;\n};\n\n/**\n * Provides deferred action functionalities for a MA v2 client, ensuring compatibility with `SmartAccountClient`.\n *\n * @param {ModularAccountV2Client} client - The client instance which provides account and sendUserOperation functionality.\n * @returns {object} - An object containing three methods: `createDeferredActionTypedDataObject`, `buildDeferredActionDigest`, and `buildUserOperationWithDeferredAction`.\n */\nexport const deferralActions: (\n client: ModularAccountV2Client\n) => DeferralActions = (client: ModularAccountV2Client): DeferralActions => {\n const createDeferredActionTypedDataObject = async ({\n callData,\n deadline,\n entityId,\n isGlobalValidation,\n nonceKeyOverride,\n }: CreateDeferredActionTypedDataParams): Promise<DeferredActionReturnData> => {\n if (!client.account) {\n throw new AccountNotFoundError();\n }\n\n const baseNonceKey = nonceKeyOverride || 0n;\n if (baseNonceKey > maxUint152) {\n throw new InvalidNonceKeyError(baseNonceKey);\n }\n\n const entryPoint = client.account.getEntryPoint();\n if (entryPoint === undefined) {\n throw new EntryPointNotFoundError(client.chain, \"0.7.0\");\n }\n\n const entryPointContract = getContract({\n address: entryPoint.address,\n abi: entryPoint.abi,\n client: client,\n });\n\n // 2 = deferred action flags 0b10\n // 1 = isGlobal validation flag 0b01\n const fullNonceKey: bigint =\n ((baseNonceKey << 40n) + (BigInt(entityId) << 8n)) |\n 2n |\n (isGlobalValidation ? 1n : 0n);\n\n const nonceOverride = (await entryPointContract.read.getNonce([\n client.account.address,\n fullNonceKey,\n ])) as bigint;\n\n return {\n typedData: {\n domain: {\n chainId: await client.getChainId(),\n verifyingContract: client.account.address,\n },\n types: {\n DeferredAction: [\n { name: \"nonce\", type: \"uint256\" },\n { name: \"deadline\", type: \"uint48\" },\n { name: \"call\", type: \"bytes\" },\n ],\n },\n primaryType: \"DeferredAction\",\n message: {\n nonce: nonceOverride,\n deadline: deadline,\n call: callData,\n },\n },\n nonceOverride: nonceOverride,\n };\n };\n\n /**\n * Creates the digest which must be prepended to the userOp signature.\n *\n * Assumption: The client this extends is used to sign the typed data.\n *\n * @param {object} args The argument object containing the following:\n * @param {DeferredActionTypedData} args.typedData The typed data object for the deferred action\n * @param {Hex} args.sig The signature to include in the digest\n * @returns {Hex} The encoded digest to be prepended to the userOp signature\n */\n const buildDeferredActionDigest = ({\n typedData,\n sig,\n }: BuildDeferredActionDigestParams): Hex => {\n const signerEntity = client.account.signerEntity;\n const validationLocator =\n (BigInt(signerEntity.entityId) << 8n) |\n (signerEntity.isGlobalValidation ? 1n : 0n);\n\n let encodedData = encodePacked(\n [\"uint168\", \"uint48\", \"bytes\"],\n [validationLocator, typedData.message.deadline, typedData.message.call]\n );\n\n const encodedDataLength = size(encodedData);\n const sigLength = size(sig);\n\n encodedData = concatHex([\n toHex(encodedDataLength, { size: 4 }),\n encodedData,\n toHex(sigLength, { size: 4 }),\n sig,\n ]);\n\n return encodedData;\n };\n\n /**\n * Builds a user operation with a deferred action by wrapping buildUserOperation() with a dummy signature override.\n *\n * @param {object} args The argument object containing the following:\n * @param {UserOperationCallData | BatchUserOperationCallData} args.uo The user operation call data to build\n * @param {Hex} args.signaturePrepend The signature data to prepend to the dummy signature\n * @param {bigint} args.nonceOverride The nonce to override in the user operation, generally given from the typed data builder\n * @returns {Promise<UserOperationRequest_v7>} The unsigned user operation request with the deferred action\n */\n const buildUserOperationWithDeferredAction = async ({\n uo,\n signaturePrepend,\n nonceOverride,\n }: BuildUserOperationWithDeferredActionParams): Promise<UserOperationRequest_v7> => {\n // Check if client.account is defined\n if (client.account === undefined) {\n throw new AccountNotFoundError();\n }\n\n // Pre-fetch the dummy sig so we can override `client.account.getDummySignature()`\n const dummySig = await client.account.getDummySignature();\n\n // Cache the previous dummy signature getter\n const previousDummySigGetter = client.account.getDummySignature;\n\n // Override client.account.getDummySignature() so `client.buildUserOperation()` uses the prepended hex and the dummy signature during gas estimation\n client.account.getDummySignature = () => {\n return concatHex([signaturePrepend, dummySig as Hex]);\n };\n\n const unsignedUo = (await client.buildUserOperation({\n uo: uo,\n overrides: {\n nonce: nonceOverride,\n },\n })) as UserOperationRequest_v7;\n\n // Restore the dummy signature getter\n client.account.getDummySignature = previousDummySigGetter;\n\n return unsignedUo;\n };\n\n return {\n createDeferredActionTypedDataObject,\n buildDeferredActionDigest,\n buildUserOperationWithDeferredAction,\n };\n};\n"]}
@@ -1,5 +1,5 @@
1
- import { hashMessage, hashTypedData, concatHex, } from "viem";
2
- import { getDefaultSingleSignerValidationModuleAddress } from "../utils.js";
1
+ import { hashMessage, hashTypedData, concatHex, concat, } from "viem";
2
+ import { getDefaultSingleSignerValidationModuleAddress, SignatureType, } from "../utils.js";
3
3
  import { packUOSignature, pack1271Signature } from "../../utils.js";
4
4
  /**
5
5
  * Creates an object with methods for generating a dummy signature, signing user operation hashes, signing messages, and signing typed data.
@@ -77,12 +77,13 @@ export const singleSignerMessageSigner = (signer, chain, accountAddress, entityI
77
77
  ReplaySafeHash: [{ name: "hash", type: "bytes32" }],
78
78
  },
79
79
  message: {
80
- hash: await hashTypedData(typedDataDefinition),
80
+ hash: hashTypedData(typedDataDefinition),
81
81
  },
82
82
  primaryType: "ReplaySafeHash",
83
83
  });
84
+ // TODO: Handle non-EOA signer case
84
85
  return isDeferredAction
85
- ? validationSignature
86
+ ? concat([SignatureType.EOA, validationSignature])
86
87
  : pack1271Signature({
87
88
  validationSignature,
88
89
  entityId,
@@ -1 +1 @@
1
- {"version":3,"file":"signer.js","sourceRoot":"","sources":["../../../../../../src/ma-v2/modules/single-signer-validation/signer.ts"],"names":[],"mappings":"AACA,OAAO,EACL,WAAW,EACX,aAAa,EACb,SAAS,GAOV,MAAM,MAAM,CAAC;AACd,OAAO,EAAE,6CAA6C,EAAE,MAAM,aAAa,CAAC;AAE5E,OAAO,EAAE,eAAe,EAAE,iBAAiB,EAAE,MAAM,gBAAgB,CAAC;AACpE;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,MAAM,CAAC,MAAM,yBAAyB,GAAG,CACvC,MAA0B,EAC1B,KAAY,EACZ,cAAuB,EACvB,QAAgB,EAChB,EAAE;IACF,OAAO;QACL,iBAAiB,EAAE,GAAQ,EAAE;YAC3B,MAAM,mBAAmB,GACvB,sIAAsI,CAAC;YAEzI,OAAO,eAAe,CAAC;gBACrB,uBAAuB;gBACvB,mBAAmB,EAAE,mBAAmB;aACzC,CAAC,CAAC;QACL,CAAC;QAED,qBAAqB,EAAE,CAAC,MAAW,EAAgB,EAAE;Y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BAAiB,EACf,6CAA6C,CAAC,KAAK,CAAC;oBACtD,IAAI,EAAE,SAAS,CAAC,CAAC,KAAK,IAAI,CAAC,MAAM,CAAC,EAAE,CAAC,EAAE,EAAE,cAAc,CAAC,CAAC;iBAC1D;gBACD,KAAK,EAAE;oBACL,cAAc,EAAE,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,SAAS,EAAE,CAAC;iBACpD;gBACD,OAAO,EAAE;oBACP,IAAI,EAAE,MAAM,aAAa,CAAC,mBAAmB,CAAC;iBAC/C;gBACD,WAAW,EAAE,gBAAgB;aAC9B,CAAC,CAAC;YAEH,OAAO,gBAAgB;gBACrB,CAAC,CAAC,mBAAmB;gBACrB,CAAC,CAAC,iBAAiB,CAAC;oBAChB,mBAAmB;oBACnB,QAAQ;iBACT,CAAC,CAAC;QACT,CAAC;KACF,CAAC;AACJ,CAAC,CAAC","sourcesContent":["import type { SmartAccountSigner } from \"@aa-sdk/core\";\nimport {\n hashMessage,\n hashTypedData,\n concatHex,\n type Hex,\n type SignableMessage,\n type TypedData,\n type TypedDataDefinition,\n type Chain,\n type Address,\n} from \"viem\";\nimport { getDefaultSingleSignerValidationModuleAddress } from \"../utils.js\";\n\nimport { packUOSignature, pack1271Signature } from \"../../utils.js\";\n/**\n * Creates an object with methods for generating a dummy signature, signing user operation hashes, signing messages, and signing typed data.\n *\n * @example \n \n * ```ts\n * import { singleSignerMessageSigner } from \"@account-kit/smart-contracts\";\n * import { LocalAccountSigner } from \"@aa-sdk/core\";\n *\n * const MNEMONIC = \"...\":\n * \n * const account = createModularAccountV2({ config });\n *\n * const signer = LocalAccountSigner.mnemonicToAccountSigner(MNEMONIC);\n *\n * const messageSigner = singleSignerMessageSigner(signer, chain, account.address, account.signerEntity.entityId);\n * ```\n *\n * @param {SmartAccountSigner} signer Signer to use for signing operations\n * @param {Chain} chain Chain object for the signer\n * @param {Address} accountAddress address of the smart account using this signer\n * @param {number} entityId the entity id of the signing validation\n * @returns {object} an object with methods for signing operations and managing signatures\n */\nexport const singleSignerMessageSigner = (\n signer: SmartAccountSigner,\n chain: Chain,\n accountAddress: Address,\n entityId: number\n) => {\n return {\n getDummySignature: (): Hex => {\n const dummyEcdsaSignature =\n \"0xfffffffffffffffffffffffffffffff0000000000000000000000000000000007aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa1c\";\n\n return packUOSignature({\n // orderedHookData: [],\n validationSignature: dummyEcdsaSignature,\n });\n },\n\n signUserOperationHash: (uoHash: Hex): Promise<Hex> => {\n return signer.signMessage({ raw: uoHash }).then((signature: Hex) =>\n packUOSignature({\n // orderedHookData: [],\n validationSignature: signature,\n })\n );\n },\n\n // we apply the expected 1271 packing here since the account contract will expect it\n async signMessage({ message }: { message: SignableMessage }): Promise<Hex> {\n const hash = await hashMessage(message);\n\n return pack1271Signature({\n validationSignature: await signer.signTypedData({\n domain: {\n chainId: Number(chain.id),\n verifyingContract:\n getDefaultSingleSignerValidationModuleAddress(chain),\n salt: concatHex([`0x${\"00\".repeat(12)}`, accountAddress]),\n },\n types: {\n ReplaySafeHash: [{ name: \"hash\", type: \"bytes32\" }],\n },\n message: {\n hash,\n },\n primaryType: \"ReplaySafeHash\",\n }),\n entityId,\n });\n },\n\n // TODO: maybe move \"sign deferred actions\" to a separate function?\n // we don't apply the expected 1271 packing since deferred sigs use typed data sigs and don't expect the 1271 packing\n signTypedData: async <\n const typedData extends TypedData | Record<string, unknown>,\n primaryType extends keyof typedData | \"EIP712Domain\" = keyof typedData\n >(\n typedDataDefinition: TypedDataDefinition<typedData, primaryType>\n ): Promise<Hex> => {\n // the accounts domain already gives replay protection across accounts for deferred actions, so we don't need to apply another wrapping\n const isDeferredAction =\n typedDataDefinition?.primaryType === \"DeferredAction\" &&\n typedDataDefinition?.domain?.verifyingContract === accountAddress;\n\n const validationSignature = await signer.signTypedData({\n domain: {\n chainId: Number(chain.id),\n verifyingContract:\n getDefaultSingleSignerValidationModuleAddress(chain),\n salt: concatHex([`0x${\"00\".repeat(12)}`, accountAddress]),\n },\n types: {\n ReplaySafeHash: [{ name: \"hash\", type: \"bytes32\" }],\n },\n message: {\n hash: await hashTypedData(typedDataDefinition),\n },\n primaryType: \"ReplaySafeHash\",\n });\n\n return isDeferredAction\n ? validationSignature\n : pack1271Signature({\n validationSignature,\n entityId,\n });\n },\n };\n};\n"]}
1
+ {"version":3,"file":"signer.js","sourceRoot":"","sources":["../../../../../../src/ma-v2/modules/single-signer-validation/signer.ts"],"names":[],"mappings":"AACA,OAAO,EACL,WAAW,EACX,aAAa,EACb,SAAS,EAOT,MAAM,GACP,MAAM,MAAM,CAAC;AACd,OAAO,EACL,6CAA6C,EAC7C,aAAa,GACd,MAAM,aAAa,CAAC;AAErB,OAAO,EAAE,eAAe,EAAE,iBAAiB,EAAE,MAAM,gBAAgB,CAAC;AACpE;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,MAAM,CAAC,MAAM,yBAAyB,GAAG,CACvC,MAA0B,EAC1B,KAAY,EACZ,cAAuB,EACvB,QAAgB,EAChB,EAAE;IACF,OAAO;QACL,iBAAiB,EAAE,GAAQ,EAAE;YAC3B,MAAM,mBAAmB,GACvB,sIAAsI,CAAC;YAEzI,OAAO,eAAe,CAAC;gBACrB,uBAAuB;gBACvB,mBAAmB,EAAE,mBAAmB;aACzC,CAAC,CAAC;QACL,CAAC;QAED,qBAAqB,EAAE,CAAC,MAAW,EAAgB,EAAE;YACnD,OAAO,MAAM,CAAC,WAAW,CAAC,EAAE,GAAG,EAAE,MAAM,EAAE,CAAC,CAAC,IAAI,CAAC,CAAC,SAAc,EAAE,EAAE,CACjE,eAAe,CAAC;gBACd,uBAAuB;gBACvB,mBAAmB,EAAE,SAAS;aAC/B,CAAC,CACH,CAAC;QACJ,CAAC;QAED,oFAAoF;QACpF,KAAK,CAAC,WAAW,CAAC,EAAE,OAAO,EAAgC;YACzD,MAAM,IAAI,GAAG,MAAM,WAAW,CAA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C,mBAAmB,CAAC;iBACzC;gBACD,WAAW,EAAE,gBAAgB;aAC9B,CAAC,CAAC;YAEH,mCAAmC;YACnC,OAAO,gBAAgB;gBACrB,CAAC,CAAC,MAAM,CAAC,CAAC,aAAa,CAAC,GAAG,EAAE,mBAAmB,CAAC,CAAC;gBAClD,CAAC,CAAC,iBAAiB,CAAC;oBAChB,mBAAmB;oBACnB,QAAQ;iBACT,CAAC,CAAC;QACT,CAAC;KACF,CAAC;AACJ,CAAC,CAAC","sourcesContent":["import type { SmartAccountSigner } from \"@aa-sdk/core\";\nimport {\n hashMessage,\n hashTypedData,\n concatHex,\n type Hex,\n type SignableMessage,\n type TypedData,\n type TypedDataDefinition,\n type Chain,\n type Address,\n concat,\n} from \"viem\";\nimport {\n getDefaultSingleSignerValidationModuleAddress,\n SignatureType,\n} from \"../utils.js\";\n\nimport { packUOSignature, pack1271Signature } from \"../../utils.js\";\n/**\n * Creates an object with methods for generating a dummy signature, signing user operation hashes, signing messages, and signing typed data.\n *\n * @example \n \n * ```ts\n * import { singleSignerMessageSigner } from \"@account-kit/smart-contracts\";\n * import { LocalAccountSigner } from \"@aa-sdk/core\";\n *\n * const MNEMONIC = \"...\":\n * \n * const account = createModularAccountV2({ config });\n *\n * const signer = LocalAccountSigner.mnemonicToAccountSigner(MNEMONIC);\n *\n * const messageSigner = singleSignerMessageSigner(signer, chain, account.address, account.signerEntity.entityId);\n * ```\n *\n * @param {SmartAccountSigner} signer Signer to use for signing operations\n * @param {Chain} chain Chain object for the signer\n * @param {Address} accountAddress address of the smart account using this signer\n * @param {number} entityId the entity id of the signing validation\n * @returns {object} an object with methods for signing operations and managing signatures\n */\nexport const singleSignerMessageSigner = (\n signer: SmartAccountSigner,\n chain: Chain,\n accountAddress: Address,\n entityId: number\n) => {\n return {\n getDummySignature: (): Hex => {\n const dummyEcdsaSignature =\n \"0xfffffffffffffffffffffffffffffff0000000000000000000000000000000007aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa1c\";\n\n return packUOSignature({\n // orderedHookData: [],\n validationSignature: dummyEcdsaSignature,\n });\n },\n\n signUserOperationHash: (uoHash: Hex): Promise<Hex> => {\n return signer.signMessage({ raw: uoHash }).then((signature: Hex) =>\n packUOSignature({\n // orderedHookData: [],\n validationSignature: signature,\n })\n );\n },\n\n // we apply the expected 1271 packing here since the account contract will expect it\n async signMessage({ message }: { message: SignableMessage }): Promise<Hex> {\n const hash = await hashMessage(message);\n\n return pack1271Signature({\n validationSignature: await signer.signTypedData({\n domain: {\n chainId: Number(chain.id),\n verifyingContract:\n getDefaultSingleSignerValidationModuleAddress(chain),\n salt: concatHex([`0x${\"00\".repeat(12)}`, accountAddress]),\n },\n types: {\n ReplaySafeHash: [{ name: \"hash\", type: \"bytes32\" }],\n },\n message: {\n hash,\n },\n primaryType: \"ReplaySafeHash\",\n }),\n entityId,\n });\n },\n\n // TODO: maybe move \"sign deferred actions\" to a separate function?\n // we don't apply the expected 1271 packing since deferred sigs use typed data sigs and don't expect the 1271 packing\n signTypedData: async <\n const typedData extends TypedData | Record<string, unknown>,\n primaryType extends keyof typedData | \"EIP712Domain\" = keyof typedData\n >(\n typedDataDefinition: TypedDataDefinition<typedData, primaryType>\n ): Promise<Hex> => {\n // the accounts domain already gives replay protection across accounts for deferred actions, so we don't need to apply another wrapping\n const isDeferredAction =\n typedDataDefinition?.primaryType === \"DeferredAction\" &&\n typedDataDefinition?.domain?.verifyingContract === accountAddress;\n\n const validationSignature = await signer.signTypedData({\n domain: {\n chainId: Number(chain.id),\n verifyingContract:\n getDefaultSingleSignerValidationModuleAddress(chain),\n salt: concatHex([`0x${\"00\".repeat(12)}`, accountAddress]),\n },\n types: {\n ReplaySafeHash: [{ name: \"hash\", type: \"bytes32\" }],\n },\n message: {\n hash: hashTypedData(typedDataDefinition),\n },\n primaryType: \"ReplaySafeHash\",\n });\n\n // TODO: Handle non-EOA signer case\n return isDeferredAction\n ? concat([SignatureType.EOA, validationSignature])\n : pack1271Signature({\n validationSignature,\n entityId,\n });\n },\n };\n};\n"]}
@@ -1,4 +1,8 @@
1
1
  import type { Chain, Address } from "viem";
2
+ export declare enum SignatureType {
3
+ EOA = "0x00",
4
+ CONTRACT = "0x01"
5
+ }
2
6
  /**
3
7
  * Maps a given chain to a specific address of the webauthn validation module by its chain ID. If no direct mapping exists, it defaults to returning a specific address.
4
8
  *
@@ -1,4 +1,9 @@
1
1
  import { arbitrum, arbitrumSepolia, base, baseSepolia, mainnet, optimism, optimismSepolia, polygon, polygonAmoy, sepolia, } from "@account-kit/infra";
2
+ export var SignatureType;
3
+ (function (SignatureType) {
4
+ SignatureType["EOA"] = "0x00";
5
+ SignatureType["CONTRACT"] = "0x01";
6
+ })(SignatureType || (SignatureType = {}));
2
7
  /**
3
8
  * Maps a given chain to a specific address of the webauthn validation module by its chain ID. If no direct mapping exists, it defaults to returning a specific address.
4
9
  *
@@ -1 +1 @@
1
- {"version":3,"file":"utils.js","sourceRoot":"","sources":["../../../../../src/ma-v2/modules/utils.ts"],"names":[],"mappings":"AACA,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;;;;;;;;;;;;;GAaG;AACH,MAAM,CAAC,MAAM,yCAAyC,GAAG,CACvD,KAAY,EACH,EAAE;IACX,QAAQ,KAAK,CAAC,EAAE,EAAE,CAAC;QACjB,wBAAwB;QACxB,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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M,gCAAgC,GAAG,CAAC,KAAY,EAAW,EAAE;IACxE,QAAQ,KAAK,CAAC,EAAE,EAAE,CAAC;QACjB,wBAAwB;QACxB,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;IACxD,CAAC;AACH,CAAC,CAAC","sourcesContent":["import type { Chain, Address } from \"viem\";\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\";\n\n/**\n * Maps a given chain to a specific address of the webauthn validation module by its chain ID. If no direct mapping exists, it defaults to returning a specific address.\n *\n * @example\n * ```ts\n * import { getDefaultWebauthnValidationModuleAddress } from \"@account-kit/smart-contracts\";\n * import { Chain, Address } from \"viem\";\n *\n * const chain: Chain = ...\n * const webauthnValidationAddress: Address = getDefaultWebauthnValidationModuleAddress(chain);\n * ```\n * @param {Chain} chain The chain object containing the chain ID to map\n * @returns {Address} The webauthn validation module address associated with the specified chain ID or a default address if no specific mapping exists\n */\nexport const getDefaultWebauthnValidationModuleAddress = (\n chain: Chain\n): Address => {\n switch (chain.id) {\n // TODO: case mekong.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 \"0x0000000000001D9d34E07D9834274dF9ae575217\";\n }\n};\n\n/**\n * Maps a given chain to a specific address of the time range module by its chain ID. If no direct mapping exists, it defaults to returning a specific address.\n *\n * @example\n * ```ts\n * import { getDefaultTimeRangeModuleAddress } from \"@account-kit/smart-contracts\";\n * import { Chain, Address } from \"viem\";\n *\n * const chain: Chain = ...\n * const timeRangeModuleAddress: Address = getDefaultTimeRangeModuleAddress(chain);\n * ```\n * @param {Chain} chain The chain object containing the chain ID to map\n * @returns {Address} The time range module address associated with the specified chain ID or a default address if no specific mapping exists\n */\nexport const getDefaultTimeRangeModuleAddress = (chain: Chain): Address => {\n switch (chain.id) {\n // TODO: case mekong.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 \"0x00000000000082B8e2012be914dFA4f62A0573eA\";\n }\n};\n\n/**\n * Maps a given chain to a specific address of the single signer validation module by its chain ID. If no direct mapping exists, it defaults to returning a specific address.\n *\n * @example\n * ```ts\n * import { getDefaultSingleSignerValidationModuleAddress } from \"@account-kit/smart-contracts\";\n * import { Chain, Address } from \"viem\";\n *\n * const chain: Chain = ...\n * const singleSignerValidationAddress: Address = getDefaultSingleSignerValidationModuleAddress(chain);\n * ```\n * @param {Chain} chain The chain object containing the chain ID to map\n * @returns {Address} The single signer validation module address associated with the specified chain ID or a default address if no specific mapping exists\n */\nexport const getDefaultSingleSignerValidationModuleAddress = (\n chain: Chain\n): Address => {\n switch (chain.id) {\n // TODO: case mekong.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 \"0x00000000000099DE0BF6fA90dEB851E2A2df7d83\";\n }\n};\n\n/**\n * Maps a given chain to a specific address of the paymaster guard module by its chain ID. If no direct mapping exists, it defaults to returning a specific address.\n *\n * @example\n * ```ts\n * import { getDefaultPaymasterGuardModuleAddress } from \"@account-kit/smart-contracts\";\n * import { Chain, Address } from \"viem\";\n *\n * const chain: Chain = ...\n * const paymasterGuardAddress: Address = getDefaultPaymasterGuardModuleAddress(chain);\n * ```\n * @param {Chain} chain The chain object containing the chain ID to map\n * @returns {Address} The paymaster guard module address associated with the specified chain ID or a default address if no specific mapping exists\n */\nexport const getDefaultPaymasterGuardModuleAddress = (\n chain: Chain\n): Address => {\n switch (chain.id) {\n // TODO: case mekong.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 \"0x0000000000001aA7A7F7E29abe0be06c72FD42A1\";\n }\n};\n\n/**\n * Maps a given chain to a specific address of the native token limit module by its chain ID. If no direct mapping exists, it defaults to returning a specific address.\n *\n * @example\n * ```ts\n * import { getDefaultNativeTokenLimitModuleAddress } from \"@account-kit/smart-contracts\";\n * import { Chain, Address } from \"viem\";\n *\n * const chain: Chain = ...\n * const nativeTokenLimitAddress: Address = getDefaultNativeTokenLimitModuleAddress(chain);\n * ```\n * @param {Chain} chain The chain object containing the chain ID to map\n * @returns {Address} The native token limit module address associated with the specified chain ID or a default address if no specific mapping exists\n */\nexport const getDefaultNativeTokenLimitModuleAddress = (\n chain: Chain\n): Address => {\n switch (chain.id) {\n // TODO: case mekong.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 \"0x00000000000001e541f0D090868FBe24b59Fbe06\";\n }\n};\n\n/**\n * Maps a given chain to a specific address of the allowlist module by its chain ID. If no direct mapping exists, it defaults to returning a specific address.\n *\n * @example\n * ```ts\n * import { getDefaultAllowlistModuleAddress } from \"@account-kit/smart-contracts\";\n * import { Chain, Address } from \"viem\";\n *\n * const chain: Chain = ...\n * const allowlistModule: Address = getDefaultAllowlistModuleAddress(chain);\n * ```\n * @param {Chain} chain The chain object containing the chain ID to map\n * @returns {Address} The allowlist module address associated with the specified chain ID or a default address if no specific mapping exists\n */\nexport const getDefaultAllowlistModuleAddress = (chain: Chain): Address => {\n switch (chain.id) {\n // TODO: case mekong.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 \"0x0000000000002311EEE9A2B887af1F144dbb4F6e\";\n }\n};\n"]}
1
+ {"version":3,"file":"utils.js","sourceRoot":"","sources":["../../../../../src/ma-v2/modules/utils.ts"],"names":[],"mappings":"AACA,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,MAAM,CAAN,IAAY,aAGX;AAHD,WAAY,aAAa;IACvB,6BAAY,CAAA;IACZ,kCAAiB,CAAA;AACnB,CAAC,EAHW,aAAa,KAAb,aAAa,QAGxB;AAED;;;;;;;;;;;;;GAaG;AACH,MAAM,CAAC,MAAM,yCAAyC,GAAG,CACvD,KAAY,EACH,EAAE;IACX,QAAQ,KAAK,CAAC,EAAE,EAAE,CAAC;QACjB,wBAAwB;QACxB,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,CA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CAAC,KAAY,EAAW,EAAE;IACxE,QAAQ,KAAK,CAAC,EAAE,EAAE,CAAC;QACjB,wBAAwB;QACxB,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;IACxD,CAAC;AACH,CAAC,CAAC","sourcesContent":["import type { Chain, Address } from \"viem\";\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\";\n\nexport enum SignatureType {\n EOA = \"0x00\",\n CONTRACT = \"0x01\",\n}\n\n/**\n * Maps a given chain to a specific address of the webauthn validation module by its chain ID. If no direct mapping exists, it defaults to returning a specific address.\n *\n * @example\n * ```ts\n * import { getDefaultWebauthnValidationModuleAddress } from \"@account-kit/smart-contracts\";\n * import { Chain, Address } from \"viem\";\n *\n * const chain: Chain = ...\n * const webauthnValidationAddress: Address = getDefaultWebauthnValidationModuleAddress(chain);\n * ```\n * @param {Chain} chain The chain object containing the chain ID to map\n * @returns {Address} The webauthn validation module address associated with the specified chain ID or a default address if no specific mapping exists\n */\nexport const getDefaultWebauthnValidationModuleAddress = (\n chain: Chain\n): Address => {\n switch (chain.id) {\n // TODO: case mekong.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 \"0x0000000000001D9d34E07D9834274dF9ae575217\";\n }\n};\n\n/**\n * Maps a given chain to a specific address of the time range module by its chain ID. If no direct mapping exists, it defaults to returning a specific address.\n *\n * @example\n * ```ts\n * import { getDefaultTimeRangeModuleAddress } from \"@account-kit/smart-contracts\";\n * import { Chain, Address } from \"viem\";\n *\n * const chain: Chain = ...\n * const timeRangeModuleAddress: Address = getDefaultTimeRangeModuleAddress(chain);\n * ```\n * @param {Chain} chain The chain object containing the chain ID to map\n * @returns {Address} The time range module address associated with the specified chain ID or a default address if no specific mapping exists\n */\nexport const getDefaultTimeRangeModuleAddress = (chain: Chain): Address => {\n switch (chain.id) {\n // TODO: case mekong.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 \"0x00000000000082B8e2012be914dFA4f62A0573eA\";\n }\n};\n\n/**\n * Maps a given chain to a specific address of the single signer validation module by its chain ID. If no direct mapping exists, it defaults to returning a specific address.\n *\n * @example\n * ```ts\n * import { getDefaultSingleSignerValidationModuleAddress } from \"@account-kit/smart-contracts\";\n * import { Chain, Address } from \"viem\";\n *\n * const chain: Chain = ...\n * const singleSignerValidationAddress: Address = getDefaultSingleSignerValidationModuleAddress(chain);\n * ```\n * @param {Chain} chain The chain object containing the chain ID to map\n * @returns {Address} The single signer validation module address associated with the specified chain ID or a default address if no specific mapping exists\n */\nexport const getDefaultSingleSignerValidationModuleAddress = (\n chain: Chain\n): Address => {\n switch (chain.id) {\n // TODO: case mekong.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 \"0x00000000000099DE0BF6fA90dEB851E2A2df7d83\";\n }\n};\n\n/**\n * Maps a given chain to a specific address of the paymaster guard module by its chain ID. If no direct mapping exists, it defaults to returning a specific address.\n *\n * @example\n * ```ts\n * import { getDefaultPaymasterGuardModuleAddress } from \"@account-kit/smart-contracts\";\n * import { Chain, Address } from \"viem\";\n *\n * const chain: Chain = ...\n * const paymasterGuardAddress: Address = getDefaultPaymasterGuardModuleAddress(chain);\n * ```\n * @param {Chain} chain The chain object containing the chain ID to map\n * @returns {Address} The paymaster guard module address associated with the specified chain ID or a default address if no specific mapping exists\n */\nexport const getDefaultPaymasterGuardModuleAddress = (\n chain: Chain\n): Address => {\n switch (chain.id) {\n // TODO: case mekong.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 \"0x0000000000001aA7A7F7E29abe0be06c72FD42A1\";\n }\n};\n\n/**\n * Maps a given chain to a specific address of the native token limit module by its chain ID. If no direct mapping exists, it defaults to returning a specific address.\n *\n * @example\n * ```ts\n * import { getDefaultNativeTokenLimitModuleAddress } from \"@account-kit/smart-contracts\";\n * import { Chain, Address } from \"viem\";\n *\n * const chain: Chain = ...\n * const nativeTokenLimitAddress: Address = getDefaultNativeTokenLimitModuleAddress(chain);\n * ```\n * @param {Chain} chain The chain object containing the chain ID to map\n * @returns {Address} The native token limit module address associated with the specified chain ID or a default address if no specific mapping exists\n */\nexport const getDefaultNativeTokenLimitModuleAddress = (\n chain: Chain\n): Address => {\n switch (chain.id) {\n // TODO: case mekong.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 \"0x00000000000001e541f0D090868FBe24b59Fbe06\";\n }\n};\n\n/**\n * Maps a given chain to a specific address of the allowlist module by its chain ID. If no direct mapping exists, it defaults to returning a specific address.\n *\n * @example\n * ```ts\n * import { getDefaultAllowlistModuleAddress } from \"@account-kit/smart-contracts\";\n * import { Chain, Address } from \"viem\";\n *\n * const chain: Chain = ...\n * const allowlistModule: Address = getDefaultAllowlistModuleAddress(chain);\n * ```\n * @param {Chain} chain The chain object containing the chain ID to map\n * @returns {Address} The allowlist module address associated with the specified chain ID or a default address if no specific mapping exists\n */\nexport const getDefaultAllowlistModuleAddress = (chain: Chain): Address => {\n switch (chain.id) {\n // TODO: case mekong.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 \"0x0000000000002311EEE9A2B887af1F144dbb4F6e\";\n }\n};\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"nativeSMASigner.d.ts","sourceRoot":"","sources":["../../../../../src/ma-v2/account/nativeSMASigner.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,cAAc,CAAC;AACvD,OAAO,EAGL,KAAK,GAAG,EACR,KAAK,eAAe,EAEpB,KAAK,mBAAmB,EACxB,KAAK,KAAK,EACV,KAAK,OAAO,EACb,MAAM,MAAM,CAAC;AAOd;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,eAAO,MAAM,eAAe,WAClB,kBAAkB,SACnB,KAAK,kBACI,OAAO;6BAGE,GAAG;oCAUM,GAAG,KAAG,QAAQ,GAAG,CAAC;;iBAUR,eAAe;QAAK,QAAQ,GAAG,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;oJA4BvE,QAAQ,GAAG,CAAC;CA0BlB,CAAC"}
1
+ {"version":3,"file":"nativeSMASigner.d.ts","sourceRoot":"","sources":["../../../../../src/ma-v2/account/nativeSMASigner.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,cAAc,CAAC;AACvD,OAAO,EAGL,KAAK,GAAG,EACR,KAAK,eAAe,EAEpB,KAAK,mBAAmB,EACxB,KAAK,KAAK,EACV,KAAK,OAAO,EAEb,MAAM,MAAM,CAAC;AAQd;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,eAAO,MAAM,eAAe,WAClB,kBAAkB,SACnB,KAAK,kBACI,OAAO;6BAGE,GAAG;oCAUM,GAAG,KAAG,QAAQ,GAAG,CAAC;;iBAUR,eAAe;QAAK,QAAQ,GAAG,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;oJA4BvE,QAAQ,GAAG,CAAC;CA6BlB,CAAC"}
@@ -0,0 +1,64 @@
1
+ import { type UserOperationCallData, type BatchUserOperationCallData, type UserOperationRequest_v7 } from "@aa-sdk/core";
2
+ import { type Address, type Hex } from "viem";
3
+ import type { ModularAccountV2Client } from "../client/client.js";
4
+ export type DeferredActionTypedData = {
5
+ domain: {
6
+ chainId: number;
7
+ verifyingContract: Address;
8
+ };
9
+ types: {
10
+ DeferredAction: [
11
+ {
12
+ name: "nonce";
13
+ type: "uint256";
14
+ },
15
+ {
16
+ name: "deadline";
17
+ type: "uint48";
18
+ },
19
+ {
20
+ name: "call";
21
+ type: "bytes";
22
+ }
23
+ ];
24
+ };
25
+ primaryType: "DeferredAction";
26
+ message: {
27
+ nonce: bigint;
28
+ deadline: number;
29
+ call: Hex;
30
+ };
31
+ };
32
+ export type DeferredActionReturnData = {
33
+ typedData: DeferredActionTypedData;
34
+ nonceOverride: bigint;
35
+ };
36
+ export type CreateDeferredActionTypedDataParams = {
37
+ callData: Hex;
38
+ deadline: number;
39
+ entityId: number;
40
+ isGlobalValidation: boolean;
41
+ nonceKeyOverride?: bigint;
42
+ };
43
+ export type BuildDeferredActionDigestParams = {
44
+ typedData: DeferredActionTypedData;
45
+ sig: Hex;
46
+ };
47
+ export type BuildUserOperationWithDeferredActionParams = {
48
+ uo: UserOperationCallData | BatchUserOperationCallData;
49
+ signaturePrepend: Hex;
50
+ nonceOverride: bigint;
51
+ };
52
+ export type DeferralActions = {
53
+ createDeferredActionTypedDataObject: (args: CreateDeferredActionTypedDataParams) => Promise<DeferredActionReturnData>;
54
+ buildDeferredActionDigest: (args: BuildDeferredActionDigestParams) => Hex;
55
+ buildUserOperationWithDeferredAction: (args: BuildUserOperationWithDeferredActionParams) => Promise<UserOperationRequest_v7>;
56
+ };
57
+ /**
58
+ * Provides deferred action functionalities for a MA v2 client, ensuring compatibility with `SmartAccountClient`.
59
+ *
60
+ * @param {ModularAccountV2Client} client - The client instance which provides account and sendUserOperation functionality.
61
+ * @returns {object} - An object containing three methods: `createDeferredActionTypedDataObject`, `buildDeferredActionDigest`, and `buildUserOperationWithDeferredAction`.
62
+ */
63
+ export declare const deferralActions: (client: ModularAccountV2Client) => DeferralActions;
64
+ //# sourceMappingURL=DeferralActions.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"DeferralActions.d.ts","sourceRoot":"","sources":["../../../../../src/ma-v2/actions/DeferralActions.ts"],"names":[],"mappings":"AAAA,OAAO,EAIL,KAAK,qBAAqB,EAC1B,KAAK,0BAA0B,EAC/B,KAAK,uBAAuB,EAC7B,MAAM,cAAc,CAAC;AACtB,OAAO,EACL,KAAK,OAAO,EACZ,KAAK,GAAG,EAOT,MAAM,MAAM,CAAC;AACd,OAAO,KAAK,EAAE,sB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nC,IAAI,EAAE,mCAAmC,KACtC,OAAO,CAAC,wBAAwB,CAAC,CAAC;IACvC,yBAAyB,EAAE,CAAC,IAAI,EAAE,+BAA+B,KAAK,GAAG,CAAC;IAC1E,oCAAoC,EAAE,CACpC,IAAI,EAAE,0CAA0C,KAC7C,OAAO,CAAC,uBAAuB,CAAC,CAAC;CACvC,CAAC;AAEF;;;;;GAKG;AACH,eAAO,MAAM,eAAe,EAAE,CAC5B,MAAM,EAAE,sBAAsB,KAC3B,eAqJJ,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"signer.d.ts","sourceRoot":"","sources":["../../../../../../src/ma-v2/modules/single-signer-validation/signer.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,cAAc,CAAC;AACvD,OAAO,EAIL,KAAK,GAAG,EACR,KAAK,eAAe,EAEpB,KAAK,mBAAmB,EACxB,KAAK,KAAK,EACV,KAAK,OAAO,EACb,MAAM,MAAM,CAAC;AAId;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,eAAO,MAAM,yBAAyB,WAC5B,kBAAkB,SACnB,KAAK,kBACI,OAAO,YACb,MAAM;6BAGS,GAAG;oCAUM,GAAG,KAAG,QAAQ,GAAG,CAAC;;iBAUR,eAAe;QAAK,QAAQ,GAAG,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;oJA8BvE,QAAQ,GAAG,CAAC;CA8BlB,CAAC"}
1
+ {"version":3,"file":"signer.d.ts","sourceRoot":"","sources":["../../../../../../src/ma-v2/modules/single-signer-validation/signer.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,cAAc,CAAC;AACvD,OAAO,EAIL,KAAK,GAAG,EACR,KAAK,eAAe,EAEpB,KAAK,mBAAmB,EACxB,KAAK,KAAK,EACV,KAAK,OAAO,EAEb,MAAM,MAAM,CAAC;AAOd;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,eAAO,MAAM,yBAAyB,WAC5B,kBAAkB,SACnB,KAAK,kBACI,OAAO,YACb,MAAM;6BAGS,GAAG;oCAUM,GAAG,KAAG,QAAQ,GAAG,CAAC;;iBAUR,eAAe;QAAK,QAAQ,GAAG,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;oJA8BvE,QAAQ,GAAG,CAAC;CA+BlB,CAAC"}
@@ -1,4 +1,8 @@
1
1
  import type { Chain, Address } from "viem";
2
+ export declare enum SignatureType {
3
+ EOA = "0x00",
4
+ CONTRACT = "0x01"
5
+ }
2
6
  /**
3
7
  * Maps a given chain to a specific address of the webauthn validation module by its chain ID. If no direct mapping exists, it defaults to returning a specific address.
4
8
  *
@@ -1 +1 @@
1
- {"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../../../../src/ma-v2/modules/utils.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,EAAE,OAAO,EAAE,MAAM,MAAM,CAAC;AAc3C;;;;;;;;;;;;;GAaG;AACH,eAAO,MAAM,yCAAyC,UAC7C,KAAK,KACX,OAgBF,CAAC;AAEF;;;;;;;;;;;;;GAaG;AACH,eAAO,MAAM,gCAAgC,UAAW,KAAK,KAAG,OAgB/D,CAAC;AAEF;;;;;;;;;;;;;GAaG;AACH,eAAO,MAAM,6CAA6C,UACjD,KAAK,KACX,OAgBF,CAAC;AAEF;;;;;;;;;;;;;GAaG;AACH,eAAO,MAAM,qCAAqC,UACzC,KAAK,KACX,OAgBF,CAAC;AAEF;;;;;;;;;;;;;GAaG;AACH,eAAO,MAAM,uCAAuC,UAC3C,KAAK,KACX,OAgBF,CAAC;AAEF;;;;;;;;;;;;;GAaG;AACH,eAAO,MAAM,gCAAgC,UAAW,KAAK,KAAG,OAgB/D,CAAC"}
1
+ {"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../../../../src/ma-v2/modules/utils.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,EAAE,OAAO,EAAE,MAAM,MAAM,CAAC;AAc3C,oBAAY,aAAa;IACvB,GAAG,SAAS;IACZ,QAAQ,SAAS;CAClB;AAED;;;;;;;;;;;;;GAaG;AACH,eAAO,MAAM,yCAAyC,UAC7C,KAAK,KACX,OAgBF,CAAC;AAEF;;;;;;;;;;;;;GAaG;AACH,eAAO,MAAM,gCAAgC,UAAW,KAAK,KAAG,OAgB/D,CAAC;AAEF;;;;;;;;;;;;;GAaG;AACH,eAAO,MAAM,6CAA6C,UACjD,KAAK,KACX,OAgBF,CAAC;AAEF;;;;;;;;;;;;;GAaG;AACH,eAAO,MAAM,qCAAqC,UACzC,KAAK,KACX,OAgBF,CAAC;AAEF;;;;;;;;;;;;;GAaG;AACH,eAAO,MAAM,uCAAuC,UAC3C,KAAK,KACX,OAgBF,CAAC;AAEF;;;;;;;;;;;;;GAaG;AACH,eAAO,MAAM,gCAAgC,UAAW,KAAK,KAAG,OAgB/D,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@account-kit/smart-contracts",
3
- "version": "4.18.0-alpha.3",
3
+ "version": "4.18.0",
4
4
  "description": "aa-sdk compatible interfaces for Alchemy Smart Accounts",
5
5
  "author": "Alchemy",
6
6
  "license": "MIT",
@@ -52,7 +52,7 @@
52
52
  "test:run": "vitest run"
53
53
  },
54
54
  "devDependencies": {
55
- "@account-kit/plugingen": "^4.18.0-alpha.3",
55
+ "@account-kit/plugingen": "^4.18.0",
56
56
  "change-case": "^5.1.2",
57
57
  "dedent": "^1.5.1",
58
58
  "dotenv": "^16.3.1",
@@ -72,10 +72,10 @@
72
72
  "url": "https://github.com/alchemyplatform/aa-sdk/issues"
73
73
  },
74
74
  "homepage": "https://github.com/alchemyplatform/aa-sdk#readme",
75
- "gitHead": "3ab0862d913254d5f4208981cbcc5e3ed8d6708f",
75
+ "gitHead": "d69993e1d23ad074ad924e067db24d71c899a227",
76
76
  "dependencies": {
77
- "@aa-sdk/core": "^4.18.0-alpha.3",
78
- "@account-kit/infra": "^4.18.0-alpha.3"
77
+ "@aa-sdk/core": "^4.18.0",
78
+ "@account-kit/infra": "^4.18.0"
79
79
  },
80
80
  "peerDependencies": {
81
81
  "viem": "^2.22.6"
@@ -8,6 +8,7 @@ import {
8
8
  type TypedDataDefinition,
9
9
  type Chain,
10
10
  type Address,
11
+ concat,
11
12
  } from "viem";
12
13
 
13
14
  import {
@@ -15,6 +16,7 @@ import {
15
16
  pack1271Signature,
16
17
  DEFAULT_OWNER_ENTITY_ID,
17
18
  } from "../utils.js";
19
+ import { SignatureType } from "../modules/utils.js";
18
20
  /**
19
21
  * Creates an object with methods for generating a dummy signature, signing user operation hashes, signing messages, and signing typed data.
20
22
  *
@@ -99,7 +101,10 @@ export const nativeSMASigner = (
99
101
  typedDataDefinition?.domain?.verifyingContract === accountAddress;
100
102
 
101
103
  return isDeferredAction
102
- ? signer.signTypedData(typedDataDefinition)
104
+ ? concat([
105
+ SignatureType.EOA,
106
+ await signer.signTypedData(typedDataDefinition),
107
+ ])
103
108
  : pack1271Signature({
104
109
  validationSignature: await signer.signTypedData({
105
110
  domain: {
@@ -0,0 +1,232 @@
1
+ import {
2
+ AccountNotFoundError,
3
+ InvalidNonceKeyError,
4
+ EntryPointNotFoundError,
5
+ type UserOperationCallData,
6
+ type BatchUserOperationCallData,
7
+ type UserOperationRequest_v7,
8
+ } from "@aa-sdk/core";
9
+ import {
10
+ type Address,
11
+ type Hex,
12
+ concatHex,
13
+ maxUint152,
14
+ getContract,
15
+ encodePacked,
16
+ size,
17
+ toHex,
18
+ } from "viem";
19
+ import type { ModularAccountV2Client } from "../client/client.js";
20
+
21
+ export type DeferredActionTypedData = {
22
+ domain: {
23
+ chainId: number;
24
+ verifyingContract: Address;
25
+ };
26
+ types: {
27
+ DeferredAction: [
28
+ { name: "nonce"; type: "uint256" },
29
+ { name: "deadline"; type: "uint48" },
30
+ { name: "call"; type: "bytes" }
31
+ ];
32
+ };
33
+ primaryType: "DeferredAction";
34
+ message: {
35
+ nonce: bigint;
36
+ deadline: number;
37
+ call: Hex;
38
+ };
39
+ };
40
+
41
+ export type DeferredActionReturnData = {
42
+ typedData: DeferredActionTypedData;
43
+ nonceOverride: bigint;
44
+ };
45
+
46
+ export type CreateDeferredActionTypedDataParams = {
47
+ callData: Hex;
48
+ deadline: number;
49
+ entityId: number;
50
+ isGlobalValidation: boolean;
51
+ nonceKeyOverride?: bigint;
52
+ };
53
+
54
+ export type BuildDeferredActionDigestParams = {
55
+ typedData: DeferredActionTypedData;
56
+ sig: Hex;
57
+ };
58
+
59
+ export type BuildUserOperationWithDeferredActionParams = {
60
+ uo: UserOperationCallData | BatchUserOperationCallData;
61
+ signaturePrepend: Hex;
62
+ nonceOverride: bigint;
63
+ };
64
+
65
+ export type DeferralActions = {
66
+ createDeferredActionTypedDataObject: (
67
+ args: CreateDeferredActionTypedDataParams
68
+ ) => Promise<DeferredActionReturnData>;
69
+ buildDeferredActionDigest: (args: BuildDeferredActionDigestParams) => Hex;
70
+ buildUserOperationWithDeferredAction: (
71
+ args: BuildUserOperationWithDeferredActionParams
72
+ ) => Promise<UserOperationRequest_v7>;
73
+ };
74
+
75
+ /**
76
+ * Provides deferred action functionalities for a MA v2 client, ensuring compatibility with `SmartAccountClient`.
77
+ *
78
+ * @param {ModularAccountV2Client} client - The client instance which provides account and sendUserOperation functionality.
79
+ * @returns {object} - An object containing three methods: `createDeferredActionTypedDataObject`, `buildDeferredActionDigest`, and `buildUserOperationWithDeferredAction`.
80
+ */
81
+ export const deferralActions: (
82
+ client: ModularAccountV2Client
83
+ ) => DeferralActions = (client: ModularAccountV2Client): DeferralActions => {
84
+ const createDeferredActionTypedDataObject = async ({
85
+ callData,
86
+ deadline,
87
+ entityId,
88
+ isGlobalValidation,
89
+ nonceKeyOverride,
90
+ }: CreateDeferredActionTypedDataParams): Promise<DeferredActionReturnData> => {
91
+ if (!client.account) {
92
+ throw new AccountNotFoundError();
93
+ }
94
+
95
+ const baseNonceKey = nonceKeyOverride || 0n;
96
+ if (baseNonceKey > maxUint152) {
97
+ throw new InvalidNonceKeyError(baseNonceKey);
98
+ }
99
+
100
+ const entryPoint = client.account.getEntryPoint();
101
+ if (entryPoint === undefined) {
102
+ throw new EntryPointNotFoundError(client.chain, "0.7.0");
103
+ }
104
+
105
+ const entryPointContract = getContract({
106
+ address: entryPoint.address,
107
+ abi: entryPoint.abi,
108
+ client: client,
109
+ });
110
+
111
+ // 2 = deferred action flags 0b10
112
+ // 1 = isGlobal validation flag 0b01
113
+ const fullNonceKey: bigint =
114
+ ((baseNonceKey << 40n) + (BigInt(entityId) << 8n)) |
115
+ 2n |
116
+ (isGlobalValidation ? 1n : 0n);
117
+
118
+ const nonceOverride = (await entryPointContract.read.getNonce([
119
+ client.account.address,
120
+ fullNonceKey,
121
+ ])) as bigint;
122
+
123
+ return {
124
+ typedData: {
125
+ domain: {
126
+ chainId: await client.getChainId(),
127
+ verifyingContract: client.account.address,
128
+ },
129
+ types: {
130
+ DeferredAction: [
131
+ { name: "nonce", type: "uint256" },
132
+ { name: "deadline", type: "uint48" },
133
+ { name: "call", type: "bytes" },
134
+ ],
135
+ },
136
+ primaryType: "DeferredAction",
137
+ message: {
138
+ nonce: nonceOverride,
139
+ deadline: deadline,
140
+ call: callData,
141
+ },
142
+ },
143
+ nonceOverride: nonceOverride,
144
+ };
145
+ };
146
+
147
+ /**
148
+ * Creates the digest which must be prepended to the userOp signature.
149
+ *
150
+ * Assumption: The client this extends is used to sign the typed data.
151
+ *
152
+ * @param {object} args The argument object containing the following:
153
+ * @param {DeferredActionTypedData} args.typedData The typed data object for the deferred action
154
+ * @param {Hex} args.sig The signature to include in the digest
155
+ * @returns {Hex} The encoded digest to be prepended to the userOp signature
156
+ */
157
+ const buildDeferredActionDigest = ({
158
+ typedData,
159
+ sig,
160
+ }: BuildDeferredActionDigestParams): Hex => {
161
+ const signerEntity = client.account.signerEntity;
162
+ const validationLocator =
163
+ (BigInt(signerEntity.entityId) << 8n) |
164
+ (signerEntity.isGlobalValidation ? 1n : 0n);
165
+
166
+ let encodedData = encodePacked(
167
+ ["uint168", "uint48", "bytes"],
168
+ [validationLocator, typedData.message.deadline, typedData.message.call]
169
+ );
170
+
171
+ const encodedDataLength = size(encodedData);
172
+ const sigLength = size(sig);
173
+
174
+ encodedData = concatHex([
175
+ toHex(encodedDataLength, { size: 4 }),
176
+ encodedData,
177
+ toHex(sigLength, { size: 4 }),
178
+ sig,
179
+ ]);
180
+
181
+ return encodedData;
182
+ };
183
+
184
+ /**
185
+ * Builds a user operation with a deferred action by wrapping buildUserOperation() with a dummy signature override.
186
+ *
187
+ * @param {object} args The argument object containing the following:
188
+ * @param {UserOperationCallData | BatchUserOperationCallData} args.uo The user operation call data to build
189
+ * @param {Hex} args.signaturePrepend The signature data to prepend to the dummy signature
190
+ * @param {bigint} args.nonceOverride The nonce to override in the user operation, generally given from the typed data builder
191
+ * @returns {Promise<UserOperationRequest_v7>} The unsigned user operation request with the deferred action
192
+ */
193
+ const buildUserOperationWithDeferredAction = async ({
194
+ uo,
195
+ signaturePrepend,
196
+ nonceOverride,
197
+ }: BuildUserOperationWithDeferredActionParams): Promise<UserOperationRequest_v7> => {
198
+ // Check if client.account is defined
199
+ if (client.account === undefined) {
200
+ throw new AccountNotFoundError();
201
+ }
202
+
203
+ // Pre-fetch the dummy sig so we can override `client.account.getDummySignature()`
204
+ const dummySig = await client.account.getDummySignature();
205
+
206
+ // Cache the previous dummy signature getter
207
+ const previousDummySigGetter = client.account.getDummySignature;
208
+
209
+ // Override client.account.getDummySignature() so `client.buildUserOperation()` uses the prepended hex and the dummy signature during gas estimation
210
+ client.account.getDummySignature = () => {
211
+ return concatHex([signaturePrepend, dummySig as Hex]);
212
+ };
213
+
214
+ const unsignedUo = (await client.buildUserOperation({
215
+ uo: uo,
216
+ overrides: {
217
+ nonce: nonceOverride,
218
+ },
219
+ })) as UserOperationRequest_v7;
220
+
221
+ // Restore the dummy signature getter
222
+ client.account.getDummySignature = previousDummySigGetter;
223
+
224
+ return unsignedUo;
225
+ };
226
+
227
+ return {
228
+ createDeferredActionTypedDataObject,
229
+ buildDeferredActionDigest,
230
+ buildUserOperationWithDeferredAction,
231
+ };
232
+ };
@@ -9,8 +9,12 @@ import {
9
9
  type TypedDataDefinition,
10
10
  type Chain,
11
11
  type Address,
12
+ concat,
12
13
  } from "viem";
13
- import { getDefaultSingleSignerValidationModuleAddress } from "../utils.js";
14
+ import {
15
+ getDefaultSingleSignerValidationModuleAddress,
16
+ SignatureType,
17
+ } from "../utils.js";
14
18
 
15
19
  import { packUOSignature, pack1271Signature } from "../../utils.js";
16
20
  /**
@@ -111,13 +115,14 @@ export const singleSignerMessageSigner = (
111
115
  ReplaySafeHash: [{ name: "hash", type: "bytes32" }],
112
116
  },
113
117
  message: {
114
- hash: await hashTypedData(typedDataDefinition),
118
+ hash: hashTypedData(typedDataDefinition),
115
119
  },
116
120
  primaryType: "ReplaySafeHash",
117
121
  });
118
122
 
123
+ // TODO: Handle non-EOA signer case
119
124
  return isDeferredAction
120
- ? validationSignature
125
+ ? concat([SignatureType.EOA, validationSignature])
121
126
  : pack1271Signature({
122
127
  validationSignature,
123
128
  entityId,
@@ -12,6 +12,11 @@ import {
12
12
  sepolia,
13
13
  } from "@account-kit/infra";
14
14
 
15
+ export enum SignatureType {
16
+ EOA = "0x00",
17
+ CONTRACT = "0x01",
18
+ }
19
+
15
20
  /**
16
21
  * Maps a given chain to a specific address of the webauthn validation module by its chain ID. If no direct mapping exists, it defaults to returning a specific address.
17
22
  *