@bsv/wallet-toolbox 1.1.2 → 1.1.4

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 (57) hide show
  1. package/README.md +12 -74
  2. package/docs/README.md +70 -6
  3. package/docs/client.md +401 -54
  4. package/docs/monitor.md +1 -2
  5. package/docs/setup.md +510 -0
  6. package/docs/storage.md +6 -8
  7. package/docs/wallet.md +401 -54
  8. package/out/src/Setup.d.ts +57 -0
  9. package/out/src/Setup.d.ts.map +1 -0
  10. package/out/src/Setup.js +88 -0
  11. package/out/src/Setup.js.map +1 -0
  12. package/out/src/SetupClient.d.ts +125 -0
  13. package/out/src/SetupClient.d.ts.map +1 -0
  14. package/out/src/SetupClient.js +222 -0
  15. package/out/src/SetupClient.js.map +1 -0
  16. package/out/src/Wallet.d.ts +10 -0
  17. package/out/src/Wallet.d.ts.map +1 -1
  18. package/out/src/Wallet.js.map +1 -1
  19. package/out/src/index.all.d.ts +2 -0
  20. package/out/src/index.all.d.ts.map +1 -1
  21. package/out/src/index.all.js +4 -1
  22. package/out/src/index.all.js.map +1 -1
  23. package/out/src/index.client.d.ts +1 -0
  24. package/out/src/index.client.d.ts.map +1 -1
  25. package/out/src/index.client.js +3 -1
  26. package/out/src/index.client.js.map +1 -1
  27. package/out/src/index.d.ts +0 -1
  28. package/out/src/index.d.ts.map +1 -1
  29. package/out/src/index.js +0 -24
  30. package/out/src/index.js.map +1 -1
  31. package/out/src/sdk/types.d.ts +5 -0
  32. package/out/src/sdk/types.d.ts.map +1 -1
  33. package/out/src/sdk/types.js.map +1 -1
  34. package/out/src/services/chaintracker/__tests/ChaintracksChainTracker.test.js +14 -11
  35. package/out/src/services/chaintracker/__tests/ChaintracksChainTracker.test.js.map +1 -1
  36. package/out/test/examples/README.man.test.js +9 -8
  37. package/out/test/examples/README.man.test.js.map +1 -1
  38. package/out/test/utils/TestUtilsWalletStorage.d.ts +11 -2
  39. package/out/test/utils/TestUtilsWalletStorage.d.ts.map +1 -1
  40. package/out/test/utils/TestUtilsWalletStorage.js +13 -4
  41. package/out/test/utils/TestUtilsWalletStorage.js.map +1 -1
  42. package/out/test/wallet/list/listActions2.test.js +121 -155
  43. package/out/test/wallet/list/listActions2.test.js.map +1 -1
  44. package/out/tsconfig.all.tsbuildinfo +1 -1
  45. package/package.json +2 -2
  46. package/src/Setup.ts +130 -0
  47. package/src/SetupClient.ts +364 -0
  48. package/src/Wallet.ts +10 -0
  49. package/src/index.all.ts +10 -0
  50. package/src/index.client.ts +1 -0
  51. package/src/index.ts +0 -1
  52. package/src/sdk/types.ts +7 -0
  53. package/src/services/chaintracker/__tests/ChaintracksChainTracker.test.ts +22 -17
  54. package/test/examples/README.man.test.ts +11 -11
  55. package/test/utils/TestUtilsWalletStorage.ts +23 -5
  56. package/test/wallet/list/listActions2.test.ts +119 -173
  57. package/ts2md.json +6 -0
@@ -438,6 +438,19 @@ export abstract class TestUtilsWalletStorage {
438
438
  })
439
439
  }
440
440
 
441
+ static async createMySQLTestSetup2Wallet(args: {
442
+ databaseName: string
443
+ mockData: MockData
444
+ chain?: sdk.Chain
445
+ rootKeyHex?: string
446
+ }): Promise<TestWallet<TestSetup2>> {
447
+ return await this.createKnexTestSetup2Wallet({
448
+ ...args,
449
+ dropAll: true,
450
+ knex: _tu.createLocalMySQL(args.databaseName)
451
+ })
452
+ }
453
+
441
454
  static async createSQLiteTestWallet(args: {
442
455
  filePath?: string
443
456
  databaseName: string
@@ -475,6 +488,7 @@ export abstract class TestUtilsWalletStorage {
475
488
 
476
489
  static async createSQLiteTestSetup2Wallet(args: {
477
490
  databaseName: string
491
+ mockData: MockData
478
492
  chain?: sdk.Chain
479
493
  rootKeyHex?: string
480
494
  }): Promise<TestWallet<TestSetup2>> {
@@ -521,13 +535,16 @@ export abstract class TestUtilsWalletStorage {
521
535
  static async createKnexTestSetup2Wallet(args: {
522
536
  knex: Knex<any, any[]>
523
537
  databaseName: string
538
+ mockData: MockData
524
539
  chain?: sdk.Chain
525
540
  rootKeyHex?: string
526
541
  dropAll?: boolean
527
542
  }): Promise<TestWallet<TestSetup2>> {
528
543
  return await _tu.createKnexTestWalletWithSetup({
529
544
  ...args,
530
- insertSetup: _tu.createTestSetup2
545
+ insertSetup: async (storage: StorageKnex, identityKey: string) => {
546
+ return _tu.createTestSetup2(storage, identityKey, args.mockData)
547
+ }
531
548
  })
532
549
  }
533
550
 
@@ -1145,7 +1162,7 @@ export abstract class TestUtilsWalletStorage {
1145
1162
 
1146
1163
  static async createTestSetup2(
1147
1164
  storage: StorageProvider,
1148
- u1IdentityKey: string,
1165
+ identityKey: string,
1149
1166
  mockData: MockData = { actions: [] }
1150
1167
  ): Promise<TestSetup2> {
1151
1168
  if (!mockData || !mockData.actions) {
@@ -1157,7 +1174,7 @@ export abstract class TestUtilsWalletStorage {
1157
1174
  const outputMap: Record<string, any> = {}
1158
1175
 
1159
1176
  // only one user
1160
- const user = await _tu.insertTestUser(storage, u1IdentityKey)
1177
+ const user = await _tu.insertTestUser(storage, identityKey)
1161
1178
 
1162
1179
  // First create your output that represent your inputs
1163
1180
  for (const action of mockData.actions) {
@@ -1328,7 +1345,7 @@ export abstract class TestUtilsWalletStorage {
1328
1345
  }
1329
1346
  }
1330
1347
 
1331
- return {}
1348
+ return mockData
1332
1349
  }
1333
1350
 
1334
1351
  static mockPostServicesAsSuccess(ctxs: TestWalletOnly[]): void {
@@ -1411,7 +1428,7 @@ export interface MockData {
1411
1428
  actions: WalletAction[]
1412
1429
  }
1413
1430
 
1414
- export interface TestSetup2 {}
1431
+ export interface TestSetup2 extends MockData {}
1415
1432
 
1416
1433
  export interface TestWallet<T> extends TestWalletOnly {
1417
1434
  activeStorage: StorageKnex
@@ -1446,6 +1463,7 @@ async function insertEmptySetup(
1446
1463
  return {}
1447
1464
  }
1448
1465
 
1466
+ export type TestSetup2Wallet = TestWallet<TestSetup2>
1449
1467
  export type TestSetup1Wallet = TestWallet<TestSetup1>
1450
1468
  export type TestWalletNoSetup = TestWallet<{}>
1451
1469
 
@@ -10,95 +10,67 @@ import {
10
10
  TestWalletNoSetup
11
11
  } from '../../utils/TestUtilsWalletStorage'
12
12
 
13
- const testName = 'listActions'
13
+ const env = _tu.getEnv('test')
14
+ const testName = () => expect.getState().currentTestName || 'test'
14
15
 
15
- describe('listActions single action tests', () => {
16
+ describe('listActions2 single action tests', () => {
16
17
  jest.setTimeout(99999999)
17
18
 
18
- let ctxs: TestWalletNoSetup[] = []
19
- let setups: { setup: TestSetup2; storage: StorageProvider }[] = []
19
+ let ctxs: TestWalletNoSetup[]
20
20
 
21
- const env = _tu.getEnv('test')
22
- const testName = () => expect.getState().currentTestName || 'test'
21
+ const mockData: MockData = {
22
+ actions: [
23
+ {
24
+ txid: 'tx',
25
+ satoshis: 1,
26
+ status: 'completed',
27
+ isOutgoing: true,
28
+ description: 'Transaction',
29
+ version: 1,
30
+ lockTime: 0,
31
+ labels: ['label', 'label2'],
32
+ inputs: [
33
+ {
34
+ sourceOutpoint: 'tx.0',
35
+ sourceSatoshis: 1,
36
+ sourceLockingScript: '0123456789abcdef',
37
+ unlockingScript: '0123456789abcdef',
38
+ inputDescription: 'description',
39
+ sequenceNumber: 0
40
+ }
41
+ ],
42
+ outputs: [
43
+ {
44
+ satoshis: 1,
45
+ spendable: false,
46
+ tags: ['tag', 'tag2'],
47
+ outputIndex: 2,
48
+ outputDescription: 'description',
49
+ basket: 'basket',
50
+ lockingScript: '0123456789abcdef'
51
+ }
52
+ ]
53
+ }
54
+ ]
55
+ }
23
56
 
24
57
  beforeEach(async () => {
25
- setups = []
26
- ctxs = []
27
-
28
- await Promise.all(
29
- ctxs.map(async ctx => {
30
- await ctx.storage.destroy()
31
- })
32
- )
33
58
  ctxs = []
34
-
35
- if (env.runMySQL) {
36
- ctxs.push(await _tu.createLegacyWalletMySQLCopy(testName))
37
- }
38
- await _tu.createSQLiteTestWallet({
59
+ const args = {
39
60
  chain: 'test',
61
+ mockData,
40
62
  databaseName: testName(),
41
63
  rootKeyHex: '2'.repeat(64),
42
64
  dropAll: true
43
- })
44
-
45
- //ctxs.push(await _tu.createLegacyWalletSQLiteCopy(testName))
46
-
47
- const mockData: MockData = {
48
- actions: [
49
- {
50
- txid: 'tx',
51
- satoshis: 1,
52
- status: 'completed',
53
- isOutgoing: true,
54
- description: 'Transaction',
55
- version: 1,
56
- lockTime: 0,
57
- labels: ['label', 'label2'],
58
- inputs: [
59
- {
60
- sourceOutpoint: 'tx.0',
61
- sourceSatoshis: 1,
62
- sourceLockingScript: '0123456789abcdef',
63
- unlockingScript: '0123456789abcdef',
64
- inputDescription: 'description',
65
- sequenceNumber: 0
66
- }
67
- ],
68
- outputs: [
69
- {
70
- satoshis: 1,
71
- spendable: false,
72
- tags: ['tag', 'tag2'],
73
- outputIndex: 2,
74
- outputDescription: 'description',
75
- basket: 'basket',
76
- lockingScript: '0123456789abcdef'
77
- }
78
- ]
79
- }
80
- ]
81
- }
82
-
83
- for (const ctx of ctxs) {
84
- const { activeStorage } = ctx
85
- await activeStorage.dropAllData()
86
- await activeStorage.migrate('insert tests', '3'.repeat(64))
87
65
  }
88
- expect(setups).toBeTruthy()
89
-
90
- for (const { activeStorage: storage, identityKey } of ctxs) {
91
- await _tu.createTestSetup2(storage, identityKey, mockData)
66
+ if (env.runMySQL) {
67
+ ctxs.push(await _tu.createMySQLTestSetup2Wallet(args))
92
68
  }
69
+ ctxs.push(await _tu.createSQLiteTestSetup2Wallet(args))
93
70
  })
94
71
 
95
72
  afterEach(async () => {
96
- await Promise.all(
97
- ctxs.map(async ctx => {
98
- await ctx.storage.destroy()
99
- })
100
- )
101
- ctxs = []
73
+ for (const { wallet } of ctxs) await wallet.destroy()
102
74
  })
103
75
 
104
76
  test('12_no labels default any', async () => {
@@ -1196,121 +1168,95 @@ describe('listActions single action tests', () => {
1196
1168
  // })
1197
1169
  })
1198
1170
 
1199
- describe('listActions two action tests', () => {
1171
+ describe('listActions2 two action tests', () => {
1200
1172
  jest.setTimeout(99999999)
1201
1173
 
1202
- let ctxs: TestWalletNoSetup[] = []
1203
- let setups: { setup: TestSetup2; storage: StorageProvider }[] = []
1174
+ let ctxs: TestWalletNoSetup[]
1204
1175
 
1205
- const env = _tu.getEnv('test')
1206
- const testName = () => expect.getState().currentTestName || 'test'
1176
+ const mockData: MockData = {
1177
+ actions: [
1178
+ {
1179
+ txid: 'tx1',
1180
+ satoshis: 1,
1181
+ status: 'completed',
1182
+ isOutgoing: true,
1183
+ description: 'Transaction 1',
1184
+ version: 1,
1185
+ lockTime: 0,
1186
+ labels: ['label 1', 'label a'],
1187
+ inputs: [
1188
+ {
1189
+ sourceOutpoint: 'tx1.1',
1190
+ sourceSatoshis: 1,
1191
+ //sourceLockingScript: '0123456789abcdef',
1192
+ //unlockingScript: '0123456789abcdef',
1193
+ inputDescription: 'description 1',
1194
+ sequenceNumber: 1
1195
+ }
1196
+ ],
1197
+ outputs: [
1198
+ {
1199
+ satoshis: 1,
1200
+ spendable: false,
1201
+ tags: ['tag1'],
1202
+ outputIndex: 1,
1203
+ outputDescription: 'description 1',
1204
+ basket: 'basket'
1205
+ //lockingScript: '0123456789abcdef'
1206
+ }
1207
+ ]
1208
+ },
1209
+ {
1210
+ txid: 'tx2',
1211
+ satoshis: 2,
1212
+ status: 'completed',
1213
+ isOutgoing: true,
1214
+ description: 'Transaction 2',
1215
+ version: 1,
1216
+ lockTime: 0,
1217
+ labels: ['label2', 'label b'],
1218
+ inputs: [
1219
+ {
1220
+ sourceOutpoint: 'tx2.2',
1221
+ sourceSatoshis: 2,
1222
+ //sourceLockingScript: '0123456789abcdef',
1223
+ //unlockingScript: '0123456789abcdef',
1224
+ inputDescription: 'description 2',
1225
+ sequenceNumber: 2
1226
+ }
1227
+ ],
1228
+ outputs: [
1229
+ {
1230
+ satoshis: 2,
1231
+ spendable: false,
1232
+ tags: ['tag2'],
1233
+ outputIndex: 2,
1234
+ outputDescription: 'description 2',
1235
+ basket: 'basket 2'
1236
+ //lockingScript: '0123456789abcdef'
1237
+ }
1238
+ ]
1239
+ }
1240
+ ]
1241
+ }
1207
1242
 
1208
1243
  beforeEach(async () => {
1209
- setups = []
1210
1244
  ctxs = []
1211
-
1212
- await Promise.all(
1213
- ctxs.map(async ctx => {
1214
- await ctx.storage.destroy()
1215
- })
1216
- )
1217
- ctxs = []
1218
-
1219
- if (env.runMySQL) {
1220
- ctxs.push(await _tu.createLegacyWalletMySQLCopy(testName))
1221
- }
1222
- await _tu.createSQLiteTestWallet({
1245
+ const args = {
1223
1246
  chain: 'test',
1247
+ mockData,
1224
1248
  databaseName: testName(),
1225
1249
  rootKeyHex: '2'.repeat(64),
1226
1250
  dropAll: true
1227
- })
1228
-
1229
- const mockData: MockData = {
1230
- actions: [
1231
- {
1232
- txid: 'tx1',
1233
- satoshis: 1,
1234
- status: 'completed',
1235
- isOutgoing: true,
1236
- description: 'Transaction 1',
1237
- version: 1,
1238
- lockTime: 0,
1239
- labels: ['label 1', 'label a'],
1240
- inputs: [
1241
- {
1242
- sourceOutpoint: 'tx1.1',
1243
- sourceSatoshis: 1,
1244
- //sourceLockingScript: '0123456789abcdef',
1245
- //unlockingScript: '0123456789abcdef',
1246
- inputDescription: 'description 1',
1247
- sequenceNumber: 1
1248
- }
1249
- ],
1250
- outputs: [
1251
- {
1252
- satoshis: 1,
1253
- spendable: false,
1254
- tags: ['tag1'],
1255
- outputIndex: 1,
1256
- outputDescription: 'description 1',
1257
- basket: 'basket'
1258
- //lockingScript: '0123456789abcdef'
1259
- }
1260
- ]
1261
- },
1262
- {
1263
- txid: 'tx2',
1264
- satoshis: 2,
1265
- status: 'completed',
1266
- isOutgoing: true,
1267
- description: 'Transaction 2',
1268
- version: 1,
1269
- lockTime: 0,
1270
- labels: ['label2', 'label b'],
1271
- inputs: [
1272
- {
1273
- sourceOutpoint: 'tx2.2',
1274
- sourceSatoshis: 2,
1275
- //sourceLockingScript: '0123456789abcdef',
1276
- //unlockingScript: '0123456789abcdef',
1277
- inputDescription: 'description 2',
1278
- sequenceNumber: 2
1279
- }
1280
- ],
1281
- outputs: [
1282
- {
1283
- satoshis: 2,
1284
- spendable: false,
1285
- tags: ['tag2'],
1286
- outputIndex: 2,
1287
- outputDescription: 'description 2',
1288
- basket: 'basket 2'
1289
- //lockingScript: '0123456789abcdef'
1290
- }
1291
- ]
1292
- }
1293
- ]
1294
1251
  }
1295
- for (const ctx of ctxs) {
1296
- const { activeStorage } = ctx
1297
- await activeStorage.dropAllData()
1298
- await activeStorage.migrate('insert tests', '3'.repeat(64))
1299
- }
1300
- expect(setups).toBeTruthy()
1301
-
1302
- for (const { activeStorage: storage, identityKey } of ctxs) {
1303
- await _tu.createTestSetup2(storage, identityKey, mockData)
1252
+ if (env.runMySQL) {
1253
+ ctxs.push(await _tu.createMySQLTestSetup2Wallet(args))
1304
1254
  }
1255
+ ctxs.push(await _tu.createSQLiteTestSetup2Wallet(args))
1305
1256
  })
1306
1257
 
1307
1258
  afterEach(async () => {
1308
- await Promise.all(
1309
- ctxs.map(async ctx => {
1310
- await ctx.storage.destroy()
1311
- })
1312
- )
1313
- ctxs = []
1259
+ for (const { wallet } of ctxs) await wallet.destroy()
1314
1260
  })
1315
1261
 
1316
1262
  test('100_no labels (default) matched default any', async () => {
package/ts2md.json CHANGED
@@ -1,5 +1,11 @@
1
1
  {
2
2
  "options": [
3
+ {
4
+ "inputFilename": "src/index.ts",
5
+ "outputFilename": "docs/setup.md",
6
+ "firstHeadingLevel": 1,
7
+ "filenameSubString": "Setup"
8
+ },
3
9
  {
4
10
  "inputFilename": "src/index.ts",
5
11
  "outputFilename": "docs/monitor.md",