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, call setRecoveryMethod with both the previous recovery params and new recovery params:
await openfort.embeddedWallet.setRecoveryMethod(previousRecovery, newRecovery);To update the recovery method, you need to provide either the user's current password or an encryption session.
When calling setRecoveryMethod, the recovery method is updated to the new method provided. The user won't need to reconstruct their private key immediately after.
As an example, you might add setRecoveryMethod as an event handler for a set recovery button in your app:
UpdateRecoveryButton.tsx
import openfort from './openfortConfig';
import {RecoveryMethod} from '@openfort/openfort-js';
import getEncryptionSession from "./encryptionSession"
// This example assumes you have already checked that Openfort 'embeddedState' is
// `ready` and the user is `authenticated`
function AddOrUpdateRecoveryButton() {
const handleUpdateRecovery = async () => {
const password = (
document.querySelector(
`input[name="password"]`
) as HTMLInputElement
).value;
const encryptionSession = await getEncryptionSession();
// Previous recovery method (e.g., automatic)
const previousRecovery = {
recoveryMethod: RecoveryMethod.AUTOMATIC,
encryptionSession,
};
// New recovery method (e.g., password)
const newRecovery = {
recoveryMethod: RecoveryMethod.PASSWORD,
password,
};
await openfort.embeddedWallet.setRecoveryMethod(previousRecovery, newRecovery);
};
return (
<div>
<input
name={'password'}
placeholder="password recovery"
/>
<button onClick={handleUpdateRecovery}>
{'Add recovery to your wallet'}
</button>
</div>
);
}