@bsv/expo-wallet-toolbox 0.5.0 → 0.7.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 +255 -0
- package/README.md +19 -0
- package/core/amountFormatHelpers.ts +238 -34
- package/core/backup/RemoteSyncReader.ts +2 -5
- package/core/backup/codec.ts +2 -2
- package/core/backup/push.ts +1 -1
- package/core/config.tsx +12 -5
- package/core/contacts/contactActivity.ts +153 -0
- package/core/contacts/contactCache.ts +41 -0
- package/core/contacts/contactsStore.ts +183 -0
- package/core/context/WalletContext.tsx +55 -10
- package/core/demo/demoAssets.ts +60 -0
- package/core/demo/demoLedger.ts +240 -0
- package/core/demo/demoMandalaRuntime.ts +96 -0
- package/core/demo/demoMode.ts +38 -0
- package/core/demo/demoWallet.ts +25 -0
- package/core/demo/index.ts +26 -0
- package/core/demo/useDemo.ts +59 -0
- package/core/headers/OfflineFirstChaintracks.ts +52 -14
- package/core/headers/headerStore.ts +7 -10
- package/core/i18n/translations.tsx +1234 -74
- package/core/identity/contactLink.ts +36 -0
- package/core/identity/handleRegistry/client.ts +285 -0
- package/core/identity/handleRegistry/profileCert.ts +254 -0
- package/core/identity/handleRegistry/registration.ts +559 -0
- package/core/identity/handleRegistry/resolver.ts +247 -0
- package/core/identity/handleRegistry/rules.ts +104 -0
- package/core/index.ts +20 -2
- package/core/localpay/pendingAborts.ts +5 -1
- package/core/monitor/MonitorSupervisor.ts +121 -0
- package/core/monitor/TaskBackupPush.ts +1 -1
- package/core/monitor/TaskCreditInbox.ts +1 -1
- package/core/monitor/TaskDrainOutbox.ts +1 -1
- package/core/monitor/TaskSendOffline.ts +1 -1
- package/core/net/online.ts +49 -0
- package/core/numberFormat.ts +19 -0
- package/core/offline/plan.ts +1 -1
- package/core/pay/recordProof.ts +2 -6
- package/core/services/arcadeBroadcastProvider.ts +1 -4
- package/core/services/exchangeRate.ts +1 -1
- package/core/services/externalOrigin.ts +5 -2
- package/core/services/vault/transfers.ts +2 -2
- package/core/services/walletServiceConfig.ts +31 -20
- package/core/storage/StorageExpoSQLite.ts +41 -34
- package/core/storage/methods/findSql.ts +3 -0
- package/core/storage/methods/listActionsSql.ts +8 -5
- package/core/storage/methods/listOutputsSql.ts +2 -2
- package/core/storage/methods/processOfflineActions.ts +2 -3
- package/core/storage/methods/reviewStatusSql.ts +7 -2
- package/core/storage/schema/createTables.ts +29 -0
- package/core/toolboxConfig.ts +70 -0
- package/core/toolboxTypes.ts +40 -0
- package/core/userAvatar.ts +79 -0
- package/core/walletMonitor.ts +8 -3
- package/package.json +7 -7
- package/ui/activityFilter.ts +115 -0
- package/ui/components/pay/PaymentSuccessOverlay.tsx +46 -6
- package/ui/components/pay/RecipientField.tsx +84 -70
- package/ui/components/pay/StepBar.tsx +32 -0
- package/ui/components/pay/UniversalSend.tsx +677 -149
- package/ui/components/ui/PencilEditField.tsx +109 -0
- package/ui/components/ui/SlideOverFromRight.tsx +86 -0
- package/ui/components/wallet/ActivityRow.tsx +222 -120
- package/ui/components/wallet/AmountInput.tsx +18 -6
- package/ui/components/wallet/ContactActivityList.tsx +149 -0
- package/ui/components/wallet/ContactSigil.tsx +49 -0
- package/ui/components/wallet/EditPictureSheet.tsx +99 -0
- package/ui/components/wallet/FitAmount.tsx +148 -0
- package/ui/components/wallet/IconPickerSheet.tsx +168 -0
- package/ui/components/wallet/IdentifierRow.tsx +69 -0
- package/ui/components/wallet/ImportFromBackupPrompt.tsx +35 -13
- package/ui/components/wallet/ProfileButton.tsx +62 -0
- package/ui/components/wallet/UserAvatar.tsx +85 -0
- package/ui/components/wallet/avatarIcons.ts +122 -0
- package/ui/hooks/useContactsStore.ts +10 -0
- package/ui/hooks/useMandala.ts +18 -1
- package/ui/hooks/useOnline.ts +65 -20
- package/ui/index.ts +26 -1
- package/ui/screens/ContactScreen.tsx +289 -0
- package/ui/screens/ContactsScreen.tsx +373 -0
- package/ui/screens/IdentifierScreen.tsx +234 -0
- package/ui/screens/NewContactScreen.tsx +362 -0
- package/ui/screens/PayScreen.tsx +20 -7
- package/ui/screens/ProfileScreen.tsx +783 -0
- package/ui/screens/TransactionDetailScreen.tsx +419 -0
- package/ui/screens/TrustScreen.tsx +1 -1
- package/ui/screens/WalletConfigScreen.tsx +42 -0
- package/ui/screens/WalletHomeScreen.tsx +528 -83
- package/ui/tokenStatus.ts +21 -0
- package/ui/txStatus.ts +43 -5
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A `MandalaRuntime` backed entirely by the demo ledger.
|
|
3
|
+
*
|
|
4
|
+
* DEV-ONLY. Implements the members the UI actually reads or calls; everything
|
|
5
|
+
* else on the interface is drain/settlement machinery that has nothing to
|
|
6
|
+
* drain here, so it answers "nothing happened" rather than throwing — a demo
|
|
7
|
+
* must never crash on a background tick.
|
|
8
|
+
*
|
|
9
|
+
* `endpoints` deliberately carries the `.invalid` demo overlay rather than the
|
|
10
|
+
* configured one: if any code path ever did try to settle one of these rows,
|
|
11
|
+
* it must fail to resolve rather than reach a real issuer.
|
|
12
|
+
*/
|
|
13
|
+
import type { MandalaRuntime, TokenAssetInfo, TokenAssetStatus, TokenBalance } from '../mandala/runtime'
|
|
14
|
+
import { DEMO_ASSETS, DEMO_USD } from './demoAssets'
|
|
15
|
+
import {
|
|
16
|
+
demoSendToken,
|
|
17
|
+
demoTokenActivity,
|
|
18
|
+
demoTokenBaseUnits,
|
|
19
|
+
demoUnsettledBaseUnits,
|
|
20
|
+
subscribeDemoLedger
|
|
21
|
+
} from './demoLedger'
|
|
22
|
+
|
|
23
|
+
function statusFor(): TokenAssetStatus {
|
|
24
|
+
return {
|
|
25
|
+
paused: false,
|
|
26
|
+
frozenBaseUnits: 0,
|
|
27
|
+
selfAdmitted: true,
|
|
28
|
+
recipientAdmitted: async () => true,
|
|
29
|
+
metadataResolved: true,
|
|
30
|
+
messageBoxUrl: 'https://messagebox.demo.invalid'
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
function balanceFor(asset: TokenAssetInfo): TokenBalance {
|
|
35
|
+
return {
|
|
36
|
+
asset,
|
|
37
|
+
baseUnits: demoTokenBaseUnits(asset.assetId),
|
|
38
|
+
unsettledBaseUnits: demoUnsettledBaseUnits(asset.assetId)
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
export function createDemoMandalaRuntime(): MandalaRuntime {
|
|
43
|
+
const runtime = {
|
|
44
|
+
available: true,
|
|
45
|
+
endpoints: {
|
|
46
|
+
overlayUrl: DEMO_USD.overlayUrl,
|
|
47
|
+
overlayIdentityKey: DEMO_USD.overlayIdentityKey,
|
|
48
|
+
messageBoxUrl: 'https://messagebox.demo.invalid'
|
|
49
|
+
},
|
|
50
|
+
store: {} as MandalaRuntime['store'],
|
|
51
|
+
|
|
52
|
+
// ── what the UI reads ───────────────────────────────────────────
|
|
53
|
+
listAssets: async () => DEMO_ASSETS,
|
|
54
|
+
balances: async () => DEMO_ASSETS.map(balanceFor),
|
|
55
|
+
activity: async (limit?: number) => demoTokenActivity(limit),
|
|
56
|
+
stuck: async () => [],
|
|
57
|
+
assetStatus: async () => statusFor(),
|
|
58
|
+
refreshAssetStatus: async () => statusFor(),
|
|
59
|
+
recipientRefusal: () => null,
|
|
60
|
+
subscribe: subscribeDemoLedger,
|
|
61
|
+
|
|
62
|
+
// ── what the UI calls ───────────────────────────────────────────
|
|
63
|
+
sendToHandle: async (args: { assetId: string; recipientIdentityKey: string; baseUnits: number }) => {
|
|
64
|
+
const row = demoSendToken(args.assetId, args.baseUnits, args.recipientIdentityKey)
|
|
65
|
+
if (!row) {
|
|
66
|
+
return {
|
|
67
|
+
kind: 'refused' as const,
|
|
68
|
+
code: 'ERR_INSUFFICIENT_FUNDS',
|
|
69
|
+
message: 'Not enough balance in demo mode.'
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
return { kind: 'sent' as const, txid: row.txid, settled: true, notified: true }
|
|
73
|
+
},
|
|
74
|
+
receiveFromInbox: async () => ({ credited: 0, failed: 0 }),
|
|
75
|
+
settleNow: async () => 'broadcast' as const,
|
|
76
|
+
cover: async () => ({ ok: true, mustSubmit: [] }),
|
|
77
|
+
|
|
78
|
+
// ── machinery with nothing to do ────────────────────────────────
|
|
79
|
+
drainNow: async () => {},
|
|
80
|
+
settlePendingSends: async () => 0,
|
|
81
|
+
ensureAdmissionsForHoldings: async () => 0,
|
|
82
|
+
reconcileJournals: async () => {},
|
|
83
|
+
recoverStaleAdmissions: async () => 0,
|
|
84
|
+
repairAdmittedAborted: async () => 0,
|
|
85
|
+
pruneBlindingReservations: async () => 0,
|
|
86
|
+
reviewTokenHoldings: async () => ({ settled: 0, removed: 0, unattested: 0, unreachable: false }),
|
|
87
|
+
resendTransfer: async () => ({ kind: 'unavailable', message: 'Demo mode' })
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
// The remaining members are injection points for machinery demo mode never
|
|
91
|
+
// starts (the drain, the nearby build, the frame verifier, the pending
|
|
92
|
+
// queue). Casting rather than stubbing each one keeps this file honest about
|
|
93
|
+
// the fact that nothing here is a real settlement path — the same approach
|
|
94
|
+
// `__tests__/__mocks__/fakeMandalaRuntime.ts` takes.
|
|
95
|
+
return runtime as unknown as MandalaRuntime
|
|
96
|
+
}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The demo-mode switch, and the only thing outside this folder that decides
|
|
3
|
+
* whether any of it is live.
|
|
4
|
+
*
|
|
5
|
+
* DEV-ONLY, enforced twice over: `setDemoModeEnabled` refuses to latch on in a
|
|
6
|
+
* release bundle even if a release caller reaches it directly, and every call
|
|
7
|
+
* site behind it is itself wrapped in `__DEV__` so this module is never
|
|
8
|
+
* required into a production bundle at all. Same belt-and-braces shape as
|
|
9
|
+
* `core/services/vault/devMock.ts`.
|
|
10
|
+
*
|
|
11
|
+
* Deliberately NOT persisted. Demo mode is something you switch on to show
|
|
12
|
+
* someone the app and switch off again; a flag that survived a restart is a
|
|
13
|
+
* flag that is eventually on when nobody meant it to be.
|
|
14
|
+
*/
|
|
15
|
+
const listeners = new Set<() => void>()
|
|
16
|
+
let enabled = false
|
|
17
|
+
|
|
18
|
+
export function isDemoModeEnabled(): boolean {
|
|
19
|
+
return __DEV__ && enabled
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export function setDemoModeEnabled(on: boolean): void {
|
|
23
|
+
// A release caller can never turn this on, whatever it passes.
|
|
24
|
+
if (!__DEV__) {
|
|
25
|
+
enabled = false
|
|
26
|
+
return
|
|
27
|
+
}
|
|
28
|
+
if (enabled === on) return
|
|
29
|
+
enabled = on
|
|
30
|
+
listeners.forEach(l => l())
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export function subscribeDemoMode(listener: () => void): () => void {
|
|
34
|
+
listeners.add(listener)
|
|
35
|
+
return () => {
|
|
36
|
+
listeners.delete(listener)
|
|
37
|
+
}
|
|
38
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The BSV half of demo mode: the two reads `WalletHomeScreen` makes for the
|
|
3
|
+
* balance figure and the activity list, answered from the demo ledger.
|
|
4
|
+
*
|
|
5
|
+
* DEV-ONLY. These are not a `WalletInterface` and deliberately are not one —
|
|
6
|
+
* demo mode substitutes the two READS the home screen performs, not the wallet
|
|
7
|
+
* itself, so no signing, key or storage path can ever be reached through here.
|
|
8
|
+
*/
|
|
9
|
+
import { demoActions, demoSatoshis, demoTotalActions, type DemoAction } from './demoLedger'
|
|
10
|
+
|
|
11
|
+
/** Shape of `permissionsManager.listActions`' result, for the home screen. */
|
|
12
|
+
export interface DemoListActionsResult {
|
|
13
|
+
totalActions: number
|
|
14
|
+
actions: DemoAction[]
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export function demoListActions(args: { limit?: number; offset?: number } = {}): DemoListActionsResult {
|
|
18
|
+
const { limit, offset = 0 } = args
|
|
19
|
+
return { totalActions: demoTotalActions(), actions: demoActions(limit, offset) }
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
/** Spendable satoshis — what `readWalletBalance`/`listOutputs` would total. */
|
|
23
|
+
export function demoWalletBalance(): number {
|
|
24
|
+
return demoSatoshis()
|
|
25
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Demo mode — a wallet full of obviously-fake money, for showing the app.
|
|
3
|
+
*
|
|
4
|
+
* DEV-ONLY, and structured so that it is not merely inert in production but
|
|
5
|
+
* absent from it: every call site requires this barrel from inside a `__DEV__`
|
|
6
|
+
* branch, and `__DEV__` is inlined to `false` at release bundle time, so the
|
|
7
|
+
* whole folder folds out. Same pattern as `utils/AgentationGate.tsx`.
|
|
8
|
+
*
|
|
9
|
+
* Nothing in here touches SQLite, the keychain, an overlay or the network.
|
|
10
|
+
*/
|
|
11
|
+
export { DEMO_ASSETS, DEMO_CHF, DEMO_COUNTERPARTIES, DEMO_USD, demoAssetById } from './demoAssets'
|
|
12
|
+
export {
|
|
13
|
+
demoReceiveBsv,
|
|
14
|
+
demoReceiveToken,
|
|
15
|
+
demoSendBsv,
|
|
16
|
+
demoSendToken,
|
|
17
|
+
demoTokenActivity,
|
|
18
|
+
demoTokenBaseUnits,
|
|
19
|
+
resetDemoLedger,
|
|
20
|
+
subscribeDemoLedger,
|
|
21
|
+
type DemoAction
|
|
22
|
+
} from './demoLedger'
|
|
23
|
+
export { isDemoModeEnabled, setDemoModeEnabled, subscribeDemoMode } from './demoMode'
|
|
24
|
+
export { createDemoMandalaRuntime } from './demoMandalaRuntime'
|
|
25
|
+
export { demoListActions, demoWalletBalance, type DemoListActionsResult } from './demoWallet'
|
|
26
|
+
export { useDemoLedgerVersion, useDemoMandalaRuntime, useDemoMode } from './useDemo'
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* React bindings for demo mode.
|
|
3
|
+
*
|
|
4
|
+
* DEV-ONLY. Kept apart from `demoMode.ts` so that module stays importable from
|
|
5
|
+
* plain (non-React) code, and so the only thing a screen has to reach for is a
|
|
6
|
+
* hook that already re-renders when either the switch or the ledger moves.
|
|
7
|
+
*/
|
|
8
|
+
import { useSyncExternalStore } from 'react'
|
|
9
|
+
import { isDemoModeEnabled, subscribeDemoMode } from './demoMode'
|
|
10
|
+
import { subscribeDemoLedger } from './demoLedger'
|
|
11
|
+
import { createDemoMandalaRuntime } from './demoMandalaRuntime'
|
|
12
|
+
import type { MandalaRuntime } from '../mandala/runtime'
|
|
13
|
+
|
|
14
|
+
/** One runtime for the session: its data is read through the ledger anyway. */
|
|
15
|
+
let runtime: MandalaRuntime | null = null
|
|
16
|
+
function demoRuntime(): MandalaRuntime {
|
|
17
|
+
if (!runtime) runtime = createDemoMandalaRuntime()
|
|
18
|
+
return runtime
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
/** Re-renders on the switch only. */
|
|
22
|
+
export function useDemoMode(): boolean {
|
|
23
|
+
return useSyncExternalStore(subscribeDemoMode, isDemoModeEnabled, () => false)
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* Re-renders on the switch AND on every ledger write, so a screen reading
|
|
28
|
+
* figures straight out of the ledger repaints when a demo payment lands.
|
|
29
|
+
*/
|
|
30
|
+
export function useDemoLedgerVersion(): number {
|
|
31
|
+
return useSyncExternalStore(
|
|
32
|
+
listener => {
|
|
33
|
+
const offMode = subscribeDemoMode(listener)
|
|
34
|
+
const offLedger = subscribeDemoLedger(listener)
|
|
35
|
+
return () => {
|
|
36
|
+
offMode()
|
|
37
|
+
offLedger()
|
|
38
|
+
}
|
|
39
|
+
},
|
|
40
|
+
() => version,
|
|
41
|
+
() => 0
|
|
42
|
+
)
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
// `useSyncExternalStore` compares snapshots by identity, so the ledger needs a
|
|
46
|
+
// changing primitive to report rather than a fresh object each call.
|
|
47
|
+
let version = 0
|
|
48
|
+
subscribeDemoLedger(() => {
|
|
49
|
+
version += 1
|
|
50
|
+
})
|
|
51
|
+
subscribeDemoMode(() => {
|
|
52
|
+
version += 1
|
|
53
|
+
})
|
|
54
|
+
|
|
55
|
+
/** The demo runtime when the switch is on, otherwise null. */
|
|
56
|
+
export function useDemoMandalaRuntime(): MandalaRuntime | null {
|
|
57
|
+
const on = useDemoMode()
|
|
58
|
+
return on ? demoRuntime() : null
|
|
59
|
+
}
|
|
@@ -14,7 +14,7 @@
|
|
|
14
14
|
* whose ancestry we resolved once should verify offline forever after.
|
|
15
15
|
*/
|
|
16
16
|
import { Utils } from '@bsv/sdk'
|
|
17
|
-
import type { ChaintracksClientApi } from '@bsv/wallet-toolbox-mobile
|
|
17
|
+
import type { Chain, ChaintracksClientApi } from '@bsv/wallet-toolbox-mobile'
|
|
18
18
|
import type { HeaderStore } from './headerStore'
|
|
19
19
|
|
|
20
20
|
/** A merkle root as display-order hex, whether the source gave us a hex string
|
|
@@ -26,6 +26,9 @@ function rootHex(v: unknown): string {
|
|
|
26
26
|
return typeof v === 'string' ? v : Utils.toHex(Array.from(v as ArrayLike<number>))
|
|
27
27
|
}
|
|
28
28
|
|
|
29
|
+
/** Handed out when the remote cannot subscribe; never reaches the remote. */
|
|
30
|
+
const INERT_SUBSCRIPTION_PREFIX = 'offline-first:inert:'
|
|
31
|
+
|
|
29
32
|
export class OfflineFirstChaintracks implements ChaintracksClientApi {
|
|
30
33
|
private store: HeaderStore | undefined
|
|
31
34
|
/**
|
|
@@ -35,9 +38,16 @@ export class OfflineFirstChaintracks implements ChaintracksClientApi {
|
|
|
35
38
|
*/
|
|
36
39
|
lastMissHeight: number | undefined
|
|
37
40
|
|
|
41
|
+
private inertSubscriptions = 0
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* @param chain The chain the remote serves. When given, `getChain` answers
|
|
45
|
+
* from it instead of asking the network.
|
|
46
|
+
*/
|
|
38
47
|
constructor(
|
|
39
48
|
private readonly remote: ChaintracksClientApi,
|
|
40
|
-
private readonly online: () => Promise<boolean
|
|
49
|
+
private readonly online: () => Promise<boolean>,
|
|
50
|
+
private readonly chain?: Chain
|
|
41
51
|
) {}
|
|
42
52
|
|
|
43
53
|
/** Consume the most recent unresolved height, if any. Kept for tests; classifiers must peek. */
|
|
@@ -124,10 +134,47 @@ export class OfflineFirstChaintracks implements ChaintracksClientApi {
|
|
|
124
134
|
return this.store?.tipHeight ?? 0
|
|
125
135
|
}
|
|
126
136
|
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
137
|
+
/**
|
|
138
|
+
* The remote's own answer. `false` (the HTTP ChaintracksServiceClient) tells
|
|
139
|
+
* the Monitor and other toolbox consumers not to subscribe at all.
|
|
140
|
+
*/
|
|
141
|
+
get supportsReorgEvents(): boolean | undefined {
|
|
142
|
+
return this.remote.supportsReorgEvents
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
// The toolbox Monitor passes this object as `chaintracksWithEvents` and, unless
|
|
146
|
+
// `supportsReorgEvents` is false, calls `getChain` and both subscriptions from
|
|
147
|
+
// every `runOnce` (via `Monitor.ready`) until they succeed. A rejection there
|
|
148
|
+
// stopped the whole task loop in 2.13 and is retried, with a network
|
|
149
|
+
// `getChain`, on every tick since 2.14, so these three answer offline and
|
|
150
|
+
// never reject. TaskReviewProvenTxs remains the reorg audit without live events.
|
|
151
|
+
async getChain(): Promise<Chain> {
|
|
152
|
+
return this.chain ?? (await this.remote.getChain())
|
|
153
|
+
}
|
|
154
|
+
async subscribeHeaders(listener: Parameters<ChaintracksClientApi['subscribeHeaders']>[0]): Promise<string> {
|
|
155
|
+
try {
|
|
156
|
+
return await this.remote.subscribeHeaders(listener)
|
|
157
|
+
} catch (e: any) {
|
|
158
|
+
return this.inertSubscription('headers', e)
|
|
159
|
+
}
|
|
130
160
|
}
|
|
161
|
+
async subscribeReorgs(listener: Parameters<ChaintracksClientApi['subscribeReorgs']>[0]): Promise<string> {
|
|
162
|
+
try {
|
|
163
|
+
return await this.remote.subscribeReorgs(listener)
|
|
164
|
+
} catch (e: any) {
|
|
165
|
+
return this.inertSubscription('reorgs', e)
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
async unsubscribe(subscriptionId: string): Promise<boolean> {
|
|
169
|
+
if (subscriptionId.startsWith(INERT_SUBSCRIPTION_PREFIX)) return true
|
|
170
|
+
return await this.remote.unsubscribe(subscriptionId)
|
|
171
|
+
}
|
|
172
|
+
private inertSubscription(kind: string, e: any): string {
|
|
173
|
+
console.warn(`[OfflineFirstChaintracks] ${kind} subscription unavailable, no live events: ${e?.message ?? e}`)
|
|
174
|
+
return `${INERT_SUBSCRIPTION_PREFIX}${kind}:${++this.inertSubscriptions}`
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
// ── Everything below is pure delegation ───────────────────────────────────
|
|
131
178
|
getInfo() {
|
|
132
179
|
return this.remote.getInfo()
|
|
133
180
|
}
|
|
@@ -164,13 +211,4 @@ export class OfflineFirstChaintracks implements ChaintracksClientApi {
|
|
|
164
211
|
isSynchronized() {
|
|
165
212
|
return this.remote.isSynchronized()
|
|
166
213
|
}
|
|
167
|
-
subscribeHeaders(listener: Parameters<ChaintracksClientApi['subscribeHeaders']>[0]) {
|
|
168
|
-
return this.remote.subscribeHeaders(listener)
|
|
169
|
-
}
|
|
170
|
-
subscribeReorgs(listener: Parameters<ChaintracksClientApi['subscribeReorgs']>[0]) {
|
|
171
|
-
return this.remote.subscribeReorgs(listener)
|
|
172
|
-
}
|
|
173
|
-
unsubscribe(subscriptionId: string) {
|
|
174
|
-
return this.remote.unsubscribe(subscriptionId)
|
|
175
|
-
}
|
|
176
214
|
}
|
|
@@ -20,14 +20,12 @@
|
|
|
20
20
|
* helper checks linkage but not difficulty.
|
|
21
21
|
*/
|
|
22
22
|
import { Utils } from '@bsv/sdk'
|
|
23
|
-
import {
|
|
24
|
-
blockHash,
|
|
25
|
-
deserializeBaseBlockHeader,
|
|
26
|
-
validateHeaderDifficulty
|
|
27
|
-
} from '@bsv/wallet-toolbox-mobile/out/src/services/chaintracker/chaintracks/util/blockHeaderUtilities'
|
|
23
|
+
import { utils as chaintracksUtils } from '@bsv/wallet-toolbox-mobile'
|
|
28
24
|
import type { HeaderCheckpoint } from './checkpoints'
|
|
29
25
|
import type { HeaderFs } from './fs'
|
|
30
26
|
|
|
27
|
+
const { blockHash, deserializeBaseBlockHeader, validateHeaderProofOfWork } = chaintracksUtils
|
|
28
|
+
|
|
31
29
|
const HEADER_BYTES = 80
|
|
32
30
|
const ROOT_BYTES = 32
|
|
33
31
|
|
|
@@ -195,11 +193,10 @@ export class HeaderStore {
|
|
|
195
193
|
}
|
|
196
194
|
const hash = blockHash(header)
|
|
197
195
|
// Throws on failure — a header that does not meet its own target is not a
|
|
198
|
-
// header, and accepting it would let anyone mint merkle roots.
|
|
199
|
-
//
|
|
200
|
-
//
|
|
201
|
-
|
|
202
|
-
validateHeaderDifficulty(hash as unknown as Buffer, parsed.bits)
|
|
196
|
+
// header, and accepting it would let anyone mint merkle roots. Takes the
|
|
197
|
+
// display-order hex hash blockHash returns, validates the compact target
|
|
198
|
+
// encoding, and honours the toolbox's consensus proof-of-work exceptions.
|
|
199
|
+
validateHeaderProofOfWork({ ...parsed, height: firstHeight + i, hash })
|
|
203
200
|
newRoots.set(new Uint8Array(Utils.toArray(parsed.merkleRoot, 'hex')), i * ROOT_BYTES)
|
|
204
201
|
prev = hash
|
|
205
202
|
}
|