@bsv/expo-wallet-toolbox 0.2.1 → 0.3.1
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 +232 -0
- package/README.md +34 -9
- package/core/amountFormatHelpers.ts +16 -30
- package/core/context/LocalStorageProvider.tsx +29 -4
- package/core/context/WalletContext.tsx +15 -3
- package/core/i18n/translations.tsx +12 -0
- package/core/index.ts +16 -5
- package/core/localpay/build.ts +4 -1
- package/core/localpay/pending.ts +5 -2
- package/core/pay/counterparty.ts +159 -0
- package/core/pay/creditInbox.ts +0 -3
- package/core/pay/patp.ts +181 -0
- package/core/pay/rails/address.ts +47 -7
- package/core/pay/rails/handle.ts +24 -14
- package/core/peerpay/handleResendRequests.ts +1 -2
- package/core/services/secrets/migration.ts +3 -2
- package/core/services/secrets/store.ts +6 -4
- package/core/services/vault/backupAttestation.ts +17 -2
- package/core/storage/StorageExpoSQLite.ts +37 -0
- package/core/storage/methods/listActionsSql.ts +9 -0
- package/core/theme/sigilPalette.ts +83 -0
- package/package.json +5 -2
- package/ui/components/pay/HandleReceive.tsx +4 -4
- package/ui/components/ui/AppLogo.tsx +9 -1
- package/ui/components/ui/Sigil.tsx +62 -0
- package/ui/components/wallet/ActivityRow.tsx +87 -24
- package/ui/isImageUrl.ts +16 -3
- package/ui/screens/ConnectionsScreen.tsx +12 -2
- package/ui/screens/TrustScreen.tsx +105 -23
- package/ui/screens/WalletCheckScreen.tsx +3 -3
- package/ui/screens/WalletConfigScreen.tsx +23 -104
- package/ui/screens/WalletHomeScreen.tsx +38 -19
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,232 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
## 0.3.1
|
|
4
|
+
|
|
5
|
+
### Wallet creation and backup
|
|
6
|
+
|
|
7
|
+
- Add `useLocalStorage().createMnemonic` for new wallets. It refuses to
|
|
8
|
+
replace an existing encrypted or legacy identity, waits for migration,
|
|
9
|
+
and blocks overlapping creation attempts. Identity checks propagate
|
|
10
|
+
storage errors instead of treating unreadable keys as an empty wallet.
|
|
11
|
+
- Wallet Home waits for migration and wallet construction before offering
|
|
12
|
+
creation or import. Backup reminders now require an explicit pending
|
|
13
|
+
record for a newly created identity; existing wallets without historical
|
|
14
|
+
backup metadata no longer receive a false warning.
|
|
15
|
+
- Add `backupAttestation.markPending` and `needsReminder`. Recording a
|
|
16
|
+
backup clears the pending reminder, and logout clears both record types.
|
|
17
|
+
- Advanced Settings replaces Copy Secret Words and Print Recovery Keys
|
|
18
|
+
with Backup Wallet Keys, linking to `/auth/mnemonic?flow=backup`, with
|
|
19
|
+
translations in all twelve supported languages.
|
|
20
|
+
|
|
21
|
+
### Pairing
|
|
22
|
+
|
|
23
|
+
- Connections accepts both `bsv-wallet://` and `bsv-browser://` pairing
|
|
24
|
+
codes. Forwarded pairing parameters retain reserved characters in
|
|
25
|
+
topics, origins, protocol identifiers, and signatures.
|
|
26
|
+
|
|
27
|
+
### Host app integration
|
|
28
|
+
|
|
29
|
+
- The mnemonic backup page and native URL registration remain owned by
|
|
30
|
+
the host app. Its `/auth/mnemonic?flow=backup` route must display the
|
|
31
|
+
existing identity, and new-wallet creation should use `createMnemonic`.
|
|
32
|
+
The confirmation delay, export actions, and back button are implemented
|
|
33
|
+
in the BSV Wallet app rather than shipped in this package.
|
|
34
|
+
- Hosts accepting both URL schemes must register them in their native
|
|
35
|
+
configuration and rebuild the app. BSV Wallet routes external pairing
|
|
36
|
+
links through `app/+native-intent.ts` to `/connections`.
|
|
37
|
+
|
|
38
|
+
## 0.3.0
|
|
39
|
+
|
|
40
|
+
### Breaking
|
|
41
|
+
|
|
42
|
+
- `INBOX_DESCRIPTION` is removed from `core/pay/creditInbox` (and so from the
|
|
43
|
+
`core` barrel). Inbound peer rows are now described by the sender's note or,
|
|
44
|
+
failing that, the sender's abbreviated identity key, so the fixed default
|
|
45
|
+
string has no remaining use.
|
|
46
|
+
- `internalizeIncoming` and `acceptWithRetry` in `core/pay/rails/handle` no
|
|
47
|
+
longer take a positional `description`. The signatures are now
|
|
48
|
+
`internalizeIncoming(wallet, client, adminOriginator, payment, repairBeef?)`
|
|
49
|
+
and `acceptWithRetry(client, messageBoxUrl, payment, internalize)`, with
|
|
50
|
+
`internalize: (p: IncomingPayment) => Promise<void>`. A JavaScript caller
|
|
51
|
+
still passing the old fifth argument would hand `acceptWithRetry` a string
|
|
52
|
+
where it expects the `internalize` function and every inbox credit would
|
|
53
|
+
throw; TypeScript callers see an arity error.
|
|
54
|
+
|
|
55
|
+
### Activity
|
|
56
|
+
|
|
57
|
+
- Activity rows show a deterministic sigil avatar for the counterparty in the
|
|
58
|
+
tile where the direction arrow used to sit. The face is derived from the
|
|
59
|
+
counterparty's identity key when the row records one (a pubkey label on an
|
|
60
|
+
outbound peer payment, or `senderIdentityKey` on an inbound one), else the
|
|
61
|
+
address from a `to:`/`from:` label, else the txid, so two payments to the
|
|
62
|
+
same key wear the same face. Direction stays on the tile's border tint, and
|
|
63
|
+
a row with nothing to identify the other side keeps the arrow. The address
|
|
64
|
+
sweep's sentinel `senderIdentityKey` (the pubkey of private key 1) is not a
|
|
65
|
+
counterparty and falls through to the txid. Each face also has its own
|
|
66
|
+
colour: the hue is taken from the four bytes before the shape seed
|
|
67
|
+
(`counterpartyHue`), so shape and colour vary independently, and
|
|
68
|
+
`sigilPalette` turns it into a per-theme symbol and tile pair (pale tile
|
|
69
|
+
and deep symbol in light, deep tile and bright symbol in dark) that is
|
|
70
|
+
contrast-checked to at least 4.5:1 for every hue in both themes.
|
|
71
|
+
- Default action descriptions are now the payment note, else the resolved
|
|
72
|
+
name, else the abbreviated identity key or address, instead of a rail name.
|
|
73
|
+
- `listActions` rows expose `senderIdentityKey` (from
|
|
74
|
+
`outputs.senderIdentityKey`) alongside `reference` and `created_at`, and
|
|
75
|
+
`ActivityAction` declares it.
|
|
76
|
+
- Address-rail rows carry `to:` (outbound send) and `from:` (inbound sweep,
|
|
77
|
+
the payer's zeroth-input P2PKH address) labels, so the address rail has a
|
|
78
|
+
counterparty to show as well. The payload after the prefix is the address's
|
|
79
|
+
version byte and hash160 as 42 hex characters, built by `addressLabel` and
|
|
80
|
+
decoded back to base58 by `counterpartyOf`: the wallet folds every label to
|
|
81
|
+
lower case before storing it (`@bsv/sdk` `validateLabel`), which a base58
|
|
82
|
+
spelling does not survive but hex does.
|
|
83
|
+
|
|
84
|
+
### Amounts
|
|
85
|
+
|
|
86
|
+
- Fiat amounts follow the satoshi sign convention: a leading minus for money
|
|
87
|
+
out and, where the caller asks for it, a leading plus for money in.
|
|
88
|
+
Accounting parentheses are gone. The sub-cent marker keeps its form with the
|
|
89
|
+
sign on the figure, e.g. `< -$0.01`.
|
|
90
|
+
|
|
91
|
+
### Trust network
|
|
92
|
+
|
|
93
|
+
- Provider icons load through `expo-image` instead of React Native's core
|
|
94
|
+
`Image`, so a BRC-68 manifest that advertises an SVG icon (for example
|
|
95
|
+
`https://auth.sigmaidentity.com/manifest.json`) passes validation and
|
|
96
|
+
displays instead of failing with "icon image URL is invalid". `prefetch`'s
|
|
97
|
+
boolean result is preserved, so an unavailable image still rejects.
|
|
98
|
+
Contributed in #12 by @rohenaz. SVG icons themselves are drawn with
|
|
99
|
+
react-native-svg's parser (`SvgUri`) rather than handed to the platform
|
|
100
|
+
decoder: iOS's decoder ignores percentage-positioned `<text>`, which is how
|
|
101
|
+
Sigma's mark is authored, and rendered it as a black square.
|
|
102
|
+
- The built-in certifiers now show their icons. The screen kept a local
|
|
103
|
+
`Certifier` type that read `icon`, while the wallet's settings type and every
|
|
104
|
+
shipped default store the URL as `iconUrl`, so the defaults always fell to
|
|
105
|
+
the initial-letter placeholder. The screen now uses the settings type,
|
|
106
|
+
accepts entries an older build saved under `icon`, and writes `iconUrl` back
|
|
107
|
+
on save (`normaliseCertifier`).
|
|
108
|
+
- A certifier icon that fails to load falls back to the initial-letter tile
|
|
109
|
+
instead of an empty square. Two shipped defaults point at `.ico` favicons
|
|
110
|
+
the iOS decoder rejects, and any provider can move its file.
|
|
111
|
+
- Sigma Identity (`auth.sigmaidentity.com`) ships as a default certifier,
|
|
112
|
+
below the existing three in trust order. Two stores are involved: the Trust screen's list
|
|
113
|
+
is hydrated from AsyncStorage and an existing wallet keeps its saved list
|
|
114
|
+
there, while the wallet's identity resolution (`discoverByIdentityKey` and
|
|
115
|
+
`discoverByAttributes`) reads the toolbox's WalletSettingsManager store,
|
|
116
|
+
which this app never writes, so for resolution the shipped defaults,
|
|
117
|
+
Sigma included, apply to every wallet. That split predates this release.
|
|
118
|
+
|
|
119
|
+
### Peer dependencies
|
|
120
|
+
|
|
121
|
+
- New peer `@urbit/sigil-js` (^2.2.0), imported only through its `./core`
|
|
122
|
+
entry. It ships CJS, so a consumer's Jest `transformIgnorePatterns` needs no
|
|
123
|
+
change; see the README's Jest configuration section.
|
|
124
|
+
- New peer `expo-image` (~55.0.11). Its package entry is raw TypeScript that
|
|
125
|
+
Jest does not transform, so the toolbox requires it lazily at render and
|
|
126
|
+
call time; a consumer's Jest config needs no change.
|
|
127
|
+
|
|
128
|
+
## 0.2.2
|
|
129
|
+
|
|
130
|
+
### Fixes
|
|
131
|
+
|
|
132
|
+
- `AppLogo`'s rotation now sets `isInteraction: false`. `Animated.timing`
|
|
133
|
+
registers an InteractionManager handle for the duration of the animation, and
|
|
134
|
+
`Animated.loop` means that duration never ends — so the handle was held for
|
|
135
|
+
as long as the component stayed mounted, and while any handle is held
|
|
136
|
+
`InteractionManager.runAfterInteractions` never fires for *anyone* in the
|
|
137
|
+
process. `Balance` renders `<AppLogo rotate />` whenever a balance is loading,
|
|
138
|
+
so this was reachable in normal use: `PayScreen`'s deferred proof sweep never
|
|
139
|
+
ran, and a host that defers real work the same way could hang indefinitely
|
|
140
|
+
with no error and no timeout. Long-standing; found by the bsv-browser session,
|
|
141
|
+
where a dApp's `listOutputs` hung forever behind a loading spinner.
|
|
142
|
+
|
|
143
|
+
## 0.2.1
|
|
144
|
+
|
|
145
|
+
### Payments
|
|
146
|
+
|
|
147
|
+
- The corrupt-pending-queue notice now has a body. `readUnprocessedPending`
|
|
148
|
+
quarantines an unparseable `localpay_pending` blob under a timestamped
|
|
149
|
+
`localpay_pending_corrupt_*` key and clears the live queue, but the card only
|
|
150
|
+
rendered a title ("Damaged payment data was found on this device"), so a user
|
|
151
|
+
carrying incoming payments was told nothing about what happened to them. The
|
|
152
|
+
new `pay_offline_kv_corrupt_body` (all twelve locales) says the payments were
|
|
153
|
+
set aside rather than deleted, and that a sender should be asked to send again
|
|
154
|
+
only if their payment is still missing — a quarantined entry may already have
|
|
155
|
+
been credited, and a blind re-send is the failure worth steering away from.
|
|
156
|
+
|
|
157
|
+
## 0.2.0
|
|
158
|
+
|
|
159
|
+
Released from bsv-wallet master, tag `expo-wallet-toolbox-v0.2.0`. Contains
|
|
160
|
+
everything merged since 0.1.3, not only the API change below.
|
|
161
|
+
|
|
162
|
+
### Breaking / API
|
|
163
|
+
|
|
164
|
+
- **`dismissTo` props are now typed `DismissTarget` (expo-router's `Href`)**
|
|
165
|
+
instead of `string`, on `PayScreen`, `PaymentSuccessOverlay`, `NearbyFlow`,
|
|
166
|
+
`AddressReceive`, `HandleReceive` and `UniversalSend`. A host with
|
|
167
|
+
`experiments.typedRoutes` enabled narrows `Href` globally to its own route
|
|
168
|
+
union, which made a `string` prop unassignable inside this package's own
|
|
169
|
+
files (TS2345); `skipLibCheck` cannot suppress it, because the package ships
|
|
170
|
+
raw `.ts`. Typed-routes hosts now get their route strings checked at the call
|
|
171
|
+
site; hosts without it see `Href` ~ `string`. `Href` also admits the object
|
|
172
|
+
form `{ pathname, params }`, so the accepted type widens — hence the minor
|
|
173
|
+
bump. `DismissTarget` is exported from the `ui` barrel.
|
|
174
|
+
- Note: the props still default to `'/'`. A typed-routes host with no `/`
|
|
175
|
+
route must pass its own value.
|
|
176
|
+
|
|
177
|
+
### Wallet build and restore
|
|
178
|
+
|
|
179
|
+
- `WalletContext` destroys an unpublished `StorageExpoSQLite` when a backup
|
|
180
|
+
restore fails, so a retry does not open a second connection to the same
|
|
181
|
+
database file.
|
|
182
|
+
- The `SimpleWalletManager` builder rejects instead of resolving `null` on
|
|
183
|
+
failure. The manager authenticates on any resolution, so a failed restore
|
|
184
|
+
could previously mark a wallet built.
|
|
185
|
+
- A failed mnemonic build no longer falls back to a stored recovered key: only
|
|
186
|
+
genuinely missing mnemonic material allows the WIF path, so a partial replay
|
|
187
|
+
stays failed and retryable instead of being built over.
|
|
188
|
+
- `restoreFromBackup` intent is preserved across an automatic build (only an
|
|
189
|
+
explicit options object now overwrites it).
|
|
190
|
+
- `restoreOnImport` passes the device manifest through to the restore.
|
|
191
|
+
- `reconcileRestoredProofs` runs after a restore, so a replayed unsent request
|
|
192
|
+
cannot rebroadcast an already-completed transaction. It calls
|
|
193
|
+
`storage.findProvenTxReqs` and `storage.findProvenTxs` — a real widening of
|
|
194
|
+
what the `StorageExpoSQLite` argument must implement. Hosts passing a test
|
|
195
|
+
double or a narrower shim through a cast will need both.
|
|
196
|
+
- `RemoteSyncReader` pages the backup index (the server caps a page at 500
|
|
197
|
+
entries) and fails when the index ends before its advertised head, instead of
|
|
198
|
+
treating a truncated wallet as a successful restore. It publishes only a
|
|
199
|
+
fully verified index, advances only after both download and decryption
|
|
200
|
+
succeed, and prefetches at most one small (<= 1 MiB) chunk ahead, storing
|
|
201
|
+
failures as values so a stopped replay leaves no unhandled rejection.
|
|
202
|
+
- Backup client requests are bounded by a single deadline covering both the
|
|
203
|
+
request and the body read (React Native's XHR fetch resolves before its
|
|
204
|
+
Blob/FileReader conversion finishes), so a stalled transfer cannot strand the
|
|
205
|
+
monitor.
|
|
206
|
+
|
|
207
|
+
### Payments
|
|
208
|
+
|
|
209
|
+
- `creditInboxOnce` rechecks the in-flight slot after each wait, so several
|
|
210
|
+
manual retries queue behind one pass rather than racing.
|
|
211
|
+
- The peerpay outbox serializes each storage's whole read-modify-write, not
|
|
212
|
+
just the final write, so a send and the background retry/prune task cannot
|
|
213
|
+
overwrite each other's checkpoints and tokens. Mutations fail closed on an
|
|
214
|
+
unreadable queue rather than treating it as empty, and payment IDs are chosen
|
|
215
|
+
against the live queue so same-millisecond sends stay distinct.
|
|
216
|
+
- localpay BLE transport wraps native calls in a promise helper; socket
|
|
217
|
+
transport reliability fixes.
|
|
218
|
+
|
|
219
|
+
### Storage and UI
|
|
220
|
+
|
|
221
|
+
- `getLabelsForTransactionId` and `getTagsForOutputId` resolve their
|
|
222
|
+
associations in a single joined query instead of one bridge round trip per
|
|
223
|
+
row.
|
|
224
|
+
- `ActivityRow` compares every prop when memoizing, so a retained row cannot
|
|
225
|
+
invoke a previous network's handler or show a stale busy label.
|
|
226
|
+
- `useSpendableBalance` / `useVaultBalance` serialize reads and retain the
|
|
227
|
+
latest invalidation, never read or cache a previous chain's storage during a
|
|
228
|
+
network rebuild, and hide the old figure immediately on switch.
|
|
229
|
+
|
|
230
|
+
## 0.1.3 and earlier
|
|
231
|
+
|
|
232
|
+
Not recorded here; see git history.
|
package/README.md
CHANGED
|
@@ -34,7 +34,7 @@ four dozen packages beyond the four listed — Expo native modules
|
|
|
34
34
|
(camera, clipboard, secure-store, haptics, ...), state/i18n libraries
|
|
35
35
|
(mobx, i18next), and BSV SDK packages. The **[Peer dependencies](#peer-dependencies)**
|
|
36
36
|
table below is the full, audited list — `package.json`'s `peerDependencies`
|
|
37
|
-
now declares all
|
|
37
|
+
now declares all 50 entries (47 directly imported + 3 required only for
|
|
38
38
|
native linking — see the Nitro row below), so a plain `npm install
|
|
39
39
|
@bsv/expo-wallet-toolbox` surfaces the rest as peer-dependency warnings
|
|
40
40
|
instead of silently missing them.
|
|
@@ -104,6 +104,26 @@ Expo SDK line.
|
|
|
104
104
|
| `react-native-svg` | 15.15.3 |
|
|
105
105
|
| `react-native-sse` | ^1.2.1 |
|
|
106
106
|
|
|
107
|
+
### Pure JS rendering (required)
|
|
108
|
+
|
|
109
|
+
| Package | Version |
|
|
110
|
+
| --- | --- |
|
|
111
|
+
| `@urbit/sigil-js` | ^2.2.0 |
|
|
112
|
+
|
|
113
|
+
Draws the counterparty avatar on activity rows. This package imports only
|
|
114
|
+
its `./core` entry: the package root pulls in a DOM renderer that touches
|
|
115
|
+
`document` at import time. `./core` ships CJS, so Jest needs neither a
|
|
116
|
+
`transformIgnorePatterns` entry nor a mock for it (see
|
|
117
|
+
[Jest configuration](#jest-configuration)).
|
|
118
|
+
|
|
119
|
+
`./core` exists only as an entry in the package's `exports` map (there is no
|
|
120
|
+
`core.js` at the package root), so Metro's package-exports resolution must stay
|
|
121
|
+
enabled (`resolver.unstable_enablePackageExports`, on by default since Expo
|
|
122
|
+
SDK 53). A host that has switched it off to work around another dual-package
|
|
123
|
+
problem gets `Unable to resolve module @urbit/sigil-js/core` at bundle time;
|
|
124
|
+
the fix is a `resolveRequest` that maps `@urbit/sigil-js/core` to
|
|
125
|
+
`@urbit/sigil-js/dist/core.js`.
|
|
126
|
+
|
|
107
127
|
### State & i18n (required)
|
|
108
128
|
|
|
109
129
|
| Package | Version |
|
|
@@ -232,12 +252,12 @@ export { WalletHomeScreen as default } from '@bsv/expo-wallet-toolbox/ui'
|
|
|
232
252
|
| `TrustScreen` | `app/trust.tsx` |
|
|
233
253
|
| `LogsScreen` | `app/logs.tsx` |
|
|
234
254
|
|
|
235
|
-
> **Note:** `ConnectionsScreen`
|
|
236
|
-
>
|
|
237
|
-
>
|
|
238
|
-
> app
|
|
239
|
-
>
|
|
240
|
-
>
|
|
255
|
+
> **Note:** `ConnectionsScreen` accepts pairing codes using `bsv-wallet://`
|
|
256
|
+
> or `bsv-browser://`. OS-level links also require native scheme registration
|
|
257
|
+
> in the host app. This repo routes external `pair` links to `/connections`
|
|
258
|
+
> through `app/+native-intent.ts`; in-app QR scanning uses the same pairing
|
|
259
|
+
> parameter validation. A consumer using another pairing scheme must update
|
|
260
|
+
> the parser and its own native registration together.
|
|
241
261
|
|
|
242
262
|
Each route file is the one-line `export { XScreen as default } from '@bsv/expo-wallet-toolbox/ui'`
|
|
243
263
|
pattern shown above — no other wiring needed per screen; navigation
|
|
@@ -280,7 +300,7 @@ vault/hardware-key support (i.e. installed `react-native-yubikey`); omit
|
|
|
280
300
|
both if you didn't.
|
|
281
301
|
|
|
282
302
|
Also add `CFBundleURLTypes` for **your own** deep-link scheme(s) — do not
|
|
283
|
-
reuse `bsv-wallet
|
|
303
|
+
reuse `bsv-wallet://`, `bsv-browser://`, or `peerpay://`, those are this repo's own app
|
|
284
304
|
identity, not the package's:
|
|
285
305
|
|
|
286
306
|
```json
|
|
@@ -429,6 +449,11 @@ are required — both hard-won during this package's extraction:
|
|
|
429
449
|
directly), and `@bsv/backup-cache-client` (see below) must be in
|
|
430
450
|
whatever pattern you end up with.
|
|
431
451
|
|
|
452
|
+
`@urbit/sigil-js`, the peer added with the activity-row sigil avatars,
|
|
453
|
+
needs no entry here: the `./core` entry this package imports ships CJS,
|
|
454
|
+
so Jest loads it untransformed. Install it alongside the other peers and
|
|
455
|
+
nothing else in this section changes.
|
|
456
|
+
|
|
432
457
|
2. **Native-module and ESM-only-package mocks** — anything the package
|
|
433
458
|
touches that has no pure-JS Jest-safe implementation, or that ships
|
|
434
459
|
as ESM-only with no `require` export condition, needs a
|
|
@@ -520,7 +545,7 @@ without an `exports` map, and Metro's own `exports` support has its own
|
|
|
520
545
|
quirks worth re-testing explicitly rather than assuming Node's behavior
|
|
521
546
|
carries over.
|
|
522
547
|
|
|
523
|
-
`files` is `["core", "ui", "assets"]`; npm always includes `package.json`
|
|
548
|
+
`files` is `["core", "ui", "assets", "CHANGELOG.md"]`; npm always includes `package.json`
|
|
524
549
|
and `README.md` regardless of `files`. `__tests__/` and `tsconfig.json`
|
|
525
550
|
live at the package root, outside every `files` entry, so they are
|
|
526
551
|
excluded from the published tarball — confirmed with `npm pack --dry-run`.
|
|
@@ -58,7 +58,8 @@ const formatCurrency = (
|
|
|
58
58
|
locale: string,
|
|
59
59
|
currency: string,
|
|
60
60
|
minDigits: number,
|
|
61
|
-
maxDigits?: number
|
|
61
|
+
maxDigits?: number,
|
|
62
|
+
showPlus = false
|
|
62
63
|
): string => {
|
|
63
64
|
const abs = Math.abs(value)
|
|
64
65
|
let formatted: string
|
|
@@ -78,9 +79,14 @@ const formatCurrency = (
|
|
|
78
79
|
} catch {
|
|
79
80
|
formatted = `${currency} ${abs.toFixed(minDigits)}`
|
|
80
81
|
}
|
|
81
|
-
|
|
82
|
+
// Same sign convention as the satoshi formatter, so a column of mixed
|
|
83
|
+
// currencies reads one way: minus for money out, plus for money in when the
|
|
84
|
+
// caller asks for it. Accounting parentheses were dropped because the row's
|
|
85
|
+
// direction cue lives in the sign, and "(...)" is not one.
|
|
86
|
+
return `${fiatSign(value, showPlus)}${formatted}`
|
|
82
87
|
}
|
|
83
88
|
|
|
89
|
+
const fiatSign = (value: number, showPlus: boolean): string => (value < 0 ? '-' : showPlus && value > 0 ? '+' : '')
|
|
84
90
|
/**
|
|
85
91
|
* Format a satoshi amount as a locale-aware integer string with grouping separators.
|
|
86
92
|
* E.g. 1234567 -> "1,234,567" (en-US) or "1.234.567" (de-DE)
|
|
@@ -113,38 +119,18 @@ const formatBsvLocale = (bsvValue: number): string => {
|
|
|
113
119
|
}
|
|
114
120
|
}
|
|
115
121
|
|
|
116
|
-
/**
|
|
117
|
-
* Format a sub-cent USD value as cents (¢).
|
|
118
|
-
* Dynamically adjusts decimal precision based on magnitude.
|
|
119
|
-
*/
|
|
120
|
-
const formatCents = (cents: number): string => {
|
|
121
|
-
const absCents = Math.abs(cents)
|
|
122
|
-
let maxDigits = 2
|
|
123
|
-
if (absCents < 0.01) maxDigits = 4
|
|
124
|
-
else if (absCents < 0.1) maxDigits = 3
|
|
125
|
-
|
|
126
|
-
try {
|
|
127
|
-
const formatted = new Intl.NumberFormat(localeDefault, {
|
|
128
|
-
minimumFractionDigits: 0,
|
|
129
|
-
maximumFractionDigits: maxDigits,
|
|
130
|
-
useGrouping: true
|
|
131
|
-
}).format(cents)
|
|
132
|
-
return `${formatted}¢`
|
|
133
|
-
} catch {
|
|
134
|
-
return `${parseFloat(cents.toFixed(maxDigits))}¢`
|
|
135
|
-
}
|
|
136
|
-
}
|
|
137
|
-
|
|
138
122
|
/**
|
|
139
123
|
* Format a satoshi amount as fiat using satoshis-per-unit of that currency.
|
|
140
|
-
* Values below one minor unit (1 cent, 1 yen, …) display as "< {smallest}"
|
|
141
|
-
* Otherwise rounds up to the
|
|
124
|
+
* Values below one minor unit (1 cent, 1 yen, …) display as "< {smallest}",
|
|
125
|
+
* with the sign on the figure ("< -$0.01"). Otherwise rounds up to the
|
|
126
|
+
* currency's minor unit.
|
|
142
127
|
*/
|
|
143
128
|
export const formatSatoshisAsFiat = (
|
|
144
129
|
satoshis: number,
|
|
145
130
|
satoshisPerUnit: number,
|
|
146
131
|
showFiatAsInteger = false,
|
|
147
|
-
currency = 'USD'
|
|
132
|
+
currency = 'USD',
|
|
133
|
+
showPlus = false
|
|
148
134
|
): string => {
|
|
149
135
|
if (!Number.isInteger(Number(satoshis)) || !satoshisPerUnit || satoshisPerUnit <= 0) {
|
|
150
136
|
return '...'
|
|
@@ -160,7 +146,7 @@ export const formatSatoshisAsFiat = (
|
|
|
160
146
|
|
|
161
147
|
if (v > 0 && v < threshold && !showFiatAsInteger) {
|
|
162
148
|
const smallest = formatCurrency(threshold, localeDefault, currency, digits, digits)
|
|
163
|
-
return
|
|
149
|
+
return `< ${fiatSign(raw, showPlus)}${smallest}`
|
|
164
150
|
}
|
|
165
151
|
|
|
166
152
|
const sign = raw < 0 ? -1 : 1
|
|
@@ -169,7 +155,7 @@ export const formatSatoshisAsFiat = (
|
|
|
169
155
|
const minDigits = showFiatAsInteger ? 0 : digits
|
|
170
156
|
const maxDigits = showFiatAsInteger ? 0 : digits
|
|
171
157
|
|
|
172
|
-
return formatCurrency(rounded, localeDefault, currency, minDigits, maxDigits)
|
|
158
|
+
return formatCurrency(rounded, localeDefault, currency, minDigits, maxDigits, showPlus)
|
|
173
159
|
}
|
|
174
160
|
|
|
175
161
|
/**
|
|
@@ -212,7 +198,7 @@ export const formatAmount = (
|
|
|
212
198
|
|
|
213
199
|
if (isFiatCurrency(currency)) {
|
|
214
200
|
const per = satoshisPerFiatUnit(currency, satoshisPerUSD, usdToFiat)
|
|
215
|
-
return formatSatoshisAsFiat(satoshis, per, showFiatAsInteger, currency)
|
|
201
|
+
return formatSatoshisAsFiat(satoshis, per, showFiatAsInteger, currency, showPlus)
|
|
216
202
|
}
|
|
217
203
|
|
|
218
204
|
return formatSatoshisAsBsv(satoshis, showPlus, abbreviate)
|
|
@@ -27,6 +27,10 @@ import {
|
|
|
27
27
|
type UnlockState
|
|
28
28
|
} from '../services/secrets'
|
|
29
29
|
|
|
30
|
+
// The identity is shared storage, so overlapping provider mounts must share the
|
|
31
|
+
// guard too. Hold it through both the existence check and the completed write.
|
|
32
|
+
let creatingMnemonic = false
|
|
33
|
+
|
|
30
34
|
/**
|
|
31
35
|
* Wallet secrets are held by services/secrets, which wraps them in AES-256-GCM
|
|
32
36
|
* under a key the OS will only release after a biometric match. This provider
|
|
@@ -40,6 +44,8 @@ import {
|
|
|
40
44
|
*/
|
|
41
45
|
export interface LocalStorageContextType {
|
|
42
46
|
/* secure */
|
|
47
|
+
/** Fresh onboarding only. Refuses to replace any existing wallet identity. */
|
|
48
|
+
createMnemonic: (mnemonic: string) => Promise<boolean>
|
|
43
49
|
setMnemonic: (mnemonic: string) => Promise<boolean>
|
|
44
50
|
getMnemonic: () => Promise<string | null>
|
|
45
51
|
deleteMnemonic: () => Promise<void>
|
|
@@ -69,6 +75,7 @@ export interface LocalStorageContextType {
|
|
|
69
75
|
|
|
70
76
|
export const LocalStorageContext = createContext<LocalStorageContextType>({
|
|
71
77
|
/* secure */
|
|
78
|
+
createMnemonic: async () => false,
|
|
72
79
|
setMnemonic: async () => false,
|
|
73
80
|
getMnemonic: async () => null,
|
|
74
81
|
deleteMnemonic: async () => {},
|
|
@@ -94,6 +101,7 @@ export const useLocalStorage = () => useContext(LocalStorageContext)
|
|
|
94
101
|
|
|
95
102
|
export default function LocalStorageProvider({ children }: { children: React.ReactNode }) {
|
|
96
103
|
const [secretsReady, setSecretsReady] = useState(false)
|
|
104
|
+
const secretsReadyRef = useRef(false)
|
|
97
105
|
const [migration, setMigration] = useState<MigrationResult | null>(null)
|
|
98
106
|
const [unlockState, setUnlockState] = useState<UnlockState>(getUnlockState)
|
|
99
107
|
/** Set when migration failed: this session keeps serving the legacy plaintext
|
|
@@ -114,11 +122,13 @@ export default function LocalStorageProvider({ children }: { children: React.Rea
|
|
|
114
122
|
}
|
|
115
123
|
if (cancelled) return
|
|
116
124
|
legacyFallback.current = result.outcome === 'failed'
|
|
125
|
+
secretsReadyRef.current = true
|
|
117
126
|
setMigration(result)
|
|
118
127
|
setSecretsReady(true)
|
|
119
128
|
})()
|
|
120
129
|
return () => {
|
|
121
130
|
cancelled = true
|
|
131
|
+
secretsReadyRef.current = false
|
|
122
132
|
}
|
|
123
133
|
}, [])
|
|
124
134
|
|
|
@@ -177,16 +187,30 @@ export default function LocalStorageProvider({ children }: { children: React.Rea
|
|
|
177
187
|
const deleteAllWalletKeys = useCallback(() => deleteAllSecrets(), [])
|
|
178
188
|
|
|
179
189
|
const hasStoredIdentity = useCallback(async (): Promise<boolean> => {
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
return hasAnySecret()
|
|
190
|
+
return (await hasAnySecret({ strict: true })) ||
|
|
191
|
+
(await readLegacySecret('mnemonic', { strict: true })) != null ||
|
|
192
|
+
(await readLegacySecret('recoveredKey', { strict: true })) != null
|
|
184
193
|
}, [])
|
|
185
194
|
|
|
195
|
+
const createMnemonic = useCallback(async (mnemonic: string): Promise<boolean> => {
|
|
196
|
+
// A failed migration cannot establish that storage is safely empty.
|
|
197
|
+
if (!secretsReadyRef.current || legacyFallback.current || creatingMnemonic) return false
|
|
198
|
+
creatingMnemonic = true
|
|
199
|
+
try {
|
|
200
|
+
if (await hasStoredIdentity()) return false
|
|
201
|
+
// The provider may have unmounted while checking storage.
|
|
202
|
+
if (!secretsReadyRef.current) return false
|
|
203
|
+
return await putSecret('mnemonic', mnemonic)
|
|
204
|
+
} finally {
|
|
205
|
+
creatingMnemonic = false
|
|
206
|
+
}
|
|
207
|
+
}, [hasStoredIdentity])
|
|
208
|
+
|
|
186
209
|
/* -------------------------------- output --------------------------------- */
|
|
187
210
|
|
|
188
211
|
const value: LocalStorageContextType = useMemo(
|
|
189
212
|
() => ({
|
|
213
|
+
createMnemonic,
|
|
190
214
|
setMnemonic,
|
|
191
215
|
getMnemonic,
|
|
192
216
|
deleteMnemonic,
|
|
@@ -206,6 +230,7 @@ export default function LocalStorageProvider({ children }: { children: React.Rea
|
|
|
206
230
|
deleteItem: AsyncStorage.removeItem
|
|
207
231
|
}),
|
|
208
232
|
[
|
|
233
|
+
createMnemonic,
|
|
209
234
|
setMnemonic,
|
|
210
235
|
getMnemonic,
|
|
211
236
|
deleteMnemonic,
|
|
@@ -118,6 +118,18 @@ const DEFAULT_SETTINGS: WalletSettings = {
|
|
|
118
118
|
iconUrl: 'https://whoiam.bsvblockchain.tech/whoiam.png',
|
|
119
119
|
identityKey: '02e7eeb3986273db6843b790a1595ed0ff1b2ae8f43ae2e7f1a0c9db4dd3fb9441',
|
|
120
120
|
trust: 5
|
|
121
|
+
},
|
|
122
|
+
// Values as published in https://auth.sigmaidentity.com/manifest.json
|
|
123
|
+
// (babbage.trust). Lowest trust of the shipped set: it is the newest
|
|
124
|
+
// certifier here and the list is ordered by trust on the Trust screen.
|
|
125
|
+
// The icon is an SVG; the Trust screen draws those with react-native-svg
|
|
126
|
+
// rather than the platform decoder, which mispositions its <text> glyph.
|
|
127
|
+
{
|
|
128
|
+
name: 'Sigma Identity',
|
|
129
|
+
description: 'Certifies verified identity claims',
|
|
130
|
+
iconUrl: 'https://auth.sigmaidentity.com/sigma-mark.svg',
|
|
131
|
+
identityKey: '02250905f0383085b53409876aefbf01fc8e7fd841922dc4ce55ae035b31341e6d',
|
|
132
|
+
trust: 2
|
|
121
133
|
}
|
|
122
134
|
]
|
|
123
135
|
}
|
|
@@ -168,7 +180,7 @@ import { inputTxidsFromRawTx, shouldDeferSendWaiting } from '../storage/skipQueu
|
|
|
168
180
|
import { provenTxFromBump } from '../pay/provenTxFromBump'
|
|
169
181
|
import { recordProof } from '../pay/recordProof'
|
|
170
182
|
import { makeCreditClassifier } from '../pay/creditErrors'
|
|
171
|
-
import { creditInboxOnce
|
|
183
|
+
import { creditInboxOnce } from '../pay/creditInbox'
|
|
172
184
|
import { isReceiveInboxFocused } from '../pay/receiveFocus'
|
|
173
185
|
import { sounds } from '../hooks/useConfirmationSound'
|
|
174
186
|
import i18n from '../i18n/translations'
|
|
@@ -1394,8 +1406,8 @@ export const WalletContextProvider: React.FC<WalletContextProps> = ({ children =
|
|
|
1394
1406
|
storage: phoneStorage!,
|
|
1395
1407
|
classify,
|
|
1396
1408
|
accept: payment =>
|
|
1397
|
-
acceptWithRetry(client, messageBoxUrl, payment,
|
|
1398
|
-
internalizeIncoming(permissionsManager as never, client, adminOriginator, p,
|
|
1409
|
+
acceptWithRetry(client, messageBoxUrl, payment, p =>
|
|
1410
|
+
internalizeIncoming(permissionsManager as never, client, adminOriginator, p, repairBeef)
|
|
1399
1411
|
)
|
|
1400
1412
|
})
|
|
1401
1413
|
return { accepted: r.accepted, attention: r.attentionCount, pending: r.pending }
|
|
@@ -606,6 +606,7 @@ const resources = {
|
|
|
606
606
|
advanced: 'Advanced',
|
|
607
607
|
copy_secret_words: 'Copy Secret Words',
|
|
608
608
|
print_recovery_keys: 'Print Recovery Keys',
|
|
609
|
+
backup_wallet_keys: 'Backup Wallet Keys',
|
|
609
610
|
log_out: 'Log Out',
|
|
610
611
|
connect_to_app: 'Connect to App',
|
|
611
612
|
no_connections_yet: 'No connections yet',
|
|
@@ -1251,6 +1252,7 @@ const resources = {
|
|
|
1251
1252
|
advanced: '高级设置',
|
|
1252
1253
|
copy_secret_words: '复制助记词',
|
|
1253
1254
|
print_recovery_keys: '打印恢复密钥',
|
|
1255
|
+
backup_wallet_keys: '备份钱包密钥',
|
|
1254
1256
|
log_out: '退出登录',
|
|
1255
1257
|
connect_to_app: '连接应用',
|
|
1256
1258
|
no_connections_yet: '暂无连接',
|
|
@@ -1901,6 +1903,7 @@ const resources = {
|
|
|
1901
1903
|
advanced: 'उन्नत',
|
|
1902
1904
|
copy_secret_words: 'गुप्त शब्द कॉपी करें',
|
|
1903
1905
|
print_recovery_keys: 'रिकवरी कुंजियाँ प्रिंट करें',
|
|
1906
|
+
backup_wallet_keys: 'वॉलेट की कुंजियों का बैकअप लें',
|
|
1904
1907
|
log_out: 'लॉग आउट',
|
|
1905
1908
|
connect_to_app: 'ऐप से कनेक्ट करें',
|
|
1906
1909
|
no_connections_yet: 'अभी तक कोई कनेक्शन नहीं',
|
|
@@ -2567,6 +2570,7 @@ const resources = {
|
|
|
2567
2570
|
advanced: 'Avanzado',
|
|
2568
2571
|
copy_secret_words: 'Copiar palabras secretas',
|
|
2569
2572
|
print_recovery_keys: 'Imprimir claves de recuperación',
|
|
2573
|
+
backup_wallet_keys: 'Respaldar claves de la cartera',
|
|
2570
2574
|
log_out: 'Cerrar sesión',
|
|
2571
2575
|
connect_to_app: 'Conectar a una app',
|
|
2572
2576
|
no_connections_yet: 'Aún no hay conexiones',
|
|
@@ -3238,6 +3242,7 @@ const resources = {
|
|
|
3238
3242
|
advanced: 'Avancé',
|
|
3239
3243
|
copy_secret_words: 'Copier les mots secrets',
|
|
3240
3244
|
print_recovery_keys: 'Imprimer les clés de récupération',
|
|
3245
|
+
backup_wallet_keys: 'Sauvegarder les clés du portefeuille',
|
|
3241
3246
|
log_out: 'Se déconnecter',
|
|
3242
3247
|
connect_to_app: 'Connecter une app',
|
|
3243
3248
|
no_connections_yet: "Aucune connexion pour l'instant",
|
|
@@ -3899,6 +3904,7 @@ const resources = {
|
|
|
3899
3904
|
advanced: 'خيارات متقدمة',
|
|
3900
3905
|
copy_secret_words: 'نسخ الكلمات السرية',
|
|
3901
3906
|
print_recovery_keys: 'طباعة مفاتيح الاسترداد',
|
|
3907
|
+
backup_wallet_keys: 'نسخ مفاتيح المحفظة احتياطيًا',
|
|
3902
3908
|
log_out: 'تسجيل الخروج',
|
|
3903
3909
|
connect_to_app: 'الاتصال بتطبيق',
|
|
3904
3910
|
no_connections_yet: 'لا اتصالات حتى الآن',
|
|
@@ -4556,6 +4562,7 @@ const resources = {
|
|
|
4556
4562
|
advanced: 'Avançado',
|
|
4557
4563
|
copy_secret_words: 'Copiar palavras secretas',
|
|
4558
4564
|
print_recovery_keys: 'Imprimir chaves de recuperação',
|
|
4565
|
+
backup_wallet_keys: 'Fazer backup das chaves da carteira',
|
|
4559
4566
|
log_out: 'Sair',
|
|
4560
4567
|
connect_to_app: 'Conectar ao app',
|
|
4561
4568
|
no_connections_yet: 'Nenhuma conexão ainda',
|
|
@@ -5218,6 +5225,7 @@ const resources = {
|
|
|
5218
5225
|
advanced: 'উন্নত',
|
|
5219
5226
|
copy_secret_words: 'গোপন শব্দ কপি করুন',
|
|
5220
5227
|
print_recovery_keys: 'রিকভারি কী প্রিন্ট করুন',
|
|
5228
|
+
backup_wallet_keys: 'ওয়ালেটের কীগুলির ব্যাকআপ নিন',
|
|
5221
5229
|
log_out: 'লগ আউট',
|
|
5222
5230
|
connect_to_app: 'অ্যাপে সংযোগ করুন',
|
|
5223
5231
|
no_connections_yet: 'এখনো কোনো সংযোগ নেই',
|
|
@@ -5882,6 +5890,7 @@ const resources = {
|
|
|
5882
5890
|
advanced: 'Расширенные',
|
|
5883
5891
|
copy_secret_words: 'Скопировать секретные слова',
|
|
5884
5892
|
print_recovery_keys: 'Распечатать ключи восстановления',
|
|
5893
|
+
backup_wallet_keys: 'Резервная копия ключей кошелька',
|
|
5885
5894
|
log_out: 'Выйти',
|
|
5886
5895
|
connect_to_app: 'Подключить приложение',
|
|
5887
5896
|
no_connections_yet: 'Нет подключений',
|
|
@@ -6545,6 +6554,7 @@ const resources = {
|
|
|
6545
6554
|
advanced: 'Lanjutan',
|
|
6546
6555
|
copy_secret_words: 'Salin Kata Rahasia',
|
|
6547
6556
|
print_recovery_keys: 'Cetak Kunci Pemulihan',
|
|
6557
|
+
backup_wallet_keys: 'Cadangkan Kunci Dompet',
|
|
6548
6558
|
log_out: 'Keluar',
|
|
6549
6559
|
connect_to_app: 'Hubungkan ke Aplikasi',
|
|
6550
6560
|
no_connections_yet: 'Belum ada koneksi',
|
|
@@ -7227,6 +7237,7 @@ const resources = {
|
|
|
7227
7237
|
advanced: '詳細設定',
|
|
7228
7238
|
copy_secret_words: 'シークレットワードをコピー',
|
|
7229
7239
|
print_recovery_keys: 'リカバリーキーを印刷',
|
|
7240
|
+
backup_wallet_keys: 'ウォレットの鍵をバックアップ',
|
|
7230
7241
|
log_out: 'ログアウト',
|
|
7231
7242
|
connect_to_app: 'アプリに接続',
|
|
7232
7243
|
no_connections_yet: 'まだ接続がありません',
|
|
@@ -7906,6 +7917,7 @@ const resources = {
|
|
|
7906
7917
|
advanced: 'Zaawansowane',
|
|
7907
7918
|
copy_secret_words: 'Kopiuj tajne słowa',
|
|
7908
7919
|
print_recovery_keys: 'Drukuj klucze odzyskiwania',
|
|
7920
|
+
backup_wallet_keys: 'Utwórz kopię zapasową kluczy portfela',
|
|
7909
7921
|
log_out: 'Wyloguj',
|
|
7910
7922
|
connect_to_app: 'Połącz z aplikacją',
|
|
7911
7923
|
no_connections_yet: 'Brak połączeń',
|