@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.
Files changed (240) hide show
  1. package/LICENSE.txt +28 -0
  2. package/README.md +512 -0
  3. package/assets/sounds/payment-receive.wav +0 -0
  4. package/assets/sounds/payment-send.wav +0 -0
  5. package/assets/sounds/vault-close.wav +0 -0
  6. package/assets/sounds/vault-open.wav +0 -0
  7. package/core/amountFormatHelpers.ts +330 -0
  8. package/core/backup/RemoteSyncReader.ts +94 -0
  9. package/core/backup/client.ts +111 -0
  10. package/core/backup/codec.ts +218 -0
  11. package/core/backup/constants.ts +88 -0
  12. package/core/backup/cursor.ts +138 -0
  13. package/core/backup/derive.ts +46 -0
  14. package/core/backup/deviceId.ts +33 -0
  15. package/core/backup/erase.ts +67 -0
  16. package/core/backup/preference.ts +33 -0
  17. package/core/backup/push.ts +295 -0
  18. package/core/backup/restore.ts +152 -0
  19. package/core/backup/restoreOnImport.ts +119 -0
  20. package/core/backup/status.ts +46 -0
  21. package/core/config.tsx +47 -0
  22. package/core/constants.ts +35 -0
  23. package/core/context/ExchangeRateContext.tsx +69 -0
  24. package/core/context/LocalStorageProvider.tsx +225 -0
  25. package/core/context/UserContext.tsx +129 -0
  26. package/core/context/VaultContext.tsx +79 -0
  27. package/core/context/WalletConnectionContext.tsx +454 -0
  28. package/core/context/WalletContext.tsx +2938 -0
  29. package/core/context/buildGeneration.ts +37 -0
  30. package/core/deviceTier.ts +89 -0
  31. package/core/diskSpace.ts +62 -0
  32. package/core/displayCurrencies.ts +56 -0
  33. package/core/headers/OfflineFirstChaintracks.ts +176 -0
  34. package/core/headers/checkpoints.ts +39 -0
  35. package/core/headers/fs.ts +119 -0
  36. package/core/headers/headerStore.ts +333 -0
  37. package/core/headers/prewarm.ts +36 -0
  38. package/core/headers/syncHeaders.ts +73 -0
  39. package/core/hooks/useConfirmationSound.ts +135 -0
  40. package/core/hooks/useHaptics.ts +51 -0
  41. package/core/hooks/usePermissionQueue.ts +69 -0
  42. package/core/i18n/translations.tsx +6692 -0
  43. package/core/index.ts +295 -0
  44. package/core/localpay/blePermissions.ts +32 -0
  45. package/core/localpay/build.ts +392 -0
  46. package/core/localpay/codec.ts +338 -0
  47. package/core/localpay/deviceCaps.ts +175 -0
  48. package/core/localpay/nearbyAdvisory.ts +32 -0
  49. package/core/localpay/nearbyPermissions.ts +34 -0
  50. package/core/localpay/pending.ts +385 -0
  51. package/core/localpay/pendingAborts.ts +67 -0
  52. package/core/localpay/qr.ts +16 -0
  53. package/core/localpay/session.ts +277 -0
  54. package/core/localpay/sessionPolicy.ts +5 -0
  55. package/core/localpay/transport/awdl.ts +11 -0
  56. package/core/localpay/transport/ble.ts +159 -0
  57. package/core/localpay/transport/nearby.ts +12 -0
  58. package/core/localpay/transport/race.ts +110 -0
  59. package/core/localpay/transport/select.ts +128 -0
  60. package/core/localpay/transport/socket.ts +244 -0
  61. package/core/localpay/types.ts +82 -0
  62. package/core/localpay/verify.ts +204 -0
  63. package/core/logging.config.ts +10 -0
  64. package/core/logging.ts +77 -0
  65. package/core/mnemonicWallet.ts +180 -0
  66. package/core/monitor/TaskBackupPush.ts +168 -0
  67. package/core/monitor/TaskCreditInbox.ts +116 -0
  68. package/core/monitor/TaskDrainOutbox.ts +122 -0
  69. package/core/monitor/TaskSendOffline.ts +123 -0
  70. package/core/monitor/unfailRetry.ts +116 -0
  71. package/core/net/chainMatch.ts +34 -0
  72. package/core/net/online.ts +34 -0
  73. package/core/offline/cancelParked.ts +56 -0
  74. package/core/offline/hold.ts +127 -0
  75. package/core/offline/order.ts +109 -0
  76. package/core/offline/payerHold.ts +144 -0
  77. package/core/offline/plan.ts +264 -0
  78. package/core/offline/queueGrace.ts +52 -0
  79. package/core/parsePeerPayURI.ts +119 -0
  80. package/core/pay/beefRepair.ts +106 -0
  81. package/core/pay/creditErrors.ts +46 -0
  82. package/core/pay/creditInbox.ts +202 -0
  83. package/core/pay/damagedInbox.ts +64 -0
  84. package/core/pay/proofNudge.ts +23 -0
  85. package/core/pay/provenTxFromBump.ts +31 -0
  86. package/core/pay/rails/address.ts +329 -0
  87. package/core/pay/rails/handle.ts +617 -0
  88. package/core/pay/rails/index.ts +197 -0
  89. package/core/pay/rails/nearby.ts +79 -0
  90. package/core/pay/receiveFocus.ts +13 -0
  91. package/core/pay/recordProof.ts +91 -0
  92. package/core/pay/refreshProofGuard.ts +34 -0
  93. package/core/pay/sweeper.ts +75 -0
  94. package/core/pay/tokenAmount.ts +18 -0
  95. package/core/pay/userError.ts +18 -0
  96. package/core/pay/watchlist.ts +126 -0
  97. package/core/peerpay/control.ts +122 -0
  98. package/core/peerpay/handleResendRequests.ts +475 -0
  99. package/core/peerpay/inboxAttempts.ts +33 -0
  100. package/core/peerpay/metadataDecryptor.ts +42 -0
  101. package/core/peerpay/offlineNacks.ts +96 -0
  102. package/core/peerpay/outbox.ts +209 -0
  103. package/core/peerpay/rebuildToken.ts +76 -0
  104. package/core/peerpay/resendBeef.ts +115 -0
  105. package/core/services/arcadeBroadcastProvider.ts +214 -0
  106. package/core/services/capWalletArgs.ts +99 -0
  107. package/core/services/exchangeRate.ts +63 -0
  108. package/core/services/secrets/envelope.ts +102 -0
  109. package/core/services/secrets/hkdf.ts +37 -0
  110. package/core/services/secrets/index.ts +63 -0
  111. package/core/services/secrets/kek.ts +274 -0
  112. package/core/services/secrets/migration.ts +188 -0
  113. package/core/services/secrets/policy.ts +120 -0
  114. package/core/services/secrets/storage.ts +54 -0
  115. package/core/services/secrets/store.ts +125 -0
  116. package/core/services/secrets/types.ts +85 -0
  117. package/core/services/usdFxRates.ts +101 -0
  118. package/core/services/vault/VaultKeyService.ts +312 -0
  119. package/core/services/vault/backupAttestation.ts +136 -0
  120. package/core/services/vault/ceremony.ts +972 -0
  121. package/core/services/vault/ceremonyHost.ts +46 -0
  122. package/core/services/vault/devMock.ts +22 -0
  123. package/core/services/vault/driver.ts +197 -0
  124. package/core/services/vault/guard.ts +90 -0
  125. package/core/services/vault/k1.ts +75 -0
  126. package/core/services/vault/mockYubiKey.ts +217 -0
  127. package/core/services/vault/random.ts +20 -0
  128. package/core/services/vault/sealing.ts +84 -0
  129. package/core/services/vault/session.ts +59 -0
  130. package/core/services/vault/transfers.ts +1151 -0
  131. package/core/services/vault/types.ts +109 -0
  132. package/core/services/vault/vaultDerivation.ts +152 -0
  133. package/core/services/vault/vaultPassphrase.ts +287 -0
  134. package/core/services/vault/vaultStore.ts +104 -0
  135. package/core/services/walletArgLimits.ts +234 -0
  136. package/core/services/walletServiceConfig.ts +170 -0
  137. package/core/storage/LocalStorageAdapter.ts +58 -0
  138. package/core/storage/README.md +391 -0
  139. package/core/storage/StorageExpoSQLite.ts +2008 -0
  140. package/core/storage/errors.ts +73 -0
  141. package/core/storage/index.ts +3 -0
  142. package/core/storage/methods/findSql.ts +286 -0
  143. package/core/storage/methods/historyNotes.ts +61 -0
  144. package/core/storage/methods/listActionsSql.ts +212 -0
  145. package/core/storage/methods/listOutputsSql.ts +211 -0
  146. package/core/storage/methods/offlineActions.ts +156 -0
  147. package/core/storage/methods/processOfflineActions.ts +503 -0
  148. package/core/storage/methods/reclaim.ts +135 -0
  149. package/core/storage/methods/reviewStatusSql.ts +167 -0
  150. package/core/storage/methods/unprovenWithoutReqSql.ts +26 -0
  151. package/core/storage/methods/walletBalanceSql.ts +55 -0
  152. package/core/storage/schema/createTables.ts +385 -0
  153. package/core/storage/skipQueuedAncestors.ts +29 -0
  154. package/core/storage/sqlUpdateValue.ts +12 -0
  155. package/core/stores/ConnectionStore.ts +71 -0
  156. package/core/theme/ThemeContext.tsx +182 -0
  157. package/core/theme/assertThemeContrast.ts +109 -0
  158. package/core/theme/motion.ts +50 -0
  159. package/core/theme/tokens.ts +232 -0
  160. package/core/theme/useThemeStyles.tsx +156 -0
  161. package/core/walletDbRegistry.ts +110 -0
  162. package/core/walletMonitor.ts +149 -0
  163. package/core/walletRepair/runWalletCheck.ts +195 -0
  164. package/core/walletRepair/shouldReleaseUtxo.ts +18 -0
  165. package/package.json +86 -0
  166. package/ui/backupShares.ts +367 -0
  167. package/ui/components/QRScanner.tsx +353 -0
  168. package/ui/components/pay/AddressReceive.tsx +507 -0
  169. package/ui/components/pay/AvailableBalance.tsx +61 -0
  170. package/ui/components/pay/HandleReceive.tsx +896 -0
  171. package/ui/components/pay/MessageBoxConfig.tsx +256 -0
  172. package/ui/components/pay/NearbyAdvisoryModal.tsx +111 -0
  173. package/ui/components/pay/NearbyFlow.tsx +2542 -0
  174. package/ui/components/pay/OfflineNotice.tsx +337 -0
  175. package/ui/components/pay/PayCellRow.tsx +101 -0
  176. package/ui/components/pay/PayForm.tsx +223 -0
  177. package/ui/components/pay/PaymentQrDisplay.tsx +105 -0
  178. package/ui/components/pay/PaymentSuccessOverlay.tsx +266 -0
  179. package/ui/components/pay/RecipientField.tsx +308 -0
  180. package/ui/components/pay/RequestHub.tsx +75 -0
  181. package/ui/components/pay/ResultBanner.tsx +69 -0
  182. package/ui/components/pay/UniversalSend.tsx +687 -0
  183. package/ui/components/pay/useRecipientInput.ts +270 -0
  184. package/ui/components/security/WalletLockNotice.tsx +138 -0
  185. package/ui/components/ui/AlertCard.tsx +223 -0
  186. package/ui/components/ui/AppLogo.tsx +166 -0
  187. package/ui/components/ui/BlurChrome.tsx +72 -0
  188. package/ui/components/ui/Celebration.tsx +84 -0
  189. package/ui/components/ui/ChoiceSheet.ts +69 -0
  190. package/ui/components/ui/CustomSafeArea.tsx +74 -0
  191. package/ui/components/ui/ErrorBoundary.tsx +154 -0
  192. package/ui/components/ui/GroupedList.tsx +125 -0
  193. package/ui/components/ui/IconButton.tsx +105 -0
  194. package/ui/components/ui/ListRow.tsx +197 -0
  195. package/ui/components/ui/PermissionSheet.tsx +920 -0
  196. package/ui/components/ui/PresenceRow.tsx +215 -0
  197. package/ui/components/ui/PressableScale.tsx +105 -0
  198. package/ui/components/ui/ScreenGradient.tsx +47 -0
  199. package/ui/components/ui/ScrollFade.tsx +76 -0
  200. package/ui/components/ui/Sheet.tsx +342 -0
  201. package/ui/components/ui/Toast.tsx +142 -0
  202. package/ui/components/ui/index.ts +8 -0
  203. package/ui/components/vault/EnrollWizard.tsx +627 -0
  204. package/ui/components/vault/PassphraseField.tsx +306 -0
  205. package/ui/components/vault/PhraseBackupSheet.tsx +227 -0
  206. package/ui/components/vault/VaultBackdrop.tsx +354 -0
  207. package/ui/components/vault/VaultCeremonySheet.tsx +327 -0
  208. package/ui/components/wallet/ActivityRow.tsx +408 -0
  209. package/ui/components/wallet/AmountDisplay.tsx +48 -0
  210. package/ui/components/wallet/AmountInput.tsx +256 -0
  211. package/ui/components/wallet/BackupReminderSheet.tsx +168 -0
  212. package/ui/components/wallet/Balance.tsx +144 -0
  213. package/ui/components/wallet/BiometricAdvisoryModal.tsx +133 -0
  214. package/ui/components/wallet/ImportFromBackupPrompt.tsx +93 -0
  215. package/ui/exportDatabases.ts +122 -0
  216. package/ui/exportTransactions.ts +129 -0
  217. package/ui/hooks/useOfflineNoticeActions.ts +136 -0
  218. package/ui/hooks/useOnline.ts +70 -0
  219. package/ui/hooks/useSpendableBalance.ts +58 -0
  220. package/ui/hooks/useVaultBalance.ts +50 -0
  221. package/ui/importDatabases.ts +170 -0
  222. package/ui/index.ts +136 -0
  223. package/ui/isImageUrl.ts +10 -0
  224. package/ui/printRecoveryShares.ts +93 -0
  225. package/ui/resolveIdentity.ts +125 -0
  226. package/ui/screens/ConnectionsScreen.tsx +438 -0
  227. package/ui/screens/LogsScreen.tsx +432 -0
  228. package/ui/screens/PairScreen.tsx +288 -0
  229. package/ui/screens/PayScreen.tsx +479 -0
  230. package/ui/screens/SettingsScreen.tsx +180 -0
  231. package/ui/screens/TrustScreen.tsx +831 -0
  232. package/ui/screens/VaultRecoverScreen.tsx +226 -0
  233. package/ui/screens/VaultScreen.tsx +423 -0
  234. package/ui/screens/VaultTransferScreen.tsx +293 -0
  235. package/ui/screens/WalletCheckScreen.tsx +539 -0
  236. package/ui/screens/WalletConfigScreen.tsx +1095 -0
  237. package/ui/screens/WalletHomeScreen.tsx +1597 -0
  238. package/ui/screens/homeBadges.ts +18 -0
  239. package/ui/txStatus.ts +79 -0
  240. package/ui/validateTrust.ts +44 -0
@@ -0,0 +1,71 @@
1
+ import { makeAutoObservable, runInAction } from 'mobx'
2
+ import AsyncStorage from '@react-native-async-storage/async-storage'
3
+
4
+ export interface Connection {
5
+ sessionId: string
6
+ origin: string
7
+ relay: string
8
+ backendIdentityKey: string
9
+ mobileIdentityKey: string
10
+ protocolID: string // JSON-stringified WalletProtocol
11
+ connectedAt: number
12
+ status: 'active' | 'disconnected'
13
+ }
14
+
15
+ const STORAGE_KEY = 'connections'
16
+
17
+ class ConnectionStore {
18
+ connections: Connection[] = []
19
+
20
+ constructor() {
21
+ makeAutoObservable(this)
22
+ void this.load()
23
+ }
24
+
25
+ add(connection: Connection) {
26
+ const idx = this.connections.findIndex(c => c.sessionId === connection.sessionId)
27
+ if (idx >= 0) {
28
+ this.connections[idx] = connection
29
+ } else {
30
+ this.connections.push(connection)
31
+ }
32
+ void this.save()
33
+ }
34
+
35
+ setStatus(sessionId: string, status: Connection['status']) {
36
+ const conn = this.connections.find(c => c.sessionId === sessionId)
37
+ if (conn) {
38
+ conn.status = status
39
+ void this.save()
40
+ }
41
+ }
42
+
43
+ remove(sessionId: string) {
44
+ this.connections = this.connections.filter(c => c.sessionId !== sessionId)
45
+ void this.save()
46
+ }
47
+
48
+ private async save() {
49
+ try {
50
+ await AsyncStorage.setItem(STORAGE_KEY, JSON.stringify(this.connections))
51
+ } catch (e) {
52
+ console.warn('[ConnectionStore] save failed', e)
53
+ }
54
+ }
55
+
56
+ private async load() {
57
+ try {
58
+ const raw = await AsyncStorage.getItem(STORAGE_KEY)
59
+ if (raw) {
60
+ runInAction(() => {
61
+ this.connections = JSON.parse(raw) as Connection[]
62
+ })
63
+ }
64
+ } catch (e) {
65
+ console.warn('[ConnectionStore] load failed', e)
66
+ }
67
+ }
68
+ }
69
+
70
+ const connectionStore = new ConnectionStore()
71
+ export default connectionStore
@@ -0,0 +1,182 @@
1
+ import React, { createContext, useContext, useEffect, useMemo } from 'react'
2
+ import { useColorScheme } from 'react-native'
3
+ import {
4
+ lightColors as tokenLightColors,
5
+ darkColors as tokenDarkColors
6
+ } from './tokens'
7
+ import { assertThemeContrast } from './assertThemeContrast'
8
+
9
+ // Theme type definitions
10
+ export type ThemeMode = 'light' | 'dark' | 'system'
11
+
12
+ export interface ThemeColors {
13
+ // Accent
14
+ accent: string
15
+ accentSecondary: string
16
+
17
+ // Backgrounds
18
+ background: string
19
+ backgroundSecondary: string
20
+ backgroundTertiary: string
21
+ backgroundElevated: string
22
+
23
+ // Translucent chrome
24
+ chromeBackground: string
25
+ chromeBackgroundBlur: string
26
+ sheetBackground: string
27
+
28
+ // Text
29
+ textPrimary: string
30
+ textSecondary: string
31
+ textTertiary: string
32
+ textQuaternary: string
33
+ textOnAccent: string
34
+
35
+ // Separators
36
+ separator: string
37
+ separatorOpaque: string
38
+
39
+ // Fills
40
+ fill: string
41
+ fillSecondary: string
42
+ fillTertiary: string
43
+
44
+ // Status
45
+ success: string
46
+ error: string
47
+ warning: string
48
+ info: string
49
+
50
+ // Money surfaces
51
+ canvasTop: string
52
+ canvasBase: string
53
+ surfaceRaised: string
54
+ surfaceRaisedBorder: string
55
+ surfaceRaisedPressed: string
56
+ surfaceSunken: string
57
+ surfaceSunkenBorder: string
58
+ surfaceRowExpanded: string
59
+ hairline: string
60
+ successStrong: string
61
+ successAmount: string
62
+ sheetTop: string
63
+ sheetBase: string
64
+ scrim: string
65
+
66
+ // Permission approval
67
+ permissionProtocol: string
68
+ permissionBasket: string
69
+ permissionIdentity: string
70
+ permissionSpending: string
71
+
72
+ // --- Legacy aliases (for gradual migration) ---
73
+ primary: string
74
+ secondary: string
75
+ paperBackground: string
76
+ buttonBackground: string
77
+ buttonText: string
78
+ buttonBackgroundDisabled: string
79
+ buttonTextDisabled: string
80
+ inputBackground: string
81
+ inputBorder: string
82
+ inputText: string
83
+ protocolApproval: string
84
+ basketApproval: string
85
+ identityApproval: string
86
+ renewalApproval: string
87
+
88
+ gold: string
89
+ }
90
+
91
+ export interface ThemeContextType {
92
+ mode: ThemeMode
93
+ setThemeMode: (mode: ThemeMode) => void
94
+ colors: ThemeColors
95
+ isDark: boolean
96
+ }
97
+
98
+ // Build full color objects that include both new tokens and legacy aliases
99
+ const lightColors: ThemeColors = {
100
+ // New tokens
101
+ ...tokenLightColors,
102
+
103
+ // Legacy aliases → mapped to new tokens
104
+ primary: tokenLightColors.accent,
105
+ secondary: tokenLightColors.accentSecondary,
106
+ paperBackground: tokenLightColors.backgroundSecondary,
107
+ buttonBackground: tokenLightColors.accent,
108
+ buttonText: tokenLightColors.textOnAccent,
109
+ buttonBackgroundDisabled: 'rgba(0, 0, 0, 0.12)',
110
+ buttonTextDisabled: 'rgba(0, 0, 0, 0.26)',
111
+ inputBackground: tokenLightColors.background,
112
+ inputBorder: tokenLightColors.separatorOpaque,
113
+ inputText: tokenLightColors.textPrimary,
114
+ protocolApproval: tokenLightColors.permissionProtocol,
115
+ basketApproval: tokenLightColors.permissionBasket,
116
+ identityApproval: tokenLightColors.permissionIdentity,
117
+ renewalApproval: tokenLightColors.accentSecondary,
118
+ gold: '#ebcc1c'
119
+ }
120
+
121
+ const darkColors: ThemeColors = {
122
+ // New tokens
123
+ ...tokenDarkColors,
124
+
125
+ // Legacy aliases → mapped to new tokens
126
+ primary: tokenDarkColors.accent,
127
+ secondary: tokenDarkColors.accentSecondary,
128
+ paperBackground: tokenDarkColors.backgroundSecondary,
129
+ buttonBackground: tokenDarkColors.accent,
130
+ buttonText: tokenDarkColors.textOnAccent,
131
+ buttonBackgroundDisabled: 'rgba(255, 255, 255, 0.12)',
132
+ buttonTextDisabled: 'rgba(255, 255, 255, 0.3)',
133
+ inputBackground: tokenDarkColors.backgroundTertiary,
134
+ inputBorder: tokenDarkColors.separatorOpaque,
135
+ inputText: tokenDarkColors.textPrimary,
136
+ protocolApproval: tokenDarkColors.permissionProtocol,
137
+ basketApproval: tokenDarkColors.permissionBasket,
138
+ identityApproval: tokenDarkColors.permissionIdentity,
139
+ renewalApproval: tokenDarkColors.accentSecondary,
140
+ gold: '#92811f',
141
+ }
142
+
143
+ // Create the context with default values
144
+ export const ThemeContext = createContext<ThemeContextType>({
145
+ mode: 'system',
146
+ setThemeMode: () => {},
147
+ colors: lightColors,
148
+ isDark: false
149
+ })
150
+
151
+ export const useTheme = () => useContext(ThemeContext)
152
+
153
+ interface ThemeProviderProps {
154
+ children: React.ReactNode
155
+ }
156
+
157
+ export const ThemeProvider: React.FC<ThemeProviderProps> = ({ children }) => {
158
+ // Always follow the device's appearance setting — no manual override.
159
+ const colorScheme = useColorScheme()
160
+ const isDark = colorScheme === 'dark'
161
+ const colors = isDark ? darkColors : lightColors
162
+
163
+ // Dev-only: warn loudly if a token edit introduces an unreadable foreground/
164
+ // background pair (e.g. textOnAccent same brightness as accent). The check
165
+ // catches white-on-white / black-on-black at first render.
166
+ useEffect(() => {
167
+ assertThemeContrast(colors, isDark ? 'dark' : 'light')
168
+ }, [colors, isDark])
169
+
170
+ const value = useMemo(() => ({
171
+ mode: 'system' as ThemeMode,
172
+ setThemeMode: () => {},
173
+ colors,
174
+ isDark
175
+ }), [colors, isDark])
176
+
177
+ return (
178
+ <ThemeContext.Provider value={value}>
179
+ {children}
180
+ </ThemeContext.Provider>
181
+ )
182
+ }
@@ -0,0 +1,109 @@
1
+ /**
2
+ * Dev-only contrast assertion for theme tokens.
3
+ *
4
+ * Runs once at app start (via ThemeProvider) and warns if any of the known
5
+ * foreground/background pairs would be unreadable. Catches mistakes like
6
+ * setting `darkColors.accent = 'white'` while leaving
7
+ * `darkColors.textOnAccent = '#FFFFFF'` — the exact bug that produced an
8
+ * invisible "Apply" button on the ARC Endpoint panel.
9
+ *
10
+ * No-ops in production builds. The check is O(pairs) and runs once per theme
11
+ * mode toggle, so the cost is irrelevant even in dev.
12
+ */
13
+
14
+ import type { ThemeColors } from './ThemeContext'
15
+
16
+ /** Pairs that must keep enough contrast for body-sized text. */
17
+ const REQUIRED_PAIRS: Array<{ fg: keyof ThemeColors; bg: keyof ThemeColors; label: string }> = [
18
+ { fg: 'textOnAccent', bg: 'accent', label: 'button text on accent' },
19
+ { fg: 'textPrimary', bg: 'background', label: 'primary text on background' },
20
+ { fg: 'textPrimary', bg: 'backgroundSecondary', label: 'primary text on backgroundSecondary' },
21
+ { fg: 'textPrimary', bg: 'backgroundTertiary', label: 'primary text on backgroundTertiary' },
22
+ { fg: 'textPrimary', bg: 'backgroundElevated', label: 'primary text on backgroundElevated' }
23
+ ]
24
+
25
+ /** WCAG AA threshold for normal-weight body text. */
26
+ const MIN_CONTRAST = 4.5
27
+
28
+ /** Parse a CSS-ish color literal into linear sRGB [0..1]. Returns null if unparseable. */
29
+ function toRgb(input: string): [number, number, number] | null {
30
+ if (!input) return null
31
+ const s = input.trim().toLowerCase()
32
+ if (s === 'transparent') return null
33
+
34
+ // Named colors we use in the token file.
35
+ const named: Record<string, [number, number, number]> = {
36
+ white: [255, 255, 255],
37
+ black: [0, 0, 0]
38
+ }
39
+ if (named[s]) return named[s]
40
+
41
+ // #rrggbb or #rgb
42
+ if (s.startsWith('#')) {
43
+ const h = s.slice(1)
44
+ if (h.length === 3) {
45
+ return [parseInt(h[0] + h[0], 16), parseInt(h[1] + h[1], 16), parseInt(h[2] + h[2], 16)]
46
+ }
47
+ if (h.length === 6 || h.length === 8) {
48
+ return [parseInt(h.slice(0, 2), 16), parseInt(h.slice(2, 4), 16), parseInt(h.slice(4, 6), 16)]
49
+ }
50
+ }
51
+
52
+ // rgba(r, g, b, a) or rgb(r, g, b) — we treat translucent fg/bg as best-effort
53
+ // (compose against the bg's own RGB if alpha < 1, but only if both have alpha).
54
+ const m = s.match(/^rgba?\(([^)]+)\)$/)
55
+ if (m) {
56
+ const parts = m[1].split(',').map(p => parseFloat(p.trim()))
57
+ if (parts.length >= 3) return [parts[0], parts[1], parts[2]]
58
+ }
59
+
60
+ return null
61
+ }
62
+
63
+ function relativeLuminance([r, g, b]: [number, number, number]): number {
64
+ const channel = (c: number) => {
65
+ const cs = c / 255
66
+ return cs <= 0.03928 ? cs / 12.92 : Math.pow((cs + 0.055) / 1.055, 2.4)
67
+ }
68
+ return 0.2126 * channel(r) + 0.7152 * channel(g) + 0.0722 * channel(b)
69
+ }
70
+
71
+ function contrastRatio(a: [number, number, number], b: [number, number, number]): number {
72
+ const la = relativeLuminance(a)
73
+ const lb = relativeLuminance(b)
74
+ const lighter = Math.max(la, lb)
75
+ const darker = Math.min(la, lb)
76
+ return (lighter + 0.05) / (darker + 0.05)
77
+ }
78
+
79
+ /** Validate a single theme palette. Returns a list of violations. */
80
+ export function findContrastViolations(colors: ThemeColors): string[] {
81
+ const violations: string[] = []
82
+ for (const pair of REQUIRED_PAIRS) {
83
+ const fg = toRgb(colors[pair.fg] as string)
84
+ const bg = toRgb(colors[pair.bg] as string)
85
+ if (!fg || !bg) continue
86
+ const ratio = contrastRatio(fg, bg)
87
+ if (ratio < MIN_CONTRAST) {
88
+ violations.push(
89
+ `theme contrast: ${pair.label} — ${colors[pair.fg]} on ${colors[pair.bg]} = ${ratio.toFixed(2)}:1 (need ${MIN_CONTRAST}:1)`
90
+ )
91
+ }
92
+ }
93
+ return violations
94
+ }
95
+
96
+ /**
97
+ * Call once when the active theme palette changes. In production this is a
98
+ * no-op (Metro folds `__DEV__` to false and dead-code-eliminates the body).
99
+ */
100
+ export function assertThemeContrast(colors: ThemeColors, mode: 'light' | 'dark'): void {
101
+ if (!__DEV__) return
102
+ const violations = findContrastViolations(colors)
103
+ if (violations.length === 0) return
104
+ // eslint-disable-next-line no-console
105
+ console.warn(
106
+ `[theme] contrast invariant violated in ${mode} mode:\n ${violations.join('\n ')}\n` +
107
+ `Fix the offending tokens in context/theme/tokens.ts so the pair contrasts ≥ ${MIN_CONTRAST}:1.`
108
+ )
109
+ }
@@ -0,0 +1,50 @@
1
+ /**
2
+ * Motion tokens — "Quiet Precision" (see docs/superpowers/specs/2026-06-11-delightful-hig-polish-design.md).
3
+ *
4
+ * Rules:
5
+ * - All animation runs on the UI thread via Reanimated. Never drive animation
6
+ * from setState/JS timers on interaction paths.
7
+ * - Nothing animates longer than `durations.moderate` (350ms).
8
+ * - Respect reduced motion: gate springs/translations behind
9
+ * `useReducedMotion()` from react-native-reanimated — collapse to opacity
10
+ * fades or instant changes.
11
+ *
12
+ * LiquidGlass / UIVisualEffectView guardrails (hard-won — do not regress):
13
+ * - NEVER animate an ancestor's opacity fractionally above LiquidGlass or
14
+ * BlurView content; the effect view freezes at a stale frame.
15
+ * - A stuck UIVisualEffectView is cured by remounting via a changed `key`.
16
+ */
17
+
18
+ import { Easing } from 'react-native-reanimated'
19
+ import type { WithSpringConfig } from 'react-native-reanimated'
20
+
21
+ /**
22
+ * Easing curves for `withTiming`.
23
+ *
24
+ * There is exactly one, and it decelerates. UI motion in this app models
25
+ * something arriving and coming to rest, so it must start at full speed and
26
+ * settle — an ease-IN reads as the interface hesitating before it obeys, and is
27
+ * never correct for a response to a tap. Where a curve is not expressive enough
28
+ * on its own, reach for `springs` instead of inventing a second curve.
29
+ */
30
+ export const easings = {
31
+ /** cubic-bezier(0.23, 1, 0.32, 1) — a long, soft deceleration. */
32
+ out: Easing.bezier(0.23, 1, 0.32, 1),
33
+ } as const
34
+
35
+ export const springs = {
36
+ /** Buttons, small elements, alert cards. Custom-tuned — NOT Reanimated's built-in presets. */
37
+ snappy: { mass: 1, stiffness: 380, damping: 36 } satisfies WithSpringConfig,
38
+ /** Larger surfaces: sheets, popovers, dropdowns. */
39
+ settle: { mass: 1, stiffness: 280, damping: 32 } satisfies WithSpringConfig,
40
+ } as const
41
+
42
+ /** All values in milliseconds. */
43
+ export const durations = {
44
+ /** Crossfades, press feedback. */
45
+ instant: 150,
46
+ /** Small movements, toasts. */
47
+ quick: 250,
48
+ /** Largest allowed — full-surface transitions. */
49
+ moderate: 350,
50
+ } as const
@@ -0,0 +1,232 @@
1
+ /**
2
+ * Safari-inspired design tokens for BSV Wallet.
3
+ *
4
+ * Colors follow iOS Human Interface Guidelines.
5
+ * Typography uses the iOS type scale (system font).
6
+ * Spacing uses a 4pt base grid.
7
+ *
8
+ * INVARIANT — contrast pairs MUST stay readable:
9
+ * - `accent` ↔ `textOnAccent` (button bg vs button text)
10
+ * - `background` ↔ `textPrimary`
11
+ * - `backgroundSecondary` / `backgroundTertiary` ↔ `textPrimary`
12
+ *
13
+ * Never set `textOnAccent` and `accent` to the same brightness (white on white,
14
+ * black on black). The light theme inverts colours from the dark theme — that
15
+ * means BOTH theme objects must be updated when changing either field. A
16
+ * runtime contrast check in `assertThemeContrast.ts` warns in dev if this
17
+ * invariant breaks.
18
+ */
19
+
20
+ /* -------------------------------- Spacing -------------------------------- */
21
+
22
+ export const spacing = {
23
+ xs: 4,
24
+ sm: 8,
25
+ md: 12,
26
+ lg: 16,
27
+ xl: 20,
28
+ xxl: 24,
29
+ xxxl: 32,
30
+ } as const
31
+
32
+ /* --------------------------------- Radii --------------------------------- */
33
+
34
+ /**
35
+ * Corner radii. The scale is softer than iOS's: `md` is the glyph-tile radius,
36
+ * `lg` the card/button radius, `xl` the radius a bottom sheet meets the screen
37
+ * edge with. Rounder corners are the loudest single cue that a surface is a
38
+ * distinct object rather than a region of the page.
39
+ */
40
+ export const radii = {
41
+ sm: 8,
42
+ md: 12,
43
+ lg: 14,
44
+ xl: 24,
45
+ pill: 999,
46
+ } as const
47
+
48
+ /* ------------------------------- Typography ------------------------------ */
49
+
50
+ /**
51
+ * The iOS type scale, which is very close to a 1.25 (major third) ratio anchored
52
+ * on `body` at 17pt: 13 · 17 · 22 · 28 · 34 — each step ≈ the previous × 1.25.
53
+ *
54
+ * `display` continues that ratio one step past `largeTitle` (34 × 1.25 ≈ 42,
55
+ * rounded to 44 to sit on the 4pt grid). It is for a single focal figure on a
56
+ * screen that has one — an amount being handed to another person — and nothing
57
+ * else. Two `display` elements on one view means the view has no focal point.
58
+ */
59
+ export const typography = {
60
+ display: { fontSize: 44, fontWeight: '700' as const, lineHeight: 52, letterSpacing: -0.5 },
61
+ largeTitle: { fontSize: 34, fontWeight: '700' as const, lineHeight: 41 },
62
+ title1: { fontSize: 28, fontWeight: '700' as const, lineHeight: 34 },
63
+ title2: { fontSize: 22, fontWeight: '700' as const, lineHeight: 28 },
64
+ title3: { fontSize: 20, fontWeight: '600' as const, lineHeight: 25 },
65
+ headline: { fontSize: 17, fontWeight: '600' as const, lineHeight: 22 },
66
+ body: { fontSize: 17, fontWeight: '400' as const, lineHeight: 22 },
67
+ callout: { fontSize: 16, fontWeight: '400' as const, lineHeight: 21 },
68
+ subhead: { fontSize: 15, fontWeight: '400' as const, lineHeight: 20 },
69
+ footnote: { fontSize: 13, fontWeight: '400' as const, lineHeight: 18 },
70
+ caption1: { fontSize: 12, fontWeight: '400' as const, lineHeight: 16 },
71
+ caption2: { fontSize: 11, fontWeight: '400' as const, lineHeight: 13 },
72
+ } as const
73
+
74
+ /* --------------------------------- Colors -------------------------------- */
75
+
76
+ export const lightColors = {
77
+ // Accent — `textOnAccent` MUST stay readable against this. Both fields invert
78
+ // in `darkColors` below; never let them collapse to the same brightness.
79
+ accent: 'black',
80
+ accentSecondary: '#222222',
81
+
82
+ // Backgrounds — the cool neutral ramp. Canvas is a step under the cards that
83
+ // sit on it; without that step, a white card on a white page has to be drawn
84
+ // with a border to exist at all.
85
+ background: '#FFFFFF',
86
+ backgroundSecondary: '#F5F6F9',
87
+ backgroundTertiary: '#FFFFFF',
88
+ backgroundElevated: '#FFFFFF',
89
+
90
+ // Translucent chrome (for toolbars, sheets)
91
+ chromeBackground: 'rgba(251, 252, 253, 0.94)',
92
+ chromeBackgroundBlur: 'rgba(255, 255, 255, 0.72)',
93
+ sheetBackground: 'rgba(244, 245, 248, 0.97)',
94
+
95
+ // Text — one ink, stepped down by alpha. Pure black on white is harsher than
96
+ // anything else in this system, so the darkest text is a near-black.
97
+ textPrimary: '#15181E',
98
+ textSecondary: 'rgba(21, 24, 30, 0.55)',
99
+ textTertiary: 'rgba(21, 24, 30, 0.38)',
100
+ textQuaternary: 'rgba(21, 24, 30, 0.2)',
101
+ textOnAccent: '#FFFFFF',
102
+
103
+ // Separators
104
+ separator: 'rgba(21, 24, 30, 0.12)',
105
+ separatorOpaque: '#E2E5EB',
106
+
107
+ // Fills
108
+ fill: 'rgba(21, 24, 30, 0.09)',
109
+ fillSecondary: 'rgba(21, 24, 30, 0.07)',
110
+ fillTertiary: 'rgba(21, 24, 30, 0.05)',
111
+
112
+ // Status
113
+ success: '#1E9E62',
114
+ error: '#FF3B30',
115
+ warning: '#FF9500',
116
+ info: '#007AFF',
117
+
118
+ // Money surfaces — a cool, slightly-blue neutral ramp used by the wallet and
119
+ // pay screens. Deliberately NOT the iOS grays above: the canvas is a shallow
120
+ // gradient the raised cards sit on, so it has to be a touch darker than the
121
+ // cards themselves or the cards stop reading as raised at all.
122
+ canvasTop: '#EAECF1',
123
+ canvasBase: '#F5F6F9',
124
+ surfaceRaised: '#FFFFFF',
125
+ surfaceRaisedBorder: '#E2E5EB',
126
+ surfaceRaisedPressed: '#F0F2F6',
127
+ // Sunken = an inset well (row glyph tiles), the opposite of raised.
128
+ surfaceSunken: 'rgba(21, 24, 30, 0.045)',
129
+ surfaceSunkenBorder: 'rgba(21, 24, 30, 0.06)',
130
+ // The surface a list row is lifted onto while it is open. In light that means
131
+ // white against the gray canvas; in dark, a hair of light added to the canvas.
132
+ surfaceRowExpanded: '#FFFFFF',
133
+ // Hairline is quieter than `separator`: it divides rows that already share a
134
+ // surface, where a full-strength rule would look like a fence.
135
+ hairline: 'rgba(21, 24, 30, 0.06)',
136
+ // Status green at two weights: the dot/glyph reads at small size, the amount
137
+ // has to survive being set in 14.5pt semibold next to plain body text.
138
+ successStrong: '#1E9E62',
139
+ successAmount: '#178A5C',
140
+
141
+ // Bottom sheets. A drawer is lit from its own top edge, so it gets its own
142
+ // two-stop ramp rather than reusing the canvas — the sheet has to separate
143
+ // from whatever is behind it even when that is the same colour.
144
+ sheetTop: '#FBFCFD',
145
+ sheetBase: '#F4F5F8',
146
+ // Scrim over the page behind a sheet. Lighter in light mode: the page is
147
+ // already bright, so it needs less dimming to fall behind the drawer.
148
+ scrim: 'rgba(24, 28, 36, 0.38)',
149
+
150
+ // Permission approval
151
+ permissionProtocol: '#34C759',
152
+ permissionBasket: '#34C759',
153
+ permissionIdentity: '#007AFF',
154
+ permissionSpending: '#FF9500',
155
+ } as const
156
+
157
+ export const darkColors = {
158
+ // Accent — inverted from light theme, so the contrasting text colour also
159
+ // inverts. Without this pairing, `<Text color={colors.textOnAccent}>` on a
160
+ // `colors.accent` button is white-on-white in dark mode.
161
+ accent: 'white',
162
+ accentSecondary: '#e8e8e8',
163
+
164
+ // Backgrounds — the same ramp inverted: canvas is the darkest thing on
165
+ // screen and surfaces are lifted out of it, never painted onto it.
166
+ background: '#0C0E12',
167
+ backgroundSecondary: '#10141B',
168
+ backgroundTertiary: '#1D222B',
169
+ backgroundElevated: '#171B22',
170
+
171
+ // Translucent chrome
172
+ chromeBackground: 'rgba(18, 22, 29, 0.94)',
173
+ chromeBackgroundBlur: 'rgba(18, 22, 29, 0.72)',
174
+ sheetBackground: 'rgba(14, 17, 22, 0.97)',
175
+
176
+ // Text — a cool near-white rather than pure white, which glares against a
177
+ // blue-black canvas at body size.
178
+ textPrimary: '#F2F4F8',
179
+ textSecondary: 'rgba(235, 240, 248, 0.55)',
180
+ textTertiary: 'rgba(235, 240, 248, 0.38)',
181
+ textQuaternary: 'rgba(235, 240, 248, 0.2)',
182
+ // textOnAccent contrasts with the white accent — must stay dark in dark mode.
183
+ textOnAccent: '#0C0E12',
184
+
185
+ // Separators
186
+ separator: 'rgba(255, 255, 255, 0.11)',
187
+ separatorOpaque: '#232833',
188
+
189
+ // Fills
190
+ fill: 'rgba(255, 255, 255, 0.1)',
191
+ fillSecondary: 'rgba(255, 255, 255, 0.08)',
192
+ fillTertiary: 'rgba(255, 255, 255, 0.06)',
193
+
194
+ // Status
195
+ success: '#34C77B',
196
+ error: '#FF453A',
197
+ warning: '#FF9F0A',
198
+ info: '#0A84FF',
199
+
200
+ // Money surfaces — see the light theme for the reasoning. In dark the ramp
201
+ // runs the other way: the canvas is the darkest thing on screen and raised
202
+ // cards are lifted OUT of it, so `surfaceRaised` is lighter, not whiter.
203
+ canvasTop: '#10141B',
204
+ canvasBase: '#0C0E12',
205
+ surfaceRaised: '#171B22',
206
+ surfaceRaisedBorder: 'rgba(255, 255, 255, 0.08)',
207
+ surfaceRaisedPressed: '#1D222B',
208
+ surfaceSunken: 'rgba(255, 255, 255, 0.05)',
209
+ surfaceSunkenBorder: 'rgba(255, 255, 255, 0.07)',
210
+ surfaceRowExpanded: 'rgba(255, 255, 255, 0.035)',
211
+ hairline: 'rgba(255, 255, 255, 0.06)',
212
+ successStrong: '#34C77B',
213
+ successAmount: '#4BD592',
214
+
215
+ // Bottom sheets — see the light theme. Sits a step above the canvas so the
216
+ // drawer reads as lifted off the dimmed page behind it.
217
+ sheetTop: '#12161D',
218
+ sheetBase: '#0E1116',
219
+ scrim: 'rgba(10, 12, 16, 0.62)',
220
+
221
+ // Permission approval
222
+ permissionProtocol: '#1fae4378',
223
+ permissionBasket: '#1fae4378',
224
+ permissionIdentity: '#24588dff',
225
+ permissionSpending: '#FF9F0A',
226
+ } as const
227
+
228
+ /* ------------------------------ Hit Targets ------------------------------ */
229
+
230
+ export const hitTargets = {
231
+ minimum: 44, // iOS HIG minimum touch target
232
+ } as const