@bsv/expo-wallet-toolbox 0.23.0 → 0.24.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 +147 -0
- package/README.md +1 -4
- package/android/build.gradle +15 -0
- package/android/src/main/AndroidManifest.xml +3 -0
- package/android/src/main/java/org/bsv/boundedfetch/BoundedBody.java +19 -0
- package/android/src/main/java/org/bsv/boundedfetch/BoundedConnection.java +28 -0
- package/android/src/main/java/org/bsv/boundedfetch/BsvBoundedFetchModule.kt +114 -0
- package/core/backup/RemoteSyncReader.ts +71 -46
- package/core/backup/client.ts +6 -15
- package/core/backup/codec.ts +78 -13
- package/core/backup/constants.ts +3 -9
- package/core/backup/cursor.ts +8 -0
- package/core/backup/push.ts +26 -16
- package/core/backup/restore.ts +6 -5
- package/core/bridge/inbox.ts +169 -64
- package/core/bridge/memoryInboxStore.ts +10 -1
- package/core/constants.ts +7 -11
- package/core/context/WalletConnectionContext.tsx +85 -48
- package/core/context/WalletContext.tsx +30 -32
- package/core/context/usePairingAttempt.ts +31 -0
- package/core/e2e/broadcaster.ts +25 -0
- package/core/e2e/consentFixture.ts +46 -0
- package/core/e2e/mode.ts +42 -0
- package/core/headers/OfflineFirstChaintracks.ts +57 -107
- package/core/headers/headerConsensus.ts +230 -0
- package/core/headers/headerStore.ts +344 -122
- package/core/headers/prewarm.ts +4 -7
- package/core/headers/syncHeaders.ts +82 -12
- package/core/i18n/translations.tsx +47 -12
- package/core/identity/handleRegistry/client.ts +4 -2
- package/core/identity/handleRegistry/resolver.ts +7 -11
- package/core/index.ts +2 -0
- package/core/localpay/pending.ts +39 -4
- package/core/network/boundedFetch.ts +101 -0
- package/core/networks.ts +11 -13
- package/core/pay/rails/address.ts +5 -4
- package/core/pay/rails/handle.ts +3 -1
- package/core/pay/rails/sweep.ts +791 -0
- package/core/peerpay/brc29.ts +4 -0
- package/core/peerpay/handleResendRequests.ts +15 -2
- package/core/peerpay/outbox.ts +115 -2
- package/core/profiles/assertProfileEmpty.ts +2 -2
- package/core/profiles/profileStore.ts +3 -2
- package/core/services/arcadeBroadcastProvider.ts +260 -114
- package/core/services/secrets/kek.ts +5 -0
- package/core/services/secrets/migration.ts +27 -2
- package/core/services/secrets/policy.ts +6 -0
- package/core/services/vault/VaultKeyService.ts +5 -2
- package/core/services/vault/ceremony.ts +2 -2
- package/core/services/vault/ceremonyHost.ts +1 -1
- package/core/services/vault/guard.ts +10 -0
- package/core/services/vault/outputAuthority.ts +76 -0
- package/core/services/vault/transfers.ts +52 -28
- package/core/services/vault/vaultStore.ts +60 -14
- package/core/services/walletConnectionValidation.ts +13 -1
- package/core/services/walletServiceConfig.ts +8 -7
- package/core/stores/ConnectionStore.ts +17 -0
- package/core/toolboxConfig.ts +60 -1
- package/expo-module.config.json +5 -0
- package/ios/BoundedBody.swift +15 -0
- package/ios/BsvBoundedFetch.podspec +17 -0
- package/ios/BsvBoundedFetchModule.swift +134 -0
- package/package.json +7 -3
- package/ui/components/pay/AddressReceive.tsx +6 -2
- package/ui/components/pay/ImportedOutboxApproval.tsx +142 -0
- package/ui/components/pay/PayCellRow.tsx +3 -1
- package/ui/components/pay/PayForm.tsx +12 -2
- package/ui/components/pay/RecipientField.tsx +1 -0
- package/ui/components/pay/RequestHub.tsx +1 -0
- package/ui/components/pay/UniversalSend.tsx +110 -42
- package/ui/components/ui/ListRow.tsx +10 -2
- package/ui/components/vault/KeyChooser.tsx +1 -1
- package/ui/components/wallet/AmountInput.tsx +4 -1
- package/ui/components/wallet/BackupReminderSheet.tsx +8 -1
- package/ui/components/wallet/BiometricAdvisoryModal.tsx +2 -0
- package/ui/components/wallet/ImportFromBackupPrompt.tsx +6 -1
- package/ui/components/wallet/ProfileButton.tsx +1 -0
- package/ui/importDatabases.ts +31 -6
- package/ui/screens/ConnectionsScreen.tsx +12 -3
- package/ui/screens/PairScreen.tsx +10 -3
- package/ui/screens/PayScreen.tsx +1 -0
- package/ui/screens/TrustScreen.tsx +6 -3
- package/ui/screens/VaultScreen.tsx +13 -3
- package/ui/screens/VaultTransferScreen.tsx +6 -3
- package/ui/screens/WalletConfigScreen.tsx +17 -2
- package/ui/screens/WalletHomeScreen.tsx +7 -1
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { Beef } from '@bsv/sdk'
|
|
2
2
|
import { PUBKEY_LABEL } from '../pay/counterparty'
|
|
3
3
|
import { ackControlMessages, isDuplicateMessageError, listControlMessages, parseControlMessage } from './control'
|
|
4
|
-
import { getOutboxEntries, type OutboxEntry } from './outbox'
|
|
4
|
+
import { getOutboxEntries, getOutboxEntriesStrict, type OutboxEntry } from './outbox'
|
|
5
5
|
import { instructionsFromOutput, rebuildPeerPayToken } from './rebuildToken'
|
|
6
6
|
|
|
7
7
|
/** The message box outbound payments are delivered into. Same name as handle.ts. */
|
|
@@ -206,6 +206,10 @@ function recipientFromLabels(labels: string[] | undefined): string | undefined {
|
|
|
206
206
|
|
|
207
207
|
function outboxTxid(entry: OutboxEntry): string | undefined {
|
|
208
208
|
if (typeof entry.txid === 'string' && entry.txid.length > 0) return entry.txid
|
|
209
|
+
return outboxTokenTxid(entry)
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
function outboxTokenTxid(entry: OutboxEntry): string | undefined {
|
|
209
213
|
try {
|
|
210
214
|
const txid = Beef.fromBinary(Array.from(entry.token.transaction)).atomicTxid
|
|
211
215
|
return typeof txid === 'string' && txid.length > 0 ? txid : undefined
|
|
@@ -398,7 +402,16 @@ async function rebuildAndDeliver(args: {
|
|
|
398
402
|
/** Unwraps metadata the permissions manager encrypted on its way to storage. */
|
|
399
403
|
decryptMetadata?: (value: string) => Promise<string>
|
|
400
404
|
}): Promise<ResendOutcome> {
|
|
401
|
-
|
|
405
|
+
// An unreadable queue cannot establish that this transaction is not held.
|
|
406
|
+
const entries = await getOutboxEntriesStrict(args.storage)
|
|
407
|
+
// Resending hands the signed payment to its recipient just like a retry.
|
|
408
|
+
// A held import must pass the reviewed release flow first; neither another
|
|
409
|
+
// history row for this txid nor the action-metadata fallback may bypass it.
|
|
410
|
+
if (
|
|
411
|
+
entries.some(e => e.status === 'import_hold' && (outboxTxid(e) === args.txid || outboxTokenTxid(e) === args.txid))
|
|
412
|
+
) {
|
|
413
|
+
throw new Error('Imported payment requires review before resending')
|
|
414
|
+
}
|
|
402
415
|
const entry = entries.find(e => outboxTxid(e) === args.txid)
|
|
403
416
|
const listed = entry ? undefined : await args.listPeerPayAction(args.txid)
|
|
404
417
|
const action = entry ? actionFromOutbox(entry, args.txid) : listed
|
package/core/peerpay/outbox.ts
CHANGED
|
@@ -14,6 +14,9 @@
|
|
|
14
14
|
* SENT_RETENTION_MS then pruned. Retry is manual — the UI lists unsent only.
|
|
15
15
|
*/
|
|
16
16
|
|
|
17
|
+
import { P2PKH, PublicKey, Transaction, type WalletInterface } from '@bsv/sdk'
|
|
18
|
+
import { BRC29_PROTOCOL_ID } from './brc29'
|
|
19
|
+
|
|
17
20
|
// ── Types ──────────────────────────────────────────────────────────────────────
|
|
18
21
|
|
|
19
22
|
export interface OutboxEntry {
|
|
@@ -48,7 +51,7 @@ export interface OutboxEntry {
|
|
|
48
51
|
* overlay lookup. Absent for entries minted from a bare key.
|
|
49
52
|
*/
|
|
50
53
|
recipientHost?: string
|
|
51
|
-
status: 'unsent' | 'sent'
|
|
54
|
+
status: 'unsent' | 'sent' | 'import_hold'
|
|
52
55
|
/** ISO 8601 timestamp of most recent delivery attempt */
|
|
53
56
|
lastAttemptAt?: string
|
|
54
57
|
/** Error message from the most recent failed delivery attempt */
|
|
@@ -153,6 +156,110 @@ export async function getOutboxEntriesStrict(storage: Pick<StorageLike, 'getKeyV
|
|
|
153
156
|
return readEntries(storage)
|
|
154
157
|
}
|
|
155
158
|
|
|
159
|
+
/** Imported history is not current approval to deliver or broadcast a payment. */
|
|
160
|
+
export async function quarantineImportedOutbox(storage: StorageLike): Promise<number> {
|
|
161
|
+
return withOutboxLock(storage, async () => {
|
|
162
|
+
const all = await readEntries(storage)
|
|
163
|
+
let count = 0
|
|
164
|
+
const held = all.map(entry => {
|
|
165
|
+
if (!entry || typeof entry !== 'object') throw new Error('Invalid imported outbox entry')
|
|
166
|
+
if (entry.status === 'sent' || entry.status === 'import_hold') return entry
|
|
167
|
+
count++
|
|
168
|
+
return { ...entry, status: 'import_hold' as const }
|
|
169
|
+
})
|
|
170
|
+
if (count) await writeEntries(storage, held)
|
|
171
|
+
return count
|
|
172
|
+
})
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
/** Verify an imported snapshot before its amount or recipient is offered for
|
|
176
|
+
* approval. Only public-key derivation is needed; no payment is signed or sent. */
|
|
177
|
+
export async function validateImportedOutboxEntry(
|
|
178
|
+
entry: OutboxEntry,
|
|
179
|
+
wallet: Pick<WalletInterface, 'getPublicKey'>,
|
|
180
|
+
adminOriginator: string
|
|
181
|
+
): Promise<OutboxEntry> {
|
|
182
|
+
// Separate the checked snapshot from the caller's mutable imported object
|
|
183
|
+
// before awaiting wallet derivation. Release still checks exact stored equality.
|
|
184
|
+
const reviewed = JSON.parse(JSON.stringify(entry)) as OutboxEntry
|
|
185
|
+
if (reviewed.status !== 'import_hold') throw new Error('Imported payment is not held for review')
|
|
186
|
+
const token = reviewed.token
|
|
187
|
+
if (
|
|
188
|
+
!token ||
|
|
189
|
+
!Array.isArray(token.transaction) ||
|
|
190
|
+
!token.transaction.length ||
|
|
191
|
+
!token.transaction.every(byte => Number.isInteger(byte) && byte >= 0 && byte <= 255)
|
|
192
|
+
) {
|
|
193
|
+
throw new Error('Imported payment has an invalid signed transaction')
|
|
194
|
+
}
|
|
195
|
+
const tx = Transaction.fromAtomicBEEF(token.transaction)
|
|
196
|
+
if (
|
|
197
|
+
reviewed.txid !== undefined &&
|
|
198
|
+
(typeof reviewed.txid !== 'string' ||
|
|
199
|
+
!/^[0-9a-f]{64}$/i.test(reviewed.txid) ||
|
|
200
|
+
tx.id('hex').toLowerCase() !== reviewed.txid.toLowerCase())
|
|
201
|
+
) {
|
|
202
|
+
throw new Error('Imported payment transaction ID does not match its signed transaction')
|
|
203
|
+
}
|
|
204
|
+
const outputIndex = token.outputIndex === undefined ? 0 : token.outputIndex
|
|
205
|
+
if (!Number.isSafeInteger(outputIndex) || outputIndex < 0 || outputIndex >= tx.outputs.length) {
|
|
206
|
+
throw new Error('Imported payment has an invalid signed output index')
|
|
207
|
+
}
|
|
208
|
+
const output = tx.outputs[outputIndex]
|
|
209
|
+
if (!Number.isSafeInteger(output.satoshis) || output.satoshis! <= 0 || token.amount !== output.satoshis) {
|
|
210
|
+
throw new Error('Imported payment amount does not match its signed output')
|
|
211
|
+
}
|
|
212
|
+
const { derivationPrefix, derivationSuffix } = token.customInstructions ?? {}
|
|
213
|
+
if (
|
|
214
|
+
typeof derivationPrefix !== 'string' ||
|
|
215
|
+
!derivationPrefix ||
|
|
216
|
+
typeof derivationSuffix !== 'string' ||
|
|
217
|
+
!derivationSuffix ||
|
|
218
|
+
typeof reviewed.recipient !== 'string' ||
|
|
219
|
+
!/^(02|03)[0-9a-f]{64}$/i.test(reviewed.recipient)
|
|
220
|
+
) {
|
|
221
|
+
throw new Error('Imported payment has invalid recipient derivation data')
|
|
222
|
+
}
|
|
223
|
+
// Exactly the BRC-29 derivation used by mintPeerPayToken, under the current
|
|
224
|
+
// admin wallet. A different recipient or prefix/suffix produces a different lock.
|
|
225
|
+
PublicKey.fromString(reviewed.recipient)
|
|
226
|
+
const { publicKey } = await wallet.getPublicKey(
|
|
227
|
+
{
|
|
228
|
+
protocolID: BRC29_PROTOCOL_ID,
|
|
229
|
+
keyID: `${derivationPrefix} ${derivationSuffix}`,
|
|
230
|
+
counterparty: reviewed.recipient
|
|
231
|
+
},
|
|
232
|
+
adminOriginator
|
|
233
|
+
)
|
|
234
|
+
const expected = new P2PKH().lock(PublicKey.fromString(publicKey).toAddress()).toHex()
|
|
235
|
+
if (output.lockingScript.toHex() !== expected) {
|
|
236
|
+
throw new Error('Imported payment recipient does not match its signed output')
|
|
237
|
+
}
|
|
238
|
+
return reviewed
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
/** Called only after reviewing the displayed imported payment for a new send. */
|
|
242
|
+
export async function releaseImportedOutboxEntry(
|
|
243
|
+
storage: StorageLike,
|
|
244
|
+
reviewed: OutboxEntry,
|
|
245
|
+
wallet: Pick<WalletInterface, 'getPublicKey'>,
|
|
246
|
+
adminOriginator: string
|
|
247
|
+
): Promise<OutboxEntry> {
|
|
248
|
+
return withOutboxLock(storage, async () => {
|
|
249
|
+
const all = await readEntries(storage)
|
|
250
|
+
const index = all.findIndex(entry => entry.id === reviewed.id)
|
|
251
|
+
const current = all[index]
|
|
252
|
+
if (!current || current.status !== 'import_hold' || JSON.stringify(current) !== JSON.stringify(reviewed)) {
|
|
253
|
+
throw new Error('Imported payment changed; review it again')
|
|
254
|
+
}
|
|
255
|
+
const validated = await validateImportedOutboxEntry(current, wallet, adminOriginator)
|
|
256
|
+
const approved = { ...validated, status: 'unsent' as const }
|
|
257
|
+
all[index] = approved
|
|
258
|
+
await writeEntries(storage, all)
|
|
259
|
+
return approved
|
|
260
|
+
})
|
|
261
|
+
}
|
|
262
|
+
|
|
156
263
|
/**
|
|
157
264
|
* Persist a new outbound payment token to the outbox before delivery is attempted.
|
|
158
265
|
* Returns the generated entry ID.
|
|
@@ -264,7 +371,13 @@ export async function pruneExpiredSent(storage: StorageLike, now: number = Date.
|
|
|
264
371
|
})
|
|
265
372
|
}
|
|
266
373
|
|
|
267
|
-
/**
|
|
374
|
+
/** Only explicitly authorized unsent entries may enter automatic delivery. */
|
|
268
375
|
export function unsentEntries(entries: OutboxEntry[]): OutboxEntry[] {
|
|
376
|
+
return entries.filter(e => e.status === 'unsent')
|
|
377
|
+
}
|
|
378
|
+
|
|
379
|
+
/** Held or unrecognized history still needs retention, even though it cannot
|
|
380
|
+
* be automatically delivered. Only sent entries are terminal. */
|
|
381
|
+
export function unresolvedOutboxEntries(entries: OutboxEntry[]): OutboxEntry[] {
|
|
269
382
|
return entries.filter(e => e.status !== 'sent')
|
|
270
383
|
}
|
|
@@ -25,7 +25,7 @@
|
|
|
25
25
|
import type { BindValue } from '../storage/methods/offlineActions'
|
|
26
26
|
import { PENDING_JOURNAL_KEY } from '../identity/handleRegistry/registration'
|
|
27
27
|
import { PENDING_KEY } from '../localpay/pending'
|
|
28
|
-
import { getOutboxEntriesStrict,
|
|
28
|
+
import { getOutboxEntriesStrict, unresolvedOutboxEntries } from '../peerpay/outbox'
|
|
29
29
|
import { TERMINAL_TRANSFER_STATES } from '../mandala/types'
|
|
30
30
|
|
|
31
31
|
/** Why a profile cannot be removed. One code per thing found, for the UI to explain. */
|
|
@@ -181,7 +181,7 @@ export async function assertProfileEmpty(
|
|
|
181
181
|
return balances.some(b => !(b.units === 0n && b.offlineUnits === 0n))
|
|
182
182
|
})
|
|
183
183
|
await check('localpay-pending', () => receivedPaymentsWaiting(storage))
|
|
184
|
-
await check('peerpay-outbox', async () =>
|
|
184
|
+
await check('peerpay-outbox', async () => unresolvedOutboxEntries(await getOutboxEntriesStrict(storage)).length > 0)
|
|
185
185
|
// Any value at all, not one parsed: `clearJournal` leaves `''` behind, and
|
|
186
186
|
// that is the only thing that means "nothing in flight".
|
|
187
187
|
await check('handle-journal', async () => !!(await storage.getKeyValue(PENDING_JOURNAL_KEY)))
|
|
@@ -24,6 +24,7 @@
|
|
|
24
24
|
import { useSyncExternalStore } from 'react'
|
|
25
25
|
import AsyncStorage from '@react-native-async-storage/async-storage'
|
|
26
26
|
import { DEFAULT_CHAIN, type AppChain } from '../config'
|
|
27
|
+
import { e2eSafeChain } from '../e2e/mode'
|
|
27
28
|
import { APP_CHAINS } from '../networks'
|
|
28
29
|
|
|
29
30
|
export const PROFILES_STORAGE_KEY = 'wallet_profiles_v1'
|
|
@@ -78,7 +79,7 @@ export function normalizeRestorePending(raw: unknown): AppChain[] | undefined {
|
|
|
78
79
|
}
|
|
79
80
|
|
|
80
81
|
export function defaultProfilesState(): ProfilesState {
|
|
81
|
-
return { active: 0, profiles: [{ index: 0, network: DEFAULT_CHAIN }] }
|
|
82
|
+
return { active: 0, profiles: [{ index: 0, network: e2eSafeChain(DEFAULT_CHAIN) }] }
|
|
82
83
|
}
|
|
83
84
|
|
|
84
85
|
/** Trim and cap a profile name; undefined when nothing is left (the default label applies). */
|
|
@@ -128,7 +129,7 @@ export function parseProfilesState(raw: string | null): ProfilesState {
|
|
|
128
129
|
)
|
|
129
130
|
byIndex.set(r.index as number, {
|
|
130
131
|
index: r.index as number,
|
|
131
|
-
network: CHAINS.includes(r.network as AppChain) ? (r.network as AppChain) : DEFAULT_CHAIN,
|
|
132
|
+
network: e2eSafeChain(CHAINS.includes(r.network as AppChain) ? (r.network as AppChain) : DEFAULT_CHAIN),
|
|
132
133
|
...(typeof r.identityKey === 'string' ? { identityKey: r.identityKey } : {}),
|
|
133
134
|
...(restorePending ? { restorePending } : {}),
|
|
134
135
|
...(CHAINS.includes(r.lastBuiltNetwork as AppChain) ? { lastBuiltNetwork: r.lastBuiltNetwork as AppChain } : {}),
|