Management API Reference

Wallet

Update recovery method

Once a wallet has been created, users have the ability to upgrade from automatic recovery to a user-owned recovery method, or to switch between different user-owned recovery methods.

Upgrading a user's recovery method#

To update the recovery method, you will need to call the setEmbeddedRecovery:


_10
await openfort.setEmbeddedRecovery({
_10
recoveryMethod,
_10
recoveryPassword,
_10
encryptionSession,
_10
});

In order to update the recovery method, you will need to request the user for their password.

(Coming soon) Users can reset their password using this method as well.

When calling setEmbeddedRecovery, then recovery method will be updated to the new method provided. The user won't be required to reconstruct their embedded signer right after.

As an example, you might add setEmbeddedRecovery as an event handler for a set recovery button in your app:

UpdateRecoveryButton.tsx
encryptionSession.ts
openfortConfig.ts

_35
import openfort from './openfortConfig';
_35
import {RecoveryMethod} from '@openfort/openfort-js';
_35
import getEncryptionSession from "./encryptionSession"
_35
_35
// This example assumes you have already checked that Openfort 'embeddedState' is
_35
// `ready` and the user is `authenticated`
_35
function AddOrUpdateRecoveryButton() {
_35
const handleUpdateRecovery = async () => {
_35
const password = (
_35
document.querySelector(
_35
`input[name="password"]`
_35
) as HTMLInputElement
_35
).value;
_35
const recoveryMethod = RecoveryMethod.PASSWORD;
_35
const recoveryPassword = password;
_35
const encryptionSession = await getEncryptionSession();
_35
await setWalletRecovery({
_35
recoveryMethod,
_35
recoveryPassword,
_35
encryptionSession,
_35
});
_35
};
_35
_35
return (
_35
<div>
_35
<input
_35
name={'password'}
_35
placeholder="password recovery"
_35
/>
_35
<button onClick={handleUpdateRecovery}>
_35
{'Add recovery to your wallet'}
_35
</button>
_35
</div>
_35
);
_35
}