UNPKG

@biconomy/modules

Version:

This package provides different validation modules/plugins for ERC4337 compatible modular account

80 lines 3.83 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.ECDSAOwnershipValidationModule = void 0; const common_1 = require("@biconomy/common"); const ethers_1 = require("ethers"); const utils_1 = require("ethers/lib/utils"); const Constants_1 = require("./utils/Constants"); const BaseValidationModule_1 = require("./BaseValidationModule"); const aa_core_1 = require("@alchemy/aa-core"); // Could be renamed with suffix API class ECDSAOwnershipValidationModule extends BaseValidationModule_1.BaseValidationModule { constructor(moduleConfig) { super(moduleConfig); this.version = "V1_0_0"; } static async create(moduleConfig) { const instance = new ECDSAOwnershipValidationModule(moduleConfig); if (moduleConfig.moduleAddress) { instance.moduleAddress = moduleConfig.moduleAddress; } else if (moduleConfig.version) { const moduleAddr = Constants_1.ECDSA_OWNERSHIP_MODULE_ADDRESSES_BY_VERSION[moduleConfig.version]; if (!moduleAddr) { throw new Error(`Invalid version ${moduleConfig.version}`); } instance.moduleAddress = moduleAddr; instance.version = moduleConfig.version; } else { instance.moduleAddress = Constants_1.DEFAULT_ECDSA_OWNERSHIP_MODULE; // Note: in this case Version remains the default one } instance.signer = moduleConfig.signer; return instance; } getAddress() { return this.moduleAddress; } async getSigner() { return Promise.resolve(this.signer); } async getDummySignature() { const moduleAddress = ethers_1.ethers.utils.getAddress(this.getAddress()); const dynamicPart = moduleAddress.substring(2).padEnd(40, "0"); return `0x0000000000000000000000000000000000000000000000000000000000000040000000000000000000000000${dynamicPart}000000000000000000000000000000000000000000000000000000000000004181d4b4981670cb18f99f0b4a66446df1bf5b204d24cfcb659bf38ba27a4359b5711649ec2423c5e1247245eba2964679b6a1dbb85c992ae40b9b00c6935b02ff1b00000000000000000000000000000000000000000000000000000000000000`; } // Note: other modules may need additional attributes to build init data async getInitData() { const ecdsaOwnerAddress = await this.signer.getAddress(); const moduleRegistryAbi = "function initForSmartAccount(address owner)"; const ecdsaModuleRegistryInterface = new ethers_1.ethers.utils.Interface([moduleRegistryAbi]); const ecdsaOwnershipInitData = ecdsaModuleRegistryInterface.encodeFunctionData("initForSmartAccount", [ecdsaOwnerAddress]); return ecdsaOwnershipInitData; } async signUserOpHash(userOpHash) { const sig = await this.signer.signMessage((0, utils_1.arrayify)(userOpHash)); common_1.Logger.log("ecdsa signature ", sig); return sig; } /** * Signs a message using the appropriate method based on the type of signer. * * @param {Bytes | string | Uint8Array} message - The message to be signed. * @returns {Promise<string>} A promise resolving to the signature or error message. * @throws {Error} If the signer type is invalid or unsupported. */ async signMessage(message) { if (this.signer instanceof aa_core_1.WalletClientSigner) { return super.signMessageWalletClientSigner(message, this.signer); } else if (this.signer instanceof ethers_1.Signer) { return super.signMessageSigner(message, this.signer); } else { throw new Error("Invalid signer type"); } } } exports.ECDSAOwnershipValidationModule = ECDSAOwnershipValidationModule; //# sourceMappingURL=ECDSAOwnershipValidationModule.js.map