@smartledger/bsv 7.5.4 → 7.5.6

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.
@@ -0,0 +1,94 @@
1
+ # `bn.js` 4 → 5: semantic review
2
+
3
+ **Date:** 2026-08-07 · **Versions compared:** 4.12.3 (pinned) vs 5.2.5 · **Verdict: do not upgrade yet — correctness is fine, bundle size is not.**
4
+
5
+ `bn.js` is the arithmetic layer beneath ECDSA, script numbers, transaction amounts and
6
+ HD derivation, so "the test suite passes" is not sufficient evidence for a major bump.
7
+ This is the review that was required instead.
8
+
9
+ ## Method
10
+
11
+ Two independent lines of evidence, both run against the **real** `lib/crypto/bn.js`
12
+ wrapper and the consensus paths built on it — not against `bn.js` in isolation.
13
+
14
+ 1. **Targeted differential harness** — 16 hand-picked values (zero, ±1, `n`, `n-1`,
15
+ 2⁵³, 2⁶⁴, high-bit-set, leading-zero-byte, negatives) crossed through every wrapper
16
+ and arithmetic operation the library uses: `toString(10)`, `toString(16)`,
17
+ `toString(16, 2)`, `toBuffer`, `toBuffer({size:32})`, little-endian variants,
18
+ `toSM`/`fromSM`, `toScriptNumBuffer`/`fromScriptNumBuffer`, `add`, `sub`, `mul`,
19
+ `div`, `mod`, `umod`, `cmp`, `neg`, `abs`, `shrn`, `ushrn`, `ushln`, `invm`, `gcd`,
20
+ `pow`, `byteLength`, `bitLength`, plus ECDSA signing, WIF, addresses, public keys
21
+ and HD derivation. **2,271 checks.**
22
+
23
+ 2. **Randomised differential fuzz** — a deterministic sha256-chained PRNG (identical
24
+ inputs on both runs) over 400 rounds of random 1–32 byte magnitudes, random signs,
25
+ the same operation set, and a real deterministic ECDSA signature per round.
26
+ **8,800 checks.**
27
+
28
+ Both versions were installed into a pristine copy of the repository in the same
29
+ container, and the JSON/line output diffed.
30
+
31
+ ## Result
32
+
33
+ **11,071 checks. Zero differences.** Identical throw sites with identical messages
34
+ (11 under each — script-number overflow and negative-shift assertions, in both).
35
+
36
+ Specifically identical: **ECDSA DER signature bytes**, WIF encodings, addresses, public
37
+ keys, script-number serialisation across the interpreter's range, and HD child
38
+ derivation. No signature this library has ever produced would change.
39
+
40
+ ## Documented v5 breaking changes vs. our call sites
41
+
42
+ | v5 change | Call sites in `lib/` |
43
+ | --- | --- |
44
+ | `.strip()` made internal | **0** |
45
+ | `.modn()` deprecated → `.modrn()` | **0** |
46
+ | negative-number fixes in `imuln`/`modrn`/`idivn` | **0** |
47
+ | `toArrayLike` refactor | **0** |
48
+ | `toBuffer` only defined when `Buffer` exists | **0** — our wrapper *overrides* `toBuffer` entirely |
49
+ | constructor rejects decimal strings | **0** — no decimal string is ever passed |
50
+ | stricter invalid-character parsing | the only one that reached us — see below |
51
+
52
+ The single `.toArray()` call site is the interpreter's `LSHIFT`/`RSHIFT` path. It is
53
+ covered by 74 bitcoind `script_tests` vectors, which pass identically under both
54
+ versions.
55
+
56
+ ### The one change that reached us
57
+
58
+ v5 rejects invalid characters instead of silently skipping them. That is what surfaced
59
+ the latent defect fixed in **7.5.5**: `PrivateKey.fromObject` accepted a malformed `bn`
60
+ and returned a different, ~40-bit key rather than throwing. v5's behaviour is strictly
61
+ safer, and our fix is in this library's own validation, so it does not depend on the
62
+ upgrade.
63
+
64
+ ## Why the upgrade is nonetheless declined
65
+
66
+ The `=4.12.3` pin in `package.json` is load-bearing for **deduplication**:
67
+
68
+ | root `bn.js` | copies inlined in `bsv.min.js` | size |
69
+ | --- | --- | --- |
70
+ | 4.12.3 (today) | 2 | 1,319,110 |
71
+ | 5.2.5 | 5 | 1,451,156 (**+132 KB, +10 %**) |
72
+
73
+ At 4.12.3, npm satisfies the transitive `^4` consumers (`asn1.js`, `miller-rabin`,
74
+ `public-encrypt`, `diffie-hellman`) from the hoisted root copy. Moving the root to 5.x
75
+ no longer satisfies `^4`, so each gets its own nested 4.12.5 — and those chains are part
76
+ of `crypto-browserify`, which **is** bundled. (`elliptic`, `browserify-sign` and
77
+ `create-ecdh` are stubbed out by the esbuild config and stay absent either way.)
78
+
79
+ So the upgrade costs every browser consumer 10 % more bundle for no functional gain:
80
+ there is no advisory against `bn.js` 4.x affecting this library, and no v5 feature it
81
+ needs.
82
+
83
+ ## When to revisit
84
+
85
+ When the `crypto-browserify` dependency chain moves to `bn.js@^5`, deduplication is
86
+ restored and the upgrade becomes free. At that point this review's correctness findings
87
+ still stand and the bump can be taken directly.
88
+
89
+ ## Reproducing
90
+
91
+ The harnesses are not committed (they need two conflicting versions of the same
92
+ dependency installed side by side). To rebuild them, run the wrapper surface and a
93
+ deterministic fuzz corpus under each version in a clean container and diff the output;
94
+ the operation list above is the required coverage.
@@ -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.5.4/bsv-shamir.min.js`
58
+ - **CDN**: `unpkg.com/@smartledger/bsv@7.5.6/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.5.4/bsv-gdaf.min.js`
64
+ - **CDN**: `unpkg.com/@smartledger/bsv@7.5.6/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.5.4/bsv-ltp.min.js`
70
+ - **CDN**: `unpkg.com/@smartledger/bsv@7.5.6/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.5.4/bsv.min.js` |
85
- | **bsv.bundle.js** | 937KB | Everything in one file | `unpkg.com/@smartledger/bsv@7.5.4/bsv.bundle.js` |
86
- | **bsv-smartcontract.min.js** | 937KB | Covenant development | `unpkg.com/@smartledger/bsv@7.5.4/bsv-smartcontract.min.js` |
87
- | **bsv-covenant.min.js** | 913KB | Covenant operations | `unpkg.com/@smartledger/bsv@7.5.4/bsv-covenant.min.js` |
88
- | **bsv-script-helper.min.js** | 26KB | Custom script tools | `unpkg.com/@smartledger/bsv@7.5.4/bsv-script-helper.min.js` |
89
- | **bsv-security.min.js** | 26KB | Security enhancements (opt-in helpers — see README › Security) | `unpkg.com/@smartledger/bsv@7.5.4/bsv-security.min.js` |
90
- | **bsv-ecies.min.js** | 71KB | Encryption | `unpkg.com/@smartledger/bsv@7.5.4/bsv-ecies.min.js` |
91
- | **bsv-message.min.js** | 26KB | Message signing | `unpkg.com/@smartledger/bsv@7.5.4/bsv-message.min.js` |
92
- | **bsv-mnemonic.min.js** | 681KB | HD wallets | `unpkg.com/@smartledger/bsv@7.5.4/bsv-mnemonic.min.js` |
93
- | **🆕 bsv-shamir.min.js** | 432KB | **Secret sharing** | `unpkg.com/@smartledger/bsv@7.5.4/bsv-shamir.min.js` |
94
- | **🆕 bsv-gdaf.min.js** | 1184KB | **Digital attestation** | `unpkg.com/@smartledger/bsv@7.5.4/bsv-gdaf.min.js` |
95
- | **🆕 bsv-ltp.min.js** | 1184KB | **Legal tokens** | `unpkg.com/@smartledger/bsv@7.5.4/bsv-ltp.min.js` |
84
+ | **bsv.min.js** | 937KB | Core BSV + SmartContract | `unpkg.com/@smartledger/bsv@7.5.6/bsv.min.js` |
85
+ | **bsv.bundle.js** | 937KB | Everything in one file | `unpkg.com/@smartledger/bsv@7.5.6/bsv.bundle.js` |
86
+ | **bsv-smartcontract.min.js** | 937KB | Covenant development | `unpkg.com/@smartledger/bsv@7.5.6/bsv-smartcontract.min.js` |
87
+ | **bsv-covenant.min.js** | 913KB | Covenant operations | `unpkg.com/@smartledger/bsv@7.5.6/bsv-covenant.min.js` |
88
+ | **bsv-script-helper.min.js** | 26KB | Custom script tools | `unpkg.com/@smartledger/bsv@7.5.6/bsv-script-helper.min.js` |
89
+ | **bsv-security.min.js** | 26KB | Security enhancements (opt-in helpers — see README › Security) | `unpkg.com/@smartledger/bsv@7.5.6/bsv-security.min.js` |
90
+ | **bsv-ecies.min.js** | 71KB | Encryption | `unpkg.com/@smartledger/bsv@7.5.6/bsv-ecies.min.js` |
91
+ | **bsv-message.min.js** | 26KB | Message signing | `unpkg.com/@smartledger/bsv@7.5.6/bsv-message.min.js` |
92
+ | **bsv-mnemonic.min.js** | 681KB | HD wallets | `unpkg.com/@smartledger/bsv@7.5.6/bsv-mnemonic.min.js` |
93
+ | **🆕 bsv-shamir.min.js** | 432KB | **Secret sharing** | `unpkg.com/@smartledger/bsv@7.5.6/bsv-shamir.min.js` |
94
+ | **🆕 bsv-gdaf.min.js** | 1184KB | **Digital attestation** | `unpkg.com/@smartledger/bsv@7.5.6/bsv-gdaf.min.js` |
95
+ | **🆕 bsv-ltp.min.js** | 1184KB | **Legal tokens** | `unpkg.com/@smartledger/bsv@7.5.6/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.5.4/bsv.min.js"></script>
104
- <script src="https://unpkg.com/@smartledger/bsv@7.5.4/bsv-script-helper.min.js"></script>
103
+ <script src="https://unpkg.com/@smartledger/bsv@7.5.6/bsv.min.js"></script>
104
+ <script src="https://unpkg.com/@smartledger/bsv@7.5.6/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.5.4/bsv.min.js"></script>
110
- <script src="https://unpkg.com/@smartledger/bsv@7.5.4/bsv-covenant.min.js"></script>
111
- <script src="https://unpkg.com/@smartledger/bsv@7.5.4/bsv-smartcontract.min.js"></script>
109
+ <script src="https://unpkg.com/@smartledger/bsv@7.5.6/bsv.min.js"></script>
110
+ <script src="https://unpkg.com/@smartledger/bsv@7.5.6/bsv-covenant.min.js"></script>
111
+ <script src="https://unpkg.com/@smartledger/bsv@7.5.6/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.5.4/bsv.min.js"></script>
117
- <script src="https://unpkg.com/@smartledger/bsv@7.5.4/bsv-ltp.min.js"></script>
118
- <script src="https://unpkg.com/@smartledger/bsv@7.5.4/bsv-gdaf.min.js"></script>
116
+ <script src="https://unpkg.com/@smartledger/bsv@7.5.6/bsv.min.js"></script>
117
+ <script src="https://unpkg.com/@smartledger/bsv@7.5.6/bsv-ltp.min.js"></script>
118
+ <script src="https://unpkg.com/@smartledger/bsv@7.5.6/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.5.4/bsv.min.js"></script>
136
- <script src="https://unpkg.com/@smartledger/bsv@7.5.4/bsv-security.min.js"></script>
137
- <script src="https://unpkg.com/@smartledger/bsv@7.5.4/bsv-shamir.min.js"></script>
135
+ <script src="https://unpkg.com/@smartledger/bsv@7.5.6/bsv.min.js"></script>
136
+ <script src="https://unpkg.com/@smartledger/bsv@7.5.6/bsv-security.min.js"></script>
137
+ <script src="https://unpkg.com/@smartledger/bsv@7.5.6/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.5.4/bsv.bundle.js"></script>
149
+ <script src="https://unpkg.com/@smartledger/bsv@7.5.6/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.5.4/bsv.min.js"></script>
725
+ <script src="https://cdn.jsdelivr.net/npm/@smartledger/bsv@7.5.6/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.5.4/bsv.min.js"></script>
51
+ <script src="https://unpkg.com/@smartledger/bsv@7.5.6/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.5.4/bsv.bundle.js"></script>
61
+ <script src="https://unpkg.com/@smartledger/bsv@7.5.6/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.5.4/bsv.min.js"></script>
75
- <script src="https://unpkg.com/@smartledger/bsv@7.5.4/bsv-covenant.min.js"></script>
76
- <script src="https://unpkg.com/@smartledger/bsv@7.5.4/bsv-smartcontract.min.js"></script>
74
+ <script src="https://unpkg.com/@smartledger/bsv@7.5.6/bsv.min.js"></script>
75
+ <script src="https://unpkg.com/@smartledger/bsv@7.5.6/bsv-covenant.min.js"></script>
76
+ <script src="https://unpkg.com/@smartledger/bsv@7.5.6/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.5.4/bsv.min.js"></script>
86
- <script src="https://unpkg.com/@smartledger/bsv@7.5.4/bsv-ltp.min.js"></script>
87
- <script src="https://unpkg.com/@smartledger/bsv@7.5.4/bsv-gdaf.min.js"></script>
85
+ <script src="https://unpkg.com/@smartledger/bsv@7.5.6/bsv.min.js"></script>
86
+ <script src="https://unpkg.com/@smartledger/bsv@7.5.6/bsv-ltp.min.js"></script>
87
+ <script src="https://unpkg.com/@smartledger/bsv@7.5.6/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.5.4/bsv.min.js"></script>
102
- <script src="https://unpkg.com/@smartledger/bsv@7.5.4/bsv-security.min.js"></script>
103
- <script src="https://unpkg.com/@smartledger/bsv@7.5.4/bsv-shamir.min.js"></script>
101
+ <script src="https://unpkg.com/@smartledger/bsv@7.5.6/bsv.min.js"></script>
102
+ <script src="https://unpkg.com/@smartledger/bsv@7.5.6/bsv-security.min.js"></script>
103
+ <script src="https://unpkg.com/@smartledger/bsv@7.5.6/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.5.4/bsv.min.js` |
118
- | **bsv.bundle.js** | 937KB | Everything in one file | `unpkg.com/@smartledger/bsv@7.5.4/bsv.bundle.js` |
119
- | **bsv-smartcontract.min.js** | 937KB | Complete covenant framework | `unpkg.com/@smartledger/bsv@7.5.4/bsv-smartcontract.min.js` |
120
- | **bsv-ltp.min.js** | 1184KB | **Legal Token Protocol** | `unpkg.com/@smartledger/bsv@7.5.4/bsv-ltp.min.js` |
121
- | **bsv-gdaf.min.js** | 1184KB | **Digital Identity & Attestation** | `unpkg.com/@smartledger/bsv@7.5.4/bsv-gdaf.min.js` |
122
- | **bsv-shamir.min.js** | 432KB | **Threshold Cryptography** | `unpkg.com/@smartledger/bsv@7.5.4/bsv-shamir.min.js` |
123
- | **bsv-security.min.js** | 26KB | Security enhancements (opt-in helpers — see README › Security) | `unpkg.com/@smartledger/bsv@7.5.4/bsv-security.min.js` |
124
- | **bsv-mnemonic.min.js** | 681KB | HD wallets | `unpkg.com/@smartledger/bsv@7.5.4/bsv-mnemonic.min.js` |
125
- | **bsv-ecies.min.js** | 71KB | Encryption | `unpkg.com/@smartledger/bsv@7.5.4/bsv-ecies.min.js` |
126
- | **bsv-covenant.min.js** | 913KB | Covenant operations | `unpkg.com/@smartledger/bsv@7.5.4/bsv-covenant.min.js` |
127
- | **bsv-script-helper.min.js** | 26KB | Custom script tools | `unpkg.com/@smartledger/bsv@7.5.4/bsv-script-helper.min.js` |
128
- | **bsv-message.min.js** | 26KB | Message signing | `unpkg.com/@smartledger/bsv@7.5.4/bsv-message.min.js` |
117
+ | **bsv.min.js** | 937KB | Core BSV + SmartContract | `unpkg.com/@smartledger/bsv@7.5.6/bsv.min.js` |
118
+ | **bsv.bundle.js** | 937KB | Everything in one file | `unpkg.com/@smartledger/bsv@7.5.6/bsv.bundle.js` |
119
+ | **bsv-smartcontract.min.js** | 937KB | Complete covenant framework | `unpkg.com/@smartledger/bsv@7.5.6/bsv-smartcontract.min.js` |
120
+ | **bsv-ltp.min.js** | 1184KB | **Legal Token Protocol** | `unpkg.com/@smartledger/bsv@7.5.6/bsv-ltp.min.js` |
121
+ | **bsv-gdaf.min.js** | 1184KB | **Digital Identity & Attestation** | `unpkg.com/@smartledger/bsv@7.5.6/bsv-gdaf.min.js` |
122
+ | **bsv-shamir.min.js** | 432KB | **Threshold Cryptography** | `unpkg.com/@smartledger/bsv@7.5.6/bsv-shamir.min.js` |
123
+ | **bsv-security.min.js** | 26KB | Security enhancements (opt-in helpers — see README › Security) | `unpkg.com/@smartledger/bsv@7.5.6/bsv-security.min.js` |
124
+ | **bsv-mnemonic.min.js** | 681KB | HD wallets | `unpkg.com/@smartledger/bsv@7.5.6/bsv-mnemonic.min.js` |
125
+ | **bsv-ecies.min.js** | 71KB | Encryption | `unpkg.com/@smartledger/bsv@7.5.6/bsv-ecies.min.js` |
126
+ | **bsv-covenant.min.js** | 913KB | Covenant operations | `unpkg.com/@smartledger/bsv@7.5.6/bsv-covenant.min.js` |
127
+ | **bsv-script-helper.min.js** | 26KB | Custom script tools | `unpkg.com/@smartledger/bsv@7.5.6/bsv-script-helper.min.js` |
128
+ | **bsv-message.min.js** | 26KB | Message signing | `unpkg.com/@smartledger/bsv@7.5.6/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.5.4/bsv.min.js"></script>
17
+ <script src="https://unpkg.com/@smartledger/bsv@7.5.6/bsv.min.js"></script>
18
18
 
19
19
  <!-- Everything included (937KB) -->
20
- <script src="https://unpkg.com/@smartledger/bsv@7.5.4/bsv.bundle.js"></script>
20
+ <script src="https://unpkg.com/@smartledger/bsv@7.5.6/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.5.4/bsv.min.js"></script>
130
+ <script src="https://unpkg.com/@smartledger/bsv@7.5.6/bsv.min.js"></script>
131
131
 
132
132
  <!-- Smart contracts (937KB) -->
133
- <script src="https://unpkg.com/@smartledger/bsv@7.5.4/bsv-smartcontract.min.js"></script>
133
+ <script src="https://unpkg.com/@smartledger/bsv@7.5.6/bsv-smartcontract.min.js"></script>
134
134
 
135
135
  <!-- Legal tokens (1.16MB) -->
136
- <script src="https://unpkg.com/@smartledger/bsv@7.5.4/bsv-ltp.min.js"></script>
136
+ <script src="https://unpkg.com/@smartledger/bsv@7.5.6/bsv-ltp.min.js"></script>
137
137
 
138
138
  <!-- Digital identity (1.16MB) -->
139
- <script src="https://unpkg.com/@smartledger/bsv@7.5.4/bsv-gdaf.min.js"></script>
139
+ <script src="https://unpkg.com/@smartledger/bsv@7.5.6/bsv-gdaf.min.js"></script>
140
140
 
141
141
  <!-- Everything (937KB) -->
142
- <script src="https://unpkg.com/@smartledger/bsv@7.5.4/bsv.bundle.js"></script>
142
+ <script src="https://unpkg.com/@smartledger/bsv@7.5.6/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.5.4/bsv.min.js"></script>
162
+ <script src="https://unpkg.com/@smartledger/bsv@7.5.6/bsv.min.js"></script>
163
163
 
164
164
  <!-- Add smart contracts when ready -->
165
- <script src="https://unpkg.com/@smartledger/bsv@7.5.4/bsv-smartcontract.min.js"></script>
165
+ <script src="https://unpkg.com/@smartledger/bsv@7.5.6/bsv-smartcontract.min.js"></script>
166
166
 
167
167
  <!-- Add advanced features as needed -->
168
- <script src="https://unpkg.com/@smartledger/bsv@7.5.4/bsv-ltp.min.js"></script>
169
- <script src="https://unpkg.com/@smartledger/bsv@7.5.4/bsv-gdaf.min.js"></script>
168
+ <script src="https://unpkg.com/@smartledger/bsv@7.5.6/bsv-ltp.min.js"></script>
169
+ <script src="https://unpkg.com/@smartledger/bsv@7.5.6/bsv-gdaf.min.js"></script>
170
170
 
171
171
  <!-- Everything in one file -->
172
- <script src="https://unpkg.com/@smartledger/bsv@7.5.4/bsv.bundle.js"></script>
172
+ <script src="https://unpkg.com/@smartledger/bsv@7.5.6/bsv.bundle.js"></script>
173
173
  ```
174
174
 
175
175
  ## 🔍 **Testing Your Migration**
package/lib/crypto/bn.js CHANGED
@@ -149,7 +149,9 @@ BN.prototype.toSMBigEndian = function () {
149
149
  }
150
150
  }
151
151
 
152
- if (buf.length === 1 & buf[0] === 0) {
152
+ // `&` here was a bitwise AND between two booleans. It happened to work because
153
+ // `===` binds tighter than `&` and `true & true` is 1, but the intent is logical.
154
+ if (buf.length === 1 && buf[0] === 0) {
153
155
  buf = Buffer.from([])
154
156
  }
155
157
  return buf
@@ -125,7 +125,12 @@ Hash.hmac = function (hashf, data, key) {
125
125
 
126
126
  if (key.length > blocksize) {
127
127
  key = hashf(key)
128
- } else if (key < blocksize) {
128
+ } else if (key.length < blocksize) {
129
+ // Was `key < blocksize` — a Buffer compared against a number, which is always
130
+ // false, so this zero-padding branch never ran. The result was correct anyway:
131
+ // the XOR loop below indexes past a short key and `x ^ undefined === x ^ 0`,
132
+ // which is exactly what the padding produces. Fixed so the code says what it
133
+ // does; HMAC output is unchanged, and the vectors below assert that.
129
134
  var fill = Buffer.alloc(blocksize)
130
135
  fill.fill(0)
131
136
  key.copy(fill)
@@ -125,7 +125,12 @@ Hash.hmac = function (hashf, data, key) {
125
125
 
126
126
  if (key.length > blocksize) {
127
127
  key = hashf(key)
128
- } else if (key < blocksize) {
128
+ } else if (key.length < blocksize) {
129
+ // Was `key < blocksize` — a Buffer compared against a number, which is always
130
+ // false, so this zero-padding branch never ran. The result was correct anyway:
131
+ // the XOR loop below indexes past a short key and `x ^ undefined === x ^ 0`,
132
+ // which is exactly what the padding produces. Fixed so the code says what it
133
+ // does; HMAC output is unchanged, and the vectors below assert that.
129
134
  var fill = Buffer.alloc(blocksize)
130
135
  fill.fill(0)
131
136
  key.copy(fill)
package/lib/networks.js CHANGED
@@ -330,7 +330,9 @@ Object.defineProperty(testnet, 'cashAddrPrefixArray', {
330
330
  if (this.regtestEnabled) {
331
331
  return cashAddrPrefixToArray(REGTEST.CASHADDRPREFIX)
332
332
  } else if (this.stnEnabled) {
333
- return STN.cashAddrPrefixToArray(STN.CASHADDRPREFIX)
333
+ // STN is a plain data object with no methods; the sibling branches call the
334
+ // module-level helper, and reaching for it on STN threw a TypeError instead.
335
+ return cashAddrPrefixToArray(STN.CASHADDRPREFIX)
334
336
  } else {
335
337
  return cashAddrPrefixToArray(TESTNET.CASHADDRPREFIX)
336
338
  }
package/lib/privatekey.js CHANGED
@@ -11,6 +11,10 @@ var PublicKey = require('./publickey')
11
11
  var Random = require('./crypto/random')
12
12
  var $ = require('./util/preconditions')
13
13
 
14
+ // The marker toJSON() emits in place of the secret. _transformObject rejects it by name
15
+ // so a JSON round-trip fails loudly instead of quietly yielding a different key.
16
+ var REDACTED = '[REDACTED]'
17
+
14
18
  /**
15
19
  * Instantiate a PrivateKey from a BN, Buffer or WIF string.
16
20
  *
@@ -215,7 +219,37 @@ PrivateKey.fromHex = function (hex, network, compressed) {
215
219
  * @private
216
220
  */
217
221
  PrivateKey._transformObject = function (json) {
222
+ // bn.js 4 silently SKIPS characters it cannot parse rather than failing, so any
223
+ // malformed `bn` produced a wrong key instead of an error. The natural round-trip
224
+ // `fromObject(JSON.parse(JSON.stringify(key)))` fed it the redaction marker that
225
+ // `toJSON` has emitted since 7.5.1 and got a deterministic ~40-bit key back, with
226
+ // no indication anything was wrong — funds sent to its address are trivially
227
+ // recoverable by anyone. Validate before parsing.
228
+ // This is reached with two different shapes: a deserialised JSON object, whose `bn`
229
+ // is a hex string, and an internal info object built by _transformBNBuffer, whose
230
+ // `bn` is already a BN. Only the former needs parsing, and only it can be malformed.
231
+ if (json.bn instanceof BN) {
232
+ return {
233
+ bn: json.bn,
234
+ network: Networks.get(json.network),
235
+ compressed: json.compressed
236
+ }
237
+ }
238
+ if (typeof json.bn !== 'string' || !json.bn.length) {
239
+ throw new TypeError('Invalid private key: `bn` must be a hex string')
240
+ }
241
+ if (json.bn === REDACTED) {
242
+ throw new TypeError('Invalid private key: `bn` is "' + REDACTED + '". ' +
243
+ 'JSON.stringify() redacts the secret on purpose — use toObject() for a ' +
244
+ 'round-trippable export, or toWIF().')
245
+ }
246
+ if (!/^[0-9a-fA-F]+$/.test(json.bn)) {
247
+ throw new TypeError('Invalid private key: `bn` is not hexadecimal')
248
+ }
218
249
  var bn = new BN(json.bn, 'hex')
250
+ if (bn.isZero() || bn.gte(Point.getN())) {
251
+ throw new TypeError('Invalid private key: outside the range of valid keys')
252
+ }
219
253
  var network = Networks.get(json.network)
220
254
  return {
221
255
  bn: bn,
@@ -403,7 +437,7 @@ PrivateKey.prototype.toObject = function toObject () {
403
437
  */
404
438
  PrivateKey.prototype.toJSON = function toJSON () {
405
439
  return {
406
- bn: '[REDACTED]',
440
+ bn: REDACTED,
407
441
  compressed: this.compressed,
408
442
  network: this.network.toString()
409
443
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@smartledger/bsv",
3
- "version": "7.5.4",
3
+ "version": "7.5.6",
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",
@@ -228,11 +228,11 @@
228
228
  "esbuild": "^0.28.1",
229
229
  "events": "^3.3.0",
230
230
  "jose": "^5.10.0",
231
- "mocha": "^11.7.6",
231
+ "mocha": "^11.8.0",
232
232
  "nyc": "^18.0.0",
233
233
  "path-browserify": "^1.0.1",
234
234
  "process": "^0.11.10",
235
- "sinon": "7.2.3",
235
+ "sinon": "22.1.0",
236
236
  "standard": "12.0.1",
237
237
  "stream-browserify": "^3.0.0",
238
238
  "typescript": "^5.9.3",
@@ -250,7 +250,9 @@
250
250
  "it"
251
251
  ],
252
252
  "ignore": [
253
- "dist/**"
253
+ "dist/**",
254
+ "bsv.bundle.js",
255
+ "*.min.js"
254
256
  ]
255
257
  }
256
258
  }
package/test/networks.js CHANGED
@@ -159,4 +159,49 @@ describe('Networks', function () {
159
159
  var fn = function () { networks.testnet.name = 'livenet' }
160
160
  expect(fn).to.throw(TypeError)
161
161
  })
162
+ // The `cashAddrPrefixArray` getter has three branches; only the STN one reached for
163
+ // the helper on the STN data object instead of the module-level function, so reading
164
+ // it with STN enabled threw `STN.cashAddrPrefixToArray is not a function`. The tests
165
+ // above cover `cashAddrPrefix` (the string) but never the array getter, which is why
166
+ // a live TypeError survived a 4,597-test suite.
167
+ describe('cashAddrPrefixArray across the regtest/stn toggles', function () {
168
+ // enableStn/enableRegtest mutate the shared testnet object, so without a reset the
169
+ // flags leak into every later test in the run.
170
+ afterEach(function () {
171
+ networks.disableStn()
172
+ networks.disableRegtest()
173
+ })
174
+
175
+ function assertPrefixArray (arr) {
176
+ Array.isArray(arr).should.equal(true)
177
+ arr.length.should.be.above(0)
178
+ arr.forEach(function (n) { n.should.be.a('number') })
179
+ }
180
+
181
+ it('works with stn enabled', function () {
182
+ networks.enableStn()
183
+ assertPrefixArray(networks.testnet.cashAddrPrefixArray)
184
+ })
185
+
186
+ it('works with regtest enabled', function () {
187
+ networks.enableRegtest()
188
+ assertPrefixArray(networks.testnet.cashAddrPrefixArray)
189
+ })
190
+
191
+ it('works with neither enabled', function () {
192
+ assertPrefixArray(networks.testnet.cashAddrPrefixArray)
193
+ })
194
+
195
+ it('returns a different prefix array per mode', function () {
196
+ var plain = networks.testnet.cashAddrPrefixArray.join(',')
197
+ networks.enableStn()
198
+ var stn = networks.testnet.cashAddrPrefixArray.join(',')
199
+ networks.disableStn()
200
+ networks.enableRegtest()
201
+ var regtest = networks.testnet.cashAddrPrefixArray.join(',')
202
+ stn.should.not.equal(plain)
203
+ regtest.should.not.equal(plain)
204
+ stn.should.not.equal(regtest)
205
+ })
206
+ })
162
207
  })
@@ -253,10 +253,43 @@ describe('PrivateKey', function () {
253
253
  }).to.not.throw()
254
254
  })
255
255
 
256
- it('also accepts an object as argument', function () {
256
+ // This asserted that feeding toJSON() output back into fromObject does NOT throw.
257
+ // Since 7.5.1 toJSON() redacts the secret, and bn.js 4 silently SKIPS characters it
258
+ // cannot parse instead of failing — so the round-trip returned a DIFFERENT key
259
+ // (a deterministic ~40-bit one, trivially recoverable by anyone) with no error at
260
+ // all. The old expectation encoded that as intended behaviour; it is now inverted.
261
+ it('refuses to rebuild a key from redacted toJSON() output', function () {
257
262
  expect(function () {
258
263
  return PrivateKey.fromObject(new PrivateKey().toJSON())
259
- }).to.not.throw()
264
+ }).to.throw(/REDACTED/)
265
+ })
266
+
267
+ it('round-trips exactly through toObject(), which is the real export', function () {
268
+ var key = new PrivateKey()
269
+ PrivateKey.fromObject(key.toObject()).toWIF().should.equal(key.toWIF())
270
+ })
271
+
272
+ it('rejects a malformed bn instead of silently deriving another key', function () {
273
+ // bn.js 4 parses '[REDACTED]' as 768491671261 rather than erroring.
274
+ var cases = ['zzzz', '[REDACTED]', 'nothex', '12g4']
275
+ cases.forEach(function (bad) {
276
+ expect(function () {
277
+ return PrivateKey.fromObject({ bn: bad, compressed: true, network: 'livenet' })
278
+ }).to.throw(/Invalid private key/)
279
+ })
280
+ })
281
+
282
+ it('rejects a bn outside the valid key range', function () {
283
+ expect(function () {
284
+ return PrivateKey.fromObject({ bn: '00'.repeat(32), compressed: true, network: 'livenet' })
285
+ }).to.throw(/outside the range/)
286
+ expect(function () {
287
+ return PrivateKey.fromObject({
288
+ bn: 'FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEBAAEDCE6AF48A03BBFD25E8CD0364142',
289
+ compressed: true,
290
+ network: 'livenet'
291
+ })
292
+ }).to.throw(/outside the range/)
260
293
  })
261
294
  })
262
295
 
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.5.4'
3
+ module.exports = '7.5.6'