# IWalletBackupManager

> Restore a wallet key from a data-provider backup, or move it directly between two TEE machines.

> For the complete documentation index, see [llms.txt](/llms.txt). Markdown versions of documentation pages are available by appending `.md` to the page URL.

Source: https://dev.flare.network/fcc/reference/IWalletBackupManager

Public interface for `WalletBackupManagerFacet` on the [`FlareTeeManager`](/fcc/reference/IFlareTeeManager) diamond.

This facet starts a restore of a [wallet key](/fcc/keys-and-backup). It does not hold the private key. The [`backupRestore`](#backuprestore) call asks the data providers and key admins to rebuild a key on a TEE that does not have it. The [`directBackup`](#directbackup) and [`directRestore`](#directrestore) calls move a key that a TEE still holds to one other TEE.

The project owner or that project's backup manager makes each call. The call is payable and pays the instruction fee. Each call sends one `F_WALLET` instruction to a TEE that is in `PRODUCTION` on the wallet's extension.

Inherits shared [`ITeeCommonErrors`](/fcc/reference/ITeeCommonErrors).

info

FCC and Protocol Managed Wallets are in the final stages of development. Prefer **Coston2** for examples and treat interfaces as subject to change.

## Types[​](#types "Direct link to Types")

### `BackupId`[​](#backupid "Direct link to backupid")

Identifies one backup of one wallet key. The TEE that produced the backup is `teeId`. The `rewardEpochId` field is the signing policy whose data-provider weights the shares were cut against. The `randomNonce` field separates two backups of the same key in the same reward epoch.

```
struct BackupId {        address teeId;        bytes32 walletId;        uint64 keyId;        bytes32 keyType;        bytes32 signingAlgo;        bytes publicKey;        uint32 rewardEpochId;        bytes32 randomNonce;    }
```

### `KeyDataProviderRestore`[​](#keydataproviderrestore "Direct link to keydataproviderrestore")

Payload of the `F_WALLET` / `KEY_DATA_PROVIDER_RESTORE` instruction sent by [`backupRestore`](#backuprestore). The `teePublicKey` field is the destination TEE. The `nonce` field is the key nonce after this call increments it.

```
struct KeyDataProviderRestore {        PublicKey teePublicKey;        BackupId backupId;        string backupUrl;        uint256 nonce;    }
```

### `KeyDirectBackup`[​](#keydirectbackup "Direct link to keydirectbackup")

Payload of the `F_WALLET` / `KEY_DIRECT_BACKUP` instruction sent by [`directBackup`](#directbackup). The source TEE encrypts the wallet key to `destinationTeePublicKey`. The `machinePathListNonce` field selects the governance-signed machine-path list the TEE checks.

```
struct KeyDirectBackup {        address sourceTeeId;        bytes32 walletId;        uint64 keyId;        PublicKey destinationTeePublicKey;        uint256 machinePathListNonce;    }
```

### `KeyDirectRestore`[​](#keydirectrestore "Direct link to keydirectrestore")

Payload of the `F_WALLET` / `KEY_DIRECT_RESTORE` instruction sent by [`directRestore`](#directrestore). The destination fetches the ciphertext from `sourceProxyUrl` at `backupInstructionId`. The `destinationNonce` field is the key nonce after this call increments it. The destination's restore proof binds to that nonce.

```
struct KeyDirectRestore {        address sourceTeeId;        string sourceProxyUrl;        BackupId backupId;        bytes32 backupInstructionId;        uint256 destinationNonce;        uint256 machinePathListNonce;    }
```

## Functions[​](#functions "Direct link to Functions")

### `backupRestore`[​](#backuprestore "Direct link to backuprestore")

Starts a data-provider restore of a wallet key onto `_teeId`. Emits [`BackupRestoreTriggered`](#backuprestoretriggered).

The project owner or the project's backup manager calls it. The destination TEE must be in `PRODUCTION` on the wallet's extension and must not already hold the key. The TEE named in `_backupId.teeId` must not be `INITIALIZED`. The backup's public key, key type, and signing algorithm must match the confirmed key.

The contract accepts `_backupId.rewardEpochId` when it is at most the current reward epoch plus one. An older backup can still fail later, when too few of that epoch's data providers can open their shares.

The call increments the key nonce on the destination, then sends one `F_WALLET` / `KEY_DATA_PROVIDER_RESTORE` instruction. The instruction's cosigners are the wallet's key admins, and its cosigner threshold is the wallet's admin threshold. Data providers and key admins then submit shares to the destination proxy. After the TEE returns a key-existence proof, the project owner or the backup manager calls [`confirmKey`](/fcc/reference/IWalletKeyManager#confirmkey) to record the new holder.

```
function backupRestore(        address _teeId,        BackupId calldata _backupId,        string calldata _backupUrl,        address _claimBackAddress    )        external payable
```

**Parameters**

-   `_teeId`: The TEE the key will be restored onto.
-   `_backupId`: The backup to restore.
-   `_backupUrl`: The URL of the backup package.
-   `_claimBackAddress`: The address that can claim the fee back if the instruction is not executed. Pass the zero address to skip it.

**Reverts**

-   [`OnlyOwnerOrBackupManager`](/fcc/reference/ITeeCommonErrors#onlyownerorbackupmanager) when the caller is not the project owner or the backup manager.
-   [`TeeMachineNotAvailable`](/fcc/reference/ITeeCommonErrors#teemachinenotavailable) when the destination TEE is not in `PRODUCTION`.
-   [`InvalidTeeMachine`](#invalidteemachine) when the TEE in `_backupId.teeId` is `INITIALIZED`.
-   [`KeyAlreadyAvailable`](#keyalreadyavailable) when the destination already holds the key.
-   [`KeyNotConfirmed`](#keynotconfirmed) when the wallet has no confirmed public key for this key id.
-   [`InvalidPublicKey`](/fcc/reference/ITeeCommonErrors#invalidpublickey) when `_backupId.publicKey` does not match the stored public key.
-   [`InvalidKeyType`](/fcc/reference/ITeeCommonErrors#invalidkeytype) when `_backupId.keyType` does not match the project.
-   [`InvalidSigningAlgo`](/fcc/reference/ITeeCommonErrors#invalidsigningalgo) when `_backupId.signingAlgo` does not match the project.
-   [`ExtensionIdMismatch`](/fcc/reference/ITeeCommonErrors#extensionidmismatch) when the backup TEE, the destination TEE, and the wallet's project are not the same extension.
-   [`InvalidRewardEpochId`](#invalidrewardepochid) when `_backupId.rewardEpochId` is greater than the current reward epoch plus one.

### `directBackup`[​](#directbackup "Direct link to directbackup")

Asks a TEE that holds the key to encrypt it for one other TEE. Emits [`DirectBackupTriggered`](#directbackuptriggered). Returns the instruction id the later [`directRestore`](#directrestore) fetches.

The project owner or the project's backup manager calls it. Both TEE machines must be in `PRODUCTION` on the wallet's extension. The extension's active machine-path list must include this pair: the source in a path's source set and the destination in that same path's destination set. The source must currently hold the key, and the destination must not.

This call does not change the destination's key nonce. A failed [`directRestore`](#directrestore) can be retried against the same instruction id.

```
function directBackup(        address _sourceTeeId,        address _destinationTeeId,        bytes32 _walletId,        uint64 _keyId,        address _claimBackAddress    )        external payable        returns (bytes32 _instructionId)
```

**Parameters**

-   `_sourceTeeId`: The TEE that currently holds the key.
-   `_destinationTeeId`: The TEE a later `directRestore` will import the key onto.
-   `_walletId`: The wallet id.
-   `_keyId`: The key id.
-   `_claimBackAddress`: The address that can claim the fee back if the instruction is not executed. Pass the zero address to skip it.

**Returns**

-   `_instructionId`: The id of the `KEY_DIRECT_BACKUP` instruction. Pass it to `directRestore`.

**Reverts**

-   [`OnlyOwnerOrBackupManager`](/fcc/reference/ITeeCommonErrors#onlyownerorbackupmanager) when the caller is not the project owner or the backup manager.
-   [`TeeMachineNotAvailable`](/fcc/reference/ITeeCommonErrors#teemachinenotavailable) when the source or the destination is not in `PRODUCTION`.
-   [`ExtensionIdMismatch`](/fcc/reference/ITeeCommonErrors#extensionidmismatch) when either TEE is outside the wallet's extension.
-   `NoActiveMachinePathList` when the extension has no signed machine-path list.
-   `InvalidMachinePath` when the active list does not allow this source and destination pair.
-   [`KeyNotConfirmed`](#keynotconfirmed) when the wallet has no confirmed public key for this key id.
-   [`SourceTeeDoesNotHoldKey`](#sourceteedoesnotholdkey) when the source is not a current holder.
-   [`KeyAlreadyAvailable`](#keyalreadyavailable) when the destination already holds the key.

### `directRestore`[​](#directrestore "Direct link to directrestore")

Imports a key onto the destination TEE from a blob produced by [`directBackup`](#directbackup). Emits [`DirectRestoreTriggered`](#directrestoretriggered).

The project owner or the project's backup manager calls it. The destination fetches the ciphertext from the source TEE's proxy at `_backupInstructionId`. The call increments the destination's key nonce, and the restore proof binds to the new nonce.

The backup's reward epoch must be the current reward epoch or the one before it. The same machine-path pair required by [`directBackup`](#directbackup) must still be in the active list. The instruction has no cosigners. Data providers still sign it with more than half the signing-policy weight.

```
function directRestore(        address _destinationTeeId,        BackupId calldata _backupId,        bytes32 _backupInstructionId,        address _claimBackAddress    )        external payable        returns (bytes32 _instructionId)
```

**Parameters**

-   `_destinationTeeId`: The TEE the key will be restored onto.
-   `_backupId`: The backup id of the blob from `directBackup`. The `teeId` in that id is the source TEE.
-   `_backupInstructionId`: The instruction id returned by `directBackup`.
-   `_claimBackAddress`: The address that can claim the fee back if the instruction is not executed. Pass the zero address to skip it.

**Returns**

-   `_instructionId`: The id of the `KEY_DIRECT_RESTORE` instruction.

**Reverts**

-   [`OnlyOwnerOrBackupManager`](/fcc/reference/ITeeCommonErrors#onlyownerorbackupmanager) when the caller is not the project owner or the backup manager.
-   [`TeeMachineNotAvailable`](/fcc/reference/ITeeCommonErrors#teemachinenotavailable) when the destination is not in `PRODUCTION`.
-   [`InvalidTeeMachine`](#invalidteemachine) when the source TEE in `_backupId.teeId` is `INITIALIZED`.
-   [`KeyAlreadyAvailable`](#keyalreadyavailable) when the destination already holds the key.
-   [`KeyNotConfirmed`](#keynotconfirmed) when the wallet has no confirmed public key for this key id.
-   [`InvalidPublicKey`](/fcc/reference/ITeeCommonErrors#invalidpublickey) when `_backupId.publicKey` does not match the stored public key.
-   [`InvalidKeyType`](/fcc/reference/ITeeCommonErrors#invalidkeytype) when `_backupId.keyType` does not match the project.
-   [`InvalidSigningAlgo`](/fcc/reference/ITeeCommonErrors#invalidsigningalgo) when `_backupId.signingAlgo` does not match the project.
-   [`ExtensionIdMismatch`](/fcc/reference/ITeeCommonErrors#extensionidmismatch) when the source TEE, the destination TEE, and the wallet's project are not the same extension.
-   [`InvalidRewardEpochId`](#invalidrewardepochid) when `_backupId.rewardEpochId` is not the current reward epoch or the one before it.
-   `NoActiveMachinePathList` when the extension has no signed machine-path list.
-   `InvalidMachinePath` when the active list does not allow this source and destination pair.

## Events[​](#events "Direct link to Events")

### `BackupRestoreTriggered`[​](#backuprestoretriggered "Direct link to backuprestoretriggered")

Emitted when [`backupRestore`](#backuprestore) sends the restore instruction. The `nonce` field is the destination key nonce after the call increments it.

```
event BackupRestoreTriggered(        address indexed teeId,        bytes32 indexed walletId,        uint64 indexed keyId,        uint256 nonce    )
```

**Parameters**

-   `teeId` (`address indexed teeId`): The destination TEE.
-   `walletId` (`bytes32 indexed walletId`)
-   `keyId` (`uint64 indexed keyId`)
-   `nonce` (`uint256 nonce`)

### `DirectBackupTriggered`[​](#directbackuptriggered "Direct link to directbackuptriggered")

Emitted when [`directBackup`](#directbackup) sends the backup instruction. The `backupInstructionId` value is what a later [`directRestore`](#directrestore) call fetches.

```
event DirectBackupTriggered(        address indexed sourceTeeId,        address indexed destinationTeeId,        bytes32 indexed walletId,        uint64 keyId,        bytes32 backupInstructionId    )
```

**Parameters**

-   `sourceTeeId` (`address indexed sourceTeeId`)
-   `destinationTeeId` (`address indexed destinationTeeId`)
-   `walletId` (`bytes32 indexed walletId`)
-   `keyId` (`uint64 keyId`)
-   `backupInstructionId` (`bytes32 backupInstructionId`)

### `DirectRestoreTriggered`[​](#directrestoretriggered "Direct link to directrestoretriggered")

Emitted when [`directRestore`](#directrestore) sends the restore instruction. The `destinationNonce` field is the destination key nonce after the call increments it.

```
event DirectRestoreTriggered(        address indexed destinationTeeId,        bytes32 indexed walletId,        uint64 indexed keyId,        uint256 destinationNonce,        bytes32 backupInstructionId    )
```

**Parameters**

-   `destinationTeeId` (`address indexed destinationTeeId`)
-   `walletId` (`bytes32 indexed walletId`)
-   `keyId` (`uint64 indexed keyId`)
-   `destinationNonce` (`uint256 destinationNonce`)
-   `backupInstructionId` (`bytes32 backupInstructionId`)

## Errors[​](#errors "Direct link to Errors")

Facet-specific errors are listed here. The interface also inherits shared [`ITeeCommonErrors`](/fcc/reference/ITeeCommonErrors), including `OnlyOwnerOrBackupManager`, `TeeMachineNotAvailable`, `ExtensionIdMismatch`, `InvalidKeyType`, `InvalidSigningAlgo`, and `InvalidPublicKey`.

### `InvalidTeeMachine`[​](#invalidteemachine "Direct link to invalidteemachine")

The TEE named as the source in `BackupId.teeId` is still `INITIALIZED`.

```
error InvalidTeeMachine()
```

### `KeyAlreadyAvailable`[​](#keyalreadyavailable "Direct link to keyalreadyavailable")

The destination TEE already holds this wallet key.

```
error KeyAlreadyAvailable()
```

### `KeyNotConfirmed`[​](#keynotconfirmed "Direct link to keynotconfirmed")

The wallet has no confirmed public key for this key id.

```
error KeyNotConfirmed()
```

### `InvalidRewardEpochId`[​](#invalidrewardepochid "Direct link to invalidrewardepochid")

The backup's reward epoch is outside the range for this call. The [`backupRestore`](#backuprestore) call accepts an epoch up through the current reward epoch plus one. The [`directRestore`](#directrestore) call accepts the current reward epoch or the one before it.

```
error InvalidRewardEpochId()
```

### `SourceTeeDoesNotHoldKey`[​](#sourceteedoesnotholdkey "Direct link to sourceteedoesnotholdkey")

The [`directBackup`](#directbackup) call named a source TEE that is not a current holder of the key.

```
error SourceTeeDoesNotHoldKey()
```
