@account-kit/smart-contracts 4.24.0 → 4.25.1
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.js +4 -8
- package/dist/esm/src/ma-v2/account/common/modularAccountV2Base.js.map +1 -1
- package/dist/esm/src/ma-v2/actions/deferralActions.d.ts +0 -5
- package/dist/esm/src/ma-v2/actions/deferralActions.js +0 -20
- package/dist/esm/src/ma-v2/actions/deferralActions.js.map +1 -1
- package/dist/esm/src/ma-v2/index.d.ts +2 -1
- package/dist/esm/src/ma-v2/index.js +2 -1
- package/dist/esm/src/ma-v2/index.js.map +1 -1
- package/dist/esm/src/ma-v2/permissionBuilder.d.ts +7 -8
- package/dist/esm/src/ma-v2/permissionBuilder.js +43 -34
- package/dist/esm/src/ma-v2/permissionBuilder.js.map +1 -1
- package/dist/esm/src/ma-v2/permissionBuilderErrors.d.ts +99 -0
- package/dist/esm/src/ma-v2/permissionBuilderErrors.js +176 -0
- package/dist/esm/src/ma-v2/permissionBuilderErrors.js.map +1 -0
- package/dist/esm/src/ma-v2/utils.d.ts +20 -0
- package/dist/esm/src/ma-v2/utils.js +28 -1
- package/dist/esm/src/ma-v2/utils.js.map +1 -1
- package/dist/types/src/ma-v2/account/common/modularAccountV2Base.d.ts.map +1 -1
- package/dist/types/src/ma-v2/actions/deferralActions.d.ts +0 -5
- package/dist/types/src/ma-v2/actions/deferralActions.d.ts.map +1 -1
- package/dist/types/src/ma-v2/index.d.ts +2 -1
- package/dist/types/src/ma-v2/index.d.ts.map +1 -1
- package/dist/types/src/ma-v2/permissionBuilder.d.ts +7 -8
- package/dist/types/src/ma-v2/permissionBuilder.d.ts.map +1 -1
- package/dist/types/src/ma-v2/permissionBuilderErrors.d.ts +100 -0
- package/dist/types/src/ma-v2/permissionBuilderErrors.d.ts.map +1 -0
- package/dist/types/src/ma-v2/utils.d.ts +20 -0
- package/dist/types/src/ma-v2/utils.d.ts.map +1 -1
- package/package.json +5 -5
- package/src/ma-v2/account/common/modularAccountV2Base.ts +4 -8
- package/src/ma-v2/actions/deferralActions.ts +0 -31
- package/src/ma-v2/index.ts +2 -1
- package/src/ma-v2/permissionBuilder.ts +58 -78
- package/src/ma-v2/permissionBuilderErrors.ts +153 -0
- package/src/ma-v2/utils.ts +45 -0
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { createBundlerClient, getEntryPoint, InvalidEntityIdError, InvalidNonceKeyError, InvalidDeferredActionNonce,
|
|
2
|
-
import { DEFAULT_OWNER_ENTITY_ID } from "../../utils.js";
|
|
1
|
+
import { createBundlerClient, getEntryPoint, InvalidEntityIdError, InvalidNonceKeyError, InvalidDeferredActionNonce, toSmartContractAccount, } from "@aa-sdk/core";
|
|
2
|
+
import { DEFAULT_OWNER_ENTITY_ID, parseDeferredAction } from "../../utils.js";
|
|
3
3
|
import { encodeFunctionData, maxUint32, zeroAddress, getContract, concatHex, maxUint152, } from "viem";
|
|
4
4
|
import { modularAccountAbi } from "../../abis/modularAccountAbi.js";
|
|
5
5
|
import { serializeModuleEntity } from "../../actions/common/utils.js";
|
|
@@ -28,9 +28,8 @@ export async function createMAv2Base(config) {
|
|
|
28
28
|
let deferredActionData = "0x";
|
|
29
29
|
let hasAssociatedExecHooks = false;
|
|
30
30
|
if (deferredAction) {
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
}
|
|
31
|
+
({ nonce, deferredActionData, hasAssociatedExecHooks } =
|
|
32
|
+
parseDeferredAction(deferredAction));
|
|
34
33
|
// Set these values if the deferred action has not been consumed. We check this with the EP
|
|
35
34
|
const nextNonceForDeferredAction = (await entryPointContract.read.getNonce([
|
|
36
35
|
accountAddress,
|
|
@@ -38,10 +37,7 @@ export async function createMAv2Base(config) {
|
|
|
38
37
|
]));
|
|
39
38
|
// we only add the deferred action in if the nonce has not been consumed
|
|
40
39
|
if (nonce === nextNonceForDeferredAction) {
|
|
41
|
-
nonce = BigInt(`0x${deferredAction.slice(6, 70)}`);
|
|
42
40
|
useDeferredAction = true;
|
|
43
|
-
deferredActionData = `0x${deferredAction.slice(70)}`;
|
|
44
|
-
hasAssociatedExecHooks = deferredAction[5] === "1";
|
|
45
41
|
}
|
|
46
42
|
else if (nonce > nextNonceForDeferredAction) {
|
|
47
43
|
throw new InvalidDeferredActionNonce();
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"modularAccountV2Base.js","sourceRoot":"","sources":["../../../../../../src/ma-v2/account/common/modularAccountV2Base.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,mBAAmB,EACnB,aAAa,EACb,oBAAoB,EACpB,oBAAoB,EACpB,0BAA0B,EAC1B,yBAAyB,EACzB,sBAAsB,GAKvB,MAAM,cAAc,CAAC;AACtB,OAAO,EAAE,uBAAuB,EAAE,MAAM,gBAAgB,CAAC;AACzD,OAAO,EAKL,kBAAkB,EAClB,SAAS,EACT,WAAW,EACX,WAAW,EACX,SAAS,EACT,UAAU,GACX,MAAM,MAAM,CAAC;AACd,OAAO,EAAE,iBAAiB,EAAE,MAAM,iCAAiC,CAAC;AACpE,OAAO,EAAE,qBAAqB,EAAE,MAAM,+BAA+B,CAAC;AACtE,OAAO,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC;AACxD,OAAO,EAAE,yBAAyB,EAAE,MAAM,kDAAkD,CAAC;AAE7F,MAAM,CAAC,MAAM,qBAAqB,GAAQ,YAAY,CAAC;AAiEvD,MAAM,CAAC,KAAK,UAAU,cAAc,CAElC,MAAqC;IACrC,MAAM,EACJ,SAAS,EACT,KAAK,EACL,MAAM,EACN,UAAU,GAAG,aAAa,CAAC,KAAK,EAAE,EAAE,OAAO,EAAE,OAAO,EAAE,CAAC,EACvD,YAAY,GAAG;QACb,kBAAkB,EAAE,IAAI;QACxB,QAAQ,EAAE,uBAAuB;KAClC,EACD,YAAY,EAAE,EACZ,kBAAkB,GAAG,IAAI,EACzB,QAAQ,GAAG,uBAAuB,GACnC,GAAG,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CAAC,CAAC;IACL,CAAC,CAAC;IAEF,MAAM,cAAc,GAAG,KAAK,EAAE,QAAa,EAAgB,EAAE;QAC3D,MAAM,cAAc,GAAG,MAAM,iBAAiB,CAAC;YAC7C,QAAQ,EAAE,MAAM,CAAC,QAAQ,CAAC;SAC3B,CAAC,CAAC;QAEH,OAAO,CAAC,iBAAiB,IAAI,sBAAsB,CAAC;YAClD,cAAc,CAAC,cAAc,CAAC,MAAM;YACpC,CAAC,CAAC,SAAS,CAAC,CAAC,qBAAqB,EAAE,QAAQ,CAAC,CAAC;YAC9C,CAAC,CAAC,QAAQ,CAAC;IACf,CAAC,CAAC;IAEF,MAAM,WAAW,GAAG,MAAM,sBAAsB,CAAC;QAC/C,GAAG,qCAAqC;QACxC,SAAS;QACT,KAAK;QACL,UAAU;QACV,cAAc;QACd,aAAa;QACb,kBAAkB;QAClB,QAAQ;QACR,GAAG,CAAC,QAAQ,KAAK,uBAAuB;YACtC,CAAC,CAAC,eAAe,CAAC,MAAM,EAAE,KAAK,EAAE,cAAc,EAAE,kBAAkB,CAAC;YACpE,CAAC,CAAC,yBAAyB,CACvB,MAAM,EACN,KAAK,EACL,cAAc,EACd,QAAQ,EACR,kBAAkB,CACnB,CAAC;KACP,CAAC,CAAC;IAEH,OAAO;QACL,GAAG,WAAW;QACd,SAAS,EAAE,GAAG,EAAE,CAAC,MAAM;QACvB,YAAY;QACZ,gBAAgB;QAChB,iBAAiB;QACjB,cAAc;KACf,CAAC;AACJ,CAAC","sourcesContent":["import {\n createBundlerClient,\n getEntryPoint,\n InvalidEntityIdError,\n InvalidNonceKeyError,\n InvalidDeferredActionNonce,\n InvalidDeferredActionMode,\n toSmartContractAccount,\n type AccountOp,\n type SmartAccountSigner,\n type SmartContractAccountWithSigner,\n type ToSmartContractAccountParams,\n} from \"@aa-sdk/core\";\nimport { DEFAULT_OWNER_ENTITY_ID } from \"../../utils.js\";\nimport {\n type Hex,\n type Address,\n type Chain,\n type Transport,\n encodeFunctionData,\n maxUint32,\n zeroAddress,\n getContract,\n concatHex,\n maxUint152,\n} from \"viem\";\nimport { modularAccountAbi } from \"../../abis/modularAccountAbi.js\";\nimport { serializeModuleEntity } from \"../../actions/common/utils.js\";\nimport { nativeSMASigner } from \"../nativeSMASigner.js\";\nimport { singleSignerMessageSigner } from \"../../modules/single-signer-validation/signer.js\";\n\nexport const executeUserOpSelector: Hex = \"0x8DD7712F\";\n\nexport type SignerEntity = {\n isGlobalValidation: boolean;\n entityId: number;\n};\n\nexport type ExecutionDataView = {\n module: Address;\n skipRuntimeValidation: boolean;\n allowGlobalValidation: boolean;\n executionHooks: readonly Hex[];\n};\n\nexport type ValidationDataView = {\n validationHooks: readonly Hex[];\n executionHooks: readonly Hex[];\n selectors: readonly Hex[];\n validationFlags: number;\n};\n\nexport type ValidationDataParams =\n | {\n validationModuleAddress: Address;\n entityId?: never;\n }\n | {\n validationModuleAddress?: never;\n entityId: number;\n };\n\nexport type ModularAccountV2<\n TSigner extends SmartAccountSigner = SmartAccountSigner\n> = SmartContractAccountWithSigner<\"ModularAccountV2\", TSigner, \"0.7.0\"> & {\n signerEntity: SignerEntity;\n getExecutionData: (selector: Hex) => Promise<ExecutionDataView>;\n getValidationData: (\n args: ValidationDataParams\n ) => Promise<ValidationDataView>;\n encodeCallData: (callData: Hex) => Promise<Hex>;\n};\n\nexport type CreateMAV2BaseParams<\n TSigner extends SmartAccountSigner = SmartAccountSigner,\n TTransport extends Transport = Transport\n> = Omit<\n ToSmartContractAccountParams<\"ModularAccountV2\", TTransport, Chain, \"0.7.0\">,\n // Implements the following methods required by `toSmartContractAccount`, and passes through any other parameters.\n | \"encodeExecute\"\n | \"encodeBatchExecute\"\n | \"getNonce\"\n | \"signMessage\"\n | \"signTypedData\"\n | \"getDummySignature\"\n> & {\n signer: TSigner;\n signerEntity?: SignerEntity;\n accountAddress: Address;\n deferredAction?: Hex;\n};\n\nexport type CreateMAV2BaseReturnType<\n TSigner extends SmartAccountSigner = SmartAccountSigner\n> = Promise<ModularAccountV2<TSigner>>;\n\nexport async function createMAv2Base<\n TSigner extends SmartAccountSigner = SmartAccountSigner\n>(config: CreateMAV2BaseParams<TSigner>): CreateMAV2BaseReturnType<TSigner> {\n const {\n transport,\n chain,\n signer,\n entryPoint = getEntryPoint(chain, { version: \"0.7.0\" }),\n signerEntity = {\n isGlobalValidation: true,\n entityId: DEFAULT_OWNER_ENTITY_ID,\n },\n signerEntity: {\n isGlobalValidation = true,\n entityId = DEFAULT_OWNER_ENTITY_ID,\n } = {},\n accountAddress,\n deferredAction,\n ...remainingToSmartContractAccountParams\n } = config;\n\n if (entityId > Number(maxUint32)) {\n throw new InvalidEntityIdError(entityId);\n }\n\n const client = createBundlerClient({\n transport,\n chain,\n });\n\n const entryPointContract = getContract({\n address: entryPoint.address,\n abi: entryPoint.abi,\n client,\n });\n\n let useDeferredAction: boolean = false;\n let nonce: bigint = 0n;\n let deferredActionData: Hex = \"0x\";\n let hasAssociatedExecHooks: boolean = false;\n\n if (deferredAction) {\n if (deferredAction.slice(2, 4) !== \"00\") {\n throw new InvalidDeferredActionMode();\n }\n // Set these values if the deferred action has not been consumed. We check this with the EP\n const nextNonceForDeferredAction: bigint =\n (await entryPointContract.read.getNonce([\n accountAddress,\n nonce >> 64n,\n ])) as bigint;\n\n // we only add the deferred action in if the nonce has not been consumed\n if (nonce === nextNonceForDeferredAction) {\n nonce = BigInt(`0x${deferredAction.slice(6, 70)}`);\n useDeferredAction = true;\n deferredActionData = `0x${deferredAction.slice(70)}`;\n hasAssociatedExecHooks = deferredAction[5] === \"1\";\n } else if (nonce > nextNonceForDeferredAction) {\n throw new InvalidDeferredActionNonce();\n }\n }\n\n const encodeExecute: (tx: AccountOp) => Promise<Hex> = async ({\n target,\n data,\n value,\n }) =>\n await encodeCallData(\n encodeFunctionData({\n abi: modularAccountAbi,\n functionName: \"execute\",\n args: [target, value ?? 0n, data],\n })\n );\n\n const encodeBatchExecute: (txs: AccountOp[]) => Promise<Hex> = async (txs) =>\n await encodeCallData(\n encodeFunctionData({\n abi: modularAccountAbi,\n functionName: \"executeBatch\",\n args: [\n txs.map((tx) => ({\n target: tx.target,\n data: tx.data,\n value: tx.value ?? 0n,\n })),\n ],\n })\n );\n\n const isAccountDeployed: () => Promise<boolean> = async () =>\n !!(await client.getCode({ address: accountAddress }));\n\n const getNonce = async (nonceKey: bigint = 0n): Promise<bigint> => {\n if (useDeferredAction) {\n return nonce;\n }\n\n if (nonceKey > maxUint152) {\n throw new InvalidNonceKeyError(nonceKey);\n }\n\n const fullNonceKey: bigint =\n (nonceKey << 40n) +\n (BigInt(entityId) << 8n) +\n (isGlobalValidation ? 1n : 0n);\n\n return entryPointContract.read.getNonce([\n accountAddress,\n fullNonceKey,\n ]) as Promise<bigint>;\n };\n\n const accountContract = getContract({\n address: accountAddress,\n abi: modularAccountAbi,\n client,\n });\n\n const getExecutionData = async (selector: Hex) => {\n if (!(await isAccountDeployed())) {\n return {\n module: zeroAddress,\n skipRuntimeValidation: false,\n allowGlobalValidation: false,\n executionHooks: [],\n };\n }\n\n return await accountContract.read.getExecutionData([selector]);\n };\n\n const getValidationData = async (args: ValidationDataParams) => {\n if (!(await isAccountDeployed())) {\n return {\n validationHooks: [],\n executionHooks: [],\n selectors: [],\n validationFlags: 0,\n };\n }\n\n const { validationModuleAddress, entityId } = args;\n return await accountContract.read.getValidationData([\n serializeModuleEntity({\n moduleAddress: validationModuleAddress ?? zeroAddress,\n entityId: entityId ?? Number(maxUint32),\n }),\n ]);\n };\n\n const encodeCallData = async (callData: Hex): Promise<Hex> => {\n const validationData = await getValidationData({\n entityId: Number(entityId),\n });\n\n return (useDeferredAction && hasAssociatedExecHooks) ||\n validationData.executionHooks.length\n ? concatHex([executeUserOpSelector, callData])\n : callData;\n };\n\n const baseAccount = await toSmartContractAccount({\n ...remainingToSmartContractAccountParams,\n transport,\n chain,\n entryPoint,\n accountAddress,\n encodeExecute,\n encodeBatchExecute,\n getNonce,\n ...(entityId === DEFAULT_OWNER_ENTITY_ID\n ? nativeSMASigner(signer, chain, accountAddress, deferredActionData)\n : singleSignerMessageSigner(\n signer,\n chain,\n accountAddress,\n entityId,\n deferredActionData\n )),\n });\n\n return {\n ...baseAccount,\n getSigner: () => signer,\n signerEntity,\n getExecutionData,\n getValidationData,\n encodeCallData,\n };\n}\n"]}
|
|
1
|
+
{"version":3,"file":"modularAccountV2Base.js","sourceRoot":"","sources":["../../../../../../src/ma-v2/account/common/modularAccountV2Base.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,mBAAmB,EACnB,aAAa,EACb,oBAAoB,EACpB,oBAAoB,EACpB,0BAA0B,EAC1B,sBAAsB,GAKvB,MAAM,cAAc,CAAC;AACtB,OAAO,EAAE,uBAAuB,EAAE,mBAAmB,EAAE,MAAM,gBAAgB,CAAC;AAC9E,OAAO,EAKL,kBAAkB,EAClB,SAAS,EACT,WAAW,EACX,WAAW,EACX,SAAS,EACT,UAAU,GACX,MAAM,MAAM,CAAC;AACd,OAAO,EAAE,iBAAiB,EAAE,MAAM,iCAAiC,CAAC;AACpE,OAAO,EAAE,qBAAqB,EAAE,MAAM,+BAA+B,CAAC;AACtE,OAAO,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC;AACxD,OAAO,EAAE,yBAAyB,EAAE,MAAM,kDAAkD,CAAC;AAE7F,MAAM,CAAC,MAAM,qBAAqB,GAAQ,YAAY,CAAC;AAiEvD,MAAM,CAAC,KAAK,UAAU,cAAc,CAElC,MAAqC;IACrC,MAAM,EACJ,SAAS,EACT,KAAK,EACL,MAAM,EACN,UAAU,GAAG,aAAa,CAAC,KAAK,EAAE,EAAE,OAAO,EAAE,OAAO,EAAE,CAAC,EACvD,YAAY,GAAG;QACb,kBAAkB,EAAE,IAAI;QACxB,QAAQ,EAAE,uBAAuB;KAClC,EACD,YAAY,EAAE,EACZ,kBAAkB,GAAG,IAAI,EACzB,QAAQ,GAAG,uBAAuB,GACnC,GAAG,EAAE,EACN,cAAc,EACd,cAAc,EACd,GAAG,qCA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AAC,qBAAqB,EAAE,QAAQ,CAAC,CAAC;YAC9C,CAAC,CAAC,QAAQ,CAAC;IACf,CAAC,CAAC;IAEF,MAAM,WAAW,GAAG,MAAM,sBAAsB,CAAC;QAC/C,GAAG,qCAAqC;QACxC,SAAS;QACT,KAAK;QACL,UAAU;QACV,cAAc;QACd,aAAa;QACb,kBAAkB;QAClB,QAAQ;QACR,GAAG,CAAC,QAAQ,KAAK,uBAAuB;YACtC,CAAC,CAAC,eAAe,CAAC,MAAM,EAAE,KAAK,EAAE,cAAc,EAAE,kBAAkB,CAAC;YACpE,CAAC,CAAC,yBAAyB,CACvB,MAAM,EACN,KAAK,EACL,cAAc,EACd,QAAQ,EACR,kBAAkB,CACnB,CAAC;KACP,CAAC,CAAC;IAEH,OAAO;QACL,GAAG,WAAW;QACd,SAAS,EAAE,GAAG,EAAE,CAAC,MAAM;QACvB,YAAY;QACZ,gBAAgB;QAChB,iBAAiB;QACjB,cAAc;KACf,CAAC;AACJ,CAAC","sourcesContent":["import {\n createBundlerClient,\n getEntryPoint,\n InvalidEntityIdError,\n InvalidNonceKeyError,\n InvalidDeferredActionNonce,\n toSmartContractAccount,\n type AccountOp,\n type SmartAccountSigner,\n type SmartContractAccountWithSigner,\n type ToSmartContractAccountParams,\n} from \"@aa-sdk/core\";\nimport { DEFAULT_OWNER_ENTITY_ID, parseDeferredAction } from \"../../utils.js\";\nimport {\n type Hex,\n type Address,\n type Chain,\n type Transport,\n encodeFunctionData,\n maxUint32,\n zeroAddress,\n getContract,\n concatHex,\n maxUint152,\n} from \"viem\";\nimport { modularAccountAbi } from \"../../abis/modularAccountAbi.js\";\nimport { serializeModuleEntity } from \"../../actions/common/utils.js\";\nimport { nativeSMASigner } from \"../nativeSMASigner.js\";\nimport { singleSignerMessageSigner } from \"../../modules/single-signer-validation/signer.js\";\n\nexport const executeUserOpSelector: Hex = \"0x8DD7712F\";\n\nexport type SignerEntity = {\n isGlobalValidation: boolean;\n entityId: number;\n};\n\nexport type ExecutionDataView = {\n module: Address;\n skipRuntimeValidation: boolean;\n allowGlobalValidation: boolean;\n executionHooks: readonly Hex[];\n};\n\nexport type ValidationDataView = {\n validationHooks: readonly Hex[];\n executionHooks: readonly Hex[];\n selectors: readonly Hex[];\n validationFlags: number;\n};\n\nexport type ValidationDataParams =\n | {\n validationModuleAddress: Address;\n entityId?: never;\n }\n | {\n validationModuleAddress?: never;\n entityId: number;\n };\n\nexport type ModularAccountV2<\n TSigner extends SmartAccountSigner = SmartAccountSigner\n> = SmartContractAccountWithSigner<\"ModularAccountV2\", TSigner, \"0.7.0\"> & {\n signerEntity: SignerEntity;\n getExecutionData: (selector: Hex) => Promise<ExecutionDataView>;\n getValidationData: (\n args: ValidationDataParams\n ) => Promise<ValidationDataView>;\n encodeCallData: (callData: Hex) => Promise<Hex>;\n};\n\nexport type CreateMAV2BaseParams<\n TSigner extends SmartAccountSigner = SmartAccountSigner,\n TTransport extends Transport = Transport\n> = Omit<\n ToSmartContractAccountParams<\"ModularAccountV2\", TTransport, Chain, \"0.7.0\">,\n // Implements the following methods required by `toSmartContractAccount`, and passes through any other parameters.\n | \"encodeExecute\"\n | \"encodeBatchExecute\"\n | \"getNonce\"\n | \"signMessage\"\n | \"signTypedData\"\n | \"getDummySignature\"\n> & {\n signer: TSigner;\n signerEntity?: SignerEntity;\n accountAddress: Address;\n deferredAction?: Hex;\n};\n\nexport type CreateMAV2BaseReturnType<\n TSigner extends SmartAccountSigner = SmartAccountSigner\n> = Promise<ModularAccountV2<TSigner>>;\n\nexport async function createMAv2Base<\n TSigner extends SmartAccountSigner = SmartAccountSigner\n>(config: CreateMAV2BaseParams<TSigner>): CreateMAV2BaseReturnType<TSigner> {\n const {\n transport,\n chain,\n signer,\n entryPoint = getEntryPoint(chain, { version: \"0.7.0\" }),\n signerEntity = {\n isGlobalValidation: true,\n entityId: DEFAULT_OWNER_ENTITY_ID,\n },\n signerEntity: {\n isGlobalValidation = true,\n entityId = DEFAULT_OWNER_ENTITY_ID,\n } = {},\n accountAddress,\n deferredAction,\n ...remainingToSmartContractAccountParams\n } = config;\n\n if (entityId > Number(maxUint32)) {\n throw new InvalidEntityIdError(entityId);\n }\n\n const client = createBundlerClient({\n transport,\n chain,\n });\n\n const entryPointContract = getContract({\n address: entryPoint.address,\n abi: entryPoint.abi,\n client,\n });\n\n let useDeferredAction: boolean = false;\n let nonce: bigint = 0n;\n let deferredActionData: Hex = \"0x\";\n let hasAssociatedExecHooks: boolean = false;\n\n if (deferredAction) {\n ({ nonce, deferredActionData, hasAssociatedExecHooks } =\n parseDeferredAction(deferredAction));\n\n // Set these values if the deferred action has not been consumed. We check this with the EP\n const nextNonceForDeferredAction: bigint =\n (await entryPointContract.read.getNonce([\n accountAddress,\n nonce >> 64n,\n ])) as bigint;\n\n // we only add the deferred action in if the nonce has not been consumed\n if (nonce === nextNonceForDeferredAction) {\n useDeferredAction = true;\n } else if (nonce > nextNonceForDeferredAction) {\n throw new InvalidDeferredActionNonce();\n }\n }\n\n const encodeExecute: (tx: AccountOp) => Promise<Hex> = async ({\n target,\n data,\n value,\n }) =>\n await encodeCallData(\n encodeFunctionData({\n abi: modularAccountAbi,\n functionName: \"execute\",\n args: [target, value ?? 0n, data],\n })\n );\n\n const encodeBatchExecute: (txs: AccountOp[]) => Promise<Hex> = async (txs) =>\n await encodeCallData(\n encodeFunctionData({\n abi: modularAccountAbi,\n functionName: \"executeBatch\",\n args: [\n txs.map((tx) => ({\n target: tx.target,\n data: tx.data,\n value: tx.value ?? 0n,\n })),\n ],\n })\n );\n\n const isAccountDeployed: () => Promise<boolean> = async () =>\n !!(await client.getCode({ address: accountAddress }));\n\n const getNonce = async (nonceKey: bigint = 0n): Promise<bigint> => {\n if (useDeferredAction) {\n return nonce;\n }\n\n if (nonceKey > maxUint152) {\n throw new InvalidNonceKeyError(nonceKey);\n }\n\n const fullNonceKey: bigint =\n (nonceKey << 40n) +\n (BigInt(entityId) << 8n) +\n (isGlobalValidation ? 1n : 0n);\n\n return entryPointContract.read.getNonce([\n accountAddress,\n fullNonceKey,\n ]) as Promise<bigint>;\n };\n\n const accountContract = getContract({\n address: accountAddress,\n abi: modularAccountAbi,\n client,\n });\n\n const getExecutionData = async (selector: Hex) => {\n if (!(await isAccountDeployed())) {\n return {\n module: zeroAddress,\n skipRuntimeValidation: false,\n allowGlobalValidation: false,\n executionHooks: [],\n };\n }\n\n return await accountContract.read.getExecutionData([selector]);\n };\n\n const getValidationData = async (args: ValidationDataParams) => {\n if (!(await isAccountDeployed())) {\n return {\n validationHooks: [],\n executionHooks: [],\n selectors: [],\n validationFlags: 0,\n };\n }\n\n const { validationModuleAddress, entityId } = args;\n return await accountContract.read.getValidationData([\n serializeModuleEntity({\n moduleAddress: validationModuleAddress ?? zeroAddress,\n entityId: entityId ?? Number(maxUint32),\n }),\n ]);\n };\n\n const encodeCallData = async (callData: Hex): Promise<Hex> => {\n const validationData = await getValidationData({\n entityId: Number(entityId),\n });\n\n return (useDeferredAction && hasAssociatedExecHooks) ||\n validationData.executionHooks.length\n ? concatHex([executeUserOpSelector, callData])\n : callData;\n };\n\n const baseAccount = await toSmartContractAccount({\n ...remainingToSmartContractAccountParams,\n transport,\n chain,\n entryPoint,\n accountAddress,\n encodeExecute,\n encodeBatchExecute,\n getNonce,\n ...(entityId === DEFAULT_OWNER_ENTITY_ID\n ? nativeSMASigner(signer, chain, accountAddress, deferredActionData)\n : singleSignerMessageSigner(\n signer,\n chain,\n accountAddress,\n entityId,\n deferredActionData\n )),\n });\n\n return {\n ...baseAccount,\n getSigner: () => signer,\n signerEntity,\n getExecutionData,\n getValidationData,\n encodeCallData,\n };\n}\n"]}
|
|
@@ -37,10 +37,6 @@ export type CreateDeferredActionTypedDataParams = {
|
|
|
37
37
|
deadline: number;
|
|
38
38
|
nonce: bigint;
|
|
39
39
|
};
|
|
40
|
-
export type BuildDeferredActionDigestParams = {
|
|
41
|
-
fullPreSignatureDeferredActionDigest: Hex;
|
|
42
|
-
sig: Hex;
|
|
43
|
-
};
|
|
44
40
|
export type BuildPreSignatureDeferredActionDigestParams = {
|
|
45
41
|
typedData: DeferredActionTypedData;
|
|
46
42
|
};
|
|
@@ -57,7 +53,6 @@ export type EntityIdAndNonceParams = {
|
|
|
57
53
|
};
|
|
58
54
|
export type DeferralActions = {
|
|
59
55
|
createDeferredActionTypedDataObject: (args: CreateDeferredActionTypedDataParams) => Promise<DeferredActionReturnData>;
|
|
60
|
-
buildDeferredActionDigest: (args: BuildDeferredActionDigestParams) => Hex;
|
|
61
56
|
buildPreSignatureDeferredActionDigest: (args: BuildPreSignatureDeferredActionDigestParams) => Hex;
|
|
62
57
|
buildUserOperationWithDeferredAction: (args: BuildUserOperationWithDeferredActionParams) => Promise<UserOperationRequest_v7>;
|
|
63
58
|
getEntityIdAndNonce: (args: EntityIdAndNonceParams) => Promise<{
|
|
@@ -39,25 +39,6 @@ export const deferralActions = (client) => {
|
|
|
39
39
|
},
|
|
40
40
|
};
|
|
41
41
|
};
|
|
42
|
-
/**
|
|
43
|
-
* Creates the digest which must be prepended to the userOp signature.
|
|
44
|
-
*
|
|
45
|
-
* Assumption: The client this extends is used to sign the typed data.
|
|
46
|
-
*
|
|
47
|
-
* @param {object} args The argument object containing the following:
|
|
48
|
-
* @param {Hex} args.fullPreSignatureDeferredActionDigest The The data to append the signature and length to
|
|
49
|
-
* @param {Hex} args.sig The signature to include in the digest
|
|
50
|
-
* @returns {Hex} The encoded digest to be prepended to the userOp signature
|
|
51
|
-
*/
|
|
52
|
-
const buildDeferredActionDigest = ({ fullPreSignatureDeferredActionDigest, sig, }) => {
|
|
53
|
-
const sigLength = size(sig);
|
|
54
|
-
const encodedData = concatHex([
|
|
55
|
-
fullPreSignatureDeferredActionDigest,
|
|
56
|
-
toHex(sigLength, { size: 4 }),
|
|
57
|
-
sig,
|
|
58
|
-
]);
|
|
59
|
-
return encodedData;
|
|
60
|
-
};
|
|
61
42
|
const buildPreSignatureDeferredActionDigest = ({ typedData, }) => {
|
|
62
43
|
const signerEntity = client.account.signerEntity;
|
|
63
44
|
const validationLocator = (BigInt(signerEntity.entityId) << 8n) |
|
|
@@ -138,7 +119,6 @@ export const deferralActions = (client) => {
|
|
|
138
119
|
};
|
|
139
120
|
return {
|
|
140
121
|
createDeferredActionTypedDataObject,
|
|
141
|
-
buildDeferredActionDigest,
|
|
142
122
|
buildPreSignatureDeferredActionDigest,
|
|
143
123
|
buildUserOperationWithDeferredAction,
|
|
144
124
|
getEntityIdAndNonce,
|
|
@@ -1 +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,MAAM,cAAc,CAAC;AACtB,OAAO,EAGL,SAAS,EACT,UAAU,EACV,YAAY,EACZ,IAAI,EACJ,KAAK,EACL,gBAAgB,EAChB,WAAW,GACZ,MAAM,MAAM,CAAC;AACd,OAAO,EAAE,8BAA8B,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAC;AAChF,OAAO,EAAE,yBAAyB,EAAE,MAAM,mCAAmC,CAAC;AAuE9E;;;;;GAKG;AACH,MAAM,CAAC,MAAM,eAAe,GAEL,CAAC,MAA8B,EAAmB,EAAE;IACzE,MAAM,mCAAmC,GAAG,KAAK,EAAE,EACjD,QAAQ,EACR,QAAQ,EACR,KAAK,GAC+B,EAAqC,EAAE;QAC3E,IAAI,CAAC,MAAM,CAAC,OAAO,EAAE,CAAC;YACpB,MAAM,IAAI,oBAAoB,EAAE,CAAC;QACnC,CAAC;QAED,MAAM,UAAU,GAAG,MAAM,CAAC,OAAO,CAAC,aAAa,EAAE,CAAC;QAClD,IAAI,UAAU,KAAK,SAAS,EAAE,CAAC;YAC7B,MAAM,IAAI,uBAAuB,CAAC,MAAM,CAAC,KAAK,EAAE,OAAO,CAAC,CAAC;QAC3D,CAAC;QAED,OAAO;YACL,SAAS,EAAE;gBACT,MAAM,EAAE;o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AqC;QACrC,oCAAoC;QACpC,mBAAmB;KACpB,CAAC;AACJ,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 encodePacked,\n size,\n toHex,\n encodeDeployData,\n hexToNumber,\n} from \"viem\";\nimport { entityIdAndNonceReaderBytecode, buildFullNonceKey } from \"../utils.js\";\nimport { entityIdAndNonceReaderAbi } from \"../abis/entityIdAndNonceReader.js\";\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};\n\nexport type CreateDeferredActionTypedDataParams = {\n callData: Hex;\n deadline: number;\n nonce: bigint;\n};\n\nexport type BuildDeferredActionDigestParams = {\n fullPreSignatureDeferredActionDigest: Hex;\n sig: Hex;\n};\n\nexport type BuildPreSignatureDeferredActionDigestParams = {\n typedData: DeferredActionTypedData;\n};\n\nexport type BuildUserOperationWithDeferredActionParams = {\n uo: UserOperationCallData | BatchUserOperationCallData;\n signaturePrepend: Hex;\n nonceOverride: bigint;\n};\n\nexport type EntityIdAndNonceParams = {\n entityId?: number;\n nonceKey?: bigint;\n isGlobalValidation: boolean;\n isDeferredAction?: boolean;\n};\n\nexport type DeferralActions = {\n createDeferredActionTypedDataObject: (\n args: CreateDeferredActionTypedDataParams\n ) => Promise<DeferredActionReturnData>;\n buildDeferredActionDigest: (args: BuildDeferredActionDigestParams) => Hex;\n buildPreSignatureDeferredActionDigest: (\n args: BuildPreSignatureDeferredActionDigestParams\n ) => Hex;\n buildUserOperationWithDeferredAction: (\n args: BuildUserOperationWithDeferredActionParams\n ) => Promise<UserOperationRequest_v7>;\n getEntityIdAndNonce: (\n args: EntityIdAndNonceParams\n ) => Promise<{ nonce: bigint; entityId: number }>;\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 nonce,\n }: CreateDeferredActionTypedDataParams): Promise<DeferredActionReturnData> => {\n if (!client.account) {\n throw new AccountNotFoundError();\n }\n\n const entryPoint = client.account.getEntryPoint();\n if (entryPoint === undefined) {\n throw new EntryPointNotFoundError(client.chain, \"0.7.0\");\n }\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: nonce,\n deadline: deadline,\n call: callData,\n },\n },\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 {Hex} args.fullPreSignatureDeferredActionDigest The The data to append the signature and length to\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 fullPreSignatureDeferredActionDigest,\n sig,\n }: BuildDeferredActionDigestParams): Hex => {\n const sigLength = size(sig);\n\n const encodedData = concatHex([\n fullPreSignatureDeferredActionDigest,\n toHex(sigLength, { size: 4 }),\n sig,\n ]);\n return encodedData;\n };\n\n const buildPreSignatureDeferredActionDigest = ({\n typedData,\n }: BuildPreSignatureDeferredActionDigestParams): Hex => {\n const signerEntity = client.account.signerEntity;\n const validationLocator =\n (BigInt(signerEntity.entityId) << 8n) |\n (signerEntity.isGlobalValidation ? 1n : 0n);\n\n const encodedCallData = encodePacked(\n [\"uint168\", \"uint48\", \"bytes\"],\n [validationLocator, typedData.message.deadline, typedData.message.call]\n );\n\n const encodedDataLength = size(encodedCallData);\n const encodedData = concatHex([\n toHex(encodedDataLength, { size: 4 }),\n encodedCallData,\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 const getEntityIdAndNonce = async ({\n entityId = 1,\n nonceKey = 0n,\n isGlobalValidation,\n isDeferredAction = true,\n }: EntityIdAndNonceParams) => {\n if (!client.account) {\n throw new AccountNotFoundError();\n }\n\n if (nonceKey > maxUint152) {\n throw new InvalidNonceKeyError(nonceKey);\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 bytecode = encodeDeployData({\n abi: entityIdAndNonceReaderAbi,\n bytecode: entityIdAndNonceReaderBytecode,\n args: [\n client.account.address,\n entryPoint.address,\n buildFullNonceKey({\n nonceKey,\n entityId,\n isGlobalValidation,\n isDeferredAction,\n }),\n ],\n });\n\n const { data } = await client.call({ data: bytecode });\n if (!data) {\n throw new Error(\"No data returned from contract call\");\n }\n\n return {\n nonce: BigInt(data),\n entityId: hexToNumber(`0x${data.slice(40, 48)}`),\n };\n };\n\n return {\n createDeferredActionTypedDataObject,\n buildDeferredActionDigest,\n buildPreSignatureDeferredActionDigest,\n buildUserOperationWithDeferredAction,\n getEntityIdAndNonce,\n };\n};\n"]}
|
|
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,MAAM,cAAc,CAAC;AACtB,OAAO,EAGL,SAAS,EACT,UAAU,EACV,YAAY,EACZ,IAAI,EACJ,KAAK,EACL,gBAAgB,EAChB,WAAW,GACZ,MAAM,MAAM,CAAC;AACd,OAAO,EAAE,8BAA8B,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAC;AAChF,OAAO,EAAE,yBAAyB,EAAE,MAAM,mCAAmC,CAAC;AAiE9E;;;;;GAKG;AACH,MAAM,CAAC,MAAM,eAAe,GAEL,CAAC,MAA8B,EAAmB,EAAE;IACzE,MAAM,mCAAmC,GAAG,KAAK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,CAAC,CAAC;IAEF,OAAO;QACL,mCAAmC;QACnC,qCAAqC;QACrC,oCAAoC;QACpC,mBAAmB;KACpB,CAAC;AACJ,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 encodePacked,\n size,\n toHex,\n encodeDeployData,\n hexToNumber,\n} from \"viem\";\nimport { entityIdAndNonceReaderBytecode, buildFullNonceKey } from \"../utils.js\";\nimport { entityIdAndNonceReaderAbi } from \"../abis/entityIdAndNonceReader.js\";\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};\n\nexport type CreateDeferredActionTypedDataParams = {\n callData: Hex;\n deadline: number;\n nonce: bigint;\n};\n\nexport type BuildPreSignatureDeferredActionDigestParams = {\n typedData: DeferredActionTypedData;\n};\n\nexport type BuildUserOperationWithDeferredActionParams = {\n uo: UserOperationCallData | BatchUserOperationCallData;\n signaturePrepend: Hex;\n nonceOverride: bigint;\n};\n\nexport type EntityIdAndNonceParams = {\n entityId?: number;\n nonceKey?: bigint;\n isGlobalValidation: boolean;\n isDeferredAction?: boolean;\n};\n\nexport type DeferralActions = {\n createDeferredActionTypedDataObject: (\n args: CreateDeferredActionTypedDataParams\n ) => Promise<DeferredActionReturnData>;\n buildPreSignatureDeferredActionDigest: (\n args: BuildPreSignatureDeferredActionDigestParams\n ) => Hex;\n buildUserOperationWithDeferredAction: (\n args: BuildUserOperationWithDeferredActionParams\n ) => Promise<UserOperationRequest_v7>;\n getEntityIdAndNonce: (\n args: EntityIdAndNonceParams\n ) => Promise<{ nonce: bigint; entityId: number }>;\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 nonce,\n }: CreateDeferredActionTypedDataParams): Promise<DeferredActionReturnData> => {\n if (!client.account) {\n throw new AccountNotFoundError();\n }\n\n const entryPoint = client.account.getEntryPoint();\n if (entryPoint === undefined) {\n throw new EntryPointNotFoundError(client.chain, \"0.7.0\");\n }\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: nonce,\n deadline: deadline,\n call: callData,\n },\n },\n };\n };\n\n const buildPreSignatureDeferredActionDigest = ({\n typedData,\n }: BuildPreSignatureDeferredActionDigestParams): Hex => {\n const signerEntity = client.account.signerEntity;\n const validationLocator =\n (BigInt(signerEntity.entityId) << 8n) |\n (signerEntity.isGlobalValidation ? 1n : 0n);\n\n const encodedCallData = encodePacked(\n [\"uint168\", \"uint48\", \"bytes\"],\n [validationLocator, typedData.message.deadline, typedData.message.call]\n );\n\n const encodedDataLength = size(encodedCallData);\n const encodedData = concatHex([\n toHex(encodedDataLength, { size: 4 }),\n encodedCallData,\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 const getEntityIdAndNonce = async ({\n entityId = 1,\n nonceKey = 0n,\n isGlobalValidation,\n isDeferredAction = true,\n }: EntityIdAndNonceParams) => {\n if (!client.account) {\n throw new AccountNotFoundError();\n }\n\n if (nonceKey > maxUint152) {\n throw new InvalidNonceKeyError(nonceKey);\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 bytecode = encodeDeployData({\n abi: entityIdAndNonceReaderAbi,\n bytecode: entityIdAndNonceReaderBytecode,\n args: [\n client.account.address,\n entryPoint.address,\n buildFullNonceKey({\n nonceKey,\n entityId,\n isGlobalValidation,\n isDeferredAction,\n }),\n ],\n });\n\n const { data } = await client.call({ data: bytecode });\n if (!data) {\n throw new Error(\"No data returned from contract call\");\n }\n\n return {\n nonce: BigInt(data),\n entityId: hexToNumber(`0x${data.slice(40, 48)}`),\n };\n };\n\n return {\n createDeferredActionTypedDataObject,\n buildPreSignatureDeferredActionDigest,\n buildUserOperationWithDeferredAction,\n getEntityIdAndNonce,\n };\n};\n"]}
|
|
@@ -12,8 +12,9 @@ export type * from "./actions/deferralActions.js";
|
|
|
12
12
|
export { deferralActions } from "./actions/deferralActions.js";
|
|
13
13
|
export type * from "./permissionBuilder.js";
|
|
14
14
|
export { PermissionBuilder, PermissionType } from "./permissionBuilder.js";
|
|
15
|
+
export * from "./permissionBuilderErrors.js";
|
|
15
16
|
export { getDefaultAllowlistModuleAddress, getDefaultNativeTokenLimitModuleAddress, getDefaultPaymasterGuardModuleAddress, getDefaultSingleSignerValidationModuleAddress, getDefaultTimeRangeModuleAddress, getDefaultWebauthnValidationModuleAddress, } from "./modules/utils.js";
|
|
16
|
-
export { buildFullNonceKey } from "./utils.js";
|
|
17
|
+
export { buildFullNonceKey, buildDeferredActionDigest } from "./utils.js";
|
|
17
18
|
export { allowlistModuleAbi } from "./modules/allowlist-module/abis/allowlistModuleAbi.js";
|
|
18
19
|
export { AllowlistModule } from "./modules/allowlist-module/module.js";
|
|
19
20
|
export { nativeTokenLimitModuleAbi } from "./modules/native-token-limit-module/abis/nativeTokenLimitModuleAbi.js";
|
|
@@ -9,8 +9,9 @@ export { serializeValidationConfig, serializeHookConfig, serializeModuleEntity,
|
|
|
9
9
|
export { installValidationActions } from "./actions/install-validation/installValidation.js";
|
|
10
10
|
export { deferralActions } from "./actions/deferralActions.js";
|
|
11
11
|
export { PermissionBuilder, PermissionType } from "./permissionBuilder.js";
|
|
12
|
+
export * from "./permissionBuilderErrors.js";
|
|
12
13
|
export { getDefaultAllowlistModuleAddress, getDefaultNativeTokenLimitModuleAddress, getDefaultPaymasterGuardModuleAddress, getDefaultSingleSignerValidationModuleAddress, getDefaultTimeRangeModuleAddress, getDefaultWebauthnValidationModuleAddress, } from "./modules/utils.js";
|
|
13
|
-
export { buildFullNonceKey } from "./utils.js";
|
|
14
|
+
export { buildFullNonceKey, buildDeferredActionDigest } from "./utils.js";
|
|
14
15
|
export { allowlistModuleAbi } from "./modules/allowlist-module/abis/allowlistModuleAbi.js";
|
|
15
16
|
export { AllowlistModule } from "./modules/allowlist-module/module.js";
|
|
16
17
|
export { nativeTokenLimitModuleAbi } from "./modules/native-token-limit-module/abis/nativeTokenLimitModuleAbi.js";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/ma-v2/index.ts"],"names":[],"mappings":"AAAA,gBAAgB;AAChB,OAAO,EAAE,iBAAiB,EAAE,MAAM,6BAA6B,CAAC;AAChE,OAAO,EAAE,iBAAiB,EAAE,MAAM,6BAA6B,CAAC;AAChE,OAAO,EAAE,6BAA6B,EAAE,MAAM,yCAAyC,CAAC;AACxF,OAAO,EAAE,4BAA4B,EAAE,MAAM,wCAAwC,CAAC;AAEtF,OAAO,EAAE,eAAe,EAAE,MAAM,8BAA8B,CAAC;AAQ/D,OAAO,EAAE,QAAQ,EAAE,MAAM,2BAA2B,CAAC;AACrD,OAAO,EACL,yBAAyB,EACzB,mBAAmB,EACnB,qBAAqB,GACtB,MAAM,2BAA2B,CAAC;AAEnC,OAAO,EAAE,wBAAwB,EAAE,MAAM,mDAAmD,CAAC;AAE7F,OAAO,EAAE,eAAe,EAAE,MAAM,8BAA8B,CAAC;AAE/D,OAAO,EAAE,iBAAiB,EAAE,cAAc,EAAE,MAAM,wBAAwB,CAAC;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/ma-v2/index.ts"],"names":[],"mappings":"AAAA,gBAAgB;AAChB,OAAO,EAAE,iBAAiB,EAAE,MAAM,6BAA6B,CAAC;AAChE,OAAO,EAAE,iBAAiB,EAAE,MAAM,6BAA6B,CAAC;AAChE,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AA2B,EAAE,MAAM,6DAA6D,CAAC","sourcesContent":["// ma v2 exports\nexport { accountFactoryAbi } from \"./abis/accountFactoryAbi.js\";\nexport { modularAccountAbi } from \"./abis/modularAccountAbi.js\";\nexport { semiModularAccountBytecodeAbi } from \"./abis/semiModularAccountBytecodeAbi.js\";\nexport { semiModularAccountStorageAbi } from \"./abis/semiModularAccountStorageAbi.js\";\n\nexport { nativeSMASigner } from \"./account/nativeSMASigner.js\";\n\nexport type {\n ModuleEntity,\n ValidationConfig,\n HookConfig,\n ValidationData,\n} from \"./actions/common/types.js\";\nexport { HookType } from \"./actions/common/types.js\";\nexport {\n serializeValidationConfig,\n serializeHookConfig,\n serializeModuleEntity,\n} from \"./actions/common/utils.js\";\nexport type * from \"./actions/install-validation/installValidation.js\";\nexport { installValidationActions } from \"./actions/install-validation/installValidation.js\";\nexport type * from \"./actions/deferralActions.js\";\nexport { deferralActions } from \"./actions/deferralActions.js\";\nexport type * from \"./permissionBuilder.js\";\nexport { PermissionBuilder, PermissionType } from \"./permissionBuilder.js\";\nexport * from \"./permissionBuilderErrors.js\";\n\nexport {\n getDefaultAllowlistModuleAddress,\n getDefaultNativeTokenLimitModuleAddress,\n getDefaultPaymasterGuardModuleAddress,\n getDefaultSingleSignerValidationModuleAddress,\n getDefaultTimeRangeModuleAddress,\n getDefaultWebauthnValidationModuleAddress,\n} from \"./modules/utils.js\";\nexport { buildFullNonceKey, buildDeferredActionDigest } from \"./utils.js\";\nexport { allowlistModuleAbi } from \"./modules/allowlist-module/abis/allowlistModuleAbi.js\";\nexport { AllowlistModule } from \"./modules/allowlist-module/module.js\";\nexport { nativeTokenLimitModuleAbi } from \"./modules/native-token-limit-module/abis/nativeTokenLimitModuleAbi.js\";\nexport { NativeTokenLimitModule } from \"./modules/native-token-limit-module/module.js\";\nexport { paymasterGuardModuleAbi } from \"./modules/paymaster-guard-module/abis/paymasterGuardModuleAbi.js\";\nexport { PaymasterGuardModule } from \"./modules/paymaster-guard-module/module.js\";\nexport { singleSignerValidationModuleAbi } from \"./modules/single-signer-validation/abis/singleSignerValidationModuleAbi.js\";\nexport { SingleSignerValidationModule } from \"./modules/single-signer-validation/module.js\";\nexport { timeRangeModuleAbi } from \"./modules/time-range-module/abis/timeRangeModuleAbi.js\";\nexport { TimeRangeModule } from \"./modules/time-range-module/module.js\";\nexport { webauthnValidationModuleAbi } from \"./modules/webauthn-validation/abis/webauthnValidationAbi.js\";\n"]}
|
|
@@ -81,14 +81,16 @@ export declare class PermissionBuilder {
|
|
|
81
81
|
private hooks;
|
|
82
82
|
private nonce;
|
|
83
83
|
private hasAssociatedExecHooks;
|
|
84
|
-
|
|
85
|
-
|
|
84
|
+
private deadline;
|
|
85
|
+
constructor({ client, key, entityId, nonce, selectors, hooks, deadline, }: {
|
|
86
|
+
client: ModularAccountV2Client;
|
|
86
87
|
key: Key;
|
|
87
88
|
entityId: number;
|
|
88
89
|
nonce: bigint;
|
|
89
90
|
selectors?: Hex[];
|
|
90
91
|
hooks?: Hook[];
|
|
91
|
-
|
|
92
|
+
deadline?: number;
|
|
93
|
+
});
|
|
92
94
|
addSelector({ selector }: {
|
|
93
95
|
selector: Hex;
|
|
94
96
|
}): this;
|
|
@@ -98,11 +100,7 @@ export declare class PermissionBuilder {
|
|
|
98
100
|
addPermissions({ permissions }: {
|
|
99
101
|
permissions: Permission[];
|
|
100
102
|
}): this;
|
|
101
|
-
compileDeferred(
|
|
102
|
-
deadline: number;
|
|
103
|
-
uoValidationEntityId: number;
|
|
104
|
-
uoIsGlobalValidation: boolean;
|
|
105
|
-
}): Promise<{
|
|
103
|
+
compileDeferred(): Promise<{
|
|
106
104
|
typedData: DeferredActionTypedData;
|
|
107
105
|
fullPreSignatureDeferredActionDigest: Hex;
|
|
108
106
|
}>;
|
|
@@ -112,4 +110,5 @@ export declare class PermissionBuilder {
|
|
|
112
110
|
private translatePermissions;
|
|
113
111
|
private addHooks;
|
|
114
112
|
}
|
|
113
|
+
export declare function assertNever(_valid: never): never;
|
|
115
114
|
export {};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { toHex, zeroAddress } from "viem";
|
|
1
|
+
import { maxUint48, toHex, zeroAddress } from "viem";
|
|
2
2
|
import { HookType, } from "./actions/common/types.js";
|
|
3
3
|
import { installValidationActions, } from "./actions/install-validation/installValidation.js";
|
|
4
4
|
import { deferralActions, } from "./actions/deferralActions.js";
|
|
@@ -7,6 +7,7 @@ import { getDefaultAllowlistModuleAddress, getDefaultNativeTokenLimitModuleAddre
|
|
|
7
7
|
import { SingleSignerValidationModule } from "./modules/single-signer-validation/module.js";
|
|
8
8
|
import { AllowlistModule } from "./modules/allowlist-module/module.js";
|
|
9
9
|
import { TimeRangeModule } from "./modules/time-range-module/module.js";
|
|
10
|
+
import { AccountAddressAsTargetError, DeadlineOverLimitError, DuplicateTargetAddressError, ExpiredDeadlineError, MultipleGasLimitError, MultipleNativeTokenTransferError, NoFunctionsProvidedError, RootPermissionOnlyError, UnsupportedPermissionTypeError, ValidationConfigUnsetError, ZeroAddressError, } from "./permissionBuilderErrors.js";
|
|
10
11
|
// We use this to offset the ERC20 spend limit entityId
|
|
11
12
|
const HALF_UINT32 = 2147483647;
|
|
12
13
|
const ERC20_APPROVE_SELECTOR = "0x095ea7b3";
|
|
@@ -36,7 +37,7 @@ var HookIdentifier;
|
|
|
36
37
|
HookIdentifier[HookIdentifier["PREVAL_ALLOWLIST"] = 3] = "PREVAL_ALLOWLIST";
|
|
37
38
|
})(HookIdentifier || (HookIdentifier = {}));
|
|
38
39
|
export class PermissionBuilder {
|
|
39
|
-
constructor(client) {
|
|
40
|
+
constructor({ client, key, entityId, nonce, selectors, hooks, deadline, }) {
|
|
40
41
|
Object.defineProperty(this, "client", {
|
|
41
42
|
enumerable: true,
|
|
42
43
|
configurable: true,
|
|
@@ -91,10 +92,13 @@ export class PermissionBuilder {
|
|
|
91
92
|
writable: true,
|
|
92
93
|
value: false
|
|
93
94
|
});
|
|
95
|
+
Object.defineProperty(this, "deadline", {
|
|
96
|
+
enumerable: true,
|
|
97
|
+
configurable: true,
|
|
98
|
+
writable: true,
|
|
99
|
+
value: 0
|
|
100
|
+
});
|
|
94
101
|
this.client = client;
|
|
95
|
-
}
|
|
96
|
-
// Configures the builder
|
|
97
|
-
configure({ key, entityId, nonce, selectors, hooks, }) {
|
|
98
102
|
this.validationConfig = {
|
|
99
103
|
moduleAddress: getDefaultSingleSignerValidationModuleAddress(this.client.chain),
|
|
100
104
|
entityId,
|
|
@@ -106,12 +110,13 @@ export class PermissionBuilder {
|
|
|
106
110
|
entityId: entityId,
|
|
107
111
|
signer: key.publicKey,
|
|
108
112
|
});
|
|
113
|
+
this.nonce = nonce;
|
|
109
114
|
if (selectors)
|
|
110
115
|
this.selectors = selectors;
|
|
111
116
|
if (hooks)
|
|
112
117
|
this.hooks = hooks;
|
|
113
|
-
|
|
114
|
-
|
|
118
|
+
if (deadline)
|
|
119
|
+
this.deadline = deadline;
|
|
115
120
|
}
|
|
116
121
|
addSelector({ selector }) {
|
|
117
122
|
this.selectors.push(selector);
|
|
@@ -121,7 +126,7 @@ export class PermissionBuilder {
|
|
|
121
126
|
// Check 1: If we're adding root, we can't have any other permissions
|
|
122
127
|
if (permission.type === PermissionType.ROOT) {
|
|
123
128
|
if (this.permissions.length !== 0) {
|
|
124
|
-
throw new
|
|
129
|
+
throw new RootPermissionOnlyError(permission);
|
|
125
130
|
}
|
|
126
131
|
this.permissions.push(permission);
|
|
127
132
|
// Set isGlobal to true
|
|
@@ -133,14 +138,14 @@ export class PermissionBuilder {
|
|
|
133
138
|
// NOTE: Technically this could be replaced by checking permissions[0] since it should not be possible
|
|
134
139
|
// to have >1 permission with root among them
|
|
135
140
|
if (this.permissions.find((p) => p.type === PermissionType.ROOT)) {
|
|
136
|
-
throw new
|
|
141
|
+
throw new RootPermissionOnlyError(permission);
|
|
137
142
|
}
|
|
138
143
|
// Check 3: If the permission is either CONTRACT_ACCESS or FUNCTIONS_ON_CONTRACT, ensure it doesn't collide with another like it.
|
|
139
144
|
if (permission.type === PermissionType.CONTRACT_ACCESS ||
|
|
140
145
|
permission.type === PermissionType.FUNCTIONS_ON_CONTRACT) {
|
|
141
146
|
// Check 3.1: address must not be the account address, or the user should use the ACCOUNT_FUNCTIONS permission
|
|
142
147
|
if (permission.data.address === this.client.account.address) {
|
|
143
|
-
throw new
|
|
148
|
+
throw new AccountAddressAsTargetError(permission);
|
|
144
149
|
}
|
|
145
150
|
// Check 3.2: there must not be an existing permission with this address as a target
|
|
146
151
|
const targetAddress = permission.data.address;
|
|
@@ -151,13 +156,15 @@ export class PermissionBuilder {
|
|
|
151
156
|
"address" in p.data &&
|
|
152
157
|
p.data.address === targetAddress));
|
|
153
158
|
if (existingPermissionWithSameAddress) {
|
|
154
|
-
throw new
|
|
159
|
+
throw new DuplicateTargetAddressError(permission, targetAddress);
|
|
155
160
|
}
|
|
156
161
|
}
|
|
157
162
|
// Check 4: If the permission is ACCOUNT_FUNCTIONS, add selectors
|
|
158
163
|
if (permission.type === PermissionType.ACCOUNT_FUNCTIONS) {
|
|
164
|
+
if (permission.data.functions.length === 0) {
|
|
165
|
+
throw new NoFunctionsProvidedError(permission);
|
|
166
|
+
}
|
|
159
167
|
this.selectors = [...this.selectors, ...permission.data.functions];
|
|
160
|
-
return this;
|
|
161
168
|
}
|
|
162
169
|
this.permissions.push(permission);
|
|
163
170
|
return this;
|
|
@@ -171,29 +178,30 @@ export class PermissionBuilder {
|
|
|
171
178
|
return this;
|
|
172
179
|
}
|
|
173
180
|
// Use for building deferred action typed data to sign
|
|
174
|
-
async compileDeferred(
|
|
175
|
-
// Need to remove this because compileRaw may add selectors
|
|
176
|
-
// this.validateConfiguration();
|
|
181
|
+
async compileDeferred() {
|
|
177
182
|
// Add time range module hook via expiry
|
|
178
|
-
if (deadline !== 0) {
|
|
179
|
-
if (deadline < Date.now() / 1000) {
|
|
180
|
-
throw new
|
|
183
|
+
if (this.deadline !== 0) {
|
|
184
|
+
if (this.deadline < Date.now() / 1000) {
|
|
185
|
+
throw new ExpiredDeadlineError(this.deadline, Date.now() / 1000);
|
|
186
|
+
}
|
|
187
|
+
if (this.deadline > maxUint48) {
|
|
188
|
+
throw new DeadlineOverLimitError(this.deadline);
|
|
181
189
|
}
|
|
182
190
|
this.hooks.push(TimeRangeModule.buildHook({
|
|
183
|
-
entityId: this.validationConfig.entityId,
|
|
184
|
-
validUntil: deadline,
|
|
191
|
+
entityId: this.validationConfig.entityId,
|
|
192
|
+
validUntil: this.deadline,
|
|
185
193
|
validAfter: 0,
|
|
186
194
|
}, getDefaultTimeRangeModuleAddress(this.client.chain)));
|
|
187
195
|
}
|
|
188
196
|
const installValidationCall = await this.compileRaw();
|
|
189
197
|
const { typedData } = await deferralActions(this.client).createDeferredActionTypedDataObject({
|
|
190
198
|
callData: installValidationCall,
|
|
191
|
-
deadline: deadline,
|
|
199
|
+
deadline: this.deadline,
|
|
192
200
|
nonce: this.nonce,
|
|
193
201
|
});
|
|
194
202
|
const preSignatureDigest = deferralActions(this.client).buildPreSignatureDeferredActionDigest({ typedData });
|
|
195
203
|
// Encode additional information to build the full pre-signature digest
|
|
196
|
-
const fullPreSignatureDeferredActionDigest = `
|
|
204
|
+
const fullPreSignatureDeferredActionDigest = `0x0${this.hasAssociatedExecHooks ? "1" : "0"}${toHex(this.nonce, {
|
|
197
205
|
size: 32,
|
|
198
206
|
}).slice(2)}${preSignatureDigest.slice(2)}`;
|
|
199
207
|
return {
|
|
@@ -232,7 +240,7 @@ export class PermissionBuilder {
|
|
|
232
240
|
validateConfiguration() {
|
|
233
241
|
if (this.validationConfig.isGlobal === false &&
|
|
234
242
|
this.selectors.length === 0) {
|
|
235
|
-
throw new
|
|
243
|
+
throw new ValidationConfigUnsetError();
|
|
236
244
|
}
|
|
237
245
|
}
|
|
238
246
|
// Used to translate consolidated permissions into raw unencoded hooks
|
|
@@ -249,7 +257,7 @@ export class PermissionBuilder {
|
|
|
249
257
|
case PermissionType.NATIVE_TOKEN_TRANSFER:
|
|
250
258
|
// Should never be added twice, check is on addPermission(s) too
|
|
251
259
|
if (rawHooks[HookIdentifier.NATIVE_TOKEN_TRANSFER] !== undefined) {
|
|
252
|
-
throw new
|
|
260
|
+
throw new MultipleNativeTokenTransferError(permission);
|
|
253
261
|
}
|
|
254
262
|
rawHooks[HookIdentifier.NATIVE_TOKEN_TRANSFER] = {
|
|
255
263
|
hookConfig: {
|
|
@@ -268,7 +276,7 @@ export class PermissionBuilder {
|
|
|
268
276
|
break;
|
|
269
277
|
case PermissionType.ERC20_TOKEN_TRANSFER:
|
|
270
278
|
if (permission.data.address === zeroAddress) {
|
|
271
|
-
throw new
|
|
279
|
+
throw new ZeroAddressError(permission);
|
|
272
280
|
}
|
|
273
281
|
rawHooks[HookIdentifier.ERC20_TOKEN_TRANSFER] = {
|
|
274
282
|
hookConfig: {
|
|
@@ -324,7 +332,7 @@ export class PermissionBuilder {
|
|
|
324
332
|
case PermissionType.GAS_LIMIT:
|
|
325
333
|
// Should only ever be added once, check is also on addPermission(s)
|
|
326
334
|
if (rawHooks[HookIdentifier.GAS_LIMIT] !== undefined) {
|
|
327
|
-
throw new
|
|
335
|
+
throw new MultipleGasLimitError(permission);
|
|
328
336
|
}
|
|
329
337
|
rawHooks[HookIdentifier.GAS_LIMIT] = {
|
|
330
338
|
hookConfig: {
|
|
@@ -342,7 +350,7 @@ export class PermissionBuilder {
|
|
|
342
350
|
break;
|
|
343
351
|
case PermissionType.CONTRACT_ACCESS:
|
|
344
352
|
if (permission.data.address === zeroAddress) {
|
|
345
|
-
throw new
|
|
353
|
+
throw new ZeroAddressError(permission);
|
|
346
354
|
}
|
|
347
355
|
rawHooks[HookIdentifier.PREVAL_ALLOWLIST] = {
|
|
348
356
|
hookConfig: {
|
|
@@ -370,13 +378,11 @@ export class PermissionBuilder {
|
|
|
370
378
|
};
|
|
371
379
|
break;
|
|
372
380
|
case PermissionType.ACCOUNT_FUNCTIONS:
|
|
373
|
-
|
|
374
|
-
throw new Error("PERMISSION: ACCOUNT_FUNCTION => No functions provided"); // should be in add perm
|
|
375
|
-
}
|
|
381
|
+
// This is handled in add permissions
|
|
376
382
|
break;
|
|
377
383
|
case PermissionType.FUNCTIONS_ON_ALL_CONTRACTS:
|
|
378
384
|
if (permission.data.functions.length === 0) {
|
|
379
|
-
throw new
|
|
385
|
+
throw new NoFunctionsProvidedError(permission);
|
|
380
386
|
}
|
|
381
387
|
rawHooks[HookIdentifier.PREVAL_ALLOWLIST] = {
|
|
382
388
|
hookConfig: {
|
|
@@ -405,10 +411,10 @@ export class PermissionBuilder {
|
|
|
405
411
|
break;
|
|
406
412
|
case PermissionType.FUNCTIONS_ON_CONTRACT:
|
|
407
413
|
if (permission.data.functions.length === 0) {
|
|
408
|
-
throw new
|
|
414
|
+
throw new NoFunctionsProvidedError(permission);
|
|
409
415
|
}
|
|
410
416
|
if (permission.data.address === zeroAddress) {
|
|
411
|
-
throw new
|
|
417
|
+
throw new ZeroAddressError(permission);
|
|
412
418
|
}
|
|
413
419
|
rawHooks[HookIdentifier.PREVAL_ALLOWLIST] = {
|
|
414
420
|
hookConfig: {
|
|
@@ -439,7 +445,7 @@ export class PermissionBuilder {
|
|
|
439
445
|
// Root permission handled in addPermission
|
|
440
446
|
break;
|
|
441
447
|
default:
|
|
442
|
-
|
|
448
|
+
assertNever(permission);
|
|
443
449
|
}
|
|
444
450
|
// isGlobal guaranteed to be false since it's only set with root permissions,
|
|
445
451
|
// we must add access to execute & executeBatch if there's a preVal allowlist hook set.
|
|
@@ -482,4 +488,7 @@ export class PermissionBuilder {
|
|
|
482
488
|
}
|
|
483
489
|
}
|
|
484
490
|
}
|
|
491
|
+
export function assertNever(_valid) {
|
|
492
|
+
throw new UnsupportedPermissionTypeError();
|
|
493
|
+
}
|
|
485
494
|
//# sourceMappingURL=permissionBuilder.js.map
|