@etherspot/remote-signer
Version:
Etherspot Permissioned Signer SDK - signs the UserOp with SessionKey and sends it to the Bundler
1 lines • 3.26 kB
Source Map (JSON)
{"version":3,"sources":["../../src/sdk/remote-signer/local-account-utils.ts"],"sourcesContent":["\nimport { isHex } from \"../common\"\nimport { GetAccountReturnType } from \"../types/user-operation-types\"\nimport { AccountSource, isAddress, InvalidAddressError, Hex, hexToSignature, signatureToHex, LocalAccount, Address, CustomSource } from \"viem\"\n\n\n// Function to create a LocalAccount from a string address\nexport function createLocalAccount(\n address: string,\n): LocalAccount<string, Address> & CustomSource {\n return {\n address: address as Address,\n publicKey: \"0x\",\n source: \"\",\n type: 'local',\n signMessage: undefined,\n signTransaction: undefined,\n signTypedData: undefined\n };\n}\n\n/**\n * @description Creates a Local Account from a custom signing implementation.\n *\n * @returns A Local Account.\n */\nexport function toExtendedLocalAccount<accountSource extends AccountSource>(\n source: accountSource,\n): GetAccountReturnType<accountSource> {\n if (typeof source === 'string') {\n if (!isAddress(source, { strict: false }))\n throw new InvalidAddressError({ address: source })\n return {\n address: source,\n type: 'json-rpc',\n } as GetAccountReturnType<accountSource>\n }\n\n if (!isAddress(source.address, { strict: false }))\n throw new InvalidAddressError({ address: source.address })\n return {\n address: source.address,\n nonceManager: source.nonceManager,\n signMessage: source.signMessage,\n signTransaction: source.signTransaction,\n signTypedData: source.signTypedData,\n source: 'custom',\n type: 'local',\n } as GetAccountReturnType<accountSource>\n}\n\n\nexport const fixSignedData = (sig: Hex): Hex => {\n let signature = sig\n if (!isHex(signature)) {\n signature = `0x${signature}`\n if (!isHex(signature)) {\n throw new Error(`Invalid signed data ${sig}`)\n }\n }\n\n let { r, s, v } = hexToSignature(signature)\n if (v === 0n || v === 1n) v += 27n\n // biome-ignore lint/style/noNonNullAssertion: <explanation>\n const joined = signatureToHex({ r, s, v: v! })\n return joined\n}\n"],"mappings":";;;;;;;;;;;;;AAOO,SAAS,mBACZ,SAC4C;AAC5C,SAAO;AAAA,IACH;AAAA,IACA,WAAW;AAAA,IACX,QAAQ;AAAA,IACR,MAAM;AAAA,IACN,aAAa;AAAA,IACb,iBAAiB;AAAA,IACjB,eAAe;AAAA,EACnB;AACJ;AAOO,SAAS,uBACZ,QACmC;AACnC,MAAI,OAAO,WAAW,UAAU;AAC5B,QAAI,CAAC,UAAU,QAAQ,EAAE,QAAQ,MAAM,CAAC;AACpC,YAAM,IAAI,oBAAoB,EAAE,SAAS,OAAO,CAAC;AACrD,WAAO;AAAA,MACH,SAAS;AAAA,MACT,MAAM;AAAA,IACV;AAAA,EACJ;AAEA,MAAI,CAAC,UAAU,OAAO,SAAS,EAAE,QAAQ,MAAM,CAAC;AAC5C,UAAM,IAAI,oBAAoB,EAAE,SAAS,OAAO,QAAQ,CAAC;AAC7D,SAAO;AAAA,IACH,SAAS,OAAO;AAAA,IAChB,cAAc,OAAO;AAAA,IACrB,aAAa,OAAO;AAAA,IACpB,iBAAiB,OAAO;AAAA,IACxB,eAAe,OAAO;AAAA,IACtB,QAAQ;AAAA,IACR,MAAM;AAAA,EACV;AACJ;AAGO,IAAM,gBAAgB,CAAC,QAAkB;AAC5C,MAAI,YAAY;AAChB,MAAI,CAAC,MAAM,SAAS,GAAG;AACnB,gBAAY,KAAK,SAAS;AAC1B,QAAI,CAAC,MAAM,SAAS,GAAG;AACnB,YAAM,IAAI,MAAM,uBAAuB,GAAG,EAAE;AAAA,IAChD;AAAA,EACJ;AAEA,MAAI,EAAE,GAAG,GAAG,EAAE,IAAI,eAAe,SAAS;AAC1C,MAAI,MAAM,MAAM,MAAM,GAAI,MAAK;AAE/B,QAAM,SAAS,mBAAe,EAAE,GAAG,GAAG,EAAM,CAAC;AAC7C,SAAO;AACX;","names":[]}