@bsv/expo-wallet-toolbox 0.4.0 → 0.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +547 -0
- package/README.md +19 -1
- package/assets/sounds/vault-deposit.wav +0 -0
- package/assets/sounds/vault-withdraw.wav +0 -0
- package/core/amountFormatHelpers.ts +238 -34
- package/core/backup/RemoteSyncReader.ts +2 -5
- package/core/backup/codec.ts +2 -2
- package/core/backup/push.ts +1 -1
- package/core/config.tsx +16 -1
- package/core/contacts/contactActivity.ts +153 -0
- package/core/contacts/contactCache.ts +41 -0
- package/core/contacts/contactsStore.ts +183 -0
- package/core/context/VaultContext.tsx +8 -11
- package/core/context/WalletConnectionContext.tsx +137 -52
- package/core/context/WalletContext.tsx +464 -30
- package/core/demo/demoAssets.ts +60 -0
- package/core/demo/demoLedger.ts +240 -0
- package/core/demo/demoMandalaRuntime.ts +96 -0
- package/core/demo/demoMode.ts +38 -0
- package/core/demo/demoWallet.ts +25 -0
- package/core/demo/index.ts +26 -0
- package/core/demo/useDemo.ts +59 -0
- package/core/headers/OfflineFirstChaintracks.ts +52 -14
- package/core/headers/headerStore.ts +7 -10
- package/core/hooks/useConfirmationSound.ts +14 -8
- package/core/i18n/translations.tsx +4562 -986
- package/core/identity/contactLink.ts +36 -0
- package/core/identity/handleRegistry/client.ts +285 -0
- package/core/identity/handleRegistry/profileCert.ts +254 -0
- package/core/identity/handleRegistry/registration.ts +559 -0
- package/core/identity/handleRegistry/resolver.ts +247 -0
- package/core/identity/handleRegistry/rules.ts +104 -0
- package/core/index.ts +116 -15
- package/core/localpay/build.ts +674 -37
- package/core/localpay/codec.ts +68 -5
- package/core/localpay/pending.ts +240 -22
- package/core/localpay/pendingAborts.ts +5 -1
- package/core/localpay/settlementAck.ts +149 -0
- package/core/localpay/types.ts +14 -1
- package/core/localpay/verify.ts +118 -69
- package/core/mandala/abortGuard.ts +134 -0
- package/core/mandala/basketMigration.ts +166 -0
- package/core/mandala/bundle.ts +244 -0
- package/core/mandala/createRuntime.ts +2437 -0
- package/core/mandala/drain.ts +670 -0
- package/core/mandala/permissionModule.ts +642 -0
- package/core/mandala/resendTransfer.ts +175 -0
- package/core/mandala/runtime.ts +357 -0
- package/core/mandala/settlementStore.ts +412 -0
- package/core/mandala/types.ts +290 -0
- package/core/monitor/MonitorSupervisor.ts +121 -0
- package/core/monitor/TaskBackupPush.ts +1 -1
- package/core/monitor/TaskCreditInbox.ts +1 -1
- package/core/monitor/TaskDrainOutbox.ts +1 -1
- package/core/monitor/TaskSendOffline.ts +1 -1
- package/core/net/online.ts +49 -0
- package/core/numberFormat.ts +19 -0
- package/core/offline/cancelParked.ts +94 -1
- package/core/offline/payerHold.ts +152 -12
- package/core/offline/plan.ts +1 -1
- package/core/offline/tokenFrames.ts +197 -0
- package/core/parsePeerPayURI.ts +70 -17
- package/core/pay/rails/address.ts +51 -3
- package/core/pay/rails/handle.ts +88 -9
- package/core/pay/rails/index.ts +16 -6
- package/core/pay/rails/nearby.ts +114 -4
- package/core/pay/recordProof.ts +2 -6
- package/core/services/arcadeBroadcastProvider.ts +1 -4
- package/core/services/capWalletArgs.ts +8 -9
- package/core/services/exchangeRate.ts +1 -1
- package/core/services/externalOrigin.ts +42 -0
- package/core/services/vault/VaultKeyService.ts +912 -251
- package/core/services/vault/ceremony.ts +435 -367
- package/core/services/vault/ceremonyHost.ts +27 -21
- package/core/services/vault/devMock.ts +30 -7
- package/core/services/vault/driver.ts +95 -41
- package/core/services/vault/guard.ts +514 -56
- package/core/services/vault/hardwareLease.ts +22 -0
- package/core/services/vault/mockYubiKey.ts +258 -90
- package/core/services/vault/pivReset.ts +145 -0
- package/core/services/vault/r1comb.ts +976 -0
- package/core/services/vault/session.ts +93 -26
- package/core/services/vault/transfers.ts +2617 -747
- package/core/services/vault/types.ts +100 -43
- package/core/services/vault/vaultStore.ts +991 -74
- package/core/services/walletConnectionValidation.ts +293 -0
- package/core/services/walletServiceConfig.ts +31 -20
- package/core/storage/StorageExpoSQLite.ts +420 -87
- package/core/storage/dbImage.ts +48 -0
- package/core/storage/methods/findSql.ts +3 -54
- package/core/storage/methods/listActionsSql.ts +8 -5
- package/core/storage/methods/listOutputsSql.ts +9 -5
- package/core/storage/methods/offlineActions.ts +15 -0
- package/core/storage/methods/processOfflineActions.ts +265 -9
- package/core/storage/methods/reviewStatusSql.ts +7 -2
- package/core/storage/methods/walletBalanceSql.ts +16 -4
- package/core/storage/schema/createTables.ts +152 -0
- package/core/storage/sqlUpdateValue.ts +24 -0
- package/core/toolboxConfig.ts +182 -1
- package/core/toolboxTypes.ts +40 -0
- package/core/userAvatar.ts +79 -0
- package/core/walletMonitor.ts +8 -3
- package/core/walletRepair/runWalletCheck.ts +19 -2
- package/package.json +31 -30
- package/ui/activityFilter.ts +115 -0
- package/ui/components/QRScanner.tsx +1 -1
- package/ui/components/pay/AdmissionNotice.tsx +99 -0
- package/ui/components/pay/AssetPicker.tsx +184 -0
- package/ui/components/pay/AvailableBalance.tsx +33 -2
- package/ui/components/pay/HandleReceive.tsx +213 -50
- package/ui/components/pay/NearbyFlow.tsx +616 -69
- package/ui/components/pay/PayForm.tsx +73 -8
- package/ui/components/pay/PaymentSuccessOverlay.tsx +89 -8
- package/ui/components/pay/RecipientField.tsx +132 -73
- package/ui/components/pay/RequestHub.tsx +68 -8
- package/ui/components/pay/ResultBanner.tsx +41 -4
- package/ui/components/pay/StepBar.tsx +32 -0
- package/ui/components/pay/UniversalSend.tsx +1118 -86
- package/ui/components/pay/tokenSendCopy.ts +116 -0
- package/ui/components/pay/useRecipientInput.ts +36 -7
- package/ui/components/ui/PencilEditField.tsx +109 -0
- package/ui/components/ui/PermissionSheet.tsx +65 -4
- package/ui/components/ui/Sheet.tsx +9 -2
- package/ui/components/ui/SlideOverFromRight.tsx +86 -0
- package/ui/components/vault/EnrollWizard.tsx +1432 -488
- package/ui/components/vault/KeyChooser.tsx +96 -0
- package/ui/components/vault/VaultCeremonySheet.tsx +107 -43
- package/ui/components/vault/vaultErrorCopy.ts +145 -0
- package/ui/components/wallet/ActivityRow.tsx +283 -97
- package/ui/components/wallet/AmountInput.tsx +92 -28
- package/ui/components/wallet/AssetAmount.tsx +95 -0
- package/ui/components/wallet/AssetSwitcherDropdown.tsx +261 -0
- package/ui/components/wallet/ContactActivityList.tsx +149 -0
- package/ui/components/wallet/ContactSigil.tsx +49 -0
- package/ui/components/wallet/EditPictureSheet.tsx +99 -0
- package/ui/components/wallet/FitAmount.tsx +148 -0
- package/ui/components/wallet/IconPickerSheet.tsx +168 -0
- package/ui/components/wallet/IdentifierRow.tsx +69 -0
- package/ui/components/wallet/ImportFromBackupPrompt.tsx +35 -13
- package/ui/components/wallet/ProfileButton.tsx +62 -0
- package/ui/components/wallet/UserAvatar.tsx +85 -0
- package/ui/components/wallet/avatarIcons.ts +122 -0
- package/ui/components/wallet/tokenEviction.ts +65 -0
- package/ui/hooks/useContactsStore.ts +10 -0
- package/ui/hooks/useExportWalletData.ts +39 -0
- package/ui/hooks/useMandala.ts +320 -0
- package/ui/hooks/useOnline.ts +65 -20
- package/ui/hooks/useVaultBalance.ts +105 -7
- package/ui/hooks/useVaultCoverage.ts +52 -0
- package/ui/importDatabases.ts +7 -3
- package/ui/index.ts +75 -7
- package/ui/screens/ConnectionsScreen.tsx +46 -29
- package/ui/screens/ContactScreen.tsx +289 -0
- package/ui/screens/ContactsScreen.tsx +373 -0
- package/ui/screens/IdentifierScreen.tsx +234 -0
- package/ui/screens/NewContactScreen.tsx +362 -0
- package/ui/screens/PairScreen.tsx +12 -12
- package/ui/screens/PayScreen.tsx +145 -12
- package/ui/screens/ProfileScreen.tsx +783 -0
- package/ui/screens/SettingsScreen.tsx +18 -9
- package/ui/screens/TransactionDetailScreen.tsx +419 -0
- package/ui/screens/TrustScreen.tsx +1 -1
- package/ui/screens/VaultScreen.tsx +925 -171
- package/ui/screens/VaultTransferScreen.tsx +376 -123
- package/ui/screens/WalletCheckScreen.tsx +10 -1
- package/ui/screens/WalletConfigScreen.tsx +80 -16
- package/ui/screens/WalletHomeScreen.tsx +915 -139
- package/ui/screens/homeBadges.ts +9 -1
- package/ui/screens/tokenRowTitle.ts +68 -0
- package/ui/tokenFormat.ts +108 -0
- package/ui/tokenSeen.ts +75 -0
- package/ui/tokenStatus.ts +100 -0
- package/ui/txStatus.ts +43 -5
- package/assets/sounds/vault-close.wav +0 -0
- package/assets/sounds/vault-open.wav +0 -0
- package/core/services/vault/k1.ts +0 -75
- package/core/services/vault/sealing.ts +0 -84
- package/core/services/vault/vaultDerivation.ts +0 -152
- package/core/services/vault/vaultPassphrase.ts +0 -287
- package/ui/components/vault/PassphraseField.tsx +0 -306
- package/ui/components/vault/PhraseBackupSheet.tsx +0 -227
- package/ui/screens/VaultRecoverScreen.tsx +0 -226
|
@@ -360,6 +360,133 @@ export async function createTables(db: SQLiteDatabase): Promise<void> {
|
|
|
360
360
|
CREATE INDEX IF NOT EXISTS idx_offline_actions_seq ON offline_actions(seq);
|
|
361
361
|
CREATE INDEX IF NOT EXISTS idx_offline_actions_txid ON offline_actions(txid);
|
|
362
362
|
`)
|
|
363
|
+
|
|
364
|
+
// Contacts — local, userId-scoped naming of counterparty identity keys.
|
|
365
|
+
// `name` is the user's own label and is never overwritten by a background
|
|
366
|
+
// refresh; `cachedHandle`/`cachedAvatarUrl`/`cachedCertifier` mirror what
|
|
367
|
+
// resolveIdentity last saw and are read-only in the UI. @bsv/sdk's
|
|
368
|
+
// ContactsManager and @bsv/mandala's contactsStore were rejected for v1:
|
|
369
|
+
// each write there is a signed on-chain action.
|
|
370
|
+
await db.execAsync(`
|
|
371
|
+
CREATE TABLE IF NOT EXISTS contacts (
|
|
372
|
+
contactId INTEGER PRIMARY KEY AUTOINCREMENT,
|
|
373
|
+
created_at TEXT NOT NULL,
|
|
374
|
+
updated_at TEXT NOT NULL,
|
|
375
|
+
userId INTEGER NOT NULL,
|
|
376
|
+
identityKey TEXT NOT NULL,
|
|
377
|
+
name TEXT NOT NULL,
|
|
378
|
+
cachedHandle TEXT,
|
|
379
|
+
cachedAvatarUrl TEXT,
|
|
380
|
+
cachedCertifier TEXT,
|
|
381
|
+
source TEXT NOT NULL DEFAULT 'manual',
|
|
382
|
+
FOREIGN KEY (userId) REFERENCES users(userId)
|
|
383
|
+
);
|
|
384
|
+
CREATE UNIQUE INDEX IF NOT EXISTS idx_contacts_unique ON contacts(userId, identityKey);
|
|
385
|
+
CREATE INDEX IF NOT EXISTS idx_contacts_userId ON contacts(userId);
|
|
386
|
+
`)
|
|
387
|
+
|
|
388
|
+
await createMandalaSettlementTables(db)
|
|
389
|
+
}
|
|
390
|
+
|
|
391
|
+
/**
|
|
392
|
+
* The four Mandala settlement tables (offline-settlement spec §4.1).
|
|
393
|
+
*
|
|
394
|
+
* Additive only: nothing in `offline_actions`, `proven_tx_reqs` or the
|
|
395
|
+
* toolbox's own schema changes shape. `CREATE TABLE IF NOT EXISTS` is the whole
|
|
396
|
+
* migration — a device upgrading into this feature gets the tables empty on its
|
|
397
|
+
* next boot, and every row in them is re-derivable from frame bytes that are
|
|
398
|
+
* already durable elsewhere (FIX G), so there is nothing to backfill.
|
|
399
|
+
*
|
|
400
|
+
* Split into its own exported function so the settlement store's tests can
|
|
401
|
+
* stand the schema up without the rest of the wallet, and so a future migration
|
|
402
|
+
* runner has one named unit to call.
|
|
403
|
+
*/
|
|
404
|
+
export async function createMandalaSettlementTables(
|
|
405
|
+
db: Pick<SQLiteDatabase, 'execAsync' | 'getAllAsync'>
|
|
406
|
+
): Promise<void> {
|
|
407
|
+
// One row per token transaction this wallet has ever built, received, or
|
|
408
|
+
// forwarded evidence for — THE single owner of "what state is this token
|
|
409
|
+
// payment in" (spec §5). The `state` CHECK is deliberately the whole state
|
|
410
|
+
// machine: a state this file does not list is a bug that must fail at the
|
|
411
|
+
// write, not survive as an unreachable row nothing drains.
|
|
412
|
+
await db.execAsync(`
|
|
413
|
+
CREATE TABLE IF NOT EXISTS token_settlements (
|
|
414
|
+
txid TEXT PRIMARY KEY,
|
|
415
|
+
role TEXT NOT NULL CHECK (role IN ('sent','received')),
|
|
416
|
+
assetId TEXT NOT NULL,
|
|
417
|
+
state TEXT NOT NULL CHECK (state IN (
|
|
418
|
+
'built','parked','handed_over','held',
|
|
419
|
+
'submitting','admitted','broadcast','refused','orphaned')),
|
|
420
|
+
counterpartyKey TEXT,
|
|
421
|
+
amountBaseUnits INTEGER,
|
|
422
|
+
overlayUrl TEXT NOT NULL,
|
|
423
|
+
overlayIdentityKey TEXT NOT NULL,
|
|
424
|
+
admissionOutputsJson TEXT,
|
|
425
|
+
admissionSignatureHex TEXT,
|
|
426
|
+
refusedCode TEXT,
|
|
427
|
+
refusedPayloadHash TEXT,
|
|
428
|
+
poisonedByTxid TEXT,
|
|
429
|
+
reference TEXT,
|
|
430
|
+
createdAt TEXT NOT NULL,
|
|
431
|
+
updatedAt TEXT NOT NULL
|
|
432
|
+
);
|
|
433
|
+
CREATE INDEX IF NOT EXISTS idx_token_settlements_state ON token_settlements(state);
|
|
434
|
+
CREATE INDEX IF NOT EXISTS idx_token_settlements_role ON token_settlements(role);
|
|
435
|
+
CREATE INDEX IF NOT EXISTS idx_token_settlements_createdAt ON token_settlements(createdAt);
|
|
436
|
+
`)
|
|
437
|
+
|
|
438
|
+
// A device that created these tables before `reference` existed keeps them;
|
|
439
|
+
// CREATE TABLE IF NOT EXISTS cannot add the column, so the guarded ALTER does.
|
|
440
|
+
await ensureTokenSettlementColumns(db)
|
|
441
|
+
await db.execAsync(`CREATE INDEX IF NOT EXISTS idx_token_settlements_reference ON token_settlements(reference);`)
|
|
442
|
+
// Drives a contact's activity pane (core/contacts/contactActivity.ts):
|
|
443
|
+
// every token transfer with this counterparty, in one indexed lookup.
|
|
444
|
+
await db.execAsync(
|
|
445
|
+
`CREATE INDEX IF NOT EXISTS idx_token_settlements_counterpartyKey ON token_settlements(counterpartyKey);`
|
|
446
|
+
)
|
|
447
|
+
|
|
448
|
+
// Cached mirror of the AdmissionEntry values this device has SEEN. Purely a
|
|
449
|
+
// derivable cache (FIX G) — never a precondition for anything.
|
|
450
|
+
await db.execAsync(`
|
|
451
|
+
CREATE TABLE IF NOT EXISTS token_admissions (
|
|
452
|
+
txid TEXT PRIMARY KEY,
|
|
453
|
+
outputsToAdmitJson TEXT NOT NULL,
|
|
454
|
+
signatureHex TEXT NOT NULL,
|
|
455
|
+
signerKey TEXT NOT NULL,
|
|
456
|
+
source TEXT NOT NULL CHECK (source IN ('minted','bundle','submitted','fetched')),
|
|
457
|
+
obtainedAt TEXT NOT NULL
|
|
458
|
+
);
|
|
459
|
+
CREATE INDEX IF NOT EXISTS idx_token_admissions_signerKey ON token_admissions(signerKey);
|
|
460
|
+
`)
|
|
461
|
+
|
|
462
|
+
// Edge index for the recursive COVER walk, so coverage is a local SQL query
|
|
463
|
+
// rather than a re-parse of a whole BEEF on every pass. Token inputs only
|
|
464
|
+
// (FIX K): a plain BSV change input funding the fee is not a token ancestor.
|
|
465
|
+
await db.execAsync(`
|
|
466
|
+
CREATE TABLE IF NOT EXISTS token_admission_edges (
|
|
467
|
+
childTxid TEXT NOT NULL,
|
|
468
|
+
parentTxid TEXT NOT NULL,
|
|
469
|
+
parentVout INTEGER NOT NULL,
|
|
470
|
+
PRIMARY KEY (childTxid, parentTxid, parentVout)
|
|
471
|
+
);
|
|
472
|
+
CREATE INDEX IF NOT EXISTS idx_token_admission_edges_child ON token_admission_edges(childTxid);
|
|
473
|
+
CREATE INDEX IF NOT EXISTS idx_token_admission_edges_parent ON token_admission_edges(parentTxid);
|
|
474
|
+
`)
|
|
475
|
+
|
|
476
|
+
// Off-chain linkage payloads for UNADMITTED chain transactions: the exact
|
|
477
|
+
// bytes a downstream submitter needs to build the /submit body for a txid
|
|
478
|
+
// nobody has σ_I for yet. Carried verbatim hop by hop — this device can never
|
|
479
|
+
// decrypt one, only forward it.
|
|
480
|
+
await db.execAsync(`
|
|
481
|
+
CREATE TABLE IF NOT EXISTS token_linkage_payloads (
|
|
482
|
+
txid TEXT PRIMARY KEY,
|
|
483
|
+
payloadBytes BLOB NOT NULL,
|
|
484
|
+
overlayUrl TEXT NOT NULL,
|
|
485
|
+
overlayIdentityKey TEXT NOT NULL,
|
|
486
|
+
source TEXT NOT NULL CHECK (source IN ('minted','forwarded')),
|
|
487
|
+
createdAt TEXT NOT NULL
|
|
488
|
+
);
|
|
489
|
+
`)
|
|
363
490
|
}
|
|
364
491
|
|
|
365
492
|
/**
|
|
@@ -383,3 +510,28 @@ export async function ensureOfflineActionsColumns(db: {
|
|
|
383
510
|
if (!have.has(col.name)) await db.execAsync(col.ddl)
|
|
384
511
|
}
|
|
385
512
|
}
|
|
513
|
+
|
|
514
|
+
/**
|
|
515
|
+
* The same doctrine for `token_settlements`, which shipped before it had a
|
|
516
|
+
* `reference` column and cannot be re-created over live rows.
|
|
517
|
+
*
|
|
518
|
+
* A nullable column with no default: every existing row reads back
|
|
519
|
+
* `reference === undefined`, which the abort guard treats as "unknown
|
|
520
|
+
* reference" and therefore never blocks on. The wallet re-derives these rows
|
|
521
|
+
* every drain tick (FIX G) but only from frame bytes, which do not carry a
|
|
522
|
+
* wallet action reference — so the backfill is simply the next hand-over.
|
|
523
|
+
*/
|
|
524
|
+
const TOKEN_SETTLEMENT_COLUMNS: { name: string; ddl: string }[] = [
|
|
525
|
+
{ name: 'reference', ddl: 'ALTER TABLE token_settlements ADD COLUMN reference TEXT' }
|
|
526
|
+
]
|
|
527
|
+
|
|
528
|
+
export async function ensureTokenSettlementColumns(db: {
|
|
529
|
+
getAllAsync(sql: string, params: BindValue[]): Promise<unknown[]>
|
|
530
|
+
execAsync(sql: string): Promise<unknown>
|
|
531
|
+
}): Promise<void> {
|
|
532
|
+
const info = (await db.getAllAsync('PRAGMA table_info(token_settlements)', [])) as { name: string }[]
|
|
533
|
+
const have = new Set(info.map(c => c.name))
|
|
534
|
+
for (const col of TOKEN_SETTLEMENT_COLUMNS) {
|
|
535
|
+
if (!have.has(col.name)) await db.execAsync(col.ddl)
|
|
536
|
+
}
|
|
537
|
+
}
|
|
@@ -1,5 +1,29 @@
|
|
|
1
|
+
import { BLOB_COLUMNS } from './methods/findSql'
|
|
2
|
+
|
|
1
3
|
export type SqlBindResult = { omit: true } | { omit: false; value: unknown }
|
|
2
4
|
|
|
5
|
+
/** Every column the schema declares BLOB, by name; no two tables disagree about one. */
|
|
6
|
+
export const BYTE_COLUMNS: ReadonlySet<string> = new Set(Object.values(BLOB_COLUMNS).flat())
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* The bind for a byte column: bytes, or nothing.
|
|
10
|
+
*
|
|
11
|
+
* expo-sqlite binds only a `Uint8Array` as a BLOB. Anything else reaches the
|
|
12
|
+
* native layer as a primitive, which Android stringifies into TEXT and iOS
|
|
13
|
+
* refuses — how a JSON-rehydrated payload (an index-keyed object) became an
|
|
14
|
+
* unreadable `token_linkage_payloads` row on 2026-09-16. Refused here, while
|
|
15
|
+
* the column is still named, rather than stored in the wrong storage class.
|
|
16
|
+
*/
|
|
17
|
+
export function bytesForColumn(column: string, value: unknown): Uint8Array | undefined {
|
|
18
|
+
if (value === undefined || value === null) return undefined
|
|
19
|
+
if (value instanceof Uint8Array) return value
|
|
20
|
+
if (value instanceof ArrayBuffer) return new Uint8Array(value)
|
|
21
|
+
if (Array.isArray(value) && value.every(b => Number.isInteger(b))) return Uint8Array.from(value as number[])
|
|
22
|
+
throw new Error(
|
|
23
|
+
`${column} must be bytes (Uint8Array or number[]), got ${Array.isArray(value) ? 'a non-integer array' : typeof value}`
|
|
24
|
+
)
|
|
25
|
+
}
|
|
26
|
+
|
|
3
27
|
/** Map an update field to a SQL bind, or omit it from the SET clause. */
|
|
4
28
|
export function sqlBindValue(table: string, column: string, value: unknown): SqlBindResult {
|
|
5
29
|
if (value === undefined) {
|
package/core/toolboxConfig.ts
CHANGED
|
@@ -15,6 +15,34 @@ export interface ToolboxServiceConfig {
|
|
|
15
15
|
taalApiKey?: string
|
|
16
16
|
}
|
|
17
17
|
|
|
18
|
+
/**
|
|
19
|
+
* The three endpoints a Mandala stablecoin deployment is addressed by, for one
|
|
20
|
+
* chain (offline-settlement spec §12: endpoints live in the host's toolbox
|
|
21
|
+
* config, never in an env read inside this package).
|
|
22
|
+
*
|
|
23
|
+
* All three are required together, and that is the point: `overlayUrl` without
|
|
24
|
+
* `overlayIdentityKey` is an overlay whose σ_I nothing can verify, which is
|
|
25
|
+
* indistinguishable from no overlay at all — so a half-stated chain entry is
|
|
26
|
+
* treated as an unstated one (`getMandalaEndpoints` returns undefined) rather
|
|
27
|
+
* than producing a runtime that can submit but never prove.
|
|
28
|
+
*/
|
|
29
|
+
export interface MandalaEndpointConfig {
|
|
30
|
+
/** Origin of the issuer's overlay, no trailing slash — `${overlayUrl}/submit` is posted to. */
|
|
31
|
+
overlayUrl: string
|
|
32
|
+
/** 66-hex compressed key; the ONLY key an admission signature may come from. */
|
|
33
|
+
overlayIdentityKey: string
|
|
34
|
+
/** MessageBox host for the `'mandala-payments'` box (the handle rail). */
|
|
35
|
+
messageBoxUrl: string
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/** The paymail handle registry this build talks to, for one chain. */
|
|
39
|
+
export interface HandleRegistryConfig {
|
|
40
|
+
/** The domain handles live under here, e.g. `deggen.com`. Bare and lowercase. */
|
|
41
|
+
domain: string
|
|
42
|
+
/** Origin of the registry that serves that domain — no path, query or fragment. */
|
|
43
|
+
url: string
|
|
44
|
+
}
|
|
45
|
+
|
|
18
46
|
/**
|
|
19
47
|
* Runtime configuration supplied by the host app.
|
|
20
48
|
*
|
|
@@ -51,11 +79,43 @@ export interface ToolboxConfig {
|
|
|
51
79
|
backupUrl: string | null
|
|
52
80
|
/** Per-chain service endpoints and keys. Omitted chains use built-in defaults. */
|
|
53
81
|
services?: Partial<Record<AppChain, ToolboxServiceConfig>>
|
|
82
|
+
/**
|
|
83
|
+
* Per-chain Mandala stablecoin endpoints. There is deliberately NO default:
|
|
84
|
+
* an issuer's overlay and its identity key are deployment facts this package
|
|
85
|
+
* cannot guess, and guessing one would mean verifying admissions against the
|
|
86
|
+
* wrong key. A chain with no complete entry has no Mandala runtime
|
|
87
|
+
* (`useWallet().mandala` is undefined). Which chains carry an entry is the
|
|
88
|
+
* host's whole policy — e.g. testnet only while the issuer's overlay is a
|
|
89
|
+
* testnet deployment.
|
|
90
|
+
*/
|
|
91
|
+
mandala?: Partial<Record<AppChain, MandalaEndpointConfig>>
|
|
92
|
+
/**
|
|
93
|
+
* The paymail handle registry, per chain: the domain this build's handles
|
|
94
|
+
* live under, and the host that serves it. Both together or neither — a
|
|
95
|
+
* domain with no URL is a registry nothing can reach, and a URL with no
|
|
96
|
+
* domain is a host whose certificates nothing can be checked against.
|
|
97
|
+
*
|
|
98
|
+
* There is deliberately no default. A chain with no complete entry shows
|
|
99
|
+
* the existing "not available yet" copy in Profile and adds no registry tier
|
|
100
|
+
* to Pay's recipient search.
|
|
101
|
+
*/
|
|
102
|
+
handleRegistry?: Partial<Record<AppChain, HandleRegistryConfig>>
|
|
103
|
+
/**
|
|
104
|
+
* Release gate for the YubiKey vault (spec §0, D15). Default false: the home
|
|
105
|
+
* button and Settings row are hidden, the vault route shows "Not available
|
|
106
|
+
* yet", and no code path may enrol hardware or create a vault output. Turned
|
|
107
|
+
* on per build profile by the host (EXPO_PUBLIC_VAULT_ENABLED in eas.json),
|
|
108
|
+
* never read from process.env here.
|
|
109
|
+
*/
|
|
110
|
+
vaultEnabled?: boolean
|
|
54
111
|
}
|
|
55
112
|
|
|
56
113
|
interface ResolvedConfig {
|
|
57
114
|
backupUrl: string
|
|
58
115
|
services: Partial<Record<AppChain, ToolboxServiceConfig>>
|
|
116
|
+
mandala: Partial<Record<AppChain, MandalaEndpointConfig>>
|
|
117
|
+
handleRegistry: Partial<Record<AppChain, HandleRegistryConfig>>
|
|
118
|
+
vaultEnabled: boolean
|
|
59
119
|
}
|
|
60
120
|
|
|
61
121
|
let current: ResolvedConfig | null = null
|
|
@@ -98,7 +158,10 @@ export function configureToolbox(config: ToolboxConfig): void {
|
|
|
98
158
|
}
|
|
99
159
|
current = {
|
|
100
160
|
backupUrl: config.backupUrl == null ? '' : normalizeBackupUrl(config.backupUrl),
|
|
101
|
-
services: config.services ?? {}
|
|
161
|
+
services: config.services ?? {},
|
|
162
|
+
mandala: config.mandala ?? {},
|
|
163
|
+
handleRegistry: config.handleRegistry ?? {},
|
|
164
|
+
vaultEnabled: config.vaultEnabled === true
|
|
102
165
|
}
|
|
103
166
|
}
|
|
104
167
|
|
|
@@ -123,6 +186,124 @@ export function getServiceConfig(chain: AppChain): ToolboxServiceConfig {
|
|
|
123
186
|
return current.services[chain] ?? {}
|
|
124
187
|
}
|
|
125
188
|
|
|
189
|
+
const COMPRESSED_KEY = /^0[23][0-9a-fA-F]{64}$/
|
|
190
|
+
|
|
191
|
+
/**
|
|
192
|
+
* The Mandala endpoints for a chain, or undefined when this build has none.
|
|
193
|
+
*
|
|
194
|
+
* Deliberately NOT throwing when the toolbox is unconfigured, for the same
|
|
195
|
+
* reason `isVaultEnabled` does not: this is read while building the wallet and
|
|
196
|
+
* while rendering, and "unconfigured" must look like "Mandala off" rather than
|
|
197
|
+
* crash a wallet that never wanted stablecoins.
|
|
198
|
+
*
|
|
199
|
+
* A partial or malformed entry answers undefined rather than a half-usable
|
|
200
|
+
* object: an overlay URL with no verifiable identity key can submit but can
|
|
201
|
+
* never prove an admission, which is the one shape this feature must not have.
|
|
202
|
+
*/
|
|
203
|
+
export function getMandalaEndpoints(chain: AppChain): MandalaEndpointConfig | undefined {
|
|
204
|
+
const entry = current?.mandala[chain]
|
|
205
|
+
if (!entry) return undefined
|
|
206
|
+
const overlayUrl = entry.overlayUrl?.trim().replace(/\/+$/, '') ?? ''
|
|
207
|
+
const overlayIdentityKey = entry.overlayIdentityKey?.trim() ?? ''
|
|
208
|
+
const messageBoxUrl = entry.messageBoxUrl?.trim().replace(/\/+$/, '') ?? ''
|
|
209
|
+
if (overlayUrl === '' || messageBoxUrl === '') return undefined
|
|
210
|
+
if (!COMPRESSED_KEY.test(overlayIdentityKey)) return undefined
|
|
211
|
+
return { overlayUrl, overlayIdentityKey, messageBoxUrl }
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
/**
|
|
215
|
+
* The same rule as `DOMAIN_FORMAT` in `identity/handleRegistry/rules.ts`, which
|
|
216
|
+
* backs the `looksLikeDomain` the resolver and `parsePaymail` apply to the same
|
|
217
|
+
* strings. Restated rather than imported so this module stays a leaf and does
|
|
218
|
+
* not depend on a feature directory — change both together, because a domain
|
|
219
|
+
* this accepts and that one rejects is a configured registry nothing resolves.
|
|
220
|
+
*/
|
|
221
|
+
const REGISTRY_DOMAIN = /^[a-z0-9]([a-z0-9-]{0,61}[a-z0-9])?(\.[a-z0-9]([a-z0-9-]{0,61}[a-z0-9])?)+$/
|
|
222
|
+
/**
|
|
223
|
+
* Hosts a development build may reach over plain http: the simulator's own
|
|
224
|
+
* machine, the Android emulator's alias for it, and RFC 1918 space. Everything
|
|
225
|
+
* else must be https — which key owns a handle is precisely what a reader on
|
|
226
|
+
* the path would want to change.
|
|
227
|
+
*/
|
|
228
|
+
const PRIVATE_HOST =
|
|
229
|
+
/^(localhost|127\.0\.0\.1|10\.\d{1,3}\.\d{1,3}\.\d{1,3}|192\.168\.\d{1,3}\.\d{1,3}|172\.(1[6-9]|2\d|3[01])\.\d{1,3}\.\d{1,3})$/
|
|
230
|
+
|
|
231
|
+
/**
|
|
232
|
+
* The handle registry for a chain, or undefined when this build has none.
|
|
233
|
+
*
|
|
234
|
+
* Same fail-closed posture as `getMandalaEndpoints`: never throws, and a
|
|
235
|
+
* partial or malformed entry answers undefined rather than a half-usable
|
|
236
|
+
* object. `10.0.2.2` — the Android emulator's route to its host — falls out of
|
|
237
|
+
* the RFC 1918 branch and needs no case of its own.
|
|
238
|
+
*
|
|
239
|
+
* `url` must be a bare origin, for the reason `normalizeBackupUrl` says it
|
|
240
|
+
* above: every route is built by appending to it (`${url}/api/handle/dee`), so
|
|
241
|
+
* a configured `https://host/?x=1` addresses neither the host's registry nor
|
|
242
|
+
* anything else — exactly the half-usable entry this getter exists to refuse.
|
|
243
|
+
*/
|
|
244
|
+
export function getHandleRegistryConfig(chain: AppChain): HandleRegistryConfig | undefined {
|
|
245
|
+
const entry = current?.handleRegistry[chain]
|
|
246
|
+
if (!entry) return undefined
|
|
247
|
+
const domain = entry.domain?.trim().toLowerCase() ?? ''
|
|
248
|
+
const url = entry.url?.trim().replace(/\/+$/, '') ?? ''
|
|
249
|
+
if (!REGISTRY_DOMAIN.test(domain) || url === '') return undefined
|
|
250
|
+
let parsed: URL
|
|
251
|
+
try {
|
|
252
|
+
parsed = new URL(url)
|
|
253
|
+
} catch {
|
|
254
|
+
return undefined
|
|
255
|
+
}
|
|
256
|
+
if (parsed.search !== '' || parsed.hash !== '') return undefined
|
|
257
|
+
if (parsed.pathname !== '' && parsed.pathname !== '/') return undefined
|
|
258
|
+
if (parsed.protocol === 'https:') return { domain, url }
|
|
259
|
+
if (parsed.protocol === 'http:' && PRIVATE_HOST.test(parsed.hostname)) return { domain, url }
|
|
260
|
+
return undefined
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
/**
|
|
264
|
+
* Whether Mandala stablecoins are available on this network.
|
|
265
|
+
*
|
|
266
|
+
* Exactly the chains the host stated complete endpoints for — nothing else
|
|
267
|
+
* gates it. (v1 hardcoded mainnet on top of that, ux §2; since 2026-09-15 the
|
|
268
|
+
* host's `mandala` map is the whole policy, so a testnet-only rollout is a
|
|
269
|
+
* config choice, not a code change.) Chain is a parameter, not a module read,
|
|
270
|
+
* for the same reason `isVaultAvailable`'s is: screens must re-render when the
|
|
271
|
+
* user switches network.
|
|
272
|
+
*/
|
|
273
|
+
export function isMandalaAvailable(chain: AppChain): boolean {
|
|
274
|
+
return getMandalaEndpoints(chain) !== undefined
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
/**
|
|
278
|
+
* Whether this build may enrol vault hardware or create vault outputs.
|
|
279
|
+
*
|
|
280
|
+
* Deliberately NOT throwing when unconfigured: this is read while rendering
|
|
281
|
+
* the home screen, and "unconfigured" must look like "vault off", not crash.
|
|
282
|
+
*/
|
|
283
|
+
export function isVaultEnabled(): boolean {
|
|
284
|
+
return current?.vaultEnabled ?? false
|
|
285
|
+
}
|
|
286
|
+
|
|
287
|
+
/**
|
|
288
|
+
* Whether the vault may be used on this network.
|
|
289
|
+
*
|
|
290
|
+
* Vault is mainnet-only by product decision (2026-09-12): there is no reason to
|
|
291
|
+
* hold different hardware keys per network, and high-value storage is
|
|
292
|
+
* meaningless on a chain whose coins are worthless. Keeping it off testnet also
|
|
293
|
+
* removes a fund-loss path — the enrollment wizard's reset offer reads enrolled
|
|
294
|
+
* serials from one wallet+chain namespace, but a YubiKey is physical and shared
|
|
295
|
+
* across all of them, so a testnet wizard could offer to factory-reset a live
|
|
296
|
+
* mainnet signer.
|
|
297
|
+
*
|
|
298
|
+
* Chain is a parameter, not a module read: screens must re-render when the user
|
|
299
|
+
* switches network, and `selectedNetwork` from the wallet context is what makes
|
|
300
|
+
* that reactive. Keeping it a parameter also keeps this module a leaf — it must
|
|
301
|
+
* never import `vaultStore`.
|
|
302
|
+
*/
|
|
303
|
+
export function isVaultAvailable(chain: AppChain): boolean {
|
|
304
|
+
return isVaultEnabled() && chain === 'main'
|
|
305
|
+
}
|
|
306
|
+
|
|
126
307
|
/** Test-only: drop the installed configuration. */
|
|
127
308
|
export function resetToolboxConfig(): void {
|
|
128
309
|
current = null
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Flat aliases for @bsv/wallet-toolbox-mobile types that the package exports
|
|
3
|
+
* only under its `sdk` namespace. Since 2.13 the toolbox ships as one bundle
|
|
4
|
+
* whose exports map exposes just the package root, so the former
|
|
5
|
+
* `out/src/...` deep imports no longer resolve.
|
|
6
|
+
*/
|
|
7
|
+
import type { sdk } from '@bsv/wallet-toolbox-mobile'
|
|
8
|
+
|
|
9
|
+
export type AuthId = sdk.AuthId
|
|
10
|
+
export type BsvExchangeRate = sdk.BsvExchangeRate
|
|
11
|
+
export type FindCertificateFieldsArgs = sdk.FindCertificateFieldsArgs
|
|
12
|
+
export type FindCertificatesArgs = sdk.FindCertificatesArgs
|
|
13
|
+
export type FindCommissionsArgs = sdk.FindCommissionsArgs
|
|
14
|
+
export type FindForUserSincePagedArgs = sdk.FindForUserSincePagedArgs
|
|
15
|
+
export type FindMonitorEventsArgs = sdk.FindMonitorEventsArgs
|
|
16
|
+
export type FindOutputBasketsArgs = sdk.FindOutputBasketsArgs
|
|
17
|
+
export type FindOutputTagMapsArgs = sdk.FindOutputTagMapsArgs
|
|
18
|
+
export type FindOutputTagsArgs = sdk.FindOutputTagsArgs
|
|
19
|
+
export type FindOutputsArgs = sdk.FindOutputsArgs
|
|
20
|
+
export type FindProvenTxReqsArgs = sdk.FindProvenTxReqsArgs
|
|
21
|
+
export type FindProvenTxsArgs = sdk.FindProvenTxsArgs
|
|
22
|
+
export type FindSyncStatesArgs = sdk.FindSyncStatesArgs
|
|
23
|
+
export type FindTransactionsArgs = sdk.FindTransactionsArgs
|
|
24
|
+
export type FindTxLabelMapsArgs = sdk.FindTxLabelMapsArgs
|
|
25
|
+
export type FindTxLabelsArgs = sdk.FindTxLabelsArgs
|
|
26
|
+
export type FindUsersArgs = sdk.FindUsersArgs
|
|
27
|
+
export type PostBeefResult = sdk.PostBeefResult
|
|
28
|
+
export type PostTxResultForTxid = sdk.PostTxResultForTxid
|
|
29
|
+
export type ProcessSyncChunkResult = sdk.ProcessSyncChunkResult
|
|
30
|
+
export type ProvenOrRawTx = sdk.ProvenOrRawTx
|
|
31
|
+
export type ProvenTxReqStatus = sdk.ProvenTxReqStatus
|
|
32
|
+
export type PurgeParams = sdk.PurgeParams
|
|
33
|
+
export type PurgeResults = sdk.PurgeResults
|
|
34
|
+
export type RequestSyncChunkArgs = sdk.RequestSyncChunkArgs
|
|
35
|
+
export type StorageProcessActionArgs = sdk.StorageProcessActionArgs
|
|
36
|
+
export type StorageProcessActionResults = sdk.StorageProcessActionResults
|
|
37
|
+
export type SyncChunk = sdk.SyncChunk
|
|
38
|
+
export type TrxToken = sdk.TrxToken
|
|
39
|
+
export type UpdateProvenTxReqWithNewProvenTxArgs = sdk.UpdateProvenTxReqWithNewProvenTxArgs
|
|
40
|
+
export type WalletServicesOptions = sdk.WalletServicesOptions
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The picture this wallet's own user wears.
|
|
3
|
+
*
|
|
4
|
+
* One stored choice, read by every surface that draws "you" — the home
|
|
5
|
+
* button, the profile hero — so picking an icon once changes all of them.
|
|
6
|
+
*
|
|
7
|
+
* Kept out of `WalletSettings`: that type belongs to
|
|
8
|
+
* `@bsv/wallet-toolbox-mobile` and is not ours to extend. AsyncStorage
|
|
9
|
+
* instead, loaded once at startup, exactly like `core/numberFormat.ts`.
|
|
10
|
+
*
|
|
11
|
+
* Stored as `family/name` rather than a component so nothing here depends on
|
|
12
|
+
* the icon package, and an unknown value from a newer build degrades to the
|
|
13
|
+
* default disc instead of crashing.
|
|
14
|
+
*/
|
|
15
|
+
import { useSyncExternalStore } from 'react'
|
|
16
|
+
import AsyncStorage from '@react-native-async-storage/async-storage'
|
|
17
|
+
|
|
18
|
+
export type AvatarIconFamily = 'ionicons' | 'material-community'
|
|
19
|
+
|
|
20
|
+
export interface AvatarIcon {
|
|
21
|
+
family: AvatarIconFamily
|
|
22
|
+
name: string
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
const STORAGE_KEY = 'wallet_user_avatar_icon'
|
|
26
|
+
|
|
27
|
+
const listeners = new Set<() => void>()
|
|
28
|
+
let icon: AvatarIcon | null = null
|
|
29
|
+
|
|
30
|
+
/** The chosen icon, or `null` for the default profile disc. */
|
|
31
|
+
export function getUserAvatarIcon(): AvatarIcon | null {
|
|
32
|
+
return icon
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export function setUserAvatarIcon(next: AvatarIcon | null): void {
|
|
36
|
+
if (icon?.family === next?.family && icon?.name === next?.name) return
|
|
37
|
+
icon = next
|
|
38
|
+
listeners.forEach(l => l())
|
|
39
|
+
// Fire-and-forget: the choice is already live in memory, and a failed write
|
|
40
|
+
// costs the next launch's avatar, never the one on screen now.
|
|
41
|
+
if (next) void AsyncStorage.setItem(STORAGE_KEY, `${next.family}/${next.name}`).catch(() => {})
|
|
42
|
+
else void AsyncStorage.removeItem(STORAGE_KEY).catch(() => {})
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
export function subscribeUserAvatar(listener: () => void): () => void {
|
|
46
|
+
listeners.add(listener)
|
|
47
|
+
return () => {
|
|
48
|
+
listeners.delete(listener)
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
function parse(stored: string | null): AvatarIcon | null {
|
|
53
|
+
if (!stored) return null
|
|
54
|
+
const at = stored.indexOf('/')
|
|
55
|
+
if (at < 0) return null
|
|
56
|
+
const family = stored.slice(0, at)
|
|
57
|
+
const name = stored.slice(at + 1)
|
|
58
|
+
if (!name) return null
|
|
59
|
+
if (family !== 'ionicons' && family !== 'material-community') return null
|
|
60
|
+
return { family, name }
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
/** Restore the stored choice. Call once at startup; safe to call twice. */
|
|
64
|
+
export async function loadUserAvatarIcon(): Promise<void> {
|
|
65
|
+
try {
|
|
66
|
+
const next = parse(await AsyncStorage.getItem(STORAGE_KEY))
|
|
67
|
+
if (next && (next.family !== icon?.family || next.name !== icon?.name)) {
|
|
68
|
+
icon = next
|
|
69
|
+
listeners.forEach(l => l())
|
|
70
|
+
}
|
|
71
|
+
} catch {
|
|
72
|
+
// Keep the default disc; an unreadable preference is not worth surfacing.
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
/** Re-renders the caller whenever the choice changes. */
|
|
77
|
+
export function useUserAvatarIcon(): AvatarIcon | null {
|
|
78
|
+
return useSyncExternalStore(subscribeUserAvatar, getUserAvatarIcon, () => null)
|
|
79
|
+
}
|
package/core/walletMonitor.ts
CHANGED
|
@@ -59,9 +59,14 @@ export function createWalletMonitorOptions(
|
|
|
59
59
|
/**
|
|
60
60
|
* Construct a Monitor and await `ready` so `_init` registers
|
|
61
61
|
* `subscribeReorgs` / `subscribeHeaders` on `chaintracksWithEvents`.
|
|
62
|
-
* Subscribe failures must not kill the rest of the task loop
|
|
63
|
-
*
|
|
64
|
-
*
|
|
62
|
+
* Subscribe failures must not kill the rest of the task loop. `Monitor.runOnce`
|
|
63
|
+
* retries `ready` on every pass (best effort since toolbox 2.14; 2.13 let a
|
|
64
|
+
* rejection stop every task), so OfflineFirstChaintracks answers `getChain`
|
|
65
|
+
* locally and degrades an unsupported subscription (the HTTP
|
|
66
|
+
* ChaintracksServiceClient throws "Method not implemented") to an inert one,
|
|
67
|
+
* and `ready` settles once instead of failing and retrying each tick.
|
|
68
|
+
* TaskReviewProvenTxs is the backup audit in that case. The warning below is
|
|
69
|
+
* left for a chaintracks that rejects anyway.
|
|
65
70
|
*/
|
|
66
71
|
export async function createWalletMonitor(
|
|
67
72
|
options: ReturnType<typeof Monitor.createDefaultWalletMonitorOptions>
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
* Ordered Check-my-wallet repair steps.
|
|
3
3
|
*
|
|
4
4
|
* Records first so phantom spendable outputs do not poison later sends.
|
|
5
|
-
* freedCoins = reviewSpendable.released + releaseStuck.released + reviewStatus.restoredInputs
|
|
5
|
+
* freedCoins = reviewSpendable.released + releaseStuck.released + reviewStatus.restoredInputs + reviewTokens.removed
|
|
6
6
|
*
|
|
7
7
|
* A port throw marks that step error; later steps still run.
|
|
8
8
|
*/
|
|
@@ -10,6 +10,7 @@
|
|
|
10
10
|
export type WalletCheckStepId =
|
|
11
11
|
| 'online'
|
|
12
12
|
| 'records'
|
|
13
|
+
| 'tokens'
|
|
13
14
|
| 'coins'
|
|
14
15
|
| 'proofs'
|
|
15
16
|
| 'missed_payments'
|
|
@@ -48,6 +49,13 @@ export interface WalletCheckPorts {
|
|
|
48
49
|
/** Whether the recovery phrase was written down or the shares printed. */
|
|
49
50
|
checkPhraseBackup: () => Promise<{ backedUp: boolean }>
|
|
50
51
|
reviewSpendable: () => Promise<{ released: number; recovered: number }>
|
|
52
|
+
/**
|
|
53
|
+
* Token settlement rows and held coins, checked against the issuer's overlay.
|
|
54
|
+
* `removed` = transactions the overlay refused, now failed locally; `unattested`
|
|
55
|
+
* = rows/coins the overlay has no record of, reported and left alone. Throws
|
|
56
|
+
* when the overlay cannot be reached.
|
|
57
|
+
*/
|
|
58
|
+
reviewTokens: () => Promise<{ settled: number; removed: number; unattested: number }>
|
|
51
59
|
checkProofs: () => Promise<{ repaired: number }>
|
|
52
60
|
reviewStatus: () => Promise<{ failedTxs: number; restoredInputs: number }>
|
|
53
61
|
releaseStuck: () => Promise<{ released: number }>
|
|
@@ -144,6 +152,14 @@ export async function runWalletCheck(
|
|
|
144
152
|
})
|
|
145
153
|
record('records', records, () => ((records as { ok?: boolean }).ok === true ? 'ok' : 'error'))
|
|
146
154
|
|
|
155
|
+
onStep('tokens')
|
|
156
|
+
const tokens = await guard(skips, 'tokens', { settled: 0, removed: 0, unattested: 0 }, () =>
|
|
157
|
+
settle(() => ports.reviewTokens(), { settled: 0, removed: 0, unattested: 0 })
|
|
158
|
+
)
|
|
159
|
+
record('tokens', tokens, () =>
|
|
160
|
+
!(tokens as { ok?: boolean }).ok ? 'error' : tokens.value.unattested > 0 ? 'attention' : 'ok'
|
|
161
|
+
)
|
|
162
|
+
|
|
147
163
|
onStep('proofs')
|
|
148
164
|
const proofs = await guard(skips, 'proofs', { repaired: 0 }, () =>
|
|
149
165
|
settle(() => ports.checkProofs(), { repaired: 0 })
|
|
@@ -185,7 +201,8 @@ export async function runWalletCheck(
|
|
|
185
201
|
record('coins', spendable, () => ((spendable as { ok?: boolean }).ok === true ? 'ok' : 'error'))
|
|
186
202
|
|
|
187
203
|
return {
|
|
188
|
-
freedCoins:
|
|
204
|
+
freedCoins:
|
|
205
|
+
spendable.value.released + records.value.stuckReleased + records.value.restoredInputs + tokens.value.removed,
|
|
189
206
|
recoveredPayments: missed.value.accepted + missed.value.imported,
|
|
190
207
|
repairedProofs: proofs.value.repaired,
|
|
191
208
|
steps,
|