@biconomy-devx/modules
Version:
This package provides different validation modules/plugins for ERC4337 compatible modular account
2 lines (1 loc) • 2.04 kB
JavaScript
;import{encodeFunctionData as i,getAddress as a,parseAbi as c,toBytes as o}from"viem";import{DEFAULT_ECDSA_OWNERSHIP_MODULE as d,ECDSA_OWNERSHIP_MODULE_ADDRESSES_BY_VERSION as u}from"./utils/Constants.js";import{convertSigner as b}from"@biconomy-devx/common";import{BaseValidationModule as g}from"./BaseValidationModule.js";export class ECDSAOwnershipValidationModule extends g{constructor(e){super(e),Object.defineProperty(this,"signer",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"moduleAddress",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"version",{enumerable:!0,configurable:!0,writable:!0,value:"V1_0_0"}),this.signer=e.signer}static async create(e){const{signer:s}=await b(e.signer,!0),t={...e,signer:s},r=new ECDSAOwnershipValidationModule(t);if(e.moduleAddress)r.moduleAddress=e.moduleAddress;else if(e.version){const n=u[e.version];if(!n)throw new Error(`Invalid version ${e.version}`);r.moduleAddress=n,r.version=e.version}else r.moduleAddress=d;return r}getAddress(){return this.moduleAddress}async getSigner(){return Promise.resolve(this.signer)}async getDummySignature(){return`0x0000000000000000000000000000000000000000000000000000000000000040000000000000000000000000${a(this.getAddress()).substring(2).padEnd(40,"0")}000000000000000000000000000000000000000000000000000000000000004181d4b4981670cb18f99f0b4a66446df1bf5b204d24cfcb659bf38ba27a4359b5711649ec2423c5e1247245eba2964679b6a1dbb85c992ae40b9b00c6935b02ff1b00000000000000000000000000000000000000000000000000000000000000`}async getInitData(){const e=await this.signer.getAddress(),s=c(["function initForSmartAccount(address owner)"]);return i({abi:s,functionName:"initForSmartAccount",args:[e]})}async signUserOpHash(e){return await this.signer.signMessage({raw:o(e)})}async signMessage(e){const s=typeof e=="string"?e:{raw:e};let t=await this.signer.signMessage(s);const r=parseInt(t.slice(-2),16);if(![27,28].includes(r)){const n=r+27;t=t.slice(0,-2)+n.toString(16)}return t}}