@smartledger/bsv 8.3.0 → 9.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.
Files changed (47) hide show
  1. package/CHANGELOG.md +133 -0
  2. package/README.md +374 -222
  3. package/bsv-gdaf.min.js +49 -49
  4. package/bsv-script-helper.min.js +1 -1
  5. package/bsv-smartcontract.min.js +21 -21
  6. package/bsv.bundle.js +49 -49
  7. package/bsv.d.ts +0 -4
  8. package/bsv.min.js +49 -49
  9. package/docs/BRC220_BATCH_LEAF_AMENDMENT.md +194 -0
  10. package/docs/BRC220_PLAN.md +9 -0
  11. package/docs/MODULE_REFERENCE_COMPLETE.md +27 -27
  12. package/docs/README.md +2 -1
  13. package/docs/THREAT_MODEL.md +10 -2
  14. package/docs/advanced/UTXO_MANAGER_GUIDE.md +1 -1
  15. package/docs/getting-started/INSTALLATION.md +23 -23
  16. package/docs/getting-started/QUICK_START.md +7 -7
  17. package/docs/migration/FROM_BSV_1_5_6.md +5 -5
  18. package/index.js +10 -26
  19. package/lib/covenant/helpers.js +34 -35
  20. package/lib/covenant/pushtx.js +2 -2
  21. package/lib/custom-script-helper.js +0 -16
  22. package/lib/notaryhash/index.js +20 -0
  23. package/lib/notaryhash/merkle.js +8 -0
  24. package/lib/notaryhash/suites.js +17 -1
  25. package/lib/ordinals/ordlock.js +1 -1
  26. package/lib/smart_contract/debugger.js +2 -2
  27. package/lib/smart_contract/dsl.js +2 -2
  28. package/lib/smart_contract/index.js +0 -3
  29. package/lib/smart_contract/locks.js +1 -41
  30. package/lib/smart_contract/pels.js +1 -1
  31. package/lib/smart_contract/token.js +1 -1
  32. package/package.json +3 -2
  33. package/test/build/esm_wrapper.js +32 -8
  34. package/test/data/brc220-batch-vector.json +129 -0
  35. package/test/notaryhash/batch_leaf.js +140 -0
  36. package/test/notaryhash/batch_vector.js +282 -0
  37. package/test/notaryhash/interop.js +112 -0
  38. package/test/notaryhash/verify.js +5 -2
  39. package/test/ordinals/inscription.js +24 -14
  40. package/test/ordinals/ordlock.js +0 -46
  41. package/test/smart_contract/covenants.js +0 -38
  42. package/test/smart_contract/dsl_debugger.js +0 -9
  43. package/test/smart_contract/ordinal_transfer.js +0 -10
  44. package/test/smart_contract/sighash_marketplace.js +0 -10
  45. package/test/smart_contract/token_generalized.js +0 -10
  46. package/tools/gen-brc220-batch-vector.js +205 -0
  47. package/version.js +1 -1
package/CHANGELOG.md CHANGED
@@ -7,6 +7,139 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
7
7
 
8
8
  ## [Unreleased]
9
9
 
10
+ ## [9.0.0] - 2026-08-21
11
+
12
+ ### BREAKING — removed APIs that enforced nothing
13
+
14
+ Everything here either did not work on mainnet or had been promised for removal and
15
+ kept shipping. None of it is replaced, because in each case the honest replacement is
16
+ "do not do this".
17
+
18
+ | Removed | Why |
19
+ | --- | --- |
20
+ | `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. |
21
+ | `SmartContract.Locks.timeLockCLTV` | Built on `OP_CHECKLOCKTIMEVERIFY`, which Genesis reverted to an upgradable NOP. Enforced nothing on mainnet — the coins were spendable immediately. |
22
+ | `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. |
23
+ | `CustomScriptHelper.createTimelockScript` | Same NOP, third copy. |
24
+ | `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. |
25
+
26
+ There is now **no time-lock primitive in this library**. That is deliberate: a lock
27
+ that does not lock has no safe use, and the previous versions passed their own tests
28
+ only because the covenant harness verified them under pre-Genesis flags.
29
+
30
+ `SmartContract.Covenant` and `SmartContract.Builder` are **kept**. They are also
31
+ non-enforcing, but they already fail closed — their script-producing methods throw
32
+ unless you pass `allowNonEnforcing: true` — so they cannot silently hand back a script
33
+ that does not do what it looks like.
34
+
35
+ ### Fixed — covenants were verified under pre-Genesis rules
36
+
37
+ `lib/covenant/helpers.js` assembled its verification flags by hand, and the list
38
+ omitted the three **UTXO-era** flags: `SCRIPT_GENESIS`, `SCRIPT_UTXO_AFTER_GENESIS`
39
+ and `SCRIPT_UTXO_AFTER_CHRONICLE`. It did carry `SCRIPT_ENABLE_CHRONICLE`, which
40
+ enables the string opcodes, so the omission was easy to miss — the opcodes ran, and
41
+ only the *limits* were wrong.
42
+
43
+ The interpreter derives its data limits from those era flags. Without them every
44
+ covenant was verified under rules BSV replaced at Genesis in February 2020:
45
+
46
+ | | before | after |
47
+ | --- | ---: | ---: |
48
+ | max stack element | 520 bytes | unbounded |
49
+ | max script size | 10,000 bytes | unbounded |
50
+
51
+ An OP_PUSH_TX preimage is ~585 bytes, so this library's flagship feature could not
52
+ verify against its own harness — it failed with `SCRIPT_ERR_PUSH_SIZE`.
53
+
54
+ `flags()` now delegates to `Interpreter.mainnetFlags()`, the same function a no-flags
55
+ `verify()` uses. Local verification and network behaviour can no longer drift apart
56
+ without both moving together. `SCRIPT_VERIFY_NULLFAIL` is gained (stricter).
57
+
58
+ ### Removed — `SmartContract.enableGenesis()`
59
+
60
+ Now a **deprecated no-op**; the symbol survives one major and goes away in 9.0.0.
61
+
62
+ It existed to paper over the missing era flags by raising the interpreter's
63
+ process-wide limit statics. That was treating the symptom: raising the statics cannot
64
+ enable post-Genesis arithmetic — only the era flags can — and it *weakens* pre-Genesis
65
+ validation, turning 15 of the reference node's 22 `SCRIPTNUM_OVERFLOW` vectors into
66
+ false accepts. With the flags fixed there is nothing for it to do.
67
+
68
+ It is a no-op rather than a passthrough deliberately: restoring the old behaviour as a
69
+ courtesy to existing call sites would reintroduce the defect this release removes.
70
+ `Interpreter.useGenesisLimits()` is untouched for callers who really do want to move
71
+ the statics.
72
+
73
+ **Action:** delete the call. Covenants now verify with no opt-in.
74
+
75
+ ### Disclosed — CLTV time locks do not bind on mainnet
76
+
77
+ Fixing the flags surfaced this. Genesis reverted `OP_CHECKLOCKTIMEVERIFY` to an
78
+ upgradable NOP for outputs created after it, so **`Locks.timeLockCLTV` and the timeout
79
+ branch of `Locks.htlc` enforce nothing on current BSV mainnet** — the coins are
80
+ spendable immediately by the key holder.
81
+
82
+ This was invisible because the covenant harness verified under flags missing the era
83
+ bits. The library's own tests asserted that an early spend was rejected, and passed,
84
+ while the network would have accepted it. That is the failure mode `docs/THREAT_MODEL.md`
85
+ §1 is written around, found in our own code.
86
+
87
+ Both behaviours are now pinned in `test/smart_contract/covenants.js`: the lock does not
88
+ bind under mainnet flags, and still binds under explicitly pre-Genesis flags — so the
89
+ opcode is implemented correctly and the issue is purely which era we verify under. The
90
+ JSDoc on both functions carries the warning, as does the README and the threat model.
91
+
92
+ The functions are kept, not deleted: they remain correct for pre-Genesis outputs and
93
+ useful for interop. **Do not use them to time-lock value on mainnet.**
94
+
95
+ ### Documentation
96
+
97
+ - README: the multisig example destructured `{ CustomScriptHelper }`, which is
98
+ `undefined` — the module exports the class itself and every method is static. The
99
+ `check:readme` gate did not catch it because it only resolves `bsv.*` symbols.
100
+
101
+ ## [8.3.1] - 2026-08-20
102
+
103
+ ### Fixed — BRC-220 signature verification was not interoperable
104
+
105
+ `lib/notaryhash/suites.js` set `endian: 'little'` before verifying, which made
106
+ ECDSA reverse the 32-byte `payloadHash` before reducing it to a scalar. That is
107
+ Bitcoin's message-signing convention, not this protocol's.
108
+
109
+ The effect was on the **verify** side. A signature produced the way BRC-220
110
+ describes — over the `payloadHash` directly — was **rejected**, and the only
111
+ signatures accepted were ones made with bsv's own byte-reversed convention. In
112
+ practice 8.3.0 could not verify a certificate from any other implementation.
113
+
114
+ Signing was never affected: `ECDSA.sign(payloadHash, key)` already produced a
115
+ conformant signature. Only the verifier disagreed with it.
116
+
117
+ **If you issued certificates with 8.3.0**, they are fine — the signatures in them
118
+ are whatever your signer produced. If you signed via `ECDSA` with
119
+ `endian: 'little'` to satisfy the old verifier, those signatures are
120
+ non-conformant and must be re-issued; 8.3.1 rejects them, deliberately, because
121
+ accepting both conventions would mean two valid signatures exist for one signing
122
+ act and both are inside `proofHash`.
123
+
124
+ ### Why the tests did not catch it
125
+
126
+ Every NotaryHash test signed through `lib/crypto/ecdsa.js` and verified through a
127
+ suite that used the same file, so the module and its tests were self-consistent
128
+ and wrong together — the failure shape `test/notaryhash/encoding.js` warns about
129
+ in its own header comment.
130
+
131
+ `test/notaryhash/interop.js` is new and verifies against `@noble/curves`, which
132
+ shares no verification code with ours. Reverting the one-line fix fails 9 tests.
133
+ It also records the trap that made this slow to diagnose: noble v2 **prehashes by
134
+ default**, so `secp256k1.sign(digest, key)` signs `sha256(digest)` and looks
135
+ self-consistent while disagreeing with everyone; every call in that file passes
136
+ `{ prehash: false }`.
137
+
138
+ ### Documentation
139
+
140
+ - The README's NotaryHash example now shows the signing step explicitly, and says
141
+ why no `endian` option belongs there.
142
+
10
143
  ## [8.3.0] - 2026-08-16
11
144
 
12
145
  ### BRC-220 (NotaryHash)