@account-kit/smart-contracts 4.70.1 → 4.71.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.
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { getEntryPoint, EntityIdOverrideError, InvalidModularAccountV2Mode, createBundlerClient, getAccountAddress, } from "@aa-sdk/core";
|
|
2
|
-
import { concatHex, encodeFunctionData, } from "viem";
|
|
2
|
+
import { concatHex, encodeFunctionData, isAddressEqual, } from "viem";
|
|
3
3
|
import { accountFactoryAbi } from "../abis/accountFactoryAbi.js";
|
|
4
4
|
import { getDefaultMAV2FactoryAddress, getDefaultWebAuthnMAV2FactoryAddress, getDefaultSMAV2BytecodeAddress, } from "../utils.js";
|
|
5
5
|
import { createMAv2Base, } from "./common/modularAccountV2Base.js";
|
|
@@ -93,7 +93,7 @@ export async function createModularAccountV2(config) {
|
|
|
93
93
|
const signerAddress = await signer.getAddress();
|
|
94
94
|
const accountAddress = _accountAddress ?? signerAddress;
|
|
95
95
|
if (entityId === DEFAULT_OWNER_ENTITY_ID &&
|
|
96
|
-
signerAddress
|
|
96
|
+
!isAddressEqual(signerAddress, accountAddress)) {
|
|
97
97
|
throw new EntityIdOverrideError();
|
|
98
98
|
}
|
|
99
99
|
const implementation = "0x69007702764179f14F51cdce752f4f775d74E139";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"modularAccountV2.js","sourceRoot":"","sources":["../../../../../src/ma-v2/account/modularAccountV2.ts"],"names":[],"mappings":"AAKA,OAAO,EACL,aAAa,EACb,qBAAqB,EACrB,2BAA2B,EAC3B,mBAAmB,EACnB,iBAAiB,GAClB,MAAM,cAAc,CAAC;AACtB,OAAO,EACL,SAAS,EACT,kBAAkB,GAKnB,MAAM,MAAM,CAAC;AACd,OAAO,EAAE,iBAAiB,EAAE,MAAM,8BAA8B,CAAC;AACjE,OAAO,EACL,4BAA4B,EAC5B,oCAAoC,EACpC,8BAA8B,GAC/B,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BAEL,OAAO;oBACL,kBAAkB;oBAClB,cAAc;iBACf,CAAC;YACJ,CAAC;YACD;gBACE,WAAW,CAAC,MAAM,CAAC,CAAC;QACxB,CAAC;IACH,CAAC,CAAC,EAAE,CAAC;IAEL,IAAI,CAAC,MAAM,EAAE,CAAC;QACZ,IAAI,CAAC,UAAU;YAAE,MAAM,IAAI,gCAAgC,EAAE,CAAC;QAC9D,OAAO,MAAM,cAAc,CAAC;YAC1B,MAAM,EAAE,kBAAkB,EAAE,wCAAwC;YACpE,SAAS;YACT,KAAK;YACL,UAAU;YACV,YAAY;YACZ,cAAc;YACd,UAAU;YACV,KAAK;YACL,IAAI;YACJ,GAAG,gBAAgB;SACpB,CAAC,CAAC;IACL,CAAC;IAED,OAAO,MAAM,cAAc,CAAC;QAC1B,MAAM,EAAE,kBAAkB,EAAE,wCAAwC;QACpE,SAAS;QACT,KAAK;QACL,MAAM;QACN,UAAU;QACV,YAAY;QACZ,cAAc;QACd,GAAG,gBAAgB;KACpB,CAAC,CAAC;AACL,CAAC;AAED,qKAAqK;AACrK,SAAS,WAAW,CAAC,MAAa;IAChC,MAAM,IAAI,2BAA2B,EAAE,CAAC;AAC1C,CAAC","sourcesContent":["import type {\n EntryPointDef,\n SmartAccountSigner,\n ToSmartContractAccountParams,\n} from \"@aa-sdk/core\";\nimport {\n getEntryPoint,\n EntityIdOverrideError,\n InvalidModularAccountV2Mode,\n createBundlerClient,\n getAccountAddress,\n} from \"@aa-sdk/core\";\nimport {\n concatHex,\n encodeFunctionData,\n type Address,\n type Chain,\n type Hex,\n type Transport,\n} from \"viem\";\nimport { accountFactoryAbi } from \"../abis/accountFactoryAbi.js\";\nimport {\n getDefaultMAV2FactoryAddress,\n getDefaultWebAuthnMAV2FactoryAddress,\n getDefaultSMAV2BytecodeAddress,\n} from \"../utils.js\";\nimport {\n type SignerEntity,\n type ModularAccountV2,\n createMAv2Base,\n type WebauthnModularAccountV2,\n} from \"./common/modularAccountV2Base.js\";\nimport { DEFAULT_OWNER_ENTITY_ID } from \"../utils.js\";\nimport { predictModularAccountV2Address } from \"./predictAddress.js\";\nimport type { ToWebAuthnAccountParameters } from \"viem/account-abstraction\";\nimport { parsePublicKey } from \"webauthn-p256\";\nimport {\n SignerRequiredFor7702Error,\n SignerRequiredForDefaultError,\n WebauthnCredentialsRequiredError,\n} from \"../errors.js\";\n\nexport type CreateModularAccountV2Params<\n TTransport extends Transport = Transport,\n TSigner extends SmartAccountSigner = SmartAccountSigner,\n> = (Pick<\n ToSmartContractAccountParams<\"ModularAccountV2\", TTransport, Chain, \"0.7.0\">,\n \"transport\" | \"chain\" | \"accountAddress\"\n> & {\n signer: TSigner;\n entryPoint?: EntryPointDef<\"0.7.0\", Chain>;\n deferredAction?: Hex;\n signerEntity?: SignerEntity;\n}) &\n (\n | {\n mode?: \"default\";\n salt?: bigint;\n factoryAddress?: Address;\n implementationAddress?: Address;\n initCode?: Hex;\n }\n | {\n mode: \"7702\";\n }\n );\n\nexport type CreateWebauthnModularAccountV2Params<\n TTransport extends Transport = Transport,\n> = Pick<\n ToSmartContractAccountParams<\"ModularAccountV2\", TTransport, Chain, \"0.7.0\">,\n \"transport\" | \"chain\" | \"accountAddress\"\n> & {\n mode: \"webauthn\";\n credential: ToWebAuthnAccountParameters[\"credential\"];\n getFn?: ToWebAuthnAccountParameters[\"getFn\"] | undefined;\n rpId?: ToWebAuthnAccountParameters[\"rpId\"] | undefined;\n entryPoint?: EntryPointDef<\"0.7.0\", Chain>;\n deferredAction?: Hex;\n signerEntity?: SignerEntity;\n salt?: bigint;\n factoryAddress?: Address;\n initCode?: Hex;\n};\n\nexport async function createModularAccountV2<\n TTransport extends Transport = Transport,\n TSigner extends SmartAccountSigner = SmartAccountSigner,\n>(\n config: CreateModularAccountV2Params<TTransport, TSigner>,\n): Promise<ModularAccountV2<TSigner>>;\n\nexport async function createModularAccountV2<\n TTransport extends Transport = Transport,\n>(\n config: CreateWebauthnModularAccountV2Params<TTransport>,\n): Promise<WebauthnModularAccountV2>;\n\n/**\n * Creates a ModularAccount V2 account, with the mode depending on the provided \"mode\" field.\n * Possible modes include: \"default\", which is SMA Bytecode, and \"7702\", which is SMA 7702.\n * Handles nonce generation, transaction encoding, and mode variant-specific behavior like initcode construction.\n *\n * @example\n * ```ts twoslash\n * import { createModularAccountV2 } from \"@account-kit/smart-contracts\";\n * import { LocalAccountSigner } from \"@aa-sdk/core\";\n * import { alchemy, sepolia } from \"@account-kit/infra\";\n *\n * const MNEMONIC = \"...\";\n * const RPC_URL = \"...\";\n *\n * const signer = LocalAccountSigner.mnemonicToAccountSigner(MNEMONIC);\n *\n * const chain = sepolia;\n *\n * const transport = alchemy({ rpcUrl: RPC_URL });\n *\n *\n * const modularAccountV2 = await createModularAccountV2({\n * mode: \"default\", // or \"7702\"\n * chain,\n * signer,\n * transport,\n * });\n * ```\n *\n * @param {CreateModularAccountV2Params | CreateWebauthnModularAccountV2Params} config Configuration parameters for creating a Modular Account V2.\n * @returns {Promise<ModularAccountV2 | WebauthnModularAccountV2>} A promise that resolves to an `ModularAccountV2` providing methods for nonce retrieval, transaction execution, and more.\n */\nexport async function createModularAccountV2<\n TTransport extends Transport = Transport,\n TSigner extends SmartAccountSigner = SmartAccountSigner,\n>(\n config:\n | CreateModularAccountV2Params<TTransport, TSigner>\n | CreateWebauthnModularAccountV2Params<TTransport>,\n): Promise<ModularAccountV2<TSigner> | WebauthnModularAccountV2> {\n const {\n transport,\n chain,\n accountAddress: _accountAddress,\n entryPoint = getEntryPoint(chain, { version: \"0.7.0\" }),\n signerEntity = {\n isGlobalValidation: true,\n entityId: DEFAULT_OWNER_ENTITY_ID,\n },\n signerEntity: { entityId = DEFAULT_OWNER_ENTITY_ID } = {},\n deferredAction,\n } = config;\n\n const signer = \"signer\" in config ? config.signer : undefined;\n\n const credential = \"credential\" in config ? config.credential : undefined;\n\n const getFn = \"getFn\" in config ? config.getFn : undefined;\n\n const rpId = \"rpId\" in config ? config.rpId : undefined;\n\n const client = createBundlerClient({\n transport,\n chain,\n });\n\n const accountFunctions = await (async () => {\n switch (config.mode) {\n case \"webauthn\": {\n if (!credential) throw new WebauthnCredentialsRequiredError();\n const publicKey = credential.publicKey;\n const { x, y } = parsePublicKey(publicKey);\n const {\n salt = 0n,\n factoryAddress = getDefaultWebAuthnMAV2FactoryAddress(),\n initCode,\n } = config;\n\n const getAccountInitCode = async () => {\n if (initCode) {\n return initCode;\n }\n\n return concatHex([\n factoryAddress,\n encodeFunctionData({\n abi: accountFactoryAbi,\n functionName: \"createWebAuthnAccount\",\n args: [x, y, salt, entityId],\n }),\n ]);\n };\n\n const accountAddress = await getAccountAddress({\n client,\n entryPoint,\n accountAddress: _accountAddress,\n getAccountInitCode,\n });\n\n return {\n getAccountInitCode,\n accountAddress,\n };\n }\n case \"7702\": {\n const getAccountInitCode = async (): Promise<Hex> => {\n return \"0x\";\n };\n if (!signer) throw new SignerRequiredFor7702Error();\n const signerAddress = await signer.getAddress();\n const accountAddress = _accountAddress ?? signerAddress;\n if (\n entityId === DEFAULT_OWNER_ENTITY_ID &&\n signerAddress !== accountAddress\n ) {\n throw new EntityIdOverrideError();\n }\n\n const implementation: Address =\n \"0x69007702764179f14F51cdce752f4f775d74E139\";\n\n const getImplementationAddress = async () => implementation;\n\n return {\n getAccountInitCode,\n accountAddress,\n getImplementationAddress,\n };\n }\n case \"default\":\n case undefined: {\n if (!signer) throw new SignerRequiredForDefaultError();\n const {\n salt = 0n,\n factoryAddress = getDefaultMAV2FactoryAddress(chain),\n implementationAddress = getDefaultSMAV2BytecodeAddress(chain),\n initCode,\n } = config;\n\n const signerAddress = await signer.getAddress();\n\n const getAccountInitCode = async () => {\n if (initCode) {\n return initCode;\n }\n\n return concatHex([\n factoryAddress,\n encodeFunctionData({\n abi: accountFactoryAbi,\n functionName: \"createSemiModularAccount\",\n args: [await signer.getAddress(), salt],\n }),\n ]);\n };\n\n const accountAddress =\n _accountAddress ??\n predictModularAccountV2Address({\n factoryAddress,\n implementationAddress,\n salt,\n type: \"SMA\",\n ownerAddress: signerAddress,\n });\n\n return {\n getAccountInitCode,\n accountAddress,\n };\n }\n default:\n assertNever(config);\n }\n })();\n\n if (!signer) {\n if (!credential) throw new WebauthnCredentialsRequiredError();\n return await createMAv2Base({\n source: \"ModularAccountV2\", // TO DO: remove need to pass in source?\n transport,\n chain,\n entryPoint,\n signerEntity,\n deferredAction,\n credential,\n getFn,\n rpId,\n ...accountFunctions,\n });\n }\n\n return await createMAv2Base({\n source: \"ModularAccountV2\", // TO DO: remove need to pass in source?\n transport,\n chain,\n signer,\n entryPoint,\n signerEntity,\n deferredAction,\n ...accountFunctions,\n });\n}\n\n// If we add more valid modes, the switch case branch's mode will no longer be `never`, which will cause a compile time error here and ensure we handle the new type.\nfunction assertNever(_valid: never): never {\n throw new InvalidModularAccountV2Mode();\n}\n"]}
|
|
1
|
+
{"version":3,"file":"modularAccountV2.js","sourceRoot":"","sources":["../../../../../src/ma-v2/account/modularAccountV2.ts"],"names":[],"mappings":"AAKA,OAAO,EACL,aAAa,EACb,qBAAqB,EACrB,2BAA2B,EAC3B,mBAAmB,EACnB,iBAAiB,GAClB,MAAM,cAAc,CAAC;AACtB,OAAO,EACL,SAAS,EACT,kBAAkB,EAClB,cAAc,GAKf,MAAM,MAAM,CAAC;AACd,OAAO,EAAE,iBAAiB,EAAE,MAAM,8BAA8B,CAAC;AACjE,OAAO,EACL,4BAA4B,EAC5B,oCAAoC,EACpC,8BAA8B,GAC/B,MAAM,aAAa,CAAC;AACrB,OAAO,EAGL,cAAc,GAEf,MAAM,kCAAkC,CAAC;AAC1C,OAAO,EAAE,uBAAuB,EAAE,MAAM,aAAa,CAAC;AACtD,OAAO,EAAE,8BAA8B,EAAE,MAAM,qBAAqB,CAAC;AAErE,OAAO,EAAE,cAAc,EAAE,MAAM,eAAe,CAAC;AAC/C,OAAO,EACL,0BAA0B,EAC1B,6BAA6B,EAC7B,gCAAgC,GACjC,MAAM,cAAc,CAAC;AA0DtB;;;;;;;;;;;;;;;;;;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E,wCAAwC;YACpE,SAAS;YACT,KAAK;YACL,UAAU;YACV,YAAY;YACZ,cAAc;YACd,UAAU;YACV,KAAK;YACL,IAAI;YACJ,GAAG,gBAAgB;SACpB,CAAC,CAAC;IACL,CAAC;IAED,OAAO,MAAM,cAAc,CAAC;QAC1B,MAAM,EAAE,kBAAkB,EAAE,wCAAwC;QACpE,SAAS;QACT,KAAK;QACL,MAAM;QACN,UAAU;QACV,YAAY;QACZ,cAAc;QACd,GAAG,gBAAgB;KACpB,CAAC,CAAC;AACL,CAAC;AAED,qKAAqK;AACrK,SAAS,WAAW,CAAC,MAAa;IAChC,MAAM,IAAI,2BAA2B,EAAE,CAAC;AAC1C,CAAC","sourcesContent":["import type {\n EntryPointDef,\n SmartAccountSigner,\n ToSmartContractAccountParams,\n} from \"@aa-sdk/core\";\nimport {\n getEntryPoint,\n EntityIdOverrideError,\n InvalidModularAccountV2Mode,\n createBundlerClient,\n getAccountAddress,\n} from \"@aa-sdk/core\";\nimport {\n concatHex,\n encodeFunctionData,\n isAddressEqual,\n type Address,\n type Chain,\n type Hex,\n type Transport,\n} from \"viem\";\nimport { accountFactoryAbi } from \"../abis/accountFactoryAbi.js\";\nimport {\n getDefaultMAV2FactoryAddress,\n getDefaultWebAuthnMAV2FactoryAddress,\n getDefaultSMAV2BytecodeAddress,\n} from \"../utils.js\";\nimport {\n type SignerEntity,\n type ModularAccountV2,\n createMAv2Base,\n type WebauthnModularAccountV2,\n} from \"./common/modularAccountV2Base.js\";\nimport { DEFAULT_OWNER_ENTITY_ID } from \"../utils.js\";\nimport { predictModularAccountV2Address } from \"./predictAddress.js\";\nimport type { ToWebAuthnAccountParameters } from \"viem/account-abstraction\";\nimport { parsePublicKey } from \"webauthn-p256\";\nimport {\n SignerRequiredFor7702Error,\n SignerRequiredForDefaultError,\n WebauthnCredentialsRequiredError,\n} from \"../errors.js\";\n\nexport type CreateModularAccountV2Params<\n TTransport extends Transport = Transport,\n TSigner extends SmartAccountSigner = SmartAccountSigner,\n> = (Pick<\n ToSmartContractAccountParams<\"ModularAccountV2\", TTransport, Chain, \"0.7.0\">,\n \"transport\" | \"chain\" | \"accountAddress\"\n> & {\n signer: TSigner;\n entryPoint?: EntryPointDef<\"0.7.0\", Chain>;\n deferredAction?: Hex;\n signerEntity?: SignerEntity;\n}) &\n (\n | {\n mode?: \"default\";\n salt?: bigint;\n factoryAddress?: Address;\n implementationAddress?: Address;\n initCode?: Hex;\n }\n | {\n mode: \"7702\";\n }\n );\n\nexport type CreateWebauthnModularAccountV2Params<\n TTransport extends Transport = Transport,\n> = Pick<\n ToSmartContractAccountParams<\"ModularAccountV2\", TTransport, Chain, \"0.7.0\">,\n \"transport\" | \"chain\" | \"accountAddress\"\n> & {\n mode: \"webauthn\";\n credential: ToWebAuthnAccountParameters[\"credential\"];\n getFn?: ToWebAuthnAccountParameters[\"getFn\"] | undefined;\n rpId?: ToWebAuthnAccountParameters[\"rpId\"] | undefined;\n entryPoint?: EntryPointDef<\"0.7.0\", Chain>;\n deferredAction?: Hex;\n signerEntity?: SignerEntity;\n salt?: bigint;\n factoryAddress?: Address;\n initCode?: Hex;\n};\n\nexport async function createModularAccountV2<\n TTransport extends Transport = Transport,\n TSigner extends SmartAccountSigner = SmartAccountSigner,\n>(\n config: CreateModularAccountV2Params<TTransport, TSigner>,\n): Promise<ModularAccountV2<TSigner>>;\n\nexport async function createModularAccountV2<\n TTransport extends Transport = Transport,\n>(\n config: CreateWebauthnModularAccountV2Params<TTransport>,\n): Promise<WebauthnModularAccountV2>;\n\n/**\n * Creates a ModularAccount V2 account, with the mode depending on the provided \"mode\" field.\n * Possible modes include: \"default\", which is SMA Bytecode, and \"7702\", which is SMA 7702.\n * Handles nonce generation, transaction encoding, and mode variant-specific behavior like initcode construction.\n *\n * @example\n * ```ts twoslash\n * import { createModularAccountV2 } from \"@account-kit/smart-contracts\";\n * import { LocalAccountSigner } from \"@aa-sdk/core\";\n * import { alchemy, sepolia } from \"@account-kit/infra\";\n *\n * const MNEMONIC = \"...\";\n * const RPC_URL = \"...\";\n *\n * const signer = LocalAccountSigner.mnemonicToAccountSigner(MNEMONIC);\n *\n * const chain = sepolia;\n *\n * const transport = alchemy({ rpcUrl: RPC_URL });\n *\n *\n * const modularAccountV2 = await createModularAccountV2({\n * mode: \"default\", // or \"7702\"\n * chain,\n * signer,\n * transport,\n * });\n * ```\n *\n * @param {CreateModularAccountV2Params | CreateWebauthnModularAccountV2Params} config Configuration parameters for creating a Modular Account V2.\n * @returns {Promise<ModularAccountV2 | WebauthnModularAccountV2>} A promise that resolves to an `ModularAccountV2` providing methods for nonce retrieval, transaction execution, and more.\n */\nexport async function createModularAccountV2<\n TTransport extends Transport = Transport,\n TSigner extends SmartAccountSigner = SmartAccountSigner,\n>(\n config:\n | CreateModularAccountV2Params<TTransport, TSigner>\n | CreateWebauthnModularAccountV2Params<TTransport>,\n): Promise<ModularAccountV2<TSigner> | WebauthnModularAccountV2> {\n const {\n transport,\n chain,\n accountAddress: _accountAddress,\n entryPoint = getEntryPoint(chain, { version: \"0.7.0\" }),\n signerEntity = {\n isGlobalValidation: true,\n entityId: DEFAULT_OWNER_ENTITY_ID,\n },\n signerEntity: { entityId = DEFAULT_OWNER_ENTITY_ID } = {},\n deferredAction,\n } = config;\n\n const signer = \"signer\" in config ? config.signer : undefined;\n\n const credential = \"credential\" in config ? config.credential : undefined;\n\n const getFn = \"getFn\" in config ? config.getFn : undefined;\n\n const rpId = \"rpId\" in config ? config.rpId : undefined;\n\n const client = createBundlerClient({\n transport,\n chain,\n });\n\n const accountFunctions = await (async () => {\n switch (config.mode) {\n case \"webauthn\": {\n if (!credential) throw new WebauthnCredentialsRequiredError();\n const publicKey = credential.publicKey;\n const { x, y } = parsePublicKey(publicKey);\n const {\n salt = 0n,\n factoryAddress = getDefaultWebAuthnMAV2FactoryAddress(),\n initCode,\n } = config;\n\n const getAccountInitCode = async () => {\n if (initCode) {\n return initCode;\n }\n\n return concatHex([\n factoryAddress,\n encodeFunctionData({\n abi: accountFactoryAbi,\n functionName: \"createWebAuthnAccount\",\n args: [x, y, salt, entityId],\n }),\n ]);\n };\n\n const accountAddress = await getAccountAddress({\n client,\n entryPoint,\n accountAddress: _accountAddress,\n getAccountInitCode,\n });\n\n return {\n getAccountInitCode,\n accountAddress,\n };\n }\n case \"7702\": {\n const getAccountInitCode = async (): Promise<Hex> => {\n return \"0x\";\n };\n if (!signer) throw new SignerRequiredFor7702Error();\n const signerAddress = await signer.getAddress();\n const accountAddress = _accountAddress ?? signerAddress;\n if (\n entityId === DEFAULT_OWNER_ENTITY_ID &&\n !isAddressEqual(signerAddress, accountAddress)\n ) {\n throw new EntityIdOverrideError();\n }\n\n const implementation: Address =\n \"0x69007702764179f14F51cdce752f4f775d74E139\";\n\n const getImplementationAddress = async () => implementation;\n\n return {\n getAccountInitCode,\n accountAddress,\n getImplementationAddress,\n };\n }\n case \"default\":\n case undefined: {\n if (!signer) throw new SignerRequiredForDefaultError();\n const {\n salt = 0n,\n factoryAddress = getDefaultMAV2FactoryAddress(chain),\n implementationAddress = getDefaultSMAV2BytecodeAddress(chain),\n initCode,\n } = config;\n\n const signerAddress = await signer.getAddress();\n\n const getAccountInitCode = async () => {\n if (initCode) {\n return initCode;\n }\n\n return concatHex([\n factoryAddress,\n encodeFunctionData({\n abi: accountFactoryAbi,\n functionName: \"createSemiModularAccount\",\n args: [await signer.getAddress(), salt],\n }),\n ]);\n };\n\n const accountAddress =\n _accountAddress ??\n predictModularAccountV2Address({\n factoryAddress,\n implementationAddress,\n salt,\n type: \"SMA\",\n ownerAddress: signerAddress,\n });\n\n return {\n getAccountInitCode,\n accountAddress,\n };\n }\n default:\n assertNever(config);\n }\n })();\n\n if (!signer) {\n if (!credential) throw new WebauthnCredentialsRequiredError();\n return await createMAv2Base({\n source: \"ModularAccountV2\", // TO DO: remove need to pass in source?\n transport,\n chain,\n entryPoint,\n signerEntity,\n deferredAction,\n credential,\n getFn,\n rpId,\n ...accountFunctions,\n });\n }\n\n return await createMAv2Base({\n source: \"ModularAccountV2\", // TO DO: remove need to pass in source?\n transport,\n chain,\n signer,\n entryPoint,\n signerEntity,\n deferredAction,\n ...accountFunctions,\n });\n}\n\n// If we add more valid modes, the switch case branch's mode will no longer be `never`, which will cause a compile time error here and ensure we handle the new type.\nfunction assertNever(_valid: never): never {\n throw new InvalidModularAccountV2Mode();\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"modularAccountV2.d.ts","sourceRoot":"","sources":["../../../../../src/ma-v2/account/modularAccountV2.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,aAAa,EACb,kBAAkB,EAClB,4BAA4B,EAC7B,MAAM,cAAc,CAAC;AAQtB,OAAO,
|
|
1
|
+
{"version":3,"file":"modularAccountV2.d.ts","sourceRoot":"","sources":["../../../../../src/ma-v2/account/modularAccountV2.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,aAAa,EACb,kBAAkB,EAClB,4BAA4B,EAC7B,MAAM,cAAc,CAAC;AAQtB,OAAO,EAIL,KAAK,OAAO,EACZ,KAAK,KAAK,EACV,KAAK,GAAG,EACR,KAAK,SAAS,EACf,MAAM,MAAM,CAAC;AAOd,OAAO,EACL,KAAK,YAAY,EACjB,KAAK,gBAAgB,EAErB,KAAK,wBAAwB,EAC9B,MAAM,kCAAkC,CAAC;AAG1C,OAAO,KAAK,EAAE,2BAA2B,EAAE,MAAM,0BAA0B,CAAC;AAQ5E,MAAM,MAAM,4BAA4B,CACtC,UAAU,SAAS,SAAS,GAAG,SAAS,EACxC,OAAO,SAAS,kBAAkB,GAAG,kBAAkB,IACrD,CAAC,IAAI,CACP,4BAA4B,CAAC,kBAAkB,EAAE,UAAU,EAAE,KAAK,EAAE,OAAO,CAAC,EAC5E,WAAW,GAAG,OAAO,GAAG,gBAAgB,CACzC,GAAG;IACF,MAAM,EAAE,OAAO,CAAC;IAChB,UAAU,CAAC,EAAE,aAAa,CAAC,OAAO,EAAE,KAAK,CAAC,CAAC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C,wBAAsB,sBAAsB,CAC1C,UAAU,SAAS,SAAS,GAAG,SAAS,EAExC,MAAM,EAAE,oCAAoC,CAAC,UAAU,CAAC,GACvD,OAAO,CAAC,wBAAwB,CAAC,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@account-kit/smart-contracts",
|
|
3
|
-
"version": "4.
|
|
3
|
+
"version": "4.71.1",
|
|
4
4
|
"description": "aa-sdk compatible interfaces for Alchemy Smart Accounts",
|
|
5
5
|
"author": "Alchemy",
|
|
6
6
|
"license": "MIT",
|
|
@@ -51,7 +51,7 @@
|
|
|
51
51
|
"test:run": "vitest run"
|
|
52
52
|
},
|
|
53
53
|
"devDependencies": {
|
|
54
|
-
"@account-kit/plugingen": "^4.
|
|
54
|
+
"@account-kit/plugingen": "^4.71.1",
|
|
55
55
|
"change-case": "^5.1.2",
|
|
56
56
|
"dedent": "^1.5.1",
|
|
57
57
|
"dotenv": "^16.3.1",
|
|
@@ -69,10 +69,10 @@
|
|
|
69
69
|
"url": "https://github.com/alchemyplatform/aa-sdk/issues"
|
|
70
70
|
},
|
|
71
71
|
"homepage": "https://github.com/alchemyplatform/aa-sdk#readme",
|
|
72
|
-
"gitHead": "
|
|
72
|
+
"gitHead": "5d0007b85f6594847cbafbc2326cb6ce17239bf7",
|
|
73
73
|
"dependencies": {
|
|
74
|
-
"@aa-sdk/core": "^4.
|
|
75
|
-
"@account-kit/infra": "^4.
|
|
74
|
+
"@aa-sdk/core": "^4.71.1",
|
|
75
|
+
"@account-kit/infra": "^4.71.1",
|
|
76
76
|
"webauthn-p256": "^0.0.10"
|
|
77
77
|
},
|
|
78
78
|
"peerDependencies": {
|
|
@@ -13,6 +13,7 @@ import {
|
|
|
13
13
|
import {
|
|
14
14
|
concatHex,
|
|
15
15
|
encodeFunctionData,
|
|
16
|
+
isAddressEqual,
|
|
16
17
|
type Address,
|
|
17
18
|
type Chain,
|
|
18
19
|
type Hex,
|
|
@@ -210,7 +211,7 @@ export async function createModularAccountV2<
|
|
|
210
211
|
const accountAddress = _accountAddress ?? signerAddress;
|
|
211
212
|
if (
|
|
212
213
|
entityId === DEFAULT_OWNER_ENTITY_ID &&
|
|
213
|
-
signerAddress
|
|
214
|
+
!isAddressEqual(signerAddress, accountAddress)
|
|
214
215
|
) {
|
|
215
216
|
throw new EntityIdOverrideError();
|
|
216
217
|
}
|