@account-kit/smart-contracts 4.7.0 → 4.8.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/abis/accountFactoryAbi.d.ts +492 -0
- package/dist/esm/src/ma-v2/abis/accountFactoryAbi.js +639 -0
- package/dist/esm/src/ma-v2/abis/accountFactoryAbi.js.map +1 -0
- package/dist/esm/src/ma-v2/abis/modularAccountAbi.d.ts +954 -0
- package/dist/esm/src/ma-v2/abis/modularAccountAbi.js +1242 -0
- package/dist/esm/src/ma-v2/abis/modularAccountAbi.js.map +1 -0
- package/dist/esm/src/ma-v2/abis/semiModularAccountBytecodeAbi.d.ts +991 -0
- package/dist/esm/src/ma-v2/abis/semiModularAccountBytecodeAbi.js +1289 -0
- package/dist/esm/src/ma-v2/abis/semiModularAccountBytecodeAbi.js.map +1 -0
- package/dist/esm/src/ma-v2/abis/semiModularAccountStorageAbi.d.ts +1001 -0
- package/dist/esm/src/ma-v2/abis/semiModularAccountStorageAbi.js +1302 -0
- package/dist/esm/src/ma-v2/abis/semiModularAccountStorageAbi.js.map +1 -0
- package/dist/esm/src/ma-v2/account/nativeSMASigner.d.ts +238 -0
- package/dist/esm/src/ma-v2/account/nativeSMASigner.js +88 -0
- package/dist/esm/src/ma-v2/account/nativeSMASigner.js.map +1 -0
- package/dist/esm/src/ma-v2/account/semiModularAccountV2.d.ts +41 -0
- package/dist/esm/src/ma-v2/account/semiModularAccountV2.js +148 -0
- package/dist/esm/src/ma-v2/account/semiModularAccountV2.js.map +1 -0
- package/dist/esm/src/ma-v2/actions/common/types.d.ts +31 -0
- package/dist/esm/src/ma-v2/actions/common/types.js +6 -0
- package/dist/esm/src/ma-v2/actions/common/types.js.map +1 -0
- package/dist/esm/src/ma-v2/actions/common/utils.d.ts +76 -0
- package/dist/esm/src/ma-v2/actions/common/utils.js +100 -0
- package/dist/esm/src/ma-v2/actions/common/utils.js.map +1 -0
- package/dist/esm/src/ma-v2/actions/install-validation/installValidation.d.ts +71 -0
- package/dist/esm/src/ma-v2/actions/install-validation/installValidation.js +109 -0
- package/dist/esm/src/ma-v2/actions/install-validation/installValidation.js.map +1 -0
- package/dist/esm/src/ma-v2/client/client.d.ts +6 -0
- package/dist/esm/src/ma-v2/client/client.js +40 -0
- package/dist/esm/src/ma-v2/client/client.js.map +1 -0
- package/dist/esm/src/ma-v2/index.d.ts +26 -0
- package/dist/esm/src/ma-v2/index.js +24 -0
- package/dist/esm/src/ma-v2/index.js.map +1 -0
- package/dist/esm/src/ma-v2/modules/allowlist-module/abis/allowlistModuleAbi.d.ts +556 -0
- package/dist/esm/src/ma-v2/modules/allowlist-module/abis/allowlistModuleAbi.js +716 -0
- package/dist/esm/src/ma-v2/modules/allowlist-module/abis/allowlistModuleAbi.js.map +1 -0
- package/dist/esm/src/ma-v2/modules/allowlist-module/module.d.ts +579 -0
- package/dist/esm/src/ma-v2/modules/allowlist-module/module.js +56 -0
- package/dist/esm/src/ma-v2/modules/allowlist-module/module.js.map +1 -0
- package/dist/esm/src/ma-v2/modules/native-token-limit-module/abis/nativeTokenLimitModuleAbi.d.ts +312 -0
- package/dist/esm/src/ma-v2/modules/native-token-limit-module/abis/nativeTokenLimitModuleAbi.js +404 -0
- package/dist/esm/src/ma-v2/modules/native-token-limit-module/abis/nativeTokenLimitModuleAbi.js.map +1 -0
- package/dist/esm/src/ma-v2/modules/native-token-limit-module/module.d.ts +322 -0
- package/dist/esm/src/ma-v2/modules/native-token-limit-module/module.js +14 -0
- package/dist/esm/src/ma-v2/modules/native-token-limit-module/module.js.map +1 -0
- package/dist/esm/src/ma-v2/modules/paymaster-guard-module/abis/paymasterGuardModuleAbi.d.ts +186 -0
- package/dist/esm/src/ma-v2/modules/paymaster-guard-module/abis/paymasterGuardModuleAbi.js +242 -0
- package/dist/esm/src/ma-v2/modules/paymaster-guard-module/abis/paymasterGuardModuleAbi.js.map +1 -0
- package/dist/esm/src/ma-v2/modules/paymaster-guard-module/module.d.ts +196 -0
- package/dist/esm/src/ma-v2/modules/paymaster-guard-module/module.js +25 -0
- package/dist/esm/src/ma-v2/modules/paymaster-guard-module/module.js.map +1 -0
- package/dist/esm/src/ma-v2/modules/single-signer-validation/abis/singleSignerValidationModuleAbi.d.ts +45 -0
- package/dist/esm/src/ma-v2/modules/single-signer-validation/abis/singleSignerValidationModuleAbi.js +331 -0
- package/dist/esm/src/ma-v2/modules/single-signer-validation/abis/singleSignerValidationModuleAbi.js.map +1 -0
- package/dist/esm/src/ma-v2/modules/single-signer-validation/module.d.ts +10 -0
- package/dist/esm/src/ma-v2/modules/single-signer-validation/module.js +16 -0
- package/dist/esm/src/ma-v2/modules/single-signer-validation/module.js.map +1 -0
- package/dist/esm/src/ma-v2/modules/single-signer-validation/signer.d.ts +239 -0
- package/dist/esm/src/ma-v2/modules/single-signer-validation/signer.js +93 -0
- package/dist/esm/src/ma-v2/modules/single-signer-validation/signer.js.map +1 -0
- package/dist/esm/src/ma-v2/modules/time-range-module/abis/timeRangeModuleAbi.d.ts +229 -0
- package/dist/esm/src/ma-v2/modules/time-range-module/abis/timeRangeModuleAbi.js +296 -0
- package/dist/esm/src/ma-v2/modules/time-range-module/abis/timeRangeModuleAbi.js.map +1 -0
- package/dist/esm/src/ma-v2/modules/time-range-module/module.d.ts +245 -0
- package/dist/esm/src/ma-v2/modules/time-range-module/module.js +42 -0
- package/dist/esm/src/ma-v2/modules/time-range-module/module.js.map +1 -0
- package/dist/esm/src/ma-v2/modules/utils.d.ts +91 -0
- package/dist/esm/src/ma-v2/modules/utils.js +188 -0
- package/dist/esm/src/ma-v2/modules/utils.js.map +1 -0
- package/dist/esm/src/ma-v2/modules/webauthn-validation/abis/webauthnValidationAbi.d.ts +287 -0
- package/dist/esm/src/ma-v2/modules/webauthn-validation/abis/webauthnValidationAbi.js +374 -0
- package/dist/esm/src/ma-v2/modules/webauthn-validation/abis/webauthnValidationAbi.js.map +1 -0
- package/dist/esm/src/ma-v2/utils.d.ts +16 -0
- package/dist/esm/src/ma-v2/utils.js +105 -0
- package/dist/esm/src/ma-v2/utils.js.map +1 -0
- package/dist/types/src/ma-v2/abis/accountFactoryAbi.d.ts +493 -0
- package/dist/types/src/ma-v2/abis/accountFactoryAbi.d.ts.map +1 -0
- package/dist/types/src/ma-v2/abis/modularAccountAbi.d.ts +955 -0
- package/dist/types/src/ma-v2/abis/modularAccountAbi.d.ts.map +1 -0
- package/dist/types/src/ma-v2/abis/semiModularAccountBytecodeAbi.d.ts +992 -0
- package/dist/types/src/ma-v2/abis/semiModularAccountBytecodeAbi.d.ts.map +1 -0
- package/dist/types/src/ma-v2/abis/semiModularAccountStorageAbi.d.ts +1002 -0
- package/dist/types/src/ma-v2/abis/semiModularAccountStorageAbi.d.ts.map +1 -0
- package/dist/types/src/ma-v2/account/nativeSMASigner.d.ts +239 -0
- package/dist/types/src/ma-v2/account/nativeSMASigner.d.ts.map +1 -0
- package/dist/types/src/ma-v2/account/semiModularAccountV2.d.ts +42 -0
- package/dist/types/src/ma-v2/account/semiModularAccountV2.d.ts.map +1 -0
- package/dist/types/src/ma-v2/actions/common/types.d.ts +32 -0
- package/dist/types/src/ma-v2/actions/common/types.d.ts.map +1 -0
- package/dist/types/src/ma-v2/actions/common/utils.d.ts +77 -0
- package/dist/types/src/ma-v2/actions/common/utils.d.ts.map +1 -0
- package/dist/types/src/ma-v2/actions/install-validation/installValidation.d.ts +72 -0
- package/dist/types/src/ma-v2/actions/install-validation/installValidation.d.ts.map +1 -0
- package/dist/types/src/ma-v2/client/client.d.ts +7 -0
- package/dist/types/src/ma-v2/client/client.d.ts.map +1 -0
- package/dist/types/src/ma-v2/index.d.ts +27 -0
- package/dist/types/src/ma-v2/index.d.ts.map +1 -0
- package/dist/types/src/ma-v2/modules/allowlist-module/abis/allowlistModuleAbi.d.ts +557 -0
- package/dist/types/src/ma-v2/modules/allowlist-module/abis/allowlistModuleAbi.d.ts.map +1 -0
- package/dist/types/src/ma-v2/modules/allowlist-module/module.d.ts +580 -0
- package/dist/types/src/ma-v2/modules/allowlist-module/module.d.ts.map +1 -0
- package/dist/types/src/ma-v2/modules/native-token-limit-module/abis/nativeTokenLimitModuleAbi.d.ts +313 -0
- package/dist/types/src/ma-v2/modules/native-token-limit-module/abis/nativeTokenLimitModuleAbi.d.ts.map +1 -0
- package/dist/types/src/ma-v2/modules/native-token-limit-module/module.d.ts +323 -0
- package/dist/types/src/ma-v2/modules/native-token-limit-module/module.d.ts.map +1 -0
- package/dist/types/src/ma-v2/modules/paymaster-guard-module/abis/paymasterGuardModuleAbi.d.ts +187 -0
- package/dist/types/src/ma-v2/modules/paymaster-guard-module/abis/paymasterGuardModuleAbi.d.ts.map +1 -0
- package/dist/types/src/ma-v2/modules/paymaster-guard-module/module.d.ts +197 -0
- package/dist/types/src/ma-v2/modules/paymaster-guard-module/module.d.ts.map +1 -0
- package/dist/types/src/ma-v2/modules/single-signer-validation/abis/singleSignerValidationModuleAbi.d.ts +46 -0
- package/dist/types/src/ma-v2/modules/single-signer-validation/abis/singleSignerValidationModuleAbi.d.ts.map +1 -0
- package/dist/types/src/ma-v2/modules/single-signer-validation/module.d.ts +11 -0
- package/dist/types/src/ma-v2/modules/single-signer-validation/module.d.ts.map +1 -0
- package/dist/types/src/ma-v2/modules/single-signer-validation/signer.d.ts +240 -0
- package/dist/types/src/ma-v2/modules/single-signer-validation/signer.d.ts.map +1 -0
- package/dist/types/src/ma-v2/modules/time-range-module/abis/timeRangeModuleAbi.d.ts +230 -0
- package/dist/types/src/ma-v2/modules/time-range-module/abis/timeRangeModuleAbi.d.ts.map +1 -0
- package/dist/types/src/ma-v2/modules/time-range-module/module.d.ts +246 -0
- package/dist/types/src/ma-v2/modules/time-range-module/module.d.ts.map +1 -0
- package/dist/types/src/ma-v2/modules/utils.d.ts +92 -0
- package/dist/types/src/ma-v2/modules/utils.d.ts.map +1 -0
- package/dist/types/src/ma-v2/modules/webauthn-validation/abis/webauthnValidationAbi.d.ts +288 -0
- package/dist/types/src/ma-v2/modules/webauthn-validation/abis/webauthnValidationAbi.d.ts.map +1 -0
- package/dist/types/src/ma-v2/utils.d.ts +17 -0
- package/dist/types/src/ma-v2/utils.d.ts.map +1 -0
- package/package.json +10 -5
- package/src/ma-v2/abis/accountFactoryAbi.ts +638 -0
- package/src/ma-v2/abis/modularAccountAbi.ts +1241 -0
- package/src/ma-v2/abis/semiModularAccountBytecodeAbi.ts +1288 -0
- package/src/ma-v2/abis/semiModularAccountStorageAbi.ts +1301 -0
- package/src/ma-v2/account/nativeSMASigner.ts +121 -0
- package/src/ma-v2/account/semiModularAccountV2.ts +289 -0
- package/src/ma-v2/actions/common/types.ts +37 -0
- package/src/ma-v2/actions/common/utils.ts +103 -0
- package/src/ma-v2/actions/install-validation/installValidation.ts +213 -0
- package/src/ma-v2/client/client.ts +74 -0
- package/src/ma-v2/index.ts +47 -0
- package/src/ma-v2/modules/allowlist-module/abis/allowlistModuleAbi.ts +715 -0
- package/src/ma-v2/modules/allowlist-module/module.ts +87 -0
- package/src/ma-v2/modules/native-token-limit-module/abis/nativeTokenLimitModuleAbi.ts +403 -0
- package/src/ma-v2/modules/native-token-limit-module/module.ts +21 -0
- package/src/ma-v2/modules/paymaster-guard-module/abis/paymasterGuardModuleAbi.ts +241 -0
- package/src/ma-v2/modules/paymaster-guard-module/module.ts +35 -0
- package/src/ma-v2/modules/single-signer-validation/abis/singleSignerValidationModuleAbi.ts +330 -0
- package/src/ma-v2/modules/single-signer-validation/module.ts +24 -0
- package/src/ma-v2/modules/single-signer-validation/signer.ts +127 -0
- package/src/ma-v2/modules/time-range-module/abis/timeRangeModuleAbi.ts +295 -0
- package/src/ma-v2/modules/time-range-module/module.ts +63 -0
- package/src/ma-v2/modules/utils.ts +213 -0
- package/src/ma-v2/modules/webauthn-validation/abis/webauthnValidationAbi.ts +373 -0
- package/src/ma-v2/utils.ts +138 -0
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
import type { SmartAccountSigner } from "@aa-sdk/core";
|
|
2
|
+
import {
|
|
3
|
+
hashMessage,
|
|
4
|
+
hashTypedData,
|
|
5
|
+
type Hex,
|
|
6
|
+
type SignableMessage,
|
|
7
|
+
type TypedData,
|
|
8
|
+
type TypedDataDefinition,
|
|
9
|
+
type Chain,
|
|
10
|
+
type Address,
|
|
11
|
+
} from "viem";
|
|
12
|
+
|
|
13
|
+
import {
|
|
14
|
+
packUOSignature,
|
|
15
|
+
pack1271Signature,
|
|
16
|
+
DEFAULT_OWNER_ENTITY_ID,
|
|
17
|
+
} from "../utils.js";
|
|
18
|
+
/**
|
|
19
|
+
* Creates an object with methods for generating a dummy signature, signing user operation hashes, signing messages, and signing typed data.
|
|
20
|
+
*
|
|
21
|
+
* @example
|
|
22
|
+
* ```ts
|
|
23
|
+
* import { nativeSMASigner } from "@account-kit/smart-contracts";
|
|
24
|
+
|
|
25
|
+
* import { LocalAccountSigner } from "@aa-sdk/core";
|
|
26
|
+
*
|
|
27
|
+
* const MNEMONIC = "...":
|
|
28
|
+
*
|
|
29
|
+
* const account = createSMAV2Account({ config });
|
|
30
|
+
*
|
|
31
|
+
* const signer = LocalAccountSigner.mnemonicToAccountSigner(MNEMONIC);
|
|
32
|
+
*
|
|
33
|
+
* const messageSigner = nativeSMASigner(signer, chain, account.address);
|
|
34
|
+
* ```
|
|
35
|
+
*
|
|
36
|
+
* @param {SmartAccountSigner} signer Signer to use for signing operations
|
|
37
|
+
* @param {Chain} chain Chain object for the signer
|
|
38
|
+
* @param {Address} accountAddress address of the smart account using this signer
|
|
39
|
+
* @returns {object} an object with methods for signing operations and managing signatures
|
|
40
|
+
*/
|
|
41
|
+
export const nativeSMASigner = (
|
|
42
|
+
signer: SmartAccountSigner,
|
|
43
|
+
chain: Chain,
|
|
44
|
+
accountAddress: Address
|
|
45
|
+
) => {
|
|
46
|
+
return {
|
|
47
|
+
getDummySignature: (): Hex => {
|
|
48
|
+
const dummyEcdsaSignature =
|
|
49
|
+
"0xfffffffffffffffffffffffffffffff0000000000000000000000000000000007aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa1c";
|
|
50
|
+
|
|
51
|
+
return packUOSignature({
|
|
52
|
+
// orderedHookData: [],
|
|
53
|
+
validationSignature: dummyEcdsaSignature,
|
|
54
|
+
});
|
|
55
|
+
},
|
|
56
|
+
|
|
57
|
+
signUserOperationHash: (uoHash: Hex): Promise<Hex> => {
|
|
58
|
+
return signer.signMessage({ raw: uoHash }).then((signature: Hex) =>
|
|
59
|
+
packUOSignature({
|
|
60
|
+
// orderedHookData: [],
|
|
61
|
+
validationSignature: signature,
|
|
62
|
+
})
|
|
63
|
+
);
|
|
64
|
+
},
|
|
65
|
+
|
|
66
|
+
// we apply the expected 1271 packing here since the account contract will expect it
|
|
67
|
+
async signMessage({ message }: { message: SignableMessage }): Promise<Hex> {
|
|
68
|
+
const hash = hashMessage(message);
|
|
69
|
+
|
|
70
|
+
return pack1271Signature({
|
|
71
|
+
validationSignature: await signer.signTypedData({
|
|
72
|
+
domain: {
|
|
73
|
+
chainId: Number(chain.id),
|
|
74
|
+
verifyingContract: accountAddress,
|
|
75
|
+
},
|
|
76
|
+
types: {
|
|
77
|
+
ReplaySafeHash: [{ name: "hash", type: "bytes32" }],
|
|
78
|
+
},
|
|
79
|
+
message: {
|
|
80
|
+
hash,
|
|
81
|
+
},
|
|
82
|
+
primaryType: "ReplaySafeHash",
|
|
83
|
+
}),
|
|
84
|
+
entityId: DEFAULT_OWNER_ENTITY_ID,
|
|
85
|
+
});
|
|
86
|
+
},
|
|
87
|
+
|
|
88
|
+
// TODO: maybe move "sign deferred actions" to a separate function?
|
|
89
|
+
// we don't apply the expected 1271 packing since deferred sigs use typed data sigs and don't expect the 1271 packing
|
|
90
|
+
signTypedData: async <
|
|
91
|
+
const typedData extends TypedData | Record<string, unknown>,
|
|
92
|
+
primaryType extends keyof typedData | "EIP712Domain" = keyof typedData
|
|
93
|
+
>(
|
|
94
|
+
typedDataDefinition: TypedDataDefinition<typedData, primaryType>
|
|
95
|
+
): Promise<Hex> => {
|
|
96
|
+
// the accounts domain already gives replay protection across accounts for deferred actions, so we don't need to apply another wrapping
|
|
97
|
+
const isDeferredAction =
|
|
98
|
+
typedDataDefinition?.primaryType === "DeferredAction" &&
|
|
99
|
+
typedDataDefinition?.domain?.verifyingContract === accountAddress;
|
|
100
|
+
|
|
101
|
+
return isDeferredAction
|
|
102
|
+
? signer.signTypedData(typedDataDefinition)
|
|
103
|
+
: pack1271Signature({
|
|
104
|
+
validationSignature: await signer.signTypedData({
|
|
105
|
+
domain: {
|
|
106
|
+
chainId: Number(chain.id),
|
|
107
|
+
verifyingContract: accountAddress,
|
|
108
|
+
},
|
|
109
|
+
types: {
|
|
110
|
+
ReplaySafeHash: [{ name: "hash", type: "bytes32" }],
|
|
111
|
+
},
|
|
112
|
+
message: {
|
|
113
|
+
hash: await hashTypedData(typedDataDefinition),
|
|
114
|
+
},
|
|
115
|
+
primaryType: "ReplaySafeHash",
|
|
116
|
+
}),
|
|
117
|
+
entityId: DEFAULT_OWNER_ENTITY_ID,
|
|
118
|
+
});
|
|
119
|
+
},
|
|
120
|
+
};
|
|
121
|
+
};
|
|
@@ -0,0 +1,289 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
EntryPointDef,
|
|
3
|
+
SmartAccountSigner,
|
|
4
|
+
AccountOp,
|
|
5
|
+
SmartContractAccountWithSigner,
|
|
6
|
+
ToSmartContractAccountParams,
|
|
7
|
+
} from "@aa-sdk/core";
|
|
8
|
+
import {
|
|
9
|
+
createBundlerClient,
|
|
10
|
+
getEntryPoint,
|
|
11
|
+
toSmartContractAccount,
|
|
12
|
+
InvalidEntityIdError,
|
|
13
|
+
InvalidNonceKeyError,
|
|
14
|
+
getAccountAddress,
|
|
15
|
+
} from "@aa-sdk/core";
|
|
16
|
+
import {
|
|
17
|
+
concatHex,
|
|
18
|
+
encodeFunctionData,
|
|
19
|
+
getContract,
|
|
20
|
+
maxUint32,
|
|
21
|
+
maxUint152,
|
|
22
|
+
zeroAddress,
|
|
23
|
+
type Address,
|
|
24
|
+
type Chain,
|
|
25
|
+
type Hex,
|
|
26
|
+
type Transport,
|
|
27
|
+
} from "viem";
|
|
28
|
+
import { accountFactoryAbi } from "../abis/accountFactoryAbi.js";
|
|
29
|
+
import {
|
|
30
|
+
getDefaultMAV2FactoryAddress,
|
|
31
|
+
DEFAULT_OWNER_ENTITY_ID,
|
|
32
|
+
} from "../utils.js";
|
|
33
|
+
import { singleSignerMessageSigner } from "../modules/single-signer-validation/signer.js";
|
|
34
|
+
import { nativeSMASigner } from "./nativeSMASigner.js";
|
|
35
|
+
import { modularAccountAbi } from "../abis/modularAccountAbi.js";
|
|
36
|
+
import { serializeModuleEntity } from "../actions/common/utils.js";
|
|
37
|
+
|
|
38
|
+
const executeUserOpSelector: Hex = "0x8DD7712F";
|
|
39
|
+
|
|
40
|
+
export type SignerEntity = {
|
|
41
|
+
isGlobalValidation: boolean;
|
|
42
|
+
entityId: number;
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
export type ExecutionDataView = {
|
|
46
|
+
module: Address;
|
|
47
|
+
skipRuntimeValidation: boolean;
|
|
48
|
+
allowGlobalValidation: boolean;
|
|
49
|
+
executionHooks: readonly Hex[];
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
export type ValidationDataView = {
|
|
53
|
+
validationHooks: readonly Hex[];
|
|
54
|
+
executionHooks: readonly Hex[];
|
|
55
|
+
selectors: readonly Hex[];
|
|
56
|
+
validationFlags: number;
|
|
57
|
+
};
|
|
58
|
+
|
|
59
|
+
export type ValidationDataParams =
|
|
60
|
+
| {
|
|
61
|
+
validationModuleAddress: Address;
|
|
62
|
+
entityId?: never;
|
|
63
|
+
}
|
|
64
|
+
| {
|
|
65
|
+
validationModuleAddress?: never;
|
|
66
|
+
entityId: number;
|
|
67
|
+
};
|
|
68
|
+
|
|
69
|
+
export type MAV2Account<
|
|
70
|
+
TSigner extends SmartAccountSigner = SmartAccountSigner
|
|
71
|
+
> = SmartContractAccountWithSigner<"MAV2Account", TSigner, "0.7.0"> & {
|
|
72
|
+
signerEntity: SignerEntity;
|
|
73
|
+
getExecutionData: (selector: Hex) => Promise<ExecutionDataView>;
|
|
74
|
+
getValidationData: (
|
|
75
|
+
args: ValidationDataParams
|
|
76
|
+
) => Promise<ValidationDataView>;
|
|
77
|
+
encodeCallData: (callData: Hex) => Promise<Hex>;
|
|
78
|
+
};
|
|
79
|
+
|
|
80
|
+
export type CreateSMAV2AccountParams<
|
|
81
|
+
TTransport extends Transport = Transport,
|
|
82
|
+
TSigner extends SmartAccountSigner = SmartAccountSigner
|
|
83
|
+
> = Pick<
|
|
84
|
+
ToSmartContractAccountParams<"MAV2Account", TTransport, Chain, "0.7.0">,
|
|
85
|
+
"transport" | "chain" | "accountAddress"
|
|
86
|
+
> & {
|
|
87
|
+
signer: TSigner;
|
|
88
|
+
salt?: bigint;
|
|
89
|
+
factoryAddress?: Address;
|
|
90
|
+
initCode?: Hex;
|
|
91
|
+
initialOwner?: Address;
|
|
92
|
+
entryPoint?: EntryPointDef<"0.7.0", Chain>;
|
|
93
|
+
signerEntity?: SignerEntity;
|
|
94
|
+
};
|
|
95
|
+
|
|
96
|
+
export async function createSMAV2Account<
|
|
97
|
+
TTransport extends Transport = Transport,
|
|
98
|
+
TSigner extends SmartAccountSigner = SmartAccountSigner
|
|
99
|
+
>(
|
|
100
|
+
config: CreateSMAV2AccountParams<TTransport, TSigner>
|
|
101
|
+
): Promise<MAV2Account<TSigner>>;
|
|
102
|
+
|
|
103
|
+
/**
|
|
104
|
+
* Creates an SMAV2 account using defined parameters including chain, signer, salt, factory address, and more.
|
|
105
|
+
* Handles account initialization code, nonce generation, transaction encoding, and more to construct a modular account with optional validation hooks.
|
|
106
|
+
*
|
|
107
|
+
* @param {CreateSMAV2AccountParams} config Configuration parameters for creating an SMAV2 account. Includes chain details, signer, salt, factory address, and more.
|
|
108
|
+
* @returns {Promise<MAV2Account>} A promise that resolves to an `MAV2Account` providing methods for nonce retrieval, transaction execution, and more.
|
|
109
|
+
*/
|
|
110
|
+
export async function createSMAV2Account(
|
|
111
|
+
config: CreateSMAV2AccountParams
|
|
112
|
+
): Promise<MAV2Account> {
|
|
113
|
+
const {
|
|
114
|
+
transport,
|
|
115
|
+
chain,
|
|
116
|
+
signer,
|
|
117
|
+
salt = 0n,
|
|
118
|
+
factoryAddress = getDefaultMAV2FactoryAddress(chain),
|
|
119
|
+
initCode,
|
|
120
|
+
initialOwner,
|
|
121
|
+
accountAddress,
|
|
122
|
+
entryPoint = getEntryPoint(chain, { version: "0.7.0" }),
|
|
123
|
+
signerEntity = {
|
|
124
|
+
isGlobalValidation: true,
|
|
125
|
+
entityId: DEFAULT_OWNER_ENTITY_ID,
|
|
126
|
+
},
|
|
127
|
+
signerEntity: {
|
|
128
|
+
isGlobalValidation = true,
|
|
129
|
+
entityId = DEFAULT_OWNER_ENTITY_ID,
|
|
130
|
+
} = {},
|
|
131
|
+
} = config;
|
|
132
|
+
|
|
133
|
+
if (entityId > Number(maxUint32)) {
|
|
134
|
+
throw new InvalidEntityIdError(entityId);
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
const client = createBundlerClient({
|
|
138
|
+
transport,
|
|
139
|
+
chain,
|
|
140
|
+
});
|
|
141
|
+
|
|
142
|
+
const getAccountInitCode = async () => {
|
|
143
|
+
if (initCode) {
|
|
144
|
+
return initCode;
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
// If an initial owner is not provided, use the signer's address
|
|
148
|
+
const ownerAddress = initialOwner ?? (await signer.getAddress());
|
|
149
|
+
|
|
150
|
+
return concatHex([
|
|
151
|
+
factoryAddress,
|
|
152
|
+
encodeFunctionData({
|
|
153
|
+
abi: accountFactoryAbi,
|
|
154
|
+
functionName: "createSemiModularAccount",
|
|
155
|
+
args: [ownerAddress, salt],
|
|
156
|
+
}),
|
|
157
|
+
]);
|
|
158
|
+
};
|
|
159
|
+
|
|
160
|
+
const encodeExecute: (tx: AccountOp) => Promise<Hex> = async ({
|
|
161
|
+
target,
|
|
162
|
+
data,
|
|
163
|
+
value,
|
|
164
|
+
}) =>
|
|
165
|
+
await encodeCallData(
|
|
166
|
+
encodeFunctionData({
|
|
167
|
+
abi: modularAccountAbi,
|
|
168
|
+
functionName: "execute",
|
|
169
|
+
args: [target, value ?? 0n, data],
|
|
170
|
+
})
|
|
171
|
+
);
|
|
172
|
+
|
|
173
|
+
const encodeBatchExecute: (txs: AccountOp[]) => Promise<Hex> = async (txs) =>
|
|
174
|
+
await encodeCallData(
|
|
175
|
+
encodeFunctionData({
|
|
176
|
+
abi: modularAccountAbi,
|
|
177
|
+
functionName: "executeBatch",
|
|
178
|
+
args: [
|
|
179
|
+
txs.map((tx) => ({
|
|
180
|
+
target: tx.target,
|
|
181
|
+
data: tx.data,
|
|
182
|
+
value: tx.value ?? 0n,
|
|
183
|
+
})),
|
|
184
|
+
],
|
|
185
|
+
})
|
|
186
|
+
);
|
|
187
|
+
|
|
188
|
+
const _accountAddress = await getAccountAddress({
|
|
189
|
+
client,
|
|
190
|
+
entryPoint,
|
|
191
|
+
accountAddress,
|
|
192
|
+
getAccountInitCode,
|
|
193
|
+
});
|
|
194
|
+
|
|
195
|
+
const baseAccount = await toSmartContractAccount({
|
|
196
|
+
transport,
|
|
197
|
+
chain,
|
|
198
|
+
entryPoint,
|
|
199
|
+
accountAddress: _accountAddress,
|
|
200
|
+
source: `MAV2Account`,
|
|
201
|
+
encodeExecute,
|
|
202
|
+
encodeBatchExecute,
|
|
203
|
+
getAccountInitCode,
|
|
204
|
+
...(entityId === DEFAULT_OWNER_ENTITY_ID
|
|
205
|
+
? nativeSMASigner(signer, chain, _accountAddress)
|
|
206
|
+
: singleSignerMessageSigner(signer, chain, _accountAddress, entityId)),
|
|
207
|
+
});
|
|
208
|
+
|
|
209
|
+
// TODO: add deferred action flag
|
|
210
|
+
const getAccountNonce = async (nonceKey: bigint = 0n): Promise<bigint> => {
|
|
211
|
+
if (nonceKey > maxUint152) {
|
|
212
|
+
throw new InvalidNonceKeyError(nonceKey);
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
const entryPointContract = getContract({
|
|
216
|
+
address: entryPoint.address,
|
|
217
|
+
abi: entryPoint.abi,
|
|
218
|
+
client,
|
|
219
|
+
});
|
|
220
|
+
|
|
221
|
+
const fullNonceKey: bigint =
|
|
222
|
+
(nonceKey << 40n) +
|
|
223
|
+
BigInt(entityId << 8) +
|
|
224
|
+
(isGlobalValidation ? 1n : 0n);
|
|
225
|
+
|
|
226
|
+
return entryPointContract.read.getNonce([
|
|
227
|
+
_accountAddress,
|
|
228
|
+
fullNonceKey,
|
|
229
|
+
]) as Promise<bigint>;
|
|
230
|
+
};
|
|
231
|
+
|
|
232
|
+
const accountContract = getContract({
|
|
233
|
+
address: _accountAddress,
|
|
234
|
+
abi: modularAccountAbi,
|
|
235
|
+
client,
|
|
236
|
+
});
|
|
237
|
+
|
|
238
|
+
const getExecutionData = async (selector: Hex) => {
|
|
239
|
+
if (!(await baseAccount.isAccountDeployed())) {
|
|
240
|
+
return {
|
|
241
|
+
module: zeroAddress,
|
|
242
|
+
skipRuntimeValidation: false,
|
|
243
|
+
allowGlobalValidation: false,
|
|
244
|
+
executionHooks: [],
|
|
245
|
+
};
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
return await accountContract.read.getExecutionData([selector]);
|
|
249
|
+
};
|
|
250
|
+
|
|
251
|
+
const getValidationData = async (args: ValidationDataParams) => {
|
|
252
|
+
if (!(await baseAccount.isAccountDeployed())) {
|
|
253
|
+
return {
|
|
254
|
+
validationHooks: [],
|
|
255
|
+
executionHooks: [],
|
|
256
|
+
selectors: [],
|
|
257
|
+
validationFlags: 0,
|
|
258
|
+
};
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
const { validationModuleAddress, entityId } = args;
|
|
262
|
+
return await accountContract.read.getValidationData([
|
|
263
|
+
serializeModuleEntity({
|
|
264
|
+
moduleAddress: validationModuleAddress ?? zeroAddress,
|
|
265
|
+
entityId: entityId ?? Number(maxUint32),
|
|
266
|
+
}),
|
|
267
|
+
]);
|
|
268
|
+
};
|
|
269
|
+
|
|
270
|
+
const encodeCallData = async (callData: Hex): Promise<Hex> => {
|
|
271
|
+
const validationData = await getValidationData({
|
|
272
|
+
entityId: Number(entityId),
|
|
273
|
+
});
|
|
274
|
+
|
|
275
|
+
return validationData.executionHooks.length
|
|
276
|
+
? concatHex([executeUserOpSelector, callData])
|
|
277
|
+
: callData;
|
|
278
|
+
};
|
|
279
|
+
|
|
280
|
+
return {
|
|
281
|
+
...baseAccount,
|
|
282
|
+
getAccountNonce,
|
|
283
|
+
getSigner: () => signer,
|
|
284
|
+
signerEntity,
|
|
285
|
+
getExecutionData,
|
|
286
|
+
getValidationData,
|
|
287
|
+
encodeCallData,
|
|
288
|
+
};
|
|
289
|
+
}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import type { Address, Hex } from "viem";
|
|
2
|
+
|
|
3
|
+
export type ModuleEntity = {
|
|
4
|
+
moduleAddress: Address;
|
|
5
|
+
entityId: number;
|
|
6
|
+
};
|
|
7
|
+
|
|
8
|
+
export type ValidationConfig = {
|
|
9
|
+
moduleAddress: Address;
|
|
10
|
+
entityId: number; // uint32
|
|
11
|
+
isGlobal: boolean;
|
|
12
|
+
isSignatureValidation: boolean;
|
|
13
|
+
isUserOpValidation: boolean;
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
export enum HookType {
|
|
17
|
+
EXECUTION = "0x00",
|
|
18
|
+
VALIDATION = "0x01",
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export type HookConfig = {
|
|
22
|
+
address: Address;
|
|
23
|
+
entityId: number; // uint32
|
|
24
|
+
hookType: HookType;
|
|
25
|
+
hasPreHooks: boolean;
|
|
26
|
+
hasPostHooks: boolean;
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
// maps to type ValidationStorage in MAv2 implementation
|
|
30
|
+
export type ValidationData = {
|
|
31
|
+
isGlobal: boolean; // validation flag
|
|
32
|
+
isSignatureValidation: boolean; // validation flag
|
|
33
|
+
isUserOpValidation: boolean;
|
|
34
|
+
validationHooks: HookConfig[];
|
|
35
|
+
executionHooks: Hex[];
|
|
36
|
+
selectors: Hex[];
|
|
37
|
+
};
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
import { type Hex, toHex, concatHex } from "viem";
|
|
2
|
+
import type { ValidationConfig, HookConfig, ModuleEntity } from "./types";
|
|
3
|
+
import { HookType } from "./types.js";
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Serializes a validation configuration into a hexadecimal string representation. This involves converting boolean flags into bitwise representation and combining them with serialized module entity data.
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* ```ts
|
|
10
|
+
* import { serializeValidationConfig } from "@account-kit/smart-contracts";
|
|
11
|
+
* import { Address } from "viem";
|
|
12
|
+
*
|
|
13
|
+
* const moduleAddress: Address = "0x1234";
|
|
14
|
+
* const entityId: number = 1234;
|
|
15
|
+
* const isGlobal: boolean = true;
|
|
16
|
+
* const isSignatureValidation: boolean = false;
|
|
17
|
+
* const isUserOpValidation: boolean = true;
|
|
18
|
+
*
|
|
19
|
+
* const validationConfigHex = serializeValidationConfig({
|
|
20
|
+
* moduleAddress,
|
|
21
|
+
* entityId
|
|
22
|
+
* isGlobal,
|
|
23
|
+
* isSignatureValidation,
|
|
24
|
+
* isUserOpValidation
|
|
25
|
+
* });
|
|
26
|
+
* ```
|
|
27
|
+
* @param {ValidationConfig} config The validation configuration object containing details to serialize
|
|
28
|
+
* @returns {Hex} A hexadecimal string representing the serialized configuration
|
|
29
|
+
*/
|
|
30
|
+
export function serializeValidationConfig(config: ValidationConfig): Hex {
|
|
31
|
+
const isUserOpValidationBit = config.isUserOpValidation ? 1 : 0;
|
|
32
|
+
const isSignatureValidationBit = config.isSignatureValidation ? 2 : 0;
|
|
33
|
+
const isGlobalBit = config.isGlobal ? 4 : 0;
|
|
34
|
+
return concatHex([
|
|
35
|
+
serializeModuleEntity(config),
|
|
36
|
+
toHex(isUserOpValidationBit + isSignatureValidationBit + isGlobalBit, {
|
|
37
|
+
size: 1,
|
|
38
|
+
}),
|
|
39
|
+
]);
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* Serializes a `HookConfig` object into a `Hex` format by encoding the hook type, presence of post/pre hooks, address, and entity ID.
|
|
44
|
+
*
|
|
45
|
+
* @example
|
|
46
|
+
* ```ts
|
|
47
|
+
* import { type HookType, serializeHookConfig } from "@account-kit/smart-contracts";
|
|
48
|
+
* import { Address } from "viem";
|
|
49
|
+
*
|
|
50
|
+
* const moduleAddress: Address = "0x1234";
|
|
51
|
+
* const entityId: number = 1234;
|
|
52
|
+
* const hookType: HookType = HookType.Validation;
|
|
53
|
+
* const hasPostHooks: boolean = false;
|
|
54
|
+
* const hasPreHooks: boolean = true;
|
|
55
|
+
*
|
|
56
|
+
* const hookConfigHex = serializeHookConfig({
|
|
57
|
+
* moduleAddress,
|
|
58
|
+
* entityId
|
|
59
|
+
* hookType,
|
|
60
|
+
* hasPostHooks,
|
|
61
|
+
* hasPreHooks
|
|
62
|
+
* });
|
|
63
|
+
* ```
|
|
64
|
+
*
|
|
65
|
+
* @param {HookConfig} config The hook configuration containing address, entity ID, hook type, and post/pre hook indicators
|
|
66
|
+
* @returns {Hex} The serialized hook configuration in hexadecimal format
|
|
67
|
+
*/
|
|
68
|
+
export function serializeHookConfig(config: HookConfig): Hex {
|
|
69
|
+
const hookTypeBit = config.hookType === HookType.VALIDATION ? 1 : 0;
|
|
70
|
+
const hasPostHooksBit = config.hasPostHooks ? 2 : 0;
|
|
71
|
+
const hasPreHooksBit = config.hasPreHooks ? 4 : 0;
|
|
72
|
+
return concatHex([
|
|
73
|
+
config.address,
|
|
74
|
+
toHex(config.entityId, { size: 4 }),
|
|
75
|
+
toHex(hookTypeBit + hasPostHooksBit + hasPreHooksBit, {
|
|
76
|
+
size: 1,
|
|
77
|
+
}),
|
|
78
|
+
]);
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
/**
|
|
82
|
+
* Serializes a module entity into a hexadecimal format by concatenating the module address and entity ID.
|
|
83
|
+
*
|
|
84
|
+
* @example
|
|
85
|
+
* ```ts
|
|
86
|
+
* import { serializeModuleEntity } from "@account-kit/smart-contracts";
|
|
87
|
+
* import { Address } from "viem";
|
|
88
|
+
*
|
|
89
|
+
* const moduleAddress: Address = "0x1234";
|
|
90
|
+
* const entityId: number = 1234;
|
|
91
|
+
*
|
|
92
|
+
* const moduleEntityHex = serializeModuleEntity({
|
|
93
|
+
* moduleAddress,
|
|
94
|
+
* entityId
|
|
95
|
+
* });
|
|
96
|
+
* ```
|
|
97
|
+
*
|
|
98
|
+
* @param {ModuleEntity} config The module entity configuration containing the module address and entity ID
|
|
99
|
+
* @returns {Hex} A hexadecimal string representation of the serialized module entity
|
|
100
|
+
*/
|
|
101
|
+
export function serializeModuleEntity(config: ModuleEntity): Hex {
|
|
102
|
+
return concatHex([config.moduleAddress, toHex(config.entityId, { size: 4 })]);
|
|
103
|
+
}
|