@smartledger/bsv 3.2.1 → 3.3.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (70) hide show
  1. package/CHANGELOG.md +147 -0
  2. package/README.md +289 -55
  3. package/architecture_demo.js +247 -0
  4. package/bsv-covenant.min.js +10 -0
  5. package/bsv-gdaf.min.js +37 -0
  6. package/bsv-ltp.min.js +37 -0
  7. package/bsv-script-helper.min.js +10 -0
  8. package/bsv-security.min.js +31 -0
  9. package/bsv-shamir.min.js +12 -0
  10. package/bsv-smartcontract.min.js +37 -0
  11. package/bsv.bundle.js +9 -9
  12. package/bsv.min.js +3 -3
  13. package/build/bsv-covenant.min.js +10 -0
  14. package/build/bsv-script-helper.min.js +10 -0
  15. package/build/bsv-security.min.js +31 -0
  16. package/build/bsv-smartcontract.min.js +39 -0
  17. package/build/bsv.bundle.js +39 -0
  18. package/build/bsv.min.js +39 -0
  19. package/build/webpack.bundle.config.js +22 -0
  20. package/build/webpack.config.js +18 -0
  21. package/build/webpack.covenant.config.js +27 -0
  22. package/build/webpack.gdaf.config.js +54 -0
  23. package/build/webpack.ltp.config.js +17 -0
  24. package/build/webpack.script-helper.config.js +27 -0
  25. package/build/webpack.security.config.js +23 -0
  26. package/build/webpack.smartcontract.config.js +25 -0
  27. package/build/webpack.subproject.config.js +6 -0
  28. package/bundle-entry.js +341 -0
  29. package/complete_ltp_demo.js +511 -0
  30. package/covenant-entry.js +44 -0
  31. package/docs/pushtx-key-insights.md +106 -0
  32. package/gdaf-entry.js +54 -0
  33. package/index.js +272 -5
  34. package/lib/crypto/shamir.js +360 -0
  35. package/lib/gdaf/attestation-signer.js +461 -0
  36. package/lib/gdaf/attestation-verifier.js +600 -0
  37. package/lib/gdaf/did-resolver.js +382 -0
  38. package/lib/gdaf/index.js +471 -0
  39. package/lib/gdaf/schema-validator.js +682 -0
  40. package/lib/gdaf/smartledger-anchor.js +486 -0
  41. package/lib/gdaf/zk-prover.js +507 -0
  42. package/lib/ltp/anchor.js +438 -0
  43. package/lib/ltp/claim.js +1026 -0
  44. package/lib/ltp/index.js +470 -0
  45. package/lib/ltp/obligation.js +945 -0
  46. package/lib/ltp/proof.js +828 -0
  47. package/lib/ltp/registry.js +702 -0
  48. package/lib/ltp/right.js +765 -0
  49. package/lib/smart_contract/API_REFERENCE.md +1 -1
  50. package/lib/smart_contract/EXAMPLES.md +2 -2
  51. package/lib/smart_contract/QUICK_START.md +2 -2
  52. package/lib/smart_contract/README.md +1 -1
  53. package/lib/smart_contract/index.js +4 -0
  54. package/ltp-entry.js +92 -0
  55. package/package.json +91 -20
  56. package/script-helper-entry.js +49 -0
  57. package/security-entry.js +70 -0
  58. package/shamir-entry.js +173 -0
  59. package/shamir_demo.js +121 -0
  60. package/simple_demo.js +204 -0
  61. package/smartcontract-entry.js +133 -0
  62. package/test_shamir.js +221 -0
  63. package/test_standalone_shamir.html +83 -0
  64. package/tests/bundle-completeness-test.html +131 -0
  65. package/tests/bundle-demo.html +476 -0
  66. package/tests/smartcontract-test.html +239 -0
  67. package/tests/standalone-modules-test.html +260 -0
  68. package/tests/test.html +612 -0
  69. package/tests/unpkg-demo.html +194 -0
  70. package/docs/nchain.md +0 -958
@@ -19,7 +19,7 @@
19
19
  ## Quick Start
20
20
 
21
21
  ```javascript
22
- const SmartContract = require('bsv-elliptic-fix').SmartContract
22
+ const SmartContract = require('smartledger-bsv').SmartContract
23
23
 
24
24
  // 🚀 Write covenant logic in JavaScript
25
25
  const builder = SmartContract.createCovenantBuilder()
@@ -17,7 +17,7 @@
17
17
  ### Example 1: Simple Value Check
18
18
 
19
19
  ```javascript
20
- const SmartContract = require('bsv-elliptic-fix').SmartContract
20
+ const SmartContract = require('smartledger-bsv').SmartContract
21
21
 
22
22
  // Ensure transaction maintains minimum value
23
23
  function createValueGuard(minimumSatoshis) {
@@ -419,7 +419,7 @@ function createSubscriptionCovenant(serviceProvider, subscriptionFee, renewalPer
419
419
  ### Example 12: Complete Covenant Deployment
420
420
 
421
421
  ```javascript
422
- const bsv = require('bsv-elliptic-fix')
422
+ const bsv = require('smartledger-bsv')
423
423
  const SmartContract = bsv.SmartContract
424
424
 
425
425
  async function deployValueLockCovenant(privateKey, minimumValue, utxo) {
@@ -9,7 +9,7 @@ The JavaScript-to-Bitcoin Script framework allows you to write complex covenant
9
9
  ## 🚀 30-Second Quick Start
10
10
 
11
11
  ```javascript
12
- const SmartContract = require('bsv-elliptic-fix').SmartContract
12
+ const SmartContract = require('smartledger-bsv').SmartContract
13
13
 
14
14
  // Write covenant logic in JavaScript
15
15
  const builder = SmartContract.createCovenantBuilder()
@@ -415,7 +415,7 @@ Object.keys(opcodes)
415
415
  ### With BSV Library
416
416
 
417
417
  ```javascript
418
- const bsv = require('bsv-elliptic-fix')
418
+ const bsv = require('smartledger-bsv')
419
419
  const SmartContract = bsv.SmartContract
420
420
 
421
421
  // Create covenant from private key
@@ -7,7 +7,7 @@ The SmartContract module provides enterprise-grade covenant functionality for Bi
7
7
  ## Installation & Usage
8
8
 
9
9
  ```javascript
10
- const bsv = require('bsv-elliptic-fix')
10
+ const bsv = require('smartledger-bsv')
11
11
 
12
12
  // Access SmartContract module
13
13
  const SmartContract = bsv.SmartContract
@@ -347,4 +347,8 @@ SmartContract.features = {
347
347
  PRODUCTION_READY: true
348
348
  }
349
349
 
350
+ // Standard debug method aliases for compatibility
351
+ SmartContract.interpretScript = SmartContract.debugScriptExecution
352
+ SmartContract.getScriptMetrics = SmartContract.scriptMetrics
353
+
350
354
  module.exports = SmartContract
package/ltp-entry.js ADDED
@@ -0,0 +1,92 @@
1
+ /**
2
+ * SmartLedger-BSV Legal Token Protocol (LTP) - Standalone Entry Point
3
+ *
4
+ * This entry point provides the complete Legal Token Protocol framework
5
+ * as a standalone module for browser and Node.js environments.
6
+ *
7
+ * Features:
8
+ * - Complete LTP primitives-only architecture
9
+ * - Legal claim validation and attestation
10
+ * - Right and obligation token management
11
+ * - Cryptographic proof generation
12
+ * - Registry and blockchain anchoring preparation
13
+ * - Full W3C compatibility and legal compliance
14
+ */
15
+
16
+ const bsv = require('./index.js')
17
+
18
+ // Export LTP functionality as standalone module
19
+ module.exports = {
20
+ // Core BSV functionality needed for LTP
21
+ PrivateKey: bsv.PrivateKey,
22
+ PublicKey: bsv.PublicKey,
23
+ Address: bsv.Address,
24
+ Transaction: bsv.Transaction,
25
+ Script: bsv.Script,
26
+ crypto: bsv.crypto,
27
+
28
+ // Complete LTP framework
29
+ LTP: bsv.LTP,
30
+
31
+ // Right Token Primitives
32
+ prepareRightToken: bsv.prepareRightToken,
33
+ prepareRightTokenVerification: bsv.prepareRightTokenVerification,
34
+ prepareRightTokenTransfer: bsv.prepareRightTokenTransfer,
35
+ prepareRightTypeValidation: bsv.prepareRightTypeValidation,
36
+
37
+ // Obligation Token Primitives
38
+ prepareObligationToken: bsv.prepareObligationToken,
39
+ prepareObligationVerification: bsv.prepareObligationVerification,
40
+ prepareObligationFulfillment: bsv.prepareObligationFulfillment,
41
+ prepareObligationBreachAssessment: bsv.prepareObligationBreachAssessment,
42
+ prepareObligationMonitoringReport: bsv.prepareObligationMonitoringReport,
43
+
44
+ // Claim Validation Primitives
45
+ prepareClaimValidation: bsv.prepareClaimValidation,
46
+ prepareClaimAttestation: bsv.prepareClaimAttestation,
47
+ prepareClaimDispute: bsv.prepareClaimDispute,
48
+ prepareBulkClaimValidation: bsv.prepareBulkClaimValidation,
49
+ prepareClaimTemplate: bsv.prepareClaimTemplate,
50
+
51
+ // Proof Generation Primitives
52
+ prepareSignatureProof: bsv.prepareSignatureProof,
53
+ prepareSignatureVerification: bsv.prepareSignatureVerification,
54
+ prepareSelectiveDisclosure: bsv.prepareSelectiveDisclosure,
55
+ prepareSelectiveDisclosureVerification: bsv.prepareSelectiveDisclosureVerification,
56
+ prepareLegalValidityProof: bsv.prepareLegalValidityProof,
57
+ prepareZeroKnowledgeProof: bsv.prepareZeroKnowledgeProof,
58
+
59
+ // Registry Management Primitives
60
+ prepareRegistry: bsv.prepareRegistry,
61
+ prepareTokenRegistration: bsv.prepareTokenRegistration,
62
+ prepareTokenApproval: bsv.prepareTokenApproval,
63
+ prepareTokenRevocation: bsv.prepareTokenRevocation,
64
+ prepareTokenStatusQuery: bsv.prepareTokenStatusQuery,
65
+ prepareTokenSearch: bsv.prepareTokenSearch,
66
+ prepareStatisticsQuery: bsv.prepareStatisticsQuery,
67
+ prepareAuditLogQuery: bsv.prepareAuditLogQuery,
68
+
69
+ // Blockchain Anchoring Primitives
70
+ prepareTokenCommitment: bsv.prepareTokenCommitment,
71
+ prepareBatchCommitment: bsv.prepareBatchCommitment,
72
+ verifyTokenAnchor: bsv.verifyTokenAnchor,
73
+ formatRevocation: bsv.formatRevocation,
74
+
75
+ // Utility Functions
76
+ getRightTypes: bsv.getRightTypes,
77
+ getObligationTypes: bsv.getObligationTypes,
78
+ getObligationPriority: bsv.getObligationPriority,
79
+ getObligationStatus: bsv.getObligationStatus,
80
+ getClaimSchemas: bsv.getClaimSchemas,
81
+ getClaimSchemaNames: bsv.getClaimSchemaNames,
82
+ getClaimSchema: bsv.getClaimSchema,
83
+ createClaimTemplate: bsv.createClaimTemplate,
84
+ canonicalizeClaim: bsv.canonicalizeClaim,
85
+ hashClaim: bsv.hashClaim,
86
+ addCustomClaimSchema: bsv.addCustomClaimSchema,
87
+
88
+ // Version and metadata
89
+ version: '3.3.0',
90
+ framework: 'Legal Token Protocol',
91
+ architecture: 'primitives-only'
92
+ }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@smartledger/bsv",
3
- "version": "3.2.1",
4
- "description": "Advanced Bitcoin SV library with JavaScript-to-Bitcoin Script framework - Complete BSV API + BIP143 preimage parsing + 121 opcode mapping + covenant builder + nChain PUSHTX techniques + custom script development + integrated debugging tools",
3
+ "version": "3.3.2",
4
+ "description": "🚀 Complete Bitcoin SV development framework with Legal Token Protocol (LTP), Global Digital Attestation Framework (GDAF), Shamir Secret Sharing, and 9 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": {
@@ -11,7 +11,9 @@
11
11
  "scripts": {
12
12
  "lint": "standard",
13
13
  "test": "standard && mocha",
14
- "test:signatures": "node validation_test.js",
14
+ "test:ltp": "node complete_ltp_demo.js",
15
+ "test:ltp-primitives": "node simple_demo.js",
16
+ "test:architecture": "node architecture_demo.js",
15
17
  "test:js2script": "node lib/smart_contract/opcode_map.js && node lib/smart_contract/covenant_builder.js",
16
18
  "test:opcodes": "node lib/smart_contract/opcode_list.js",
17
19
  "test:covenants": "node examples/covenants/advanced_covenant_demo.js",
@@ -19,13 +21,22 @@
19
21
  "test:basic": "node examples/basic/transaction-creation.js",
20
22
  "test:all": "npm test && npm run test:covenants && npm run test:scripts",
21
23
  "coverage": "nyc --reporter=text npm run test",
22
- "build-bsv": "NODE_OPTIONS=\"--openssl-legacy-provider\" webpack index.js --config webpack.config.js",
23
- "build-ecies": "NODE_OPTIONS=\"--openssl-legacy-provider\" webpack ecies/index.js --config webpack.subproject.config.js --output-library bsvEcies -o bsv-ecies.min.js",
24
- "build-message": "NODE_OPTIONS=\"--openssl-legacy-provider\" webpack message/index.js --config webpack.subproject.config.js --output-library bsvMessage -o bsv-message.min.js",
25
- "build-mnemonic": "NODE_OPTIONS=\"--openssl-legacy-provider\" webpack mnemonic/index.js --config webpack.subproject.config.js --output-library bsvMnemonic -o bsv-mnemonic.min.js",
26
- "build-bundle": "NODE_OPTIONS=\"--openssl-legacy-provider\" webpack bundle-entry.js --config webpack.bundle.config.js",
27
- "build": "npm run build-bsv && npm run build-ecies && npm run build-message && npm run build-mnemonic",
28
- "build-all": "npm run build && npm run build-bundle",
24
+ "build-bsv": "NODE_OPTIONS=\"--openssl-legacy-provider\" webpack index.js --config build/webpack.config.js",
25
+ "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
+ "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",
27
+ "build-mnemonic": "NODE_OPTIONS=\"--openssl-legacy-provider\" webpack mnemonic/index.js --config build/webpack.subproject.config.js --output-library bsvMnemonic -o bsv-mnemonic.min.js",
28
+ "build-shamir": "NODE_OPTIONS=\"--openssl-legacy-provider\" webpack shamir-entry.js --config build/webpack.subproject.config.js --output-library bsvShamir -o bsv-shamir.min.js",
29
+ "build-ltp": "NODE_OPTIONS=\"--openssl-legacy-provider\" webpack ltp-entry.js --config build/webpack.ltp.config.js",
30
+ "build-smartcontract": "NODE_OPTIONS=\"--openssl-legacy-provider\" webpack smartcontract-entry.js --config build/webpack.smartcontract.config.js",
31
+ "build-covenant": "NODE_OPTIONS=\"--openssl-legacy-provider\" webpack covenant-entry.js --config build/webpack.covenant.config.js",
32
+ "build-script-helper": "NODE_OPTIONS=\"--openssl-legacy-provider\" webpack script-helper-entry.js --config build/webpack.script-helper.config.js",
33
+ "build-security": "NODE_OPTIONS=\"--openssl-legacy-provider\" webpack security-entry.js --config build/webpack.security.config.js",
34
+ "build-bundle": "NODE_OPTIONS=\"--openssl-legacy-provider\" webpack bundle-entry.js --config build/webpack.bundle.config.js",
35
+ "build": "npm run build-bsv && npm run build-ecies && npm run build-message && npm run build-mnemonic && npm run build-shamir && npm run build-smartcontract",
36
+ "build-specialized": "npm run build-covenant && npm run build-script-helper && npm run build-security",
37
+ "build-all": "npm run build && npm run build-bundle && npm run build-specialized",
38
+ "test:browser": "echo 'Open tests/standalone-modules-test.html in browser for comprehensive testing'",
39
+ "test:bundle": "echo 'Open tests/bundle-completeness-test.html in browser to verify bundle completeness'",
29
40
  "demo": "npm run test:covenants",
30
41
  "demo:basic": "npm run test:basic",
31
42
  "demo:scripts": "npm run test:scripts",
@@ -43,13 +54,29 @@
43
54
  "ecies/",
44
55
  "message/",
45
56
  "mnemonic/",
57
+ "build/",
58
+ "tests/",
59
+ "*-entry.js",
46
60
  "bsv.min.js",
47
61
  "bsv.bundle.js",
48
62
  "bsv-ecies.min.js",
49
63
  "bsv-message.min.js",
50
64
  "bsv-mnemonic.min.js",
65
+ "bsv-shamir.min.js",
66
+ "bsv-gdaf.min.js",
67
+ "bsv-ltp.min.js",
68
+ "bsv-smartcontract.min.js",
69
+ "bsv-covenant.min.js",
70
+ "bsv-script-helper.min.js",
71
+ "bsv-security.min.js",
51
72
  "bsv.d.ts",
52
73
  "validation_test.js",
74
+ "test_shamir.js",
75
+ "shamir_demo.js",
76
+ "complete_ltp_demo.js",
77
+ "simple_demo.js",
78
+ "architecture_demo.js",
79
+ "test_standalone_shamir.html",
53
80
  "docs/",
54
81
  "examples/",
55
82
  "LICENSE",
@@ -59,22 +86,61 @@
59
86
  ],
60
87
  "keywords": [
61
88
  "bitcoin",
62
- "bitcoin-sv",
89
+ "bitcoin-sv",
63
90
  "bsv",
64
- "transaction",
65
- "address",
91
+ "legal-token-protocol",
92
+ "ltp",
93
+ "legal-tokens",
94
+ "primitives-only",
95
+ "legal-compliance",
96
+ "property-rights",
97
+ "obligations",
98
+ "attestations",
99
+ "gdaf",
100
+ "global-digital-attestation",
101
+ "w3c-credentials",
102
+ "verifiable-credentials",
103
+ "decentralized-identity",
104
+ "shamir-secret-sharing",
105
+ "threshold-cryptography",
66
106
  "cryptocurrency",
67
107
  "blockchain",
68
- "security",
69
- "hardened",
70
- "vulnerability-free",
71
- "drop-in-replacement",
108
+ "smart-contracts",
109
+ "defi",
72
110
  "covenant",
73
111
  "covenants",
112
+ "script-debugger",
113
+ "debug-tools",
114
+ "modular-loading",
115
+ "standalone-modules",
116
+ "security-hardened",
117
+ "elliptic-curve-fix",
118
+ "smartledger",
119
+ "transaction",
120
+ "address",
121
+ "signature",
122
+ "wallet",
123
+ "hd-wallet",
124
+ "mnemonic",
125
+ "ecies",
126
+ "encryption",
127
+ "message-signing",
74
128
  "pushtx",
75
129
  "pels",
76
130
  "bip143",
77
131
  "preimage",
132
+ "shamir-secret-sharing",
133
+ "threshold-cryptography",
134
+ "secret-splitting",
135
+ "global-digital-attestation",
136
+ "gdaf",
137
+ "verifiable-credentials",
138
+ "w3c-credentials",
139
+ "decentralized-identity",
140
+ "did-resolution",
141
+ "zero-knowledge-proofs",
142
+ "blockchain-anchoring",
143
+ "attestation-framework",
78
144
  "nchain",
79
145
  "custom-scripts",
80
146
  "multisig",
@@ -94,9 +160,14 @@
94
160
  "miner-simulator",
95
161
  "testing-tools",
96
162
  "development-framework",
97
- "ecies",
98
- "p2p",
99
- "payment",
163
+ "browser-compatible",
164
+ "nodejs-compatible",
165
+ "webpack-ready",
166
+ "cdn-ready",
167
+ "typescript-definitions",
168
+ "vulnerability-free",
169
+ "drop-in-replacement",
170
+ "performance-optimized",
100
171
  "bip21",
101
172
  "bip32",
102
173
  "bip37",
@@ -0,0 +1,49 @@
1
+ /**
2
+ * SmartLedger BSV Custom Script Helper - Standalone Module
3
+ *
4
+ * Simplified API for custom script development and signing
5
+ * Requires main BSV library to be loaded first.
6
+ *
7
+ * Usage:
8
+ * <script src="bsv.min.js"></script>
9
+ * <script src="bsv-script-helper.min.js"></script>
10
+ * <script>
11
+ * const sig = bsvScriptHelper.createSignature(tx, key, 0, script, sats);
12
+ * </script>
13
+ */
14
+
15
+ 'use strict'
16
+
17
+ // Verify BSV library is available
18
+ if (typeof bsv === 'undefined') {
19
+ throw new Error('CustomScriptHelper requires BSV library. Load bsv.min.js first.');
20
+ }
21
+
22
+ // Load CustomScriptHelper
23
+ const CustomScriptHelper = require('./lib/custom-script-helper.js');
24
+
25
+ // Browser compatibility
26
+ if (typeof window !== 'undefined') {
27
+ window.bsvScriptHelper = {
28
+ CustomScriptHelper: CustomScriptHelper,
29
+ createSignature: CustomScriptHelper.createSignature,
30
+ verifySignature: CustomScriptHelper.verifySignature,
31
+ createMultisigSignature: CustomScriptHelper.createMultisigSignature,
32
+ version: bsv.version || 'unknown'
33
+ };
34
+
35
+ // Also attach to main bsv object if available
36
+ if (typeof bsv !== 'undefined') {
37
+ bsv.CustomScriptHelper = CustomScriptHelper;
38
+ }
39
+
40
+ console.log('CustomScriptHelper standalone module loaded');
41
+ }
42
+
43
+ module.exports = {
44
+ CustomScriptHelper: CustomScriptHelper,
45
+ createSignature: CustomScriptHelper.createSignature,
46
+ verifySignature: CustomScriptHelper.verifySignature,
47
+ createMultisigSignature: CustomScriptHelper.createMultisigSignature,
48
+ version: bsv.version || 'unknown'
49
+ };
@@ -0,0 +1,70 @@
1
+ /**
2
+ * SmartLedger BSV Security Module - Standalone Module
3
+ *
4
+ * SmartLedger security enhancements and elliptic curve fixes
5
+ * Can be used standalone or with main BSV library.
6
+ *
7
+ * Usage:
8
+ * <script src="bsv-security.min.js"></script>
9
+ * <script>
10
+ * const verified = bsvSecurity.SmartVerify.verify(sig, hash, pubkey);
11
+ * </script>
12
+ */
13
+
14
+ 'use strict'
15
+
16
+ // Load security modules
17
+ const SmartVerify = require('./lib/crypto/smartledger_verify');
18
+ const EllipticFixed = require('./lib/crypto/elliptic-fixed');
19
+
20
+ // Browser compatibility
21
+ if (typeof window !== 'undefined') {
22
+ window.bsvSecurity = {
23
+ SmartVerify: SmartVerify,
24
+ EllipticFixed: EllipticFixed,
25
+ SmartLedger: {
26
+ version: 'v3.2.1',
27
+ hardenedBy: 'SmartLedger',
28
+ baseVersion: 'v1.5.6',
29
+ securityFeatures: [
30
+ 'canonical-signatures',
31
+ 'malleability-protection',
32
+ 'enhanced-validation',
33
+ 'elliptic-patches'
34
+ ],
35
+ SmartVerify: SmartVerify,
36
+ EllipticFixed: EllipticFixed
37
+ },
38
+ version: 'v3.2.1'
39
+ };
40
+
41
+ // Also attach to main bsv object if available
42
+ if (typeof bsv !== 'undefined') {
43
+ bsv.SmartVerify = SmartVerify;
44
+ bsv.EllipticFixed = EllipticFixed;
45
+ if (!bsv.SmartLedger) {
46
+ bsv.SmartLedger = window.bsvSecurity.SmartLedger;
47
+ }
48
+ }
49
+
50
+ console.log('SmartLedger Security standalone module loaded');
51
+ }
52
+
53
+ module.exports = {
54
+ SmartVerify: SmartVerify,
55
+ EllipticFixed: EllipticFixed,
56
+ SmartLedger: {
57
+ version: 'v3.2.1',
58
+ hardenedBy: 'SmartLedger',
59
+ baseVersion: 'v1.5.6',
60
+ securityFeatures: [
61
+ 'canonical-signatures',
62
+ 'malleability-protection',
63
+ 'enhanced-validation',
64
+ 'elliptic-patches'
65
+ ],
66
+ SmartVerify: SmartVerify,
67
+ EllipticFixed: EllipticFixed
68
+ },
69
+ version: 'v3.2.1'
70
+ };
@@ -0,0 +1,173 @@
1
+ 'use strict'
2
+
3
+ /**
4
+ * BSV Shamir Secret Sharing - Standalone Module
5
+ * Secure secret distribution using Shamir's Secret Sharing algorithm
6
+ *
7
+ * Usage:
8
+ * // Split a secret into shares
9
+ * var shares = bsvShamir.split('my secret', 3, 5) // 3-of-5 threshold
10
+ *
11
+ * // Reconstruct secret from shares
12
+ * var secret = bsvShamir.combine(shares.slice(0, 3))
13
+ *
14
+ * Features:
15
+ * - Cryptographically secure threshold secret sharing
16
+ * - Support for any threshold (k) and total shares (n) where k <= n
17
+ * - Handles arbitrary secret sizes through chunking
18
+ * - Share verification and integrity checking
19
+ * - Compatible with BSV cryptographic ecosystem
20
+ */
21
+
22
+ // Initialize dependencies for browser compatibility
23
+ var deps = {}
24
+ try {
25
+ deps.bnjs = require('bn.js')
26
+ deps.Buffer = (typeof Buffer !== 'undefined') ? Buffer : null
27
+ } catch (e) {
28
+ // Browser environment - dependencies should be available globally
29
+ if (typeof window !== 'undefined') {
30
+ deps.bnjs = window.BN || (window.bsv && window.bsv.deps && window.bsv.deps.bnjs)
31
+ deps.Buffer = window.Buffer || (window.bsv && window.bsv.deps && window.bsv.deps.Buffer)
32
+ }
33
+ }
34
+
35
+ // Ensure we have required dependencies
36
+ if (!deps.bnjs) {
37
+ throw new Error('BN.js dependency not found. Please include bn.js or bsv.min.js')
38
+ }
39
+
40
+ if (!deps.Buffer) {
41
+ // Provide minimal Buffer polyfill for basic operations
42
+ deps.Buffer = {
43
+ isBuffer: function(obj) { return obj && obj.constructor && obj.constructor.name === 'Buffer' },
44
+ from: function(data, encoding) {
45
+ if (typeof data === 'string') {
46
+ if (encoding === 'hex') {
47
+ return new Uint8Array(data.match(/.{2}/g).map(byte => parseInt(byte, 16)))
48
+ }
49
+ return new Uint8Array(Array.from(data).map(c => c.charCodeAt(0)))
50
+ }
51
+ return new Uint8Array(data)
52
+ },
53
+ concat: function(arrays) {
54
+ var totalLength = arrays.reduce((sum, arr) => sum + arr.length, 0)
55
+ var result = new Uint8Array(totalLength)
56
+ var offset = 0
57
+ for (var i = 0; i < arrays.length; i++) {
58
+ result.set(arrays[i], offset)
59
+ offset += arrays[i].length
60
+ }
61
+ return result
62
+ }
63
+ }
64
+ }
65
+
66
+ // Import the core Shamir implementation
67
+ var Shamir = require('./lib/crypto/shamir')
68
+
69
+ // Create standalone module interface
70
+ var bsvShamir = {
71
+ /**
72
+ * Split a secret into threshold shares
73
+ * @param {String|Buffer} secret - Secret to split
74
+ * @param {Number} threshold - Minimum shares needed to reconstruct
75
+ * @param {Number} shares - Total shares to generate
76
+ * @returns {Array} Array of share objects
77
+ */
78
+ split: function(secret, threshold, shares) {
79
+ return Shamir.split(secret, threshold, shares)
80
+ },
81
+
82
+ /**
83
+ * Combine shares to reconstruct secret
84
+ * @param {Array} shares - Array of share objects
85
+ * @returns {Buffer} Reconstructed secret
86
+ */
87
+ combine: function(shares) {
88
+ return Shamir.combine(shares)
89
+ },
90
+
91
+ /**
92
+ * Verify if a share is valid
93
+ * @param {Object} share - Share to verify
94
+ * @returns {Boolean} True if valid
95
+ */
96
+ verifyShare: function(share) {
97
+ return Shamir.verifyShare(share)
98
+ },
99
+
100
+ /**
101
+ * Generate test vectors for validation
102
+ * @returns {Object} Test data with secret, shares, and reconstruction
103
+ */
104
+ generateTestVectors: function() {
105
+ return Shamir.generateTestVectors()
106
+ },
107
+
108
+ /**
109
+ * Create a simple demo showing basic usage
110
+ * @returns {Object} Demo results
111
+ */
112
+ demo: function() {
113
+ console.log('=== BSV Shamir Secret Sharing Demo ===')
114
+
115
+ var originalSecret = 'Bitcoin SV is the original Bitcoin!'
116
+ var threshold = 3
117
+ var totalShares = 5
118
+
119
+ console.log('Original secret:', originalSecret)
120
+ console.log('Creating', totalShares, 'shares with threshold of', threshold)
121
+
122
+ // Split the secret
123
+ var shares = bsvShamir.split(originalSecret, threshold, totalShares)
124
+ console.log('Generated', shares.length, 'shares')
125
+
126
+ // Show first share structure (truncated for display)
127
+ var displayShare = JSON.parse(JSON.stringify(shares[0]))
128
+ if (displayShare.chunks && displayShare.chunks.length > 0) {
129
+ displayShare.chunks = displayShare.chunks.slice(0, 1) // Show only first chunk
130
+ displayShare.chunks[0].y = displayShare.chunks[0].y.substring(0, 20) + '...'
131
+ }
132
+ console.log('Sample share structure:', displayShare)
133
+
134
+ // Reconstruct with minimum shares
135
+ var minShares = shares.slice(0, threshold)
136
+ var reconstructed = bsvShamir.combine(minShares)
137
+ var reconstructedSecret = reconstructed.toString('utf8')
138
+
139
+ console.log('Reconstructed secret:', reconstructedSecret)
140
+ console.log('Reconstruction successful:', originalSecret === reconstructedSecret)
141
+
142
+ return {
143
+ original: originalSecret,
144
+ threshold: threshold,
145
+ totalShares: totalShares,
146
+ shares: shares,
147
+ reconstructed: reconstructedSecret,
148
+ success: originalSecret === reconstructedSecret
149
+ }
150
+ },
151
+
152
+ // Expose version and metadata
153
+ version: '3.2.2',
154
+ algorithm: 'Shamir Secret Sharing',
155
+ description: 'Threshold cryptography for secure secret distribution'
156
+ }
157
+
158
+ // Browser compatibility
159
+ if (typeof window !== 'undefined') {
160
+ window.bsvShamir = bsvShamir
161
+ }
162
+
163
+ // Node.js compatibility
164
+ if (typeof module !== 'undefined' && module.exports) {
165
+ module.exports = bsvShamir
166
+ }
167
+
168
+ // AMD compatibility
169
+ if (typeof define === 'function' && define.amd) {
170
+ define(function() {
171
+ return bsvShamir
172
+ })
173
+ }