@smartledger/bsv 7.4.0 → 7.5.1

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,134 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
7
7
 
8
8
  ## [Unreleased]
9
9
 
10
+ ## [7.5.1] - 2026-08-06
11
+
12
+ Three defects reported from the field against 7.4.0, each reproduced here before
13
+ being fixed. All three return or publish a key other than the one the caller
14
+ intended. **Anyone using `GDAF.anchorCredential` or `anchorBatch` should treat any
15
+ key passed to them as compromised and rotate it.**
16
+
17
+ ### Fixed (security)
18
+
19
+ - **`GDAF.anchorCredential` and `anchorBatch` published the caller's private key in
20
+ the OP_RETURN.** The wrappers take `(payload, privateKey, options)` while the
21
+ underlying `SmartLedgerAnchor` methods take `(payload, metadata, utxos)`, and every
22
+ wrapper forwarded `privateKey` into a slot that is not a key. For these two it
23
+ landed in `metadata`, which is `JSON.stringify`-ed straight into the anchor payload
24
+ — and `PrivateKey.prototype.toJSON` emitted the secret scalar as hex. The key was
25
+ therefore recoverable from chain data: reconstructing it from the OP_RETURN yields
26
+ an **identical WIF and address**, so an observer can spend the funds.
27
+
28
+ The anchor already holds the key it was constructed with, so the wrappers no longer
29
+ forward it. `options` is now `{ utxos, metadata }`; a bare UTXO array is still
30
+ accepted, since that was the only shape that previously produced a transaction.
31
+ `registerDID` and `revokeCredential` shared the argument-order defect but put the
32
+ key in the `utxos` slot, where they died on `utxos.reduce` — they never leaked, and
33
+ are corrected too.
34
+
35
+ Defence in depth: `_createAnchorPayload` now refuses to serialise a `PrivateKey`
36
+ instance or any key-shaped field (`bn`, `wif`, `privateJwk`, `seed`, `xprv`, ...),
37
+ so reaching the payload builder with key material fails loudly instead of
38
+ broadcasting it.
39
+
40
+ - **`PrivateKey.prototype.toJSON` no longer emits the secret scalar.** It was the same
41
+ function as `toObject`, so *anything* that stringified a key — a log line, an error
42
+ dump, a request body, or the anchor path above — published it. `JSON.stringify(key)`
43
+ now yields `bn: '[REDACTED]'`. `toObject()` is unchanged and remains the deliberate
44
+ export, so `PrivateKey.fromObject(key.toObject())` still round-trips exactly.
45
+
46
+ - **`PrivateKey.fromString(str, network)` honours `network` instead of discarding it.**
47
+ It accepted the argument and ignored it, so `fromString(hex, 'testnet')` returned a
48
+ livenet key and therefore a **mainnet address** — funds sent there land on the wrong
49
+ network. The failure was intermittent because `toAddress(network)` does honour its
50
+ own argument. For a WIF, which encodes its own network, a conflicting `network` now
51
+ throws rather than being silently overridden.
52
+
53
+ - **`PrivateKey.fromHex` / `fromBuffer` agree with the constructor.**
54
+ `_transformBNBuffer` hardcoded `compressed: false` while every other path — random
55
+ keys, hex strings, compressed WIF — produced `true`, so `PrivateKey.fromHex(h)` and
56
+ `new PrivateKey(h)` returned **different addresses and different WIFs for identical
57
+ input**. Restore a key by the wrong route and you derive an address you never funded.
58
+ A raw 32-byte scalar carries no compression information, so the default now matches
59
+ the rest of the library; pass `compressed = false` explicitly for the legacy form.
60
+
61
+ ### Changed
62
+
63
+ - `bsv.d.ts`: `fromString`/`fromWIF` take an optional `network`; `fromHex`/`fromBuffer`
64
+ take optional `network` and `compressed`; `toObject()` and `toJSON()` have distinct
65
+ return types so the redaction is visible to TypeScript; the GDAF anchoring methods
66
+ declare `AnchorOptions | Utxo[]` and return `Promise`. Verified under `tsc --strict`.
67
+
68
+ - Two tests asserted that `JSON.stringify(privateKey)` emits the scalar, encoding the
69
+ unsafe behaviour as intent. They now assert the opposite, while still checking that
70
+ `toObject()` round-trips exactly.
71
+
72
+ ### Breaking
73
+
74
+ `JSON.stringify(privateKey)` no longer contains the key; use `toObject()` or `toWIF()`
75
+ where the export is intended. `PrivateKey.fromHex`/`fromBuffer` on a 32-byte scalar now
76
+ default to compressed, changing the derived address and WIF — pass `false` for the old
77
+ behaviour. The GDAF anchoring wrappers no longer accept a private key in the `options`
78
+ position, and reject key material in `metadata`.
79
+
80
+ Suite 4544 → 4559.
81
+
82
+ ## [7.5.0] - 2026-08-05
83
+
84
+ ### Fixed
85
+
86
+ - **`useGenesisLimits()` now lifts the total script size cap, which it previously
87
+ could not.** The cap was a literal inside `Interpreter.prototype.evaluate`,
88
+ carrying its own `// TODO: script size should be configurable. no magic numbers`:
89
+
90
+ ```js
91
+ if (this.script.toBuffer().length > 10000) {
92
+ ```
93
+
94
+ So a caller who opted into post-Genesis limits still hit a **pre-Genesis 10,000
95
+ byte ceiling** — the function said "post-Genesis limits" and enforced one of the
96
+ limits Genesis removed. Any script above 10 KB failed `SCRIPT_ERR_SCRIPT_SIZE`
97
+ no matter what was asked for, which put a sizeable 1Sat Ordinals inscription out
98
+ of reach of the interpreter entirely: transferring one could not be verified by
99
+ this library at all, in any version, and callers were pushed into checking the
100
+ ECDSA signature against the sighash by hand.
101
+
102
+ The cap is now `Interpreter.MAX_SCRIPT_SIZE`, still defaulting to the
103
+ pre-Genesis 10,000, and `useGenesisLimits()` raises it along with the other
104
+ three. Two limits bite at different sizes and the regression test pins both: a
105
+ 3 KB inscription loads and fails on the 520-byte push cap
106
+ (`SCRIPT_ERR_PUSH_SIZE`), while a 50 KB one is refused before evaluation begins
107
+ (`SCRIPT_ERR_SCRIPT_SIZE`).
108
+
109
+ ### Added
110
+
111
+ - **`Interpreter.getLimits()` / `Interpreter.setLimits()`** — capture and restore
112
+ the four caps as a unit. The caps are process-wide statics, so anything that
113
+ raises them must put them back or it silently changes the rules for unrelated
114
+ code later in the same process. Five test files were each restoring three caps
115
+ by hand, which would have quietly leaked the new fourth one into the bitcoind
116
+ consensus fixtures; they now use the pair.
117
+
118
+ - Regression coverage for the case that prompted this: signing a large inscription
119
+ transfer over the **full previous locking script** (envelope included, which is
120
+ the script code the network uses), verifying it through the interpreter under
121
+ Genesis limits, and confirming the interpreter agrees with a direct
122
+ signature-against-sighash check. A companion test asserts the trap: a signature
123
+ made over the **base lock alone** verifies against its own preimage and fails the
124
+ real one, so that mistake cannot pass unnoticed.
125
+
126
+ ### Note on defaults
127
+
128
+ Post-Genesis limits remain **opt-in**. Making them the default was measured, not
129
+ assumed: it fails **19 bitcoind consensus fixtures** that assert oversized pushes,
130
+ excess opcodes and oversized numerics must be rejected. Those fixtures encode
131
+ pre-Genesis consensus and share the same process-wide statics, so the default
132
+ cannot move while the caps are global. Making the limits per-`Interpreter` policy
133
+ is the real fix and is deliberately not attempted here — it changes a
134
+ consensus-critical evaluation path and deserves its own change.
135
+
136
+ Suite 4536 → 4544.
137
+
10
138
  ## [7.4.0] - 2026-08-05
11
139
 
12
140
  Completes BSV-21 coverage. 7.3.0 taught the parser every operation the specification
package/README.md CHANGED
@@ -186,42 +186,42 @@ console.log('Status:', status) // 'revoked'
186
186
  ### **Core Modules**
187
187
  | Module | Size | Use Case | CDN |
188
188
  |--------|------|----------|-----|
189
- | **bsv.min.js** | 1149KB | Core BSV + SmartContract | `unpkg.com/@smartledger/bsv@7.4.0/bsv.min.js` |
190
- | **bsv.bundle.js** | 1149KB | Everything in one file | `unpkg.com/@smartledger/bsv@7.4.0/bsv.bundle.js` |
189
+ | **bsv.min.js** | 1149KB | Core BSV + SmartContract | `unpkg.com/@smartledger/bsv@7.5.1/bsv.min.js` |
190
+ | **bsv.bundle.js** | 1149KB | Everything in one file | `unpkg.com/@smartledger/bsv@7.5.1/bsv.bundle.js` |
191
191
 
192
192
  ### **W3C Verifiable Credentials**
193
193
  | Module | Size | Use Case | CDN |
194
194
  |--------|------|----------|-----|
195
- | **🟢 bsv-didweb.min.js** | 315KB | **DID:web generation** | `unpkg.com/@smartledger/bsv@7.4.0/bsv-didweb.min.js` |
196
- | **🟢 bsv-vcjwt.min.js** | 315KB | **VC-JWT issue/verify** | `unpkg.com/@smartledger/bsv@7.4.0/bsv-vcjwt.min.js` |
197
- | **🟢 bsv-statuslist.min.js** | 415KB | **StatusList2021 revocation** | `unpkg.com/@smartledger/bsv@7.4.0/bsv-statuslist.min.js` |
198
- | **🟢 bsv-anchor.min.js** | 314KB | **BSV anchoring (hash-only)** | `unpkg.com/@smartledger/bsv@7.4.0/bsv-anchor.min.js` |
195
+ | **🟢 bsv-didweb.min.js** | 315KB | **DID:web generation** | `unpkg.com/@smartledger/bsv@7.5.1/bsv-didweb.min.js` |
196
+ | **🟢 bsv-vcjwt.min.js** | 315KB | **VC-JWT issue/verify** | `unpkg.com/@smartledger/bsv@7.5.1/bsv-vcjwt.min.js` |
197
+ | **🟢 bsv-statuslist.min.js** | 415KB | **StatusList2021 revocation** | `unpkg.com/@smartledger/bsv@7.5.1/bsv-statuslist.min.js` |
198
+ | **🟢 bsv-anchor.min.js** | 314KB | **BSV anchoring (hash-only)** | `unpkg.com/@smartledger/bsv@7.5.1/bsv-anchor.min.js` |
199
199
 
200
200
  ### **Smart Contract & Development**
201
201
  | Module | Size | Use Case | CDN |
202
202
  |--------|------|----------|-----|
203
- | **bsv-smartcontract.min.js** | 873KB | Complete covenant framework | `unpkg.com/@smartledger/bsv@7.4.0/bsv-smartcontract.min.js` |
204
- | **bsv-covenant.min.js** | 873KB | Covenant operations | `unpkg.com/@smartledger/bsv@7.4.0/bsv-covenant.min.js` |
205
- | **bsv-script-helper.min.js** | 30KB | Custom script tools | `unpkg.com/@smartledger/bsv@7.4.0/bsv-script-helper.min.js` |
206
- | **bsv-security.min.js** | 30KB | Security enhancements | `unpkg.com/@smartledger/bsv@7.4.0/bsv-security.min.js` |
203
+ | **bsv-smartcontract.min.js** | 873KB | Complete covenant framework | `unpkg.com/@smartledger/bsv@7.5.1/bsv-smartcontract.min.js` |
204
+ | **bsv-covenant.min.js** | 873KB | Covenant operations | `unpkg.com/@smartledger/bsv@7.5.1/bsv-covenant.min.js` |
205
+ | **bsv-script-helper.min.js** | 30KB | Custom script tools | `unpkg.com/@smartledger/bsv@7.5.1/bsv-script-helper.min.js` |
206
+ | **bsv-security.min.js** | 30KB | Security enhancements | `unpkg.com/@smartledger/bsv@7.5.1/bsv-security.min.js` |
207
207
 
208
208
  ### **Legal & Compliance**
209
209
  | Module | Size | Use Case | CDN |
210
210
  |--------|------|----------|-----|
211
- | **bsv-ltp.min.js** | 1149KB | Legal Token Protocol | `unpkg.com/@smartledger/bsv@7.4.0/bsv-ltp.min.js` |
212
- | **bsv-gdaf.min.js** | 1149KB | Digital Identity & Attestation | `unpkg.com/@smartledger/bsv@7.4.0/bsv-gdaf.min.js` |
211
+ | **bsv-ltp.min.js** | 1149KB | Legal Token Protocol | `unpkg.com/@smartledger/bsv@7.5.1/bsv-ltp.min.js` |
212
+ | **bsv-gdaf.min.js** | 1149KB | Digital Identity & Attestation | `unpkg.com/@smartledger/bsv@7.5.1/bsv-gdaf.min.js` |
213
213
 
214
214
  ### **Advanced Cryptography**
215
215
  | Module | Size | Use Case | CDN |
216
216
  |--------|------|----------|-----|
217
- | **bsv-shamir.min.js** | 353KB | Threshold Cryptography | `unpkg.com/@smartledger/bsv@7.4.0/bsv-shamir.min.js` |
217
+ | **bsv-shamir.min.js** | 353KB | Threshold Cryptography | `unpkg.com/@smartledger/bsv@7.5.1/bsv-shamir.min.js` |
218
218
 
219
219
  ### **Utilities**
220
220
  | Module | Size | Use Case | CDN |
221
221
  |--------|------|----------|-----|
222
- | **bsv-ecies.min.js** | 79KB | Encryption | `unpkg.com/@smartledger/bsv@7.4.0/bsv-ecies.min.js` |
223
- | **bsv-message.min.js** | 30KB | Message signing | `unpkg.com/@smartledger/bsv@7.4.0/bsv-message.min.js` |
224
- | **bsv-mnemonic.min.js** | 592KB | HD wallets | `unpkg.com/@smartledger/bsv@7.4.0/bsv-mnemonic.min.js` |
222
+ | **bsv-ecies.min.js** | 79KB | Encryption | `unpkg.com/@smartledger/bsv@7.5.1/bsv-ecies.min.js` |
223
+ | **bsv-message.min.js** | 30KB | Message signing | `unpkg.com/@smartledger/bsv@7.5.1/bsv-message.min.js` |
224
+ | **bsv-mnemonic.min.js** | 592KB | HD wallets | `unpkg.com/@smartledger/bsv@7.5.1/bsv-mnemonic.min.js` |
225
225
 
226
226
  ## ⚡ **2-Minute Quick Start**
227
227
 
@@ -232,7 +232,7 @@ Get started with Bitcoin SV development in under 2 minutes:
232
232
  npm install @smartledger/bsv
233
233
 
234
234
  # Or include in HTML
235
- <script src="https://unpkg.com/@smartledger/bsv@7.4.0/bsv.min.js"></script>
235
+ <script src="https://unpkg.com/@smartledger/bsv@7.5.1/bsv.min.js"></script>
236
236
  ```
237
237
 
238
238
  > **🔒 v5.0.0 (production hardening — has breaking changes):** Shamir secret
@@ -332,8 +332,8 @@ const covenant = bsv.SmartContract.createCovenantBuilder()
332
332
 
333
333
  ### 🔧 **Basic Development** (~1.2MB total)
334
334
  ```html
335
- <script src="https://unpkg.com/@smartledger/bsv@7.4.0/bsv.min.js"></script>
336
- <script src="https://unpkg.com/@smartledger/bsv@7.4.0/bsv-script-helper.min.js"></script>
335
+ <script src="https://unpkg.com/@smartledger/bsv@7.5.1/bsv.min.js"></script>
336
+ <script src="https://unpkg.com/@smartledger/bsv@7.5.1/bsv-script-helper.min.js"></script>
337
337
  <script>
338
338
  const privateKey = new bsv.PrivateKey();
339
339
  const utxos = new bsv.SmartContract.UTXOGenerator().createRealUTXOs(2, 100000);
@@ -342,9 +342,9 @@ const covenant = bsv.SmartContract.createCovenantBuilder()
342
342
 
343
343
  ### 🔒 **Smart Contract Development** (~2.8MB total — each bundle re-embeds core BSV)
344
344
  ```html
345
- <script src="https://unpkg.com/@smartledger/bsv@7.4.0/bsv.min.js"></script>
346
- <script src="https://unpkg.com/@smartledger/bsv@7.4.0/bsv-covenant.min.js"></script>
347
- <script src="https://unpkg.com/@smartledger/bsv@7.4.0/bsv-smartcontract.min.js"></script>
345
+ <script src="https://unpkg.com/@smartledger/bsv@7.5.1/bsv.min.js"></script>
346
+ <script src="https://unpkg.com/@smartledger/bsv@7.5.1/bsv-covenant.min.js"></script>
347
+ <script src="https://unpkg.com/@smartledger/bsv@7.5.1/bsv-smartcontract.min.js"></script>
348
348
  <script>
349
349
  const covenant = bsv.SmartContract.createCovenantBuilder()
350
350
  .extractField('amount').push(50000).greaterThanOrEqual().verify().build();
@@ -354,9 +354,9 @@ const covenant = bsv.SmartContract.createCovenantBuilder()
354
354
 
355
355
  ### 🆕 **Legal & Identity Development** (~3.4MB total — each bundle re-embeds core BSV)
356
356
  ```html
357
- <script src="https://unpkg.com/@smartledger/bsv@7.4.0/bsv.min.js"></script>
358
- <script src="https://unpkg.com/@smartledger/bsv@7.4.0/bsv-ltp.min.js"></script>
359
- <script src="https://unpkg.com/@smartledger/bsv@7.4.0/bsv-gdaf.min.js"></script>
357
+ <script src="https://unpkg.com/@smartledger/bsv@7.5.1/bsv.min.js"></script>
358
+ <script src="https://unpkg.com/@smartledger/bsv@7.5.1/bsv-ltp.min.js"></script>
359
+ <script src="https://unpkg.com/@smartledger/bsv@7.5.1/bsv-gdaf.min.js"></script>
360
360
  <script>
361
361
  // Legal Token Protocol
362
362
  const propertyToken = bsv.createPropertyToken({
@@ -370,9 +370,9 @@ const covenant = bsv.SmartContract.createCovenantBuilder()
370
370
 
371
371
  ### 🆕 **Security & Cryptography** (~1.5MB total)
372
372
  ```html
373
- <script src="https://unpkg.com/@smartledger/bsv@7.4.0/bsv.min.js"></script>
374
- <script src="https://unpkg.com/@smartledger/bsv@7.4.0/bsv-security.min.js"></script>
375
- <script src="https://unpkg.com/@smartledger/bsv@7.4.0/bsv-shamir.min.js"></script>
373
+ <script src="https://unpkg.com/@smartledger/bsv@7.5.1/bsv.min.js"></script>
374
+ <script src="https://unpkg.com/@smartledger/bsv@7.5.1/bsv-security.min.js"></script>
375
+ <script src="https://unpkg.com/@smartledger/bsv@7.5.1/bsv-shamir.min.js"></script>
376
376
  <script>
377
377
  // Threshold Cryptography
378
378
  const shares = bsv.splitSecret('my_secret_key', 5, 3); // 5 shares, 3 needed
@@ -384,7 +384,7 @@ const covenant = bsv.SmartContract.createCovenantBuilder()
384
384
 
385
385
  ### 🎯 **Everything Bundle** (~1.1MB)
386
386
  ```html
387
- <script src="https://unpkg.com/@smartledger/bsv@7.4.0/bsv.bundle.js"></script>
387
+ <script src="https://unpkg.com/@smartledger/bsv@7.5.1/bsv.bundle.js"></script>
388
388
  <script>
389
389
  // Everything available immediately
390
390
  const shares = bsv.splitSecret('secret', 5, 3); // Shamir Secret Sharing
@@ -494,8 +494,8 @@ const contractTx = covenant.createCovenantTransaction({
494
494
 
495
495
  #### 1. **Minimal Setup** - Core + Script Helper (~1.2MB)
496
496
  ```html
497
- <script src="https://unpkg.com/@smartledger/bsv@7.4.0/bsv.min.js"></script>
498
- <script src="https://unpkg.com/@smartledger/bsv@7.4.0/bsv-script-helper.min.js"></script>
497
+ <script src="https://unpkg.com/@smartledger/bsv@7.5.1/bsv.min.js"></script>
498
+ <script src="https://unpkg.com/@smartledger/bsv@7.5.1/bsv-script-helper.min.js"></script>
499
499
  <script>
500
500
  const tx = new bsv.Transaction();
501
501
  const sig = bsvScriptHelper.createSignature(tx, privateKey, 0, script, satoshis);
@@ -504,9 +504,9 @@ const contractTx = covenant.createCovenantTransaction({
504
504
 
505
505
  #### 2. **DeFi Development** - Core + Covenants + Debug (~2.8MB — each bundle re-embeds core BSV)
506
506
  ```html
507
- <script src="https://unpkg.com/@smartledger/bsv@7.4.0/bsv.min.js"></script>
508
- <script src="https://unpkg.com/@smartledger/bsv@7.4.0/bsv-covenant.min.js"></script>
509
- <script src="https://unpkg.com/@smartledger/bsv@7.4.0/bsv-smartcontract.min.js"></script>
507
+ <script src="https://unpkg.com/@smartledger/bsv@7.5.1/bsv.min.js"></script>
508
+ <script src="https://unpkg.com/@smartledger/bsv@7.5.1/bsv-covenant.min.js"></script>
509
+ <script src="https://unpkg.com/@smartledger/bsv@7.5.1/bsv-smartcontract.min.js"></script>
510
510
  <script>
511
511
  const covenant = new bsvCovenant.CovenantInterface();
512
512
  const debugInfo = SmartContract.interpretScript(script);
@@ -516,8 +516,8 @@ const contractTx = covenant.createCovenantTransaction({
516
516
 
517
517
  #### 3. **Security First** - Core + Enhanced Security (~1.2MB)
518
518
  ```html
519
- <script src="https://unpkg.com/@smartledger/bsv@7.4.0/bsv.min.js"></script>
520
- <script src="https://unpkg.com/@smartledger/bsv@7.4.0/bsv-security.min.js"></script>
519
+ <script src="https://unpkg.com/@smartledger/bsv@7.5.1/bsv.min.js"></script>
520
+ <script src="https://unpkg.com/@smartledger/bsv@7.5.1/bsv-security.min.js"></script>
521
521
  <script>
522
522
  const verified = bsvSecurity.SmartVerify.verify(signature, hash, publicKey);
523
523
  const enhanced = bsvSecurity.EllipticFixed.createSignature(privateKey, hash);
@@ -526,7 +526,7 @@ const contractTx = covenant.createCovenantTransaction({
526
526
 
527
527
  #### 4. **Everything Bundle** - One File Solution (~1.1MB)
528
528
  ```html
529
- <script src="https://unpkg.com/@smartledger/bsv@7.4.0/bsv.bundle.js"></script>
529
+ <script src="https://unpkg.com/@smartledger/bsv@7.5.1/bsv.bundle.js"></script>
530
530
  <script>
531
531
  // Everything available under bsv namespace
532
532
  const keys = bsv.SmartLedgerBundle.generateKeys();
@@ -834,7 +834,7 @@ const timelockScript = helper.createTimelockScript(
834
834
 
835
835
  See the **[16 Loading Options](#-16-loading-options---choose-your-approach)**
836
836
  table near the top for the full list of bundles with current sizes and
837
- canonical `unpkg.com/@smartledger/bsv@7.4.0/...` URLs.
837
+ canonical `unpkg.com/@smartledger/bsv@7.5.1/...` URLs.
838
838
 
839
839
  ## 🔐 Security
840
840