@smartledger/bsv 3.4.3 → 3.4.5

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 (89) hide show
  1. package/CHANGELOG.md +367 -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 +60 -57
  14. package/docs/advanced/UTXO_MANAGER_GUIDE.md +1 -1
  15. package/docs/getting-started/INSTALLATION.md +30 -30
  16. package/docs/getting-started/QUICK_START.md +14 -14
  17. package/docs/migration/FROM_BSV_1_5_6.md +5 -5
  18. package/gdaf-entry.js +1 -2
  19. package/index.js +20 -7
  20. package/lib/script/script.js +19 -0
  21. package/lib/smart_contract/covenant.js +10 -1
  22. package/lib/smartutxo.js +20 -12
  23. package/lib/transaction/input/publickeyhash.js +6 -1
  24. package/lib/transaction/transaction.js +12 -1
  25. package/ltp-entry.js +1 -2
  26. package/package.json +3 -3
  27. package/utilities/blockchain-state.js +32 -23
  28. package/demos/README.md +0 -188
  29. package/demos/architecture_demo.js +0 -247
  30. package/demos/browser-test.html +0 -1208
  31. package/demos/bsv_wallet_demo.js +0 -242
  32. package/demos/complete_ltp_demo.js +0 -511
  33. package/demos/debug_tools_demo.js +0 -87
  34. package/demos/demo_features.js +0 -123
  35. package/demos/easy_interface_demo.js +0 -109
  36. package/demos/ecies_demo.js +0 -182
  37. package/demos/gdaf_demo.js +0 -237
  38. package/demos/ltp_demo.js +0 -361
  39. package/demos/ltp_primitives_demo.js +0 -403
  40. package/demos/message_demo.js +0 -209
  41. package/demos/preimage_separation_demo.js +0 -383
  42. package/demos/script_helper_demo.js +0 -289
  43. package/demos/security_demo.js +0 -287
  44. package/demos/shamir_demo.js +0 -121
  45. package/demos/simple_demo.js +0 -204
  46. package/demos/simple_p2pkh_demo.js +0 -169
  47. package/demos/simple_utxo_preimage_demo.js +0 -196
  48. package/demos/smart_contract_demo.html +0 -1347
  49. package/demos/smart_contract_demo.js +0 -910
  50. package/demos/utxo_generator_demo.js +0 -244
  51. package/demos/validation_pipeline_demo.js +0 -155
  52. package/demos/web3keys.html +0 -740
  53. package/examples/README.md +0 -200
  54. package/examples/basic/transaction-creation.js +0 -534
  55. package/examples/basic/transaction_signature_api_gap.js +0 -178
  56. package/examples/complete_workflow_demo.js +0 -783
  57. package/examples/covenants/advanced_covenant_demo.js +0 -219
  58. package/examples/covenants/covenant_interface_demo.js +0 -270
  59. package/examples/covenants/covenant_manual_signature_resolved.js +0 -212
  60. package/examples/covenants/covenant_signature_template.js +0 -117
  61. package/examples/covenants2/covenant_bidirectional_example.js +0 -262
  62. package/examples/covenants2/covenant_utils_demo.js +0 -120
  63. package/examples/covenants2/preimage_covenant_utils.js +0 -287
  64. package/examples/covenants2/production_integration.js +0 -256
  65. package/examples/data/covenant_utxos.json +0 -28
  66. package/examples/data/utxos.json +0 -26
  67. package/examples/definitive_working_demo.js +0 -261
  68. package/examples/final_working_contracts.js +0 -338
  69. package/examples/legacy/README.md +0 -11
  70. package/examples/legacy/smart_contract_test_integration.js +0 -269
  71. package/examples/legacy/test_builtin_verify.js +0 -117
  72. package/examples/legacy/test_debug_integration.js +0 -71
  73. package/examples/legacy/test_ecdsa_little.js +0 -70
  74. package/examples/legacy/test_shamir.js +0 -221
  75. package/examples/legacy/test_smartverify_der.js +0 -110
  76. package/examples/preimage/README.md +0 -178
  77. package/examples/preimage/extract_preimage_bidirectional.js +0 -421
  78. package/examples/preimage/generate_sample_preimage.js +0 -208
  79. package/examples/preimage/generate_sighash_examples.js +0 -152
  80. package/examples/preimage/parse_preimage.js +0 -117
  81. package/examples/preimage/test_preimage_extractor.js +0 -53
  82. package/examples/preimage/test_varint_extraction.js +0 -95
  83. package/examples/scripts/custom_script_helper_example.js +0 -273
  84. package/examples/scripts/script_interpreter.js +0 -193
  85. package/examples/smart_contract/complete_workflow_demo.js +0 -343
  86. package/examples/smart_contract/covenant_builder_demo.js +0 -176
  87. package/examples/smart_contract/script_testing_integration.js +0 -198
  88. package/examples/smart_contract_templates.js +0 -718
  89. package/examples/working_smart_contracts.js +0 -348
@@ -1,242 +0,0 @@
1
- #!/usr/bin/env node
2
-
3
- /**
4
- * SmartLedger Real BSV Wallet Demo
5
- *
6
- * This script demonstrates how to use SmartLedger-BSV with real BSV addresses
7
- * for UTXO management, transaction creation, and validation.
8
- *
9
- * Usage Examples:
10
- * - Check real BSV address balance and UTXOs
11
- * - Create and validate real BSV transactions
12
- * - Test signature verification with real data
13
- * - Optionally broadcast transactions to BSV network
14
- */
15
-
16
- const bsv = require('../index.js');
17
-
18
- // Demo configuration - replace with your own for real use
19
- const DEMO_CONFIG = {
20
- // Test private key (has 0 balance) - replace with your own for real testing
21
- privateKey: 'L1aW4aubDFB7yfras2S1mN3bqg9nwySY8nkoLmJebSLD5BWv3ENZ',
22
-
23
- // Demo addresses for testing
24
- testAddresses: {
25
- bitcoinEater: '1BitcoinEaterAddressDontSendf59kuE', // Provably unspendable
26
- satoshiGenesis: '12c6DSiU4Rq3P4ZxziKxzrL5LmMBrzjrJX' // Genesis block address
27
- }
28
- };
29
-
30
- console.log('šŸš€ SmartLedger Real BSV Wallet Demo');
31
- console.log('===================================\n');
32
-
33
- console.log('šŸ’” This demo shows how to:');
34
- console.log(' • Use real BSV private keys and addresses');
35
- console.log(' • Fetch real UTXOs from the BSV blockchain');
36
- console.log(' • Create and validate real BSV transactions');
37
- console.log(' • Test signature verification with real data');
38
- console.log(' • Optionally broadcast to the BSV network\n');
39
-
40
- console.log('āš ļø IMPORTANT SAFETY NOTES:');
41
- console.log(' • This demo uses a test key with 0 balance');
42
- console.log(' • Replace DEMO_CONFIG.privateKey with your own for real use');
43
- console.log(' • Always test on testnet first (use --testnet flag)');
44
- console.log(' • Broadcasting requires --broadcast flag for safety\n');
45
-
46
- // Initialize wallet
47
- const privateKey = new bsv.PrivateKey(DEMO_CONFIG.privateKey);
48
- const address = privateKey.toAddress().toString();
49
-
50
- console.log('šŸ“± Demo Wallet:');
51
- console.log(`Private Key: ${DEMO_CONFIG.privateKey}`);
52
- console.log(`Address: ${address}`);
53
- console.log(`Public Key: ${privateKey.publicKey.toString()}\n`);
54
-
55
- // Real BSV integration example
56
- async function demonstrateRealBSV() {
57
- console.log('šŸŒ Real BSV Blockchain Integration:');
58
- console.log('==================================');
59
- console.log('');
60
- console.log('šŸ“š Real BSV integration available via separate modules');
61
-
62
- console.log('1. āœ… SmartLedger signature verification works');
63
- console.log('2. āœ… Real UTXO fetching via WhatsOnChain API');
64
- console.log('3. āœ… Transaction creation and validation');
65
- console.log('4. āœ… Broadcasting capability (when enabled)');
66
- console.log('5. āœ… Mock UTXO fallback for testing\n');
67
- }
68
-
69
- // Signature verification demo with real keys
70
- function demonstrateSignatureVerification() {
71
- console.log('šŸ” Signature Verification with Real Keys:');
72
- console.log('=========================================');
73
-
74
- // Create a message to sign
75
- const message = `SmartLedger-BSV Demo - ${new Date().toISOString()}`;
76
- const messageBuffer = Buffer.from(message, 'utf8');
77
- const hash = bsv.crypto.Hash.sha256(messageBuffer);
78
-
79
- console.log(`Message: "${message}"`);
80
- console.log(`Hash: ${hash.toString('hex')}`);
81
-
82
- // Create signature
83
- const signature = bsv.crypto.ECDSA.sign(hash, privateKey);
84
- const derSig = signature.toDER();
85
-
86
- console.log(`Signature: ${derSig.toString('hex')}`);
87
- console.log(`Is canonical: ${signature.isCanonical()}`);
88
-
89
- // Verify signature - this was broken in v3.0.1, fixed in v3.0.2!
90
- const verified1 = bsv.crypto.ECDSA.verify(hash, derSig, privateKey.publicKey);
91
- const verified2 = bsv.SmartVerify.smartVerify(hash, derSig, privateKey.publicKey);
92
- const isCanonical = bsv.SmartVerify.isCanonical(derSig);
93
-
94
- console.log('\nšŸ“Š Verification Results:');
95
- console.log(`ECDSA.verify(): ${verified1 ? 'āœ… VALID' : 'āŒ INVALID'}`);
96
- console.log(`SmartVerify.smartVerify(): ${verified2 ? 'āœ… VALID' : 'āŒ INVALID'}`);
97
- console.log(`SmartVerify.isCanonical(): ${isCanonical ? 'āœ… CANONICAL' : 'āŒ NON-CANONICAL'}`);
98
-
99
- if (verified1 && verified2 && isCanonical) {
100
- console.log('\nšŸŽ‰ All signature verification methods working correctly!');
101
- } else {
102
- console.log('\nāŒ Signature verification failed - this indicates a bug');
103
- }
104
- }
105
-
106
- // Transaction creation demo
107
- function demonstrateTransactionCreation() {
108
- console.log('\nšŸ’ø Transaction Creation Demo:');
109
- console.log('============================');
110
-
111
- // Create a mock UTXO for demonstration
112
- const mockUTXO = {
113
- txid: '0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef',
114
- vout: 0,
115
- address: address,
116
- satoshis: 100000, // 1000 bits
117
- script: '76a914' + bsv.Address.fromString(address).hashBuffer.toString('hex') + '88ac'
118
- };
119
-
120
- console.log('Mock UTXO for demo:');
121
- console.log(` TXID: ${mockUTXO.txid}`);
122
- console.log(` Vout: ${mockUTXO.vout}`);
123
- console.log(` Address: ${mockUTXO.address}`);
124
- console.log(` Satoshis: ${mockUTXO.satoshis}`);
125
-
126
- try {
127
- // Create transaction
128
- const transaction = new bsv.Transaction()
129
- .from(mockUTXO)
130
- .to(DEMO_CONFIG.testAddresses.bitcoinEater, 1000)
131
- .change(address)
132
- .sign(privateKey);
133
-
134
- console.log('\nšŸ—ļø Transaction Created:');
135
- console.log(` Transaction ID: ${transaction.id}`);
136
- console.log(` Inputs: ${transaction.inputs.length}`);
137
- console.log(` Outputs: ${transaction.outputs.length}`);
138
- console.log(` Size: ${transaction.toBuffer().length} bytes`);
139
-
140
- // Validate transaction
141
- const isValid = transaction.verify();
142
- console.log(` Validation: ${isValid ? 'āœ… VALID' : 'āŒ INVALID'}`);
143
-
144
- if (isValid) {
145
- console.log(` Raw TX: ${transaction.toString()}`);
146
- console.log('\nāœ… Transaction created and validated successfully!');
147
- console.log('šŸ’” This transaction could be broadcast with real UTXOs');
148
- } else {
149
- console.log('\nāŒ Transaction validation failed');
150
- }
151
- } catch (error) {
152
- console.log(`\nāŒ Transaction creation failed: ${error.message}`);
153
- }
154
- }
155
-
156
- // UTXO management demo
157
- function demonstrateUTXOManagement() {
158
- console.log('\nšŸ’° UTXO Management Demo:');
159
- console.log('========================');
160
-
161
- // Create SmartUTXO manager
162
- const utxoManager = new bsv.SmartUTXO();
163
-
164
- // Create some mock UTXOs
165
- const mockUTXOs = utxoManager.createMockUTXOs(address, 3, 50000);
166
-
167
- console.log('Adding mock UTXOs to management system:');
168
- mockUTXOs.forEach((utxo, i) => {
169
- utxoManager.addUTXO(utxo);
170
- console.log(` ${i + 1}: ${utxo.txid.substring(0, 16)}...${utxo.txid.substring(48)}:${utxo.vout} = ${utxo.satoshis} sats`);
171
- });
172
-
173
- // Check balance and UTXOs
174
- const balance = utxoManager.getBalance(address);
175
- const utxos = utxoManager.getUTXOsForAddress(address);
176
- const stats = utxoManager.getStats();
177
-
178
- console.log('\nšŸ“Š Wallet Status:');
179
- console.log(` Balance: ${balance} satoshis (${balance / 100000000} BSV)`);
180
- console.log(` Available UTXOs: ${utxos.length}`);
181
- console.log(` Total blockchain UTXOs: ${stats.totalUTXOs}`);
182
- console.log(` Total blockchain value: ${stats.totalValue} satoshis`);
183
-
184
- // Demonstrate spending
185
- if (utxos.length > 0) {
186
- const utxoToSpend = utxos[0];
187
- console.log(`\nšŸ’ø Spending UTXO: ${utxoToSpend.txid.substring(0, 16)}...${utxoToSpend.txid.substring(48)}:${utxoToSpend.vout}`);
188
-
189
- utxoManager.spendUTXOs([{ txid: utxoToSpend.txid, vout: utxoToSpend.vout }]);
190
-
191
- const newBalance = utxoManager.getBalance(address);
192
- console.log(` New balance: ${newBalance} satoshis (reduced by ${balance - newBalance})`);
193
- }
194
-
195
- console.log('\nāœ… UTXO management working correctly!');
196
- }
197
-
198
- // Production usage guide
199
- function showProductionGuide() {
200
- console.log('\nšŸ“š Production Usage Guide:');
201
- console.log('=========================');
202
-
203
- console.log('For real BSV applications:');
204
- console.log('');
205
- console.log('1. šŸ”‘ Replace DEMO_CONFIG.privateKey with your private key');
206
- console.log(' const privateKey = new bsv.PrivateKey("YOUR_PRIVATE_KEY_WIF");');
207
- console.log('');
208
- console.log('2. šŸŒ Fetch real UTXOs using the RealUTXOManager:');
209
- console.log(' const utxoManager = new RealUTXOManager({ network: "main" });');
210
- console.log(' const realUTXOs = await utxoManager.fetchRealUTXOs(address);');
211
- console.log('');
212
- console.log('3. šŸ’ø Create real transactions:');
213
- console.log(' const txResult = await utxoManager.createAndValidateTransaction(');
214
- console.log(' fromAddress, toAddress, satoshis, feePerByte');
215
- console.log(' );');
216
- console.log('');
217
- console.log('4. šŸ“” Broadcast to network (BE CAREFUL!):');
218
- console.log(' if (txResult.isValid) {');
219
- console.log(' await utxoManager.broadcastTransaction(txResult.rawTx);');
220
- console.log(' }');
221
- console.log('');
222
- console.log('šŸ’” Always test on testnet first: node real_utxo_test.js --testnet');
223
- console.log('āš ļø Use --broadcast flag only when ready to spend real BSV!');
224
- }
225
-
226
- // Run all demos
227
- console.log('šŸš€ Running SmartLedger-BSV Demos...\n');
228
-
229
- demonstrateSignatureVerification();
230
- demonstrateTransactionCreation();
231
- demonstrateUTXOManagement();
232
- demonstrateRealBSV();
233
- showProductionGuide();
234
-
235
- console.log('\nšŸŽ‰ Demo completed successfully!');
236
- console.log('āœ… SmartLedger-BSV v3.0.2 is ready for real BSV development!');
237
- console.log('');
238
- console.log('šŸ“– Next steps:');
239
- console.log(' • Run: node real_utxo_test.js --help');
240
- console.log(' • Test with testnet: node real_utxo_test.js --testnet');
241
- console.log(' • Check documentation: README.md and CHANGELOG.md');
242
- console.log(' • Report issues: https://github.com/codenlighten/smartledger-bsv/issues');