@bsv/expo-wallet-toolbox 0.1.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/LICENSE.txt +28 -0
- package/README.md +512 -0
- package/assets/sounds/payment-receive.wav +0 -0
- package/assets/sounds/payment-send.wav +0 -0
- package/assets/sounds/vault-close.wav +0 -0
- package/assets/sounds/vault-open.wav +0 -0
- package/core/amountFormatHelpers.ts +330 -0
- package/core/backup/RemoteSyncReader.ts +94 -0
- package/core/backup/client.ts +111 -0
- package/core/backup/codec.ts +218 -0
- package/core/backup/constants.ts +88 -0
- package/core/backup/cursor.ts +138 -0
- package/core/backup/derive.ts +46 -0
- package/core/backup/deviceId.ts +33 -0
- package/core/backup/erase.ts +67 -0
- package/core/backup/preference.ts +33 -0
- package/core/backup/push.ts +295 -0
- package/core/backup/restore.ts +152 -0
- package/core/backup/restoreOnImport.ts +119 -0
- package/core/backup/status.ts +46 -0
- package/core/config.tsx +47 -0
- package/core/constants.ts +35 -0
- package/core/context/ExchangeRateContext.tsx +69 -0
- package/core/context/LocalStorageProvider.tsx +225 -0
- package/core/context/UserContext.tsx +129 -0
- package/core/context/VaultContext.tsx +79 -0
- package/core/context/WalletConnectionContext.tsx +454 -0
- package/core/context/WalletContext.tsx +2938 -0
- package/core/context/buildGeneration.ts +37 -0
- package/core/deviceTier.ts +89 -0
- package/core/diskSpace.ts +62 -0
- package/core/displayCurrencies.ts +56 -0
- package/core/headers/OfflineFirstChaintracks.ts +176 -0
- package/core/headers/checkpoints.ts +39 -0
- package/core/headers/fs.ts +119 -0
- package/core/headers/headerStore.ts +333 -0
- package/core/headers/prewarm.ts +36 -0
- package/core/headers/syncHeaders.ts +73 -0
- package/core/hooks/useConfirmationSound.ts +135 -0
- package/core/hooks/useHaptics.ts +51 -0
- package/core/hooks/usePermissionQueue.ts +69 -0
- package/core/i18n/translations.tsx +6692 -0
- package/core/index.ts +295 -0
- package/core/localpay/blePermissions.ts +32 -0
- package/core/localpay/build.ts +392 -0
- package/core/localpay/codec.ts +338 -0
- package/core/localpay/deviceCaps.ts +175 -0
- package/core/localpay/nearbyAdvisory.ts +32 -0
- package/core/localpay/nearbyPermissions.ts +34 -0
- package/core/localpay/pending.ts +385 -0
- package/core/localpay/pendingAborts.ts +67 -0
- package/core/localpay/qr.ts +16 -0
- package/core/localpay/session.ts +277 -0
- package/core/localpay/sessionPolicy.ts +5 -0
- package/core/localpay/transport/awdl.ts +11 -0
- package/core/localpay/transport/ble.ts +159 -0
- package/core/localpay/transport/nearby.ts +12 -0
- package/core/localpay/transport/race.ts +110 -0
- package/core/localpay/transport/select.ts +128 -0
- package/core/localpay/transport/socket.ts +244 -0
- package/core/localpay/types.ts +82 -0
- package/core/localpay/verify.ts +204 -0
- package/core/logging.config.ts +10 -0
- package/core/logging.ts +77 -0
- package/core/mnemonicWallet.ts +180 -0
- package/core/monitor/TaskBackupPush.ts +168 -0
- package/core/monitor/TaskCreditInbox.ts +116 -0
- package/core/monitor/TaskDrainOutbox.ts +122 -0
- package/core/monitor/TaskSendOffline.ts +123 -0
- package/core/monitor/unfailRetry.ts +116 -0
- package/core/net/chainMatch.ts +34 -0
- package/core/net/online.ts +34 -0
- package/core/offline/cancelParked.ts +56 -0
- package/core/offline/hold.ts +127 -0
- package/core/offline/order.ts +109 -0
- package/core/offline/payerHold.ts +144 -0
- package/core/offline/plan.ts +264 -0
- package/core/offline/queueGrace.ts +52 -0
- package/core/parsePeerPayURI.ts +119 -0
- package/core/pay/beefRepair.ts +106 -0
- package/core/pay/creditErrors.ts +46 -0
- package/core/pay/creditInbox.ts +202 -0
- package/core/pay/damagedInbox.ts +64 -0
- package/core/pay/proofNudge.ts +23 -0
- package/core/pay/provenTxFromBump.ts +31 -0
- package/core/pay/rails/address.ts +329 -0
- package/core/pay/rails/handle.ts +617 -0
- package/core/pay/rails/index.ts +197 -0
- package/core/pay/rails/nearby.ts +79 -0
- package/core/pay/receiveFocus.ts +13 -0
- package/core/pay/recordProof.ts +91 -0
- package/core/pay/refreshProofGuard.ts +34 -0
- package/core/pay/sweeper.ts +75 -0
- package/core/pay/tokenAmount.ts +18 -0
- package/core/pay/userError.ts +18 -0
- package/core/pay/watchlist.ts +126 -0
- package/core/peerpay/control.ts +122 -0
- package/core/peerpay/handleResendRequests.ts +475 -0
- package/core/peerpay/inboxAttempts.ts +33 -0
- package/core/peerpay/metadataDecryptor.ts +42 -0
- package/core/peerpay/offlineNacks.ts +96 -0
- package/core/peerpay/outbox.ts +209 -0
- package/core/peerpay/rebuildToken.ts +76 -0
- package/core/peerpay/resendBeef.ts +115 -0
- package/core/services/arcadeBroadcastProvider.ts +214 -0
- package/core/services/capWalletArgs.ts +99 -0
- package/core/services/exchangeRate.ts +63 -0
- package/core/services/secrets/envelope.ts +102 -0
- package/core/services/secrets/hkdf.ts +37 -0
- package/core/services/secrets/index.ts +63 -0
- package/core/services/secrets/kek.ts +274 -0
- package/core/services/secrets/migration.ts +188 -0
- package/core/services/secrets/policy.ts +120 -0
- package/core/services/secrets/storage.ts +54 -0
- package/core/services/secrets/store.ts +125 -0
- package/core/services/secrets/types.ts +85 -0
- package/core/services/usdFxRates.ts +101 -0
- package/core/services/vault/VaultKeyService.ts +312 -0
- package/core/services/vault/backupAttestation.ts +136 -0
- package/core/services/vault/ceremony.ts +972 -0
- package/core/services/vault/ceremonyHost.ts +46 -0
- package/core/services/vault/devMock.ts +22 -0
- package/core/services/vault/driver.ts +197 -0
- package/core/services/vault/guard.ts +90 -0
- package/core/services/vault/k1.ts +75 -0
- package/core/services/vault/mockYubiKey.ts +217 -0
- package/core/services/vault/random.ts +20 -0
- package/core/services/vault/sealing.ts +84 -0
- package/core/services/vault/session.ts +59 -0
- package/core/services/vault/transfers.ts +1151 -0
- package/core/services/vault/types.ts +109 -0
- package/core/services/vault/vaultDerivation.ts +152 -0
- package/core/services/vault/vaultPassphrase.ts +287 -0
- package/core/services/vault/vaultStore.ts +104 -0
- package/core/services/walletArgLimits.ts +234 -0
- package/core/services/walletServiceConfig.ts +170 -0
- package/core/storage/LocalStorageAdapter.ts +58 -0
- package/core/storage/README.md +391 -0
- package/core/storage/StorageExpoSQLite.ts +2008 -0
- package/core/storage/errors.ts +73 -0
- package/core/storage/index.ts +3 -0
- package/core/storage/methods/findSql.ts +286 -0
- package/core/storage/methods/historyNotes.ts +61 -0
- package/core/storage/methods/listActionsSql.ts +212 -0
- package/core/storage/methods/listOutputsSql.ts +211 -0
- package/core/storage/methods/offlineActions.ts +156 -0
- package/core/storage/methods/processOfflineActions.ts +503 -0
- package/core/storage/methods/reclaim.ts +135 -0
- package/core/storage/methods/reviewStatusSql.ts +167 -0
- package/core/storage/methods/unprovenWithoutReqSql.ts +26 -0
- package/core/storage/methods/walletBalanceSql.ts +55 -0
- package/core/storage/schema/createTables.ts +385 -0
- package/core/storage/skipQueuedAncestors.ts +29 -0
- package/core/storage/sqlUpdateValue.ts +12 -0
- package/core/stores/ConnectionStore.ts +71 -0
- package/core/theme/ThemeContext.tsx +182 -0
- package/core/theme/assertThemeContrast.ts +109 -0
- package/core/theme/motion.ts +50 -0
- package/core/theme/tokens.ts +232 -0
- package/core/theme/useThemeStyles.tsx +156 -0
- package/core/walletDbRegistry.ts +110 -0
- package/core/walletMonitor.ts +149 -0
- package/core/walletRepair/runWalletCheck.ts +195 -0
- package/core/walletRepair/shouldReleaseUtxo.ts +18 -0
- package/package.json +86 -0
- package/ui/backupShares.ts +367 -0
- package/ui/components/QRScanner.tsx +353 -0
- package/ui/components/pay/AddressReceive.tsx +507 -0
- package/ui/components/pay/AvailableBalance.tsx +61 -0
- package/ui/components/pay/HandleReceive.tsx +896 -0
- package/ui/components/pay/MessageBoxConfig.tsx +256 -0
- package/ui/components/pay/NearbyAdvisoryModal.tsx +111 -0
- package/ui/components/pay/NearbyFlow.tsx +2542 -0
- package/ui/components/pay/OfflineNotice.tsx +337 -0
- package/ui/components/pay/PayCellRow.tsx +101 -0
- package/ui/components/pay/PayForm.tsx +223 -0
- package/ui/components/pay/PaymentQrDisplay.tsx +105 -0
- package/ui/components/pay/PaymentSuccessOverlay.tsx +266 -0
- package/ui/components/pay/RecipientField.tsx +308 -0
- package/ui/components/pay/RequestHub.tsx +75 -0
- package/ui/components/pay/ResultBanner.tsx +69 -0
- package/ui/components/pay/UniversalSend.tsx +687 -0
- package/ui/components/pay/useRecipientInput.ts +270 -0
- package/ui/components/security/WalletLockNotice.tsx +138 -0
- package/ui/components/ui/AlertCard.tsx +223 -0
- package/ui/components/ui/AppLogo.tsx +166 -0
- package/ui/components/ui/BlurChrome.tsx +72 -0
- package/ui/components/ui/Celebration.tsx +84 -0
- package/ui/components/ui/ChoiceSheet.ts +69 -0
- package/ui/components/ui/CustomSafeArea.tsx +74 -0
- package/ui/components/ui/ErrorBoundary.tsx +154 -0
- package/ui/components/ui/GroupedList.tsx +125 -0
- package/ui/components/ui/IconButton.tsx +105 -0
- package/ui/components/ui/ListRow.tsx +197 -0
- package/ui/components/ui/PermissionSheet.tsx +920 -0
- package/ui/components/ui/PresenceRow.tsx +215 -0
- package/ui/components/ui/PressableScale.tsx +105 -0
- package/ui/components/ui/ScreenGradient.tsx +47 -0
- package/ui/components/ui/ScrollFade.tsx +76 -0
- package/ui/components/ui/Sheet.tsx +342 -0
- package/ui/components/ui/Toast.tsx +142 -0
- package/ui/components/ui/index.ts +8 -0
- package/ui/components/vault/EnrollWizard.tsx +627 -0
- package/ui/components/vault/PassphraseField.tsx +306 -0
- package/ui/components/vault/PhraseBackupSheet.tsx +227 -0
- package/ui/components/vault/VaultBackdrop.tsx +354 -0
- package/ui/components/vault/VaultCeremonySheet.tsx +327 -0
- package/ui/components/wallet/ActivityRow.tsx +408 -0
- package/ui/components/wallet/AmountDisplay.tsx +48 -0
- package/ui/components/wallet/AmountInput.tsx +256 -0
- package/ui/components/wallet/BackupReminderSheet.tsx +168 -0
- package/ui/components/wallet/Balance.tsx +144 -0
- package/ui/components/wallet/BiometricAdvisoryModal.tsx +133 -0
- package/ui/components/wallet/ImportFromBackupPrompt.tsx +93 -0
- package/ui/exportDatabases.ts +122 -0
- package/ui/exportTransactions.ts +129 -0
- package/ui/hooks/useOfflineNoticeActions.ts +136 -0
- package/ui/hooks/useOnline.ts +70 -0
- package/ui/hooks/useSpendableBalance.ts +58 -0
- package/ui/hooks/useVaultBalance.ts +50 -0
- package/ui/importDatabases.ts +170 -0
- package/ui/index.ts +136 -0
- package/ui/isImageUrl.ts +10 -0
- package/ui/printRecoveryShares.ts +93 -0
- package/ui/resolveIdentity.ts +125 -0
- package/ui/screens/ConnectionsScreen.tsx +438 -0
- package/ui/screens/LogsScreen.tsx +432 -0
- package/ui/screens/PairScreen.tsx +288 -0
- package/ui/screens/PayScreen.tsx +479 -0
- package/ui/screens/SettingsScreen.tsx +180 -0
- package/ui/screens/TrustScreen.tsx +831 -0
- package/ui/screens/VaultRecoverScreen.tsx +226 -0
- package/ui/screens/VaultScreen.tsx +423 -0
- package/ui/screens/VaultTransferScreen.tsx +293 -0
- package/ui/screens/WalletCheckScreen.tsx +539 -0
- package/ui/screens/WalletConfigScreen.tsx +1095 -0
- package/ui/screens/WalletHomeScreen.tsx +1597 -0
- package/ui/screens/homeBadges.ts +18 -0
- package/ui/txStatus.ts +79 -0
- package/ui/validateTrust.ts +44 -0
|
@@ -0,0 +1,391 @@
|
|
|
1
|
+
# BSV Wallet Storage - Expo SQLite
|
|
2
|
+
|
|
3
|
+
Local storage implementation for BSV wallet data on mobile platforms using expo-sqlite. This implementation is based on the `@bsv/wallet-toolbox` `StorageIdb` and `StorageKnex` implementations, adapted for React Native with Expo.
|
|
4
|
+
|
|
5
|
+
## Features
|
|
6
|
+
|
|
7
|
+
- **Full wallet storage**: Supports all wallet data types including transactions, outputs, certificates, labels, and tags
|
|
8
|
+
- **SQLite-based**: Uses expo-sqlite for reliable local storage on iOS and Android
|
|
9
|
+
- **Transaction support**: Atomic operations with rollback capabilities
|
|
10
|
+
- **Type-safe**: Full TypeScript support with comprehensive type definitions
|
|
11
|
+
- **Schema migrations**: Automatic table creation and initialization
|
|
12
|
+
- **Compatible with wallet-toolbox**: Designed to work with `@bsv/wallet-toolbox` ecosystem
|
|
13
|
+
|
|
14
|
+
## Installation
|
|
15
|
+
|
|
16
|
+
The storage module requires expo-sqlite, which is already installed in this project:
|
|
17
|
+
|
|
18
|
+
```bash
|
|
19
|
+
npm install expo-sqlite
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
## Usage
|
|
23
|
+
|
|
24
|
+
### Basic Setup
|
|
25
|
+
|
|
26
|
+
```typescript
|
|
27
|
+
import { StorageExpoSQLite } from './storage'
|
|
28
|
+
|
|
29
|
+
// Create storage instance
|
|
30
|
+
const storage = new StorageExpoSQLite({
|
|
31
|
+
chain: 'main', // or 'test'
|
|
32
|
+
databaseName: 'my-wallet.db' // optional, defaults to 'wallet-toolbox-{chain}net.db'
|
|
33
|
+
})
|
|
34
|
+
|
|
35
|
+
// Initialize database
|
|
36
|
+
await storage.migrate('wallet-name', 'storage-identity-key')
|
|
37
|
+
|
|
38
|
+
// Check availability
|
|
39
|
+
if (storage.isAvailable()) {
|
|
40
|
+
console.log('Storage is ready')
|
|
41
|
+
}
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
### Working with Users
|
|
45
|
+
|
|
46
|
+
```typescript
|
|
47
|
+
// Create or find a user
|
|
48
|
+
const { user, isNew } = await storage.findOrInsertUser('user-identity-key')
|
|
49
|
+
|
|
50
|
+
console.log('User ID:', user.userId)
|
|
51
|
+
console.log('Is new user:', isNew)
|
|
52
|
+
|
|
53
|
+
// Update user
|
|
54
|
+
await storage.updateUser(user.userId, {
|
|
55
|
+
activeStorage: 'new-storage-key'
|
|
56
|
+
})
|
|
57
|
+
|
|
58
|
+
// Find users
|
|
59
|
+
const users = await storage.findUsers({
|
|
60
|
+
partial: { identityKey: 'user-identity-key' }
|
|
61
|
+
})
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
### Managing Transactions
|
|
65
|
+
|
|
66
|
+
```typescript
|
|
67
|
+
// Create a transaction
|
|
68
|
+
const txId = await storage.insertTransaction({
|
|
69
|
+
userId: user.userId,
|
|
70
|
+
status: 'completed',
|
|
71
|
+
reference: 'unique-tx-reference',
|
|
72
|
+
satoshis: 100000,
|
|
73
|
+
description: 'Payment for services',
|
|
74
|
+
isOutgoing: false,
|
|
75
|
+
version: 1,
|
|
76
|
+
lockTime: 0
|
|
77
|
+
})
|
|
78
|
+
|
|
79
|
+
// Find transactions
|
|
80
|
+
const transactions = await storage.findTransactions({
|
|
81
|
+
partial: {
|
|
82
|
+
userId: user.userId,
|
|
83
|
+
status: 'completed'
|
|
84
|
+
},
|
|
85
|
+
orderDescending: true,
|
|
86
|
+
limit: 10
|
|
87
|
+
})
|
|
88
|
+
|
|
89
|
+
// Update transaction
|
|
90
|
+
await storage.updateTransaction(txId, {
|
|
91
|
+
status: 'unproven'
|
|
92
|
+
})
|
|
93
|
+
|
|
94
|
+
// Count transactions
|
|
95
|
+
const count = await storage.countTransactions({
|
|
96
|
+
partial: { userId: user.userId }
|
|
97
|
+
})
|
|
98
|
+
```
|
|
99
|
+
|
|
100
|
+
### Managing Outputs
|
|
101
|
+
|
|
102
|
+
```typescript
|
|
103
|
+
// Create output basket
|
|
104
|
+
const basket = await storage.findOrInsertOutputBasket(user.userId, 'default')
|
|
105
|
+
|
|
106
|
+
// Insert output
|
|
107
|
+
const outputId = await storage.insertOutput({
|
|
108
|
+
userId: user.userId,
|
|
109
|
+
transactionId: txId,
|
|
110
|
+
vout: 0,
|
|
111
|
+
satoshis: 100000,
|
|
112
|
+
basketId: basket.basketId,
|
|
113
|
+
spendable: true,
|
|
114
|
+
change: false,
|
|
115
|
+
outpoint: 'txid:0',
|
|
116
|
+
providedBy: 'you'
|
|
117
|
+
})
|
|
118
|
+
|
|
119
|
+
// Find spendable outputs
|
|
120
|
+
const outputs = await storage.findOutputs({
|
|
121
|
+
partial: {
|
|
122
|
+
userId: user.userId,
|
|
123
|
+
spendable: true
|
|
124
|
+
}
|
|
125
|
+
})
|
|
126
|
+
|
|
127
|
+
// Update output (mark as spent)
|
|
128
|
+
await storage.updateOutput(outputId, {
|
|
129
|
+
spendable: false,
|
|
130
|
+
spentBy: 'spending-txid'
|
|
131
|
+
})
|
|
132
|
+
```
|
|
133
|
+
|
|
134
|
+
### Using Transactions (Atomic Operations)
|
|
135
|
+
|
|
136
|
+
```typescript
|
|
137
|
+
// Ensure all operations succeed or fail together
|
|
138
|
+
await storage.transaction(async trx => {
|
|
139
|
+
// Create transaction
|
|
140
|
+
const txId = await storage.insertTransaction(
|
|
141
|
+
{
|
|
142
|
+
userId: user.userId,
|
|
143
|
+
status: 'completed',
|
|
144
|
+
reference: 'atomic-ref',
|
|
145
|
+
satoshis: 50000
|
|
146
|
+
},
|
|
147
|
+
trx
|
|
148
|
+
)
|
|
149
|
+
|
|
150
|
+
// Create output
|
|
151
|
+
await storage.insertOutput(
|
|
152
|
+
{
|
|
153
|
+
userId: user.userId,
|
|
154
|
+
transactionId: txId,
|
|
155
|
+
vout: 0,
|
|
156
|
+
satoshis: 50000,
|
|
157
|
+
basketId: basket.basketId,
|
|
158
|
+
outpoint: 'atomic-ref:0',
|
|
159
|
+
providedBy: 'you'
|
|
160
|
+
},
|
|
161
|
+
trx
|
|
162
|
+
)
|
|
163
|
+
|
|
164
|
+
// If any operation fails, everything rolls back
|
|
165
|
+
})
|
|
166
|
+
```
|
|
167
|
+
|
|
168
|
+
### Labels and Tags
|
|
169
|
+
|
|
170
|
+
```typescript
|
|
171
|
+
// Create transaction label
|
|
172
|
+
const label = await storage.findOrInsertTxLabel(user.userId, 'payment')
|
|
173
|
+
|
|
174
|
+
// Map label to transaction
|
|
175
|
+
await storage.insertTxLabelMap({
|
|
176
|
+
txLabelId: label.txLabelId,
|
|
177
|
+
transactionId: txId
|
|
178
|
+
})
|
|
179
|
+
|
|
180
|
+
// Create output tag
|
|
181
|
+
const tag = await storage.findOrInsertOutputTag(user.userId, 'income')
|
|
182
|
+
|
|
183
|
+
// Map tag to output
|
|
184
|
+
await storage.insertOutputTagMap({
|
|
185
|
+
outputTagId: tag.outputTagId,
|
|
186
|
+
outputId: outputId
|
|
187
|
+
})
|
|
188
|
+
```
|
|
189
|
+
|
|
190
|
+
### Certificates
|
|
191
|
+
|
|
192
|
+
```typescript
|
|
193
|
+
// Insert certificate
|
|
194
|
+
const certId = await storage.insertCertificate({
|
|
195
|
+
userId: user.userId,
|
|
196
|
+
type: 'identity',
|
|
197
|
+
subject: 'user-subject',
|
|
198
|
+
serialNumber: 'cert-serial-123',
|
|
199
|
+
certifier: 'certifier-key',
|
|
200
|
+
revocationOutpoint: 'outpoint',
|
|
201
|
+
signature: 'signature'
|
|
202
|
+
})
|
|
203
|
+
|
|
204
|
+
// Add certificate field
|
|
205
|
+
await storage.insertCertificateField({
|
|
206
|
+
certificateId: certId,
|
|
207
|
+
userId: user.userId,
|
|
208
|
+
fieldName: 'email',
|
|
209
|
+
fieldValue: 'encrypted-email',
|
|
210
|
+
masterKey: 'master-key'
|
|
211
|
+
})
|
|
212
|
+
|
|
213
|
+
// Find certificates
|
|
214
|
+
const certs = await storage.findCertificates({
|
|
215
|
+
partial: { userId: user.userId, type: 'identity' }
|
|
216
|
+
})
|
|
217
|
+
```
|
|
218
|
+
|
|
219
|
+
### Proven Transactions
|
|
220
|
+
|
|
221
|
+
```typescript
|
|
222
|
+
// Insert proven transaction
|
|
223
|
+
const provenTxId = await storage.insertProvenTx({
|
|
224
|
+
txid: 'transaction-hash',
|
|
225
|
+
height: 800000,
|
|
226
|
+
idx: 5,
|
|
227
|
+
merklePath: merklePathArray,
|
|
228
|
+
rawTx: rawTxArray,
|
|
229
|
+
blockHash: 'block-hash',
|
|
230
|
+
merkleRoot: 'merkle-root'
|
|
231
|
+
})
|
|
232
|
+
|
|
233
|
+
// Create proof request
|
|
234
|
+
const reqId = await storage.insertProvenTxReq({
|
|
235
|
+
txid: 'transaction-hash',
|
|
236
|
+
status: 'pending',
|
|
237
|
+
attempts: 0,
|
|
238
|
+
notified: 0
|
|
239
|
+
})
|
|
240
|
+
|
|
241
|
+
// Update proof request when proven
|
|
242
|
+
await storage.updateProvenTxReq(reqId, {
|
|
243
|
+
status: 'completed',
|
|
244
|
+
provenTxId: provenTxId
|
|
245
|
+
})
|
|
246
|
+
```
|
|
247
|
+
|
|
248
|
+
## Database Schema
|
|
249
|
+
|
|
250
|
+
The storage implementation creates the following tables:
|
|
251
|
+
|
|
252
|
+
- **users**: User identities and settings
|
|
253
|
+
- **transactions**: Transaction records with status tracking
|
|
254
|
+
- **outputs**: Transaction outputs (UTXOs)
|
|
255
|
+
- **output_baskets**: Logical groupings of outputs
|
|
256
|
+
- **output_tags**: Tags for categorizing outputs
|
|
257
|
+
- **output_tags_map**: Many-to-many relationship between outputs and tags
|
|
258
|
+
- **tx_labels**: Labels for categorizing transactions
|
|
259
|
+
- **tx_labels_map**: Many-to-many relationship between transactions and labels
|
|
260
|
+
- **certificates**: Identity certificates
|
|
261
|
+
- **certificate_fields**: Certificate field data
|
|
262
|
+
- **proven_txs**: Transactions with merkle proofs
|
|
263
|
+
- **proven_tx_reqs**: Requests for transaction proofs
|
|
264
|
+
- **commissions**: Commission outputs
|
|
265
|
+
- **sync_states**: Synchronization state tracking
|
|
266
|
+
- **monitor_events**: Event monitoring logs
|
|
267
|
+
- **settings**: Storage configuration (singleton)
|
|
268
|
+
|
|
269
|
+
## Type Definitions
|
|
270
|
+
|
|
271
|
+
All tables have corresponding TypeScript interfaces exported from the module:
|
|
272
|
+
|
|
273
|
+
```typescript
|
|
274
|
+
import type {
|
|
275
|
+
TableUser,
|
|
276
|
+
TableTransaction,
|
|
277
|
+
TableOutput,
|
|
278
|
+
TableOutputBasket,
|
|
279
|
+
TableCertificate
|
|
280
|
+
// ... and more
|
|
281
|
+
} from './storage'
|
|
282
|
+
```
|
|
283
|
+
|
|
284
|
+
## API Reference
|
|
285
|
+
|
|
286
|
+
### Core Methods
|
|
287
|
+
|
|
288
|
+
- `migrate(storageName, storageIdentityKey)`: Initialize database
|
|
289
|
+
- `isAvailable()`: Check if storage is ready
|
|
290
|
+
- `makeAvailable()`: Ensure storage is initialized and return settings
|
|
291
|
+
- `getSettings()`: Get storage configuration
|
|
292
|
+
- `destroy()`: Close database connection
|
|
293
|
+
- `dropAllData()`: Delete all data (useful for testing)
|
|
294
|
+
- `transaction(scope)`: Execute operations atomically
|
|
295
|
+
|
|
296
|
+
### Insert Methods
|
|
297
|
+
|
|
298
|
+
All entities have `insert*` methods:
|
|
299
|
+
|
|
300
|
+
- `insertUser(user)`
|
|
301
|
+
- `insertTransaction(tx)`
|
|
302
|
+
- `insertOutput(output)`
|
|
303
|
+
- `insertCertificate(cert)`
|
|
304
|
+
- etc.
|
|
305
|
+
|
|
306
|
+
### Update Methods
|
|
307
|
+
|
|
308
|
+
All entities have `update*` methods:
|
|
309
|
+
|
|
310
|
+
- `updateUser(id, update)`
|
|
311
|
+
- `updateTransaction(id, update)`
|
|
312
|
+
- `updateOutput(id, update)`
|
|
313
|
+
- etc.
|
|
314
|
+
|
|
315
|
+
### Find Methods
|
|
316
|
+
|
|
317
|
+
All entities have `find*` methods with filtering:
|
|
318
|
+
|
|
319
|
+
- `findUsers(args)`
|
|
320
|
+
- `findTransactions(args)`
|
|
321
|
+
- `findOutputs(args)`
|
|
322
|
+
- etc.
|
|
323
|
+
|
|
324
|
+
Find arguments support:
|
|
325
|
+
|
|
326
|
+
```typescript
|
|
327
|
+
interface FindArgs<T> {
|
|
328
|
+
partial: Partial<T> // Filter by fields
|
|
329
|
+
since?: Date // Filter by update time
|
|
330
|
+
limit?: number // Pagination limit
|
|
331
|
+
offset?: number // Pagination offset
|
|
332
|
+
orderDescending?: boolean // Sort order
|
|
333
|
+
trx?: TrxToken // Transaction context
|
|
334
|
+
}
|
|
335
|
+
```
|
|
336
|
+
|
|
337
|
+
### Find By ID Methods
|
|
338
|
+
|
|
339
|
+
Direct lookups by primary key:
|
|
340
|
+
|
|
341
|
+
- `findUserById(id)`
|
|
342
|
+
- `findTransactionById(id)`
|
|
343
|
+
- `findOutputById(id)`
|
|
344
|
+
- etc.
|
|
345
|
+
|
|
346
|
+
### Count Methods
|
|
347
|
+
|
|
348
|
+
Count records matching criteria:
|
|
349
|
+
|
|
350
|
+
- `countUsers(args)`
|
|
351
|
+
- `countTransactions(args)`
|
|
352
|
+
- `countOutputs(args)`
|
|
353
|
+
- etc.
|
|
354
|
+
|
|
355
|
+
### Find Or Insert Methods
|
|
356
|
+
|
|
357
|
+
Convenience methods that create if not exists:
|
|
358
|
+
|
|
359
|
+
- `findOrInsertUser(identityKey)`
|
|
360
|
+
- `findOrInsertTransaction(newTx)`
|
|
361
|
+
- `findOrInsertOutputBasket(userId, name)`
|
|
362
|
+
- `findOrInsertTxLabel(userId, label)`
|
|
363
|
+
- `findOrInsertOutputTag(userId, tag)`
|
|
364
|
+
|
|
365
|
+
## Data Type Conversions
|
|
366
|
+
|
|
367
|
+
The storage implementation handles several automatic conversions:
|
|
368
|
+
|
|
369
|
+
- **Dates**: Stored as ISO strings, returned as Date objects
|
|
370
|
+
- **Booleans**: Stored as integers (0/1), returned as booleans
|
|
371
|
+
- **BLOBs**: Number arrays converted to Uint8Array for storage
|
|
372
|
+
- **Timestamps**: Automatically managed (created_at, updated_at)
|
|
373
|
+
|
|
374
|
+
## Integration with wallet-toolbox
|
|
375
|
+
|
|
376
|
+
This storage implementation follows the same patterns as `@bsv/wallet-toolbox` StorageIdb and can be used as a drop-in replacement for mobile platforms. The table structures and method signatures are designed to be compatible with the `@bsv/wallet-toolbox-mobile` ecosystem.
|
|
377
|
+
|
|
378
|
+
## Future Enhancements
|
|
379
|
+
|
|
380
|
+
Potential areas for improvement:
|
|
381
|
+
|
|
382
|
+
- Add support for advanced querying (complex WHERE clauses)
|
|
383
|
+
- Implement filter methods (for streaming large result sets)
|
|
384
|
+
- Add sync methods for multi-device synchronization
|
|
385
|
+
- Implement storage provider interface for compatibility with WalletStorageManager
|
|
386
|
+
- Add migration support for schema updates
|
|
387
|
+
- Performance optimizations (indexes, query optimization)
|
|
388
|
+
|
|
389
|
+
## License
|
|
390
|
+
|
|
391
|
+
Open BSV License
|