smartledger-bsv 3.2.1 → 3.2.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.
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "smartledger-bsv",
3
- "version": "3.2.1",
4
- "description": "Advanced Bitcoin SV library with JavaScript-to-Bitcoin Script framework - Complete BSV API + BIP143 preimage parsing + 121 opcode mapping + covenant builder + nChain PUSHTX techniques + custom script development + integrated debugging tools",
3
+ "version": "3.2.2",
4
+ "description": "🚀 Complete Bitcoin SV development framework with 9 flexible loading options: standalone modules (covenant, script-helper, security, debug tools), complete bundle, or modular approach. Includes SmartContract framework, covenant builder, script debugger, elliptic curve security fixes, and comprehensive Bitcoin SV API. Perfect for DeFi, smart contracts, custom scripts, and secure Bitcoin applications.",
5
5
  "author": "SmartLedger Technology <hello@smartledger.technology> (https://smartledger.technology)",
6
6
  "homepage": "https://github.com/codenlighten/smartledger-bsv#readme",
7
7
  "bugs": {
@@ -19,13 +19,20 @@
19
19
  "test:basic": "node examples/basic/transaction-creation.js",
20
20
  "test:all": "npm test && npm run test:covenants && npm run test:scripts",
21
21
  "coverage": "nyc --reporter=text npm run test",
22
- "build-bsv": "NODE_OPTIONS=\"--openssl-legacy-provider\" webpack index.js --config webpack.config.js",
23
- "build-ecies": "NODE_OPTIONS=\"--openssl-legacy-provider\" webpack ecies/index.js --config webpack.subproject.config.js --output-library bsvEcies -o bsv-ecies.min.js",
24
- "build-message": "NODE_OPTIONS=\"--openssl-legacy-provider\" webpack message/index.js --config webpack.subproject.config.js --output-library bsvMessage -o bsv-message.min.js",
25
- "build-mnemonic": "NODE_OPTIONS=\"--openssl-legacy-provider\" webpack mnemonic/index.js --config webpack.subproject.config.js --output-library bsvMnemonic -o bsv-mnemonic.min.js",
26
- "build-bundle": "NODE_OPTIONS=\"--openssl-legacy-provider\" webpack bundle-entry.js --config webpack.bundle.config.js",
27
- "build": "npm run build-bsv && npm run build-ecies && npm run build-message && npm run build-mnemonic",
28
- "build-all": "npm run build && npm run build-bundle",
22
+ "build-bsv": "NODE_OPTIONS=\"--openssl-legacy-provider\" webpack index.js --config build/webpack.config.js",
23
+ "build-ecies": "NODE_OPTIONS=\"--openssl-legacy-provider\" webpack ecies/index.js --config build/webpack.subproject.config.js --output-library bsvEcies -o bsv-ecies.min.js",
24
+ "build-message": "NODE_OPTIONS=\"--openssl-legacy-provider\" webpack message/index.js --config build/webpack.subproject.config.js --output-library bsvMessage -o bsv-message.min.js",
25
+ "build-mnemonic": "NODE_OPTIONS=\"--openssl-legacy-provider\" webpack mnemonic/index.js --config build/webpack.subproject.config.js --output-library bsvMnemonic -o bsv-mnemonic.min.js",
26
+ "build-smartcontract": "NODE_OPTIONS=\"--openssl-legacy-provider\" webpack smartcontract-entry.js --config build/webpack.smartcontract.config.js",
27
+ "build-covenant": "NODE_OPTIONS=\"--openssl-legacy-provider\" webpack covenant-entry.js --config build/webpack.covenant.config.js",
28
+ "build-script-helper": "NODE_OPTIONS=\"--openssl-legacy-provider\" webpack script-helper-entry.js --config build/webpack.script-helper.config.js",
29
+ "build-security": "NODE_OPTIONS=\"--openssl-legacy-provider\" webpack security-entry.js --config build/webpack.security.config.js",
30
+ "build-bundle": "NODE_OPTIONS=\"--openssl-legacy-provider\" webpack bundle-entry.js --config build/webpack.bundle.config.js",
31
+ "build": "npm run build-bsv && npm run build-ecies && npm run build-message && npm run build-mnemonic && npm run build-smartcontract",
32
+ "build-specialized": "npm run build-covenant && npm run build-script-helper && npm run build-security",
33
+ "build-all": "npm run build && npm run build-bundle && npm run build-specialized",
34
+ "test:browser": "echo 'Open tests/standalone-modules-test.html in browser for comprehensive testing'",
35
+ "test:bundle": "echo 'Open tests/bundle-completeness-test.html in browser to verify bundle completeness'",
29
36
  "demo": "npm run test:covenants",
30
37
  "demo:basic": "npm run test:basic",
31
38
  "demo:scripts": "npm run test:scripts",
@@ -43,11 +50,18 @@
43
50
  "ecies/",
44
51
  "message/",
45
52
  "mnemonic/",
53
+ "build/",
54
+ "tests/",
55
+ "*-entry.js",
46
56
  "bsv.min.js",
47
57
  "bsv.bundle.js",
48
58
  "bsv-ecies.min.js",
49
59
  "bsv-message.min.js",
50
60
  "bsv-mnemonic.min.js",
61
+ "bsv-smartcontract.min.js",
62
+ "bsv-covenant.min.js",
63
+ "bsv-script-helper.min.js",
64
+ "bsv-security.min.js",
51
65
  "bsv.d.ts",
52
66
  "validation_test.js",
53
67
  "docs/",
@@ -59,18 +73,30 @@
59
73
  ],
60
74
  "keywords": [
61
75
  "bitcoin",
62
- "bitcoin-sv",
76
+ "bitcoin-sv",
63
77
  "bsv",
64
- "transaction",
65
- "address",
66
78
  "cryptocurrency",
67
79
  "blockchain",
68
- "security",
69
- "hardened",
70
- "vulnerability-free",
71
- "drop-in-replacement",
80
+ "smart-contracts",
81
+ "defi",
72
82
  "covenant",
73
83
  "covenants",
84
+ "script-debugger",
85
+ "debug-tools",
86
+ "modular-loading",
87
+ "standalone-modules",
88
+ "security-hardened",
89
+ "elliptic-curve-fix",
90
+ "smartledger",
91
+ "transaction",
92
+ "address",
93
+ "signature",
94
+ "wallet",
95
+ "hd-wallet",
96
+ "mnemonic",
97
+ "ecies",
98
+ "encryption",
99
+ "message-signing",
74
100
  "pushtx",
75
101
  "pels",
76
102
  "bip143",
@@ -94,9 +120,14 @@
94
120
  "miner-simulator",
95
121
  "testing-tools",
96
122
  "development-framework",
97
- "ecies",
98
- "p2p",
99
- "payment",
123
+ "browser-compatible",
124
+ "nodejs-compatible",
125
+ "webpack-ready",
126
+ "cdn-ready",
127
+ "typescript-definitions",
128
+ "vulnerability-free",
129
+ "drop-in-replacement",
130
+ "performance-optimized",
100
131
  "bip21",
101
132
  "bip32",
102
133
  "bip37",
@@ -0,0 +1,49 @@
1
+ /**
2
+ * SmartLedger BSV Custom Script Helper - Standalone Module
3
+ *
4
+ * Simplified API for custom script development and signing
5
+ * Requires main BSV library to be loaded first.
6
+ *
7
+ * Usage:
8
+ * <script src="bsv.min.js"></script>
9
+ * <script src="bsv-script-helper.min.js"></script>
10
+ * <script>
11
+ * const sig = bsvScriptHelper.createSignature(tx, key, 0, script, sats);
12
+ * </script>
13
+ */
14
+
15
+ 'use strict'
16
+
17
+ // Verify BSV library is available
18
+ if (typeof bsv === 'undefined') {
19
+ throw new Error('CustomScriptHelper requires BSV library. Load bsv.min.js first.');
20
+ }
21
+
22
+ // Load CustomScriptHelper
23
+ const CustomScriptHelper = require('./lib/custom-script-helper.js');
24
+
25
+ // Browser compatibility
26
+ if (typeof window !== 'undefined') {
27
+ window.bsvScriptHelper = {
28
+ CustomScriptHelper: CustomScriptHelper,
29
+ createSignature: CustomScriptHelper.createSignature,
30
+ verifySignature: CustomScriptHelper.verifySignature,
31
+ createMultisigSignature: CustomScriptHelper.createMultisigSignature,
32
+ version: bsv.version || 'unknown'
33
+ };
34
+
35
+ // Also attach to main bsv object if available
36
+ if (typeof bsv !== 'undefined') {
37
+ bsv.CustomScriptHelper = CustomScriptHelper;
38
+ }
39
+
40
+ console.log('CustomScriptHelper standalone module loaded');
41
+ }
42
+
43
+ module.exports = {
44
+ CustomScriptHelper: CustomScriptHelper,
45
+ createSignature: CustomScriptHelper.createSignature,
46
+ verifySignature: CustomScriptHelper.verifySignature,
47
+ createMultisigSignature: CustomScriptHelper.createMultisigSignature,
48
+ version: bsv.version || 'unknown'
49
+ };
@@ -0,0 +1,70 @@
1
+ /**
2
+ * SmartLedger BSV Security Module - Standalone Module
3
+ *
4
+ * SmartLedger security enhancements and elliptic curve fixes
5
+ * Can be used standalone or with main BSV library.
6
+ *
7
+ * Usage:
8
+ * <script src="bsv-security.min.js"></script>
9
+ * <script>
10
+ * const verified = bsvSecurity.SmartVerify.verify(sig, hash, pubkey);
11
+ * </script>
12
+ */
13
+
14
+ 'use strict'
15
+
16
+ // Load security modules
17
+ const SmartVerify = require('./lib/crypto/smartledger_verify');
18
+ const EllipticFixed = require('./lib/crypto/elliptic-fixed');
19
+
20
+ // Browser compatibility
21
+ if (typeof window !== 'undefined') {
22
+ window.bsvSecurity = {
23
+ SmartVerify: SmartVerify,
24
+ EllipticFixed: EllipticFixed,
25
+ SmartLedger: {
26
+ version: 'v3.2.1',
27
+ hardenedBy: 'SmartLedger',
28
+ baseVersion: 'v1.5.6',
29
+ securityFeatures: [
30
+ 'canonical-signatures',
31
+ 'malleability-protection',
32
+ 'enhanced-validation',
33
+ 'elliptic-patches'
34
+ ],
35
+ SmartVerify: SmartVerify,
36
+ EllipticFixed: EllipticFixed
37
+ },
38
+ version: 'v3.2.1'
39
+ };
40
+
41
+ // Also attach to main bsv object if available
42
+ if (typeof bsv !== 'undefined') {
43
+ bsv.SmartVerify = SmartVerify;
44
+ bsv.EllipticFixed = EllipticFixed;
45
+ if (!bsv.SmartLedger) {
46
+ bsv.SmartLedger = window.bsvSecurity.SmartLedger;
47
+ }
48
+ }
49
+
50
+ console.log('SmartLedger Security standalone module loaded');
51
+ }
52
+
53
+ module.exports = {
54
+ SmartVerify: SmartVerify,
55
+ EllipticFixed: EllipticFixed,
56
+ SmartLedger: {
57
+ version: 'v3.2.1',
58
+ hardenedBy: 'SmartLedger',
59
+ baseVersion: 'v1.5.6',
60
+ securityFeatures: [
61
+ 'canonical-signatures',
62
+ 'malleability-protection',
63
+ 'enhanced-validation',
64
+ 'elliptic-patches'
65
+ ],
66
+ SmartVerify: SmartVerify,
67
+ EllipticFixed: EllipticFixed
68
+ },
69
+ version: 'v3.2.1'
70
+ };
@@ -0,0 +1,133 @@
1
+ /**
2
+ * SmartLedger BSV - SmartContract Interface
3
+ *
4
+ * Standalone SmartContract interface with debug tools for browser use.
5
+ * This module provides the complete SmartContract development framework
6
+ * including covenant builders, script debuggers, and testing tools.
7
+ *
8
+ * Usage:
9
+ * <script src="bsv.min.js"></script>
10
+ * <script src="bsv-smartcontract.min.js"></script>
11
+ * <script>
12
+ * // SmartContract interface available under bsv.SmartContract
13
+ * const script = bsv.Script.fromASM('OP_1 OP_2 OP_ADD');
14
+ * const result = bsv.SmartContract.examineStack(script);
15
+ * const metrics = bsv.SmartContract.getScriptMetrics(script);
16
+ * </script>
17
+ */
18
+
19
+ 'use strict'
20
+
21
+ // Check if BSV library is available
22
+ if (typeof window !== 'undefined' && typeof window.bsv === 'undefined') {
23
+ throw new Error('SmartContract interface requires BSV library. Load bsv.min.js first.')
24
+ }
25
+
26
+ // Get BSV reference (works in both Node.js and browser)
27
+ var bsv = (typeof window !== 'undefined') ? window.bsv : require('./index.js')
28
+
29
+ if (!bsv) {
30
+ throw new Error('BSV library not found. Ensure bsv.min.js is loaded before bsv-smartcontract.min.js')
31
+ }
32
+
33
+ // Load SmartContract interface
34
+ var SmartContract
35
+ try {
36
+ SmartContract = require('./lib/smart_contract')
37
+ } catch (e) {
38
+ throw new Error('SmartContract module not found: ' + e.message)
39
+ }
40
+
41
+ // Attach to BSV library
42
+ bsv.SmartContract = SmartContract
43
+
44
+ // Make available globally for browser usage
45
+ if (typeof window !== 'undefined') {
46
+ window.bsvSmartContract = SmartContract
47
+
48
+ // Also ensure it's on the global bsv object
49
+ if (window.bsv) {
50
+ window.bsv.SmartContract = SmartContract
51
+ }
52
+ }
53
+
54
+ // Add debug tools information
55
+ if (SmartContract) {
56
+ SmartContract.version = bsv.version || '3.2.1'
57
+ SmartContract.standalone = true
58
+ SmartContract.debugToolsAvailable = {
59
+ examineStack: !!SmartContract.examineStack,
60
+ interpretScript: !!SmartContract.interpretScript,
61
+ getScriptMetrics: !!SmartContract.getScriptMetrics,
62
+ optimizeScript: !!SmartContract.optimizeScript
63
+ }
64
+
65
+ // Convenience method to check if debug tools are working
66
+ SmartContract.testDebugTools = function() {
67
+ try {
68
+ if (!bsv.Script) {
69
+ return { success: false, error: 'BSV Script class not available' }
70
+ }
71
+
72
+ const testScript = bsv.Script.fromASM('OP_1 OP_2 OP_ADD')
73
+ const results = {}
74
+
75
+ if (SmartContract.examineStack) {
76
+ try {
77
+ results.examineStack = SmartContract.examineStack(testScript)
78
+ results.examineStackWorking = true
79
+ } catch (e) {
80
+ results.examineStackWorking = false
81
+ results.examineStackError = e.message
82
+ }
83
+ }
84
+
85
+ if (SmartContract.interpretScript) {
86
+ try {
87
+ results.interpretScript = SmartContract.interpretScript(testScript)
88
+ results.interpretScriptWorking = true
89
+ } catch (e) {
90
+ results.interpretScriptWorking = false
91
+ results.interpretScriptError = e.message
92
+ }
93
+ }
94
+
95
+ if (SmartContract.getScriptMetrics) {
96
+ try {
97
+ results.scriptMetrics = SmartContract.getScriptMetrics(testScript)
98
+ results.scriptMetricsWorking = true
99
+ } catch (e) {
100
+ results.scriptMetricsWorking = false
101
+ results.scriptMetricsError = e.message
102
+ }
103
+ }
104
+
105
+ if (SmartContract.optimizeScript) {
106
+ try {
107
+ results.optimizeScript = SmartContract.optimizeScript(testScript)
108
+ results.optimizeScriptWorking = true
109
+ } catch (e) {
110
+ results.optimizeScriptWorking = false
111
+ results.optimizeScriptError = e.message
112
+ }
113
+ }
114
+
115
+ return {
116
+ success: true,
117
+ testScript: 'OP_1 OP_2 OP_ADD',
118
+ results: results,
119
+ methodCount: Object.keys(SmartContract).length
120
+ }
121
+ } catch (e) {
122
+ return { success: false, error: e.message }
123
+ }
124
+ }
125
+ }
126
+
127
+ console.log('SmartContract interface loaded:', !!SmartContract)
128
+ if (SmartContract) {
129
+ console.log('SmartContract methods available:', Object.keys(SmartContract).length)
130
+ console.log('Debug tools available:', SmartContract.debugToolsAvailable)
131
+ }
132
+
133
+ module.exports = SmartContract
@@ -0,0 +1,131 @@
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>