@bsv/wallet-toolbox 1.1.4 → 1.1.6

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 (84) hide show
  1. package/docs/README.md +1 -1
  2. package/docs/client.md +714 -470
  3. package/docs/monitor.md +54 -37
  4. package/docs/services.md +53 -34
  5. package/docs/setup.md +326 -53
  6. package/docs/storage.md +116 -104
  7. package/docs/wallet.md +713 -470
  8. package/license.md +28 -1
  9. package/out/src/Setup.d.ts +27 -3
  10. package/out/src/Setup.d.ts.map +1 -1
  11. package/out/src/Setup.js +17 -5
  12. package/out/src/Setup.js.map +1 -1
  13. package/out/src/SetupClient.d.ts +130 -15
  14. package/out/src/SetupClient.d.ts.map +1 -1
  15. package/out/src/SetupClient.js +29 -15
  16. package/out/src/SetupClient.js.map +1 -1
  17. package/out/src/Wallet.d.ts +4 -0
  18. package/out/src/Wallet.d.ts.map +1 -1
  19. package/out/src/Wallet.js +7 -0
  20. package/out/src/Wallet.js.map +1 -1
  21. package/out/src/sdk/WalletError.d.ts +0 -1
  22. package/out/src/sdk/WalletError.d.ts.map +1 -1
  23. package/out/src/sdk/WalletError.js +0 -1
  24. package/out/src/sdk/WalletError.js.map +1 -1
  25. package/out/src/sdk/validationHelpers.d.ts +1 -0
  26. package/out/src/sdk/validationHelpers.d.ts.map +1 -1
  27. package/out/src/sdk/validationHelpers.js +2 -1
  28. package/out/src/sdk/validationHelpers.js.map +1 -1
  29. package/out/src/storage/StorageProvider.d.ts +1 -4
  30. package/out/src/storage/StorageProvider.d.ts.map +1 -1
  31. package/out/src/storage/StorageProvider.js +1 -4
  32. package/out/src/storage/StorageProvider.js.map +1 -1
  33. package/out/src/storage/WalletStorageManager.d.ts +1 -1
  34. package/out/src/storage/WalletStorageManager.js +1 -1
  35. package/out/src/storage/methods/createAction.d.ts.map +1 -1
  36. package/out/src/storage/methods/createAction.js +42 -11
  37. package/out/src/storage/methods/createAction.js.map +1 -1
  38. package/out/src/storage/methods/generateChange.js +1 -1
  39. package/out/src/storage/methods/generateChange.js.map +1 -1
  40. package/out/src/storage/methods/listOutputs.d.ts.map +1 -1
  41. package/out/src/storage/methods/listOutputs.js +4 -2
  42. package/out/src/storage/methods/listOutputs.js.map +1 -1
  43. package/out/src/storage/schema/tables/ProvenTxReq.d.ts +4 -4
  44. package/out/src/utility/ScriptTemplateSABPPP.d.ts +4 -0
  45. package/out/src/utility/ScriptTemplateSABPPP.d.ts.map +1 -1
  46. package/out/src/utility/ScriptTemplateSABPPP.js +4 -0
  47. package/out/src/utility/ScriptTemplateSABPPP.js.map +1 -1
  48. package/out/test/examples/README.man.test.js +1 -1
  49. package/out/test/utils/TestUtilsWalletStorage.d.ts +2 -1
  50. package/out/test/utils/TestUtilsWalletStorage.d.ts.map +1 -1
  51. package/out/test/utils/TestUtilsWalletStorage.js +112 -27
  52. package/out/test/utils/TestUtilsWalletStorage.js.map +1 -1
  53. package/out/test/wallet/action/createAction.test.js +31 -5
  54. package/out/test/wallet/action/createAction.test.js.map +1 -1
  55. package/out/test/wallet/action/createAction2.test.d.ts +37 -0
  56. package/out/test/wallet/action/createAction2.test.d.ts.map +1 -0
  57. package/out/test/wallet/action/createAction2.test.js +1145 -0
  58. package/out/test/wallet/action/createAction2.test.js.map +1 -0
  59. package/out/test/wallet/list/listOutputs.test.js +8 -12
  60. package/out/test/wallet/list/listOutputs.test.js.map +1 -1
  61. package/out/tsconfig.all.tsbuildinfo +1 -1
  62. package/package.json +2 -2
  63. package/src/Setup.ts +29 -5
  64. package/src/SetupClient.ts +136 -22
  65. package/src/Wallet.ts +9 -0
  66. package/src/sdk/WalletError.ts +0 -1
  67. package/src/sdk/validationHelpers.ts +3 -1
  68. package/src/storage/StorageProvider.ts +1 -4
  69. package/src/storage/WalletStorageManager.ts +1 -1
  70. package/src/storage/methods/createAction.ts +48 -12
  71. package/src/storage/methods/generateChange.ts +1 -1
  72. package/src/storage/methods/listOutputs.ts +4 -2
  73. package/src/storage/schema/tables/ProvenTxReq.ts +4 -4
  74. package/src/utility/ScriptTemplateSABPPP.ts +4 -0
  75. package/test/examples/README.man.test.ts +1 -1
  76. package/test/utils/TestUtilsWalletStorage.ts +131 -35
  77. package/test/wallet/action/createAction.test.ts +36 -5
  78. package/test/wallet/action/createAction2.test.ts +1400 -0
  79. package/test/wallet/list/listOutputs.test.ts +7 -13
  80. package/ts2md.json +6 -6
  81. package/tsconfig.all.json +1 -1
  82. package/LICENSE.txt +0 -28
  83. package/dev.sqlite3 +0 -0
  84. package/knexfile.js +0 -9
@@ -11,7 +11,7 @@ describe('examples README tests', () => {
11
11
  it('1 internalize wallet payment', async () => {
12
12
  const env = Setup.getEnv('test')
13
13
 
14
- const { wallet } = await Setup.createSQLiteWallet({
14
+ const { wallet } = await Setup.createWalletSQLite({
15
15
  env,
16
16
  filePath: './myTestWallet.sqlite',
17
17
  databaseName: 'myTestWallet'
@@ -2008,20 +2008,54 @@ export async function logTransaction(
2008
2008
  txid: HexString
2009
2009
  ): Promise<string> {
2010
2010
  let amount: SatoshiValue = 0
2011
- let log = `txid: ${txid}\n`
2012
- const rt = await storage.findTransactions({ partial: { txid } })
2013
- for (const t of rt) {
2014
- log += `status: ${t.status}\n`
2015
- log += `description: ${t.description}\n`
2016
- const ro = await storage.findOutputs({
2017
- partial: { transactionId: t.transactionId }
2011
+ let log = `\n==== Transaction Log ====\ntxid: ${txid}\n`
2012
+
2013
+ const transactions = await storage.findTransactions({ partial: { txid } })
2014
+ for (const tx of transactions) {
2015
+ log += `Status: ${tx.status}\n`
2016
+ log += `Description: ${tx.description}\n`
2017
+
2018
+ const txLabelMaps = await storage.findTxLabelMaps({
2019
+ partial: { transactionId: tx.transactionId }
2018
2020
  })
2019
- for (const o of ro) {
2020
- log += `${await logOutput(storage, o)}`
2021
- amount += o.spendable ? o.satoshis : 0
2021
+ if (txLabelMaps.length > 0) {
2022
+ log += `Labels:\n`
2023
+ for (const txLabelMap of txLabelMaps) {
2024
+ const labels = await storage.findTxLabels({
2025
+ partial: { txLabelId: txLabelMap.txLabelId }
2026
+ })
2027
+ if (labels.length > 0) {
2028
+ log += ` - ${labels[0].label}\n`
2029
+ }
2030
+ }
2031
+ } else {
2032
+ log += `Labels: N/A\n`
2033
+ }
2034
+
2035
+ const inputs = await storage.findOutputs({
2036
+ partial: { transactionId: tx.transactionId }
2037
+ })
2038
+ for (const input of inputs) {
2039
+ log += await logInput(storage, input.txid!, input.vout)
2040
+ }
2041
+
2042
+ const outputs = await storage.findOutputs({
2043
+ partial: { transactionId: tx.transactionId }
2044
+ })
2045
+ for (const output of outputs) {
2046
+ log += await logOutput(storage, output)
2047
+ amount += output.spendable ? output.satoshis : 0
2048
+ }
2049
+
2050
+ const beef = await storage.getBeefForTransaction(txid, {})
2051
+ if (beef) {
2052
+ log += `Beef Data:\n${beef.toLogString()}\n${beef.toHex()}\n`
2053
+ } else {
2054
+ log += `Beef Data: N/A\n`
2022
2055
  }
2023
2056
  }
2024
- log += `------------------\namount: ${amount}\n`
2057
+
2058
+ log += `-------------\nTotal Amount: ${amount} satoshis\n=============\n`
2025
2059
  return log
2026
2060
  }
2027
2061
 
@@ -2029,28 +2063,103 @@ export async function logOutput(
2029
2063
  storage: StorageKnex,
2030
2064
  output: table.Output
2031
2065
  ): Promise<string> {
2032
- let log = `satoshis: ${output.satoshis}\n`
2033
- log += `spendable: ${output.spendable}\n`
2034
- log += `change: ${output.change}\n`
2035
- log += `providedBy: ${output.providedBy}\n`
2036
- log += `spentBy: ${output.providedBy}\n`
2066
+ let log = `\n-- Output --\n`
2067
+ log += `Outpoint: ${output.txid}:${output.vout}\n`
2068
+ log += `Satoshis: ${output.satoshis}\n`
2069
+ log += `Spendable: ${output.spendable}\n`
2070
+ log += `Change: ${output.change}\n`
2071
+ log += `Provided By: ${output.providedBy}\n`
2072
+ log += `Spent By: ${output.spentBy ?? 'Unspent'}\n`
2073
+
2037
2074
  if (output.basketId) {
2038
- const rb = await storage.findOutputBaskets({
2075
+ const baskets = await storage.findOutputBaskets({
2039
2076
  partial: { basketId: output.basketId }
2040
2077
  })
2041
- log += `basket:${await logBasket(storage, rb[0])}\n`
2078
+ if (baskets.length === 1) {
2079
+ log += `Basket: ${logBasket(baskets[0])}\n`
2080
+ } else {
2081
+ log += '*** PROBLEM WITH BASKET ***'
2082
+ }
2042
2083
  }
2084
+
2085
+ const outputTags = await storage.findOutputTagMaps({
2086
+ partial: { outputId: output.outputId }
2087
+ })
2088
+ if (outputTags.length > 0) {
2089
+ log += `Tags:\n`
2090
+ for (const outputTag of outputTags) {
2091
+ const tags = await storage.findOutputTags({
2092
+ partial: { outputTagId: outputTag.outputTagId }
2093
+ })
2094
+ if (tags.length > 0) {
2095
+ log += ` - ${tags[0].tag}\n`
2096
+ }
2097
+ }
2098
+ } else {
2099
+ log += `Tags: N/A\n`
2100
+ }
2101
+
2043
2102
  return log
2044
2103
  }
2045
2104
 
2046
- export function logBasket(
2105
+ export async function logInput(
2047
2106
  storage: StorageKnex,
2048
- basket: table.OutputBasket
2049
- ): string {
2050
- let log = `${basket.name}\n`
2107
+ prevOutputTxid: HexString,
2108
+ prevOutputVout: number,
2109
+ indentLevel = 1
2110
+ ): Promise<string> {
2111
+ const indent = ' '.repeat(indentLevel)
2112
+ let log = `\n${indent}-- Input (Previous Output) --\n`
2113
+
2114
+ const prevOutputs = await storage.findOutputs({
2115
+ partial: { txid: prevOutputTxid, vout: prevOutputVout }
2116
+ })
2117
+
2118
+ if (prevOutputs.length === 0) {
2119
+ log += `${indent}Previous Output Not Found (Outpoint: ${prevOutputTxid}:${prevOutputVout})\n`
2120
+ return log
2121
+ }
2122
+
2123
+ for (const prevOutput of prevOutputs) {
2124
+ const outpoint = `${prevOutputTxid}:${prevOutput.vout}`
2125
+
2126
+ log += `${indent}Source Outpoint: ${outpoint}\n`
2127
+ log += `${indent}Satoshis: ${prevOutput.satoshis}\n`
2128
+ log += `${indent}Spendable: ${prevOutput.spendable}\n`
2129
+ log += `${indent}Change: ${prevOutput.change}\n`
2130
+ log += `${indent}Provided By: ${prevOutput.providedBy}\n`
2131
+ log += `${indent}Spent By: ${prevOutput.spentBy ?? 'Unspent'}\n`
2132
+ log += `${indent}Locking Script: ${prevOutput.lockingScript}\n`
2133
+
2134
+ // If this output was spent, recursively log its inputs
2135
+ if (prevOutput.spentBy) {
2136
+ const spendingTx = await storage.findTransactions({
2137
+ partial: { transactionId: prevOutput.spentBy }
2138
+ })
2139
+
2140
+ if (spendingTx.length > 0) {
2141
+ const spentByTxid = spendingTx[0].txid
2142
+
2143
+ log += `${indent} ↳ Spent By TXID: ${spentByTxid}\n`
2144
+ log += await logInput(
2145
+ storage,
2146
+ spentByTxid!,
2147
+ prevOutput.vout,
2148
+ indentLevel + 2
2149
+ )
2150
+ } else {
2151
+ log += `${indent} ↳ Spent By TXID Unknown (transactionId: ${prevOutput.spentBy})\n`
2152
+ }
2153
+ }
2154
+ }
2155
+
2051
2156
  return log
2052
2157
  }
2053
2158
 
2159
+ export function logBasket(basket: table.OutputBasket): string {
2160
+ return `\n-- Basket --\nName: ${basket.name}\n`
2161
+ }
2162
+
2054
2163
  export function hexStringToNumberArray(hexString: string): number[] {
2055
2164
  const sanitizedHex = hexString.replace(/[^a-fA-F0-9]/g, '')
2056
2165
  const result: number[] = []
@@ -2059,16 +2168,3 @@ export function hexStringToNumberArray(hexString: string): number[] {
2059
2168
  }
2060
2169
  return result
2061
2170
  }
2062
-
2063
- async function getOutputByTxIdAndVout(
2064
- storage: StorageProvider,
2065
- txid: string,
2066
- vout: number
2067
- ): Promise<table.Output | null> {
2068
- const results = await storage.findOutputs({
2069
- partial: { txid }
2070
- })
2071
-
2072
- // Return the first matching result or null if no match is found
2073
- return results.length > 0 ? results[0] : null
2074
- }
@@ -16,21 +16,23 @@ describe('createAction test', () => {
16
16
  const env = _tu.getEnv('test')
17
17
  const testName = () => expect.getState().currentTestName || 'test'
18
18
 
19
- const ctxs: TestWalletNoSetup[] = []
19
+ let ctxs: TestWalletNoSetup[]
20
20
 
21
- beforeAll(async () => {
21
+ beforeEach(async () => {
22
+ ctxs = []
22
23
  if (env.runMySQL)
23
24
  ctxs.push(await _tu.createLegacyWalletMySQLCopy('createActionTests'))
24
- ctxs.push(await _tu.createLegacyWalletSQLiteCopy('createActionTests'))
25
+ ctxs.push(await _tu.createLegacyWalletSQLiteCopy(`${testName()}`))
25
26
  _tu.mockPostServicesAsSuccess(ctxs)
26
27
  })
27
28
 
28
- afterAll(async () => {
29
+ afterEach(async () => {
29
30
  for (const ctx of ctxs) {
30
31
  await ctx.storage.destroy()
31
32
  }
32
33
  })
33
- test('1_invalid_params', async () => {
34
+
35
+ test('0_invalid_params', async () => {
34
36
  for (const { wallet } of ctxs) {
35
37
  {
36
38
  const log = `\n${testName()}\n`
@@ -64,6 +66,35 @@ describe('createAction test', () => {
64
66
  }
65
67
  })
66
68
 
69
+ test('1_repeatable txid', async () => {
70
+ for (const { wallet } of ctxs) {
71
+ wallet.randomVals = [0.1, 0.2, 0.3, 0.7, 0.8, 0.9]
72
+ const root = '02135476'
73
+ const kp = _tu.getKeyPair(root.repeat(8))
74
+ const createArgs: CreateActionArgs = {
75
+ description: `repeatable`,
76
+ outputs: [
77
+ {
78
+ satoshis: 45,
79
+ lockingScript: _tu.getLockP2PKH(kp.address).toHex(),
80
+ outputDescription: 'pay echo'
81
+ }
82
+ ],
83
+ options: {
84
+ randomizeOutputs: false,
85
+ signAndProcess: true,
86
+ noSend: true
87
+ }
88
+ }
89
+
90
+ const cr = await wallet.createAction(createArgs)
91
+ expect(
92
+ cr.txid ===
93
+ '4f428a93c43c2d120204ecdc06f7916be8a5f4542cc8839a0fd79bd1b44582f3'
94
+ )
95
+ }
96
+ })
97
+
67
98
  test('2_signableTransaction', async () => {
68
99
  for (const { wallet } of ctxs) {
69
100
  const root = '02135476'