@smartledger/bsv 7.0.0 → 7.0.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.
@@ -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@7.0.0/bsv-shamir.min.js`
58
+ - **CDN**: `unpkg.com/@smartledger/bsv@7.0.2/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@7.0.0/bsv-gdaf.min.js`
64
+ - **CDN**: `unpkg.com/@smartledger/bsv@7.0.2/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@7.0.0/bsv-ltp.min.js`
70
+ - **CDN**: `unpkg.com/@smartledger/bsv@7.0.2/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@7.0.0/bsv.min.js` |
85
- | **bsv.bundle.js** | 937KB | Everything in one file | `unpkg.com/@smartledger/bsv@7.0.0/bsv.bundle.js` |
86
- | **bsv-smartcontract.min.js** | 937KB | Covenant development | `unpkg.com/@smartledger/bsv@7.0.0/bsv-smartcontract.min.js` |
87
- | **bsv-covenant.min.js** | 913KB | Covenant operations | `unpkg.com/@smartledger/bsv@7.0.0/bsv-covenant.min.js` |
88
- | **bsv-script-helper.min.js** | 26KB | Custom script tools | `unpkg.com/@smartledger/bsv@7.0.0/bsv-script-helper.min.js` |
89
- | **bsv-security.min.js** | 26KB | Security enhancements (opt-in helpers — see README › Security) | `unpkg.com/@smartledger/bsv@7.0.0/bsv-security.min.js` |
90
- | **bsv-ecies.min.js** | 71KB | Encryption | `unpkg.com/@smartledger/bsv@7.0.0/bsv-ecies.min.js` |
91
- | **bsv-message.min.js** | 26KB | Message signing | `unpkg.com/@smartledger/bsv@7.0.0/bsv-message.min.js` |
92
- | **bsv-mnemonic.min.js** | 681KB | HD wallets | `unpkg.com/@smartledger/bsv@7.0.0/bsv-mnemonic.min.js` |
93
- | **🆕 bsv-shamir.min.js** | 432KB | **Secret sharing** | `unpkg.com/@smartledger/bsv@7.0.0/bsv-shamir.min.js` |
94
- | **🆕 bsv-gdaf.min.js** | 1184KB | **Digital attestation** | `unpkg.com/@smartledger/bsv@7.0.0/bsv-gdaf.min.js` |
95
- | **🆕 bsv-ltp.min.js** | 1184KB | **Legal tokens** | `unpkg.com/@smartledger/bsv@7.0.0/bsv-ltp.min.js` |
84
+ | **bsv.min.js** | 937KB | Core BSV + SmartContract | `unpkg.com/@smartledger/bsv@7.0.2/bsv.min.js` |
85
+ | **bsv.bundle.js** | 937KB | Everything in one file | `unpkg.com/@smartledger/bsv@7.0.2/bsv.bundle.js` |
86
+ | **bsv-smartcontract.min.js** | 937KB | Covenant development | `unpkg.com/@smartledger/bsv@7.0.2/bsv-smartcontract.min.js` |
87
+ | **bsv-covenant.min.js** | 913KB | Covenant operations | `unpkg.com/@smartledger/bsv@7.0.2/bsv-covenant.min.js` |
88
+ | **bsv-script-helper.min.js** | 26KB | Custom script tools | `unpkg.com/@smartledger/bsv@7.0.2/bsv-script-helper.min.js` |
89
+ | **bsv-security.min.js** | 26KB | Security enhancements (opt-in helpers — see README › Security) | `unpkg.com/@smartledger/bsv@7.0.2/bsv-security.min.js` |
90
+ | **bsv-ecies.min.js** | 71KB | Encryption | `unpkg.com/@smartledger/bsv@7.0.2/bsv-ecies.min.js` |
91
+ | **bsv-message.min.js** | 26KB | Message signing | `unpkg.com/@smartledger/bsv@7.0.2/bsv-message.min.js` |
92
+ | **bsv-mnemonic.min.js** | 681KB | HD wallets | `unpkg.com/@smartledger/bsv@7.0.2/bsv-mnemonic.min.js` |
93
+ | **🆕 bsv-shamir.min.js** | 432KB | **Secret sharing** | `unpkg.com/@smartledger/bsv@7.0.2/bsv-shamir.min.js` |
94
+ | **🆕 bsv-gdaf.min.js** | 1184KB | **Digital attestation** | `unpkg.com/@smartledger/bsv@7.0.2/bsv-gdaf.min.js` |
95
+ | **🆕 bsv-ltp.min.js** | 1184KB | **Legal tokens** | `unpkg.com/@smartledger/bsv@7.0.2/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@7.0.0/bsv.min.js"></script>
104
- <script src="https://unpkg.com/@smartledger/bsv@7.0.0/bsv-script-helper.min.js"></script>
103
+ <script src="https://unpkg.com/@smartledger/bsv@7.0.2/bsv.min.js"></script>
104
+ <script src="https://unpkg.com/@smartledger/bsv@7.0.2/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@7.0.0/bsv.min.js"></script>
110
- <script src="https://unpkg.com/@smartledger/bsv@7.0.0/bsv-covenant.min.js"></script>
111
- <script src="https://unpkg.com/@smartledger/bsv@7.0.0/bsv-smartcontract.min.js"></script>
109
+ <script src="https://unpkg.com/@smartledger/bsv@7.0.2/bsv.min.js"></script>
110
+ <script src="https://unpkg.com/@smartledger/bsv@7.0.2/bsv-covenant.min.js"></script>
111
+ <script src="https://unpkg.com/@smartledger/bsv@7.0.2/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@7.0.0/bsv.min.js"></script>
117
- <script src="https://unpkg.com/@smartledger/bsv@7.0.0/bsv-ltp.min.js"></script>
118
- <script src="https://unpkg.com/@smartledger/bsv@7.0.0/bsv-gdaf.min.js"></script>
116
+ <script src="https://unpkg.com/@smartledger/bsv@7.0.2/bsv.min.js"></script>
117
+ <script src="https://unpkg.com/@smartledger/bsv@7.0.2/bsv-ltp.min.js"></script>
118
+ <script src="https://unpkg.com/@smartledger/bsv@7.0.2/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@7.0.0/bsv.min.js"></script>
136
- <script src="https://unpkg.com/@smartledger/bsv@7.0.0/bsv-security.min.js"></script>
137
- <script src="https://unpkg.com/@smartledger/bsv@7.0.0/bsv-shamir.min.js"></script>
135
+ <script src="https://unpkg.com/@smartledger/bsv@7.0.2/bsv.min.js"></script>
136
+ <script src="https://unpkg.com/@smartledger/bsv@7.0.2/bsv-security.min.js"></script>
137
+ <script src="https://unpkg.com/@smartledger/bsv@7.0.2/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@7.0.0/bsv.bundle.js"></script>
149
+ <script src="https://unpkg.com/@smartledger/bsv@7.0.2/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@7.0.0/bsv.min.js"></script>
725
+ <script src="https://cdn.jsdelivr.net/npm/@smartledger/bsv@7.0.2/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@7.0.0/bsv.min.js"></script>
51
+ <script src="https://unpkg.com/@smartledger/bsv@7.0.2/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@7.0.0/bsv.bundle.js"></script>
61
+ <script src="https://unpkg.com/@smartledger/bsv@7.0.2/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@7.0.0/bsv.min.js"></script>
75
- <script src="https://unpkg.com/@smartledger/bsv@7.0.0/bsv-covenant.min.js"></script>
76
- <script src="https://unpkg.com/@smartledger/bsv@7.0.0/bsv-smartcontract.min.js"></script>
74
+ <script src="https://unpkg.com/@smartledger/bsv@7.0.2/bsv.min.js"></script>
75
+ <script src="https://unpkg.com/@smartledger/bsv@7.0.2/bsv-covenant.min.js"></script>
76
+ <script src="https://unpkg.com/@smartledger/bsv@7.0.2/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@7.0.0/bsv.min.js"></script>
86
- <script src="https://unpkg.com/@smartledger/bsv@7.0.0/bsv-ltp.min.js"></script>
87
- <script src="https://unpkg.com/@smartledger/bsv@7.0.0/bsv-gdaf.min.js"></script>
85
+ <script src="https://unpkg.com/@smartledger/bsv@7.0.2/bsv.min.js"></script>
86
+ <script src="https://unpkg.com/@smartledger/bsv@7.0.2/bsv-ltp.min.js"></script>
87
+ <script src="https://unpkg.com/@smartledger/bsv@7.0.2/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@7.0.0/bsv.min.js"></script>
102
- <script src="https://unpkg.com/@smartledger/bsv@7.0.0/bsv-security.min.js"></script>
103
- <script src="https://unpkg.com/@smartledger/bsv@7.0.0/bsv-shamir.min.js"></script>
101
+ <script src="https://unpkg.com/@smartledger/bsv@7.0.2/bsv.min.js"></script>
102
+ <script src="https://unpkg.com/@smartledger/bsv@7.0.2/bsv-security.min.js"></script>
103
+ <script src="https://unpkg.com/@smartledger/bsv@7.0.2/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@7.0.0/bsv.min.js` |
118
- | **bsv.bundle.js** | 937KB | Everything in one file | `unpkg.com/@smartledger/bsv@7.0.0/bsv.bundle.js` |
119
- | **bsv-smartcontract.min.js** | 937KB | Complete covenant framework | `unpkg.com/@smartledger/bsv@7.0.0/bsv-smartcontract.min.js` |
120
- | **bsv-ltp.min.js** | 1184KB | **Legal Token Protocol** | `unpkg.com/@smartledger/bsv@7.0.0/bsv-ltp.min.js` |
121
- | **bsv-gdaf.min.js** | 1184KB | **Digital Identity & Attestation** | `unpkg.com/@smartledger/bsv@7.0.0/bsv-gdaf.min.js` |
122
- | **bsv-shamir.min.js** | 432KB | **Threshold Cryptography** | `unpkg.com/@smartledger/bsv@7.0.0/bsv-shamir.min.js` |
123
- | **bsv-security.min.js** | 26KB | Security enhancements (opt-in helpers — see README › Security) | `unpkg.com/@smartledger/bsv@7.0.0/bsv-security.min.js` |
124
- | **bsv-mnemonic.min.js** | 681KB | HD wallets | `unpkg.com/@smartledger/bsv@7.0.0/bsv-mnemonic.min.js` |
125
- | **bsv-ecies.min.js** | 71KB | Encryption | `unpkg.com/@smartledger/bsv@7.0.0/bsv-ecies.min.js` |
126
- | **bsv-covenant.min.js** | 913KB | Covenant operations | `unpkg.com/@smartledger/bsv@7.0.0/bsv-covenant.min.js` |
127
- | **bsv-script-helper.min.js** | 26KB | Custom script tools | `unpkg.com/@smartledger/bsv@7.0.0/bsv-script-helper.min.js` |
128
- | **bsv-message.min.js** | 26KB | Message signing | `unpkg.com/@smartledger/bsv@7.0.0/bsv-message.min.js` |
117
+ | **bsv.min.js** | 937KB | Core BSV + SmartContract | `unpkg.com/@smartledger/bsv@7.0.2/bsv.min.js` |
118
+ | **bsv.bundle.js** | 937KB | Everything in one file | `unpkg.com/@smartledger/bsv@7.0.2/bsv.bundle.js` |
119
+ | **bsv-smartcontract.min.js** | 937KB | Complete covenant framework | `unpkg.com/@smartledger/bsv@7.0.2/bsv-smartcontract.min.js` |
120
+ | **bsv-ltp.min.js** | 1184KB | **Legal Token Protocol** | `unpkg.com/@smartledger/bsv@7.0.2/bsv-ltp.min.js` |
121
+ | **bsv-gdaf.min.js** | 1184KB | **Digital Identity & Attestation** | `unpkg.com/@smartledger/bsv@7.0.2/bsv-gdaf.min.js` |
122
+ | **bsv-shamir.min.js** | 432KB | **Threshold Cryptography** | `unpkg.com/@smartledger/bsv@7.0.2/bsv-shamir.min.js` |
123
+ | **bsv-security.min.js** | 26KB | Security enhancements (opt-in helpers — see README › Security) | `unpkg.com/@smartledger/bsv@7.0.2/bsv-security.min.js` |
124
+ | **bsv-mnemonic.min.js** | 681KB | HD wallets | `unpkg.com/@smartledger/bsv@7.0.2/bsv-mnemonic.min.js` |
125
+ | **bsv-ecies.min.js** | 71KB | Encryption | `unpkg.com/@smartledger/bsv@7.0.2/bsv-ecies.min.js` |
126
+ | **bsv-covenant.min.js** | 913KB | Covenant operations | `unpkg.com/@smartledger/bsv@7.0.2/bsv-covenant.min.js` |
127
+ | **bsv-script-helper.min.js** | 26KB | Custom script tools | `unpkg.com/@smartledger/bsv@7.0.2/bsv-script-helper.min.js` |
128
+ | **bsv-message.min.js** | 26KB | Message signing | `unpkg.com/@smartledger/bsv@7.0.2/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@7.0.0/bsv.min.js"></script>
17
+ <script src="https://unpkg.com/@smartledger/bsv@7.0.2/bsv.min.js"></script>
18
18
 
19
19
  <!-- Everything included (937KB) -->
20
- <script src="https://unpkg.com/@smartledger/bsv@7.0.0/bsv.bundle.js"></script>
20
+ <script src="https://unpkg.com/@smartledger/bsv@7.0.2/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@7.0.0/bsv.min.js"></script>
130
+ <script src="https://unpkg.com/@smartledger/bsv@7.0.2/bsv.min.js"></script>
131
131
 
132
132
  <!-- Smart contracts (937KB) -->
133
- <script src="https://unpkg.com/@smartledger/bsv@7.0.0/bsv-smartcontract.min.js"></script>
133
+ <script src="https://unpkg.com/@smartledger/bsv@7.0.2/bsv-smartcontract.min.js"></script>
134
134
 
135
135
  <!-- Legal tokens (1.16MB) -->
136
- <script src="https://unpkg.com/@smartledger/bsv@7.0.0/bsv-ltp.min.js"></script>
136
+ <script src="https://unpkg.com/@smartledger/bsv@7.0.2/bsv-ltp.min.js"></script>
137
137
 
138
138
  <!-- Digital identity (1.16MB) -->
139
- <script src="https://unpkg.com/@smartledger/bsv@7.0.0/bsv-gdaf.min.js"></script>
139
+ <script src="https://unpkg.com/@smartledger/bsv@7.0.2/bsv-gdaf.min.js"></script>
140
140
 
141
141
  <!-- Everything (937KB) -->
142
- <script src="https://unpkg.com/@smartledger/bsv@7.0.0/bsv.bundle.js"></script>
142
+ <script src="https://unpkg.com/@smartledger/bsv@7.0.2/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@7.0.0/bsv.min.js"></script>
162
+ <script src="https://unpkg.com/@smartledger/bsv@7.0.2/bsv.min.js"></script>
163
163
 
164
164
  <!-- Add smart contracts when ready -->
165
- <script src="https://unpkg.com/@smartledger/bsv@7.0.0/bsv-smartcontract.min.js"></script>
165
+ <script src="https://unpkg.com/@smartledger/bsv@7.0.2/bsv-smartcontract.min.js"></script>
166
166
 
167
167
  <!-- Add advanced features as needed -->
168
- <script src="https://unpkg.com/@smartledger/bsv@7.0.0/bsv-ltp.min.js"></script>
169
- <script src="https://unpkg.com/@smartledger/bsv@7.0.0/bsv-gdaf.min.js"></script>
168
+ <script src="https://unpkg.com/@smartledger/bsv@7.0.2/bsv-ltp.min.js"></script>
169
+ <script src="https://unpkg.com/@smartledger/bsv@7.0.2/bsv-gdaf.min.js"></script>
170
170
 
171
171
  <!-- Everything in one file -->
172
- <script src="https://unpkg.com/@smartledger/bsv@7.0.0/bsv.bundle.js"></script>
172
+ <script src="https://unpkg.com/@smartledger/bsv@7.0.2/bsv.bundle.js"></script>
173
173
  ```
174
174
 
175
175
  ## 🔍 **Testing Your Migration**
@@ -57,7 +57,10 @@ AESCBC.decrypt = function (encbuf, cipherkeybuf) {
57
57
  }
58
58
 
59
59
  var ECIES = function ECIES (opts) {
60
- if (!(this instanceof ECIES)) return new ECIES()
60
+ // Forward opts through the no-`new` guard; dropping it (the pre-7.0.2
61
+ // `new ECIES()`) silently ignored { noKey, shortTag } when called as a
62
+ // factory, changing the wire format (e.g. leaking the 33-byte sender pubkey).
63
+ if (!(this instanceof ECIES)) return new ECIES(opts)
61
64
  this.opts = opts || {}
62
65
  }
63
66
 
@@ -94,7 +94,10 @@ Base58Check.prototype.fromString = function (str) {
94
94
 
95
95
  Base58Check.fromString = function (str) {
96
96
  var buf = Base58Check.decode(str)
97
- return new Base58(buf)
97
+ // Must be a Base58Check, not a Base58: returning the latter re-encodes without
98
+ // the checksum, so a Base58Check.encode(...) -> fromString -> toString round
99
+ // trip silently produced a different, unchecksummed string (no error).
100
+ return new Base58Check(buf)
98
101
  }
99
102
 
100
103
  Base58Check.prototype.toBuffer = function () {
@@ -60,8 +60,12 @@ function HDPrivateKey (arg) {
60
60
  }
61
61
  }
62
62
 
63
- HDPrivateKey.fromRandom = function () {
64
- return new HDPrivateKey()
63
+ // Forward the network so `fromRandom('testnet')` generates a testnet key. The
64
+ // constructor routes a network arg to _generateRandomly(network); dropping it
65
+ // (the pre-7.0.2 `new HDPrivateKey()`) silently produced a mainnet key on a
66
+ // testnet request, with no error.
67
+ HDPrivateKey.fromRandom = function (network) {
68
+ return new HDPrivateKey(network)
65
69
  }
66
70
 
67
71
  /**
@@ -89,8 +89,38 @@ var Mnemonic = function (data, wordlist) {
89
89
  })
90
90
  }
91
91
 
92
- Mnemonic.fromRandom = function (wordlist = Mnemonic.Words.ENGLISH) {
93
- return new Mnemonic(wordlist)
92
+ /**
93
+ * Generate a random Mnemonic with the given wordlist and entropy.
94
+ *
95
+ * A number in either argument position is the entropy in bits (128, 160, 192,
96
+ * 224 or 256 — higher = more words); an array is the wordlist. So every form
97
+ * below works AND honours the requested strength:
98
+ * fromRandom() -> ENGLISH, 128-bit (12 words)
99
+ * fromRandom(wordlist) -> wordlist, 128-bit
100
+ * fromRandom(wordlist, 256) -> wordlist, 256-bit (24 words)
101
+ * fromRandom(256) -> ENGLISH, 256-bit
102
+ * fromRandom(256, wordlist) -> wordlist, 256-bit
103
+ *
104
+ * Prior to 7.0.1 the second argument was silently dropped, so the documented
105
+ * `fromRandom(wordlist, 256)` form returned a weaker 12-word (128-bit) phrase
106
+ * with no error — a security foot-gun this fix closes. Invalid entropy still
107
+ * throws (must be a multiple of 32 and >= 128).
108
+ *
109
+ * @param {Array<string>|number} [wordlist] - wordlist, or entropy bits
110
+ * @param {number|Array<string>} [ent] - entropy bits, or wordlist
111
+ * @returns {Mnemonic}
112
+ */
113
+ Mnemonic.fromRandom = function (wordlist, ent) {
114
+ // A number in the first position is the entropy; normalise so `ent` holds it
115
+ // and `wordlist` holds the array (either argument order is accepted).
116
+ if (_.isNumber(wordlist)) {
117
+ var swapped = ent
118
+ ent = wordlist
119
+ wordlist = swapped
120
+ }
121
+ wordlist = wordlist || Mnemonic.Words.ENGLISH
122
+ ent = ent || 128
123
+ return new Mnemonic(ent, wordlist)
94
124
  }
95
125
 
96
126
  Mnemonic.fromString = function (mnemonic, wordlist = Mnemonic.Words.ENGLISH) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@smartledger/bsv",
3
- "version": "7.0.0",
3
+ "version": "7.0.2",
4
4
  "description": "🚀 Complete Bitcoin SV development framework with legally-recognizable DID:web + W3C VC-JWT toolkit, Legal Token Protocol (LTP), Global Digital Attestation Framework (GDAF), StatusList2021 revocation, and 16 flexible loading options. Standards-based credentials with ES256/ES256K support, on-chain BSV anchoring, and comprehensive Bitcoin SV API. Perfect for legal tokens, verifiable credentials, 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",
@@ -28,6 +28,14 @@ describe('Bitcore ECIES', function () {
28
28
  (ecies instanceof ECIES).should.equal(true)
29
29
  })
30
30
 
31
+ // Regression: the no-`new` factory path used to drop opts (return new ECIES()),
32
+ // silently ignoring { noKey, shortTag } and changing the wire format.
33
+ it('forwards opts through the no-"new" factory path', function () {
34
+ var ecies = ECIES({ noKey: true, shortTag: true })
35
+ ecies.opts.noKey.should.equal(true)
36
+ ecies.opts.shortTag.should.equal(true)
37
+ })
38
+
31
39
  it('privateKey fails with no argument', function () {
32
40
  var ecies = ECIES()
33
41
  var fail = function () {
@@ -111,6 +111,15 @@ describe('Base58Check', function () {
111
111
  it('should convert this known string to a buffer', function () {
112
112
  Base58Check.fromString(enc).toBuffer().toString('hex').should.equal(buf.toString('hex'))
113
113
  })
114
+
115
+ // Regression: the static factory used to return a plain Base58 (no checksum),
116
+ // so encode -> fromString -> toString silently round-tripped to a different
117
+ // string. It must return a Base58Check that re-encodes with the checksum.
118
+ it('returns a Base58Check that round-trips through toString', function () {
119
+ var r = Base58Check.fromString(enc)
120
+ r.should.be.instanceof(Base58Check)
121
+ r.toString().should.equal(enc)
122
+ })
114
123
  })
115
124
 
116
125
  describe('#toBuffer', function () {
@@ -291,6 +291,15 @@ describe('HDPrivate key interface', function () {
291
291
  xprv2.toString().should.not.equal(xprv3.toString())
292
292
  xprv1.toString().should.not.equal(xprv3.toString())
293
293
  })
294
+
295
+ // Regression: fromRandom used to drop its argument and always return a
296
+ // mainnet key, so fromRandom('testnet') silently produced an xprv.
297
+ it('honours the network argument', function () {
298
+ HDPrivateKey.fromRandom('testnet').network.name.should.equal('testnet')
299
+ HDPrivateKey.fromRandom('testnet').toString().slice(0, 4).should.equal('tprv')
300
+ HDPrivateKey.fromRandom('livenet').network.name.should.equal('livenet')
301
+ HDPrivateKey.fromRandom().network.name.should.equal('livenet') // default unchanged
302
+ })
294
303
  })
295
304
 
296
305
  describe('conversion to plain object/json', function () {
@@ -27,6 +27,38 @@ describe('Mnemonic', function () {
27
27
  Mnemonic.Words.SPANISH.includes(mnemonic3.toString().split(' ')[1]).should.equal(true)
28
28
  Mnemonic.Words.SPANISH.includes(mnemonic3.toString().split(' ')[2]).should.equal(true)
29
29
  })
30
+
31
+ // Regression: the second argument used to be silently dropped, so the
32
+ // documented fromRandom(wordlist, 256) form returned a WEAK 12-word phrase.
33
+ function wordCount (m) { return m.toString().split(' ').length }
34
+
35
+ it('defaults to a 12-word (128-bit) phrase', function () {
36
+ wordCount(Mnemonic.fromRandom()).should.equal(12)
37
+ wordCount(Mnemonic.fromRandom(Mnemonic.Words.ENGLISH)).should.equal(12)
38
+ })
39
+
40
+ it('honours entropy passed as the second argument (wordlist, ent)', function () {
41
+ // The previously-broken documented form: must now yield 24 words.
42
+ wordCount(Mnemonic.fromRandom(Mnemonic.Words.ENGLISH, 256)).should.equal(24)
43
+ wordCount(Mnemonic.fromRandom(Mnemonic.Words.ENGLISH, 192)).should.equal(18)
44
+ wordCount(Mnemonic.fromRandom(Mnemonic.Words.ENGLISH, 160)).should.equal(15)
45
+ })
46
+
47
+ it('honours entropy passed as the first argument (ent) or (ent, wordlist)', function () {
48
+ wordCount(Mnemonic.fromRandom(256)).should.equal(24)
49
+ var es = Mnemonic.fromRandom(256, Mnemonic.Words.SPANISH)
50
+ wordCount(es).should.equal(24)
51
+ Mnemonic.Words.SPANISH.includes(es.toString().split(' ')[0]).should.equal(true)
52
+ })
53
+
54
+ it('throws on invalid entropy instead of silently degrading', function () {
55
+ ;(function () { Mnemonic.fromRandom(Mnemonic.Words.ENGLISH, 200) }).should.throw(/ENT/)
56
+ ;(function () { Mnemonic.fromRandom(64) }).should.throw(/ENT/)
57
+ })
58
+
59
+ it('reports a meaningful arity (2), not 0', function () {
60
+ Mnemonic.fromRandom.length.should.equal(2)
61
+ })
30
62
  })
31
63
 
32
64
  describe('# Mnemonic', function () {
package/version.js CHANGED
@@ -1,3 +1,3 @@
1
1
  'use strict'
2
2
  // GENERATED by scripts/sync-version.js on `npm version` — do not edit.
3
- module.exports = '7.0.0'
3
+ module.exports = '7.0.2'