Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,8 @@ packages/*/dist/**
docs/core/FedimintWallet/BalanceService/subscribeBalance.md
docs/core/FedimintWallet/LightningService/createInvoice.md
docs/core/FedimintWallet/LightningService/payInvoice.md
docs/core/FedimintWallet/RecoveryService/subscribeToRecoveryProgress.md
docs/core/FedimintWallet/RecoveryService/backupToFederation.md
docs/core/FedimintWallet/WalletService/sendOnchain.md
docs/core/FedimintWallet/FederationService/listOperations.md
flake.lock
10 changes: 9 additions & 1 deletion docs/.vitepress/sidebar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,15 @@ const FedimintWalletSidebar = [
{
text: 'RecoveryService',
base: '/core/FedimintWallet/RecoveryService/',
items: [{ text: 'Docs TODO' }],
items: [
{ text: 'backupToFederation()', link: 'backupToFederation' },
{ text: 'hasPendingRecoveries()', link: 'hasPendingRecoveries' },
{
text: 'subscribeToRecoveryProgress()',
link: 'subscribeToRecoveryProgress',
},
{ text: 'waitForRecovery()', link: 'waitForRecovery' },
],
},
],
},
Expand Down
2 changes: 2 additions & 0 deletions docs/core/FedimintWallet/BalanceService/getBalance.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

Get the current balance of the wallet in milli-satoshis (MSats).

> **WARNING**: This function will throw an error if the wallet is currently recovering.

```ts twoslash
// @esModuleInterop
import { WalletDirector } from '@fedimint/core'
Expand Down
2 changes: 2 additions & 0 deletions docs/core/FedimintWallet/BalanceService/subscribeBalance.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

Subscribe to balance updates as they occur.

> **WARNING**: This function will throw an error if the wallet is currently recovering.

```ts twoslash
// @esModuleInterop
import { WalletDirector } from '@fedimint/core'
Expand Down
2 changes: 2 additions & 0 deletions docs/core/FedimintWallet/FederationService/getConfig.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

Access configuration details about a connected federation.

> **WARNING**: This function will throw an error if the wallet is currently recovering.

```ts twoslash
// @esModuleInterop
import { WalletDirector } from '@fedimint/core'
Expand Down
2 changes: 2 additions & 0 deletions docs/core/FedimintWallet/FederationService/getFederationId.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

Access the `federationId` of the connected Federation.

> **WARNING**: This function will throw an error if the wallet is currently recovering.

```ts twoslash
// @esModuleInterop
import { WalletDirector } from '@fedimint/core'
Expand Down
2 changes: 2 additions & 0 deletions docs/core/FedimintWallet/FederationService/getInviteCode.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

Access the invite code for the connected federation.

> **WARNING**: This function will throw an error if the wallet is currently recovering.

```ts twoslash
// @esModuleInterop
import { WalletDirector } from '@fedimint/core'
Expand Down
8 changes: 5 additions & 3 deletions docs/core/FedimintWallet/FederationService/getOperation.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

Get the transaction data using the operation id.

> **WARNING**: This function will throw an error if the wallet is currently recovering.

```ts twoslash
// @esModuleInterop
import { WalletDirector } from '@fedimint/core'
Expand All @@ -14,7 +16,7 @@ const wallet = await director.createWallet()

await wallet.open()

const operationId =
'3ff56b29cf014b9ff6c8b6b4aa78e02d3c429de7112bfaf42a876f6a797ddf8b'
const config = await wallet.federation.getOperation(operationId)
const operationId = // [!code focus]
'3ff56b29cf014b9ff6c8b6b4aa78e02d3c429de7112bfaf42a876f6a797ddf8b' // [!code focus]
const config = await wallet.federation.getOperation(operationId) // [!code focus]
```
14 changes: 8 additions & 6 deletions docs/core/FedimintWallet/FederationService/listOperations.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

Returns a paginated list of operations (transactions) from the federation. In case limit and lastseen not given, returns all the available operations.

> **WARNING**: This function will throw an error if the wallet is currently recovering.

```ts twoslash
// @esModuleInterop
import { WalletDirector } from '@fedimint/core'
Expand All @@ -15,10 +17,10 @@ const wallet = await director.createWallet()
await wallet.open()

const limit = 10
const lastseen = {
creation_time: { secs_since_epoch: 2323233, nanos_since_epoch: 93429234 },
operation_id:
'3ff56b29cf014b9ff6c8b6b4aa78e02d3c429de7112bfaf42a876f6a797ddf8b',
}
const operations = await wallet.federation.listOperations(limit, lastseen)
const lastseen = { // [!code focus]
creation_time: { secs_since_epoch: 2323233, nanos_since_epoch: 93429234 }, // [!code focus]
operation_id: // [!code focus]
'3ff56b29cf014b9ff6c8b6b4aa78e02d3c429de7112bfaf42a876f6a797ddf8b', // [!code focus]
} // [!code focus]
const operations = await wallet.federation.listOperations(limit, lastseen) // [!code focus]
```
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

Returns a paginated list of transactions from the federation. In case limit and lastseen not given, returns all the available transactions.

> **WARNING**: This function will throw an error if the wallet is currently recovering.

```ts twoslash
/**
* Represents wallet transaction record.
Expand Down
2 changes: 2 additions & 0 deletions docs/core/FedimintWallet/LightningService/createInvoice.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ You can use `subscribeLnReceive` to track the invoice status.

`waitForReceive` returns a `Promise` that resolves when the invoice succeeds or `timeoutMs` is reached.

> **WARNING**: This function will throw an error if the wallet is currently recovering.

```ts twoslash
// @esModuleInterop
import { WalletDirector } from '@fedimint/core'
Expand Down
4 changes: 4 additions & 0 deletions docs/core/FedimintWallet/LightningService/payInvoice.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

Attempts to pay an invoice. Returns a `Promise` that resolves when the payment succeeds or fails / times out.

> **WARNING**: This function will throw an error if the wallet is currently recovering.

```ts twoslash
// @esModuleInterop
import { WalletDirector } from '@fedimint/core'
Expand Down Expand Up @@ -32,6 +34,8 @@ You can use `subscribeLnPay` and `subscribeInternalPay` to track the payment sta

`subscribeInternalPay` can be used to track the internal payments status

> **WARNING**: This function will throw an error if the wallet is currently recovering.

```ts twoslash
// @esModuleInterop
import { WalletDirector } from '@fedimint/core'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

Gives count of ecash notes by denomination present in the wallet.

> **WARNING**: This function will throw an error if the wallet is currently recovering.

```ts twoslash
// @esModuleInterop
import { WalletDirector } from '@fedimint/core'
Expand All @@ -14,6 +16,6 @@ const wallet = await director.createWallet()

await wallet.open()

const notes = await wallet.mint.getNotesByDenomination()
const notes = await wallet.mint.getNotesByDenomination() // [!code focus]
console.log('Notes are: ', notes) // {1: 2, 2: 1, 8: 2}
```
2 changes: 2 additions & 0 deletions docs/core/FedimintWallet/MintService/parseNotes.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

Parses an ecash note string without redeeming it. Use [`redeemEcash()`](./redeemEcash) to redeem the notes.

> **WARNING**: This function will throw an error if the wallet is currently recovering.

```ts twoslash
// @esModuleInterop
import { WalletDirector } from '@fedimint/core'
Expand Down
2 changes: 2 additions & 0 deletions docs/core/FedimintWallet/MintService/redeemEcash.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

Redeem a set of ecash notes.

> **WARNING**: This function will throw an error if the wallet is currently recovering.

```ts twoslash
// @esModuleInterop
import { WalletDirector } from '@fedimint/core'
Expand Down
2 changes: 2 additions & 0 deletions docs/core/FedimintWallet/MintService/spendNotes.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

Generates ecash notes for spending.

> **WARNING**: This function will throw an error if the wallet is currently recovering.

```ts twoslash
// @esModuleInterop
import { WalletDirector } from '@fedimint/core'
Expand Down
45 changes: 45 additions & 0 deletions docs/core/FedimintWallet/RecoveryService/backupToFederation.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
# Backup to Federation

### `recovery.backupToFederation(metadata?: JSONValue)`

Backup the wallet state to the federation with optional metadata. You should call this function periodically to refresh the user's backups.

> **WARNING**: This function will throw an error if the wallet is currently recovering.

```ts twoslash
// @esModuleInterop
import { WalletDirector } from '@fedimint/core'
import { WasmWorkerTransport } from '@fedimint/transport-web'

const director = new WalletDirector(new WasmWorkerTransport())
const wallet = await director.createWallet()

await wallet.open()

// Backup without metadata
try {
await wallet.recovery.backupToFederation() // [!code focus]
console.log('Backup successful')
} catch (error) {
console.error('Failed to backup', error)
}

// Backup with metadata
try {
await wallet.recovery.backupToFederation({ // [!code focus]
timestamp: Date.now(), // [!code focus]
note: 'My backup', // [!code focus]
}) // [!code focus]
console.log('Backup with metadata successful')
} catch (error) {
console.error('Failed to backup', error)
}
```

## Parameters

- `metadata` (optional): A JSON value containing custom metadata to store with the backup. Defaults to an empty object if not provided.

## Returns

Returns a `Promise<void>` that resolves when the backup is complete.
31 changes: 31 additions & 0 deletions docs/core/FedimintWallet/RecoveryService/hasPendingRecoveries.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# Has Pending Recoveries

### `recovery.hasPendingRecoveries()`

Check if there are any pending recovery operations.

```ts twoslash
// @esModuleInterop
import { WalletDirector } from '@fedimint/core'
import { WasmWorkerTransport } from '@fedimint/transport-web'

const director = new WalletDirector(new WasmWorkerTransport())
const wallet = await director.createWallet()

await wallet.open()

try {
const hasPending = await wallet.recovery.hasPendingRecoveries() // [!code focus]
if (hasPending) {
console.log('Recovery operations in progress')
} else {
console.log('No pending recoveries')
}
} catch (error) {
console.error('Failed to check recovery status', error)
}
```

## Returns

Returns a `Promise<boolean>` that resolves to `true` if there are pending recoveries, `false` otherwise.
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# Subscribe to Recovery Progress

### `recovery.subscribeToRecoveryProgress(onSuccess, onError)`

Subscribe to recovery progress updates for all modules.

```ts twoslash
// @esModuleInterop
import { WalletDirector } from '@fedimint/core'
import { WasmWorkerTransport } from '@fedimint/transport-web'

const director = new WalletDirector(new WasmWorkerTransport())
const wallet = await director.createWallet()

await wallet.open()

const unsubscribe = wallet.recovery.subscribeToRecoveryProgress( // [!code focus]
(progress) => { // [!code focus]
console.log('Module:', progress.module_id) // [!code focus]
console.log('Progress:', progress.progress) // [!code focus]
}, // [!code focus]
(error) => { // [!code focus]
console.error('Recovery error:', error) // [!code focus]
}, // [!code focus]
) // [!code focus]

// Later, to stop listening for updates
unsubscribe()
```

## Parameters

- `onSuccess`: Callback function invoked with progress updates. Receives an object containing:
- `module_id`: The module identifier (number)
- `progress`: The progress data (JSONValue)
- `onError`: Callback function invoked when an error occurs. Receives an error string.

## Returns

Returns a function that can be called to unsubscribe from progress updates.
28 changes: 28 additions & 0 deletions docs/core/FedimintWallet/RecoveryService/waitForRecovery.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# Wait for Recovery

### `recovery.waitForRecovery()`

Wait for all pending recovery operations of a particular wallet to complete.

```ts twoslash
// @esModuleInterop
import { WalletDirector } from '@fedimint/core'
import { WasmWorkerTransport } from '@fedimint/transport-web'

const director = new WalletDirector(new WasmWorkerTransport())
const wallet = await director.createWallet()

await wallet.open()

try {
console.log('Waiting for recoveries to complete...')
await wallet.recovery.waitForRecovery() // [!code focus]
console.log('All recoveries completed')
} catch (error) {
console.error('Recovery failed', error)
}
```

## Returns

Returns a `Promise<void>` that resolves when all recovery operations are complete.
2 changes: 2 additions & 0 deletions docs/core/FedimintWallet/WalletService/generateAddress.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

Create an onchain address. Returns a `deposit_address` (string) and an `operation_id` (string).

> **WARNING**: This function will throw an error if the wallet is currently recovering.

```ts twoslash
// @esModuleInterop
import { WalletDirector } from '@fedimint/core'
Expand Down
2 changes: 2 additions & 0 deletions docs/core/FedimintWallet/WalletService/getWalletSummary.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

Gives wallet UTXO set

> **WARNING**: This function will throw an error if the wallet is currently recovering.

```ts twoslash
// @esModuleInterop
import { WalletDirector } from '@fedimint/core'
Expand Down
4 changes: 3 additions & 1 deletion docs/core/FedimintWallet/WalletService/sendOnchain.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

Attempts to send bitcoin to an onchain address.

> **WARNING**: This function will throw an error if the wallet is currently recovering.

```ts twoslash
// @esModuleInterop
import { WalletDirector } from '@fedimint/core'
Expand All @@ -17,7 +19,7 @@ await wallet.open()
const amount = 20 // amount in Sats // [!code focus]
const address = 'bc1q...' // [!code focus]

const { operation_id } = await wallet.wallet.sendOnchain(
const { operation_id } = await wallet.wallet.sendOnchain( // [!code focus]
amount, // [!code focus]
address, // [!code focus]
) // [!code focus]
Expand Down
4 changes: 4 additions & 0 deletions docs/core/FedimintWallet/joinFederation.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@

Attempts to join a federation.

::: info
If there is an existing backup stored with the federation associated with the user's root mnemonic, it will be automatically fetched and restored when you join the federation.
:::

```ts twoslash
// @esModuleInterop
import { WalletDirector } from '@fedimint/core'
Expand Down
Loading
Loading