@bsv/wallet-toolbox 1.5.11 → 1.5.13

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (111) hide show
  1. package/docs/client.md +189 -84
  2. package/docs/monitor.md +39 -2
  3. package/docs/setup.md +8 -8
  4. package/docs/wallet.md +189 -84
  5. package/mobile/out/src/SetupClient.d.ts +2 -2
  6. package/mobile/out/src/SetupClient.d.ts.map +1 -1
  7. package/mobile/out/src/SetupClient.js +2 -2
  8. package/mobile/out/src/SetupClient.js.map +1 -1
  9. package/mobile/out/src/SetupWallet.d.ts +2 -2
  10. package/mobile/out/src/SetupWallet.d.ts.map +1 -1
  11. package/mobile/out/src/Wallet.d.ts +3 -3
  12. package/mobile/out/src/Wallet.d.ts.map +1 -1
  13. package/mobile/out/src/Wallet.js.map +1 -1
  14. package/mobile/out/src/monitor/Monitor.d.ts +23 -0
  15. package/mobile/out/src/monitor/Monitor.d.ts.map +1 -1
  16. package/mobile/out/src/monitor/Monitor.js +26 -16
  17. package/mobile/out/src/monitor/Monitor.js.map +1 -1
  18. package/mobile/out/src/monitor/tasks/TaskCheckForProofs.d.ts.map +1 -1
  19. package/mobile/out/src/monitor/tasks/TaskCheckForProofs.js +8 -0
  20. package/mobile/out/src/monitor/tasks/TaskCheckForProofs.js.map +1 -1
  21. package/mobile/out/src/monitor/tasks/TaskSendWaiting.d.ts.map +1 -1
  22. package/mobile/out/src/monitor/tasks/TaskSendWaiting.js +9 -0
  23. package/mobile/out/src/monitor/tasks/TaskSendWaiting.js.map +1 -1
  24. package/mobile/out/src/sdk/types.d.ts +11 -0
  25. package/mobile/out/src/sdk/types.d.ts.map +1 -1
  26. package/mobile/out/src/sdk/types.js.map +1 -1
  27. package/mobile/out/src/signer/WalletSigner.d.ts +3 -3
  28. package/mobile/out/src/signer/WalletSigner.d.ts.map +1 -1
  29. package/mobile/out/src/signer/WalletSigner.js.map +1 -1
  30. package/mobile/out/src/storage/methods/processAction.d.ts.map +1 -1
  31. package/mobile/out/src/storage/methods/processAction.js +6 -64
  32. package/mobile/out/src/storage/methods/processAction.js.map +1 -1
  33. package/mobile/out/src/utility/ScriptTemplateBRC29.d.ts.map +1 -1
  34. package/mobile/out/src/utility/ScriptTemplateBRC29.js +1 -1
  35. package/mobile/out/src/utility/ScriptTemplateBRC29.js.map +1 -1
  36. package/mobile/out/src/utility/aggregateResults.d.ts +8 -0
  37. package/mobile/out/src/utility/aggregateResults.d.ts.map +1 -0
  38. package/mobile/out/src/utility/aggregateResults.js +59 -0
  39. package/mobile/out/src/utility/aggregateResults.js.map +1 -0
  40. package/mobile/package-lock.json +6 -7
  41. package/mobile/package.json +2 -2
  42. package/out/src/Setup.d.ts +2 -2
  43. package/out/src/Setup.d.ts.map +1 -1
  44. package/out/src/Setup.js +2 -2
  45. package/out/src/Setup.js.map +1 -1
  46. package/out/src/SetupClient.d.ts +2 -2
  47. package/out/src/SetupClient.d.ts.map +1 -1
  48. package/out/src/SetupClient.js +2 -2
  49. package/out/src/SetupClient.js.map +1 -1
  50. package/out/src/SetupWallet.d.ts +2 -2
  51. package/out/src/SetupWallet.d.ts.map +1 -1
  52. package/out/src/Wallet.d.ts +3 -3
  53. package/out/src/Wallet.d.ts.map +1 -1
  54. package/out/src/Wallet.js.map +1 -1
  55. package/out/src/__tests/WalletPermissionsManager.proxying.test.js +1 -1
  56. package/out/src/__tests/WalletPermissionsManager.proxying.test.js.map +1 -1
  57. package/out/src/monitor/Monitor.d.ts +23 -0
  58. package/out/src/monitor/Monitor.d.ts.map +1 -1
  59. package/out/src/monitor/Monitor.js +26 -16
  60. package/out/src/monitor/Monitor.js.map +1 -1
  61. package/out/src/monitor/tasks/TaskCheckForProofs.d.ts.map +1 -1
  62. package/out/src/monitor/tasks/TaskCheckForProofs.js +8 -0
  63. package/out/src/monitor/tasks/TaskCheckForProofs.js.map +1 -1
  64. package/out/src/monitor/tasks/TaskSendWaiting.d.ts.map +1 -1
  65. package/out/src/monitor/tasks/TaskSendWaiting.js +9 -0
  66. package/out/src/monitor/tasks/TaskSendWaiting.js.map +1 -1
  67. package/out/src/sdk/types.d.ts +11 -0
  68. package/out/src/sdk/types.d.ts.map +1 -1
  69. package/out/src/sdk/types.js.map +1 -1
  70. package/out/src/services/__tests/ARC.timeout.man.test.js +1 -1
  71. package/out/src/signer/WalletSigner.d.ts +3 -3
  72. package/out/src/signer/WalletSigner.d.ts.map +1 -1
  73. package/out/src/signer/WalletSigner.js.map +1 -1
  74. package/out/src/storage/methods/processAction.d.ts.map +1 -1
  75. package/out/src/storage/methods/processAction.js +6 -64
  76. package/out/src/storage/methods/processAction.js.map +1 -1
  77. package/out/src/utility/ScriptTemplateBRC29.d.ts.map +1 -1
  78. package/out/src/utility/ScriptTemplateBRC29.js +1 -1
  79. package/out/src/utility/ScriptTemplateBRC29.js.map +1 -1
  80. package/out/src/utility/aggregateResults.d.ts +8 -0
  81. package/out/src/utility/aggregateResults.d.ts.map +1 -0
  82. package/out/src/utility/aggregateResults.js +59 -0
  83. package/out/src/utility/aggregateResults.js.map +1 -0
  84. package/out/test/Wallet/live/walletLive.man.test.d.ts.map +1 -1
  85. package/out/test/Wallet/live/walletLive.man.test.js +1 -1
  86. package/out/test/Wallet/live/walletLive.man.test.js.map +1 -1
  87. package/out/test/monitor/Monitor.test.js +101 -0
  88. package/out/test/monitor/Monitor.test.js.map +1 -1
  89. package/out/test/utils/TestUtilsWalletStorage.d.ts +4 -4
  90. package/out/test/utils/TestUtilsWalletStorage.d.ts.map +1 -1
  91. package/out/test/utils/TestUtilsWalletStorage.js +3 -3
  92. package/out/test/utils/TestUtilsWalletStorage.js.map +1 -1
  93. package/out/tsconfig.all.tsbuildinfo +1 -1
  94. package/package.json +2 -2
  95. package/src/Setup.ts +5 -3
  96. package/src/SetupClient.ts +5 -3
  97. package/src/SetupWallet.ts +2 -2
  98. package/src/Wallet.ts +4 -3
  99. package/src/__tests/WalletPermissionsManager.proxying.test.ts +1 -1
  100. package/src/monitor/Monitor.ts +36 -15
  101. package/src/monitor/tasks/TaskCheckForProofs.ts +9 -0
  102. package/src/monitor/tasks/TaskSendWaiting.ts +12 -1
  103. package/src/sdk/types.ts +12 -0
  104. package/src/services/__tests/ARC.timeout.man.test.ts +1 -1
  105. package/src/signer/WalletSigner.ts +3 -3
  106. package/src/storage/methods/processAction.ts +7 -78
  107. package/src/utility/ScriptTemplateBRC29.ts +3 -2
  108. package/src/utility/aggregateResults.ts +68 -0
  109. package/test/Wallet/live/walletLive.man.test.ts +2 -1
  110. package/test/monitor/Monitor.test.ts +123 -1
  111. package/test/utils/TestUtilsWalletStorage.ts +8 -6
@@ -1,4 +1,4 @@
1
- import { MerklePath } from '@bsv/sdk'
1
+ import { Beef, MerklePath } from '@bsv/sdk'
2
2
  import { asArray, EntityProvenTxReq, sdk, verifyOne, verifyTruthy, wait } from '../../src/index.client'
3
3
  import { TaskCheckForProofs } from '../../src/monitor/tasks/TaskCheckForProofs'
4
4
  import { TaskClock } from '../../src/monitor/tasks/TaskClock'
@@ -490,4 +490,126 @@ describe('Monitor tests', () => {
490
490
  await ctx.storage.destroy()
491
491
  }
492
492
  })
493
+
494
+ test('8 ProcessProvenTransaction', async () => {
495
+ const ctxs: TestWallet<{}>[] = []
496
+ ctxs.push(await _tu.createLegacyWalletSQLiteCopy('monitorTest8'))
497
+ let mockResultIndex = 0
498
+ let updatesReceived = 0
499
+
500
+ const expectedTxids = [
501
+ 'c099c52277426abb863dc902d0389b008ddf2301d6b40ac718746ac16ca59136',
502
+ '6935ce33b9e3b9ee60360ce0606aa0a0970b4840203f457b5559212676dc33ab',
503
+ '67ca2475886b3fc2edd76a2eb8c32bd0bc308176c7dff463e0507942aeebcbec',
504
+ '3fa94b62a3b10d8c18bada527a9b68c4e70db67140719df16c44fb0328782532',
505
+ '519675259eff036c6597e4a497d37c132e718171dde4ea2257e84c947ecf656b'
506
+ ]
507
+
508
+ _tu.mockMerklePathServicesAsCallback(ctxs, async txid => {
509
+ expect(expectedTxids).toContain(txid)
510
+ const r = mockGetMerklePathResults[mockResultIndex++]
511
+ return r
512
+ })
513
+
514
+ for (const { activeStorage: storage, monitor } of ctxs) {
515
+ if (!monitor) throw new sdk.WERR_INTERNAL('test requires setup with monitor')
516
+
517
+ monitor.lastNewHeader = {
518
+ height: 999999999,
519
+ hash: '',
520
+ time: 0,
521
+ version: 0,
522
+ previousHash: '',
523
+ merkleRoot: '',
524
+ bits: 0,
525
+ nonce: 0
526
+ }
527
+
528
+ monitor.onTransactionProven = async (txStatus: sdk.ProvenTransactionStatus) => {
529
+ expect(txStatus.txid).toBeTruthy()
530
+ expect(txStatus.blockHash).toBeTruthy()
531
+ expect(txStatus.blockHeight).toBeTruthy()
532
+ expect(txStatus.merkleRoot).toBeTruthy()
533
+ updatesReceived++
534
+ }
535
+
536
+ for (const txid of expectedTxids) {
537
+ // no matching ProvenTx exists.
538
+ expect((await storage.findProvenTxs({ partial: { txid } })).length).toBe(0)
539
+ const req = verifyTruthy(await EntityProvenTxReq.fromStorageTxid(storage, txid))
540
+ expect(req.status).toBe('unmined')
541
+ }
542
+
543
+ const task = new TaskCheckForProofs(monitor, 1)
544
+ monitor._tasks.push(task)
545
+
546
+ await monitor.runTask('CheckForProofs')
547
+
548
+ for (const txid of expectedTxids) {
549
+ const proven = verifyOne(await storage.findProvenTxs({ partial: { txid } }))
550
+ expect(proven.merklePath).toBeTruthy()
551
+ const req = verifyTruthy(await EntityProvenTxReq.fromStorageTxid(storage, txid))
552
+ expect(req.status).toBe('completed')
553
+ expect(req.provenTxId).toBe(proven.provenTxId)
554
+ }
555
+
556
+ expect(updatesReceived).toEqual(expectedTxids.length)
557
+ }
558
+
559
+ for (const ctx of ctxs) {
560
+ await ctx.storage.destroy()
561
+ }
562
+ })
563
+
564
+ test('9 ProcessBroadcastedTransactions', async () => {
565
+ const ctxs: TestWallet<{}>[] = []
566
+ ctxs.push(await _tu.createLegacyWalletSQLiteCopy('monitorTest8'))
567
+ let updatesReceived = 0
568
+ let txidsPosted: string[] = []
569
+
570
+ const expectedTxids = [
571
+ 'd9ec73b2e0f06e0f482d2d1db9ceccf2f212f0b24afbe10846ac907567be571f',
572
+ 'b7634f08d8c7f3c6244050bebf73a79f40e672aba7d5232663609a58b123b816',
573
+ '3d2ea64ee584a1f6eb161dbedf3a8d299e3e4497ac7a203d23c044c998c6aa08',
574
+ 'a3a8fe7f541c1383ff7b975af49b27284ae720af5f2705d8409baaf519190d26',
575
+ '6d68cc6fa7363e59aaccbaa65f0ca613a6ae8af718453ab5d3a2b022c59b5cc6'
576
+ ]
577
+
578
+ _tu.mockPostServicesAsCallback(ctxs, (beef: Beef, txids: string[]) => {
579
+ txidsPosted.push(...txids)
580
+ return 'success'
581
+ })
582
+
583
+ for (const { activeStorage: storage, monitor } of ctxs) {
584
+ if (!monitor) throw new sdk.WERR_INTERNAL('test requires setup with monitor')
585
+
586
+ for (const txid of expectedTxids) {
587
+ const req = verifyTruthy(await EntityProvenTxReq.fromStorageTxid(storage, txid))
588
+ expect(req.status).toBe('unsent')
589
+ }
590
+
591
+ monitor.onTransactionBroadcasted = async (broadcastResult: sdk.ReviewActionResult) => {
592
+ expect(broadcastResult.status).toBe('success')
593
+ expect(expectedTxids).toContain(broadcastResult.txid)
594
+ updatesReceived++
595
+ }
596
+
597
+ const task = new TaskSendWaiting(monitor, 1, 1)
598
+ monitor._tasks.push(task)
599
+
600
+ await monitor.runTask('SendWaiting')
601
+
602
+ expect(txidsPosted).toEqual(expectedTxids)
603
+ for (const txid of expectedTxids) {
604
+ const req = verifyOne(await storage.findProvenTxReqs({ partial: { txid } }))
605
+ expect(req.status).toBe('unmined')
606
+ }
607
+
608
+ expect(updatesReceived).toEqual(expectedTxids.length)
609
+ }
610
+
611
+ for (const ctx of ctxs) {
612
+ await ctx.storage.destroy()
613
+ }
614
+ })
493
615
  })
@@ -1,10 +1,12 @@
1
1
  import {
2
2
  Beef,
3
+ CachedKeyDeriver,
3
4
  CreateActionArgs,
4
5
  CreateActionOutput,
5
6
  CreateActionResult,
6
7
  HexString,
7
8
  KeyDeriver,
9
+ KeyDeriverApi,
8
10
  P2PKH,
9
11
  PrivateKey,
10
12
  PublicKey,
@@ -309,7 +311,7 @@ export abstract class TestUtilsWalletStorage {
309
311
  args.rootKeyHex ||= '1'.repeat(64)
310
312
  const rootKey = PrivateKey.fromHex(args.rootKeyHex)
311
313
  const identityKey = rootKey.toPublicKey().toString()
312
- const keyDeriver = new KeyDeriver(rootKey)
314
+ const keyDeriver = new CachedKeyDeriver(rootKey)
313
315
  const chain = args.chain
314
316
  const storage = new WalletStorageManager(identityKey, args.active, args.backups)
315
317
  if (storage.canMakeAvailable()) await storage.makeAvailable()
@@ -807,7 +809,7 @@ export abstract class TestUtilsWalletStorage {
807
809
  const rootKeyHex = _tu.legacyRootKeyHex
808
810
  const identityKey = '03ac2d10bdb0023f4145cc2eba2fcd2ad3070cb2107b0b48170c46a9440e4cc3fe'
809
811
  const rootKey = PrivateKey.fromHex(rootKeyHex)
810
- const keyDeriver = new KeyDeriver(rootKey)
812
+ const keyDeriver = new CachedKeyDeriver(rootKey)
811
813
  const activeStorage = new StorageKnex({
812
814
  chain,
813
815
  knex: walletKnex,
@@ -977,7 +979,7 @@ export abstract class TestUtilsWalletStorage {
977
979
  const rootKeyHex = _tu.legacyRootKeyHex
978
980
  const identityKey = '03ac2d10bdb0023f4145cc2eba2fcd2ad3070cb2107b0b48170c46a9440e4cc3fe'
979
981
  const rootKey = PrivateKey.fromHex(rootKeyHex)
980
- const keyDeriver = new KeyDeriver(rootKey)
982
+ const keyDeriver = new CachedKeyDeriver(rootKey)
981
983
 
982
984
  const activeStorage = new StorageIdb({
983
985
  chain,
@@ -1835,7 +1837,7 @@ export interface TestWalletProvider<T> extends TestWalletOnly {
1835
1837
 
1836
1838
  rootKey: PrivateKey
1837
1839
  identityKey: string
1838
- keyDeriver: KeyDeriver
1840
+ keyDeriver: KeyDeriverApi
1839
1841
  chain: sdk.Chain
1840
1842
  storage: WalletStorageManager
1841
1843
  services: Services
@@ -1853,7 +1855,7 @@ export interface TestWallet<T> extends TestWalletOnly {
1853
1855
 
1854
1856
  rootKey: PrivateKey
1855
1857
  identityKey: string
1856
- keyDeriver: KeyDeriver
1858
+ keyDeriver: KeyDeriverApi
1857
1859
  chain: sdk.Chain
1858
1860
  storage: WalletStorageManager
1859
1861
  services: Services
@@ -1867,7 +1869,7 @@ export interface TestWallet<T> extends TestWalletOnly {
1867
1869
  export interface TestWalletOnly {
1868
1870
  rootKey: PrivateKey
1869
1871
  identityKey: string
1870
- keyDeriver: KeyDeriver
1872
+ keyDeriver: KeyDeriverApi
1871
1873
  chain: sdk.Chain
1872
1874
  storage: WalletStorageManager
1873
1875
  services: Services