@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,166 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* BRC-185 Android loopback launch proof (spec 7.5): the MACs under the per-launch secret `k` and the
|
|
3
|
+
* launch URI codec. Pure and synchronous; depends only on `@bsv/sdk` HMAC and the protocol codecs, so it
|
|
4
|
+
* bundles into the page-side stand-in client as well as the wallet.
|
|
5
|
+
*
|
|
6
|
+
* Every output is HMAC-SHA-256 under `k` with its own label, so no MAC can serve as an oracle for another.
|
|
7
|
+
* `k`, the epoch and every output here are secret-like: callers must never log them.
|
|
8
|
+
*/
|
|
9
|
+
import { Hash } from '@bsv/sdk'
|
|
10
|
+
import { b64uDecode, b64uEncode } from '../protocol/base64url'
|
|
11
|
+
import { canonicalize } from '../protocol/json'
|
|
12
|
+
|
|
13
|
+
const encoder = new TextEncoder()
|
|
14
|
+
|
|
15
|
+
const LABEL_HELLO = 'BRC-185 android hello v1\n'
|
|
16
|
+
const LABEL_DESCRIBE_ACK = 'BRC-185 android describe ack v1\n'
|
|
17
|
+
const LABEL_LAUNCH = 'BRC-185 android launch v1\n'
|
|
18
|
+
const LABEL_ACK = 'BRC-185 android ack v1\n'
|
|
19
|
+
const LABEL_BINDING = 'BRC-185 android binding v1\n'
|
|
20
|
+
|
|
21
|
+
/** The wallet's identity for one origin (spec 6.9). */
|
|
22
|
+
export interface LaunchWallet {
|
|
23
|
+
instanceId: string
|
|
24
|
+
continuityKey: string
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export interface LaunchMessage {
|
|
28
|
+
wallet: LaunchWallet
|
|
29
|
+
epoch: string
|
|
30
|
+
origin: string
|
|
31
|
+
challenge: string
|
|
32
|
+
host: string
|
|
33
|
+
nonce: string
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
function mac(k: Uint8Array, label: string, payload: unknown): string {
|
|
37
|
+
const data = Array.from(encoder.encode(label + canonicalize(payload)))
|
|
38
|
+
return b64uEncode(Uint8Array.from(Hash.sha256hmac(Array.from(k), data)))
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
function walletPart(w: LaunchWallet): LaunchWallet {
|
|
42
|
+
return { instanceId: w.instanceId, continuityKey: w.continuityKey }
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
function message(m: LaunchMessage): Record<string, unknown> {
|
|
46
|
+
return {
|
|
47
|
+
v: 1,
|
|
48
|
+
wallet: walletPart(m.wallet),
|
|
49
|
+
epoch: m.epoch,
|
|
50
|
+
origin: m.origin,
|
|
51
|
+
challenge: m.challenge,
|
|
52
|
+
host: m.host,
|
|
53
|
+
nonce: m.nonce
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
export function helloMac(k: Uint8Array, p: { origin: string; challenge: string; host: string }): string {
|
|
58
|
+
return mac(k, LABEL_HELLO, { v: 1, origin: p.origin, challenge: p.challenge, host: p.host })
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
export function describeAck(
|
|
62
|
+
k: Uint8Array,
|
|
63
|
+
p: { wallet: LaunchWallet; origin: string; challenge: string; host: string; nonce: string }
|
|
64
|
+
): string {
|
|
65
|
+
return mac(k, LABEL_DESCRIBE_ACK, {
|
|
66
|
+
v: 1,
|
|
67
|
+
wallet: walletPart(p.wallet),
|
|
68
|
+
origin: p.origin,
|
|
69
|
+
challenge: p.challenge,
|
|
70
|
+
host: p.host,
|
|
71
|
+
nonce: p.nonce
|
|
72
|
+
})
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
/** Body member `android.launchProof` of the connect request. */
|
|
76
|
+
export function launchProof(k: Uint8Array, m: LaunchMessage): string {
|
|
77
|
+
return mac(k, LABEL_LAUNCH, message(m))
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
/** Response header `BRC-185-Android-Ack` of a successful connect. */
|
|
81
|
+
export function connectAck(k: Uint8Array, m: LaunchMessage): string {
|
|
82
|
+
return mac(k, LABEL_ACK, message(m))
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
/** Never sent: both sides derive it and the page presents it as `BRC-185-Android-Binding`. */
|
|
86
|
+
export function bindingSecret(k: Uint8Array, m: LaunchMessage): string {
|
|
87
|
+
return mac(k, LABEL_BINDING, message(m))
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
/**
|
|
91
|
+
* Constant-time comparison of two base64url strings. A length difference returns false immediately
|
|
92
|
+
* (lengths of MAC outputs are public); equal-length strings are compared without early exit.
|
|
93
|
+
*/
|
|
94
|
+
export function timingSafeEqualB64u(a: string, b: string): boolean {
|
|
95
|
+
if (typeof a !== 'string' || typeof b !== 'string' || a.length !== b.length) return false
|
|
96
|
+
let diff = 0
|
|
97
|
+
for (let i = 0; i < a.length; i++) diff |= a.charCodeAt(i) ^ b.charCodeAt(i)
|
|
98
|
+
return diff === 0
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
const MAX_URI_BYTES = 512
|
|
102
|
+
const EPOCH_RE = /^[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/
|
|
103
|
+
const B64U_RE = /^[A-Za-z0-9_-]+$/
|
|
104
|
+
|
|
105
|
+
function canonicalBytes(s: string, length: number): Uint8Array | undefined {
|
|
106
|
+
if (!B64U_RE.test(s)) return undefined
|
|
107
|
+
try {
|
|
108
|
+
const bytes = b64uDecode(s)
|
|
109
|
+
return bytes.length === length ? bytes : undefined
|
|
110
|
+
} catch {
|
|
111
|
+
return undefined
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
/**
|
|
116
|
+
* Parse the plain URI the trampoline receives, `<scheme>://launch?v=1&e=&k=&n=`. Returns undefined for
|
|
117
|
+
* anything off-shape: wrong scheme or host, a fragment, a percent escape, an unknown or duplicate
|
|
118
|
+
* parameter, `v` other than `1`, an epoch that is not a lowercase UUIDv4, `k` not 32 and `n` not 16
|
|
119
|
+
* canonical base64url bytes, or more than 512 bytes.
|
|
120
|
+
*/
|
|
121
|
+
export function parseLaunchUri(uri: string, scheme: string): { epoch: string; k: Uint8Array; n: string } | undefined {
|
|
122
|
+
if (typeof uri !== 'string' || encoder.encode(uri).length > MAX_URI_BYTES) return undefined
|
|
123
|
+
const prefix = `${scheme}://launch?`
|
|
124
|
+
if (!uri.startsWith(prefix)) return undefined
|
|
125
|
+
const query = uri.slice(prefix.length)
|
|
126
|
+
if (query.includes('#') || query.includes('%')) return undefined
|
|
127
|
+
const seen = new Map<string, string>()
|
|
128
|
+
for (const part of query.split('&')) {
|
|
129
|
+
const eq = part.indexOf('=')
|
|
130
|
+
if (eq <= 0) return undefined
|
|
131
|
+
const name = part.slice(0, eq)
|
|
132
|
+
if (name !== 'v' && name !== 'e' && name !== 'k' && name !== 'n') return undefined
|
|
133
|
+
if (seen.has(name)) return undefined
|
|
134
|
+
seen.set(name, part.slice(eq + 1))
|
|
135
|
+
}
|
|
136
|
+
if (seen.size !== 4 || seen.get('v') !== '1') return undefined
|
|
137
|
+
const epoch = seen.get('e')!
|
|
138
|
+
if (!EPOCH_RE.test(epoch)) return undefined
|
|
139
|
+
const kBytes = canonicalBytes(seen.get('k')!, 32)
|
|
140
|
+
const n = seen.get('n')!
|
|
141
|
+
if (!kBytes || !canonicalBytes(n, 16)) return undefined
|
|
142
|
+
return { epoch, k: kBytes, n }
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
/** The plain URI the trampoline receives. Parameter order is fixed. */
|
|
146
|
+
export function buildLaunchUri(o: { scheme: string; epoch: string; k: Uint8Array; n: string }): string {
|
|
147
|
+
if (!EPOCH_RE.test(o.epoch)) throw new Error('launch epoch must be a lowercase UUIDv4')
|
|
148
|
+
if (o.k.length !== 32) throw new Error('launch secret must be 32 bytes')
|
|
149
|
+
if (!canonicalBytes(o.n, 16)) throw new Error('launch nonce must be 16 canonical base64url bytes')
|
|
150
|
+
return `${o.scheme}://launch?v=1&e=${o.epoch}&k=${b64uEncode(o.k)}&n=${o.n}`
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
/** Page side: the `intent://` link Chrome rewrites into {@link buildLaunchUri}'s form. */
|
|
154
|
+
export function buildIntentLink(opts: {
|
|
155
|
+
scheme: string
|
|
156
|
+
packageId: string
|
|
157
|
+
epoch: string
|
|
158
|
+
k: Uint8Array
|
|
159
|
+
n: string
|
|
160
|
+
fallbackUrl?: string
|
|
161
|
+
}): string {
|
|
162
|
+
const plain = buildLaunchUri({ scheme: opts.scheme, epoch: opts.epoch, k: opts.k, n: opts.n })
|
|
163
|
+
const rest = plain.slice(`${opts.scheme}://`.length)
|
|
164
|
+
const fallback = opts.fallbackUrl ? `S.browser_fallback_url=${encodeURIComponent(opts.fallbackUrl)};` : ''
|
|
165
|
+
return `intent://${rest}#Intent;scheme=${opts.scheme};package=${opts.packageId};${fallback}end`
|
|
166
|
+
}
|