@bsv/expo-wallet-toolbox 0.21.0 → 0.23.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 +222 -0
- package/README.md +82 -13
- 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 +464 -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 +222 -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/contacts/contactActivity.ts +48 -28
- package/core/contacts/contactsStore.ts +2 -2
- package/core/context/WalletConnectionContext.tsx +7 -1
- package/core/context/WalletContext.tsx +420 -348
- package/core/context/sessionTeardown.ts +46 -0
- package/core/demo/demoAssets.ts +8 -10
- package/core/demo/demoLedger.ts +32 -38
- package/core/demo/demoMandalaRuntime.ts +67 -49
- package/core/demo/index.ts +1 -1
- package/core/hooks/usePermissionQueue.ts +89 -34
- package/core/i18n/translations.tsx +983 -12
- package/core/index.ts +70 -37
- package/core/localpay/build.ts +110 -569
- package/core/localpay/codec.ts +190 -93
- package/core/localpay/pending.ts +217 -202
- package/core/localpay/session.ts +99 -25
- package/core/localpay/types.ts +6 -5
- package/core/localpay/verify.ts +118 -173
- package/core/mandala/abortGuard.ts +97 -120
- package/core/mandala/accessPolicy.ts +133 -0
- package/core/mandala/assets.ts +370 -0
- package/core/mandala/colorGuard.ts +178 -0
- package/core/mandala/colorModule.ts +82 -0
- package/core/mandala/createRuntime.ts +483 -2392
- package/core/mandala/handle.ts +694 -0
- package/core/mandala/kvStore.ts +105 -0
- package/core/mandala/nearby.ts +185 -0
- package/core/mandala/receipt.ts +121 -0
- package/core/mandala/runtime.ts +166 -312
- package/core/mandala/settle.ts +540 -0
- package/core/mandala/transferJournal.ts +395 -0
- package/core/mandala/types.ts +61 -311
- package/core/networks.ts +5 -5
- package/core/offline/cancelParked.ts +80 -63
- package/core/offline/payerHold.ts +52 -118
- package/core/parsePeerPayURI.ts +25 -12
- package/core/pay/rails/handle.ts +15 -14
- package/core/pay/rails/index.ts +5 -3
- package/core/pay/rails/nearby.ts +25 -87
- package/core/profiles/assertProfileEmpty.ts +19 -10
- package/core/services/autoApprovePolicy.ts +7 -1
- package/core/services/capWalletArgs.ts +2 -1
- package/core/services/permissionPrompts.ts +132 -0
- package/core/services/signingPermissionPolicy.ts +230 -2
- package/core/services/vault/guard.ts +15 -4
- package/core/services/walletArgLimits.ts +17 -2
- package/core/storage/StorageExpoSQLite.ts +93 -229
- package/core/storage/encryptedDbImage.ts +325 -0
- package/core/storage/methods/processOfflineActions.ts +86 -136
- package/core/storage/schema/createTables.ts +9 -184
- package/core/toolboxConfig.ts +18 -1
- package/package.json +9 -8
- package/ui/bridgeSheet/ContextRelay.tsx +86 -0
- package/ui/bridgeSheet/relayedContexts.ts +21 -0
- package/ui/components/pay/AssetPicker.tsx +2 -2
- package/ui/components/pay/HandleReceive.tsx +4 -4
- package/ui/components/pay/NearbyFlow.tsx +324 -239
- package/ui/components/pay/RequestHub.tsx +10 -0
- package/ui/components/pay/UniversalSend.tsx +31 -28
- package/ui/components/pay/useRecipientInput.ts +2 -2
- package/ui/components/ui/PermissionSheet.tsx +625 -315
- package/ui/components/ui/Sheet.tsx +59 -7
- package/ui/components/ui/colorPrompt.ts +236 -0
- package/ui/components/ui/sheetResumeSignal.ts +19 -0
- package/ui/components/wallet/AmountInput.tsx +9 -6
- package/ui/components/wallet/AssetAmount.tsx +6 -6
- package/ui/components/wallet/AssetSwitcherDropdown.tsx +26 -7
- package/ui/components/wallet/Balance.tsx +3 -1
- package/ui/components/wallet/ContactActivityList.tsx +10 -13
- package/ui/components/wallet/tokenEviction.ts +9 -9
- package/ui/exportDatabases.ts +94 -5
- package/ui/hooks/useExportWalletData.ts +37 -24
- package/ui/hooks/useMandala.ts +6 -6
- package/ui/hooks/useSpendableBalance.ts +3 -1
- package/ui/importDatabases.ts +124 -29
- package/ui/index.ts +4 -0
- package/ui/screens/PayScreen.tsx +14 -20
- package/ui/screens/SettingsScreen.tsx +3 -1
- package/ui/screens/WalletCheckScreen.tsx +7 -2
- package/ui/screens/WalletConfigScreen.tsx +13 -1
- package/ui/screens/WalletHomeScreen.tsx +40 -14
- package/ui/screens/tokenRowTitle.ts +28 -15
- package/ui/tokenFormat.ts +133 -69
- package/ui/tokenStatus.ts +5 -8
- package/core/localpay/settlementAck.ts +0 -155
- package/core/mandala/basketMigration.ts +0 -166
- package/core/mandala/bundle.ts +0 -244
- package/core/mandala/drain.ts +0 -754
- package/core/mandala/inboxPrehold.ts +0 -193
- package/core/mandala/permissionModule.ts +0 -931
- package/core/mandala/resendTransfer.ts +0 -178
- package/core/mandala/settlementStore.ts +0 -434
- package/core/mandala/token.ts +0 -45
- package/core/offline/tokenFrames.ts +0 -197
|
@@ -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
|
+
}
|