smartledger-bsv 3.3.2 → 3.3.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.
- package/CHANGELOG.md +220 -79
- package/README.md +283 -71
- package/bsv-covenant.min.js +26 -3
- package/bsv-gdaf.min.js +11 -9
- package/bsv-ltp.min.js +10 -8
- package/bsv-mnemonic.min.js +4 -4
- package/bsv-script-helper.min.js +2 -2
- package/bsv-security.min.js +3 -24
- package/bsv-shamir.min.js +2 -2
- package/bsv-smartcontract.min.js +10 -8
- package/bsv.bundle.js +9 -9
- package/bsv.min.js +10 -8
- package/build/webpack.bundle.config.js +2 -2
- package/build/webpack.config.js +2 -2
- package/build/webpack.covenant.config.js +2 -2
- package/build/webpack.gdaf.config.js +6 -43
- package/build/webpack.script-helper.config.js +2 -2
- package/build/webpack.security.config.js +2 -2
- package/build/webpack.smartcontract.config.js +2 -2
- package/bundle-entry.js +1 -341
- package/covenant-entry.js +1 -44
- package/demos/README.md +188 -0
- package/{architecture_demo.js → demos/architecture_demo.js} +2 -2
- package/demos/bsv_wallet_demo.js +242 -0
- package/{complete_ltp_demo.js → demos/complete_ltp_demo.js} +1 -1
- package/demos/debug_tools_demo.js +87 -0
- package/demos/demo_features.js +123 -0
- package/demos/easy_interface_demo.js +109 -0
- package/demos/ecies_demo.js +182 -0
- package/demos/gdaf_core_test.js +131 -0
- package/demos/gdaf_demo.js +237 -0
- package/demos/ltp_demo.js +361 -0
- package/demos/ltp_primitives_demo.js +403 -0
- package/demos/message_demo.js +209 -0
- package/demos/preimage_separation_demo.js +383 -0
- package/demos/script_helper_demo.js +289 -0
- package/demos/security_demo.js +287 -0
- package/{shamir_demo.js → demos/shamir_demo.js} +1 -1
- package/{simple_demo.js → demos/simple_demo.js} +1 -1
- package/demos/simple_p2pkh_demo.js +169 -0
- package/demos/simple_utxo_preimage_demo.js +196 -0
- package/demos/smart_contract_demo.html +1347 -0
- package/demos/smart_contract_demo.js +910 -0
- package/demos/utxo_generator_demo.js +244 -0
- package/demos/validation_pipeline_demo.js +155 -0
- package/demos/web3keys.html +740 -0
- package/docs/BUNDLE_UPDATE_SUMMARY.md +40 -0
- package/docs/DOCUMENTATION_REVIEW_REPORT.md +295 -0
- package/docs/FIX_CREATEHMAC_ISSUE.md +91 -0
- package/docs/MODULE_REFERENCE_COMPLETE.md +330 -0
- package/docs/README.md +107 -79
- package/docs/SMARTLEDGER_BSV_USAGE_ANSWERS.md +477 -0
- package/docs/SMARTLEDGER_BSV_USAGE_EXAMPLES.js +372 -0
- package/docs/SMARTLEDGER_BSV_USAGE_GUIDE.md +555 -0
- package/docs/SMART_CONTRACT_DEVELOPMENT_GUIDE.md +1459 -0
- package/docs/advanced/LEGAL_TOKEN_PROTOCOL.md +411 -0
- package/docs/advanced/SMART_CONTRACT_GUIDE.md +1255 -0
- package/docs/advanced/UTXO_MANAGER_GUIDE.md +851 -0
- package/docs/api/LTP.md +334 -0
- package/docs/getting-started/INSTALLATION.md +410 -0
- package/docs/getting-started/QUICK_START.md +180 -0
- package/docs/migration/FROM_BSV_1_5_6.md +260 -0
- package/docs/technical/GDAF_DEVELOPER_INTERFACE.md +187 -0
- package/docs/technical/GDAF_IMPLEMENTATION_COMPLETE.md +190 -0
- package/docs/technical/SHAMIR_INTEGRATION_SUMMARY.md +165 -0
- package/docs/technical/roadmap.md +1250 -0
- package/docs/technical/trust_law.md +142 -0
- package/examples/complete_workflow_demo.js +783 -0
- package/examples/definitive_working_demo.js +261 -0
- package/examples/final_working_contracts.js +338 -0
- package/examples/smart_contract_templates.js +718 -0
- package/examples/working_smart_contracts.js +348 -0
- package/gdaf-entry.js +2 -54
- package/index.js +32 -0
- package/lib/mnemonic/pbkdf2.browser.js +69 -0
- package/lib/mnemonic/pbkdf2.js +2 -68
- package/lib/mnemonic/pbkdf2.node.js +68 -0
- package/ltp-entry.js +2 -92
- package/package.json +21 -8
- package/script-helper-entry.js +1 -49
- package/security-entry.js +1 -70
- package/shamir-entry.js +1 -173
- package/smartcontract-entry.js +1 -133
- package/tests/browser-compatibility/README.md +35 -0
- package/tests/browser-compatibility/test-cdn-vs-local.html +186 -0
- package/tests/browser-compatibility/test-pbkdf2.html +51 -0
- package/tests/test_builtin_verify.js +117 -0
- package/tests/test_debug_integration.js +71 -0
- package/tests/test_ecdsa_little.js +70 -0
- package/tests/test_smartverify_der.js +110 -0
- package/utilities/blockchain-state.js +155 -155
- package/utilities/blockchain-state.json +103293 -5244
- package/utilities/miner-simulator.js +354 -358
- package/utilities/mock-utxo-generator.js +54 -54
- package/utilities/raw-tx-examples.js +120 -122
- package/utilities/success-demo.js +104 -105
- package/utilities/transaction-examples.js +188 -188
- package/utilities/utxo-manager.js +91 -91
- package/utilities/wallet-setup.js +79 -80
- package/utilities/working-signature-demo.js +108 -110
- package/SECURITY.md +0 -75
- package/build/bsv-covenant.min.js +0 -10
- package/build/bsv-script-helper.min.js +0 -10
- package/build/bsv-security.min.js +0 -31
- package/build/bsv-smartcontract.min.js +0 -39
- package/build/bsv.bundle.js +0 -39
- package/build/bsv.min.js +0 -39
- package/validation_test.js +0 -97
- /package/docs/{ADVANCED_COVENANT_DEVELOPMENT.md → advanced/ADVANCED_COVENANT_DEVELOPMENT.md} +0 -0
- /package/docs/{CUSTOM_SCRIPT_DEVELOPMENT.md → advanced/CUSTOM_SCRIPT_DEVELOPMENT.md} +0 -0
- /package/docs/{block.md → api/BLOCKS.md} +0 -0
- /package/docs/{ecies.md → api/ECIES.md} +0 -0
- /package/docs/{networks.md → api/NETWORKS.md} +0 -0
- /package/docs/{script.md → api/SCRIPTS.md} +0 -0
- /package/docs/{transaction.md → api/TRANSACTIONS.md} +0 -0
- /package/docs/{unspentoutput.md → api/UTXO.md} +0 -0
- /package/{test_shamir.js → tests/test_shamir.js} +0 -0
- /package/{test_standalone_shamir.html → tests/test_standalone_shamir.html} +0 -0
|
@@ -0,0 +1,186 @@
|
|
|
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.3/bsv.min.js';
|
|
62
|
+
bsvScript.onload = () => {
|
|
63
|
+
const mnemonicScript = document.createElement('script');
|
|
64
|
+
mnemonicScript.src = 'https://cdn.jsdelivr.net/npm/smartledger-bsv@3.3.3/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>
|
|
@@ -0,0 +1,51 @@
|
|
|
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>
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Test Transaction VerifySignature Method
|
|
5
|
+
*
|
|
6
|
+
* Tests the transaction's built-in verifySignature method
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
const bsv = require('./index.js');
|
|
10
|
+
|
|
11
|
+
console.log('🔍 Test Transaction VerifySignature Method');
|
|
12
|
+
console.log('==========================================\n');
|
|
13
|
+
|
|
14
|
+
const privateKey = new bsv.PrivateKey('L1aW4aubDFB7yfras2S1mN3bqg9nwySY8nkoLmJebSLD5BWv3ENZ');
|
|
15
|
+
const address = privateKey.toAddress().toString();
|
|
16
|
+
|
|
17
|
+
// Create and sign transaction
|
|
18
|
+
const mockUTXO = {
|
|
19
|
+
txid: '1234567890abcdef1234567890abcdef1234567890abcdef1234567890abcdef',
|
|
20
|
+
vout: 0,
|
|
21
|
+
address: address,
|
|
22
|
+
satoshis: 50000,
|
|
23
|
+
script: bsv.Script.buildPublicKeyHashOut(address).toHex()
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
const transaction = new bsv.Transaction()
|
|
27
|
+
.from(mockUTXO)
|
|
28
|
+
.to(address, 100)
|
|
29
|
+
.change(address)
|
|
30
|
+
.feePerKb(10)
|
|
31
|
+
.sign(privateKey);
|
|
32
|
+
|
|
33
|
+
console.log('✅ Transaction created and signed');
|
|
34
|
+
console.log(`Transaction ID: ${transaction.id}`);
|
|
35
|
+
console.log(`Basic verify(): ${transaction.verify()}`);
|
|
36
|
+
|
|
37
|
+
// Extract signature details
|
|
38
|
+
const input = transaction.inputs[0];
|
|
39
|
+
const signature = input.script.chunks[0]?.buf;
|
|
40
|
+
const publicKey = input.script.chunks[1]?.buf;
|
|
41
|
+
|
|
42
|
+
if (signature && publicKey) {
|
|
43
|
+
console.log('\n🧪 Transaction VerifySignature Method Test:');
|
|
44
|
+
console.log('==========================================');
|
|
45
|
+
|
|
46
|
+
const sigWithoutHashtype = signature.slice(0, -1);
|
|
47
|
+
const pubkeyObj = new bsv.PublicKey(publicKey);
|
|
48
|
+
const subscript = input.output.script;
|
|
49
|
+
const satoshisBN = new bsv.crypto.BN(input.output.satoshis);
|
|
50
|
+
|
|
51
|
+
try {
|
|
52
|
+
// Parse the signature first
|
|
53
|
+
const parsedSig = bsv.crypto.Signature.fromDER(sigWithoutHashtype);
|
|
54
|
+
parsedSig.nhashtype = signature[signature.length - 1]; // Set the hashtype
|
|
55
|
+
|
|
56
|
+
console.log(`Parsed signature r: ${parsedSig.r.toString('hex')}`);
|
|
57
|
+
console.log(`Parsed signature s: ${parsedSig.s.toString('hex')}`);
|
|
58
|
+
console.log(`Signature hashtype: 0x${parsedSig.nhashtype.toString(16)}`);
|
|
59
|
+
|
|
60
|
+
// Test transaction's built-in verifySignature method
|
|
61
|
+
const builtinVerify = transaction.verifySignature(parsedSig, pubkeyObj, 0, subscript, satoshisBN);
|
|
62
|
+
console.log(`transaction.verifySignature(): ${builtinVerify ? '✅ VALID' : '❌ INVALID'}`);
|
|
63
|
+
|
|
64
|
+
// Test with default flags
|
|
65
|
+
const builtinVerifyWithFlags = transaction.verifySignature(parsedSig, pubkeyObj, 0, subscript, satoshisBN,
|
|
66
|
+
bsv.Script.Interpreter.SCRIPT_ENABLE_SIGHASH_FORKID);
|
|
67
|
+
console.log(`transaction.verifySignature() with flags: ${builtinVerifyWithFlags ? '✅ VALID' : '❌ INVALID'}`);
|
|
68
|
+
|
|
69
|
+
console.log('\n🔍 Manual Sighash.verify Test:');
|
|
70
|
+
console.log('==============================');
|
|
71
|
+
|
|
72
|
+
// Test the Sighash.verify method directly
|
|
73
|
+
const sighashVerify = bsv.Transaction.Sighash.verify(transaction, parsedSig, pubkeyObj, 0, subscript, satoshisBN);
|
|
74
|
+
console.log(`Sighash.verify(): ${sighashVerify ? '✅ VALID' : '❌ INVALID'}`);
|
|
75
|
+
|
|
76
|
+
const sighashVerifyWithFlags = bsv.Transaction.Sighash.verify(transaction, parsedSig, pubkeyObj, 0, subscript, satoshisBN,
|
|
77
|
+
bsv.Script.Interpreter.SCRIPT_ENABLE_SIGHASH_FORKID);
|
|
78
|
+
console.log(`Sighash.verify() with flags: ${sighashVerifyWithFlags ? '✅ VALID' : '❌ INVALID'}`);
|
|
79
|
+
|
|
80
|
+
console.log('\n🔧 Compare Sighash Calculation:');
|
|
81
|
+
console.log('===============================');
|
|
82
|
+
|
|
83
|
+
// Get the sighash that Sighash.verify would calculate
|
|
84
|
+
const officialSighash = bsv.Transaction.Sighash.sighash(
|
|
85
|
+
transaction,
|
|
86
|
+
parsedSig.nhashtype,
|
|
87
|
+
0,
|
|
88
|
+
subscript,
|
|
89
|
+
satoshisBN,
|
|
90
|
+
bsv.Script.Interpreter.SCRIPT_ENABLE_SIGHASH_FORKID
|
|
91
|
+
);
|
|
92
|
+
|
|
93
|
+
console.log(`Official Sighash.sighash(): ${officialSighash.toString('hex')}`);
|
|
94
|
+
|
|
95
|
+
// Compare with our transaction.sighash method
|
|
96
|
+
const ourSighash = transaction.sighash(0, parsedSig.nhashtype, subscript, satoshisBN);
|
|
97
|
+
console.log(`Our transaction.sighash(): ${ourSighash.toString('hex')}`);
|
|
98
|
+
console.log(`Sighashes match: ${officialSighash.equals(ourSighash) ? '✅ YES' : '❌ NO'}`);
|
|
99
|
+
|
|
100
|
+
// Test verification with the official sighash
|
|
101
|
+
console.log('\n🎯 Verification with Official Sighash:');
|
|
102
|
+
console.log('=====================================');
|
|
103
|
+
|
|
104
|
+
const ecdsaWithOfficial = bsv.crypto.ECDSA.verify(officialSighash, parsedSig, pubkeyObj);
|
|
105
|
+
console.log(`ECDSA.verify(officialSighash): ${ecdsaWithOfficial ? '✅ VALID' : '❌ INVALID'}`);
|
|
106
|
+
|
|
107
|
+
const smartVerifyWithOfficial = bsv.SmartVerify.smartVerify(officialSighash, parsedSig, pubkeyObj);
|
|
108
|
+
console.log(`SmartVerify(officialSighash): ${smartVerifyWithOfficial ? '✅ VALID' : '❌ INVALID'}`);
|
|
109
|
+
|
|
110
|
+
} catch (error) {
|
|
111
|
+
console.log('❌ Test failed:', error.message);
|
|
112
|
+
console.log('Stack:', error.stack);
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
} else {
|
|
116
|
+
console.log('❌ Could not extract signature or public key');
|
|
117
|
+
}
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
/**
|
|
3
|
+
* Test Script for Debug Tools Integration
|
|
4
|
+
* =======================================
|
|
5
|
+
* Tests the newly integrated StackExaminer and ScriptInterpreter tools
|
|
6
|
+
* in the SmartContract interface
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
const SmartContract = require('./lib/smart_contract/index.js');
|
|
10
|
+
|
|
11
|
+
console.log("🧪 Testing SmartContract Debug Tools Integration");
|
|
12
|
+
console.log("=================================================\n");
|
|
13
|
+
|
|
14
|
+
// Test 1: Check if modules are loaded
|
|
15
|
+
console.log("1. Module Loading Test:");
|
|
16
|
+
console.log(" StackExaminer loaded:", !!SmartContract.StackExaminer);
|
|
17
|
+
console.log(" ScriptInterpreter loaded:", !!SmartContract.ScriptInterpreter);
|
|
18
|
+
console.log(" examineStack method:", typeof SmartContract.examineStack);
|
|
19
|
+
console.log(" debugScriptExecution method:", typeof SmartContract.debugScriptExecution);
|
|
20
|
+
console.log(" parseScript method:", typeof SmartContract.parseScript);
|
|
21
|
+
|
|
22
|
+
// Test 2: Feature flags
|
|
23
|
+
console.log("\n2. Feature Flags Test:");
|
|
24
|
+
console.log(" STACK_EXAMINATION:", SmartContract.features.STACK_EXAMINATION);
|
|
25
|
+
console.log(" SCRIPT_DEBUGGING:", SmartContract.features.SCRIPT_DEBUGGING);
|
|
26
|
+
console.log(" STEP_BY_STEP_EXECUTION:", SmartContract.features.STEP_BY_STEP_EXECUTION);
|
|
27
|
+
console.log(" INTERACTIVE_DEBUGGING:", SmartContract.features.INTERACTIVE_DEBUGGING);
|
|
28
|
+
|
|
29
|
+
// Test 3: Simple script parsing
|
|
30
|
+
console.log("\n3. Script Parsing Test:");
|
|
31
|
+
try {
|
|
32
|
+
const parsedASM = SmartContract.parseScript("OP_DUP OP_HASH160");
|
|
33
|
+
console.log(" ✅ ASM parsing successful");
|
|
34
|
+
console.log(" Script length:", parsedASM.chunks.length);
|
|
35
|
+
} catch (err) {
|
|
36
|
+
console.log(" ❌ ASM parsing failed:", err.message);
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
try {
|
|
40
|
+
const parsedHex = SmartContract.parseScript("76a914");
|
|
41
|
+
console.log(" ✅ HEX parsing successful");
|
|
42
|
+
console.log(" Script length:", parsedHex.chunks.length);
|
|
43
|
+
} catch (err) {
|
|
44
|
+
console.log(" ❌ HEX parsing failed:", err.message);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
// Test 4: Stack examination (non-interactive)
|
|
48
|
+
console.log("\n4. Stack Examination Test:");
|
|
49
|
+
try {
|
|
50
|
+
// Use simple valid scripts for testing
|
|
51
|
+
const result = SmartContract.examineStack("51", "51"); // OP_1, OP_1
|
|
52
|
+
console.log(" ✅ Stack examination completed, result:", result);
|
|
53
|
+
} catch (err) {
|
|
54
|
+
console.log(" ⚠️ Stack examination had issues:", err.message);
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
console.log("\n=================================================");
|
|
58
|
+
console.log("🎉 Debug Tools Integration Test Complete!");
|
|
59
|
+
console.log("=================================================");
|
|
60
|
+
|
|
61
|
+
// Count total methods in SmartContract
|
|
62
|
+
const methodCount = Object.keys(SmartContract).filter(key =>
|
|
63
|
+
typeof SmartContract[key] === 'function'
|
|
64
|
+
).length;
|
|
65
|
+
|
|
66
|
+
console.log(`\n📊 SmartContract Interface Summary:`);
|
|
67
|
+
console.log(` Total Methods: ${methodCount}`);
|
|
68
|
+
console.log(` Total Modules: ${Object.keys(SmartContract).filter(key =>
|
|
69
|
+
typeof SmartContract[key] === 'object' && SmartContract[key].constructor.name !== 'Object'
|
|
70
|
+
).length}`);
|
|
71
|
+
console.log(` Feature Flags: ${Object.keys(SmartContract.features).length}`);
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Test ECDSA.verify with 'little' endianness
|
|
5
|
+
*
|
|
6
|
+
* Tests if adding 'little' parameter fixes ECDSA.verify too
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
const bsv = require('./index.js');
|
|
10
|
+
|
|
11
|
+
console.log('🔍 Test ECDSA.verify with little endianness');
|
|
12
|
+
console.log('============================================\n');
|
|
13
|
+
|
|
14
|
+
// Simple signature test
|
|
15
|
+
const privateKey = new bsv.PrivateKey('L1aW4aubDFB7yfras2S1mN3bqg9nwySY8nkoLmJebSLD5BWv3ENZ');
|
|
16
|
+
const publicKey = privateKey.publicKey;
|
|
17
|
+
const message = Buffer.from('hello world', 'utf8');
|
|
18
|
+
const hash = bsv.crypto.Hash.sha256(message);
|
|
19
|
+
|
|
20
|
+
console.log('Creating signature...');
|
|
21
|
+
const signature = bsv.crypto.ECDSA.sign(hash, privateKey);
|
|
22
|
+
const derSig = signature.toDER();
|
|
23
|
+
|
|
24
|
+
console.log('\n🧪 ECDSA.verify Test Matrix:');
|
|
25
|
+
console.log('============================');
|
|
26
|
+
|
|
27
|
+
// Test without 'little'
|
|
28
|
+
const ecdsaWithoutLittle = bsv.crypto.ECDSA.verify(hash, signature, publicKey);
|
|
29
|
+
console.log(`ECDSA.verify(hash, sig, pubkey): ${ecdsaWithoutLittle ? '✅ VALID' : '❌ INVALID'}`);
|
|
30
|
+
|
|
31
|
+
// Test with 'little'
|
|
32
|
+
const ecdsaWithLittle = bsv.crypto.ECDSA.verify(hash, signature, publicKey, 'little');
|
|
33
|
+
console.log(`ECDSA.verify(hash, sig, pubkey, 'little'): ${ecdsaWithLittle ? '✅ VALID' : '❌ INVALID'}`);
|
|
34
|
+
|
|
35
|
+
// Test with DER buffer without 'little'
|
|
36
|
+
const ecdsaDerWithoutLittle = bsv.crypto.ECDSA.verify(hash, derSig, publicKey);
|
|
37
|
+
console.log(`ECDSA.verify(hash, derSig, pubkey): ${ecdsaDerWithoutLittle ? '✅ VALID' : '❌ INVALID'}`);
|
|
38
|
+
|
|
39
|
+
// Test with DER buffer with 'little'
|
|
40
|
+
const ecdsaDerWithLittle = bsv.crypto.ECDSA.verify(hash, derSig, publicKey, 'little');
|
|
41
|
+
console.log(`ECDSA.verify(hash, derSig, pubkey, 'little'): ${ecdsaDerWithLittle ? '✅ VALID' : '❌ INVALID'}`);
|
|
42
|
+
|
|
43
|
+
console.log('\n🔍 Compare with SmartVerify:');
|
|
44
|
+
console.log('============================');
|
|
45
|
+
|
|
46
|
+
// Test SmartVerify
|
|
47
|
+
const smartVerifyObj = bsv.SmartVerify.smartVerify(hash, signature, publicKey);
|
|
48
|
+
console.log(`SmartVerify(hash, sig, pubkey): ${smartVerifyObj ? '✅ VALID' : '❌ INVALID'}`);
|
|
49
|
+
|
|
50
|
+
const smartVerifyDer = bsv.SmartVerify.smartVerify(hash, derSig, publicKey);
|
|
51
|
+
console.log(`SmartVerify(hash, derSig, pubkey): ${smartVerifyDer ? '✅ VALID' : '❌ INVALID'}`);
|
|
52
|
+
|
|
53
|
+
console.log('\n🔧 Signature Details:');
|
|
54
|
+
console.log('=====================');
|
|
55
|
+
console.log(`Signature r: ${signature.r.toString('hex')}`);
|
|
56
|
+
console.log(`Signature s: ${signature.s.toString('hex')}`);
|
|
57
|
+
console.log(`Is canonical: ${signature.isCanonical()}`);
|
|
58
|
+
|
|
59
|
+
// Check if this is a canonicalization issue
|
|
60
|
+
const canonicalSig = signature.toCanonical();
|
|
61
|
+
console.log(`Canonical r: ${canonicalSig.r.toString('hex')}`);
|
|
62
|
+
console.log(`Canonical s: ${canonicalSig.s.toString('hex')}`);
|
|
63
|
+
console.log(`Same as original: ${signature.r.eq(canonicalSig.r) && signature.s.eq(canonicalSig.s)}`);
|
|
64
|
+
|
|
65
|
+
// Test with canonical signature
|
|
66
|
+
const ecdsaCanonical = bsv.crypto.ECDSA.verify(hash, canonicalSig, publicKey, 'little');
|
|
67
|
+
console.log(`ECDSA.verify(hash, canonicalSig, pubkey, 'little'): ${ecdsaCanonical ? '✅ VALID' : '❌ INVALID'}`);
|
|
68
|
+
|
|
69
|
+
const smartVerifyCanonical = bsv.SmartVerify.smartVerify(hash, canonicalSig, publicKey);
|
|
70
|
+
console.log(`SmartVerify(hash, canonicalSig, pubkey): ${smartVerifyCanonical ? '✅ VALID' : '❌ INVALID'}`);
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Test SmartVerify DER Buffer Handling
|
|
5
|
+
*
|
|
6
|
+
* Tests SmartVerify with different input types to isolate the DER parsing issue
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
const bsv = require('./index.js');
|
|
10
|
+
|
|
11
|
+
console.log('🔍 Test SmartVerify DER Buffer Handling');
|
|
12
|
+
console.log('=======================================\n');
|
|
13
|
+
|
|
14
|
+
// Simple signature test like minimal reproduction
|
|
15
|
+
const privateKey = new bsv.PrivateKey('L1aW4aubDFB7yfras2S1mN3bqg9nwySY8nkoLmJebSLD5BWv3ENZ');
|
|
16
|
+
const publicKey = privateKey.publicKey;
|
|
17
|
+
const message = Buffer.from('hello world', 'utf8');
|
|
18
|
+
const hash = bsv.crypto.Hash.sha256(message);
|
|
19
|
+
|
|
20
|
+
console.log('Creating signature...');
|
|
21
|
+
const signature = bsv.crypto.ECDSA.sign(hash, privateKey);
|
|
22
|
+
const derSig = signature.toDER();
|
|
23
|
+
|
|
24
|
+
console.log(`Original signature r: ${signature.r.toString('hex')}`);
|
|
25
|
+
console.log(`Original signature s: ${signature.s.toString('hex')}`);
|
|
26
|
+
console.log(`DER buffer: ${derSig.toString('hex')}`);
|
|
27
|
+
console.log(`DER length: ${derSig.length}`);
|
|
28
|
+
|
|
29
|
+
console.log('\n🧪 SmartVerify Test Matrix:');
|
|
30
|
+
console.log('===========================');
|
|
31
|
+
|
|
32
|
+
// Test 1: Signature object
|
|
33
|
+
const smartVerifyObj = bsv.SmartVerify.smartVerify(hash, signature, publicKey);
|
|
34
|
+
console.log(`SmartVerify(hash, sigObject, pubkey): ${smartVerifyObj ? '✅ VALID' : '❌ INVALID'}`);
|
|
35
|
+
|
|
36
|
+
// Test 2: DER buffer
|
|
37
|
+
const smartVerifyBuffer = bsv.SmartVerify.smartVerify(hash, derSig, publicKey);
|
|
38
|
+
console.log(`SmartVerify(hash, derBuffer, pubkey): ${smartVerifyBuffer ? '✅ VALID' : '❌ INVALID'}`);
|
|
39
|
+
|
|
40
|
+
// Test 3: Manually parsed DER
|
|
41
|
+
try {
|
|
42
|
+
const parsedFromDER = bsv.crypto.Signature.fromDER(derSig);
|
|
43
|
+
console.log(`Parsed from DER r: ${parsedFromDER.r.toString('hex')}`);
|
|
44
|
+
console.log(`Parsed from DER s: ${parsedFromDER.s.toString('hex')}`);
|
|
45
|
+
|
|
46
|
+
const smartVerifyParsed = bsv.SmartVerify.smartVerify(hash, parsedFromDER, publicKey);
|
|
47
|
+
console.log(`SmartVerify(hash, parsedSig, pubkey): ${smartVerifyParsed ? '✅ VALID' : '❌ INVALID'}`);
|
|
48
|
+
|
|
49
|
+
console.log('\n🔍 Compare r,s values:');
|
|
50
|
+
console.log('======================');
|
|
51
|
+
console.log(`Original r: ${signature.r.toString('hex')}`);
|
|
52
|
+
console.log(`Parsed r : ${parsedFromDER.r.toString('hex')}`);
|
|
53
|
+
console.log(`r matches : ${signature.r.eq(parsedFromDER.r) ? '✅ YES' : '❌ NO'}`);
|
|
54
|
+
|
|
55
|
+
console.log(`Original s: ${signature.s.toString('hex')}`);
|
|
56
|
+
console.log(`Parsed s : ${parsedFromDER.s.toString('hex')}`);
|
|
57
|
+
console.log(`s matches : ${signature.s.eq(parsedFromDER.s) ? '✅ YES' : '❌ NO'}`);
|
|
58
|
+
|
|
59
|
+
} catch (error) {
|
|
60
|
+
console.log(`❌ DER parsing failed: ${error.message}`);
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
console.log('\n🔧 Debug SmartVerify DER Parsing:');
|
|
64
|
+
console.log('==================================');
|
|
65
|
+
|
|
66
|
+
// Let's manually step through what SmartVerify does with DER buffers
|
|
67
|
+
try {
|
|
68
|
+
console.log('Step 1: Input validation...');
|
|
69
|
+
console.log(` Hash is Buffer: ${Buffer.isBuffer(hash)}`);
|
|
70
|
+
console.log(` Hash length: ${hash.length}`);
|
|
71
|
+
console.log(` DER is Buffer: ${Buffer.isBuffer(derSig)}`);
|
|
72
|
+
|
|
73
|
+
console.log('Step 2: DER parsing in SmartVerify...');
|
|
74
|
+
|
|
75
|
+
// This replicates what SmartVerify does internally
|
|
76
|
+
const Signature = bsv.crypto.Signature;
|
|
77
|
+
const testParsed = Signature.fromDER(derSig);
|
|
78
|
+
console.log(` Parsed successfully: ✅`);
|
|
79
|
+
console.log(` Parsed r: ${testParsed.r.toString('hex')}`);
|
|
80
|
+
console.log(` Parsed s: ${testParsed.s.toString('hex')}`);
|
|
81
|
+
|
|
82
|
+
const BN = bsv.crypto.BN;
|
|
83
|
+
const r = BN.isBN(testParsed.r) ? testParsed.r : new BN(testParsed.r);
|
|
84
|
+
const s = BN.isBN(testParsed.s) ? testParsed.s : new BN(testParsed.s);
|
|
85
|
+
console.log(` r as BN: ${r.toString('hex')}`);
|
|
86
|
+
console.log(` s as BN: ${s.toString('hex')}`);
|
|
87
|
+
|
|
88
|
+
// Check canonicalization
|
|
89
|
+
const Point = bsv.crypto.Point;
|
|
90
|
+
const n = Point.getN();
|
|
91
|
+
const nh = n.shrn(1);
|
|
92
|
+
console.log(` s > n/2: ${s.gt(nh)}`);
|
|
93
|
+
|
|
94
|
+
const canonicalS = s.gt(nh) ? n.sub(s) : s;
|
|
95
|
+
console.log(` canonical s: ${canonicalS.toString('hex')}`);
|
|
96
|
+
|
|
97
|
+
// Test final ECDSA call
|
|
98
|
+
const canonicalSig = new Signature({
|
|
99
|
+
r: r,
|
|
100
|
+
s: canonicalS
|
|
101
|
+
});
|
|
102
|
+
|
|
103
|
+
const ECDSA = bsv.crypto.ECDSA;
|
|
104
|
+
const finalResult = ECDSA.verify(hash, canonicalSig, publicKey, 'little');
|
|
105
|
+
console.log(` Final ECDSA result: ${finalResult ? '✅ VALID' : '❌ INVALID'}`);
|
|
106
|
+
|
|
107
|
+
} catch (error) {
|
|
108
|
+
console.log(`❌ Debug failed: ${error.message}`);
|
|
109
|
+
console.log(`Stack: ${error.stack}`);
|
|
110
|
+
}
|