@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
package/core/offline/plan.ts
CHANGED
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
*/
|
|
10
10
|
import { dependencyOrder, descendantsOf, releaseOrder, type OrderableTx } from './order'
|
|
11
11
|
import type { OfflineActionRow } from '../storage/methods/offlineActions'
|
|
12
|
-
import type { ProvenTxReqStatus } from '
|
|
12
|
+
import type { ProvenTxReqStatus } from '../toolboxTypes'
|
|
13
13
|
|
|
14
14
|
export type PostOutcome = 'success' | 'serviceError' | 'invalidTx' | 'doubleSpend'
|
|
15
15
|
|
package/core/pay/recordProof.ts
CHANGED
|
@@ -10,12 +10,8 @@
|
|
|
10
10
|
* no req, the proof is written directly: a proven_tx row (the toolbox's own
|
|
11
11
|
* `findOrInsertProvenTx` shape) and the transaction promoted to `completed`.
|
|
12
12
|
*/
|
|
13
|
-
import type {
|
|
14
|
-
|
|
15
|
-
TableProvenTxReq,
|
|
16
|
-
TableTransaction
|
|
17
|
-
} from '@bsv/wallet-toolbox-mobile/out/src/storage/schema/tables'
|
|
18
|
-
import type { UpdateProvenTxReqWithNewProvenTxArgs } from '@bsv/wallet-toolbox-mobile/out/src/sdk/WalletStorage.interfaces'
|
|
13
|
+
import type { TableProvenTx, TableProvenTxReq, TableTransaction } from '@bsv/wallet-toolbox-mobile'
|
|
14
|
+
import type { UpdateProvenTxReqWithNewProvenTxArgs } from '../toolboxTypes'
|
|
19
15
|
|
|
20
16
|
export interface ProofStorage {
|
|
21
17
|
findProvenTxReqs(args: {
|
|
@@ -1,8 +1,5 @@
|
|
|
1
1
|
import { Beef, Transaction, Utils } from '@bsv/sdk'
|
|
2
|
-
import type {
|
|
3
|
-
PostBeefResult,
|
|
4
|
-
PostTxResultForTxid
|
|
5
|
-
} from '@bsv/wallet-toolbox-mobile/out/src/sdk'
|
|
2
|
+
import type { PostBeefResult, PostTxResultForTxid } from '../toolboxTypes'
|
|
6
3
|
|
|
7
4
|
/**
|
|
8
5
|
* ARC intermediate statuses that still mean "accepted for relay".
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import type { BsvExchangeRate } from '@bsv/wallet-toolbox-mobile/out/src/sdk'
|
|
2
1
|
import AsyncStorage from '@react-native-async-storage/async-storage'
|
|
2
|
+
import type { BsvExchangeRate } from '../toolboxTypes'
|
|
3
3
|
|
|
4
4
|
// Shared with context/ExchangeRateContext.tsx so a single cache serves both the
|
|
5
5
|
// fiat-display UI and the wallet-build seed. Same key + same { usdPerBsv } shape.
|
|
@@ -31,8 +31,11 @@ export function parseExternalOrigin(raw: string): ExternalOrigin {
|
|
|
31
31
|
}
|
|
32
32
|
|
|
33
33
|
const originator = url.port ? `${url.hostname.toLowerCase()}:${url.port}` : url.hostname.toLowerCase()
|
|
34
|
-
//
|
|
35
|
-
|
|
34
|
+
// The wallet's own authority lives in the reserved `.invalid` TLD (see
|
|
35
|
+
// ADMIN_ORIGINATOR). No real origin can be served from it, so refuse the
|
|
36
|
+
// whole TLD rather than only the exact label.
|
|
37
|
+
const hostname = url.hostname.toLowerCase().replace(/\.$/, '')
|
|
38
|
+
if (hostname === 'invalid' || hostname.endsWith('.invalid') || originator === ADMIN_ORIGINATOR.toLowerCase()) {
|
|
36
39
|
throw new Error('Origin is reserved for the wallet')
|
|
37
40
|
}
|
|
38
41
|
return { origin: url.origin, originator }
|
|
@@ -43,7 +43,7 @@
|
|
|
43
43
|
import { Beef, Hash, LockingScript, Transaction, UnlockingScript, Utils } from '@bsv/sdk'
|
|
44
44
|
import { isBackupPushEnabled } from '../../backup/preference'
|
|
45
45
|
import { getBackupUrl, isVaultAvailable, isVaultEnabled } from '../../toolboxConfig'
|
|
46
|
-
import {
|
|
46
|
+
import { sdk as toolboxSdk } from '@bsv/wallet-toolbox-mobile'
|
|
47
47
|
import { noteVaultProgress, requestVaultSigner } from './ceremonyHost'
|
|
48
48
|
import {
|
|
49
49
|
R1C_LOCK_LEN,
|
|
@@ -601,7 +601,7 @@ async function scanVaultActions(
|
|
|
601
601
|
await scan(details)
|
|
602
602
|
if (!includeFailed) return
|
|
603
603
|
const ordinaryLabels = Array.isArray(details.labels) ? details.labels.filter(label => typeof label === 'string') : ['vault']
|
|
604
|
-
await scan({ ...details, labels: [specOpFailedActions, ...ordinaryLabels] })
|
|
604
|
+
await scan({ ...details, labels: [toolboxSdk.specOpFailedActions, ...ordinaryLabels] })
|
|
605
605
|
}
|
|
606
606
|
|
|
607
607
|
const actionClaimsVaultSpend = (action: VaultActionRow): boolean => {
|
|
@@ -5,12 +5,9 @@ import {
|
|
|
5
5
|
ChaintracksServiceClient,
|
|
6
6
|
Services
|
|
7
7
|
} from '@bsv/wallet-toolbox-mobile'
|
|
8
|
-
import type {
|
|
9
|
-
BsvExchangeRate,
|
|
10
|
-
WalletServicesOptions
|
|
11
|
-
} from '@bsv/wallet-toolbox-mobile/out/src/sdk'
|
|
12
|
-
import type { ChaintracksClientApi } from '@bsv/wallet-toolbox-mobile/out/src/services/chaintracker/chaintracks/Api/ChaintracksClientApi'
|
|
8
|
+
import type { ChaintracksClientApi } from '@bsv/wallet-toolbox-mobile'
|
|
13
9
|
import type { ChainTracker } from '@bsv/sdk'
|
|
10
|
+
import type { BsvExchangeRate, WalletServicesOptions } from '../toolboxTypes'
|
|
14
11
|
|
|
15
12
|
/**
|
|
16
13
|
* The chaintracks URL for a network — the one place this table is defined.
|
|
@@ -80,14 +77,36 @@ export function createServiceOptions(
|
|
|
80
77
|
}
|
|
81
78
|
}
|
|
82
79
|
|
|
80
|
+
// One resolved Arcade endpoint feeds BOTH option slots. `arcUrl` is the
|
|
81
|
+
// toolbox's generic ARC slot (broadcast fallback, `services.arcTaal`).
|
|
82
|
+
// `arcadeUrl` is what makes `Services` construct its `Arcade` provider —
|
|
83
|
+
// and that provider is the only `getMerklePath` source that can answer for
|
|
84
|
+
// a transaction the moment Arcade sees it mined (GET /v1/tx/{txid} carries
|
|
85
|
+
// the BUMP), and the only thing `TaskArcadeSSE` will subscribe to. Without
|
|
86
|
+
// it every proof lookup went straight to WhatsOnChain/Bitails, and the
|
|
87
|
+
// monitor logged "no arcadeUrl configured; SSE disabled" on every start —
|
|
88
|
+
// a nosend received while online sat unrecognised for 12 h on 2026-09-18
|
|
89
|
+
// while the explorer showed it with 6 confirmations.
|
|
90
|
+
const arcadeUrl =
|
|
91
|
+
arcUrlOverride ??
|
|
92
|
+
svc.arcUrl ??
|
|
93
|
+
(network === 'main'
|
|
94
|
+
? 'https://arcade-v2-us-1.bsvblockchain.tech'
|
|
95
|
+
: network === 'test'
|
|
96
|
+
? 'https://arcade-v2-testnet-us-1.bsvblockchain.tech'
|
|
97
|
+
: 'https://arcade-v2-ttn-us-1.bsvblockchain.tech')
|
|
98
|
+
const arcConfig = {
|
|
99
|
+
apiKey: arcApiKeyOverride ?? svc.arcApiKey ?? '',
|
|
100
|
+
// Must equal the Monitor's callbackToken so Arcade routes this wallet's
|
|
101
|
+
// status events to its SSE subscription (WalletServicesOptions.arcadeConfig).
|
|
102
|
+
callbackToken
|
|
103
|
+
}
|
|
104
|
+
const arcade = { arcUrl: arcadeUrl, arcConfig, arcadeUrl, arcadeConfig: arcConfig }
|
|
105
|
+
|
|
83
106
|
if (network === 'main') {
|
|
84
107
|
return {
|
|
85
108
|
...base,
|
|
86
|
-
|
|
87
|
-
arcConfig: {
|
|
88
|
-
apiKey: arcApiKeyOverride ?? svc.arcApiKey ?? '',
|
|
89
|
-
callbackToken
|
|
90
|
-
},
|
|
109
|
+
...arcade,
|
|
91
110
|
bsvUpdateMsecs: 60 * 60 * 1000,
|
|
92
111
|
fiatUpdateMsecs: 60 * 60 * 1000,
|
|
93
112
|
whatsOnChainApiKey: svc.whatsOnChainApiKey ?? '',
|
|
@@ -99,11 +118,7 @@ export function createServiceOptions(
|
|
|
99
118
|
if (network === 'test') {
|
|
100
119
|
return {
|
|
101
120
|
...base,
|
|
102
|
-
|
|
103
|
-
arcConfig: {
|
|
104
|
-
apiKey: arcApiKeyOverride ?? svc.arcApiKey ?? '',
|
|
105
|
-
callbackToken
|
|
106
|
-
},
|
|
121
|
+
...arcade,
|
|
107
122
|
bsvUpdateMsecs: 60 * 60 * 1000000,
|
|
108
123
|
fiatUpdateMsecs: 60 * 60 * 1000000,
|
|
109
124
|
whatsOnChainApiKey: svc.whatsOnChainApiKey ?? '',
|
|
@@ -115,11 +130,7 @@ export function createServiceOptions(
|
|
|
115
130
|
// teratest
|
|
116
131
|
return {
|
|
117
132
|
...base,
|
|
118
|
-
|
|
119
|
-
arcConfig: {
|
|
120
|
-
apiKey: arcApiKeyOverride ?? svc.arcApiKey ?? '',
|
|
121
|
-
callbackToken
|
|
122
|
-
},
|
|
133
|
+
...arcade,
|
|
123
134
|
bsvUpdateMsecs: 60 * 60 * 1000000,
|
|
124
135
|
fiatUpdateMsecs: 60 * 60 * 1000000,
|
|
125
136
|
whatsOnChainApiKey: svc.whatsOnChainApiKey ?? '',
|
|
@@ -3,6 +3,7 @@ import type { SQLiteDatabase } from 'expo-sqlite'
|
|
|
3
3
|
import { createTables, ensureOfflineActionsColumns } from './schema/createTables'
|
|
4
4
|
import {
|
|
5
5
|
PROVEN_HEIGHTS_SQL,
|
|
6
|
+
PROVEN_HEIGHT_SQL,
|
|
6
7
|
buildFindSql,
|
|
7
8
|
columnsExcluding,
|
|
8
9
|
rangeReadSql,
|
|
@@ -21,38 +22,11 @@ import {
|
|
|
21
22
|
} from './methods/reclaim'
|
|
22
23
|
import { availableDiskBytes, diskPressure } from '../diskSpace'
|
|
23
24
|
import { devLog } from '../logging'
|
|
24
|
-
import { StorageProvider } from '@bsv/wallet-toolbox-mobile'
|
|
25
|
-
import type { StorageProviderOptions } from '@bsv/wallet-toolbox-mobile'
|
|
26
|
-
import type {
|
|
27
|
-
AuthId,
|
|
28
|
-
FindCertificateFieldsArgs,
|
|
29
|
-
FindCertificatesArgs,
|
|
30
|
-
FindCommissionsArgs,
|
|
31
|
-
FindMonitorEventsArgs,
|
|
32
|
-
FindOutputBasketsArgs,
|
|
33
|
-
FindOutputsArgs,
|
|
34
|
-
FindOutputTagsArgs,
|
|
35
|
-
FindOutputTagMapsArgs,
|
|
36
|
-
FindProvenTxReqsArgs,
|
|
37
|
-
FindProvenTxsArgs,
|
|
38
|
-
FindSyncStatesArgs,
|
|
39
|
-
FindTransactionsArgs,
|
|
40
|
-
FindTxLabelsArgs,
|
|
41
|
-
FindTxLabelMapsArgs,
|
|
42
|
-
FindUsersArgs,
|
|
43
|
-
FindForUserSincePagedArgs,
|
|
44
|
-
ProcessSyncChunkResult,
|
|
45
|
-
ProvenOrRawTx,
|
|
46
|
-
PurgeParams,
|
|
47
|
-
PurgeResults,
|
|
48
|
-
RequestSyncChunkArgs,
|
|
49
|
-
StorageProcessActionArgs,
|
|
50
|
-
StorageProcessActionResults,
|
|
51
|
-
SyncChunk,
|
|
52
|
-
TrxToken
|
|
53
|
-
} from '@bsv/wallet-toolbox-mobile/out/src/sdk/WalletStorage.interfaces'
|
|
54
|
-
import type { AdminStatsResult } from '@bsv/wallet-toolbox-mobile/out/src/storage/StorageProvider'
|
|
25
|
+
import { EntityProvenTxReq, StorageProvider } from '@bsv/wallet-toolbox-mobile'
|
|
55
26
|
import type {
|
|
27
|
+
AdminStatsResult,
|
|
28
|
+
PostReqsToNetworkResult,
|
|
29
|
+
StorageProviderOptions,
|
|
56
30
|
TableCertificate,
|
|
57
31
|
TableCertificateField,
|
|
58
32
|
TableCertificateX,
|
|
@@ -70,11 +44,9 @@ import type {
|
|
|
70
44
|
TableTxLabel,
|
|
71
45
|
TableTxLabelMap,
|
|
72
46
|
TableUser
|
|
73
|
-
} from '@bsv/wallet-toolbox-mobile
|
|
47
|
+
} from '@bsv/wallet-toolbox-mobile'
|
|
74
48
|
import type { ListActionsResult, ListOutputsResult, Validation, WalletLoggerInterface } from '@bsv/sdk'
|
|
75
49
|
import { Beef, Transaction } from '@bsv/sdk'
|
|
76
|
-
import { EntityProvenTxReq } from '@bsv/wallet-toolbox-mobile/out/src/storage/schema/entities'
|
|
77
|
-
import type { PostReqsToNetworkResult } from '@bsv/wallet-toolbox-mobile/out/src/storage/methods/attemptToPostReqsToNetwork'
|
|
78
50
|
import { listActionsSql } from './methods/listActionsSql'
|
|
79
51
|
import { listOutputsSql } from './methods/listOutputsSql'
|
|
80
52
|
import { findUnprovenTxidsWithoutReq } from './methods/unprovenWithoutReqSql'
|
|
@@ -95,6 +67,34 @@ import { buildOfflineHoldResult, groupOfflineHolds } from '../offline/hold'
|
|
|
95
67
|
import { getOnline } from '../net/online'
|
|
96
68
|
import { TaskSendOffline } from '../monitor/TaskSendOffline'
|
|
97
69
|
import { isR1CLockingScript } from '../services/vault/guard'
|
|
70
|
+
import type {
|
|
71
|
+
AuthId,
|
|
72
|
+
FindCertificateFieldsArgs,
|
|
73
|
+
FindCertificatesArgs,
|
|
74
|
+
FindCommissionsArgs,
|
|
75
|
+
FindMonitorEventsArgs,
|
|
76
|
+
FindOutputBasketsArgs,
|
|
77
|
+
FindOutputsArgs,
|
|
78
|
+
FindOutputTagsArgs,
|
|
79
|
+
FindOutputTagMapsArgs,
|
|
80
|
+
FindProvenTxReqsArgs,
|
|
81
|
+
FindProvenTxsArgs,
|
|
82
|
+
FindSyncStatesArgs,
|
|
83
|
+
FindTransactionsArgs,
|
|
84
|
+
FindTxLabelsArgs,
|
|
85
|
+
FindTxLabelMapsArgs,
|
|
86
|
+
FindUsersArgs,
|
|
87
|
+
FindForUserSincePagedArgs,
|
|
88
|
+
ProcessSyncChunkResult,
|
|
89
|
+
ProvenOrRawTx,
|
|
90
|
+
PurgeParams,
|
|
91
|
+
PurgeResults,
|
|
92
|
+
RequestSyncChunkArgs,
|
|
93
|
+
StorageProcessActionArgs,
|
|
94
|
+
StorageProcessActionResults,
|
|
95
|
+
SyncChunk,
|
|
96
|
+
TrxToken
|
|
97
|
+
} from '../toolboxTypes'
|
|
98
98
|
|
|
99
99
|
export interface StorageExpoSQLiteOptions extends StorageProviderOptions {
|
|
100
100
|
databaseName?: string
|
|
@@ -1653,6 +1653,13 @@ export class StorageExpoSQLite extends StorageProvider {
|
|
|
1653
1653
|
return map
|
|
1654
1654
|
}
|
|
1655
1655
|
|
|
1656
|
+
/** The block height of a proven transaction, or null while it is unproven. */
|
|
1657
|
+
async getProvenTxHeight(txid: string): Promise<number | null> {
|
|
1658
|
+
if (!this.isAvailable()) await this.makeAvailable()
|
|
1659
|
+
const row = (await this.getDB().getFirstAsync(PROVEN_HEIGHT_SQL, [txid])) as { height?: number } | null
|
|
1660
|
+
return typeof row?.height === 'number' ? row.height : null
|
|
1661
|
+
}
|
|
1662
|
+
|
|
1656
1663
|
async getRawTxOfKnownValidTransaction(
|
|
1657
1664
|
txid?: string,
|
|
1658
1665
|
offset?: number,
|
|
@@ -204,6 +204,9 @@ export function rangeReadSql(table: 'proven_txs' | 'proven_tx_reqs'): string {
|
|
|
204
204
|
*/
|
|
205
205
|
export const PROVEN_HEIGHTS_SQL = 'SELECT txid, height FROM proven_txs'
|
|
206
206
|
|
|
207
|
+
/** One transaction's block height, without reading its rawTx or merklePath. */
|
|
208
|
+
export const PROVEN_HEIGHT_SQL = 'SELECT height FROM proven_txs WHERE txid = ? LIMIT 1'
|
|
209
|
+
|
|
207
210
|
/**
|
|
208
211
|
* The transactions that have reserved the given outpoints, by `reference`.
|
|
209
212
|
*
|
|
@@ -4,11 +4,14 @@
|
|
|
4
4
|
* Handles specOp patterns (noSend actions, failed actions, etc.)
|
|
5
5
|
*/
|
|
6
6
|
import type { ListActionsResult, Validation } from '@bsv/sdk'
|
|
7
|
-
import type { AuthId } from '@bsv/wallet-toolbox-mobile/out/src/sdk/WalletStorage.interfaces'
|
|
8
7
|
import type { StorageExpoSQLite } from '../StorageExpoSQLite'
|
|
9
|
-
import {
|
|
10
|
-
|
|
11
|
-
|
|
8
|
+
import {
|
|
9
|
+
getLabelToSpecOp,
|
|
10
|
+
makeBrc114ActionTimeLabel,
|
|
11
|
+
parseBrc114ActionTimeLabels,
|
|
12
|
+
sdk as toolboxSdk
|
|
13
|
+
} from '@bsv/wallet-toolbox-mobile'
|
|
14
|
+
import type { AuthId } from '../../toolboxTypes'
|
|
12
15
|
|
|
13
16
|
export async function listActionsSql(
|
|
14
17
|
storage: StorageExpoSQLite,
|
|
@@ -32,7 +35,7 @@ export async function listActionsSql(
|
|
|
32
35
|
let specOpLabels: string[] = []
|
|
33
36
|
let labels: string[] = []
|
|
34
37
|
for (const label of ordinaryLabelsPreSpecOp) {
|
|
35
|
-
if (isListActionsSpecOp(label)) {
|
|
38
|
+
if (toolboxSdk.isListActionsSpecOp(label)) {
|
|
36
39
|
specOp = getLabelToSpecOp()[label]
|
|
37
40
|
} else {
|
|
38
41
|
labels.push(label)
|
|
@@ -4,11 +4,11 @@
|
|
|
4
4
|
* Handles specOp patterns (wallet balance, invalid change, etc.)
|
|
5
5
|
*/
|
|
6
6
|
import type { ListOutputsResult, Validation } from '@bsv/sdk'
|
|
7
|
-
import type { AuthId } from '@bsv/wallet-toolbox-mobile/out/src/sdk/WalletStorage.interfaces'
|
|
8
7
|
import type { StorageExpoSQLite } from '../StorageExpoSQLite'
|
|
9
|
-
import { getListOutputsSpecOp } from '@bsv/wallet-toolbox-mobile
|
|
8
|
+
import { getListOutputsSpecOp } from '@bsv/wallet-toolbox-mobile'
|
|
10
9
|
import { devLog, isLoggingEnabled } from '../../logging'
|
|
11
10
|
import { BALANCE_TX_STATUS } from './walletBalanceSql'
|
|
11
|
+
import type { AuthId } from '../../toolboxTypes'
|
|
12
12
|
|
|
13
13
|
export async function listOutputsSql(
|
|
14
14
|
storage: StorageExpoSQLite,
|
|
@@ -18,9 +18,8 @@
|
|
|
18
18
|
* database reads, writes and logging, which is validated on device.
|
|
19
19
|
*/
|
|
20
20
|
import { Beef } from '@bsv/sdk'
|
|
21
|
-
import { attemptToPostReqsToNetwork } from '@bsv/wallet-toolbox-mobile
|
|
22
|
-
import {
|
|
23
|
-
import type { TableProvenTxReq, TableTransaction } from '@bsv/wallet-toolbox-mobile/out/src/storage/schema/tables'
|
|
21
|
+
import { attemptToPostReqsToNetwork, EntityProvenTxReq } from '@bsv/wallet-toolbox-mobile'
|
|
22
|
+
import type { TableProvenTxReq, TableTransaction } from '@bsv/wallet-toolbox-mobile'
|
|
24
23
|
import type { StorageExpoSQLite } from '../StorageExpoSQLite'
|
|
25
24
|
import { findOfflineActions, updateOfflineAction, type OfflineActionRow, type OfflineDb } from './offlineActions'
|
|
26
25
|
import {
|
|
@@ -14,9 +14,14 @@ import { devLog } from '../../logging'
|
|
|
14
14
|
const SAFE_REQ_STATUSES = new Set(['invalid', 'doubleSpend'])
|
|
15
15
|
|
|
16
16
|
export type ReviewStatusDb = {
|
|
17
|
+
// Method shorthand (not arrow-style properties) is intentional: it keeps this
|
|
18
|
+
// structurally assignable from node:sqlite's DatabaseSync, whose statement
|
|
19
|
+
// methods take the narrower SQLInputValue type rather than unknown. Arrow-style
|
|
20
|
+
// properties are checked contravariantly under strictFunctionTypes and reject
|
|
21
|
+
// that narrower parameter type; method shorthand is checked bivariantly.
|
|
17
22
|
prepare(sql: string): {
|
|
18
|
-
all
|
|
19
|
-
run
|
|
23
|
+
all(...params: unknown[]): unknown[]
|
|
24
|
+
run(...params: unknown[]): unknown
|
|
20
25
|
}
|
|
21
26
|
}
|
|
22
27
|
|
|
@@ -361,6 +361,30 @@ export async function createTables(db: SQLiteDatabase): Promise<void> {
|
|
|
361
361
|
CREATE INDEX IF NOT EXISTS idx_offline_actions_txid ON offline_actions(txid);
|
|
362
362
|
`)
|
|
363
363
|
|
|
364
|
+
// Contacts — local, userId-scoped naming of counterparty identity keys.
|
|
365
|
+
// `name` is the user's own label and is never overwritten by a background
|
|
366
|
+
// refresh; `cachedHandle`/`cachedAvatarUrl`/`cachedCertifier` mirror what
|
|
367
|
+
// resolveIdentity last saw and are read-only in the UI. @bsv/sdk's
|
|
368
|
+
// ContactsManager and @bsv/mandala's contactsStore were rejected for v1:
|
|
369
|
+
// each write there is a signed on-chain action.
|
|
370
|
+
await db.execAsync(`
|
|
371
|
+
CREATE TABLE IF NOT EXISTS contacts (
|
|
372
|
+
contactId INTEGER PRIMARY KEY AUTOINCREMENT,
|
|
373
|
+
created_at TEXT NOT NULL,
|
|
374
|
+
updated_at TEXT NOT NULL,
|
|
375
|
+
userId INTEGER NOT NULL,
|
|
376
|
+
identityKey TEXT NOT NULL,
|
|
377
|
+
name TEXT NOT NULL,
|
|
378
|
+
cachedHandle TEXT,
|
|
379
|
+
cachedAvatarUrl TEXT,
|
|
380
|
+
cachedCertifier TEXT,
|
|
381
|
+
source TEXT NOT NULL DEFAULT 'manual',
|
|
382
|
+
FOREIGN KEY (userId) REFERENCES users(userId)
|
|
383
|
+
);
|
|
384
|
+
CREATE UNIQUE INDEX IF NOT EXISTS idx_contacts_unique ON contacts(userId, identityKey);
|
|
385
|
+
CREATE INDEX IF NOT EXISTS idx_contacts_userId ON contacts(userId);
|
|
386
|
+
`)
|
|
387
|
+
|
|
364
388
|
await createMandalaSettlementTables(db)
|
|
365
389
|
}
|
|
366
390
|
|
|
@@ -415,6 +439,11 @@ export async function createMandalaSettlementTables(
|
|
|
415
439
|
// CREATE TABLE IF NOT EXISTS cannot add the column, so the guarded ALTER does.
|
|
416
440
|
await ensureTokenSettlementColumns(db)
|
|
417
441
|
await db.execAsync(`CREATE INDEX IF NOT EXISTS idx_token_settlements_reference ON token_settlements(reference);`)
|
|
442
|
+
// Drives a contact's activity pane (core/contacts/contactActivity.ts):
|
|
443
|
+
// every token transfer with this counterparty, in one indexed lookup.
|
|
444
|
+
await db.execAsync(
|
|
445
|
+
`CREATE INDEX IF NOT EXISTS idx_token_settlements_counterpartyKey ON token_settlements(counterpartyKey);`
|
|
446
|
+
)
|
|
418
447
|
|
|
419
448
|
// Cached mirror of the AdmissionEntry values this device has SEEN. Purely a
|
|
420
449
|
// derivable cache (FIX G) — never a precondition for anything.
|
package/core/toolboxConfig.ts
CHANGED
|
@@ -35,6 +35,14 @@ export interface MandalaEndpointConfig {
|
|
|
35
35
|
messageBoxUrl: string
|
|
36
36
|
}
|
|
37
37
|
|
|
38
|
+
/** The paymail handle registry this build talks to, for one chain. */
|
|
39
|
+
export interface HandleRegistryConfig {
|
|
40
|
+
/** The domain handles live under here, e.g. `deggen.com`. Bare and lowercase. */
|
|
41
|
+
domain: string
|
|
42
|
+
/** Origin of the registry that serves that domain — no path, query or fragment. */
|
|
43
|
+
url: string
|
|
44
|
+
}
|
|
45
|
+
|
|
38
46
|
/**
|
|
39
47
|
* Runtime configuration supplied by the host app.
|
|
40
48
|
*
|
|
@@ -81,6 +89,17 @@ export interface ToolboxConfig {
|
|
|
81
89
|
* testnet deployment.
|
|
82
90
|
*/
|
|
83
91
|
mandala?: Partial<Record<AppChain, MandalaEndpointConfig>>
|
|
92
|
+
/**
|
|
93
|
+
* The paymail handle registry, per chain: the domain this build's handles
|
|
94
|
+
* live under, and the host that serves it. Both together or neither — a
|
|
95
|
+
* domain with no URL is a registry nothing can reach, and a URL with no
|
|
96
|
+
* domain is a host whose certificates nothing can be checked against.
|
|
97
|
+
*
|
|
98
|
+
* There is deliberately no default. A chain with no complete entry shows
|
|
99
|
+
* the existing "not available yet" copy in Profile and adds no registry tier
|
|
100
|
+
* to Pay's recipient search.
|
|
101
|
+
*/
|
|
102
|
+
handleRegistry?: Partial<Record<AppChain, HandleRegistryConfig>>
|
|
84
103
|
/**
|
|
85
104
|
* Release gate for the YubiKey vault (spec §0, D15). Default false: the home
|
|
86
105
|
* button and Settings row are hidden, the vault route shows "Not available
|
|
@@ -95,6 +114,7 @@ interface ResolvedConfig {
|
|
|
95
114
|
backupUrl: string
|
|
96
115
|
services: Partial<Record<AppChain, ToolboxServiceConfig>>
|
|
97
116
|
mandala: Partial<Record<AppChain, MandalaEndpointConfig>>
|
|
117
|
+
handleRegistry: Partial<Record<AppChain, HandleRegistryConfig>>
|
|
98
118
|
vaultEnabled: boolean
|
|
99
119
|
}
|
|
100
120
|
|
|
@@ -140,6 +160,7 @@ export function configureToolbox(config: ToolboxConfig): void {
|
|
|
140
160
|
backupUrl: config.backupUrl == null ? '' : normalizeBackupUrl(config.backupUrl),
|
|
141
161
|
services: config.services ?? {},
|
|
142
162
|
mandala: config.mandala ?? {},
|
|
163
|
+
handleRegistry: config.handleRegistry ?? {},
|
|
143
164
|
vaultEnabled: config.vaultEnabled === true
|
|
144
165
|
}
|
|
145
166
|
}
|
|
@@ -190,6 +211,55 @@ export function getMandalaEndpoints(chain: AppChain): MandalaEndpointConfig | un
|
|
|
190
211
|
return { overlayUrl, overlayIdentityKey, messageBoxUrl }
|
|
191
212
|
}
|
|
192
213
|
|
|
214
|
+
/**
|
|
215
|
+
* The same rule as `DOMAIN_FORMAT` in `identity/handleRegistry/rules.ts`, which
|
|
216
|
+
* backs the `looksLikeDomain` the resolver and `parsePaymail` apply to the same
|
|
217
|
+
* strings. Restated rather than imported so this module stays a leaf and does
|
|
218
|
+
* not depend on a feature directory — change both together, because a domain
|
|
219
|
+
* this accepts and that one rejects is a configured registry nothing resolves.
|
|
220
|
+
*/
|
|
221
|
+
const REGISTRY_DOMAIN = /^[a-z0-9]([a-z0-9-]{0,61}[a-z0-9])?(\.[a-z0-9]([a-z0-9-]{0,61}[a-z0-9])?)+$/
|
|
222
|
+
/**
|
|
223
|
+
* Hosts a development build may reach over plain http: the simulator's own
|
|
224
|
+
* machine, the Android emulator's alias for it, and RFC 1918 space. Everything
|
|
225
|
+
* else must be https — which key owns a handle is precisely what a reader on
|
|
226
|
+
* the path would want to change.
|
|
227
|
+
*/
|
|
228
|
+
const PRIVATE_HOST =
|
|
229
|
+
/^(localhost|127\.0\.0\.1|10\.\d{1,3}\.\d{1,3}\.\d{1,3}|192\.168\.\d{1,3}\.\d{1,3}|172\.(1[6-9]|2\d|3[01])\.\d{1,3}\.\d{1,3})$/
|
|
230
|
+
|
|
231
|
+
/**
|
|
232
|
+
* The handle registry for a chain, or undefined when this build has none.
|
|
233
|
+
*
|
|
234
|
+
* Same fail-closed posture as `getMandalaEndpoints`: never throws, and a
|
|
235
|
+
* partial or malformed entry answers undefined rather than a half-usable
|
|
236
|
+
* object. `10.0.2.2` — the Android emulator's route to its host — falls out of
|
|
237
|
+
* the RFC 1918 branch and needs no case of its own.
|
|
238
|
+
*
|
|
239
|
+
* `url` must be a bare origin, for the reason `normalizeBackupUrl` says it
|
|
240
|
+
* above: every route is built by appending to it (`${url}/api/handle/dee`), so
|
|
241
|
+
* a configured `https://host/?x=1` addresses neither the host's registry nor
|
|
242
|
+
* anything else — exactly the half-usable entry this getter exists to refuse.
|
|
243
|
+
*/
|
|
244
|
+
export function getHandleRegistryConfig(chain: AppChain): HandleRegistryConfig | undefined {
|
|
245
|
+
const entry = current?.handleRegistry[chain]
|
|
246
|
+
if (!entry) return undefined
|
|
247
|
+
const domain = entry.domain?.trim().toLowerCase() ?? ''
|
|
248
|
+
const url = entry.url?.trim().replace(/\/+$/, '') ?? ''
|
|
249
|
+
if (!REGISTRY_DOMAIN.test(domain) || url === '') return undefined
|
|
250
|
+
let parsed: URL
|
|
251
|
+
try {
|
|
252
|
+
parsed = new URL(url)
|
|
253
|
+
} catch {
|
|
254
|
+
return undefined
|
|
255
|
+
}
|
|
256
|
+
if (parsed.search !== '' || parsed.hash !== '') return undefined
|
|
257
|
+
if (parsed.pathname !== '' && parsed.pathname !== '/') return undefined
|
|
258
|
+
if (parsed.protocol === 'https:') return { domain, url }
|
|
259
|
+
if (parsed.protocol === 'http:' && PRIVATE_HOST.test(parsed.hostname)) return { domain, url }
|
|
260
|
+
return undefined
|
|
261
|
+
}
|
|
262
|
+
|
|
193
263
|
/**
|
|
194
264
|
* Whether Mandala stablecoins are available on this network.
|
|
195
265
|
*
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Flat aliases for @bsv/wallet-toolbox-mobile types that the package exports
|
|
3
|
+
* only under its `sdk` namespace. Since 2.13 the toolbox ships as one bundle
|
|
4
|
+
* whose exports map exposes just the package root, so the former
|
|
5
|
+
* `out/src/...` deep imports no longer resolve.
|
|
6
|
+
*/
|
|
7
|
+
import type { sdk } from '@bsv/wallet-toolbox-mobile'
|
|
8
|
+
|
|
9
|
+
export type AuthId = sdk.AuthId
|
|
10
|
+
export type BsvExchangeRate = sdk.BsvExchangeRate
|
|
11
|
+
export type FindCertificateFieldsArgs = sdk.FindCertificateFieldsArgs
|
|
12
|
+
export type FindCertificatesArgs = sdk.FindCertificatesArgs
|
|
13
|
+
export type FindCommissionsArgs = sdk.FindCommissionsArgs
|
|
14
|
+
export type FindForUserSincePagedArgs = sdk.FindForUserSincePagedArgs
|
|
15
|
+
export type FindMonitorEventsArgs = sdk.FindMonitorEventsArgs
|
|
16
|
+
export type FindOutputBasketsArgs = sdk.FindOutputBasketsArgs
|
|
17
|
+
export type FindOutputTagMapsArgs = sdk.FindOutputTagMapsArgs
|
|
18
|
+
export type FindOutputTagsArgs = sdk.FindOutputTagsArgs
|
|
19
|
+
export type FindOutputsArgs = sdk.FindOutputsArgs
|
|
20
|
+
export type FindProvenTxReqsArgs = sdk.FindProvenTxReqsArgs
|
|
21
|
+
export type FindProvenTxsArgs = sdk.FindProvenTxsArgs
|
|
22
|
+
export type FindSyncStatesArgs = sdk.FindSyncStatesArgs
|
|
23
|
+
export type FindTransactionsArgs = sdk.FindTransactionsArgs
|
|
24
|
+
export type FindTxLabelMapsArgs = sdk.FindTxLabelMapsArgs
|
|
25
|
+
export type FindTxLabelsArgs = sdk.FindTxLabelsArgs
|
|
26
|
+
export type FindUsersArgs = sdk.FindUsersArgs
|
|
27
|
+
export type PostBeefResult = sdk.PostBeefResult
|
|
28
|
+
export type PostTxResultForTxid = sdk.PostTxResultForTxid
|
|
29
|
+
export type ProcessSyncChunkResult = sdk.ProcessSyncChunkResult
|
|
30
|
+
export type ProvenOrRawTx = sdk.ProvenOrRawTx
|
|
31
|
+
export type ProvenTxReqStatus = sdk.ProvenTxReqStatus
|
|
32
|
+
export type PurgeParams = sdk.PurgeParams
|
|
33
|
+
export type PurgeResults = sdk.PurgeResults
|
|
34
|
+
export type RequestSyncChunkArgs = sdk.RequestSyncChunkArgs
|
|
35
|
+
export type StorageProcessActionArgs = sdk.StorageProcessActionArgs
|
|
36
|
+
export type StorageProcessActionResults = sdk.StorageProcessActionResults
|
|
37
|
+
export type SyncChunk = sdk.SyncChunk
|
|
38
|
+
export type TrxToken = sdk.TrxToken
|
|
39
|
+
export type UpdateProvenTxReqWithNewProvenTxArgs = sdk.UpdateProvenTxReqWithNewProvenTxArgs
|
|
40
|
+
export type WalletServicesOptions = sdk.WalletServicesOptions
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The picture this wallet's own user wears.
|
|
3
|
+
*
|
|
4
|
+
* One stored choice, read by every surface that draws "you" — the home
|
|
5
|
+
* button, the profile hero — so picking an icon once changes all of them.
|
|
6
|
+
*
|
|
7
|
+
* Kept out of `WalletSettings`: that type belongs to
|
|
8
|
+
* `@bsv/wallet-toolbox-mobile` and is not ours to extend. AsyncStorage
|
|
9
|
+
* instead, loaded once at startup, exactly like `core/numberFormat.ts`.
|
|
10
|
+
*
|
|
11
|
+
* Stored as `family/name` rather than a component so nothing here depends on
|
|
12
|
+
* the icon package, and an unknown value from a newer build degrades to the
|
|
13
|
+
* default disc instead of crashing.
|
|
14
|
+
*/
|
|
15
|
+
import { useSyncExternalStore } from 'react'
|
|
16
|
+
import AsyncStorage from '@react-native-async-storage/async-storage'
|
|
17
|
+
|
|
18
|
+
export type AvatarIconFamily = 'ionicons' | 'material-community'
|
|
19
|
+
|
|
20
|
+
export interface AvatarIcon {
|
|
21
|
+
family: AvatarIconFamily
|
|
22
|
+
name: string
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
const STORAGE_KEY = 'wallet_user_avatar_icon'
|
|
26
|
+
|
|
27
|
+
const listeners = new Set<() => void>()
|
|
28
|
+
let icon: AvatarIcon | null = null
|
|
29
|
+
|
|
30
|
+
/** The chosen icon, or `null` for the default profile disc. */
|
|
31
|
+
export function getUserAvatarIcon(): AvatarIcon | null {
|
|
32
|
+
return icon
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export function setUserAvatarIcon(next: AvatarIcon | null): void {
|
|
36
|
+
if (icon?.family === next?.family && icon?.name === next?.name) return
|
|
37
|
+
icon = next
|
|
38
|
+
listeners.forEach(l => l())
|
|
39
|
+
// Fire-and-forget: the choice is already live in memory, and a failed write
|
|
40
|
+
// costs the next launch's avatar, never the one on screen now.
|
|
41
|
+
if (next) void AsyncStorage.setItem(STORAGE_KEY, `${next.family}/${next.name}`).catch(() => {})
|
|
42
|
+
else void AsyncStorage.removeItem(STORAGE_KEY).catch(() => {})
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
export function subscribeUserAvatar(listener: () => void): () => void {
|
|
46
|
+
listeners.add(listener)
|
|
47
|
+
return () => {
|
|
48
|
+
listeners.delete(listener)
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
function parse(stored: string | null): AvatarIcon | null {
|
|
53
|
+
if (!stored) return null
|
|
54
|
+
const at = stored.indexOf('/')
|
|
55
|
+
if (at < 0) return null
|
|
56
|
+
const family = stored.slice(0, at)
|
|
57
|
+
const name = stored.slice(at + 1)
|
|
58
|
+
if (!name) return null
|
|
59
|
+
if (family !== 'ionicons' && family !== 'material-community') return null
|
|
60
|
+
return { family, name }
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
/** Restore the stored choice. Call once at startup; safe to call twice. */
|
|
64
|
+
export async function loadUserAvatarIcon(): Promise<void> {
|
|
65
|
+
try {
|
|
66
|
+
const next = parse(await AsyncStorage.getItem(STORAGE_KEY))
|
|
67
|
+
if (next && (next.family !== icon?.family || next.name !== icon?.name)) {
|
|
68
|
+
icon = next
|
|
69
|
+
listeners.forEach(l => l())
|
|
70
|
+
}
|
|
71
|
+
} catch {
|
|
72
|
+
// Keep the default disc; an unreadable preference is not worth surfacing.
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
/** Re-renders the caller whenever the choice changes. */
|
|
77
|
+
export function useUserAvatarIcon(): AvatarIcon | null {
|
|
78
|
+
return useSyncExternalStore(subscribeUserAvatar, getUserAvatarIcon, () => null)
|
|
79
|
+
}
|
package/core/walletMonitor.ts
CHANGED
|
@@ -59,9 +59,14 @@ export function createWalletMonitorOptions(
|
|
|
59
59
|
/**
|
|
60
60
|
* Construct a Monitor and await `ready` so `_init` registers
|
|
61
61
|
* `subscribeReorgs` / `subscribeHeaders` on `chaintracksWithEvents`.
|
|
62
|
-
* Subscribe failures must not kill the rest of the task loop
|
|
63
|
-
*
|
|
64
|
-
*
|
|
62
|
+
* Subscribe failures must not kill the rest of the task loop. `Monitor.runOnce`
|
|
63
|
+
* retries `ready` on every pass (best effort since toolbox 2.14; 2.13 let a
|
|
64
|
+
* rejection stop every task), so OfflineFirstChaintracks answers `getChain`
|
|
65
|
+
* locally and degrades an unsupported subscription (the HTTP
|
|
66
|
+
* ChaintracksServiceClient throws "Method not implemented") to an inert one,
|
|
67
|
+
* and `ready` settles once instead of failing and retrying each tick.
|
|
68
|
+
* TaskReviewProvenTxs is the backup audit in that case. The warning below is
|
|
69
|
+
* left for a chaintracks that rejects anyway.
|
|
65
70
|
*/
|
|
66
71
|
export async function createWalletMonitor(
|
|
67
72
|
options: ReturnType<typeof Monitor.createDefaultWalletMonitorOptions>
|