smartledger-bsv 4.0.1 → 4.2.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,112 @@ 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.2.0] - 2026-06-07
9
+
10
+ ### Added
11
+
12
+ - **First-class, interpreter-verified covenants under `bsv.SmartContract`.**
13
+ A complete, tested stack of custom locking scripts that verify end-to-end
14
+ through `Script.Interpreter` (positive and negative cases), building on the
15
+ post-Genesis limits from 4.1.0:
16
+ - **`SmartContract.PushTx`** — a *correct* OP_PUSH_TX (nChain WP1605). The
17
+ locking script generates an ECDSA signature in-script from the pushed
18
+ preimage (`a=k=1`, `r=Gx`, `s=(e+Gx) mod n`, pubkey `02||Gx`) and verifies
19
+ it with `OP_CHECKSIG`, proving the preimage is this very transaction. Uses a
20
+ fixed-length DER template with an `nLockTime` grind (`PushTx.grind`). Exposes
21
+ `authenticator()`, `valueCovenant()`, `hashOutputs()`, `extractHashOutputs()`.
22
+ - **`SmartContract.PELS` / `perpetualCovenant(fee)`** — a Perpetually Enforcing
23
+ Locking Script: every spend must recreate the same script (value − fee).
24
+ Reads its own script from the authenticated preimage's `scriptCode`, so there
25
+ is no self-hash circularity.
26
+ - **`SmartContract.Token` / `ownershipToken(fee, ownerHash)`** — a stateful
27
+ ownership token (NFT) carrying its owner as on-chain state; transfer requires
28
+ the owner's secret and rewrites the state, perpetuating the token code.
29
+ - **`SmartContract.Locks`** — hash-lock, P2PKH, CLTV time-lock, m-of-n
30
+ multisig, and HTLC primitives.
31
+ - **`SmartContract.CovenantHelpers`** + convenience methods
32
+ `enableGenesis()`, `verifyScript()`, `valueCovenant()` — a consensus-flag
33
+ `verify()` harness, raw BIP-143 preimage access, signing, and fund/spend
34
+ scaffolding.
35
+ - New mocha suite `test/smart_contract/covenants.js` (11 specs / 24 assertions),
36
+ all green; full suite 4178 → 4189 passing.
37
+
38
+ ### Notes
39
+
40
+ - These covenants require post-Genesis limits: call `SmartContract.enableGenesis()`
41
+ (a.k.a `Interpreter.useGenesisLimits()`) before verifying. Research-grade and
42
+ interpreter-verified — review before mainnet value (the OP_PUSH_TX key is the
43
+ intentionally public `a=k=1`; low-S malleability is left unenforced).
44
+
45
+ ## [4.1.0] - 2026-06-07
46
+
47
+ ### Added
48
+
49
+ - **`Interpreter.useGenesisLimits([max])` — one-call opt-in for
50
+ post-Genesis BSV consensus.** The bundled `Script.Interpreter`
51
+ hardcoded the *pre-Genesis* consensus caps that BSV removed at the
52
+ Genesis upgrade (February 2020): 520-byte stack elements, 4-byte
53
+ script numbers, 201 non-push opcodes per script. Those caps make this
54
+ library's own flagship features impossible to evaluate — OP_PUSH_TX
55
+ covenants push a ~585-byte preimage element, do 32-byte modular
56
+ arithmetic (`OP_ADD`/`OP_MOD`), and run a few hundred opcodes.
57
+
58
+ ```js
59
+ // Default: bound the limits to a safe ceiling.
60
+ // 64 KB covers every covenant pattern seen in production and blocks
61
+ // memory-exhaustion via oversized pushes from untrusted scripts.
62
+ bsv.Script.Interpreter.useGenesisLimits(64 * 1024)
63
+
64
+ // Or fully unbounded (~2 GB) — only safe for trusted scripts:
65
+ // bsv.Script.Interpreter.useGenesisLimits()
66
+ ```
67
+
68
+ Defaults are unchanged out of the box (520 / 4 / 201) — existing
69
+ consumers see zero behavior change unless they opt in. The call
70
+ mutates static properties on the `Interpreter` constructor and
71
+ therefore affects every subsequent `new Interpreter()` in the
72
+ process; treat it as an app-startup setting, not per-request.
73
+
74
+ - **`Interpreter.MAX_OPS_PER_SCRIPT`** exposed as a named constant
75
+ (= 201). Replaces the two hardcoded `> 201` checks in `Interpreter.step`.
76
+
77
+ - **`bsv.d.ts`** now types `Interpreter.MAX_SCRIPT_ELEMENT_SIZE`,
78
+ `MAXIMUM_ELEMENT_SIZE`, `MAX_OPS_PER_SCRIPT`, and `useGenesisLimits()`.
79
+
80
+ ### Fixed
81
+
82
+ - **`Interpreter.MAXIMUM_ELEMENT_SIZE` was a dead knob in the numeric
83
+ opcodes.** The constant was defined as `4` but never threaded into the
84
+ `BN.fromScriptNumBuffer(buf, fRequireMinimal, size)` calls in
85
+ `OP_ADD`/`OP_SUB`/`OP_MUL`/`OP_DIV`/`OP_MOD`/`OP_BOOLAND`/`OP_BOOLOR`/
86
+ `OP_NUMEQUAL`/`OP_NUMEQUALVERIFY`/`OP_NUMNOTEQUAL`/`OP_LESSTHAN`/
87
+ `OP_GREATERTHAN`/`OP_LESSTHANOREQUAL`/`OP_GREATERTHANOREQUAL`/`OP_MIN`/
88
+ `OP_MAX` (binary) and `OP_WITHIN` (ternary). The 3rd `size` argument was
89
+ always omitted, so BN fell back to its own 4-byte default — raising
90
+ `Interpreter.MAXIMUM_ELEMENT_SIZE` above 4 had no effect. Now threaded
91
+ through, so the knob actually does what its name implies.
92
+
93
+ ### Tests
94
+
95
+ - Added `test/script/genesis_limits.js` (6 tests) covering defaults,
96
+ the lift, rejection of >4-byte arithmetic and >201 opcodes under
97
+ defaults, and acceptance of both after `useGenesisLimits()`. Full
98
+ suite: **4178 passing, 0 failing**.
99
+
100
+ ### Docs
101
+
102
+ - README §"Evaluating covenants locally" — one-paragraph mention of
103
+ the new API in the covenant/smart-contract section.
104
+ - JSDoc on `useGenesisLimits` calls out the process-wide-mutation
105
+ semantics and recommends bounded ceilings for untrusted input.
106
+ - CDN/install refs bumped `@4.0.1` → `@4.1.0` across README + 6 docs
107
+ files.
108
+
109
+ ### Semver
110
+
111
+ Minor bump — purely additive: a new public method and a fixed-but-was-
112
+ dead constant. No existing API or default behavior changes.
113
+
8
114
  ## [4.0.1] - 2026-05-31
9
115
 
10
116
  ### Deprecated