@smartledger/bsv 9.11.2 → 9.12.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.
@@ -34,14 +34,14 @@ module sounds. That is a deliberate revision: an earlier version of this documen
34
34
  scoped Tier 1 as "the cryptographic core" and would have excluded four of the six real
35
35
  defects this codebase has produced. See §2.1.
36
36
 
37
- ### Tier 1 — 12,013 lines
37
+ ### Tier 1 — 12,065 lines
38
38
 
39
39
  | Module | Lines | Why it matters |
40
40
  | --- | ---: | --- |
41
41
  | `lib/transaction/` | 2,786 | Sighash construction and signing — both BIP-143 and the Original Transaction Digest Algorithm. |
42
42
  | `lib/script/interpreter.js` | 2,851 | **Scoped to the flag and era surface, not opcode execution.** Consensus-flag selection and defaults, era derivation (Genesis/Chronicle), the limits derived from them, and the semantics of the exported `verify()`. Opcode execution is excluded — see §2.2. |
43
43
  | `lib/crypto/` | 2,519 | ECDSA, nonce derivation, signature encoding, the script-number type. **Scope this for an architectural judgement as well as for bugs** — see §2.3. |
44
- | `lib/notaryhash/` | 2,028 | BRC-220 signing and verification. Publicly reachable and relied on downstream. |
44
+ | `lib/notaryhash/` | 2,080 | BRC-220 signing and verification. Publicly reachable and relied on downstream. |
45
45
  | `lib/privatekey.js`, `lib/publickey.js` | 843 | Key construction, serialisation, WIF. Recent defects here produced a *different* key without error. |
46
46
  | `lib/smart_contract/` (targeted) | 472 | `locks.js` and the covenant-facing entrypoints in `index.js`: CLTV and HTLC locking semantics, flag plumbing, and any wrapper claiming mainnet-equivalent verification. Not the whole 6,908-line module. |
47
47
  | `lib/covenant/` | 409 | The verification harness. Its flag word is what made covenants verify under 2019 rules while claiming to mirror mainnet. |
@@ -150,14 +150,14 @@ this repository.
150
150
  | `lib/address.js`, `lib/networks.js`, `lib/opcode.js`, `lib/hdprivatekey.js`, `lib/hdpublickey.js` (2,391 lines) | Cut to pay for §2.1 | Formatting, network constants and BIP-32 derivation. No defect has originated here, and `networks.js` in particular defines addressing constants — pubkey hashes, xpub prefixes, ports, DNS seeds — and contains **no consensus-flag logic at all**. |
151
151
  | The rest of the application layer — `lib/gdaf/`, `lib/ltp/`, `lib/ordinals/`, `lib/block/`, `lib/didweb/`, `lib/vcjwt/`, `lib/statuslist/`, most of `lib/smart_contract/`, plus assorted top-level files | Excluded | ~26,000 lines. Worth a separate engagement; including it here would blur the question in §1. Note the parts of it with a demonstrated defect history have been pulled *into* Tier 1 rather than left here — see §2.1. |
152
152
 
153
- Totals reconcile against `lib/`, which is 39,791 lines across 131 files:
153
+ Totals reconcile against `lib/`, which is 40,020 lines across 131 files:
154
154
 
155
155
  ```
156
- tier 1 12,013
156
+ tier 1 12,065
157
157
  tier 2 1,607
158
- excluded 26,171
158
+ excluded 26,348
159
159
  ------
160
- total 39,791
160
+ total 40,020
161
161
  ```
162
162
 
163
163
  Measured 2026-08-29 at `a954c27`. These figures drift as the library changes — an
@@ -228,7 +228,7 @@ seeking a quote for an independent security review.
228
228
 
229
229
  Scope, and we would like these priced separately:
230
230
 
231
- Tier 1 — 12,013 lines. Sighash construction and signing; ECDSA, nonce
231
+ Tier 1 — 12,065 lines. Sighash construction and signing; ECDSA, nonce
232
232
  derivation and signature encoding; the consensus-flag and era-derivation
233
233
  surface of the script interpreter; BRC-220 signing and verification;
234
234
  key construction and serialisation; the covenant verification harness and
@@ -55,19 +55,19 @@ Three advanced modules totaling **~2.7MB** of functionality:
55
55
  - **Purpose**: Threshold cryptography for secure secret distribution
56
56
  - **Use Cases**: Backup keys, multi-party security, key recovery
57
57
  - **Features**: Split secrets into N shares, require M to reconstruct
58
- - **CDN**: `unpkg.com/@smartledger/bsv@9.11.2/bsv-shamir.min.js`
58
+ - **CDN**: `unpkg.com/@smartledger/bsv@9.12.0/bsv-shamir.min.js`
59
59
 
60
60
  #### **🌐 Global Digital Attestation Framework - GDAF (1184KB)**
61
61
  - **Purpose**: W3C Verifiable Credentials and decentralized identity
62
62
  - **Use Cases**: Identity verification, attestations, zero-knowledge proofs
63
63
  - **Features**: DID creation, credential issuance, selective disclosure
64
- - **CDN**: `unpkg.com/@smartledger/bsv@9.11.2/bsv-gdaf.min.js`
64
+ - **CDN**: `unpkg.com/@smartledger/bsv@9.12.0/bsv-gdaf.min.js`
65
65
 
66
66
  #### **⚖️ Legal Token Protocol - LTP (1184KB)**
67
67
  - **Purpose**: Legal compliance framework for tokenized assets
68
68
  - **Use Cases**: Property rights, obligations, compliant tokenization
69
69
  - **Features**: Legal primitives, compliance checking, attestation anchoring
70
- - **CDN**: `unpkg.com/@smartledger/bsv@9.11.2/bsv-ltp.min.js`
70
+ - **CDN**: `unpkg.com/@smartledger/bsv@9.12.0/bsv-ltp.min.js`
71
71
 
72
72
  ### **2. Incorrect File Sizes in Documentation**
73
73
 
@@ -81,18 +81,18 @@ Three advanced modules totaling **~2.7MB** of functionality:
81
81
 
82
82
  | Module | Size | Use Case | CDN Link |
83
83
  |--------|------|----------|----------|
84
- | **bsv.min.js** | 937KB | Core BSV + SmartContract | `unpkg.com/@smartledger/bsv@9.11.2/bsv.min.js` |
85
- | **bsv.bundle.js** | 937KB | Everything in one file | `unpkg.com/@smartledger/bsv@9.11.2/bsv.bundle.js` |
86
- | **bsv-smartcontract.min.js** | 937KB | Covenant development | `unpkg.com/@smartledger/bsv@9.11.2/bsv-smartcontract.min.js` |
87
- | **bsv-covenant.min.js** | 913KB | Covenant operations | `unpkg.com/@smartledger/bsv@9.11.2/bsv-covenant.min.js` |
88
- | **bsv-script-helper.min.js** | 26KB | Custom script tools | `unpkg.com/@smartledger/bsv@9.11.2/bsv-script-helper.min.js` |
89
- | **bsv-security.min.js** | 26KB | Security enhancements (opt-in helpers — see README › Security) | `unpkg.com/@smartledger/bsv@9.11.2/bsv-security.min.js` |
90
- | **bsv-ecies.min.js** | 71KB | Encryption | `unpkg.com/@smartledger/bsv@9.11.2/bsv-ecies.min.js` |
91
- | **bsv-message.min.js** | 26KB | Message signing | `unpkg.com/@smartledger/bsv@9.11.2/bsv-message.min.js` |
92
- | **bsv-mnemonic.min.js** | 681KB | HD wallets | `unpkg.com/@smartledger/bsv@9.11.2/bsv-mnemonic.min.js` |
93
- | **🆕 bsv-shamir.min.js** | 432KB | **Secret sharing** | `unpkg.com/@smartledger/bsv@9.11.2/bsv-shamir.min.js` |
94
- | **🆕 bsv-gdaf.min.js** | 1184KB | **Digital attestation** | `unpkg.com/@smartledger/bsv@9.11.2/bsv-gdaf.min.js` |
95
- | **🆕 bsv-ltp.min.js** | 1184KB | **Legal tokens** | `unpkg.com/@smartledger/bsv@9.11.2/bsv-ltp.min.js` |
84
+ | **bsv.min.js** | 937KB | Core BSV + SmartContract | `unpkg.com/@smartledger/bsv@9.12.0/bsv.min.js` |
85
+ | **bsv.bundle.js** | 937KB | Everything in one file | `unpkg.com/@smartledger/bsv@9.12.0/bsv.bundle.js` |
86
+ | **bsv-smartcontract.min.js** | 937KB | Covenant development | `unpkg.com/@smartledger/bsv@9.12.0/bsv-smartcontract.min.js` |
87
+ | **bsv-covenant.min.js** | 913KB | Covenant operations | `unpkg.com/@smartledger/bsv@9.12.0/bsv-covenant.min.js` |
88
+ | **bsv-script-helper.min.js** | 26KB | Custom script tools | `unpkg.com/@smartledger/bsv@9.12.0/bsv-script-helper.min.js` |
89
+ | **bsv-security.min.js** | 26KB | Security enhancements (opt-in helpers — see README › Security) | `unpkg.com/@smartledger/bsv@9.12.0/bsv-security.min.js` |
90
+ | **bsv-ecies.min.js** | 71KB | Encryption | `unpkg.com/@smartledger/bsv@9.12.0/bsv-ecies.min.js` |
91
+ | **bsv-message.min.js** | 26KB | Message signing | `unpkg.com/@smartledger/bsv@9.12.0/bsv-message.min.js` |
92
+ | **bsv-mnemonic.min.js** | 681KB | HD wallets | `unpkg.com/@smartledger/bsv@9.12.0/bsv-mnemonic.min.js` |
93
+ | **🆕 bsv-shamir.min.js** | 432KB | **Secret sharing** | `unpkg.com/@smartledger/bsv@9.12.0/bsv-shamir.min.js` |
94
+ | **🆕 bsv-gdaf.min.js** | 1184KB | **Digital attestation** | `unpkg.com/@smartledger/bsv@9.12.0/bsv-gdaf.min.js` |
95
+ | **🆕 bsv-ltp.min.js** | 1184KB | **Legal tokens** | `unpkg.com/@smartledger/bsv@9.12.0/bsv-ltp.min.js` |
96
96
 
97
97
  ## 🎯 **Updated Usage Examples**
98
98
 
@@ -100,22 +100,22 @@ Three advanced modules totaling **~2.7MB** of functionality:
100
100
 
101
101
  #### **1. Basic Development (~963KB)**
102
102
  ```html
103
- <script src="https://unpkg.com/@smartledger/bsv@9.11.2/bsv.min.js"></script>
104
- <script src="https://unpkg.com/@smartledger/bsv@9.11.2/bsv-script-helper.min.js"></script>
103
+ <script src="https://unpkg.com/@smartledger/bsv@9.12.0/bsv.min.js"></script>
104
+ <script src="https://unpkg.com/@smartledger/bsv@9.12.0/bsv-script-helper.min.js"></script>
105
105
  ```
106
106
 
107
107
  #### **2. Smart Contract Development (~2.7MB — each bundle re-embeds core BSV)**
108
108
  ```html
109
- <script src="https://unpkg.com/@smartledger/bsv@9.11.2/bsv.min.js"></script>
110
- <script src="https://unpkg.com/@smartledger/bsv@9.11.2/bsv-covenant.min.js"></script>
111
- <script src="https://unpkg.com/@smartledger/bsv@9.11.2/bsv-smartcontract.min.js"></script>
109
+ <script src="https://unpkg.com/@smartledger/bsv@9.12.0/bsv.min.js"></script>
110
+ <script src="https://unpkg.com/@smartledger/bsv@9.12.0/bsv-covenant.min.js"></script>
111
+ <script src="https://unpkg.com/@smartledger/bsv@9.12.0/bsv-smartcontract.min.js"></script>
112
112
  ```
113
113
 
114
114
  #### **3. 🆕 Legal & Compliance Development (~3.2MB — each bundle re-embeds core BSV)**
115
115
  ```html
116
- <script src="https://unpkg.com/@smartledger/bsv@9.11.2/bsv.min.js"></script>
117
- <script src="https://unpkg.com/@smartledger/bsv@9.11.2/bsv-ltp.min.js"></script>
118
- <script src="https://unpkg.com/@smartledger/bsv@9.11.2/bsv-gdaf.min.js"></script>
116
+ <script src="https://unpkg.com/@smartledger/bsv@9.12.0/bsv.min.js"></script>
117
+ <script src="https://unpkg.com/@smartledger/bsv@9.12.0/bsv-ltp.min.js"></script>
118
+ <script src="https://unpkg.com/@smartledger/bsv@9.12.0/bsv-gdaf.min.js"></script>
119
119
  <script>
120
120
  // Legal Token Protocol
121
121
  const legalToken = bsv.createLegalToken({
@@ -132,9 +132,9 @@ Three advanced modules totaling **~2.7MB** of functionality:
132
132
 
133
133
  #### **4. 🆕 Security & Cryptography (~1.4MB)**
134
134
  ```html
135
- <script src="https://unpkg.com/@smartledger/bsv@9.11.2/bsv.min.js"></script>
136
- <script src="https://unpkg.com/@smartledger/bsv@9.11.2/bsv-security.min.js"></script>
137
- <script src="https://unpkg.com/@smartledger/bsv@9.11.2/bsv-shamir.min.js"></script>
135
+ <script src="https://unpkg.com/@smartledger/bsv@9.12.0/bsv.min.js"></script>
136
+ <script src="https://unpkg.com/@smartledger/bsv@9.12.0/bsv-security.min.js"></script>
137
+ <script src="https://unpkg.com/@smartledger/bsv@9.12.0/bsv-shamir.min.js"></script>
138
138
  <script>
139
139
  // Shamir Secret Sharing
140
140
  const shares = bsv.splitSecret('my_secret_key', 5, 3); // 5 shares, 3 needed
@@ -146,7 +146,7 @@ Three advanced modules totaling **~2.7MB** of functionality:
146
146
 
147
147
  #### **5. Everything Bundle (937KB)**
148
148
  ```html
149
- <script src="https://unpkg.com/@smartledger/bsv@9.11.2/bsv.bundle.js"></script>
149
+ <script src="https://unpkg.com/@smartledger/bsv@9.12.0/bsv.bundle.js"></script>
150
150
  <script>
151
151
  // Everything available immediately
152
152
  const shares = bsv.splitSecret('secret', 5, 3);
@@ -722,7 +722,7 @@ interface UTXO {
722
722
  <html>
723
723
  <head>
724
724
  <title>UTXO Manager Demo</title>
725
- <script src="https://cdn.jsdelivr.net/npm/@smartledger/bsv@9.11.2/bsv.min.js"></script>
725
+ <script src="https://cdn.jsdelivr.net/npm/@smartledger/bsv@9.12.0/bsv.min.js"></script>
726
726
  </head>
727
727
  <body>
728
728
  <script>
@@ -15,7 +15,7 @@ seeking a quote for an independent security review of its cryptographic core.
15
15
 
16
16
  Scope, and we would like these priced separately:
17
17
 
18
- Tier 1 — 12,013 lines. Sighash construction and signing; ECDSA, nonce
18
+ Tier 1 — 12,065 lines. Sighash construction and signing; ECDSA, nonce
19
19
  derivation and signature encoding; the consensus-flag and era surface of the
20
20
  script interpreter; BRC-220 signing; the covenant verification harness; RFC
21
21
  8785 canonicalization; and the covenant-facing entrypoints of the smart
@@ -30,7 +30,7 @@ Explicitly out of scope: elliptic-curve and hash primitives, which are supplied
30
30
  by the Noble libraries and already audited; opcode EXECUTION in the script
31
31
  interpreter, which passes 1,483 of 1,483 of the reference node's own consensus
32
32
  vectors with zero false accepts and zero false rejects; and the remaining
33
- 26,171-line application layer (credentials, tokens, ordinals), which we would
33
+ 26,348-line application layer (credentials, tokens, ordinals), which we would
34
34
  treat as a separate engagement.
35
35
 
36
36
  Note the shape of that first exclusion, because it is what we want priced. The
@@ -15,7 +15,7 @@ seeking a quote for an independent security review of its cryptographic core.
15
15
 
16
16
  Scope, and we would like these priced separately:
17
17
 
18
- Tier 1 — 12,013 lines. Sighash construction and signing; ECDSA, nonce
18
+ Tier 1 — 12,065 lines. Sighash construction and signing; ECDSA, nonce
19
19
  derivation and signature encoding; the consensus-flag and era surface of the
20
20
  script interpreter; BRC-220 signing; the covenant verification harness; RFC
21
21
  8785 canonicalization; and the covenant-facing entrypoints of the smart
@@ -30,7 +30,7 @@ Explicitly out of scope: elliptic-curve and hash primitives, which are supplied
30
30
  by the Noble libraries and already audited; opcode EXECUTION in the script
31
31
  interpreter, which passes 1,483 of 1,483 of the reference node's own consensus
32
32
  vectors with zero false accepts and zero false rejects; and the remaining
33
- 26,171-line application layer (credentials, tokens, ordinals), which we would
33
+ 26,348-line application layer (credentials, tokens, ordinals), which we would
34
34
  treat as a separate engagement.
35
35
 
36
36
  Note the shape of that first exclusion, because it is what we want priced. The
@@ -15,7 +15,7 @@ seeking a quote for an independent security review of its cryptographic core.
15
15
 
16
16
  Scope, and we would like these priced separately:
17
17
 
18
- Tier 1 — 12,013 lines. Sighash construction and signing; ECDSA, nonce
18
+ Tier 1 — 12,065 lines. Sighash construction and signing; ECDSA, nonce
19
19
  derivation and signature encoding; the consensus-flag and era surface of the
20
20
  script interpreter; BRC-220 signing; the covenant verification harness; RFC
21
21
  8785 canonicalization; and the covenant-facing entrypoints of the smart
@@ -30,7 +30,7 @@ Explicitly out of scope: elliptic-curve and hash primitives, which are supplied
30
30
  by the Noble libraries and already audited; opcode EXECUTION in the script
31
31
  interpreter, which passes 1,483 of 1,483 of the reference node's own consensus
32
32
  vectors with zero false accepts and zero false rejects; and the remaining
33
- 26,171-line application layer (credentials, tokens, ordinals), which we would
33
+ 26,348-line application layer (credentials, tokens, ordinals), which we would
34
34
  treat as a separate engagement.
35
35
 
36
36
  Note the shape of that first exclusion, because it is what we want priced. The
@@ -48,7 +48,7 @@ const tx: Transaction = new Transaction();
48
48
  #### **Core Library Only (937KB)**
49
49
  For basic Bitcoin SV operations:
50
50
  ```html
51
- <script src="https://unpkg.com/@smartledger/bsv@9.11.2/bsv.min.js"></script>
51
+ <script src="https://unpkg.com/@smartledger/bsv@9.12.0/bsv.min.js"></script>
52
52
  <script>
53
53
  const privateKey = new bsv.PrivateKey();
54
54
  const address = privateKey.toAddress();
@@ -58,7 +58,7 @@ For basic Bitcoin SV operations:
58
58
  #### **Complete Bundle (937KB)**
59
59
  Everything in one file:
60
60
  ```html
61
- <script src="https://unpkg.com/@smartledger/bsv@9.11.2/bsv.bundle.js"></script>
61
+ <script src="https://unpkg.com/@smartledger/bsv@9.12.0/bsv.bundle.js"></script>
62
62
  <script>
63
63
  // All features available immediately
64
64
  const shares = bsv.splitSecret('secret', 5, 3);
@@ -71,9 +71,9 @@ Everything in one file:
71
71
 
72
72
  #### **Smart Contract Development (~2.7MB total — each bundle is self-contained and re-embeds core BSV)**
73
73
  ```html
74
- <script src="https://unpkg.com/@smartledger/bsv@9.11.2/bsv.min.js"></script>
75
- <script src="https://unpkg.com/@smartledger/bsv@9.11.2/bsv-covenant.min.js"></script>
76
- <script src="https://unpkg.com/@smartledger/bsv@9.11.2/bsv-smartcontract.min.js"></script>
74
+ <script src="https://unpkg.com/@smartledger/bsv@9.12.0/bsv.min.js"></script>
75
+ <script src="https://unpkg.com/@smartledger/bsv@9.12.0/bsv-covenant.min.js"></script>
76
+ <script src="https://unpkg.com/@smartledger/bsv@9.12.0/bsv-smartcontract.min.js"></script>
77
77
  <script>
78
78
  const covenant = bsv.SmartContract.createCovenantBuilder()
79
79
  .extractField('amount').push(50000).greaterThanOrEqual().build();
@@ -82,9 +82,9 @@ Everything in one file:
82
82
 
83
83
  #### **Legal & Identity Development (~3.2MB total — each bundle is self-contained and re-embeds core BSV)**
84
84
  ```html
85
- <script src="https://unpkg.com/@smartledger/bsv@9.11.2/bsv.min.js"></script>
86
- <script src="https://unpkg.com/@smartledger/bsv@9.11.2/bsv-ltp.min.js"></script>
87
- <script src="https://unpkg.com/@smartledger/bsv@9.11.2/bsv-gdaf.min.js"></script>
85
+ <script src="https://unpkg.com/@smartledger/bsv@9.12.0/bsv.min.js"></script>
86
+ <script src="https://unpkg.com/@smartledger/bsv@9.12.0/bsv-ltp.min.js"></script>
87
+ <script src="https://unpkg.com/@smartledger/bsv@9.12.0/bsv-gdaf.min.js"></script>
88
88
  <script>
89
89
  // Legal Token Protocol
90
90
  const propertyToken = bsv.createPropertyToken({
@@ -98,9 +98,9 @@ Everything in one file:
98
98
 
99
99
  #### **Security & Cryptography (~1.4MB total — each bundle is self-contained and re-embeds core BSV)**
100
100
  ```html
101
- <script src="https://unpkg.com/@smartledger/bsv@9.11.2/bsv.min.js"></script>
102
- <script src="https://unpkg.com/@smartledger/bsv@9.11.2/bsv-security.min.js"></script>
103
- <script src="https://unpkg.com/@smartledger/bsv@9.11.2/bsv-shamir.min.js"></script>
101
+ <script src="https://unpkg.com/@smartledger/bsv@9.12.0/bsv.min.js"></script>
102
+ <script src="https://unpkg.com/@smartledger/bsv@9.12.0/bsv-security.min.js"></script>
103
+ <script src="https://unpkg.com/@smartledger/bsv@9.12.0/bsv-shamir.min.js"></script>
104
104
  <script>
105
105
  // Threshold Cryptography
106
106
  const shares = bsv.splitSecret('my_secret_key', 5, 3);
@@ -114,18 +114,18 @@ Everything in one file:
114
114
 
115
115
  | Module | Size | Purpose | CDN Link |
116
116
  |--------|------|---------|----------|
117
- | **bsv.min.js** | 937KB | Core BSV + SmartContract | `unpkg.com/@smartledger/bsv@9.11.2/bsv.min.js` |
118
- | **bsv.bundle.js** | 937KB | Everything in one file | `unpkg.com/@smartledger/bsv@9.11.2/bsv.bundle.js` |
119
- | **bsv-smartcontract.min.js** | 937KB | Complete covenant framework | `unpkg.com/@smartledger/bsv@9.11.2/bsv-smartcontract.min.js` |
120
- | **bsv-ltp.min.js** | 1184KB | **Legal Token Protocol** | `unpkg.com/@smartledger/bsv@9.11.2/bsv-ltp.min.js` |
121
- | **bsv-gdaf.min.js** | 1184KB | **Digital Identity & Attestation** | `unpkg.com/@smartledger/bsv@9.11.2/bsv-gdaf.min.js` |
122
- | **bsv-shamir.min.js** | 432KB | **Threshold Cryptography** | `unpkg.com/@smartledger/bsv@9.11.2/bsv-shamir.min.js` |
123
- | **bsv-security.min.js** | 26KB | Security enhancements (opt-in helpers — see README › Security) | `unpkg.com/@smartledger/bsv@9.11.2/bsv-security.min.js` |
124
- | **bsv-mnemonic.min.js** | 681KB | HD wallets | `unpkg.com/@smartledger/bsv@9.11.2/bsv-mnemonic.min.js` |
125
- | **bsv-ecies.min.js** | 71KB | Encryption | `unpkg.com/@smartledger/bsv@9.11.2/bsv-ecies.min.js` |
126
- | **bsv-covenant.min.js** | 913KB | Covenant operations | `unpkg.com/@smartledger/bsv@9.11.2/bsv-covenant.min.js` |
127
- | **bsv-script-helper.min.js** | 26KB | Custom script tools | `unpkg.com/@smartledger/bsv@9.11.2/bsv-script-helper.min.js` |
128
- | **bsv-message.min.js** | 26KB | Message signing | `unpkg.com/@smartledger/bsv@9.11.2/bsv-message.min.js` |
117
+ | **bsv.min.js** | 937KB | Core BSV + SmartContract | `unpkg.com/@smartledger/bsv@9.12.0/bsv.min.js` |
118
+ | **bsv.bundle.js** | 937KB | Everything in one file | `unpkg.com/@smartledger/bsv@9.12.0/bsv.bundle.js` |
119
+ | **bsv-smartcontract.min.js** | 937KB | Complete covenant framework | `unpkg.com/@smartledger/bsv@9.12.0/bsv-smartcontract.min.js` |
120
+ | **bsv-ltp.min.js** | 1184KB | **Legal Token Protocol** | `unpkg.com/@smartledger/bsv@9.12.0/bsv-ltp.min.js` |
121
+ | **bsv-gdaf.min.js** | 1184KB | **Digital Identity & Attestation** | `unpkg.com/@smartledger/bsv@9.12.0/bsv-gdaf.min.js` |
122
+ | **bsv-shamir.min.js** | 432KB | **Threshold Cryptography** | `unpkg.com/@smartledger/bsv@9.12.0/bsv-shamir.min.js` |
123
+ | **bsv-security.min.js** | 26KB | Security enhancements (opt-in helpers — see README › Security) | `unpkg.com/@smartledger/bsv@9.12.0/bsv-security.min.js` |
124
+ | **bsv-mnemonic.min.js** | 681KB | HD wallets | `unpkg.com/@smartledger/bsv@9.12.0/bsv-mnemonic.min.js` |
125
+ | **bsv-ecies.min.js** | 71KB | Encryption | `unpkg.com/@smartledger/bsv@9.12.0/bsv-ecies.min.js` |
126
+ | **bsv-covenant.min.js** | 913KB | Covenant operations | `unpkg.com/@smartledger/bsv@9.12.0/bsv-covenant.min.js` |
127
+ | **bsv-script-helper.min.js** | 26KB | Custom script tools | `unpkg.com/@smartledger/bsv@9.12.0/bsv-script-helper.min.js` |
128
+ | **bsv-message.min.js** | 26KB | Message signing | `unpkg.com/@smartledger/bsv@9.12.0/bsv-message.min.js` |
129
129
 
130
130
  ## ⚙️ **Development Environment Setup**
131
131
 
@@ -14,10 +14,10 @@ npm install @smartledger/bsv
14
14
  ### Browser CDN (Instant)
15
15
  ```html
16
16
  <!-- Core library (937KB) -->
17
- <script src="https://unpkg.com/@smartledger/bsv@9.11.2/bsv.min.js"></script>
17
+ <script src="https://unpkg.com/@smartledger/bsv@9.12.0/bsv.min.js"></script>
18
18
 
19
19
  <!-- Everything included (937KB) -->
20
- <script src="https://unpkg.com/@smartledger/bsv@9.11.2/bsv.bundle.js"></script>
20
+ <script src="https://unpkg.com/@smartledger/bsv@9.12.0/bsv.bundle.js"></script>
21
21
  ```
22
22
 
23
23
  ## 💰 **Your First Transaction (60 seconds)**
@@ -127,19 +127,19 @@ SmartLedger-BSV offers 12 different loading options - use only what you need:
127
127
 
128
128
  ```html
129
129
  <!-- Core BSV only (937KB) -->
130
- <script src="https://unpkg.com/@smartledger/bsv@9.11.2/bsv.min.js"></script>
130
+ <script src="https://unpkg.com/@smartledger/bsv@9.12.0/bsv.min.js"></script>
131
131
 
132
132
  <!-- Smart contracts (937KB) -->
133
- <script src="https://unpkg.com/@smartledger/bsv@9.11.2/bsv-smartcontract.min.js"></script>
133
+ <script src="https://unpkg.com/@smartledger/bsv@9.12.0/bsv-smartcontract.min.js"></script>
134
134
 
135
135
  <!-- Legal tokens (1.16MB) -->
136
- <script src="https://unpkg.com/@smartledger/bsv@9.11.2/bsv-ltp.min.js"></script>
136
+ <script src="https://unpkg.com/@smartledger/bsv@9.12.0/bsv-ltp.min.js"></script>
137
137
 
138
138
  <!-- Digital identity (1.16MB) -->
139
- <script src="https://unpkg.com/@smartledger/bsv@9.11.2/bsv-gdaf.min.js"></script>
139
+ <script src="https://unpkg.com/@smartledger/bsv@9.12.0/bsv-gdaf.min.js"></script>
140
140
 
141
141
  <!-- Everything (937KB) -->
142
- <script src="https://unpkg.com/@smartledger/bsv@9.11.2/bsv.bundle.js"></script>
142
+ <script src="https://unpkg.com/@smartledger/bsv@9.12.0/bsv.bundle.js"></script>
143
143
  ```
144
144
 
145
145
  ## ⚡ **Key Advantages**
@@ -159,17 +159,17 @@ const recovered = bsv.reconstructSecret([shares[0], shares[2], shares[4]]);
159
159
  ### **New Modular Options**
160
160
  ```html
161
161
  <!-- Core compatibility (same size as bsv@1.5.6) -->
162
- <script src="https://unpkg.com/@smartledger/bsv@9.11.2/bsv.min.js"></script>
162
+ <script src="https://unpkg.com/@smartledger/bsv@9.12.0/bsv.min.js"></script>
163
163
 
164
164
  <!-- Add smart contracts when ready -->
165
- <script src="https://unpkg.com/@smartledger/bsv@9.11.2/bsv-smartcontract.min.js"></script>
165
+ <script src="https://unpkg.com/@smartledger/bsv@9.12.0/bsv-smartcontract.min.js"></script>
166
166
 
167
167
  <!-- Add advanced features as needed -->
168
- <script src="https://unpkg.com/@smartledger/bsv@9.11.2/bsv-ltp.min.js"></script>
169
- <script src="https://unpkg.com/@smartledger/bsv@9.11.2/bsv-gdaf.min.js"></script>
168
+ <script src="https://unpkg.com/@smartledger/bsv@9.12.0/bsv-ltp.min.js"></script>
169
+ <script src="https://unpkg.com/@smartledger/bsv@9.12.0/bsv-gdaf.min.js"></script>
170
170
 
171
171
  <!-- Everything in one file -->
172
- <script src="https://unpkg.com/@smartledger/bsv@9.11.2/bsv.bundle.js"></script>
172
+ <script src="https://unpkg.com/@smartledger/bsv@9.12.0/bsv.bundle.js"></script>
173
173
  ```
174
174
 
175
175
  ## 🔍 **Testing Your Migration**
@@ -615,6 +615,7 @@ SmartLedgerAnchor._verifyAnchorSPV = function(txid, expectedHash, options) {
615
615
  if (options.headerChain) {
616
616
  chainResult = SPV.verifyHeaderChain(options.headerChain, {
617
617
  requirePow: options.requirePow !== false,
618
+ powLimit: options.powLimit,
618
619
  trustedHash: options.trustedHash
619
620
  })
620
621
  inclusionHeader = options.headerChain[0]
@@ -625,7 +626,9 @@ SmartLedgerAnchor._verifyAnchorSPV = function(txid, expectedHash, options) {
625
626
  index: proof.index,
626
627
  nodes: proof.nodes,
627
628
  header: inclusionHeader,
628
- requirePow: options.requirePow !== false
629
+ requirePow: options.requirePow !== false,
630
+ powLimit: options.powLimit,
631
+ minWork: options.minWork
629
632
  })
630
633
 
631
634
  // Bind the raw tx to the proven txid (double-SHA256, reversed to display order),
@@ -164,9 +164,22 @@ NotaryHash.recordMatchesCertificate = function (record, certificate) {
164
164
  *
165
165
  * @param {Object} certificate - must carry an `spv` envelope
166
166
  * @param {Object} opts
167
- * @param {String|Buffer|BlockHeader} opts.header - independently obtained
167
+ * A header's work is only as good as the target it declares, and it declares its own, so
168
+ * the declared target is capped at `powLimit` (difficulty 1 by default). Even a genuine,
169
+ * fully worked header can be an orphan: `blockHashAtHeight` is how a caller that has its
170
+ * own chain view says which block that height really holds.
171
+ *
172
+ * @param {Object} certificate - must carry an `spv` envelope
173
+ * @param {Object} opts
174
+ * @param {String|Buffer|BlockHeader} opts.header - independently obtained, 80 bytes
168
175
  * @param {Number} [opts.height] - the height the header was obtained at. A header's 80
169
176
  * bytes do not carry it, so it is checked against spv.blockHeight only when supplied.
177
+ * @param {String} [opts.blockHashAtHeight] - the block hash the caller's own chain source
178
+ * has at that height. Rejects an orphaned block, which no header check can detect.
179
+ * @param {Number|String} [opts.powLimit] - easiest target a header may declare, as compact
180
+ * bits. Default 0x1d00ffff, the limit of mainnet and testnet; regtest is 0x207fffff.
181
+ * @param {Number|String} [opts.minWork] - minimum work the header must represent.
182
+ * Difficulty 1 is about 4.295e9.
170
183
  * @param {Boolean} [opts.requirePow=true] - pass false only for test fixtures
171
184
  * @returns {Object} { valid, errors }
172
185
  */
@@ -201,17 +214,41 @@ NotaryHash.verifyAnchorSPV = function (certificate, opts) {
201
214
  }
202
215
 
203
216
  var proof = spv.merkleProof || {}
204
- var inclusion = SPV.verifyTxInclusion({
205
- header: opts.header,
206
- txid: txid,
207
- index: proof.index,
208
- nodes: proof.nodes,
209
- requirePow: opts.requirePow !== false
210
- })
211
- if (inclusion.valid !== true) {
212
- errors.push(inclusion.rootMatches === false
213
- ? 'merkle proof does not fold to the header\'s root'
214
- : 'block header failed proof-of-work validation')
217
+ var inclusion
218
+ try {
219
+ inclusion = SPV.verifyTxInclusion({
220
+ header: opts.header,
221
+ txid: txid,
222
+ index: proof.index,
223
+ nodes: proof.nodes,
224
+ requirePow: opts.requirePow !== false,
225
+ powLimit: opts.powLimit,
226
+ minWork: opts.minWork
227
+ })
228
+ } catch (inputError) {
229
+ // Something the caller passed cannot be used: a header that is not 80 bytes (often an
230
+ // object stating a merkleRoot, the very assertion this check exists to stop
231
+ // believing), a malformed powLimit or minWork, or a malformed proof. Said plainly.
232
+ errors.push(inputError.message)
233
+ return { valid: false, errors: errors }
234
+ }
235
+ if (inclusion.rootMatches !== true) {
236
+ errors.push('merkle proof does not fold to the header\'s root')
237
+ }
238
+ // The work checks, all of which requirePow:false turns off together, as it always did.
239
+ if (opts.requirePow !== false) {
240
+ if (inclusion.powValid !== true) {
241
+ errors.push('block header failed proof-of-work validation')
242
+ }
243
+ // A forged header can declare any target it likes and then meet it: with bits of
244
+ // 0x2100ffff every hash qualifies. Work below the network's limit is not work.
245
+ if (inclusion.targetAllowed !== true) {
246
+ errors.push('block header declares a target easier than the proof-of-work limit, ' +
247
+ 'so its work proves nothing')
248
+ }
249
+ if (inclusion.workSufficient !== true) {
250
+ errors.push('block header carries less work than required: ' + inclusion.work)
251
+ }
215
252
  }
216
253
 
217
254
  // The spec anchors the certificate in "the block header for spv.blockHash". A header
@@ -230,6 +267,21 @@ NotaryHash.verifyAnchorSPV = function (certificate, opts) {
230
267
  errors.push('the supplied header is not at the height the SPV envelope names')
231
268
  }
232
269
 
270
+ // The one check no amount of proof of work can replace. A genuine block that lost a
271
+ // race carries real work and a real Merkle root; only a chain source knows which block
272
+ // the chain kept at that height, so a caller holding one says so here.
273
+ if (opts.blockHashAtHeight !== undefined && opts.blockHashAtHeight !== null) {
274
+ var claimed = Buffer.isBuffer(opts.blockHashAtHeight)
275
+ ? opts.blockHashAtHeight.toString('hex')
276
+ : String(opts.blockHashAtHeight).replace(/^0x/, '')
277
+ if (!/^[0-9a-fA-F]{64}$/.test(claimed)) {
278
+ errors.push('blockHashAtHeight must be a 32-byte block hash')
279
+ } else if (claimed.toLowerCase() !== String(inclusion.blockHash).toLowerCase()) {
280
+ errors.push('the header is not the block the caller\'s chain has at that height: ' +
281
+ 'it may be orphaned')
282
+ }
283
+ }
284
+
233
285
  return { valid: errors.length === 0, errors: errors }
234
286
  } catch (e) {
235
287
  return { valid: false, errors: ['anchor verification error: ' + e.message] }
@@ -8,28 +8,33 @@
8
8
  * the chain is anchored at a hash the caller independently trusts.
9
9
  *
10
10
  * TRUST MODEL — read this. It validates linkage + PER-HEADER proof-of-work, but NOT
11
- * the difficulty-retargeting schedule. A determined attacker can mine cheap headers
12
- * at an artificially easy `bits`, so PoW-per-header alone is not sufficient in an
13
- * adversarial setting. For real assurance pass `opts.trustedHash` — a block hash you
11
+ * the difficulty-retargeting schedule. Mining a header at an artificially easy `bits`
12
+ * is no longer enough on its own: every header's DECLARED target must be at least as
13
+ * hard as `opts.powLimit` (difficulty 1 by default), so a chain of free headers is
14
+ * refused. Retargeting is still unchecked, so a fork whose headers are each above the
15
+ * limit remains possible. For real assurance pass `opts.trustedHash` — a block hash you
14
16
  * already trust (from your own node, or a hardcoded checkpoint) that the chain's tip
15
17
  * (or anchor) must match; the headers around it are then real work extending a block
16
18
  * you trust. Full difficulty-retarget validation is intentionally out of scope here.
17
19
  */
18
- var BlockHeader = require('../block/blockheader')
20
+ var BN = require('../crypto/bn')
21
+ var merkleproof = require('./merkleproof')
19
22
 
20
23
  function rev (b) { return Buffer.from(b).reverse() }
21
24
 
25
+ // Every header goes through the same 80-byte snapshot verifyTxInclusion uses, so a chain
26
+ // cannot be built from objects that merely claim a prevHash, an id and a passing
27
+ // validProofOfWork(). Their fields are read from the bytes, or there are no bytes.
22
28
  function toHeader (h) {
23
- if (h && typeof h.validProofOfWork === 'function') return h
24
- if (Buffer.isBuffer(h)) return BlockHeader.fromBuffer(h)
25
- if (typeof h === 'string') return BlockHeader.fromBuffer(Buffer.from(h, 'hex'))
26
- throw new Error('each header must be a BlockHeader, an 80-byte Buffer, or hex')
29
+ return merkleproof.headerSnapshot(h)
27
30
  }
28
31
 
29
32
  /**
30
33
  * @param {Array} headers consecutive headers, oldest→newest (BlockHeader/Buffer/hex).
31
34
  * @param {object} [opts]
32
35
  * requirePow {boolean=true} verify each header meets its bits target.
36
+ * powLimit {number|string} easiest target a header may declare, as compact bits.
37
+ * Default 0x1d00ffff; regtest headers need 0x207fffff.
33
38
  * trustedHash {string} a block hash the chain's tip or anchor must equal.
34
39
  * @returns {{ valid, reason?, count, anchorHash, tipHash, work }}
35
40
  */
@@ -42,9 +47,25 @@ function verifyHeaderChain (headers, opts) {
42
47
  var requirePow = opts.requirePow !== false
43
48
  var work = 0
44
49
 
50
+ var limit = requirePow ? merkleproof.targetLimit(opts.powLimit) : null
45
51
  for (var i = 0; i < hs.length; i++) {
46
- if (requirePow && !hs[i].validProofOfWork()) {
47
- return { valid: false, reason: 'invalid proof-of-work at index ' + i, count: hs.length }
52
+ // The declared target, read the way the node reads it. validProofOfWork() would use
53
+ // BlockHeader.getTargetDifficulty, which disagrees with this for a size below 4, so
54
+ // the hash test and the limit test would be against two different targets.
55
+ var declared = merkleproof.targetFromBits(hs[i].bits)
56
+ if (requirePow) {
57
+ if (declared === null || new BN(hs[i].id, 'hex').cmp(declared) > 0) {
58
+ return { valid: false, reason: 'invalid proof-of-work at index ' + i, count: hs.length }
59
+ }
60
+ // Work against a target the header chose for itself is not work. Without this, a
61
+ // chain of headers mined at bits 0x2100ffff costs nothing and links perfectly.
62
+ if (declared.cmp(limit) > 0) {
63
+ return {
64
+ valid: false,
65
+ reason: 'target easier than the proof-of-work limit at index ' + i,
66
+ count: hs.length
67
+ }
68
+ }
48
69
  }
49
70
  work += hs[i].getDifficulty()
50
71
  if (i > 0) {
package/lib/spv/index.js CHANGED
@@ -9,6 +9,7 @@ var merkleproof = require('./merkleproof')
9
9
  var headerchain = require('./headerchain')
10
10
 
11
11
  module.exports = {
12
+ POW_LIMIT_BITS: merkleproof.POW_LIMIT_BITS,
12
13
  merkleRootFromBranch: merkleproof.merkleRootFromBranch,
13
14
  verifyMerkleProof: merkleproof.verifyMerkleProof,
14
15
  verifyTxInclusion: merkleproof.verifyTxInclusion,