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
:
await openfort.embeddedWallet.setEmbeddedRecovery({
recoveryMethod,
recoveryPassword,
encryptionSession,
});
In order to update the recovery method, you will need to request the user for their password.
When calling setEmbeddedRecovery
, then recovery method will be updated to the new method provided. The user won't be required to reconstruct their private key right after.
As an example, you might add setEmbeddedRecovery
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 recoveryMethod = RecoveryMethod.PASSWORD;
const recoveryPassword = password;
const encryptionSession = await getEncryptionSession();
await setWalletRecovery({
recoveryMethod,
recoveryPassword,
encryptionSession,
});
};
return (
<div>
<input
name={'password'}
placeholder="password recovery"
/>
<button onClick={handleUpdateRecovery}>
{'Add recovery to your wallet'}
</button>
</div>
);
}