> ## Documentation Index
> Fetch the complete documentation index at: https://www.dynamic.xyz/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# Offline recovery

> Create encrypted offline recovery shares for embedded wallets from the Swift SDK.

Offline recovery creates two additional encrypted key shares, separate from the wallet's primary key shares. Share 1 is stored in the user's Google Drive, and Share 2 is delivered to your configured webhook. Together they let the user reconstruct the wallet when Dynamic is offline. For the complete recovery model and recovery tool, see [Offline Recovery](https://www.dynamic.xyz/docs/embedded-wallets/mpc/offline-recovery.md).

## Prerequisites

Before calling the SDK method, configure offline recovery for the environment:

1. Configure [Google Drive backup](https://www.dynamic.xyz/docs/embedded-wallets/mpc/backup.md).
2. In the Dynamic Console, go to **Wallets** > **Embedded Wallets** > **Backup & Recovery**.
3. Turn on **Developer Recovery Share**.
4. Configure the **Share Delivery** webhook URL and the RSA public key used to encrypt shares.

When offline recovery is enabled, users cannot use Google Drive as a regular cloud backup.

## Create recovery shares

Call `createOfflineRecoveryShares` on `sdk.wallets.waas` with the embedded wallet:

```swift theme={"system"}
import DynamicSDKSwift

let sdk = DynamicSDK.instance()

func createRecoveryShares(
    wallet: BaseWallet,
    password: String?
) async throws {
    try await sdk.wallets.waas.createOfflineRecoveryShares(
        wallet: wallet,
        password: password
    )
}
```

Pass the wallet password when the wallet is password-protected. The method returns after the recovery shares are created. Your webhook then receives a `wallet.offlineRecovery.created` event containing the encrypted developer recovery share.

### Require MFA

Step-up authentication is not required, but Dynamic strongly recommends verifying the user before creating recovery shares. Complete an MFA verification that returns a token, then pass it as `mfaToken`:

```swift theme={"system"}
try await sdk.wallets.waas.createOfflineRecoveryShares(
    wallet: wallet,
    password: password,
    mfaToken: mfaToken
)
```

See [MFA](https://www.dynamic.xyz/docs/swift/mfa.md) for the available verification methods.

### Encrypt to an end user's key

By default, Share 2 is encrypted to the RSA public key configured on your environment, which means your backend can decrypt it. To make the share decryptable only with a private key held elsewhere, pass a base64-encoded RSA public key of 2048 bits or larger as `recoveryEncryptionPublicKey`:

```swift theme={"system"}
try await sdk.wallets.waas.createOfflineRecoveryShares(
    wallet: wallet,
    password: password,
    mfaToken: mfaToken,
    recoveryEncryptionPublicKey: userRegisteredPublicKey
)
```

`userRegisteredPublicKey` is application-supplied and can be a base64-encoded PEM key or raw public key data. Keep the matching private key where recovery should be possible, such as on the user's device. When `recoveryEncryptionPublicKey` is omitted, the environment's configured key is used.

## Parameters

| Parameter | Type | Required | Description |
| - | - | - | - |
| `wallet` | `BaseWallet` | Yes | The embedded wallet to create recovery shares for. |
| `password` | `String?` | No | The wallet password when the wallet is password-protected. |
| `cloudProviderAccessToken` | `String?` | No | OAuth access token for the cloud backup provider. |
| `mfaToken` | `String?` | No | Token returned by MFA verification. |
| `recoveryEncryptionPublicKey` | `String?` | No | Base64-encoded RSA public key, 2048 bits or larger, used to encrypt Share 2. |

## Related

> [card] [Offline Recovery](https://www.dynamic.xyz/docs/embedded-wallets/mpc/offline-recovery.md)
>
> Understand the recovery shares, webhook event, and recovery tool.

> [card] [Password encryption](https://www.dynamic.xyz/docs/swift/wallets/embedded-wallets/mpc/password-encryption.md)
>
> Unlock password-protected wallets before sensitive operations.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.