Skip to main content

Recovery Service SDK Reference

The Safe Recovery Service SDK provides TypeScript classes for interacting with the Safe Recovery Service. It covers three main workflows: self-managed guardian recovery, custodial guardian recovery (email/SMS), and recovery alert notifications.

tip

Looking for the on-chain Social Recovery Module SDK? See the Module SDK Reference.

Install

npm i safe-recovery-service-sdk

Import

import {
RecoveryByGuardian,
RecoveryByCustodialGuardian,
Alerts,
generateSIWEMessage,
SafeRecoveryServiceSdkError,
SocialRecoveryModuleGracePeriodSelector,
} from "safe-recovery-service-sdk";

RecoveryByGuardian

Service client for managing recovery flows using self-managed guardians. Handles creating recovery requests, collecting guardian signatures, and executing/finalizing recovery.

Initialize

import { RecoveryByGuardian, SocialRecoveryModuleGracePeriodSelector } from "safe-recovery-service-sdk";

const recoveryService = new RecoveryByGuardian(
"https://safe-recovery.candide.dev",
1n, // chainId
SocialRecoveryModuleGracePeriodSelector.After3Days
);
keytypedescription
serviceEndpointstringThe URL of the Safe Recovery Service endpoint
chainIdbigintThe chain ID of the network (e.g. 1n for Ethereum mainnet)
recoveryModuleAddressSocialRecoveryModuleGracePeriodSelectorThe address of the Social Recovery Module with the desired grace period. Options: After3Minutes, After3Days, After7Days, After14Days

createRecoveryRequest

Creates a new recovery request with the specified new owners and threshold. Requires a guardian signature authorizing the recovery.

keytypedescription
accountAddressstringThe Safe account address to recover
newOwnersstring[]The new owners for the Safe account
newThresholdnumberThe new threshold for the Safe account
guardianAddressstringThe guardian address initiating the recovery request
guardianSignaturestringThe EIP-712 signature from the guardian authorizing the recovery

submitGuardianSignatureForRecoveryRequest

Submits an additional guardian signature for an existing recovery request. Used when multiple guardian approvals are required.

keytypedescription
idstringThe recovery request ID
guardianAddressstringThe guardian address submitting the signature
guardianSignaturestringThe EIP-712 signature from the guardian

executeRecoveryRequest

Triggers the execution of a recovery request. Once executed, the grace period countdown begins before the recovery can be finalized.

keytypedescription
idstringThe recovery request ID to execute

finalizeRecoveryRequest

Finalizes a recovery request after the grace period has elapsed. This completes the ownership transfer.

keytypedescription
idstringThe recovery request ID to finalize

getRecoveryRequests

Queries recovery requests for a specific account and nonce.

keytypedescription
accountAddressstringThe Safe account address
recoveryNoncebigintThe recovery module nonce to query

getRecoveryRequestsForLatestNonce

Fetches recovery requests for the latest on-chain nonce, filtered by status. Automatically queries the RPC node for the current nonce.

keytypedescription
rpcNodestringThe RPC node URL to query the on-chain nonce
accountAddressstringThe Safe account address
status"PENDING" | "EXECUTED" | "FINALIZED"Filter recovery requests by status

getPendingRecoveryRequestsForLatestNonce

Convenience method that fetches pending recovery requests for the latest nonce.

keytypedescription
rpcNodestringThe RPC node URL to query the on-chain nonce
accountAddressstringThe Safe account address

getExecutedRecoveryRequestForLatestNonce

Fetches the executed recovery request for the latest nonce, if one exists.

keytypedescription
rpcNodestringThe RPC node URL to query the on-chain nonce
accountAddressstringThe Safe account address

getFinalizedRecoveryRequestForLatestNonce

Fetches the finalized recovery request for the latest nonce, if one exists.

keytypedescription
rpcNodestringThe RPC node URL to query the on-chain nonce
accountAddressstringThe Safe account address

RecoveryByCustodialGuardian

Interface for managing recovery using custodial guardians via email or SMS. Handles channel registration, OTP verification, and recovery execution through Candide's custodial guardian service.

Initialize

import { RecoveryByCustodialGuardian } from "safe-recovery-service-sdk";

const custodialRecovery = new RecoveryByCustodialGuardian(
"https://safe-recovery.candide.dev",
1n, // chainId
);

You can optionally override the SIWE domain and URI:

const custodialRecovery = new RecoveryByCustodialGuardian(
"https://safe-recovery.candide.dev",
1n,
{ siweDomain: "myapp.com", siweUri: "https://myapp.com" }
);
keytypedescription
serviceEndpointstringThe URL of the Safe Recovery Service endpoint
chainIdbigintThe chain ID of the network (e.g. 1n for Ethereum mainnet)
overridesobject | undefinedOptional overrides for SIWE message generation. Contains siweDomain (string) and siweUri (string)

Registration Management

getRegistrationsSiweStatementToSign

Returns the SIWE statement string that needs to be signed to fetch registrations.

keytypedescription
accountAddressstringThe Safe account address

getRegistrations

Fetches active email/SMS recovery registrations for a Safe account.

keytypedescription
accountAddressstringThe Safe account address
siweMessagestringThe SIWE message to authenticate the request
eip1271SiweContractSignaturestringThe EIP-1271 contract signature for the SIWE message

createRegistrationToEmailRecoverySiweStatementToSign

Returns the SIWE statement for registering an email recovery method.

keytypedescription
accountAddressstringThe Safe account address
emailstringThe email address to register for recovery

createRegistrationToEmailRecovery

Registers an email address as a recovery channel. Returns a challenge ID for OTP verification.

keytypedescription
accountAddressstringThe Safe account address
emailstringThe email address to register for recovery
siweMessagestringThe SIWE message to authenticate the request
eip1271SiweContractSignaturestringThe EIP-1271 contract signature for the SIWE message

createRegistrationToSmsRecoverySiweStatementToSign

Returns the SIWE statement for registering an SMS recovery method.

keytypedescription
accountAddressstringThe Safe account address
phoneNumberstringThe phone number to register for recovery

createRegistrationToSmsRecovery

Registers a phone number as a recovery channel. Returns a challenge ID for OTP verification.

keytypedescription
accountAddressstringThe Safe account address
phoneNumberstringThe phone number to register for recovery
siweMessagestringThe SIWE message to authenticate the request
eip1271SiweContractSignaturestringThe EIP-1271 contract signature for the SIWE message

createRegistrationToRecoverySiweStatementToSign

Generic method that returns the SIWE statement for registering any recovery channel.

keytypedescription
accountAddressstringThe Safe account address
channel"sms" | "email"The recovery channel type
channelTargetstringThe email address or phone number

createRegistrationToRecovery

Generic method that registers a recovery channel. Returns a challenge ID for OTP verification.

keytypedescription
accountAddressstringThe Safe account address
channel"sms" | "email"The recovery channel type
channelTargetstringThe email address or phone number
siweMessagestringThe SIWE message to authenticate the request
eip1271SiweContractSignaturestringThe EIP-1271 contract signature for the SIWE message

submitRegistrationChallenge

Submits the OTP code to verify a registration. Returns the registration ID and the assigned custodial guardian address.

keytypedescription
challengeIdstringThe challenge ID received from the registration step
otpChallengestringThe OTP code received via email or SMS

deleteRegistrationSiweStatementToSign

Returns the SIWE statement for deleting a registration.

keytypedescription
accountAddressstringThe Safe account address
registrationIdstringThe registration ID to delete

deleteRegistration

Removes an email or SMS recovery registration.

keytypedescription
registrationIdstringThe registration ID to delete
siweMessagestringThe SIWE message to authenticate the request
eip1271SiweContractSignaturestringThe EIP-1271 contract signature for the SIWE message

Recovery Flow

requestCustodialGuardianSignatureChallenge

Initiates a recovery request through the custodial guardian. Sends OTP challenges to all registered recovery channels.

keytypedescription
accountAddressstringThe Safe account address to recover
newOwnersstring[]The new owners for the Safe account
newThresholdnumberThe new threshold for the Safe account

submitCustodialGuardianSignatureChallenge

Submits an OTP code for a specific authentication challenge. When all required verifications are collected, returns the custodial guardian address and signature.

keytypedescription
requestIdstringThe signature request ID from requestCustodialGuardianSignatureChallenge
challengeIdstringThe challenge ID for the specific authentication method
otpChallengestringThe OTP code received via email or SMS

createAndExecuteRecoveryRequest

Creates a recovery request and immediately triggers execution using the custodial guardian's signature. Combines createRecoveryRequest and executeRecoveryRequest into a single call.

keytypedescription
accountAddressstringThe Safe account address to recover
newOwnersstring[]The new owners for the Safe account
newThresholdnumberThe new threshold for the Safe account
custodianGuardianAddressstringThe custodial guardian address obtained from signature challenge
custodianGuardianSignaturestringThe recovery signature from the custodial guardian

Alerts

Service class for managing email and SMS alert subscriptions for recovery events on Safe accounts. Account owners receive notifications when recovery actions are initiated.

Initialize

import { Alerts } from "safe-recovery-service-sdk";

const alerts = new Alerts(
"https://safe-recovery.candide.dev",
1n, // chainId
);
keytypedescription
serviceEndpointstringThe URL of the Safe Recovery Service endpoint
chainIdbigintThe chain ID of the network (e.g. 1n for Ethereum mainnet)
overridesobject | undefinedOptional overrides for SIWE message generation. Contains siweDomain (string) and siweUri (string)

createEmailSubscriptionSiweStatementToSign

Returns the SIWE statement for creating an email alert subscription.

keytypedescription
accountAddressstringThe Safe account address
ownerAddressstringThe owner address of the Safe account
emailstringThe email address for alert notifications

createEmailSubscription

Creates an email alert subscription. Returns a subscription ID for OTP activation.

keytypedescription
accountAddressstringThe Safe account address
ownerAddressstringThe owner address of the Safe account
emailstringThe email address for alert notifications
siweMessagestringThe SIWE message to authenticate the request
siweOwnerSignaturestringThe owner's signature for the SIWE message

createSubscriptionSiweStatementToSign

Generic method that returns the SIWE statement for creating an alert subscription on any channel.

keytypedescription
accountAddressstringThe Safe account address
ownerAddressstringThe owner address of the Safe account
channel"sms" | "email"The notification channel type
channelTargetstringThe email address or phone number

createSubscription

Generic method that creates an alert subscription on any channel. Returns a subscription ID for OTP activation.

keytypedescription
accountAddressstringThe Safe account address
ownerAddressstringThe owner address of the Safe account
channel"sms" | "email"The notification channel type
channelTargetstringThe email address or phone number
siweMessagestringThe SIWE message to authenticate the request
siweOwnerSignaturestringThe owner's signature for the SIWE message

activateSubscription

Verifies and activates a subscription using the OTP code sent to the email or phone number.

keytypedescription
subscriptionIdstringThe subscription ID to activate
otpChallengestringThe OTP code received via email or SMS

getSubscriptionsSiweStatementToSign

Returns the SIWE statement for fetching active subscriptions.

keytypedescription
ownerAddressstringThe owner address of the Safe account

getActiveSubscriptions

Fetches all active alert subscriptions for a Safe account.

keytypedescription
accountAddressstringThe Safe account address to query subscriptions for
ownerAddressstringThe owner address of the Safe account
siweMessagestringThe SIWE message to authenticate the request
siweOwnerSignaturestringThe owner's signature for the SIWE message

unsubscribeSiweStatementToSign

Returns the SIWE statement for removing a subscription.

keytypedescription
ownerAddressstringThe owner address of the Safe account

unsubscribe

Removes an alert subscription.

keytypedescription
subscriptionIdstringThe subscription ID to remove
ownerAddressstringThe owner address of the Safe account
siweMessagestringThe SIWE message to authenticate the request
siweOwnerSignaturestringThe owner's signature for the SIWE message

Utility Functions

generateSIWEMessage

Generates a Sign-In with Ethereum (EIP-4361) message. Used internally by RecoveryByCustodialGuardian and Alerts, but also available for custom integrations.

keytypedescription
accountAddressstringThe account address for the SIWE message
statementstringThe human-readable statement for the SIWE message
chainIdbigintThe chain ID of the network
siweDomainstringThe domain for the SIWE message (e.g. 'example.com')
siweUristringThe URI for the SIWE message (e.g. 'https://example.com')

Types

RecoveryByGuardianRequest

Represents a recovery request with its current state and metadata.

keytypedescription
idstringUnique recovery request ID
emojistringEmoji identifier associated with the recovery request
accountstringThe Safe account address being recovered
newOwnersstring[]The new owners for the Safe account
newThresholdnumberThe new threshold for the Safe account
chainIdnumberThe chain ID of the network
noncebigintRecovery module contract nonce
signaturesstring[]Guardian signatures collected for this recovery request
executeData
keytypedescription
sponsoredbooleanWhether the execution transaction is gas-sponsored
transactionHashstring | undefinedThe transaction hash of the execution (if available)
Data about the recovery execution transaction
finalizeData
keytypedescription
sponsoredbooleanWhether the finalization transaction is gas-sponsored
transactionHashstring | undefinedThe transaction hash of the finalization (if available)
Data about the recovery finalization transaction
status"PENDING" | "EXECUTED" | "FINALIZED"Current status of the recovery request
discoverablebooleanWhether the recovery request is publicly discoverable
createdAtstringISO 8601 timestamp of when the request was created
updatedAtstringISO 8601 timestamp of the last update

Registration

Represents an email or SMS recovery channel registration.

keytypedescription
idstringUnique registration ID
channelstringThe recovery channel: "email" or "sms"
targetstringThe email address or phone number registered

SignatureRequest

Represents a custodial guardian signature request with its OTP challenges.

keytypedescription
requestIdstringUnique signature request ID
requiredVerificationsnumberMinimum number of OTP challenges required to obtain the guardian signature
auths
keytypedescription
challengeIdstringThe challenge ID for this authentication method
channelstringThe channel type: "email" or "sms"
targetstringThe email address or phone number to verify
List of authentication methods that can be used for verification

AlertsSubscription

Represents an active alert subscription.

keytypedescription
idstringUnique subscription ID
channel"email" | "sms"The notification delivery channel
targetstringThe email address or phone number receiving notifications

SocialRecoveryModuleGracePeriodSelector

Enum of deployed Social Recovery Module addresses with different grace periods.

keytypedescription
After3Minutesstring0x949d01d424bE050D09C16025dd007CB59b3A8c66 (useful for testing)
After3Daysstring0x38275826E1933303E508433dD5f289315Da2541c
After7Daysstring0x088f6cfD8BB1dDb1BB069CCb3fc1A98927D233f2
After14Daysstring0x9BacD92F4687Db306D7ded5d4513a51EA05df25b

Error Handling

SafeRecoveryServiceSdkError

All SDK methods throw SafeRecoveryServiceSdkError on failure. The error includes a code, message, and optional context for debugging.

import { SafeRecoveryServiceSdkError } from "safe-recovery-service-sdk";

try {
await recoveryService.createRecoveryRequest(/* ... */);
} catch (error) {
if (error instanceof SafeRecoveryServiceSdkError) {
console.log(error.code); // e.g. "HTTP_BAD_REQUEST"
console.log(error.message); // Human-readable message
console.log(error.context); // Additional context
console.log(error.stringify()); // Serialized error (useful for React Native)
}
}
keytypedescription
codeBasicErrorCodeThe error code identifying the type of error (e.g. HTTP_BAD_REQUEST, SIWE_ERROR, UNKNOWN_ERROR)
messagestringHuman-readable error message
contextJsonable | undefinedAdditional context about the error (e.g. URL, request options)
errnonumber | undefinedNumeric error code (typically the HTTP status code)

Error Codes:

CodeDescription
UNKNOWN_ERRORAn unexpected error occurred
TIMEOUTThe request timed out
SIWE_ERRORError generating or validating SIWE message
BAD_DATAInvalid data provided
HTTP_BAD_REQUEST400: Invalid request parameters
HTTP_UNAUTHORIZED401: Authentication required
HTTP_FORBIDDEN403: Insufficient permissions
HTTP_NOT_FOUND404: Resource not found
HTTP_CONFLICT409: Conflicting request
HTTP_TOO_MANY_REQUESTS429: Rate limit exceeded
HTTP_INTERNAL_ERROR500: Server error
HTTP_BAD_GATEWAY502: Bad gateway
HTTP_SERVICE_UNAVAILABLE503: Service temporarily unavailable
HTTP_GATEWAY_TIMEOUT504: Gateway timeout