smartledger-bsv 3.3.3 → 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 +20 -7
- package/README.md +18 -1
- package/bsv-covenant.min.js +5 -5
- package/bsv-gdaf.min.js +4 -4
- package/bsv-ltp.min.js +4 -4
- package/bsv-mnemonic.min.js +4 -4
- package/bsv-smartcontract.min.js +4 -4
- package/bsv.bundle.js +4 -4
- package/bsv.min.js +4 -4
- package/demos/README.md +188 -0
- package/demos/architecture_demo.js +247 -0
- package/demos/bsv_wallet_demo.js +242 -0
- package/demos/complete_ltp_demo.js +511 -0
- 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/demos/shamir_demo.js +121 -0
- package/demos/simple_demo.js +204 -0
- 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/FIX_CREATEHMAC_ISSUE.md +91 -0
- 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/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/lib/mnemonic/pbkdf2.browser.js +69 -0
- package/lib/mnemonic/pbkdf2.js +2 -68
- package/lib/mnemonic/pbkdf2.node.js +68 -0
- package/package.json +17 -6
- 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
|
@@ -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>
|