@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
|
@@ -0,0 +1,244 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* UTXO Generator Standalone Demo
|
|
5
|
+
* ==============================
|
|
6
|
+
*
|
|
7
|
+
* Demonstrates the SmartContract.UTXOGenerator capabilities for creating
|
|
8
|
+
* authentic BSV UTXOs for testing and development.
|
|
9
|
+
*
|
|
10
|
+
* Features demonstrated:
|
|
11
|
+
* - Real BSV keypair generation
|
|
12
|
+
* - P2PKH, P2SH, and custom UTXO creation
|
|
13
|
+
* - SmartUTXO integration
|
|
14
|
+
* - Blockchain state management
|
|
15
|
+
* - Multi-network support
|
|
16
|
+
*/
|
|
17
|
+
|
|
18
|
+
const bsv = require('../index.js');
|
|
19
|
+
|
|
20
|
+
console.log('💎 SmartLedger-BSV UTXO Generator Demo');
|
|
21
|
+
console.log('======================================\n');
|
|
22
|
+
|
|
23
|
+
async function demonstrateUTXOGenerator() {
|
|
24
|
+
try {
|
|
25
|
+
// Test 1: Basic UTXO Generation
|
|
26
|
+
console.log('🏗️ Test 1: Basic UTXO Generation');
|
|
27
|
+
console.log('--------------------------------');
|
|
28
|
+
|
|
29
|
+
const generator = bsv.SmartContract.createUTXOGenerator({
|
|
30
|
+
network: bsv.Networks.testnet
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
console.log('✅ UTXOGenerator created for testnet');
|
|
34
|
+
|
|
35
|
+
// Generate a keypair
|
|
36
|
+
const keypair = generator.generateKeypair('main_wallet');
|
|
37
|
+
console.log('🔑 Generated keypair:');
|
|
38
|
+
console.log(' 📍 Address:', keypair.addressString);
|
|
39
|
+
console.log(' 🔐 WIF:', keypair.wif);
|
|
40
|
+
console.log(' 🔑 Public Key:', keypair.publicKey.toString().substring(0, 20) + '...');
|
|
41
|
+
console.log('');
|
|
42
|
+
|
|
43
|
+
// Create basic UTXOs
|
|
44
|
+
const utxos = generator.createRealUTXOs({
|
|
45
|
+
count: 3,
|
|
46
|
+
satoshis: 100000,
|
|
47
|
+
scriptType: 'P2PKH',
|
|
48
|
+
keypair: keypair
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
console.log('📊 Generated UTXOs:', utxos.length);
|
|
52
|
+
utxos.forEach((utxo, index) => {
|
|
53
|
+
console.log(` UTXO ${index + 1}:`);
|
|
54
|
+
console.log(` 🆔 TxID: ${utxo.txid.substring(0, 16)}...`);
|
|
55
|
+
console.log(` 📍 Vout: ${utxo.vout}`);
|
|
56
|
+
console.log(` 💰 Value: ${utxo.satoshis} satoshis`);
|
|
57
|
+
console.log(` 🏠 Address: ${utxo.address}`);
|
|
58
|
+
console.log(` 📜 Script Type: ${utxo.scriptType}`);
|
|
59
|
+
});
|
|
60
|
+
console.log('');
|
|
61
|
+
|
|
62
|
+
// Test 2: Different Script Types
|
|
63
|
+
console.log('🔧 Test 2: Different Script Types');
|
|
64
|
+
console.log('---------------------------------');
|
|
65
|
+
|
|
66
|
+
const scriptTypes = ['P2PKH', 'P2SH'];
|
|
67
|
+
|
|
68
|
+
for (const scriptType of scriptTypes) {
|
|
69
|
+
console.log(`🛠️ Creating ${scriptType} UTXOs...`);
|
|
70
|
+
|
|
71
|
+
const typeKeypair = generator.generateKeypair(`${scriptType.toLowerCase()}_wallet`);
|
|
72
|
+
const typeUTXOs = generator.createRealUTXOs({
|
|
73
|
+
count: 2,
|
|
74
|
+
satoshis: 50000,
|
|
75
|
+
scriptType: scriptType,
|
|
76
|
+
keypair: typeKeypair
|
|
77
|
+
});
|
|
78
|
+
|
|
79
|
+
console.log(` ✅ Created ${typeUTXOs.length} ${scriptType} UTXOs`);
|
|
80
|
+
console.log(` 📍 Address: ${typeKeypair.addressString}`);
|
|
81
|
+
console.log(` 📜 Script: ${typeUTXOs[0].script.substring(0, 30)}...`);
|
|
82
|
+
console.log('');
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
// Test 3: Different Networks
|
|
86
|
+
console.log('🌐 Test 3: Multi-Network Support');
|
|
87
|
+
console.log('-------------------------------');
|
|
88
|
+
|
|
89
|
+
const networks = [
|
|
90
|
+
{ name: 'mainnet', network: bsv.Networks.mainnet },
|
|
91
|
+
{ name: 'testnet', network: bsv.Networks.testnet },
|
|
92
|
+
{ name: 'regtest', network: bsv.Networks.regtest }
|
|
93
|
+
];
|
|
94
|
+
|
|
95
|
+
networks.forEach(({ name, network }) => {
|
|
96
|
+
const netGenerator = bsv.SmartContract.createUTXOGenerator({ network });
|
|
97
|
+
const netKeypair = netGenerator.generateKeypair(`${name}_key`);
|
|
98
|
+
|
|
99
|
+
console.log(`🌐 ${name}:`);
|
|
100
|
+
console.log(` 📍 Address: ${netKeypair.addressString}`);
|
|
101
|
+
console.log(` 🔑 Network: ${netKeypair.privateKey.network.name}`);
|
|
102
|
+
});
|
|
103
|
+
console.log('');
|
|
104
|
+
|
|
105
|
+
// Test 4: UTXO Pool Management
|
|
106
|
+
console.log('🗃️ Test 4: UTXO Pool Management');
|
|
107
|
+
console.log('--------------------------------');
|
|
108
|
+
|
|
109
|
+
console.log('📊 Total UTXOs in pool:', generator.utxoPool.length);
|
|
110
|
+
console.log('🔑 Keypairs in keyring:', Object.keys(generator.keyRing).length);
|
|
111
|
+
|
|
112
|
+
// Show UTXO statistics
|
|
113
|
+
const totalValue = generator.utxoPool.reduce((sum, utxo) => sum + utxo.satoshis, 0);
|
|
114
|
+
console.log('💰 Total value in pool:', totalValue, 'satoshis');
|
|
115
|
+
console.log('💸 Average UTXO value:', Math.round(totalValue / generator.utxoPool.length), 'satoshis');
|
|
116
|
+
|
|
117
|
+
// Group by script type
|
|
118
|
+
const scriptTypeStats = {};
|
|
119
|
+
generator.utxoPool.forEach(utxo => {
|
|
120
|
+
scriptTypeStats[utxo.scriptType] = (scriptTypeStats[utxo.scriptType] || 0) + 1;
|
|
121
|
+
});
|
|
122
|
+
|
|
123
|
+
console.log('📊 UTXOs by script type:');
|
|
124
|
+
Object.entries(scriptTypeStats).forEach(([type, count]) => {
|
|
125
|
+
console.log(` ${type}: ${count} UTXOs`);
|
|
126
|
+
});
|
|
127
|
+
console.log('');
|
|
128
|
+
|
|
129
|
+
// Test 5: SmartUTXO Integration
|
|
130
|
+
console.log('🔗 Test 5: SmartUTXO Integration');
|
|
131
|
+
console.log('-------------------------------');
|
|
132
|
+
|
|
133
|
+
if (bsv.SmartUTXO) {
|
|
134
|
+
console.log('✅ SmartUTXO integration available');
|
|
135
|
+
|
|
136
|
+
// Create SmartUTXO instance
|
|
137
|
+
const smartUTXO = new bsv.SmartUTXO();
|
|
138
|
+
|
|
139
|
+
// Check UTXOs for an address
|
|
140
|
+
const testAddress = keypair.addressString;
|
|
141
|
+
const addressUTXOs = smartUTXO.getUTXOsForAddress(testAddress);
|
|
142
|
+
|
|
143
|
+
console.log(`💎 UTXOs found for ${testAddress}:`, addressUTXOs.length);
|
|
144
|
+
|
|
145
|
+
if (addressUTXOs.length > 0) {
|
|
146
|
+
console.log('📋 Sample UTXO details:');
|
|
147
|
+
const sample = addressUTXOs[0];
|
|
148
|
+
console.log(` 🆔 TxID: ${sample.txid || sample.txId}`);
|
|
149
|
+
console.log(` 💰 Value: ${sample.satoshis || sample.amount} satoshis`);
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
} else {
|
|
153
|
+
console.log('⚠️ SmartUTXO integration not available');
|
|
154
|
+
}
|
|
155
|
+
console.log('');
|
|
156
|
+
|
|
157
|
+
// Test 6: Custom UTXO Creation
|
|
158
|
+
console.log('⚙️ Test 6: Custom UTXO Creation');
|
|
159
|
+
console.log('-------------------------------');
|
|
160
|
+
|
|
161
|
+
const customKeypair = generator.generateKeypair('custom_wallet');
|
|
162
|
+
|
|
163
|
+
// Create UTXOs with different values
|
|
164
|
+
const customConfigs = [
|
|
165
|
+
{ satoshis: 546, description: 'Dust limit UTXO' },
|
|
166
|
+
{ satoshis: 10000, description: 'Small payment UTXO' },
|
|
167
|
+
{ satoshis: 1000000, description: 'Large value UTXO' },
|
|
168
|
+
{ satoshis: 21000000, description: 'Very large UTXO' }
|
|
169
|
+
];
|
|
170
|
+
|
|
171
|
+
customConfigs.forEach(config => {
|
|
172
|
+
const customUTXOs = generator.createRealUTXOs({
|
|
173
|
+
count: 1,
|
|
174
|
+
satoshis: config.satoshis,
|
|
175
|
+
scriptType: 'P2PKH',
|
|
176
|
+
keypair: customKeypair
|
|
177
|
+
});
|
|
178
|
+
|
|
179
|
+
console.log(`💎 ${config.description}:`);
|
|
180
|
+
console.log(` 💰 ${config.satoshis} satoshis (${(config.satoshis / 100000000).toFixed(8)} BSV)`);
|
|
181
|
+
console.log(` 🆔 ${customUTXOs[0].txid.substring(0, 16)}...`);
|
|
182
|
+
});
|
|
183
|
+
console.log('');
|
|
184
|
+
|
|
185
|
+
// Test 7: Performance Metrics
|
|
186
|
+
console.log('📊 Test 7: Performance Metrics');
|
|
187
|
+
console.log('------------------------------');
|
|
188
|
+
|
|
189
|
+
const perfKeypair = generator.generateKeypair('perf_test');
|
|
190
|
+
const iterations = 50;
|
|
191
|
+
|
|
192
|
+
console.log(`🚀 Creating ${iterations} UTXOs for performance test...`);
|
|
193
|
+
|
|
194
|
+
const startTime = Date.now();
|
|
195
|
+
|
|
196
|
+
for (let i = 0; i < iterations; i++) {
|
|
197
|
+
generator.createRealUTXOs({
|
|
198
|
+
count: 1,
|
|
199
|
+
satoshis: 10000,
|
|
200
|
+
scriptType: 'P2PKH',
|
|
201
|
+
keypair: perfKeypair
|
|
202
|
+
});
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
const endTime = Date.now();
|
|
206
|
+
const totalTime = endTime - startTime;
|
|
207
|
+
|
|
208
|
+
console.log(`⏱️ Generated ${iterations} UTXOs in ${totalTime}ms`);
|
|
209
|
+
console.log(`📊 Average: ${(totalTime / iterations).toFixed(2)}ms per UTXO`);
|
|
210
|
+
console.log(`🚀 Rate: ${(iterations * 1000 / totalTime).toFixed(0)} UTXOs/second`);
|
|
211
|
+
console.log('');
|
|
212
|
+
|
|
213
|
+
// Final statistics
|
|
214
|
+
console.log('📊 Final Statistics');
|
|
215
|
+
console.log('------------------');
|
|
216
|
+
console.log('🔑 Total keypairs generated:', Object.keys(generator.keyRing).length);
|
|
217
|
+
console.log('💎 Total UTXOs created:', generator.utxoPool.length);
|
|
218
|
+
console.log('💰 Total value generated:', generator.utxoPool.reduce((sum, utxo) => sum + utxo.satoshis, 0), 'satoshis');
|
|
219
|
+
console.log('🌐 Network:', generator.network.name);
|
|
220
|
+
|
|
221
|
+
} catch (error) {
|
|
222
|
+
console.error('❌ Demo error:', error.message);
|
|
223
|
+
console.error('📋 Stack:', error.stack);
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
// Run the demo
|
|
228
|
+
demonstrateUTXOGenerator().then(() => {
|
|
229
|
+
console.log('\n🎉 UTXO Generator Demo completed!');
|
|
230
|
+
console.log('');
|
|
231
|
+
console.log('💡 Use Cases:');
|
|
232
|
+
console.log(' • Test environment setup for smart contracts');
|
|
233
|
+
console.log(' • Local development with realistic UTXOs');
|
|
234
|
+
console.log(' • Integration testing with multiple addresses');
|
|
235
|
+
console.log(' • Performance testing of transaction creation');
|
|
236
|
+
console.log(' • Educational demonstrations of UTXO model');
|
|
237
|
+
console.log(' • Mock data generation for BSV applications');
|
|
238
|
+
console.log('');
|
|
239
|
+
console.log('🔧 Integration Tips:');
|
|
240
|
+
console.log(' • Use with SmartContract.Covenant for covenant testing');
|
|
241
|
+
console.log(' • Combine with transaction builders for end-to-end tests');
|
|
242
|
+
console.log(' • Store generated UTXOs for reuse across tests');
|
|
243
|
+
console.log(' • Use different networks for different test scenarios');
|
|
244
|
+
});
|
|
@@ -0,0 +1,155 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Enhanced Validation Pipeline Demo
|
|
5
|
+
*
|
|
6
|
+
* This demonstrates the comprehensive validation that happens before broadcasting
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
const bsv = require('../index.js');
|
|
10
|
+
|
|
11
|
+
console.log('🛡️ SmartLedger Enhanced Validation Pipeline Demo');
|
|
12
|
+
console.log('================================================\n');
|
|
13
|
+
|
|
14
|
+
console.log('This demo shows our 4-step validation process:');
|
|
15
|
+
console.log('1. ✅ Basic BSV Transaction Validation');
|
|
16
|
+
console.log('2. 🔐 SmartVerify Enhanced Signature Validation');
|
|
17
|
+
console.log('3. ⛏️ Miner Simulation Validation');
|
|
18
|
+
console.log('4. 📡 Pre-Broadcast Final Validation\n');
|
|
19
|
+
|
|
20
|
+
const privateKey = new bsv.PrivateKey('L1aW4aubDFB7yfras2S1mN3bqg9nwySY8nkoLmJebSLD5BWv3ENZ');
|
|
21
|
+
const address = privateKey.toAddress().toString();
|
|
22
|
+
|
|
23
|
+
// Create a mock transaction for validation testing
|
|
24
|
+
const mockUTXO = {
|
|
25
|
+
txid: 'abcdef1234567890abcdef1234567890abcdef1234567890abcdef1234567890',
|
|
26
|
+
vout: 0,
|
|
27
|
+
address: address,
|
|
28
|
+
satoshis: 100000,
|
|
29
|
+
script: '76a914' + bsv.Address.fromString(address).hashBuffer.toString('hex') + '88ac'
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
console.log('📝 Creating Test Transaction:');
|
|
33
|
+
console.log(`From: ${address}`);
|
|
34
|
+
console.log(`Amount: 10,000 satoshis`);
|
|
35
|
+
console.log(`To: 1BitcoinEaterAddressDontSendf59kuE\n`);
|
|
36
|
+
|
|
37
|
+
try {
|
|
38
|
+
// Create transaction
|
|
39
|
+
const transaction = new bsv.Transaction()
|
|
40
|
+
.from(mockUTXO)
|
|
41
|
+
.to('1BitcoinEaterAddressDontSendf59kuE', 10000)
|
|
42
|
+
.change(address)
|
|
43
|
+
.sign(privateKey);
|
|
44
|
+
|
|
45
|
+
console.log('🔍 Starting Enhanced Validation Pipeline:\n');
|
|
46
|
+
|
|
47
|
+
// Step 1: Basic BSV Validation
|
|
48
|
+
console.log('Step 1: Basic BSV Transaction Validation');
|
|
49
|
+
console.log('========================================');
|
|
50
|
+
const basicValid = transaction.verify();
|
|
51
|
+
console.log(`Result: ${basicValid ? '✅ VALID' : '❌ INVALID'}`);
|
|
52
|
+
console.log(`Transaction ID: ${transaction.id}`);
|
|
53
|
+
console.log(`Size: ${transaction.toBuffer().length} bytes\n`);
|
|
54
|
+
|
|
55
|
+
// Step 2: SmartVerify Validation
|
|
56
|
+
console.log('Step 2: SmartVerify Enhanced Signature Validation');
|
|
57
|
+
console.log('=================================================');
|
|
58
|
+
|
|
59
|
+
let smartVerifyPassed = true;
|
|
60
|
+
for (let i = 0; i < transaction.inputs.length; i++) {
|
|
61
|
+
try {
|
|
62
|
+
const sighash = transaction.sighash(i);
|
|
63
|
+
const input = transaction.inputs[i];
|
|
64
|
+
const signature = input.script.chunks[0]?.buf;
|
|
65
|
+
const publicKey = input.script.chunks[1]?.buf;
|
|
66
|
+
|
|
67
|
+
if (signature && publicKey) {
|
|
68
|
+
const sigBuffer = signature.slice(0, -1); // Remove sighash flag
|
|
69
|
+
const pubkeyObj = new bsv.PublicKey(publicKey);
|
|
70
|
+
|
|
71
|
+
const smartValid = bsv.SmartVerify.smartVerify(sighash, sigBuffer, pubkeyObj);
|
|
72
|
+
const isCanonical = bsv.SmartVerify.isCanonical(sigBuffer);
|
|
73
|
+
|
|
74
|
+
console.log(`Input ${i}:`);
|
|
75
|
+
console.log(` SmartVerify: ${smartValid ? '✅ VALID' : '❌ INVALID'}`);
|
|
76
|
+
console.log(` Canonical: ${isCanonical ? '✅ YES' : '❌ NO'}`);
|
|
77
|
+
console.log(` Signature: ${sigBuffer.toString('hex').substring(0, 32)}...`);
|
|
78
|
+
|
|
79
|
+
if (!smartValid || !isCanonical) {
|
|
80
|
+
smartVerifyPassed = false;
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
} catch (error) {
|
|
84
|
+
console.log(`Input ${i}: Validation error - ${error.message}`);
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
console.log(`SmartVerify Result: ${smartVerifyPassed ? '✅ PASSED' : '❌ FAILED'}\n`);
|
|
89
|
+
|
|
90
|
+
// Step 3: Miner Simulation
|
|
91
|
+
console.log('Step 3: Miner Simulation Validation');
|
|
92
|
+
console.log('===================================');
|
|
93
|
+
|
|
94
|
+
const miner = new bsv.SmartMiner(bsv, {
|
|
95
|
+
validateScripts: true,
|
|
96
|
+
logLevel: 'info'
|
|
97
|
+
});
|
|
98
|
+
|
|
99
|
+
const minerAccepted = miner.acceptTransaction(transaction);
|
|
100
|
+
console.log(`Miner Result: ${minerAccepted ? '✅ ACCEPTED' : '❌ REJECTED'}`);
|
|
101
|
+
|
|
102
|
+
const mempoolStats = miner.getMempoolStats();
|
|
103
|
+
console.log(`Mempool Status: ${mempoolStats.transactionCount} transactions\n`);
|
|
104
|
+
|
|
105
|
+
// Step 4: Pre-Broadcast Validation
|
|
106
|
+
console.log('Step 4: Pre-Broadcast Final Validation');
|
|
107
|
+
console.log('======================================');
|
|
108
|
+
|
|
109
|
+
const validationResults = {
|
|
110
|
+
basic: basicValid,
|
|
111
|
+
smartVerify: smartVerifyPassed,
|
|
112
|
+
miner: minerAccepted,
|
|
113
|
+
overall: basicValid && smartVerifyPassed && minerAccepted
|
|
114
|
+
};
|
|
115
|
+
|
|
116
|
+
console.log(`Basic BSV: ${validationResults.basic ? '✅' : '❌'}`);
|
|
117
|
+
console.log(`SmartVerify: ${validationResults.smartVerify ? '✅' : '❌'}`);
|
|
118
|
+
console.log(`Miner: ${validationResults.miner ? '✅' : '❌'}`);
|
|
119
|
+
console.log(`Overall: ${validationResults.overall ? '✅ READY FOR BROADCAST' : '❌ BLOCKED FROM BROADCAST'}`);
|
|
120
|
+
|
|
121
|
+
// Simulate broadcast check
|
|
122
|
+
console.log('\n📡 Broadcast Readiness Check:');
|
|
123
|
+
console.log('=============================');
|
|
124
|
+
|
|
125
|
+
if (validationResults.overall) {
|
|
126
|
+
console.log('✅ Transaction passed all validation steps');
|
|
127
|
+
console.log('✅ SmartVerify confirms canonical signatures');
|
|
128
|
+
console.log('✅ Miner simulation accepts transaction');
|
|
129
|
+
console.log('✅ Ready for broadcast to BSV network');
|
|
130
|
+
console.log('');
|
|
131
|
+
console.log('💡 To actually broadcast: node real_utxo_test.js --broadcast');
|
|
132
|
+
console.log('⚠️ WARNING: This would spend real BSV!');
|
|
133
|
+
} else {
|
|
134
|
+
console.log('❌ Transaction BLOCKED from broadcast');
|
|
135
|
+
console.log('⚠️ This transaction would likely be rejected by the network');
|
|
136
|
+
|
|
137
|
+
if (!validationResults.basic) console.log(' - Failed basic BSV validation');
|
|
138
|
+
if (!validationResults.smartVerify) console.log(' - Failed SmartVerify validation');
|
|
139
|
+
if (!validationResults.miner) console.log(' - Rejected by miner simulation');
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
console.log('\n🎯 Validation Summary:');
|
|
143
|
+
console.log('=====================');
|
|
144
|
+
console.log('SmartLedger-BSV uses a comprehensive 4-step validation pipeline:');
|
|
145
|
+
console.log('');
|
|
146
|
+
console.log('1. 🔧 Basic BSV validation (standard library validation)');
|
|
147
|
+
console.log('2. 🔐 SmartVerify validation (enhanced signature verification)');
|
|
148
|
+
console.log('3. ⛏️ Miner simulation (real mining node acceptance test)');
|
|
149
|
+
console.log('4. 📡 Pre-broadcast validation (final safety check)');
|
|
150
|
+
console.log('');
|
|
151
|
+
console.log('This ensures maximum confidence before spending real BSV!');
|
|
152
|
+
|
|
153
|
+
} catch (error) {
|
|
154
|
+
console.error('❌ Validation demo failed:', error.message);
|
|
155
|
+
}
|