@etherspot/remote-signer
Version:
Etherspot Permissioned Signer SDK - signs the UserOp with SessionKey and sends it to the Bundler
179 lines (139 loc) • 5.77 kB
Markdown
# 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
1. account
2. chainId
3. apiKey
4. sessionKey
The `signUserOperation` function will handle the signing process and return the signed user operation.
```ts
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
```json
{
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-deepdive](./remote-signer-deepdive.MD)
## Remote Signer SDK - Usage
developers can do remote sign an UserOp using SessionKeys and send the `signedUserOp` to Etherspot Bundler
### Background
1. RemoteSignerSDK is used to sign a userOp via SessionKeys of the etherspot-wallet
2. SessionKeys are maintained in a remote secured cloud environment
3. Signing with SessionKey needs the user to call a secured API call to `etherspot-permissions-backend`
4. 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
5. Signer API (etherspot-permissions-backend) will sign the UserOp and return the signedUserOp data
6. SignedUserOp can be sent to the EtherspotBunder for further verification, validation and execution by entryPoint
## Remote Signer Usage
1. `remote-signer-sdk` is to be installed from the npm public repo
2. refer to the script below to use the remote-signer for a functionality of erc20 transfer to a recipient
3. remote-signer is meant to be operated on etherspot-modular-account which must have corresponding validator module installed where the validation happens
4. RemoteSigner will perform validations offchain and onchain on validity of sessionKey
Sample Usage Script:
[session-key-signer-script-for-erc20-transfer](./examples/transfer-erc20-session-key.ts)
## SDK Functions
1. **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
```js
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);
```
2. **signUserOp**
- extracts the sessionKey Data and privateKey from Cloud KMS Storage
- sign the userOp using the privateKey associated with SessionKey
```js
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
1. getSessionKey
```js
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',
},
});
```
2. SignUserOp with SessionKey
```js
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))),
});
```