@smartledger/bsv 3.4.5 → 4.0.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.
package/CHANGELOG.md CHANGED
@@ -5,6 +5,128 @@ All notable changes to SmartLedger-BSV will be documented in this file.
5
5
  The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
6
6
  and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7
7
 
8
+ ## [4.0.0] - 2026-05-31
9
+
10
+ ### Security
11
+
12
+ This release fixes three critical vulnerabilities in the GDAF Verifiable
13
+ Credential signing/verification path. **Any credential signed by a version
14
+ prior to 4.0.0 should be considered unprotected and re-issued, and any
15
+ verification result produced by a prior version should be considered
16
+ untrustworthy.** See the Breaking Changes note below.
17
+
18
+ - **Credential signatures now cover the entire credential body, including
19
+ nested claims (e.g. `credentialSubject`).** `AttestationSigner._canonicalizeJSON`
20
+ previously called `JSON.stringify(obj, Object.keys(obj).sort())`. The second
21
+ argument is the JSON.stringify *replacer array*, which whitelists keys at
22
+ **every** nesting level to the top-level key set; every nested object
23
+ therefore serialized to `{}` and was excluded from the signed hash. An
24
+ attacker could rewrite the subject's identity and claims without
25
+ invalidating the proof. Canonicalization is now a recursive, depth-complete
26
+ key sort (`AttestationSigner._sortValue`).
27
+
28
+ - **The signature is now actually checked during verification.**
29
+ `AttestationVerifier._verifySignature` and `_verifyPresentationSignature`
30
+ assigned `var valid = ecdsa.verify()`. `ECDSA.prototype.verify()` returns the
31
+ ECDSA *instance* (always truthy), not a boolean, so the `if (valid)` branch
32
+ always passed — credentials and presentations were accepted regardless of
33
+ whether the signature was valid, or present at all. Both sites now read
34
+ `ecdsa.verify().verified`.
35
+
36
+ - **The signing key is now bound to the claimed issuer (issuer-spoofing fix).**
37
+ `_verifySignature` resolved the public key from the attacker-controlled
38
+ `proof.verificationMethod` and never compared it to `credential.issuer`. A
39
+ valid signature from any DID was accepted while the credential named a
40
+ different (e.g. trusted) authority as issuer. Verification now requires the
41
+ DID owning `proof.verificationMethod` to equal the credential issuer
42
+ (`AttestationVerifier._normalizeDID`, supporting both string and `{ id }`
43
+ issuer forms).
44
+
45
+ - **Removed a live private key from the published package.**
46
+ `utilities/wallet.json` shipped a valid mainnet WIF
47
+ (`KwbaQqFU…`, address `15XJXD7CSMqHL2ivFCu8PZTACQQ8MPbWY9`). The file has
48
+ been deleted and removed from the `files` allow-list. The dev utilities that
49
+ used it (`utilities/wallet-setup.js`, `utxo-manager.js`, `blockchain-state.js`)
50
+ already generate/import a local `wallet.json` at runtime and tolerate its
51
+ absence. **The published key must be considered compromised — do not reuse
52
+ it or send funds to that address.**
53
+
54
+ - **`trustedIssuers` is now enforced instead of advisory.** When a
55
+ `trustedIssuers` allow-list is passed to `verifyCredential`, an issuer outside
56
+ the list is now a hard verification failure (previously only a warning, so the
57
+ list had no effect). Comparison is done on normalized DIDs.
58
+
59
+ Regression coverage added in `test/gdaf/canonicalize.js` (8 tests): nested-key
60
+ coverage, key-order independence, array-order significance, tamper-detection at
61
+ the hash level, an untampered sign/verify round-trip, rejection of an
62
+ issuer-spoofed credential, enforcement of the `trustedIssuers` allow-list, and
63
+ rejection of a post-signing nested-claim tamper.
64
+
65
+ ### Changed
66
+
67
+ - **Constant-time MAC comparison in Electrum/BIE1 ECIES** (`lib/ecies/electrum-ecies.js`).
68
+ The decrypt path compared the authentication tag with `Buffer.equals()`, which
69
+ short-circuits on the first differing byte and can leak how many leading bytes
70
+ matched. Replaced with an unconditional byte-wise compare (matching the
71
+ existing loop in `bitcore-ecies.js`). Behaviour is unchanged for valid and
72
+ invalid tags.
73
+ - **Simplified ECDSA signature verification** (`lib/crypto/ecdsa.js#sigError`).
74
+ Removed a redundant s-canonicalization step and an unreachable
75
+ "backwards-compatibility" retry branch (because `(r, s)` and `(r, n - s)`
76
+ always verify identically, the retry could never succeed where the primary
77
+ check failed). Out-of-range rejection of `r`/`s` is retained. Accept/reject
78
+ results are byte-for-byte identical to 3.4.5; low-S is still enforced at
79
+ signing time via `ECDSA.toLowS`.
80
+
81
+ ### Removed
82
+
83
+ - Dropped the inaccurate `vulnerability-free` and `security-hardened` npm
84
+ keywords. `bsv.isHardened` and `bsv.securityFeatures` remain but only describe
85
+ opt-in helpers, as documented in `index.js` and the README Security section.
86
+
87
+ ### Tests / Tooling
88
+
89
+ - **The test runner now executes the whole suite.** mocha 8 dropped support for
90
+ `test/mocha.opts`, so its `--recursive` flag was silently ignored and
91
+ `npm test` only ran the 10 top-level `test/*.js` files (534 tests) — the ~40
92
+ files under `test/crypto`, `test/script`, `test/transaction`, `test/gdaf`,
93
+ etc. never ran in CI. Added `.mocharc.json` (`recursive`, `spec:
94
+ test/**/*.js`) and removed the defunct `test/mocha.opts`. `npm test` now runs
95
+ the full suite (4172 passing, 0 failing), including the new GDAF security
96
+ tests.
97
+ - **Repaired `test/crypto/security.js`.** It was 0 passing / 8 failing in 3.4.5
98
+ (missing `require('chai').should()`, plus calls to a non-existent
99
+ `SmartVerify.verifySignature`, `Signature.validate()` used as if it returned a
100
+ boolean rather than throwing, and an invalid TXID fixture). Rewritten against
101
+ the real API (`SmartVerify.smartVerify`, `Signature#validate/isCanonical/
102
+ toCanonical`); now 12 passing.
103
+ - **Fixed the 18 pre-existing failures that recursion surfaced** (all failed on
104
+ a pristine 3.4.5 checkout; the full suite is now green at 4172 passing):
105
+ - 3 in `test/crypto/ecdsa.js` — `ECDSA#sigError` did not reject negative
106
+ `r`/`s`. Tightened the range check to `[1, n-1]` (`lte(0)` now covers
107
+ negative and zero); negative-value DER vectors are correctly rejected as
108
+ 'r and s not in range'. (Real correctness fix, in `lib/crypto/ecdsa.js`.)
109
+ - 14 in `test/script/interpreter.js` — stale upstream Bitcoin Core vectors
110
+ asserting `DISABLED_OPCODE` for CAT/SPLIT/NUM2BIN/BIN2NUM/AND/OR/XOR/DIV/MOD
111
+ (re-enabled in BSV at Genesis) and `BAD_OPCODE` for `0xba` (which is OP_NOP8
112
+ in this build). The vendored `script_tests.json` is left untouched; a
113
+ documented `BSV_DIVERGENCES` override in the harness records each divergence
114
+ and asserts the correct BSV result.
115
+ - 1 in `test/script/script.js` — expected byte `0xba` to disassemble as raw
116
+ hex, but `0xba` is `OP_NOP8` in this build's opcode table; updated to the
117
+ correct disassembly with an explanatory comment.
118
+
119
+ ### Breaking Changes
120
+
121
+ - The bytes that get signed have changed (nested claims are now included), so
122
+ credentials and presentations signed by **≤ 3.4.5 will no longer verify**
123
+ under 4.0.0. This is intentional: the previous signatures did not protect
124
+ those bytes. Re-issue affected credentials with 4.0.0.
125
+ - Verification is now strict: callers relying on the previous (broken)
126
+ behaviour where verification effectively always succeeded will see
127
+ legitimate failures for unsigned, mis-signed, or issuer-mismatched
128
+ credentials.
129
+
8
130
  ## [3.4.5] - 2026-05-29
9
131
 
10
132
  ### Fixed