@bsv/expo-wallet-toolbox 0.16.0 → 0.17.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 +41 -0
- package/core/backup/restore.ts +26 -4
- package/core/backup/restoreOnImport.ts +13 -4
- package/core/context/WalletContext.tsx +251 -74
- package/core/directpay/dialFailure.ts +56 -0
- package/core/directpay/index.ts +7 -0
- package/core/directpay/payFlow.ts +117 -0
- package/core/directpay/paymentKey.ts +16 -0
- package/core/directpay/settings.ts +253 -0
- package/core/directpay/status.ts +52 -0
- package/core/directpay/types.ts +128 -0
- package/core/i18n/translations.tsx +354 -12
- package/core/index.ts +12 -1
- package/core/profiles/discovery.ts +17 -8
- package/core/profiles/profileStore.ts +34 -7
- package/core/services/callbackToken.ts +7 -0
- package/core/toolboxConfig.ts +63 -1
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,46 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 0.17.0
|
|
4
|
+
|
|
5
|
+
### Added
|
|
6
|
+
|
|
7
|
+
- **Direct pay core for push payments** (`core/directpay/`, exported from
|
|
8
|
+
`core/index.ts`). This is the device-free half of paying a person live over
|
|
9
|
+
WebRTC, mirroring BSV Desktop:
|
|
10
|
+
- **Settings.** Receiving is on by default. The default relay is
|
|
11
|
+
`wss://webrtpay-relay-us-1.bsvblockchain.tech`, and BSV Association's STUN
|
|
12
|
+
server comes first. Relay, STUN and TURN addresses are validated without
|
|
13
|
+
`URL`. Settings are stored per device under `direct_pay_settings_v1`
|
|
14
|
+
through the host's `KVStorage`.
|
|
15
|
+
- **`payIdentity`.** Outcomes are `paid_live`, `paid_messagebox`,
|
|
16
|
+
`ask_fallback` and `failed`.
|
|
17
|
+
- **"Isn't online" prompt.** This prompt is the only route to the message
|
|
18
|
+
box, and only when nothing was spent: a route that stops first must
|
|
19
|
+
throw `NotSentError`.
|
|
20
|
+
- **`dialFailure`** classifies a dial error.
|
|
21
|
+
- **`liveStatus`** gives the Receive card's status.
|
|
22
|
+
- **`paymentKey`** is the dedupe key shared with the desktop.
|
|
23
|
+
- **Host config.** `configureToolbox` takes an optional `directPay` field,
|
|
24
|
+
read with `getDirectPayConfig()`. It is unset by default, so existing
|
|
25
|
+
hosts see no change.
|
|
26
|
+
- **Translations.** The new strings are in all 12 locales.
|
|
27
|
+
|
|
28
|
+
Nothing is wired into `WalletContext` or a screen yet. The live manager
|
|
29
|
+
and receive/send rails follow in a later release.
|
|
30
|
+
- **`deriveCallbackToken` is exported.** Known-answer vectors pin it. BSV
|
|
31
|
+
Desktop now derives the same Arcade callback token, so a wallet open in both
|
|
32
|
+
apps hears one status stream. No behaviour change.
|
|
33
|
+
|
|
34
|
+
### Fixed
|
|
35
|
+
|
|
36
|
+
- **Backups restore on every network.** A seed imported on mainnet then
|
|
37
|
+
switched to testnet or teratestnet came up empty even when the server held
|
|
38
|
+
a backup for that network. Each network's backup is now restored the first
|
|
39
|
+
time that network's database is built: after an import, on a network
|
|
40
|
+
switch, and for every network a discovered profile has backups on. Profile
|
|
41
|
+
0's other networks are included. Backup format, derivation and keys are
|
|
42
|
+
unchanged.
|
|
43
|
+
|
|
3
44
|
## 0.16.0
|
|
4
45
|
|
|
5
46
|
### Added
|
package/core/backup/restore.ts
CHANGED
|
@@ -37,6 +37,13 @@ export interface RestoreDeps {
|
|
|
37
37
|
* first chunk arrives.
|
|
38
38
|
*/
|
|
39
39
|
onProgress?: (chunks: number, total: number) => void
|
|
40
|
+
/**
|
|
41
|
+
* Called whenever the restore finishes a step that is not a chunk: ranking a candidate
|
|
42
|
+
* generation, and each page of the post-replay proof reconciliation. Carries nothing; it
|
|
43
|
+
* only says the restore is still working, so a caller waiting on it can tell a slow
|
|
44
|
+
* restore from a stuck one.
|
|
45
|
+
*/
|
|
46
|
+
onActivity?: () => void
|
|
40
47
|
}
|
|
41
48
|
|
|
42
49
|
export interface RestoreResult {
|
|
@@ -92,7 +99,16 @@ export async function restoreFromBackup (deps: RestoreDeps): Promise<RestoreResu
|
|
|
92
99
|
}
|
|
93
100
|
|
|
94
101
|
const settings = await deps.storage.makeAvailable()
|
|
95
|
-
const chosen = await pickTarget(
|
|
102
|
+
const chosen = await pickTarget(
|
|
103
|
+
devices,
|
|
104
|
+
client,
|
|
105
|
+
wallet,
|
|
106
|
+
deps.chain,
|
|
107
|
+
settings,
|
|
108
|
+
deps.deviceId,
|
|
109
|
+
deps.generation,
|
|
110
|
+
deps.onActivity
|
|
111
|
+
)
|
|
96
112
|
|
|
97
113
|
// processSyncChunk's preconditions, which a fresh, just-migrated database does
|
|
98
114
|
// not meet: it does verifyTruthy(findUserByIdentityKey(identityKey)) and then
|
|
@@ -144,7 +160,8 @@ export async function restoreFromBackup (deps: RestoreDeps): Promise<RestoreResu
|
|
|
144
160
|
if (chunks > reader.length) throw new Error('Backup replay did not acknowledge completion')
|
|
145
161
|
}
|
|
146
162
|
|
|
147
|
-
|
|
163
|
+
deps.onActivity?.()
|
|
164
|
+
await reconcileRestoredProofs(deps.storage, deps.onActivity)
|
|
148
165
|
return {
|
|
149
166
|
chunks,
|
|
150
167
|
deviceId: chosen.deviceId,
|
|
@@ -162,9 +179,10 @@ export async function restoreFromBackup (deps: RestoreDeps): Promise<RestoreResu
|
|
|
162
179
|
* which also reconciles notification IDs and preserves completed transactions.
|
|
163
180
|
* Run only after the entire log lands, before the wallet/monitor is published.
|
|
164
181
|
*/
|
|
165
|
-
async function reconcileRestoredProofs (storage: StorageExpoSQLite): Promise<void> {
|
|
182
|
+
async function reconcileRestoredProofs (storage: StorageExpoSQLite, onActivity?: () => void): Promise<void> {
|
|
166
183
|
const limit = 1
|
|
167
184
|
for (let offset = 0; ; offset += limit) {
|
|
185
|
+
if (offset > 0) onActivity?.()
|
|
168
186
|
// Page over every status so completing a request cannot shift the next
|
|
169
187
|
// page's offsets. A request may contain a large expanded inputBEEF, so
|
|
170
188
|
// retain only one request at a time while completion reloads its proof.
|
|
@@ -229,7 +247,9 @@ export async function pickTarget (
|
|
|
229
247
|
chain: BackupChain,
|
|
230
248
|
settings: TableSettings,
|
|
231
249
|
deviceId?: string,
|
|
232
|
-
generation?: number
|
|
250
|
+
generation?: number,
|
|
251
|
+
/** Called after each candidate is checked, readable or not (see RestoreDeps.onActivity). */
|
|
252
|
+
onActivity?: () => void
|
|
233
253
|
): Promise<PickedTarget> {
|
|
234
254
|
const candidates = deviceId != null ? devices.filter(d => d.deviceId === deviceId) : devices
|
|
235
255
|
if (candidates.length === 0) {
|
|
@@ -244,6 +264,7 @@ export async function pickTarget (
|
|
|
244
264
|
if (exact == null) throw new Error(`No backup found for generation ${generation}`)
|
|
245
265
|
const reader = readerFor(exact)
|
|
246
266
|
const verified = await reader.verifiedComplete()
|
|
267
|
+
onActivity?.()
|
|
247
268
|
return { deviceId: exact.deviceId, generation: exact.generation, verified, reader }
|
|
248
269
|
}
|
|
249
270
|
|
|
@@ -262,6 +283,7 @@ export async function pickTarget (
|
|
|
262
283
|
// and was never going to be chosen anyway — it is simply not verified.
|
|
263
284
|
verified = false
|
|
264
285
|
}
|
|
286
|
+
onActivity?.()
|
|
265
287
|
if (verified) return { deviceId: candidate.deviceId, generation: candidate.generation, verified: true, reader }
|
|
266
288
|
}
|
|
267
289
|
|
|
@@ -62,6 +62,12 @@ export interface RestoreOnImportDeps {
|
|
|
62
62
|
* once per device, each restarting from its own generation's own total.
|
|
63
63
|
*/
|
|
64
64
|
onProgress?: (chunks: number, total: number) => void
|
|
65
|
+
/**
|
|
66
|
+
* Called whenever the restore finishes a step that is not a chunk: each candidate it
|
|
67
|
+
* ranks, before and during proof reconciliation, and before the coin review.
|
|
68
|
+
* See RestoreDeps.onActivity.
|
|
69
|
+
*/
|
|
70
|
+
onActivity?: () => void
|
|
65
71
|
/**
|
|
66
72
|
* After a successful replay, check that restored coins are still spendable.
|
|
67
73
|
* Awaited before this function resolves, but best-effort: a failure is logged and
|
|
@@ -112,7 +118,7 @@ export async function restoreOnImport (deps: RestoreOnImportDeps): Promise<Resto
|
|
|
112
118
|
// manifest — the overwhelming common case — restores exactly as before.
|
|
113
119
|
const wallet = deriveBackupWallet(deps.primaryKey, deps.chain)
|
|
114
120
|
const settings = await deps.storage.makeAvailable()
|
|
115
|
-
const primary = await pickTarget(devices, client, wallet, deps.chain, settings)
|
|
121
|
+
const primary = await pickTarget(devices, client, wallet, deps.chain, settings, undefined, undefined, deps.onActivity)
|
|
116
122
|
|
|
117
123
|
const primaryResult = await restoreFromBackup({
|
|
118
124
|
storage: deps.storage,
|
|
@@ -123,7 +129,8 @@ export async function restoreOnImport (deps: RestoreOnImportDeps): Promise<Resto
|
|
|
123
129
|
manifest: devices,
|
|
124
130
|
deviceId: primary.deviceId,
|
|
125
131
|
generation: primary.generation,
|
|
126
|
-
onProgress: deps.onProgress
|
|
132
|
+
onProgress: deps.onProgress,
|
|
133
|
+
onActivity: deps.onActivity
|
|
127
134
|
})
|
|
128
135
|
|
|
129
136
|
let chunks = primaryResult.chunks
|
|
@@ -144,7 +151,7 @@ export async function restoreOnImport (deps: RestoreOnImportDeps): Promise<Resto
|
|
|
144
151
|
// rather than blindly taking its newest generation.
|
|
145
152
|
const otherDeviceIds = [...new Set(devices.map(d => d.deviceId))].filter(id => id !== primary.deviceId)
|
|
146
153
|
for (const deviceId of otherDeviceIds) {
|
|
147
|
-
const target = await pickTarget(devices, client, wallet, deps.chain, settings, deviceId)
|
|
154
|
+
const target = await pickTarget(devices, client, wallet, deps.chain, settings, deviceId, undefined, deps.onActivity)
|
|
148
155
|
const result = await restoreFromBackup({
|
|
149
156
|
storage: deps.storage,
|
|
150
157
|
primaryKey: deps.primaryKey,
|
|
@@ -154,7 +161,8 @@ export async function restoreOnImport (deps: RestoreOnImportDeps): Promise<Resto
|
|
|
154
161
|
manifest: devices,
|
|
155
162
|
deviceId: target.deviceId,
|
|
156
163
|
generation: target.generation,
|
|
157
|
-
onProgress: deps.onProgress
|
|
164
|
+
onProgress: deps.onProgress,
|
|
165
|
+
onActivity: deps.onActivity
|
|
158
166
|
})
|
|
159
167
|
chunks += result.chunks
|
|
160
168
|
verified = verified && result.verified
|
|
@@ -185,6 +193,7 @@ export async function restoreOnImport (deps: RestoreOnImportDeps): Promise<Resto
|
|
|
185
193
|
}
|
|
186
194
|
|
|
187
195
|
if (deps.validateRestoredCoins) {
|
|
196
|
+
deps.onActivity?.()
|
|
188
197
|
try {
|
|
189
198
|
await deps.validateRestoredCoins()
|
|
190
199
|
} catch (error) {
|