@bsv/expo-wallet-toolbox 0.22.0 → 0.24.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 +241 -0
- package/README.md +10 -9
- 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/BrowserBridgeProvider.tsx +273 -0
- package/core/bridge/bindings.ts +459 -0
- package/core/bridge/conformance.ts +222 -0
- package/core/bridge/consent.ts +494 -0
- package/core/bridge/consentSheetSource.ts +98 -0
- package/core/bridge/dispatcher.ts +621 -0
- package/core/bridge/inbox.ts +569 -0
- package/core/bridge/index.ts +48 -0
- package/core/bridge/loopback/cors.ts +57 -0
- package/core/bridge/loopback/endpoints.ts +11 -0
- package/core/bridge/loopback/hostCheck.ts +25 -0
- package/core/bridge/loopback/index.ts +7 -0
- package/core/bridge/loopback/launchProof.ts +166 -0
- package/core/bridge/loopback/router.ts +770 -0
- package/core/bridge/loopback/routerTypes.ts +115 -0
- package/core/bridge/loopback/status.ts +52 -0
- package/core/bridge/memoryInboxStore.ts +231 -0
- package/core/bridge/permissionPolicy.ts +247 -0
- package/core/bridge/policy.ts +72 -0
- package/core/bridge/protocol/base64url.ts +64 -0
- package/core/bridge/protocol/connectionError.ts +79 -0
- package/core/bridge/protocol/constants.ts +21 -0
- package/core/bridge/protocol/continuity.ts +21 -0
- package/core/bridge/protocol/descriptor.ts +395 -0
- package/core/bridge/protocol/envelopes.ts +188 -0
- package/core/bridge/protocol/errorCodec.ts +164 -0
- package/core/bridge/protocol/json.ts +237 -0
- package/core/bridge/protocol/limits.ts +43 -0
- package/core/bridge/protocol/methods.ts +55 -0
- package/core/bridge/protocol/origin.ts +130 -0
- package/core/bridge/runtime.ts +642 -0
- package/core/bridge/runtimeFlags.ts +34 -0
- package/core/bridge/testing/conformanceCases.ts +149 -0
- package/core/bridge/testing/pageClient.ts +44 -0
- package/core/bridge/unverifiedManager.ts +97 -0
- package/core/bridge/unverifiedOriginator.ts +79 -0
- package/core/config.tsx +1 -16
- package/core/constants.ts +7 -11
- package/core/context/WalletConnectionContext.tsx +92 -49
- package/core/context/WalletContext.tsx +288 -165
- package/core/context/sessionTeardown.ts +46 -0
- 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/hooks/usePermissionQueue.ts +89 -34
- package/core/i18n/translations.tsx +958 -24
- package/core/identity/handleRegistry/client.ts +4 -2
- package/core/identity/handleRegistry/resolver.ts +7 -11
- package/core/index.ts +17 -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/autoApprovePolicy.ts +7 -1
- package/core/services/capWalletArgs.ts +2 -1
- package/core/services/permissionPrompts.ts +132 -0
- 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/signingPermissionPolicy.ts +230 -2
- 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 +20 -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/walletArgLimits.ts +17 -2
- package/core/services/walletConnectionValidation.ts +13 -1
- package/core/services/walletServiceConfig.ts +8 -7
- package/core/storage/encryptedDbImage.ts +325 -0
- package/core/stores/ConnectionStore.ts +17 -0
- package/core/toolboxConfig.ts +78 -2
- package/expo-module.config.json +5 -0
- package/ios/BoundedBody.swift +15 -0
- package/ios/BsvBoundedFetch.podspec +17 -0
- package/ios/BsvBoundedFetchModule.swift +121 -0
- package/package.json +12 -8
- package/ui/bridgeSheet/ContextRelay.tsx +86 -0
- package/ui/bridgeSheet/relayedContexts.ts +21 -0
- 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/ui/PermissionSheet.tsx +534 -158
- package/ui/components/ui/Sheet.tsx +59 -7
- package/ui/components/ui/sheetResumeSignal.ts +19 -0
- 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/exportDatabases.ts +94 -5
- package/ui/hooks/useExportWalletData.ts +37 -24
- package/ui/importDatabases.ts +154 -34
- package/ui/index.ts +4 -0
- 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 +30 -3
- package/ui/screens/WalletHomeScreen.tsx +7 -1
|
@@ -21,9 +21,10 @@ import {
|
|
|
21
21
|
looksLikeDomain
|
|
22
22
|
} from './rules'
|
|
23
23
|
import { verifyProfileCertificate, type ProfileCertJson, type RegistryProfile } from './profileCert'
|
|
24
|
-
import { createRegistryResolver, fetchWithTimeout, type RegistryPin, type RegistryResolver } from './resolver'
|
|
24
|
+
import { createRegistryResolver, fetchWithTimeout, REGISTRY_MAX_BODY_BYTES, type RegistryPin, type RegistryResolver } from './resolver'
|
|
25
25
|
import { createKeyPinStore, type KeyPinStore } from './keyPinStore'
|
|
26
26
|
import { trimTrailingSlashes } from '../../net/trimTrailingSlashes'
|
|
27
|
+
import { createBoundedNativeFetch } from '../../network/boundedFetch'
|
|
27
28
|
|
|
28
29
|
/** Why a handle is not free. The server's `stale` arrives as `cooldown`. */
|
|
29
30
|
export type AvailabilityReason = 'taken' | 'too_similar' | 'reserved' | 'invalid' | 'cooldown'
|
|
@@ -83,12 +84,13 @@ function reasonOf(raw: unknown): AvailabilityReason | null {
|
|
|
83
84
|
|
|
84
85
|
export function createHandleRegistryClient(args: {
|
|
85
86
|
pinned: RegistryPin
|
|
87
|
+
/** Trusted test transport; production must retain the native byte ceiling. */
|
|
86
88
|
fetchImpl?: typeof fetch
|
|
87
89
|
now?: () => number
|
|
88
90
|
resolver?: RegistryResolver
|
|
89
91
|
pinStore?: KeyPinStore
|
|
90
92
|
}): HandleRegistryClient {
|
|
91
|
-
const fetchImpl = args.fetchImpl ?? (
|
|
93
|
+
const fetchImpl = args.fetchImpl ?? createBoundedNativeFetch(REGISTRY_MAX_BODY_BYTES)
|
|
92
94
|
const now = args.now ?? (() => Date.now())
|
|
93
95
|
const domain = args.pinned.domain.trim().toLowerCase()
|
|
94
96
|
const origin = trimTrailingSlashes(args.pinned.url.trim())
|
|
@@ -14,6 +14,7 @@
|
|
|
14
14
|
import { BRFC_LOOKUP, BRFC_REVERSE_LOOKUP, looksLikeDomain } from './rules'
|
|
15
15
|
import { isPublicHttpsUrl } from '../../net/publicDestination'
|
|
16
16
|
import { trimTrailingSlashes } from '../../net/trimTrailingSlashes'
|
|
17
|
+
import { createBoundedNativeFetch } from '../../network/boundedFetch'
|
|
17
18
|
|
|
18
19
|
/** The domain this build's own handles live under, and the host serving it. */
|
|
19
20
|
export interface RegistryPin {
|
|
@@ -52,16 +53,10 @@ const NOERROR = 0
|
|
|
52
53
|
const NXDOMAIN = 3
|
|
53
54
|
|
|
54
55
|
/**
|
|
55
|
-
*
|
|
56
|
-
*
|
|
57
|
-
*
|
|
58
|
-
*
|
|
59
|
-
* total crosses the cap — an untrusted host cannot make this allocate more
|
|
60
|
-
* than the cap regardless of what it claims or how it paces the bytes
|
|
61
|
-
* (XR-077 / SEC2-027). `fallback` (the original, unbounded `response.json`)
|
|
62
|
-
* is used only when the runtime gives no stream to count from at all, which
|
|
63
|
-
* this feature's own test doubles do — a floor, not a firewall, on a runtime
|
|
64
|
-
* where nothing better is available.
|
|
56
|
+
* Decode a response already receive-bounded by the production native transport.
|
|
57
|
+
* The streaming check also bounds trusted injected test transports. On native
|
|
58
|
+
* Response implementations without a WHATWG stream, the original JSON reader
|
|
59
|
+
* is safe because accumulation was capped before the Response was returned.
|
|
65
60
|
*/
|
|
66
61
|
async function readBoundedJson(res: Response, fallback: () => Promise<unknown>, url: string): Promise<unknown> {
|
|
67
62
|
const declared = res.headers?.get?.('content-length')
|
|
@@ -209,11 +204,12 @@ function templateOf(value: unknown, placeholder: string): string | null {
|
|
|
209
204
|
|
|
210
205
|
export function createRegistryResolver(args: {
|
|
211
206
|
pinned?: RegistryPin
|
|
207
|
+
/** Trusted test transport; production must retain the native byte ceiling. */
|
|
212
208
|
fetchImpl?: typeof fetch
|
|
213
209
|
now?: () => number
|
|
214
210
|
dohEndpoints?: readonly string[]
|
|
215
211
|
}): RegistryResolver {
|
|
216
|
-
const fetchImpl = args.fetchImpl ?? (
|
|
212
|
+
const fetchImpl = args.fetchImpl ?? createBoundedNativeFetch(REGISTRY_MAX_BODY_BYTES)
|
|
217
213
|
const now = args.now ?? (() => Date.now())
|
|
218
214
|
const dohEndpoints = args.dohEndpoints ?? DOH_ENDPOINTS
|
|
219
215
|
const pinnedDomain = args.pinned?.domain.trim().toLowerCase() ?? ''
|
package/core/index.ts
CHANGED
|
@@ -68,6 +68,7 @@ export {
|
|
|
68
68
|
isVaultAvailable,
|
|
69
69
|
resetToolboxConfig
|
|
70
70
|
} from './toolboxConfig'
|
|
71
|
+
export { isE2eBuild, getE2eBroadcasterUrl, e2eSafeChain } from './e2e/mode'
|
|
71
72
|
export type {
|
|
72
73
|
ToolboxConfig,
|
|
73
74
|
ToolboxServiceConfig,
|
|
@@ -132,6 +133,8 @@ export * from './directpay/deviceStore'
|
|
|
132
133
|
export * from './directpay/receive'
|
|
133
134
|
export * from './directpay/DirectPayManager'
|
|
134
135
|
export * from './directpay/DirectPayProvider'
|
|
136
|
+
// The browser bridge's public API (BRC-185 core): see './bridge/index'.
|
|
137
|
+
export * from './bridge'
|
|
135
138
|
export * from './peerpay/outbox'
|
|
136
139
|
export * from './peerpay/control'
|
|
137
140
|
export * from './peerpay/handleResendRequests'
|
|
@@ -249,6 +252,19 @@ export { processOfflineActions } from './storage/methods/processOfflineActions'
|
|
|
249
252
|
export { colorHeldTxids, txHasColorOutput } from './mandala/colorGuard'
|
|
250
253
|
export * from './storage/skipQueuedAncestors'
|
|
251
254
|
export { prepareSqliteImageForDeserialize } from './storage/dbImage'
|
|
255
|
+
export {
|
|
256
|
+
encryptDbImage,
|
|
257
|
+
decryptDbImage,
|
|
258
|
+
isEncryptedDbImage,
|
|
259
|
+
EncryptedDbError,
|
|
260
|
+
ENCRYPTED_DB_EXTENSION,
|
|
261
|
+
DB_EXPORT_PROTOCOL,
|
|
262
|
+
type DbExportWallet,
|
|
263
|
+
type EncryptedDbErrorCode,
|
|
264
|
+
type EncryptedDbOptions,
|
|
265
|
+
type ByteSource,
|
|
266
|
+
type ByteSink
|
|
267
|
+
} from './storage/encryptedDbImage'
|
|
252
268
|
|
|
253
269
|
// Local secrets storage
|
|
254
270
|
export {
|
|
@@ -290,6 +306,7 @@ export * from './pay/userError'
|
|
|
290
306
|
export * from './pay/patp'
|
|
291
307
|
export * from './pay/counterparty'
|
|
292
308
|
export * from './pay/rails/address'
|
|
309
|
+
export * from './pay/rails/sweep'
|
|
293
310
|
export * from './pay/rails/handle'
|
|
294
311
|
export * from './pay/rails/direct'
|
|
295
312
|
// nearby.ts is a pure re-export barrel over localpay/* (already exported above)
|
package/core/localpay/pending.ts
CHANGED
|
@@ -67,14 +67,48 @@ const descriptionDecoder = new TextDecoder()
|
|
|
67
67
|
/**
|
|
68
68
|
* Truncates on the UTF-8 byte boundary, not the JS string index — slicing by
|
|
69
69
|
* character count alone can still overshoot the byte ceiling for non-ASCII
|
|
70
|
-
* text.
|
|
71
|
-
* U+FFFD
|
|
72
|
-
* is fine here: this is a display fallback, not the payment amount.
|
|
70
|
+
* text. Drop an incomplete trailing scalar: decoding its partial bytes would
|
|
71
|
+
* insert U+FFFD, whose three bytes can exceed the original byte budget.
|
|
73
72
|
*/
|
|
74
73
|
export function truncateUtf8Bytes(s: string, maxBytes: number): string {
|
|
75
74
|
const bytes = descriptionEncoder.encode(s)
|
|
76
75
|
if (bytes.length <= maxBytes) return s
|
|
77
|
-
|
|
76
|
+
let end = Math.max(0, Math.floor(maxBytes))
|
|
77
|
+
while (end > 0 && (bytes[end] & 0xc0) === 0x80) end--
|
|
78
|
+
return descriptionDecoder.decode(bytes.subarray(0, end))
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
/** Repair only exhausted BSV entries affected by the old description truncation. */
|
|
82
|
+
async function repairDescriptionFailures(storage: KVStorage): Promise<void> {
|
|
83
|
+
await withQueueLock(async () => {
|
|
84
|
+
let repaired = false
|
|
85
|
+
const next = (await readAll(storage)).map(p => {
|
|
86
|
+
const reason = p.failureReason ?? ''
|
|
87
|
+
if (
|
|
88
|
+
p.frame.kind !== 'bsv' ||
|
|
89
|
+
!isPendingExhausted(p) ||
|
|
90
|
+
!/description/i.test(reason) ||
|
|
91
|
+
!/2000|byte|length/i.test(reason)
|
|
92
|
+
)
|
|
93
|
+
return p
|
|
94
|
+
const note = p.frame.note?.trim()
|
|
95
|
+
if (!note) return p
|
|
96
|
+
const bytes = descriptionEncoder.encode(note.padEnd(5))
|
|
97
|
+
if (bytes.length <= MAX_INTERNALIZE_DESCRIPTION_BYTES) return p
|
|
98
|
+
const previous = descriptionDecoder.decode(bytes.subarray(0, MAX_INTERNALIZE_DESCRIPTION_BYTES))
|
|
99
|
+
if (descriptionEncoder.encode(previous).length <= MAX_INTERNALIZE_DESCRIPTION_BYTES) return p
|
|
100
|
+
repaired = true
|
|
101
|
+
return {
|
|
102
|
+
...p,
|
|
103
|
+
frame: { ...p.frame, note: truncateUtf8Bytes(note, MAX_INTERNALIZE_DESCRIPTION_BYTES) },
|
|
104
|
+
status: 'pending' as const,
|
|
105
|
+
attempts: 0,
|
|
106
|
+
failureReason: undefined
|
|
107
|
+
}
|
|
108
|
+
})
|
|
109
|
+
// Persist the normalized note so this migration cannot reset retries again.
|
|
110
|
+
if (repaired) await writeAll(storage, next)
|
|
111
|
+
})
|
|
78
112
|
}
|
|
79
113
|
|
|
80
114
|
export interface PendingSummary {
|
|
@@ -595,6 +629,7 @@ export async function processPending(
|
|
|
595
629
|
*/
|
|
596
630
|
acceptToken?: TokenAcceptHook
|
|
597
631
|
): Promise<{ id: string; success: boolean; error?: string }[]> {
|
|
632
|
+
await repairDescriptionFailures(storage)
|
|
598
633
|
const results: { id: string; success: boolean; error?: string }[] = []
|
|
599
634
|
for (const p of await getRetryable(storage)) {
|
|
600
635
|
await updateStatus(storage, p.id, 'processing')
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
import { Utils } from '@bsv/sdk'
|
|
2
|
+
|
|
3
|
+
interface NativeReply {
|
|
4
|
+
status: number
|
|
5
|
+
headers: [string, string][]
|
|
6
|
+
body: string
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
interface BoundedFetchNative {
|
|
10
|
+
request(options: {
|
|
11
|
+
id: string
|
|
12
|
+
url: string
|
|
13
|
+
method: string
|
|
14
|
+
headers: [string, string][]
|
|
15
|
+
body: string | null
|
|
16
|
+
maxBytes: number
|
|
17
|
+
}): Promise<NativeReply>
|
|
18
|
+
cancel(id: string): Promise<void>
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
let nextRequest = 0
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* Fetch-shaped transport with an actual native receive ceiling. Both native
|
|
25
|
+
* implementations count decoded bytes before appending, never stream events
|
|
26
|
+
* to an unbounded JS queue, and return at most maxBytes. Missing or dishonest
|
|
27
|
+
* Content-Length cannot bypass the ceiling. Redirects are returned as 3xx:
|
|
28
|
+
* signed backup credentials must never be forwarded to a different endpoint.
|
|
29
|
+
* There is deliberately no fallback to React Native's buffering global fetch.
|
|
30
|
+
*/
|
|
31
|
+
export function createBoundedNativeFetch(maxBytes: number): typeof fetch {
|
|
32
|
+
if (!Number.isSafeInteger(maxBytes) || maxBytes < 0 || maxBytes > 64 * 1024 * 1024) {
|
|
33
|
+
throw new RangeError('Invalid native response byte ceiling')
|
|
34
|
+
}
|
|
35
|
+
return async (input, init) => {
|
|
36
|
+
const original = typeof Request !== 'undefined' && input instanceof Request ? input : undefined
|
|
37
|
+
const signal = init?.signal ?? original?.signal
|
|
38
|
+
if (signal?.aborted) throw signal.reason ?? new Error('Request aborted')
|
|
39
|
+
// Loading lazily allows tests and unsupported platforms to import the
|
|
40
|
+
// toolbox. A missing native module fails before any network request.
|
|
41
|
+
// eslint-disable-next-line @typescript-eslint/no-require-imports
|
|
42
|
+
const { requireNativeModule } = require('expo-modules-core') as typeof import('expo-modules-core')
|
|
43
|
+
const native = requireNativeModule<BoundedFetchNative>('BsvBoundedFetch')
|
|
44
|
+
const body = init?.body
|
|
45
|
+
let bytes: Uint8Array | undefined
|
|
46
|
+
if (typeof body === 'string') bytes = new TextEncoder().encode(body)
|
|
47
|
+
else if (body instanceof Uint8Array) bytes = body
|
|
48
|
+
else if (body instanceof ArrayBuffer) bytes = new Uint8Array(body)
|
|
49
|
+
else if (typeof Blob !== 'undefined' && body instanceof Blob) bytes = new Uint8Array(await body.arrayBuffer())
|
|
50
|
+
else if (body != null || original?.body != null) throw new TypeError('Unsupported bounded request body')
|
|
51
|
+
if (signal?.aborted) throw signal.reason ?? new Error('Request aborted')
|
|
52
|
+
const id = String(++nextRequest)
|
|
53
|
+
let rejectAborted!: (reason: unknown) => void
|
|
54
|
+
const aborted = new Promise<never>((_resolve, reject) => { rejectAborted = reject })
|
|
55
|
+
const onAbort = () => {
|
|
56
|
+
rejectAborted(signal?.reason ?? new Error('Request aborted'))
|
|
57
|
+
void native.cancel(id).catch(() => {})
|
|
58
|
+
}
|
|
59
|
+
const headers: [string, string][] = []
|
|
60
|
+
new Headers(init?.headers ?? original?.headers).forEach((value, key) => headers.push([key, value]))
|
|
61
|
+
signal?.addEventListener('abort', onAbort)
|
|
62
|
+
try {
|
|
63
|
+
const reply = await Promise.race([
|
|
64
|
+
native.request({
|
|
65
|
+
id,
|
|
66
|
+
url: original?.url ?? String(input),
|
|
67
|
+
method: init?.method ?? original?.method ?? 'GET',
|
|
68
|
+
headers,
|
|
69
|
+
body: bytes ? encodeBody(bytes) : null,
|
|
70
|
+
maxBytes
|
|
71
|
+
}),
|
|
72
|
+
aborted
|
|
73
|
+
])
|
|
74
|
+
// The native receiver has already enforced the cap, before this decoding
|
|
75
|
+
// or any JSON parsing. The Response readers cannot bypass that boundary.
|
|
76
|
+
const responseBody = Uint8Array.from(atob(reply.body), value => value.charCodeAt(0))
|
|
77
|
+
const response = new Response([204, 205, 304].includes(reply.status) ? null : responseBody, {
|
|
78
|
+
status: reply.status,
|
|
79
|
+
headers: reply.headers
|
|
80
|
+
})
|
|
81
|
+
// RN's whatwg-fetch buffer-to-text reader maps bytes as Latin-1. Decode
|
|
82
|
+
// explicitly, through the original byte reader so bodyUsed/one-shot reads
|
|
83
|
+
// still work and binary backup blobs remain byte-exact.
|
|
84
|
+
response.text = async () => new TextDecoder().decode(await response.arrayBuffer())
|
|
85
|
+
response.json = async () => JSON.parse(await response.text())
|
|
86
|
+
return response
|
|
87
|
+
} finally {
|
|
88
|
+
signal?.removeEventListener('abort', onAbort)
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
// Keep SDK number[] conversion bounded for large backup uploads. All complete
|
|
94
|
+
// base64 chunks are multiples of three bytes so concatenation preserves bytes.
|
|
95
|
+
function encodeBody(bytes: Uint8Array): string {
|
|
96
|
+
const chunks: string[] = []
|
|
97
|
+
for (let offset = 0; offset < bytes.length; offset += 24_576) {
|
|
98
|
+
chunks.push(Utils.toBase64(Array.from(bytes.subarray(offset, offset + 24_576))))
|
|
99
|
+
}
|
|
100
|
+
return chunks.join('')
|
|
101
|
+
}
|
package/core/networks.ts
CHANGED
|
@@ -52,15 +52,13 @@ export interface NetworkProfile {
|
|
|
52
52
|
* place, but no new wallet can be put on it.
|
|
53
53
|
*/
|
|
54
54
|
available: boolean
|
|
55
|
-
/** Default
|
|
55
|
+
/** Default BSV Broadcaster origin (broadcast, SSE, and `/chaintracks/v1`). */
|
|
56
56
|
arcadeUrl: string
|
|
57
57
|
/** Default MessageBox origin. Each network has its own server. */
|
|
58
58
|
messageBoxUrl: string
|
|
59
59
|
/** Undefined on a network with no WhatsOnChain: address rails, WoC proofs and explorer links are off. */
|
|
60
60
|
woc?: WocEndpoints
|
|
61
|
-
/**
|
|
62
|
-
taalArcUrl?: string
|
|
63
|
-
/** GorillaPool ARC broadcast fallback, where GorillaPool runs one. */
|
|
61
|
+
/** GorillaPool's BSV Broadcaster root (posts to `/tx`), where GorillaPool runs one. */
|
|
64
62
|
gorillaPoolArcUrl?: string
|
|
65
63
|
/** Whether Bitails (the toolbox's built-in provider) serves this network. */
|
|
66
64
|
bitails: boolean
|
|
@@ -80,11 +78,10 @@ export const NETWORKS: Record<AppChain, NetworkProfile> = {
|
|
|
80
78
|
main: {
|
|
81
79
|
available: true,
|
|
82
80
|
walletChain: 'main',
|
|
83
|
-
arcadeUrl: 'https://
|
|
81
|
+
arcadeUrl: 'https://broadcast.bsvblockchain.tech',
|
|
84
82
|
messageBoxUrl: 'https://messagebox.bsvblockchain.tech',
|
|
85
83
|
woc: { apiBase: 'https://api.whatsonchain.com', segment: 'main', explorerBase: 'https://whatsonchain.com' },
|
|
86
|
-
|
|
87
|
-
gorillaPoolArcUrl: 'https://arc.gorillapool.io',
|
|
84
|
+
gorillaPoolArcUrl: 'https://arcade.gorillapool.io',
|
|
88
85
|
bitails: true,
|
|
89
86
|
overlayPreset: 'mainnet',
|
|
90
87
|
push: true
|
|
@@ -92,10 +89,10 @@ export const NETWORKS: Record<AppChain, NetworkProfile> = {
|
|
|
92
89
|
test: {
|
|
93
90
|
available: true,
|
|
94
91
|
walletChain: 'test',
|
|
95
|
-
arcadeUrl: 'https://
|
|
92
|
+
arcadeUrl: 'https://broadcast.bsvblockchain.tech/testnet',
|
|
96
93
|
messageBoxUrl: 'https://messagebox-testnet.bsvblockchain.tech',
|
|
97
94
|
woc: { apiBase: 'https://api.whatsonchain.com', segment: 'test', explorerBase: 'https://test.whatsonchain.com' },
|
|
98
|
-
|
|
95
|
+
gorillaPoolArcUrl: 'https://testnet.arcade.gorillapool.io',
|
|
99
96
|
bitails: true,
|
|
100
97
|
overlayPreset: 'testnet',
|
|
101
98
|
push: false
|
|
@@ -103,7 +100,7 @@ export const NETWORKS: Record<AppChain, NetworkProfile> = {
|
|
|
103
100
|
teratest: {
|
|
104
101
|
available: true,
|
|
105
102
|
walletChain: 'ttn',
|
|
106
|
-
arcadeUrl: 'https://
|
|
103
|
+
arcadeUrl: 'https://broadcast.bsvblockchain.tech/ttn',
|
|
107
104
|
messageBoxUrl: 'https://messagebox-ttn.bsvblockchain.tech',
|
|
108
105
|
woc: {
|
|
109
106
|
apiBase: 'https://api.woc-ttn.bsvblockchain.tech',
|
|
@@ -114,8 +111,9 @@ export const NETWORKS: Record<AppChain, NetworkProfile> = {
|
|
|
114
111
|
overlayPreset: 'teratestnet',
|
|
115
112
|
push: false
|
|
116
113
|
},
|
|
117
|
-
// The scaling teratestnet.
|
|
118
|
-
// no WhatsOnChain, explorer or overlay for it.
|
|
114
|
+
// The scaling teratestnet. BSV Broadcaster, chaintracks and MessageBox only:
|
|
115
|
+
// there is no WhatsOnChain, explorer or overlay for it. The `/tstn`
|
|
116
|
+
// chaintracks now reports `tstn`; `available` stays false.
|
|
119
117
|
//
|
|
120
118
|
// Not available yet. The deployed chain runs Teranode regtest parameters
|
|
121
119
|
// (regtest genesis 0f9188f1…, bits 0x207fffff; its chaintracks reports
|
|
@@ -127,7 +125,7 @@ export const NETWORKS: Record<AppChain, NetworkProfile> = {
|
|
|
127
125
|
scaletest: {
|
|
128
126
|
walletChain: 'regtest',
|
|
129
127
|
available: false,
|
|
130
|
-
arcadeUrl: 'https://
|
|
128
|
+
arcadeUrl: 'https://broadcast.bsvblockchain.tech/tstn',
|
|
131
129
|
messageBoxUrl: 'https://messagebox-tstn.bsvblockchain.tech',
|
|
132
130
|
bitails: false,
|
|
133
131
|
overlayPreset: 'local',
|
|
@@ -18,15 +18,15 @@ import {
|
|
|
18
18
|
Transaction,
|
|
19
19
|
Utils,
|
|
20
20
|
type InternalizeActionArgs,
|
|
21
|
-
type InternalizeOutput
|
|
22
|
-
type WalletProtocol
|
|
21
|
+
type InternalizeOutput
|
|
23
22
|
} from '@bsv/sdk'
|
|
24
23
|
import type { AppChain } from '../../config'
|
|
25
24
|
import { NETWORKS } from '../../networks'
|
|
26
25
|
import { abbreviateKey, addressLabel, FROM_ADDRESS_LABEL_PREFIX, TO_ADDRESS_LABEL_PREFIX } from '../counterparty'
|
|
27
26
|
import { addressNetwork, isValidBsvAddress } from './index'
|
|
28
27
|
|
|
29
|
-
|
|
28
|
+
import { BRC29_PROTOCOL_ID } from '../../peerpay/brc29'
|
|
29
|
+
export { BRC29_PROTOCOL_ID } from '../../peerpay/brc29'
|
|
30
30
|
|
|
31
31
|
/** Whether the address rail can carry a particular payment, and why not when it cannot. */
|
|
32
32
|
export type AddressRailAvailability = { kind: 'available' } | { kind: 'unavailable'; reason: string }
|
|
@@ -181,7 +181,8 @@ export function wocRequestInit(woc: WocConfig): { headers: Record<string, string
|
|
|
181
181
|
return woc.apiKey ? { headers: { 'woc-api-key': woc.apiKey } } : undefined
|
|
182
182
|
}
|
|
183
183
|
|
|
184
|
-
|
|
184
|
+
/** A WhatsOnChain GET that turns a 429 into WocRateLimited. Shared with pay/rails/sweep.ts. */
|
|
185
|
+
export async function wocFetch(woc: WocConfig, url: string): Promise<Response> {
|
|
185
186
|
const init = wocRequestInit(woc)
|
|
186
187
|
const response = init ? await fetch(url, init) : await fetch(url)
|
|
187
188
|
if (response.status === 429) throw new WocRateLimited()
|
package/core/pay/rails/handle.ts
CHANGED
|
@@ -923,6 +923,7 @@ export async function retryDelivery(args: {
|
|
|
923
923
|
entry: OutboxEntry
|
|
924
924
|
}): Promise<void> {
|
|
925
925
|
const { wallet, adminOriginator, client, storage, entry } = args
|
|
926
|
+
if (entry.status !== 'unsent') return
|
|
926
927
|
await updateOutboxEntry(storage, entry.id, { lastAttemptAt: new Date().toISOString() })
|
|
927
928
|
// XR-052: a concurrent UI abandon (cancelOutboxPayment) can remove this same
|
|
928
929
|
// row between awaits — it shares no lock with the background drain beyond
|
|
@@ -931,7 +932,8 @@ export async function retryDelivery(args: {
|
|
|
931
932
|
// (mirrors cancelOutboxPayment's own re-read for its 'undelivered' mode) and
|
|
932
933
|
// stop cleanly if the row is gone, so an in-flight retry cannot still
|
|
933
934
|
// deliver or broadcast a payment the user just cancelled.
|
|
934
|
-
const stillPending = async (): Promise<boolean> =>
|
|
935
|
+
const stillPending = async (): Promise<boolean> =>
|
|
936
|
+
(await getOutboxEntries(storage)).some(e => e.id === entry.id && e.status === 'unsent')
|
|
935
937
|
try {
|
|
936
938
|
if (entry.delivered !== true) {
|
|
937
939
|
if (!(await stillPending())) return
|