@bsv/expo-wallet-toolbox 0.1.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/LICENSE.txt +28 -0
- package/README.md +512 -0
- package/assets/sounds/payment-receive.wav +0 -0
- package/assets/sounds/payment-send.wav +0 -0
- package/assets/sounds/vault-close.wav +0 -0
- package/assets/sounds/vault-open.wav +0 -0
- package/core/amountFormatHelpers.ts +330 -0
- package/core/backup/RemoteSyncReader.ts +94 -0
- package/core/backup/client.ts +111 -0
- package/core/backup/codec.ts +218 -0
- package/core/backup/constants.ts +88 -0
- package/core/backup/cursor.ts +138 -0
- package/core/backup/derive.ts +46 -0
- package/core/backup/deviceId.ts +33 -0
- package/core/backup/erase.ts +67 -0
- package/core/backup/preference.ts +33 -0
- package/core/backup/push.ts +295 -0
- package/core/backup/restore.ts +152 -0
- package/core/backup/restoreOnImport.ts +119 -0
- package/core/backup/status.ts +46 -0
- package/core/config.tsx +47 -0
- package/core/constants.ts +35 -0
- package/core/context/ExchangeRateContext.tsx +69 -0
- package/core/context/LocalStorageProvider.tsx +225 -0
- package/core/context/UserContext.tsx +129 -0
- package/core/context/VaultContext.tsx +79 -0
- package/core/context/WalletConnectionContext.tsx +454 -0
- package/core/context/WalletContext.tsx +2938 -0
- package/core/context/buildGeneration.ts +37 -0
- package/core/deviceTier.ts +89 -0
- package/core/diskSpace.ts +62 -0
- package/core/displayCurrencies.ts +56 -0
- package/core/headers/OfflineFirstChaintracks.ts +176 -0
- package/core/headers/checkpoints.ts +39 -0
- package/core/headers/fs.ts +119 -0
- package/core/headers/headerStore.ts +333 -0
- package/core/headers/prewarm.ts +36 -0
- package/core/headers/syncHeaders.ts +73 -0
- package/core/hooks/useConfirmationSound.ts +135 -0
- package/core/hooks/useHaptics.ts +51 -0
- package/core/hooks/usePermissionQueue.ts +69 -0
- package/core/i18n/translations.tsx +6692 -0
- package/core/index.ts +295 -0
- package/core/localpay/blePermissions.ts +32 -0
- package/core/localpay/build.ts +392 -0
- package/core/localpay/codec.ts +338 -0
- package/core/localpay/deviceCaps.ts +175 -0
- package/core/localpay/nearbyAdvisory.ts +32 -0
- package/core/localpay/nearbyPermissions.ts +34 -0
- package/core/localpay/pending.ts +385 -0
- package/core/localpay/pendingAborts.ts +67 -0
- package/core/localpay/qr.ts +16 -0
- package/core/localpay/session.ts +277 -0
- package/core/localpay/sessionPolicy.ts +5 -0
- package/core/localpay/transport/awdl.ts +11 -0
- package/core/localpay/transport/ble.ts +159 -0
- package/core/localpay/transport/nearby.ts +12 -0
- package/core/localpay/transport/race.ts +110 -0
- package/core/localpay/transport/select.ts +128 -0
- package/core/localpay/transport/socket.ts +244 -0
- package/core/localpay/types.ts +82 -0
- package/core/localpay/verify.ts +204 -0
- package/core/logging.config.ts +10 -0
- package/core/logging.ts +77 -0
- package/core/mnemonicWallet.ts +180 -0
- package/core/monitor/TaskBackupPush.ts +168 -0
- package/core/monitor/TaskCreditInbox.ts +116 -0
- package/core/monitor/TaskDrainOutbox.ts +122 -0
- package/core/monitor/TaskSendOffline.ts +123 -0
- package/core/monitor/unfailRetry.ts +116 -0
- package/core/net/chainMatch.ts +34 -0
- package/core/net/online.ts +34 -0
- package/core/offline/cancelParked.ts +56 -0
- package/core/offline/hold.ts +127 -0
- package/core/offline/order.ts +109 -0
- package/core/offline/payerHold.ts +144 -0
- package/core/offline/plan.ts +264 -0
- package/core/offline/queueGrace.ts +52 -0
- package/core/parsePeerPayURI.ts +119 -0
- package/core/pay/beefRepair.ts +106 -0
- package/core/pay/creditErrors.ts +46 -0
- package/core/pay/creditInbox.ts +202 -0
- package/core/pay/damagedInbox.ts +64 -0
- package/core/pay/proofNudge.ts +23 -0
- package/core/pay/provenTxFromBump.ts +31 -0
- package/core/pay/rails/address.ts +329 -0
- package/core/pay/rails/handle.ts +617 -0
- package/core/pay/rails/index.ts +197 -0
- package/core/pay/rails/nearby.ts +79 -0
- package/core/pay/receiveFocus.ts +13 -0
- package/core/pay/recordProof.ts +91 -0
- package/core/pay/refreshProofGuard.ts +34 -0
- package/core/pay/sweeper.ts +75 -0
- package/core/pay/tokenAmount.ts +18 -0
- package/core/pay/userError.ts +18 -0
- package/core/pay/watchlist.ts +126 -0
- package/core/peerpay/control.ts +122 -0
- package/core/peerpay/handleResendRequests.ts +475 -0
- package/core/peerpay/inboxAttempts.ts +33 -0
- package/core/peerpay/metadataDecryptor.ts +42 -0
- package/core/peerpay/offlineNacks.ts +96 -0
- package/core/peerpay/outbox.ts +209 -0
- package/core/peerpay/rebuildToken.ts +76 -0
- package/core/peerpay/resendBeef.ts +115 -0
- package/core/services/arcadeBroadcastProvider.ts +214 -0
- package/core/services/capWalletArgs.ts +99 -0
- package/core/services/exchangeRate.ts +63 -0
- package/core/services/secrets/envelope.ts +102 -0
- package/core/services/secrets/hkdf.ts +37 -0
- package/core/services/secrets/index.ts +63 -0
- package/core/services/secrets/kek.ts +274 -0
- package/core/services/secrets/migration.ts +188 -0
- package/core/services/secrets/policy.ts +120 -0
- package/core/services/secrets/storage.ts +54 -0
- package/core/services/secrets/store.ts +125 -0
- package/core/services/secrets/types.ts +85 -0
- package/core/services/usdFxRates.ts +101 -0
- package/core/services/vault/VaultKeyService.ts +312 -0
- package/core/services/vault/backupAttestation.ts +136 -0
- package/core/services/vault/ceremony.ts +972 -0
- package/core/services/vault/ceremonyHost.ts +46 -0
- package/core/services/vault/devMock.ts +22 -0
- package/core/services/vault/driver.ts +197 -0
- package/core/services/vault/guard.ts +90 -0
- package/core/services/vault/k1.ts +75 -0
- package/core/services/vault/mockYubiKey.ts +217 -0
- package/core/services/vault/random.ts +20 -0
- package/core/services/vault/sealing.ts +84 -0
- package/core/services/vault/session.ts +59 -0
- package/core/services/vault/transfers.ts +1151 -0
- package/core/services/vault/types.ts +109 -0
- package/core/services/vault/vaultDerivation.ts +152 -0
- package/core/services/vault/vaultPassphrase.ts +287 -0
- package/core/services/vault/vaultStore.ts +104 -0
- package/core/services/walletArgLimits.ts +234 -0
- package/core/services/walletServiceConfig.ts +170 -0
- package/core/storage/LocalStorageAdapter.ts +58 -0
- package/core/storage/README.md +391 -0
- package/core/storage/StorageExpoSQLite.ts +2008 -0
- package/core/storage/errors.ts +73 -0
- package/core/storage/index.ts +3 -0
- package/core/storage/methods/findSql.ts +286 -0
- package/core/storage/methods/historyNotes.ts +61 -0
- package/core/storage/methods/listActionsSql.ts +212 -0
- package/core/storage/methods/listOutputsSql.ts +211 -0
- package/core/storage/methods/offlineActions.ts +156 -0
- package/core/storage/methods/processOfflineActions.ts +503 -0
- package/core/storage/methods/reclaim.ts +135 -0
- package/core/storage/methods/reviewStatusSql.ts +167 -0
- package/core/storage/methods/unprovenWithoutReqSql.ts +26 -0
- package/core/storage/methods/walletBalanceSql.ts +55 -0
- package/core/storage/schema/createTables.ts +385 -0
- package/core/storage/skipQueuedAncestors.ts +29 -0
- package/core/storage/sqlUpdateValue.ts +12 -0
- package/core/stores/ConnectionStore.ts +71 -0
- package/core/theme/ThemeContext.tsx +182 -0
- package/core/theme/assertThemeContrast.ts +109 -0
- package/core/theme/motion.ts +50 -0
- package/core/theme/tokens.ts +232 -0
- package/core/theme/useThemeStyles.tsx +156 -0
- package/core/walletDbRegistry.ts +110 -0
- package/core/walletMonitor.ts +149 -0
- package/core/walletRepair/runWalletCheck.ts +195 -0
- package/core/walletRepair/shouldReleaseUtxo.ts +18 -0
- package/package.json +86 -0
- package/ui/backupShares.ts +367 -0
- package/ui/components/QRScanner.tsx +353 -0
- package/ui/components/pay/AddressReceive.tsx +507 -0
- package/ui/components/pay/AvailableBalance.tsx +61 -0
- package/ui/components/pay/HandleReceive.tsx +896 -0
- package/ui/components/pay/MessageBoxConfig.tsx +256 -0
- package/ui/components/pay/NearbyAdvisoryModal.tsx +111 -0
- package/ui/components/pay/NearbyFlow.tsx +2542 -0
- package/ui/components/pay/OfflineNotice.tsx +337 -0
- package/ui/components/pay/PayCellRow.tsx +101 -0
- package/ui/components/pay/PayForm.tsx +223 -0
- package/ui/components/pay/PaymentQrDisplay.tsx +105 -0
- package/ui/components/pay/PaymentSuccessOverlay.tsx +266 -0
- package/ui/components/pay/RecipientField.tsx +308 -0
- package/ui/components/pay/RequestHub.tsx +75 -0
- package/ui/components/pay/ResultBanner.tsx +69 -0
- package/ui/components/pay/UniversalSend.tsx +687 -0
- package/ui/components/pay/useRecipientInput.ts +270 -0
- package/ui/components/security/WalletLockNotice.tsx +138 -0
- package/ui/components/ui/AlertCard.tsx +223 -0
- package/ui/components/ui/AppLogo.tsx +166 -0
- package/ui/components/ui/BlurChrome.tsx +72 -0
- package/ui/components/ui/Celebration.tsx +84 -0
- package/ui/components/ui/ChoiceSheet.ts +69 -0
- package/ui/components/ui/CustomSafeArea.tsx +74 -0
- package/ui/components/ui/ErrorBoundary.tsx +154 -0
- package/ui/components/ui/GroupedList.tsx +125 -0
- package/ui/components/ui/IconButton.tsx +105 -0
- package/ui/components/ui/ListRow.tsx +197 -0
- package/ui/components/ui/PermissionSheet.tsx +920 -0
- package/ui/components/ui/PresenceRow.tsx +215 -0
- package/ui/components/ui/PressableScale.tsx +105 -0
- package/ui/components/ui/ScreenGradient.tsx +47 -0
- package/ui/components/ui/ScrollFade.tsx +76 -0
- package/ui/components/ui/Sheet.tsx +342 -0
- package/ui/components/ui/Toast.tsx +142 -0
- package/ui/components/ui/index.ts +8 -0
- package/ui/components/vault/EnrollWizard.tsx +627 -0
- package/ui/components/vault/PassphraseField.tsx +306 -0
- package/ui/components/vault/PhraseBackupSheet.tsx +227 -0
- package/ui/components/vault/VaultBackdrop.tsx +354 -0
- package/ui/components/vault/VaultCeremonySheet.tsx +327 -0
- package/ui/components/wallet/ActivityRow.tsx +408 -0
- package/ui/components/wallet/AmountDisplay.tsx +48 -0
- package/ui/components/wallet/AmountInput.tsx +256 -0
- package/ui/components/wallet/BackupReminderSheet.tsx +168 -0
- package/ui/components/wallet/Balance.tsx +144 -0
- package/ui/components/wallet/BiometricAdvisoryModal.tsx +133 -0
- package/ui/components/wallet/ImportFromBackupPrompt.tsx +93 -0
- package/ui/exportDatabases.ts +122 -0
- package/ui/exportTransactions.ts +129 -0
- package/ui/hooks/useOfflineNoticeActions.ts +136 -0
- package/ui/hooks/useOnline.ts +70 -0
- package/ui/hooks/useSpendableBalance.ts +58 -0
- package/ui/hooks/useVaultBalance.ts +50 -0
- package/ui/importDatabases.ts +170 -0
- package/ui/index.ts +136 -0
- package/ui/isImageUrl.ts +10 -0
- package/ui/printRecoveryShares.ts +93 -0
- package/ui/resolveIdentity.ts +125 -0
- package/ui/screens/ConnectionsScreen.tsx +438 -0
- package/ui/screens/LogsScreen.tsx +432 -0
- package/ui/screens/PairScreen.tsx +288 -0
- package/ui/screens/PayScreen.tsx +479 -0
- package/ui/screens/SettingsScreen.tsx +180 -0
- package/ui/screens/TrustScreen.tsx +831 -0
- package/ui/screens/VaultRecoverScreen.tsx +226 -0
- package/ui/screens/VaultScreen.tsx +423 -0
- package/ui/screens/VaultTransferScreen.tsx +293 -0
- package/ui/screens/WalletCheckScreen.tsx +539 -0
- package/ui/screens/WalletConfigScreen.tsx +1095 -0
- package/ui/screens/WalletHomeScreen.tsx +1597 -0
- package/ui/screens/homeBadges.ts +18 -0
- package/ui/txStatus.ts +79 -0
- package/ui/validateTrust.ts +44 -0
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Did this wallet's owner back up?
|
|
3
|
+
*
|
|
4
|
+
* This is an ADVISORY record, not a security control. It stores the fact that
|
|
5
|
+
* a user pressed "I have written these down" or completed a print — nothing
|
|
6
|
+
* verifies that paper exists. It gates the vault because inviting someone to
|
|
7
|
+
* lock funds behind a hardware key with no recovery path is a lie, not because
|
|
8
|
+
* the flag protects anything.
|
|
9
|
+
*
|
|
10
|
+
* Scoped per wallet identity ON PURPOSE. Logout clears only four keys and
|
|
11
|
+
* "Delete Wallet" is wired straight to logout(), so a global key would survive
|
|
12
|
+
* a wipe and the next wallet on the device would be born already backed up.
|
|
13
|
+
*
|
|
14
|
+
* Follows vaultStore's conventions: a frozen object literal with async
|
|
15
|
+
* accessors, a numeric `v` discriminant, and getters that swallow parse errors
|
|
16
|
+
* and return null instead of throwing.
|
|
17
|
+
*/
|
|
18
|
+
import AsyncStorage from '@react-native-async-storage/async-storage'
|
|
19
|
+
|
|
20
|
+
export const ATTEST_KEY_PREFIX = 'vault_backup_attest_v1_'
|
|
21
|
+
|
|
22
|
+
export type BackupMedium = 'phrase' | 'shares'
|
|
23
|
+
|
|
24
|
+
export interface BackupAttestation {
|
|
25
|
+
v: 1
|
|
26
|
+
/** Which route the user took. Both are equivalent for recovery. */
|
|
27
|
+
medium: BackupMedium
|
|
28
|
+
at: number
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/** Last 8 hex chars of the identity key — the app's established scope suffix. */
|
|
32
|
+
const scopeKey = (identityKey: string): string => ATTEST_KEY_PREFIX + identityKey.slice(-8)
|
|
33
|
+
|
|
34
|
+
export const backupAttestation = {
|
|
35
|
+
async get(identityKey: string): Promise<BackupAttestation | null> {
|
|
36
|
+
const raw = await AsyncStorage.getItem(scopeKey(identityKey))
|
|
37
|
+
if (!raw) return null
|
|
38
|
+
try {
|
|
39
|
+
const parsed = JSON.parse(raw) as BackupAttestation
|
|
40
|
+
return parsed?.v === 1 ? parsed : null
|
|
41
|
+
} catch {
|
|
42
|
+
return null
|
|
43
|
+
}
|
|
44
|
+
},
|
|
45
|
+
|
|
46
|
+
async set(identityKey: string, medium: BackupMedium): Promise<void> {
|
|
47
|
+
const record: BackupAttestation = { v: 1, medium, at: Date.now() }
|
|
48
|
+
await AsyncStorage.setItem(scopeKey(identityKey), JSON.stringify(record))
|
|
49
|
+
},
|
|
50
|
+
|
|
51
|
+
async clear(identityKey: string): Promise<void> {
|
|
52
|
+
await AsyncStorage.removeItem(scopeKey(identityKey))
|
|
53
|
+
},
|
|
54
|
+
|
|
55
|
+
/** Logout has no identity key to hand, so sweep the prefix. */
|
|
56
|
+
async clearAll(): Promise<void> {
|
|
57
|
+
const keys = await AsyncStorage.getAllKeys()
|
|
58
|
+
const mine = keys.filter(k => k.startsWith(ATTEST_KEY_PREFIX))
|
|
59
|
+
if (mine.length > 0) await AsyncStorage.multiRemove(mine)
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* The wallet surface needed to scope an attestation. Structural on purpose:
|
|
65
|
+
* both call sites hold a WalletPermissionsManager, but this module only ever
|
|
66
|
+
* needs the identity key.
|
|
67
|
+
*/
|
|
68
|
+
export interface AttestationIdentitySource {
|
|
69
|
+
getPublicKey(args: unknown, originator: string): Promise<{ publicKey: string }>
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
/**
|
|
73
|
+
* Resolve the wallet identity that scopes an attestation, on demand.
|
|
74
|
+
*
|
|
75
|
+
* On demand rather than from cached state: a screen that reads a key populated
|
|
76
|
+
* by a mount effect can act before that effect resolves, and would then skip
|
|
77
|
+
* the write silently.
|
|
78
|
+
*
|
|
79
|
+
* Guarded — a rejecting getPublicKey (managers not ready, permission denied)
|
|
80
|
+
* resolves to null rather than propagating. Callers treat null as "cannot
|
|
81
|
+
* attest right now"; an unguarded rejection would surface as an unhandled
|
|
82
|
+
* promise instead of something the user can see.
|
|
83
|
+
*/
|
|
84
|
+
export async function resolveAttestationIdentity(
|
|
85
|
+
wallet: AttestationIdentitySource | null | undefined,
|
|
86
|
+
adminOriginator: string
|
|
87
|
+
): Promise<string | null> {
|
|
88
|
+
try {
|
|
89
|
+
const r = await wallet?.getPublicKey({ identityKey: true }, adminOriginator)
|
|
90
|
+
return r?.publicKey || null
|
|
91
|
+
} catch (err) {
|
|
92
|
+
console.warn('[backupAttestation] identity lookup failed:', err)
|
|
93
|
+
return null
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
/** This wallet's attestation, or null when there is none — or no identity yet. */
|
|
98
|
+
export async function readBackupAttestation(
|
|
99
|
+
wallet: AttestationIdentitySource | null | undefined,
|
|
100
|
+
adminOriginator: string
|
|
101
|
+
): Promise<BackupAttestation | null> {
|
|
102
|
+
const identityKey = await resolveAttestationIdentity(wallet, adminOriginator)
|
|
103
|
+
if (!identityKey) return null
|
|
104
|
+
try {
|
|
105
|
+
return await backupAttestation.get(identityKey)
|
|
106
|
+
} catch (err) {
|
|
107
|
+
console.warn('[backupAttestation] read failed:', err)
|
|
108
|
+
return null
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
/**
|
|
113
|
+
* Record that the user backed up. The single writer — every surface that can
|
|
114
|
+
* satisfy the vault's backup prerequisite goes through here, so the guard
|
|
115
|
+
* against an unresolved identity cannot drift between them.
|
|
116
|
+
*
|
|
117
|
+
* Returns false when nothing was persisted, and NEVER throws. Callers must
|
|
118
|
+
* surface a false: treating it as success tells the user they are backed up
|
|
119
|
+
* while the deposit gate still refuses them, with nothing on screen to explain
|
|
120
|
+
* why.
|
|
121
|
+
*/
|
|
122
|
+
export async function recordBackupAttestation(
|
|
123
|
+
wallet: AttestationIdentitySource | null | undefined,
|
|
124
|
+
adminOriginator: string,
|
|
125
|
+
medium: BackupMedium
|
|
126
|
+
): Promise<boolean> {
|
|
127
|
+
const identityKey = await resolveAttestationIdentity(wallet, adminOriginator)
|
|
128
|
+
if (!identityKey) return false
|
|
129
|
+
try {
|
|
130
|
+
await backupAttestation.set(identityKey, medium)
|
|
131
|
+
return true
|
|
132
|
+
} catch (err) {
|
|
133
|
+
console.warn('[backupAttestation] write failed:', err)
|
|
134
|
+
return false
|
|
135
|
+
}
|
|
136
|
+
}
|