> ## Documentation Index
> Fetch the complete documentation index at: https://build.onswig.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Set Up Recovery

Recovery setup happens after wallet creation. It is not finished by
`swig.wallets.create(...)` alone.

Use [Add a Guardian After Wallet Creation](/developer-sdk/add-guardian-after-creation)
instead if the wallet already exists and you are enabling recovery later.

## Create from a recovery-enabled policy

<CodeGroup dropdown>
  ```typescript TypeScript theme={null}
  const created = await swig.wallets.create({
    feePayer,
    policyId,
    initialUser: {
      secp256r1: {
        publicKey: passkeyPublicKey,
      },
    },
    recovery: {
      guardianPubkey: guardianPublicKey,
      delaySeconds: 86_400,
    },
  });
  ```

  ```python Python theme={null}
  from swig_developer_sdk import RecoveryOptions

  created = await swig.wallets.create(
      fee_payer=fee_payer,
      policy_id=policy_id,
      initial_user={
          "secp256r1": {
              "publicKey": passkey_public_key,
          },
      },
      recovery=RecoveryOptions(
          guardian_pubkey=guardian_public_key,
          delay_seconds=86_400,
      ),
  )
  ```
</CodeGroup>

If the policy is recovery-enabled and the SDK can derive the requester
authority and guardian information, `create(...)` returns `recoverySetup` /
`recovery_setup`.

## What `create(...)` gives you

For a recovery-enabled flow, the important pieces are:

* `creationTransaction` / `creation_transaction`
* `clientAuthorityTransactions` / `client_authority_transactions`
* `operatorSignedTransactions` / `operator_signed_transactions`
* `recoverySetup` / `recovery_setup`

## Prepare the follow-up setup

After wallet creation is submitted, prepare recovery setup:

<CodeGroup dropdown>
  ```typescript TypeScript theme={null}
  const wallet = swig.wallets.use(created.wallet);

  const setup = await wallet.recovery.prepareSetup({
    feePayer,
    ...created.recoverySetup!,
  });
  ```

  ```python Python theme={null}
  wallet = swig.wallets.use(created.wallet)
  assert created.recovery_setup is not None

  setup = await wallet.recovery.prepare_setup(
      fee_payer=fee_payer,
      guardian_pubkey=created.recovery_setup.guardian_pubkey,
      requester_authority=created.recovery_setup.requester_authority,
      delay_seconds=created.recovery_setup.delay_seconds,
      target_role_id=created.recovery_setup.target_role_id,
  )
  ```
</CodeGroup>

That returns:

* `addAuthorityTransaction` / `add_authority_transaction`
* `configureRecoveryTransaction` / `configure_recovery_transaction`

## Who signs what

| Transaction                                                       | Who signs                                  |
| ----------------------------------------------------------------- | ------------------------------------------ |
| `creationTransaction` / `creation_transaction`                    | fee payer or sponsor path                  |
| `addAuthorityTransaction` / `add_authority_transaction`           | current wallet authority                   |
| `configureRecoveryTransaction` / `configure_recovery_transaction` | backend recovery operator already signs it |

Treat `operatorSignedTransactions` / `operator_signed_transactions` as already
authority-signed and submit them through the fee payer or sponsor path.

## Advanced option

`targetRoleId` / `target_role_id` is available when you intentionally want
recovery bound to a specific non-default role.
