@etherspot/remote-signer
Version:
Etherspot Permissioned Signer SDK - signs the UserOp with SessionKey and sends it to the Bundler
1 lines • 3.97 kB
Source Map (JSON)
{"version":3,"sources":["../../src/sdk/remote-signer/remote-signer.ts"],"sourcesContent":["import {\n Account,\n type LocalAccount,\n TypedData,\n type TypedDataDefinition,\n} from \"viem\"\nimport { PERMISSIONS_URL, UserOperation } from \"../common\"\nimport { getSessionKey, signUserOpWithSessionKey } from \"../session-keys\"\nimport { ExtendedLocalAccount } from \"../types/user-operation-types\"\n\nexport type RemoteSignerParams = {\n account: LocalAccount,\n chainId: number,\n apiKey: string,\n sessionKey: string,\n permissionsBackendUrl?: string\n}\n\nasync function signUserOp(account: Account, \n chainId: number, \n apiKey: string, \n sessionKey: string, \n userOp: UserOperation, \n permissionsBackendUrl: string = PERMISSIONS_URL): Promise<UserOperation> {\n return signUserOpWithSessionKey(account.address, chainId, apiKey, sessionKey, userOp, permissionsBackendUrl);\n}\n\nexport async function toRemoteSigner({\n account,\n chainId,\n apiKey,\n sessionKey\n}: RemoteSignerParams): Promise<ExtendedLocalAccount> {\n // Get sessionKey from apiKey and account\n const sessionKeyResponse = await getSessionKey(account.address, chainId, apiKey, sessionKey);\n\n // Create the extendedLocalAccount object and add the method\n const extendedLocalAccount: ExtendedLocalAccount = {\n ...account, // Spread the properties of the original LocalAccount\n async signUserOpWithRemoteSigner(userOp: UserOperation) {\n const signedUserOp = await signUserOp(account, chainId, apiKey, sessionKeyResponse.sessionKey, userOp);\n return signedUserOp;\n },\n\n async signMessage({ message }) {\n throw new Error('signMessage with sessionKey not implemented');\n },\n async signTransaction(_, __) {\n throw new Error('signTransaction with sessionKey not implemented');\n },\n async signTypedData<\n const TTypedData extends TypedData | Record<string, unknown>,\n TPrimaryType extends keyof TTypedData | 'EIP712Domain' = keyof TTypedData\n >(typedData: TypedDataDefinition<TTypedData, TPrimaryType>) {\n throw new Error('signTypedData not implemented');\n },\n };\n\n return extendedLocalAccount;\n}\n\n\nexport const signUserOperation = async (etherspotWalletAccount: LocalAccount, chainId: number, apiKey: string, sessionKey: string, userOp: UserOperation) => {\n const remoteSigner: ExtendedLocalAccount = await toRemoteSigner({\n account: etherspotWalletAccount,\n chainId: chainId,\n apiKey: apiKey,\n sessionKey: sessionKey,\n permissionsBackendUrl: PERMISSIONS_URL\n });\n\n const signedUserOp = await remoteSigner.signUserOpWithRemoteSigner(userOp);\n\n if (!signedUserOp || !signedUserOp.signature || signedUserOp.signature === '0x') {\n throw new Error('Failed to sign user operation');\n }\n\n return signedUserOp;\n}\n"],"mappings":";;;;;;;;;;;AAkBA,eAAe,WAAW,SACtB,SACA,QACA,YACA,QACA,wBAAgC,iBAAyC;AACzE,SAAO,yBAAyB,QAAQ,SAAS,SAAS,QAAQ,YAAY,QAAQ,qBAAqB;AAC/G;AAEA,eAAsB,eAAe;AAAA,EACjC;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACJ,GAAsD;AAElD,QAAM,qBAAqB,MAAM,cAAc,QAAQ,SAAS,SAAS,QAAQ,UAAU;AAG3F,QAAM,uBAA6C;AAAA,IAC/C,GAAG;AAAA;AAAA,IACH,MAAM,2BAA2B,QAAuB;AACpD,YAAM,eAAe,MAAM,WAAW,SAAS,SAAS,QAAQ,mBAAmB,YAAY,MAAM;AACrG,aAAO;AAAA,IACX;AAAA,IAEA,MAAM,YAAY,EAAE,QAAQ,GAAG;AAC3B,YAAM,IAAI,MAAM,6CAA6C;AAAA,IACjE;AAAA,IACA,MAAM,gBAAgB,GAAG,IAAI;AACzB,YAAM,IAAI,MAAM,iDAAiD;AAAA,IACrE;AAAA,IACA,MAAM,cAGJ,WAA0D;AACxD,YAAM,IAAI,MAAM,+BAA+B;AAAA,IACnD;AAAA,EACJ;AAEA,SAAO;AACX;AAGO,IAAM,oBAAoB,OAAO,wBAAsC,SAAiB,QAAgB,YAAoB,WAA0B;AACzJ,QAAM,eAAqC,MAAM,eAAe;AAAA,IAC5D,SAAS;AAAA,IACT;AAAA,IACA;AAAA,IACA;AAAA,IACA,uBAAuB;AAAA,EAC3B,CAAC;AAED,QAAM,eAAe,MAAM,aAAa,2BAA2B,MAAM;AAEzE,MAAI,CAAC,gBAAgB,CAAC,aAAa,aAAa,aAAa,cAAc,MAAM;AAC7E,UAAM,IAAI,MAAM,+BAA+B;AAAA,EACnD;AAEA,SAAO;AACX;","names":[]}