@smartledger/bsv 3.4.2 → 3.4.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.
Files changed (88) hide show
  1. package/CHANGELOG.md +336 -0
  2. package/README.md +72 -72
  3. package/SECURITY.md +88 -0
  4. package/bin/cli.js +13 -8
  5. package/bsv-covenant.min.js +4 -4
  6. package/bsv-gdaf.min.js +5 -5
  7. package/bsv-ltp.min.js +7 -7
  8. package/bsv-smartcontract.min.js +5 -5
  9. package/bsv.bundle.js +5 -5
  10. package/bsv.d.ts +486 -9
  11. package/bsv.min.js +5 -5
  12. package/docs/COVENANT_DEVELOPMENT_RESOLVED.md +2 -2
  13. package/docs/MODULE_REFERENCE_COMPLETE.md +61 -58
  14. package/docs/advanced/LEGAL_TOKEN_PROTOCOL.md +3 -3
  15. package/docs/advanced/UTXO_MANAGER_GUIDE.md +1 -1
  16. package/docs/getting-started/INSTALLATION.md +30 -30
  17. package/docs/getting-started/QUICK_START.md +18 -18
  18. package/docs/migration/FROM_BSV_1_5_6.md +16 -10
  19. package/gdaf-entry.js +1 -2
  20. package/index.js +20 -7
  21. package/lib/smart_contract/covenant.js +10 -1
  22. package/lib/smartutxo.js +20 -12
  23. package/lib/transaction/transaction.js +7 -0
  24. package/ltp-entry.js +1 -2
  25. package/package.json +3 -3
  26. package/utilities/blockchain-state.js +32 -23
  27. package/demos/README.md +0 -188
  28. package/demos/architecture_demo.js +0 -247
  29. package/demos/browser-test.html +0 -1208
  30. package/demos/bsv_wallet_demo.js +0 -242
  31. package/demos/complete_ltp_demo.js +0 -511
  32. package/demos/debug_tools_demo.js +0 -87
  33. package/demos/demo_features.js +0 -123
  34. package/demos/easy_interface_demo.js +0 -109
  35. package/demos/ecies_demo.js +0 -182
  36. package/demos/gdaf_demo.js +0 -237
  37. package/demos/ltp_demo.js +0 -361
  38. package/demos/ltp_primitives_demo.js +0 -403
  39. package/demos/message_demo.js +0 -209
  40. package/demos/preimage_separation_demo.js +0 -383
  41. package/demos/script_helper_demo.js +0 -289
  42. package/demos/security_demo.js +0 -287
  43. package/demos/shamir_demo.js +0 -121
  44. package/demos/simple_demo.js +0 -204
  45. package/demos/simple_p2pkh_demo.js +0 -169
  46. package/demos/simple_utxo_preimage_demo.js +0 -196
  47. package/demos/smart_contract_demo.html +0 -1347
  48. package/demos/smart_contract_demo.js +0 -910
  49. package/demos/utxo_generator_demo.js +0 -244
  50. package/demos/validation_pipeline_demo.js +0 -155
  51. package/demos/web3keys.html +0 -740
  52. package/examples/README.md +0 -200
  53. package/examples/basic/transaction-creation.js +0 -534
  54. package/examples/basic/transaction_signature_api_gap.js +0 -178
  55. package/examples/complete_workflow_demo.js +0 -783
  56. package/examples/covenants/advanced_covenant_demo.js +0 -219
  57. package/examples/covenants/covenant_interface_demo.js +0 -270
  58. package/examples/covenants/covenant_manual_signature_resolved.js +0 -212
  59. package/examples/covenants/covenant_signature_template.js +0 -117
  60. package/examples/covenants2/covenant_bidirectional_example.js +0 -262
  61. package/examples/covenants2/covenant_utils_demo.js +0 -120
  62. package/examples/covenants2/preimage_covenant_utils.js +0 -287
  63. package/examples/covenants2/production_integration.js +0 -256
  64. package/examples/data/covenant_utxos.json +0 -28
  65. package/examples/data/utxos.json +0 -26
  66. package/examples/definitive_working_demo.js +0 -261
  67. package/examples/final_working_contracts.js +0 -338
  68. package/examples/legacy/README.md +0 -11
  69. package/examples/legacy/smart_contract_test_integration.js +0 -269
  70. package/examples/legacy/test_builtin_verify.js +0 -117
  71. package/examples/legacy/test_debug_integration.js +0 -71
  72. package/examples/legacy/test_ecdsa_little.js +0 -70
  73. package/examples/legacy/test_shamir.js +0 -221
  74. package/examples/legacy/test_smartverify_der.js +0 -110
  75. package/examples/preimage/README.md +0 -178
  76. package/examples/preimage/extract_preimage_bidirectional.js +0 -421
  77. package/examples/preimage/generate_sample_preimage.js +0 -208
  78. package/examples/preimage/generate_sighash_examples.js +0 -152
  79. package/examples/preimage/parse_preimage.js +0 -117
  80. package/examples/preimage/test_preimage_extractor.js +0 -53
  81. package/examples/preimage/test_varint_extraction.js +0 -95
  82. package/examples/scripts/custom_script_helper_example.js +0 -273
  83. package/examples/scripts/script_interpreter.js +0 -193
  84. package/examples/smart_contract/complete_workflow_demo.js +0 -343
  85. package/examples/smart_contract/covenant_builder_demo.js +0 -176
  86. package/examples/smart_contract/script_testing_integration.js +0 -198
  87. package/examples/smart_contract_templates.js +0 -718
  88. package/examples/working_smart_contracts.js +0 -348
@@ -1,244 +0,0 @@
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
- });
@@ -1,155 +0,0 @@
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
- }