@smartledger/bsv 9.16.0 → 9.18.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,195 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
7
7
 
8
8
  ## [Unreleased]
9
9
 
10
+ ## [9.18.0] - 2026-10-03
11
+
12
+ 9.17.0 was committed but never published to npm; its contents are included here. The version
13
+ number is skipped on the registry rather than reused, so a reader comparing git to npm cannot find
14
+ two different 9.17.0s.
15
+
16
+ ### Fixed — `NotaryHash.verifySignature` reported a missing `createdAt` as a signature failure
17
+
18
+ It derived its inputs from `Certificate.toProofInput`, which also decodes `createdAt` because the
19
+ proofHash commits to the creation time. **The signature does not.** So on a certificate with no
20
+ `createdAt`, `toUnixSeconds(undefined)` threw, the function's `try/catch` turned that into `false`,
21
+ and the caller was told the signature did not match its payloadHash and public key.
22
+
23
+ That is the one answer a caller cannot act on correctly. `verifySignature` returning `false` means
24
+ exactly one thing to every reader — the cryptography does not check out — so the remedy they reach
25
+ for is their key, their digest convention or their endian handling. On this library that has
26
+ historically been the right place to look, which makes the misdirection worse rather than better.
27
+
28
+ The regression arrived with the BRC-220 reference format work; 9.3.0 answered `true` for all of
29
+ these. Measured, identical inputs:
30
+
31
+ | certificate | 9.3.0 | 9.16.1 | 9.18.0 |
32
+ |---|---|---|---|
33
+ | no `createdAt` | true | **false** | true |
34
+ | with `createdAt` | true | true | true |
35
+ | `anchor: {txid}`, no `createdAt` | true | **false** | true |
36
+ | `anchor: {}`, no `createdAt` | true | **false** | true |
37
+
38
+ `Certificate.toSignatureInput` now returns only the five fields a signature check uses, and
39
+ `toProofInput` builds on it by adding `createdAtUnix`. Nothing that should fail now passes: a
40
+ signature over a different digest, a different public key, a flipped byte, a truncated signature
41
+ and a certificate missing `signature`, `publicKey` or `payloadHash` are all still `false`.
42
+ **Certificate completeness is unchanged** — `Certificate.validateShape` lists every missing
43
+ required field by name, and `NotaryHash.verify` runs it first and returns before the signature
44
+ check, so a certificate with no `createdAt` is still not a valid certificate.
45
+
46
+ ### Added — `NotaryHash.verifySignatureOnly(payloadHash, signature, publicKey, algorithm?)`
47
+
48
+ For the case that exposed the bug: verifying a submitted signature **before** spending anything to
49
+ anchor it, when no certificate exists yet and so there is no `createdAt`, `proofHash` or `anchor`.
50
+ Certificate metadata cannot influence the answer because none is passed.
51
+
52
+ It takes Buffers or hex, and **throws** on input it cannot decode rather than returning `false`. A
53
+ boolean that means both "the signature does not match" and "your hex was malformed" is the
54
+ ambiguity this entry point exists to remove, and a pre-flight check is where acting on the wrong
55
+ one costs money.
56
+
57
+ Reported with a complete reproduction by the ordinals mint that anchors BRC-220 proofs, which hit
58
+ it as a pre-anchor check rejecting every valid submission with a 400.
59
+
60
+ ## [9.17.0] - 2026-10-03
61
+
62
+ ### Deprecated — `Script.fromHex` accepts a string that does not decode whole
63
+
64
+ `Buffer.from(str, 'hex')` stops at the first character it cannot decode — including the trailing
65
+ nibble of an odd-length string — and returns what it had. So `Script.fromHex` has always answered
66
+ a malformed string with a **shorter script, or none, and no error**:
67
+
68
+ ```js
69
+ Script.fromHex('<html>503</html>') // 0 bytes
70
+ Script.fromHex('76a91') // 2 bytes, the last nibble dropped
71
+ Script.fromHex('<p2pkh hex>' + '\nmore') // the 25-byte prefix, still a valid P2PKH
72
+ ```
73
+
74
+ A caller that builds an output from the result pays to a truncated script with nothing to tell it,
75
+ and `Transaction#addOutput` accepts a zero-byte script without complaint. `Script.fromString`,
76
+ directly below it in the source, has always refused non-hex with `JSUtil.isHexa`; this function
77
+ never did.
78
+
79
+ The damage is bounded in one useful way: **truncation can only drop a suffix.** It cannot alter the
80
+ bytes it did decode, so an address derived from the result is always the one the input's leading
81
+ bytes named, never a third party's. That makes this a correctness problem rather than a theft one.
82
+
83
+ A string that does not decode whole now emits a deprecation notice naming the replacement, once per
84
+ process. **Nothing throws and no verdict changes**; the notice is the whole change. `10.0.0` will
85
+ refuse it, which under STABILITY.md cannot land before 2027-09-01.
86
+
87
+ Callers wanting the strict behaviour today should check the round trip, which separates every
88
+ truncating input from every whole one:
89
+
90
+ ```js
91
+ if (Script.fromHex(h).toHex() !== h.toLowerCase()) throw new Error('not whole hex')
92
+ ```
93
+
94
+ Found while answering a downstream consumer about an upgrade: its paymail resolver passes a remote
95
+ host's string to `Script.fromHex`. That consumer was not exposed — it gates the result on
96
+ `isPublicKeyHashOut()` — but it had no help from this library in getting there.
97
+
98
+
99
+ ### Changed — `@noble/curves`, `@noble/hashes` and `@noble/ciphers` to `^2.4.0`
100
+
101
+ The declared range was already `^2.3.0`, so a fresh consumer install had been resolving 2.4.0
102
+ while the shipped bundles still inlined 2.3.0. This release realigns them: the floor moves to
103
+ `^2.4.0` and the bundles are a reproducible build of it. All three declare `engines` of
104
+ `node >= 20.19.0`, unchanged, so the supported runtime floor does not move. Five bundles grew by
105
+ 2-3 KB.
106
+
107
+ ## [9.16.1] - 2026-10-01
108
+
109
+ Three resource and validation defects in the shift and binary-conversion opcodes, found by a
110
+ differential fuzzer run against this package and by independent review of the first fix. The
111
+ conformance corpus passes 1483/1483 before and after: every one of these was invisible to it.
112
+
113
+ ### Security — `OP_LSHIFT` and `OP_RSHIFT` did work proportional to the shift COUNT
114
+
115
+ Both built the shifted value as a bignum and then truncated it, so `ushln(n)` allocated a value of
116
+ the shifted width — the count's magnitude, not the operand's. A short script could therefore buy
117
+ an unbounded amount of work from a verifier, in **every era**, since a count of 2^31-1 fits the
118
+ four bytes allowed before Genesis, and `IsOpcodeDisabled` in the node disables only `OP_2MUL`
119
+ and `OP_2DIV` — never the shifts. Confirmed by execution: a pre-Genesis `OP_LSHIFT` with a count
120
+ of 2^31-1 is accepted and returns one zero byte. Past a certain count the implied length is not a valid array
121
+ length and bn.js raised a `RangeError`, which the evaluator reported as
122
+ `SCRIPT_ERR_UNKNOWN_ERROR`. **That is a false reject**, not merely a slow one: the node returns
123
+ zero bytes for the same script, so this library refused spends the node accepts. So the path had
124
+ two faults at once — unbounded work, and a wrong verdict in the direction of refusal. No false
125
+ accept was found on this path; the false accept in this release is the separate empty-operand bug
126
+ below.
127
+
128
+ Both opcodes now follow the node's shape, which bounds the work by the operand:
129
+
130
+ ```cpp
131
+ CScriptNum n{top, requireMinimal, params.MaxScriptNumLength(), utxo_after_genesis};
132
+ if(n < 0) return SCRIPT_ERR_INVALID_NUMBER_RANGE;
133
+ if(n >= values.size() * bits_per_byte) fill(begin(values), end(values), 0);
134
+ else { ... LShift(values, n.getint()) ... }
135
+ ```
136
+
137
+ The count is compared as a bignum before any narrowing, and a shift reaching the operand's full
138
+ width returns that many zero bytes directly. The node's `LShift` allocates
139
+ `valtype result(x.size(), 0x00)` and loops over `x.size()`; nothing it allocates follows the
140
+ count. Verified against the previous implementation on 719,360 operand-and-count pairs — every value at
141
+ operand lengths 1 to 4, sampled above 4096 per length, at every count from 0 to 8·len+4, both
142
+ directions — and against an independent bit-string model. That equivalence covers the **valid
143
+ counts for which the previous implementation completed**, and over those the output is
144
+ byte-identical. It deliberately does not cover the counts that previously threw, or the
145
+ empty-operand counts in the next section, where the verdict changes on purpose; both are covered
146
+ by their own tests.
147
+
148
+ ### Security — an invalid shift count was accepted whenever the operand was empty
149
+
150
+ Both opcodes short-circuited when the value being shifted was empty, popping the count without
151
+ decoding it, and therefore without any of its three checks. A negative count, a count too wide for
152
+ the era, and a non-minimally-encoded count were all accepted, where the node refuses each by name.
153
+ **A false accept.** The node's only guard before the decode is `stack.size() < 2`, and it checks
154
+ `n < 0` before it reads the operand at all.
155
+
156
+ This one was found by review of the first shift fix, which corrected the cost and left this in
157
+ place.
158
+
159
+ ### Fixed — `OP_NUM2BIN`'s size was not bounded by `INT32_MAX`
160
+
161
+ The node caps it in every era, **before** the element-size test:
162
+
163
+ ```cpp
164
+ if(n < 0 || n > std::numeric_limits<int32_t>::max()) return SCRIPT_ERR_PUSH_SIZE;
165
+ const auto size{n.to_size_t_limited()};
166
+ if(!utxo_after_genesis && (size > MAX_SCRIPT_ELEMENT_SIZE_BEFORE_GENESIS))
167
+ return SCRIPT_ERR_PUSH_SIZE;
168
+ ```
169
+
170
+ The era only widens the second test; the first is fixed. Without it a size above `INT32_MAX`
171
+ passed the post-Genesis element check, which is effectively unbounded, and the allocation that
172
+ followed was proportional to the operand's **value** rather than its length. A size the node
173
+ refuses without allocating is now refused the same way, and the bound is checked on the bignum
174
+ before narrowing, because `toNumber()` rounds past 2^53 and returns `Infinity` at extreme widths
175
+ rather than failing.
176
+
177
+ **This cap matches the node; it does not make the opcode cheap.** A size just under `INT32_MAX` is
178
+ consensus-valid and still requests an allocation approaching 2 GB, from a script of a few bytes —
179
+ so a limit on script size does not address it. **This release adds no execution or allocation
180
+ budget, and this package enforces none.** Evaluating untrusted scripts therefore needs a bound on
181
+ execution resources, not just on input size: run it in a process whose memory and CPU time are
182
+ capped, or do not evaluate untrusted scripts in a process you need to keep alive.
183
+
184
+ ### Note on `OP_DIV` and `OP_MOD`
185
+
186
+ Both are quadratic in operand length. **This is not a consensus divergence, and it is not fixed in
187
+ this release.** The node shares the shape: `OP_DIV`/`OP_MOD` are bounded only by
188
+ `params.MaxScriptNumLength()` and its `bsv::bint` division is also schoolbook, so verdicts and
189
+ bounds match and changing ours would diverge from consensus.
190
+
191
+ Parity settles the verdict, not the cost. **Quadratic CPU exhaustion remains a risk when
192
+ evaluating attacker-controlled scripts**, and the node's practical protection is policy rather
193
+ than consensus — `DEFAULT_MAX_SCRIPT_SIZE_POLICY_AFTER_GENESIS` of 500 KB and
194
+ `DEFAULT_STACK_MEMORY_USAGE_POLICY_AFTER_GENESIS` of 100 MB. Neither is a CPU-time bound, and this
195
+ package enforces neither. Measured here: 320 KB of operand takes about 18 seconds, growing by
196
+ roughly 4× per doubling. Bound execution resources yourself, as above. An opt-in budget is under
197
+ consideration and will not change default behaviour.
198
+
10
199
  ## [9.16.0] - 2026-10-01
11
200
 
12
201
  ### Security — `OP_CHECKMULTISIG`'s counts were decoded with the era's length, not four bytes
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.16.0-blue.svg)](https://www.npmjs.com/package/@smartledger/bsv)
5
+ [![Version](https://img.shields.io/badge/version-9.18.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** | 1062KB | Core BSV + SmartContract | `unpkg.com/@smartledger/bsv@9.16.0/bsv.min.js` |
159
- | **bsv.bundle.js** | 1062KB | Everything in one file | `unpkg.com/@smartledger/bsv@9.16.0/bsv.bundle.js` |
158
+ | **bsv.min.js** | 1065KB | Core BSV + SmartContract | `unpkg.com/@smartledger/bsv@9.18.0/bsv.min.js` |
159
+ | **bsv.bundle.js** | 1065KB | Everything in one file | `unpkg.com/@smartledger/bsv@9.18.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.16.0/bsv-didweb.min.js` |
165
- | **🟢 bsv-vcjwt.min.js** | 166KB | **VC-JWT issue/verify** | `unpkg.com/@smartledger/bsv@9.16.0/bsv-vcjwt.min.js` |
166
- | **🟢 bsv-statuslist.min.js** | 256KB | **StatusList2021 revocation** | `unpkg.com/@smartledger/bsv@9.16.0/bsv-statuslist.min.js` |
167
- | **🟢 bsv-anchor.min.js** | 164KB | **BSV anchoring (hash-only)** | `unpkg.com/@smartledger/bsv@9.16.0/bsv-anchor.min.js` |
164
+ | **🟢 bsv-didweb.min.js** | 166KB | **DID:web generation** | `unpkg.com/@smartledger/bsv@9.18.0/bsv-didweb.min.js` |
165
+ | **🟢 bsv-vcjwt.min.js** | 166KB | **VC-JWT issue/verify** | `unpkg.com/@smartledger/bsv@9.18.0/bsv-vcjwt.min.js` |
166
+ | **🟢 bsv-statuslist.min.js** | 256KB | **StatusList2021 revocation** | `unpkg.com/@smartledger/bsv@9.18.0/bsv-statuslist.min.js` |
167
+ | **🟢 bsv-anchor.min.js** | 164KB | **BSV anchoring (hash-only)** | `unpkg.com/@smartledger/bsv@9.18.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.16.0/bsv-smartcontract.min.js` |
173
- | **bsv-covenant.min.js** | 35KB | Covenant operations | `unpkg.com/@smartledger/bsv@9.16.0/bsv-covenant.min.js` |
174
- | **bsv-script-helper.min.js** | 33KB | Custom script tools | `unpkg.com/@smartledger/bsv@9.16.0/bsv-script-helper.min.js` |
175
- | **bsv-security.min.js** | 32KB | Security enhancements | `unpkg.com/@smartledger/bsv@9.16.0/bsv-security.min.js` |
172
+ | **bsv-smartcontract.min.js** | 141KB | Complete covenant framework | `unpkg.com/@smartledger/bsv@9.18.0/bsv-smartcontract.min.js` |
173
+ | **bsv-covenant.min.js** | 35KB | Covenant operations | `unpkg.com/@smartledger/bsv@9.18.0/bsv-covenant.min.js` |
174
+ | **bsv-script-helper.min.js** | 33KB | Custom script tools | `unpkg.com/@smartledger/bsv@9.18.0/bsv-script-helper.min.js` |
175
+ | **bsv-security.min.js** | 32KB | Security enhancements | `unpkg.com/@smartledger/bsv@9.18.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** | 542KB | Legal Token Protocol | `unpkg.com/@smartledger/bsv@9.16.0/bsv-ltp.min.js` |
181
- | **bsv-gdaf.min.js** | 1062KB | Digital Identity & Attestation | `unpkg.com/@smartledger/bsv@9.16.0/bsv-gdaf.min.js` |
180
+ | **bsv-ltp.min.js** | 544KB | Legal Token Protocol | `unpkg.com/@smartledger/bsv@9.18.0/bsv-ltp.min.js` |
181
+ | **bsv-gdaf.min.js** | 1065KB | Digital Identity & Attestation | `unpkg.com/@smartledger/bsv@9.18.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.16.0/bsv-shamir.min.js` |
186
+ | **bsv-shamir.min.js** | 177KB | Threshold Cryptography | `unpkg.com/@smartledger/bsv@9.18.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.16.0/bsv-ecies.min.js` |
192
- | **bsv-message.min.js** | 34KB | Message signing | `unpkg.com/@smartledger/bsv@9.16.0/bsv-message.min.js` |
193
- | **bsv-mnemonic.min.js** | 320KB | HD wallets | `unpkg.com/@smartledger/bsv@9.16.0/bsv-mnemonic.min.js` |
191
+ | **bsv-ecies.min.js** | 139KB | Encryption | `unpkg.com/@smartledger/bsv@9.18.0/bsv-ecies.min.js` |
192
+ | **bsv-message.min.js** | 34KB | Message signing | `unpkg.com/@smartledger/bsv@9.18.0/bsv-message.min.js` |
193
+ | **bsv-mnemonic.min.js** | 320KB | HD wallets | `unpkg.com/@smartledger/bsv@9.18.0/bsv-mnemonic.min.js` |
194
194
  ```html
195
- <script src="https://unpkg.com/@smartledger/bsv@9.16.0/bsv.min.js"></script>
195
+ <script src="https://unpkg.com/@smartledger/bsv@9.18.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.16.0**
243
+ **SmartLedger-BSV v9.18.0**