@bsv/expo-wallet-toolbox 0.3.0 → 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 +8 -8
- package/core/context/LocalStorageProvider.tsx +29 -4
- package/core/i18n/translations.tsx +12 -0
- 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/package.json +3 -2
- package/ui/screens/ConnectionsScreen.tsx +12 -2
- 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
|
@@ -252,12 +252,12 @@ export { WalletHomeScreen as default } from '@bsv/expo-wallet-toolbox/ui'
|
|
|
252
252
|
| `TrustScreen` | `app/trust.tsx` |
|
|
253
253
|
| `LogsScreen` | `app/logs.tsx` |
|
|
254
254
|
|
|
255
|
-
> **Note:** `ConnectionsScreen`
|
|
256
|
-
>
|
|
257
|
-
>
|
|
258
|
-
> app
|
|
259
|
-
>
|
|
260
|
-
>
|
|
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.
|
|
261
261
|
|
|
262
262
|
Each route file is the one-line `export { XScreen as default } from '@bsv/expo-wallet-toolbox/ui'`
|
|
263
263
|
pattern shown above — no other wiring needed per screen; navigation
|
|
@@ -300,7 +300,7 @@ vault/hardware-key support (i.e. installed `react-native-yubikey`); omit
|
|
|
300
300
|
both if you didn't.
|
|
301
301
|
|
|
302
302
|
Also add `CFBundleURLTypes` for **your own** deep-link scheme(s) — do not
|
|
303
|
-
reuse `bsv-wallet
|
|
303
|
+
reuse `bsv-wallet://`, `bsv-browser://`, or `peerpay://`, those are this repo's own app
|
|
304
304
|
identity, not the package's:
|
|
305
305
|
|
|
306
306
|
```json
|
|
@@ -545,7 +545,7 @@ without an `exports` map, and Metro's own `exports` support has its own
|
|
|
545
545
|
quirks worth re-testing explicitly rather than assuming Node's behavior
|
|
546
546
|
carries over.
|
|
547
547
|
|
|
548
|
-
`files` is `["core", "ui", "assets"]`; npm always includes `package.json`
|
|
548
|
+
`files` is `["core", "ui", "assets", "CHANGELOG.md"]`; npm always includes `package.json`
|
|
549
549
|
and `README.md` regardless of `files`. `__tests__/` and `tsconfig.json`
|
|
550
550
|
live at the package root, outside every `files` entry, so they are
|
|
551
551
|
excluded from the published tarball — confirmed with `npm pack --dry-run`.
|
|
@@ -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,
|
|
@@ -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ń',
|
|
@@ -35,10 +35,11 @@ export type MigrationResult =
|
|
|
35
35
|
/** Reads a legacy plaintext item. Prompt-free — these were always written
|
|
36
36
|
* unauthenticated. Kept exported so the provider can still serve a session
|
|
37
37
|
* whose migration failed, instead of showing the user an empty wallet. */
|
|
38
|
-
export async function readLegacySecret(name: SecretName): Promise<string | null> {
|
|
38
|
+
export async function readLegacySecret(name: SecretName, options?: { strict?: boolean }): Promise<string | null> {
|
|
39
39
|
try {
|
|
40
40
|
return await SecureStore.getItemAsync(LEGACY_KEYS[name])
|
|
41
|
-
} catch {
|
|
41
|
+
} catch (err) {
|
|
42
|
+
if (options?.strict) throw err
|
|
42
43
|
return null
|
|
43
44
|
}
|
|
44
45
|
}
|
|
@@ -28,17 +28,19 @@ import { EnvelopeBlob, EnvelopeError, SECRET_NAMES, SecretName } from './types'
|
|
|
28
28
|
* the stale ciphertext. Harmless — it was already unopenable — but don't call
|
|
29
29
|
* it speculatively in a hot path.
|
|
30
30
|
*/
|
|
31
|
-
export async function hasSecret(name: SecretName): Promise<boolean> {
|
|
31
|
+
export async function hasSecret(name: SecretName, options?: { strict?: boolean }): Promise<boolean> {
|
|
32
32
|
try {
|
|
33
33
|
return (await SecureStore.getItemAsync(envKey(name), envOptions)) !== null
|
|
34
|
-
} catch {
|
|
34
|
+
} catch (err) {
|
|
35
|
+
// Creation must distinguish an unreadable keychain from an empty one.
|
|
36
|
+
if (options?.strict) throw err
|
|
35
37
|
return false
|
|
36
38
|
}
|
|
37
39
|
}
|
|
38
40
|
|
|
39
|
-
export async function hasAnySecret(): Promise<boolean> {
|
|
41
|
+
export async function hasAnySecret(options?: { strict?: boolean }): Promise<boolean> {
|
|
40
42
|
for (const name of SECRET_NAMES) {
|
|
41
|
-
if (await hasSecret(name)) return true
|
|
43
|
+
if (await hasSecret(name, options)) return true
|
|
42
44
|
}
|
|
43
45
|
return false
|
|
44
46
|
}
|
|
@@ -18,6 +18,7 @@
|
|
|
18
18
|
import AsyncStorage from '@react-native-async-storage/async-storage'
|
|
19
19
|
|
|
20
20
|
export const ATTEST_KEY_PREFIX = 'vault_backup_attest_v1_'
|
|
21
|
+
export const PENDING_KEY_PREFIX = 'wallet_backup_pending_v1_'
|
|
21
22
|
|
|
22
23
|
export type BackupMedium = 'phrase' | 'shares'
|
|
23
24
|
|
|
@@ -30,8 +31,21 @@ export interface BackupAttestation {
|
|
|
30
31
|
|
|
31
32
|
/** Last 8 hex chars of the identity key — the app's established scope suffix. */
|
|
32
33
|
const scopeKey = (identityKey: string): string => ATTEST_KEY_PREFIX + identityKey.slice(-8)
|
|
34
|
+
const pendingKey = (identityKey: string): string => PENDING_KEY_PREFIX + identityKey
|
|
33
35
|
|
|
34
36
|
export const backupAttestation = {
|
|
37
|
+
/** Only newly generated wallets are known to need their first backup.
|
|
38
|
+
* A returning wallet with no record predates tracking: its backup status is
|
|
39
|
+
* unknown, not evidence that the owner has never saved their keys. */
|
|
40
|
+
async markPending(identityKey: string): Promise<void> {
|
|
41
|
+
await AsyncStorage.setItem(pendingKey(identityKey), '1')
|
|
42
|
+
},
|
|
43
|
+
|
|
44
|
+
async needsReminder(identityKey: string): Promise<boolean> {
|
|
45
|
+
if ((await AsyncStorage.getItem(pendingKey(identityKey))) !== '1') return false
|
|
46
|
+
return (await backupAttestation.get(identityKey)) === null
|
|
47
|
+
},
|
|
48
|
+
|
|
35
49
|
async get(identityKey: string): Promise<BackupAttestation | null> {
|
|
36
50
|
const raw = await AsyncStorage.getItem(scopeKey(identityKey))
|
|
37
51
|
if (!raw) return null
|
|
@@ -46,16 +60,17 @@ export const backupAttestation = {
|
|
|
46
60
|
async set(identityKey: string, medium: BackupMedium): Promise<void> {
|
|
47
61
|
const record: BackupAttestation = { v: 1, medium, at: Date.now() }
|
|
48
62
|
await AsyncStorage.setItem(scopeKey(identityKey), JSON.stringify(record))
|
|
63
|
+
await AsyncStorage.removeItem(pendingKey(identityKey))
|
|
49
64
|
},
|
|
50
65
|
|
|
51
66
|
async clear(identityKey: string): Promise<void> {
|
|
52
|
-
await AsyncStorage.
|
|
67
|
+
await AsyncStorage.multiRemove([scopeKey(identityKey), pendingKey(identityKey)])
|
|
53
68
|
},
|
|
54
69
|
|
|
55
70
|
/** Logout has no identity key to hand, so sweep the prefix. */
|
|
56
71
|
async clearAll(): Promise<void> {
|
|
57
72
|
const keys = await AsyncStorage.getAllKeys()
|
|
58
|
-
const mine = keys.filter(k => k.startsWith(ATTEST_KEY_PREFIX))
|
|
73
|
+
const mine = keys.filter(k => k.startsWith(ATTEST_KEY_PREFIX) || k.startsWith(PENDING_KEY_PREFIX))
|
|
59
74
|
if (mine.length > 0) await AsyncStorage.multiRemove(mine)
|
|
60
75
|
}
|
|
61
76
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@bsv/expo-wallet-toolbox",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.1",
|
|
4
4
|
"private": false,
|
|
5
5
|
"description": "Wallet screens and P2P local-payment backend for Expo/React Native apps, extracted from BSV Wallet.",
|
|
6
6
|
"license": "SEE LICENSE IN LICENSE.txt",
|
|
@@ -25,7 +25,8 @@
|
|
|
25
25
|
"files": [
|
|
26
26
|
"core",
|
|
27
27
|
"ui",
|
|
28
|
-
"assets"
|
|
28
|
+
"assets",
|
|
29
|
+
"CHANGELOG.md"
|
|
29
30
|
],
|
|
30
31
|
"peerDependencies": {
|
|
31
32
|
"@bsv/air-gap": "^0.1.1",
|
|
@@ -93,7 +93,9 @@ type ParseResult = { params: PairingParams; error: null } | { params: null; erro
|
|
|
93
93
|
function parsePairingUri(raw: string): ParseResult {
|
|
94
94
|
try {
|
|
95
95
|
const url = new URL(raw)
|
|
96
|
-
if (url.protocol !== 'bsv-wallet:'
|
|
96
|
+
if (url.protocol !== 'bsv-wallet:' && url.protocol !== 'bsv-browser:') {
|
|
97
|
+
return { params: null, error: 'Not a bsv-wallet:// or bsv-browser:// URI' }
|
|
98
|
+
}
|
|
97
99
|
|
|
98
100
|
const g = (k: string) => url.searchParams.get(k) ?? ''
|
|
99
101
|
const topic = g('topic')
|
|
@@ -163,7 +165,15 @@ export const ConnectionsScreen = observer(function ConnectionsScreen() {
|
|
|
163
165
|
// Auto-connect when navigated here with deep link pairing params
|
|
164
166
|
useEffect(() => {
|
|
165
167
|
if (!deepLinkParams.topic || !managers.permissionsManager) return
|
|
166
|
-
const
|
|
168
|
+
const query = new URLSearchParams({
|
|
169
|
+
topic: deepLinkParams.topic,
|
|
170
|
+
backendIdentityKey: deepLinkParams.backendIdentityKey ?? '',
|
|
171
|
+
protocolID: deepLinkParams.protocolID ?? '',
|
|
172
|
+
origin: deepLinkParams.origin ?? '',
|
|
173
|
+
expiry: deepLinkParams.expiry ?? '',
|
|
174
|
+
sig: deepLinkParams.sig ?? ''
|
|
175
|
+
})
|
|
176
|
+
const uri = `bsv-wallet://pair?${query}`
|
|
167
177
|
handleScan(uri)
|
|
168
178
|
}, [deepLinkParams.topic, managers.permissionsManager]) // eslint-disable-line react-hooks/exhaustive-deps
|
|
169
179
|
|
|
@@ -24,7 +24,6 @@ import {
|
|
|
24
24
|
satoshisPerFiatUnit,
|
|
25
25
|
ExchangeRateContext,
|
|
26
26
|
DISPLAY_CURRENCY_OPTIONS,
|
|
27
|
-
recordBackupAttestation,
|
|
28
27
|
isBackupPushEnabled,
|
|
29
28
|
setBackupPushEnabled,
|
|
30
29
|
BACKUP_CHAINS,
|
|
@@ -33,7 +32,6 @@ import {
|
|
|
33
32
|
TaskBackupPush,
|
|
34
33
|
DEFAULT_BACKUP_URL,
|
|
35
34
|
setMockDriverEnabled,
|
|
36
|
-
UserContext,
|
|
37
35
|
NO_MESSAGE_BOX
|
|
38
36
|
} from '@bsv/expo-wallet-toolbox'
|
|
39
37
|
|
|
@@ -68,7 +66,6 @@ import { showToast } from '../components/ui/Toast'
|
|
|
68
66
|
import { PrivateKey } from '@bsv/sdk'
|
|
69
67
|
import { exportAllWalletDatabases } from '../exportDatabases'
|
|
70
68
|
import { importWalletDatabase } from '../importDatabases'
|
|
71
|
-
import { printRecoveryShares } from '../printRecoveryShares'
|
|
72
69
|
import { useSafeAreaInsets } from 'react-native-safe-area-context'
|
|
73
70
|
|
|
74
71
|
/**
|
|
@@ -108,29 +105,13 @@ function loadExpoRouter(): ExpoRouterModule {
|
|
|
108
105
|
return expoRouterMod
|
|
109
106
|
}
|
|
110
107
|
|
|
111
|
-
/**
|
|
112
|
-
* @react-native-clipboard/clipboard reaches for its native TurboModule at
|
|
113
|
-
* import time (`TurboModuleRegistry.getEnforcing`), which throws under Jest
|
|
114
|
-
* (no native binary registered there) even though the module itself
|
|
115
|
-
* transforms fine. Required lazily, only when a handler actually copies
|
|
116
|
-
* something, so importing the `ui` barrel never touches the native module.
|
|
117
|
-
* Same pattern as WalletHomeScreen.tsx's lazy clipboard load.
|
|
118
|
-
*/
|
|
119
|
-
type ClipboardModule = typeof import('@react-native-clipboard/clipboard').default
|
|
120
|
-
let clipboardModule: ClipboardModule | undefined
|
|
121
|
-
function loadClipboard(): ClipboardModule {
|
|
122
|
-
if (!clipboardModule) {
|
|
123
|
-
// eslint-disable-next-line @typescript-eslint/no-require-imports
|
|
124
|
-
clipboardModule = require('@react-native-clipboard/clipboard').default as ClipboardModule
|
|
125
|
-
}
|
|
126
|
-
return clipboardModule
|
|
127
|
-
}
|
|
128
|
-
|
|
129
108
|
export function WalletConfigScreen() {
|
|
130
109
|
const versionLabel = useMemo(() => appVersionLabel(), [])
|
|
131
110
|
const { t } = useTranslation()
|
|
132
111
|
const { colors } = useTheme()
|
|
133
|
-
const { router } = loadExpoRouter()
|
|
112
|
+
const { router, useLocalSearchParams } = loadExpoRouter()
|
|
113
|
+
const { section } = useLocalSearchParams<{ section?: string }>()
|
|
114
|
+
const openBackup = section === 'backup'
|
|
134
115
|
const Ionicons = loadIonicons()
|
|
135
116
|
const {
|
|
136
117
|
managers,
|
|
@@ -146,8 +127,6 @@ export function WalletConfigScreen() {
|
|
|
146
127
|
const { getMnemonic, getRecoveredKey } = useLocalStorage()
|
|
147
128
|
const insets = useSafeAreaInsets()
|
|
148
129
|
|
|
149
|
-
const [isPrinting, setIsPrinting] = useState(false)
|
|
150
|
-
const [copiedMnemonic, setCopiedMnemonic] = useState(false)
|
|
151
130
|
const [switchingNetwork, setSwitchingNetwork] = useState(false)
|
|
152
131
|
const [networkExpanded, setNetworkExpanded] = useState(false)
|
|
153
132
|
const [isExporting, setIsExporting] = useState(false)
|
|
@@ -158,7 +137,10 @@ export function WalletConfigScreen() {
|
|
|
158
137
|
const [loggingOut, setLoggingOut] = useState(false)
|
|
159
138
|
const [storageBusy, setStorageBusy] = useState(false)
|
|
160
139
|
const [currencyExpanded, setCurrencyExpanded] = useState(false)
|
|
161
|
-
const [advancedExpanded, setAdvancedExpanded] = useState(
|
|
140
|
+
const [advancedExpanded, setAdvancedExpanded] = useState(openBackup)
|
|
141
|
+
const scrollRef = useRef<ScrollView>(null)
|
|
142
|
+
const [backupSectionY, setBackupSectionY] = useState<number | null>(null)
|
|
143
|
+
const scrolledToBackup = useRef(false)
|
|
162
144
|
const [thresholdExpanded, setThresholdExpanded] = useState(false)
|
|
163
145
|
const [thresholdSats, setThresholdSats] = useState(DEFAULT_AUTO_APPROVE_THRESHOLD)
|
|
164
146
|
const [thresholdInput, setThresholdInput] = useState('')
|
|
@@ -167,11 +149,21 @@ export function WalletConfigScreen() {
|
|
|
167
149
|
const [arcTokenInput, setArcTokenInput] = useState('')
|
|
168
150
|
const [arcSaving, setArcSaving] = useState(false)
|
|
169
151
|
const { satoshisPerUSD, usdToFiat = {} } = useContext(ExchangeRateContext)
|
|
170
|
-
const { appName } = useContext(UserContext)
|
|
171
152
|
|
|
172
153
|
const currentCurrency = settings?.currency || 'BSV'
|
|
173
154
|
const messageBox = useMessageBoxConfig(t)
|
|
174
155
|
|
|
156
|
+
useEffect(() => {
|
|
157
|
+
if (openBackup) setAdvancedExpanded(true)
|
|
158
|
+
else scrolledToBackup.current = false
|
|
159
|
+
}, [openBackup])
|
|
160
|
+
|
|
161
|
+
useEffect(() => {
|
|
162
|
+
if (!openBackup || backupSectionY === null || scrolledToBackup.current) return
|
|
163
|
+
scrollRef.current?.scrollTo({ y: backupSectionY, animated: false })
|
|
164
|
+
scrolledToBackup.current = true
|
|
165
|
+
}, [openBackup, backupSectionY])
|
|
166
|
+
|
|
175
167
|
// Load persisted auto-approve threshold
|
|
176
168
|
useEffect(() => {
|
|
177
169
|
AsyncStorage.getItem(AUTO_APPROVE_STORAGE_KEY).then(v => {
|
|
@@ -378,61 +370,6 @@ export function WalletConfigScreen() {
|
|
|
378
370
|
})
|
|
379
371
|
}, [])
|
|
380
372
|
|
|
381
|
-
const handleCopyMnemonic = async () => {
|
|
382
|
-
try {
|
|
383
|
-
// Copy mnemonic if available, otherwise fall back to primary key hex
|
|
384
|
-
const mnemonic = await getMnemonic()
|
|
385
|
-
if (mnemonic) {
|
|
386
|
-
loadClipboard().setString(mnemonic)
|
|
387
|
-
} else {
|
|
388
|
-
const wif = await getRecoveredKey()
|
|
389
|
-
if (!wif) return
|
|
390
|
-
loadClipboard().setString(PrivateKey.fromWif(wif).toHex())
|
|
391
|
-
}
|
|
392
|
-
setCopiedMnemonic(true)
|
|
393
|
-
setTimeout(() => setCopiedMnemonic(false), 2000)
|
|
394
|
-
} catch (error) {
|
|
395
|
-
console.error('Error retrieving recovery key:', error)
|
|
396
|
-
}
|
|
397
|
-
}
|
|
398
|
-
|
|
399
|
-
const handlePrintRecoveryShares = async () => {
|
|
400
|
-
if (isPrinting) return
|
|
401
|
-
setIsPrinting(true)
|
|
402
|
-
try {
|
|
403
|
-
const result = await printRecoveryShares({
|
|
404
|
-
mnemonic: await getMnemonic(),
|
|
405
|
-
recoveredKeyWif: await getRecoveredKey(),
|
|
406
|
-
appName
|
|
407
|
-
})
|
|
408
|
-
if (result.ok) {
|
|
409
|
-
// A resolved print sheet from Settings is the same genuine backup
|
|
410
|
-
// EnrollWizard records — the other route to satisfying the vault's
|
|
411
|
-
// backup prerequisite — so it records the same attestation, through
|
|
412
|
-
// the same writer.
|
|
413
|
-
//
|
|
414
|
-
// A failure here must be visible. The paper is real and correct; only
|
|
415
|
-
// the record is missing. Staying silent would send the user away
|
|
416
|
-
// believing they are covered, and the vault would refuse every deposit
|
|
417
|
-
// later with nothing on screen connecting the two.
|
|
418
|
-
if (!(await recordBackupAttestation(managers?.permissionsManager, adminOriginator, 'shares'))) {
|
|
419
|
-
showToast(t('vault_backup_attest_failed_printed'), { type: 'error' })
|
|
420
|
-
}
|
|
421
|
-
} else {
|
|
422
|
-
showToast(
|
|
423
|
-
result.reason === 'unsupported-word-count'
|
|
424
|
-
? t('vault_shares_word_count')
|
|
425
|
-
: 'Unable to access wallet key. Please authenticate and try again.',
|
|
426
|
-
{ type: 'error' }
|
|
427
|
-
)
|
|
428
|
-
}
|
|
429
|
-
} catch (error: any) {
|
|
430
|
-
console.info('[WalletConfig] Print recovery shares did not complete:', error?.message)
|
|
431
|
-
} finally {
|
|
432
|
-
setIsPrinting(false)
|
|
433
|
-
}
|
|
434
|
-
}
|
|
435
|
-
|
|
436
373
|
const handleExportData = async () => {
|
|
437
374
|
if (isExporting) return
|
|
438
375
|
setIsExporting(true)
|
|
@@ -545,7 +482,7 @@ export function WalletConfigScreen() {
|
|
|
545
482
|
<Text style={[localStyles.headerTitle, { color: colors.textPrimary }]}>{t('settings')}</Text>
|
|
546
483
|
<View style={localStyles.headerBack} />
|
|
547
484
|
</View>
|
|
548
|
-
<ScrollView style={{ flex: 1 }} contentContainerStyle={{ paddingTop: spacing.lg, paddingBottom: spacing.xxxl }}>
|
|
485
|
+
<ScrollView ref={scrollRef} style={{ flex: 1 }} contentContainerStyle={{ paddingTop: spacing.lg, paddingBottom: spacing.xxxl }}>
|
|
549
486
|
{/* ── Essentials ──
|
|
550
487
|
The rows a holder reaches for without being told to: what their money
|
|
551
488
|
is denominated in, how to hand an app access, and the two ways out of
|
|
@@ -845,6 +782,7 @@ export function WalletConfigScreen() {
|
|
|
845
782
|
</GroupedSection>
|
|
846
783
|
|
|
847
784
|
{/* ── Data & Security ── */}
|
|
785
|
+
<View onLayout={event => setBackupSectionY(event.nativeEvent.layout.y)}>
|
|
848
786
|
<GroupedSection header={t('data_and_security')}>
|
|
849
787
|
{/* Vault's primary entry lives on the wallet menu (below Payments).
|
|
850
788
|
The DEV mock toggle stays here. */}
|
|
@@ -862,31 +800,11 @@ export function WalletConfigScreen() {
|
|
|
862
800
|
}}
|
|
863
801
|
/>
|
|
864
802
|
)}
|
|
865
|
-
{/* Both are recovery material rather than everyday controls, so
|
|
866
|
-
they sit with the rest of the data-and-security rows. */}
|
|
867
803
|
<ListRow
|
|
868
|
-
label={t('
|
|
804
|
+
label={t('backup_wallet_keys', { defaultValue: 'Backup Wallet Keys' })}
|
|
869
805
|
icon="key-outline"
|
|
870
806
|
iconColor="#CC8400"
|
|
871
|
-
onPress={
|
|
872
|
-
showChevron={false}
|
|
873
|
-
trailing={
|
|
874
|
-
<TouchableOpacity onPress={handleCopyMnemonic} style={{ padding: spacing.xs }}>
|
|
875
|
-
<Ionicons
|
|
876
|
-
name={copiedMnemonic ? 'checkmark' : 'copy-outline'}
|
|
877
|
-
size={18}
|
|
878
|
-
color={copiedMnemonic ? colors.success : colors.textSecondary}
|
|
879
|
-
/>
|
|
880
|
-
</TouchableOpacity>
|
|
881
|
-
}
|
|
882
|
-
/>
|
|
883
|
-
<ListRow
|
|
884
|
-
label={t('print_recovery_keys')}
|
|
885
|
-
icon="print-outline"
|
|
886
|
-
iconColor="#5856D6"
|
|
887
|
-
onPress={handlePrintRecoveryShares}
|
|
888
|
-
showChevron={false}
|
|
889
|
-
trailing={isPrinting ? <ActivityIndicator size="small" /> : undefined}
|
|
807
|
+
onPress={() => router.push('/auth/mnemonic?flow=backup')}
|
|
890
808
|
/>
|
|
891
809
|
<ListRow
|
|
892
810
|
label={t('storage_row')}
|
|
@@ -920,6 +838,7 @@ export function WalletConfigScreen() {
|
|
|
920
838
|
isLast
|
|
921
839
|
/>
|
|
922
840
|
</GroupedSection>
|
|
841
|
+
</View>
|
|
923
842
|
|
|
924
843
|
{/* ── Private backup ──
|
|
925
844
|
Its own section purely so the footer can carry the disclosure: the app sends an
|
|
@@ -239,9 +239,10 @@ export function WalletHomeScreen({ topLeft }: WalletHomeScreenProps = {}) {
|
|
|
239
239
|
refreshProof,
|
|
240
240
|
settings,
|
|
241
241
|
walletBuilt,
|
|
242
|
+
walletBuilding,
|
|
242
243
|
buildWalletFromMnemonic
|
|
243
244
|
} = useWallet()
|
|
244
|
-
const {
|
|
245
|
+
const { createMnemonic, hasStoredIdentity, secretsReady } = useLocalStorage()
|
|
245
246
|
const { satoshisPerUSD, usdToFiat = {} } = useContext(ExchangeRateContext)
|
|
246
247
|
const currency = settings?.currency || 'BSV'
|
|
247
248
|
const online = useOnline()
|
|
@@ -250,7 +251,7 @@ export function WalletHomeScreen({ topLeft }: WalletHomeScreenProps = {}) {
|
|
|
250
251
|
/**
|
|
251
252
|
* Apple HIG: never ask for Face ID/Touch ID before the user has done
|
|
252
253
|
* something that explains why. Creating a wallet needs biometric-gated
|
|
253
|
-
* storage (
|
|
254
|
+
* storage (createMnemonic below), so building one eagerly on first mount —
|
|
254
255
|
* as this screen used to — put a biometric prompt in front of a user who
|
|
255
256
|
* had not yet tapped anything. Instead, wallet creation is deferred until
|
|
256
257
|
* the first Pay or Get Paid tap (see destinationPress below), behind a
|
|
@@ -267,45 +268,62 @@ export function WalletHomeScreen({ topLeft }: WalletHomeScreenProps = {}) {
|
|
|
267
268
|
const creatingWalletRef = useRef(false)
|
|
268
269
|
const ensureWalletExists = useCallback(async (): Promise<boolean> => {
|
|
269
270
|
if (managers.permissionsManager) return true
|
|
270
|
-
if (creatingWalletRef.current) return false
|
|
271
|
+
if (!secretsReady || walletBuilding || creatingWalletRef.current) return false
|
|
271
272
|
creatingWalletRef.current = true
|
|
272
273
|
try {
|
|
274
|
+
// A missing manager during migration, unlock, or a failed build does
|
|
275
|
+
// not mean the device has no wallet. Never replace that stored identity.
|
|
276
|
+
if (await hasStoredIdentity()) return false
|
|
273
277
|
const wallet = generateMnemonicWallet()
|
|
274
|
-
const stored = await
|
|
278
|
+
const stored = await createMnemonic(wallet.mnemonic)
|
|
275
279
|
if (!stored) {
|
|
276
280
|
// Biometric access was needed and unavailable/declined — same dead
|
|
277
281
|
// end onboarding's own generate flow hits. Send the user there to
|
|
278
282
|
// retry explicitly rather than silently failing the tap.
|
|
279
|
-
router.replace('/auth/mnemonic')
|
|
283
|
+
if (!(await hasStoredIdentity())) router.replace('/auth/mnemonic')
|
|
280
284
|
return false
|
|
281
285
|
}
|
|
286
|
+
try {
|
|
287
|
+
await backupAttestation.markPending(wallet.identityKey)
|
|
288
|
+
} catch (error) {
|
|
289
|
+
console.warn('[WalletHome] Could not record pending backup reminder:', error)
|
|
290
|
+
}
|
|
282
291
|
await buildWalletFromMnemonic(wallet.mnemonic)
|
|
283
292
|
return true
|
|
293
|
+
} catch (error) {
|
|
294
|
+
console.warn('[WalletHome] Wallet creation did not complete:', error)
|
|
295
|
+
return false
|
|
284
296
|
} finally {
|
|
285
297
|
creatingWalletRef.current = false
|
|
286
298
|
}
|
|
287
|
-
}, [managers.permissionsManager,
|
|
299
|
+
}, [managers.permissionsManager, secretsReady, walletBuilding, hasStoredIdentity, createMnemonic, buildWalletFromMnemonic, router])
|
|
288
300
|
|
|
289
301
|
const [pendingDestination, setPendingDestination] = useState<string | null>(null)
|
|
290
302
|
const [showBiometricAdvisory, setShowBiometricAdvisory] = useState(false)
|
|
291
303
|
const [creatingWalletFromAdvisory, setCreatingWalletFromAdvisory] = useState(false)
|
|
292
304
|
|
|
293
305
|
const destinationPress = useCallback(
|
|
294
|
-
(destination: string) => {
|
|
306
|
+
async (destination: string) => {
|
|
295
307
|
if (managers.permissionsManager) {
|
|
296
308
|
router.push(destination as Parameters<typeof router.push>[0])
|
|
297
309
|
return
|
|
298
310
|
}
|
|
311
|
+
if (!secretsReady || walletBuilding) return
|
|
312
|
+
try {
|
|
313
|
+
if (await hasStoredIdentity()) return
|
|
314
|
+
} catch {
|
|
315
|
+
return
|
|
316
|
+
}
|
|
299
317
|
setPendingDestination(destination)
|
|
300
318
|
setShowBiometricAdvisory(true)
|
|
301
319
|
},
|
|
302
|
-
[managers.permissionsManager, router]
|
|
320
|
+
[managers.permissionsManager, secretsReady, walletBuilding, hasStoredIdentity, router]
|
|
303
321
|
)
|
|
304
322
|
|
|
305
323
|
// ── backup reminder ─────────────────────────────────────────────────
|
|
306
324
|
/**
|
|
307
|
-
*
|
|
308
|
-
*
|
|
325
|
+
* Remind only identities created with an explicit pending-backup record.
|
|
326
|
+
* Older wallets without tracking have unknown status. Re-check on focus so
|
|
309
327
|
* dismissing the card never sticks for the session — it reappears the
|
|
310
328
|
* moment the user lands back on the main page, until they actually back
|
|
311
329
|
* up or import. Same advisory attestation the vault gate reads.
|
|
@@ -313,6 +331,7 @@ export function WalletHomeScreen({ topLeft }: WalletHomeScreenProps = {}) {
|
|
|
313
331
|
const [showBackupReminder, setShowBackupReminder] = useState(false)
|
|
314
332
|
useFocusEffect(
|
|
315
333
|
useCallback(() => {
|
|
334
|
+
setShowBackupReminder(false)
|
|
316
335
|
if (!walletBuilt) return
|
|
317
336
|
const wallet = managers.permissionsManager
|
|
318
337
|
if (!wallet) return
|
|
@@ -320,12 +339,11 @@ export function WalletHomeScreen({ topLeft }: WalletHomeScreenProps = {}) {
|
|
|
320
339
|
;(async () => {
|
|
321
340
|
try {
|
|
322
341
|
const { publicKey } = await wallet.getPublicKey({ identityKey: true }, adminOriginator)
|
|
323
|
-
const
|
|
324
|
-
if (!cancelled) setShowBackupReminder(
|
|
342
|
+
const needsReminder = await backupAttestation.needsReminder(publicKey)
|
|
343
|
+
if (!cancelled) setShowBackupReminder(needsReminder)
|
|
325
344
|
} catch {
|
|
326
|
-
//
|
|
327
|
-
|
|
328
|
-
if (!cancelled) setShowBackupReminder(true)
|
|
345
|
+
// An unavailable status is not proof that the wallet is unbacked.
|
|
346
|
+
if (!cancelled) setShowBackupReminder(false)
|
|
329
347
|
}
|
|
330
348
|
})()
|
|
331
349
|
return () => {
|
|
@@ -381,8 +399,7 @@ export function WalletHomeScreen({ topLeft }: WalletHomeScreenProps = {}) {
|
|
|
381
399
|
|
|
382
400
|
/**
|
|
383
401
|
* Whether a wallet is already stored on this device, checked prompt-free
|
|
384
|
-
*
|
|
385
|
-
* itself finishes building. That build gap is briefly indistinguishable
|
|
402
|
+
* after migration and the initial build settle. That build gap is briefly indistinguishable
|
|
386
403
|
* from "no wallet at all" — both show no permissions manager — and two
|
|
387
404
|
* things key off telling them apart: ImportFromBackupPrompt below (must
|
|
388
405
|
* not flash "import" over an existing user's already-populated screen)
|
|
@@ -393,6 +410,8 @@ export function WalletHomeScreen({ topLeft }: WalletHomeScreenProps = {}) {
|
|
|
393
410
|
*/
|
|
394
411
|
const [knownNoStoredIdentity, setKnownNoStoredIdentity] = useState(false)
|
|
395
412
|
useEffect(() => {
|
|
413
|
+
setKnownNoStoredIdentity(false)
|
|
414
|
+
if (!secretsReady || walletBuilding) return
|
|
396
415
|
let cancelled = false
|
|
397
416
|
;(async () => {
|
|
398
417
|
try {
|
|
@@ -405,7 +424,7 @@ export function WalletHomeScreen({ topLeft }: WalletHomeScreenProps = {}) {
|
|
|
405
424
|
return () => {
|
|
406
425
|
cancelled = true
|
|
407
426
|
}
|
|
408
|
-
}, [hasStoredIdentity])
|
|
427
|
+
}, [hasStoredIdentity, secretsReady, walletBuilding])
|
|
409
428
|
|
|
410
429
|
// ── balance ─────────────────────────────────────────────────────────
|
|
411
430
|
/**
|
|
@@ -1462,7 +1481,7 @@ export function WalletHomeScreen({ topLeft }: WalletHomeScreenProps = {}) {
|
|
|
1462
1481
|
/>
|
|
1463
1482
|
|
|
1464
1483
|
<ImportFromBackupPrompt
|
|
1465
|
-
visible={!hasWallet && knownNoStoredIdentity}
|
|
1484
|
+
visible={!hasWallet && secretsReady && !walletBuilding && knownNoStoredIdentity}
|
|
1466
1485
|
onImport={() => router.push('/auth/mnemonic?flow=import')}
|
|
1467
1486
|
/>
|
|
1468
1487
|
</View>
|