@smartledger/bsv 3.4.0 → 3.4.2

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 (48) hide show
  1. package/CHANGELOG.md +64 -0
  2. package/README.md +60 -32
  3. package/bsv-anchor.min.js +12 -0
  4. package/bsv-covenant.min.js +8 -8
  5. package/bsv-didweb.min.js +12 -0
  6. package/bsv-gdaf.min.js +9 -9
  7. package/bsv-ltp.min.js +9 -9
  8. package/bsv-mnemonic.min.js +2 -2
  9. package/bsv-shamir.min.js +3 -3
  10. package/bsv-smartcontract.min.js +5 -5
  11. package/bsv-statuslist.min.js +18 -0
  12. package/bsv-vcjwt.min.js +12 -0
  13. package/bsv.bundle.js +9 -9
  14. package/bsv.min.js +5 -5
  15. package/build/webpack.anchor.config.js +9 -13
  16. package/build/webpack.didweb.config.js +10 -14
  17. package/build/webpack.statuslist.config.js +9 -14
  18. package/build/webpack.vcjwt.config.js +9 -13
  19. package/examples/legacy/README.md +11 -0
  20. package/index.js +24 -6
  21. package/lib/browser-utxo-manager-es5.js +11 -4
  22. package/lib/browser-utxo-manager.js +15 -8
  23. package/lib/ltp/claim.js +1 -0
  24. package/lib/ltp/obligation.js +1 -0
  25. package/lib/ltp/registry.js +2 -0
  26. package/lib/ltp/right.js +1 -0
  27. package/lib/transaction/transaction.js +1 -1
  28. package/lib/util/_.js +7 -1
  29. package/package.json +9 -11
  30. package/demos/gdaf_core_test.js +0 -131
  31. package/examples/scripts/custom_script_signature_test.js +0 -344
  32. package/tests/browser-compatibility/README.md +0 -35
  33. package/tests/browser-compatibility/test-cdn-vs-local.html +0 -186
  34. package/tests/browser-compatibility/test-pbkdf2.html +0 -51
  35. package/tests/bundle-completeness-test.html +0 -131
  36. package/tests/bundle-demo.html +0 -476
  37. package/tests/smartcontract-test.html +0 -239
  38. package/tests/standalone-modules-test.html +0 -260
  39. package/tests/test.html +0 -612
  40. package/tests/test_standalone_shamir.html +0 -83
  41. package/tests/unpkg-demo.html +0 -194
  42. package/utilities/blockchain-state.json +0 -118565
  43. /package/{lib/smart_contract/test_integration.js → examples/legacy/smart_contract_test_integration.js} +0 -0
  44. /package/{tests → examples/legacy}/test_builtin_verify.js +0 -0
  45. /package/{tests → examples/legacy}/test_debug_integration.js +0 -0
  46. /package/{tests → examples/legacy}/test_ecdsa_little.js +0 -0
  47. /package/{tests → examples/legacy}/test_shamir.js +0 -0
  48. /package/{tests → examples/legacy}/test_smartverify_der.js +0 -0
@@ -1,131 +0,0 @@
1
- <!DOCTYPE html>
2
- <html>
3
- <head>
4
- <title>BSV Bundle Completeness Test</title>
5
- <style>
6
- body { font-family: Arial; margin: 20px; }
7
- .success { color: green; }
8
- .error { color: red; }
9
- .warning { color: orange; }
10
- .module-test { margin: 10px 0; padding: 10px; border: 1px solid #ccc; }
11
- </style>
12
- </head>
13
- <body>
14
- <h1>🔬 BSV Bundle Completeness Test</h1>
15
- <p>Testing that our bundle includes all modules from the main library...</p>
16
-
17
- <div id="results"></div>
18
-
19
- <script src="bsv.bundle.js"></script>
20
- <script>
21
- const results = document.getElementById('results');
22
-
23
- function log(message, className = '') {
24
- const div = document.createElement('div');
25
- div.className = className;
26
- div.innerHTML = message;
27
- results.appendChild(div);
28
- console.log(message);
29
- }
30
-
31
- function testModule(name, accessor, required = true) {
32
- const div = document.createElement('div');
33
- div.className = 'module-test';
34
-
35
- try {
36
- const module = accessor();
37
- if (module) {
38
- div.innerHTML = `<span class="success">✅ ${name}: Available</span>`;
39
- if (typeof module === 'function') {
40
- div.innerHTML += ` (Constructor)`;
41
- } else if (typeof module === 'object') {
42
- const keys = Object.keys(module);
43
- div.innerHTML += ` (${keys.length} properties: ${keys.slice(0, 3).join(', ')}${keys.length > 3 ? '...' : ''})`;
44
- }
45
- } else {
46
- div.innerHTML = `<span class="${required ? 'error' : 'warning'}">${required ? '❌' : '⚠️'} ${name}: Not available</span>`;
47
- }
48
- } catch (e) {
49
- div.innerHTML = `<span class="${required ? 'error' : 'warning'}">${required ? '❌' : '⚠️'} ${name}: Error - ${e.message}</span>`;
50
- }
51
-
52
- results.appendChild(div);
53
- }
54
-
55
- // Test all modules that should be in the bundle
56
- log('<h2>Core BSV Library</h2>');
57
- testModule('bsv', () => bsv);
58
- testModule('bsv.version', () => bsv.version);
59
- testModule('bsv.PrivateKey', () => bsv.PrivateKey);
60
- testModule('bsv.PublicKey', () => bsv.PublicKey);
61
- testModule('bsv.Address', () => bsv.Address);
62
- testModule('bsv.Transaction', () => bsv.Transaction);
63
- testModule('bsv.Script', () => bsv.Script);
64
-
65
- log('<h2>Crypto Modules</h2>');
66
- testModule('bsv.crypto.Hash', () => bsv.crypto.Hash);
67
- testModule('bsv.crypto.ECDSA', () => bsv.crypto.ECDSA);
68
- testModule('bsv.crypto.Signature', () => bsv.crypto.Signature);
69
- testModule('bsv.crypto.SmartVerify', () => bsv.crypto.SmartVerify);
70
- testModule('bsv.crypto.EllipticFixed', () => bsv.crypto.EllipticFixed);
71
-
72
- log('<h2>SmartLedger Security</h2>');
73
- testModule('bsv.SmartLedger', () => bsv.SmartLedger);
74
- testModule('bsv.SmartVerify', () => bsv.SmartVerify);
75
- testModule('bsv.EllipticFixed', () => bsv.EllipticFixed);
76
-
77
- log('<h2>Additional Modules</h2>');
78
- testModule('bsv.Message', () => bsv.Message);
79
- testModule('bsv.Mnemonic', () => bsv.Mnemonic, false); // May not work in browser
80
- testModule('bsv.ECIES', () => bsv.ECIES);
81
-
82
- log('<h2>SmartContract Framework</h2>');
83
- testModule('bsv.SmartContract', () => bsv.SmartContract);
84
- if (bsv.SmartContract) {
85
- testModule('SmartContract.interpretScript', () => bsv.SmartContract.interpretScript);
86
- testModule('SmartContract.getScriptMetrics', () => bsv.SmartContract.getScriptMetrics);
87
- testModule('SmartContract.examineStack', () => bsv.SmartContract.examineStack);
88
- testModule('SmartContract.optimizeScript', () => bsv.SmartContract.optimizeScript);
89
- }
90
-
91
- log('<h2>NEW: Advanced Development Tools</h2>');
92
- testModule('bsv.CovenantInterface', () => bsv.CovenantInterface);
93
- testModule('bsv.CustomScriptHelper', () => bsv.CustomScriptHelper);
94
- testModule('bsv.Transaction.sighash', () => bsv.Transaction.sighash);
95
-
96
- log('<h2>Bundle Information</h2>');
97
- testModule('bsv.bundle', () => bsv.bundle);
98
- testModule('bsv.SmartLedgerBundle', () => bsv.SmartLedgerBundle);
99
-
100
- // Test bundle convenience methods
101
- log('<h2>Bundle Convenience Methods</h2>');
102
- if (bsv.SmartLedgerBundle) {
103
- testModule('generateKeys()', () => bsv.SmartLedgerBundle.generateKeys);
104
- testModule('createMessage()', () => bsv.SmartLedgerBundle.createMessage);
105
- testModule('encrypt()', () => bsv.SmartLedgerBundle.encrypt);
106
- testModule('examineScript()', () => bsv.SmartLedgerBundle.examineScript);
107
- testModule('createCovenant()', () => bsv.SmartLedgerBundle.createCovenant);
108
- testModule('createCustomSignature()', () => bsv.SmartLedgerBundle.createCustomSignature);
109
- testModule('calculateSighash()', () => bsv.SmartLedgerBundle.calculateSighash);
110
- }
111
-
112
- // Show bundle info
113
- if (bsv.bundle) {
114
- log('<h2>Bundle Contents</h2>');
115
- log(`<div>Version: ${bsv.bundle.version}</div>`);
116
- log(`<div>Type: ${bsv.bundle.type}</div>`);
117
- log(`<div>Includes: ${bsv.bundle.includes.join(', ')}</div>`);
118
- }
119
-
120
- // Final summary
121
- log('<h2>Summary</h2>');
122
- const successCount = document.querySelectorAll('.success').length;
123
- const errorCount = document.querySelectorAll('.error').length;
124
- const warningCount = document.querySelectorAll('.warning').length;
125
-
126
- log(`<div><strong>✅ Successful: ${successCount}</strong></div>`);
127
- if (errorCount > 0) log(`<div><strong>❌ Errors: ${errorCount}</strong></div>`);
128
- if (warningCount > 0) log(`<div><strong>⚠️ Warnings: ${warningCount}</strong></div>`);
129
- </script>
130
- </body>
131
- </html>
@@ -1,476 +0,0 @@
1
- <!DOCTYPE html>
2
- <html lang="en">
3
- <head>
4
- <meta charset="UTF-8">
5
- <meta name="viewport" content="width=device-width, initial-scale=1.0">
6
- <title>SmartLedger BSV Bundle Demo - All-in-One</title>
7
- <style>
8
- body {
9
- font-family: Arial, sans-serif;
10
- max-width: 1000px;
11
- margin: 0 auto;
12
- padding: 20px;
13
- background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
14
- color: white;
15
- }
16
- .demo-section {
17
- background: rgba(255,255,255,0.1);
18
- backdrop-filter: blur(10px);
19
- padding: 20px;
20
- margin: 20px 0;
21
- border-radius: 12px;
22
- border: 1px solid rgba(255,255,255,0.2);
23
- }
24
- h1 {
25
- color: #fff;
26
- text-align: center;
27
- font-size: 2.5em;
28
- margin-bottom: 10px;
29
- }
30
- h2 {
31
- color: #f0f0f0;
32
- border-bottom: 2px solid rgba(255,255,255,0.3);
33
- padding-bottom: 5px;
34
- }
35
- .result {
36
- background: rgba(0,0,0,0.3);
37
- padding: 15px;
38
- border-left: 4px solid #4CAF50;
39
- margin: 10px 0;
40
- font-family: 'Courier New', monospace;
41
- border-radius: 5px;
42
- font-size: 0.9em;
43
- line-height: 1.4;
44
- }
45
- .button {
46
- background: linear-gradient(45deg, #4CAF50, #45a049);
47
- color: white;
48
- border: none;
49
- padding: 12px 24px;
50
- border-radius: 25px;
51
- cursor: pointer;
52
- margin: 8px;
53
- font-weight: bold;
54
- transition: all 0.3s;
55
- box-shadow: 0 4px 8px rgba(0,0,0,0.2);
56
- }
57
- .button:hover {
58
- transform: translateY(-2px);
59
- box-shadow: 0 6px 12px rgba(0,0,0,0.3);
60
- }
61
- .feature-grid {
62
- display: grid;
63
- grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
64
- gap: 15px;
65
- margin: 20px 0;
66
- }
67
- .feature-card {
68
- background: rgba(255,255,255,0.1);
69
- padding: 15px;
70
- border-radius: 8px;
71
- text-align: center;
72
- border: 1px solid rgba(255,255,255,0.2);
73
- }
74
- .bundle-info {
75
- background: linear-gradient(45deg, #FF6B6B, #FF8E53);
76
- padding: 20px;
77
- border-radius: 12px;
78
- margin: 20px 0;
79
- text-align: center;
80
- }
81
- </style>
82
- </head>
83
- <body>
84
- <h1>🚀 SmartLedger BSV Complete Bundle</h1>
85
-
86
- <div class="bundle-info">
87
- <h2>📦 Single File - Everything Included!</h2>
88
- <p><strong>Size:</strong> ~770KB | <strong>File:</strong> bsv.bundle.js | <strong>Version:</strong> v3.2.1</p>
89
- <p>Core BSV + Message + 24-Word Mnemonics + ECIES + SmartContract + Debug Tools</p>
90
- <p><em>🔒 Defaults to 24-word mnemonics (256-bit entropy) for maximum security</em></p>
91
- <p><em>🐛 Includes integrated debug tools for script analysis</em></p>
92
- </div>
93
-
94
- <div class="demo-section">
95
- <h2>📋 Bundle Contents & Information</h2>
96
- <div id="bundle-info" class="result">Loading bundle information...</div>
97
- </div>
98
-
99
- <div class="demo-section">
100
- <h2>🔑 Core BSV - Keys & Addresses</h2>
101
- <button class="button" onclick="testCore()">Generate Keys</button>
102
- <div id="core-results" class="result">Click button to test core functionality...</div>
103
- </div>
104
-
105
- <div class="demo-section">
106
- <h2>💬 Message Signing (Built-in)</h2>
107
- <button class="button" onclick="testMessage()">Sign Message</button>
108
- <div id="message-results" class="result">Click button to test message signing...</div>
109
- </div>
110
-
111
- <div class="demo-section">
112
- <h2>🎲 HD Wallets & Mnemonic (Built-in)</h2>
113
- <button class="button" onclick="testMnemonic()">Generate Mnemonic</button>
114
- <div id="mnemonic-results" class="result">Click button to test mnemonic generation...</div>
115
- </div>
116
-
117
- <div class="demo-section">
118
- <h2>🔒 ECIES Encryption (Built-in)</h2>
119
- <button class="button" onclick="testECIES()">Test Encryption</button>
120
- <div id="ecies-results" class="result">Click button to test ECIES encryption...</div>
121
- </div>
122
-
123
- <div class="demo-section">
124
- <h2>🛡️ SmartLedger Bundle Helper</h2>
125
- <button class="button" onclick="testBundleHelpers()">Quick Generate</button>
126
- <div id="helper-results" class="result">Click button to test bundle helpers...</div>
127
- </div>
128
-
129
- <div class="demo-section">
130
- <h2>🐛 Debug Tools (v3.2.1 NEW!)</h2>
131
- <button class="button" onclick="testDebugTools()">Test Script Debug</button>
132
- <div id="debug-results" class="result">Click button to test integrated debug tools...</div>
133
- </div>
134
-
135
- <div class="demo-section">
136
- <h2>📊 Feature Comparison</h2>
137
- <div class="feature-grid">
138
- <div class="feature-card">
139
- <strong>bsv.min.js</strong><br>
140
- 459KB<br>
141
- Core only
142
- </div>
143
- <div class="feature-card">
144
- <strong>4 Separate Files</strong><br>
145
- ~1.3MB total<br>
146
- Load as needed
147
- </div>
148
- <div class="feature-card" style="background: rgba(76, 175, 80, 0.3);">
149
- <strong>bsv.bundle.js</strong><br>
150
- 770KB<br>
151
- Everything included!
152
- </div>
153
- </div>
154
- </div>
155
-
156
- <!-- Load the complete bundle -->
157
- <script src="https://unpkg.com/@smartledger/bsv@3.2.1/bsv.bundle.js"></script>
158
-
159
- <script>
160
- // Check if library loaded properly
161
- function checkLibraryLoaded() {
162
- if (typeof bsv === 'undefined') {
163
- console.error('SmartLedger-BSV not loaded');
164
- document.getElementById('bundle-info').innerHTML = `
165
- <strong>❌ Library Loading Failed</strong><br>
166
- CDN: https://unpkg.com/@smartledger/bsv@3.2.1/bsv.bundle.js<br>
167
- Please check your internet connection and try refreshing the page.
168
- `;
169
- return false;
170
- }
171
- console.log('✅ SmartLedger-BSV v3.2.1 Bundle loaded successfully');
172
- return true;
173
- }
174
- // Display bundle information
175
- function showBundleInfo() {
176
- const info = document.getElementById('bundle-info');
177
-
178
- let bundleContent = `
179
- <strong>Bundle Version:</strong> v3.2.1<br>
180
- <strong>CDN Source:</strong> https://unpkg.com/@smartledger/bsv@3.2.1/<br>
181
- <strong>Bundle Size:</strong> ~770KB<br>
182
- <strong>Available Classes:</strong><br>
183
- `;
184
-
185
- // Check what's available
186
- const available = [];
187
- if (bsv.PrivateKey) available.push('PrivateKey');
188
- if (bsv.PublicKey) available.push('PublicKey');
189
- if (bsv.Address) available.push('Address');
190
- if (bsv.Transaction) available.push('Transaction');
191
- if (bsv.Script) available.push('Script');
192
- if (bsv.Message) available.push('Message');
193
- if (bsv.Mnemonic) available.push('Mnemonic');
194
- if (bsv.HDPrivateKey) available.push('HDPrivateKey');
195
- if (bsv.ECIES) available.push('ECIES');
196
- if (bsv.crypto) available.push('crypto');
197
-
198
- bundleContent += `&nbsp;&nbsp;${available.join(', ')}<br>`;
199
-
200
- // Check SmartContract debug methods if available
201
- if (bsv.SmartContract) {
202
- const methodCount = Object.keys(bsv.SmartContract).length;
203
- const hasDebugTools = !!(bsv.SmartContract.examineStack && bsv.SmartContract.interpretScript);
204
- bundleContent += `<strong>SmartContract Methods:</strong> ${methodCount}<br>`;
205
- bundleContent += `<strong>Debug Tools Available:</strong> ${hasDebugTools ? 'Yes ✅' : 'No ❌'}<br>`;
206
- } else {
207
- bundleContent += `<strong>SmartContract Interface:</strong> Not in bundle (available in bsv.min.js)<br>`;
208
- bundleContent += `<strong>Bundle Focus:</strong> Core BSV + Message + Mnemonic + ECIES<br>`;
209
- }
210
-
211
- // Show total available properties
212
- const totalProps = Object.keys(bsv).length;
213
- bundleContent += `<strong>Total BSV Properties:</strong> ${totalProps}<br>`;
214
- bundleContent += `<strong>Bundle Status:</strong> ${available.length > 5 ? 'Fully Loaded ✅' : 'Partially Loaded ⚠️'}`;
215
-
216
- info.innerHTML = bundleContent;
217
- }
218
-
219
- // Test core BSV functionality
220
- function testCore() {
221
- try {
222
- const privateKey = new bsv.PrivateKey();
223
- const publicKey = privateKey.toPublicKey();
224
- const address = privateKey.toAddress();
225
-
226
- document.getElementById('core-results').innerHTML = `
227
- <strong>✅ Core BSV Working!</strong><br>
228
- Private Key: ${privateKey.toString().substring(0, 20)}...<br>
229
- Public Key: ${publicKey.toString().substring(0, 40)}...<br>
230
- Address: ${address.toString()}<br>
231
- Network: ${address.network.name}
232
- `;
233
- } catch (error) {
234
- document.getElementById('core-results').innerHTML = `❌ Error: ${error.message}`;
235
- }
236
- }
237
-
238
- // Test message functionality
239
- function testMessage() {
240
- try {
241
- const privateKey = new bsv.PrivateKey();
242
- const message = new bsv.Message('Hello from SmartLedger BSV Bundle!');
243
- const signature = message.sign(privateKey);
244
- const verified = message.verify(privateKey.toAddress(), signature);
245
-
246
- document.getElementById('message-results').innerHTML = `
247
- <strong>✅ Message Signing Working!</strong><br>
248
- Message: "Hello from SmartLedger BSV Bundle!"<br>
249
- Signature: ${signature.substring(0, 40)}...<br>
250
- Address: ${privateKey.toAddress().toString()}<br>
251
- Verified: ${verified ? '✅ Valid' : '❌ Invalid'}
252
- `;
253
- } catch (error) {
254
- document.getElementById('message-results').innerHTML = `❌ Error: ${error.message}`;
255
- }
256
- }
257
-
258
- // Test mnemonic functionality
259
- function testMnemonic() {
260
- try {
261
- // Generate 24-word mnemonic (256-bit entropy) for maximum security
262
- const mnemonic = new bsv.Mnemonic(256);
263
- const hdKey = mnemonic.toHDPrivateKey();
264
- const firstAddress = hdKey.deriveChild(0).privateKey.toAddress();
265
-
266
- document.getElementById('mnemonic-results').innerHTML = `
267
- <strong>✅ 24-Word Mnemonic Generation Working!</strong><br>
268
- Mnemonic: ${mnemonic.toString()}<br>
269
- Word Count: ${mnemonic.toString().split(' ').length} words (256-bit entropy)<br>
270
- HD Master: ${hdKey.toString().substring(0, 30)}...<br>
271
- First Address: ${firstAddress.toString()}<br>
272
- <em>🔒 Maximum security with 24-word phrase</em>
273
- `;
274
- } catch (error) {
275
- if (error.message.includes('createHmac') || error.message.includes('crypto')) {
276
- document.getElementById('mnemonic-results').innerHTML = `
277
- <strong>ℹ️ Browser Crypto Limitation</strong><br>
278
- <em>Mnemonic generation requires Node.js crypto module</em><br><br>
279
- <strong>✅ Available Solutions:</strong><br>
280
- • Use separate <code>bsv-mnemonic.min.js</code> for full browser support<br>
281
- • Or use in Node.js environment for complete functionality<br><br>
282
- <strong>Bundle Status:</strong> Core BSV + Message + ECIES working perfectly!<br>
283
- <em>This is expected behavior for browser crypto limitations</em>
284
- `;
285
- } else {
286
- document.getElementById('mnemonic-results').innerHTML = `❌ Error: ${error.message}`;
287
- }
288
- }
289
- }
290
-
291
- // Test ECIES functionality
292
- function testECIES() {
293
- try {
294
- const privateKey = new bsv.PrivateKey();
295
- const publicKey = privateKey.toPublicKey();
296
- const message = 'Secret message for ECIES encryption test!';
297
-
298
- // This might not work depending on ECIES implementation
299
- if (bsv.ECIES && bsv.ECIES.encrypt) {
300
- const encrypted = bsv.ECIES.encrypt(message, publicKey);
301
-
302
- document.getElementById('ecies-results').innerHTML = `
303
- <strong>✅ ECIES Encryption Working!</strong><br>
304
- Original: "${message}"<br>
305
- Encrypted: ${encrypted.toString('hex').substring(0, 40)}...<br>
306
- Public Key: ${publicKey.toString().substring(0, 40)}...
307
- `;
308
- } else {
309
- document.getElementById('ecies-results').innerHTML = `
310
- <strong>ℹ️ ECIES Available but needs specific usage pattern</strong><br>
311
- ECIES module loaded: ${bsv.ECIES ? 'Yes' : 'No'}<br>
312
- Check console for ECIES object structure
313
- `;
314
- console.log('ECIES object:', bsv.ECIES);
315
- }
316
- } catch (error) {
317
- document.getElementById('ecies-results').innerHTML = `❌ Error: ${error.message}`;
318
- }
319
- }
320
-
321
- // Test bundle helper functions
322
- function testBundleHelpers() {
323
- try {
324
- // Test basic functionality that should be available
325
- const privateKey = new bsv.PrivateKey();
326
- const address = privateKey.toAddress();
327
-
328
- // Try to create a simple transaction
329
- const tx = new bsv.Transaction();
330
-
331
- document.getElementById('helper-results').innerHTML = `
332
- <strong>✅ Bundle Core Functions Working!</strong><br>
333
- <strong>Quick Key Generation:</strong><br>
334
- &nbsp;&nbsp;Address: ${address.toString()}<br>
335
- &nbsp;&nbsp;Network: ${address.network.name}<br>
336
- <strong>Transaction Creation:</strong><br>
337
- &nbsp;&nbsp;Empty TX: ${tx.id || 'Created successfully'}<br>
338
- <strong>Bundle Status:</strong> All core features operational!<br>
339
- <em>Note: Advanced helpers may vary by bundle configuration</em>
340
- `;
341
- } catch (error) {
342
- document.getElementById('helper-results').innerHTML = `❌ Error: ${error.message}`;
343
- }
344
- }
345
-
346
- // Test debug tools (NEW in v3.2.1)
347
- function testDebugTools() {
348
- try {
349
- // First, let's see what's actually available in the bsv object
350
- console.log('BSV object keys:', Object.keys(bsv));
351
- console.log('SmartContract available:', !!bsv.SmartContract);
352
-
353
- let debugContent = `<strong>🐛 Debug Tools Investigation (v3.2.1):</strong><br>`;
354
-
355
- // Check for SmartContract interface
356
- if (bsv.SmartContract) {
357
- const methodCount = Object.keys(bsv.SmartContract).length;
358
- const hasExaminer = !!bsv.SmartContract.examineStack;
359
- const hasInterpreter = !!bsv.SmartContract.interpretScript;
360
- const hasMetrics = !!bsv.SmartContract.getScriptMetrics;
361
- const hasOptimizer = !!bsv.SmartContract.optimizeScript;
362
-
363
- debugContent += `
364
- <strong>✅ SmartContract Interface Found!</strong><br>
365
- <strong>Total Methods:</strong> ${methodCount}<br>
366
- <strong>Debug Tools Available:</strong><br>
367
- &nbsp;&nbsp;examineStack: ${hasExaminer ? '✅' : '❌'}<br>
368
- &nbsp;&nbsp;interpretScript: ${hasInterpreter ? '✅' : '❌'}<br>
369
- &nbsp;&nbsp;getScriptMetrics: ${hasMetrics ? '✅' : '❌'}<br>
370
- &nbsp;&nbsp;optimizeScript: ${hasOptimizer ? '✅' : '❌'}<br>
371
- `;
372
-
373
- // Test with a simple script if debug tools are available
374
- if (hasExaminer) {
375
- try {
376
- const script = bsv.Script.fromASM('OP_1 OP_2 OP_ADD');
377
- const result = bsv.SmartContract.examineStack(script);
378
- debugContent += `<strong>Live Test:</strong><br>`;
379
- debugContent += `&nbsp;&nbsp;Script: OP_1 OP_2 OP_ADD<br>`;
380
- debugContent += `&nbsp;&nbsp;Examination: Success ✅<br>`;
381
- } catch (e) {
382
- debugContent += `&nbsp;&nbsp;Script test error: ${e.message}<br>`;
383
- }
384
- }
385
-
386
- debugContent += `<strong>Status:</strong> Debug tools ${hasExaminer && hasInterpreter ? 'fully integrated! 🚀' : 'partially available'}`;
387
- } else {
388
- // SmartContract not available, but let's check what debug functionality might exist
389
- debugContent += `
390
- <strong>ℹ️ SmartContract Interface Not Found in Bundle</strong><br>
391
- <strong>Available BSV Components:</strong><br>
392
- `;
393
-
394
- // List available components
395
- const coreComponents = [
396
- 'PrivateKey', 'PublicKey', 'Address', 'Transaction', 'Script',
397
- 'Message', 'Mnemonic', 'HDPrivateKey', 'crypto', 'util'
398
- ];
399
-
400
- coreComponents.forEach(component => {
401
- if (bsv[component]) {
402
- debugContent += `&nbsp;&nbsp;${component}: ✅<br>`;
403
- }
404
- });
405
-
406
- // Check for script-related debugging capability
407
- if (bsv.Script) {
408
- try {
409
- const script = bsv.Script.fromASM('OP_1 OP_2 OP_ADD');
410
- debugContent += `<strong>Basic Script Test:</strong><br>`;
411
- debugContent += `&nbsp;&nbsp;Script creation: ✅<br>`;
412
- debugContent += `&nbsp;&nbsp;ASM: ${script.toASM()}<br>`;
413
- debugContent += `&nbsp;&nbsp;Hex: ${script.toHex().substring(0, 20)}...<br>`;
414
- } catch (e) {
415
- debugContent += `&nbsp;&nbsp;Script test failed: ${e.message}<br>`;
416
- }
417
- }
418
-
419
- debugContent += `
420
- <strong>Bundle Note:</strong> Debug tools may be in the separate minified file.<br>
421
- <em>Use <code>bsv.min.js</code> for full SmartContract interface with debug tools.</em>
422
- `;
423
- }
424
-
425
- document.getElementById('debug-results').innerHTML = debugContent;
426
- } catch (error) {
427
- document.getElementById('debug-results').innerHTML = `
428
- <strong>❌ Debug Tools Test Failed:</strong><br>
429
- Error: ${error.message}<br><br>
430
- <strong>Troubleshooting:</strong><br>
431
- • Check browser console for detailed errors<br>
432
- • Verify CDN connectivity<br>
433
- • Try refreshing the page<br>
434
- • Debug tools may require the main bsv.min.js file
435
- `;
436
- }
437
- }
438
-
439
- // Initialize on page load
440
- window.addEventListener('load', () => {
441
- // Wait a moment for the library to fully load
442
- setTimeout(() => {
443
- if (checkLibraryLoaded()) {
444
- showBundleInfo();
445
-
446
- // Enhanced debugging information
447
- console.log('=== SmartLedger-BSV Bundle Debug Info ===');
448
- console.log('BSV object keys:', Object.keys(bsv));
449
- console.log('SmartContract available:', !!bsv.SmartContract);
450
- console.log('Total BSV properties:', Object.keys(bsv).length);
451
-
452
- if (bsv.SmartContract) {
453
- console.log('SmartContract methods:', Object.keys(bsv.SmartContract).length);
454
- console.log('Debug tools:', {
455
- examineStack: !!bsv.SmartContract.examineStack,
456
- interpretScript: !!bsv.SmartContract.interpretScript,
457
- getScriptMetrics: !!bsv.SmartContract.getScriptMetrics,
458
- optimizeScript: !!bsv.SmartContract.optimizeScript
459
- });
460
- } else {
461
- console.log('SmartContract not found in bundle - debug tools available in bsv.min.js');
462
- }
463
-
464
- // Check for other important components
465
- const components = ['crypto', 'Message', 'Script', 'Transaction'];
466
- components.forEach(comp => {
467
- console.log(`${comp} available:`, !!bsv[comp]);
468
- });
469
-
470
- console.log('=== End Debug Info ===');
471
- }
472
- }, 500);
473
- });
474
- </script>
475
- </body>
476
- </html>