@bsv/expo-wallet-toolbox 0.3.1 → 0.5.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.
Files changed (119) hide show
  1. package/CHANGELOG.md +311 -0
  2. package/README.md +52 -1
  3. package/assets/sounds/vault-deposit.wav +0 -0
  4. package/assets/sounds/vault-withdraw.wav +0 -0
  5. package/core/config.tsx +21 -18
  6. package/core/context/VaultContext.tsx +8 -11
  7. package/core/context/WalletConnectionContext.tsx +137 -52
  8. package/core/context/WalletContext.tsx +413 -23
  9. package/core/hooks/useConfirmationSound.ts +14 -8
  10. package/core/i18n/translations.tsx +3368 -952
  11. package/core/index.ts +107 -14
  12. package/core/localpay/build.ts +674 -37
  13. package/core/localpay/codec.ts +68 -5
  14. package/core/localpay/pending.ts +240 -22
  15. package/core/localpay/settlementAck.ts +149 -0
  16. package/core/localpay/types.ts +14 -1
  17. package/core/localpay/verify.ts +118 -69
  18. package/core/mandala/abortGuard.ts +134 -0
  19. package/core/mandala/basketMigration.ts +166 -0
  20. package/core/mandala/bundle.ts +244 -0
  21. package/core/mandala/createRuntime.ts +2437 -0
  22. package/core/mandala/drain.ts +670 -0
  23. package/core/mandala/permissionModule.ts +642 -0
  24. package/core/mandala/resendTransfer.ts +175 -0
  25. package/core/mandala/runtime.ts +357 -0
  26. package/core/mandala/settlementStore.ts +412 -0
  27. package/core/mandala/types.ts +290 -0
  28. package/core/offline/cancelParked.ts +94 -1
  29. package/core/offline/payerHold.ts +152 -12
  30. package/core/offline/tokenFrames.ts +197 -0
  31. package/core/parsePeerPayURI.ts +70 -17
  32. package/core/pay/rails/address.ts +51 -3
  33. package/core/pay/rails/handle.ts +88 -9
  34. package/core/pay/rails/index.ts +16 -6
  35. package/core/pay/rails/nearby.ts +114 -4
  36. package/core/services/capWalletArgs.ts +8 -9
  37. package/core/services/externalOrigin.ts +39 -0
  38. package/core/services/vault/VaultKeyService.ts +912 -251
  39. package/core/services/vault/ceremony.ts +435 -367
  40. package/core/services/vault/ceremonyHost.ts +27 -21
  41. package/core/services/vault/devMock.ts +30 -7
  42. package/core/services/vault/driver.ts +95 -41
  43. package/core/services/vault/guard.ts +514 -56
  44. package/core/services/vault/hardwareLease.ts +22 -0
  45. package/core/services/vault/mockYubiKey.ts +258 -90
  46. package/core/services/vault/pivReset.ts +145 -0
  47. package/core/services/vault/r1comb.ts +976 -0
  48. package/core/services/vault/session.ts +93 -26
  49. package/core/services/vault/transfers.ts +2617 -747
  50. package/core/services/vault/types.ts +100 -43
  51. package/core/services/vault/vaultStore.ts +991 -74
  52. package/core/services/walletConnectionValidation.ts +293 -0
  53. package/core/services/walletServiceConfig.ts +19 -24
  54. package/core/storage/StorageExpoSQLite.ts +382 -56
  55. package/core/storage/dbImage.ts +48 -0
  56. package/core/storage/methods/findSql.ts +0 -54
  57. package/core/storage/methods/listOutputsSql.ts +7 -3
  58. package/core/storage/methods/offlineActions.ts +15 -0
  59. package/core/storage/methods/processOfflineActions.ts +263 -6
  60. package/core/storage/methods/walletBalanceSql.ts +16 -4
  61. package/core/storage/schema/createTables.ts +123 -0
  62. package/core/storage/sqlUpdateValue.ts +24 -0
  63. package/core/toolboxConfig.ts +240 -0
  64. package/core/walletRepair/runWalletCheck.ts +19 -2
  65. package/package.json +25 -24
  66. package/ui/components/QRScanner.tsx +1 -1
  67. package/ui/components/pay/AdmissionNotice.tsx +99 -0
  68. package/ui/components/pay/AssetPicker.tsx +184 -0
  69. package/ui/components/pay/AvailableBalance.tsx +33 -2
  70. package/ui/components/pay/HandleReceive.tsx +213 -50
  71. package/ui/components/pay/NearbyFlow.tsx +616 -69
  72. package/ui/components/pay/PayForm.tsx +73 -8
  73. package/ui/components/pay/PaymentSuccessOverlay.tsx +43 -2
  74. package/ui/components/pay/RecipientField.tsx +49 -4
  75. package/ui/components/pay/RequestHub.tsx +68 -8
  76. package/ui/components/pay/ResultBanner.tsx +41 -4
  77. package/ui/components/pay/UniversalSend.tsx +534 -30
  78. package/ui/components/pay/tokenSendCopy.ts +116 -0
  79. package/ui/components/pay/useRecipientInput.ts +36 -7
  80. package/ui/components/ui/PermissionSheet.tsx +65 -4
  81. package/ui/components/ui/Sheet.tsx +9 -2
  82. package/ui/components/vault/EnrollWizard.tsx +1432 -488
  83. package/ui/components/vault/KeyChooser.tsx +96 -0
  84. package/ui/components/vault/VaultCeremonySheet.tsx +107 -43
  85. package/ui/components/vault/vaultErrorCopy.ts +145 -0
  86. package/ui/components/wallet/ActivityRow.tsx +101 -17
  87. package/ui/components/wallet/AmountInput.tsx +77 -25
  88. package/ui/components/wallet/AssetAmount.tsx +95 -0
  89. package/ui/components/wallet/AssetSwitcherDropdown.tsx +261 -0
  90. package/ui/components/wallet/tokenEviction.ts +65 -0
  91. package/ui/hooks/useExportWalletData.ts +39 -0
  92. package/ui/hooks/useMandala.ts +303 -0
  93. package/ui/hooks/useVaultBalance.ts +105 -7
  94. package/ui/hooks/useVaultCoverage.ts +52 -0
  95. package/ui/importDatabases.ts +7 -3
  96. package/ui/index.ts +50 -7
  97. package/ui/screens/ConnectionsScreen.tsx +46 -29
  98. package/ui/screens/PairScreen.tsx +12 -12
  99. package/ui/screens/PayScreen.tsx +130 -10
  100. package/ui/screens/SettingsScreen.tsx +18 -9
  101. package/ui/screens/VaultScreen.tsx +925 -171
  102. package/ui/screens/VaultTransferScreen.tsx +376 -123
  103. package/ui/screens/WalletCheckScreen.tsx +10 -1
  104. package/ui/screens/WalletConfigScreen.tsx +42 -20
  105. package/ui/screens/WalletHomeScreen.tsx +417 -86
  106. package/ui/screens/homeBadges.ts +9 -1
  107. package/ui/screens/tokenRowTitle.ts +68 -0
  108. package/ui/tokenFormat.ts +108 -0
  109. package/ui/tokenSeen.ts +75 -0
  110. package/ui/tokenStatus.ts +79 -0
  111. package/assets/sounds/vault-close.wav +0 -0
  112. package/assets/sounds/vault-open.wav +0 -0
  113. package/core/services/vault/k1.ts +0 -75
  114. package/core/services/vault/sealing.ts +0 -84
  115. package/core/services/vault/vaultDerivation.ts +0 -152
  116. package/core/services/vault/vaultPassphrase.ts +0 -287
  117. package/ui/components/vault/PassphraseField.tsx +0 -306
  118. package/ui/components/vault/PhraseBackupSheet.tsx +0 -227
  119. package/ui/screens/VaultRecoverScreen.tsx +0 -226
@@ -106,6 +106,26 @@ function loadQuietEventSourceClass(): EventSourceCtor {
106
106
  return quietEventSourceClass
107
107
  }
108
108
 
109
+ /**
110
+ * `MandalaTokenModuleDeps.resolveAssetMetadata`, over the lib's own registry
111
+ * lookup (`@bsv/mandala`'s `resolveAssetMetadata` — overlay lookup,
112
+ * SPV-verified genesis, memoized). Only ever affects the display (name AND,
113
+ * per adversarial-review finding 4, decimal formatting) in a permission
114
+ * prompt, never a decision to prompt or to grant, so a failure is null and
115
+ * the prompt falls back to the raw assetId in base units — including on a
116
+ * build where `configureMandala` has not run, where the lib throws rather
117
+ * than pretending the asset has no name.
118
+ */
119
+ async function resolveMandalaAssetMetadata(assetId: string): Promise<MandalaAssetMetadata | null> {
120
+ try {
121
+ const meta = await resolveAssetMetadata(assetId)
122
+ if (!meta) return null
123
+ return { label: meta.label, ticker: meta.ticker, decimals: meta.decimals }
124
+ } catch {
125
+ return null
126
+ }
127
+ }
128
+
109
129
  const DEFAULT_SETTINGS: WalletSettings = {
110
130
  ...LIB_DEFAULT_SETTINGS,
111
131
  trustSettings: {
@@ -135,12 +155,24 @@ const DEFAULT_SETTINGS: WalletSettings = {
135
155
  }
136
156
  }
137
157
  import type { AppChain } from '../config'
138
- import { DEFAULT_STORAGE_URL, DEFAULT_CHAIN, ADMIN_ORIGINATOR, DEFAULT_BACKUP_URL, toWalletChain } from '../config'
158
+ import { DEFAULT_STORAGE_URL, DEFAULT_CHAIN, ADMIN_ORIGINATOR, toWalletChain } from '../config'
159
+ import { getBackupUrl, getMandalaEndpoints } from '../toolboxConfig'
139
160
  import { DEFAULT_AUTO_APPROVE_THRESHOLD, AUTO_APPROVE_COOLDOWN_MS, AUTO_APPROVE_STORAGE_KEY } from '../constants'
140
161
  import AsyncStorage from '@react-native-async-storage/async-storage'
141
162
  import { UserContext } from './UserContext'
142
163
  import { useLocalStorage } from './LocalStorageProvider'
143
164
  import { usePermissionQueue } from '../hooks/usePermissionQueue'
165
+ import { configureMandala, resolveAssetMetadata } from '@bsv/mandala'
166
+ import { MessageBoxClient } from '@bsv/message-box-client'
167
+ import { MandalaTokenModule, wrapCreateActionForTokenInputs, type MandalaAssetMetadata } from '../mandala/permissionModule'
168
+ import { wrapAbortActionForSettlements } from '../mandala/abortGuard'
169
+ import { migrateMandalaBasketName } from '../mandala/basketMigration'
170
+ import { bindOriginator, createMandalaKvStorage, createMandalaRuntime, type MandalaMessageBox } from '../mandala/createRuntime'
171
+ import type { MandalaRuntime } from '../mandala/runtime'
172
+ import { MANDALA_BASKET } from '../mandala/types'
173
+ import { mandalaSettlementDeps, type CancelParkedSettlementDeps } from '../offline/cancelParked'
174
+ import { drainMandalaInbox } from '../pay/rails/handle'
175
+ import { forgetSessionPsks, sealedFramePayloadDecoder } from '../offline/tokenFrames'
144
176
  import { createServices, chaintracksUrlFor } from '../services/walletServiceConfig'
145
177
  import {
146
178
  boundReviewProvenTxs,
@@ -158,6 +190,8 @@ import {
158
190
  import { getExchangeRate } from '../services/exchangeRate'
159
191
  import { logWithTimestamp } from '../logging'
160
192
  import { recoverMnemonicWallet } from '../mnemonicWallet'
193
+ import { vaultStore } from '../services/vault/vaultStore'
194
+ import { guardVaultAccess } from '../services/vault/guard'
161
195
  import { StorageProvider, ChaintracksServiceClient } from '@bsv/wallet-toolbox-mobile'
162
196
  import { StorageExpoSQLite } from '../storage'
163
197
  import { makeBuildGeneration } from './buildGeneration'
@@ -267,11 +301,13 @@ export interface WalletContextValue {
267
301
  protocolRequests: ProtocolAccessRequest[]
268
302
  spendingRequests: SpendingRequest[]
269
303
  btmsRequests: BtmsRequest[]
304
+ mandalaRequests: MandalaRequest[]
270
305
  advanceBasketQueue: () => void
271
306
  advanceCertificateQueue: () => void
272
307
  advanceProtocolQueue: () => void
273
308
  advanceSpendingQueue: () => void
274
309
  advanceBtmsQueue: (approved: boolean) => void
310
+ advanceMandalaQueue: (approved: boolean) => void
275
311
  finalizeConfig: (wabConfig: WABConfig) => boolean
276
312
  setConfigStatus: (status: ConfigStatus) => void
277
313
  configStatus: ConfigStatus
@@ -296,6 +332,24 @@ export interface WalletContextValue {
296
332
  * "import from backup" over an auto-created wallet). */
297
333
  rebuildWallet: (opts?: { restoreFromBackup?: boolean }) => Promise<void>
298
334
  storage: StorageExpoSQLite | null
335
+ /**
336
+ * Mandala stablecoins, or undefined.
337
+ *
338
+ * Undefined until the wallet is built, and on every chain the host has not
339
+ * stated endpoints for (mainnet only in v1) — so `mandala === undefined` is
340
+ * exactly "this wallet cannot do stablecoins right now", which is what the UI
341
+ * renders. Consumed through `useMandala()`; nothing above this context may
342
+ * reach `@bsv/mandala` directly.
343
+ */
344
+ mandala: MandalaRuntime | undefined
345
+ /**
346
+ * `cancelParkedPayment`'s `settlement` argument, pre-assembled from
347
+ * `mandala` (FIX J — an online cancel of an already-admitted token payment
348
+ * refuses with `'already-sent'` rather than aborting inputs the overlay
349
+ * considers spent). `undefined` exactly when `mandala` is, which is also
350
+ * the argument a plain BSV cancel needs — nothing else has to branch on it.
351
+ */
352
+ mandalaSettlement: CancelParkedSettlementDeps | undefined
299
353
  /** Fetch BUMP from WoC and store merkle proof, advancing tx status to completed */
300
354
  refreshProof: (txid: string) => Promise<'confirmed' | 'pending' | 'failed'>
301
355
  /** Peek OfflineFirstChaintracks.lastMissHeight for credit-error classification. Does not clear. */
@@ -337,11 +391,13 @@ export const WalletContext = createContext<WalletContextValue>({
337
391
  protocolRequests: [],
338
392
  spendingRequests: [],
339
393
  btmsRequests: [],
394
+ mandalaRequests: [],
340
395
  advanceBasketQueue: () => {},
341
396
  advanceCertificateQueue: () => {},
342
397
  advanceProtocolQueue: () => {},
343
398
  advanceSpendingQueue: () => {},
344
399
  advanceBtmsQueue: () => {},
400
+ advanceMandalaQueue: () => {},
345
401
  finalizeConfig: () => false,
346
402
  setConfigStatus: () => {},
347
403
  configStatus: 'initial',
@@ -355,6 +411,8 @@ export const WalletContext = createContext<WalletContextValue>({
355
411
  switchNetwork: async () => {},
356
412
  rebuildWallet: async () => {},
357
413
  storage: null,
414
+ mandala: undefined,
415
+ mandalaSettlement: undefined,
358
416
  refreshProof: async () => 'pending',
359
417
  peekLastMissHeight: () => undefined,
360
418
  txStatusVersion: 0,
@@ -447,6 +505,16 @@ type BtmsRequest = {
447
505
  resolve: (approved: boolean) => void
448
506
  }
449
507
 
508
+ /** Same shape as BtmsRequest — MandalaTokenModule's requestTokenAccess queue item. */
509
+ type MandalaRequest = {
510
+ /** The originator (dApp domain) requesting Mandala token access */
511
+ originator: string
512
+ /** The raw message from MandalaTokenModule (JSON-encoded promptData) */
513
+ message: string
514
+ /** Resolve the pending Promise from MandalaTokenModule — true = approved */
515
+ resolve: (approved: boolean) => void
516
+ }
517
+
450
518
  export interface WABConfig {
451
519
  wabUrl: string
452
520
  wabInfo?: any // Optional for noWAB (self-custodial) mode
@@ -517,6 +585,18 @@ export const WalletContextProvider: React.FC<WalletContextProps> = ({ children =
517
585
  // buildWallet's getAuth() call below). null until a wallet is built, or if
518
586
  // getAuth() fails — callers treat null as "unscoped" rather than a gate.
519
587
  const [walletUserId, setWalletUserId] = useState<number | null>(null)
588
+ /**
589
+ * The Mandala stablecoin runtime, or undefined — before the wallet is built,
590
+ * and on every chain but the one the host stated endpoints for (mainnet in
591
+ * v1). `useMandala()` reads this; nothing else in the app may reach the lib.
592
+ *
593
+ * The ref beside it is what the monitor tasks read. They are registered once,
594
+ * inside the build, and close over whatever the ref holds at the moment they
595
+ * run — so a rebuild or a network switch cannot leave a task draining the
596
+ * previous wallet's settlement tables.
597
+ */
598
+ const [mandala, setMandala] = useState<MandalaRuntime | undefined>(undefined)
599
+ const mandalaRef = useRef<MandalaRuntime | undefined>(undefined)
520
600
  const appStateRef = useRef<AppStateStatus>(AppState.currentState)
521
601
  const monitorRef = useRef<Monitor | null>(null)
522
602
  // The offline-first chain tracker and the header store it wraps. Populated
@@ -736,6 +816,27 @@ export const WalletContextProvider: React.FC<WalletContextProps> = ({ children =
736
816
  [btmsQueue.enqueue]
737
817
  )
738
818
 
819
+ // Same usePermissionQueue pattern as BTMS above — a separate queue so a
820
+ // pending BTMS prompt and a pending Mandala prompt never resolve each
821
+ // other's promise.
822
+ const mandalaQueue = usePermissionQueue<MandalaRequest>(focusOpts)
823
+
824
+ const advanceMandalaQueue = useCallback(
825
+ (approved: boolean) => {
826
+ mandalaQueue.advance(head => head.resolve(approved))
827
+ },
828
+ [mandalaQueue.advance]
829
+ )
830
+
831
+ const mandalaPromptHandler = useCallback(
832
+ (originator: string, message: string): Promise<boolean> => {
833
+ return new Promise<boolean>(resolve => {
834
+ mandalaQueue.enqueue({ originator, message, resolve })
835
+ })
836
+ },
837
+ [mandalaQueue.enqueue]
838
+ )
839
+
739
840
  const updateSettings = useCallback(
740
841
  async (newSettings: WalletSettings) => {
741
842
  setSettings(newSettings)
@@ -968,6 +1069,11 @@ export const WalletContextProvider: React.FC<WalletContextProps> = ({ children =
968
1069
  const newManagers = {} as any
969
1070
  // Deliberately the ref, not the state: see selectedNetworkRef.
970
1071
  const chain = selectedNetworkRef.current
1072
+ // Mandala runs on exactly the chains the host stated endpoints for
1073
+ // (currently testnet only, see app/_layout.tsx): an overlay URL with no
1074
+ // verifiable identity key is an overlay whose admissions nothing can
1075
+ // check, so a partial entry reads as no entry at all (see toolboxConfig).
1076
+ const mandalaEndpoints = getMandalaEndpoints(chain)
971
1077
  // Toolbox chain id ('teratest' -> 'ttn'). App keeps 'teratest' for AsyncStorage keys / env / UI.
972
1078
  const walletChain = toWalletChain(chain)
973
1079
  // The backup log's network name. Distinct from walletChain ('ttn' for teratest):
@@ -1084,6 +1190,15 @@ export const WalletContextProvider: React.FC<WalletContextProps> = ({ children =
1084
1190
  }
1085
1191
 
1086
1192
  const wallet = new Wallet(signer, services, undefined, privilegedKeyManager)
1193
+ // Consumed only by the toolbox storage-boundary hook. The value is set
1194
+ // by trusted host code and compared with WalletClient's originator;
1195
+ // external action fields cannot manufacture this authorization bit.
1196
+ Object.defineProperty(wallet, '__bsvVaultAdminOriginator', {
1197
+ value: adminOriginator,
1198
+ enumerable: false,
1199
+ configurable: false,
1200
+ writable: false
1201
+ })
1087
1202
 
1088
1203
  // Every write to the transaction/output tables refreshes the money on
1089
1204
  // screen immediately. The monitor's onTransactionStatusChanged only
@@ -1188,7 +1303,7 @@ export const WalletContextProvider: React.FC<WalletContextProps> = ({ children =
1188
1303
  primaryKey,
1189
1304
  chain: chainStr,
1190
1305
  identityKey,
1191
- baseUrl: DEFAULT_BACKUP_URL,
1306
+ baseUrl: getBackupUrl(),
1192
1307
  onProgress: (chunks, total) => setBackupRestore({ phase: 'restoring', chunks, total }),
1193
1308
  // reviewSpendableOutputs talks to Services through the Wallet, which
1194
1309
  // needs this storage attached first. Attach here (idempotent with the
@@ -1239,14 +1354,58 @@ export const WalletContextProvider: React.FC<WalletContextProps> = ({ children =
1239
1354
  console.error('[WalletContext] Failed to add local storage provider:', error)
1240
1355
  }
1241
1356
 
1357
+ let migrationUserId: number | undefined
1242
1358
  try {
1243
1359
  const auth = await storageManager.getAuth()
1244
1360
  setWalletUserId(auth.userId ?? null)
1361
+ migrationUserId = auth.userId ?? undefined
1245
1362
  } catch {
1246
1363
  // Scoping is a filter, not a gate: with no id the queue reads fall
1247
1364
  // back to unscoped, which is today's behaviour.
1248
1365
  setWalletUserId(null)
1249
1366
  }
1367
+
1368
+ // One-time basket rename ('mandala-tokens' -> MANDALA_BASKET), run
1369
+ // after storage is attached (and any backup restore above has had
1370
+ // its chance to write old-named rows) so a restored device's rows
1371
+ // are migrated too, not just a freshly-created wallet's. Guarded
1372
+ // internally by its own key_value_store marker; the per-user pass
1373
+ // still runs on every build so a restored backup's old-named rows
1374
+ // are caught even after the marker is set. See offline-settlement-final.md §8.3.
1375
+ try {
1376
+ await migrateMandalaBasketName(phoneStorage, migrationUserId)
1377
+ } catch (error) {
1378
+ console.error('[WalletContext] Mandala basket migration failed:', error)
1379
+ }
1380
+
1381
+ // Hand `@bsv/mandala` this deployment's endpoints, this wallet's
1382
+ // basket, and a DURABLE journal store — before any lib call can run.
1383
+ //
1384
+ // The storage adapter is the load-bearing half. The lib's journals
1385
+ // are its recovery contract: an overlay-accepted, not-yet-broadcast
1386
+ // transaction is recoverable only because the 'accepted' entry
1387
+ // outlives the process that wrote it. React Native has no
1388
+ // localStorage, so a host that injects nothing here gets a
1389
+ // process-lifetime Map — i.e. no crash recovery at all — and the
1390
+ // failure is silent. See lib/src/storage.ts.
1391
+ //
1392
+ // `basket` is the wallet's own deviation from the lib default
1393
+ // ('mandala-tokens'): 'p mandala' is BRC-99 P-routed, which is what
1394
+ // puts every listOutputs/createAction/internalizeAction against it
1395
+ // through MandalaTokenModule regardless of originator (spec §8.3).
1396
+ if (mandalaEndpoints) {
1397
+ try {
1398
+ configureMandala({
1399
+ overlayUrl: mandalaEndpoints.overlayUrl,
1400
+ overlayIdentityKey: mandalaEndpoints.overlayIdentityKey,
1401
+ messageBoxUrl: mandalaEndpoints.messageBoxUrl,
1402
+ basket: MANDALA_BASKET,
1403
+ storage: createMandalaKvStorage(phoneStorage)
1404
+ })
1405
+ } catch (error) {
1406
+ console.error('[WalletContext] configureMandala failed:', error)
1407
+ }
1408
+ }
1250
1409
  }
1251
1410
  // TODO: Re-add remote storage support in future version
1252
1411
 
@@ -1254,6 +1413,39 @@ export const WalletContextProvider: React.FC<WalletContextProps> = ({ children =
1254
1413
  // "p btms" operations surface a UI modal rather than silently denying.
1255
1414
  const btmsModule = loadBtmsPermissionModule().createBtmsModule({ wallet, promptHandler: btmsPromptHandler })
1256
1415
 
1416
+ // Adversarial-review finding (2): every outpoint this wallet holds in
1417
+ // MANDALA_BASKET, via the ADMIN-originator wallet -- i.e. this call
1418
+ // itself passes through MandalaTokenModule with zero prompts (the
1419
+ // module's own admin pass-through branch). Shared by the module's
1420
+ // deps below AND by wrapCreateActionForTokenInputs's wrapper further
1421
+ // down, so both use the exact same listing.
1422
+ const listMandalaTokenOutpoints = async (): Promise<Set<string>> => {
1423
+ try {
1424
+ const { outputs } = await wallet.listOutputs(
1425
+ { basket: MANDALA_BASKET, includeCustomInstructions: false, limit: 10000 } as never,
1426
+ adminOriginator
1427
+ )
1428
+ return new Set(outputs.map((o: { outpoint: string }) => o.outpoint))
1429
+ } catch {
1430
+ // A wallet with no Mandala basket yet, or a storage fault -- treat
1431
+ // as "no known token inputs" rather than blocking createAction;
1432
+ // see permissionModule.ts's doc on this dep failing open.
1433
+ return new Set()
1434
+ }
1435
+ }
1436
+
1437
+ // Mandala's own P-module (schemeID 'mandala', basket MANDALA_BASKET =
1438
+ // 'p mandala') -- same routing mechanism as BTMS above
1439
+ // (WalletPermissionsManager delegates by basket prefix regardless of
1440
+ // originator), but decodes Mandala's own script layout rather than
1441
+ // BTMS's PushDrop. See offline-settlement-final.md §8.
1442
+ const mandalaModule = new MandalaTokenModule({
1443
+ adminOriginator,
1444
+ requestTokenAccess: mandalaPromptHandler,
1445
+ resolveAssetMetadata: resolveMandalaAssetMetadata,
1446
+ listTokenOutpoints: listMandalaTokenOutpoints
1447
+ })
1448
+
1257
1449
  // Setup permissions with provided callbacks and BTMS module.
1258
1450
  const permissionsManager = new WalletPermissionsManager(wallet, adminOriginator, {
1259
1451
  differentiatePrivilegedOperations: true,
@@ -1275,7 +1467,7 @@ export const WalletContextProvider: React.FC<WalletContextProps> = ({ children =
1275
1467
  seekProtocolPermissionsForHMAC: false,
1276
1468
  seekProtocolPermissionsForSigning: false,
1277
1469
  seekSpendingPermissions: true,
1278
- permissionModules: { btms: btmsModule }
1470
+ permissionModules: { btms: btmsModule, mandala: mandalaModule }
1279
1471
  } as any)
1280
1472
 
1281
1473
  if (protocolPermissionCallback) {
@@ -1291,7 +1483,90 @@ export const WalletContextProvider: React.FC<WalletContextProps> = ({ children =
1291
1483
  permissionsManager.bindCallback('onCertificateAccessRequested', certificateAccessCallback)
1292
1484
  }
1293
1485
 
1294
- newManagers.permissionsManager = permissionsManager
1486
+ // Publish one idempotently guarded manager for both trusted in-app
1487
+ // Vault calls and external WalletClient calls. Admin output mutations
1488
+ // therefore share the guard's FIFO with external inventory scan+use;
1489
+ // external call sites may safely apply guardVaultAccess again.
1490
+ //
1491
+ // wrapCreateActionForTokenInputs wraps the RAW permissionsManager
1492
+ // FIRST, and guardVaultAccess is applied to ITS result (never the
1493
+ // other way around) -- adversarial-review finding (2):
1494
+ // WalletPermissionsManager only P-routes a createAction call whose
1495
+ // OUTPUTS or LABELS name a 'p ' scheme, never its inputs, so a
1496
+ // createAction that spends 'p mandala' inputs with no basketed/
1497
+ // decodable change output would otherwise reach
1498
+ // MandalaTokenModule.onRequest for exactly zero callers of this
1499
+ // manager. Wrapping outside-in (guard around this wrapper) would
1500
+ // instead break guardVaultAccess's own re-wrap dedup, which several
1501
+ // screens rely on (`guardVaultAccess(managers.permissionsManager,
1502
+ // ADMIN_ORIGINATOR)` again) -- see permissionModule.ts's wrapper doc
1503
+ // for the full mechanism.
1504
+ //
1505
+ // `wrapAbortActionForSettlements` goes on the same stack, for the same
1506
+ // reason and in the same place: inside `guardVaultAccess`, so the
1507
+ // published object stays the one the guard's dedup recognises. It is
1508
+ // the last line of defence for the 2026-09-15 incident — an
1509
+ // `abortAction` against a token payment the overlay has already
1510
+ // admitted (and therefore broadcast) releases inputs that are spent on
1511
+ // chain. It reads the settlement store LATE, off `mandalaRef`, because
1512
+ // the runtime is built below this line and replaced on every rebuild.
1513
+ newManagers.permissionsManager = guardVaultAccess(
1514
+ wrapAbortActionForSettlements(
1515
+ wrapCreateActionForTokenInputs(permissionsManager, listMandalaTokenOutpoints, adminOriginator),
1516
+ () => mandalaRef.current?.store
1517
+ ),
1518
+ adminOriginator
1519
+ )
1520
+
1521
+ // THE MANDALA RUNTIME'S ONE CONSTRUCTION SITE.
1522
+ //
1523
+ // Built here, after the permissions manager, because every lib call it
1524
+ // makes must go through the P-module gate — a runtime holding the raw
1525
+ // wallet would bypass exactly the routing §8.3 exists to establish. It
1526
+ // is published only when `available`: a runtime on a chain with no
1527
+ // endpoints could submit nowhere and verify nothing, and `undefined` is
1528
+ // what the UI already renders as "not on this network".
1529
+ if (phoneStorage) {
1530
+ try {
1531
+ const runtime = createMandalaRuntime({
1532
+ wallet: newManagers.permissionsManager as never,
1533
+ adminOriginator,
1534
+ storage: phoneStorage,
1535
+ chain,
1536
+ endpoints: mandalaEndpoints,
1537
+ // Lazy: constructing a runtime must do no I/O, and a wallet that
1538
+ // never touches stablecoins never opens a MessageBox connection.
1539
+ messageBox: mandalaEndpoints
1540
+ ? async () =>
1541
+ new MessageBoxClient({
1542
+ host: mandalaEndpoints.messageBoxUrl,
1543
+ // The client calls getPublicKey / createSignature itself;
1544
+ // those must carry the admin originator or the vault guard
1545
+ // refuses them ("Originator is required for permission checks").
1546
+ walletClient: bindOriginator(newManagers.permissionsManager as object, adminOriginator) as never,
1547
+ enableLogging: false
1548
+ }) as unknown as MandalaMessageBox
1549
+ : undefined,
1550
+ // The payer's own frames are sealed with a nearby session PSK the
1551
+ // drain never persists; this opens the ones whose session this
1552
+ // process still holds. See offline/tokenFrames.ts.
1553
+ decodeSealedFrame: sealedFramePayloadDecoder(),
1554
+ // The one thing `settleNow` asks about connectivity: whether a
1555
+ // hand-over that just landed should be followed by this device's
1556
+ // own submit now, or left to the drain. The runtime deliberately
1557
+ // has no NetInfo dependency of its own, so the app-wide probe is
1558
+ // handed to it here.
1559
+ isOnline: getOnline,
1560
+ refetchBeef: makeBeefRepair({ woc: wocConfigFor(chain), online: getOnline })
1561
+ })
1562
+ mandalaRef.current = runtime.available ? runtime : undefined
1563
+ setMandala(runtime.available ? runtime : undefined)
1564
+ } catch (error) {
1565
+ console.error('[WalletContext] could not build the Mandala runtime:', error)
1566
+ mandalaRef.current = undefined
1567
+ setMandala(undefined)
1568
+ }
1569
+ }
1295
1570
 
1296
1571
  // Start background monitor for transaction status updates (sending → unproven → completed)
1297
1572
  try {
@@ -1345,9 +1620,48 @@ export const WalletContextProvider: React.FC<WalletContextProps> = ({ children =
1345
1620
  if (phoneStorage) {
1346
1621
  monitor.addTask(
1347
1622
  new TaskSendOffline(monitor, async () => {
1623
+ // FIX C recovery and the nearby-blinding reservation sweep ride
1624
+ // this same tick, ahead of the submit-then-broadcast pass below
1625
+ // so a row this recovers to `admitted` can broadcast in the
1626
+ // SAME pass rather than waiting for the next one. Read from the
1627
+ // ref for the same reason `token: mandalaRef.current?.tokenDeps`
1628
+ // is below — a rebuild replaces the runtime under a task
1629
+ // registered once. Both are best-effort and never throw.
1630
+ await mandalaRef.current?.recoverStaleAdmissions()
1631
+ // The 2026-09-15 repair: a settlement row that says the overlay
1632
+ // has the transaction, beside a wallet that failed it and
1633
+ // released its input coin as spendable although it is spent on
1634
+ // chain. Ahead of the release pass on purpose — a coin this
1635
+ // re-marks spent must not be planned into a send below.
1636
+ await mandalaRef.current?.repairAdmittedAborted()
1637
+ // The LIB's own journals, on the same tick and with the same
1638
+ // ref discipline: an overlay-accepted transfer whose broadcast
1639
+ // never went out, a liftable refusal still holding its inputs,
1640
+ // and the recipient notification a committed transfer owes its
1641
+ // payee. Nothing else in this wallet drives them — the
1642
+ // settlement drain below only knows `token_settlements` rows,
1643
+ // and the handle rail writes none of these entries. Never
1644
+ // throws (see `reconcileJournals`).
1645
+ await mandalaRef.current?.reconcileJournals()
1646
+ // The payer's handle-rail rows: no queue row exists for them,
1647
+ // so the release pass below would never step them. Each one
1648
+ // takes its `settleNow` step here instead (2026-09-15).
1649
+ await mandalaRef.current?.settlePendingSends()
1650
+ // Every held coin's σ_I on device, for the next offline hand-over.
1651
+ await mandalaRef.current?.ensureAdmissionsForHoldings()
1652
+ await mandalaRef.current?.pruneBlindingReservations()
1348
1653
  const r = await processOfflineActions({
1349
1654
  storage: phoneStorage!,
1350
- refetchBeef: makeBeefRepair({ woc: wocConfigFor(chain), online: getOnline })
1655
+ refetchBeef: makeBeefRepair({ woc: wocConfigFor(chain), online: getOnline }),
1656
+ // The settlement drain, on the same cadence and in the same
1657
+ // pass as the BSV release. That is the whole of §4.3: a token
1658
+ // transaction takes the ordinary plan's place in dependency
1659
+ // order and simply has `/submit` in front of its broadcast,
1660
+ // so the recipient's `held` rows and the payer's
1661
+ // `handed_over` rows both settle on every online tick.
1662
+ // Read from the ref, not captured: a rebuild replaces the
1663
+ // runtime under a task that was registered once.
1664
+ token: mandalaRef.current?.tokenDeps
1351
1665
  })
1352
1666
  // The drain writes transaction statuses directly, below the
1353
1667
  // monitor's onTransactionStatusChanged callback — bump the
@@ -1410,7 +1724,19 @@ export const WalletContextProvider: React.FC<WalletContextProps> = ({ children =
1410
1724
  internalizeIncoming(permissionsManager as never, client, adminOriginator, p, repairBeef)
1411
1725
  )
1412
1726
  })
1413
- return { accepted: r.accepted, attention: r.attentionCount, pending: r.pending }
1727
+ // The SAME rail, a second box. A handle-rail token payment
1728
+ // is delivered into 'mandala-payments', not 'payment_inbox',
1729
+ // so a receive drain that read only the satoshi box would
1730
+ // leave real money sitting in the other one. Never throws
1731
+ // (see drainMandalaInbox) — a MessageBox fault on the token
1732
+ // side must not take the satoshi inbox down with it.
1733
+ const tokens = await drainMandalaInbox(mandalaRef.current)
1734
+ if (tokens.credited > 0) setTxStatusVersion(v => v + 1)
1735
+ return {
1736
+ accepted: r.accepted + tokens.credited,
1737
+ attention: r.attentionCount,
1738
+ pending: r.pending
1739
+ }
1414
1740
  },
1415
1741
  Date.now,
1416
1742
  () => {
@@ -1461,7 +1787,7 @@ export const WalletContextProvider: React.FC<WalletContextProps> = ({ children =
1461
1787
  //
1462
1788
  // Reads chunks straight from phoneStorage rather than through
1463
1789
  // WalletStorageManager, whose sync lock would block all storage access.
1464
- if (DEFAULT_BACKUP_URL !== '') {
1790
+ if (getBackupUrl() !== '') {
1465
1791
  monitor.addTask(
1466
1792
  new TaskBackupPush(monitor, async () => {
1467
1793
  return await pushOnce({
@@ -1469,7 +1795,7 @@ export const WalletContextProvider: React.FC<WalletContextProps> = ({ children =
1469
1795
  primaryKey,
1470
1796
  chain: backupChain,
1471
1797
  identityKey: keyDeriver.identityKey,
1472
- baseUrl: DEFAULT_BACKUP_URL
1798
+ baseUrl: getBackupUrl()
1473
1799
  })
1474
1800
  })
1475
1801
  )
@@ -1485,11 +1811,17 @@ export const WalletContextProvider: React.FC<WalletContextProps> = ({ children =
1485
1811
  // the drain so the parent goes out first.
1486
1812
  if (phoneStorage) {
1487
1813
  const sendWaiting = monitor._tasks.find(t => t.name === 'SendWaiting') as
1488
- | { processUnsent?: (reqApis: Array<{ rawTx?: number[] }>, indent?: number) => Promise<string> }
1814
+ | { processUnsent?: (reqApis: Array<{ txid: string; rawTx?: number[] }>, indent?: number) => Promise<string> }
1489
1815
  | undefined
1490
1816
  if (sendWaiting?.processUnsent) {
1491
1817
  const orig = sendWaiting.processUnsent.bind(sendWaiting)
1492
- sendWaiting.processUnsent = async (reqApis, indent) => {
1818
+ sendWaiting.processUnsent = async (allReqApis, indent) => {
1819
+ // Guard #2 for this path: a request with a `token_settlements`
1820
+ // row is the settlement drain's to broadcast, after `/submit`,
1821
+ // never the monitor's. Held here and dropped from this pass.
1822
+ const heldTokenTxids = await phoneStorage.holdTokenReqsForDrain(allReqApis as never)
1823
+ const reqApis = heldTokenTxids.size > 0 ? allReqApis.filter(r => !heldTokenTxids.has(r.txid)) : allReqApis
1824
+ if (heldTokenTxids.size > 0) TaskSendOffline.requestNow()
1493
1825
  let queuedTxids = new Set<string>()
1494
1826
  try {
1495
1827
  const db = phoneStorage.sqliteDb
@@ -1508,7 +1840,10 @@ export const WalletContextProvider: React.FC<WalletContextProps> = ({ children =
1508
1840
  }
1509
1841
  if (deferred > 0) TaskSendOffline.requestNow()
1510
1842
  if (ready.length === 0) {
1511
- return deferred > 0 ? `deferred ${deferred} req(s) behind queued ancestors\n` : ''
1843
+ const notes: string[] = []
1844
+ if (heldTokenTxids.size > 0) notes.push(`held ${heldTokenTxids.size} token req(s) for the settlement drain`)
1845
+ if (deferred > 0) notes.push(`deferred ${deferred} req(s) behind queued ancestors`)
1846
+ return notes.length > 0 ? `${notes.join('; ')}\n` : ''
1512
1847
  }
1513
1848
  return orig(ready, indent)
1514
1849
  }
@@ -1722,6 +2057,7 @@ export const WalletContextProvider: React.FC<WalletContextProps> = ({ children =
1722
2057
  logWithTimestamp(F, 'Discarding a build the network switch overtook')
1723
2058
  return null
1724
2059
  }
2060
+ vaultStore.configureScope({ identityKey: keyDeriver.identityKey, chain: backupChain })
1725
2061
  updateManagers(m => ({ ...m, ...newManagers }))
1726
2062
  logWithTimestamp(F, 'Wallet build completed successfully')
1727
2063
 
@@ -1745,6 +2081,7 @@ export const WalletContextProvider: React.FC<WalletContextProps> = ({ children =
1745
2081
  spendingAuthorizationCallback,
1746
2082
  certificateAccessCallback,
1747
2083
  btmsPromptHandler,
2084
+ mandalaPromptHandler,
1748
2085
  runHeaderSync,
1749
2086
  noteLedgerChanged,
1750
2087
  onToast
@@ -1924,6 +2261,10 @@ export const WalletContextProvider: React.FC<WalletContextProps> = ({ children =
1924
2261
  restoreIntentRef.current = opts?.restoreFromBackup === true
1925
2262
  // Any build already in flight belongs to the configuration being replaced.
1926
2263
  const token = buildGenRef.current.bump()
2264
+ // Invalidate Vault operations before the first teardown await. Otherwise a
2265
+ // signer/listing already in flight can resume against the departing wallet.
2266
+ vaultStore.clearScope()
2267
+ vaultCeremony.cancel()
1927
2268
 
1928
2269
  // Stop any running monitor and let its current pass drain before the
1929
2270
  // storage teardown below closes the connection under it.
@@ -1951,8 +2292,15 @@ export const WalletContextProvider: React.FC<WalletContextProps> = ({ children =
1951
2292
  // the screens reading the OLD chain's database until the new build
1952
2293
  // replaced it — which is how a testnet wallet displayed mainnet money.
1953
2294
  setStorage(null)
2295
+ // The runtime holds this build's settlement store, which is a handle on
2296
+ // the database just destroyed. Dropping it here is what stops a monitor
2297
+ // task or a screen draining the departed wallet's tables.
2298
+ mandalaRef.current = undefined
2299
+ setMandala(undefined)
2300
+ forgetSessionPsks()
1954
2301
 
1955
2302
  // Tear down current wallet state (but keep mnemonic / config)
2303
+ vaultStore.clearScope()
1956
2304
  updateManagers({})
1957
2305
  walletBuiltRef.current = false
1958
2306
  setWalletBuilt(false)
@@ -1979,6 +2327,8 @@ export const WalletContextProvider: React.FC<WalletContextProps> = ({ children =
1979
2327
  if (network === selectedNetwork) return
1980
2328
  logWithTimestamp(F, `Switching network from ${selectedNetwork} to ${network}`)
1981
2329
  buildGenRef.current.bump()
2330
+ vaultStore.clearScope()
2331
+ vaultCeremony.cancel()
1982
2332
 
1983
2333
  // Stop any running monitor and let its current pass drain before the
1984
2334
  // storage teardown below closes the connection under it.
@@ -2001,8 +2351,12 @@ export const WalletContextProvider: React.FC<WalletContextProps> = ({ children =
2001
2351
  } catch {}
2002
2352
  }
2003
2353
  setStorage(null)
2354
+ mandalaRef.current = undefined
2355
+ setMandala(undefined)
2356
+ forgetSessionPsks()
2004
2357
 
2005
2358
  // Tear down current wallet state (but keep mnemonic)
2359
+ vaultStore.clearScope()
2006
2360
  updateManagers({})
2007
2361
  walletBuiltRef.current = false
2008
2362
  setWalletBuilt(false)
@@ -2078,7 +2432,24 @@ export const WalletContextProvider: React.FC<WalletContextProps> = ({ children =
2078
2432
  online = false
2079
2433
  }
2080
2434
  if (!canInternalizePending(online)) return
2081
- const results = await processPending(managers.permissionsManager as any, storage, adminOriginator)
2435
+ const results = await processPending(
2436
+ managers.permissionsManager as any,
2437
+ storage,
2438
+ adminOriginator,
2439
+ undefined,
2440
+ // A credited TOKEN frame is the moment this device becomes
2441
+ // responsible for submitting its chain (settlement rule 3), so the
2442
+ // row and the evidence the frame carried are written here — not
2443
+ // inside the queue, which knows nothing about settlement. Its own
2444
+ // failure is never the payment's: the coin is already credited, and
2445
+ // the drain re-derives what this missed on the next online tick.
2446
+ mandalaRef.current?.onTokenCredited,
2447
+ // The same facts, written BEFORE the internalize — which is the only
2448
+ // ordering the unadmitted-broadcast guard can actually read
2449
+ // (§4.3 guard #2). This one IS allowed to refuse the credit: the
2450
+ // frame stays durable in the queue and the next tick retries it.
2451
+ mandalaRef.current?.onTokenHeld
2452
+ )
2082
2453
  const successes = results.filter(r => r.success)
2083
2454
  if (successes.length > 0) {
2084
2455
  // The activity list and balance re-read on this version; without it
@@ -2269,16 +2640,12 @@ export const WalletContextProvider: React.FC<WalletContextProps> = ({ children =
2269
2640
  return () => subscription.remove()
2270
2641
  }, [])
2271
2642
 
2272
- // Relock-on-unplug, for PERSISTENT readers only (Android USB). Start discovery
2273
- // at launch and, when the key is pulled, tell the ceremony (its onRelock
2274
- // fires the close sound/haptic) so an armed or mid-signature vault session
2275
- // ends with the hardware rather than lingering.
2643
+ // Relock-on-unplug for injected persistent readers. Native iOS and Android
2644
+ // drivers are ceremony-scoped: the ceremony owns discovery and its listener
2645
+ // through signer release, including Android USB unplug events.
2276
2646
  //
2277
- // Session-based transports (iOS NFC) are skipped here: they have no persistent
2278
- // presence — the scan session is opened per ceremony and closed on arm — so
2279
- // starting discovery at launch would pop the NFC sheet, and a session-end
2280
- // "detach" is normal, not an unplug. The ceremony's own session-scoped
2281
- // listener (see ceremony.ts) handles relock there instead.
2647
+ // Session-based drivers are skipped here so no hardware reader or NFC sheet
2648
+ // is opened at launch. See ceremony.ts for their scoped listener lifecycle.
2282
2649
  useEffect(() => {
2283
2650
  const driver = getVaultDriver()
2284
2651
  if (!driver || driver.sessionBased) return
@@ -2315,11 +2682,17 @@ export const WalletContextProvider: React.FC<WalletContextProps> = ({ children =
2315
2682
  monitorRef.current = null
2316
2683
  offlineChaintracksRef.current = undefined
2317
2684
  headerStoreRef.current = undefined
2685
+ vaultStore.clearScope()
2686
+ vaultCeremony.cancel()
2318
2687
  }
2319
2688
  }, [])
2320
2689
 
2321
2690
  const logout = useCallback(() => {
2322
2691
  logWithTimestamp(F, 'Logout')
2692
+ // Synchronous on purpose: invalidate transfer tokens and release any PIN /
2693
+ // hardware session before monitor or storage teardown yields.
2694
+ vaultStore.clearScope()
2695
+ vaultCeremony.cancel()
2323
2696
  ;(async () => {
2324
2697
  // Tear the wallet down the same way rebuildWallet does. Logout used to
2325
2698
  // skip this, which orphaned a running monitor AND left the SQLite
@@ -2342,7 +2715,11 @@ export const WalletContextProvider: React.FC<WalletContextProps> = ({ children =
2342
2715
  } catch {}
2343
2716
  }
2344
2717
  setStorage(null)
2718
+ mandalaRef.current = undefined
2719
+ setMandala(undefined)
2720
+ forgetSessionPsks()
2345
2721
 
2722
+ vaultStore.clearScope()
2346
2723
  updateManagers({})
2347
2724
  setConfigStatus('initial')
2348
2725
  walletBuiltRef.current = false
@@ -2783,11 +3160,13 @@ export const WalletContextProvider: React.FC<WalletContextProps> = ({ children =
2783
3160
  protocolRequests: protocolQueue.requests,
2784
3161
  spendingRequests: spendingQueue.requests,
2785
3162
  btmsRequests: btmsQueue.requests,
3163
+ mandalaRequests: mandalaQueue.requests,
2786
3164
  advanceBasketQueue: basketQueue.advance,
2787
3165
  advanceCertificateQueue: certificateQueue.advance,
2788
3166
  advanceProtocolQueue: protocolQueue.advance,
2789
3167
  advanceSpendingQueue: spendingQueue.advance,
2790
3168
  advanceBtmsQueue,
3169
+ advanceMandalaQueue,
2791
3170
  finalizeConfig,
2792
3171
  setConfigStatus,
2793
3172
  configStatus,
@@ -2801,6 +3180,8 @@ export const WalletContextProvider: React.FC<WalletContextProps> = ({ children =
2801
3180
  switchNetwork,
2802
3181
  rebuildWallet,
2803
3182
  storage,
3183
+ mandala,
3184
+ mandalaSettlement: mandalaSettlementDeps(mandala),
2804
3185
  refreshProof,
2805
3186
  peekLastMissHeight,
2806
3187
  txStatusVersion,
@@ -2826,11 +3207,13 @@ export const WalletContextProvider: React.FC<WalletContextProps> = ({ children =
2826
3207
  protocolQueue.requests,
2827
3208
  spendingQueue.requests,
2828
3209
  btmsQueue.requests,
3210
+ mandalaQueue.requests,
2829
3211
  basketQueue.advance,
2830
3212
  certificateQueue.advance,
2831
3213
  protocolQueue.advance,
2832
3214
  spendingQueue.advance,
2833
3215
  advanceBtmsQueue,
3216
+ advanceMandalaQueue,
2834
3217
  finalizeConfig,
2835
3218
  setConfigStatus,
2836
3219
  configStatus,
@@ -2844,6 +3227,7 @@ export const WalletContextProvider: React.FC<WalletContextProps> = ({ children =
2844
3227
  switchNetwork,
2845
3228
  rebuildWallet,
2846
3229
  storage,
3230
+ mandala,
2847
3231
  refreshProof,
2848
3232
  peekLastMissHeight,
2849
3233
  txStatusVersion,
@@ -2922,11 +3306,13 @@ export interface WalletQueuesSlice {
2922
3306
  protocolRequests: ProtocolAccessRequest[]
2923
3307
  spendingRequests: SpendingRequest[]
2924
3308
  btmsRequests: BtmsRequest[]
3309
+ mandalaRequests: MandalaRequest[]
2925
3310
  advanceBasketQueue: () => void
2926
3311
  advanceCertificateQueue: () => void
2927
3312
  advanceProtocolQueue: () => void
2928
3313
  advanceSpendingQueue: () => void
2929
3314
  advanceBtmsQueue: (approved: boolean) => void
3315
+ advanceMandalaQueue: (approved: boolean) => void
2930
3316
  }
2931
3317
  export const useWalletQueues = (): WalletQueuesSlice => {
2932
3318
  const ctx = useContext(WalletContext)
@@ -2937,11 +3323,13 @@ export const useWalletQueues = (): WalletQueuesSlice => {
2937
3323
  protocolRequests: ctx.protocolRequests,
2938
3324
  spendingRequests: ctx.spendingRequests,
2939
3325
  btmsRequests: ctx.btmsRequests,
3326
+ mandalaRequests: ctx.mandalaRequests,
2940
3327
  advanceBasketQueue: ctx.advanceBasketQueue,
2941
3328
  advanceCertificateQueue: ctx.advanceCertificateQueue,
2942
3329
  advanceProtocolQueue: ctx.advanceProtocolQueue,
2943
3330
  advanceSpendingQueue: ctx.advanceSpendingQueue,
2944
- advanceBtmsQueue: ctx.advanceBtmsQueue
3331
+ advanceBtmsQueue: ctx.advanceBtmsQueue,
3332
+ advanceMandalaQueue: ctx.advanceMandalaQueue
2945
3333
  }),
2946
3334
  [
2947
3335
  ctx.basketRequests,
@@ -2949,11 +3337,13 @@ export const useWalletQueues = (): WalletQueuesSlice => {
2949
3337
  ctx.protocolRequests,
2950
3338
  ctx.spendingRequests,
2951
3339
  ctx.btmsRequests,
3340
+ ctx.mandalaRequests,
2952
3341
  ctx.advanceBasketQueue,
2953
3342
  ctx.advanceCertificateQueue,
2954
3343
  ctx.advanceProtocolQueue,
2955
3344
  ctx.advanceSpendingQueue,
2956
- ctx.advanceBtmsQueue
3345
+ ctx.advanceBtmsQueue,
3346
+ ctx.advanceMandalaQueue
2957
3347
  ]
2958
3348
  )
2959
3349
  }