@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.
- package/docs/README.md +1 -1
- package/docs/client.md +714 -470
- package/docs/monitor.md +54 -37
- package/docs/services.md +53 -34
- package/docs/setup.md +326 -53
- package/docs/storage.md +116 -104
- package/docs/wallet.md +713 -470
- package/license.md +28 -1
- package/out/src/Setup.d.ts +27 -3
- package/out/src/Setup.d.ts.map +1 -1
- package/out/src/Setup.js +17 -5
- package/out/src/Setup.js.map +1 -1
- package/out/src/SetupClient.d.ts +130 -15
- package/out/src/SetupClient.d.ts.map +1 -1
- package/out/src/SetupClient.js +29 -15
- package/out/src/SetupClient.js.map +1 -1
- package/out/src/Wallet.d.ts +4 -0
- package/out/src/Wallet.d.ts.map +1 -1
- package/out/src/Wallet.js +7 -0
- package/out/src/Wallet.js.map +1 -1
- package/out/src/sdk/WalletError.d.ts +0 -1
- package/out/src/sdk/WalletError.d.ts.map +1 -1
- package/out/src/sdk/WalletError.js +0 -1
- package/out/src/sdk/WalletError.js.map +1 -1
- package/out/src/sdk/validationHelpers.d.ts +1 -0
- package/out/src/sdk/validationHelpers.d.ts.map +1 -1
- package/out/src/sdk/validationHelpers.js +2 -1
- package/out/src/sdk/validationHelpers.js.map +1 -1
- package/out/src/storage/StorageProvider.d.ts +1 -4
- package/out/src/storage/StorageProvider.d.ts.map +1 -1
- package/out/src/storage/StorageProvider.js +1 -4
- package/out/src/storage/StorageProvider.js.map +1 -1
- package/out/src/storage/WalletStorageManager.d.ts +1 -1
- package/out/src/storage/WalletStorageManager.js +1 -1
- package/out/src/storage/methods/createAction.d.ts.map +1 -1
- package/out/src/storage/methods/createAction.js +42 -11
- package/out/src/storage/methods/createAction.js.map +1 -1
- package/out/src/storage/methods/generateChange.js +1 -1
- package/out/src/storage/methods/generateChange.js.map +1 -1
- package/out/src/storage/methods/listOutputs.d.ts.map +1 -1
- package/out/src/storage/methods/listOutputs.js +4 -2
- package/out/src/storage/methods/listOutputs.js.map +1 -1
- package/out/src/storage/schema/tables/ProvenTxReq.d.ts +4 -4
- package/out/src/utility/ScriptTemplateSABPPP.d.ts +4 -0
- package/out/src/utility/ScriptTemplateSABPPP.d.ts.map +1 -1
- package/out/src/utility/ScriptTemplateSABPPP.js +4 -0
- package/out/src/utility/ScriptTemplateSABPPP.js.map +1 -1
- package/out/test/examples/README.man.test.js +1 -1
- package/out/test/utils/TestUtilsWalletStorage.d.ts +2 -1
- package/out/test/utils/TestUtilsWalletStorage.d.ts.map +1 -1
- package/out/test/utils/TestUtilsWalletStorage.js +112 -27
- package/out/test/utils/TestUtilsWalletStorage.js.map +1 -1
- package/out/test/wallet/action/createAction.test.js +31 -5
- package/out/test/wallet/action/createAction.test.js.map +1 -1
- package/out/test/wallet/action/createAction2.test.d.ts +37 -0
- package/out/test/wallet/action/createAction2.test.d.ts.map +1 -0
- package/out/test/wallet/action/createAction2.test.js +1145 -0
- package/out/test/wallet/action/createAction2.test.js.map +1 -0
- package/out/test/wallet/list/listOutputs.test.js +8 -12
- package/out/test/wallet/list/listOutputs.test.js.map +1 -1
- package/out/tsconfig.all.tsbuildinfo +1 -1
- package/package.json +2 -2
- package/src/Setup.ts +29 -5
- package/src/SetupClient.ts +136 -22
- package/src/Wallet.ts +9 -0
- package/src/sdk/WalletError.ts +0 -1
- package/src/sdk/validationHelpers.ts +3 -1
- package/src/storage/StorageProvider.ts +1 -4
- package/src/storage/WalletStorageManager.ts +1 -1
- package/src/storage/methods/createAction.ts +48 -12
- package/src/storage/methods/generateChange.ts +1 -1
- package/src/storage/methods/listOutputs.ts +4 -2
- package/src/storage/schema/tables/ProvenTxReq.ts +4 -4
- package/src/utility/ScriptTemplateSABPPP.ts +4 -0
- package/test/examples/README.man.test.ts +1 -1
- package/test/utils/TestUtilsWalletStorage.ts +131 -35
- package/test/wallet/action/createAction.test.ts +36 -5
- package/test/wallet/action/createAction2.test.ts +1400 -0
- package/test/wallet/list/listOutputs.test.ts +7 -13
- package/ts2md.json +6 -6
- package/tsconfig.all.json +1 -1
- package/LICENSE.txt +0 -28
- package/dev.sqlite3 +0 -0
- 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.
|
|
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 =
|
|
2012
|
-
|
|
2013
|
-
|
|
2014
|
-
|
|
2015
|
-
log += `
|
|
2016
|
-
|
|
2017
|
-
|
|
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
|
-
|
|
2020
|
-
log +=
|
|
2021
|
-
|
|
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
|
-
|
|
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 =
|
|
2033
|
-
log += `
|
|
2034
|
-
log += `
|
|
2035
|
-
log += `
|
|
2036
|
-
log += `
|
|
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
|
|
2075
|
+
const baskets = await storage.findOutputBaskets({
|
|
2039
2076
|
partial: { basketId: output.basketId }
|
|
2040
2077
|
})
|
|
2041
|
-
|
|
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
|
|
2105
|
+
export async function logInput(
|
|
2047
2106
|
storage: StorageKnex,
|
|
2048
|
-
|
|
2049
|
-
|
|
2050
|
-
|
|
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
|
-
|
|
19
|
+
let ctxs: TestWalletNoSetup[]
|
|
20
20
|
|
|
21
|
-
|
|
21
|
+
beforeEach(async () => {
|
|
22
|
+
ctxs = []
|
|
22
23
|
if (env.runMySQL)
|
|
23
24
|
ctxs.push(await _tu.createLegacyWalletMySQLCopy('createActionTests'))
|
|
24
|
-
ctxs.push(await _tu.createLegacyWalletSQLiteCopy(
|
|
25
|
+
ctxs.push(await _tu.createLegacyWalletSQLiteCopy(`${testName()}`))
|
|
25
26
|
_tu.mockPostServicesAsSuccess(ctxs)
|
|
26
27
|
})
|
|
27
28
|
|
|
28
|
-
|
|
29
|
+
afterEach(async () => {
|
|
29
30
|
for (const ctx of ctxs) {
|
|
30
31
|
await ctx.storage.destroy()
|
|
31
32
|
}
|
|
32
33
|
})
|
|
33
|
-
|
|
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'
|