smartledger-bsv 3.3.3 → 3.3.5
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 +50 -28
- package/README.md +55 -36
- package/bsv-covenant.min.js +6 -6
- package/bsv-gdaf.min.js +6 -6
- package/bsv-ltp.min.js +6 -6
- package/bsv-mnemonic.min.js +4 -4
- package/bsv-smartcontract.min.js +5 -5
- package/bsv.bundle.js +5 -5
- package/bsv.min.js +5 -5
- package/demos/README.md +188 -0
- package/demos/architecture_demo.js +247 -0
- package/demos/browser-test.html +1208 -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/DOCUMENTATION_REVIEW_REPORT.md +11 -11
- package/docs/FIX_CREATEHMAC_ISSUE.md +91 -0
- package/docs/MODULE_REFERENCE_COMPLETE.md +28 -28
- 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/UTXO_MANAGER_GUIDE.md +2 -2
- package/docs/getting-started/INSTALLATION.md +25 -25
- package/docs/getting-started/QUICK_START.md +7 -7
- package/docs/migration/FROM_BSV_1_5_6.md +5 -5
- 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/index.js +7 -0
- package/lib/browser-utxo-manager-es5.js +316 -0
- package/lib/browser-utxo-manager.js +533 -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 +19 -8
- 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,68 @@
|
|
|
1
|
+
'use strict'
|
|
2
|
+
|
|
3
|
+
var crypto = require('crypto')
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* PDKBF2
|
|
7
|
+
* Credit to: https://github.com/stayradiated/pbkdf2-sha512
|
|
8
|
+
* Copyright (c) 2014, JP Richardson Copyright (c) 2010-2011 Intalio Pte, All Rights Reserved
|
|
9
|
+
*/
|
|
10
|
+
function pbkdf2 (key, salt, iterations, dkLen) {
|
|
11
|
+
var hLen = 64 // SHA512 Mac length
|
|
12
|
+
if (dkLen > (Math.pow(2, 32) - 1) * hLen) {
|
|
13
|
+
throw Error('Requested key length too long')
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
if (typeof key !== 'string' && !Buffer.isBuffer(key)) {
|
|
17
|
+
throw new TypeError('key must a string or Buffer')
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
if (typeof salt !== 'string' && !Buffer.isBuffer(salt)) {
|
|
21
|
+
throw new TypeError('salt must a string or Buffer')
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
if (typeof key === 'string') {
|
|
25
|
+
key = Buffer.from(key)
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
if (typeof salt === 'string') {
|
|
29
|
+
salt = Buffer.from(salt)
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
var DK = Buffer.alloc(dkLen)
|
|
33
|
+
|
|
34
|
+
var U = Buffer.alloc(hLen)
|
|
35
|
+
var T = Buffer.alloc(hLen)
|
|
36
|
+
var block1 = Buffer.alloc(salt.length + 4)
|
|
37
|
+
|
|
38
|
+
var l = Math.ceil(dkLen / hLen)
|
|
39
|
+
var r = dkLen - (l - 1) * hLen
|
|
40
|
+
|
|
41
|
+
salt.copy(block1, 0, 0, salt.length)
|
|
42
|
+
for (var i = 1; i <= l; i++) {
|
|
43
|
+
block1[salt.length + 0] = (i >> 24 & 0xff)
|
|
44
|
+
block1[salt.length + 1] = (i >> 16 & 0xff)
|
|
45
|
+
block1[salt.length + 2] = (i >> 8 & 0xff)
|
|
46
|
+
block1[salt.length + 3] = (i >> 0 & 0xff)
|
|
47
|
+
|
|
48
|
+
U = crypto.createHmac('sha512', key).update(block1).digest()
|
|
49
|
+
|
|
50
|
+
U.copy(T, 0, 0, hLen)
|
|
51
|
+
|
|
52
|
+
for (var j = 1; j < iterations; j++) {
|
|
53
|
+
U = crypto.createHmac('sha512', key).update(U).digest()
|
|
54
|
+
|
|
55
|
+
for (var k = 0; k < hLen; k++) {
|
|
56
|
+
T[k] ^= U[k]
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
var destPos = (i - 1) * hLen
|
|
61
|
+
var len = (i === l ? r : hLen)
|
|
62
|
+
T.copy(DK, destPos, 0, len)
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
return DK
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
module.exports = pbkdf2
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "smartledger-bsv",
|
|
3
|
-
"version": "3.3.
|
|
4
|
-
"description": "🚀 Complete Bitcoin SV development framework with Legal Token Protocol (LTP), Global Digital Attestation Framework (GDAF), Shamir Secret Sharing, and
|
|
3
|
+
"version": "3.3.5",
|
|
4
|
+
"description": "🚀 Complete Bitcoin SV development framework with Legal Token Protocol (LTP), Global Digital Attestation Framework (GDAF), Shamir Secret Sharing, and 12 flexible loading options. Includes primitives-only architecture for maximum integration flexibility, SmartContract framework, covenant builder, and comprehensive Bitcoin SV API. Perfect for legal tokens, DeFi, smart contracts, 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": {
|
|
@@ -21,6 +21,20 @@
|
|
|
21
21
|
"test:basic": "node examples/basic/transaction-creation.js",
|
|
22
22
|
"test:all": "npm test && npm run test:covenants && npm run test:scripts",
|
|
23
23
|
"coverage": "nyc --reporter=text npm run test",
|
|
24
|
+
"demo": "node demos/smart_contract_demo.js",
|
|
25
|
+
"demo:web": "echo '🌐 Open demos/smart_contract_demo.html in your browser'",
|
|
26
|
+
"demo:basics": "node demos/smart_contract_demo.js --feature basics",
|
|
27
|
+
"demo:covenant": "node demos/smart_contract_demo.js --feature covenant",
|
|
28
|
+
"demo:preimage": "node demos/smart_contract_demo.js --feature preimage",
|
|
29
|
+
"demo:utxo": "node demos/smart_contract_demo.js --feature utxo",
|
|
30
|
+
"demo:scripts": "node demos/smart_contract_demo.js --feature scripts",
|
|
31
|
+
"demo:legacy": "npm run test:covenants",
|
|
32
|
+
"demo:legacy:basic": "npm run test:basic",
|
|
33
|
+
"demo:legacy:scripts": "npm run test:scripts",
|
|
34
|
+
"demo:legacy:preimage": "echo '🧠 BIP-143 Preimage Extractor Demo' && node examples/preimage/extract_preimage_bidirectional.js",
|
|
35
|
+
"smart-contracts": "node examples/smart_contract_templates.js",
|
|
36
|
+
"smart-contracts:working": "node examples/final_working_contracts.js",
|
|
37
|
+
"workflow": "node examples/complete_workflow_demo.js",
|
|
24
38
|
"build-bsv": "NODE_OPTIONS=\"--openssl-legacy-provider\" webpack index.js --config build/webpack.config.js",
|
|
25
39
|
"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",
|
|
26
40
|
"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",
|
|
@@ -39,10 +53,6 @@
|
|
|
39
53
|
"build-all": "npm run build && npm run build-bundle && npm run build-specialized && npm run build-advanced",
|
|
40
54
|
"test:browser": "echo 'Open tests/standalone-modules-test.html in browser for comprehensive testing'",
|
|
41
55
|
"test:bundle": "echo 'Open tests/bundle-completeness-test.html in browser to verify bundle completeness'",
|
|
42
|
-
"demo": "npm run test:covenants",
|
|
43
|
-
"demo:basic": "npm run test:basic",
|
|
44
|
-
"demo:scripts": "npm run test:scripts",
|
|
45
|
-
"demo:preimage": "echo '🧠 BIP-143 Preimage Extractor Demo' && node examples/preimage/extract_preimage_bidirectional.js",
|
|
46
56
|
"preimage:extract": "node examples/preimage/extract_preimage_bidirectional.js",
|
|
47
57
|
"prepublishOnly": "NODE_OPTIONS=\"--openssl-legacy-provider\" npm run build"
|
|
48
58
|
},
|
|
@@ -62,7 +72,7 @@
|
|
|
62
72
|
"bsv.min.js",
|
|
63
73
|
"bsv.bundle.js",
|
|
64
74
|
"bsv-ecies.min.js",
|
|
65
|
-
"bsv-message.min.js",
|
|
75
|
+
"bsv-message.min.js",
|
|
66
76
|
"bsv-mnemonic.min.js",
|
|
67
77
|
"bsv-shamir.min.js",
|
|
68
78
|
"bsv-gdaf.min.js",
|
|
@@ -80,6 +90,7 @@
|
|
|
80
90
|
"architecture_demo.js",
|
|
81
91
|
"test_standalone_shamir.html",
|
|
82
92
|
"docs/",
|
|
93
|
+
"demos/",
|
|
83
94
|
"examples/",
|
|
84
95
|
"LICENSE",
|
|
85
96
|
"README.md",
|
|
@@ -88,7 +99,7 @@
|
|
|
88
99
|
],
|
|
89
100
|
"keywords": [
|
|
90
101
|
"bitcoin",
|
|
91
|
-
"bitcoin-sv",
|
|
102
|
+
"bitcoin-sv",
|
|
92
103
|
"bsv",
|
|
93
104
|
"legal-token-protocol",
|
|
94
105
|
"ltp",
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
# Browser Compatibility Tests
|
|
2
|
+
|
|
3
|
+
This directory contains test files for verifying browser compatibility fixes.
|
|
4
|
+
|
|
5
|
+
## Test Files
|
|
6
|
+
|
|
7
|
+
### `test-cdn-vs-local.html`
|
|
8
|
+
Comprehensive test that compares CDN bundles vs local bundles to verify the `createHmac` fix.
|
|
9
|
+
|
|
10
|
+
**Usage:**
|
|
11
|
+
1. Open in browser
|
|
12
|
+
2. Click "Test CDN Version" - should show `createHmac` error (if using unfixed CDN)
|
|
13
|
+
3. Click "Test Local Version" - should work with fixed bundles
|
|
14
|
+
4. View summary to confirm fix effectiveness
|
|
15
|
+
|
|
16
|
+
### `test-pbkdf2.html`
|
|
17
|
+
Simple test focused specifically on PBKDF2 functionality.
|
|
18
|
+
|
|
19
|
+
**Usage:**
|
|
20
|
+
1. Open in browser
|
|
21
|
+
2. Tests mnemonic generation using PBKDF2
|
|
22
|
+
3. Shows detailed error information if PBKDF2 fails
|
|
23
|
+
|
|
24
|
+
## Background
|
|
25
|
+
|
|
26
|
+
These tests were created to verify the fix for issue where CDN users experienced:
|
|
27
|
+
- `createHmac is not a function` errors
|
|
28
|
+
- Failed mnemonic generation
|
|
29
|
+
- Failed HD wallet key derivation
|
|
30
|
+
|
|
31
|
+
The fix implemented browser-compatible PBKDF2 using BSV's crypto modules instead of Node.js crypto.
|
|
32
|
+
|
|
33
|
+
## Fix Details
|
|
34
|
+
|
|
35
|
+
See `docs/FIX_CREATEHMAC_ISSUE.md` for complete technical details.
|
|
@@ -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.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>
|
|
@@ -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>
|