smartledger-bsv 3.3.3 → 3.3.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 (62) hide show
  1. package/CHANGELOG.md +50 -28
  2. package/README.md +55 -36
  3. package/bsv-covenant.min.js +6 -6
  4. package/bsv-gdaf.min.js +6 -6
  5. package/bsv-ltp.min.js +6 -6
  6. package/bsv-mnemonic.min.js +4 -4
  7. package/bsv-smartcontract.min.js +5 -5
  8. package/bsv.bundle.js +5 -5
  9. package/bsv.min.js +5 -5
  10. package/demos/README.md +188 -0
  11. package/demos/architecture_demo.js +247 -0
  12. package/demos/browser-test.html +1208 -0
  13. package/demos/bsv_wallet_demo.js +242 -0
  14. package/demos/complete_ltp_demo.js +511 -0
  15. package/demos/debug_tools_demo.js +87 -0
  16. package/demos/demo_features.js +123 -0
  17. package/demos/easy_interface_demo.js +109 -0
  18. package/demos/ecies_demo.js +182 -0
  19. package/demos/gdaf_core_test.js +131 -0
  20. package/demos/gdaf_demo.js +237 -0
  21. package/demos/ltp_demo.js +361 -0
  22. package/demos/ltp_primitives_demo.js +403 -0
  23. package/demos/message_demo.js +209 -0
  24. package/demos/preimage_separation_demo.js +383 -0
  25. package/demos/script_helper_demo.js +289 -0
  26. package/demos/security_demo.js +287 -0
  27. package/demos/shamir_demo.js +121 -0
  28. package/demos/simple_demo.js +204 -0
  29. package/demos/simple_p2pkh_demo.js +169 -0
  30. package/demos/simple_utxo_preimage_demo.js +196 -0
  31. package/demos/smart_contract_demo.html +1347 -0
  32. package/demos/smart_contract_demo.js +910 -0
  33. package/demos/utxo_generator_demo.js +244 -0
  34. package/demos/validation_pipeline_demo.js +155 -0
  35. package/demos/web3keys.html +740 -0
  36. package/docs/BUNDLE_UPDATE_SUMMARY.md +40 -0
  37. package/docs/DOCUMENTATION_REVIEW_REPORT.md +11 -11
  38. package/docs/FIX_CREATEHMAC_ISSUE.md +91 -0
  39. package/docs/MODULE_REFERENCE_COMPLETE.md +28 -28
  40. package/docs/SMARTLEDGER_BSV_USAGE_ANSWERS.md +477 -0
  41. package/docs/SMARTLEDGER_BSV_USAGE_EXAMPLES.js +372 -0
  42. package/docs/SMARTLEDGER_BSV_USAGE_GUIDE.md +555 -0
  43. package/docs/SMART_CONTRACT_DEVELOPMENT_GUIDE.md +1459 -0
  44. package/docs/advanced/UTXO_MANAGER_GUIDE.md +2 -2
  45. package/docs/getting-started/INSTALLATION.md +25 -25
  46. package/docs/getting-started/QUICK_START.md +7 -7
  47. package/docs/migration/FROM_BSV_1_5_6.md +5 -5
  48. package/examples/complete_workflow_demo.js +783 -0
  49. package/examples/definitive_working_demo.js +261 -0
  50. package/examples/final_working_contracts.js +338 -0
  51. package/examples/smart_contract_templates.js +718 -0
  52. package/examples/working_smart_contracts.js +348 -0
  53. package/index.js +7 -0
  54. package/lib/browser-utxo-manager-es5.js +316 -0
  55. package/lib/browser-utxo-manager.js +533 -0
  56. package/lib/mnemonic/pbkdf2.browser.js +69 -0
  57. package/lib/mnemonic/pbkdf2.js +2 -68
  58. package/lib/mnemonic/pbkdf2.node.js +68 -0
  59. package/package.json +19 -8
  60. package/tests/browser-compatibility/README.md +35 -0
  61. package/tests/browser-compatibility/test-cdn-vs-local.html +186 -0
  62. package/tests/browser-compatibility/test-pbkdf2.html +51 -0
@@ -0,0 +1,242 @@
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');