@smartledger/bsv 8.3.1 → 9.1.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.
Files changed (169) hide show
  1. package/CHANGELOG.md +228 -0
  2. package/README.md +152 -1031
  3. package/STABILITY.md +134 -0
  4. package/bsv-gdaf.min.js +58 -53
  5. package/bsv-ltp.min.js +23 -18
  6. package/bsv-script-helper.min.js +1 -1
  7. package/bsv-smartcontract.min.js +21 -21
  8. package/bsv.bundle.js +58 -53
  9. package/bsv.d.ts +0 -4
  10. package/bsv.min.js +58 -53
  11. package/docs/BRC220_BATCH_LEAF_AMENDMENT.md +82 -7
  12. package/docs/MODULE_REFERENCE_COMPLETE.md +27 -27
  13. package/docs/README.md +2 -1
  14. package/docs/THREAT_MODEL.md +10 -2
  15. package/docs/advanced/UTXO_MANAGER_GUIDE.md +1 -1
  16. package/docs/getting-started/INSTALLATION.md +23 -23
  17. package/docs/getting-started/QUICK_START.md +7 -7
  18. package/docs/migration/FROM_BSV_1_5_6.md +5 -5
  19. package/docs/proposals/10.0.0-package-split.md +131 -0
  20. package/index.js +15 -26
  21. package/lib/block/merkleblock.js +19 -5
  22. package/lib/covenant/helpers.js +34 -35
  23. package/lib/covenant/pushtx.js +2 -2
  24. package/lib/custom-script-helper.js +0 -16
  25. package/lib/hdprivatekey.js +15 -0
  26. package/lib/ordinals/ordlock.js +1 -1
  27. package/lib/script/interpreter.js +109 -1
  28. package/lib/smart_contract/builder.js +14 -0
  29. package/lib/smart_contract/debugger.js +2 -2
  30. package/lib/smart_contract/dsl.js +2 -2
  31. package/lib/smart_contract/index.js +0 -3
  32. package/lib/smart_contract/locks.js +1 -41
  33. package/lib/smart_contract/pels.js +1 -1
  34. package/lib/smart_contract/token.js +1 -1
  35. package/lib/util/deprecate.js +159 -0
  36. package/package.json +19 -82
  37. package/tools/gen-brc220-batch-vector.js +205 -0
  38. package/version.js +1 -1
  39. package/.mocharc.json +0 -5
  40. package/test/address.js +0 -629
  41. package/test/block/block.js +0 -239
  42. package/test/block/blockheader.js +0 -270
  43. package/test/block/merkleblock.js +0 -207
  44. package/test/build/bundle_crypto_shim.js +0 -104
  45. package/test/build/bundle_externals.js +0 -125
  46. package/test/build/bundle_smoke.js +0 -55
  47. package/test/build/esbuild_main.js +0 -65
  48. package/test/build/esm_wrapper.js +0 -73
  49. package/test/build/exports_resolution.js +0 -84
  50. package/test/build/version_sync.js +0 -14
  51. package/test/cli/smoke.js +0 -261
  52. package/test/consensus/base58-vectors.js +0 -120
  53. package/test/consensus/sv-script-vectors.js +0 -81
  54. package/test/consensus/sv-sighash-vectors.js +0 -51
  55. package/test/consensus/sv-tx-vectors.js +0 -48
  56. package/test/credentials-test.js +0 -332
  57. package/test/crypto/backend_selection.js +0 -126
  58. package/test/crypto/bn.js +0 -168
  59. package/test/crypto/ecdsa.js +0 -426
  60. package/test/crypto/elliptic-fixed.js +0 -61
  61. package/test/crypto/hash.browser.js +0 -121
  62. package/test/crypto/hash.js +0 -122
  63. package/test/crypto/point.js +0 -193
  64. package/test/crypto/random.js +0 -105
  65. package/test/crypto/security.js +0 -176
  66. package/test/crypto/shamir.js +0 -177
  67. package/test/crypto/shamir_rngcap.js +0 -29
  68. package/test/crypto/signature.js +0 -399
  69. package/test/data/bip69.json +0 -215
  70. package/test/data/bitcoin-sv/README.md +0 -170
  71. package/test/data/bitcoin-sv/base58_encode_decode.json +0 -14
  72. package/test/data/bitcoin-sv/base58_keys_invalid.json +0 -152
  73. package/test/data/bitcoin-sv/base58_keys_valid.json +0 -452
  74. package/test/data/bitcoin-sv/script_tests.json +0 -2591
  75. package/test/data/bitcoin-sv/sighash.json +0 -1003
  76. package/test/data/bitcoin-sv/tx_invalid.json +0 -285
  77. package/test/data/bitcoin-sv/tx_valid.json +0 -367
  78. package/test/data/bitcoind/base58_keys_invalid.json +0 -152
  79. package/test/data/bitcoind/base58_keys_valid.json +0 -452
  80. package/test/data/bitcoind/blocks.json +0 -27
  81. package/test/data/bitcoind/script_tests.json +0 -2244
  82. package/test/data/bitcoind/sig_canonical.json +0 -7
  83. package/test/data/bitcoind/sig_noncanonical.json +0 -22
  84. package/test/data/bitcoind/tx_invalid.json +0 -177
  85. package/test/data/bitcoind/tx_valid.json +0 -224
  86. package/test/data/blk86756-testnet.dat +0 -0
  87. package/test/data/blk86756-testnet.js +0 -12
  88. package/test/data/blk86756-testnet.json +0 -684
  89. package/test/data/ecdsa.json +0 -230
  90. package/test/data/merkleblocks.js +0 -486
  91. package/test/data/messages.json +0 -22
  92. package/test/data/sighash.json +0 -1004
  93. package/test/data/tx_creation.json +0 -85
  94. package/test/didweb/relationships.js +0 -144
  95. package/test/ecies/bitcore-ecies.js +0 -178
  96. package/test/ecies/electrum-ecies.js +0 -206
  97. package/test/encoding/base58.js +0 -131
  98. package/test/encoding/base58check.js +0 -145
  99. package/test/encoding/bufferreader.js +0 -328
  100. package/test/encoding/bufferwriter.js +0 -160
  101. package/test/encoding/varint.js +0 -104
  102. package/test/gdaf/anchor_no_key_leak.js +0 -146
  103. package/test/gdaf/anchor_spv.js +0 -163
  104. package/test/gdaf/canonicalization.js +0 -106
  105. package/test/gdaf/canonicalize.js +0 -140
  106. package/test/gdaf/zk_prover.js +0 -204
  107. package/test/hdkeys.js +0 -365
  108. package/test/hdprivatekey.js +0 -339
  109. package/test/hdpublickey.js +0 -293
  110. package/test/index.js +0 -16
  111. package/test/ltp/ids.js +0 -74
  112. package/test/ltp/right.js +0 -198
  113. package/test/ltp/verify_failclosed.js +0 -134
  114. package/test/message/message.js +0 -190
  115. package/test/mnemonic/data/fixtures.json +0 -300
  116. package/test/mnemonic/mnemonic.js +0 -277
  117. package/test/mnemonic/mocha.opts +0 -1
  118. package/test/mnemonic/pbkdf2.test.js +0 -43
  119. package/test/networks.js +0 -207
  120. package/test/notaryhash/batch_leaf.js +0 -140
  121. package/test/notaryhash/certificate.js +0 -249
  122. package/test/notaryhash/encoding.js +0 -186
  123. package/test/notaryhash/interop.js +0 -112
  124. package/test/notaryhash/merkle.js +0 -181
  125. package/test/notaryhash/script.js +0 -270
  126. package/test/notaryhash/verify.js +0 -342
  127. package/test/opcode.js +0 -186
  128. package/test/ordinals/bsv20.js +0 -337
  129. package/test/ordinals/inscription.js +0 -319
  130. package/test/ordinals/ordlock.js +0 -613
  131. package/test/privatekey.js +0 -540
  132. package/test/publickey.js +0 -411
  133. package/test/regressions.js +0 -215
  134. package/test/script/chronicle.js +0 -543
  135. package/test/script/defaults.js +0 -160
  136. package/test/script/genesis_limits.js +0 -203
  137. package/test/script/interpreter.js +0 -776
  138. package/test/script/script.js +0 -1259
  139. package/test/script/string_ops.js +0 -88
  140. package/test/security/fail_closed_contracts.js +0 -104
  141. package/test/security/threat_model_coverage.js +0 -31
  142. package/test/smart_contract/covenants.js +0 -245
  143. package/test/smart_contract/dsl_debugger.js +0 -101
  144. package/test/smart_contract/extract_field.js +0 -61
  145. package/test/smart_contract/nonenforcing_guard.js +0 -44
  146. package/test/smart_contract/ordinal_transfer.js +0 -81
  147. package/test/smart_contract/preimage.js +0 -98
  148. package/test/smart_contract/sighash_marketplace.js +0 -108
  149. package/test/smart_contract/token_generalized.js +0 -185
  150. package/test/spv/headerchain.js +0 -86
  151. package/test/spv/merkleproof.js +0 -133
  152. package/test/statuslist/failclosed.js +0 -78
  153. package/test/transaction/deserialize.js +0 -33
  154. package/test/transaction/input/input.js +0 -92
  155. package/test/transaction/input/multisig.js +0 -174
  156. package/test/transaction/input/multisigscripthash.js +0 -111
  157. package/test/transaction/input/publickey.js +0 -68
  158. package/test/transaction/input/publickeyhash.js +0 -59
  159. package/test/transaction/output.js +0 -185
  160. package/test/transaction/sighash.js +0 -91
  161. package/test/transaction/signature.js +0 -127
  162. package/test/transaction/transaction.js +0 -1299
  163. package/test/transaction/unspentoutput.js +0 -97
  164. package/test/types/dts_drift.js +0 -124
  165. package/test/types/surface_honesty.js +0 -102
  166. package/test/util/id.js +0 -72
  167. package/test/util/js.js +0 -76
  168. package/test/util/preconditions.js +0 -79
  169. package/test/vcjwt/interop.js +0 -126
package/CHANGELOG.md CHANGED
@@ -7,6 +7,234 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
7
7
 
8
8
  ## [Unreleased]
9
9
 
10
+ ## [9.1.0] - 2026-08-23
11
+
12
+ Nothing in this release breaks a caller. That is the release.
13
+
14
+ ### Added — a support commitment, and the mechanism that makes it keepable
15
+
16
+ Between 4.0.0 (2026-05-31) and 9.0.0 (2026-08-21) — 82 days — this library
17
+ published six major versions, part of 83 releases in 307 days. A major is a
18
+ promise that the consumer's code breaks. Made six times a quarter it is a promise
19
+ no team can plan around, and correctness in the releases does not compensate for
20
+ it.
21
+
22
+ The releases were not gratuitous. Most encoded a real finding: Genesis reverted
23
+ `OP_CLTV`/`OP_CSV` to NOPs, so the CLTV locks guaranteed nothing and went in
24
+ 9.0.0; covenant verification was applying pre-Genesis limits and was corrected in
25
+ 8.4.0. Those calls were right. The delivery was the problem — an API found to be
26
+ wrong was changed to `throw` in the same release that found it, which turns every
27
+ correctness fix into a breaking change.
28
+
29
+ **[STABILITY.md](STABILITY.md)** commits 9.x through **2027-09-01**: patch and
30
+ minor only. Two carve-outs, both narrow and stated up front — consensus changes
31
+ track the network in a minor regardless, and an API that can lose funds may throw
32
+ inside a minor.
33
+
34
+ **`lib/util/deprecate.js`** is what makes that affordable. It warns once per API
35
+ per process, records every notice for tooling, is silenced with
36
+ `BSV_NO_DEPRECATION_WARNINGS=1`, and never throws — a deprecation that throws is a
37
+ breaking change wearing a warning's name.
38
+
39
+ ```js
40
+ Klass.prototype.old = deprecate.fn(Klass.prototype.old, {
41
+ what: 'Klass#old', since: '9.1.0', removeIn: '10.0.0',
42
+ use: 'Klass#replacement', why: 'it does not constrain the spend'
43
+ })
44
+ ```
45
+
46
+ Deprecating becomes a non-breaking act belonging in a minor. Correctness fixes
47
+ ship continuously; breakage batches into one planned major whose migration path
48
+ has been in consumers' logs for months.
49
+
50
+ ### Changed — the two APIs that motivated it, resolved differently
51
+
52
+ Both threw with no warning period. The difference between them *is* the policy.
53
+
54
+ | API | 9.1.0 | Why |
55
+ | --- | --- | --- |
56
+ | `MerkleBlock#filterdTxsHash` | warns and delegates | A misspelling of `filteredTxsHash`, one missing letter. Exactly one thing it can mean, so making the typo fix a breaking change bought nothing. Removed in 10.0.0. |
57
+ | `HDPrivateKey#derive` | still throws | Its replacements return **different keys**. No default is safe. |
58
+
59
+ `deriveChild` is BIP32-compliant; `deriveNonCompliantChild` reproduces the old
60
+ unpadded behaviour. Measured over 1600 derivations they disagree **0.5% of the
61
+ time**, only when an intermediate private key serialises to under 32 bytes.
62
+
63
+ That rarity argues for throwing, not against it. A caller handed a guessed default
64
+ would pass every test they wrote and then derive unrecoverable addresses for about
65
+ one wallet in two hundred. A default that is wrong half a percent of the time is
66
+ more dangerous than one wrong always, because nothing catches it. The caller
67
+ chooses, and the error names both options.
68
+
69
+ `SmartContract.Builder`'s `{ allowNonEnforcing: true }` opt-in now says it is
70
+ scheduled for removal in 10.0.0. The throw for callers who did *not* opt in is
71
+ unchanged — a covenant that silently enforces nothing is the fund-loss case.
72
+
73
+ ### Added — the era-flag trap now explains itself
74
+
75
+ Flags and *limits* are separate mechanisms. The era bits are what the interpreter
76
+ derives its element-size, script-size, opcode-count and script-number caps from.
77
+ Hand-assemble a flag word out of named constants — the idiom every pre-Genesis
78
+ tutorial teaches — and you get the feature opcodes you asked for while silently
79
+ keeping the 2019 caps. The script *runs*, so nothing looks wrong until a ~586-byte
80
+ preimage is rejected against a 520-byte limit and the error blames the push.
81
+
82
+ `verify()` now sets `interp.eraHint` and warns once per process when an era-less
83
+ flag word produces an era-derived failure (`PUSH_SIZE`, `SCRIPT_SIZE`, `OP_COUNT`,
84
+ `SCRIPTNUM_OVERFLOW`). Set `Interpreter.eraDiagnostics = false` or
85
+ `BSV_NO_ERA_HINT=1` to silence it.
86
+
87
+ Warning on *every* era-less `verify()` was measured and rejected: about 78% of
88
+ this library's own verifies are legitimately era-less, because the reference
89
+ `script_tests.json` vectors are pre-Genesis by construction. Firing only on the
90
+ intersection lands on ~5% of era-less failures, all genuine pre-Genesis vectors.
91
+
92
+ ### Added — the compatibility promise is now enforced, not remembered
93
+
94
+ A promise nothing checks decays. The failure that matters is not *deciding* to
95
+ break the API but arriving at a major without having decided to, which is how this
96
+ library reached 9.0.0.
97
+
98
+ `scripts/api-surface.js` snapshots the covered surface — 1934 reachable members
99
+ plus the 35 `exports` subpaths — as names, kinds and arities, never values.
100
+ `test/api_surface.js` diffs it: removals fail naming the policy and the fix, shape
101
+ changes fail, and additions fail asking for a deliberate snapshot update so API
102
+ growth shows up in review instead of accumulating. Regenerate with
103
+ `npm run api:snapshot`; `npm run check:api` joins `prepublishOnly`.
104
+
105
+ It deliberately does not walk into `bsv.deps`, which re-exports Node's own
106
+ `Buffer`. Node 20 and 22 disagree on the arity of `Buffer#utf8Write`,
107
+ `#asciiWrite` and `#latin1Write`, and a snapshot that varies by runtime reports
108
+ drift that did not happen.
109
+
110
+ `check-readme-accuracy` gains two checks its own header called impossible: prose
111
+ calling an old version "latest" is mechanical after all — that exact claim
112
+ survived five releases — and the stability badge is now diffed against
113
+ STABILITY.md. Historical references ("Upgrading to v8.0.0", "migrating from 5.x")
114
+ are left alone.
115
+
116
+ ### Changed — what the package says it is, and what it ships
117
+
118
+ The README is **1132 lines to 244**. The covenant stack and the era-flag trap
119
+ lead; the credential subsystems keep an entry point and a link each. The npm
120
+ description and keywords (**79 to 15**) now describe the package rather than
121
+ listing everything it touches.
122
+
123
+ `test/` no longer ships — no consumer runs the library's own suite from
124
+ `node_modules`.
125
+
126
+ | | 9.0.0 | 9.1.0 |
127
+ | --- | ---: | ---: |
128
+ | tarball | 3.1 MB | 2.3 MB |
129
+ | unpacked | 12 MB | 7.9 MB |
130
+
131
+ ### Added — a proposal for 10.0.0
132
+
133
+ `docs/proposals/10.0.0-package-split.md`. Requiring the root costs 129 modules,
134
+ 270ms and 12.7MB of heap to get `Script`, against 24 modules for
135
+ `require('@smartledger/bsv/lib/script')`, and the ESM wrapper re-exports CJS so
136
+ nothing tree-shakes. The proposal is five packages plus a meta-package that keeps
137
+ `require('@smartledger/bsv')` returning exactly what it returns today, so no
138
+ install moves — and a section arguing against doing it at all if the install base
139
+ genuinely uses credentials alongside the Bitcoin surface. Nothing there ships in
140
+ 9.x.
141
+
142
+ ### Verification
143
+
144
+ 4708 tests passing, 452 conformance cases against the reference corpus, on Node 20
145
+ and 22. Every new guard was verified by reintroducing the bug it exists for.
146
+
147
+ ## [9.0.0] - 2026-08-21
148
+
149
+ ### BREAKING — removed APIs that enforced nothing
150
+
151
+ Everything here either did not work on mainnet or had been promised for removal and
152
+ kept shipping. None of it is replaced, because in each case the honest replacement is
153
+ "do not do this".
154
+
155
+ | Removed | Why |
156
+ | --- | --- |
157
+ | `SmartContract.enableGenesis()` | A workaround for the flags bug below. With the era flags present there is nothing for it to do, and what it did — mutating process-wide limit statics — turned 15 of the node's 22 `SCRIPTNUM_OVERFLOW` vectors into false accepts. `Interpreter.useGenesisLimits()` is untouched for callers who really want it. |
158
+ | `SmartContract.Locks.timeLockCLTV` | Built on `OP_CHECKLOCKTIMEVERIFY`, which Genesis reverted to an upgradable NOP. Enforced nothing on mainnet — the coins were spendable immediately. |
159
+ | `SmartContract.Locks.htlc` | Its timeout branch is the same NOP. An HTLC whose timeout does not bind is a hash-lock, which `Locks.hashLock` already provides. |
160
+ | `CustomScriptHelper.createTimelockScript` | Same NOP, third copy. |
161
+ | `bsv.SmartUTXO` (namespace export) | A development-only file-backed simulator on the production namespace. Soft-deprecated in 4.0.1 promising removal in 6.0.0, then shipped through 6.x, 7.x and 8.x still warning. The module is unchanged and still available as `require('@smartledger/bsv/lib/smartutxo')` — what the warning always said to do. |
162
+
163
+ There is now **no time-lock primitive in this library**. That is deliberate: a lock
164
+ that does not lock has no safe use, and the previous versions passed their own tests
165
+ only because the covenant harness verified them under pre-Genesis flags.
166
+
167
+ `SmartContract.Covenant` and `SmartContract.Builder` are **kept**. They are also
168
+ non-enforcing, but they already fail closed — their script-producing methods throw
169
+ unless you pass `allowNonEnforcing: true` — so they cannot silently hand back a script
170
+ that does not do what it looks like.
171
+
172
+ ### Fixed — covenants were verified under pre-Genesis rules
173
+
174
+ `lib/covenant/helpers.js` assembled its verification flags by hand, and the list
175
+ omitted the three **UTXO-era** flags: `SCRIPT_GENESIS`, `SCRIPT_UTXO_AFTER_GENESIS`
176
+ and `SCRIPT_UTXO_AFTER_CHRONICLE`. It did carry `SCRIPT_ENABLE_CHRONICLE`, which
177
+ enables the string opcodes, so the omission was easy to miss — the opcodes ran, and
178
+ only the *limits* were wrong.
179
+
180
+ The interpreter derives its data limits from those era flags. Without them every
181
+ covenant was verified under rules BSV replaced at Genesis in February 2020:
182
+
183
+ | | before | after |
184
+ | --- | ---: | ---: |
185
+ | max stack element | 520 bytes | unbounded |
186
+ | max script size | 10,000 bytes | unbounded |
187
+
188
+ An OP_PUSH_TX preimage is ~585 bytes, so this library's flagship feature could not
189
+ verify against its own harness — it failed with `SCRIPT_ERR_PUSH_SIZE`.
190
+
191
+ `flags()` now delegates to `Interpreter.mainnetFlags()`, the same function a no-flags
192
+ `verify()` uses. Local verification and network behaviour can no longer drift apart
193
+ without both moving together. `SCRIPT_VERIFY_NULLFAIL` is gained (stricter).
194
+
195
+ ### Removed — `SmartContract.enableGenesis()`
196
+
197
+ Now a **deprecated no-op**; the symbol survives one major and goes away in 9.0.0.
198
+
199
+ It existed to paper over the missing era flags by raising the interpreter's
200
+ process-wide limit statics. That was treating the symptom: raising the statics cannot
201
+ enable post-Genesis arithmetic — only the era flags can — and it *weakens* pre-Genesis
202
+ validation, turning 15 of the reference node's 22 `SCRIPTNUM_OVERFLOW` vectors into
203
+ false accepts. With the flags fixed there is nothing for it to do.
204
+
205
+ It is a no-op rather than a passthrough deliberately: restoring the old behaviour as a
206
+ courtesy to existing call sites would reintroduce the defect this release removes.
207
+ `Interpreter.useGenesisLimits()` is untouched for callers who really do want to move
208
+ the statics.
209
+
210
+ **Action:** delete the call. Covenants now verify with no opt-in.
211
+
212
+ ### Disclosed — CLTV time locks do not bind on mainnet
213
+
214
+ Fixing the flags surfaced this. Genesis reverted `OP_CHECKLOCKTIMEVERIFY` to an
215
+ upgradable NOP for outputs created after it, so **`Locks.timeLockCLTV` and the timeout
216
+ branch of `Locks.htlc` enforce nothing on current BSV mainnet** — the coins are
217
+ spendable immediately by the key holder.
218
+
219
+ This was invisible because the covenant harness verified under flags missing the era
220
+ bits. The library's own tests asserted that an early spend was rejected, and passed,
221
+ while the network would have accepted it. That is the failure mode `docs/THREAT_MODEL.md`
222
+ §1 is written around, found in our own code.
223
+
224
+ Both behaviours are now pinned in `test/smart_contract/covenants.js`: the lock does not
225
+ bind under mainnet flags, and still binds under explicitly pre-Genesis flags — so the
226
+ opcode is implemented correctly and the issue is purely which era we verify under. The
227
+ JSDoc on both functions carries the warning, as does the README and the threat model.
228
+
229
+ The functions are kept, not deleted: they remain correct for pre-Genesis outputs and
230
+ useful for interop. **Do not use them to time-lock value on mainnet.**
231
+
232
+ ### Documentation
233
+
234
+ - README: the multisig example destructured `{ CustomScriptHelper }`, which is
235
+ `undefined` — the module exports the class itself and every method is static. The
236
+ `check:readme` gate did not catch it because it only resolves `bsv.*` symbols.
237
+
10
238
  ## [8.3.1] - 2026-08-20
11
239
 
12
240
  ### Fixed — BRC-220 signature verification was not interoperable