Skip to main content

SocialRecoveryModule SDK Reference

Install​

tip

Prefer to run a simple example? Fork this repo and add your first guardian here.

npm i abstractionkit

Import​

import { SocialRecoveryModule } from "abstractionkit";

Initialize​

Initialize a SocialRecoveryModule instance. By default, the grace period for recovery is set to 3 days.

const srm = new SocialRecoveryModule(); // 3 days

If you need a different grace period, you can override it by providing a different grace period address during initialization.

import { SocialRecoveryModule, SocialRecoveryModuleGracePeriodSelector } from "abstractionkit";

const gracePeriod = SocialRecoveryModuleGracePeriodSelector.After7Days;
const srm = new SocialRecovery(gracePeriod); // 7 days

Then consume the module methods like the following:

const accountAddress = "0x1.."
const guardianAddress= "0x2.."

const metaTransaction1 = srm.createEnableModuleMetaTransaction(accountAddress);

const metaTransaction2 = srm.createAddGuardianWithThresholdMetaTransaction(
guardianAddress,
1n //threshold
);

Setup Guardians​

createEnableModuleMetaTransaction​

Active the recovery plugin for the smart account

keytypedescription
accountAddressstringThe target account address.

createAddGuardianWithThresholdMetaTransaction​

Creates a MetaTransaction that lets the owner add a guardian for its account.

keytypedescription
guardianAddressstringThe guardian to add.
thresholdbigintThe new threshold that will be set after addition.

Change Guardians Setup​

createRevokeGuardianWithThresholdMetaTransaction​

Creates a MetaTransaction that lets the owner revoke a guardian from its account. This async version auto-detects the previous guardian by querying the node.

keytypedescription
nodeRpcUrlstringThe JSON-RPC API url for the target chain (to get the prevGuardian parameter).
accountAddressstringThe target account.
guardianAddressstringThe guardian to revoke.
thresholdbigintThe new threshold that will be set after execution of revocation.
overridesobjectOptional overrides object with prevGuardianAddress.

createStandardRevokeGuardianWithThresholdMetaTransaction​

Creates a MetaTransaction that lets the owner revoke a guardian from its account. This synchronous version requires the previous guardian address to be provided manually.

keytypedescription
prevGuardianAddressstringThe previous guardian linking to the guardian in the linked list.
guardianAddressstringThe guardian to revoke.
thresholdbigintThe new threshold that will be set after execution of revocation.

createChangeThresholdMetaTransaction​

Creates a MetaTransaction that lets the owner change the guardian threshold required to initiate a recovery.

keytypedescription
thresholdbigintThe new threshold that will be set after execution of revokation.

Recover​

createConfirmRecoveryMetaTransaction​

Creates a MetaTransaction that lets a single guardian confirm the execution of the recovery request. It can also trigger the start of the execution by passing true to 'execute' parameter. Once triggered, the recovery will started the recovery period delay, before it can be finalised.

keytypedescription
accountAddressstringThe target account address.
newOwnersstring[]The new owners' addresses.
newThresholdnumberThe new threshold for the safe.
executebooleanWhether to auto-start execution of recovery.

createMultiConfirmRecoveryMetaTransaction​

Creates a MetaTransaction that lets multiple guardians confirm the execution of the recovery request. It can also trigger the start of the execution by passing true to 'execute' parameter. Once triggered, the recovery will start the recovery period delay, before it can be finalised.

keytypedescription
accountAddressstringThe target account address.
newOwnersstring[]The new owners' addresses.
newThresholdnumberThe new threshold for the safe.
signaturePairListRecoverySignaturePair[]The guardians signers and signatures pair list.
executebooleanWhether to auto-start execution of recovery.

createExecuteRecoveryMetaTransaction​

Creates a MetaTransaction that lets the guardians start the execution of the recovery request. Once triggered, the recovery will be pending for the recovery period before it can be finalized.

keytypedescription
accountAddressstringThe target account address.
newOwnersstring[]The new owners' addresses.
newThresholdnumberThe new threshold for the safe.

createFinalizeRecoveryMetaTransaction​

Creates a MetaTransaction that finalizes an ongoing recovery request if the recovery period is over. The method is public and callable by anyone to enable orchestration.

keytypedescription
accountAddressstringThe target account address.

Cancel a Recovery​

createCancelRecoveryMetaTransaction​

Creates a MetaTransaction that lets the account cancel an ongoing recovery request.

Helpers​

hasGuardianApproved​

Retrieves specific guardian approval status for a particular recovery request at the current nonce.

keytypedescription
nodeURLstringThe Node URL of the Ethereum RPC endpoint.
accountAddressstringThe target account address.
guardianstringThe guardian.
newOwnersstring[]The new owners' addresses.
newThresholdnumberThe new threshold for the safe.

isGuardian​

Checks if an address is a guardian for an account.

keytypedescription
nodeRpcUrlstringThe Node URL of the Ethereum RPC endpoint.
accountAddressstringThe target account address.
guardianstringThe address to check.

guardiansCount​

Counts the number of active guardians for an account.

keytypedescription
nodeRpcUrlstringThe Node URL of the Ethereum RPC endpoint.
accountAddressstringThe target account address.

threshold​

Retrieves the guardians threshold for the account.

keytypedescription
nodeURLstringThe Node URL of the Ethereum RPC endpoint.
accountAddressstringThe target account address.

getGuardians​

Get the active guardians for an account.

keytypedescription
nodeRpcUrlstringThe Node URL of the Ethereum RPC endpoint.
accountAddressstringThe target account address.

getRecoveryRequest​

Retrieves the account's current ongoing recovery request.

keytypedescription
nodeUrlstringThe Node URL of the Ethereum RPC endpoint.
accountAddressstringThe target account address.

getRecoveryApprovals​

Retrieves the guardian approval count for this particular recovery request at the current nonce.

keytypedescription
nodeUrlstringThe Node URL of the Ethereum RPC endpoint.
accountAddressstringThe target account address.
newOwnersstring[]The new owners' addresses.
newThresholdnumberThe new threshold for the safe.

nonce​

Get the module nonce for an account.

keytypedescription
nodeRpcUrlstringThe Node URL of the Ethereum RPC endpoint.
accountAddressstringThe target account address.

getRecoveryHash​

Generates the recovery hash that should be signed by the guardian to authorize a recovery.

keytypedescription
nodeRpcUrlstringThe JSON-RPC API url for the target chain.
accountAddressstringThe target account address.
newOwnersstring[]The new owners' addresses.
newThresholdnumberThe new threshold for the safe.
noncebigintRecovery nonce.

getRecoveryRequestEip712Data​

Creates recovery request EIP-712 data for signing by guardians.

keytypedescription
rpcNodestringNode to fetch the recovery nonce.
chainIdbigintChain ID of the target network.
accountAddressstringAddress of account to recover.
newOwnersstring[]New owners to recover to.
newThresholdbigintNew threshold.
overridesobjectOptional overrides with recoveryNonce.

Types​

RecoverySignaturePair​

A guardian address paired with its EIP-712 signature authorizing a recovery.

keytypedescription
signerstringGuardian address that produced the signature.
signaturestringHex-encoded signature bytes.