Skip to main content

Social Recovery Module SDK Reference

abstractionkit ships one class per Social Recovery Module version. Use SocialRecoveryModuleV2 (module v0.2.0) for new integrations, and SocialRecoveryModuleV1 (module v0.1.0) for accounts that already enabled v0.1.0.

Install​

tip

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

npm i abstractionkit

Import​

import { SocialRecoveryModuleV2 } from "abstractionkit";

Choose a Module Version​

Social Recovery Module v0.2.0 fixes the findings of Certora's audit and is a new deployment with new addresses. v0.1.0 stays deployed. Each version has its own class and grace period selector:

Module versionClassGrace period selectorRecovery request type
v0.2.0 (recommended)SocialRecoveryModuleV2SocialRecoveryModuleGracePeriodSelectorV2RecoveryRequestV2
v0.1.0SocialRecoveryModuleV1SocialRecoveryModuleGracePeriodSelectorV1RecoveryRequestV1
Accounts on v0.1.0 must stay on V1

Pick the class that matches the module your accounts enabled. If your users enabled the v0.1.0 module, use SocialRecoveryModuleV1 and SocialRecoveryModuleGracePeriodSelectorV1. Pointed at a v0.2.0 address, an account that enabled v0.1.0 has no guardians, and its recovery calls fail.

SocialRecoveryModuleV1 and SocialRecoveryModuleGracePeriodSelectorV1 are what SocialRecoveryModule and SocialRecoveryModuleGracePeriodSelector were before abstractionkit v1.0.0, with the same addresses.

V1 vs V2 Differences​

V1 (module v0.1.0)V2 (module v0.2.0)
createConfirmRecoveryMetaTransaction(accountAddress, newOwners, newThreshold, execute)(accountAddress, newOwners, newThreshold, nonce, execute)
createMultiConfirmRecoveryMetaTransaction(accountAddress, newOwners, newThreshold, signaturePairList, execute)(accountAddress, newOwners, newThreshold, nonce, signaturePairList, execute)
Guardian signature EIP-712 domain version"0.0.1""0.2.0". Signatures made for v0.1.0 are not valid on v0.2.0.
getRecoveryRequest returnsRecoveryRequestV1 with executeAfterRecoveryRequestV2 with nonce and executableAt
Adding or revoking a guardian, changing the thresholdLeaves a recovery in progress untouchedCancels the recovery in progress and invalidates the guardian confirmations collected so far
cancelRecoveryReverts when no recovery is in progressAlso invalidates collected confirmations, and works when no recovery is in progress
New ownersValidated at finalizationAlso validated at confirmation and execution. For example, confirming a recovery that names a guardian as a new owner reverts.
hasGuardianApprovedCan report an approval from an address that is no longer a guardianReports approvals from current guardians only

On V2, pass the recovery nonce the guardians signed to the confirm methods. Read it from messageValue.nonce returned by getRecoveryRequestEip712Data, or call nonce for a single guardian confirming on-chain. The module reverts with SM: invalid nonce if the nonce changed before the transaction is included.

SocialRecoveryModuleBase​

SocialRecoveryModuleBase is the abstract class both versions extend. It holds every method the two versions share: guardian management, execute, finalize, cancel, the read helpers, and getRecoveryRequestEip712Data. Use it as a type for code that accepts either version. The confirm methods and getRecoveryRequest differ between versions, so they live on SocialRecoveryModuleV1 and SocialRecoveryModuleV2.

import { SocialRecoveryModuleBase } from "abstractionkit";

async function listGuardians(srm: SocialRecoveryModuleBase, nodeUrl: string, accountAddress: string) {
return srm.getGuardians(nodeUrl, accountAddress);
}

Initialize​

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

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

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

import { SocialRecoveryModuleV2, SocialRecoveryModuleGracePeriodSelectorV2 } from "abstractionkit";

const gracePeriod = SocialRecoveryModuleGracePeriodSelectorV2.After7Days;
const srm = new SocialRecoveryModuleV2(gracePeriod); // 7 days

SocialRecoveryModuleGracePeriodSelectorV2 offers After3Minutes, After3Days, After7Days, and After14Days. The 3-minute deployment is on testnets only.

For accounts that enabled module v0.1.0, use the V1 class with the V1 selector:

import { SocialRecoveryModuleV1, SocialRecoveryModuleGracePeriodSelectorV1 } from "abstractionkit";

const srm = new SocialRecoveryModuleV1(SocialRecoveryModuleGracePeriodSelectorV1.After3Days);

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. On V2 this also cancels any recovery in progress and invalidates collected guardian confirmations.

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
nodeRpcUrlstring | Transport | JsonRpcNodeThe 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 guardian threshold.

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 starts the grace period, before it can be finalized.

On V2 it takes the account's current recovery nonce before execute. Get it with nonce.

// SocialRecoveryModuleV2
const nonce = await srm.nonce(nodeUrl, accountAddress);
const confirmTx = srm.createConfirmRecoveryMetaTransaction(
accountAddress,
[newOwnerAddress],
1, // new threshold
nonce,
true, // execute
);
keytypedescription
accountAddressstringThe target account address.
newOwnersstring[]The new owners' addresses.
newThresholdnumberThe new threshold for the safe.
noncebigintThe account's current recovery nonce (see nonce). The module reverts if it changed before the transaction is included.
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 starts the grace period, before it can be finalized. Signature pairs are sorted by signer address for you.

On V2 it takes the recovery nonce the guardians signed, before the signatures. Use messageValue.nonce from getRecoveryRequestEip712Data. A signature may be empty when its signer is the transaction sender, or when the signer is a Safe guardian that pre-approved the recovery hash (EIP-1271).

// SocialRecoveryModuleV2
const { domain, types, messageValue } = await srm.getRecoveryRequestEip712Data(
nodeUrl,
chainId,
accountAddress,
[newOwnerAddress],
1n, // new threshold
);

// each guardian signs { domain, types, messageValue } and returns { signer, signature }

const multiConfirmTx = srm.createMultiConfirmRecoveryMetaTransaction(
accountAddress,
[newOwnerAddress],
1, // new threshold
messageValue.nonce,
signaturePairList,
true, // execute
);
keytypedescription
accountAddressstringThe target account address.
newOwnersstring[]The new owners' addresses.
newThresholdnumberThe new threshold for the safe.
noncebigintThe recovery nonce the guardians signed (messageValue.nonce from getRecoveryRequestEip712Data). It must still be the account's current nonce when the transaction is included.
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.

On V2 it also invalidates the guardian confirmations collected for the current nonce, and can be sent when no recovery is in progress. On V1 it reverts when no recovery is in progress.

Helpers​

hasGuardianApproved​

Retrieves specific guardian approval status for a particular recovery request at the current nonce. On V2, only current guardians are reported as having approved.

keytypedescription
nodeRpcUrlstring | Transport | JsonRpcNodeThe 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
nodeRpcUrlstring | Transport | JsonRpcNodeThe 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
nodeRpcUrlstring | Transport | JsonRpcNodeThe Node URL of the Ethereum RPC endpoint.
accountAddressstringThe target account address.

threshold​

Retrieves the guardians threshold for the account.

keytypedescription
nodeRpcUrlstring | Transport | JsonRpcNodeThe Node URL of the Ethereum RPC endpoint.
accountAddressstringThe target account address.

getGuardians​

Get the active guardians for an account.

keytypedescription
nodeRpcUrlstring | Transport | JsonRpcNodeThe Node URL of the Ethereum RPC endpoint.
accountAddressstringThe target account address.

getRecoveryRequest​

Retrieves the account's current ongoing recovery request. V2 returns a RecoveryRequestV2, which adds the request nonce and renames executeAfter to executableAt. V1 returns a RecoveryRequestV1.

keytypedescription
nodeRpcUrlstring | Transport | JsonRpcNodeThe 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
nodeRpcUrlstring | Transport | JsonRpcNodeThe 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's recovery nonce for an account. On V2, pass it to createConfirmRecoveryMetaTransaction.

keytypedescription
nodeRpcUrlstring | Transport | JsonRpcNodeThe 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
nodeRpcUrlstring | Transport | JsonRpcNodeThe 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. It reads the current recovery nonce from the node unless overrides.recoveryNonce is set. The domain version matches the class: "0.2.0" for V2 and "0.0.1" for V1.

keytypedescription
rpcNodestring | Transport | JsonRpcNodeNode 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. recoveryNonce sets the recovery nonce instead of reading it from the node.

Types​

RecoveryRequestV2​

Returned by SocialRecoveryModuleV2.getRecoveryRequest.

keytypedescription
guardiansApprovalCountbigintThe number of guardian approvals.
newThresholdbigintThe new threshold for the safe.
noncebigintThe recovery nonce the request was approved under.
executableAtbigintUnix timestamp (seconds) from which the recovery can be finalized. 0 if no recovery is in progress.
newOwnersstring[]Array of new owners' addresses.

RecoveryRequestV1​

Returned by SocialRecoveryModuleV1.getRecoveryRequest.

keytypedescription
guardiansApprovalCountbigintThe number of guardian approvals.
newThresholdbigintThe new threshold for the safe.
executeAfterbigintUnix timestamp (seconds) from which the recovery can be finalized. 0 if not yet executed.
newOwnersstring[]Array of new owners' addresses.

RecoverySignaturePair​

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

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