@bsv/wallet-toolbox 1.6.33 → 1.6.34
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 +7 -0
- package/docs/client.md +340 -93
- package/docs/monitor.md +34 -12
- package/docs/storage.md +49 -1
- package/docs/wallet.md +340 -93
- package/mobile/out/src/monitor/tasks/TaskReorg.d.ts.map +1 -1
- package/mobile/out/src/monitor/tasks/TaskReorg.js +5 -1
- package/mobile/out/src/monitor/tasks/TaskReorg.js.map +1 -1
- package/mobile/out/src/sdk/WERR_errors.d.ts +8 -0
- package/mobile/out/src/sdk/WERR_errors.d.ts.map +1 -1
- package/mobile/out/src/sdk/WERR_errors.js +33 -0
- package/mobile/out/src/sdk/WERR_errors.js.map +1 -1
- package/mobile/out/src/sdk/WalletError.d.ts +19 -0
- package/mobile/out/src/sdk/WalletError.d.ts.map +1 -1
- package/mobile/out/src/sdk/WalletError.js +42 -1
- package/mobile/out/src/sdk/WalletError.js.map +1 -1
- package/mobile/out/src/sdk/WalletErrorFromJson.d.ts +12 -0
- package/mobile/out/src/sdk/WalletErrorFromJson.d.ts.map +1 -0
- package/mobile/out/src/sdk/WalletErrorFromJson.js +69 -0
- package/mobile/out/src/sdk/WalletErrorFromJson.js.map +1 -0
- package/mobile/out/src/sdk/index.d.ts +1 -0
- package/mobile/out/src/sdk/index.d.ts.map +1 -1
- package/mobile/out/src/sdk/index.js +1 -0
- package/mobile/out/src/sdk/index.js.map +1 -1
- package/mobile/out/src/services/chaintracker/ChaintracksChainTracker.js +1 -1
- package/mobile/out/src/services/chaintracker/ChaintracksChainTracker.js.map +1 -1
- package/mobile/out/src/services/chaintracker/chaintracks/util/ChaintracksFetch.d.ts.map +1 -1
- package/mobile/out/src/services/chaintracker/chaintracks/util/ChaintracksFetch.js +16 -9
- package/mobile/out/src/services/chaintracker/chaintracks/util/ChaintracksFetch.js.map +1 -1
- package/mobile/out/src/storage/WalletStorageManager.d.ts.map +1 -1
- package/mobile/out/src/storage/WalletStorageManager.js.map +1 -1
- package/mobile/out/src/storage/remoting/StorageClient.d.ts.map +1 -1
- package/mobile/out/src/storage/remoting/StorageClient.js +3 -5
- package/mobile/out/src/storage/remoting/StorageClient.js.map +1 -1
- package/mobile/package-lock.json +2 -2
- package/mobile/package.json +1 -1
- package/out/src/monitor/tasks/TaskReorg.d.ts.map +1 -1
- package/out/src/monitor/tasks/TaskReorg.js +5 -1
- package/out/src/monitor/tasks/TaskReorg.js.map +1 -1
- package/out/src/sdk/WERR_errors.d.ts +8 -0
- package/out/src/sdk/WERR_errors.d.ts.map +1 -1
- package/out/src/sdk/WERR_errors.js +33 -0
- package/out/src/sdk/WERR_errors.js.map +1 -1
- package/out/src/sdk/WalletError.d.ts +19 -0
- package/out/src/sdk/WalletError.d.ts.map +1 -1
- package/out/src/sdk/WalletError.js +42 -1
- package/out/src/sdk/WalletError.js.map +1 -1
- package/out/src/sdk/WalletErrorFromJson.d.ts +12 -0
- package/out/src/sdk/WalletErrorFromJson.d.ts.map +1 -0
- package/out/src/sdk/WalletErrorFromJson.js +69 -0
- package/out/src/sdk/WalletErrorFromJson.js.map +1 -0
- package/out/src/sdk/__test/WalletError.test.d.ts +2 -0
- package/out/src/sdk/__test/WalletError.test.d.ts.map +1 -0
- package/out/src/sdk/__test/WalletError.test.js +255 -0
- package/out/src/sdk/__test/WalletError.test.js.map +1 -0
- package/out/src/sdk/index.d.ts +1 -0
- package/out/src/sdk/index.d.ts.map +1 -1
- package/out/src/sdk/index.js +1 -0
- package/out/src/sdk/index.js.map +1 -1
- package/out/src/services/__tests/verifyBeef.test.js.map +1 -1
- package/out/src/services/chaintracker/ChaintracksChainTracker.js +1 -1
- package/out/src/services/chaintracker/ChaintracksChainTracker.js.map +1 -1
- package/out/src/services/chaintracker/chaintracks/util/ChaintracksFetch.d.ts.map +1 -1
- package/out/src/services/chaintracker/chaintracks/util/ChaintracksFetch.js +16 -9
- package/out/src/services/chaintracker/chaintracks/util/ChaintracksFetch.js.map +1 -1
- package/out/src/storage/WalletStorageManager.d.ts.map +1 -1
- package/out/src/storage/WalletStorageManager.js.map +1 -1
- package/out/src/storage/remoting/StorageClient.d.ts.map +1 -1
- package/out/src/storage/remoting/StorageClient.js +3 -5
- package/out/src/storage/remoting/StorageClient.js.map +1 -1
- package/out/src/storage/remoting/StorageServer.d.ts.map +1 -1
- package/out/src/storage/remoting/StorageServer.js +12 -10
- package/out/src/storage/remoting/StorageServer.js.map +1 -1
- package/out/test/Wallet/specOps/specOps.man.test.js +8 -6
- package/out/test/Wallet/specOps/specOps.man.test.js.map +1 -1
- package/out/tsconfig.all.tsbuildinfo +1 -1
- package/package.json +1 -1
- package/src/monitor/tasks/TaskReorg.ts +5 -1
- package/src/sdk/WERR_errors.ts +34 -0
- package/src/sdk/WalletError.ts +42 -1
- package/src/sdk/WalletErrorFromJson.ts +80 -0
- package/src/sdk/WalletStorage.interfaces.ts +3 -3
- package/src/sdk/__test/WalletError.test.ts +318 -0
- package/src/sdk/index.ts +1 -0
- package/src/services/__tests/verifyBeef.test.ts +0 -1
- package/src/services/chaintracker/ChaintracksChainTracker.ts +1 -1
- package/src/services/chaintracker/chaintracks/util/ChaintracksFetch.ts +18 -11
- package/src/storage/WalletStorageManager.ts +16 -19
- package/src/storage/methods/internalizeAction.ts +1 -1
- package/src/storage/remoting/StorageClient.ts +4 -6
- package/src/storage/remoting/StorageServer.ts +13 -11
- package/test/Wallet/specOps/specOps.man.test.ts +6 -4
|
@@ -525,9 +525,9 @@ export class WalletStorageManager implements sdk.WalletStorage {
|
|
|
525
525
|
* For each proven_txs record currently sourcing its transaction merkle proof from the given deactivated header,
|
|
526
526
|
* attempt to reprove the transaction against the current chain,
|
|
527
527
|
* updating the proven_txs record if a new valid proof is found.
|
|
528
|
-
*
|
|
528
|
+
*
|
|
529
529
|
* @param deactivatedHash An orphaned header than may have served as a proof source for proven_txs records.
|
|
530
|
-
* @returns
|
|
530
|
+
* @returns
|
|
531
531
|
*/
|
|
532
532
|
async reproveHeader(deactivatedHash: string): Promise<sdk.ReproveHeaderResult> {
|
|
533
533
|
const r: sdk.ReproveHeaderResult = { log: '', updated: [], unchanged: [], unavailable: [] }
|
|
@@ -547,8 +547,8 @@ export class WalletStorageManager implements sdk.WalletStorage {
|
|
|
547
547
|
const rp = await this.reproveProven(ptx, true)
|
|
548
548
|
|
|
549
549
|
r.log += rp.log
|
|
550
|
-
if (rp.unavailable) r.unavailable.push(ptx)
|
|
551
|
-
if (rp.unchanged) r.unchanged.push(ptx)
|
|
550
|
+
if (rp.unavailable) r.unavailable.push(ptx)
|
|
551
|
+
if (rp.unchanged) r.unchanged.push(ptx)
|
|
552
552
|
if (rp.updated) r.updated.push({ was: ptx, update: rp.updated.update, logUpdate: rp.updated.logUpdate })
|
|
553
553
|
}
|
|
554
554
|
|
|
@@ -566,14 +566,14 @@ export class WalletStorageManager implements sdk.WalletStorage {
|
|
|
566
566
|
|
|
567
567
|
/**
|
|
568
568
|
* Extends the Beef `verify` function to handle BUMPs that have become invalid due to a chain reorg.
|
|
569
|
-
*
|
|
569
|
+
*
|
|
570
570
|
* Any merkle root that fails `isValidRootForHeight` triggers a reprove attempt for that block header.
|
|
571
571
|
* This results in proven_txs with invalid proofs being updated with new valid proofs where possible.
|
|
572
572
|
* Finally, a new beef is generated and verified against the chaintracker.
|
|
573
|
-
*
|
|
574
|
-
* @param beef
|
|
575
|
-
* @param allowTxidOnly
|
|
576
|
-
* @returns
|
|
573
|
+
*
|
|
574
|
+
* @param beef
|
|
575
|
+
* @param allowTxidOnly
|
|
576
|
+
* @returns
|
|
577
577
|
*/
|
|
578
578
|
async verifyAndRepairBeef(beef: Beef, allowTxidOnly?: boolean): Promise<boolean> {
|
|
579
579
|
throw new sdk.WERR_NOT_IMPLEMENTED()
|
|
@@ -587,10 +587,7 @@ export class WalletStorageManager implements sdk.WalletStorage {
|
|
|
587
587
|
|
|
588
588
|
const invalidRoots: Record<number, string> = {}
|
|
589
589
|
for (const height of Object.keys(r.roots)) {
|
|
590
|
-
const isValid = await chaintracker.isValidRootForHeight(
|
|
591
|
-
r.roots[height],
|
|
592
|
-
Number(height)
|
|
593
|
-
)
|
|
590
|
+
const isValid = await chaintracker.isValidRootForHeight(r.roots[height], Number(height))
|
|
594
591
|
if (!isValid) {
|
|
595
592
|
invalidRoots[height] = r.roots[height]
|
|
596
593
|
}
|
|
@@ -619,10 +616,10 @@ export class WalletStorageManager implements sdk.WalletStorage {
|
|
|
619
616
|
* If a new valid proof is found and noUpdate is not true,
|
|
620
617
|
* update the proven_txs record with new block and merkle proof data.
|
|
621
618
|
* If noUpdate is true, the update to be applied is available in the returned result.
|
|
622
|
-
*
|
|
619
|
+
*
|
|
623
620
|
* @param ptx proven_txs record to reprove
|
|
624
|
-
* @param noUpdate
|
|
625
|
-
* @returns
|
|
621
|
+
* @param noUpdate
|
|
622
|
+
* @returns
|
|
626
623
|
*/
|
|
627
624
|
async reproveProven(ptx: TableProvenTx, noUpdate?: boolean): Promise<sdk.ReproveProvenResult> {
|
|
628
625
|
const r: sdk.ReproveProvenResult = { log: '', updated: undefined, unchanged: false, unavailable: false }
|
|
@@ -672,8 +669,8 @@ export class WalletStorageManager implements sdk.WalletStorage {
|
|
|
672
669
|
|
|
673
670
|
if (r.updated && !noUpdate) {
|
|
674
671
|
await this.runAsStorageProvider(async sp => {
|
|
675
|
-
|
|
676
|
-
|
|
672
|
+
await sp.updateProvenTx(ptx.provenTxId, r.updated!.update)
|
|
673
|
+
r.log += ` txid ${ptx.txid} proof data updated\n` + r.updated!.logUpdate
|
|
677
674
|
})
|
|
678
675
|
}
|
|
679
676
|
|
|
@@ -924,4 +921,4 @@ export class WalletStorageManager implements sdk.WalletStorage {
|
|
|
924
921
|
}
|
|
925
922
|
return stores
|
|
926
923
|
}
|
|
927
|
-
}
|
|
924
|
+
}
|
|
@@ -44,6 +44,8 @@ import { TableOutputBasket } from '../schema/tables/TableOutputBasket'
|
|
|
44
44
|
import { TableOutput } from '../schema/tables/TableOutput'
|
|
45
45
|
import { TableProvenTxReq } from '../schema/tables/TableProvenTxReq'
|
|
46
46
|
import { EntityTimeStamp } from '../../sdk/types'
|
|
47
|
+
import { WalletError } from '../../sdk/WalletError'
|
|
48
|
+
import { WalletErrorFromJson } from '../../sdk/WalletErrorFromJson'
|
|
47
49
|
|
|
48
50
|
/**
|
|
49
51
|
* `StorageClient` implements the `WalletStorageProvider` interface which allows it to
|
|
@@ -118,12 +120,8 @@ export class StorageClient implements WalletStorageProvider {
|
|
|
118
120
|
|
|
119
121
|
const json = await response.json()
|
|
120
122
|
if (json.error) {
|
|
121
|
-
const
|
|
122
|
-
|
|
123
|
-
// You could attach more info here if you like:
|
|
124
|
-
;(err as any).code = code
|
|
125
|
-
;(err as any).data = data
|
|
126
|
-
throw err
|
|
123
|
+
const werr = WalletErrorFromJson(json.error)
|
|
124
|
+
throw werr
|
|
127
125
|
}
|
|
128
126
|
|
|
129
127
|
return json.result
|
|
@@ -14,6 +14,7 @@ import { StorageProvider } from '../StorageProvider'
|
|
|
14
14
|
import { WERR_UNAUTHORIZED } from '../../sdk/WERR_errors'
|
|
15
15
|
import { SyncChunk } from '../../sdk/WalletStorage.interfaces'
|
|
16
16
|
import { EntityTimeStamp } from '../../sdk/types'
|
|
17
|
+
import { WalletError } from '../../sdk/WalletError'
|
|
17
18
|
|
|
18
19
|
export interface WalletStorageServerOptions {
|
|
19
20
|
port: number
|
|
@@ -165,19 +166,20 @@ export class StorageServer {
|
|
|
165
166
|
id
|
|
166
167
|
})
|
|
167
168
|
}
|
|
168
|
-
} catch (error) {
|
|
169
|
-
|
|
170
|
-
|
|
169
|
+
} catch (error: unknown) {
|
|
170
|
+
/**
|
|
171
|
+
* Catch any thrown errors from the local walletStorage method.
|
|
172
|
+
*
|
|
173
|
+
* Convert errors to standard JSON object format that can be converted
|
|
174
|
+
* back to WalletError derived objects on the client side and re-thrown.
|
|
175
|
+
*
|
|
176
|
+
* Uses WalletError.fromJson(<error object>) on the client side to re-create
|
|
177
|
+
* an error object of the right class and properties.
|
|
178
|
+
*/
|
|
179
|
+
const json = WalletError.unknownToJson(error)
|
|
171
180
|
return res.status(200).json({
|
|
172
181
|
jsonrpc: '2.0',
|
|
173
|
-
error:
|
|
174
|
-
code: -32000,
|
|
175
|
-
message: err.message,
|
|
176
|
-
data: {
|
|
177
|
-
name: err.name,
|
|
178
|
-
stack: err.stack
|
|
179
|
-
}
|
|
180
|
-
},
|
|
182
|
+
error: JSON.parse(json),
|
|
181
183
|
id
|
|
182
184
|
})
|
|
183
185
|
}
|
|
@@ -200,13 +200,15 @@ describe('specOps tests', () => {
|
|
|
200
200
|
|
|
201
201
|
async function createSetup(chain: sdk.Chain): Promise<TestWalletNoSetup> {
|
|
202
202
|
const env = _tu.getEnv(chain)
|
|
203
|
-
|
|
204
|
-
|
|
203
|
+
const identityKey = chain === 'test' ? env.testIdentityKey : env.identityKey
|
|
204
|
+
const filePath = chain === 'test' ? env.testFilePath : env.filePath
|
|
205
|
+
if (!identityKey) throw new sdk.WERR_INVALID_PARAMETER('identityKey', 'valid for chain ' + chain)
|
|
206
|
+
if (!filePath) throw new sdk.WERR_INVALID_PARAMETER('filePath', 'valid for chain ' + chain)
|
|
205
207
|
|
|
206
208
|
const setup = await _tu.createTestWallet({
|
|
207
209
|
chain,
|
|
208
|
-
rootKeyHex: env.devKeys[
|
|
209
|
-
filePath
|
|
210
|
+
rootKeyHex: env.devKeys[identityKey],
|
|
211
|
+
filePath,
|
|
210
212
|
setActiveClient: false,
|
|
211
213
|
addLocalBackup: false,
|
|
212
214
|
useMySQLConnectionForClient: false
|