@account-kit/smart-contracts 4.23.1 → 4.25.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/esm/src/ma-v2/account/common/modularAccountV2Base.d.ts +1 -0
- package/dist/esm/src/ma-v2/account/common/modularAccountV2Base.js +35 -12
- package/dist/esm/src/ma-v2/account/common/modularAccountV2Base.js.map +1 -1
- package/dist/esm/src/ma-v2/account/modularAccountV2.d.ts +1 -0
- package/dist/esm/src/ma-v2/account/modularAccountV2.js +2 -1
- package/dist/esm/src/ma-v2/account/modularAccountV2.js.map +1 -1
- package/dist/esm/src/ma-v2/account/nativeSMASigner.d.ts +2 -2
- package/dist/esm/src/ma-v2/account/nativeSMASigner.js +11 -8
- package/dist/esm/src/ma-v2/account/nativeSMASigner.js.map +1 -1
- package/dist/esm/src/ma-v2/actions/deferralActions.d.ts +9 -7
- package/dist/esm/src/ma-v2/actions/deferralActions.js +21 -35
- package/dist/esm/src/ma-v2/actions/deferralActions.js.map +1 -1
- package/dist/esm/src/ma-v2/index.d.ts +4 -0
- package/dist/esm/src/ma-v2/index.js +2 -0
- package/dist/esm/src/ma-v2/index.js.map +1 -1
- package/dist/esm/src/ma-v2/modules/single-signer-validation/signer.d.ts +2 -1
- package/dist/esm/src/ma-v2/modules/single-signer-validation/signer.js +10 -6
- package/dist/esm/src/ma-v2/modules/single-signer-validation/signer.js.map +1 -1
- package/dist/esm/src/ma-v2/permissionBuilder.d.ts +113 -0
- package/dist/esm/src/ma-v2/permissionBuilder.js +487 -0
- package/dist/esm/src/ma-v2/permissionBuilder.js.map +1 -0
- package/dist/esm/src/ma-v2/utils.d.ts +42 -0
- package/dist/esm/src/ma-v2/utils.js +15 -1
- package/dist/esm/src/ma-v2/utils.js.map +1 -1
- package/dist/types/src/ma-v2/account/common/modularAccountV2Base.d.ts +1 -0
- package/dist/types/src/ma-v2/account/common/modularAccountV2Base.d.ts.map +1 -1
- package/dist/types/src/ma-v2/account/modularAccountV2.d.ts +1 -0
- package/dist/types/src/ma-v2/account/modularAccountV2.d.ts.map +1 -1
- package/dist/types/src/ma-v2/account/nativeSMASigner.d.ts +2 -2
- package/dist/types/src/ma-v2/account/nativeSMASigner.d.ts.map +1 -1
- package/dist/types/src/ma-v2/actions/deferralActions.d.ts +9 -7
- package/dist/types/src/ma-v2/actions/deferralActions.d.ts.map +1 -1
- package/dist/types/src/ma-v2/index.d.ts +4 -0
- package/dist/types/src/ma-v2/index.d.ts.map +1 -1
- package/dist/types/src/ma-v2/modules/single-signer-validation/signer.d.ts +2 -1
- package/dist/types/src/ma-v2/modules/single-signer-validation/signer.d.ts.map +1 -1
- package/dist/types/src/ma-v2/permissionBuilder.d.ts +114 -0
- package/dist/types/src/ma-v2/permissionBuilder.d.ts.map +1 -0
- package/dist/types/src/ma-v2/utils.d.ts +42 -0
- package/dist/types/src/ma-v2/utils.d.ts.map +1 -1
- package/package.json +6 -5
- package/src/ma-v2/account/common/modularAccountV2Base.ts +49 -11
- package/src/ma-v2/account/modularAccountV2.ts +3 -0
- package/src/ma-v2/account/nativeSMASigner.ts +20 -14
- package/src/ma-v2/actions/deferralActions.ts +38 -51
- package/src/ma-v2/index.ts +4 -0
- package/src/ma-v2/modules/single-signer-validation/signer.ts +19 -13
- package/src/ma-v2/permissionBuilder.ts +716 -0
- package/src/ma-v2/utils.ts +25 -0
|
@@ -23,22 +23,26 @@ import { packUOSignature, pack1271Signature } from "../../utils.js";
|
|
|
23
23
|
* @param {Chain} chain Chain object for the signer
|
|
24
24
|
* @param {Address} accountAddress address of the smart account using this signer
|
|
25
25
|
* @param {number} entityId the entity id of the signing validation
|
|
26
|
+
* @param {Hex} deferredActionData optional deferred action data to prepend to the uo signatures
|
|
26
27
|
* @returns {object} an object with methods for signing operations and managing signatures
|
|
27
28
|
*/
|
|
28
|
-
export const singleSignerMessageSigner = (signer, chain, accountAddress, entityId) => {
|
|
29
|
+
export const singleSignerMessageSigner = (signer, chain, accountAddress, entityId, deferredActionData) => {
|
|
29
30
|
return {
|
|
30
31
|
getDummySignature: () => {
|
|
31
|
-
const
|
|
32
|
-
return packUOSignature({
|
|
32
|
+
const sig = packUOSignature({
|
|
33
33
|
// orderedHookData: [],
|
|
34
|
-
validationSignature:
|
|
34
|
+
validationSignature: "0xfffffffffffffffffffffffffffffff0000000000000000000000000000000007aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa1c",
|
|
35
35
|
});
|
|
36
|
+
return deferredActionData ? concatHex([deferredActionData, sig]) : sig;
|
|
36
37
|
},
|
|
37
|
-
signUserOperationHash: (uoHash) => {
|
|
38
|
-
|
|
38
|
+
signUserOperationHash: async (uoHash) => {
|
|
39
|
+
const sig = await signer
|
|
40
|
+
.signMessage({ raw: uoHash })
|
|
41
|
+
.then((signature) => packUOSignature({
|
|
39
42
|
// orderedHookData: [],
|
|
40
43
|
validationSignature: signature,
|
|
41
44
|
}));
|
|
45
|
+
return deferredActionData ? concatHex([deferredActionData, sig]) : sig;
|
|
42
46
|
},
|
|
43
47
|
// we apply the expected 1271 packing here since the account contract will expect it
|
|
44
48
|
async signMessage({ message }) {
|
|
@@ -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,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
|
|
1
|
+
{"version":3,"file":"signer.js","sourceRoot":"","sources":["../../../../../../src/ma-v2/modules/single-signer-validation/signer.ts"],"names":[],"mappings":"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","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 * @param {Hex} deferredActionData optional deferred action data to prepend to the uo signatures\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 deferredActionData?: Hex\n) => {\n return {\n getDummySignature: (): Hex => {\n const sig = packUOSignature({\n // orderedHookData: [],\n validationSignature:\n \"0xfffffffffffffffffffffffffffffff0000000000000000000000000000000007aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa1c\",\n });\n\n return deferredActionData ? concatHex([deferredActionData, sig]) : sig;\n },\n\n signUserOperationHash: async (uoHash: Hex): Promise<Hex> => {\n const sig = await signer\n .signMessage({ raw: uoHash })\n .then((signature: Hex) =>\n packUOSignature({\n // orderedHookData: [],\n validationSignature: signature,\n })\n );\n\n return deferredActionData ? concatHex([deferredActionData, sig]) : sig;\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"]}
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
import { type Address, type Hex } from "viem";
|
|
2
|
+
import { type HookConfig } from "./actions/common/types.js";
|
|
3
|
+
import { type InstallValidationParams } from "./actions/install-validation/installValidation.js";
|
|
4
|
+
import type { ModularAccountV2Client } from "./client/client.js";
|
|
5
|
+
import { type DeferredActionTypedData } from "./actions/deferralActions.js";
|
|
6
|
+
export declare enum PermissionType {
|
|
7
|
+
NATIVE_TOKEN_TRANSFER = "native-token-transfer",
|
|
8
|
+
ERC20_TOKEN_TRANSFER = "erc20-token-transfer",
|
|
9
|
+
GAS_LIMIT = "gas-limit",
|
|
10
|
+
CONTRACT_ACCESS = "contract-access",
|
|
11
|
+
ACCOUNT_FUNCTIONS = "account-functions",
|
|
12
|
+
FUNCTIONS_ON_ALL_CONTRACTS = "functions-on-all-contracts",
|
|
13
|
+
FUNCTIONS_ON_CONTRACT = "functions-on-contract",
|
|
14
|
+
ROOT = "root"
|
|
15
|
+
}
|
|
16
|
+
type OneOf<T extends {}[]> = T[number];
|
|
17
|
+
type Key = {
|
|
18
|
+
publicKey: Hex;
|
|
19
|
+
type: "secp256k1" | "contract";
|
|
20
|
+
};
|
|
21
|
+
export type Permission = OneOf<[
|
|
22
|
+
{
|
|
23
|
+
type: PermissionType.NATIVE_TOKEN_TRANSFER;
|
|
24
|
+
data: {
|
|
25
|
+
allowance: Hex;
|
|
26
|
+
};
|
|
27
|
+
},
|
|
28
|
+
{
|
|
29
|
+
type: PermissionType.ERC20_TOKEN_TRANSFER;
|
|
30
|
+
data: {
|
|
31
|
+
address: Address;
|
|
32
|
+
allowance: Hex;
|
|
33
|
+
};
|
|
34
|
+
},
|
|
35
|
+
{
|
|
36
|
+
type: PermissionType.GAS_LIMIT;
|
|
37
|
+
data: {
|
|
38
|
+
limit: Hex;
|
|
39
|
+
};
|
|
40
|
+
},
|
|
41
|
+
{
|
|
42
|
+
type: PermissionType.CONTRACT_ACCESS;
|
|
43
|
+
data: {
|
|
44
|
+
address: Address;
|
|
45
|
+
};
|
|
46
|
+
},
|
|
47
|
+
{
|
|
48
|
+
type: PermissionType.ACCOUNT_FUNCTIONS;
|
|
49
|
+
data: {
|
|
50
|
+
functions: Hex[];
|
|
51
|
+
};
|
|
52
|
+
},
|
|
53
|
+
{
|
|
54
|
+
type: PermissionType.FUNCTIONS_ON_ALL_CONTRACTS;
|
|
55
|
+
data: {
|
|
56
|
+
functions: Hex[];
|
|
57
|
+
};
|
|
58
|
+
},
|
|
59
|
+
{
|
|
60
|
+
type: PermissionType.FUNCTIONS_ON_CONTRACT;
|
|
61
|
+
data: {
|
|
62
|
+
address: Address;
|
|
63
|
+
functions: Hex[];
|
|
64
|
+
};
|
|
65
|
+
},
|
|
66
|
+
{
|
|
67
|
+
type: PermissionType.ROOT;
|
|
68
|
+
data?: never;
|
|
69
|
+
}
|
|
70
|
+
]>;
|
|
71
|
+
type Hook = {
|
|
72
|
+
hookConfig: HookConfig;
|
|
73
|
+
initData: Hex;
|
|
74
|
+
};
|
|
75
|
+
export declare class PermissionBuilder {
|
|
76
|
+
private client;
|
|
77
|
+
private validationConfig;
|
|
78
|
+
private selectors;
|
|
79
|
+
private installData;
|
|
80
|
+
private permissions;
|
|
81
|
+
private hooks;
|
|
82
|
+
private nonce;
|
|
83
|
+
private hasAssociatedExecHooks;
|
|
84
|
+
private deadline;
|
|
85
|
+
constructor({ client, key, entityId, nonce, selectors, hooks, deadline, }: {
|
|
86
|
+
client: ModularAccountV2Client;
|
|
87
|
+
key: Key;
|
|
88
|
+
entityId: number;
|
|
89
|
+
nonce: bigint;
|
|
90
|
+
selectors?: Hex[];
|
|
91
|
+
hooks?: Hook[];
|
|
92
|
+
deadline?: number;
|
|
93
|
+
});
|
|
94
|
+
addSelector({ selector }: {
|
|
95
|
+
selector: Hex;
|
|
96
|
+
}): this;
|
|
97
|
+
addPermission({ permission }: {
|
|
98
|
+
permission: Permission;
|
|
99
|
+
}): this;
|
|
100
|
+
addPermissions({ permissions }: {
|
|
101
|
+
permissions: Permission[];
|
|
102
|
+
}): this;
|
|
103
|
+
compileDeferred(): Promise<{
|
|
104
|
+
typedData: DeferredActionTypedData;
|
|
105
|
+
fullPreSignatureDeferredActionDigest: Hex;
|
|
106
|
+
}>;
|
|
107
|
+
compileRaw(): Promise<Hex>;
|
|
108
|
+
compileInstallArgs(): Promise<InstallValidationParams>;
|
|
109
|
+
private validateConfiguration;
|
|
110
|
+
private translatePermissions;
|
|
111
|
+
private addHooks;
|
|
112
|
+
}
|
|
113
|
+
export {};
|
|
@@ -0,0 +1,487 @@
|
|
|
1
|
+
import { toHex, zeroAddress } from "viem";
|
|
2
|
+
import { HookType, } from "./actions/common/types.js";
|
|
3
|
+
import { installValidationActions, } from "./actions/install-validation/installValidation.js";
|
|
4
|
+
import { deferralActions, } from "./actions/deferralActions.js";
|
|
5
|
+
import { NativeTokenLimitModule } from "./modules/native-token-limit-module/module.js";
|
|
6
|
+
import { getDefaultAllowlistModuleAddress, getDefaultNativeTokenLimitModuleAddress, getDefaultSingleSignerValidationModuleAddress, getDefaultTimeRangeModuleAddress, } from "./modules/utils.js";
|
|
7
|
+
import { SingleSignerValidationModule } from "./modules/single-signer-validation/module.js";
|
|
8
|
+
import { AllowlistModule } from "./modules/allowlist-module/module.js";
|
|
9
|
+
import { TimeRangeModule } from "./modules/time-range-module/module.js";
|
|
10
|
+
// We use this to offset the ERC20 spend limit entityId
|
|
11
|
+
const HALF_UINT32 = 2147483647;
|
|
12
|
+
const ERC20_APPROVE_SELECTOR = "0x095ea7b3";
|
|
13
|
+
const ERC20_TRANSFER_SELECTOR = "0xa9059cbb";
|
|
14
|
+
const ACCOUNT_EXECUTE_SELECTOR = "0xb61d27f6";
|
|
15
|
+
const ACCOUNT_EXECUTEBATCH_SELECTOR = "0x34fcd5be";
|
|
16
|
+
export var PermissionType;
|
|
17
|
+
(function (PermissionType) {
|
|
18
|
+
PermissionType["NATIVE_TOKEN_TRANSFER"] = "native-token-transfer";
|
|
19
|
+
PermissionType["ERC20_TOKEN_TRANSFER"] = "erc20-token-transfer";
|
|
20
|
+
// ERC721_TOKEN_TRANSFER = "erc721-token-transfer", //Unimplemented
|
|
21
|
+
// ERC1155_TOKEN_TRANSFER = "erc1155-token-transfer", //Unimplemented
|
|
22
|
+
PermissionType["GAS_LIMIT"] = "gas-limit";
|
|
23
|
+
// CALL_LIMIT = "call-limit", //Unimplemented
|
|
24
|
+
// RATE_LIMIT = "rate-limit", //Unimplemented
|
|
25
|
+
PermissionType["CONTRACT_ACCESS"] = "contract-access";
|
|
26
|
+
PermissionType["ACCOUNT_FUNCTIONS"] = "account-functions";
|
|
27
|
+
PermissionType["FUNCTIONS_ON_ALL_CONTRACTS"] = "functions-on-all-contracts";
|
|
28
|
+
PermissionType["FUNCTIONS_ON_CONTRACT"] = "functions-on-contract";
|
|
29
|
+
PermissionType["ROOT"] = "root";
|
|
30
|
+
})(PermissionType || (PermissionType = {}));
|
|
31
|
+
var HookIdentifier;
|
|
32
|
+
(function (HookIdentifier) {
|
|
33
|
+
HookIdentifier[HookIdentifier["NATIVE_TOKEN_TRANSFER"] = 0] = "NATIVE_TOKEN_TRANSFER";
|
|
34
|
+
HookIdentifier[HookIdentifier["ERC20_TOKEN_TRANSFER"] = 1] = "ERC20_TOKEN_TRANSFER";
|
|
35
|
+
HookIdentifier[HookIdentifier["GAS_LIMIT"] = 2] = "GAS_LIMIT";
|
|
36
|
+
HookIdentifier[HookIdentifier["PREVAL_ALLOWLIST"] = 3] = "PREVAL_ALLOWLIST";
|
|
37
|
+
})(HookIdentifier || (HookIdentifier = {}));
|
|
38
|
+
export class PermissionBuilder {
|
|
39
|
+
constructor({ client, key, entityId, nonce, selectors, hooks, deadline, }) {
|
|
40
|
+
Object.defineProperty(this, "client", {
|
|
41
|
+
enumerable: true,
|
|
42
|
+
configurable: true,
|
|
43
|
+
writable: true,
|
|
44
|
+
value: void 0
|
|
45
|
+
});
|
|
46
|
+
Object.defineProperty(this, "validationConfig", {
|
|
47
|
+
enumerable: true,
|
|
48
|
+
configurable: true,
|
|
49
|
+
writable: true,
|
|
50
|
+
value: {
|
|
51
|
+
moduleAddress: zeroAddress,
|
|
52
|
+
entityId: 0, // uint32
|
|
53
|
+
isGlobal: false,
|
|
54
|
+
isSignatureValidation: false,
|
|
55
|
+
isUserOpValidation: false,
|
|
56
|
+
}
|
|
57
|
+
});
|
|
58
|
+
Object.defineProperty(this, "selectors", {
|
|
59
|
+
enumerable: true,
|
|
60
|
+
configurable: true,
|
|
61
|
+
writable: true,
|
|
62
|
+
value: []
|
|
63
|
+
});
|
|
64
|
+
Object.defineProperty(this, "installData", {
|
|
65
|
+
enumerable: true,
|
|
66
|
+
configurable: true,
|
|
67
|
+
writable: true,
|
|
68
|
+
value: "0x"
|
|
69
|
+
});
|
|
70
|
+
Object.defineProperty(this, "permissions", {
|
|
71
|
+
enumerable: true,
|
|
72
|
+
configurable: true,
|
|
73
|
+
writable: true,
|
|
74
|
+
value: []
|
|
75
|
+
});
|
|
76
|
+
Object.defineProperty(this, "hooks", {
|
|
77
|
+
enumerable: true,
|
|
78
|
+
configurable: true,
|
|
79
|
+
writable: true,
|
|
80
|
+
value: []
|
|
81
|
+
});
|
|
82
|
+
Object.defineProperty(this, "nonce", {
|
|
83
|
+
enumerable: true,
|
|
84
|
+
configurable: true,
|
|
85
|
+
writable: true,
|
|
86
|
+
value: 0n
|
|
87
|
+
});
|
|
88
|
+
Object.defineProperty(this, "hasAssociatedExecHooks", {
|
|
89
|
+
enumerable: true,
|
|
90
|
+
configurable: true,
|
|
91
|
+
writable: true,
|
|
92
|
+
value: false
|
|
93
|
+
});
|
|
94
|
+
Object.defineProperty(this, "deadline", {
|
|
95
|
+
enumerable: true,
|
|
96
|
+
configurable: true,
|
|
97
|
+
writable: true,
|
|
98
|
+
value: 0
|
|
99
|
+
});
|
|
100
|
+
this.client = client;
|
|
101
|
+
this.validationConfig = {
|
|
102
|
+
moduleAddress: getDefaultSingleSignerValidationModuleAddress(this.client.chain),
|
|
103
|
+
entityId,
|
|
104
|
+
isUserOpValidation: true,
|
|
105
|
+
isGlobal: false,
|
|
106
|
+
isSignatureValidation: false,
|
|
107
|
+
};
|
|
108
|
+
this.installData = SingleSignerValidationModule.encodeOnInstallData({
|
|
109
|
+
entityId: entityId,
|
|
110
|
+
signer: key.publicKey,
|
|
111
|
+
});
|
|
112
|
+
this.nonce = nonce;
|
|
113
|
+
if (selectors)
|
|
114
|
+
this.selectors = selectors;
|
|
115
|
+
if (hooks)
|
|
116
|
+
this.hooks = hooks;
|
|
117
|
+
if (deadline)
|
|
118
|
+
this.deadline = deadline;
|
|
119
|
+
}
|
|
120
|
+
addSelector({ selector }) {
|
|
121
|
+
this.selectors.push(selector);
|
|
122
|
+
return this;
|
|
123
|
+
}
|
|
124
|
+
addPermission({ permission }) {
|
|
125
|
+
// Check 1: If we're adding root, we can't have any other permissions
|
|
126
|
+
if (permission.type === PermissionType.ROOT) {
|
|
127
|
+
if (this.permissions.length !== 0) {
|
|
128
|
+
throw new Error("PERMISSION: ROOT: Cannot add ROOT permission with other permissions");
|
|
129
|
+
}
|
|
130
|
+
this.permissions.push(permission);
|
|
131
|
+
// Set isGlobal to true
|
|
132
|
+
this.validationConfig.isGlobal = true;
|
|
133
|
+
return this;
|
|
134
|
+
}
|
|
135
|
+
// Check 2: If the permission is NOT ROOT (guaranteed), ensure there is no ROOT permission set
|
|
136
|
+
// Will resolve to undefined if ROOT is not found
|
|
137
|
+
// NOTE: Technically this could be replaced by checking permissions[0] since it should not be possible
|
|
138
|
+
// to have >1 permission with root among them
|
|
139
|
+
if (this.permissions.find((p) => p.type === PermissionType.ROOT)) {
|
|
140
|
+
throw new Error(`PERMISSION: ${permission.type} => Cannot add permissions with ROOT enabled`);
|
|
141
|
+
}
|
|
142
|
+
// Check 3: If the permission is either CONTRACT_ACCESS or FUNCTIONS_ON_CONTRACT, ensure it doesn't collide with another like it.
|
|
143
|
+
if (permission.type === PermissionType.CONTRACT_ACCESS ||
|
|
144
|
+
permission.type === PermissionType.FUNCTIONS_ON_CONTRACT) {
|
|
145
|
+
// Check 3.1: address must not be the account address, or the user should use the ACCOUNT_FUNCTIONS permission
|
|
146
|
+
if (permission.data.address === this.client.account.address) {
|
|
147
|
+
throw new Error(`PERMISSION: ${permission.type} => Account address as target, use ACCOUNT_FUNCTIONS for account address`);
|
|
148
|
+
}
|
|
149
|
+
// Check 3.2: there must not be an existing permission with this address as a target
|
|
150
|
+
const targetAddress = permission.data.address;
|
|
151
|
+
const existingPermissionWithSameAddress = this.permissions.find((p) => (p.type === PermissionType.CONTRACT_ACCESS &&
|
|
152
|
+
"address" in p.data &&
|
|
153
|
+
p.data.address === targetAddress) ||
|
|
154
|
+
(p.type === PermissionType.FUNCTIONS_ON_CONTRACT &&
|
|
155
|
+
"address" in p.data &&
|
|
156
|
+
p.data.address === targetAddress));
|
|
157
|
+
if (existingPermissionWithSameAddress) {
|
|
158
|
+
throw new Error(`PERMISSION: ${permission.type} => Address ${targetAddress} already has a permission. Cannot add multiple CONTRACT_ACCESS or FUNCTIONS_ON_CONTRACT permissions for the same target address.`);
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
// Check 4: If the permission is ACCOUNT_FUNCTIONS, add selectors
|
|
162
|
+
if (permission.type === PermissionType.ACCOUNT_FUNCTIONS) {
|
|
163
|
+
this.selectors = [...this.selectors, ...permission.data.functions];
|
|
164
|
+
return this;
|
|
165
|
+
}
|
|
166
|
+
this.permissions.push(permission);
|
|
167
|
+
return this;
|
|
168
|
+
}
|
|
169
|
+
addPermissions({ permissions }) {
|
|
170
|
+
// We could validate each permission here, but for simplicity we'll just add them
|
|
171
|
+
// A better approach would be to call addPermission for each one
|
|
172
|
+
permissions.forEach((permission) => {
|
|
173
|
+
this.addPermission({ permission });
|
|
174
|
+
});
|
|
175
|
+
return this;
|
|
176
|
+
}
|
|
177
|
+
// Use for building deferred action typed data to sign
|
|
178
|
+
async compileDeferred() {
|
|
179
|
+
// Add time range module hook via expiry
|
|
180
|
+
if (this.deadline !== 0) {
|
|
181
|
+
if (this.deadline < Date.now() / 1000) {
|
|
182
|
+
throw new Error(`PERMISSION: compileDeferred(): deadline ${this.deadline} cannot be before now (${Date.now() / 1000})`);
|
|
183
|
+
}
|
|
184
|
+
this.hooks.push(TimeRangeModule.buildHook({
|
|
185
|
+
entityId: this.validationConfig.entityId, // will be timerange entityId
|
|
186
|
+
validUntil: this.deadline,
|
|
187
|
+
validAfter: 0,
|
|
188
|
+
}, getDefaultTimeRangeModuleAddress(this.client.chain)));
|
|
189
|
+
}
|
|
190
|
+
const installValidationCall = await this.compileRaw();
|
|
191
|
+
const { typedData } = await deferralActions(this.client).createDeferredActionTypedDataObject({
|
|
192
|
+
callData: installValidationCall,
|
|
193
|
+
deadline: this.deadline,
|
|
194
|
+
nonce: this.nonce,
|
|
195
|
+
});
|
|
196
|
+
const preSignatureDigest = deferralActions(this.client).buildPreSignatureDeferredActionDigest({ typedData });
|
|
197
|
+
// Encode additional information to build the full pre-signature digest
|
|
198
|
+
const fullPreSignatureDeferredActionDigest = `0x0${this.hasAssociatedExecHooks ? "1" : "0"}${toHex(this.nonce, {
|
|
199
|
+
size: 32,
|
|
200
|
+
}).slice(2)}${preSignatureDigest.slice(2)}`;
|
|
201
|
+
return {
|
|
202
|
+
typedData,
|
|
203
|
+
fullPreSignatureDeferredActionDigest,
|
|
204
|
+
};
|
|
205
|
+
}
|
|
206
|
+
// Use for direct `installValidation()` low-level calls (maybe useless)
|
|
207
|
+
async compileRaw() {
|
|
208
|
+
// Translate all permissions into raw hooks if >0
|
|
209
|
+
if (this.permissions.length > 0) {
|
|
210
|
+
const rawHooks = this.translatePermissions(this.validationConfig.entityId);
|
|
211
|
+
// Add the translated permissions as hooks
|
|
212
|
+
this.addHooks(rawHooks);
|
|
213
|
+
}
|
|
214
|
+
this.validateConfiguration();
|
|
215
|
+
return await installValidationActions(this.client).encodeInstallValidation({
|
|
216
|
+
validationConfig: this.validationConfig,
|
|
217
|
+
selectors: this.selectors,
|
|
218
|
+
installData: this.installData,
|
|
219
|
+
hooks: this.hooks,
|
|
220
|
+
account: this.client.account,
|
|
221
|
+
});
|
|
222
|
+
}
|
|
223
|
+
// Use for compiling args to installValidation
|
|
224
|
+
async compileInstallArgs() {
|
|
225
|
+
this.validateConfiguration();
|
|
226
|
+
return {
|
|
227
|
+
validationConfig: this.validationConfig,
|
|
228
|
+
selectors: this.selectors,
|
|
229
|
+
installData: this.installData,
|
|
230
|
+
hooks: this.hooks,
|
|
231
|
+
account: this.client.account,
|
|
232
|
+
};
|
|
233
|
+
}
|
|
234
|
+
validateConfiguration() {
|
|
235
|
+
if (this.validationConfig.isGlobal === false &&
|
|
236
|
+
this.selectors.length === 0) {
|
|
237
|
+
throw new Error("Validation config unset, use permissionBuilder.configure(...)");
|
|
238
|
+
}
|
|
239
|
+
}
|
|
240
|
+
// Used to translate consolidated permissions into raw unencoded hooks
|
|
241
|
+
// Note entityId will be a member object later
|
|
242
|
+
translatePermissions(entityId) {
|
|
243
|
+
const rawHooks = {
|
|
244
|
+
[HookIdentifier.NATIVE_TOKEN_TRANSFER]: undefined,
|
|
245
|
+
[HookIdentifier.ERC20_TOKEN_TRANSFER]: undefined,
|
|
246
|
+
[HookIdentifier.GAS_LIMIT]: undefined,
|
|
247
|
+
[HookIdentifier.PREVAL_ALLOWLIST]: undefined,
|
|
248
|
+
};
|
|
249
|
+
this.permissions.forEach((permission) => {
|
|
250
|
+
switch (permission.type) {
|
|
251
|
+
case PermissionType.NATIVE_TOKEN_TRANSFER:
|
|
252
|
+
// Should never be added twice, check is on addPermission(s) too
|
|
253
|
+
if (rawHooks[HookIdentifier.NATIVE_TOKEN_TRANSFER] !== undefined) {
|
|
254
|
+
throw new Error("PERMISSION: NATIVE_TOKEN_TRANSFER => Must have at most ONE native token transfer permission");
|
|
255
|
+
}
|
|
256
|
+
rawHooks[HookIdentifier.NATIVE_TOKEN_TRANSFER] = {
|
|
257
|
+
hookConfig: {
|
|
258
|
+
address: getDefaultNativeTokenLimitModuleAddress(this.client.chain),
|
|
259
|
+
entityId,
|
|
260
|
+
hookType: HookType.EXECUTION,
|
|
261
|
+
hasPreHooks: true,
|
|
262
|
+
hasPostHooks: false,
|
|
263
|
+
},
|
|
264
|
+
initData: {
|
|
265
|
+
entityId,
|
|
266
|
+
spendLimit: BigInt(permission.data.allowance),
|
|
267
|
+
},
|
|
268
|
+
};
|
|
269
|
+
this.hasAssociatedExecHooks = true;
|
|
270
|
+
break;
|
|
271
|
+
case PermissionType.ERC20_TOKEN_TRANSFER:
|
|
272
|
+
if (permission.data.address === zeroAddress) {
|
|
273
|
+
throw new Error("PERMISSION: ERC20_TOKEN_TRANSFER => Zero address provided");
|
|
274
|
+
}
|
|
275
|
+
rawHooks[HookIdentifier.ERC20_TOKEN_TRANSFER] = {
|
|
276
|
+
hookConfig: {
|
|
277
|
+
address: getDefaultAllowlistModuleAddress(this.client.chain),
|
|
278
|
+
entityId: entityId + HALF_UINT32,
|
|
279
|
+
hookType: HookType.EXECUTION,
|
|
280
|
+
hasPreHooks: true,
|
|
281
|
+
hasPostHooks: false,
|
|
282
|
+
},
|
|
283
|
+
initData: {
|
|
284
|
+
entityId: entityId + HALF_UINT32,
|
|
285
|
+
inputs: [
|
|
286
|
+
// Add previous inputs if they exist
|
|
287
|
+
...(rawHooks[HookIdentifier.ERC20_TOKEN_TRANSFER]?.initData
|
|
288
|
+
.inputs || []),
|
|
289
|
+
{
|
|
290
|
+
target: permission.data.address,
|
|
291
|
+
hasSelectorAllowlist: false,
|
|
292
|
+
hasERC20SpendLimit: true,
|
|
293
|
+
erc20SpendLimit: BigInt(permission.data.allowance),
|
|
294
|
+
selectors: [],
|
|
295
|
+
},
|
|
296
|
+
],
|
|
297
|
+
},
|
|
298
|
+
};
|
|
299
|
+
this.hasAssociatedExecHooks = true;
|
|
300
|
+
// Also allow `approve` and `transfer` for the erc20
|
|
301
|
+
rawHooks[HookIdentifier.PREVAL_ALLOWLIST] = {
|
|
302
|
+
hookConfig: {
|
|
303
|
+
address: getDefaultAllowlistModuleAddress(this.client.chain),
|
|
304
|
+
entityId,
|
|
305
|
+
hookType: HookType.VALIDATION,
|
|
306
|
+
hasPreHooks: true,
|
|
307
|
+
hasPostHooks: false,
|
|
308
|
+
},
|
|
309
|
+
initData: {
|
|
310
|
+
entityId,
|
|
311
|
+
inputs: [
|
|
312
|
+
// Add previous inputs if they exist
|
|
313
|
+
...(rawHooks[HookIdentifier.PREVAL_ALLOWLIST]?.initData
|
|
314
|
+
.inputs || []),
|
|
315
|
+
{
|
|
316
|
+
target: permission.data.address,
|
|
317
|
+
hasSelectorAllowlist: true,
|
|
318
|
+
hasERC20SpendLimit: false,
|
|
319
|
+
erc20SpendLimit: 0n,
|
|
320
|
+
selectors: [ERC20_APPROVE_SELECTOR, ERC20_TRANSFER_SELECTOR], // approve, transfer
|
|
321
|
+
},
|
|
322
|
+
],
|
|
323
|
+
},
|
|
324
|
+
};
|
|
325
|
+
break;
|
|
326
|
+
case PermissionType.GAS_LIMIT:
|
|
327
|
+
// Should only ever be added once, check is also on addPermission(s)
|
|
328
|
+
if (rawHooks[HookIdentifier.GAS_LIMIT] !== undefined) {
|
|
329
|
+
throw new Error("PERMISSION: GAS_LIMIT => Must have at most ONE gas limit permission");
|
|
330
|
+
}
|
|
331
|
+
rawHooks[HookIdentifier.GAS_LIMIT] = {
|
|
332
|
+
hookConfig: {
|
|
333
|
+
address: getDefaultNativeTokenLimitModuleAddress(this.client.chain),
|
|
334
|
+
entityId,
|
|
335
|
+
hookType: HookType.VALIDATION,
|
|
336
|
+
hasPreHooks: true,
|
|
337
|
+
hasPostHooks: false,
|
|
338
|
+
},
|
|
339
|
+
initData: {
|
|
340
|
+
entityId,
|
|
341
|
+
spendLimit: BigInt(permission.data.limit),
|
|
342
|
+
},
|
|
343
|
+
};
|
|
344
|
+
break;
|
|
345
|
+
case PermissionType.CONTRACT_ACCESS:
|
|
346
|
+
if (permission.data.address === zeroAddress) {
|
|
347
|
+
throw new Error("PERMISSION: CONTRACT_ACCESS => Zero address provided");
|
|
348
|
+
}
|
|
349
|
+
rawHooks[HookIdentifier.PREVAL_ALLOWLIST] = {
|
|
350
|
+
hookConfig: {
|
|
351
|
+
address: getDefaultAllowlistModuleAddress(this.client.chain),
|
|
352
|
+
entityId,
|
|
353
|
+
hookType: HookType.VALIDATION,
|
|
354
|
+
hasPreHooks: true,
|
|
355
|
+
hasPostHooks: false,
|
|
356
|
+
},
|
|
357
|
+
initData: {
|
|
358
|
+
entityId,
|
|
359
|
+
inputs: [
|
|
360
|
+
// Add previous inputs if they exist
|
|
361
|
+
...(rawHooks[HookIdentifier.PREVAL_ALLOWLIST]?.initData
|
|
362
|
+
.inputs || []),
|
|
363
|
+
{
|
|
364
|
+
target: permission.data.address,
|
|
365
|
+
hasSelectorAllowlist: false,
|
|
366
|
+
hasERC20SpendLimit: false,
|
|
367
|
+
erc20SpendLimit: 0n,
|
|
368
|
+
selectors: [],
|
|
369
|
+
},
|
|
370
|
+
],
|
|
371
|
+
},
|
|
372
|
+
};
|
|
373
|
+
break;
|
|
374
|
+
case PermissionType.ACCOUNT_FUNCTIONS:
|
|
375
|
+
if (permission.data.functions.length === 0) {
|
|
376
|
+
throw new Error("PERMISSION: ACCOUNT_FUNCTION => No functions provided"); // should be in add perm
|
|
377
|
+
}
|
|
378
|
+
break;
|
|
379
|
+
case PermissionType.FUNCTIONS_ON_ALL_CONTRACTS:
|
|
380
|
+
if (permission.data.functions.length === 0) {
|
|
381
|
+
throw new Error("PERMISSION: FUNCTIONS_ON_ALL_CONTRACTS => No functions provided");
|
|
382
|
+
}
|
|
383
|
+
rawHooks[HookIdentifier.PREVAL_ALLOWLIST] = {
|
|
384
|
+
hookConfig: {
|
|
385
|
+
address: getDefaultAllowlistModuleAddress(this.client.chain),
|
|
386
|
+
entityId,
|
|
387
|
+
hookType: HookType.VALIDATION,
|
|
388
|
+
hasPreHooks: true,
|
|
389
|
+
hasPostHooks: false,
|
|
390
|
+
},
|
|
391
|
+
initData: {
|
|
392
|
+
entityId,
|
|
393
|
+
inputs: [
|
|
394
|
+
// Add previous inputs if they exist
|
|
395
|
+
...(rawHooks[HookIdentifier.PREVAL_ALLOWLIST]?.initData
|
|
396
|
+
.inputs || []),
|
|
397
|
+
{
|
|
398
|
+
target: zeroAddress,
|
|
399
|
+
hasSelectorAllowlist: false,
|
|
400
|
+
hasERC20SpendLimit: false,
|
|
401
|
+
erc20SpendLimit: 0n,
|
|
402
|
+
selectors: permission.data.functions,
|
|
403
|
+
},
|
|
404
|
+
],
|
|
405
|
+
},
|
|
406
|
+
};
|
|
407
|
+
break;
|
|
408
|
+
case PermissionType.FUNCTIONS_ON_CONTRACT:
|
|
409
|
+
if (permission.data.functions.length === 0) {
|
|
410
|
+
throw new Error("PERMISSION: FUNCTIONS_ON_CONTRACT => No functions provided");
|
|
411
|
+
}
|
|
412
|
+
if (permission.data.address === zeroAddress) {
|
|
413
|
+
throw new Error("PERMISSION: FUNCTIONS_ON_CONTRACT => Zero address provided");
|
|
414
|
+
}
|
|
415
|
+
rawHooks[HookIdentifier.PREVAL_ALLOWLIST] = {
|
|
416
|
+
hookConfig: {
|
|
417
|
+
address: getDefaultAllowlistModuleAddress(this.client.chain),
|
|
418
|
+
entityId,
|
|
419
|
+
hookType: HookType.VALIDATION,
|
|
420
|
+
hasPreHooks: true,
|
|
421
|
+
hasPostHooks: false,
|
|
422
|
+
},
|
|
423
|
+
initData: {
|
|
424
|
+
entityId,
|
|
425
|
+
inputs: [
|
|
426
|
+
// Add previous inputs if they exist
|
|
427
|
+
...(rawHooks[HookIdentifier.PREVAL_ALLOWLIST]?.initData
|
|
428
|
+
.inputs || []),
|
|
429
|
+
{
|
|
430
|
+
target: permission.data.address,
|
|
431
|
+
hasSelectorAllowlist: true,
|
|
432
|
+
hasERC20SpendLimit: false,
|
|
433
|
+
erc20SpendLimit: 0n,
|
|
434
|
+
selectors: permission.data.functions,
|
|
435
|
+
},
|
|
436
|
+
],
|
|
437
|
+
},
|
|
438
|
+
};
|
|
439
|
+
break;
|
|
440
|
+
case PermissionType.ROOT:
|
|
441
|
+
// Root permission handled in addPermission
|
|
442
|
+
break;
|
|
443
|
+
default:
|
|
444
|
+
throw new Error(`Unsupported permission type: ${permission.type}`);
|
|
445
|
+
}
|
|
446
|
+
// isGlobal guaranteed to be false since it's only set with root permissions,
|
|
447
|
+
// we must add access to execute & executeBatch if there's a preVal allowlist hook set.
|
|
448
|
+
if (rawHooks[HookIdentifier.PREVAL_ALLOWLIST] !== undefined) {
|
|
449
|
+
const selectorsToAdd = [
|
|
450
|
+
ACCOUNT_EXECUTE_SELECTOR,
|
|
451
|
+
ACCOUNT_EXECUTEBATCH_SELECTOR,
|
|
452
|
+
]; // execute, executeBatch
|
|
453
|
+
// Only add the selectors if they aren't already in this.selectors
|
|
454
|
+
const newSelectors = selectorsToAdd.filter((selector) => !this.selectors.includes(selector));
|
|
455
|
+
this.selectors = [...this.selectors, ...newSelectors];
|
|
456
|
+
}
|
|
457
|
+
});
|
|
458
|
+
return rawHooks;
|
|
459
|
+
}
|
|
460
|
+
addHooks(rawHooks) {
|
|
461
|
+
if (rawHooks[HookIdentifier.NATIVE_TOKEN_TRANSFER]) {
|
|
462
|
+
this.hooks.push({
|
|
463
|
+
hookConfig: rawHooks[HookIdentifier.NATIVE_TOKEN_TRANSFER].hookConfig,
|
|
464
|
+
initData: NativeTokenLimitModule.encodeOnInstallData(rawHooks[HookIdentifier.NATIVE_TOKEN_TRANSFER].initData),
|
|
465
|
+
});
|
|
466
|
+
}
|
|
467
|
+
if (rawHooks[HookIdentifier.ERC20_TOKEN_TRANSFER]) {
|
|
468
|
+
this.hooks.push({
|
|
469
|
+
hookConfig: rawHooks[HookIdentifier.ERC20_TOKEN_TRANSFER].hookConfig,
|
|
470
|
+
initData: AllowlistModule.encodeOnInstallData(rawHooks[HookIdentifier.ERC20_TOKEN_TRANSFER].initData),
|
|
471
|
+
});
|
|
472
|
+
}
|
|
473
|
+
if (rawHooks[HookIdentifier.GAS_LIMIT]) {
|
|
474
|
+
this.hooks.push({
|
|
475
|
+
hookConfig: rawHooks[HookIdentifier.GAS_LIMIT].hookConfig,
|
|
476
|
+
initData: NativeTokenLimitModule.encodeOnInstallData(rawHooks[HookIdentifier.GAS_LIMIT].initData),
|
|
477
|
+
});
|
|
478
|
+
}
|
|
479
|
+
if (rawHooks[HookIdentifier.PREVAL_ALLOWLIST]) {
|
|
480
|
+
this.hooks.push({
|
|
481
|
+
hookConfig: rawHooks[HookIdentifier.PREVAL_ALLOWLIST].hookConfig,
|
|
482
|
+
initData: AllowlistModule.encodeOnInstallData(rawHooks[HookIdentifier.PREVAL_ALLOWLIST].initData),
|
|
483
|
+
});
|
|
484
|
+
}
|
|
485
|
+
}
|
|
486
|
+
}
|
|
487
|
+
//# sourceMappingURL=permissionBuilder.js.map
|