@smartledger/bsv 9.7.0 → 9.9.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
@@ -7,6 +7,223 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
7
7
 
8
8
  ## [Unreleased]
9
9
 
10
+ ## [9.9.0] - 2026-09-11
11
+
12
+ **NotaryHash interoperates with the BRC-220 reference implementation, without breaking
13
+ anything in 9.x.** Verification reads both certificate formats. `Certificate.build()`
14
+ writes the reference format given `format: 'reference'`; without it, it still writes
15
+ exactly what 9.8.0 wrote and warns once, as STABILITY.md requires. Against v9.8.0 the
16
+ public API gains 13 names and changes or removes none.
17
+
18
+ ### Fixed — NotaryHash verifies the certificates the BRC-220 reference implementation issues
19
+
20
+ 8.3.0 through 9.8.0 could not verify a single certificate the BRC-220 reference
21
+ implementation issued: `NotaryHash.verify` rejected every one with `unsupported version:
22
+ 1.0`, and the reference could not read this library's either. The cryptography agreed
23
+ throughout — `proofHash`, the signature digest, the RFC 6962 tree and the on-chain record
24
+ are byte-identical — and only the JSON differed. BRC-220 lists a certificate's required
25
+ fields but not their values, and 8.3.0 filled that gap from this implementation alone.
26
+ Every test passed, because every test built its certificates here.
27
+
28
+ | field | 8.3.0–9.8.0 format | reference format |
29
+ | --- | --- | --- |
30
+ | `version` | `1` | `"1.0"` |
31
+ | `mode` | `0` / `1` / `2` | `"full"` / `"hybrid"` |
32
+ | a batch | `mode: 2` | `anchor.type: "batch"`; the mode stays full or hybrid |
33
+ | `encoding` | `"raw"` / `"der"` — the signature's byte form | `"hex"` / `"base64"` — how `publicKey` and `signature` are written |
34
+ | `anchor` | `{ txid, blockHeight }` | `{ type, network, txid, vout, blockHeight, blockTime }` |
35
+ | `merkle.path` | bare hashes | `{ hash, side }`, leaf upward |
36
+
37
+ Verification now reads both formats — `verify()` reports `legacy: true` for the old one —
38
+ and accepts what the reference accepts, each of which 9.8.0 refused:
39
+
40
+ - **High-S ECDSA signatures.** The reference accepts them deliberately. It is safe:
41
+ `proofHash` covers the exact signature bytes, so the malleated form of a signature is a
42
+ *different* certificate, never a forgery of this one — a test asserts exactly that.
43
+ - **DER signatures**, told apart from 64-byte `r ‖ s` by the bytes, and **65-byte
44
+ uncompressed public keys**.
45
+ - **Base64 fields**, including the URL-safe alphabet and missing padding, as the
46
+ reference's `Buffer.from` reads them. Characters outside the alphabet are refused, where
47
+ `Buffer.from` would skip them and decode a corrupted field to different bytes.
48
+ - **A merkle proof on a direct anchor** is checked when present, as the reference checks
49
+ it: accepted if it folds to its stated root, refused if not.
50
+
51
+ One check is added: the supplied header must be the block `spv.blockHash` names. A header
52
+ the proof folds to that is some other block left the certificate's own statement of where
53
+ it was mined unchecked. The reference checks the same. A certificate that passed 9.8.0
54
+ fails it only if its `spv.blockHash` names a different block from the header supplied.
55
+
56
+ ### Deprecated — the default format of `NotaryHash.Certificate.build()`
57
+
58
+ `build()` takes a `format`. `'reference'` (`NotaryHash.Certificate.FORMAT.REFERENCE`)
59
+ writes the reference format; `'legacy'` writes the 8.3.0–9.8.0 one. Omitting it writes the
60
+ legacy format — byte for byte what 9.8.0 wrote, pinned by test against certificates the
61
+ 9.8.0 code itself built — and warns once. **The default becomes `'reference'` in 10.0.0.**
62
+
63
+ ```js
64
+ NotaryHash.Certificate.build({ ...params, format: 'reference' })
65
+ // { version: '1.0', mode: 'full', encoding: 'hex', anchor: { type: 'direct', … }, … }
66
+ ```
67
+
68
+ Per STABILITY.md this is a minor, so what `build()` returns does not change in 9.x, and
69
+ code reading `cert.mode === NotaryHash.MODE.FULL` keeps working. It is the shape of the
70
+ LTP claim canonicalization in 9.2.0, for a similar reason: the default is deterministic and
71
+ agrees with itself, and is not interoperable. The cost here is immediate rather than
72
+ latent — no other BRC-220 verifier can check a default-built certificate — so pass
73
+ `format: 'reference'` for anything issued to someone else. An unrecognised `format` throws
74
+ rather than falling back.
75
+
76
+ `Certificate.VERSION` is still `1`, what the default writes; `Certificate.REFERENCE_VERSION`
77
+ is `'1.0'`. `Certificate.ENCODING` gains `HEX` and `BASE64` beside `RAW` and `DER`.
78
+
79
+ ### Added
80
+
81
+ - `test/notaryhash/reference_certs.js`, over ten certificates produced by the reference
82
+ implementation's own code — full and hybrid, hex and base64, a DER signature, a high-S
83
+ signature, an uncompressed key, and a five-leaf batch. Each verifies here, and each is
84
+ rebuilt byte for byte by `Certificate.build({ format: 'reference' })`. The reference's
85
+ batch is the same tree as the BRC-220 batch vector: same root, same paths.
86
+ - `test/data/notaryhash-9.8.0-certs.json`: certificates built by the 9.8.0 code, which the
87
+ 9.x default must reproduce exactly.
88
+ - `Certificate.FORMAT`, `REFERENCE_VERSION`, `MODE`, `ANCHOR_TYPE`, `DEFAULT_NETWORK`,
89
+ `isLegacy`, `normalize`, `decodeBytes` and `toProofInput`; `Merkle.auditPath`,
90
+ `pathSides`, `rootFromPath` and `verifyAuditPath` for the sided path form.
91
+ - `bsv.d.ts` declares `NotaryHash` in full, with `build()` overloaded on `format`. It was
92
+ 48 of 56 names undeclared, so it could not be used from TypeScript at all; the
93
+ declaration gate now holds it at zero.
94
+
95
+ ### Docs
96
+
97
+ - `docs/BRC220_ENCODING_AMENDMENT.md` is **withdrawn**. It proposed `"raw"`/`"der"` and
98
+ mandatory low-S; the reference contradicts it on every point. It was never filed.
99
+ - `docs/BRC220_BATCH_LEAF_AMENDMENT.md` was confirmed against the reference and filed as
100
+ [bsv-blockchain/BRCs#246](https://github.com/bsv-blockchain/BRCs/pull/246).
101
+ - `test/data/brc220-batch-vector.json` records `encoding: "hex"` and sided paths. The root,
102
+ the rejected-reading root, and every `proofHash` and signature are unchanged.
103
+
104
+ ## [9.8.0] - 2026-09-08
105
+
106
+ **No runtime change.** `git diff v9.7.0..HEAD -- lib/` is empty. Four bundles do differ,
107
+ which looks like a contradiction and is not: reverting `version.js` alone and rebuilding
108
+ reproduces all four **byte-identical to the v9.7.0 release**, so the embedded version
109
+ string is the only changed input and the shifted minifier identifiers are a
110
+ deterministic consequence of it.
111
+
112
+ This release exists because the two things it corrects both ship in the tarball and
113
+ reach nobody until they are published. `bsv.d.ts` is the package's `types` entry, and
114
+ `docs/` is in `files[]`. On 9.7.0 this is a compile error in three places:
115
+
116
+ ```ts
117
+ const i = new bsv.Script.Interpreter() // TS7009: no construct signature
118
+ const w = i.maxScriptNumLength()
119
+ const f = I.mainnetFlags() | I.SCRIPT_UTXO_AFTER_GENESIS // TS2339: does not exist
120
+ const n = new bsv.crypto.BN(0) // TS2554: expected 0 arguments
121
+ ```
122
+
123
+ ### Fixed — `docs/preimage.md` was wrong in ways that cost money
124
+
125
+ The page ships in the npm tarball and is linked from the README, and people build
126
+ covenants from it. It gave the preimage as **~108 bytes** when it is 182 — 156 fixed
127
+ plus a length-prefixed `scriptCode` — and its own arithmetic said 181 because it
128
+ counted a 25-byte script without the varint that precedes it.
129
+
130
+ Every byte offset from the txid onward was wrong. `outpoint.txid` was labelled 32
131
+ bytes over a 28-byte range, and everything after it shifted by three or four:
132
+ `hashOutputs` was given as starting at 139 when it starts at 142.
133
+
134
+ **Four of its seven Script fragments did not work**, run against a real preimage:
135
+
136
+ | fragment | result |
137
+ | --- | --- |
138
+ | `hashPrevouts`: `4 OP_SPLIT OP_DROP 32 OP_SPLIT OP_DROP` | `SCRIPT_ERR_INVALID_SPLIT_RANGE` — `OP_DROP` keeps the wrong half |
139
+ | `hashOutputs`: `<len-44>` | reads `nSequence` and the first 28 bytes of the hash |
140
+ | `amount`: `40 OP_SPLIT` | a literal offset landing inside `hashPrevouts` |
141
+ | `nSequence`: `12 OP_SPLIT` | likewise |
142
+
143
+ It showed `hashSequence` as `00…00` for an ordinary `0x41` signature. It is only zero
144
+ under `ANYONECANPAY`, `NONE` or `SINGLE`, and the page now carries the measured table
145
+ for all five combinations — which matters, because a covenant reading `hashOutputs`
146
+ without pinning the sighash type is checking 32 zero bytes.
147
+
148
+ And it recommended `OP_BIN2NUM` on `amount`, `nSequence` and `nLockTime`, which are
149
+ **unsigned**. That is the defect fixed in 9.4.0, recommended as practice:
150
+
151
+ ```
152
+ nLockTime ffffffff -> -2147483647 should be 4294967295 (year 2106)
153
+ 01000080 -> -1 should be 2147483649
154
+ 00000080 -> 0 should be 2147483648 (19 Jan 2038)
155
+ ```
156
+
157
+ `nSequence` is `0xffffffff` more often than not, so that one is wrong today rather
158
+ than in 2038.
159
+
160
+ Two things the page said that were not merely inaccurate but backwards:
161
+
162
+ - **"Re-hash the preimage (`OP_HASH256`) to verify it matches what was signed."** It
163
+ does not. `OP_HASH256` yields a hash and nothing else; a spender can supply any 182
164
+ well-formed bytes, satisfy every field check, and spend on a different transaction.
165
+ The binding comes from `OP_CHECKSIG` over a signature constructed from the preimage
166
+ hash — which is what `OP_PUSH_TX` does and what the page now describes.
167
+ - **The 32-byte hashes were called "big-endian"**, inviting someone to reverse them.
168
+ They are the bytes `HASH256()` returns. The only reversed field is the txid inside
169
+ the outpoint.
170
+
171
+ Also: `scriptCode` is not "usually `scriptPubKey`" — it is variable, `OP_CODESEPARATOR`
172
+ moves it, and covenant scripts make it hundreds of bytes, which is why every extraction
173
+ this library ships reads from the END of the preimage rather than by absolute offset.
174
+ The page now says so and gives the from-end offsets: `amount` 52, `nSequence` 44,
175
+ `hashOutputs` 40, `nLockTime` 8, `sighashType` 4.
176
+
177
+ It opens with the Chronicle caveat, since BIP-143 is no longer the only digest
178
+ algorithm on this chain.
179
+
180
+ **`test/covenant/preimage_doc.js` asserts the page** — 24 cases covering every offset,
181
+ every fragment, the zero-hash table, the `OP_BIN2NUM` figures and the authentication
182
+ claim, all against a preimage the library actually produces. Reintroducing the old
183
+ `hashOutputs` offset of 44 fails it.
184
+
185
+ ### Fixed — the consensus API was uncallable from TypeScript
186
+
187
+ Everything added across 9.4.0 to 9.7.0 shipped with no declaration. `bsv.d.ts` said
188
+ one thing about the interpreter — a `verify()` returning boolean — so
189
+ `interp.maxScriptNumLength()` was a compile error, the instance had no `errstr` and
190
+ no `stack`, and not one of the era flags existed as a name.
191
+
192
+ `crypto.BN` was worse: `class BN { }`, an empty declaration. `new BN(0)` did not
193
+ compile and every satoshi amount in the public API widened to `{}`, which is what
194
+ made the interpreter unusable rather than merely undocumented.
195
+
196
+ Both are now declared in full: the interpreter's twenty instance members and
197
+ fifty-four statics, and BN's constructor, comparisons, arithmetic and the Bitcoin
198
+ codecs (`fromScriptNumBuffer`, `toScriptNumBuffer`, `fromSM`, `toSM`). bn.js's own
199
+ internals — the `red`/`mont` modular-arithmetic family, the in-place `i*` mutators —
200
+ are deliberately left out: they are inherited, not this library's contract.
201
+
202
+ The declarations are exercised, not just written. `types-test/positive.ts` now
203
+ constructs an interpreter both ways, reads every era method and moves the stack
204
+ ceiling; `negative.ts` gained five cases that must fail, including calling an
205
+ instance method on the constructor and assigning `checkStackLimits()` to a boolean.
206
+ A declaration that quietly degrades to `any` makes those errors vanish.
207
+
208
+ ### Added — `npm run check:dts`, a declaration-coverage ratchet
209
+
210
+ `check:types` proves the declarations that exist are correct. Nothing measured the
211
+ surface that was never declared at all, which is how four consecutive releases
212
+ shipped an API no TypeScript consumer could call.
213
+
214
+ `scripts/check-dts-coverage.js` compares `test/fixtures/api-surface.json` against
215
+ `bsv.d.ts` and fails when a name is added to the runtime with no declaration, when a
216
+ name is declared but still sits in the baseline (the ratchet only turns one way), or
217
+ when a namespace listed as COMPLETE develops a gap. `bsv.Script.Interpreter` is the
218
+ first entry in that list, at zero.
219
+
220
+ Coverage is **934 of 1,946 names, 48.0%**. The remaining 1,012 are recorded in
221
+ `test/fixtures/dts-coverage-baseline.json` so the number is visible rather than
222
+ implied — `bsv.Opcode` and its 110 constants are the largest block left.
223
+
224
+ The gate's first act was to reject a claim of mine: I listed `crypto.BN` as complete
225
+ and it named the 69 bn.js internals I had not declared.
226
+
10
227
  ## [9.7.0] - 2026-09-05
11
228
 
12
229
  ### Fixed — the stack limits diverged from the node in both directions
package/README.md CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  Bitcoin SV library with an interpreter-verified script engine.
4
4
 
5
- [![Version](https://img.shields.io/badge/version-9.7.0-blue.svg)](https://www.npmjs.com/package/@smartledger/bsv)
5
+ [![Version](https://img.shields.io/badge/version-9.9.0-blue.svg)](https://www.npmjs.com/package/@smartledger/bsv)
6
6
  [![License](https://img.shields.io/badge/license-MIT-green.svg)](LICENSE)
7
7
  [![Stability](https://img.shields.io/badge/9.x%20stable%20until-2027--09--01-brightgreen.svg)](STABILITY.md)
8
8
 
@@ -155,44 +155,44 @@ const bsv = require('@smartledger/bsv') // 128 modules
155
155
  ### **Core Modules**
156
156
  | Module | Size | Use Case | CDN |
157
157
  |--------|------|----------|-----|
158
- | **bsv.min.js** | 1046KB | Core BSV + SmartContract | `unpkg.com/@smartledger/bsv@9.7.0/bsv.min.js` |
159
- | **bsv.bundle.js** | 1046KB | Everything in one file | `unpkg.com/@smartledger/bsv@9.7.0/bsv.bundle.js` |
158
+ | **bsv.min.js** | 1056KB | Core BSV + SmartContract | `unpkg.com/@smartledger/bsv@9.9.0/bsv.min.js` |
159
+ | **bsv.bundle.js** | 1056KB | Everything in one file | `unpkg.com/@smartledger/bsv@9.9.0/bsv.bundle.js` |
160
160
 
161
161
  ### **W3C Verifiable Credentials**
162
162
  | Module | Size | Use Case | CDN |
163
163
  |--------|------|----------|-----|
164
- | **🟢 bsv-didweb.min.js** | 166KB | **DID:web generation** | `unpkg.com/@smartledger/bsv@9.7.0/bsv-didweb.min.js` |
165
- | **🟢 bsv-vcjwt.min.js** | 166KB | **VC-JWT issue/verify** | `unpkg.com/@smartledger/bsv@9.7.0/bsv-vcjwt.min.js` |
166
- | **🟢 bsv-statuslist.min.js** | 256KB | **StatusList2021 revocation** | `unpkg.com/@smartledger/bsv@9.7.0/bsv-statuslist.min.js` |
167
- | **🟢 bsv-anchor.min.js** | 164KB | **BSV anchoring (hash-only)** | `unpkg.com/@smartledger/bsv@9.7.0/bsv-anchor.min.js` |
164
+ | **🟢 bsv-didweb.min.js** | 166KB | **DID:web generation** | `unpkg.com/@smartledger/bsv@9.9.0/bsv-didweb.min.js` |
165
+ | **🟢 bsv-vcjwt.min.js** | 166KB | **VC-JWT issue/verify** | `unpkg.com/@smartledger/bsv@9.9.0/bsv-vcjwt.min.js` |
166
+ | **🟢 bsv-statuslist.min.js** | 256KB | **StatusList2021 revocation** | `unpkg.com/@smartledger/bsv@9.9.0/bsv-statuslist.min.js` |
167
+ | **🟢 bsv-anchor.min.js** | 164KB | **BSV anchoring (hash-only)** | `unpkg.com/@smartledger/bsv@9.9.0/bsv-anchor.min.js` |
168
168
 
169
169
  ### **Smart Contract & Development**
170
170
  | Module | Size | Use Case | CDN |
171
171
  |--------|------|----------|-----|
172
- | **bsv-smartcontract.min.js** | 141KB | Complete covenant framework | `unpkg.com/@smartledger/bsv@9.7.0/bsv-smartcontract.min.js` |
173
- | **bsv-covenant.min.js** | 35KB | Covenant operations | `unpkg.com/@smartledger/bsv@9.7.0/bsv-covenant.min.js` |
174
- | **bsv-script-helper.min.js** | 33KB | Custom script tools | `unpkg.com/@smartledger/bsv@9.7.0/bsv-script-helper.min.js` |
175
- | **bsv-security.min.js** | 32KB | Security enhancements | `unpkg.com/@smartledger/bsv@9.7.0/bsv-security.min.js` |
172
+ | **bsv-smartcontract.min.js** | 141KB | Complete covenant framework | `unpkg.com/@smartledger/bsv@9.9.0/bsv-smartcontract.min.js` |
173
+ | **bsv-covenant.min.js** | 35KB | Covenant operations | `unpkg.com/@smartledger/bsv@9.9.0/bsv-covenant.min.js` |
174
+ | **bsv-script-helper.min.js** | 33KB | Custom script tools | `unpkg.com/@smartledger/bsv@9.9.0/bsv-script-helper.min.js` |
175
+ | **bsv-security.min.js** | 32KB | Security enhancements | `unpkg.com/@smartledger/bsv@9.9.0/bsv-security.min.js` |
176
176
 
177
177
  ### **Legal & Compliance**
178
178
  | Module | Size | Use Case | CDN |
179
179
  |--------|------|----------|-----|
180
- | **bsv-ltp.min.js** | 540KB | Legal Token Protocol | `unpkg.com/@smartledger/bsv@9.7.0/bsv-ltp.min.js` |
181
- | **bsv-gdaf.min.js** | 1046KB | Digital Identity & Attestation | `unpkg.com/@smartledger/bsv@9.7.0/bsv-gdaf.min.js` |
180
+ | **bsv-ltp.min.js** | 540KB | Legal Token Protocol | `unpkg.com/@smartledger/bsv@9.9.0/bsv-ltp.min.js` |
181
+ | **bsv-gdaf.min.js** | 1056KB | Digital Identity & Attestation | `unpkg.com/@smartledger/bsv@9.9.0/bsv-gdaf.min.js` |
182
182
 
183
183
  ### **Advanced Cryptography**
184
184
  | Module | Size | Use Case | CDN |
185
185
  |--------|------|----------|-----|
186
- | **bsv-shamir.min.js** | 177KB | Threshold Cryptography | `unpkg.com/@smartledger/bsv@9.7.0/bsv-shamir.min.js` |
186
+ | **bsv-shamir.min.js** | 177KB | Threshold Cryptography | `unpkg.com/@smartledger/bsv@9.9.0/bsv-shamir.min.js` |
187
187
 
188
188
  ### **Utilities**
189
189
  | Module | Size | Use Case | CDN |
190
190
  |--------|------|----------|-----|
191
- | **bsv-ecies.min.js** | 137KB | Encryption | `unpkg.com/@smartledger/bsv@9.7.0/bsv-ecies.min.js` |
192
- | **bsv-message.min.js** | 34KB | Message signing | `unpkg.com/@smartledger/bsv@9.7.0/bsv-message.min.js` |
193
- | **bsv-mnemonic.min.js** | 320KB | HD wallets | `unpkg.com/@smartledger/bsv@9.7.0/bsv-mnemonic.min.js` |
191
+ | **bsv-ecies.min.js** | 137KB | Encryption | `unpkg.com/@smartledger/bsv@9.9.0/bsv-ecies.min.js` |
192
+ | **bsv-message.min.js** | 34KB | Message signing | `unpkg.com/@smartledger/bsv@9.9.0/bsv-message.min.js` |
193
+ | **bsv-mnemonic.min.js** | 320KB | HD wallets | `unpkg.com/@smartledger/bsv@9.9.0/bsv-mnemonic.min.js` |
194
194
  ```html
195
- <script src="https://unpkg.com/@smartledger/bsv@9.7.0/bsv.min.js"></script>
195
+ <script src="https://unpkg.com/@smartledger/bsv@9.9.0/bsv.min.js"></script>
196
196
  <script>
197
197
  const key = bsv.PrivateKey.fromRandom()
198
198
  </script>
@@ -240,4 +240,4 @@ MIT
240
240
 
241
241
  ---
242
242
 
243
- **SmartLedger-BSV v9.7.0**
243
+ **SmartLedger-BSV v9.9.0**