smartledger-bsv 3.3.5 → 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 (126) hide show
  1. package/CHANGELOG.md +400 -0
  2. package/README.md +235 -80
  3. package/SECURITY.md +88 -0
  4. package/anchor-entry.js +1 -0
  5. package/bin/cli.js +354 -0
  6. package/bsv-anchor.min.js +12 -0
  7. package/bsv-covenant.min.js +8 -8
  8. package/bsv-didweb.min.js +12 -0
  9. package/bsv-gdaf.min.js +9 -9
  10. package/bsv-ltp.min.js +9 -9
  11. package/bsv-mnemonic.min.js +2 -2
  12. package/bsv-shamir.min.js +3 -3
  13. package/bsv-smartcontract.min.js +9 -9
  14. package/bsv-statuslist.min.js +18 -0
  15. package/bsv-vcjwt.min.js +12 -0
  16. package/bsv.bundle.js +9 -9
  17. package/bsv.d.ts +486 -9
  18. package/bsv.min.js +8 -8
  19. package/build/webpack.anchor.config.js +17 -0
  20. package/build/webpack.didweb.config.js +17 -0
  21. package/build/webpack.statuslist.config.js +17 -0
  22. package/build/webpack.vcjwt.config.js +17 -0
  23. package/didweb-entry.js +1 -0
  24. package/docs/COVENANT_DEVELOPMENT_RESOLVED.md +2 -2
  25. package/docs/MODULE_REFERENCE_COMPLETE.md +61 -58
  26. package/docs/advanced/LEGAL_TOKEN_PROTOCOL.md +3 -3
  27. package/docs/advanced/UTXO_MANAGER_GUIDE.md +1 -1
  28. package/docs/getting-started/INSTALLATION.md +30 -30
  29. package/docs/getting-started/QUICK_START.md +18 -18
  30. package/docs/migration/FROM_BSV_1_5_6.md +16 -10
  31. package/docs/technical/roadmap.md +3 -3
  32. package/gdaf-entry.js +1 -2
  33. package/index.js +68 -9
  34. package/lib/anchor/index.js +102 -0
  35. package/lib/browser-utxo-manager-es5.js +11 -4
  36. package/lib/browser-utxo-manager.js +15 -8
  37. package/lib/didweb/index.js +177 -0
  38. package/lib/ltp/claim.js +1 -0
  39. package/lib/ltp/obligation.js +1 -0
  40. package/lib/ltp/registry.js +2 -0
  41. package/lib/ltp/right.js +1 -0
  42. package/lib/smart_contract/covenant.js +10 -1
  43. package/lib/smartutxo.js +20 -12
  44. package/lib/statuslist/index.js +164 -0
  45. package/lib/transaction/transaction.js +8 -1
  46. package/lib/util/_.js +7 -1
  47. package/lib/vcjwt/index.js +189 -0
  48. package/ltp-entry.js +1 -2
  49. package/package.json +21 -15
  50. package/statuslist-entry.js +1 -0
  51. package/utilities/blockchain-state.js +32 -23
  52. package/vcjwt-entry.js +1 -0
  53. package/demos/README.md +0 -188
  54. package/demos/architecture_demo.js +0 -247
  55. package/demos/browser-test.html +0 -1208
  56. package/demos/bsv_wallet_demo.js +0 -242
  57. package/demos/complete_ltp_demo.js +0 -511
  58. package/demos/debug_tools_demo.js +0 -87
  59. package/demos/demo_features.js +0 -123
  60. package/demos/easy_interface_demo.js +0 -109
  61. package/demos/ecies_demo.js +0 -182
  62. package/demos/gdaf_core_test.js +0 -131
  63. package/demos/gdaf_demo.js +0 -237
  64. package/demos/ltp_demo.js +0 -361
  65. package/demos/ltp_primitives_demo.js +0 -403
  66. package/demos/message_demo.js +0 -209
  67. package/demos/preimage_separation_demo.js +0 -383
  68. package/demos/script_helper_demo.js +0 -289
  69. package/demos/security_demo.js +0 -287
  70. package/demos/shamir_demo.js +0 -121
  71. package/demos/simple_demo.js +0 -204
  72. package/demos/simple_p2pkh_demo.js +0 -169
  73. package/demos/simple_utxo_preimage_demo.js +0 -196
  74. package/demos/smart_contract_demo.html +0 -1347
  75. package/demos/smart_contract_demo.js +0 -910
  76. package/demos/utxo_generator_demo.js +0 -244
  77. package/demos/validation_pipeline_demo.js +0 -155
  78. package/demos/web3keys.html +0 -740
  79. package/examples/README.md +0 -200
  80. package/examples/basic/transaction-creation.js +0 -534
  81. package/examples/basic/transaction_signature_api_gap.js +0 -178
  82. package/examples/complete_workflow_demo.js +0 -783
  83. package/examples/covenants/advanced_covenant_demo.js +0 -219
  84. package/examples/covenants/covenant_interface_demo.js +0 -270
  85. package/examples/covenants/covenant_manual_signature_resolved.js +0 -212
  86. package/examples/covenants/covenant_signature_template.js +0 -117
  87. package/examples/covenants2/covenant_bidirectional_example.js +0 -262
  88. package/examples/covenants2/covenant_utils_demo.js +0 -120
  89. package/examples/covenants2/preimage_covenant_utils.js +0 -287
  90. package/examples/covenants2/production_integration.js +0 -256
  91. package/examples/data/covenant_utxos.json +0 -28
  92. package/examples/data/utxos.json +0 -26
  93. package/examples/definitive_working_demo.js +0 -261
  94. package/examples/final_working_contracts.js +0 -338
  95. package/examples/preimage/README.md +0 -178
  96. package/examples/preimage/extract_preimage_bidirectional.js +0 -421
  97. package/examples/preimage/generate_sample_preimage.js +0 -208
  98. package/examples/preimage/generate_sighash_examples.js +0 -152
  99. package/examples/preimage/parse_preimage.js +0 -117
  100. package/examples/preimage/test_preimage_extractor.js +0 -53
  101. package/examples/preimage/test_varint_extraction.js +0 -95
  102. package/examples/scripts/custom_script_helper_example.js +0 -273
  103. package/examples/scripts/custom_script_signature_test.js +0 -344
  104. package/examples/scripts/script_interpreter.js +0 -193
  105. package/examples/smart_contract/complete_workflow_demo.js +0 -343
  106. package/examples/smart_contract/covenant_builder_demo.js +0 -176
  107. package/examples/smart_contract/script_testing_integration.js +0 -198
  108. package/examples/smart_contract_templates.js +0 -718
  109. package/examples/working_smart_contracts.js +0 -348
  110. package/lib/smart_contract/test_integration.js +0 -269
  111. package/tests/browser-compatibility/README.md +0 -35
  112. package/tests/browser-compatibility/test-cdn-vs-local.html +0 -186
  113. package/tests/browser-compatibility/test-pbkdf2.html +0 -51
  114. package/tests/bundle-completeness-test.html +0 -131
  115. package/tests/bundle-demo.html +0 -476
  116. package/tests/smartcontract-test.html +0 -239
  117. package/tests/standalone-modules-test.html +0 -260
  118. package/tests/test.html +0 -612
  119. package/tests/test_builtin_verify.js +0 -117
  120. package/tests/test_debug_integration.js +0 -71
  121. package/tests/test_ecdsa_little.js +0 -70
  122. package/tests/test_shamir.js +0 -221
  123. package/tests/test_smartverify_der.js +0 -110
  124. package/tests/test_standalone_shamir.html +0 -83
  125. package/tests/unpkg-demo.html +0 -194
  126. package/utilities/blockchain-state.json +0 -118565
@@ -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');