@bsv/expo-wallet-toolbox 0.16.0 → 0.18.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 CHANGED
@@ -1,5 +1,87 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.18.0
4
+
5
+ ### Added
6
+
7
+ - **Live (WebRTC) push payments.** Hosts can now pay and be paid live, with
8
+ the message box as the fallback.
9
+ - **Opt in.** It turns on when the host installs `@bsv/webrtpay` (an
10
+ optional peer, `^0.2.1`), sets `configureToolbox({ directPay: { enabled:
11
+ true, RTCPeerConnection } })` and mounts `DirectPayProvider` inside
12
+ `WalletContextProvider`. Without all three nothing changes.
13
+ - **`DirectPayManager`.** Wallets find each other through the relay by
14
+ default. If the relay is not online within 5 s, receiving falls back to
15
+ the message box while the relay is retried (5 s doubling to 5 min). It
16
+ uses the relay's TURN servers and gives a dial 10 s. It receives only
17
+ while the app is in the foreground.
18
+ - **Receiving** (`core/directpay/receive.ts`). A live payment is verified
19
+ and taken into the wallet once, labelled `peerpay`. A seen store keyed by
20
+ `paymentKey`, shared with the inbox credit path, stops a payment that
21
+ arrives both live and through the message box from being credited or
22
+ toasted twice. A payment that cannot be added for environmental reasons
23
+ is kept on the device and retried. It is never dropped.
24
+ - **Sending** (`core/pay/rails/direct.ts`, `sendViaDirect`). One
25
+ transaction and one outbox row per payment. The order is dial, mint,
26
+ send, then broadcast after the ack. Once a payment has been sent it is
27
+ never aborted: a refused or unconfirmed live delivery finishes through
28
+ the message box. Every stop before sending throws `NotSentError`, so
29
+ `payIdentity` can offer the message box.
30
+ - **`useDirectPay()`** exposes the snapshot, the Receive card status
31
+ (`live`), settings, `canSendDirect` and `sendDirect`, the `direct` route
32
+ for `payIdentity`.
33
+ - **`withReactNativeDataChannels(RTCPeerConnection)`** makes
34
+ react-native-webrtc data channels acceptable to `@bsv/webrtpay` 0.2.1
35
+ (Android reports -1 and iOS 65535 for an unset limit). Drop it once
36
+ webrtpay ships the fix.
37
+
38
+ ### Changed
39
+
40
+ - **The inbox credit path takes an optional seen store.**
41
+ `internalizeIncoming` returns `'credited' | 'duplicate'`, and
42
+ `autoAcceptInbox` does not count duplicates.
43
+
44
+ ## 0.17.0
45
+
46
+ ### Added
47
+
48
+ - **Direct pay core for push payments** (`core/directpay/`, exported from
49
+ `core/index.ts`). This is the device-free half of paying a person live over
50
+ WebRTC, mirroring BSV Desktop:
51
+ - **Settings.** Receiving is on by default. The default relay is
52
+ `wss://webrtpay-relay-us-1.bsvblockchain.tech`, and BSV Association's STUN
53
+ server comes first. Relay, STUN and TURN addresses are validated without
54
+ `URL`. Settings are stored per device under `direct_pay_settings_v1`
55
+ through the host's `KVStorage`.
56
+ - **`payIdentity`.** Outcomes are `paid_live`, `paid_messagebox`,
57
+ `ask_fallback` and `failed`.
58
+ - **"Isn't online" prompt.** This prompt is the only route to the message
59
+ box, and only when nothing was spent: a route that stops first must
60
+ throw `NotSentError`.
61
+ - **`dialFailure`** classifies a dial error.
62
+ - **`liveStatus`** gives the Receive card's status.
63
+ - **`paymentKey`** is the dedupe key shared with the desktop.
64
+ - **Host config.** `configureToolbox` takes an optional `directPay` field,
65
+ read with `getDirectPayConfig()`. It is unset by default, so existing
66
+ hosts see no change.
67
+ - **Translations.** The new strings are in all 12 locales.
68
+
69
+ Nothing is wired into `WalletContext` or a screen yet. The live manager
70
+ and receive/send rails follow in a later release.
71
+ - **`deriveCallbackToken` is exported.** Known-answer vectors pin it. BSV
72
+ Desktop now derives the same Arcade callback token, so a wallet open in both
73
+ apps hears one status stream. No behaviour change.
74
+
75
+ ### Fixed
76
+
77
+ - **Backups restore on every network.** A seed imported on mainnet then
78
+ switched to testnet or teratestnet came up empty even when the server held
79
+ a backup for that network. Each network's backup is now restored the first
80
+ time that network's database is built: after an import, on a network
81
+ switch, and for every network a discovered profile has backups on. Profile
82
+ 0's other networks are included. Backup format, derivation and keys are
83
+ unchanged.
84
+
3
85
  ## 0.16.0
4
86
 
5
87
  ### Added
@@ -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(devices, client, wallet, deps.chain, settings, deps.deviceId, deps.generation)
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
- await reconcileRestoredProofs(deps.storage)
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) {