smartledger-bsv 3.4.0 → 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 (117) hide show
  1. package/CHANGELOG.md +400 -0
  2. package/README.md +112 -84
  3. package/SECURITY.md +88 -0
  4. package/bin/cli.js +13 -8
  5. package/bsv-anchor.min.js +12 -0
  6. package/bsv-covenant.min.js +8 -8
  7. package/bsv-didweb.min.js +12 -0
  8. package/bsv-gdaf.min.js +9 -9
  9. package/bsv-ltp.min.js +9 -9
  10. package/bsv-mnemonic.min.js +2 -2
  11. package/bsv-shamir.min.js +3 -3
  12. package/bsv-smartcontract.min.js +5 -5
  13. package/bsv-statuslist.min.js +18 -0
  14. package/bsv-vcjwt.min.js +12 -0
  15. package/bsv.bundle.js +9 -9
  16. package/bsv.d.ts +486 -9
  17. package/bsv.min.js +5 -5
  18. package/build/webpack.anchor.config.js +9 -13
  19. package/build/webpack.didweb.config.js +10 -14
  20. package/build/webpack.statuslist.config.js +9 -14
  21. package/build/webpack.vcjwt.config.js +9 -13
  22. package/docs/COVENANT_DEVELOPMENT_RESOLVED.md +2 -2
  23. package/docs/MODULE_REFERENCE_COMPLETE.md +61 -58
  24. package/docs/advanced/LEGAL_TOKEN_PROTOCOL.md +3 -3
  25. package/docs/advanced/UTXO_MANAGER_GUIDE.md +1 -1
  26. package/docs/getting-started/INSTALLATION.md +30 -30
  27. package/docs/getting-started/QUICK_START.md +18 -18
  28. package/docs/migration/FROM_BSV_1_5_6.md +16 -10
  29. package/gdaf-entry.js +1 -2
  30. package/index.js +44 -13
  31. package/lib/browser-utxo-manager-es5.js +11 -4
  32. package/lib/browser-utxo-manager.js +15 -8
  33. package/lib/ltp/claim.js +1 -0
  34. package/lib/ltp/obligation.js +1 -0
  35. package/lib/ltp/registry.js +2 -0
  36. package/lib/ltp/right.js +1 -0
  37. package/lib/smart_contract/covenant.js +10 -1
  38. package/lib/smartutxo.js +20 -12
  39. package/lib/transaction/transaction.js +8 -1
  40. package/lib/util/_.js +7 -1
  41. package/ltp-entry.js +1 -2
  42. package/package.json +11 -13
  43. package/utilities/blockchain-state.js +32 -23
  44. package/demos/README.md +0 -188
  45. package/demos/architecture_demo.js +0 -247
  46. package/demos/browser-test.html +0 -1208
  47. package/demos/bsv_wallet_demo.js +0 -242
  48. package/demos/complete_ltp_demo.js +0 -511
  49. package/demos/debug_tools_demo.js +0 -87
  50. package/demos/demo_features.js +0 -123
  51. package/demos/easy_interface_demo.js +0 -109
  52. package/demos/ecies_demo.js +0 -182
  53. package/demos/gdaf_core_test.js +0 -131
  54. package/demos/gdaf_demo.js +0 -237
  55. package/demos/ltp_demo.js +0 -361
  56. package/demos/ltp_primitives_demo.js +0 -403
  57. package/demos/message_demo.js +0 -209
  58. package/demos/preimage_separation_demo.js +0 -383
  59. package/demos/script_helper_demo.js +0 -289
  60. package/demos/security_demo.js +0 -287
  61. package/demos/shamir_demo.js +0 -121
  62. package/demos/simple_demo.js +0 -204
  63. package/demos/simple_p2pkh_demo.js +0 -169
  64. package/demos/simple_utxo_preimage_demo.js +0 -196
  65. package/demos/smart_contract_demo.html +0 -1347
  66. package/demos/smart_contract_demo.js +0 -910
  67. package/demos/utxo_generator_demo.js +0 -244
  68. package/demos/validation_pipeline_demo.js +0 -155
  69. package/demos/web3keys.html +0 -740
  70. package/examples/README.md +0 -200
  71. package/examples/basic/transaction-creation.js +0 -534
  72. package/examples/basic/transaction_signature_api_gap.js +0 -178
  73. package/examples/complete_workflow_demo.js +0 -783
  74. package/examples/covenants/advanced_covenant_demo.js +0 -219
  75. package/examples/covenants/covenant_interface_demo.js +0 -270
  76. package/examples/covenants/covenant_manual_signature_resolved.js +0 -212
  77. package/examples/covenants/covenant_signature_template.js +0 -117
  78. package/examples/covenants2/covenant_bidirectional_example.js +0 -262
  79. package/examples/covenants2/covenant_utils_demo.js +0 -120
  80. package/examples/covenants2/preimage_covenant_utils.js +0 -287
  81. package/examples/covenants2/production_integration.js +0 -256
  82. package/examples/data/covenant_utxos.json +0 -28
  83. package/examples/data/utxos.json +0 -26
  84. package/examples/definitive_working_demo.js +0 -261
  85. package/examples/final_working_contracts.js +0 -338
  86. package/examples/preimage/README.md +0 -178
  87. package/examples/preimage/extract_preimage_bidirectional.js +0 -421
  88. package/examples/preimage/generate_sample_preimage.js +0 -208
  89. package/examples/preimage/generate_sighash_examples.js +0 -152
  90. package/examples/preimage/parse_preimage.js +0 -117
  91. package/examples/preimage/test_preimage_extractor.js +0 -53
  92. package/examples/preimage/test_varint_extraction.js +0 -95
  93. package/examples/scripts/custom_script_helper_example.js +0 -273
  94. package/examples/scripts/custom_script_signature_test.js +0 -344
  95. package/examples/scripts/script_interpreter.js +0 -193
  96. package/examples/smart_contract/complete_workflow_demo.js +0 -343
  97. package/examples/smart_contract/covenant_builder_demo.js +0 -176
  98. package/examples/smart_contract/script_testing_integration.js +0 -198
  99. package/examples/smart_contract_templates.js +0 -718
  100. package/examples/working_smart_contracts.js +0 -348
  101. package/lib/smart_contract/test_integration.js +0 -269
  102. package/tests/browser-compatibility/README.md +0 -35
  103. package/tests/browser-compatibility/test-cdn-vs-local.html +0 -186
  104. package/tests/browser-compatibility/test-pbkdf2.html +0 -51
  105. package/tests/bundle-completeness-test.html +0 -131
  106. package/tests/bundle-demo.html +0 -476
  107. package/tests/smartcontract-test.html +0 -239
  108. package/tests/standalone-modules-test.html +0 -260
  109. package/tests/test.html +0 -612
  110. package/tests/test_builtin_verify.js +0 -117
  111. package/tests/test_debug_integration.js +0 -71
  112. package/tests/test_ecdsa_little.js +0 -70
  113. package/tests/test_shamir.js +0 -221
  114. package/tests/test_smartverify_der.js +0 -110
  115. package/tests/test_standalone_shamir.html +0 -83
  116. package/tests/unpkg-demo.html +0 -194
  117. package/utilities/blockchain-state.json +0 -118565
@@ -1,186 +0,0 @@
1
- <!DOCTYPE html>
2
- <html lang="en">
3
- <head>
4
- <meta charset="utf-8">
5
- <title>CDN vs Local PBKDF2 Test</title>
6
- <style>
7
- body { font-family: Arial, sans-serif; margin: 20px; }
8
- .test-section { margin: 20px 0; padding: 15px; border: 1px solid #ccc; border-radius: 5px; }
9
- .error { color: red; }
10
- .success { color: green; }
11
- .info { color: blue; }
12
- pre { background: #f5f5f5; padding: 10px; border-radius: 3px; }
13
- </style>
14
- </head>
15
- <body>
16
- <h1>SmartLedger BSV: CDN vs Local PBKDF2 Test</h1>
17
-
18
- <div class="test-section">
19
- <h2>Test 1: CDN Version (Expected to fail with createHmac error)</h2>
20
- <button onclick="testCDN()">Test CDN Version</button>
21
- <div id="cdn-results"></div>
22
- </div>
23
-
24
- <div class="test-section">
25
- <h2>Test 2: Local Fixed Version (Should work)</h2>
26
- <button onclick="testLocal()">Test Local Version</button>
27
- <div id="local-results"></div>
28
- </div>
29
-
30
- <div class="test-section">
31
- <h2>Summary</h2>
32
- <div id="summary"></div>
33
- </div>
34
-
35
- <script>
36
- function log(elementId, message, type = 'info') {
37
- const element = document.getElementById(elementId);
38
- const className = type === 'error' ? 'error' : type === 'success' ? 'success' : 'info';
39
- element.innerHTML += `<div class="${className}">${message}</div>`;
40
- }
41
-
42
- function clearResults(elementId) {
43
- document.getElementById(elementId).innerHTML = '';
44
- }
45
-
46
- function testCDN() {
47
- clearResults('cdn-results');
48
- log('cdn-results', 'Loading CDN version...');
49
-
50
- // Remove any existing scripts
51
- const existingScripts = document.querySelectorAll('script[src*="bsv"]');
52
- existingScripts.forEach(script => script.remove());
53
-
54
- // Clear global variables
55
- if (window.bsv) delete window.bsv;
56
- if (window.bsvMnemonic) delete window.bsvMnemonic;
57
- if (window.Mnemonic) delete window.Mnemonic;
58
-
59
- // Load CDN scripts
60
- const bsvScript = document.createElement('script');
61
- bsvScript.src = 'https://cdn.jsdelivr.net/npm/smartledger-bsv@3.3.4/bsv.min.js';
62
- bsvScript.onload = () => {
63
- const mnemonicScript = document.createElement('script');
64
- mnemonicScript.src = 'https://cdn.jsdelivr.net/npm/smartledger-bsv@3.3.4/bsv-mnemonic.min.js';
65
- mnemonicScript.onload = () => {
66
- testMnemonicGeneration('cdn-results', 'CDN');
67
- };
68
- mnemonicScript.onerror = () => {
69
- log('cdn-results', '❌ Failed to load CDN mnemonic script', 'error');
70
- };
71
- document.head.appendChild(mnemonicScript);
72
- };
73
- bsvScript.onerror = () => {
74
- log('cdn-results', '❌ Failed to load CDN BSV script', 'error');
75
- };
76
- document.head.appendChild(bsvScript);
77
- }
78
-
79
- function testLocal() {
80
- clearResults('local-results');
81
- log('local-results', 'Loading local fixed version...');
82
-
83
- // Remove any existing scripts
84
- const existingScripts = document.querySelectorAll('script[src*="bsv"]');
85
- existingScripts.forEach(script => script.remove());
86
-
87
- // Clear global variables
88
- if (window.bsv) delete window.bsv;
89
- if (window.bsvMnemonic) delete window.bsvMnemonic;
90
- if (window.Mnemonic) delete window.Mnemonic;
91
-
92
- // Load local scripts
93
- const bsvScript = document.createElement('script');
94
- bsvScript.src = '../bsv.min.js';
95
- bsvScript.onload = () => {
96
- const mnemonicScript = document.createElement('script');
97
- mnemonicScript.src = '../bsv-mnemonic.min.js';
98
- mnemonicScript.onload = () => {
99
- testMnemonicGeneration('local-results', 'Local');
100
- };
101
- mnemonicScript.onerror = () => {
102
- log('local-results', '❌ Failed to load local mnemonic script', 'error');
103
- };
104
- document.head.appendChild(mnemonicScript);
105
- };
106
- bsvScript.onerror = () => {
107
- log('local-results', '❌ Failed to load local BSV script', 'error');
108
- };
109
- document.head.appendChild(bsvScript);
110
- }
111
-
112
- function testMnemonicGeneration(resultElementId, version) {
113
- try {
114
- log(resultElementId, `${version} scripts loaded successfully`, 'info');
115
-
116
- // Check what's available
117
- const MnemonicClass = window.bsvMnemonic || window.Mnemonic || (window.bsv && window.bsv.Mnemonic);
118
- log(resultElementId, `Mnemonic class available: ${!!MnemonicClass}`, 'info');
119
-
120
- if (MnemonicClass) {
121
- // Test mnemonic generation
122
- log(resultElementId, 'Attempting to generate mnemonic...', 'info');
123
- const mnemonic = MnemonicClass.fromRandom(256);
124
- log(resultElementId, `✅ ${version} mnemonic generation successful!`, 'success');
125
- log(resultElementId, `Sample words: ${mnemonic.phrase.split(' ').slice(0, 4).join(' ')}...`, 'info');
126
-
127
- // Test key derivation
128
- log(resultElementId, 'Testing key derivation...', 'info');
129
- const hdPrivateKey = bsv.HDPrivateKey.fromSeed(mnemonic.toSeed());
130
- const derived = hdPrivateKey.deriveChild("m/44'/236'/0'/0/0");
131
- const address = derived.privateKey.toAddress().toString();
132
- log(resultElementId, `✅ ${version} key derivation successful!`, 'success');
133
- log(resultElementId, `Address: ${address}`, 'info');
134
-
135
- updateSummary(version, 'SUCCESS');
136
- } else {
137
- log(resultElementId, `❌ ${version} mnemonic class not available`, 'error');
138
- updateSummary(version, 'NO_MNEMONIC_CLASS');
139
- }
140
-
141
- } catch (error) {
142
- log(resultElementId, `❌ ${version} error: ${error.message}`, 'error');
143
- if (error.message.includes('createHmac')) {
144
- log(resultElementId, '🔍 This is the createHmac error we are fixing!', 'error');
145
- updateSummary(version, 'CREATEHMAC_ERROR');
146
- } else {
147
- updateSummary(version, 'OTHER_ERROR');
148
- }
149
- }
150
- }
151
-
152
- let testResults = {};
153
-
154
- function updateSummary(version, result) {
155
- testResults[version] = result;
156
-
157
- let summary = '<h3>Test Results Summary:</h3>';
158
-
159
- if (testResults['CDN']) {
160
- const cdnStatus = testResults['CDN'] === 'SUCCESS' ? '✅ Working' :
161
- testResults['CDN'] === 'CREATEHMAC_ERROR' ? '❌ createHmac error' :
162
- '❌ Failed';
163
- summary += `<div><strong>CDN Version:</strong> ${cdnStatus}</div>`;
164
- }
165
-
166
- if (testResults['Local']) {
167
- const localStatus = testResults['Local'] === 'SUCCESS' ? '✅ Working' : '❌ Failed';
168
- summary += `<div><strong>Local Fixed Version:</strong> ${localStatus}</div>`;
169
- }
170
-
171
- if (testResults['CDN'] && testResults['Local']) {
172
- if (testResults['CDN'] === 'CREATEHMAC_ERROR' && testResults['Local'] === 'SUCCESS') {
173
- summary += '<div class="success"><strong>✅ Fix confirmed!</strong> The local version resolves the CDN createHmac issue.</div>';
174
- summary += '<div class="info"><strong>Solution:</strong> The CDN bundle needs browser-compatible PBKDF2 implementation that uses BSV crypto instead of Node.js crypto.</div>';
175
- } else if (testResults['CDN'] === 'SUCCESS' && testResults['Local'] === 'SUCCESS') {
176
- summary += '<div class="success"><strong>Both versions working!</strong></div>';
177
- } else {
178
- summary += '<div class="error"><strong>Unexpected results.</strong> Please check the implementation.</div>';
179
- }
180
- }
181
-
182
- document.getElementById('summary').innerHTML = summary;
183
- }
184
- </script>
185
- </body>
186
- </html>
@@ -1,51 +0,0 @@
1
- <!DOCTYPE html>
2
- <html>
3
- <head>
4
- <title>PBKDF2 Test</title>
5
- </head>
6
- <body>
7
- <h1>Testing PBKDF2 Browser Compatibility</h1>
8
- <div id="results"></div>
9
-
10
- <script src="../bsv.min.js"></script>
11
- <script src="../bsv-mnemonic.min.js"></script>
12
-
13
- <script>
14
- const results = document.getElementById('results');
15
-
16
- function log(message) {
17
- results.innerHTML += '<div>' + message + '</div>';
18
- console.log(message);
19
- }
20
-
21
- // Test mnemonic generation
22
- try {
23
- log('Testing mnemonic generation...');
24
-
25
- // Check if modules are available
26
- const MnemonicClass = window.bsvMnemonic || window.Mnemonic || (window.bsv && window.bsv.Mnemonic);
27
- log('Mnemonic class available: ' + !!MnemonicClass);
28
-
29
- if (MnemonicClass) {
30
- // Generate a mnemonic
31
- const mnemonic = MnemonicClass.fromRandom(256);
32
- log('✅ Mnemonic generated successfully: ' + mnemonic.phrase.split(' ').slice(0, 4).join(' ') + '...');
33
-
34
- // Test derivation
35
- const hdPrivateKey = bsv.HDPrivateKey.fromSeed(mnemonic.toSeed());
36
- const derived = hdPrivateKey.deriveChild("m/44'/236'/0'/0/0");
37
- log('✅ Key derivation successful');
38
- log('✅ Address: ' + derived.privateKey.toAddress().toString());
39
- } else {
40
- log('❌ Mnemonic class not available');
41
- }
42
-
43
- } catch (error) {
44
- log('❌ Error: ' + error.message);
45
- if (error.message.includes('createHmac')) {
46
- log('🔍 This is the createHmac error we are fixing!');
47
- }
48
- }
49
- </script>
50
- </body>
51
- </html>
@@ -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>