@smartledger/bsv 5.1.0 → 5.3.0

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.
@@ -55,19 +55,19 @@ Three advanced modules totaling **~2.7MB** of functionality:
55
55
  - **Purpose**: Threshold cryptography for secure secret distribution
56
56
  - **Use Cases**: Backup keys, multi-party security, key recovery
57
57
  - **Features**: Split secrets into N shares, require M to reconstruct
58
- - **CDN**: `unpkg.com/@smartledger/bsv@5.1.0/bsv-shamir.min.js`
58
+ - **CDN**: `unpkg.com/@smartledger/bsv@5.3.0/bsv-shamir.min.js`
59
59
 
60
60
  #### **🌐 Global Digital Attestation Framework - GDAF (1184KB)**
61
61
  - **Purpose**: W3C Verifiable Credentials and decentralized identity
62
62
  - **Use Cases**: Identity verification, attestations, zero-knowledge proofs
63
63
  - **Features**: DID creation, credential issuance, selective disclosure
64
- - **CDN**: `unpkg.com/@smartledger/bsv@5.1.0/bsv-gdaf.min.js`
64
+ - **CDN**: `unpkg.com/@smartledger/bsv@5.3.0/bsv-gdaf.min.js`
65
65
 
66
66
  #### **⚖️ Legal Token Protocol - LTP (1184KB)**
67
67
  - **Purpose**: Legal compliance framework for tokenized assets
68
68
  - **Use Cases**: Property rights, obligations, compliant tokenization
69
69
  - **Features**: Legal primitives, compliance checking, attestation anchoring
70
- - **CDN**: `unpkg.com/@smartledger/bsv@5.1.0/bsv-ltp.min.js`
70
+ - **CDN**: `unpkg.com/@smartledger/bsv@5.3.0/bsv-ltp.min.js`
71
71
 
72
72
  ### **2. Incorrect File Sizes in Documentation**
73
73
 
@@ -81,18 +81,18 @@ Three advanced modules totaling **~2.7MB** of functionality:
81
81
 
82
82
  | Module | Size | Use Case | CDN Link |
83
83
  |--------|------|----------|----------|
84
- | **bsv.min.js** | 937KB | Core BSV + SmartContract | `unpkg.com/@smartledger/bsv@5.1.0/bsv.min.js` |
85
- | **bsv.bundle.js** | 937KB | Everything in one file | `unpkg.com/@smartledger/bsv@5.1.0/bsv.bundle.js` |
86
- | **bsv-smartcontract.min.js** | 937KB | Covenant development | `unpkg.com/@smartledger/bsv@5.1.0/bsv-smartcontract.min.js` |
87
- | **bsv-covenant.min.js** | 913KB | Covenant operations | `unpkg.com/@smartledger/bsv@5.1.0/bsv-covenant.min.js` |
88
- | **bsv-script-helper.min.js** | 26KB | Custom script tools | `unpkg.com/@smartledger/bsv@5.1.0/bsv-script-helper.min.js` |
89
- | **bsv-security.min.js** | 26KB | Security enhancements (opt-in helpers — see README › Security) | `unpkg.com/@smartledger/bsv@5.1.0/bsv-security.min.js` |
90
- | **bsv-ecies.min.js** | 71KB | Encryption | `unpkg.com/@smartledger/bsv@5.1.0/bsv-ecies.min.js` |
91
- | **bsv-message.min.js** | 26KB | Message signing | `unpkg.com/@smartledger/bsv@5.1.0/bsv-message.min.js` |
92
- | **bsv-mnemonic.min.js** | 681KB | HD wallets | `unpkg.com/@smartledger/bsv@5.1.0/bsv-mnemonic.min.js` |
93
- | **🆕 bsv-shamir.min.js** | 432KB | **Secret sharing** | `unpkg.com/@smartledger/bsv@5.1.0/bsv-shamir.min.js` |
94
- | **🆕 bsv-gdaf.min.js** | 1184KB | **Digital attestation** | `unpkg.com/@smartledger/bsv@5.1.0/bsv-gdaf.min.js` |
95
- | **🆕 bsv-ltp.min.js** | 1184KB | **Legal tokens** | `unpkg.com/@smartledger/bsv@5.1.0/bsv-ltp.min.js` |
84
+ | **bsv.min.js** | 937KB | Core BSV + SmartContract | `unpkg.com/@smartledger/bsv@5.3.0/bsv.min.js` |
85
+ | **bsv.bundle.js** | 937KB | Everything in one file | `unpkg.com/@smartledger/bsv@5.3.0/bsv.bundle.js` |
86
+ | **bsv-smartcontract.min.js** | 937KB | Covenant development | `unpkg.com/@smartledger/bsv@5.3.0/bsv-smartcontract.min.js` |
87
+ | **bsv-covenant.min.js** | 913KB | Covenant operations | `unpkg.com/@smartledger/bsv@5.3.0/bsv-covenant.min.js` |
88
+ | **bsv-script-helper.min.js** | 26KB | Custom script tools | `unpkg.com/@smartledger/bsv@5.3.0/bsv-script-helper.min.js` |
89
+ | **bsv-security.min.js** | 26KB | Security enhancements (opt-in helpers — see README › Security) | `unpkg.com/@smartledger/bsv@5.3.0/bsv-security.min.js` |
90
+ | **bsv-ecies.min.js** | 71KB | Encryption | `unpkg.com/@smartledger/bsv@5.3.0/bsv-ecies.min.js` |
91
+ | **bsv-message.min.js** | 26KB | Message signing | `unpkg.com/@smartledger/bsv@5.3.0/bsv-message.min.js` |
92
+ | **bsv-mnemonic.min.js** | 681KB | HD wallets | `unpkg.com/@smartledger/bsv@5.3.0/bsv-mnemonic.min.js` |
93
+ | **🆕 bsv-shamir.min.js** | 432KB | **Secret sharing** | `unpkg.com/@smartledger/bsv@5.3.0/bsv-shamir.min.js` |
94
+ | **🆕 bsv-gdaf.min.js** | 1184KB | **Digital attestation** | `unpkg.com/@smartledger/bsv@5.3.0/bsv-gdaf.min.js` |
95
+ | **🆕 bsv-ltp.min.js** | 1184KB | **Legal tokens** | `unpkg.com/@smartledger/bsv@5.3.0/bsv-ltp.min.js` |
96
96
 
97
97
  ## 🎯 **Updated Usage Examples**
98
98
 
@@ -100,22 +100,22 @@ Three advanced modules totaling **~2.7MB** of functionality:
100
100
 
101
101
  #### **1. Basic Development (~963KB)**
102
102
  ```html
103
- <script src="https://unpkg.com/@smartledger/bsv@5.1.0/bsv.min.js"></script>
104
- <script src="https://unpkg.com/@smartledger/bsv@5.1.0/bsv-script-helper.min.js"></script>
103
+ <script src="https://unpkg.com/@smartledger/bsv@5.3.0/bsv.min.js"></script>
104
+ <script src="https://unpkg.com/@smartledger/bsv@5.3.0/bsv-script-helper.min.js"></script>
105
105
  ```
106
106
 
107
107
  #### **2. Smart Contract Development (~2.7MB — each bundle re-embeds core BSV)**
108
108
  ```html
109
- <script src="https://unpkg.com/@smartledger/bsv@5.1.0/bsv.min.js"></script>
110
- <script src="https://unpkg.com/@smartledger/bsv@5.1.0/bsv-covenant.min.js"></script>
111
- <script src="https://unpkg.com/@smartledger/bsv@5.1.0/bsv-smartcontract.min.js"></script>
109
+ <script src="https://unpkg.com/@smartledger/bsv@5.3.0/bsv.min.js"></script>
110
+ <script src="https://unpkg.com/@smartledger/bsv@5.3.0/bsv-covenant.min.js"></script>
111
+ <script src="https://unpkg.com/@smartledger/bsv@5.3.0/bsv-smartcontract.min.js"></script>
112
112
  ```
113
113
 
114
114
  #### **3. 🆕 Legal & Compliance Development (~3.2MB — each bundle re-embeds core BSV)**
115
115
  ```html
116
- <script src="https://unpkg.com/@smartledger/bsv@5.1.0/bsv.min.js"></script>
117
- <script src="https://unpkg.com/@smartledger/bsv@5.1.0/bsv-ltp.min.js"></script>
118
- <script src="https://unpkg.com/@smartledger/bsv@5.1.0/bsv-gdaf.min.js"></script>
116
+ <script src="https://unpkg.com/@smartledger/bsv@5.3.0/bsv.min.js"></script>
117
+ <script src="https://unpkg.com/@smartledger/bsv@5.3.0/bsv-ltp.min.js"></script>
118
+ <script src="https://unpkg.com/@smartledger/bsv@5.3.0/bsv-gdaf.min.js"></script>
119
119
  <script>
120
120
  // Legal Token Protocol
121
121
  const legalToken = bsv.createLegalToken({
@@ -132,9 +132,9 @@ Three advanced modules totaling **~2.7MB** of functionality:
132
132
 
133
133
  #### **4. 🆕 Security & Cryptography (~1.4MB)**
134
134
  ```html
135
- <script src="https://unpkg.com/@smartledger/bsv@5.1.0/bsv.min.js"></script>
136
- <script src="https://unpkg.com/@smartledger/bsv@5.1.0/bsv-security.min.js"></script>
137
- <script src="https://unpkg.com/@smartledger/bsv@5.1.0/bsv-shamir.min.js"></script>
135
+ <script src="https://unpkg.com/@smartledger/bsv@5.3.0/bsv.min.js"></script>
136
+ <script src="https://unpkg.com/@smartledger/bsv@5.3.0/bsv-security.min.js"></script>
137
+ <script src="https://unpkg.com/@smartledger/bsv@5.3.0/bsv-shamir.min.js"></script>
138
138
  <script>
139
139
  // Shamir Secret Sharing
140
140
  const shares = bsv.splitSecret('my_secret_key', 5, 3); // 5 shares, 3 needed
@@ -146,7 +146,7 @@ Three advanced modules totaling **~2.7MB** of functionality:
146
146
 
147
147
  #### **5. Everything Bundle (937KB)**
148
148
  ```html
149
- <script src="https://unpkg.com/@smartledger/bsv@5.1.0/bsv.bundle.js"></script>
149
+ <script src="https://unpkg.com/@smartledger/bsv@5.3.0/bsv.bundle.js"></script>
150
150
  <script>
151
151
  // Everything available immediately
152
152
  const shares = bsv.splitSecret('secret', 5, 3);
@@ -722,7 +722,7 @@ interface UTXO {
722
722
  <html>
723
723
  <head>
724
724
  <title>UTXO Manager Demo</title>
725
- <script src="https://cdn.jsdelivr.net/npm/@smartledger/bsv@5.1.0/bsv.min.js"></script>
725
+ <script src="https://cdn.jsdelivr.net/npm/@smartledger/bsv@5.3.0/bsv.min.js"></script>
726
726
  </head>
727
727
  <body>
728
728
  <script>
@@ -48,7 +48,7 @@ const tx: Transaction = new Transaction();
48
48
  #### **Core Library Only (937KB)**
49
49
  For basic Bitcoin SV operations:
50
50
  ```html
51
- <script src="https://unpkg.com/@smartledger/bsv@5.1.0/bsv.min.js"></script>
51
+ <script src="https://unpkg.com/@smartledger/bsv@5.3.0/bsv.min.js"></script>
52
52
  <script>
53
53
  const privateKey = new bsv.PrivateKey();
54
54
  const address = privateKey.toAddress();
@@ -58,7 +58,7 @@ For basic Bitcoin SV operations:
58
58
  #### **Complete Bundle (937KB)**
59
59
  Everything in one file:
60
60
  ```html
61
- <script src="https://unpkg.com/@smartledger/bsv@5.1.0/bsv.bundle.js"></script>
61
+ <script src="https://unpkg.com/@smartledger/bsv@5.3.0/bsv.bundle.js"></script>
62
62
  <script>
63
63
  // All features available immediately
64
64
  const shares = bsv.splitSecret('secret', 5, 3);
@@ -71,9 +71,9 @@ Everything in one file:
71
71
 
72
72
  #### **Smart Contract Development (~2.7MB total — each bundle is self-contained and re-embeds core BSV)**
73
73
  ```html
74
- <script src="https://unpkg.com/@smartledger/bsv@5.1.0/bsv.min.js"></script>
75
- <script src="https://unpkg.com/@smartledger/bsv@5.1.0/bsv-covenant.min.js"></script>
76
- <script src="https://unpkg.com/@smartledger/bsv@5.1.0/bsv-smartcontract.min.js"></script>
74
+ <script src="https://unpkg.com/@smartledger/bsv@5.3.0/bsv.min.js"></script>
75
+ <script src="https://unpkg.com/@smartledger/bsv@5.3.0/bsv-covenant.min.js"></script>
76
+ <script src="https://unpkg.com/@smartledger/bsv@5.3.0/bsv-smartcontract.min.js"></script>
77
77
  <script>
78
78
  const covenant = bsv.SmartContract.createCovenantBuilder()
79
79
  .extractField('amount').push(50000).greaterThanOrEqual().build();
@@ -82,9 +82,9 @@ Everything in one file:
82
82
 
83
83
  #### **Legal & Identity Development (~3.2MB total — each bundle is self-contained and re-embeds core BSV)**
84
84
  ```html
85
- <script src="https://unpkg.com/@smartledger/bsv@5.1.0/bsv.min.js"></script>
86
- <script src="https://unpkg.com/@smartledger/bsv@5.1.0/bsv-ltp.min.js"></script>
87
- <script src="https://unpkg.com/@smartledger/bsv@5.1.0/bsv-gdaf.min.js"></script>
85
+ <script src="https://unpkg.com/@smartledger/bsv@5.3.0/bsv.min.js"></script>
86
+ <script src="https://unpkg.com/@smartledger/bsv@5.3.0/bsv-ltp.min.js"></script>
87
+ <script src="https://unpkg.com/@smartledger/bsv@5.3.0/bsv-gdaf.min.js"></script>
88
88
  <script>
89
89
  // Legal Token Protocol
90
90
  const propertyToken = bsv.createPropertyToken({
@@ -98,9 +98,9 @@ Everything in one file:
98
98
 
99
99
  #### **Security & Cryptography (~1.4MB total — each bundle is self-contained and re-embeds core BSV)**
100
100
  ```html
101
- <script src="https://unpkg.com/@smartledger/bsv@5.1.0/bsv.min.js"></script>
102
- <script src="https://unpkg.com/@smartledger/bsv@5.1.0/bsv-security.min.js"></script>
103
- <script src="https://unpkg.com/@smartledger/bsv@5.1.0/bsv-shamir.min.js"></script>
101
+ <script src="https://unpkg.com/@smartledger/bsv@5.3.0/bsv.min.js"></script>
102
+ <script src="https://unpkg.com/@smartledger/bsv@5.3.0/bsv-security.min.js"></script>
103
+ <script src="https://unpkg.com/@smartledger/bsv@5.3.0/bsv-shamir.min.js"></script>
104
104
  <script>
105
105
  // Threshold Cryptography
106
106
  const shares = bsv.splitSecret('my_secret_key', 5, 3);
@@ -114,18 +114,18 @@ Everything in one file:
114
114
 
115
115
  | Module | Size | Purpose | CDN Link |
116
116
  |--------|------|---------|----------|
117
- | **bsv.min.js** | 937KB | Core BSV + SmartContract | `unpkg.com/@smartledger/bsv@5.1.0/bsv.min.js` |
118
- | **bsv.bundle.js** | 937KB | Everything in one file | `unpkg.com/@smartledger/bsv@5.1.0/bsv.bundle.js` |
119
- | **bsv-smartcontract.min.js** | 937KB | Complete covenant framework | `unpkg.com/@smartledger/bsv@5.1.0/bsv-smartcontract.min.js` |
120
- | **bsv-ltp.min.js** | 1184KB | **Legal Token Protocol** | `unpkg.com/@smartledger/bsv@5.1.0/bsv-ltp.min.js` |
121
- | **bsv-gdaf.min.js** | 1184KB | **Digital Identity & Attestation** | `unpkg.com/@smartledger/bsv@5.1.0/bsv-gdaf.min.js` |
122
- | **bsv-shamir.min.js** | 432KB | **Threshold Cryptography** | `unpkg.com/@smartledger/bsv@5.1.0/bsv-shamir.min.js` |
123
- | **bsv-security.min.js** | 26KB | Security enhancements (opt-in helpers — see README › Security) | `unpkg.com/@smartledger/bsv@5.1.0/bsv-security.min.js` |
124
- | **bsv-mnemonic.min.js** | 681KB | HD wallets | `unpkg.com/@smartledger/bsv@5.1.0/bsv-mnemonic.min.js` |
125
- | **bsv-ecies.min.js** | 71KB | Encryption | `unpkg.com/@smartledger/bsv@5.1.0/bsv-ecies.min.js` |
126
- | **bsv-covenant.min.js** | 913KB | Covenant operations | `unpkg.com/@smartledger/bsv@5.1.0/bsv-covenant.min.js` |
127
- | **bsv-script-helper.min.js** | 26KB | Custom script tools | `unpkg.com/@smartledger/bsv@5.1.0/bsv-script-helper.min.js` |
128
- | **bsv-message.min.js** | 26KB | Message signing | `unpkg.com/@smartledger/bsv@5.1.0/bsv-message.min.js` |
117
+ | **bsv.min.js** | 937KB | Core BSV + SmartContract | `unpkg.com/@smartledger/bsv@5.3.0/bsv.min.js` |
118
+ | **bsv.bundle.js** | 937KB | Everything in one file | `unpkg.com/@smartledger/bsv@5.3.0/bsv.bundle.js` |
119
+ | **bsv-smartcontract.min.js** | 937KB | Complete covenant framework | `unpkg.com/@smartledger/bsv@5.3.0/bsv-smartcontract.min.js` |
120
+ | **bsv-ltp.min.js** | 1184KB | **Legal Token Protocol** | `unpkg.com/@smartledger/bsv@5.3.0/bsv-ltp.min.js` |
121
+ | **bsv-gdaf.min.js** | 1184KB | **Digital Identity & Attestation** | `unpkg.com/@smartledger/bsv@5.3.0/bsv-gdaf.min.js` |
122
+ | **bsv-shamir.min.js** | 432KB | **Threshold Cryptography** | `unpkg.com/@smartledger/bsv@5.3.0/bsv-shamir.min.js` |
123
+ | **bsv-security.min.js** | 26KB | Security enhancements (opt-in helpers — see README › Security) | `unpkg.com/@smartledger/bsv@5.3.0/bsv-security.min.js` |
124
+ | **bsv-mnemonic.min.js** | 681KB | HD wallets | `unpkg.com/@smartledger/bsv@5.3.0/bsv-mnemonic.min.js` |
125
+ | **bsv-ecies.min.js** | 71KB | Encryption | `unpkg.com/@smartledger/bsv@5.3.0/bsv-ecies.min.js` |
126
+ | **bsv-covenant.min.js** | 913KB | Covenant operations | `unpkg.com/@smartledger/bsv@5.3.0/bsv-covenant.min.js` |
127
+ | **bsv-script-helper.min.js** | 26KB | Custom script tools | `unpkg.com/@smartledger/bsv@5.3.0/bsv-script-helper.min.js` |
128
+ | **bsv-message.min.js** | 26KB | Message signing | `unpkg.com/@smartledger/bsv@5.3.0/bsv-message.min.js` |
129
129
 
130
130
  ## ⚙️ **Development Environment Setup**
131
131
 
@@ -14,10 +14,10 @@ npm install @smartledger/bsv
14
14
  ### Browser CDN (Instant)
15
15
  ```html
16
16
  <!-- Core library (937KB) -->
17
- <script src="https://unpkg.com/@smartledger/bsv@5.1.0/bsv.min.js"></script>
17
+ <script src="https://unpkg.com/@smartledger/bsv@5.3.0/bsv.min.js"></script>
18
18
 
19
19
  <!-- Everything included (937KB) -->
20
- <script src="https://unpkg.com/@smartledger/bsv@5.1.0/bsv.bundle.js"></script>
20
+ <script src="https://unpkg.com/@smartledger/bsv@5.3.0/bsv.bundle.js"></script>
21
21
  ```
22
22
 
23
23
  ## 💰 **Your First Transaction (60 seconds)**
@@ -127,19 +127,19 @@ SmartLedger-BSV offers 12 different loading options - use only what you need:
127
127
 
128
128
  ```html
129
129
  <!-- Core BSV only (937KB) -->
130
- <script src="https://unpkg.com/@smartledger/bsv@5.1.0/bsv.min.js"></script>
130
+ <script src="https://unpkg.com/@smartledger/bsv@5.3.0/bsv.min.js"></script>
131
131
 
132
132
  <!-- Smart contracts (937KB) -->
133
- <script src="https://unpkg.com/@smartledger/bsv@5.1.0/bsv-smartcontract.min.js"></script>
133
+ <script src="https://unpkg.com/@smartledger/bsv@5.3.0/bsv-smartcontract.min.js"></script>
134
134
 
135
135
  <!-- Legal tokens (1.16MB) -->
136
- <script src="https://unpkg.com/@smartledger/bsv@5.1.0/bsv-ltp.min.js"></script>
136
+ <script src="https://unpkg.com/@smartledger/bsv@5.3.0/bsv-ltp.min.js"></script>
137
137
 
138
138
  <!-- Digital identity (1.16MB) -->
139
- <script src="https://unpkg.com/@smartledger/bsv@5.1.0/bsv-gdaf.min.js"></script>
139
+ <script src="https://unpkg.com/@smartledger/bsv@5.3.0/bsv-gdaf.min.js"></script>
140
140
 
141
141
  <!-- Everything (937KB) -->
142
- <script src="https://unpkg.com/@smartledger/bsv@5.1.0/bsv.bundle.js"></script>
142
+ <script src="https://unpkg.com/@smartledger/bsv@5.3.0/bsv.bundle.js"></script>
143
143
  ```
144
144
 
145
145
  ## ⚡ **Key Advantages**
@@ -159,17 +159,17 @@ const recovered = bsv.reconstructSecret([shares[0], shares[2], shares[4]]);
159
159
  ### **New Modular Options**
160
160
  ```html
161
161
  <!-- Core compatibility (same size as bsv@1.5.6) -->
162
- <script src="https://unpkg.com/@smartledger/bsv@5.1.0/bsv.min.js"></script>
162
+ <script src="https://unpkg.com/@smartledger/bsv@5.3.0/bsv.min.js"></script>
163
163
 
164
164
  <!-- Add smart contracts when ready -->
165
- <script src="https://unpkg.com/@smartledger/bsv@5.1.0/bsv-smartcontract.min.js"></script>
165
+ <script src="https://unpkg.com/@smartledger/bsv@5.3.0/bsv-smartcontract.min.js"></script>
166
166
 
167
167
  <!-- Add advanced features as needed -->
168
- <script src="https://unpkg.com/@smartledger/bsv@5.1.0/bsv-ltp.min.js"></script>
169
- <script src="https://unpkg.com/@smartledger/bsv@5.1.0/bsv-gdaf.min.js"></script>
168
+ <script src="https://unpkg.com/@smartledger/bsv@5.3.0/bsv-ltp.min.js"></script>
169
+ <script src="https://unpkg.com/@smartledger/bsv@5.3.0/bsv-gdaf.min.js"></script>
170
170
 
171
171
  <!-- Everything in one file -->
172
- <script src="https://unpkg.com/@smartledger/bsv@5.1.0/bsv.bundle.js"></script>
172
+ <script src="https://unpkg.com/@smartledger/bsv@5.3.0/bsv.bundle.js"></script>
173
173
  ```
174
174
 
175
175
  ## 🔍 **Testing Your Migration**
package/index.js CHANGED
@@ -20,12 +20,10 @@ if (typeof window === 'undefined') {
20
20
  // Node — hard require; failure means broken install.
21
21
  bsv.deps.bnjs = require('bn.js')
22
22
  bsv.deps.bs58 = require('bs58')
23
- bsv.deps.elliptic = require('elliptic')
24
23
  } else {
25
24
  // Browser — bundler-resolved; tolerate absence individually.
26
25
  try { bsv.deps.bnjs = require('bn.js') } catch (e) { /* polyfilled by bundler */ }
27
26
  try { bsv.deps.bs58 = require('bs58') } catch (e) { /* polyfilled by bundler */ }
28
- try { bsv.deps.elliptic = require('elliptic') } catch (e) { /* polyfilled by bundler */ }
29
27
  }
30
28
 
31
29
  // module information
@@ -1,67 +1,103 @@
1
1
  'use strict'
2
2
 
3
3
  /**
4
- * SmartLedger Elliptic Security Wrapper
4
+ * SmartLedger Elliptic Security Wrapper (@noble-backed)
5
5
  *
6
- * Wraps the elliptic secp256k1 context with:
7
- * - verify: strict rejection of malformed / out-of-range (r, s) before the
8
- * underlying verify runs.
9
- * - sign: low-S canonical signatures via elliptic's own `canonical` option,
10
- * which also keeps `recoveryParam` consistent (a manual s-flip does not).
6
+ * A small elliptic-compatible secp256k1 context, exposing the hardened
7
+ * sign/verify/recover surface used by `bsv.EllipticFixed`, now backed by the
8
+ * audited @noble/curves instead of the `elliptic` package:
9
+ * - sign: low-S canonical signatures with a consistent recoveryParam
10
+ * (@noble's signer flips the recovery bit together with s).
11
+ * - verify: strict rejection of malformed / out-of-range (r, s); returns
12
+ * false (never throws) on garbage input.
13
+ *
14
+ * Signature objects expose `r`/`s` as bn.js BNs and `recoveryParam` as a number,
15
+ * matching the previous elliptic-derived shape.
11
16
  */
12
17
 
13
- const { ec: EC } = require('elliptic')
14
- const ec = new EC('secp256k1')
18
+ var BN = require('./bn')
19
+ var { secp256k1 } = require('@noble/curves/secp256k1.js')
15
20
 
16
- // Store original methods.
17
- const origVerify = ec.verify.bind(ec)
18
- const origSign = ec.sign.bind(ec)
21
+ var NoblePoint = secp256k1.Point
22
+ var N_BIG = NoblePoint.Fn.ORDER
19
23
 
20
- /**
21
- * Hardened verify: reject malformed or out-of-range signatures up front.
22
- * (elliptic already range-checks internally; this fails fast and never
23
- * throws on garbage input, returning false instead.)
24
- */
25
- ec.verify = function (msg, sig, key, enc, opts) {
26
- if (!sig || typeof sig !== 'object') {
27
- return false
28
- }
24
+ function bigToBN (big) {
25
+ var h = big.toString(16)
26
+ if (h.length % 2) h = '0' + h
27
+ return new BN(h, 16)
28
+ }
29
29
 
30
- const r = sig.r
31
- const s = sig.s
30
+ // Normalize a message (hex string or Buffer, a 32-byte hash) to Uint8Array.
31
+ function toMsg (msg) {
32
+ if (Buffer.isBuffer(msg)) return Uint8Array.from(msg)
33
+ if (msg instanceof Uint8Array) return msg
34
+ return Uint8Array.from(Buffer.from(msg, 'hex'))
35
+ }
32
36
 
33
- // r and s must be BN-like with a usable comparison.
34
- if (!r || !s || typeof r.cmp !== 'function' || typeof s.cmp !== 'function') {
35
- return false
36
- }
37
+ // Public-point wrapper exposing the `.eq()` the consumers use.
38
+ function PubPoint (noblePt) {
39
+ this._p = noblePt
40
+ }
41
+ PubPoint.prototype.eq = function (other) {
42
+ var o = other && other._p ? other._p : other
43
+ return this._p.equals(o)
44
+ }
37
45
 
38
- // Reject r or s outside [1, n-1].
39
- if (r.isZero() || s.isZero()) {
40
- return false
41
- }
42
- if (r.cmp(this.curve.n) >= 0 || s.cmp(this.curve.n) >= 0) {
43
- return false
44
- }
46
+ var ec = {
47
+ curve: { n: bigToBN(N_BIG) },
45
48
 
46
- return origVerify(msg, sig, key, enc, opts)
47
- }
49
+ keyFromPrivate: function (priv, enc) {
50
+ var pb
51
+ if (Buffer.isBuffer(priv)) pb = priv
52
+ else if (priv instanceof Uint8Array) pb = Buffer.from(priv)
53
+ else pb = Buffer.from(priv, enc || 'hex')
54
+ var privBytes = Uint8Array.from(pb)
55
+ return {
56
+ _priv: privBytes,
57
+ getPublic: function () {
58
+ return new PubPoint(NoblePoint.fromBytes(secp256k1.getPublicKey(privBytes, true)))
59
+ }
60
+ }
61
+ },
48
62
 
49
- /**
50
- * Hardened sign: always produce low-S canonical signatures.
51
- *
52
- * We delegate canonicalization to elliptic (`{ canonical: true }`) rather than
53
- * flipping s after the fact, because elliptic also flips `recoveryParam` when
54
- * it negates s. A manual flip leaves recoveryParam pointing at the wrong
55
- * candidate key, silently breaking public-key recovery.
56
- */
57
- ec.sign = function (msg, key, enc, options) {
58
- // Mirror elliptic's own argument normalization: sign(msg, key, options).
59
- if (typeof enc !== 'string') {
60
- options = enc
61
- enc = undefined
63
+ // sign(msg, key) — bitcoin signs the digest directly (prehash:false).
64
+ sign: function (msg, key) {
65
+ var recovered = secp256k1.sign(toMsg(msg), key._priv, { lowS: true, prehash: false, format: 'recovered' })
66
+ var recid = recovered[0]
67
+ var r = bigToBN(BigInt('0x' + Buffer.from(recovered.subarray(1, 33)).toString('hex')))
68
+ var s = bigToBN(BigInt('0x' + Buffer.from(recovered.subarray(33, 65)).toString('hex')))
69
+ return { r: r, s: s, recoveryParam: recid }
70
+ },
71
+
72
+ verify: function (msg, sig, key) {
73
+ try {
74
+ if (!sig || typeof sig !== 'object') return false
75
+ var r = sig.r
76
+ var s = sig.s
77
+ if (!r || !s || typeof r.cmp !== 'function' || typeof s.cmp !== 'function') return false
78
+ if (r.isZero() || s.isZero()) return false
79
+ var n = ec.curve.n
80
+ if (r.cmp(n) >= 0 || s.cmp(n) >= 0) return false
81
+
82
+ var compact = Buffer.concat([r.toBuffer({ size: 32 }), s.toBuffer({ size: 32 })])
83
+ var pubBytes = key._priv
84
+ ? secp256k1.getPublicKey(key._priv, true)
85
+ : (key._p ? key._p.toBytes(true) : key)
86
+ // lowS:false to match the previous behaviour (verify accepts any in-range s).
87
+ return secp256k1.verify(Uint8Array.from(compact), toMsg(msg), Uint8Array.from(pubBytes), { lowS: false, prehash: false })
88
+ } catch (e) {
89
+ return false
90
+ }
91
+ },
92
+
93
+ recoverPubKey: function (msg, sig, recoveryParam) {
94
+ var compact = Buffer.concat([
95
+ sig.r.toBuffer({ size: 32 }),
96
+ sig.s.toBuffer({ size: 32 })
97
+ ])
98
+ var signature = secp256k1.Signature.fromBytes(Uint8Array.from(compact), 'compact').addRecoveryBit(recoveryParam)
99
+ return new PubPoint(signature.recoverPublicKey(toMsg(msg)))
62
100
  }
63
- options = Object.assign({}, options, { canonical: true })
64
- return origSign(msg, key, enc, options)
65
101
  }
66
102
 
67
103
  module.exports = ec