@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
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,227 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## Unreleased
|
|
4
|
+
|
|
5
|
+
## 0.23.0
|
|
6
|
+
|
|
7
|
+
Peer floors raised to the latest `@bsv` releases, the browser wallet bridge
|
|
8
|
+
(BRC-185 core, Android loopback and iOS Safari seams: #57, #58, #59) and
|
|
9
|
+
encrypted wallet database export/import (#60).
|
|
10
|
+
|
|
11
|
+
### Peers
|
|
12
|
+
|
|
13
|
+
- **Raised floors** to the latest published releases: `@bsv/sdk` ^4.0.1,
|
|
14
|
+
`@bsv/wallet-toolbox-mobile` ^2.15.1, `@bsv/btms-permission-module` ^1.2.4,
|
|
15
|
+
`@bsv/message-box-client` ^2.7.0, `@bsv/webrtpay` ^0.2.3. Hosts copy
|
|
16
|
+
`patches/@bsv+wallet-toolbox-mobile+2.15.1.patch` in place of the 2.15.0 patch
|
|
17
|
+
(same changes, ported onto the 2.15.1 signing guard).
|
|
18
|
+
- `@bsv/backup-cache-client` 0.1.0 still peers `@bsv/sdk` ^2.4.1 (and its
|
|
19
|
+
`@bsv/auth` 0.1.3 peers ^2.1.6). Hosts keep an `overrides` entry for
|
|
20
|
+
`@bsv/sdk` until upstream widens these ranges.
|
|
21
|
+
|
|
22
|
+
### Fixed (review of the Android bridge overlay)
|
|
23
|
+
|
|
24
|
+
- `Sheet`: the open-spring completion no longer re-applies the open position once the sheet has been closed, and a
|
|
25
|
+
non-dismissible sheet hides its backdrop from screen readers.
|
|
26
|
+
- `PermissionSheet`: no longer closes a queue's modal flag itself; the queue does it when it empties, so a request
|
|
27
|
+
enqueued just before an answer cannot be left behind a closed flag.
|
|
28
|
+
|
|
29
|
+
### Browser bridge core
|
|
30
|
+
|
|
31
|
+
- **Transport-agnostic BRC-185 bridge engine** (`core/bridge`): origin rule, site consent with
|
|
32
|
+
reconnect tokens and a fresh grant tag per approval, a separate permissions manager for
|
|
33
|
+
unverified origins, bindings, the 28-method dispatcher, a durable inbox contract and host
|
|
34
|
+
wiring through `BrowserBridgeProvider`. No transport ships yet.
|
|
35
|
+
- **Conformance report.** `buildConformanceReport()` returns a versioned JSON listing the 28
|
|
36
|
+
methods, the bridge's refusals and the recorded deviations from BRC-185 / BRC-219; a snapshot
|
|
37
|
+
test keeps it deliberate.
|
|
38
|
+
|
|
39
|
+
### Browser bridge: seams for the Android loopback kit
|
|
40
|
+
|
|
41
|
+
- **`ContextRelay`** (`ui/bridgeSheet`). `ContextRelayPublisher` (first root, inside the providers) copies the
|
|
42
|
+
contexts `PermissionSheet` reads (`RELAYED_CONTEXTS`: theme, wallet, exchange rate, user) into a module store, and
|
|
43
|
+
`ContextRelaySubscriber` re-provides them on a second React root, rendering nothing until every entry is published.
|
|
44
|
+
A theme change reaches the second root without remounting it. Language is the i18n singleton and is not relayed;
|
|
45
|
+
safe-area insets are per native root and the second root mounts its own provider. A scan test fails when the
|
|
46
|
+
sheet's import closure reads a context that is not listed.
|
|
47
|
+
- **`Sheet` re-applies its open position on mount and on a host signal.** `signalSheetResumed()`
|
|
48
|
+
(`ui/components/ui/sheetResumeSignal`) nudges every open `Sheet`, for a host window that resumes without an
|
|
49
|
+
`AppState` change the sheet can see (the Android bridge's second root). The open spring also re-applies once it settles.
|
|
50
|
+
- **`PermissionSheet backdropDismisses={false}`, `Sheet dismissible={false}`.** `PermissionSheet` treats a backdrop tap
|
|
51
|
+
or a swipe down as a rejection; a host window where an outside tap must do nothing (the Android bridge's overlay root)
|
|
52
|
+
passes `false` on its own instance. A swipe then springs back to the open position instead of leaving the sheet off
|
|
53
|
+
screen. The default is unchanged, and the setting is per instance, not process-wide.
|
|
54
|
+
- **A second request queued behind an answered one is shown.** `PermissionSheet` closed the queue's modal flag after
|
|
55
|
+
every grant or deny, even with another request of the same kind still queued, and the queue only opens that flag when
|
|
56
|
+
it goes from empty to non-empty, so the next request (another site's, or the same site's) stayed hidden and its call
|
|
57
|
+
hung. The flag is now closed only when nothing else is queued behind the answered request.
|
|
58
|
+
|
|
59
|
+
- **`BridgeSnapshot.hostAttached`.** True once a host is attached and the runtime has loaded, false at start and
|
|
60
|
+
after detach. Every change goes through `onSnapshotChange`, so a transport hears attach and detach even when
|
|
61
|
+
readiness stays `none` (a cold start with no wallet).
|
|
62
|
+
- **`assertAdvertisesResponder(descriptor, responder)`** (protocol/descriptor): throws `ProofError` unless a
|
|
63
|
+
`http-json` endpoint of the descriptor has the same scheme, host and port as the responder that answered.
|
|
64
|
+
- **Loopback HTTP router** (`core/bridge/loopback/`): the pure BRC-185 4.1 HTTP semantics for a native loopback
|
|
65
|
+
transport. Router (describe, connect, RPC, disconnect, outcome mapping), Host check, endpoint list, CORS, status table
|
|
66
|
+
and the launch proof MACs (hello, describe ack, launch, ack, binding) with their JCS payloads. Platform code supplies
|
|
67
|
+
requests and receives responses; nothing here opens a socket.
|
|
68
|
+
- **Testing helpers** (`core/bridge/testing`): the `PageClient` contract types and the transport-independent
|
|
69
|
+
conformance cases (all 28 methods, error codec, request and response caps) a transport runs against its executor.
|
|
70
|
+
- **Stable test ids on the connection and permission sheet.** `bridge-connect-origin` (the full origin),
|
|
71
|
+
`bridge-approve` and `bridge-deny` for every prompt kind, for UI automation; no visual change.
|
|
72
|
+
- **Android copy.** `bridge_notifications_off`, `bridge_ports_exhausted` and `bridge_not_ready_android` in all
|
|
73
|
+
12 locales.
|
|
74
|
+
|
|
75
|
+
### Browser bridge: seams for a native transport (iOS Safari kit)
|
|
76
|
+
|
|
77
|
+
- **Exports.** The transport API (inbox processor, store contract, origin constants) is exported for
|
|
78
|
+
a native transport to import, the contract suite `__tests__/bridge/inboxContract` runs against any
|
|
79
|
+
store, and the origin and permission-policy constants moved into a pure module so
|
|
80
|
+
an extension bundle can import them without the app's config.
|
|
81
|
+
- **Events gap and retention.** The inbox event log keeps at most 1024 events and 24 hours; a reader
|
|
82
|
+
that asks after a trimmed cursor gets an explicit gap instead of silence. `flushEvents()` writes
|
|
83
|
+
pending events before a transport reads them. The store contract's raw-bytes hook is owned by the
|
|
84
|
+
harness, not the adapter.
|
|
85
|
+
- **`onPromptRaised`** transport hook: fires when a wallet prompt is raised for a binding, so a
|
|
86
|
+
transport can tell a call needed approval.
|
|
87
|
+
- **Merged Connect sheet.** One sheet lists the site's manifest groups (no toggles) and Connect mints
|
|
88
|
+
every listed item at once; the later group check raises no second sheet. "Don't connect" mints and
|
|
89
|
+
records nothing and starts a 30 second backoff (`RESOURCE_LIMIT`, "This site was just declined").
|
|
90
|
+
Unattested origins keep the plain sheet. New copy in all 12 locales (`bridge_*` keys).
|
|
91
|
+
- **`usePermissionSheetBusy()`** (from `PermissionSheet`): true while a permission sheet is open or
|
|
92
|
+
queued, so a done screen never covers one.
|
|
93
|
+
|
|
94
|
+
### Wallet data export
|
|
95
|
+
|
|
96
|
+
- **Encrypted export.** `exportAllWalletDatabases(storage, { encrypt: true, wallet, originator })`
|
|
97
|
+
writes `wallet-…-<ts>.db.enc`: a random file key wrapped by `wallet.encrypt` (counterparty
|
|
98
|
+
`self`, protocol `[2, 'wallet db export']`), body in 1 MiB AES-256-GCM chunks (STREAM nonces,
|
|
99
|
+
so reordered, dropped or truncated chunks fail). The snapshot comes from `VACUUM INTO` and is
|
|
100
|
+
encrypted a chunk at a time in native AES (`globalThis.__bsvNativeCrypto`), never held whole
|
|
101
|
+
in JS memory. Without `encrypt` the plain `.db` export is unchanged.
|
|
102
|
+
- **Encrypted import.** `importWalletDatabase(storage, { wallet, originator })` accepts `.db.enc`
|
|
103
|
+
up to 2 GiB, decrypting chunk by chunk to a temp file that SQLite opens from disk, then the same
|
|
104
|
+
identity/schema checks as before. Another wallet's file or a damaged one is refused as
|
|
105
|
+
untrusted; the picked copy and decrypted temp file are deleted either way.
|
|
106
|
+
- **UI.** Settings and Vault "Export Wallet Data" now export encrypted; dev builds get an extra
|
|
107
|
+
"Export Wallet Data (unencrypted)" row. `useExportWalletData().exportData({ encrypt })`
|
|
108
|
+
defaults to `true`.
|
|
109
|
+
- New core exports: `encryptDbImage`, `decryptDbImage`, `isEncryptedDbImage`, `EncryptedDbError`.
|
|
110
|
+
|
|
111
|
+
## 0.22.0
|
|
112
|
+
|
|
113
|
+
1Color / BRC-207 tokens through `@bsv/color-permission-module`. There is no
|
|
114
|
+
compatibility with `@bsv/mandala` 0.4: its assets, `'p mandala'` outputs,
|
|
115
|
+
`[2, 'p mandala token']` derivations, settlement tables and journals, frame
|
|
116
|
+
versions below 7, session version 1 and MessageBox bodies v1-v3 are all gone.
|
|
117
|
+
Built on design Amendment B7: the module transports no token history; the
|
|
118
|
+
host verifies hand-overs with `@bsv/mandala` and a host ledger.
|
|
119
|
+
|
|
120
|
+
### Breaking
|
|
121
|
+
|
|
122
|
+
- **Peers.** New: `@bsv/color-permission-module` ^0.2.0 and `@bsv/mandala`
|
|
123
|
+
^0.5.0. Raised: `@bsv/sdk` ^4.0.0, `@bsv/wallet-toolbox-mobile` ^2.15.0
|
|
124
|
+
(both from npm), `@bsv/templates` ^2.2.0. Hosts copy
|
|
125
|
+
`patches/@bsv+sdk+4.0.1.patch` (the color module 0.2.0 needs sdk ^4.0.1) and
|
|
126
|
+
`patches/@bsv+wallet-toolbox-mobile+2.15.0.patch` (regenerated against the
|
|
127
|
+
published 2.15.0) in place of the 2.8.11 / 2.14.9 patches and drop the
|
|
128
|
+
`@bsv+mandala+0.4.1` patch. The module's `@bsv/wallet-toolbox-client` peer
|
|
129
|
+
is satisfied by an npm alias of `-mobile` (README).
|
|
130
|
+
- **Metro and Jest.** Alias `@bsv/wallet-toolbox-client` to
|
|
131
|
+
`@bsv/wallet-toolbox-mobile` and enable package `exports` with `.mjs`/`.cjs`
|
|
132
|
+
source extensions (Metro). Transform `.mjs` with `babel-jest`, map
|
|
133
|
+
`@bsv/wallet-toolbox-client` and `@bsv/color-permission-module`, and allow
|
|
134
|
+
`@bsv/color-permission-module|@bsv/templates|@bsv/mandala` through
|
|
135
|
+
`transformIgnorePatterns` (Jest). See the README.
|
|
136
|
+
- **Token custody.** The `'p mandala'` P-module (`MandalaTokenModule`), the
|
|
137
|
+
basket migration and `wrapCreateActionForTokenInputs` are deleted.
|
|
138
|
+
WalletContext registers the BRC-207 color module as
|
|
139
|
+
`permissionModules.color` (the Mandala issuer-v1 profile only, over a
|
|
140
|
+
Mandala host ledger in `key_value_store`; a Mandala overlay provider; a
|
|
141
|
+
`ColorModuleStore` over `key_value_store`) only when the chain has Mandala
|
|
142
|
+
endpoints; otherwise `p color` calls fail closed. `BuiltColorModule` adds
|
|
143
|
+
`ledger`. `configureMandala` no longer takes a basket.
|
|
144
|
+
- **Storage.** A one-time guarded migration drops `token_settlements`,
|
|
145
|
+
`token_admissions`, `token_admission_edges` and `token_linkage_payloads` and
|
|
146
|
+
the old lib's `mandala.*` key-value journals, and creates the
|
|
147
|
+
`color_transfers` journal. The broadcast hold applies only where this
|
|
148
|
+
wallet's token custody is in a 1Color tx (a journal row, a Mandala
|
|
149
|
+
host-ledger record, or an input spent from one of its `p color` baskets)
|
|
150
|
+
and holds it until its row reads `settled`; a 1Color output with no custody
|
|
151
|
+
of ours (a payer's decoy) never parks a credit, on any rail. The abort
|
|
152
|
+
refusal keys on the journal: a `handed_over` or `settled` transfer is never
|
|
153
|
+
aborted. A pre-1Color backup
|
|
154
|
+
that still carries a settlement table is refused on import.
|
|
155
|
+
`ensureTokenSettlementColumns`, `createMandalaSettlementTables`,
|
|
156
|
+
`createSettlementStore`, `TokenTransactionRepair` and `OfflineTokenDeps` are
|
|
157
|
+
removed.
|
|
158
|
+
- **Exact amounts.** Token amounts are `bigint` in every API (per output
|
|
159
|
+
`1..18446744073709551615`) and canonical decimal strings on every wire and
|
|
160
|
+
in SQLite. `TokenBalance`, `TokenActivityRow`, `TokenAssetStatus` and the
|
|
161
|
+
`ui/tokenFormat` helpers take `bigint` units (`baseUnits` becomes `units`).
|
|
162
|
+
The `'reversed'` activity status is gone.
|
|
163
|
+
- **Runtime.** `MandalaRuntime` is the host over the color module (only its
|
|
164
|
+
host-only `markSettled(txid)`), `@bsv/mandala` 0.5.0 with the host ledger,
|
|
165
|
+
and the journal. `CreateMandalaRuntimeArgs` takes `color`
|
|
166
|
+
(`Pick<ColorPermissionModule, 'markSettled'>`), `ledger` and `hostWallet`
|
|
167
|
+
(the underlying wallet; hand-over envelopes are built from its custody);
|
|
168
|
+
`refetchBeef` is gone. Settlement is the host's: a delivered own hand-over
|
|
169
|
+
goes through lib `settleHandover`, a pending receipt through
|
|
170
|
+
`settleReceipts`, and both end in `markSettled` then the journal row.
|
|
171
|
+
Balances read the `p color balance <assetTag>` view; `offlineUnits` is the
|
|
172
|
+
same view filtered to `color_offline` (pending), the rest settled. Asset
|
|
173
|
+
metadata comes from the deploy tx (`readDeploy`). `tick()` redelivers
|
|
174
|
+
undelivered hand-overs, settles and reconciles held receipts, and the
|
|
175
|
+
offline drain runs it first.
|
|
176
|
+
- **Handle rail.** MessageBox box `mandala-color`, hand-over body `v: 4`
|
|
177
|
+
(receipt fields, σ `admission`/`admissions[]`, envelope `linkage[]`). A
|
|
178
|
+
hand-over's body is kept (`bsvwallet.color.handover.<txid>`) and its row
|
|
179
|
+
journaled `handed_over` before delivery; the tick redelivers the kept body.
|
|
180
|
+
Receive runs the lib's recipient path with the host ledger (online submit,
|
|
181
|
+
or offline COVER with the S1 hop checks) before the plain receipt is
|
|
182
|
+
internalized; a verified credit is journaled `settled`, a COVER one `held`.
|
|
183
|
+
- **Nearby.** Session version 2 (token units as a decimal string in `a`, no
|
|
184
|
+
overlay url/key) and localpay frame version 7 (IC §7.3: token block
|
|
185
|
+
`assetId`, decimal `amount`, `senderMode`, `admission?`, `admissions`,
|
|
186
|
+
`linkage`, `certificates`; frames below 7 are a `CodecError`). The payer
|
|
187
|
+
frames the v4 body of its hand-over; the payee pre-checks the evidence by
|
|
188
|
+
COVER against its own overlay key (`verifyFramePayment` opts gain
|
|
189
|
+
`overlayIdentityKey`; failures decline `not_covered`), and `processPending`
|
|
190
|
+
hands a token frame to the runtime's new `nearby.accept` (lib
|
|
191
|
+
`acceptHandover`) instead of internalizing it; `processPending` takes it as
|
|
192
|
+
a sixth argument and `NearbyTokenDeps.onReceived` reports `offline`. The
|
|
193
|
+
σI pieces are removed: `offline/tokenFrames`, `localpay/settlementAck`,
|
|
194
|
+
`mandala/drain`, `mandala/bundle` (`coverFromFrame`, `assembleBundle`,
|
|
195
|
+
`tokenParentsOf`) and their exports. A nearby BSV frame carrying a 1Color
|
|
196
|
+
output is no longer declined: the custody-scoped hold does not park it.
|
|
197
|
+
- **Hosted payer renderers.** On a token session `NearbyConfirm`,
|
|
198
|
+
`NearbySending` and `NearbyShowCode` carry the exact figure as `units`
|
|
199
|
+
(bigint) and `amountText`, and `NearbyConfirm` adds `fixedUnits`. The
|
|
200
|
+
number-shaped `amount` is 0 and `fixedAmount` is undefined there, and
|
|
201
|
+
`NearbyDone.amount` is 0 on a token payment. `NearbyConfirm.holding` is a
|
|
202
|
+
bigint, and `setAmount` takes a bigint (token base units) or a number
|
|
203
|
+
(satoshis). Hosts gate Send on `canSend` and read the payee's figure from
|
|
204
|
+
`fixedUnits` on a token session, never from `amount` / `fixedAmount`.
|
|
205
|
+
|
|
206
|
+
### Added
|
|
207
|
+
|
|
208
|
+
- Core barrel: `buildColorModule`, `createColorModuleStore`,
|
|
209
|
+
`createColorAccessPolicy`, `colorPromptType`, `COLOR_PROMPT_TYPES`,
|
|
210
|
+
`createTransferJournal`, `migrateMandalaToColor`, `colorHeldTxids`,
|
|
211
|
+
`txHasColorOutput`, the inventory readers (`readInventory`,
|
|
212
|
+
`readAvailable`, `readPending`, `offlineUnitsOf`, `createAssetMetadata`),
|
|
213
|
+
the v7 frame helpers (`bodyFromFrame`, `tokenPaymentOfHandover`), the
|
|
214
|
+
receipt failure classifiers and `createHandoverBodies`.
|
|
215
|
+
- The permission sheet renders the color module's consent messages
|
|
216
|
+
(`color_send`, `color_signature`, `color_access`, `color_relinquish`) with
|
|
217
|
+
exact amounts and the full asset id. The wallet's own screens are approved
|
|
218
|
+
for every type; a connected app prompts, and a read approval lasts 30
|
|
219
|
+
minutes for that app only. The removed `color_receive_offline` type is
|
|
220
|
+
unknown and refused.
|
|
221
|
+
- The services for the scaling teratestnet (`scaletest`, toolbox chain
|
|
222
|
+
`'regtest'`) now build on toolbox 2.15.0. The network stays out of the
|
|
223
|
+
picker.
|
|
224
|
+
|
|
3
225
|
## 0.21.0
|
|
4
226
|
|
|
5
227
|
### Breaking
|
package/README.md
CHANGED
|
@@ -55,17 +55,34 @@ Expo SDK line.
|
|
|
55
55
|
|
|
56
56
|
### BSV SDK & protocol libraries (required)
|
|
57
57
|
|
|
58
|
-
| Package
|
|
59
|
-
|
|
|
60
|
-
| `@bsv/sdk`
|
|
61
|
-
| `@bsv/wallet-toolbox-mobile`
|
|
62
|
-
| `@bsv/btms-permission-module`
|
|
63
|
-
| `@bsv/
|
|
64
|
-
| `@bsv/
|
|
65
|
-
| `@bsv/
|
|
66
|
-
| `@bsv/
|
|
67
|
-
| `@
|
|
68
|
-
| `
|
|
58
|
+
| Package | Version |
|
|
59
|
+
| ------------------------------ | ------- |
|
|
60
|
+
| `@bsv/sdk` | ^4.0.1 |
|
|
61
|
+
| `@bsv/wallet-toolbox-mobile` | ^2.15.1 |
|
|
62
|
+
| `@bsv/btms-permission-module` | ^1.2.4 |
|
|
63
|
+
| `@bsv/color-permission-module` | ^0.2.0 |
|
|
64
|
+
| `@bsv/mandala` | ^0.5.0 |
|
|
65
|
+
| `@bsv/air-gap` | ^0.1.3 |
|
|
66
|
+
| `@bsv/backup-cache-client` | ^0.1.0 |
|
|
67
|
+
| `@bsv/message-box-client` | ^2.7.0 |
|
|
68
|
+
| `@bsv/templates` | ^2.2.0 |
|
|
69
|
+
| `@noble/curves` | ^2.3.0 |
|
|
70
|
+
| `qrcode` | ^1.5.4 |
|
|
71
|
+
|
|
72
|
+
`@bsv/color-permission-module` is the BRC-207 color module that holds every
|
|
73
|
+
1Color token output; `@bsv/mandala` builds and reads Mandala hand-overs.
|
|
74
|
+
`@bsv/color-permission-module` imports `@bsv/wallet-toolbox-client`, which a
|
|
75
|
+
React Native app must alias to `@bsv/wallet-toolbox-mobile` (see
|
|
76
|
+
[`metro.config.js`](#metroconfigjs) and [Jest configuration](#jest-configuration)).
|
|
77
|
+
The module also declares `@bsv/wallet-toolbox-client` as a peer; satisfy it
|
|
78
|
+
with an npm alias of the mobile toolbox, e.g.
|
|
79
|
+
`"@bsv/wallet-toolbox-client": "npm:@bsv/wallet-toolbox-mobile@^2.15.1"`, so no
|
|
80
|
+
second toolbox is installed. That copy is never loaded (the bundler and Jest
|
|
81
|
+
map the name to `-mobile`), so `patch-package` patches only `-mobile`.
|
|
82
|
+
|
|
83
|
+
The files under this repo's `patches/` are in pnpm format: paths are relative
|
|
84
|
+
to the package root. For `patch-package`, prefix each path with
|
|
85
|
+
`node_modules/<package name>/`.
|
|
69
86
|
|
|
70
87
|
### Expo native modules (required — each needs its own autolinking/config)
|
|
71
88
|
|
|
@@ -462,6 +479,17 @@ config.resolver.extraNodeModules = {
|
|
|
462
479
|
...config.resolver.extraNodeModules
|
|
463
480
|
}
|
|
464
481
|
|
|
482
|
+
// The 1Color packages (@bsv/color-permission-module, @bsv/mandala,
|
|
483
|
+
// @bsv/templates) resolve through package `exports` to .mjs/.cjs entries.
|
|
484
|
+
config.resolver.unstable_enablePackageExports = true
|
|
485
|
+
for (const ext of ['mjs', 'cjs']) {
|
|
486
|
+
if (!config.resolver.sourceExts.includes(ext)) config.resolver.sourceExts.push(ext)
|
|
487
|
+
}
|
|
488
|
+
|
|
489
|
+
// @bsv/color-permission-module imports @bsv/wallet-toolbox-client; on React
|
|
490
|
+
// Native that is the same toolbox as -mobile (one toolbox in the bundle).
|
|
491
|
+
const MODULE_ALIASES = { '@bsv/wallet-toolbox-client': '@bsv/wallet-toolbox-mobile' }
|
|
492
|
+
|
|
465
493
|
const emptyShim = path.resolve(__dirname, 'metro-shims/empty.js') // module.exports = {}
|
|
466
494
|
const quickCryptoMain = require.resolve('react-native-quick-crypto')
|
|
467
495
|
|
|
@@ -473,6 +501,9 @@ config.resolver.resolveRequest = (context, moduleName, platform) => {
|
|
|
473
501
|
if (moduleName === 'node:buffer' || moduleName === 'node:process') {
|
|
474
502
|
return { type: 'sourceFile', filePath: emptyShim }
|
|
475
503
|
}
|
|
504
|
+
if (Object.prototype.hasOwnProperty.call(MODULE_ALIASES, moduleName)) {
|
|
505
|
+
moduleName = MODULE_ALIASES[moduleName]
|
|
506
|
+
}
|
|
476
507
|
if (typeof upstream === 'function') return upstream(context, moduleName, platform)
|
|
477
508
|
return context.resolveRequest(context, moduleName, platform)
|
|
478
509
|
}
|
|
@@ -496,7 +527,7 @@ are required — both hard-won during this package's extraction:
|
|
|
496
527
|
|
|
497
528
|
```
|
|
498
529
|
transformIgnorePatterns: [
|
|
499
|
-
"node_modules/(?!((jest-)?react-native|@react-native(-community)?|expo(nent)?|@expo(nent)?/.*|@expo-google-fonts/.*|react-navigation|@react-navigation/.*|@sentry/react-native|native-base|react-native-svg|react-native-reanimated|react-native-gesture-handler|react-native-worklets|expo-modules-core|@noble/secp256k1|@noble/curves|@noble/hashes|@bsv/backup-cache-client|@bsv/auth|@bsv/expo-wallet-toolbox|@bsv/react-native-localpay-transport)/)",
|
|
530
|
+
"node_modules/(?!((jest-)?react-native|@react-native(-community)?|expo(nent)?|@expo(nent)?/.*|@expo-google-fonts/.*|react-navigation|@react-navigation/.*|@sentry/react-native|native-base|react-native-svg|react-native-reanimated|react-native-gesture-handler|react-native-worklets|expo-modules-core|@noble/secp256k1|@noble/curves|@noble/hashes|@bsv/backup-cache-client|@bsv/auth|@bsv/expo-wallet-toolbox|@bsv/color-permission-module|@bsv/templates|@bsv/mandala|@bsv/react-native-localpay-transport|@bsv/webrtpay)/)",
|
|
500
531
|
"/node_modules/react-native-reanimated/plugin/"
|
|
501
532
|
]
|
|
502
533
|
```
|
|
@@ -510,7 +541,11 @@ are required — both hard-won during this package's extraction:
|
|
|
510
541
|
`@bsv/expo-wallet-toolbox`, `@bsv/react-native-localpay-transport`
|
|
511
542
|
(also raw TypeScript — `core/localpay/transport/select.ts` imports it
|
|
512
543
|
directly), and `@bsv/backup-cache-client` (see below) must be in
|
|
513
|
-
whatever pattern you end up with.
|
|
544
|
+
whatever pattern you end up with. Since 0.21.0 the allowlist must also
|
|
545
|
+
name `@bsv/color-permission-module`, `@bsv/templates` and `@bsv/mandala`:
|
|
546
|
+
they ship ES modules (`.mjs`) that Jest's CJS runtime must transform.
|
|
547
|
+
(`@bsv/webrtpay` is this repo's own optional peer; add it only if you
|
|
548
|
+
install it.)
|
|
514
549
|
|
|
515
550
|
`@urbit/sigil-js`, the peer added with the activity-row sigil avatars,
|
|
516
551
|
needs no entry here: the `./core` entry this package imports ships CJS,
|
|
@@ -526,6 +561,12 @@ are required — both hard-won during this package's extraction:
|
|
|
526
561
|
moduleNameMapper: {
|
|
527
562
|
'^@bsv/backup-cache-client$':
|
|
528
563
|
'<rootDir>/node_modules/@bsv/backup-cache-client/dist/index.js',
|
|
564
|
+
'^@bsv/wallet-toolbox-client$':
|
|
565
|
+
'<rootDir>/node_modules/@bsv/wallet-toolbox-mobile/out/index.mobile.cjs',
|
|
566
|
+
'^@bsv/wallet-toolbox-mobile$':
|
|
567
|
+
'<rootDir>/node_modules/@bsv/wallet-toolbox-mobile/out/index.mobile.cjs',
|
|
568
|
+
'^@bsv/color-permission-module$':
|
|
569
|
+
'<rootDir>/node_modules/@bsv/color-permission-module/dist/index.mjs',
|
|
529
570
|
'^react-native-reanimated$': '<rootDir>/__tests__/__mocks__/reanimated.js',
|
|
530
571
|
'^react-native-worklets$':
|
|
531
572
|
'<rootDir>/node_modules/react-native-worklets/lib/module/mock.js',
|
|
@@ -548,6 +589,23 @@ are required — both hard-won during this package's extraction:
|
|
|
548
589
|
entries below, which only bite once a test actually exercises that
|
|
549
590
|
native API.
|
|
550
591
|
|
|
592
|
+
The three 1Color entries (since 0.21.0):
|
|
593
|
+
- `@bsv/wallet-toolbox-client` → the mobile toolbox's CJS entry. The color
|
|
594
|
+
module imports `-client`; this is the same alias as in Metro, so tests
|
|
595
|
+
and the app run one toolbox.
|
|
596
|
+
- `@bsv/wallet-toolbox-mobile` → the same CJS entry, so both names resolve
|
|
597
|
+
to one module instance.
|
|
598
|
+
- `@bsv/color-permission-module` → `dist/index.mjs`. Its `exports` carries
|
|
599
|
+
only an `import` condition, which Jest's require-side resolver never
|
|
600
|
+
matches.
|
|
601
|
+
|
|
602
|
+
Add a transform for `.mjs` beside the preset's, so those `.mjs` entries go
|
|
603
|
+
through Babel:
|
|
604
|
+
|
|
605
|
+
```js
|
|
606
|
+
transform: { '\\.mjs$': 'babel-jest' }
|
|
607
|
+
```
|
|
608
|
+
|
|
551
609
|
`expo-sqlite`/`expo-audio` need hand-written mocks (see this repo's
|
|
552
610
|
`__tests__/__mocks__/` for working examples) since they wrap native
|
|
553
611
|
modules with no official Jest mock; `async-storage` and
|
|
@@ -562,6 +620,17 @@ are required — both hard-won during this package's extraction:
|
|
|
562
620
|
|
|
563
621
|
## Breaking changes
|
|
564
622
|
|
|
623
|
+
**0.21.0:** tokens are 1Color (BRC-162) assets held by the BRC-207 color
|
|
624
|
+
module, with no compatibility with `@bsv/mandala` 0.4 assets, outputs or the
|
|
625
|
+
`'p mandala'` basket. Install the new peers (`@bsv/color-permission-module`
|
|
626
|
+
^0.2.0, `@bsv/mandala` ^0.5.0) and the raised ones (`@bsv/sdk` ^4.0.0,
|
|
627
|
+
`@bsv/wallet-toolbox-mobile` ^2.15.0, `@bsv/templates` ^2.2.0). Copy
|
|
628
|
+
`patches/@bsv+sdk+4.0.1.patch` and `patches/@bsv+wallet-toolbox-mobile+2.15.0.patch`
|
|
629
|
+
in place of the 2.8.11/2.14.9 patches, and delete any `@bsv+mandala+0.4.1`
|
|
630
|
+
patch. Add the Metro alias and `exports` settings and the Jest `.mjs`
|
|
631
|
+
transform, mappers and allowlist entries above. Token amounts are `bigint`
|
|
632
|
+
everywhere. See the CHANGELOG's 0.21.0 entry for the full list.
|
|
633
|
+
|
|
565
634
|
**0.10.0:** `verifyFramePayment` takes `{ wallet, chainTracker }`
|
|
566
635
|
(`FrameVerifyDeps`) as its first argument instead of a single wallet, and
|
|
567
636
|
`DerivingWallet` no longer includes `getServices()`. Pass the permissions
|
|
@@ -0,0 +1,273 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* BrowserBridgeProvider publishes the open wallet to the bridge runtime (spec 6.9).
|
|
3
|
+
*
|
|
4
|
+
* Mount it inside `WalletContextProvider` (opt-in; without it every bridge request fails
|
|
5
|
+
* `CONFIGURATION_ERROR`). It follows the `DirectPayProvider` template: once the wallet is built it
|
|
6
|
+
* reads the identity key from that wallet's manager, derives the account context from it and the
|
|
7
|
+
* network, and keeps the result keyed on the manager's object identity so a rebuilt wallet never
|
|
8
|
+
* publishes the last one's context.
|
|
9
|
+
*
|
|
10
|
+
* It reports, in one place: the attested manager, the unverified one when an unattested transport
|
|
11
|
+
* was registered at build time, readiness, network and account context. What the runtime does with
|
|
12
|
+
* a replaced manager (revision bump, binding close, prompt withdrawal) is in `runtime.ts`.
|
|
13
|
+
*
|
|
14
|
+
* Wiring: as soon as the runtime is loaded it builds the `ConsentStore`, installs the dispatcher
|
|
15
|
+
* on it, registers the store's withdrawal with the runtime and hands the store to the
|
|
16
|
+
* PermissionSheet's `connection` kind. The dispatcher is installed whether or not a wallet is
|
|
17
|
+
* built, so a request that arrives while the wallet is still building parks (6.6) instead of
|
|
18
|
+
* failing. The store reaches the admin-scoped wallet (wrapped exactly as `PairScreen` wraps it for
|
|
19
|
+
* `connectionAuthority`) through a lookup that always reads the current one, and the dispatcher
|
|
20
|
+
* only touches the store once readiness is `ready`. A wallet replacement settles pending consent
|
|
21
|
+
* through the binding close (`account-changed`), not by declining it; unmount withdraws the
|
|
22
|
+
* requests and uninstalls all of it.
|
|
23
|
+
*
|
|
24
|
+
* Readiness: `blocked` while the secrets layer is locked, `ready` once a manager and its account
|
|
25
|
+
* context are in hand, `building` while a build runs or the context is still being derived, and
|
|
26
|
+
* `none` otherwise.
|
|
27
|
+
*/
|
|
28
|
+
import React, { useEffect, useMemo, useRef, useState, useSyncExternalStore } from 'react'
|
|
29
|
+
import AsyncStorage from '@react-native-async-storage/async-storage'
|
|
30
|
+
import type { WalletInterface } from '@bsv/sdk'
|
|
31
|
+
import { profileScopedKey } from '../profiles/profileStore'
|
|
32
|
+
import { capWalletArgs } from '../services/capWalletArgs'
|
|
33
|
+
import { guardVaultAccess } from '../services/vault/guard'
|
|
34
|
+
import { getUnlockState, subscribeUnlockState } from '../services/secrets'
|
|
35
|
+
import { useWallet, useWalletManagers, useWalletStatus } from '../context/WalletContext'
|
|
36
|
+
import type { SigningPolicyPermissionsManager } from '../services/signingPermissionPolicy'
|
|
37
|
+
import { createConsentStore, type HmacCapableWallet } from './consent'
|
|
38
|
+
import { mintGrantTag, unverifiedOriginator, isUnattestedOriginator } from './unverifiedOriginator'
|
|
39
|
+
import { createDispatcher, installDispatcher } from './dispatcher'
|
|
40
|
+
import { setConsentSheetSource } from './consentSheetSource'
|
|
41
|
+
import { loadStoredPolicy, resolvePermissionPolicy, type PermissionPolicy } from './permissionPolicy'
|
|
42
|
+
import {
|
|
43
|
+
attachBridgeHost,
|
|
44
|
+
computeAccountContext,
|
|
45
|
+
initBridgeRuntime,
|
|
46
|
+
publish,
|
|
47
|
+
registerConsentWithdrawal,
|
|
48
|
+
setActiveConsent,
|
|
49
|
+
getBridgeSnapshot,
|
|
50
|
+
getPublishedManagers,
|
|
51
|
+
setBridgeBaseVersion,
|
|
52
|
+
type BridgeManager,
|
|
53
|
+
type BridgeReadiness
|
|
54
|
+
} from './runtime'
|
|
55
|
+
|
|
56
|
+
const ACCOUNT_CONTEXT_RETRY_MS = 1000
|
|
57
|
+
const ACCOUNT_CONTEXT_RETRY_MAX_MS = 30_000
|
|
58
|
+
|
|
59
|
+
interface ContextFor {
|
|
60
|
+
signing: SigningPolicyPermissionsManager
|
|
61
|
+
network: string
|
|
62
|
+
value: string
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
export const BrowserBridgeProvider: React.FC<{ children?: React.ReactNode; baseVersion?: string }> = ({
|
|
66
|
+
children,
|
|
67
|
+
baseVersion
|
|
68
|
+
}) => {
|
|
69
|
+
const { managers, adminOriginator } = useWalletManagers()
|
|
70
|
+
const { walletBuilt, walletBuilding, selectedNetwork } = useWalletStatus()
|
|
71
|
+
const { withdrawPrompts, configStatus } = useWallet()
|
|
72
|
+
const unlock = useSyncExternalStore(subscribeUnlockState, getUnlockState, getUnlockState)
|
|
73
|
+
|
|
74
|
+
// The context value changes on every queue change; teardown needs the current function.
|
|
75
|
+
const withdrawRef = useRef(withdrawPrompts)
|
|
76
|
+
withdrawRef.current = withdrawPrompts
|
|
77
|
+
|
|
78
|
+
// Cold start: until the wallet shell has read its stored config (`configStatus` leaves 'initial'
|
|
79
|
+
// for the first time) it is not yet known whether this install has a wallet, so the bridge
|
|
80
|
+
// reports `building`, never `none` (spec 6.15 item 9). A later 'initial' (after logout) is not a
|
|
81
|
+
// cold start: the ref is cleared for good.
|
|
82
|
+
const coldStartRef = useRef(true)
|
|
83
|
+
if (configStatus !== 'initial') coldStartRef.current = false
|
|
84
|
+
const awaitingConfig = coldStartRef.current
|
|
85
|
+
|
|
86
|
+
const [loaded, setLoaded] = useState(false)
|
|
87
|
+
useEffect(() => {
|
|
88
|
+
let current = true
|
|
89
|
+
const detach = attachBridgeHost({ withdrawPrompts: old => withdrawRef.current(old), hasWallet: true })
|
|
90
|
+
initBridgeRuntime().then(
|
|
91
|
+
() => {
|
|
92
|
+
if (current) setLoaded(true)
|
|
93
|
+
},
|
|
94
|
+
e => console.warn('[BrowserBridgeProvider] runtime did not load:', e instanceof Error ? e.message : String(e))
|
|
95
|
+
)
|
|
96
|
+
return () => {
|
|
97
|
+
current = false
|
|
98
|
+
detach()
|
|
99
|
+
}
|
|
100
|
+
}, [])
|
|
101
|
+
|
|
102
|
+
useEffect(() => {
|
|
103
|
+
if (baseVersion !== undefined) setBridgeBaseVersion(baseVersion)
|
|
104
|
+
}, [baseVersion])
|
|
105
|
+
|
|
106
|
+
const signing = managers.signingPermissionsManager
|
|
107
|
+
const wallet = managers.permissionsManager as unknown as (WalletInterface & object) | undefined
|
|
108
|
+
|
|
109
|
+
// The account context of the wallet it was derived from, never of its predecessor. A failed
|
|
110
|
+
// derivation (a locked keychain, a transient secure-store error) is retried with a growing
|
|
111
|
+
// delay; readiness stays `building` meanwhile, so requests park and the dispatcher's own
|
|
112
|
+
// `wallet-not-ready` nudge stays true.
|
|
113
|
+
const [contextFor, setContextFor] = useState<ContextFor | undefined>(undefined)
|
|
114
|
+
const [contextAttempt, setContextAttempt] = useState(0)
|
|
115
|
+
const contextFailures = useRef(0)
|
|
116
|
+
useEffect(() => {
|
|
117
|
+
if (!loaded || !walletBuilt || !signing || !wallet) return
|
|
118
|
+
let current = true
|
|
119
|
+
let retry: ReturnType<typeof setTimeout> | undefined
|
|
120
|
+
wallet
|
|
121
|
+
.getPublicKey({ identityKey: true }, adminOriginator)
|
|
122
|
+
.then(({ publicKey }) => computeAccountContext(publicKey, selectedNetwork))
|
|
123
|
+
.then(value => {
|
|
124
|
+
contextFailures.current = 0
|
|
125
|
+
if (current) setContextFor({ signing, network: selectedNetwork, value })
|
|
126
|
+
})
|
|
127
|
+
.catch(e => {
|
|
128
|
+
console.warn('[BrowserBridgeProvider] No account context:', e instanceof Error ? e.message : String(e))
|
|
129
|
+
if (!current) return
|
|
130
|
+
const delay = Math.min(
|
|
131
|
+
ACCOUNT_CONTEXT_RETRY_MAX_MS,
|
|
132
|
+
ACCOUNT_CONTEXT_RETRY_MS * 2 ** Math.min(contextFailures.current++, 8)
|
|
133
|
+
)
|
|
134
|
+
retry = setTimeout(() => setContextAttempt(n => n + 1), delay)
|
|
135
|
+
})
|
|
136
|
+
return () => {
|
|
137
|
+
current = false
|
|
138
|
+
if (retry !== undefined) clearTimeout(retry)
|
|
139
|
+
}
|
|
140
|
+
}, [loaded, walletBuilt, signing, wallet, adminOriginator, selectedNetwork, contextAttempt, unlock.status])
|
|
141
|
+
|
|
142
|
+
// The admin-scoped wallet the consent store authenticates with. Read through `adminRef`, so the
|
|
143
|
+
// one store (below) always uses the current wallet and never a stale one.
|
|
144
|
+
const adminWallet = useMemo(
|
|
145
|
+
() => (wallet ? capWalletArgs(guardVaultAccess(wallet, adminOriginator)) : undefined),
|
|
146
|
+
[wallet, adminOriginator]
|
|
147
|
+
)
|
|
148
|
+
const adminRef = useRef(adminWallet)
|
|
149
|
+
adminRef.current = adminWallet
|
|
150
|
+
|
|
151
|
+
// The user's stored prompt policy, as the wallet was built with it: what the sheet discloses.
|
|
152
|
+
const storedPolicyRef = useRef<PermissionPolicy | undefined>(undefined)
|
|
153
|
+
useEffect(() => {
|
|
154
|
+
storedPolicyRef.current = undefined
|
|
155
|
+
if (!loaded || !adminWallet) return
|
|
156
|
+
let current = true
|
|
157
|
+
loadStoredPolicy(profileScopedKey(''), adminWallet, adminOriginator).then(
|
|
158
|
+
p => {
|
|
159
|
+
if (current) storedPolicyRef.current = p
|
|
160
|
+
},
|
|
161
|
+
() => undefined
|
|
162
|
+
)
|
|
163
|
+
return () => {
|
|
164
|
+
current = false
|
|
165
|
+
}
|
|
166
|
+
}, [loaded, adminWallet, adminOriginator])
|
|
167
|
+
|
|
168
|
+
// Consent store and dispatcher, installed once the runtime is loaded and kept across wallet
|
|
169
|
+
// replacements. The store's records are tagged by the admin key, so a different wallet never
|
|
170
|
+
// shares one; the profile key is read live, so the store notices a profile switch that has not
|
|
171
|
+
// yet produced a new wallet.
|
|
172
|
+
useEffect(() => {
|
|
173
|
+
if (!loaded) return
|
|
174
|
+
const lookup = (): HmacCapableWallet => {
|
|
175
|
+
const w = adminRef.current
|
|
176
|
+
if (!w) throw new Error('No wallet is available')
|
|
177
|
+
return w
|
|
178
|
+
}
|
|
179
|
+
const lazyAdmin: HmacCapableWallet = {
|
|
180
|
+
createHmac: (args, originator) => lookup().createHmac(args, originator),
|
|
181
|
+
verifyHmac: (args, originator) => lookup().verifyHmac(args, originator)
|
|
182
|
+
}
|
|
183
|
+
const store = createConsentStore({
|
|
184
|
+
storage: AsyncStorage,
|
|
185
|
+
adminWallet: lazyAdmin,
|
|
186
|
+
adminOriginator,
|
|
187
|
+
profileKey: () => profileScopedKey(''),
|
|
188
|
+
now: () => Date.now(),
|
|
189
|
+
randomBytes: n => globalThis.crypto.getRandomValues(new Uint8Array(n)),
|
|
190
|
+
// The manager that will check the group: the unverified one for an unverified originator.
|
|
191
|
+
mint: async (originator, group) => {
|
|
192
|
+
const published = getPublishedManagers()
|
|
193
|
+
const manager = isUnattestedOriginator(originator) ? published.unverified : published.attested
|
|
194
|
+
if (manager === undefined) throw new Error('No permissions manager to mint under')
|
|
195
|
+
await manager.signing.mintGroupedPermissions(originator, group)
|
|
196
|
+
}
|
|
197
|
+
})
|
|
198
|
+
const unregister = registerConsentWithdrawal(() => store.withdrawAll())
|
|
199
|
+
const unregisterActive = setActiveConsent({
|
|
200
|
+
store,
|
|
201
|
+
adminWallet: lazyAdmin,
|
|
202
|
+
adminOriginator,
|
|
203
|
+
profileKey: () => profileScopedKey('')
|
|
204
|
+
})
|
|
205
|
+
const dispatcher = createDispatcher({
|
|
206
|
+
consent: store,
|
|
207
|
+
previewGroup: async binding => {
|
|
208
|
+
const host = /^https?:\/\/([^/:]+)(?::\d+)?$/.exec(binding.applicationOrigin)?.[1]
|
|
209
|
+
if (host === undefined) return null
|
|
210
|
+
const published = getPublishedManagers()
|
|
211
|
+
// An unverified site's real originator carries a grant tag minted at approval; the
|
|
212
|
+
// preview needs only the hostname, which the unverified manager reads the manifest from.
|
|
213
|
+
const preview =
|
|
214
|
+
binding.attestation === 'unattested'
|
|
215
|
+
? { manager: published.unverified, originator: unverifiedOriginator(host, mintGrantTag()) }
|
|
216
|
+
: { manager: published.attested, originator: host }
|
|
217
|
+
return (await preview.manager?.signing.peekGroupPermissions(preview.originator)) ?? null
|
|
218
|
+
}
|
|
219
|
+
})
|
|
220
|
+
installDispatcher(dispatcher)
|
|
221
|
+
setConsentSheetSource({
|
|
222
|
+
store,
|
|
223
|
+
context: () => ({ walletRevision: Number(getBridgeSnapshot().walletRevision), profileKey: profileScopedKey('') }),
|
|
224
|
+
// The policy the unverified manager was built with (WalletContext): the host's statement
|
|
225
|
+
// plus the user's stored policy.
|
|
226
|
+
policy: () => resolvePermissionPolicy(storedPolicyRef.current)
|
|
227
|
+
})
|
|
228
|
+
return () => {
|
|
229
|
+
store.withdrawAll()
|
|
230
|
+
unregister()
|
|
231
|
+
unregisterActive()
|
|
232
|
+
setConsentSheetSource(undefined)
|
|
233
|
+
installDispatcher(undefined)
|
|
234
|
+
}
|
|
235
|
+
}, [loaded, adminOriginator])
|
|
236
|
+
|
|
237
|
+
const unverifiedSigning = managers.unverifiedSigningPermissionsManager
|
|
238
|
+
const unverifiedWallet = managers.unverifiedPermissionsManager as unknown as WalletInterface | undefined
|
|
239
|
+
|
|
240
|
+
useEffect(() => {
|
|
241
|
+
if (!loaded) return
|
|
242
|
+
const haveWallet = walletBuilt && !!signing && !!wallet
|
|
243
|
+
const accountContext =
|
|
244
|
+
haveWallet && contextFor?.signing === signing && contextFor.network === selectedNetwork ? contextFor.value : ''
|
|
245
|
+
const status = unlock.status
|
|
246
|
+
let readiness: BridgeReadiness
|
|
247
|
+
if (status === 'locked' || status === 'unlocking' || status === 'cancelled') readiness = 'blocked'
|
|
248
|
+
else if (haveWallet && accountContext) readiness = 'ready'
|
|
249
|
+
else if (walletBuilding || haveWallet || awaitingConfig) readiness = 'building'
|
|
250
|
+
else readiness = 'none'
|
|
251
|
+
|
|
252
|
+
const attestedManager: BridgeManager | undefined = haveWallet ? { wallet: wallet!, signing: signing! } : undefined
|
|
253
|
+
const unverifiedManager: BridgeManager | undefined =
|
|
254
|
+
haveWallet && unverifiedSigning && unverifiedWallet
|
|
255
|
+
? { wallet: unverifiedWallet, signing: unverifiedSigning }
|
|
256
|
+
: undefined
|
|
257
|
+
publish({ attestedManager, unverifiedManager, readiness, network: selectedNetwork, accountContext })
|
|
258
|
+
}, [
|
|
259
|
+
loaded,
|
|
260
|
+
walletBuilt,
|
|
261
|
+
walletBuilding,
|
|
262
|
+
awaitingConfig,
|
|
263
|
+
signing,
|
|
264
|
+
wallet,
|
|
265
|
+
unverifiedSigning,
|
|
266
|
+
unverifiedWallet,
|
|
267
|
+
selectedNetwork,
|
|
268
|
+
contextFor,
|
|
269
|
+
unlock.status
|
|
270
|
+
])
|
|
271
|
+
|
|
272
|
+
return <>{children}</>
|
|
273
|
+
}
|