@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.
Files changed (137) hide show
  1. package/CHANGELOG.md +241 -0
  2. package/README.md +10 -9
  3. package/android/build.gradle +15 -0
  4. package/android/src/main/AndroidManifest.xml +3 -0
  5. package/android/src/main/java/org/bsv/boundedfetch/BoundedBody.java +19 -0
  6. package/android/src/main/java/org/bsv/boundedfetch/BoundedConnection.java +28 -0
  7. package/android/src/main/java/org/bsv/boundedfetch/BsvBoundedFetchModule.kt +114 -0
  8. package/core/backup/RemoteSyncReader.ts +71 -46
  9. package/core/backup/client.ts +6 -15
  10. package/core/backup/codec.ts +78 -13
  11. package/core/backup/constants.ts +3 -9
  12. package/core/backup/cursor.ts +8 -0
  13. package/core/backup/push.ts +26 -16
  14. package/core/backup/restore.ts +6 -5
  15. package/core/bridge/BrowserBridgeProvider.tsx +273 -0
  16. package/core/bridge/bindings.ts +459 -0
  17. package/core/bridge/conformance.ts +222 -0
  18. package/core/bridge/consent.ts +494 -0
  19. package/core/bridge/consentSheetSource.ts +98 -0
  20. package/core/bridge/dispatcher.ts +621 -0
  21. package/core/bridge/inbox.ts +569 -0
  22. package/core/bridge/index.ts +48 -0
  23. package/core/bridge/loopback/cors.ts +57 -0
  24. package/core/bridge/loopback/endpoints.ts +11 -0
  25. package/core/bridge/loopback/hostCheck.ts +25 -0
  26. package/core/bridge/loopback/index.ts +7 -0
  27. package/core/bridge/loopback/launchProof.ts +166 -0
  28. package/core/bridge/loopback/router.ts +770 -0
  29. package/core/bridge/loopback/routerTypes.ts +115 -0
  30. package/core/bridge/loopback/status.ts +52 -0
  31. package/core/bridge/memoryInboxStore.ts +231 -0
  32. package/core/bridge/permissionPolicy.ts +247 -0
  33. package/core/bridge/policy.ts +72 -0
  34. package/core/bridge/protocol/base64url.ts +64 -0
  35. package/core/bridge/protocol/connectionError.ts +79 -0
  36. package/core/bridge/protocol/constants.ts +21 -0
  37. package/core/bridge/protocol/continuity.ts +21 -0
  38. package/core/bridge/protocol/descriptor.ts +395 -0
  39. package/core/bridge/protocol/envelopes.ts +188 -0
  40. package/core/bridge/protocol/errorCodec.ts +164 -0
  41. package/core/bridge/protocol/json.ts +237 -0
  42. package/core/bridge/protocol/limits.ts +43 -0
  43. package/core/bridge/protocol/methods.ts +55 -0
  44. package/core/bridge/protocol/origin.ts +130 -0
  45. package/core/bridge/runtime.ts +642 -0
  46. package/core/bridge/runtimeFlags.ts +34 -0
  47. package/core/bridge/testing/conformanceCases.ts +149 -0
  48. package/core/bridge/testing/pageClient.ts +44 -0
  49. package/core/bridge/unverifiedManager.ts +97 -0
  50. package/core/bridge/unverifiedOriginator.ts +79 -0
  51. package/core/config.tsx +1 -16
  52. package/core/constants.ts +7 -11
  53. package/core/context/WalletConnectionContext.tsx +92 -49
  54. package/core/context/WalletContext.tsx +288 -165
  55. package/core/context/sessionTeardown.ts +46 -0
  56. package/core/context/usePairingAttempt.ts +31 -0
  57. package/core/e2e/broadcaster.ts +25 -0
  58. package/core/e2e/consentFixture.ts +46 -0
  59. package/core/e2e/mode.ts +42 -0
  60. package/core/headers/OfflineFirstChaintracks.ts +57 -107
  61. package/core/headers/headerConsensus.ts +230 -0
  62. package/core/headers/headerStore.ts +344 -122
  63. package/core/headers/prewarm.ts +4 -7
  64. package/core/headers/syncHeaders.ts +82 -12
  65. package/core/hooks/usePermissionQueue.ts +89 -34
  66. package/core/i18n/translations.tsx +958 -24
  67. package/core/identity/handleRegistry/client.ts +4 -2
  68. package/core/identity/handleRegistry/resolver.ts +7 -11
  69. package/core/index.ts +17 -0
  70. package/core/localpay/pending.ts +39 -4
  71. package/core/network/boundedFetch.ts +101 -0
  72. package/core/networks.ts +11 -13
  73. package/core/pay/rails/address.ts +5 -4
  74. package/core/pay/rails/handle.ts +3 -1
  75. package/core/pay/rails/sweep.ts +791 -0
  76. package/core/peerpay/brc29.ts +4 -0
  77. package/core/peerpay/handleResendRequests.ts +15 -2
  78. package/core/peerpay/outbox.ts +115 -2
  79. package/core/profiles/assertProfileEmpty.ts +2 -2
  80. package/core/profiles/profileStore.ts +3 -2
  81. package/core/services/arcadeBroadcastProvider.ts +260 -114
  82. package/core/services/autoApprovePolicy.ts +7 -1
  83. package/core/services/capWalletArgs.ts +2 -1
  84. package/core/services/permissionPrompts.ts +132 -0
  85. package/core/services/secrets/kek.ts +5 -0
  86. package/core/services/secrets/migration.ts +27 -2
  87. package/core/services/secrets/policy.ts +6 -0
  88. package/core/services/signingPermissionPolicy.ts +230 -2
  89. package/core/services/vault/VaultKeyService.ts +5 -2
  90. package/core/services/vault/ceremony.ts +2 -2
  91. package/core/services/vault/ceremonyHost.ts +1 -1
  92. package/core/services/vault/guard.ts +20 -0
  93. package/core/services/vault/outputAuthority.ts +76 -0
  94. package/core/services/vault/transfers.ts +52 -28
  95. package/core/services/vault/vaultStore.ts +60 -14
  96. package/core/services/walletArgLimits.ts +17 -2
  97. package/core/services/walletConnectionValidation.ts +13 -1
  98. package/core/services/walletServiceConfig.ts +8 -7
  99. package/core/storage/encryptedDbImage.ts +325 -0
  100. package/core/stores/ConnectionStore.ts +17 -0
  101. package/core/toolboxConfig.ts +78 -2
  102. package/expo-module.config.json +5 -0
  103. package/ios/BoundedBody.swift +15 -0
  104. package/ios/BsvBoundedFetch.podspec +17 -0
  105. package/ios/BsvBoundedFetchModule.swift +121 -0
  106. package/package.json +12 -8
  107. package/ui/bridgeSheet/ContextRelay.tsx +86 -0
  108. package/ui/bridgeSheet/relayedContexts.ts +21 -0
  109. package/ui/components/pay/AddressReceive.tsx +6 -2
  110. package/ui/components/pay/ImportedOutboxApproval.tsx +142 -0
  111. package/ui/components/pay/PayCellRow.tsx +3 -1
  112. package/ui/components/pay/PayForm.tsx +12 -2
  113. package/ui/components/pay/RecipientField.tsx +1 -0
  114. package/ui/components/pay/RequestHub.tsx +1 -0
  115. package/ui/components/pay/UniversalSend.tsx +110 -42
  116. package/ui/components/ui/ListRow.tsx +10 -2
  117. package/ui/components/ui/PermissionSheet.tsx +534 -158
  118. package/ui/components/ui/Sheet.tsx +59 -7
  119. package/ui/components/ui/sheetResumeSignal.ts +19 -0
  120. package/ui/components/vault/KeyChooser.tsx +1 -1
  121. package/ui/components/wallet/AmountInput.tsx +4 -1
  122. package/ui/components/wallet/BackupReminderSheet.tsx +8 -1
  123. package/ui/components/wallet/BiometricAdvisoryModal.tsx +2 -0
  124. package/ui/components/wallet/ImportFromBackupPrompt.tsx +6 -1
  125. package/ui/components/wallet/ProfileButton.tsx +1 -0
  126. package/ui/exportDatabases.ts +94 -5
  127. package/ui/hooks/useExportWalletData.ts +37 -24
  128. package/ui/importDatabases.ts +154 -34
  129. package/ui/index.ts +4 -0
  130. package/ui/screens/ConnectionsScreen.tsx +12 -3
  131. package/ui/screens/PairScreen.tsx +10 -3
  132. package/ui/screens/PayScreen.tsx +1 -0
  133. package/ui/screens/TrustScreen.tsx +6 -3
  134. package/ui/screens/VaultScreen.tsx +13 -3
  135. package/ui/screens/VaultTransferScreen.tsx +6 -3
  136. package/ui/screens/WalletConfigScreen.tsx +30 -3
  137. package/ui/screens/WalletHomeScreen.tsx +7 -1
@@ -0,0 +1,130 @@
1
+ /**
2
+ * BRC-185 origin -> originator (spec 6.3).
3
+ *
4
+ * Pure: the only imports are constants. The strict ASCII grammar runs first and `URL` is used
5
+ * only as a cross-check, because this code runs on Node (jest), WebKit (the extension) and
6
+ * Hermes with `whatwg-url-minimum`, and they do not serialise origins identically.
7
+ */
8
+ import { ADMIN_ORIGINATOR, LEGACY_ADMIN_ORIGINATOR } from './constants'
9
+ import {
10
+ isLdhHostname,
11
+ isUnattestedOriginator,
12
+ MAX_ORIGINATOR_BYTES,
13
+ MAX_UNVERIFIED_HOSTNAME_BYTES,
14
+ OriginRefused
15
+ } from '../unverifiedOriginator'
16
+
17
+ export {
18
+ hostnameOfUnattested,
19
+ isGrantTag,
20
+ isUnattestedOriginator,
21
+ mintGrantTag,
22
+ OriginRefused,
23
+ unverifiedOriginator
24
+ } from '../unverifiedOriginator'
25
+
26
+ export type Attestation = 'browser' | 'unattested'
27
+
28
+ export interface CanonicalOrigin {
29
+ applicationOrigin: string
30
+ hostname: string
31
+ attestation: Attestation
32
+ /** The hostname for `browser`. Undefined for `unattested` until consent mints a grant tag (6.4). */
33
+ originator: string | undefined
34
+ }
35
+
36
+ const MAX_ORIGIN_BYTES = 2048
37
+ const MAX_HOST_CHARS = 253
38
+ const HTTPS_RE = /^https:\/\/([^:/?#@\s]+)(?::([1-9][0-9]{0,4}))?$/
39
+ const LOCALHOST_HTTP_RE = /^http:\/\/localhost:([1-9][0-9]{0,4})$/
40
+
41
+ function utf8Length(s: string): number {
42
+ let n = 0
43
+ for (const ch of s) {
44
+ const c = ch.codePointAt(0) as number
45
+ n += c < 0x80 ? 1 : c < 0x800 ? 2 : c < 0x10000 ? 3 : 4
46
+ }
47
+ return n
48
+ }
49
+
50
+ function isAdminHost(host: string): boolean {
51
+ return host === ADMIN_ORIGINATOR || host === LEGACY_ADMIN_ORIGINATOR
52
+ }
53
+
54
+ function crossCheck(origin: string, protocol: string, host: string, port: string | undefined): void {
55
+ // Any disagreement with the platform URL parser, or a parser failure, refuses the origin.
56
+ let u: URL
57
+ try {
58
+ u = new URL(origin)
59
+ } catch {
60
+ throw new OriginRefused('origin not parseable')
61
+ }
62
+ if (u.protocol !== protocol || u.hostname !== host || u.port !== (port ?? '') || u.username || u.password) {
63
+ throw new OriginRefused('origin parsers disagree')
64
+ }
65
+ }
66
+
67
+ export function canonicalizeBridgeOrigin(input: {
68
+ origin: string
69
+ attestation: Attestation
70
+ /** Host policy: `configureToolbox({ browserBridge: { allowLocalhostHttp } })`, gated on `__DEV__`. */
71
+ allowLocalhostHttp?: boolean
72
+ }): CanonicalOrigin {
73
+ const { origin, attestation } = input
74
+ if (attestation !== 'browser' && attestation !== 'unattested') throw new OriginRefused('unknown attestation')
75
+ if (typeof origin !== 'string' || origin.length === 0 || utf8Length(origin) > MAX_ORIGIN_BYTES) {
76
+ throw new OriginRefused('origin missing or too long')
77
+ }
78
+
79
+ let host: string
80
+ let port: string | undefined
81
+ let protocol: string
82
+ const https = HTTPS_RE.exec(origin)
83
+ if (https) {
84
+ protocol = 'https:'
85
+ host = https[1]
86
+ port = https[2]
87
+ if (Number(port ?? 1) > 65535) throw new OriginRefused('port out of range')
88
+ if (port === '443') throw new OriginRefused('default port is not canonical')
89
+ if (!isLdhHostname(host, MAX_HOST_CHARS)) throw new OriginRefused('host is not a canonical ASCII hostname')
90
+ } else {
91
+ const dev = input.allowLocalhostHttp === true ? LOCALHOST_HTTP_RE.exec(origin) : null
92
+ if (!dev || Number(dev[1]) > 65535) throw new OriginRefused('origin must be https')
93
+ protocol = 'http:'
94
+ host = 'localhost'
95
+ port = dev[1]
96
+ }
97
+
98
+ // The `invalid` TLD holds the admin name and the unverified namespace; no site may claim it.
99
+ if (isAdminHost(host) || host === 'invalid' || host.endsWith('.invalid')) {
100
+ throw new OriginRefused('reserved host')
101
+ }
102
+ if (attestation === 'unattested' && host.length > MAX_UNVERIFIED_HOSTNAME_BYTES) {
103
+ throw new OriginRefused('host too long for the unverified namespace')
104
+ }
105
+ if (host.length > MAX_ORIGINATOR_BYTES) throw new OriginRefused('host too long')
106
+
107
+ crossCheck(origin, protocol, host, port)
108
+
109
+ return {
110
+ applicationOrigin: origin,
111
+ hostname: host,
112
+ attestation,
113
+ originator: attestation === 'browser' ? host : undefined
114
+ }
115
+ }
116
+
117
+ /**
118
+ * Final check, run immediately before every wallet call (6.3 step 5). Requires a hostname shape,
119
+ * no `:` or `@`, not admin, and `.invalid` only in the exact unverified form.
120
+ */
121
+ export function assertCanonicalOriginator(o: unknown): asserts o is string {
122
+ if (typeof o !== 'string' || o.length === 0 || utf8Length(o) > MAX_ORIGINATOR_BYTES) {
123
+ throw new OriginRefused('originator missing or too long')
124
+ }
125
+ if (o.includes(':') || o.includes('@') || isAdminHost(o)) throw new OriginRefused('originator not permitted')
126
+ const s: string = o
127
+ if (isUnattestedOriginator(s)) return
128
+ if (!isLdhHostname(s, MAX_ORIGINATOR_BYTES)) throw new OriginRefused('originator is not a canonical hostname')
129
+ if (s === 'invalid' || s.endsWith('.invalid')) throw new OriginRefused('originator is in a reserved namespace')
130
+ }