@smartledger/bsv 3.2.2 → 3.3.3

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 (95) hide show
  1. package/CHANGELOG.md +279 -4
  2. package/README.md +266 -71
  3. package/bsv-covenant.min.js +26 -3
  4. package/bsv-gdaf.min.js +39 -0
  5. package/bsv-ltp.min.js +39 -0
  6. package/bsv-script-helper.min.js +2 -2
  7. package/bsv-security.min.js +3 -24
  8. package/bsv-shamir.min.js +12 -0
  9. package/bsv-smartcontract.min.js +10 -8
  10. package/bsv.bundle.js +7 -7
  11. package/bsv.min.js +10 -8
  12. package/build/webpack.bundle.config.js +2 -2
  13. package/build/webpack.config.js +2 -2
  14. package/build/webpack.covenant.config.js +2 -2
  15. package/build/webpack.gdaf.config.js +17 -0
  16. package/build/webpack.ltp.config.js +17 -0
  17. package/build/webpack.script-helper.config.js +2 -2
  18. package/build/webpack.security.config.js +2 -2
  19. package/build/webpack.smartcontract.config.js +2 -2
  20. package/bundle-entry.js +1 -265
  21. package/covenant-entry.js +1 -44
  22. package/docs/DOCUMENTATION_REVIEW_REPORT.md +295 -0
  23. package/docs/MODULE_REFERENCE_COMPLETE.md +330 -0
  24. package/docs/README.md +107 -79
  25. package/docs/advanced/LEGAL_TOKEN_PROTOCOL.md +411 -0
  26. package/docs/advanced/SMART_CONTRACT_GUIDE.md +1255 -0
  27. package/docs/advanced/UTXO_MANAGER_GUIDE.md +851 -0
  28. package/docs/api/LTP.md +334 -0
  29. package/docs/getting-started/INSTALLATION.md +410 -0
  30. package/docs/getting-started/QUICK_START.md +180 -0
  31. package/docs/migration/FROM_BSV_1_5_6.md +260 -0
  32. package/docs/technical/GDAF_DEVELOPER_INTERFACE.md +187 -0
  33. package/docs/technical/GDAF_IMPLEMENTATION_COMPLETE.md +190 -0
  34. package/docs/technical/SHAMIR_INTEGRATION_SUMMARY.md +165 -0
  35. package/docs/technical/roadmap.md +1250 -0
  36. package/docs/technical/trust_law.md +142 -0
  37. package/gdaf-entry.js +2 -0
  38. package/index.js +291 -0
  39. package/lib/crypto/shamir.js +360 -0
  40. package/lib/gdaf/attestation-signer.js +461 -0
  41. package/lib/gdaf/attestation-verifier.js +600 -0
  42. package/lib/gdaf/did-resolver.js +382 -0
  43. package/lib/gdaf/index.js +471 -0
  44. package/lib/gdaf/schema-validator.js +682 -0
  45. package/lib/gdaf/smartledger-anchor.js +486 -0
  46. package/lib/gdaf/zk-prover.js +507 -0
  47. package/lib/ltp/anchor.js +438 -0
  48. package/lib/ltp/claim.js +1026 -0
  49. package/lib/ltp/index.js +470 -0
  50. package/lib/ltp/obligation.js +945 -0
  51. package/lib/ltp/proof.js +828 -0
  52. package/lib/ltp/registry.js +702 -0
  53. package/lib/ltp/right.js +765 -0
  54. package/lib/smart_contract/API_REFERENCE.md +1 -1
  55. package/lib/smart_contract/EXAMPLES.md +2 -2
  56. package/lib/smart_contract/QUICK_START.md +2 -2
  57. package/lib/smart_contract/README.md +1 -1
  58. package/ltp-entry.js +2 -0
  59. package/package.json +48 -6
  60. package/script-helper-entry.js +1 -49
  61. package/security-entry.js +1 -70
  62. package/shamir-entry.js +1 -0
  63. package/smartcontract-entry.js +1 -133
  64. package/tests/test_builtin_verify.js +117 -0
  65. package/tests/test_debug_integration.js +71 -0
  66. package/tests/test_ecdsa_little.js +70 -0
  67. package/tests/test_shamir.js +221 -0
  68. package/tests/test_smartverify_der.js +110 -0
  69. package/tests/test_standalone_shamir.html +83 -0
  70. package/utilities/blockchain-state.js +155 -155
  71. package/utilities/blockchain-state.json +103293 -5244
  72. package/utilities/miner-simulator.js +354 -358
  73. package/utilities/mock-utxo-generator.js +54 -54
  74. package/utilities/raw-tx-examples.js +120 -122
  75. package/utilities/success-demo.js +104 -105
  76. package/utilities/transaction-examples.js +188 -188
  77. package/utilities/utxo-manager.js +91 -91
  78. package/utilities/wallet-setup.js +79 -80
  79. package/utilities/working-signature-demo.js +108 -110
  80. package/SECURITY.md +0 -75
  81. package/build/bsv-covenant.min.js +0 -10
  82. package/build/bsv-script-helper.min.js +0 -10
  83. package/build/bsv-security.min.js +0 -31
  84. package/build/bsv-smartcontract.min.js +0 -37
  85. package/build/bsv.bundle.js +0 -39
  86. package/build/bsv.min.js +0 -37
  87. package/validation_test.js +0 -97
  88. /package/docs/{ADVANCED_COVENANT_DEVELOPMENT.md → advanced/ADVANCED_COVENANT_DEVELOPMENT.md} +0 -0
  89. /package/docs/{CUSTOM_SCRIPT_DEVELOPMENT.md → advanced/CUSTOM_SCRIPT_DEVELOPMENT.md} +0 -0
  90. /package/docs/{block.md → api/BLOCKS.md} +0 -0
  91. /package/docs/{ecies.md → api/ECIES.md} +0 -0
  92. /package/docs/{networks.md → api/NETWORKS.md} +0 -0
  93. /package/docs/{script.md → api/SCRIPTS.md} +0 -0
  94. /package/docs/{transaction.md → api/TRANSACTIONS.md} +0 -0
  95. /package/docs/{unspentoutput.md → api/UTXO.md} +0 -0
@@ -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,221 @@
1
+ #!/usr/bin/env node
2
+
3
+ /**
4
+ * BSV Shamir Secret Sharing Test
5
+ * Comprehensive test of the Shamir Secret Sharing implementation
6
+ */
7
+
8
+ 'use strict'
9
+
10
+ console.log('=== BSV Shamir Secret Sharing Test ===\n')
11
+
12
+ // Load the BSV library with Shamir support
13
+ var bsv
14
+ try {
15
+ bsv = require('./index.js')
16
+ console.log('✓ Loaded BSV library with Shamir support')
17
+ } catch (e) {
18
+ console.error('✗ Failed to load BSV library:', e.message)
19
+ process.exit(1)
20
+ }
21
+
22
+ // Test 1: Basic functionality test
23
+ console.log('\n--- Test 1: Basic Secret Sharing ---')
24
+ try {
25
+ var secret = 'Hello, Bitcoin SV!'
26
+ var threshold = 3
27
+ var shares = 5
28
+
29
+ console.log('Original secret:', secret)
30
+ console.log('Threshold:', threshold, '/ Total shares:', shares)
31
+
32
+ // Split the secret
33
+ var splitShares = bsv.Shamir.split(secret, threshold, shares)
34
+ console.log('✓ Successfully split secret into', splitShares.length, 'shares')
35
+
36
+ // Reconstruct with minimum shares
37
+ var reconstructed = bsv.Shamir.combine(splitShares.slice(0, threshold))
38
+ var reconstructedSecret = reconstructed.toString('utf8')
39
+
40
+ console.log('Reconstructed:', reconstructedSecret)
41
+
42
+ if (reconstructedSecret === secret) {
43
+ console.log('✓ Test 1 PASSED: Secret correctly reconstructed')
44
+ } else {
45
+ console.log('✗ Test 1 FAILED: Secret reconstruction failed')
46
+ }
47
+ } catch (e) {
48
+ console.log('✗ Test 1 ERROR:', e.message)
49
+ }
50
+
51
+ // Test 2: Larger secret test
52
+ console.log('\n--- Test 2: Large Secret Test ---')
53
+ try {
54
+ var largeSecret = 'This is a much longer secret that will test the chunking functionality of the Shamir Secret Sharing implementation. It should handle secrets of arbitrary length by breaking them into manageable chunks and processing each chunk separately.'
55
+ var threshold2 = 4
56
+ var shares2 = 7
57
+
58
+ console.log('Large secret length:', largeSecret.length, 'characters')
59
+
60
+ var splitShares2 = bsv.Shamir.split(largeSecret, threshold2, shares2)
61
+ console.log('✓ Successfully split large secret')
62
+
63
+ var reconstructed2 = bsv.Shamir.combine(splitShares2.slice(0, threshold2))
64
+ var reconstructedSecret2 = reconstructed2.toString('utf8')
65
+
66
+ if (reconstructedSecret2 === largeSecret) {
67
+ console.log('✓ Test 2 PASSED: Large secret correctly reconstructed')
68
+ } else {
69
+ console.log('✗ Test 2 FAILED: Large secret reconstruction failed')
70
+ console.log('Expected length:', largeSecret.length)
71
+ console.log('Actual length:', reconstructedSecret2.length)
72
+ console.log('First 50 chars expected:', largeSecret.substring(0, 50))
73
+ console.log('First 50 chars actual :', reconstructedSecret2.substring(0, 50))
74
+ console.log('Match:', largeSecret === reconstructedSecret2)
75
+ }
76
+ } catch (e) {
77
+ console.log('✗ Test 2 ERROR:', e.message)
78
+ }
79
+
80
+ // Test 3: Different share combinations
81
+ console.log('\n--- Test 3: Share Combination Test ---')
82
+ try {
83
+ var secret3 = 'Testing different combinations'
84
+ var splitShares3 = bsv.Shamir.split(secret3, 3, 6)
85
+
86
+ // Test different combinations of 3 shares
87
+ var combinations = [
88
+ [0, 1, 2], // First three
89
+ [1, 3, 5], // Every other
90
+ [2, 4, 5] // Last three + one
91
+ ]
92
+
93
+ var allPassed = true
94
+ for (var i = 0; i < combinations.length; i++) {
95
+ var combo = combinations[i]
96
+ var testShares = combo.map(function(idx) { return splitShares3[idx] })
97
+ var reconstructed3 = bsv.Shamir.combine(testShares)
98
+ var result = reconstructed3.toString('utf8')
99
+
100
+ if (result === secret3) {
101
+ console.log('✓ Combination', combo, 'successful')
102
+ } else {
103
+ console.log('✗ Combination', combo, 'failed')
104
+ allPassed = false
105
+ }
106
+ }
107
+
108
+ if (allPassed) {
109
+ console.log('✓ Test 3 PASSED: All share combinations work')
110
+ } else {
111
+ console.log('✗ Test 3 FAILED: Some combinations failed')
112
+ }
113
+ } catch (e) {
114
+ console.log('✗ Test 3 ERROR:', e.message)
115
+ }
116
+
117
+ // Test 4: Share verification
118
+ console.log('\n--- Test 4: Share Verification Test ---')
119
+ try {
120
+ var secret4 = 'Verification test'
121
+ var splitShares4 = bsv.Shamir.split(secret4, 2, 4)
122
+
123
+ var validCount = 0
124
+ for (var j = 0; j < splitShares4.length; j++) {
125
+ if (bsv.Shamir.verifyShare(splitShares4[j])) {
126
+ validCount++
127
+ }
128
+ }
129
+
130
+ if (validCount === splitShares4.length) {
131
+ console.log('✓ Test 4 PASSED: All shares verified as valid')
132
+ } else {
133
+ console.log('✗ Test 4 FAILED: Only', validCount, 'of', splitShares4.length, 'shares valid')
134
+ }
135
+
136
+ // Test invalid share
137
+ var invalidShare = { invalid: 'data' }
138
+ if (!bsv.Shamir.verifyShare(invalidShare)) {
139
+ console.log('✓ Invalid share correctly rejected')
140
+ } else {
141
+ console.log('✗ Invalid share incorrectly accepted')
142
+ }
143
+ } catch (e) {
144
+ console.log('✗ Test 4 ERROR:', e.message)
145
+ }
146
+
147
+ // Test 5: Error handling
148
+ console.log('\n--- Test 5: Error Handling Test ---')
149
+ try {
150
+ var errorTests = [
151
+ function() { bsv.Shamir.split('', 2, 3) }, // Empty secret
152
+ function() { bsv.Shamir.split('secret', 1, 3) }, // Threshold too low
153
+ function() { bsv.Shamir.split('secret', 3, 2) }, // More threshold than shares
154
+ function() { bsv.Shamir.combine([]) }, // Empty shares array
155
+ function() { bsv.Shamir.combine([{id: 1, threshold: 2, shares: 3, length: 1, bytes: []}]) } // Insufficient shares
156
+ ]
157
+
158
+ var errorsPassed = 0
159
+ for (var k = 0; k < errorTests.length; k++) {
160
+ try {
161
+ errorTests[k]()
162
+ console.log('✗ Error test', k + 1, 'should have thrown an error')
163
+ } catch (e) {
164
+ console.log('✓ Error test', k + 1, 'correctly threw:', e.message)
165
+ errorsPassed++
166
+ }
167
+ }
168
+
169
+ if (errorsPassed === errorTests.length) {
170
+ console.log('✓ Test 5 PASSED: All error conditions handled correctly')
171
+ } else {
172
+ console.log('✗ Test 5 FAILED: Some error conditions not handled')
173
+ }
174
+ } catch (e) {
175
+ console.log('✗ Test 5 ERROR:', e.message)
176
+ }
177
+
178
+ // Test 6: Binary data test
179
+ console.log('\n--- Test 6: Binary Data Test ---')
180
+ try {
181
+ var binaryData = Buffer.from([0x00, 0x01, 0x02, 0xFF, 0xFE, 0xFD, 0x80, 0x7F])
182
+ var splitBinary = bsv.Shamir.split(binaryData, 2, 3)
183
+ var reconstructedBinary = bsv.Shamir.combine(splitBinary.slice(0, 2))
184
+
185
+ if (Buffer.compare(binaryData, reconstructedBinary) === 0) {
186
+ console.log('✓ Test 6 PASSED: Binary data correctly handled')
187
+ } else {
188
+ console.log('✗ Test 6 FAILED: Binary data reconstruction failed')
189
+ console.log('Original:', Array.from(binaryData))
190
+ console.log('Reconstructed:', Array.from(reconstructedBinary))
191
+ }
192
+ } catch (e) {
193
+ console.log('✗ Test 6 ERROR:', e.message)
194
+ }
195
+
196
+ // Test 7: Generate test vectors
197
+ console.log('\n--- Test 7: Test Vectors Generation ---')
198
+ try {
199
+ var testVectors = bsv.Shamir.generateTestVectors()
200
+
201
+ console.log('Test vectors generated:')
202
+ console.log('- Secret:', testVectors.secret)
203
+ console.log('- Threshold:', testVectors.threshold)
204
+ console.log('- Total shares:', testVectors.totalShares)
205
+ console.log('- Shares generated:', testVectors.shares.length)
206
+ console.log('- Reconstruction successful:', testVectors.valid)
207
+
208
+ if (testVectors.valid) {
209
+ console.log('✓ Test 7 PASSED: Test vectors generated and validated')
210
+ } else {
211
+ console.log('✗ Test 7 FAILED: Test vectors validation failed')
212
+ }
213
+ } catch (e) {
214
+ console.log('✗ Test 7 ERROR:', e.message)
215
+ }
216
+
217
+ console.log('\n=== Shamir Secret Sharing Tests Complete ===')
218
+ console.log('💡 Integration successful! Shamir Secret Sharing is now available in:')
219
+ console.log(' • Main library: bsv.Shamir or bsv.crypto.Shamir')
220
+ console.log(' • Standalone: bsv-shamir.min.js (after build)')
221
+ console.log(' • CDN ready: Use npm run build-shamir to generate minified version')
@@ -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
+ }
@@ -0,0 +1,83 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>BSV Shamir Secret Sharing - Standalone Test</title>
5
+ <meta charset="utf-8">
6
+ </head>
7
+ <body>
8
+ <h1>BSV Shamir Secret Sharing - Standalone Module Test</h1>
9
+ <div id="output"></div>
10
+
11
+ <script src="bsv-shamir.min.js"></script>
12
+ <script>
13
+ function log(message) {
14
+ document.getElementById('output').innerHTML += message + '<br>';
15
+ console.log(message);
16
+ }
17
+
18
+ log('=== BSV Shamir Standalone Module Test ===');
19
+ log('');
20
+
21
+ try {
22
+ if (typeof bsvShamir === 'undefined') {
23
+ log('❌ bsvShamir not available');
24
+ } else {
25
+ log('✅ bsvShamir loaded successfully');
26
+ log('Version: ' + bsvShamir.version);
27
+ log('Algorithm: ' + bsvShamir.algorithm);
28
+ log('');
29
+
30
+ // Test basic functionality
31
+ var secret = 'Hello from Browser!';
32
+ var threshold = 2;
33
+ var shares = 4;
34
+
35
+ log('🔐 Testing secret splitting...');
36
+ log('Secret: ' + secret);
37
+ log('Threshold: ' + threshold + ', Total shares: ' + shares);
38
+
39
+ var splitShares = bsvShamir.split(secret, threshold, shares);
40
+ log('✅ Split into ' + splitShares.length + ' shares');
41
+
42
+ // Test reconstruction
43
+ log('');
44
+ log('🔓 Testing secret reconstruction...');
45
+ var reconstructed = bsvShamir.combine(splitShares.slice(0, threshold));
46
+ var reconstructedSecret = reconstructed.toString();
47
+
48
+ log('Reconstructed: ' + reconstructedSecret);
49
+
50
+ if (reconstructedSecret === secret) {
51
+ log('✅ Reconstruction successful!');
52
+ } else {
53
+ log('❌ Reconstruction failed');
54
+ }
55
+
56
+ // Test share verification
57
+ log('');
58
+ log('🔍 Testing share verification...');
59
+ var validShares = 0;
60
+ for (var i = 0; i < splitShares.length; i++) {
61
+ if (bsvShamir.verifyShare(splitShares[i])) {
62
+ validShares++;
63
+ }
64
+ }
65
+ log('Valid shares: ' + validShares + '/' + splitShares.length);
66
+
67
+ // Run demo
68
+ log('');
69
+ log('🚀 Running demo...');
70
+ var demoResult = bsvShamir.demo();
71
+ log('Demo completed: ' + (demoResult.success ? 'SUCCESS' : 'FAILED'));
72
+
73
+ log('');
74
+ log('🎉 All tests completed successfully!');
75
+ log('📦 BSV Shamir Secret Sharing standalone module is working correctly.');
76
+ }
77
+ } catch (error) {
78
+ log('❌ Error: ' + error.message);
79
+ console.error('Full error:', error);
80
+ }
81
+ </script>
82
+ </body>
83
+ </html>