@bsv/wallet-toolbox 1.2.2 → 1.2.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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bsv/wallet-toolbox",
3
- "version": "1.2.2",
3
+ "version": "1.2.4",
4
4
  "description": "BRC100 conforming wallet, wallet storage and wallet signer components",
5
5
  "main": "./out/src/index.js",
6
6
  "types": "./out/src/index.d.ts",
@@ -39,7 +39,7 @@ export class Services implements sdk.WalletServices {
39
39
 
40
40
  //prettier-ignore
41
41
  this.getMerklePathServices = new ServiceCollection<sdk.GetMerklePathService>()
42
- //.add({ name: 'WhatsOnChain', service: this.whatsonchain.getMerklePath.bind(this.whatsonchain) })
42
+ .add({ name: 'WhatsOnChain', service: this.whatsonchain.getMerklePath.bind(this.whatsonchain) })
43
43
  .add({ name: 'Bitails', service: this.bitails.getMerklePath.bind(this.bitails) })
44
44
 
45
45
  //prettier-ignore
@@ -1,12 +1,10 @@
1
1
  import {
2
- Transaction as BsvTransaction,
2
+ Transaction,
3
3
  AbortActionResult,
4
4
  Beef,
5
5
  InternalizeActionArgs,
6
6
  InternalizeActionResult,
7
- ListActionsArgs,
8
7
  ListActionsResult,
9
- ListOutputsArgs,
10
8
  ListOutputsResult,
11
9
  PubKeyHex,
12
10
  ListCertificatesResult,
@@ -19,7 +17,6 @@ import {
19
17
  asArray,
20
18
  asString,
21
19
  sdk,
22
- TableCertificate,
23
20
  TableCertificateX,
24
21
  TableMonitorEvent,
25
22
  TableOutput,
@@ -248,7 +245,7 @@ export abstract class StorageProvider extends StorageReaderWriter implements sdk
248
245
  if (!rawTx || !beef) throw new sdk.WERR_INTERNAL(`req rawTx and beef must be valid.`)
249
246
  mergeToBeef.mergeRawTx(asArray(rawTx))
250
247
  mergeToBeef.mergeBeef(asArray(beef))
251
- const tx = BsvTransaction.fromBinary(asArray(rawTx))
248
+ const tx = Transaction.fromBinary(asArray(rawTx))
252
249
  for (const input of tx.inputs) {
253
250
  if (!input.sourceTXID) throw new sdk.WERR_INTERNAL(`req all transaction inputs must have valid sourceTXID`)
254
251
  const txid = input.sourceTXID
@@ -441,7 +438,7 @@ export abstract class StorageProvider extends StorageReaderWriter implements sdk
441
438
  else {
442
439
  beef.mergeRawTx(r.rawTx)
443
440
  beef.mergeBeef(r.inputBEEF)
444
- const tx = BsvTransaction.fromBinary(r.rawTx)
441
+ const tx = Transaction.fromBinary(r.rawTx)
445
442
  for (const input of tx.inputs) {
446
443
  const btx = beef.findTxid(input.sourceTXID!)
447
444
  if (!btx) {
@@ -8,6 +8,7 @@ interface SpecOp {
8
8
  name: string
9
9
  useBasket?: string
10
10
  ignoreLimit?: boolean
11
+ includeOutputScripts?: boolean
11
12
  resultFromTags?: (
12
13
  s: StorageKnex,
13
14
  auth: sdk.AuthId,
@@ -61,6 +62,7 @@ const basketToSpecOp: Record<string, SpecOp> = {
61
62
  name: 'invalidChangeOutputs',
62
63
  useBasket: 'default',
63
64
  ignoreLimit: true,
65
+ includeOutputScripts: true,
64
66
  tagsToIntercept: ['release'],
65
67
  filterOutputs: async (
66
68
  s: StorageKnex,
@@ -71,16 +73,24 @@ const basketToSpecOp: Record<string, SpecOp> = {
71
73
  ): Promise<TableOutput[]> => {
72
74
  const filteredOutputs: TableOutput[] = []
73
75
  for (const o of outputs) {
74
- let ok = false
76
+ await s.validateOutputScript(o)
77
+ let ok: boolean | undefined = false
78
+ let r: sdk.GetUtxoStatusResult
75
79
  if (o.lockingScript && o.lockingScript.length > 0) {
76
- const r = await s.getServices().getUtxoStatus(asString(o.lockingScript), 'script')
80
+ r = await s.getServices().getUtxoStatus(asString(o.lockingScript), 'script')
77
81
  if (r.status === 'success' && r.isUtxo && r.details?.length > 0) {
78
82
  if (r.details.some(d => d.txid === o.txid && d.satoshis === o.satoshis && d.index === o.vout)) {
79
83
  ok = true
84
+ } else {
85
+ ok = undefined
80
86
  }
87
+ } else {
88
+ ok = false
81
89
  }
90
+ } else {
91
+ ok = undefined
82
92
  }
83
- if (!ok) {
93
+ if (ok === false) {
84
94
  filteredOutputs.push(o)
85
95
  }
86
96
  }
@@ -198,7 +198,7 @@ export class StorageMySQLDojoReader extends StorageReader implements sdk.WalletS
198
198
  reference: forceToBase64(d.referenceNumber),
199
199
  isOutgoing: !!d.isOutgoing,
200
200
  satoshis: verifyInteger(d.amount),
201
- description: verifyTruthy(d.note || ''),
201
+ description: verifyTruthy(d.note || '12345'),
202
202
  provenTxId: verifyOptionalInteger(d.provenTxId),
203
203
  version: verifyOptionalInteger(d.version),
204
204
  lockTime: verifyOptionalInteger(d.lockTime),
@@ -29,51 +29,53 @@ import { _tu, TestWalletNoSetup } from '../../utils/TestUtilsWalletStorage'
29
29
  import { monitorEventLoopDelay } from 'perf_hooks'
30
30
  import { specOpInvalidChange, validateCreateActionArgs, ValidCreateActionArgs } from '../../../src/sdk'
31
31
 
32
+ const chain: sdk.Chain = 'test'
32
33
  const setActiveClient = true
33
- const useMySQLConnectionForClient = true
34
+ const useMySQLConnectionForClient = false
35
+ const useTestIdentityKey = true
36
+ const useIdentityKey2 = false
34
37
 
35
38
  describe('localWallet tests', () => {
36
39
  jest.setTimeout(99999999)
37
40
 
38
41
  test('00', () => {})
39
- if (_tu.noTestEnv('test')) return
40
- if (_tu.noTestEnv('main')) return
42
+ if (_tu.noTestEnv(chain)) return
41
43
 
42
44
  test('0 monitor runOnce', async () => {
43
- const setup = await createSetup('test')
45
+ const setup = await createSetup(chain)
44
46
  await setup.monitor.runOnce()
45
47
  await setup.wallet.destroy()
46
48
  })
47
49
 
48
50
  test('1 recover 1 sat outputs', async () => {
49
- const setup = await createSetup('test')
51
+ const setup = await createSetup(chain)
50
52
  await recoverOneSatTestOutputs(setup)
51
53
  await setup.wallet.destroy()
52
54
  })
53
55
 
54
56
  test('2 create 1 sat delayed', async () => {
55
- const setup = await createSetup('test')
57
+ const setup = await createSetup(chain)
56
58
  const car = await createOneSatTestOutput(setup, {}, 1)
57
59
  //await trackReqByTxid(setup, car.txid!)
58
60
  await setup.wallet.destroy()
59
61
  })
60
62
 
61
63
  test('2a create 1 sat immediate', async () => {
62
- const setup = await createSetup('test')
64
+ const setup = await createSetup(chain)
63
65
  const car = await createOneSatTestOutput(setup, { acceptDelayedBroadcast: false }, 1)
64
66
  // await trackReqByTxid(setup, car.txid!)
65
67
  await setup.wallet.destroy()
66
68
  })
67
69
 
68
70
  test('2b create 2 nosend and sendWith', async () => {
69
- const setup = await createSetup('test')
71
+ const setup = await createSetup(chain)
70
72
  const car = await createOneSatTestOutput(setup, { noSend: true }, 2)
71
73
  //await trackReqByTxid(setup, car.txid!)
72
74
  await setup.wallet.destroy()
73
75
  })
74
76
 
75
77
  test('3 return active to cloud client', async () => {
76
- const setup = await createSetup('test')
78
+ const setup = await createSetup(chain)
77
79
  const localBalance = await setup.wallet.balance()
78
80
  const log = await setup.storage.setActive(setup.clientStorageIdentityKey!)
79
81
  console.log(log)
@@ -84,10 +86,9 @@ describe('localWallet tests', () => {
84
86
  })
85
87
 
86
88
  test('4 review change utxos', async () => {
87
- const setup = await createSetup('test')
89
+ const setup = await createSetup(chain)
88
90
  const lor = await setup.wallet.listOutputs({
89
- basket: specOpInvalidChange,
90
- limit: 1000
91
+ basket: specOpInvalidChange
91
92
  })
92
93
  if (lor.totalOutputs > 0) {
93
94
  debugger
@@ -112,7 +113,7 @@ describe('localWallet tests', () => {
112
113
  })
113
114
 
114
115
  test('5 review synchunk', async () => {
115
- const setup = await createSetup('test')
116
+ const setup = await createSetup(chain)
116
117
  const identityKey = setup.identityKey
117
118
  const reader = setup.activeStorage
118
119
  const readerSettings = reader.getSettings()
@@ -125,7 +126,7 @@ describe('localWallet tests', () => {
125
126
  })
126
127
 
127
128
  test('6 backup', async () => {
128
- const setup = await createSetup('test')
129
+ const setup = await createSetup(chain)
129
130
  const log = await setup.storage.updateBackups()
130
131
  console.log(log)
131
132
  await setup.wallet.destroy()
@@ -134,13 +135,26 @@ describe('localWallet tests', () => {
134
135
 
135
136
  async function createSetup(chain: sdk.Chain): Promise<TestWalletNoSetup> {
136
137
  const env = _tu.getEnv(chain)
137
- if (!env.testIdentityKey) throw new sdk.WERR_INVALID_PARAMETER('env.testIdentityKey', 'valid')
138
- if (!env.testFilePath) throw new sdk.WERR_INVALID_PARAMETER('env.testFilePath', 'valid')
138
+ let identityKey: string | undefined
139
+ let filePath: string | undefined
140
+ if (useTestIdentityKey) {
141
+ identityKey = env.testIdentityKey
142
+ filePath = env.testFilePath
143
+ } else {
144
+ if (useIdentityKey2) {
145
+ identityKey = env.identityKey2
146
+ } else {
147
+ identityKey = env.identityKey
148
+ filePath = env.filePath
149
+ }
150
+ }
151
+ if (!identityKey) throw new sdk.WERR_INVALID_PARAMETER('identityKey', 'valid')
152
+ if (!filePath) filePath = `./backup-${chain}-${identityKey}.sqlite`
139
153
 
140
154
  const setup = await _tu.createTestWallet({
141
155
  chain,
142
- rootKeyHex: env.devKeys[env.testIdentityKey],
143
- filePath: env.testFilePath,
156
+ rootKeyHex: env.devKeys[identityKey],
157
+ filePath,
144
158
  setActiveClient,
145
159
  addLocalBackup: false,
146
160
  useMySQLConnectionForClient
@@ -8,8 +8,8 @@ import { StorageMySQLDojoReader } from '../../../src/storage/sync'
8
8
  import { _tu, TestSetup1Wallet } from '../../utils/TestUtilsWalletStorage'
9
9
 
10
10
  import * as dotenv from 'dotenv'
11
-
12
11
  dotenv.config()
12
+ const main_satoshi_shop = process.env.MAIN_SATOSHI_SHOP || ''
13
13
 
14
14
  /**
15
15
  * NOTICE: These tests are designed to chain one after the other.
@@ -64,16 +64,16 @@ describe('Wallet sync tests', () => {
64
64
  })
65
65
 
66
66
  test.skip('0a sync production dojo to local MySQL', async () => {
67
+ const chain: sdk.Chain = 'main'
68
+ const env = _tu.getEnv(chain)
67
69
  console.log('Importing from production dojo to local MySQL productiondojotone')
68
- // production faucet key
69
- const identityKey = '030b78da8101cd8929ec355c694c275fbaf4f73d4eaa104873463779cac69a2a01' // process.env.MY_MAIN_IDENTITY || ''
70
+ const identityKey = main_satoshi_shop
70
71
  const rootKeyHex = env.devKeys[identityKey]
71
- const chain: sdk.Chain = 'main'
72
72
  const connection = JSON.parse(process.env.MAIN_DOJO_CONNECTION || '')
73
73
  const readerKnex = _tu.createMySQLFromConnection(connection)
74
74
  const reader = new StorageMySQLDojoReader({ chain, knex: readerKnex })
75
75
  const writer = await _tu.createMySQLTestWallet({
76
- databaseName: 'productiondojofaucet',
76
+ databaseName: 'main_satoshi_shop',
77
77
  chain: 'main',
78
78
  rootKeyHex,
79
79
  dropAll: true
@@ -85,23 +85,23 @@ describe('Wallet sync tests', () => {
85
85
  await writer.activeStorage.destroy()
86
86
  })
87
87
 
88
- test.skip('0b sweep mysql dojo sync to new sqlite', async () => {
88
+ test.skip('0b sweep mysql dojo sync to another wallet', async () => {
89
89
  const chain: sdk.Chain = 'main'
90
- const identityKey = '030b78da8101cd8929ec355c694c275fbaf4f73d4eaa104873463779cac69a2a01' // prod faucet
91
- //const identityKeyTone = process.env.MY_MAIN_IDENTITY || ''
90
+ const env = _tu.getEnv(chain)
91
+ // const prod_faucet = '030b78da8101cd8929ec355c694c275fbaf4f73d4eaa104873463779cac69a2a01' // prod faucet
92
+ // const identityKeyTone = process.env.MY_MAIN_IDENTITY || ''
93
+ const identityKey = main_satoshi_shop
92
94
  const rootKeyHex = env.devKeys[identityKey]
93
95
 
94
96
  const sweepFrom = await _tu.createMySQLTestWallet({
95
- databaseName: 'productiondojofaucet',
97
+ databaseName: 'main_satoshi_shop',
96
98
  chain,
97
99
  rootKeyHex
98
100
  })
99
101
 
100
- const sweepTo = await _tu.createSQLiteTestWallet({
101
- filePath: '/Users/tone/Kz/tone42.sqlite',
102
- databaseName: 'tone42',
103
- chain,
104
- rootKeyHex
102
+ const sweepTo = await _tu.createTestWalletWithStorageClient({
103
+ rootKeyHex: env.devKeys[env.identityKey],
104
+ chain
105
105
  })
106
106
 
107
107
  //await sweepTo.activeStorage.updateProvenTxReq(2, { status: 'invalid' })