@bsv/expo-wallet-toolbox 0.22.0 → 0.24.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 +241 -0
- package/README.md +10 -9
- package/android/build.gradle +15 -0
- package/android/src/main/AndroidManifest.xml +3 -0
- package/android/src/main/java/org/bsv/boundedfetch/BoundedBody.java +19 -0
- package/android/src/main/java/org/bsv/boundedfetch/BoundedConnection.java +28 -0
- package/android/src/main/java/org/bsv/boundedfetch/BsvBoundedFetchModule.kt +114 -0
- package/core/backup/RemoteSyncReader.ts +71 -46
- package/core/backup/client.ts +6 -15
- package/core/backup/codec.ts +78 -13
- package/core/backup/constants.ts +3 -9
- package/core/backup/cursor.ts +8 -0
- package/core/backup/push.ts +26 -16
- package/core/backup/restore.ts +6 -5
- package/core/bridge/BrowserBridgeProvider.tsx +273 -0
- package/core/bridge/bindings.ts +459 -0
- package/core/bridge/conformance.ts +222 -0
- package/core/bridge/consent.ts +494 -0
- package/core/bridge/consentSheetSource.ts +98 -0
- package/core/bridge/dispatcher.ts +621 -0
- package/core/bridge/inbox.ts +569 -0
- package/core/bridge/index.ts +48 -0
- package/core/bridge/loopback/cors.ts +57 -0
- package/core/bridge/loopback/endpoints.ts +11 -0
- package/core/bridge/loopback/hostCheck.ts +25 -0
- package/core/bridge/loopback/index.ts +7 -0
- package/core/bridge/loopback/launchProof.ts +166 -0
- package/core/bridge/loopback/router.ts +770 -0
- package/core/bridge/loopback/routerTypes.ts +115 -0
- package/core/bridge/loopback/status.ts +52 -0
- package/core/bridge/memoryInboxStore.ts +231 -0
- package/core/bridge/permissionPolicy.ts +247 -0
- package/core/bridge/policy.ts +72 -0
- package/core/bridge/protocol/base64url.ts +64 -0
- package/core/bridge/protocol/connectionError.ts +79 -0
- package/core/bridge/protocol/constants.ts +21 -0
- package/core/bridge/protocol/continuity.ts +21 -0
- package/core/bridge/protocol/descriptor.ts +395 -0
- package/core/bridge/protocol/envelopes.ts +188 -0
- package/core/bridge/protocol/errorCodec.ts +164 -0
- package/core/bridge/protocol/json.ts +237 -0
- package/core/bridge/protocol/limits.ts +43 -0
- package/core/bridge/protocol/methods.ts +55 -0
- package/core/bridge/protocol/origin.ts +130 -0
- package/core/bridge/runtime.ts +642 -0
- package/core/bridge/runtimeFlags.ts +34 -0
- package/core/bridge/testing/conformanceCases.ts +149 -0
- package/core/bridge/testing/pageClient.ts +44 -0
- package/core/bridge/unverifiedManager.ts +97 -0
- package/core/bridge/unverifiedOriginator.ts +79 -0
- package/core/config.tsx +1 -16
- package/core/constants.ts +7 -11
- package/core/context/WalletConnectionContext.tsx +92 -49
- package/core/context/WalletContext.tsx +288 -165
- package/core/context/sessionTeardown.ts +46 -0
- package/core/context/usePairingAttempt.ts +31 -0
- package/core/e2e/broadcaster.ts +25 -0
- package/core/e2e/consentFixture.ts +46 -0
- package/core/e2e/mode.ts +42 -0
- package/core/headers/OfflineFirstChaintracks.ts +57 -107
- package/core/headers/headerConsensus.ts +230 -0
- package/core/headers/headerStore.ts +344 -122
- package/core/headers/prewarm.ts +4 -7
- package/core/headers/syncHeaders.ts +82 -12
- package/core/hooks/usePermissionQueue.ts +89 -34
- package/core/i18n/translations.tsx +958 -24
- package/core/identity/handleRegistry/client.ts +4 -2
- package/core/identity/handleRegistry/resolver.ts +7 -11
- package/core/index.ts +17 -0
- package/core/localpay/pending.ts +39 -4
- package/core/network/boundedFetch.ts +101 -0
- package/core/networks.ts +11 -13
- package/core/pay/rails/address.ts +5 -4
- package/core/pay/rails/handle.ts +3 -1
- package/core/pay/rails/sweep.ts +791 -0
- package/core/peerpay/brc29.ts +4 -0
- package/core/peerpay/handleResendRequests.ts +15 -2
- package/core/peerpay/outbox.ts +115 -2
- package/core/profiles/assertProfileEmpty.ts +2 -2
- package/core/profiles/profileStore.ts +3 -2
- package/core/services/arcadeBroadcastProvider.ts +260 -114
- package/core/services/autoApprovePolicy.ts +7 -1
- package/core/services/capWalletArgs.ts +2 -1
- package/core/services/permissionPrompts.ts +132 -0
- package/core/services/secrets/kek.ts +5 -0
- package/core/services/secrets/migration.ts +27 -2
- package/core/services/secrets/policy.ts +6 -0
- package/core/services/signingPermissionPolicy.ts +230 -2
- package/core/services/vault/VaultKeyService.ts +5 -2
- package/core/services/vault/ceremony.ts +2 -2
- package/core/services/vault/ceremonyHost.ts +1 -1
- package/core/services/vault/guard.ts +20 -0
- package/core/services/vault/outputAuthority.ts +76 -0
- package/core/services/vault/transfers.ts +52 -28
- package/core/services/vault/vaultStore.ts +60 -14
- package/core/services/walletArgLimits.ts +17 -2
- package/core/services/walletConnectionValidation.ts +13 -1
- package/core/services/walletServiceConfig.ts +8 -7
- package/core/storage/encryptedDbImage.ts +325 -0
- package/core/stores/ConnectionStore.ts +17 -0
- package/core/toolboxConfig.ts +78 -2
- package/expo-module.config.json +5 -0
- package/ios/BoundedBody.swift +15 -0
- package/ios/BsvBoundedFetch.podspec +17 -0
- package/ios/BsvBoundedFetchModule.swift +121 -0
- package/package.json +12 -8
- package/ui/bridgeSheet/ContextRelay.tsx +86 -0
- package/ui/bridgeSheet/relayedContexts.ts +21 -0
- package/ui/components/pay/AddressReceive.tsx +6 -2
- package/ui/components/pay/ImportedOutboxApproval.tsx +142 -0
- package/ui/components/pay/PayCellRow.tsx +3 -1
- package/ui/components/pay/PayForm.tsx +12 -2
- package/ui/components/pay/RecipientField.tsx +1 -0
- package/ui/components/pay/RequestHub.tsx +1 -0
- package/ui/components/pay/UniversalSend.tsx +110 -42
- package/ui/components/ui/ListRow.tsx +10 -2
- package/ui/components/ui/PermissionSheet.tsx +534 -158
- package/ui/components/ui/Sheet.tsx +59 -7
- package/ui/components/ui/sheetResumeSignal.ts +19 -0
- package/ui/components/vault/KeyChooser.tsx +1 -1
- package/ui/components/wallet/AmountInput.tsx +4 -1
- package/ui/components/wallet/BackupReminderSheet.tsx +8 -1
- package/ui/components/wallet/BiometricAdvisoryModal.tsx +2 -0
- package/ui/components/wallet/ImportFromBackupPrompt.tsx +6 -1
- package/ui/components/wallet/ProfileButton.tsx +1 -0
- package/ui/exportDatabases.ts +94 -5
- package/ui/hooks/useExportWalletData.ts +37 -24
- package/ui/importDatabases.ts +154 -34
- package/ui/index.ts +4 -0
- package/ui/screens/ConnectionsScreen.tsx +12 -3
- package/ui/screens/PairScreen.tsx +10 -3
- package/ui/screens/PayScreen.tsx +1 -0
- package/ui/screens/TrustScreen.tsx +6 -3
- package/ui/screens/VaultScreen.tsx +13 -3
- package/ui/screens/VaultTransferScreen.tsx +6 -3
- package/ui/screens/WalletConfigScreen.tsx +30 -3
- package/ui/screens/WalletHomeScreen.tsx +7 -1
|
@@ -17,6 +17,11 @@ import { KeyDeriver, PrivateKey, MerklePath, Transaction, Utils } from '@bsv/sdk
|
|
|
17
17
|
import { DEFAULT_SETTINGS } from './defaultWalletSettings'
|
|
18
18
|
import { conformWalletResults } from '../services/conformWalletResults'
|
|
19
19
|
import { SigningPolicyPermissionsManager } from '../services/signingPermissionPolicy'
|
|
20
|
+
import {
|
|
21
|
+
guardTokenPromptHandlers,
|
|
22
|
+
handleSpendingPrompt,
|
|
23
|
+
withdrawPrompts as withdrawPromptsFrom
|
|
24
|
+
} from '../services/permissionPrompts'
|
|
20
25
|
import { VAULT_RETENTION_MS, ceremony as vaultCeremony } from '../services/vault/ceremonyHost'
|
|
21
26
|
import { getVaultDriver } from '../services/vault/driver'
|
|
22
27
|
import { backupAttestation } from '../services/vault/backupAttestation'
|
|
@@ -127,9 +132,14 @@ function disposeColorModule(ref: { current: BuiltColorModule | undefined }): voi
|
|
|
127
132
|
}
|
|
128
133
|
|
|
129
134
|
import type { AppChain } from '../config'
|
|
135
|
+
import { effectiveUnverified, loadStoredPolicy, resolvePermissionPolicy } from '../bridge/permissionPolicy'
|
|
136
|
+
import { notifyPromptRaised } from '../bridge/runtime'
|
|
137
|
+
import { hasUnattestedTransport, onUnattestedTransportChange } from '../bridge/runtimeFlags'
|
|
138
|
+
import { buildUnverifiedPermissionsManager } from '../bridge/unverifiedManager'
|
|
130
139
|
import { DEFAULT_STORAGE_URL, DEFAULT_CHAIN, ADMIN_ORIGINATOR, toWalletChain } from '../config'
|
|
131
140
|
import { NETWORKS, isAppChain } from '../networks'
|
|
132
141
|
import { getBackupUrl, getHandleRegistryConfig, getMandalaEndpoints, getPushAdapter } from '../toolboxConfig'
|
|
142
|
+
import { e2eSafeChain } from '../e2e/mode'
|
|
133
143
|
import { inboxSeenStore } from '../directpay/receive'
|
|
134
144
|
import {
|
|
135
145
|
DEFAULT_AUTO_APPROVE_THRESHOLD,
|
|
@@ -159,7 +169,7 @@ import {
|
|
|
159
169
|
import type { MandalaRuntime } from '../mandala/runtime'
|
|
160
170
|
import { mandalaSettlementDeps, type CancelParkedSettlementDeps } from '../offline/cancelParked'
|
|
161
171
|
import { drainMandalaInbox } from '../pay/rails/handle'
|
|
162
|
-
import {
|
|
172
|
+
import { runSessionTeardown } from './sessionTeardown'
|
|
163
173
|
import connectionStore from '../stores/ConnectionStore'
|
|
164
174
|
import { loadUserAvatarIcon } from '../userAvatar'
|
|
165
175
|
import { createServices, chaintracksUrlFor } from '../services/walletServiceConfig'
|
|
@@ -171,12 +181,7 @@ import {
|
|
|
171
181
|
createWalletMonitorOptions
|
|
172
182
|
} from '../walletMonitor'
|
|
173
183
|
import { runBoundedUnfail } from '../monitor/unfailRetry'
|
|
174
|
-
import {
|
|
175
|
-
createArcadeBroadcastService,
|
|
176
|
-
createTaalBroadcastService,
|
|
177
|
-
createGorillaPoolBroadcastService,
|
|
178
|
-
createWocBroadcastService
|
|
179
|
-
} from '../services/arcadeBroadcastProvider'
|
|
184
|
+
import { registerBroadcastProviders } from '../services/arcadeBroadcastProvider'
|
|
180
185
|
import { getExchangeRate } from '../services/exchangeRate'
|
|
181
186
|
import { devLog, logWithTimestamp } from '../logging'
|
|
182
187
|
import { recoverMnemonicWallet } from '../mnemonicWallet'
|
|
@@ -371,6 +376,15 @@ const profilePurgeIo: PurgeProfileIo = {
|
|
|
371
376
|
interface ManagerState {
|
|
372
377
|
walletManager?: SimpleWalletManager
|
|
373
378
|
permissionsManager?: WalletPermissionsManager
|
|
379
|
+
/** The attested manager itself, before the guard and conformance wrappers
|
|
380
|
+
* `permissionsManager` carries. What `withdrawPrompts` retires. */
|
|
381
|
+
signingPermissionsManager?: SigningPolicyPermissionsManager
|
|
382
|
+
/** The manager for unverified (unattested) browser origins, behind the same wrapper stack as
|
|
383
|
+
* `permissionsManager`. Present only when a transport that can deliver unattested calls was
|
|
384
|
+
* registered when the wallet was built (spec 6.5). */
|
|
385
|
+
unverifiedPermissionsManager?: WalletPermissionsManager
|
|
386
|
+
/** The unverified manager itself, before its wrappers. What `withdrawPrompts` retires. */
|
|
387
|
+
unverifiedSigningPermissionsManager?: SigningPolicyPermissionsManager
|
|
374
388
|
settingsManager?: WalletSettingsManager
|
|
375
389
|
}
|
|
376
390
|
|
|
@@ -441,13 +455,23 @@ export interface WalletContextValue {
|
|
|
441
455
|
groupRequests: GroupPermissionRequest[]
|
|
442
456
|
btmsRequests: BtmsRequest[]
|
|
443
457
|
mandalaRequests: MandalaRequest[]
|
|
444
|
-
advanceBasketQueue: () => void
|
|
445
|
-
advanceCertificateQueue: () => void
|
|
446
|
-
advanceProtocolQueue: () => void
|
|
447
|
-
advanceSpendingQueue: () => void
|
|
448
|
-
advanceGroupQueue: () => void
|
|
458
|
+
advanceBasketQueue: (requestID?: string) => void
|
|
459
|
+
advanceCertificateQueue: (requestID?: string) => void
|
|
460
|
+
advanceProtocolQueue: (requestID?: string) => void
|
|
461
|
+
advanceSpendingQueue: (requestID?: string) => void
|
|
462
|
+
advanceGroupQueue: (requestID?: string) => void
|
|
449
463
|
advanceBtmsQueue: (approved: boolean) => void
|
|
450
464
|
advanceMandalaQueue: (approved: boolean) => void
|
|
465
|
+
/**
|
|
466
|
+
* Retires the given (replaced) managers, denies what they still hold and
|
|
467
|
+
* empties every permission queue. Idempotent. Runs by itself on every
|
|
468
|
+
* teardown the context performs; the bridge runtime calls it for a wallet it
|
|
469
|
+
* sees replaced some other way.
|
|
470
|
+
*/
|
|
471
|
+
withdrawPrompts: (oldManagers: SigningPolicyPermissionsManager[]) => void
|
|
472
|
+
/** Registers something else to clear on a withdrawal (pending connection
|
|
473
|
+
* requests). Returns the unregister function. */
|
|
474
|
+
registerPromptWithdrawal: (clear: () => void) => () => void
|
|
451
475
|
finalizeConfig: (wabConfig: WABConfig) => boolean
|
|
452
476
|
setConfigStatus: (status: ConfigStatus) => void
|
|
453
477
|
configStatus: ConfigStatus
|
|
@@ -587,6 +611,8 @@ export const WalletContext = createContext<WalletContextValue>({
|
|
|
587
611
|
advanceGroupQueue: () => {},
|
|
588
612
|
advanceBtmsQueue: () => {},
|
|
589
613
|
advanceMandalaQueue: () => {},
|
|
614
|
+
withdrawPrompts: () => {},
|
|
615
|
+
registerPromptWithdrawal: () => () => {},
|
|
590
616
|
finalizeConfig: () => false,
|
|
591
617
|
setConfigStatus: () => {},
|
|
592
618
|
configStatus: 'initial',
|
|
@@ -653,7 +679,12 @@ export const useWalletManagers = (): WalletManagersSlice => useContext(WalletMan
|
|
|
653
679
|
|
|
654
680
|
type PermissionType = 'identity' | 'protocol' | 'renewal' | 'basket'
|
|
655
681
|
|
|
656
|
-
|
|
682
|
+
/** Each prompt callback is bound per manager and each queue item records the
|
|
683
|
+
* manager that raised it; the sheet answers that manager, never whichever one
|
|
684
|
+
* is current, so a stale answer cannot reach a replacement. */
|
|
685
|
+
type RaisedBy = { manager?: SigningPolicyPermissionsManager }
|
|
686
|
+
|
|
687
|
+
type BasketAccessRequest = RaisedBy & {
|
|
657
688
|
requestID: string
|
|
658
689
|
basket?: string
|
|
659
690
|
originator: string
|
|
@@ -661,7 +692,7 @@ type BasketAccessRequest = {
|
|
|
661
692
|
renewal?: boolean
|
|
662
693
|
}
|
|
663
694
|
|
|
664
|
-
type CertificateAccessRequest = {
|
|
695
|
+
type CertificateAccessRequest = RaisedBy & {
|
|
665
696
|
requestID: string
|
|
666
697
|
certificate?: {
|
|
667
698
|
certType?: string
|
|
@@ -673,7 +704,7 @@ type CertificateAccessRequest = {
|
|
|
673
704
|
renewal?: boolean
|
|
674
705
|
}
|
|
675
706
|
|
|
676
|
-
type ProtocolAccessRequest = {
|
|
707
|
+
type ProtocolAccessRequest = RaisedBy & {
|
|
677
708
|
requestID: string
|
|
678
709
|
protocolSecurityLevel: number
|
|
679
710
|
protocolID: string
|
|
@@ -687,7 +718,7 @@ type ProtocolAccessRequest = {
|
|
|
687
718
|
type?: PermissionType
|
|
688
719
|
}
|
|
689
720
|
|
|
690
|
-
type SpendingRequest = {
|
|
721
|
+
type SpendingRequest = RaisedBy & {
|
|
691
722
|
requestID: string
|
|
692
723
|
originator: string
|
|
693
724
|
description?: string
|
|
@@ -701,7 +732,7 @@ type SpendingRequest = {
|
|
|
701
732
|
|
|
702
733
|
/** A site's grouped permission request, from its manifest's
|
|
703
734
|
* `metanet.groupPermissions` (WalletPermissionsManager.waitForAuthentication). */
|
|
704
|
-
export type GroupPermissionRequest = {
|
|
735
|
+
export type GroupPermissionRequest = RaisedBy & {
|
|
705
736
|
requestID: string
|
|
706
737
|
originator: string
|
|
707
738
|
permissions: {
|
|
@@ -1101,7 +1132,13 @@ export const WalletContextProvider: React.FC<WalletContextProps> = ({ children =
|
|
|
1101
1132
|
setSpendingAuthorizationModalOpen
|
|
1102
1133
|
} = useContext(UserContext)
|
|
1103
1134
|
|
|
1104
|
-
|
|
1135
|
+
// A prompt raised for a connected site while the app is in the background must pull the user to
|
|
1136
|
+
// the sheet; the bridge decides whether that applies (live binding of this originator, not active).
|
|
1137
|
+
const notePromptRaised = useCallback((item: unknown) => {
|
|
1138
|
+
const originator = (item as { originator?: unknown } | null)?.originator
|
|
1139
|
+
if (typeof originator === 'string') notifyPromptRaised(originator)
|
|
1140
|
+
}, [])
|
|
1141
|
+
const focusOpts = { isFocused, onFocusRequested, onFocusRelinquished, onEnqueue: notePromptRaised }
|
|
1105
1142
|
|
|
1106
1143
|
const basketQueue = usePermissionQueue<BasketAccessRequest>({
|
|
1107
1144
|
...focusOpts,
|
|
@@ -1160,6 +1197,70 @@ export const WalletContextProvider: React.FC<WalletContextProps> = ({ children =
|
|
|
1160
1197
|
[mandalaQueue.enqueue]
|
|
1161
1198
|
)
|
|
1162
1199
|
|
|
1200
|
+
// The five manager-backed queues answer by identity: with a requestID only
|
|
1201
|
+
// that item is removed, and nothing if it is no longer queued (a withdrawal
|
|
1202
|
+
// emptied the queue while the user's answer was on its way).
|
|
1203
|
+
const advanceBasketQueue = useCallback(
|
|
1204
|
+
(requestID?: string) => basketQueue.advance(undefined, requestID),
|
|
1205
|
+
[basketQueue.advance]
|
|
1206
|
+
)
|
|
1207
|
+
const advanceCertificateQueue = useCallback(
|
|
1208
|
+
(requestID?: string) => certificateQueue.advance(undefined, requestID),
|
|
1209
|
+
[certificateQueue.advance]
|
|
1210
|
+
)
|
|
1211
|
+
const advanceProtocolQueue = useCallback(
|
|
1212
|
+
(requestID?: string) => protocolQueue.advance(undefined, requestID),
|
|
1213
|
+
[protocolQueue.advance]
|
|
1214
|
+
)
|
|
1215
|
+
const advanceSpendingQueue = useCallback(
|
|
1216
|
+
(requestID?: string) => spendingQueue.advance(undefined, requestID),
|
|
1217
|
+
[spendingQueue.advance]
|
|
1218
|
+
)
|
|
1219
|
+
const advanceGroupQueue = useCallback(
|
|
1220
|
+
(requestID?: string) => groupQueue.advance(undefined, requestID),
|
|
1221
|
+
[groupQueue.advance]
|
|
1222
|
+
)
|
|
1223
|
+
|
|
1224
|
+
const promptWithdrawalsRef = useRef(new Set<() => void>())
|
|
1225
|
+
const registerPromptWithdrawal = useCallback((clear: () => void) => {
|
|
1226
|
+
promptWithdrawalsRef.current.add(clear)
|
|
1227
|
+
return () => {
|
|
1228
|
+
promptWithdrawalsRef.current.delete(clear)
|
|
1229
|
+
}
|
|
1230
|
+
}, [])
|
|
1231
|
+
const withdrawPrompts = useCallback(
|
|
1232
|
+
(oldManagers: SigningPolicyPermissionsManager[]) => {
|
|
1233
|
+
withdrawPromptsFrom(oldManagers, {
|
|
1234
|
+
managerQueues: [basketQueue, certificateQueue, protocolQueue, spendingQueue, groupQueue],
|
|
1235
|
+
tokenQueues: [btmsQueue, mandalaQueue],
|
|
1236
|
+
others: [...promptWithdrawalsRef.current]
|
|
1237
|
+
})
|
|
1238
|
+
},
|
|
1239
|
+
[
|
|
1240
|
+
basketQueue.clear,
|
|
1241
|
+
certificateQueue.clear,
|
|
1242
|
+
protocolQueue.clear,
|
|
1243
|
+
spendingQueue.clear,
|
|
1244
|
+
groupQueue.clear,
|
|
1245
|
+
btmsQueue.clear,
|
|
1246
|
+
mandalaQueue.clear
|
|
1247
|
+
]
|
|
1248
|
+
)
|
|
1249
|
+
// Teardown paths are declared far from here and must not re-create on every
|
|
1250
|
+
// queue change, so they reach the current function through a ref.
|
|
1251
|
+
const withdrawPromptsRef = useRef(withdrawPrompts)
|
|
1252
|
+
withdrawPromptsRef.current = withdrawPrompts
|
|
1253
|
+
/** Withdraws the prompts of the managers currently published, before the
|
|
1254
|
+
* wallet they belong to is torn down. */
|
|
1255
|
+
const withdrawCurrentPrompts = useCallback(() => {
|
|
1256
|
+
const { signingPermissionsManager, unverifiedSigningPermissionsManager } = managersRef.current
|
|
1257
|
+
withdrawPromptsRef.current(
|
|
1258
|
+
[signingPermissionsManager, unverifiedSigningPermissionsManager].filter(
|
|
1259
|
+
(m): m is SigningPolicyPermissionsManager => m !== undefined
|
|
1260
|
+
)
|
|
1261
|
+
)
|
|
1262
|
+
}, [])
|
|
1263
|
+
|
|
1163
1264
|
const updateSettings = useCallback(
|
|
1164
1265
|
async (newSettings: WalletSettings) => {
|
|
1165
1266
|
setSettings(newSettings)
|
|
@@ -1176,7 +1277,8 @@ export const WalletContextProvider: React.FC<WalletContextProps> = ({ children =
|
|
|
1176
1277
|
originator: string
|
|
1177
1278
|
reason?: string
|
|
1178
1279
|
renewal?: boolean
|
|
1179
|
-
}
|
|
1280
|
+
},
|
|
1281
|
+
manager?: SigningPolicyPermissionsManager
|
|
1180
1282
|
) => {
|
|
1181
1283
|
if (incomingRequest?.requestID) {
|
|
1182
1284
|
basketQueue.enqueue({
|
|
@@ -1184,7 +1286,8 @@ export const WalletContextProvider: React.FC<WalletContextProps> = ({ children =
|
|
|
1184
1286
|
basket: incomingRequest.basket,
|
|
1185
1287
|
originator: incomingRequest.originator,
|
|
1186
1288
|
reason: incomingRequest.reason,
|
|
1187
|
-
renewal: incomingRequest.renewal
|
|
1289
|
+
renewal: incomingRequest.renewal,
|
|
1290
|
+
manager
|
|
1188
1291
|
})
|
|
1189
1292
|
}
|
|
1190
1293
|
},
|
|
@@ -1203,7 +1306,8 @@ export const WalletContextProvider: React.FC<WalletContextProps> = ({ children =
|
|
|
1203
1306
|
originator: string
|
|
1204
1307
|
reason?: string
|
|
1205
1308
|
renewal?: boolean
|
|
1206
|
-
}
|
|
1309
|
+
},
|
|
1310
|
+
manager?: SigningPolicyPermissionsManager
|
|
1207
1311
|
) => {
|
|
1208
1312
|
if (incomingRequest?.requestID) {
|
|
1209
1313
|
const certificate = incomingRequest.certificate as any
|
|
@@ -1214,7 +1318,8 @@ export const WalletContextProvider: React.FC<WalletContextProps> = ({ children =
|
|
|
1214
1318
|
certificateType: certificate?.certType || '',
|
|
1215
1319
|
fieldsArray: certificate?.fields || [],
|
|
1216
1320
|
description: incomingRequest.reason,
|
|
1217
|
-
renewal: incomingRequest.renewal
|
|
1321
|
+
renewal: incomingRequest.renewal,
|
|
1322
|
+
manager
|
|
1218
1323
|
} as any)
|
|
1219
1324
|
}
|
|
1220
1325
|
},
|
|
@@ -1222,7 +1327,7 @@ export const WalletContextProvider: React.FC<WalletContextProps> = ({ children =
|
|
|
1222
1327
|
)
|
|
1223
1328
|
|
|
1224
1329
|
const protocolPermissionCallback = useCallback(
|
|
1225
|
-
(args: PermissionRequest & { requestID: string }): Promise<void> => {
|
|
1330
|
+
(args: PermissionRequest & { requestID: string }, manager?: SigningPolicyPermissionsManager): Promise<void> => {
|
|
1226
1331
|
const { requestID, counterparty, originator, reason, renewal, protocolID } = args
|
|
1227
1332
|
const keyID = (args as { keyID?: unknown }).keyID
|
|
1228
1333
|
if (!requestID || !protocolID) return Promise.resolve()
|
|
@@ -1243,7 +1348,8 @@ export const WalletContextProvider: React.FC<WalletContextProps> = ({ children =
|
|
|
1243
1348
|
originator,
|
|
1244
1349
|
description: reason,
|
|
1245
1350
|
renewal,
|
|
1246
|
-
type: permissionType
|
|
1351
|
+
type: permissionType,
|
|
1352
|
+
manager
|
|
1247
1353
|
})
|
|
1248
1354
|
return Promise.resolve()
|
|
1249
1355
|
},
|
|
@@ -1251,74 +1357,53 @@ export const WalletContextProvider: React.FC<WalletContextProps> = ({ children =
|
|
|
1251
1357
|
)
|
|
1252
1358
|
|
|
1253
1359
|
const spendingAuthorizationCallback = useCallback(
|
|
1254
|
-
async (
|
|
1255
|
-
|
|
1256
|
-
|
|
1257
|
-
|
|
1360
|
+
async (
|
|
1361
|
+
args: PermissionRequest & { requestID: string },
|
|
1362
|
+
manager?: SigningPolicyPermissionsManager
|
|
1363
|
+
): Promise<void> => {
|
|
1258
1364
|
// Auto-approve small transactions if within threshold, per-originator
|
|
1259
1365
|
// cooldown, and the global rolling 24h cap (misc-p2-04) — accounting
|
|
1260
1366
|
// lives in autoApprovePolicy.ts. Read the persisted threshold fresh on
|
|
1261
1367
|
// every request so a change made in wallet-config takes effect
|
|
1262
1368
|
// immediately (the mount-time ref read alone left the old value live
|
|
1263
1369
|
// until app restart — felt like auto-approve was "stuck on").
|
|
1264
|
-
|
|
1265
|
-
|
|
1266
|
-
|
|
1267
|
-
|
|
1268
|
-
|
|
1269
|
-
|
|
1270
|
-
|
|
1271
|
-
|
|
1272
|
-
|
|
1273
|
-
|
|
1274
|
-
|
|
1275
|
-
|
|
1276
|
-
|
|
1277
|
-
|
|
1278
|
-
|
|
1279
|
-
|
|
1280
|
-
|
|
1281
|
-
|
|
1282
|
-
|
|
1283
|
-
|
|
1284
|
-
ephemeral: true,
|
|
1285
|
-
amount: spending.satoshis
|
|
1286
|
-
})
|
|
1287
|
-
return
|
|
1288
|
-
}
|
|
1289
|
-
if (__DEV__) {
|
|
1290
|
-
console.log(
|
|
1291
|
-
`[spend-auth] not eligible (${autoApproveDecision.reason}) → manual modal requestID=${requestID} sats=${spending.satoshis} threshold=${threshold}`
|
|
1292
|
-
)
|
|
1293
|
-
}
|
|
1294
|
-
|
|
1295
|
-
spendingQueue.enqueue({
|
|
1296
|
-
requestID,
|
|
1297
|
-
originator,
|
|
1298
|
-
description: reason,
|
|
1299
|
-
transactionAmount: 0,
|
|
1300
|
-
totalPastSpending: 0,
|
|
1301
|
-
amountPreviouslyAuthorized: 0,
|
|
1302
|
-
authorizationAmount: spending.satoshis,
|
|
1303
|
-
renewal,
|
|
1304
|
-
lineItems: spending.lineItems || []
|
|
1370
|
+
// The flow itself (including what a withdrawal during that read means)
|
|
1371
|
+
// is handleSpendingPrompt's.
|
|
1372
|
+
await handleSpendingPrompt<SpendingRequest>(args as never, manager, {
|
|
1373
|
+
loadThreshold: async () => {
|
|
1374
|
+
try {
|
|
1375
|
+
const stored = await AsyncStorage.getItem(profileScopedKey(AUTO_APPROVE_STORAGE_KEY))
|
|
1376
|
+
// Unset means this profile never chose one: the default, never another profile's.
|
|
1377
|
+
autoApproveThresholdRef.current = stored !== null ? Number(stored) || 0 : DEFAULT_AUTO_APPROVE_THRESHOLD
|
|
1378
|
+
} catch {}
|
|
1379
|
+
},
|
|
1380
|
+
decide: (originator, satoshis) => {
|
|
1381
|
+
autoApproveThresholdSnapshot = autoApproveThresholdRef.current
|
|
1382
|
+
return autoApprovePolicy.shouldAutoApprove({ originator, satoshis })
|
|
1383
|
+
},
|
|
1384
|
+
recordAutoApproved: (originator, satoshis) => {
|
|
1385
|
+
autoApprovePolicy.record({ originator, satoshis, at: Date.now() })
|
|
1386
|
+
persistAutoApproveLedger()
|
|
1387
|
+
},
|
|
1388
|
+
enqueue: spendingQueue.enqueue,
|
|
1389
|
+
currentManager: () => managersRef.current.signingPermissionsManager
|
|
1305
1390
|
})
|
|
1306
1391
|
},
|
|
1307
1392
|
[spendingQueue.enqueue]
|
|
1308
1393
|
)
|
|
1309
1394
|
|
|
1310
1395
|
const groupedPermissionCallback = useCallback(
|
|
1311
|
-
async (args: GroupPermissionRequest): Promise<void> => {
|
|
1396
|
+
async (args: GroupPermissionRequest, manager?: SigningPolicyPermissionsManager): Promise<void> => {
|
|
1312
1397
|
const { requestID, originator, permissions } = args ?? ({} as GroupPermissionRequest)
|
|
1313
1398
|
if (!requestID || !permissions) return
|
|
1314
|
-
groupQueue.enqueue({ requestID, originator, permissions })
|
|
1399
|
+
groupQueue.enqueue({ requestID, originator, permissions, manager })
|
|
1315
1400
|
},
|
|
1316
1401
|
[groupQueue.enqueue]
|
|
1317
1402
|
)
|
|
1318
1403
|
|
|
1319
1404
|
// ---- WAB + network + storage configuration ----
|
|
1320
1405
|
const [selectedMethod, setSelectedMethod] = useState<string>('')
|
|
1321
|
-
const [selectedNetwork, setSelectedNetwork] = useState<AppChain>(DEFAULT_CHAIN)
|
|
1406
|
+
const [selectedNetwork, setSelectedNetwork] = useState<AppChain>(e2eSafeChain(DEFAULT_CHAIN))
|
|
1322
1407
|
/**
|
|
1323
1408
|
* The network a build should use, readable without a closure.
|
|
1324
1409
|
*
|
|
@@ -1328,7 +1413,7 @@ export const WalletContextProvider: React.FC<WalletContextProps> = ({ children =
|
|
|
1328
1413
|
* and published it, leaving a mainnet label over a testnet wallet. The state
|
|
1329
1414
|
* is what the UI renders; this ref is what the build reads.
|
|
1330
1415
|
*/
|
|
1331
|
-
const selectedNetworkRef = useRef<AppChain>(DEFAULT_CHAIN)
|
|
1416
|
+
const selectedNetworkRef = useRef<AppChain>(e2eSafeChain(DEFAULT_CHAIN))
|
|
1332
1417
|
selectedNetworkRef.current = selectedNetwork
|
|
1333
1418
|
const [selectedStorageUrl, setSelectedStorageUrl] = useState<string>(DEFAULT_STORAGE_URL)
|
|
1334
1419
|
// Wallet profiles (one mnemonic, many wallets). The store is module state so
|
|
@@ -1374,8 +1459,9 @@ export const WalletContextProvider: React.FC<WalletContextProps> = ({ children =
|
|
|
1374
1459
|
console.error('Network selection is required')
|
|
1375
1460
|
return false
|
|
1376
1461
|
}
|
|
1462
|
+
const chain = e2eSafeChain(network)
|
|
1377
1463
|
setSelectedMethod(method || 'mnemonic')
|
|
1378
|
-
setSelectedNetwork(
|
|
1464
|
+
setSelectedNetwork(chain)
|
|
1379
1465
|
setSelectedStorageUrl(storageUrl || 'local')
|
|
1380
1466
|
setConfigStatus('configured')
|
|
1381
1467
|
return true
|
|
@@ -1430,7 +1516,12 @@ export const WalletContextProvider: React.FC<WalletContextProps> = ({ children =
|
|
|
1430
1516
|
})
|
|
1431
1517
|
await setItem(
|
|
1432
1518
|
'finalConfig',
|
|
1433
|
-
JSON.stringify({
|
|
1519
|
+
JSON.stringify({
|
|
1520
|
+
wabUrl: 'noWAB',
|
|
1521
|
+
method: 'mnemonic',
|
|
1522
|
+
network: e2eSafeChain(DEFAULT_CHAIN),
|
|
1523
|
+
storageUrl: 'local'
|
|
1524
|
+
})
|
|
1434
1525
|
)
|
|
1435
1526
|
}
|
|
1436
1527
|
} else {
|
|
@@ -1443,7 +1534,12 @@ export const WalletContextProvider: React.FC<WalletContextProps> = ({ children =
|
|
|
1443
1534
|
})
|
|
1444
1535
|
await setItem(
|
|
1445
1536
|
'finalConfig',
|
|
1446
|
-
JSON.stringify({
|
|
1537
|
+
JSON.stringify({
|
|
1538
|
+
wabUrl: 'noWAB',
|
|
1539
|
+
method: 'mnemonic',
|
|
1540
|
+
network: e2eSafeChain(DEFAULT_CHAIN),
|
|
1541
|
+
storageUrl: 'local'
|
|
1542
|
+
})
|
|
1447
1543
|
)
|
|
1448
1544
|
}
|
|
1449
1545
|
})()
|
|
@@ -1548,33 +1644,22 @@ export const WalletContextProvider: React.FC<WalletContextProps> = ({ children =
|
|
|
1548
1644
|
)
|
|
1549
1645
|
|
|
1550
1646
|
// Replace all default broadcast providers with EF/rawtx-only services.
|
|
1551
|
-
// Order:
|
|
1647
|
+
// Order: BSV Broadcaster → GorillaPool → WoC → Bitails. UntilSuccess stops at first success.
|
|
1552
1648
|
// Each fallback is registered only where NETWORKS says it serves the
|
|
1553
|
-
// network:
|
|
1649
|
+
// network: GorillaPool on main + test, WhatsOnChain where
|
|
1554
1650
|
// one exists, Bitails on main + test.
|
|
1555
1651
|
// 'ArcadeBeef' is the toolbox's own Arcade broadcaster, registered
|
|
1556
1652
|
// because serviceOptions now carries arcadeUrl (needed for Arcade-first
|
|
1557
1653
|
// proofs and SSE). Our createArcadeBroadcastService replaces it here so
|
|
1558
1654
|
// the same tx is not posted to Arcade twice with two header sets.
|
|
1559
|
-
|
|
1560
|
-
|
|
1561
|
-
|
|
1562
|
-
|
|
1563
|
-
|
|
1564
|
-
|
|
1565
|
-
|
|
1566
|
-
|
|
1567
|
-
services.postBeefServices.add(createTaalBroadcastService(network.taalArcUrl, serviceOptions.taalApiKey))
|
|
1568
|
-
}
|
|
1569
|
-
if (network.gorillaPoolArcUrl) {
|
|
1570
|
-
services.postBeefServices.add(createGorillaPoolBroadcastService(network.gorillaPoolArcUrl))
|
|
1571
|
-
}
|
|
1572
|
-
if (network.woc) {
|
|
1573
|
-
services.postBeefServices.add(createWocBroadcastService(network.woc, serviceOptions.whatsOnChainApiKey))
|
|
1574
|
-
}
|
|
1575
|
-
if (bitailsService && network.bitails) {
|
|
1576
|
-
services.postBeefServices.add({ name: 'Bitails', service: bitailsService.postBeef.bind(bitailsService) })
|
|
1577
|
-
}
|
|
1655
|
+
registerBroadcastProviders(
|
|
1656
|
+
services,
|
|
1657
|
+
network,
|
|
1658
|
+
serviceOptions.arcUrl!,
|
|
1659
|
+
callbackToken,
|
|
1660
|
+
serviceOptions.whatsOnChainApiKey,
|
|
1661
|
+
(services as any).bitails
|
|
1662
|
+
)
|
|
1578
1663
|
|
|
1579
1664
|
// Replace WoC getMerklePath with BUMP endpoint — no TSC→BUMP conversion needed.
|
|
1580
1665
|
// The toolbox's 'Arcade' provider stays where Services put it: first.
|
|
@@ -1958,7 +2043,11 @@ export const WalletContextProvider: React.FC<WalletContextProps> = ({ children =
|
|
|
1958
2043
|
|
|
1959
2044
|
// Create BTMS permission module, wiring in the prompt handler so that
|
|
1960
2045
|
// "p btms" operations surface a UI modal rather than silently denying.
|
|
1961
|
-
|
|
2046
|
+
// Both token-module prompt functions are tied to this build: once its
|
|
2047
|
+
// manager is retired (the wallet was replaced) they resolve false
|
|
2048
|
+
// without enqueueing. The manager below retires them with itself.
|
|
2049
|
+
const buildPrompts = guardTokenPromptHandlers({ btms: btmsPromptHandler, mandala: mandalaPromptHandler })
|
|
2050
|
+
const btmsModule = loadBtmsPermissionModule().createBtmsModule({ wallet, promptHandler: buildPrompts.btms })
|
|
1962
2051
|
|
|
1963
2052
|
// The BRC-207 color module (plan 07 Task 10): all token custody and
|
|
1964
2053
|
// evidence, registered below as `permissionModules.color`, so every
|
|
@@ -1999,7 +2088,7 @@ export const WalletContextProvider: React.FC<WalletContextProps> = ({ children =
|
|
|
1999
2088
|
wallet,
|
|
2000
2089
|
endpoints: mandalaEndpoints,
|
|
2001
2090
|
kv: phoneStorage,
|
|
2002
|
-
requestTokenAccess: createColorAccessPolicy({ adminOriginator, prompt:
|
|
2091
|
+
requestTokenAccess: createColorAccessPolicy({ adminOriginator, prompt: buildPrompts.mandala })
|
|
2003
2092
|
})
|
|
2004
2093
|
} catch (error) {
|
|
2005
2094
|
console.error('[WalletContext] could not build the color module; p color calls will be refused:', error)
|
|
@@ -2008,53 +2097,44 @@ export const WalletContextProvider: React.FC<WalletContextProps> = ({ children =
|
|
|
2008
2097
|
colorModule = colorRef.current?.module
|
|
2009
2098
|
}
|
|
2010
2099
|
|
|
2100
|
+
// The user's stored prompt policy for this profile (spec 6.5), authenticated by the admin
|
|
2101
|
+
// key. It applies from this build on; absent or not authentic means the defaults.
|
|
2102
|
+
const builtPolicy = resolvePermissionPolicy(
|
|
2103
|
+
await loadStoredPolicy(profileScopedKey(''), wallet as never, adminOriginator)
|
|
2104
|
+
)
|
|
2105
|
+
|
|
2011
2106
|
// Setup permissions with provided callbacks and BTMS module.
|
|
2012
2107
|
const permissionsManager = new SigningPolicyPermissionsManager(wallet, adminOriginator, {
|
|
2013
2108
|
differentiatePrivilegedOperations: true,
|
|
2014
|
-
|
|
2015
|
-
|
|
2016
|
-
|
|
2017
|
-
seekCertificateAcquisitionPermissions: false,
|
|
2018
|
-
seekCertificateDisclosurePermissions: false,
|
|
2019
|
-
seekCertificateRelinquishmentPermissions: false,
|
|
2020
|
-
seekCertificateListingPermissions: false,
|
|
2021
|
-
// A site whose manifest declares metanet.groupPermissions is asked
|
|
2022
|
-
// for them all in one sheet during waitForAuthentication. The request
|
|
2023
|
-
// holds that origin's permission lock until answered, so it MUST be
|
|
2024
|
-
// handled (onGroupedPermissionRequested, below) or the site hangs.
|
|
2025
|
-
seekGroupedPermission: true,
|
|
2026
|
-
seekPermissionsForIdentityKeyRevelation: false,
|
|
2027
|
-
seekPermissionsForIdentityResolution: false,
|
|
2028
|
-
seekPermissionsForKeyLinkageRevelation: false,
|
|
2029
|
-
seekPermissionsForPublicKeyRevelation: false,
|
|
2030
|
-
seekPermissionWhenApplyingActionLabels: false,
|
|
2031
|
-
seekPermissionWhenListingActionsByLabel: false,
|
|
2032
|
-
seekProtocolPermissionsForEncrypting: false,
|
|
2033
|
-
seekProtocolPermissionsForHMAC: false,
|
|
2034
|
-
// On, unlike Metanet Desktop: the vault guard no longer refuses
|
|
2035
|
-
// external BRC-29 ([2,'3241645161d8']) signing outright, and that
|
|
2036
|
-
// namespace also derives this wallet's own address-rail keys
|
|
2037
|
-
// (counterparty 'anyone'), so a site signing under it must be
|
|
2038
|
-
// asked first -- for BRC-29, on every signature. BRC-103/104 auth
|
|
2039
|
-
// signing is exempt (SigningPolicyPermissionsManager).
|
|
2040
|
-
seekProtocolPermissionsForSigning: true,
|
|
2041
|
-
seekSpendingPermissions: true,
|
|
2109
|
+
// The prompt settings live in core/bridge/permissionPolicy.ts (default: exactly the
|
|
2110
|
+
// configuration this literal used to hold).
|
|
2111
|
+
...builtPolicy.verified,
|
|
2042
2112
|
permissionModules: colorModule ? { btms: btmsModule, color: colorModule } : { btms: btmsModule }
|
|
2043
2113
|
} as any)
|
|
2044
2114
|
|
|
2045
|
-
|
|
2046
|
-
|
|
2047
|
-
|
|
2048
|
-
|
|
2049
|
-
|
|
2050
|
-
|
|
2051
|
-
|
|
2052
|
-
|
|
2053
|
-
|
|
2054
|
-
|
|
2055
|
-
|
|
2056
|
-
|
|
2115
|
+
permissionsManager.onRetire(buildPrompts.retire)
|
|
2116
|
+
|
|
2117
|
+
const bindPromptCallbacks = (mgr: SigningPolicyPermissionsManager) => {
|
|
2118
|
+
// Bound per manager: each queue item records the manager that raised
|
|
2119
|
+
// it, and the sheet answers that one (see RaisedBy).
|
|
2120
|
+
if (protocolPermissionCallback) {
|
|
2121
|
+
mgr.bindCallback('onProtocolPermissionRequested', (args: any) => protocolPermissionCallback(args, mgr))
|
|
2122
|
+
}
|
|
2123
|
+
if (basketAccessCallback) {
|
|
2124
|
+
mgr.bindCallback('onBasketAccessRequested', (args: any) => basketAccessCallback(args, mgr))
|
|
2125
|
+
}
|
|
2126
|
+
if (spendingAuthorizationCallback) {
|
|
2127
|
+
mgr.bindCallback('onSpendingAuthorizationRequested', (args: any) =>
|
|
2128
|
+
spendingAuthorizationCallback(args, mgr)
|
|
2129
|
+
)
|
|
2130
|
+
}
|
|
2131
|
+
mgr.bindCallback('onGroupedPermissionRequested', ((args: any) => groupedPermissionCallback(args, mgr)) as any)
|
|
2132
|
+
if (certificateAccessCallback) {
|
|
2133
|
+
mgr.bindCallback('onCertificateAccessRequested', (args: any) => certificateAccessCallback(args, mgr))
|
|
2134
|
+
}
|
|
2057
2135
|
}
|
|
2136
|
+
bindPromptCallbacks(permissionsManager)
|
|
2137
|
+
newManagers.signingPermissionsManager = permissionsManager
|
|
2058
2138
|
|
|
2059
2139
|
// Publish one idempotently guarded manager for both trusted in-app
|
|
2060
2140
|
// Vault calls and external WalletClient calls; external call sites may
|
|
@@ -2085,15 +2165,29 @@ export const WalletContextProvider: React.FC<WalletContextProps> = ({ children =
|
|
|
2085
2165
|
// `mandalaRef.current`, whose `undefined` also covers a runtime that
|
|
2086
2166
|
// threw or is mid-rebuild, both of which can leave real journal rows
|
|
2087
2167
|
// unreadable rather than absent.
|
|
2088
|
-
|
|
2089
|
-
|
|
2090
|
-
|
|
2091
|
-
(
|
|
2092
|
-
|
|
2093
|
-
|
|
2094
|
-
|
|
2095
|
-
|
|
2096
|
-
|
|
2168
|
+
// The unverified manager gets the same stack (spec 6.5).
|
|
2169
|
+
const guardedStack = (mgr: SigningPolicyPermissionsManager) =>
|
|
2170
|
+
guardVaultAccess(
|
|
2171
|
+
wrapAbortActionForSettlements(
|
|
2172
|
+
conformWalletResults(adminOriginator, mgr),
|
|
2173
|
+
() => mandalaRef.current?.journal,
|
|
2174
|
+
() => mandalaEndpoints !== undefined
|
|
2175
|
+
),
|
|
2176
|
+
adminOriginator,
|
|
2177
|
+
{ lookup: phoneStorage }
|
|
2178
|
+
)
|
|
2179
|
+
newManagers.permissionsManager = guardedStack(permissionsManager)
|
|
2180
|
+
|
|
2181
|
+
if (hasUnattestedTransport()) {
|
|
2182
|
+
const unverified = buildUnverifiedPermissionsManager(
|
|
2183
|
+
wallet,
|
|
2184
|
+
adminOriginator,
|
|
2185
|
+
effectiveUnverified(builtPolicy)
|
|
2186
|
+
)
|
|
2187
|
+
bindPromptCallbacks(unverified)
|
|
2188
|
+
newManagers.unverifiedSigningPermissionsManager = unverified
|
|
2189
|
+
newManagers.unverifiedPermissionsManager = guardedStack(unverified)
|
|
2190
|
+
}
|
|
2097
2191
|
|
|
2098
2192
|
// THE MANDALA RUNTIME'S ONE CONSTRUCTION SITE.
|
|
2099
2193
|
//
|
|
@@ -3041,6 +3135,10 @@ export const WalletContextProvider: React.FC<WalletContextProps> = ({ children =
|
|
|
3041
3135
|
* anything can resume against the departing wallet.
|
|
3042
3136
|
*/
|
|
3043
3137
|
const teardownBuiltWallet = useCallback(async () => {
|
|
3138
|
+
// Prompts raised by the departing wallet are withdrawn, and its managers
|
|
3139
|
+
// retired, before anything yields: otherwise a sheet for it survives the
|
|
3140
|
+
// switch and answering it throws on the new manager.
|
|
3141
|
+
withdrawCurrentPrompts()
|
|
3044
3142
|
// Invalidate Vault operations before the first teardown await. Otherwise a
|
|
3045
3143
|
// signer/listing already in flight can resume against the departing wallet.
|
|
3046
3144
|
vaultStore.clearScope()
|
|
@@ -3112,6 +3210,9 @@ export const WalletContextProvider: React.FC<WalletContextProps> = ({ children =
|
|
|
3112
3210
|
reviewImportedCoinsRef.current = opts?.reviewImportedCoins === true
|
|
3113
3211
|
// Any build already in flight belongs to the configuration being replaced.
|
|
3114
3212
|
const token = buildGenRef.current.bump()
|
|
3213
|
+
// The bridge's bindings and published managers belong to the wallet being torn down: close
|
|
3214
|
+
// and drop them before anything yields (spec G9), not when the next build publishes.
|
|
3215
|
+
runSessionTeardown('rebuild')
|
|
3115
3216
|
await teardownBuiltWallet()
|
|
3116
3217
|
|
|
3117
3218
|
// Re-finalize with current config — triggers auto-build effect
|
|
@@ -3133,6 +3234,20 @@ export const WalletContextProvider: React.FC<WalletContextProps> = ({ children =
|
|
|
3133
3234
|
[selectedNetwork, teardownBuiltWallet, finalizeConfig, waitForRebuild]
|
|
3134
3235
|
)
|
|
3135
3236
|
|
|
3237
|
+
// A transport that can deliver unattested calls registered after this wallet was built: the
|
|
3238
|
+
// unverified manager is made in the build, so build again to get it (spec 6.5). Normally the
|
|
3239
|
+
// provider registers before the first build and this never fires.
|
|
3240
|
+
const rebuildWalletRef = useRef(rebuildWallet)
|
|
3241
|
+
rebuildWalletRef.current = rebuildWallet
|
|
3242
|
+
useEffect(
|
|
3243
|
+
() =>
|
|
3244
|
+
onUnattestedTransportChange(present => {
|
|
3245
|
+
if (!present || !walletBuiltRef.current || managersRef.current.unverifiedPermissionsManager) return
|
|
3246
|
+
void rebuildWalletRef.current().catch(() => {})
|
|
3247
|
+
}),
|
|
3248
|
+
[]
|
|
3249
|
+
)
|
|
3250
|
+
|
|
3136
3251
|
// Switch network: tear down wallet, update config, and rebuild on new chain.
|
|
3137
3252
|
// The network belongs to the active profile, so this changes that profile's.
|
|
3138
3253
|
//
|
|
@@ -3142,9 +3257,12 @@ export const WalletContextProvider: React.FC<WalletContextProps> = ({ children =
|
|
|
3142
3257
|
// strands the user on an unusable wallet. Switching again retries.
|
|
3143
3258
|
const switchNetwork = useCallback(
|
|
3144
3259
|
async (network: AppChain, opts: { fallback?: boolean } = {}) => {
|
|
3260
|
+
// The harness cannot be moved onto mainnet, whatever asked.
|
|
3261
|
+
if (e2eSafeChain(network) !== network) return
|
|
3145
3262
|
// The ref, not the state: the fallback below runs inside the same call.
|
|
3146
3263
|
const from = selectedNetworkRef.current
|
|
3147
3264
|
if (network === from || switchInFlightRef.current) return
|
|
3265
|
+
runSessionTeardown('network')
|
|
3148
3266
|
logWithTimestamp(F, `Switching network from ${from} to ${network}`)
|
|
3149
3267
|
const token = buildGenRef.current.bump()
|
|
3150
3268
|
// Same hold-off as switchProfile: no build may start on the old network
|
|
@@ -3226,7 +3344,7 @@ export const WalletContextProvider: React.FC<WalletContextProps> = ({ children =
|
|
|
3226
3344
|
let __tBuild = 0
|
|
3227
3345
|
try {
|
|
3228
3346
|
// Pairings belong to the departing identity.
|
|
3229
|
-
|
|
3347
|
+
runSessionTeardown('profile')
|
|
3230
3348
|
profileTransitionRef.current = true
|
|
3231
3349
|
try {
|
|
3232
3350
|
await teardownBuiltWallet()
|
|
@@ -3920,7 +4038,8 @@ export const WalletContextProvider: React.FC<WalletContextProps> = ({ children =
|
|
|
3920
4038
|
// XR-018: a live paired RPC socket otherwise outlives logout/wallet
|
|
3921
4039
|
// deletion — the peer would keep dispatching allowlisted BRC-100 methods
|
|
3922
4040
|
// against a wallet the user believes they've logged out of.
|
|
3923
|
-
|
|
4041
|
+
runSessionTeardown('logout')
|
|
4042
|
+
withdrawCurrentPrompts()
|
|
3924
4043
|
// The IIFE's promise IS returned (unlike the old fire-and-forget version):
|
|
3925
4044
|
// XR-107 needs the caller to await the verified outcome of the secret
|
|
3926
4045
|
// erasure below, not just the synchronous kickoff. This does not
|
|
@@ -4589,13 +4708,15 @@ export const WalletContextProvider: React.FC<WalletContextProps> = ({ children =
|
|
|
4589
4708
|
groupRequests: groupQueue.requests,
|
|
4590
4709
|
btmsRequests: btmsQueue.requests,
|
|
4591
4710
|
mandalaRequests: mandalaQueue.requests,
|
|
4592
|
-
advanceBasketQueue
|
|
4593
|
-
advanceCertificateQueue
|
|
4594
|
-
advanceProtocolQueue
|
|
4595
|
-
advanceSpendingQueue
|
|
4596
|
-
advanceGroupQueue
|
|
4711
|
+
advanceBasketQueue,
|
|
4712
|
+
advanceCertificateQueue,
|
|
4713
|
+
advanceProtocolQueue,
|
|
4714
|
+
advanceSpendingQueue,
|
|
4715
|
+
advanceGroupQueue,
|
|
4597
4716
|
advanceBtmsQueue,
|
|
4598
4717
|
advanceMandalaQueue,
|
|
4718
|
+
withdrawPrompts,
|
|
4719
|
+
registerPromptWithdrawal,
|
|
4599
4720
|
finalizeConfig,
|
|
4600
4721
|
setConfigStatus,
|
|
4601
4722
|
configStatus,
|
|
@@ -4649,13 +4770,15 @@ export const WalletContextProvider: React.FC<WalletContextProps> = ({ children =
|
|
|
4649
4770
|
groupQueue.requests,
|
|
4650
4771
|
btmsQueue.requests,
|
|
4651
4772
|
mandalaQueue.requests,
|
|
4652
|
-
|
|
4653
|
-
|
|
4654
|
-
|
|
4655
|
-
|
|
4656
|
-
|
|
4773
|
+
advanceBasketQueue,
|
|
4774
|
+
advanceCertificateQueue,
|
|
4775
|
+
advanceProtocolQueue,
|
|
4776
|
+
advanceSpendingQueue,
|
|
4777
|
+
advanceGroupQueue,
|
|
4657
4778
|
advanceBtmsQueue,
|
|
4658
4779
|
advanceMandalaQueue,
|
|
4780
|
+
withdrawPrompts,
|
|
4781
|
+
registerPromptWithdrawal,
|
|
4659
4782
|
finalizeConfig,
|
|
4660
4783
|
setConfigStatus,
|
|
4661
4784
|
configStatus,
|
|
@@ -4760,11 +4883,11 @@ export interface WalletQueuesSlice {
|
|
|
4760
4883
|
groupRequests: GroupPermissionRequest[]
|
|
4761
4884
|
btmsRequests: BtmsRequest[]
|
|
4762
4885
|
mandalaRequests: MandalaRequest[]
|
|
4763
|
-
advanceBasketQueue: () => void
|
|
4764
|
-
advanceCertificateQueue: () => void
|
|
4765
|
-
advanceProtocolQueue: () => void
|
|
4766
|
-
advanceSpendingQueue: () => void
|
|
4767
|
-
advanceGroupQueue: () => void
|
|
4886
|
+
advanceBasketQueue: (requestID?: string) => void
|
|
4887
|
+
advanceCertificateQueue: (requestID?: string) => void
|
|
4888
|
+
advanceProtocolQueue: (requestID?: string) => void
|
|
4889
|
+
advanceSpendingQueue: (requestID?: string) => void
|
|
4890
|
+
advanceGroupQueue: (requestID?: string) => void
|
|
4768
4891
|
advanceBtmsQueue: (approved: boolean) => void
|
|
4769
4892
|
advanceMandalaQueue: (approved: boolean) => void
|
|
4770
4893
|
}
|