smartledger-bsv 3.3.2 → 3.3.3
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/CHANGELOG.md +211 -83
- package/README.md +266 -71
- package/bsv-covenant.min.js +26 -3
- package/bsv-gdaf.min.js +11 -9
- package/bsv-ltp.min.js +10 -8
- package/bsv-script-helper.min.js +2 -2
- package/bsv-security.min.js +3 -24
- package/bsv-shamir.min.js +2 -2
- package/bsv-smartcontract.min.js +10 -8
- package/bsv.bundle.js +9 -9
- package/bsv.min.js +10 -8
- package/build/webpack.bundle.config.js +2 -2
- package/build/webpack.config.js +2 -2
- package/build/webpack.covenant.config.js +2 -2
- package/build/webpack.gdaf.config.js +6 -43
- package/build/webpack.script-helper.config.js +2 -2
- package/build/webpack.security.config.js +2 -2
- package/build/webpack.smartcontract.config.js +2 -2
- package/bundle-entry.js +1 -341
- package/covenant-entry.js +1 -44
- package/docs/DOCUMENTATION_REVIEW_REPORT.md +295 -0
- package/docs/MODULE_REFERENCE_COMPLETE.md +330 -0
- package/docs/README.md +107 -79
- package/docs/advanced/LEGAL_TOKEN_PROTOCOL.md +411 -0
- package/docs/advanced/SMART_CONTRACT_GUIDE.md +1255 -0
- package/docs/advanced/UTXO_MANAGER_GUIDE.md +851 -0
- package/docs/api/LTP.md +334 -0
- package/docs/getting-started/INSTALLATION.md +410 -0
- package/docs/getting-started/QUICK_START.md +180 -0
- package/docs/migration/FROM_BSV_1_5_6.md +260 -0
- package/docs/technical/GDAF_DEVELOPER_INTERFACE.md +187 -0
- package/docs/technical/GDAF_IMPLEMENTATION_COMPLETE.md +190 -0
- package/docs/technical/SHAMIR_INTEGRATION_SUMMARY.md +165 -0
- package/docs/technical/roadmap.md +1250 -0
- package/docs/technical/trust_law.md +142 -0
- package/gdaf-entry.js +2 -54
- package/index.js +32 -0
- package/ltp-entry.js +2 -92
- package/package.json +5 -3
- package/script-helper-entry.js +1 -49
- package/security-entry.js +1 -70
- package/shamir-entry.js +1 -173
- package/smartcontract-entry.js +1 -133
- package/tests/test_builtin_verify.js +117 -0
- package/tests/test_debug_integration.js +71 -0
- package/tests/test_ecdsa_little.js +70 -0
- package/tests/test_smartverify_der.js +110 -0
- package/utilities/blockchain-state.js +155 -155
- package/utilities/blockchain-state.json +103293 -5244
- package/utilities/miner-simulator.js +354 -358
- package/utilities/mock-utxo-generator.js +54 -54
- package/utilities/raw-tx-examples.js +120 -122
- package/utilities/success-demo.js +104 -105
- package/utilities/transaction-examples.js +188 -188
- package/utilities/utxo-manager.js +91 -91
- package/utilities/wallet-setup.js +79 -80
- package/utilities/working-signature-demo.js +108 -110
- package/SECURITY.md +0 -75
- package/architecture_demo.js +0 -247
- package/build/bsv-covenant.min.js +0 -10
- package/build/bsv-script-helper.min.js +0 -10
- package/build/bsv-security.min.js +0 -31
- package/build/bsv-smartcontract.min.js +0 -39
- package/build/bsv.bundle.js +0 -39
- package/build/bsv.min.js +0 -39
- package/complete_ltp_demo.js +0 -511
- package/shamir_demo.js +0 -121
- package/simple_demo.js +0 -204
- package/validation_test.js +0 -97
- /package/docs/{ADVANCED_COVENANT_DEVELOPMENT.md → advanced/ADVANCED_COVENANT_DEVELOPMENT.md} +0 -0
- /package/docs/{CUSTOM_SCRIPT_DEVELOPMENT.md → advanced/CUSTOM_SCRIPT_DEVELOPMENT.md} +0 -0
- /package/docs/{block.md → api/BLOCKS.md} +0 -0
- /package/docs/{ecies.md → api/ECIES.md} +0 -0
- /package/docs/{networks.md → api/NETWORKS.md} +0 -0
- /package/docs/{script.md → api/SCRIPTS.md} +0 -0
- /package/docs/{transaction.md → api/TRANSACTIONS.md} +0 -0
- /package/docs/{unspentoutput.md → api/UTXO.md} +0 -0
- /package/{test_shamir.js → tests/test_shamir.js} +0 -0
- /package/{test_standalone_shamir.html → tests/test_standalone_shamir.html} +0 -0
|
@@ -2,61 +2,61 @@
|
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
4
|
* 🔄 BSV UTXO Manager
|
|
5
|
-
*
|
|
5
|
+
*
|
|
6
6
|
* Updates the wallet.json file with new UTXOs after transactions.
|
|
7
7
|
* Tracks which UTXOs are spent and which are available for BSV development.
|
|
8
8
|
*/
|
|
9
9
|
|
|
10
|
-
const bsv = require('../index.js')
|
|
11
|
-
const fs = require('fs')
|
|
12
|
-
const path = require('path')
|
|
10
|
+
// const bsv = require('../index.js') // Currently unused
|
|
11
|
+
const fs = require('fs')
|
|
12
|
+
const path = require('path')
|
|
13
13
|
|
|
14
|
-
function loadConfig() {
|
|
15
|
-
const configPath = path.join(__dirname, 'wallet.json')
|
|
16
|
-
return JSON.parse(fs.readFileSync(configPath, 'utf8'))
|
|
14
|
+
function loadConfig () {
|
|
15
|
+
const configPath = path.join(__dirname, 'wallet.json')
|
|
16
|
+
return JSON.parse(fs.readFileSync(configPath, 'utf8'))
|
|
17
17
|
}
|
|
18
18
|
|
|
19
|
-
function saveConfig(config) {
|
|
20
|
-
const configPath = path.join(__dirname, 'wallet.json')
|
|
21
|
-
fs.writeFileSync(configPath, JSON.stringify(config, null, 2))
|
|
22
|
-
console.log('💾 Updated wallet.json')
|
|
19
|
+
function saveConfig (config) {
|
|
20
|
+
const configPath = path.join(__dirname, 'wallet.json')
|
|
21
|
+
fs.writeFileSync(configPath, JSON.stringify(config, null, 2))
|
|
22
|
+
console.log('💾 Updated wallet.json')
|
|
23
23
|
}
|
|
24
24
|
|
|
25
|
-
function updateUTXOFromTransaction(tx, spentUTXO = null) {
|
|
26
|
-
console.log('🔄 Updating UTXO set from transaction...\n')
|
|
27
|
-
|
|
28
|
-
const config = loadConfig()
|
|
29
|
-
|
|
30
|
-
console.log('📋 Transaction Analysis:')
|
|
31
|
-
console.log(`Transaction ID: ${tx.id}`)
|
|
32
|
-
console.log(`Inputs: ${tx.inputs.length}`)
|
|
33
|
-
console.log(`Outputs: ${tx.outputs.length}\n`)
|
|
34
|
-
|
|
25
|
+
function updateUTXOFromTransaction (tx, spentUTXO = null) {
|
|
26
|
+
console.log('🔄 Updating UTXO set from transaction...\n')
|
|
27
|
+
|
|
28
|
+
const config = loadConfig()
|
|
29
|
+
|
|
30
|
+
console.log('📋 Transaction Analysis:')
|
|
31
|
+
console.log(`Transaction ID: ${tx.id}`)
|
|
32
|
+
console.log(`Inputs: ${tx.inputs.length}`)
|
|
33
|
+
console.log(`Outputs: ${tx.outputs.length}\n`)
|
|
34
|
+
|
|
35
35
|
// Mark spent UTXO
|
|
36
36
|
if (spentUTXO) {
|
|
37
|
-
console.log('❌ Spent UTXO:')
|
|
38
|
-
console.log(` TXID: ${spentUTXO.txid}`)
|
|
39
|
-
console.log(` Vout: ${spentUTXO.vout}`)
|
|
40
|
-
console.log(` Amount: ${spentUTXO.satoshis} satoshis\n`)
|
|
41
|
-
|
|
37
|
+
console.log('❌ Spent UTXO:')
|
|
38
|
+
console.log(` TXID: ${spentUTXO.txid}`)
|
|
39
|
+
console.log(` Vout: ${spentUTXO.vout}`)
|
|
40
|
+
console.log(` Amount: ${spentUTXO.satoshis} satoshis\n`)
|
|
41
|
+
|
|
42
42
|
// Add to spent UTXOs list
|
|
43
|
-
if (!config.spentUTXOs) config.spentUTXOs = []
|
|
43
|
+
if (!config.spentUTXOs) config.spentUTXOs = []
|
|
44
44
|
config.spentUTXOs.push({
|
|
45
45
|
txid: spentUTXO.txid,
|
|
46
46
|
vout: spentUTXO.vout,
|
|
47
47
|
satoshis: spentUTXO.satoshis,
|
|
48
48
|
spentInTx: tx.id,
|
|
49
49
|
spentAt: new Date().toISOString()
|
|
50
|
-
})
|
|
50
|
+
})
|
|
51
51
|
}
|
|
52
|
-
|
|
52
|
+
|
|
53
53
|
// Add new UTXOs from outputs
|
|
54
|
-
const newUTXOs = []
|
|
55
|
-
|
|
54
|
+
const newUTXOs = []
|
|
55
|
+
|
|
56
56
|
for (let i = 0; i < tx.outputs.length; i++) {
|
|
57
|
-
const output = tx.outputs[i]
|
|
58
|
-
const outputAddress = output.script.toAddress()
|
|
59
|
-
|
|
57
|
+
const output = tx.outputs[i]
|
|
58
|
+
const outputAddress = output.script.toAddress()
|
|
59
|
+
|
|
60
60
|
// Only track UTXOs that go to our wallet address
|
|
61
61
|
if (outputAddress.toString() === config.wallet.address) {
|
|
62
62
|
const newUTXO = {
|
|
@@ -68,89 +68,89 @@ function updateUTXOFromTransaction(tx, spentUTXO = null) {
|
|
|
68
68
|
satoshis: output.satoshis,
|
|
69
69
|
address: outputAddress.toString(),
|
|
70
70
|
createdAt: new Date().toISOString()
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
newUTXOs.push(newUTXO)
|
|
74
|
-
|
|
75
|
-
console.log(`✅ New UTXO ${i}:`)
|
|
76
|
-
console.log(` TXID: ${newUTXO.txid}`)
|
|
77
|
-
console.log(` Vout: ${newUTXO.vout}`)
|
|
78
|
-
console.log(` Amount: ${newUTXO.satoshis} satoshis`)
|
|
79
|
-
console.log(` Address: ${newUTXO.address}`)
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
newUTXOs.push(newUTXO)
|
|
74
|
+
|
|
75
|
+
console.log(`✅ New UTXO ${i}:`)
|
|
76
|
+
console.log(` TXID: ${newUTXO.txid}`)
|
|
77
|
+
console.log(` Vout: ${newUTXO.vout}`)
|
|
78
|
+
console.log(` Amount: ${newUTXO.satoshis} satoshis`)
|
|
79
|
+
console.log(` Address: ${newUTXO.address}`)
|
|
80
80
|
}
|
|
81
81
|
}
|
|
82
|
-
|
|
82
|
+
|
|
83
83
|
// Update config with new UTXOs
|
|
84
|
-
if (!config.availableUTXOs) config.availableUTXOs = []
|
|
85
|
-
config.availableUTXOs = config.availableUTXOs.concat(newUTXOs)
|
|
86
|
-
|
|
84
|
+
if (!config.availableUTXOs) config.availableUTXOs = []
|
|
85
|
+
config.availableUTXOs = config.availableUTXOs.concat(newUTXOs)
|
|
86
|
+
|
|
87
87
|
// Update the main UTXO to the largest available UTXO
|
|
88
88
|
if (newUTXOs.length > 0) {
|
|
89
|
-
const largestUTXO = newUTXOs.reduce((max, utxo) =>
|
|
89
|
+
const largestUTXO = newUTXOs.reduce((max, utxo) =>
|
|
90
90
|
utxo.satoshis > max.satoshis ? utxo : max
|
|
91
|
-
)
|
|
92
|
-
|
|
93
|
-
config.utxo = largestUTXO
|
|
94
|
-
console.log(`\n🎯 Primary UTXO updated to: ${largestUTXO.satoshis} satoshis`)
|
|
91
|
+
)
|
|
92
|
+
|
|
93
|
+
config.utxo = largestUTXO
|
|
94
|
+
console.log(`\n🎯 Primary UTXO updated to: ${largestUTXO.satoshis} satoshis`)
|
|
95
95
|
}
|
|
96
|
-
|
|
96
|
+
|
|
97
97
|
// Update metadata
|
|
98
|
-
config.metadata.lastUpdated = new Date().toISOString()
|
|
99
|
-
config.metadata.transactionCount = (config.metadata.transactionCount || 0) + 1
|
|
100
|
-
|
|
101
|
-
saveConfig(config)
|
|
102
|
-
|
|
98
|
+
config.metadata.lastUpdated = new Date().toISOString()
|
|
99
|
+
config.metadata.transactionCount = (config.metadata.transactionCount || 0) + 1
|
|
100
|
+
|
|
101
|
+
saveConfig(config)
|
|
102
|
+
|
|
103
103
|
return {
|
|
104
104
|
newUTXOs,
|
|
105
105
|
totalValue: newUTXOs.reduce((sum, utxo) => sum + utxo.satoshis, 0),
|
|
106
106
|
config
|
|
107
|
-
}
|
|
107
|
+
}
|
|
108
108
|
}
|
|
109
109
|
|
|
110
|
-
function getAvailableBalance() {
|
|
111
|
-
const config = loadConfig()
|
|
112
|
-
|
|
113
|
-
const balance = config.availableUTXOs
|
|
110
|
+
function getAvailableBalance () {
|
|
111
|
+
const config = loadConfig()
|
|
112
|
+
|
|
113
|
+
const balance = config.availableUTXOs
|
|
114
114
|
? config.availableUTXOs.reduce((sum, utxo) => sum + utxo.satoshis, 0)
|
|
115
|
-
: config.utxo.satoshis
|
|
116
|
-
|
|
117
|
-
return balance
|
|
115
|
+
: config.utxo.satoshis
|
|
116
|
+
|
|
117
|
+
return balance
|
|
118
118
|
}
|
|
119
119
|
|
|
120
|
-
function listUTXOs() {
|
|
121
|
-
const config = loadConfig()
|
|
122
|
-
|
|
123
|
-
console.log('💰 Current UTXO Set:')
|
|
124
|
-
console.log('═══════════════════════════════════════════\n')
|
|
125
|
-
|
|
126
|
-
console.log('🎯 Primary UTXO:')
|
|
127
|
-
console.log(` TXID: ${config.utxo.txid}`)
|
|
128
|
-
console.log(` Vout: ${config.utxo.vout}`)
|
|
129
|
-
console.log(` Amount: ${config.utxo.satoshis} satoshis\n`)
|
|
130
|
-
|
|
120
|
+
function listUTXOs () {
|
|
121
|
+
const config = loadConfig()
|
|
122
|
+
|
|
123
|
+
console.log('💰 Current UTXO Set:')
|
|
124
|
+
console.log('═══════════════════════════════════════════\n')
|
|
125
|
+
|
|
126
|
+
console.log('🎯 Primary UTXO:')
|
|
127
|
+
console.log(` TXID: ${config.utxo.txid}`)
|
|
128
|
+
console.log(` Vout: ${config.utxo.vout}`)
|
|
129
|
+
console.log(` Amount: ${config.utxo.satoshis} satoshis\n`)
|
|
130
|
+
|
|
131
131
|
if (config.availableUTXOs && config.availableUTXOs.length > 0) {
|
|
132
|
-
console.log('📝 All Available UTXOs:')
|
|
132
|
+
console.log('📝 All Available UTXOs:')
|
|
133
133
|
config.availableUTXOs.forEach((utxo, index) => {
|
|
134
|
-
console.log(` ${index + 1}. ${utxo.txid}:${utxo.vout} - ${utxo.satoshis} sats`)
|
|
135
|
-
})
|
|
134
|
+
console.log(` ${index + 1}. ${utxo.txid}:${utxo.vout} - ${utxo.satoshis} sats`)
|
|
135
|
+
})
|
|
136
136
|
}
|
|
137
|
-
|
|
137
|
+
|
|
138
138
|
if (config.spentUTXOs && config.spentUTXOs.length > 0) {
|
|
139
|
-
console.log('\n❌ Spent UTXOs:')
|
|
139
|
+
console.log('\n❌ Spent UTXOs:')
|
|
140
140
|
config.spentUTXOs.forEach((utxo, index) => {
|
|
141
|
-
console.log(` ${index + 1}. ${utxo.txid}:${utxo.vout} - ${utxo.satoshis} sats (spent in ${utxo.spentInTx})`)
|
|
142
|
-
})
|
|
141
|
+
console.log(` ${index + 1}. ${utxo.txid}:${utxo.vout} - ${utxo.satoshis} sats (spent in ${utxo.spentInTx})`)
|
|
142
|
+
})
|
|
143
143
|
}
|
|
144
|
-
|
|
145
|
-
const totalBalance = getAvailableBalance()
|
|
146
|
-
console.log(`\n💰 Total Available Balance: ${totalBalance} satoshis`)
|
|
147
|
-
|
|
148
|
-
return config
|
|
144
|
+
|
|
145
|
+
const totalBalance = getAvailableBalance()
|
|
146
|
+
console.log(`\n💰 Total Available Balance: ${totalBalance} satoshis`)
|
|
147
|
+
|
|
148
|
+
return config
|
|
149
149
|
}
|
|
150
150
|
|
|
151
151
|
// If called directly, list current UTXOs
|
|
152
152
|
if (require.main === module) {
|
|
153
|
-
listUTXOs()
|
|
153
|
+
listUTXOs()
|
|
154
154
|
}
|
|
155
155
|
|
|
156
156
|
module.exports = {
|
|
@@ -159,4 +159,4 @@ module.exports = {
|
|
|
159
159
|
listUTXOs,
|
|
160
160
|
loadConfig,
|
|
161
161
|
saveConfig
|
|
162
|
-
}
|
|
162
|
+
}
|
|
@@ -2,34 +2,34 @@
|
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
4
|
* 🎯 BSV Wallet Setup Utility
|
|
5
|
-
*
|
|
5
|
+
*
|
|
6
6
|
* Creates a test wallet with mock UTXO for BSV development and testing.
|
|
7
7
|
* Generates a consistent environment with private keys, addresses, and UTXOs.
|
|
8
8
|
*/
|
|
9
9
|
|
|
10
|
-
const bsv = require('../index.js')
|
|
11
|
-
const fs = require('fs')
|
|
12
|
-
const path = require('path')
|
|
10
|
+
const bsv = require('../index.js')
|
|
11
|
+
const fs = require('fs')
|
|
12
|
+
const path = require('path')
|
|
13
13
|
|
|
14
14
|
// Import the mock UTXO functionality from mock-utxo-generator.js
|
|
15
|
-
function randomHex(len) {
|
|
16
|
-
const crypto = require('crypto')
|
|
17
|
-
return crypto.randomBytes(len).toString('hex')
|
|
15
|
+
function randomHex (len) {
|
|
16
|
+
const crypto = require('crypto')
|
|
17
|
+
return crypto.randomBytes(len).toString('hex')
|
|
18
18
|
}
|
|
19
19
|
|
|
20
|
-
function createMockTxId() {
|
|
21
|
-
return randomHex(32)
|
|
20
|
+
function createMockTxId () {
|
|
21
|
+
return randomHex(32)
|
|
22
22
|
}
|
|
23
23
|
|
|
24
|
-
function buildP2pkhScriptHex(address) {
|
|
25
|
-
return bsv.Script.buildPublicKeyHashOut(address).toHex()
|
|
24
|
+
function buildP2pkhScriptHex (address) {
|
|
25
|
+
return bsv.Script.buildPublicKeyHashOut(address).toHex()
|
|
26
26
|
}
|
|
27
27
|
|
|
28
|
-
function mkUtxo(privateKey, sats = 100000) {
|
|
29
|
-
const address = privateKey.toAddress().toString()
|
|
30
|
-
const txid = createMockTxId()
|
|
31
|
-
const vout = 0
|
|
32
|
-
const scriptHex = buildP2pkhScriptHex(address)
|
|
28
|
+
function mkUtxo (privateKey, sats = 100000) {
|
|
29
|
+
const address = privateKey.toAddress().toString()
|
|
30
|
+
const txid = createMockTxId()
|
|
31
|
+
const vout = 0
|
|
32
|
+
const scriptHex = buildP2pkhScriptHex(address)
|
|
33
33
|
|
|
34
34
|
return {
|
|
35
35
|
txId: txid,
|
|
@@ -40,33 +40,33 @@ function mkUtxo(privateKey, sats = 100000) {
|
|
|
40
40
|
value: sats,
|
|
41
41
|
script: scriptHex,
|
|
42
42
|
scriptPubKey: scriptHex,
|
|
43
|
-
address
|
|
44
|
-
}
|
|
43
|
+
address
|
|
44
|
+
}
|
|
45
45
|
}
|
|
46
46
|
|
|
47
|
-
function createTestWallet() {
|
|
48
|
-
console.log('🔧 Creating test wallet...\n')
|
|
47
|
+
function createTestWallet () {
|
|
48
|
+
console.log('🔧 Creating test wallet...\n')
|
|
49
49
|
|
|
50
50
|
// Generate a new private key for testing
|
|
51
|
-
const privateKey = new bsv.PrivateKey()
|
|
52
|
-
const publicKey = privateKey.toPublicKey()
|
|
53
|
-
const address = privateKey.toAddress()
|
|
51
|
+
const privateKey = new bsv.PrivateKey()
|
|
52
|
+
const publicKey = privateKey.toPublicKey()
|
|
53
|
+
const address = privateKey.toAddress()
|
|
54
54
|
|
|
55
|
-
console.log('📋 Test Wallet Details:')
|
|
56
|
-
console.log(`Private Key (WIF): ${privateKey.toWIF()}`)
|
|
57
|
-
console.log(`Private Key (Hex): ${privateKey.toString('hex')}`)
|
|
58
|
-
console.log(`Public Key: ${publicKey.toString()}`)
|
|
59
|
-
console.log(`Address: ${address.toString()}`)
|
|
60
|
-
console.log(`Pubkey Hash160: ${bsv.crypto.Hash.sha256ripemd160(publicKey.toBuffer()).toString('hex')}\n`)
|
|
55
|
+
console.log('📋 Test Wallet Details:')
|
|
56
|
+
console.log(`Private Key (WIF): ${privateKey.toWIF()}`)
|
|
57
|
+
console.log(`Private Key (Hex): ${privateKey.toString('hex')}`)
|
|
58
|
+
console.log(`Public Key: ${publicKey.toString()}`)
|
|
59
|
+
console.log(`Address: ${address.toString()}`)
|
|
60
|
+
console.log(`Pubkey Hash160: ${bsv.crypto.Hash.sha256ripemd160(publicKey.toBuffer()).toString('hex')}\n`)
|
|
61
61
|
|
|
62
62
|
// Create a mock UTXO with sufficient funds for testing
|
|
63
|
-
const utxo = mkUtxo(privateKey, 50000)
|
|
63
|
+
const utxo = mkUtxo(privateKey, 50000) // 50,000 satoshis
|
|
64
64
|
|
|
65
|
-
console.log('💰 Mock UTXO Created:')
|
|
66
|
-
console.log(`TXID: ${utxo.txid}`)
|
|
67
|
-
console.log(`Vout: ${utxo.vout}`)
|
|
68
|
-
console.log(`Satoshis: ${utxo.satoshis}`)
|
|
69
|
-
console.log(`Script: ${utxo.script}\n`)
|
|
65
|
+
console.log('💰 Mock UTXO Created:')
|
|
66
|
+
console.log(`TXID: ${utxo.txid}`)
|
|
67
|
+
console.log(`Vout: ${utxo.vout}`)
|
|
68
|
+
console.log(`Satoshis: ${utxo.satoshis}`)
|
|
69
|
+
console.log(`Script: ${utxo.script}\n`)
|
|
70
70
|
|
|
71
71
|
// Create test environment config
|
|
72
72
|
const testConfig = {
|
|
@@ -89,74 +89,73 @@ function createTestWallet() {
|
|
|
89
89
|
testParams: {
|
|
90
90
|
nLockTimeTarget: 1000,
|
|
91
91
|
sighashType: bsv.crypto.Signature.SIGHASH_ALL | bsv.crypto.Signature.SIGHASH_FORKID,
|
|
92
|
-
covenantAmount: 40000,
|
|
93
|
-
fee: 1000,
|
|
94
|
-
changeAmount: 9000
|
|
92
|
+
covenantAmount: 40000, // Amount for covenant output
|
|
93
|
+
fee: 1000, // Transaction fee
|
|
94
|
+
changeAmount: 9000 // Remaining change
|
|
95
95
|
},
|
|
96
96
|
metadata: {
|
|
97
97
|
created: new Date().toISOString(),
|
|
98
98
|
description: 'Test wallet and UTXO for BSV preimage covenant testing',
|
|
99
99
|
version: '1.0'
|
|
100
100
|
}
|
|
101
|
-
}
|
|
101
|
+
}
|
|
102
102
|
|
|
103
|
-
return testConfig
|
|
103
|
+
return testConfig
|
|
104
104
|
}
|
|
105
105
|
|
|
106
|
-
function saveTestConfig(config) {
|
|
107
|
-
const configPath = path.join(__dirname, 'wallet.json')
|
|
108
|
-
|
|
109
|
-
console.log('💾 Saving wallet configuration...')
|
|
110
|
-
fs.writeFileSync(configPath, JSON.stringify(config, null, 2))
|
|
111
|
-
|
|
112
|
-
console.log(`✅ Wallet configuration saved to: ${configPath}\n`)
|
|
113
|
-
|
|
114
|
-
return configPath
|
|
106
|
+
function saveTestConfig (config) {
|
|
107
|
+
const configPath = path.join(__dirname, 'wallet.json')
|
|
108
|
+
|
|
109
|
+
console.log('💾 Saving wallet configuration...')
|
|
110
|
+
fs.writeFileSync(configPath, JSON.stringify(config, null, 2))
|
|
111
|
+
|
|
112
|
+
console.log(`✅ Wallet configuration saved to: ${configPath}\n`)
|
|
113
|
+
|
|
114
|
+
return configPath
|
|
115
115
|
}
|
|
116
116
|
|
|
117
|
-
function displaySetupSummary(config) {
|
|
118
|
-
console.log('📊 Test Environment Summary:')
|
|
119
|
-
console.log('═══════════════════════════════════════════')
|
|
120
|
-
console.log(`Address: ${config.wallet.address}`)
|
|
121
|
-
console.log(`Balance: ${config.utxo.satoshis} satoshis`)
|
|
122
|
-
console.log(`Mock TXID: ${config.utxo.txid.substring(0, 16)}...`)
|
|
123
|
-
console.log(`nLockTime Target: ${config.testParams.nLockTimeTarget}`)
|
|
124
|
-
console.log(`Covenant Amount: ${config.testParams.covenantAmount} satoshis`)
|
|
125
|
-
console.log(`Fee: ${config.testParams.fee} satoshis`)
|
|
126
|
-
console.log('═══════════════════════════════════════════\n')
|
|
127
|
-
|
|
128
|
-
console.log('\n🎯 Next Steps:')
|
|
129
|
-
console.log('1. Use the wallet credentials in your tests')
|
|
130
|
-
console.log('2. Import wallet.json in your test files')
|
|
131
|
-
console.log('3. Call updateUTXOFromTransaction() after each transaction\n')
|
|
117
|
+
function displaySetupSummary (config) {
|
|
118
|
+
console.log('📊 Test Environment Summary:')
|
|
119
|
+
console.log('═══════════════════════════════════════════')
|
|
120
|
+
console.log(`Address: ${config.wallet.address}`)
|
|
121
|
+
console.log(`Balance: ${config.utxo.satoshis} satoshis`)
|
|
122
|
+
console.log(`Mock TXID: ${config.utxo.txid.substring(0, 16)}...`)
|
|
123
|
+
console.log(`nLockTime Target: ${config.testParams.nLockTimeTarget}`)
|
|
124
|
+
console.log(`Covenant Amount: ${config.testParams.covenantAmount} satoshis`)
|
|
125
|
+
console.log(`Fee: ${config.testParams.fee} satoshis`)
|
|
126
|
+
console.log('═══════════════════════════════════════════\n')
|
|
127
|
+
|
|
128
|
+
console.log('\n🎯 Next Steps:')
|
|
129
|
+
console.log('1. Use the wallet credentials in your tests')
|
|
130
|
+
console.log('2. Import wallet.json in your test files')
|
|
131
|
+
console.log('3. Call updateUTXOFromTransaction() after each transaction\n')
|
|
132
132
|
}
|
|
133
133
|
|
|
134
134
|
// Main execution
|
|
135
|
-
function main() {
|
|
136
|
-
console.log('🚀 BSV Preimage Covenant - Test Wallet Setup\n')
|
|
137
|
-
|
|
135
|
+
function main () {
|
|
136
|
+
console.log('🚀 BSV Preimage Covenant - Test Wallet Setup\n')
|
|
137
|
+
|
|
138
138
|
try {
|
|
139
139
|
// Create test wallet and configuration
|
|
140
|
-
const testConfig = createTestWallet()
|
|
141
|
-
|
|
140
|
+
const testConfig = createTestWallet()
|
|
141
|
+
|
|
142
142
|
// Save configuration to file
|
|
143
|
-
const configPath = saveTestConfig(testConfig)
|
|
144
|
-
|
|
143
|
+
const configPath = saveTestConfig(testConfig)
|
|
144
|
+
|
|
145
145
|
// Display summary
|
|
146
|
-
displaySetupSummary(testConfig)
|
|
147
|
-
|
|
148
|
-
console.log('✅ Test wallet setup complete!')
|
|
149
|
-
console.log(`📁 Configuration file: ${path.basename(configPath)}`)
|
|
150
|
-
|
|
146
|
+
displaySetupSummary(testConfig)
|
|
147
|
+
|
|
148
|
+
console.log('✅ Test wallet setup complete!')
|
|
149
|
+
console.log(`📁 Configuration file: ${path.basename(configPath)}`)
|
|
151
150
|
} catch (error) {
|
|
152
|
-
console.error('❌ Error setting up test wallet:', error.message)
|
|
153
|
-
process.exit(1)
|
|
151
|
+
console.error('❌ Error setting up test wallet:', error.message)
|
|
152
|
+
process.exit(1)
|
|
154
153
|
}
|
|
155
154
|
}
|
|
156
155
|
|
|
157
156
|
// Run if called directly
|
|
158
157
|
if (require.main === module) {
|
|
159
|
-
main()
|
|
158
|
+
main()
|
|
160
159
|
}
|
|
161
160
|
|
|
162
161
|
// Export functions for use in other files
|
|
@@ -164,4 +163,4 @@ module.exports = {
|
|
|
164
163
|
createTestWallet,
|
|
165
164
|
mkUtxo,
|
|
166
165
|
saveTestConfig
|
|
167
|
-
}
|
|
166
|
+
}
|