@etherspot/remote-signer
v0.0.1
Published
Etherspot Permissioned Signer SDK - signs the UserOp with SessionKey and sends it to the Bundler
Downloads
7
Readme
RemoteSigner SDK
- RemoteSigner SDK is a fully open source SDK which let's dapp developers easily get building with SessionKey Signature enabled Modular Smart Accounts.
- The SDK makes it incredibly easy to get up and running with using Sessionkey based Signature from remote signer and send the UserOp to the bundler.
- Session-Key-Signer is hosted in AWS cloud environment which stores the sessionKeys and backend infra service to sign using the privateKey associated with the sessionKey. Signed UserOp is sent to the Etherspot Bundler
Modules and functions in Remote-Signer
Usage
- remote signer need to provide the necessary parameters
- account
- chainId
- apiKey
- sessionKey
The signUserOperation
function will handle the signing process and return the signed user operation.
import { signUserOperation } from './path/to/remote-signer';
const extendedLocalAccount: ExtendedLocalAccount = await toRemoteSigner({
account: createLocalAccount(etherspotWalletAddress),
chainId: chainId,
apiKey: apiKey,
sessionKey: sessionKey
});
SessionKey Format
SessionKeys are stored in AWS Secrets in this format
SessionKey is stored as a secret with secretName:
sessionKey-${account}
account is the EtherspotWalletAddress
an account can have multiple sessionkeys under a chainId
{ 1: [ { chainId, account, apiKey, publicKey, privateKey, nonce, validUntil, validAfter } ], 100: [ { chainId, account, apiKey, publicKey, privateKey, nonce, validUntil, validAfter }, { chainId, account, apiKey, publicKey, privateKey, nonce, validUntil, validAfter } ], }
RemoteSigner - Deep dive
Remote Signer SDK - Usage
developers can do remote sign an UserOp using SessionKeys and send the signedUserOp
to Etherspot Bundler
Background
- RemoteSignerSDK is used to sign a userOp via SessionKeys of the etherspot-wallet
- SessionKeys are maintained in a remote secured cloud environment
- Signing with SessionKey needs the user to call a secured API call to
etherspot-permissions-backend
- API request sent to remote service authenticates using apiKey and sessionKey and looksup for ther privateKey (ECDSA) associated with the sessionKey
- userOp
- apiKey
- sessionKey
- chainId
- Signer API (etherspot-permissions-backend) will sign the UserOp and return the signedUserOp data
- SignedUserOp can be sent to the EtherspotBunder for further verification, validation and execution by entryPoint
Remote Signer Usage
remote-signer-sdk
is to be installed from the npm public repo- refer to the script below to use the remote-signer for a functionality of erc20 transfer to a recipient
- remote-signer is meant to be operated on etherspot-modular-account which must have corresponding validator module installed where the validation happens
- RemoteSigner will perform validations offchain and onchain on validity of sessionKey
Sample Usage Script: session-key-signer-script-for-erc20-transfer
SDK Functions
toRemoteSigner
Initialize an ExtendedLocalAccount which is an extended version of Viem's
LocalAccount
This is a closure created with functions to sign the Userop using SessionKey of the etherspotWalletAddress
const extendedLocalAccount: ExtendedLocalAccount = await toRemoteSigner({ account: createLocalAccount(etherspotWalletAddress), chainId: chainId, apiKey: apiKey, sessionKey: sessionKey }); const op = await generateSignedUserOp(); const signedUserOp: UserOperation = await extendedLocalAccount.signUserOpWithRemoteSigner(op);
signUserOp
extracts the sessionKey Data and privateKey from Cloud KMS Storage
sign the userOp using the privateKey associated with SessionKey
const externalViemAccount = privateKeyToAccount(process.env.WALLET_PRIVATE_KEY as string as Hex); const bundlerProvider = new EtherspotBundler(chainId, bundlerApiKey); const remoteSignerSdk = await RemoteSignerSdk.create(externalViemAccount, { etherspotWalletAddress: etherspotWalletAddress, chainId: chainId, apiKey: apiKey, sessionKey: sessionKey, bundlerProvider: bundlerProvider }); const signedUserOp = await remoteSignerSdk.signUserOp(op);
API Endpoints use for query and signing by SessionKeys
getSessionKey
let url = `<permissionedBackendURL>/account/getSessionKey?account=${accountAddress}&chainId=${chainId}&apiKey=${apiKey}&sessionKey=${sessionKey}`; response = await fetch(url, { method: 'GET', headers: { 'Accept': 'application/json', 'Content-Type': 'application/json', }, });
SignUserOp with SessionKey
let url = `<permissionedBackendURL>/account/signUserOp?account=${accountAddress}&chainId=${chainId}&sessionKey=${sessionKey}&apiKey=${apiKey}`; response = await fetch(url, { method: 'POST', headers: { 'Accept': 'application/json', 'Content-Type': 'application/json', }, body: JSON.stringify(deepHexlify(await resolveProperties(userOp))), });