@bsv/expo-wallet-toolbox 0.3.1 → 0.5.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.
Files changed (119) hide show
  1. package/CHANGELOG.md +311 -0
  2. package/README.md +52 -1
  3. package/assets/sounds/vault-deposit.wav +0 -0
  4. package/assets/sounds/vault-withdraw.wav +0 -0
  5. package/core/config.tsx +21 -18
  6. package/core/context/VaultContext.tsx +8 -11
  7. package/core/context/WalletConnectionContext.tsx +137 -52
  8. package/core/context/WalletContext.tsx +413 -23
  9. package/core/hooks/useConfirmationSound.ts +14 -8
  10. package/core/i18n/translations.tsx +3368 -952
  11. package/core/index.ts +107 -14
  12. package/core/localpay/build.ts +674 -37
  13. package/core/localpay/codec.ts +68 -5
  14. package/core/localpay/pending.ts +240 -22
  15. package/core/localpay/settlementAck.ts +149 -0
  16. package/core/localpay/types.ts +14 -1
  17. package/core/localpay/verify.ts +118 -69
  18. package/core/mandala/abortGuard.ts +134 -0
  19. package/core/mandala/basketMigration.ts +166 -0
  20. package/core/mandala/bundle.ts +244 -0
  21. package/core/mandala/createRuntime.ts +2437 -0
  22. package/core/mandala/drain.ts +670 -0
  23. package/core/mandala/permissionModule.ts +642 -0
  24. package/core/mandala/resendTransfer.ts +175 -0
  25. package/core/mandala/runtime.ts +357 -0
  26. package/core/mandala/settlementStore.ts +412 -0
  27. package/core/mandala/types.ts +290 -0
  28. package/core/offline/cancelParked.ts +94 -1
  29. package/core/offline/payerHold.ts +152 -12
  30. package/core/offline/tokenFrames.ts +197 -0
  31. package/core/parsePeerPayURI.ts +70 -17
  32. package/core/pay/rails/address.ts +51 -3
  33. package/core/pay/rails/handle.ts +88 -9
  34. package/core/pay/rails/index.ts +16 -6
  35. package/core/pay/rails/nearby.ts +114 -4
  36. package/core/services/capWalletArgs.ts +8 -9
  37. package/core/services/externalOrigin.ts +39 -0
  38. package/core/services/vault/VaultKeyService.ts +912 -251
  39. package/core/services/vault/ceremony.ts +435 -367
  40. package/core/services/vault/ceremonyHost.ts +27 -21
  41. package/core/services/vault/devMock.ts +30 -7
  42. package/core/services/vault/driver.ts +95 -41
  43. package/core/services/vault/guard.ts +514 -56
  44. package/core/services/vault/hardwareLease.ts +22 -0
  45. package/core/services/vault/mockYubiKey.ts +258 -90
  46. package/core/services/vault/pivReset.ts +145 -0
  47. package/core/services/vault/r1comb.ts +976 -0
  48. package/core/services/vault/session.ts +93 -26
  49. package/core/services/vault/transfers.ts +2617 -747
  50. package/core/services/vault/types.ts +100 -43
  51. package/core/services/vault/vaultStore.ts +991 -74
  52. package/core/services/walletConnectionValidation.ts +293 -0
  53. package/core/services/walletServiceConfig.ts +19 -24
  54. package/core/storage/StorageExpoSQLite.ts +382 -56
  55. package/core/storage/dbImage.ts +48 -0
  56. package/core/storage/methods/findSql.ts +0 -54
  57. package/core/storage/methods/listOutputsSql.ts +7 -3
  58. package/core/storage/methods/offlineActions.ts +15 -0
  59. package/core/storage/methods/processOfflineActions.ts +263 -6
  60. package/core/storage/methods/walletBalanceSql.ts +16 -4
  61. package/core/storage/schema/createTables.ts +123 -0
  62. package/core/storage/sqlUpdateValue.ts +24 -0
  63. package/core/toolboxConfig.ts +240 -0
  64. package/core/walletRepair/runWalletCheck.ts +19 -2
  65. package/package.json +25 -24
  66. package/ui/components/QRScanner.tsx +1 -1
  67. package/ui/components/pay/AdmissionNotice.tsx +99 -0
  68. package/ui/components/pay/AssetPicker.tsx +184 -0
  69. package/ui/components/pay/AvailableBalance.tsx +33 -2
  70. package/ui/components/pay/HandleReceive.tsx +213 -50
  71. package/ui/components/pay/NearbyFlow.tsx +616 -69
  72. package/ui/components/pay/PayForm.tsx +73 -8
  73. package/ui/components/pay/PaymentSuccessOverlay.tsx +43 -2
  74. package/ui/components/pay/RecipientField.tsx +49 -4
  75. package/ui/components/pay/RequestHub.tsx +68 -8
  76. package/ui/components/pay/ResultBanner.tsx +41 -4
  77. package/ui/components/pay/UniversalSend.tsx +534 -30
  78. package/ui/components/pay/tokenSendCopy.ts +116 -0
  79. package/ui/components/pay/useRecipientInput.ts +36 -7
  80. package/ui/components/ui/PermissionSheet.tsx +65 -4
  81. package/ui/components/ui/Sheet.tsx +9 -2
  82. package/ui/components/vault/EnrollWizard.tsx +1432 -488
  83. package/ui/components/vault/KeyChooser.tsx +96 -0
  84. package/ui/components/vault/VaultCeremonySheet.tsx +107 -43
  85. package/ui/components/vault/vaultErrorCopy.ts +145 -0
  86. package/ui/components/wallet/ActivityRow.tsx +101 -17
  87. package/ui/components/wallet/AmountInput.tsx +77 -25
  88. package/ui/components/wallet/AssetAmount.tsx +95 -0
  89. package/ui/components/wallet/AssetSwitcherDropdown.tsx +261 -0
  90. package/ui/components/wallet/tokenEviction.ts +65 -0
  91. package/ui/hooks/useExportWalletData.ts +39 -0
  92. package/ui/hooks/useMandala.ts +303 -0
  93. package/ui/hooks/useVaultBalance.ts +105 -7
  94. package/ui/hooks/useVaultCoverage.ts +52 -0
  95. package/ui/importDatabases.ts +7 -3
  96. package/ui/index.ts +50 -7
  97. package/ui/screens/ConnectionsScreen.tsx +46 -29
  98. package/ui/screens/PairScreen.tsx +12 -12
  99. package/ui/screens/PayScreen.tsx +130 -10
  100. package/ui/screens/SettingsScreen.tsx +18 -9
  101. package/ui/screens/VaultScreen.tsx +925 -171
  102. package/ui/screens/VaultTransferScreen.tsx +376 -123
  103. package/ui/screens/WalletCheckScreen.tsx +10 -1
  104. package/ui/screens/WalletConfigScreen.tsx +42 -20
  105. package/ui/screens/WalletHomeScreen.tsx +417 -86
  106. package/ui/screens/homeBadges.ts +9 -1
  107. package/ui/screens/tokenRowTitle.ts +68 -0
  108. package/ui/tokenFormat.ts +108 -0
  109. package/ui/tokenSeen.ts +75 -0
  110. package/ui/tokenStatus.ts +79 -0
  111. package/assets/sounds/vault-close.wav +0 -0
  112. package/assets/sounds/vault-open.wav +0 -0
  113. package/core/services/vault/k1.ts +0 -75
  114. package/core/services/vault/sealing.ts +0 -84
  115. package/core/services/vault/vaultDerivation.ts +0 -152
  116. package/core/services/vault/vaultPassphrase.ts +0 -287
  117. package/ui/components/vault/PassphraseField.tsx +0 -306
  118. package/ui/components/vault/PhraseBackupSheet.tsx +0 -227
  119. package/ui/screens/VaultRecoverScreen.tsx +0 -226
@@ -0,0 +1,293 @@
1
+ import { PublicKey, type WalletProtocol } from '@bsv/sdk'
2
+ import { parseExternalOrigin, type ExternalOrigin } from './externalOrigin'
3
+
4
+ const KB = 1024
5
+ const MB = 1024 * KB
6
+
7
+ /** Pairing QR codes are normally valid for two minutes. A short upper bound
8
+ * prevents a signed QR from becoming a practically permanent bearer token
9
+ * while leaving ample room for clock skew and custom deployments. */
10
+ export const MAX_PAIRING_EXPIRY_HORIZON_SECONDS = 15 * 60
11
+ export const MAX_PAIRING_TOPIC_BYTES = 128
12
+ export const MAX_PAIRING_ORIGIN_BYTES = 2048
13
+ export const MAX_PAIRING_PROTOCOL_BYTES = 512
14
+ export const MAX_PAIRING_SIGNATURE_CHARS = 128
15
+ export const MAX_RELAY_URL_BYTES = 2048
16
+ export const MAX_RELAY_RESPONSE_BYTES = 4 * KB
17
+
18
+ /** The largest encrypted RPC body accepted by the mobile bridge. The normal
19
+ * wallet-relay traffic is orders of magnitude smaller; 5 MiB still admits a
20
+ * one-megabyte AtomicBEEF represented as a JSON number array. */
21
+ export const MAX_RPC_PLAINTEXT_BYTES = 5 * MB
22
+ // @bsv/sdk authenticated encryption adds 48 bytes today. Keep a small explicit
23
+ // allowance so a future compatible envelope does not fail at the boundary.
24
+ export const MAX_RPC_CIPHERTEXT_BYTES = MAX_RPC_PLAINTEXT_BYTES + 256
25
+ export const MAX_RPC_CIPHERTEXT_CHARS = Math.ceil(MAX_RPC_CIPHERTEXT_BYTES * 4 / 3)
26
+ export const MAX_RPC_WIRE_CHARS = MAX_RPC_CIPHERTEXT_CHARS + 1024
27
+ export const MAX_IN_FLIGHT_RPC = 4
28
+
29
+ export interface ConnectParams {
30
+ topic: string
31
+ backendIdentityKey: string
32
+ protocolID: string
33
+ origin: string
34
+ expiry?: string
35
+ sig?: string
36
+ }
37
+
38
+ export interface ValidatedConnectParams {
39
+ params: Required<ConnectParams>
40
+ external: ExternalOrigin
41
+ protocolID: WalletProtocol
42
+ expiry: number
43
+ }
44
+
45
+ export const PAIRING_SIGNATURE_DOMAIN = 'bsv-wallet-pairing-v1'
46
+
47
+ /** Exact transcript signed by the desktop pairing peer. Every field that
48
+ * chooses the transport endpoint or its BRC-42 key namespace is included. */
49
+ export function buildPairingSignatureMessage(
50
+ params: Pick<Required<ConnectParams>, 'topic' | 'backendIdentityKey' | 'protocolID' | 'origin' | 'expiry'>
51
+ ): string {
52
+ return [
53
+ PAIRING_SIGNATURE_DOMAIN,
54
+ params.topic,
55
+ params.backendIdentityKey,
56
+ params.protocolID,
57
+ params.origin,
58
+ params.expiry
59
+ ].join('|')
60
+ }
61
+
62
+ function requireBoundedString(value: unknown, name: string, maxBytes: number, minBytes = 1): string {
63
+ if (typeof value !== 'string') throw new Error(`${name} must be a string`)
64
+ // UTF-8 is never shorter than the UTF-16 code-unit count. This rejects a
65
+ // giant value before TextEncoder would allocate another giant buffer.
66
+ if (value.length > maxBytes) throw new Error(`${name} is too long`)
67
+ const bytes = new TextEncoder().encode(value).length
68
+ if (bytes < minBytes || bytes > maxBytes) throw new Error(`${name} has an invalid length`)
69
+ return value
70
+ }
71
+
72
+ export function parseWalletProtocol(raw: unknown): { raw: string; value: WalletProtocol } {
73
+ const encoded = requireBoundedString(raw, 'protocolID', MAX_PAIRING_PROTOCOL_BYTES)
74
+ let parsed: unknown
75
+ try {
76
+ parsed = JSON.parse(encoded)
77
+ } catch {
78
+ throw new Error('protocolID is not valid JSON')
79
+ }
80
+ if (!Array.isArray(parsed) || parsed.length !== 2 || !Number.isInteger(parsed[0]) ||
81
+ parsed[0] < 0 || parsed[0] > 2 || typeof parsed[1] !== 'string') {
82
+ throw new Error('protocolID must be a valid [security level, protocol name] tuple')
83
+ }
84
+ const name = parsed[1]
85
+ if (name.length < 5 || name.length > 400 || name !== name.trim().toLowerCase() ||
86
+ !/^[a-z0-9 ]+$/.test(name) || name.includes(' ') || name.endsWith(' protocol')) {
87
+ throw new Error('protocolID contains an invalid protocol name')
88
+ }
89
+ const value = [parsed[0], name] as WalletProtocol
90
+ if (JSON.stringify(value) !== encoded) throw new Error('protocolID must use canonical JSON encoding')
91
+ return { raw: encoded, value }
92
+ }
93
+
94
+ export function validateBackendIdentityKey(raw: unknown): string {
95
+ const key = requireBoundedString(raw, 'backendIdentityKey', 66, 66)
96
+ if (!/^(02|03)[0-9a-f]{64}$/.test(key)) {
97
+ throw new Error('Backend identity key must be a canonical compressed secp256k1 public key')
98
+ }
99
+ try {
100
+ if (PublicKey.fromString(key).toString() !== key) throw new Error('non-canonical key')
101
+ } catch {
102
+ throw new Error('Backend identity key is not a valid secp256k1 point')
103
+ }
104
+ return key
105
+ }
106
+
107
+ export function validateMobileIdentityKey(raw: unknown): string {
108
+ try {
109
+ return validateBackendIdentityKey(raw)
110
+ } catch {
111
+ throw new Error('Mobile identity key must be a canonical compressed secp256k1 public key')
112
+ }
113
+ }
114
+
115
+ export function validatePairingTopic(raw: unknown): string {
116
+ const topic = requireBoundedString(raw, 'topic', MAX_PAIRING_TOPIC_BYTES)
117
+ // The signature payload uses `|` separators and the topic is used in URL
118
+ // path/query components. Restrict it to an unambiguous, percent-free token.
119
+ if (!/^[A-Za-z0-9_-]+$/.test(topic)) throw new Error('Pairing topic contains invalid characters')
120
+ return topic
121
+ }
122
+
123
+ export function validateCanonicalExternalOrigin(raw: unknown): ExternalOrigin {
124
+ const origin = requireBoundedString(raw, 'origin', MAX_PAIRING_ORIGIN_BYTES)
125
+ const external = parseExternalOrigin(origin)
126
+ if (external.origin !== origin) throw new Error('Origin must use its canonical HTTPS form')
127
+ return external
128
+ }
129
+
130
+ function validateSignature(raw: unknown): string {
131
+ const sig = requireBoundedString(raw, 'sig', MAX_PAIRING_SIGNATURE_CHARS)
132
+ if (!/^[A-Za-z0-9_-]+$/.test(sig) || sig.length % 4 === 1) {
133
+ throw new Error('Pairing signature is not canonical base64url')
134
+ }
135
+ // A DER ECDSA signature is normally 70-72 bytes. These wider bounds reject
136
+ // empty/truncated and oversized values before the SDK's base64 decoder.
137
+ const decodedBytes = Math.floor(sig.length * 3 / 4)
138
+ if (decodedBytes < 8 || decodedBytes > 80) throw new Error('Pairing signature has an invalid length')
139
+ return sig
140
+ }
141
+
142
+ function validateExpiry(raw: unknown, nowMs: number): { raw: string; value: number } {
143
+ const expiryRaw = requireBoundedString(raw, 'expiry', 11)
144
+ if (!/^[1-9][0-9]{0,10}$/.test(expiryRaw)) throw new Error('Pairing expiry must be canonical Unix seconds')
145
+ const expiry = Number(expiryRaw)
146
+ const nowSeconds = Math.floor(nowMs / 1000)
147
+ if (!Number.isSafeInteger(expiry) || expiry <= nowSeconds) throw new Error('QR code has expired')
148
+ if (expiry > nowSeconds + MAX_PAIRING_EXPIRY_HORIZON_SECONDS) {
149
+ throw new Error('QR code expiry is too far in the future')
150
+ }
151
+ return { raw: expiryRaw, value: expiry }
152
+ }
153
+
154
+ export function validateConnectParams(raw: ConnectParams, nowMs = Date.now()): ValidatedConnectParams {
155
+ if (raw === null || typeof raw !== 'object' || Array.isArray(raw)) {
156
+ throw new Error('Pairing parameters are invalid')
157
+ }
158
+ const topic = validatePairingTopic(raw.topic)
159
+ const backendIdentityKey = validateBackendIdentityKey(raw.backendIdentityKey)
160
+ const protocol = parseWalletProtocol(raw.protocolID)
161
+ const external = validateCanonicalExternalOrigin(raw.origin)
162
+ const origin = external.origin
163
+ const expiry = validateExpiry(raw.expiry, nowMs)
164
+ const sig = validateSignature(raw.sig)
165
+ return {
166
+ params: { topic, backendIdentityKey, protocolID: protocol.raw, origin, expiry: expiry.raw, sig },
167
+ external,
168
+ protocolID: protocol.value,
169
+ expiry: expiry.value
170
+ }
171
+ }
172
+
173
+ export function validateStoredConnectionFields(raw: {
174
+ sessionId: unknown
175
+ backendIdentityKey: unknown
176
+ mobileIdentityKey: unknown
177
+ protocolID: unknown
178
+ origin: unknown
179
+ }): {
180
+ topic: string
181
+ backendIdentityKey: string
182
+ mobileIdentityKey: string
183
+ protocolIDRaw: string
184
+ protocolID: WalletProtocol
185
+ external: ExternalOrigin
186
+ } {
187
+ if (raw === null || typeof raw !== 'object') throw new Error('Stored connection is invalid')
188
+ const topic = validatePairingTopic(raw.sessionId)
189
+ const backendIdentityKey = validateBackendIdentityKey(raw.backendIdentityKey)
190
+ const mobileIdentityKey = validateMobileIdentityKey(raw.mobileIdentityKey)
191
+ const protocol = parseWalletProtocol(raw.protocolID)
192
+ const external = validateCanonicalExternalOrigin(raw.origin)
193
+ return { topic, backendIdentityKey, mobileIdentityKey, protocolIDRaw: protocol.raw, protocolID: protocol.value, external }
194
+ }
195
+
196
+ /** SecureStore data can be corrupted or restored independently of the
197
+ * connection database. Only canonical sequence values that can be incremented
198
+ * safely for the next authenticated message are accepted. */
199
+ export function validateStoredConnectionSequence(raw: unknown): number {
200
+ if (raw === null || raw === undefined) return 0
201
+ if (typeof raw !== 'string' || !/^(0|[1-9][0-9]*)$/.test(raw)) {
202
+ throw new Error('Stored connection sequence is invalid')
203
+ }
204
+ const sequence = Number(raw)
205
+ if (!Number.isSafeInteger(sequence) || sequence < 0 || sequence >= Number.MAX_SAFE_INTEGER) {
206
+ throw new Error('Stored connection sequence is invalid')
207
+ }
208
+ return sequence
209
+ }
210
+
211
+ export function validateRelayUrl(raw: unknown): string {
212
+ const value = requireBoundedString(raw, 'relay URL', MAX_RELAY_URL_BYTES)
213
+ let url: URL
214
+ try {
215
+ url = new URL(value)
216
+ } catch {
217
+ throw new Error('Origin server returned an invalid relay URL')
218
+ }
219
+ if (url.protocol !== 'wss:' || !url.hostname) throw new Error('Relay URL must use wss://')
220
+ if (url.username || url.password) throw new Error('Relay URL must not include credentials')
221
+ if (url.pathname !== '/' || url.search || url.hash) {
222
+ throw new Error('Relay URL must be a bare WSS origin')
223
+ }
224
+ return url.origin
225
+ }
226
+
227
+ export function parseRelayResponse(raw: unknown): string {
228
+ const text = requireBoundedString(raw, 'relay response', MAX_RELAY_RESPONSE_BYTES)
229
+ let data: unknown
230
+ try {
231
+ data = JSON.parse(text)
232
+ } catch {
233
+ throw new Error('Origin server returned invalid relay JSON')
234
+ }
235
+ if (data === null || typeof data !== 'object' || Array.isArray(data) ||
236
+ typeof (data as { relay?: unknown }).relay !== 'string') {
237
+ throw new Error('Origin server did not return a relay URL')
238
+ }
239
+ return validateRelayUrl((data as { relay: string }).relay)
240
+ }
241
+
242
+ export function buildRelayWebSocketUrl(relay: string, topic: string): string {
243
+ const url = new URL('/ws', `${validateRelayUrl(relay)}/`)
244
+ url.searchParams.set('topic', validatePairingTopic(topic))
245
+ url.searchParams.set('role', 'mobile')
246
+ return url.toString()
247
+ }
248
+
249
+ export interface BoundedWireEnvelope {
250
+ topic: string
251
+ ciphertext: string
252
+ mobileIdentityKey?: string
253
+ }
254
+
255
+ export function parseBoundedWireEnvelope(raw: unknown, expectedTopic: string): BoundedWireEnvelope {
256
+ if (typeof raw !== 'string' || raw.length === 0 || raw.length > MAX_RPC_WIRE_CHARS) {
257
+ throw new Error('Wallet relay message exceeds the transport limit')
258
+ }
259
+ let parsed: unknown
260
+ try {
261
+ parsed = JSON.parse(raw)
262
+ } catch {
263
+ throw new Error('Wallet relay message is not valid JSON')
264
+ }
265
+ if (parsed === null || typeof parsed !== 'object' || Array.isArray(parsed)) {
266
+ throw new Error('Wallet relay message is not an object')
267
+ }
268
+ const envelope = parsed as Record<string, unknown>
269
+ for (const key of Object.keys(envelope)) {
270
+ if (key !== 'topic' && key !== 'ciphertext' && key !== 'mobileIdentityKey') {
271
+ throw new Error(`Wallet relay message contains unknown field ${key}`)
272
+ }
273
+ }
274
+ if (envelope.topic !== expectedTopic) throw new Error('Wallet relay message has the wrong topic')
275
+ if (typeof envelope.ciphertext !== 'string' || envelope.ciphertext.length === 0 ||
276
+ envelope.ciphertext.length > MAX_RPC_CIPHERTEXT_CHARS ||
277
+ envelope.ciphertext.length % 4 === 1 ||
278
+ Math.floor(envelope.ciphertext.length * 3 / 4) > MAX_RPC_CIPHERTEXT_BYTES ||
279
+ !/^[A-Za-z0-9_-]+$/.test(envelope.ciphertext)) {
280
+ throw new Error('Wallet relay ciphertext is invalid or too large')
281
+ }
282
+ const mobileIdentityKey = envelope.mobileIdentityKey === undefined
283
+ ? undefined
284
+ : validateMobileIdentityKey(envelope.mobileIdentityKey)
285
+ return { topic: expectedTopic, ciphertext: envelope.ciphertext, mobileIdentityKey }
286
+ }
287
+
288
+ export function requireBoundedPlaintext(plaintext: unknown): number[] {
289
+ if (!Array.isArray(plaintext) || plaintext.length > MAX_RPC_PLAINTEXT_BYTES) {
290
+ throw new Error('Wallet relay plaintext exceeds the transport limit')
291
+ }
292
+ return plaintext
293
+ }
@@ -1,5 +1,6 @@
1
1
  import type { AppChain } from '../config'
2
2
  import { toWalletChain } from '../config'
3
+ import { getServiceConfig } from '../toolboxConfig'
3
4
  import {
4
5
  ChaintracksServiceClient,
5
6
  Services
@@ -18,18 +19,11 @@ import type { ChainTracker } from '@bsv/sdk'
18
19
  * this, rather than each keeping their own copy that could drift.
19
20
  */
20
21
  export function chaintracksUrlFor(network: AppChain): string {
21
- if (network === 'main') {
22
- return process.env?.EXPO_PUBLIC_CHAINTRACKS_URL ?? 'https://arcade-v2-us-1.bsvblockchain.tech/chaintracks/v1'
23
- }
24
- if (network === 'test') {
25
- return (
26
- process.env?.EXPO_PUBLIC_TEST_CHAINTRACKS_URL ??
27
- 'https://arcade-v2-testnet-us-1.bsvblockchain.tech/chaintracks/v1'
28
- )
29
- }
30
- return (
31
- process.env?.EXPO_PUBLIC_TERATEST_CHAINTRACKS_URL ?? 'https://arcade-v2-ttn-us-1.bsvblockchain.tech/chaintracks/v1'
32
- )
22
+ const configured = getServiceConfig(network).chaintracksUrl
23
+ if (configured != null && configured !== '') return configured
24
+ if (network === 'main') return 'https://arcade-v2-us-1.bsvblockchain.tech/chaintracks/v1'
25
+ if (network === 'test') return 'https://arcade-v2-testnet-us-1.bsvblockchain.tech/chaintracks/v1'
26
+ return 'https://arcade-v2-ttn-us-1.bsvblockchain.tech/chaintracks/v1'
33
27
  }
34
28
 
35
29
  /**
@@ -75,6 +69,7 @@ export function createServiceOptions(
75
69
  chaintracksOverride?: ChaintracksClientApi
76
70
  ): WalletServicesOptions {
77
71
  const walletChain = toWalletChain(network)
72
+ const svc = getServiceConfig(network)
78
73
  const base = {
79
74
  chain: walletChain,
80
75
  bsvExchangeRate,
@@ -88,15 +83,15 @@ export function createServiceOptions(
88
83
  if (network === 'main') {
89
84
  return {
90
85
  ...base,
91
- arcUrl: arcUrlOverride ?? process.env?.EXPO_PUBLIC_ARC_URL ?? 'https://arcade-v2-us-1.bsvblockchain.tech',
86
+ arcUrl: arcUrlOverride ?? svc.arcUrl ?? 'https://arcade-v2-us-1.bsvblockchain.tech',
92
87
  arcConfig: {
93
- apiKey: arcApiKeyOverride ?? process.env?.EXPO_PUBLIC_ARC_API_KEY ?? '',
88
+ apiKey: arcApiKeyOverride ?? svc.arcApiKey ?? '',
94
89
  callbackToken
95
90
  },
96
91
  bsvUpdateMsecs: 60 * 60 * 1000,
97
92
  fiatUpdateMsecs: 60 * 60 * 1000,
98
- whatsOnChainApiKey: process.env?.EXPO_PUBLIC_WOC_API_KEY ?? '',
99
- taalApiKey: process.env?.EXPO_PUBLIC_WOC_API_KEY ?? '',
93
+ whatsOnChainApiKey: svc.whatsOnChainApiKey ?? '',
94
+ taalApiKey: svc.taalApiKey ?? svc.whatsOnChainApiKey ?? '',
100
95
  chaintracks: chaintracksOverride ?? new ChaintracksServiceClient(walletChain, chaintracksUrlFor(network))
101
96
  }
102
97
  }
@@ -104,15 +99,15 @@ export function createServiceOptions(
104
99
  if (network === 'test') {
105
100
  return {
106
101
  ...base,
107
- arcUrl: arcUrlOverride ?? process.env?.EXPO_PUBLIC_TEST_ARC_URL ?? 'https://arcade-v2-testnet-us-1.bsvblockchain.tech',
102
+ arcUrl: arcUrlOverride ?? svc.arcUrl ?? 'https://arcade-v2-testnet-us-1.bsvblockchain.tech',
108
103
  arcConfig: {
109
- apiKey: arcApiKeyOverride ?? process.env?.EXPO_PUBLIC_TEST_ARC_API_KEY ?? '',
104
+ apiKey: arcApiKeyOverride ?? svc.arcApiKey ?? '',
110
105
  callbackToken
111
106
  },
112
107
  bsvUpdateMsecs: 60 * 60 * 1000000,
113
108
  fiatUpdateMsecs: 60 * 60 * 1000000,
114
- whatsOnChainApiKey: process.env?.EXPO_PUBLIC_TEST_WOC_API_KEY ?? '',
115
- taalApiKey: process.env?.EXPO_PUBLIC_TEST_TAAL_API_KEY ?? '',
109
+ whatsOnChainApiKey: svc.whatsOnChainApiKey ?? '',
110
+ taalApiKey: svc.taalApiKey ?? svc.whatsOnChainApiKey ?? '',
116
111
  chaintracks: chaintracksOverride ?? new ChaintracksServiceClient(walletChain, chaintracksUrlFor(network))
117
112
  }
118
113
  }
@@ -120,15 +115,15 @@ export function createServiceOptions(
120
115
  // teratest
121
116
  return {
122
117
  ...base,
123
- arcUrl: arcUrlOverride ?? process.env?.EXPO_PUBLIC_TERATEST_ARC_URL ?? 'https://arcade-v2-ttn-us-1.bsvblockchain.tech',
118
+ arcUrl: arcUrlOverride ?? svc.arcUrl ?? 'https://arcade-v2-ttn-us-1.bsvblockchain.tech',
124
119
  arcConfig: {
125
- apiKey: arcApiKeyOverride ?? process.env?.EXPO_PUBLIC_TERATEST_ARC_API_KEY ?? '',
120
+ apiKey: arcApiKeyOverride ?? svc.arcApiKey ?? '',
126
121
  callbackToken
127
122
  },
128
123
  bsvUpdateMsecs: 60 * 60 * 1000000,
129
124
  fiatUpdateMsecs: 60 * 60 * 1000000,
130
- whatsOnChainApiKey: process.env?.EXPO_PUBLIC_TERATEST_WOC_API_KEY ?? '',
131
- taalApiKey: process.env?.EXPO_PUBLIC_TERATEST_WOC_API_KEY ?? '',
125
+ whatsOnChainApiKey: svc.whatsOnChainApiKey ?? '',
126
+ taalApiKey: svc.taalApiKey ?? svc.whatsOnChainApiKey ?? '',
132
127
  chaintracks: chaintracksOverride ?? new ChaintracksServiceClient(walletChain, chaintracksUrlFor(network))
133
128
  }
134
129
  }