diff --git a/aa-sdk/core/src/errors/client.ts b/aa-sdk/core/src/errors/client.ts index 2e5f0d0737..b1ccddb739 100644 --- a/aa-sdk/core/src/errors/client.ts +++ b/aa-sdk/core/src/errors/client.ts @@ -84,7 +84,9 @@ export class InvalidNonceKeyError extends BaseError { * @param {bigint} nonceKey the invalid nonceKey used */ constructor(nonceKey: bigint) { - super(`Nonce key is ${nonceKey} but has to be less than 2**152`); + super( + `Nonce key is ${nonceKey} but has to be less than or equal to 2**152` + ); } } @@ -98,8 +100,6 @@ export class EntityIdOverrideError extends BaseError { * Initializes a new instance of the error message with a default message indicating that the nonce key is invalid. */ constructor() { - super( - `Installing entityId of 0 overrides the owner's entity id in the account` - ); + super(`EntityId of 0 is reserved for the owner and cannot be used`); } } diff --git a/account-kit/smart-contracts/src/index.ts b/account-kit/smart-contracts/src/index.ts index d55a0f43a8..a2ba4feddc 100644 --- a/account-kit/smart-contracts/src/index.ts +++ b/account-kit/smart-contracts/src/index.ts @@ -115,3 +115,51 @@ export { getMAInitializationData, getMSCAUpgradeToData, } from "./msca/utils.js"; + +// ma v2 exports +export { accountFactoryAbi } from "./ma-v2/abis/accountFactoryAbi.js"; +export { modularAccountAbi } from "./ma-v2/abis/modularAccountAbi.js"; +export { semiModularAccountBytecodeAbi } from "./ma-v2/abis/semiModularAccountBytecodeAbi.js"; +export { semiModularAccountStorageAbi } from "./ma-v2/abis/semiModularAccountStorageAbi.js"; + +export { nativeSMASigner } from "./ma-v2/account/nativeSMASigner.js"; +export type * from "./ma-v2/account/semiModularAccountV2.js"; +export { createSMAV2Account } from "./ma-v2/account/semiModularAccountV2.js"; + +export type { + ModuleEntity, + ValidationConfig, + HookConfig, + ValidationData, +} from "./ma-v2/actions/common/types.js"; +export { HookType } from "./ma-v2/actions/common/types.js"; +export { + serializeValidationConfig, + serializeHookConfig, + serializeModuleEntity, +} from "./ma-v2/actions/common/utils.js"; +export type * from "./ma-v2/actions/install-validation/installValidation.js"; +export { installValidationActions } from "./ma-v2/actions/install-validation/installValidation.js"; + +export type * from "./ma-v2/client/client.js"; +export { createSMAV2AccountClient } from "./ma-v2/client/client.js"; + +export { + getDefaultAllowlistModuleAddress, + getDefaultNativeTokenLimitModuleAddress, + getDefaultPaymasterGuardModuleAddress, + getDefaultSingleSignerValidationModuleAddress, + getDefaultTimeRangeModuleAddress, + getDefaultWebauthnValidationModuleAddress, +} from "./ma-v2/modules/utils.js"; +export { allowlistModuleAbi } from "./ma-v2/modules/allowlist-module/abis/allowlistModuleAbi.js"; +export { AllowlistModule } from "./ma-v2/modules/allowlist-module/module.js"; +export { nativeTokenLimitModuleAbi } from "./ma-v2/modules/native-token-limit-module/abis/nativeTokenLimitModuleAbi.js"; +export { NativeTokenLimitModule } from "./ma-v2/modules/native-token-limit-module/module.js"; +export { paymasterGuardModuleAbi } from "./ma-v2/modules/paymaster-guard-module/abis/paymasterGuardModuleAbi.js"; +export { PaymasterGuardModule } from "./ma-v2/modules/paymaster-guard-module/module.js"; +export { singleSignerValidationModuleAbi } from "./ma-v2/modules/single-signer-validation/abis/singleSignerValidationModuleAbi.js"; +export { SingleSignerValidationModule } from "./ma-v2/modules/single-signer-validation/module.js"; +export { timeRangeModuleAbi } from "./ma-v2/modules/time-range-module/abis/timeRangeModuleAbi.js"; +export { TimeRangeModule } from "./ma-v2/modules/time-range-module/module.js"; +export { webauthnValidationModuleAbi } from "./ma-v2/modules/webauthn-validation/abis/webauthnValidationAbi.js"; diff --git a/account-kit/smart-contracts/src/ma-v2/account/nativeSMASigner.ts b/account-kit/smart-contracts/src/ma-v2/account/nativeSMASigner.ts index 1b1237a8c1..61e3974de8 100644 --- a/account-kit/smart-contracts/src/ma-v2/account/nativeSMASigner.ts +++ b/account-kit/smart-contracts/src/ma-v2/account/nativeSMASigner.ts @@ -10,13 +10,17 @@ import { type Address, } from "viem"; -import { packUOSignature, pack1271Signature } from "../utils.js"; +import { + packUOSignature, + pack1271Signature, + DEFAULT_OWNER_ENTITY_ID, +} from "../utils.js"; /** * Creates an object with methods for generating a dummy signature, signing user operation hashes, signing messages, and signing typed data. * * @example * ```ts - * import { singleSignerMessageSigner } from "@account-kit/smart-contracts"; + * import { nativeSMASigner } from "@account-kit/smart-contracts"; * import { LocalAccountSigner } from "@aa-sdk/core"; * @@ -26,20 +30,18 @@ import { packUOSignature, pack1271Signature } from "../utils.js"; * * const signer = LocalAccountSigner.mnemonicToAccountSigner(MNEMONIC); * - * const messageSigner = singleSignerMessageSigner(signer, chain); + * const messageSigner = nativeSMASigner(signer, chain, account.address); * ``` * * @param {SmartAccountSigner} signer Signer to use for signing operations * @param {Chain} chain Chain object for the signer * @param {Address} accountAddress address of the smart account using this signer - * @param {number} entityId the entity id of the signing validation * @returns {object} an object with methods for signing operations and managing signatures */ export const nativeSMASigner = ( signer: SmartAccountSigner, chain: Chain, - accountAddress: Address, - entityId: number + accountAddress: Address ) => { return { getDummySignature: (): Hex => { @@ -79,7 +81,7 @@ export const nativeSMASigner = ( }, primaryType: "ReplaySafeHash", }), - entityId, + entityId: DEFAULT_OWNER_ENTITY_ID, }); }, @@ -112,7 +114,7 @@ export const nativeSMASigner = ( }, primaryType: "ReplaySafeHash", }), - entityId, + entityId: DEFAULT_OWNER_ENTITY_ID, }); }, }; diff --git a/account-kit/smart-contracts/src/ma-v2/account/semiModularAccountV2.ts b/account-kit/smart-contracts/src/ma-v2/account/semiModularAccountV2.ts index 7f3ed73a82..83bf5d5772 100644 --- a/account-kit/smart-contracts/src/ma-v2/account/semiModularAccountV2.ts +++ b/account-kit/smart-contracts/src/ma-v2/account/semiModularAccountV2.ts @@ -66,9 +66,9 @@ export type ValidationDataParams = entityId: number; }; -export type SMAV2Account< +export type MAV2Account< TSigner extends SmartAccountSigner = SmartAccountSigner -> = SmartContractAccountWithSigner<"SMAV2Account", TSigner, "0.7.0"> & { +> = SmartContractAccountWithSigner<"MAV2Account", TSigner, "0.7.0"> & { signerEntity: SignerEntity; getExecutionData: (selector: Hex) => Promise; getValidationData: ( @@ -81,7 +81,7 @@ export type CreateSMAV2AccountParams< TTransport extends Transport = Transport, TSigner extends SmartAccountSigner = SmartAccountSigner > = Pick< - ToSmartContractAccountParams<"SMAV2Account", TTransport, Chain, "0.7.0">, + ToSmartContractAccountParams<"MAV2Account", TTransport, Chain, "0.7.0">, "transport" | "chain" | "accountAddress" > & { signer: TSigner; @@ -98,11 +98,18 @@ export async function createSMAV2Account< TSigner extends SmartAccountSigner = SmartAccountSigner >( config: CreateSMAV2AccountParams -): Promise>; +): Promise>; +/** + * Creates an SMAV2 account using defined parameters including chain, signer, salt, factory address, and more. + * Handles account initialization code, nonce generation, transaction encoding, and more to construct a modular account with optional validation hooks. + * + * @param {CreateSMAV2AccountParams} config Configuration parameters for creating an SMAV2 account. Includes chain details, signer, salt, factory address, and more. + * @returns {Promise} A promise that resolves to an `MAV2Account` providing methods for nonce retrieval, transaction execution, and more. + */ export async function createSMAV2Account( config: CreateSMAV2AccountParams -): Promise { +): Promise { const { transport, chain, @@ -117,10 +124,12 @@ export async function createSMAV2Account( isGlobalValidation: true, entityId: DEFAULT_OWNER_ENTITY_ID, }, + signerEntity: { + isGlobalValidation = true, + entityId = DEFAULT_OWNER_ENTITY_ID, + } = {}, } = config; - const { isGlobalValidation, entityId } = signerEntity; - if (entityId > Number(maxUint32)) { throw new InvalidEntityIdError(entityId); } @@ -188,18 +197,18 @@ export async function createSMAV2Account( chain, entryPoint, accountAddress: _accountAddress, - source: `SMAV2Account`, + source: `MAV2Account`, encodeExecute, encodeBatchExecute, getAccountInitCode, ...(entityId === DEFAULT_OWNER_ENTITY_ID - ? nativeSMASigner(signer, chain, _accountAddress, entityId) + ? nativeSMASigner(signer, chain, _accountAddress) : singleSignerMessageSigner(signer, chain, _accountAddress, entityId)), }); // TODO: add deferred action flag - const getAccountNonce = async (nonceKey?: bigint): Promise => { - if (nonceKey && nonceKey > maxUint152) { + const getAccountNonce = async (nonceKey: bigint = 0n): Promise => { + if (nonceKey > maxUint152) { throw new InvalidNonceKeyError(nonceKey); } @@ -210,7 +219,7 @@ export async function createSMAV2Account( }); const fullNonceKey: bigint = - (nonceKey ? nonceKey << 40n : 0n) + + (nonceKey << 40n) + BigInt(entityId << 8) + (isGlobalValidation ? 1n : 0n); diff --git a/account-kit/smart-contracts/src/ma-v2/actions/common/utils.ts b/account-kit/smart-contracts/src/ma-v2/actions/common/utils.ts index 8bd366ab76..f1f08f331a 100644 --- a/account-kit/smart-contracts/src/ma-v2/actions/common/utils.ts +++ b/account-kit/smart-contracts/src/ma-v2/actions/common/utils.ts @@ -2,6 +2,31 @@ import { type Hex, toHex, concatHex } from "viem"; import type { ValidationConfig, HookConfig, ModuleEntity } from "./types"; import { HookType } from "./types.js"; +/** + * Serializes a validation configuration into a hexadecimal string representation. This involves converting boolean flags into bitwise representation and combining them with serialized module entity data. + * + * @example + * ```ts + * import { serializeValidationConfig } from "@account-kit/smart-contracts"; + * import { Address } from "viem"; + * + * const moduleAddress: Address = "0x1234"; + * const entityId: number = 1234; + * const isGlobal: boolean = true; + * const isSignatureValidation: boolean = false; + * const isUserOpValidation: boolean = true; + * + * const validationConfigHex = serializeValidationConfig({ + * moduleAddress, + * entityId + * isGlobal, + * isSignatureValidation, + * isUserOpValidation + * }); + * ``` + * @param {ValidationConfig} config The validation configuration object containing details to serialize + * @returns {Hex} A hexadecimal string representing the serialized configuration + */ export function serializeValidationConfig(config: ValidationConfig): Hex { const isUserOpValidationBit = config.isUserOpValidation ? 1 : 0; const isSignatureValidationBit = config.isSignatureValidation ? 2 : 0; @@ -14,6 +39,32 @@ export function serializeValidationConfig(config: ValidationConfig): Hex { ]); } +/** + * Serializes a `HookConfig` object into a `Hex` format by encoding the hook type, presence of post/pre hooks, address, and entity ID. + * + * @example + * ```ts + * import { type HookType, serializeHookConfig } from "@account-kit/smart-contracts"; + * import { Address } from "viem"; + * + * const moduleAddress: Address = "0x1234"; + * const entityId: number = 1234; + * const hookType: HookType = HookType.Validation; + * const hasPostHooks: boolean = false; + * const hasPreHooks: boolean = true; + * + * const hookConfigHex = serializeHookConfig({ + * moduleAddress, + * entityId + * hookType, + * hasPostHooks, + * hasPreHooks + * }); + * ``` + * + * @param {HookConfig} config The hook configuration containing address, entity ID, hook type, and post/pre hook indicators + * @returns {Hex} The serialized hook configuration in hexadecimal format + */ export function serializeHookConfig(config: HookConfig): Hex { const hookTypeBit = config.hookType === HookType.VALIDATION ? 1 : 0; const hasPostHooksBit = config.hasPostHooks ? 2 : 0; @@ -27,6 +78,26 @@ export function serializeHookConfig(config: HookConfig): Hex { ]); } +/** + * Serializes a module entity into a hexadecimal format by concatenating the module address and entity ID. + * + * @example + * ```ts + * import { serializeModuleEntity } from "@account-kit/smart-contracts"; + * import { Address } from "viem"; + * + * const moduleAddress: Address = "0x1234"; + * const entityId: number = 1234; + * + * const moduleEntityHex = serializeModuleEntity({ + * moduleAddress, + * entityId + * }); + * ``` + * + * @param {ModuleEntity} config The module entity configuration containing the module address and entity ID + * @returns {Hex} A hexadecimal string representation of the serialized module entity + */ export function serializeModuleEntity(config: ModuleEntity): Hex { return concatHex([config.moduleAddress, toHex(config.entityId, { size: 4 })]); } diff --git a/account-kit/smart-contracts/src/ma-v2/actions/install-validation/installValidation.ts b/account-kit/smart-contracts/src/ma-v2/actions/install-validation/installValidation.ts index fc4329b455..ffc1c38fea 100644 --- a/account-kit/smart-contracts/src/ma-v2/actions/install-validation/installValidation.ts +++ b/account-kit/smart-contracts/src/ma-v2/actions/install-validation/installValidation.ts @@ -25,7 +25,7 @@ import { } from "../common/utils.js"; import { type SMAV2AccountClient } from "../../client/client.js"; -import { type SMAV2Account } from "../../account/semiModularAccountV2.js"; +import { type MAV2Account } from "../../account/semiModularAccountV2.js"; import { DEFAULT_OWNER_ENTITY_ID } from "../../utils.js"; export type InstallValidationParams< @@ -38,9 +38,9 @@ export type InstallValidationParams< hookConfig: HookConfig; initData: Hex; }[]; - account?: SMAV2Account | undefined; + account?: MAV2Account | undefined; } & UserOperationOverridesParameter< - GetEntryPointFromAccount> + GetEntryPointFromAccount> >; export type UninstallValidationParams< @@ -50,9 +50,9 @@ export type UninstallValidationParams< entityId: number; uninstallData: Hex; hookUninstallDatas: Hex[]; - account?: SMAV2Account | undefined; + account?: MAV2Account | undefined; } & UserOperationOverridesParameter< - GetEntryPointFromAccount> + GetEntryPointFromAccount> >; export type InstallValidationActions< @@ -66,6 +66,50 @@ export type InstallValidationActions< ) => Promise; }; +/** + * Provides validation installation and uninstallation functionalities for a MA v2 client, ensuring compatibility with `SmartAccountClient`. + * + * @example + * ```ts + * import { createSMAV2AccountClient, installValidationActions, getDefaultSingleSignerValidationModuleAddress, SingleSignerValidationModule } from "@account-kit/smart-contracts"; + * import { Address } from "viem"; + * + * const client = (await createSMAV2AccountClient({ ... })).extend(installValidationActions); + * const sessionKeyAddress: Address = "0x1234"; + * const sessionKeyEntityId: number = 1; + * + * await client.installValidation({ + * validationConfig: { + * moduleAddress: getDefaultSingleSignerValidationModuleAddress( + * client.chain + * ), + * entityId: sessionKeyEntityId, + * isGlobal: true, + * isSignatureValidation: false, + * isUserOpValidation: true, + * }, + * selectors: [], + * installData: SingleSignerValidationModule.encodeOnInstallData({ + * entityId: sessionKeyEntityId, + * signer: sessionKeyAddress, + * }), + * hooks: [], + * }); + * + * await client.uninstallValidation({ + * moduleAddress: sessionKeyAddress, + * entityId: sessionKeyEntityId, + * uninstallData: SingleSignerValidationModule.encodeOnUninstallData({ + * entityId: sessionKeyEntityId, + * }), + * hookUninstallDatas: [], + * }); + * + * ``` + * + * @param {object} client - The client instance which provides account and sendUserOperation functionality. + * @returns {object} - An object containing two methods, `installValidation` and `uninstallValidation`. + */ export const installValidationActions: < TSigner extends SmartAccountSigner = SmartAccountSigner >( diff --git a/account-kit/smart-contracts/src/ma-v2/client/client.test.ts b/account-kit/smart-contracts/src/ma-v2/client/client.test.ts index af63c7f08f..098514aee7 100644 --- a/account-kit/smart-contracts/src/ma-v2/client/client.test.ts +++ b/account-kit/smart-contracts/src/ma-v2/client/client.test.ts @@ -10,27 +10,28 @@ import { zeroAddress, getContract, hashMessage, + hashTypedData, } from "viem"; -import { createSMAV2AccountClient } from "./client.js"; -import { local070Instance } from "~test/instances.js"; -import { setBalance } from "viem/actions"; -import { accounts } from "~test/constants.js"; +import { HookType } from "../actions/common/types.js"; import { + createSMAV2AccountClient, getDefaultPaymasterGuardModuleAddress, getDefaultSingleSignerValidationModuleAddress, getDefaultTimeRangeModuleAddress, getDefaultAllowlistModuleAddress, getDefaultNativeTokenLimitModuleAddress, -} from "../modules/utils.js"; -import { SingleSignerValidationModule } from "../modules/single-signer-validation/module.js"; -import { installValidationActions } from "../actions/install-validation/installValidation.js"; + installValidationActions, + SingleSignerValidationModule, + PaymasterGuardModule, + TimeRangeModule, + AllowlistModule, + NativeTokenLimitModule, + semiModularAccountBytecodeAbi, +} from "@account-kit/smart-contracts"; +import { local070Instance } from "~test/instances.js"; +import { setBalance } from "viem/actions"; +import { accounts } from "~test/constants.js"; import { paymaster070 } from "~test/paymaster/paymaster070.js"; -import { PaymasterGuardModule } from "../modules/paymaster-guard-module/module.js"; -import { HookType } from "../actions/common/types.js"; -import { TimeRangeModule } from "../modules/time-range-module/module.js"; -import { allowlistModule } from "../modules/allowlist-module/module.js"; -import { nativeTokenLimitModule } from "../modules/native-token-limit-module/module.js"; -import { semiModularAccountBytecodeAbi } from "../abis/semiModularAccountBytecodeAbi.js"; // TODO: Include a snapshot to reset to in afterEach. describe("MA v2 Tests", async () => { @@ -130,7 +131,7 @@ describe("MA v2 Tests", async () => { accountContract.read.isValidSignature([hashMessage(message), signature]) ).resolves.toEqual(isValidSigSuccess); - // connect session key and send tx with session key + // connect session key let sessionKeyClient = await createSMAV2AccountClient({ chain: instance.chain, signer: sessionKey, @@ -146,6 +147,98 @@ describe("MA v2 Tests", async () => { ).resolves.toEqual(isValidSigSuccess); }); + it("successfully sign + validate typed data messages, for native and single signer validation", async () => { + const provider = (await givenConnectedProvider({ signer })).extend( + installValidationActions + ); + + await setBalance(instance.getClient(), { + address: provider.getAddress(), + value: parseEther("2"), + }); + + const accountContract = getContract({ + address: provider.getAddress(), + abi: semiModularAccountBytecodeAbi, + client, + }); + + // UO deploys the account to test 1271 against + const result = await provider.installValidation({ + validationConfig: { + moduleAddress: getDefaultSingleSignerValidationModuleAddress( + provider.chain + ), + entityId: 1, + isGlobal: true, + isSignatureValidation: true, + isUserOpValidation: true, + }, + selectors: [], + installData: SingleSignerValidationModule.encodeOnInstallData({ + entityId: 1, + signer: await sessionKey.getAddress(), + }), + hooks: [], + }); + + await provider.waitForUserOperationTransaction(result); + + const typedData = { + domain: { + name: "Ether Mail", + version: "1", + chainId: 1, + verifyingContract: "0xCcCCccccCCCCcCCCCCCcCcCccCcCCCcCcccccccC", + }, + types: { + Person: [ + { name: "name", type: "string" }, + { name: "wallet", type: "address" }, + ], + Mail: [ + { name: "from", type: "Person" }, + { name: "to", type: "Person" }, + { name: "contents", type: "string" }, + ], + }, + primaryType: "Mail", + message: { + from: { + name: "Cow", + wallet: "0xCD2a3d9F938E13CD947Ec05AbC7FE734Df8DD826", + }, + to: { + name: "Bob", + wallet: "0xbBbBBBBbbBBBbbbBbbBbbbbBBbBbbbbBbBbbBBbB", + }, + contents: "Hello, Bob!", + }, + }; + + const hashedMessageTypedData = hashTypedData(typedData); + let signature = await provider.signTypedData({ typedData }); + + await expect( + accountContract.read.isValidSignature([hashedMessageTypedData, signature]) + ).resolves.toEqual(isValidSigSuccess); + + // connect session key + let sessionKeyClient = await createSMAV2AccountClient({ + chain: instance.chain, + signer: sessionKey, + transport: custom(instance.getClient()), + accountAddress: provider.getAddress(), + signerEntity: { entityId: 1, isGlobalValidation: true }, + }); + + signature = await sessionKeyClient.signTypedData({ typedData }); + + await expect( + accountContract.read.isValidSignature([hashedMessageTypedData, signature]) + ).resolves.toEqual(isValidSigSuccess); + }); + it("adds a session key with no permissions", async () => { let provider = (await givenConnectedProvider({ signer })).extend( installValidationActions @@ -432,7 +525,7 @@ describe("MA v2 Tests", async () => { value: parseEther("2"), }); - const hookInstallData = allowlistModule.encodeOnInstallData({ + const hookInstallData = AllowlistModule.encodeOnInstallData({ entityId: 0, inputs: [ { @@ -494,7 +587,7 @@ describe("MA v2 Tests", async () => { }) ).rejects.toThrowError(); - const hookUninstallData = allowlistModule.encodeOnUninstallData({ + const hookUninstallData = AllowlistModule.encodeOnUninstallData({ entityId: 0, inputs: [ { @@ -541,7 +634,7 @@ describe("MA v2 Tests", async () => { const spendLimit = parseEther("0.5"); // Let's verify the module's limit is set correctly after installation - const hookInstallData = nativeTokenLimitModule.encodeOnInstallData({ + const hookInstallData = NativeTokenLimitModule.encodeOnInstallData({ entityId: 0, spendLimit, }); @@ -603,7 +696,7 @@ describe("MA v2 Tests", async () => { }) ).rejects.toThrowError(); - const hookUninstallData = nativeTokenLimitModule.encodeOnUninstallData({ + const hookUninstallData = NativeTokenLimitModule.encodeOnUninstallData({ entityId: 0, }); diff --git a/account-kit/smart-contracts/src/ma-v2/client/client.ts b/account-kit/smart-contracts/src/ma-v2/client/client.ts index 6e7783e74d..58bf4f3dc6 100644 --- a/account-kit/smart-contracts/src/ma-v2/client/client.ts +++ b/account-kit/smart-contracts/src/ma-v2/client/client.ts @@ -9,12 +9,12 @@ import { type Chain, type Transport } from "viem"; import { createSMAV2Account, type CreateSMAV2AccountParams, - type SMAV2Account, + type MAV2Account, } from "../account/semiModularAccountV2.js"; export type SMAV2AccountClient< TSigner extends SmartAccountSigner = SmartAccountSigner -> = SmartAccountClient>; +> = SmartAccountClient>; export type CreateSMAV2AccountClientParams< TTransport extends Transport = Transport, @@ -34,7 +34,7 @@ export function createSMAV2AccountClient< ): Promise>; /** - * Creates a MAv2 account client using the provided configuration parameters. + * Creates a SMAv2 account client using the provided configuration parameters. * * @example * ```ts @@ -65,10 +65,10 @@ export function createSMAV2AccountClient< export async function createSMAV2AccountClient( config: CreateSMAV2AccountClientParams ): Promise { - const maV2Account = await createSMAV2Account(config); + const smaV2Account = await createSMAV2Account(config); return createSmartAccountClient({ ...config, - account: maV2Account, + account: smaV2Account, }); } diff --git a/account-kit/smart-contracts/src/ma-v2/modules/allowlist-module/module.ts b/account-kit/smart-contracts/src/ma-v2/modules/allowlist-module/module.ts index 67f4da1406..911f53b1fd 100644 --- a/account-kit/smart-contracts/src/ma-v2/modules/allowlist-module/module.ts +++ b/account-kit/smart-contracts/src/ma-v2/modules/allowlist-module/module.ts @@ -1,7 +1,7 @@ import { encodeAbiParameters, type Address, type Hex } from "viem"; import { allowlistModuleAbi } from "./abis/allowlistModuleAbi.js"; -export const allowlistModule = { +export const AllowlistModule = { abi: allowlistModuleAbi, encodeOnInstallData: (args: { entityId: number; diff --git a/account-kit/smart-contracts/src/ma-v2/modules/native-token-limit-module/module.ts b/account-kit/smart-contracts/src/ma-v2/modules/native-token-limit-module/module.ts index 5e8c84dc5c..764176d27a 100644 --- a/account-kit/smart-contracts/src/ma-v2/modules/native-token-limit-module/module.ts +++ b/account-kit/smart-contracts/src/ma-v2/modules/native-token-limit-module/module.ts @@ -1,7 +1,7 @@ import { encodeAbiParameters, type Hex } from "viem"; import { nativeTokenLimitModuleAbi } from "./abis/nativeTokenLimitModuleAbi.js"; -export const nativeTokenLimitModule = { +export const NativeTokenLimitModule = { abi: nativeTokenLimitModuleAbi, encodeOnInstallData: (args: { entityId: number; diff --git a/account-kit/smart-contracts/src/ma-v2/modules/single-signer-validation/signer.ts b/account-kit/smart-contracts/src/ma-v2/modules/single-signer-validation/signer.ts index c6c477274b..04f13ffcfa 100644 --- a/account-kit/smart-contracts/src/ma-v2/modules/single-signer-validation/signer.ts +++ b/account-kit/smart-contracts/src/ma-v2/modules/single-signer-validation/signer.ts @@ -28,7 +28,7 @@ import { packUOSignature, pack1271Signature } from "../../utils.js"; * * const signer = LocalAccountSigner.mnemonicToAccountSigner(MNEMONIC); * - * const messageSigner = singleSignerMessageSigner(signer, chain); + * const messageSigner = singleSignerMessageSigner(signer, chain, account.address, account.signerEntity.entityId); * ``` * * @param {SmartAccountSigner} signer Signer to use for signing operations @@ -105,7 +105,7 @@ export const singleSignerMessageSigner = ( chainId: Number(chain.id), verifyingContract: getDefaultSingleSignerValidationModuleAddress(chain), - salt: accountAddress, + salt: concatHex([`0x${"00".repeat(12)}`, accountAddress]), }, types: { ReplaySafeHash: [{ name: "hash", type: "bytes32" }], diff --git a/account-kit/smart-contracts/src/ma-v2/modules/time-range-module/module.ts b/account-kit/smart-contracts/src/ma-v2/modules/time-range-module/module.ts index 6045dc0f2c..a6b3680278 100644 --- a/account-kit/smart-contracts/src/ma-v2/modules/time-range-module/module.ts +++ b/account-kit/smart-contracts/src/ma-v2/modules/time-range-module/module.ts @@ -2,7 +2,6 @@ import { encodeAbiParameters, type Hex } from "viem"; import { timeRangeModuleAbi } from "./abis/timeRangeModuleAbi.js"; -// Todo: some unified type for ERC-6900 v0.8 modules. I couldn't figure out how to parameterize the class itself over the abi type parameters for onInstall and onUninstall. export const TimeRangeModule = { abi: timeRangeModuleAbi, encodeOnInstallData: (args: { diff --git a/account-kit/smart-contracts/src/ma-v2/modules/utils.ts b/account-kit/smart-contracts/src/ma-v2/modules/utils.ts index 8da6ba6028..e940d097a4 100644 --- a/account-kit/smart-contracts/src/ma-v2/modules/utils.ts +++ b/account-kit/smart-contracts/src/ma-v2/modules/utils.ts @@ -12,6 +12,20 @@ import { sepolia, } from "@account-kit/infra"; +/** + * Maps a given chain to a specific address of the webauthn validation module by its chain ID. If no direct mapping exists, it defaults to returning a specific address. + * + * @example + * ```ts + * import { getDefaultWebauthnValidationModuleAddress } from "@account-kit/smart-contracts"; + * import { Chain, Address } from "viem"; + * + * const chain: Chain = ... + * const webauthnValidationAddress: Address = getDefaultWebauthnValidationModuleAddress(chain); + * ``` + * @param {Chain} chain The chain object containing the chain ID to map + * @returns {Address} The webauthn validation module address associated with the specified chain ID or a default address if no specific mapping exists + */ export const getDefaultWebauthnValidationModuleAddress = ( chain: Chain ): Address => { @@ -32,6 +46,20 @@ export const getDefaultWebauthnValidationModuleAddress = ( } }; +/** + * Maps a given chain to a specific address of the time range module by its chain ID. If no direct mapping exists, it defaults to returning a specific address. + * + * @example + * ```ts + * import { getDefaultTimeRangeModuleAddress } from "@account-kit/smart-contracts"; + * import { Chain, Address } from "viem"; + * + * const chain: Chain = ... + * const timeRangeModuleAddress: Address = getDefaultTimeRangeModuleAddress(chain); + * ``` + * @param {Chain} chain The chain object containing the chain ID to map + * @returns {Address} The time range module address associated with the specified chain ID or a default address if no specific mapping exists + */ export const getDefaultTimeRangeModuleAddress = (chain: Chain): Address => { switch (chain.id) { // TODO: case mekong.id: @@ -50,6 +78,20 @@ export const getDefaultTimeRangeModuleAddress = (chain: Chain): Address => { } }; +/** + * Maps a given chain to a specific address of the single signer validation module by its chain ID. If no direct mapping exists, it defaults to returning a specific address. + * + * @example + * ```ts + * import { getDefaultSingleSignerValidationModuleAddress } from "@account-kit/smart-contracts"; + * import { Chain, Address } from "viem"; + * + * const chain: Chain = ... + * const singleSignerValidationAddress: Address = getDefaultSingleSignerValidationModuleAddress(chain); + * ``` + * @param {Chain} chain The chain object containing the chain ID to map + * @returns {Address} The single signer validation module address associated with the specified chain ID or a default address if no specific mapping exists + */ export const getDefaultSingleSignerValidationModuleAddress = ( chain: Chain ): Address => { @@ -70,6 +112,20 @@ export const getDefaultSingleSignerValidationModuleAddress = ( } }; +/** + * Maps a given chain to a specific address of the paymaster guard module by its chain ID. If no direct mapping exists, it defaults to returning a specific address. + * + * @example + * ```ts + * import { getDefaultPaymasterGuardModuleAddress } from "@account-kit/smart-contracts"; + * import { Chain, Address } from "viem"; + * + * const chain: Chain = ... + * const paymasterGuardAddress: Address = getDefaultPaymasterGuardModuleAddress(chain); + * ``` + * @param {Chain} chain The chain object containing the chain ID to map + * @returns {Address} The paymaster guard module address associated with the specified chain ID or a default address if no specific mapping exists + */ export const getDefaultPaymasterGuardModuleAddress = ( chain: Chain ): Address => { @@ -90,6 +146,20 @@ export const getDefaultPaymasterGuardModuleAddress = ( } }; +/** + * Maps a given chain to a specific address of the native token limit module by its chain ID. If no direct mapping exists, it defaults to returning a specific address. + * + * @example + * ```ts + * import { getDefaultNativeTokenLimitModuleAddress } from "@account-kit/smart-contracts"; + * import { Chain, Address } from "viem"; + * + * const chain: Chain = ... + * const nativeTokenLimitAddress: Address = getDefaultNativeTokenLimitModuleAddress(chain); + * ``` + * @param {Chain} chain The chain object containing the chain ID to map + * @returns {Address} The native token limit module address associated with the specified chain ID or a default address if no specific mapping exists + */ export const getDefaultNativeTokenLimitModuleAddress = ( chain: Chain ): Address => { @@ -110,6 +180,20 @@ export const getDefaultNativeTokenLimitModuleAddress = ( } }; +/** + * Maps a given chain to a specific address of the allowlist module by its chain ID. If no direct mapping exists, it defaults to returning a specific address. + * + * @example + * ```ts + * import { getDefaultAllowlistModuleAddress } from "@account-kit/smart-contracts"; + * import { Chain, Address } from "viem"; + * + * const chain: Chain = ... + * const allowlistModule: Address = getDefaultAllowlistModuleAddress(chain); + * ``` + * @param {Chain} chain The chain object containing the chain ID to map + * @returns {Address} The allowlist module address associated with the specified chain ID or a default address if no specific mapping exists + */ export const getDefaultAllowlistModuleAddress = (chain: Chain): Address => { switch (chain.id) { // TODO: case mekong.id: diff --git a/site/pages/reference/account-kit/smart-contracts/functions/createSMAV2Account.mdx b/site/pages/reference/account-kit/smart-contracts/functions/createSMAV2Account.mdx new file mode 100644 index 0000000000..d789f0559b --- /dev/null +++ b/site/pages/reference/account-kit/smart-contracts/functions/createSMAV2Account.mdx @@ -0,0 +1,28 @@ +--- +# This file is autogenerated +title: createSMAV2Account +description: Overview of the createSMAV2Account method +--- + +# createSMAV2Account + +Creates an SMAV2 account using defined parameters including chain, signer, salt, factory address, and more. +Handles account initialization code, nonce generation, transaction encoding, and more to construct a modular account with optional validation hooks. + +## Import + +```ts +import { createSMAV2Account } from "@account-kit/smart-contracts"; +``` + +## Parameters + +### config + +`CreateSMAV2AccountParams` +Configuration parameters for creating an SMAV2 account. Includes chain details, signer, salt, factory address, and more. + +## Returns + +`Promise` +A promise that resolves to an `MAV2Account` providing methods for nonce retrieval, transaction execution, and more. diff --git a/site/pages/reference/account-kit/smart-contracts/functions/createSMAV2AccountClient.mdx b/site/pages/reference/account-kit/smart-contracts/functions/createSMAV2AccountClient.mdx new file mode 100644 index 0000000000..8b7bcd96ab --- /dev/null +++ b/site/pages/reference/account-kit/smart-contracts/functions/createSMAV2AccountClient.mdx @@ -0,0 +1,52 @@ +--- +# This file is autogenerated + +title: createSMAV2AccountClient +description: Overview of the createSMAV2AccountClient method +--- + +# createSMAV2AccountClient + +Creates a SMAv2 account client using the provided configuration parameters. + +## Import + +```ts +import { createSMAV2AccountClient } from "@account-kit/smart-contracts"; +``` + +## Usage + +```ts +import { http } from "viem"; +import { createSMAV2AccountClient } from "@account-kit/smart-contracts"; +import { LocalAccountSigner } from "@aa-sdk/core"; +import { sepolia } from "@account-kit/infra"; + +const MNEMONIC = "..."; +const RPC_URL = "..."; + +const signer = LocalAccountSigner.mnemonicToAccountSigner(MNEMONIC); + +const chain = sepolia; + +const transport = http(RPC_URL); + +const SMAV2SignerAccountClient = await createSMAV2AccountClient({ + chain, + signer, + transport, +}); +``` + +## Parameters + +### config + +`CreateSMAV2AccountClientParams` +The configuration parameters required to create the MAv2 account client + +## Returns + +`Promise` +A promise that resolves to a `SmartAccountClient` instance diff --git a/site/pages/reference/account-kit/smart-contracts/functions/getDefaultAllowlistModuleAddress.mdx b/site/pages/reference/account-kit/smart-contracts/functions/getDefaultAllowlistModuleAddress.mdx new file mode 100644 index 0000000000..5522e43076 --- /dev/null +++ b/site/pages/reference/account-kit/smart-contracts/functions/getDefaultAllowlistModuleAddress.mdx @@ -0,0 +1,37 @@ +--- +# This file is autogenerated +title: getDefaultAllowlistModuleAddress +description: Overview of the getDefaultAllowlistModuleAddress method +--- + +# getDefaultAllowlistModuleAddress + +Maps a given chain to a specific address of the allowlist module by its chain ID. If no direct mapping exists, it defaults to returning a specific address. + +## Import + +```ts +import { getDefaultAllowlistModuleAddress } from "@account-kit/smart-contracts"; +``` + +## Usage + +```ts +import { getDefaultAllowlistModuleAddress } from "@account-kit/smart-contracts"; +import { Chain, Address } from "viem"; + +const chain: Chain = ... +const allowlistModule: Address = getDefaultAllowlistModuleAddress(chain); +``` + +## Parameters + +### chain + +`Chain` +The chain object containing the chain ID to map + +## Returns + +`Address` +The allowlist module address associated with the specified chain ID or a default address if no specific mapping exists diff --git a/site/pages/reference/account-kit/smart-contracts/functions/getDefaultNativeTokenLimitModuleAddress.mdx b/site/pages/reference/account-kit/smart-contracts/functions/getDefaultNativeTokenLimitModuleAddress.mdx new file mode 100644 index 0000000000..54dcc49268 --- /dev/null +++ b/site/pages/reference/account-kit/smart-contracts/functions/getDefaultNativeTokenLimitModuleAddress.mdx @@ -0,0 +1,37 @@ +--- +# This file is autogenerated +title: getDefaultNativeTokenLimitModuleAddress +description: Overview of the getDefaultNativeTokenLimitModuleAddress method +--- + +# getDefaultNativeTokenLimitModuleAddress + +Maps a given chain to a specific address of the native token limit module by its chain ID. If no direct mapping exists, it defaults to returning a specific address. + +## Import + +```ts +import { getDefaultNativeTokenLimitModuleAddress } from "@account-kit/smart-contracts"; +``` + +## Usage + +```ts +import { getDefaultNativeTokenLimitModuleAddress } from "@account-kit/smart-contracts"; +import { Chain, Address } from "viem"; + +const chain: Chain = ... +const nativeTokenLimitAddress: Address = getDefaultNativeTokenLimitModuleAddress(chain); +``` + +## Parameters + +### chain + +`Chain` +The chain object containing the chain ID to map + +## Returns + +`Address` +The native token limit module address associated with the specified chain ID or a default address if no specific mapping exists diff --git a/site/pages/reference/account-kit/smart-contracts/functions/getDefaultPaymasterGuardModuleAddress.mdx b/site/pages/reference/account-kit/smart-contracts/functions/getDefaultPaymasterGuardModuleAddress.mdx new file mode 100644 index 0000000000..11e25ca3b0 --- /dev/null +++ b/site/pages/reference/account-kit/smart-contracts/functions/getDefaultPaymasterGuardModuleAddress.mdx @@ -0,0 +1,37 @@ +--- +# This file is autogenerated +title: getDefaultPaymasterGuardModuleAddress +description: Overview of the getDefaultPaymasterGuardModuleAddress method +--- + +# getDefaultPaymasterGuardModuleAddress + +Maps a given chain to a specific address of the paymaster guard module by its chain ID. If no direct mapping exists, it defaults to returning a specific address. + +## Import + +```ts +import { getDefaultPaymasterGuardModuleAddress } from "@account-kit/smart-contracts"; +``` + +## Usage + +```ts +import { getDefaultPaymasterGuardModuleAddress } from "@account-kit/smart-contracts"; +import { Chain, Address } from "viem"; + +const chain: Chain = ... +const paymasterGuardAddress: Address = getDefaultPaymasterGuardModuleAddress(chain); +``` + +## Parameters + +### chain + +`Chain` +The chain object containing the chain ID to map + +## Returns + +`Address` +The paymaster guard module address associated with the specified chain ID or a default address if no specific mapping exists diff --git a/site/pages/reference/account-kit/smart-contracts/functions/getDefaultSingleSignerValidationModuleAddress.mdx b/site/pages/reference/account-kit/smart-contracts/functions/getDefaultSingleSignerValidationModuleAddress.mdx new file mode 100644 index 0000000000..04c02888cc --- /dev/null +++ b/site/pages/reference/account-kit/smart-contracts/functions/getDefaultSingleSignerValidationModuleAddress.mdx @@ -0,0 +1,37 @@ +--- +# This file is autogenerated +title: getDefaultSingleSignerValidationModuleAddress +description: Overview of the getDefaultSingleSignerValidationModuleAddress method +--- + +# getDefaultSingleSignerValidationModuleAddress + +Maps a given chain to a specific address of the single signer validation module by its chain ID. If no direct mapping exists, it defaults to returning a specific address. + +## Import + +```ts +import { getDefaultSingleSignerValidationModuleAddress } from "@account-kit/smart-contracts"; +``` + +## Usage + +```ts +import { getDefaultSingleSignerValidationModuleAddress } from "@account-kit/smart-contracts"; +import { Chain, Address } from "viem"; + +const chain: Chain = ... +const singleSignerValidationAddress: Address = getDefaultSingleSignerValidationModuleAddress(chain); +``` + +## Parameters + +### chain + +`Chain` +The chain object containing the chain ID to map + +## Returns + +`Address` +The single signer validation module address associated with the specified chain ID or a default address if no specific mapping exists diff --git a/site/pages/reference/account-kit/smart-contracts/functions/getDefaultTimeRangeModuleAddress.mdx b/site/pages/reference/account-kit/smart-contracts/functions/getDefaultTimeRangeModuleAddress.mdx new file mode 100644 index 0000000000..3de832b874 --- /dev/null +++ b/site/pages/reference/account-kit/smart-contracts/functions/getDefaultTimeRangeModuleAddress.mdx @@ -0,0 +1,37 @@ +--- +# This file is autogenerated +title: getDefaultTimeRangeModuleAddress +description: Overview of the getDefaultTimeRangeModuleAddress method +--- + +# getDefaultTimeRangeModuleAddress + +Maps a given chain to a specific address of the time range module by its chain ID. If no direct mapping exists, it defaults to returning a specific address. + +## Import + +```ts +import { getDefaultTimeRangeModuleAddress } from "@account-kit/smart-contracts"; +``` + +## Usage + +```ts +import { getDefaultTimeRangeModuleAddress } from "@account-kit/smart-contracts"; +import { Chain, Address } from "viem"; + +const chain: Chain = ... +const timeRangeModuleAddress: Address = getDefaultTimeRangeModuleAddress(chain); +``` + +## Parameters + +### chain + +`Chain` +The chain object containing the chain ID to map + +## Returns + +`Address` +The time range module address associated with the specified chain ID or a default address if no specific mapping exists diff --git a/site/pages/reference/account-kit/smart-contracts/functions/getDefaultWebauthnValidationModuleAddress.mdx b/site/pages/reference/account-kit/smart-contracts/functions/getDefaultWebauthnValidationModuleAddress.mdx new file mode 100644 index 0000000000..fd27c9dac5 --- /dev/null +++ b/site/pages/reference/account-kit/smart-contracts/functions/getDefaultWebauthnValidationModuleAddress.mdx @@ -0,0 +1,37 @@ +--- +# This file is autogenerated +title: getDefaultWebauthnValidationModuleAddress +description: Overview of the getDefaultWebauthnValidationModuleAddress method +--- + +# getDefaultWebauthnValidationModuleAddress + +Maps a given chain to a specific address of the webauthn validation module by its chain ID. If no direct mapping exists, it defaults to returning a specific address. + +## Import + +```ts +import { getDefaultWebauthnValidationModuleAddress } from "@account-kit/smart-contracts"; +``` + +## Usage + +```ts +import { getDefaultWebauthnValidationModuleAddress } from "@account-kit/smart-contracts"; +import { Chain, Address } from "viem"; + +const chain: Chain = ... +const webauthnValidationAddress: Address = getDefaultWebauthnValidationModuleAddress(chain); +``` + +## Parameters + +### chain + +`Chain` +The chain object containing the chain ID to map + +## Returns + +`Address` +The webauthn validation module address associated with the specified chain ID or a default address if no specific mapping exists diff --git a/site/pages/reference/account-kit/smart-contracts/functions/installValidationActions.mdx b/site/pages/reference/account-kit/smart-contracts/functions/installValidationActions.mdx new file mode 100644 index 0000000000..602162dacc --- /dev/null +++ b/site/pages/reference/account-kit/smart-contracts/functions/installValidationActions.mdx @@ -0,0 +1,69 @@ +--- +# This file is autogenerated + +title: installValidationActions +description: Overview of the installValidationActions method +--- + +# installValidationActions + +Provides validation installation and uninstallation functionalities for a MA v2 client, ensuring compatibility with `SmartAccountClient`. + +## Import + +```ts +import { installValidationActions } from "@account-kit/smart-contracts"; +``` + +## Usage + +```ts +import { createSMAV2AccountClient, installValidationActions, getDefaultSingleSignerValidationModuleAddress, SingleSignerValidationModule } from "@account-kit/smart-contracts"; +import { Address } from "viem"; + +const client = (await createSMAV2AccountClient({ ... })).extend(installValidationActions); +const sessionKeyAddress: Address = "0x1234"; +const sessionKeyEntityId: number = 1; + +await client.installValidation({ +validationConfig: { +moduleAddress: getDefaultSingleSignerValidationModuleAddress( + client.chain +), +entityId: sessionKeyEntityId, +isGlobal: true, +isSignatureValidation: false, +isUserOpValidation: true, +}, +selectors: [], +installData: SingleSignerValidationModule.encodeOnInstallData({ +entityId: sessionKeyEntityId, +signer: sessionKeyAddress, +}), +hooks: [], +}); + +await client.uninstallValidation({ +moduleAddress: sessionKeyAddress, +entityId: sessionKeyEntityId, +uninstallData: SingleSignerValidationModule.encodeOnUninstallData({ +entityId: sessionKeyEntityId, +}), +hookUninstallDatas: [], +}); + +``` + +## Parameters + +### client + +`object` + +- The client instance which provides account and sendUserOperation functionality. + + ## Returns + + `object` + +- An object containing two methods, `installValidation` and `uninstallValidation`. diff --git a/site/pages/reference/account-kit/smart-contracts/functions/nativeSMASigner.mdx b/site/pages/reference/account-kit/smart-contracts/functions/nativeSMASigner.mdx new file mode 100644 index 0000000000..0052b9b056 --- /dev/null +++ b/site/pages/reference/account-kit/smart-contracts/functions/nativeSMASigner.mdx @@ -0,0 +1,53 @@ +--- +# This file is autogenerated +title: nativeSMASigner +description: Overview of the nativeSMASigner method +--- + +# nativeSMASigner + +Creates an object with methods for generating a dummy signature, signing user operation hashes, signing messages, and signing typed data. + +## Import + +```ts +import { nativeSMASigner } from "@account-kit/smart-contracts"; +``` + +## Usage + +```ts +import { nativeSMASigner } from "@account-kit/smart-contracts"; + +import { LocalAccountSigner } from "@aa-sdk/core"; + +const MNEMONIC = "...": + +const account = createSMAV2Account({ config }); + +const signer = LocalAccountSigner.mnemonicToAccountSigner(MNEMONIC); + +const messageSigner = nativeSMASigner(signer, chain, account.address); +``` + +## Parameters + +### signer + +`SmartAccountSigner` +Signer to use for signing operations + +### chain + +`Chain` +Chain object for the signer + +### accountAddress + +`Address` +address of the smart account using this signer + +## Returns + +`object` +an object with methods for signing operations and managing signatures diff --git a/site/pages/reference/account-kit/smart-contracts/functions/serializeHookConfig.mdx b/site/pages/reference/account-kit/smart-contracts/functions/serializeHookConfig.mdx new file mode 100644 index 0000000000..94b6f1f3b1 --- /dev/null +++ b/site/pages/reference/account-kit/smart-contracts/functions/serializeHookConfig.mdx @@ -0,0 +1,49 @@ +--- +# This file is autogenerated + +title: serializeHookConfig +description: Overview of the serializeHookConfig method +--- + +# serializeHookConfig + +Serializes a `HookConfig` object into a `Hex` format by encoding the hook type, presence of post/pre hooks, address, and entity ID. + +## Import + +```ts +import { serializeHookConfig } from "@account-kit/smart-contracts"; +``` + +## Usage + +```ts +import { type HookType, serializeHookConfig } from "@account-kit/smart-contracts"; +import { Address } from "viem"; + +const moduleAddress: Address = "0x1234"; +const entityId: number = 1234; +const hookType: HookType = HookType.Validation; +const hasPostHooks: boolean = false; +const hasPreHooks: boolean = true; + +const hookConfigHex = serializeHookConfig({ +moduleAddress, +entityId +hookType, +hasPostHooks, +hasPreHooks +}); +``` + +## Parameters + +### config + +`HookConfig` +The hook configuration containing address, entity ID, hook type, and post/pre hook indicators + +## Returns + +`Hex` +The serialized hook configuration in hexadecimal format diff --git a/site/pages/reference/account-kit/smart-contracts/functions/serializeModuleEntity.mdx b/site/pages/reference/account-kit/smart-contracts/functions/serializeModuleEntity.mdx new file mode 100644 index 0000000000..a95495eaa9 --- /dev/null +++ b/site/pages/reference/account-kit/smart-contracts/functions/serializeModuleEntity.mdx @@ -0,0 +1,43 @@ +--- +# This file is autogenerated + +title: serializeModuleEntity +description: Overview of the serializeModuleEntity method +--- + +# serializeModuleEntity + +Serializes a module entity into a hexadecimal format by concatenating the module address and entity ID. + +## Import + +```ts +import { serializeModuleEntity } from "@account-kit/smart-contracts"; +``` + +## Usage + +```ts +import { serializeModuleEntity } from "@account-kit/smart-contracts"; +import { Address } from "viem"; + +const moduleAddress: Address = "0x1234"; +const entityId: number = 1234; + +const moduleEntityHex = serializeModuleEntity({ + moduleAddress, + entityId, +}); +``` + +## Parameters + +### config + +`ModuleEntity` +The module entity configuration containing the module address and entity ID + +## Returns + +`Hex` +A hexadecimal string representation of the serialized module entity diff --git a/site/pages/reference/account-kit/smart-contracts/functions/serializeValidationConfig.mdx b/site/pages/reference/account-kit/smart-contracts/functions/serializeValidationConfig.mdx new file mode 100644 index 0000000000..f66a26e095 --- /dev/null +++ b/site/pages/reference/account-kit/smart-contracts/functions/serializeValidationConfig.mdx @@ -0,0 +1,49 @@ +--- +# This file is autogenerated + +title: serializeValidationConfig +description: Overview of the serializeValidationConfig method +--- + +# serializeValidationConfig + +Serializes a validation configuration into a hexadecimal string representation. This involves converting boolean flags into bitwise representation and combining them with serialized module entity data. + +## Import + +```ts +import { serializeValidationConfig } from "@account-kit/smart-contracts"; +``` + +## Usage + +```ts +import { serializeValidationConfig } from "@account-kit/smart-contracts"; +import { Address } from "viem"; + +const moduleAddress: Address = "0x1234"; +const entityId: number = 1234; +const isGlobal: boolean = true; +const isSignatureValidation: boolean = false; +const isUserOpValidation: boolean = true; + +const validationConfigHex = serializeValidationConfig({ +moduleAddress, +entityId +isGlobal, +isSignatureValidation, +isUserOpValidation +}); +``` + +## Parameters + +### config + +`ValidationConfig` +The validation configuration object containing details to serialize + +## Returns + +`Hex` +A hexadecimal string representing the serialized configuration