@smartledger/bsv 7.13.0 → 8.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 (36) hide show
  1. package/CHANGELOG.md +106 -0
  2. package/README.md +38 -38
  3. package/bsv-gdaf.min.js +55 -55
  4. package/bsv-ltp.min.js +39 -39
  5. package/bsv-smartcontract.min.js +1 -1
  6. package/bsv.bundle.js +55 -55
  7. package/bsv.min.js +55 -55
  8. package/docs/AUDIT_SCOPE.md +21 -12
  9. package/docs/MODULE_REFERENCE_COMPLETE.md +27 -27
  10. package/docs/advanced/UTXO_MANAGER_GUIDE.md +1 -1
  11. package/docs/getting-started/INSTALLATION.md +23 -23
  12. package/docs/getting-started/QUICK_START.md +7 -7
  13. package/docs/migration/FROM_BSV_1_5_6.md +5 -5
  14. package/lib/crypto/bn.js +22 -2
  15. package/lib/script/interpreter.js +399 -56
  16. package/lib/transaction/sighash.js +18 -6
  17. package/package.json +4 -1
  18. package/test/consensus/base58-vectors.js +120 -0
  19. package/test/consensus/sv-script-vectors.js +81 -0
  20. package/test/consensus/sv-sighash-vectors.js +51 -0
  21. package/test/consensus/sv-tx-vectors.js +48 -0
  22. package/test/data/bitcoin-sv/README.md +170 -0
  23. package/test/data/bitcoin-sv/base58_encode_decode.json +14 -0
  24. package/test/data/bitcoin-sv/base58_keys_invalid.json +152 -0
  25. package/test/data/bitcoin-sv/base58_keys_valid.json +452 -0
  26. package/test/data/bitcoin-sv/script_tests.json +2591 -0
  27. package/test/data/bitcoin-sv/sighash.json +1003 -0
  28. package/test/data/bitcoin-sv/tx_invalid.json +285 -0
  29. package/test/data/bitcoin-sv/tx_valid.json +367 -0
  30. package/test/regressions.js +35 -0
  31. package/test/script/chronicle.js +170 -25
  32. package/test/script/defaults.js +93 -0
  33. package/test/script/genesis_limits.js +62 -6
  34. package/test/script/interpreter.js +24 -8
  35. package/test/transaction/sighash.js +21 -1
  36. package/version.js +1 -1
package/CHANGELOG.md CHANGED
@@ -7,6 +7,112 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
7
7
 
8
8
  ## [Unreleased]
9
9
 
10
+ ## [8.0.0] - 2026-08-13
11
+
12
+ This library is now measured against the reference node's own consensus vectors, and its
13
+ defaults describe BSV as the network actually runs it.
14
+
15
+ Until this release the only consensus reference was the `script_tests.json` inherited
16
+ from the upstream fork — Bitcoin Core vectors encoding rules BSV abandoned at Genesis in
17
+ 2020. Passing them completely said very little about whether this library agrees with the
18
+ network. The first run against the node's own vectors scored **1426/1483 with 21 false
19
+ accepts**: scripts this library accepted that BSV rejects.
20
+
21
+ That is the direction that is hardest to catch. Nothing which tests this library against
22
+ itself can see it, because the library is the thing being wrong.
23
+
24
+ ### BREAKING — read before upgrading
25
+
26
+ **`verify()` with no flags now means BSV mainnet, not "no rules".**
27
+
28
+ ```js
29
+ interp.verify(sig, pubkey, tx, nin) // was: Bitcoin 2015; now: current mainnet
30
+ interp.verify(sig, pubkey, tx, nin, 0) // the old behaviour, stated explicitly
31
+ Interpreter.mainnetFlags({ afterChronicle: false }) // pre-Chronicle UTXO
32
+ ```
33
+
34
+ Spending a pre-activation output is now the case you state, because the era of the output
35
+ being spent is the input the caller knows and the library cannot.
36
+
37
+ **Two flag constants changed value.** The node assigns `1<<18` and `1<<19` to
38
+ `SCRIPT_GENESIS` and `SCRIPT_UTXO_AFTER_GENESIS`, so ours had to vacate:
39
+
40
+ ```
41
+ SCRIPT_ENABLE_MONOLITH_OPCODES 1<<18 → 1<<11
42
+ SCRIPT_ENABLE_MAGNETIC_OPCODES 1<<19 → 1<<12
43
+ ```
44
+
45
+ Anything using the named constants is unaffected. Anything that **persisted or hardcoded
46
+ the numbers** must be updated: `262144` no longer means "Monolith opcodes", it now means
47
+ `SCRIPT_GENESIS`, so an old stored value silently enables a different era model.
48
+
49
+ **Other behaviour changes, all moving toward the node:**
50
+
51
+ - a signature carrying `SIGHASH_CHRONICLE` outside Chronicle is now *rejected* rather
52
+ than reinterpreted, and a digest with that bit set selects the original algorithm
53
+ - `MAX_OPS_PER_SCRIPT` is 500 (BSV's number), was 201 (Bitcoin Core's)
54
+ - `OP_CAT` is no longer capped at 520 bytes after Genesis
55
+ - `OP_MOD` reports `MOD_BY_ZERO`; `OP_DIV`/`OP_MOD` now actually detect a zero divisor
56
+ - script number, truncated push and `OP_NUM2BIN` failures report the node's result code
57
+ instead of a generic `UNKNOWN_ERROR`
58
+
59
+ ### The vectors
60
+
61
+ Copied verbatim from `bitcoin-sv/bitcoin-sv` v1.2.0, provenance recorded in
62
+ `test/data/bitcoin-sv/README.md`.
63
+
64
+ | | |
65
+ | --- | --- |
66
+ | script vectors | 1483/1483, 0 false accepts, 0 false rejects |
67
+ | result codes | 600/600 (491 exact, 109 via documented aliases) |
68
+ | transaction vectors | 161/161 |
69
+ | digest vectors | 1000/1000, on both columns |
70
+
71
+ ```
72
+ npm run vectors:sv npm run vectors:sv-tx npm run vectors:sv-sighash
73
+ ```
74
+
75
+ ### What they found
76
+
77
+ **The era now travels in flags, as it does in the node.** Genesis was a process-wide
78
+ opt-in mutating four static caps, and there were no `SCRIPT_GENESIS` /
79
+ `SCRIPT_UTXO_AFTER_GENESIS` / `SCRIPT_UTXO_AFTER_CHRONICLE` flags at all, so rules gated
80
+ on the era of the output being spent could not be expressed, let alone enforced.
81
+
82
+ **Genesis allows only one `OP_ELSE` per `OP_IF`** — 17 of the 21 false accepts.
83
+
84
+ **Genesis reverts CLTV/CSV to upgradable NOPs** — found by the *transaction* vectors, not
85
+ the script ones, because the behaviour only appears once a real `nLockTime` and sequence
86
+ exist. Four transactions the network accepts were being rejected.
87
+
88
+ **Chronicle digest routing** — 260 of 1000 rows disagreed. `SIGHASH_CHRONICLE` was
89
+ honoured only when `SCRIPT_ENABLE_CHRONICLE` was also set; the node routes on the bit
90
+ alone and rejects a signature carrying it outside Chronicle as `ILLEGAL_CHRONICLE`.
91
+ Rejected, not reinterpreted — a stronger protection, and it leaves the digest a function
92
+ of the transaction rather than of a flag the node never consults.
93
+
94
+ **Four bugs a pass/fail check is structurally blind to.** Matching the node's outcome is
95
+ not failing for the node's *reason*. Comparing the result code of all 600 rejected
96
+ vectors found a divide-by-zero guard written `bn2 === 0` where `bn2` is a `BN` (never
97
+ true), script-number decoding escaping into a generic catch (78 vectors), a truncated
98
+ `PUSHDATA` doing the same, and `OP_NUM2BIN` checking only the upper bound of its size
99
+ argument. Every one left the script failing, so 1483/1483 stayed green throughout.
100
+
101
+ ### Also in this release
102
+
103
+ `verify()`'s default set is derived from what the vector harness applies rather than
104
+ assembled by judgement, which is why it includes the `MONOLITH`/`MAGNETIC` pair: BSV
105
+ restored those opcodes in 2018 and the node does not gate them, so omitting them would
106
+ make the default *stricter* than consensus.
107
+
108
+ `useMainnetConsensus()` no longer raises the script-number bound to `0x7fffffff`. That
109
+ ceiling made Chronicle's shift-overflow check unreachable, since it tests
110
+ `current_size + shift_bytes > max_length`.
111
+
112
+ Timelock checks report a consensus error instead of a `TypeError` when there is no input
113
+ at `nin`. `checkSequence` dereferenced the input as its first statement; `checkLockTime`
114
+ had the identical dereference, hidden only by statement order.
115
+
10
116
  ## [7.13.0] - 2026-08-11
11
117
 
12
118
  Two of the three fixes below came from another team building a React Native keystore on
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.13.0/bsv.min.js` |
190
- | **bsv.bundle.js** | 1149KB | Everything in one file | `unpkg.com/@smartledger/bsv@7.13.0/bsv.bundle.js` |
189
+ | **bsv.min.js** | 1149KB | Core BSV + SmartContract | `unpkg.com/@smartledger/bsv@8.0.0/bsv.min.js` |
190
+ | **bsv.bundle.js** | 1149KB | Everything in one file | `unpkg.com/@smartledger/bsv@8.0.0/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.13.0/bsv-didweb.min.js` |
196
- | **🟢 bsv-vcjwt.min.js** | 315KB | **VC-JWT issue/verify** | `unpkg.com/@smartledger/bsv@7.13.0/bsv-vcjwt.min.js` |
197
- | **🟢 bsv-statuslist.min.js** | 415KB | **StatusList2021 revocation** | `unpkg.com/@smartledger/bsv@7.13.0/bsv-statuslist.min.js` |
198
- | **🟢 bsv-anchor.min.js** | 314KB | **BSV anchoring (hash-only)** | `unpkg.com/@smartledger/bsv@7.13.0/bsv-anchor.min.js` |
195
+ | **🟢 bsv-didweb.min.js** | 315KB | **DID:web generation** | `unpkg.com/@smartledger/bsv@8.0.0/bsv-didweb.min.js` |
196
+ | **🟢 bsv-vcjwt.min.js** | 315KB | **VC-JWT issue/verify** | `unpkg.com/@smartledger/bsv@8.0.0/bsv-vcjwt.min.js` |
197
+ | **🟢 bsv-statuslist.min.js** | 415KB | **StatusList2021 revocation** | `unpkg.com/@smartledger/bsv@8.0.0/bsv-statuslist.min.js` |
198
+ | **🟢 bsv-anchor.min.js** | 314KB | **BSV anchoring (hash-only)** | `unpkg.com/@smartledger/bsv@8.0.0/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.13.0/bsv-smartcontract.min.js` |
204
- | **bsv-covenant.min.js** | 873KB | Covenant operations | `unpkg.com/@smartledger/bsv@7.13.0/bsv-covenant.min.js` |
205
- | **bsv-script-helper.min.js** | 30KB | Custom script tools | `unpkg.com/@smartledger/bsv@7.13.0/bsv-script-helper.min.js` |
206
- | **bsv-security.min.js** | 30KB | Security enhancements | `unpkg.com/@smartledger/bsv@7.13.0/bsv-security.min.js` |
203
+ | **bsv-smartcontract.min.js** | 873KB | Complete covenant framework | `unpkg.com/@smartledger/bsv@8.0.0/bsv-smartcontract.min.js` |
204
+ | **bsv-covenant.min.js** | 873KB | Covenant operations | `unpkg.com/@smartledger/bsv@8.0.0/bsv-covenant.min.js` |
205
+ | **bsv-script-helper.min.js** | 30KB | Custom script tools | `unpkg.com/@smartledger/bsv@8.0.0/bsv-script-helper.min.js` |
206
+ | **bsv-security.min.js** | 30KB | Security enhancements | `unpkg.com/@smartledger/bsv@8.0.0/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.13.0/bsv-ltp.min.js` |
212
- | **bsv-gdaf.min.js** | 1149KB | Digital Identity & Attestation | `unpkg.com/@smartledger/bsv@7.13.0/bsv-gdaf.min.js` |
211
+ | **bsv-ltp.min.js** | 1149KB | Legal Token Protocol | `unpkg.com/@smartledger/bsv@8.0.0/bsv-ltp.min.js` |
212
+ | **bsv-gdaf.min.js** | 1149KB | Digital Identity & Attestation | `unpkg.com/@smartledger/bsv@8.0.0/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.13.0/bsv-shamir.min.js` |
217
+ | **bsv-shamir.min.js** | 353KB | Threshold Cryptography | `unpkg.com/@smartledger/bsv@8.0.0/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.13.0/bsv-ecies.min.js` |
223
- | **bsv-message.min.js** | 30KB | Message signing | `unpkg.com/@smartledger/bsv@7.13.0/bsv-message.min.js` |
224
- | **bsv-mnemonic.min.js** | 592KB | HD wallets | `unpkg.com/@smartledger/bsv@7.13.0/bsv-mnemonic.min.js` |
222
+ | **bsv-ecies.min.js** | 79KB | Encryption | `unpkg.com/@smartledger/bsv@8.0.0/bsv-ecies.min.js` |
223
+ | **bsv-message.min.js** | 30KB | Message signing | `unpkg.com/@smartledger/bsv@8.0.0/bsv-message.min.js` |
224
+ | **bsv-mnemonic.min.js** | 592KB | HD wallets | `unpkg.com/@smartledger/bsv@8.0.0/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.13.0/bsv.min.js"></script>
235
+ <script src="https://unpkg.com/@smartledger/bsv@8.0.0/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.13.0/bsv.min.js"></script>
336
- <script src="https://unpkg.com/@smartledger/bsv@7.13.0/bsv-script-helper.min.js"></script>
335
+ <script src="https://unpkg.com/@smartledger/bsv@8.0.0/bsv.min.js"></script>
336
+ <script src="https://unpkg.com/@smartledger/bsv@8.0.0/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.13.0/bsv.min.js"></script>
346
- <script src="https://unpkg.com/@smartledger/bsv@7.13.0/bsv-covenant.min.js"></script>
347
- <script src="https://unpkg.com/@smartledger/bsv@7.13.0/bsv-smartcontract.min.js"></script>
345
+ <script src="https://unpkg.com/@smartledger/bsv@8.0.0/bsv.min.js"></script>
346
+ <script src="https://unpkg.com/@smartledger/bsv@8.0.0/bsv-covenant.min.js"></script>
347
+ <script src="https://unpkg.com/@smartledger/bsv@8.0.0/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.13.0/bsv.min.js"></script>
358
- <script src="https://unpkg.com/@smartledger/bsv@7.13.0/bsv-ltp.min.js"></script>
359
- <script src="https://unpkg.com/@smartledger/bsv@7.13.0/bsv-gdaf.min.js"></script>
357
+ <script src="https://unpkg.com/@smartledger/bsv@8.0.0/bsv.min.js"></script>
358
+ <script src="https://unpkg.com/@smartledger/bsv@8.0.0/bsv-ltp.min.js"></script>
359
+ <script src="https://unpkg.com/@smartledger/bsv@8.0.0/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.13.0/bsv.min.js"></script>
374
- <script src="https://unpkg.com/@smartledger/bsv@7.13.0/bsv-security.min.js"></script>
375
- <script src="https://unpkg.com/@smartledger/bsv@7.13.0/bsv-shamir.min.js"></script>
373
+ <script src="https://unpkg.com/@smartledger/bsv@8.0.0/bsv.min.js"></script>
374
+ <script src="https://unpkg.com/@smartledger/bsv@8.0.0/bsv-security.min.js"></script>
375
+ <script src="https://unpkg.com/@smartledger/bsv@8.0.0/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.13.0/bsv.bundle.js"></script>
387
+ <script src="https://unpkg.com/@smartledger/bsv@8.0.0/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.13.0/bsv.min.js"></script>
498
- <script src="https://unpkg.com/@smartledger/bsv@7.13.0/bsv-script-helper.min.js"></script>
497
+ <script src="https://unpkg.com/@smartledger/bsv@8.0.0/bsv.min.js"></script>
498
+ <script src="https://unpkg.com/@smartledger/bsv@8.0.0/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.13.0/bsv.min.js"></script>
508
- <script src="https://unpkg.com/@smartledger/bsv@7.13.0/bsv-covenant.min.js"></script>
509
- <script src="https://unpkg.com/@smartledger/bsv@7.13.0/bsv-smartcontract.min.js"></script>
507
+ <script src="https://unpkg.com/@smartledger/bsv@8.0.0/bsv.min.js"></script>
508
+ <script src="https://unpkg.com/@smartledger/bsv@8.0.0/bsv-covenant.min.js"></script>
509
+ <script src="https://unpkg.com/@smartledger/bsv@8.0.0/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.13.0/bsv.min.js"></script>
520
- <script src="https://unpkg.com/@smartledger/bsv@7.13.0/bsv-security.min.js"></script>
519
+ <script src="https://unpkg.com/@smartledger/bsv@8.0.0/bsv.min.js"></script>
520
+ <script src="https://unpkg.com/@smartledger/bsv@8.0.0/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.13.0/bsv.bundle.js"></script>
529
+ <script src="https://unpkg.com/@smartledger/bsv@8.0.0/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.13.0/...` URLs.
837
+ canonical `unpkg.com/@smartledger/bsv@8.0.0/...` URLs.
838
838
 
839
839
  ## 🔐 Security
840
840