@smartledger/bsv 3.3.2 → 3.3.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/CHANGELOG.md +220 -79
- package/README.md +283 -71
- package/bsv-covenant.min.js +26 -3
- package/bsv-gdaf.min.js +11 -9
- package/bsv-ltp.min.js +10 -8
- package/bsv-mnemonic.min.js +4 -4
- 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/demos/README.md +188 -0
- package/{architecture_demo.js → demos/architecture_demo.js} +2 -2
- package/demos/bsv_wallet_demo.js +242 -0
- package/{complete_ltp_demo.js → demos/complete_ltp_demo.js} +1 -1
- package/demos/debug_tools_demo.js +87 -0
- package/demos/demo_features.js +123 -0
- package/demos/easy_interface_demo.js +109 -0
- package/demos/ecies_demo.js +182 -0
- package/demos/gdaf_core_test.js +131 -0
- package/demos/gdaf_demo.js +237 -0
- package/demos/ltp_demo.js +361 -0
- package/demos/ltp_primitives_demo.js +403 -0
- package/demos/message_demo.js +209 -0
- package/demos/preimage_separation_demo.js +383 -0
- package/demos/script_helper_demo.js +289 -0
- package/demos/security_demo.js +287 -0
- package/{shamir_demo.js → demos/shamir_demo.js} +1 -1
- package/{simple_demo.js → demos/simple_demo.js} +1 -1
- package/demos/simple_p2pkh_demo.js +169 -0
- package/demos/simple_utxo_preimage_demo.js +196 -0
- package/demos/smart_contract_demo.html +1347 -0
- package/demos/smart_contract_demo.js +910 -0
- package/demos/utxo_generator_demo.js +244 -0
- package/demos/validation_pipeline_demo.js +155 -0
- package/demos/web3keys.html +740 -0
- package/docs/BUNDLE_UPDATE_SUMMARY.md +40 -0
- package/docs/DOCUMENTATION_REVIEW_REPORT.md +295 -0
- package/docs/FIX_CREATEHMAC_ISSUE.md +91 -0
- package/docs/MODULE_REFERENCE_COMPLETE.md +330 -0
- package/docs/README.md +107 -79
- package/docs/SMARTLEDGER_BSV_USAGE_ANSWERS.md +477 -0
- package/docs/SMARTLEDGER_BSV_USAGE_EXAMPLES.js +372 -0
- package/docs/SMARTLEDGER_BSV_USAGE_GUIDE.md +555 -0
- package/docs/SMART_CONTRACT_DEVELOPMENT_GUIDE.md +1459 -0
- 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/examples/complete_workflow_demo.js +783 -0
- package/examples/definitive_working_demo.js +261 -0
- package/examples/final_working_contracts.js +338 -0
- package/examples/smart_contract_templates.js +718 -0
- package/examples/working_smart_contracts.js +348 -0
- package/gdaf-entry.js +2 -54
- package/index.js +32 -0
- package/lib/mnemonic/pbkdf2.browser.js +69 -0
- package/lib/mnemonic/pbkdf2.js +2 -68
- package/lib/mnemonic/pbkdf2.node.js +68 -0
- package/ltp-entry.js +2 -92
- package/package.json +21 -8
- 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/browser-compatibility/README.md +35 -0
- package/tests/browser-compatibility/test-cdn-vs-local.html +186 -0
- package/tests/browser-compatibility/test-pbkdf2.html +51 -0
- 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/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/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
|
@@ -21,80 +21,80 @@
|
|
|
21
21
|
* create a matching real TX there).
|
|
22
22
|
*/
|
|
23
23
|
|
|
24
|
-
const bsv = require('../index.js')
|
|
25
|
-
const crypto = require('crypto')
|
|
24
|
+
const bsv = require('../index.js')
|
|
25
|
+
const crypto = require('crypto')
|
|
26
26
|
|
|
27
|
-
function usage() {
|
|
28
|
-
console.log('Usage: node mock_utxo_generator.js [WIF] [satoshis] [recipientAddress]')
|
|
29
|
-
console.log('If WIF omitted, a random private key is generated.')
|
|
27
|
+
function usage () {
|
|
28
|
+
console.log('Usage: node mock_utxo_generator.js [WIF] [satoshis] [recipientAddress]')
|
|
29
|
+
console.log('If WIF omitted, a random private key is generated.')
|
|
30
30
|
}
|
|
31
31
|
|
|
32
|
-
function randomHex(len) {
|
|
33
|
-
return crypto.randomBytes(len).toString('hex')
|
|
32
|
+
function randomHex (len) {
|
|
33
|
+
return crypto.randomBytes(len).toString('hex')
|
|
34
34
|
}
|
|
35
35
|
|
|
36
|
-
function createMockTxId() {
|
|
36
|
+
function createMockTxId () {
|
|
37
37
|
// create random 32-byte hex as fake txid (little-endian vs big-endian not important for mocks)
|
|
38
|
-
return randomHex(32)
|
|
38
|
+
return randomHex(32)
|
|
39
39
|
}
|
|
40
40
|
|
|
41
|
-
function buildP2pkhScriptHex(address) {
|
|
42
|
-
return bsv.Script.buildPublicKeyHashOut(address).toHex()
|
|
41
|
+
function buildP2pkhScriptHex (address) {
|
|
42
|
+
return bsv.Script.buildPublicKeyHashOut(address).toHex()
|
|
43
43
|
}
|
|
44
44
|
|
|
45
|
-
function mkUtxo(privateKey, sats = 100000) {
|
|
46
|
-
const address = privateKey.toAddress().toString()
|
|
47
|
-
const txid = createMockTxId()
|
|
48
|
-
const vout = 0
|
|
49
|
-
const scriptHex = buildP2pkhScriptHex(address)
|
|
45
|
+
function mkUtxo (privateKey, sats = 100000) {
|
|
46
|
+
const address = privateKey.toAddress().toString()
|
|
47
|
+
const txid = createMockTxId()
|
|
48
|
+
const vout = 0
|
|
49
|
+
const scriptHex = buildP2pkhScriptHex(address)
|
|
50
50
|
|
|
51
51
|
// Return a utxo shape compatible with bsv.Transaction().from(...)
|
|
52
52
|
return {
|
|
53
53
|
txId: txid,
|
|
54
|
-
txid: txid,
|
|
54
|
+
txid: txid, // alternate naming used by some code
|
|
55
55
|
vout: vout,
|
|
56
|
-
outputIndex: vout,
|
|
56
|
+
outputIndex: vout, // bsv accepts outputIndex or vout
|
|
57
57
|
satoshis: sats,
|
|
58
58
|
value: sats,
|
|
59
59
|
script: scriptHex,
|
|
60
60
|
scriptPubKey: scriptHex,
|
|
61
|
-
address
|
|
62
|
-
}
|
|
61
|
+
address
|
|
62
|
+
}
|
|
63
63
|
}
|
|
64
64
|
|
|
65
|
-
async function main() {
|
|
66
|
-
const argv = process.argv.slice(2)
|
|
65
|
+
async function main () {
|
|
66
|
+
const argv = process.argv.slice(2)
|
|
67
67
|
if (argv.includes('-h') || argv.includes('--help')) {
|
|
68
|
-
usage()
|
|
69
|
-
return
|
|
68
|
+
usage()
|
|
69
|
+
return
|
|
70
70
|
}
|
|
71
71
|
|
|
72
|
-
const maybeWif = argv[0]
|
|
73
|
-
const maybeSatoshis = argv[1]
|
|
74
|
-
const recipient = argv[2]
|
|
72
|
+
const maybeWif = argv[0]
|
|
73
|
+
const maybeSatoshis = argv[1]
|
|
74
|
+
const recipient = argv[2]
|
|
75
75
|
|
|
76
|
-
let privateKey
|
|
76
|
+
let privateKey
|
|
77
77
|
try {
|
|
78
78
|
if (maybeWif) {
|
|
79
79
|
// try to load from WIF
|
|
80
|
-
privateKey = bsv.PrivateKey.fromWIF(maybeWif)
|
|
80
|
+
privateKey = bsv.PrivateKey.fromWIF(maybeWif)
|
|
81
81
|
} else {
|
|
82
|
-
privateKey = new bsv.PrivateKey()
|
|
82
|
+
privateKey = new bsv.PrivateKey() // random
|
|
83
83
|
}
|
|
84
84
|
} catch (e) {
|
|
85
|
-
console.error('Invalid WIF provided. Exiting.')
|
|
86
|
-
process.exit(1)
|
|
85
|
+
console.error('Invalid WIF provided. Exiting.')
|
|
86
|
+
process.exit(1)
|
|
87
87
|
}
|
|
88
88
|
|
|
89
|
-
const satoshis = maybeSatoshis ? parseInt(maybeSatoshis, 10) : 100000
|
|
89
|
+
const satoshis = maybeSatoshis ? parseInt(maybeSatoshis, 10) : 100000
|
|
90
90
|
if (Number.isNaN(satoshis) || satoshis <= 0) {
|
|
91
|
-
console.error('Invalid satoshis amount. Must be positive integer.')
|
|
92
|
-
process.exit(1)
|
|
91
|
+
console.error('Invalid satoshis amount. Must be positive integer.')
|
|
92
|
+
process.exit(1)
|
|
93
93
|
}
|
|
94
94
|
|
|
95
|
-
const utxo = mkUtxo(privateKey, satoshis)
|
|
95
|
+
const utxo = mkUtxo(privateKey, satoshis)
|
|
96
96
|
|
|
97
|
-
console.log('\n=== MOCK UTXO ===')
|
|
97
|
+
console.log('\n=== MOCK UTXO ===')
|
|
98
98
|
console.log(JSON.stringify({
|
|
99
99
|
privateKeyWIF: privateKey.toWIF(),
|
|
100
100
|
privateKeyHex: privateKey.toString('hex'),
|
|
@@ -105,17 +105,17 @@ async function main() {
|
|
|
105
105
|
scriptPubKey: utxo.scriptPubKey,
|
|
106
106
|
satoshis: utxo.satoshis
|
|
107
107
|
}
|
|
108
|
-
}, null, 2))
|
|
109
|
-
console.log('=================\n')
|
|
108
|
+
}, null, 2))
|
|
109
|
+
console.log('=================\n')
|
|
110
110
|
|
|
111
111
|
if (recipient) {
|
|
112
112
|
// Build a small tx that spends the mock utxo and sends everything minus a tiny fee
|
|
113
113
|
try {
|
|
114
|
-
const fee = 500
|
|
115
|
-
const sendAmount = Math.max(0, utxo.satoshis - fee)
|
|
114
|
+
const fee = 500 // tiny fee for local testing
|
|
115
|
+
const sendAmount = Math.max(0, utxo.satoshis - fee)
|
|
116
116
|
if (sendAmount <= 0) {
|
|
117
|
-
console.error('UTXO too small to cover fee. Increase satoshis or reduce fee.')
|
|
118
|
-
process.exit(1)
|
|
117
|
+
console.error('UTXO too small to cover fee. Increase satoshis or reduce fee.')
|
|
118
|
+
process.exit(1)
|
|
119
119
|
}
|
|
120
120
|
|
|
121
121
|
// Build transaction using bsv.Transaction.from style
|
|
@@ -128,22 +128,22 @@ async function main() {
|
|
|
128
128
|
})
|
|
129
129
|
.to(recipient, sendAmount)
|
|
130
130
|
// .change(utxo.address) // not necessary here because we send everything minus fee
|
|
131
|
-
.sign(privateKey)
|
|
131
|
+
.sign(privateKey)
|
|
132
132
|
|
|
133
|
-
console.log('=== SIGNED SPEND TX ===')
|
|
134
|
-
console.log('TX HEX:', tx.toString())
|
|
135
|
-
console.log('TX ID (hash):', tx.hash)
|
|
136
|
-
console.log('fee (mock):', fee)
|
|
137
|
-
console.log('sendAmount:', sendAmount)
|
|
138
|
-
console.log('========================\n')
|
|
133
|
+
console.log('=== SIGNED SPEND TX ===')
|
|
134
|
+
console.log('TX HEX:', tx.toString())
|
|
135
|
+
console.log('TX ID (hash):', tx.hash)
|
|
136
|
+
console.log('fee (mock):', fee)
|
|
137
|
+
console.log('sendAmount:', sendAmount)
|
|
138
|
+
console.log('========================\n')
|
|
139
139
|
|
|
140
|
-
console.log('Note: This TX is signed against our mock UTXO and can be used in local tests that accept fake txids.')
|
|
140
|
+
console.log('Note: This TX is signed against our mock UTXO and can be used in local tests that accept fake txids.')
|
|
141
141
|
} catch (e) {
|
|
142
|
-
console.error('Failed to build or sign tx:', e)
|
|
142
|
+
console.error('Failed to build or sign tx:', e)
|
|
143
143
|
}
|
|
144
144
|
} else {
|
|
145
|
-
console.log('No recipient provided. To produce a signed spending tx, run again with a recipient address as the 3rd arg.')
|
|
145
|
+
console.log('No recipient provided. To produce a signed spending tx, run again with a recipient address as the 3rd arg.')
|
|
146
146
|
}
|
|
147
147
|
}
|
|
148
148
|
|
|
149
|
-
main()
|
|
149
|
+
main()
|
|
@@ -2,99 +2,98 @@
|
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
4
|
* 🔧 BSV Raw Transaction Hex Validation Example
|
|
5
|
-
*
|
|
5
|
+
*
|
|
6
6
|
* Demonstrates sending raw transaction hex to the miner for validation
|
|
7
7
|
* using the BSV script interpreter for proper signature verification.
|
|
8
8
|
*/
|
|
9
9
|
|
|
10
|
-
const bsv = require('../index.js')
|
|
11
|
-
const {
|
|
12
|
-
acceptTransaction,
|
|
13
|
-
acceptRawTransaction
|
|
14
|
-
} = require('./miner-simulator')
|
|
15
|
-
const {
|
|
16
|
-
loadConfig
|
|
17
|
-
} = require('./utxo-manager')
|
|
10
|
+
const bsv = require('../index.js')
|
|
11
|
+
const {
|
|
12
|
+
acceptTransaction,
|
|
13
|
+
acceptRawTransaction
|
|
14
|
+
} = require('./miner-simulator')
|
|
15
|
+
const {
|
|
16
|
+
loadConfig
|
|
17
|
+
} = require('./utxo-manager')
|
|
18
18
|
|
|
19
19
|
/**
|
|
20
20
|
* Example: Create and validate raw transaction hex
|
|
21
21
|
*/
|
|
22
|
-
function exampleRawTransactionValidation() {
|
|
23
|
-
console.log('🔧 BSV Raw Transaction Hex Validation Example')
|
|
24
|
-
console.log('═'.repeat(80))
|
|
25
|
-
|
|
22
|
+
function exampleRawTransactionValidation () {
|
|
23
|
+
console.log('🔧 BSV Raw Transaction Hex Validation Example')
|
|
24
|
+
console.log('═'.repeat(80))
|
|
25
|
+
|
|
26
26
|
try {
|
|
27
27
|
// Load wallet config
|
|
28
|
-
const config = loadConfig()
|
|
29
|
-
const wallet = config.wallet
|
|
30
|
-
|
|
28
|
+
const config = loadConfig()
|
|
29
|
+
const wallet = config.wallet
|
|
30
|
+
|
|
31
31
|
// Create recipient
|
|
32
|
-
const recipientKey = new bsv.PrivateKey()
|
|
33
|
-
const recipientAddress = recipientKey.toAddress().toString()
|
|
34
|
-
|
|
32
|
+
const recipientKey = new bsv.PrivateKey()
|
|
33
|
+
const recipientAddress = recipientKey.toAddress().toString()
|
|
34
|
+
|
|
35
35
|
// Get available UTXO
|
|
36
|
-
const utxo = config.utxo
|
|
37
|
-
|
|
38
|
-
console.log('📋 Transaction Details:')
|
|
39
|
-
console.log(`👛 From: ${wallet.address}`)
|
|
40
|
-
console.log(`🎯 To: ${recipientAddress}`)
|
|
41
|
-
console.log(`💰 Amount: 10,000 satoshis`)
|
|
42
|
-
console.log(`💳 Using UTXO: ${utxo.txid}:${utxo.vout} (${utxo.satoshis} sats)\n`)
|
|
43
|
-
|
|
36
|
+
const utxo = config.utxo
|
|
37
|
+
|
|
38
|
+
console.log('📋 Transaction Details:')
|
|
39
|
+
console.log(`👛 From: ${wallet.address}`)
|
|
40
|
+
console.log(`🎯 To: ${recipientAddress}`)
|
|
41
|
+
console.log(`💰 Amount: 10,000 satoshis`)
|
|
42
|
+
console.log(`💳 Using UTXO: ${utxo.txid}:${utxo.vout} (${utxo.satoshis} sats)\n`)
|
|
43
|
+
|
|
44
44
|
// Create transaction with proper SIGHASH_FORKID
|
|
45
45
|
const tx = new bsv.Transaction()
|
|
46
46
|
.from(utxo)
|
|
47
47
|
.to(recipientAddress, 10000)
|
|
48
48
|
.change(wallet.address)
|
|
49
49
|
.fee(1000)
|
|
50
|
-
.sign(bsv.PrivateKey.fromWIF(wallet.privateKeyWIF), bsv.crypto.Signature.SIGHASH_ALL | bsv.crypto.Signature.SIGHASH_FORKID)
|
|
51
|
-
|
|
52
|
-
console.log('✅ Transaction created successfully')
|
|
53
|
-
console.log(`🆔 Transaction ID: ${tx.id}`)
|
|
54
|
-
|
|
50
|
+
.sign(bsv.PrivateKey.fromWIF(wallet.privateKeyWIF), bsv.crypto.Signature.SIGHASH_ALL | bsv.crypto.Signature.SIGHASH_FORKID)
|
|
51
|
+
|
|
52
|
+
console.log('✅ Transaction created successfully')
|
|
53
|
+
console.log(`🆔 Transaction ID: ${tx.id}`)
|
|
54
|
+
|
|
55
55
|
// Get raw transaction hex
|
|
56
|
-
const rawHex = tx.toString()
|
|
57
|
-
console.log(`\n📦 Raw Transaction Hex (${rawHex.length} chars):`)
|
|
58
|
-
console.log(`${rawHex.substring(0, 80)}...`)
|
|
59
|
-
console.log(`...${rawHex.substring(rawHex.length - 80)}`)
|
|
60
|
-
|
|
56
|
+
const rawHex = tx.toString()
|
|
57
|
+
console.log(`\n📦 Raw Transaction Hex (${rawHex.length} chars):`)
|
|
58
|
+
console.log(`${rawHex.substring(0, 80)}...`)
|
|
59
|
+
console.log(`...${rawHex.substring(rawHex.length - 80)}`)
|
|
60
|
+
|
|
61
61
|
// Method 1: Send transaction object
|
|
62
|
-
console.log('\n' + '─'.repeat(60))
|
|
63
|
-
console.log('🔄 Method 1: Sending Transaction Object')
|
|
64
|
-
console.log('─'.repeat(60))
|
|
65
|
-
|
|
66
|
-
const result1 = acceptTransaction(tx)
|
|
67
|
-
console.log(`\nResult: ${result1.accepted ? '✅ ACCEPTED' : '❌ REJECTED'}`)
|
|
62
|
+
console.log('\n' + '─'.repeat(60))
|
|
63
|
+
console.log('🔄 Method 1: Sending Transaction Object')
|
|
64
|
+
console.log('─'.repeat(60))
|
|
65
|
+
|
|
66
|
+
const result1 = acceptTransaction(tx)
|
|
67
|
+
console.log(`\nResult: ${result1.accepted ? '✅ ACCEPTED' : '❌ REJECTED'}`)
|
|
68
68
|
if (result1.errors.length > 0) {
|
|
69
|
-
console.log('Errors:', result1.errors)
|
|
69
|
+
console.log('Errors:', result1.errors)
|
|
70
70
|
}
|
|
71
|
-
|
|
71
|
+
|
|
72
72
|
// Method 2: Send raw transaction hex
|
|
73
|
-
console.log('\n' + '─'.repeat(60))
|
|
74
|
-
console.log('🔄 Method 2: Sending Raw Transaction Hex')
|
|
75
|
-
console.log('─'.repeat(60))
|
|
76
|
-
|
|
77
|
-
const result2 = acceptRawTransaction(rawHex)
|
|
78
|
-
console.log(`\nResult: ${result2.accepted ? '✅ ACCEPTED' : '❌ REJECTED'}`)
|
|
73
|
+
console.log('\n' + '─'.repeat(60))
|
|
74
|
+
console.log('🔄 Method 2: Sending Raw Transaction Hex')
|
|
75
|
+
console.log('─'.repeat(60))
|
|
76
|
+
|
|
77
|
+
const result2 = acceptRawTransaction(rawHex)
|
|
78
|
+
console.log(`\nResult: ${result2.accepted ? '✅ ACCEPTED' : '❌ REJECTED'}`)
|
|
79
79
|
if (result2.errors.length > 0) {
|
|
80
|
-
console.log('Errors:', result2.errors)
|
|
80
|
+
console.log('Errors:', result2.errors)
|
|
81
81
|
}
|
|
82
|
-
|
|
83
|
-
console.log('\n🎯 Both methods should produce identical validation results!')
|
|
84
|
-
|
|
82
|
+
|
|
83
|
+
console.log('\n🎯 Both methods should produce identical validation results!')
|
|
85
84
|
} catch (error) {
|
|
86
|
-
console.error('❌ Error in example:', error.message)
|
|
85
|
+
console.error('❌ Error in example:', error.message)
|
|
87
86
|
}
|
|
88
87
|
}
|
|
89
88
|
|
|
90
89
|
/**
|
|
91
90
|
* Example: Test invalid raw transaction hex
|
|
92
91
|
*/
|
|
93
|
-
function exampleInvalidRawHex() {
|
|
94
|
-
console.log('\n' + '═'.repeat(80))
|
|
95
|
-
console.log('🚫 Testing Invalid Raw Transaction Hex')
|
|
96
|
-
console.log('═'.repeat(80))
|
|
97
|
-
|
|
92
|
+
function exampleInvalidRawHex () {
|
|
93
|
+
console.log('\n' + '═'.repeat(80))
|
|
94
|
+
console.log('🚫 Testing Invalid Raw Transaction Hex')
|
|
95
|
+
console.log('═'.repeat(80))
|
|
96
|
+
|
|
98
97
|
// Test various invalid hex scenarios
|
|
99
98
|
const invalidHexExamples = [
|
|
100
99
|
{
|
|
@@ -112,97 +111,96 @@ function exampleInvalidRawHex() {
|
|
|
112
111
|
hex: '01000000010000000000000000000000000000000000000000000000000000000000000000',
|
|
113
112
|
description: 'Valid hex but malformed transaction structure'
|
|
114
113
|
}
|
|
115
|
-
]
|
|
116
|
-
|
|
114
|
+
]
|
|
115
|
+
|
|
117
116
|
invalidHexExamples.forEach((example, index) => {
|
|
118
|
-
console.log(`\n${index + 1}. ${example.name}:`)
|
|
119
|
-
console.log(` Description: ${example.description}`)
|
|
120
|
-
console.log(` Hex: ${example.hex}`)
|
|
121
|
-
|
|
122
|
-
const result = acceptRawTransaction(example.hex)
|
|
123
|
-
console.log(` Result: ${result.accepted ? '✅ ACCEPTED' : '❌ REJECTED'} (Expected: REJECTED)`)
|
|
124
|
-
|
|
117
|
+
console.log(`\n${index + 1}. ${example.name}:`)
|
|
118
|
+
console.log(` Description: ${example.description}`)
|
|
119
|
+
console.log(` Hex: ${example.hex}`)
|
|
120
|
+
|
|
121
|
+
const result = acceptRawTransaction(example.hex)
|
|
122
|
+
console.log(` Result: ${result.accepted ? '✅ ACCEPTED' : '❌ REJECTED'} (Expected: REJECTED)`)
|
|
123
|
+
|
|
125
124
|
if (result.errors.length > 0) {
|
|
126
|
-
console.log(` Error: ${result.errors[0]}`)
|
|
125
|
+
console.log(` Error: ${result.errors[0]}`)
|
|
127
126
|
}
|
|
128
|
-
})
|
|
127
|
+
})
|
|
129
128
|
}
|
|
130
129
|
|
|
131
130
|
/**
|
|
132
131
|
* Example: Parse and analyze transaction components
|
|
133
132
|
*/
|
|
134
|
-
function exampleTransactionAnalysis() {
|
|
135
|
-
console.log('\n' + '═'.repeat(80))
|
|
136
|
-
console.log('🔍 Transaction Component Analysis')
|
|
137
|
-
console.log('═'.repeat(80))
|
|
138
|
-
|
|
133
|
+
function exampleTransactionAnalysis () {
|
|
134
|
+
console.log('\n' + '═'.repeat(80))
|
|
135
|
+
console.log('🔍 Transaction Component Analysis')
|
|
136
|
+
console.log('═'.repeat(80))
|
|
137
|
+
|
|
139
138
|
try {
|
|
140
|
-
const config = loadConfig()
|
|
141
|
-
const wallet = config.wallet
|
|
142
|
-
const utxo = config.utxo
|
|
143
|
-
|
|
139
|
+
const config = loadConfig()
|
|
140
|
+
const wallet = config.wallet
|
|
141
|
+
const utxo = config.utxo
|
|
142
|
+
|
|
144
143
|
// Create simple transaction with proper SIGHASH_FORKID
|
|
145
144
|
const tx = new bsv.Transaction()
|
|
146
145
|
.from(utxo)
|
|
147
146
|
.to(new bsv.PrivateKey().toAddress(), 5000)
|
|
148
147
|
.change(wallet.address)
|
|
149
148
|
.fee(500)
|
|
150
|
-
.sign(bsv.PrivateKey.fromWIF(wallet.privateKeyWIF), bsv.crypto.Signature.SIGHASH_ALL | bsv.crypto.Signature.SIGHASH_FORKID)
|
|
151
|
-
|
|
152
|
-
const rawHex = tx.toString()
|
|
153
|
-
|
|
154
|
-
console.log('📋 Transaction Analysis:')
|
|
155
|
-
console.log(`🆔 TXID: ${tx.id}`)
|
|
156
|
-
console.log(`📦 Raw Hex: ${rawHex}`)
|
|
157
|
-
console.log(`📏 Size: ${rawHex.length / 2} bytes`)
|
|
158
|
-
console.log(`💰 Fee: ${tx.getFee()} satoshis`)
|
|
159
|
-
|
|
160
|
-
console.log('\n🔍 Input Details:')
|
|
149
|
+
.sign(bsv.PrivateKey.fromWIF(wallet.privateKeyWIF), bsv.crypto.Signature.SIGHASH_ALL | bsv.crypto.Signature.SIGHASH_FORKID)
|
|
150
|
+
|
|
151
|
+
const rawHex = tx.toString()
|
|
152
|
+
|
|
153
|
+
console.log('📋 Transaction Analysis:')
|
|
154
|
+
console.log(`🆔 TXID: ${tx.id}`)
|
|
155
|
+
console.log(`📦 Raw Hex: ${rawHex}`)
|
|
156
|
+
console.log(`📏 Size: ${rawHex.length / 2} bytes`)
|
|
157
|
+
console.log(`💰 Fee: ${tx.getFee()} satoshis`)
|
|
158
|
+
|
|
159
|
+
console.log('\n🔍 Input Details:')
|
|
161
160
|
tx.inputs.forEach((input, i) => {
|
|
162
|
-
console.log(` Input ${i}:`)
|
|
163
|
-
console.log(` Previous TXID: ${input.prevTxId.toString('hex')}`)
|
|
164
|
-
console.log(` Output Index: ${input.outputIndex}`)
|
|
165
|
-
console.log(` Script: ${input.script.toHex()}`)
|
|
166
|
-
console.log(` Script ASM: ${input.script.toASM()}`)
|
|
167
|
-
})
|
|
168
|
-
|
|
169
|
-
console.log('\n📤 Output Details:')
|
|
161
|
+
console.log(` Input ${i}:`)
|
|
162
|
+
console.log(` Previous TXID: ${input.prevTxId.toString('hex')}`)
|
|
163
|
+
console.log(` Output Index: ${input.outputIndex}`)
|
|
164
|
+
console.log(` Script: ${input.script.toHex()}`)
|
|
165
|
+
console.log(` Script ASM: ${input.script.toASM()}`)
|
|
166
|
+
})
|
|
167
|
+
|
|
168
|
+
console.log('\n📤 Output Details:')
|
|
170
169
|
tx.outputs.forEach((output, i) => {
|
|
171
|
-
console.log(` Output ${i}:`)
|
|
172
|
-
console.log(` Value: ${output.satoshis} satoshis`)
|
|
173
|
-
console.log(` Script: ${output.script.toHex()}`)
|
|
174
|
-
console.log(` Script ASM: ${output.script.toASM()}`)
|
|
170
|
+
console.log(` Output ${i}:`)
|
|
171
|
+
console.log(` Value: ${output.satoshis} satoshis`)
|
|
172
|
+
console.log(` Script: ${output.script.toHex()}`)
|
|
173
|
+
console.log(` Script ASM: ${output.script.toASM()}`)
|
|
175
174
|
try {
|
|
176
|
-
console.log(` Address: ${output.script.toAddress()}`)
|
|
175
|
+
console.log(` Address: ${output.script.toAddress()}`)
|
|
177
176
|
} catch (e) {
|
|
178
|
-
console.log(` Address: [Non-standard script]`)
|
|
177
|
+
console.log(` Address: [Non-standard script]`)
|
|
179
178
|
}
|
|
180
|
-
})
|
|
181
|
-
|
|
179
|
+
})
|
|
182
180
|
} catch (error) {
|
|
183
|
-
console.error('❌ Error in analysis:', error.message)
|
|
181
|
+
console.error('❌ Error in analysis:', error.message)
|
|
184
182
|
}
|
|
185
183
|
}
|
|
186
184
|
|
|
187
185
|
/**
|
|
188
186
|
* Run all raw transaction examples
|
|
189
187
|
*/
|
|
190
|
-
function runAllExamples() {
|
|
191
|
-
exampleRawTransactionValidation()
|
|
192
|
-
exampleInvalidRawHex()
|
|
193
|
-
exampleTransactionAnalysis()
|
|
194
|
-
|
|
195
|
-
console.log('\n🎯 Raw transaction validation examples completed!')
|
|
196
|
-
console.log('💡 The miner now validates transactions using:')
|
|
197
|
-
console.log(' - Raw hex format validation')
|
|
198
|
-
console.log(' - UTXO existence checking')
|
|
199
|
-
console.log(' - BSV script interpreter for signature verification')
|
|
200
|
-
console.log(' - Transaction balance and structure validation')
|
|
188
|
+
function runAllExamples () {
|
|
189
|
+
exampleRawTransactionValidation()
|
|
190
|
+
exampleInvalidRawHex()
|
|
191
|
+
exampleTransactionAnalysis()
|
|
192
|
+
|
|
193
|
+
console.log('\n🎯 Raw transaction validation examples completed!')
|
|
194
|
+
console.log('💡 The miner now validates transactions using:')
|
|
195
|
+
console.log(' - Raw hex format validation')
|
|
196
|
+
console.log(' - UTXO existence checking')
|
|
197
|
+
console.log(' - BSV script interpreter for signature verification')
|
|
198
|
+
console.log(' - Transaction balance and structure validation')
|
|
201
199
|
}
|
|
202
200
|
|
|
203
201
|
// Run examples if called directly
|
|
204
202
|
if (require.main === module) {
|
|
205
|
-
runAllExamples()
|
|
203
|
+
runAllExamples()
|
|
206
204
|
}
|
|
207
205
|
|
|
208
206
|
module.exports = {
|
|
@@ -210,4 +208,4 @@ module.exports = {
|
|
|
210
208
|
exampleInvalidRawHex,
|
|
211
209
|
exampleTransactionAnalysis,
|
|
212
210
|
runAllExamples
|
|
213
|
-
}
|
|
211
|
+
}
|