@smartledger/bsv 9.21.0 → 9.22.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.
@@ -34,11 +34,11 @@ 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,469 lines
37
+ ### Tier 1 — 12,539 lines
38
38
 
39
39
  | Module | Lines | Why it matters |
40
40
  | --- | ---: | --- |
41
- | `lib/transaction/` | 2,786 | Sighash construction and signing — both BIP-143 and the Original Transaction Digest Algorithm. |
41
+ | `lib/transaction/` | 2,856 | Sighash construction and signing — both BIP-143 and the Original Transaction Digest Algorithm. |
42
42
  | `lib/script/interpreter.js` | 2,962 | **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
44
  | `lib/notaryhash/` | 2,373 | BRC-220 signing and verification. Publicly reachable and relied on downstream. |
@@ -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 40,594 lines across 131 files:
153
+ Totals reconcile against `lib/`, which is 40,721 lines across 131 files:
154
154
 
155
155
  ```
156
- tier 1 12,469
156
+ tier 1 12,539
157
157
  tier 2 1,607
158
- excluded 26,518
158
+ excluded 26,575
159
159
  ------
160
- total 40,594
160
+ total 40,721
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,469 lines. Sighash construction and signing; ECDSA, nonce
231
+ Tier 1 — 12,539 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.21.0/bsv-shamir.min.js`
58
+ - **CDN**: `unpkg.com/@smartledger/bsv@9.22.1/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.21.0/bsv-gdaf.min.js`
64
+ - **CDN**: `unpkg.com/@smartledger/bsv@9.22.1/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.21.0/bsv-ltp.min.js`
70
+ - **CDN**: `unpkg.com/@smartledger/bsv@9.22.1/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.21.0/bsv.min.js` |
85
- | **bsv.bundle.js** | 937KB | Everything in one file | `unpkg.com/@smartledger/bsv@9.21.0/bsv.bundle.js` |
86
- | **bsv-smartcontract.min.js** | 937KB | Covenant development | `unpkg.com/@smartledger/bsv@9.21.0/bsv-smartcontract.min.js` |
87
- | **bsv-covenant.min.js** | 913KB | Covenant operations | `unpkg.com/@smartledger/bsv@9.21.0/bsv-covenant.min.js` |
88
- | **bsv-script-helper.min.js** | 26KB | Custom script tools | `unpkg.com/@smartledger/bsv@9.21.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.21.0/bsv-security.min.js` |
90
- | **bsv-ecies.min.js** | 71KB | Encryption | `unpkg.com/@smartledger/bsv@9.21.0/bsv-ecies.min.js` |
91
- | **bsv-message.min.js** | 26KB | Message signing | `unpkg.com/@smartledger/bsv@9.21.0/bsv-message.min.js` |
92
- | **bsv-mnemonic.min.js** | 681KB | HD wallets | `unpkg.com/@smartledger/bsv@9.21.0/bsv-mnemonic.min.js` |
93
- | **🆕 bsv-shamir.min.js** | 432KB | **Secret sharing** | `unpkg.com/@smartledger/bsv@9.21.0/bsv-shamir.min.js` |
94
- | **🆕 bsv-gdaf.min.js** | 1184KB | **Digital attestation** | `unpkg.com/@smartledger/bsv@9.21.0/bsv-gdaf.min.js` |
95
- | **🆕 bsv-ltp.min.js** | 1184KB | **Legal tokens** | `unpkg.com/@smartledger/bsv@9.21.0/bsv-ltp.min.js` |
84
+ | **bsv.min.js** | 937KB | Core BSV + SmartContract | `unpkg.com/@smartledger/bsv@9.22.1/bsv.min.js` |
85
+ | **bsv.bundle.js** | 937KB | Everything in one file | `unpkg.com/@smartledger/bsv@9.22.1/bsv.bundle.js` |
86
+ | **bsv-smartcontract.min.js** | 937KB | Covenant development | `unpkg.com/@smartledger/bsv@9.22.1/bsv-smartcontract.min.js` |
87
+ | **bsv-covenant.min.js** | 913KB | Covenant operations | `unpkg.com/@smartledger/bsv@9.22.1/bsv-covenant.min.js` |
88
+ | **bsv-script-helper.min.js** | 26KB | Custom script tools | `unpkg.com/@smartledger/bsv@9.22.1/bsv-script-helper.min.js` |
89
+ | **bsv-security.min.js** | 26KB | Security enhancements (opt-in helpers — see README › Security) | `unpkg.com/@smartledger/bsv@9.22.1/bsv-security.min.js` |
90
+ | **bsv-ecies.min.js** | 71KB | Encryption | `unpkg.com/@smartledger/bsv@9.22.1/bsv-ecies.min.js` |
91
+ | **bsv-message.min.js** | 26KB | Message signing | `unpkg.com/@smartledger/bsv@9.22.1/bsv-message.min.js` |
92
+ | **bsv-mnemonic.min.js** | 681KB | HD wallets | `unpkg.com/@smartledger/bsv@9.22.1/bsv-mnemonic.min.js` |
93
+ | **🆕 bsv-shamir.min.js** | 432KB | **Secret sharing** | `unpkg.com/@smartledger/bsv@9.22.1/bsv-shamir.min.js` |
94
+ | **🆕 bsv-gdaf.min.js** | 1184KB | **Digital attestation** | `unpkg.com/@smartledger/bsv@9.22.1/bsv-gdaf.min.js` |
95
+ | **🆕 bsv-ltp.min.js** | 1184KB | **Legal tokens** | `unpkg.com/@smartledger/bsv@9.22.1/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.21.0/bsv.min.js"></script>
104
- <script src="https://unpkg.com/@smartledger/bsv@9.21.0/bsv-script-helper.min.js"></script>
103
+ <script src="https://unpkg.com/@smartledger/bsv@9.22.1/bsv.min.js"></script>
104
+ <script src="https://unpkg.com/@smartledger/bsv@9.22.1/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.21.0/bsv.min.js"></script>
110
- <script src="https://unpkg.com/@smartledger/bsv@9.21.0/bsv-covenant.min.js"></script>
111
- <script src="https://unpkg.com/@smartledger/bsv@9.21.0/bsv-smartcontract.min.js"></script>
109
+ <script src="https://unpkg.com/@smartledger/bsv@9.22.1/bsv.min.js"></script>
110
+ <script src="https://unpkg.com/@smartledger/bsv@9.22.1/bsv-covenant.min.js"></script>
111
+ <script src="https://unpkg.com/@smartledger/bsv@9.22.1/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.21.0/bsv.min.js"></script>
117
- <script src="https://unpkg.com/@smartledger/bsv@9.21.0/bsv-ltp.min.js"></script>
118
- <script src="https://unpkg.com/@smartledger/bsv@9.21.0/bsv-gdaf.min.js"></script>
116
+ <script src="https://unpkg.com/@smartledger/bsv@9.22.1/bsv.min.js"></script>
117
+ <script src="https://unpkg.com/@smartledger/bsv@9.22.1/bsv-ltp.min.js"></script>
118
+ <script src="https://unpkg.com/@smartledger/bsv@9.22.1/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.21.0/bsv.min.js"></script>
136
- <script src="https://unpkg.com/@smartledger/bsv@9.21.0/bsv-security.min.js"></script>
137
- <script src="https://unpkg.com/@smartledger/bsv@9.21.0/bsv-shamir.min.js"></script>
135
+ <script src="https://unpkg.com/@smartledger/bsv@9.22.1/bsv.min.js"></script>
136
+ <script src="https://unpkg.com/@smartledger/bsv@9.22.1/bsv-security.min.js"></script>
137
+ <script src="https://unpkg.com/@smartledger/bsv@9.22.1/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.21.0/bsv.bundle.js"></script>
149
+ <script src="https://unpkg.com/@smartledger/bsv@9.22.1/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.21.0/bsv.min.js"></script>
725
+ <script src="https://cdn.jsdelivr.net/npm/@smartledger/bsv@9.22.1/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,469 lines. Sighash construction and signing; ECDSA, nonce
18
+ Tier 1 — 12,539 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,518-line application layer (credentials, tokens, ordinals), which we would
33
+ 26,575-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,469 lines. Sighash construction and signing; ECDSA, nonce
18
+ Tier 1 — 12,539 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,518-line application layer (credentials, tokens, ordinals), which we would
33
+ 26,575-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,469 lines. Sighash construction and signing; ECDSA, nonce
18
+ Tier 1 — 12,539 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,518-line application layer (credentials, tokens, ordinals), which we would
33
+ 26,575-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.21.0/bsv.min.js"></script>
51
+ <script src="https://unpkg.com/@smartledger/bsv@9.22.1/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.21.0/bsv.bundle.js"></script>
61
+ <script src="https://unpkg.com/@smartledger/bsv@9.22.1/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.21.0/bsv.min.js"></script>
75
- <script src="https://unpkg.com/@smartledger/bsv@9.21.0/bsv-covenant.min.js"></script>
76
- <script src="https://unpkg.com/@smartledger/bsv@9.21.0/bsv-smartcontract.min.js"></script>
74
+ <script src="https://unpkg.com/@smartledger/bsv@9.22.1/bsv.min.js"></script>
75
+ <script src="https://unpkg.com/@smartledger/bsv@9.22.1/bsv-covenant.min.js"></script>
76
+ <script src="https://unpkg.com/@smartledger/bsv@9.22.1/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.21.0/bsv.min.js"></script>
86
- <script src="https://unpkg.com/@smartledger/bsv@9.21.0/bsv-ltp.min.js"></script>
87
- <script src="https://unpkg.com/@smartledger/bsv@9.21.0/bsv-gdaf.min.js"></script>
85
+ <script src="https://unpkg.com/@smartledger/bsv@9.22.1/bsv.min.js"></script>
86
+ <script src="https://unpkg.com/@smartledger/bsv@9.22.1/bsv-ltp.min.js"></script>
87
+ <script src="https://unpkg.com/@smartledger/bsv@9.22.1/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.21.0/bsv.min.js"></script>
102
- <script src="https://unpkg.com/@smartledger/bsv@9.21.0/bsv-security.min.js"></script>
103
- <script src="https://unpkg.com/@smartledger/bsv@9.21.0/bsv-shamir.min.js"></script>
101
+ <script src="https://unpkg.com/@smartledger/bsv@9.22.1/bsv.min.js"></script>
102
+ <script src="https://unpkg.com/@smartledger/bsv@9.22.1/bsv-security.min.js"></script>
103
+ <script src="https://unpkg.com/@smartledger/bsv@9.22.1/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.21.0/bsv.min.js` |
118
- | **bsv.bundle.js** | 937KB | Everything in one file | `unpkg.com/@smartledger/bsv@9.21.0/bsv.bundle.js` |
119
- | **bsv-smartcontract.min.js** | 937KB | Complete covenant framework | `unpkg.com/@smartledger/bsv@9.21.0/bsv-smartcontract.min.js` |
120
- | **bsv-ltp.min.js** | 1184KB | **Legal Token Protocol** | `unpkg.com/@smartledger/bsv@9.21.0/bsv-ltp.min.js` |
121
- | **bsv-gdaf.min.js** | 1184KB | **Digital Identity & Attestation** | `unpkg.com/@smartledger/bsv@9.21.0/bsv-gdaf.min.js` |
122
- | **bsv-shamir.min.js** | 432KB | **Threshold Cryptography** | `unpkg.com/@smartledger/bsv@9.21.0/bsv-shamir.min.js` |
123
- | **bsv-security.min.js** | 26KB | Security enhancements (opt-in helpers — see README › Security) | `unpkg.com/@smartledger/bsv@9.21.0/bsv-security.min.js` |
124
- | **bsv-mnemonic.min.js** | 681KB | HD wallets | `unpkg.com/@smartledger/bsv@9.21.0/bsv-mnemonic.min.js` |
125
- | **bsv-ecies.min.js** | 71KB | Encryption | `unpkg.com/@smartledger/bsv@9.21.0/bsv-ecies.min.js` |
126
- | **bsv-covenant.min.js** | 913KB | Covenant operations | `unpkg.com/@smartledger/bsv@9.21.0/bsv-covenant.min.js` |
127
- | **bsv-script-helper.min.js** | 26KB | Custom script tools | `unpkg.com/@smartledger/bsv@9.21.0/bsv-script-helper.min.js` |
128
- | **bsv-message.min.js** | 26KB | Message signing | `unpkg.com/@smartledger/bsv@9.21.0/bsv-message.min.js` |
117
+ | **bsv.min.js** | 937KB | Core BSV + SmartContract | `unpkg.com/@smartledger/bsv@9.22.1/bsv.min.js` |
118
+ | **bsv.bundle.js** | 937KB | Everything in one file | `unpkg.com/@smartledger/bsv@9.22.1/bsv.bundle.js` |
119
+ | **bsv-smartcontract.min.js** | 937KB | Complete covenant framework | `unpkg.com/@smartledger/bsv@9.22.1/bsv-smartcontract.min.js` |
120
+ | **bsv-ltp.min.js** | 1184KB | **Legal Token Protocol** | `unpkg.com/@smartledger/bsv@9.22.1/bsv-ltp.min.js` |
121
+ | **bsv-gdaf.min.js** | 1184KB | **Digital Identity & Attestation** | `unpkg.com/@smartledger/bsv@9.22.1/bsv-gdaf.min.js` |
122
+ | **bsv-shamir.min.js** | 432KB | **Threshold Cryptography** | `unpkg.com/@smartledger/bsv@9.22.1/bsv-shamir.min.js` |
123
+ | **bsv-security.min.js** | 26KB | Security enhancements (opt-in helpers — see README › Security) | `unpkg.com/@smartledger/bsv@9.22.1/bsv-security.min.js` |
124
+ | **bsv-mnemonic.min.js** | 681KB | HD wallets | `unpkg.com/@smartledger/bsv@9.22.1/bsv-mnemonic.min.js` |
125
+ | **bsv-ecies.min.js** | 71KB | Encryption | `unpkg.com/@smartledger/bsv@9.22.1/bsv-ecies.min.js` |
126
+ | **bsv-covenant.min.js** | 913KB | Covenant operations | `unpkg.com/@smartledger/bsv@9.22.1/bsv-covenant.min.js` |
127
+ | **bsv-script-helper.min.js** | 26KB | Custom script tools | `unpkg.com/@smartledger/bsv@9.22.1/bsv-script-helper.min.js` |
128
+ | **bsv-message.min.js** | 26KB | Message signing | `unpkg.com/@smartledger/bsv@9.22.1/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.21.0/bsv.min.js"></script>
17
+ <script src="https://unpkg.com/@smartledger/bsv@9.22.1/bsv.min.js"></script>
18
18
 
19
19
  <!-- Everything included (937KB) -->
20
- <script src="https://unpkg.com/@smartledger/bsv@9.21.0/bsv.bundle.js"></script>
20
+ <script src="https://unpkg.com/@smartledger/bsv@9.22.1/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.21.0/bsv.min.js"></script>
130
+ <script src="https://unpkg.com/@smartledger/bsv@9.22.1/bsv.min.js"></script>
131
131
 
132
132
  <!-- Smart contracts (937KB) -->
133
- <script src="https://unpkg.com/@smartledger/bsv@9.21.0/bsv-smartcontract.min.js"></script>
133
+ <script src="https://unpkg.com/@smartledger/bsv@9.22.1/bsv-smartcontract.min.js"></script>
134
134
 
135
135
  <!-- Legal tokens (1.16MB) -->
136
- <script src="https://unpkg.com/@smartledger/bsv@9.21.0/bsv-ltp.min.js"></script>
136
+ <script src="https://unpkg.com/@smartledger/bsv@9.22.1/bsv-ltp.min.js"></script>
137
137
 
138
138
  <!-- Digital identity (1.16MB) -->
139
- <script src="https://unpkg.com/@smartledger/bsv@9.21.0/bsv-gdaf.min.js"></script>
139
+ <script src="https://unpkg.com/@smartledger/bsv@9.22.1/bsv-gdaf.min.js"></script>
140
140
 
141
141
  <!-- Everything (937KB) -->
142
- <script src="https://unpkg.com/@smartledger/bsv@9.21.0/bsv.bundle.js"></script>
142
+ <script src="https://unpkg.com/@smartledger/bsv@9.22.1/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.21.0/bsv.min.js"></script>
162
+ <script src="https://unpkg.com/@smartledger/bsv@9.22.1/bsv.min.js"></script>
163
163
 
164
164
  <!-- Add smart contracts when ready -->
165
- <script src="https://unpkg.com/@smartledger/bsv@9.21.0/bsv-smartcontract.min.js"></script>
165
+ <script src="https://unpkg.com/@smartledger/bsv@9.22.1/bsv-smartcontract.min.js"></script>
166
166
 
167
167
  <!-- Add advanced features as needed -->
168
- <script src="https://unpkg.com/@smartledger/bsv@9.21.0/bsv-ltp.min.js"></script>
169
- <script src="https://unpkg.com/@smartledger/bsv@9.21.0/bsv-gdaf.min.js"></script>
168
+ <script src="https://unpkg.com/@smartledger/bsv@9.22.1/bsv-ltp.min.js"></script>
169
+ <script src="https://unpkg.com/@smartledger/bsv@9.22.1/bsv-gdaf.min.js"></script>
170
170
 
171
171
  <!-- Everything in one file -->
172
- <script src="https://unpkg.com/@smartledger/bsv@9.21.0/bsv.bundle.js"></script>
172
+ <script src="https://unpkg.com/@smartledger/bsv@9.22.1/bsv.bundle.js"></script>
173
173
  ```
174
174
 
175
175
  ## 🔍 **Testing Your Migration**
@@ -5,6 +5,7 @@ var AttestationSigner = require('./attestation-signer')
5
5
  var Hash = require('../crypto/hash')
6
6
  var BN = require('../crypto/bn')
7
7
  var $ = require('../util/preconditions')
8
+ var JCS = require('../util/jcs')
8
9
 
9
10
  /**
10
11
  * ZKProver
@@ -552,19 +553,72 @@ ZKProver._generateAgeChallenge = function(birthDate, minimumAge, salt) {
552
553
  * @param {String} salt - Random salt
553
554
  * @returns {Object} Membership proof
554
555
  */
556
+ /**
557
+ * The canonical bytes a set member or claimed value commits to.
558
+ *
559
+ * `JSON.stringify` is NOT injective, and the commitment inherited every collision. All of
560
+ * `null`, `NaN`, `Infinity` and `-Infinity` render as `"null"`, so a prover could claim `NaN`
561
+ * was a member of `[null]` and the recomputed commitments matched — a forgery that survived
562
+ * the 9.20.0 fix, found by red-teaming it rather than by a test. `{a:1,b:undefined}` renders
563
+ * identically to `{a:1}`, and key order made two spellings of the same object commit
564
+ * differently, so a legitimate caller could also be refused.
565
+ *
566
+ * So: a restricted value domain, validated recursively, encoded with RFC 8785 canonical JSON.
567
+ * JCS sorts keys (two spellings of one object now agree) and refuses non-finite numbers and
568
+ * `undefined` outright. The recursive check adds what JCS alone does not catch — an
569
+ * `undefined` PROPERTY VALUE, which JCS drops exactly as JSON does.
570
+ *
571
+ * Allowed: null, boolean, finite number, string, array, plain object of those.
572
+ */
573
+ function canonicalMember (value, path) {
574
+ var where = path || 'value'
575
+ var t = typeof value
576
+ if (value === null || t === 'boolean' || t === 'string') {
577
+ // fine
578
+ } else if (t === 'number') {
579
+ if (!isFinite(value)) throw new Error(where + ' must be a finite number')
580
+ } else if (Array.isArray(value)) {
581
+ for (var i = 0; i < value.length; i++) {
582
+ if (value[i] === undefined) throw new Error(where + '[' + i + '] is undefined')
583
+ canonicalMember(value[i], where + '[' + i + ']')
584
+ }
585
+ } else if (t === 'object') {
586
+ if (Object.getPrototypeOf(value) !== Object.prototype &&
587
+ Object.getPrototypeOf(value) !== null) {
588
+ throw new Error(where + ' must be a plain object')
589
+ }
590
+ var keys = Object.keys(value)
591
+ for (var k = 0; k < keys.length; k++) {
592
+ if (value[keys[k]] === undefined) {
593
+ throw new Error(where + '.' + keys[k] + ' is undefined')
594
+ }
595
+ canonicalMember(value[keys[k]], where + '.' + keys[k])
596
+ }
597
+ } else {
598
+ throw new Error(where + ' is not a permitted type: ' + t)
599
+ }
600
+ return JCS.stringify(value)
601
+ }
602
+
555
603
  ZKProver.generateMembershipProof = function(set, value, salt) {
556
604
  $.checkArgument(Array.isArray(set), 'Set must be array')
557
- $.checkArgument(set.includes(value), 'Value not in set')
558
-
605
+
606
+ // Membership is structural, over the canonical form. `set.includes(value)` compared objects
607
+ // by reference, so generating a proof for a structurally equal object threw "Value not in
608
+ // set" — a caller could not use this with object members at all.
609
+ var canonicalSet = set.map(function (member, i) {
610
+ return canonicalMember(member, 'set[' + i + ']')
611
+ })
612
+ var canonicalValue = canonicalMember(value)
613
+ $.checkArgument(canonicalSet.indexOf(canonicalValue) !== -1, 'Value not in set')
614
+
559
615
  salt = salt || Random.getRandomBuffer(32).toString('hex')
560
-
561
- // Create commitments to all set members
562
- var commitments = set.map(function(member) {
563
- return Hash.sha256(Buffer.from(JSON.stringify(member) + ':' + salt, 'utf8')).toString('hex')
616
+
617
+ var commitments = canonicalSet.map(function (form) {
618
+ return Hash.sha256(Buffer.from(form + ':' + salt, 'utf8')).toString('hex')
564
619
  })
565
-
566
- // Create commitment to the claimed value
567
- var valueCommitment = Hash.sha256(Buffer.from(JSON.stringify(value) + ':' + salt, 'utf8')).toString('hex')
620
+
621
+ var valueCommitment = Hash.sha256(Buffer.from(canonicalValue + ':' + salt, 'utf8')).toString('hex')
568
622
 
569
623
  return {
570
624
  type: 'MembershipProof',
@@ -640,15 +694,18 @@ ZKProver.verifyMembershipProof = function(proof, opening, set) {
640
694
  return false
641
695
  }
642
696
 
643
- var commit = function (member) {
697
+ // Canonical, injective encoding over a validated domain — see canonicalMember. Anything
698
+ // outside the domain throws, and the catch below answers false, which is the honest
699
+ // verdict for a value this construction cannot commit to unambiguously.
700
+ var commit = function (member, path) {
644
701
  return Hash.sha256(
645
- Buffer.from(JSON.stringify(member) + ':' + opening.salt, 'utf8')
702
+ Buffer.from(canonicalMember(member, path) + ':' + opening.salt, 'utf8')
646
703
  ).toString('hex')
647
704
  }
648
705
 
649
706
  // The prover's array must be exactly the commitments the verifier's set implies, in
650
707
  // order. Comparing as a set would let a prover append a commitment of its own.
651
- var expected = set.map(commit)
708
+ var expected = set.map(function (m, i) { return commit(m, 'set[' + i + ']') })
652
709
  if (expected.length !== proof.setCommitments.length) {
653
710
  return false
654
711
  }
@@ -659,7 +716,7 @@ ZKProver.verifyMembershipProof = function(proof, opening, set) {
659
716
  }
660
717
 
661
718
  // The opening must commit to the value the proof names.
662
- if (commit(opening.value) !== proof.valueCommitment) {
719
+ if (commit(opening.value, 'opening.value') !== proof.valueCommitment) {
663
720
  return false
664
721
  }
665
722
 
@@ -72,18 +72,48 @@ var sighashPreimageForForkId = function (transaction, sighashType, inputNumber,
72
72
  var hashSequence = Buffer.alloc(32)
73
73
  var hashOutputs = Buffer.alloc(32)
74
74
 
75
+ // These three digests are the same for EVERY input of a transaction, and computing them
76
+ // costs a pass over all the inputs or all the outputs. Recomputing them per input made
77
+ // signing quadratic: measured on 9.22.0, 100 inputs took 0.9 s and 5,000 took 194 s —
78
+ // 50x the inputs for 216x the time.
79
+ //
80
+ // `Transaction.prototype.getSignatures` opens a cache for the duration of its pass and
81
+ // closes it afterwards. That window is safe without any invalidation logic, because
82
+ // `sign()` collects every signature BEFORE applying any of them, so no input or output
83
+ // changes while the cache is open. Outside that window there is no cache and nothing is
84
+ // remembered, which is why this cannot go stale.
85
+ //
86
+ // The SIGHASH_SINGLE branch is deliberately NOT cached: it hashes one output chosen by
87
+ // `inputNumber`, so it differs per input and is O(1) anyway.
88
+ var midstates = transaction && transaction._sighashMidstates
89
+
75
90
  if (!(sighashType & Signature.SIGHASH_ANYONECANPAY)) {
76
- hashPrevouts = GetPrevoutHash(transaction)
91
+ if (midstates) {
92
+ if (!midstates.prevouts) midstates.prevouts = GetPrevoutHash(transaction)
93
+ hashPrevouts = midstates.prevouts
94
+ } else {
95
+ hashPrevouts = GetPrevoutHash(transaction)
96
+ }
77
97
  }
78
98
 
79
99
  if (!(sighashType & Signature.SIGHASH_ANYONECANPAY) &&
80
100
  (sighashType & 31) !== Signature.SIGHASH_SINGLE &&
81
101
  (sighashType & 31) !== Signature.SIGHASH_NONE) {
82
- hashSequence = GetSequenceHash(transaction)
102
+ if (midstates) {
103
+ if (!midstates.sequence) midstates.sequence = GetSequenceHash(transaction)
104
+ hashSequence = midstates.sequence
105
+ } else {
106
+ hashSequence = GetSequenceHash(transaction)
107
+ }
83
108
  }
84
109
 
85
110
  if ((sighashType & 31) !== Signature.SIGHASH_SINGLE && (sighashType & 31) !== Signature.SIGHASH_NONE) {
86
- hashOutputs = GetOutputsHash(transaction)
111
+ if (midstates) {
112
+ if (!midstates.outputsAll) midstates.outputsAll = GetOutputsHash(transaction)
113
+ hashOutputs = midstates.outputsAll
114
+ } else {
115
+ hashOutputs = GetOutputsHash(transaction)
116
+ }
87
117
  } else if ((sighashType & 31) === Signature.SIGHASH_SINGLE && inputNumber < transaction.outputs.length) {
88
118
  hashOutputs = GetOutputsHash(transaction, inputNumber)
89
119
  }
@@ -1080,9 +1080,30 @@ Transaction.prototype.sign = function (privateKey, sigtype) {
1080
1080
  })
1081
1081
  return this
1082
1082
  }
1083
- _.each(this.getSignatures(privateKey, sigtype), function (signature) {
1084
- self.applySignature(signature)
1085
- })
1083
+
1084
+ // The midstate cache covers the WHOLE signing call, not just signature collection.
1085
+ //
1086
+ // `applySignature` -> `addSignature` re-verifies each signature before applying it, which
1087
+ // recomputes the preimage, so the apply loop was quadratic for the same reason the collect
1088
+ // loop was — and measured larger: at 5,000 inputs, 68.7 s applying against 50.3 s
1089
+ // collecting.
1090
+ //
1091
+ // Widening the window is safe because the only thing the apply loop changes is each input's
1092
+ // SCRIPT, and none of the three cached digests depends on a script: hashPrevouts covers
1093
+ // outpoints, hashSequence covers sequence numbers, hashOutputs covers outputs. A script
1094
+ // cannot alter any of them.
1095
+ //
1096
+ // `_.isArray` recursion above re-enters this function, so an existing cache is left alone
1097
+ // and only the outermost call clears it.
1098
+ var owns = !this._sighashMidstates
1099
+ if (owns) this._sighashMidstates = {}
1100
+ try {
1101
+ _.each(this.getSignatures(privateKey, sigtype), function (signature) {
1102
+ self.applySignature(signature)
1103
+ })
1104
+ } finally {
1105
+ if (owns) delete this._sighashMidstates
1106
+ }
1086
1107
  return this
1087
1108
  }
1088
1109
 
@@ -1093,11 +1114,30 @@ Transaction.prototype.getSignatures = function (privKey, sigtype) {
1093
1114
  var transaction = this
1094
1115
  var results = []
1095
1116
  var hashData = Hash.sha256ripemd160(privKey.publicKey.toBuffer())
1096
- _.each(this.inputs, function forEachInput (input, index) {
1097
- _.each(input.getSignatures(transaction, privKey, index, sigtype, hashData), function (signature) {
1098
- results.push(signature)
1117
+
1118
+ // The FORKID preimage's hashPrevouts, hashSequence and hashOutputs are identical for every
1119
+ // input of this transaction, and each costs a pass over all inputs or all outputs. Without
1120
+ // this, signing n inputs recomputed them n times and the cost was quadratic: 5,000 inputs
1121
+ // took 194 seconds on 9.22.0.
1122
+ //
1123
+ // The cache is opened for this pass only and removed in a `finally`, so nothing survives
1124
+ // the call and no invalidation is needed. It is sound precisely because this loop only
1125
+ // COLLECTS signatures — `sign()` applies them afterwards — so no input or output changes
1126
+ // while it is open. Anything that mutates the transaction does so outside this window and
1127
+ // finds no cache to go stale.
1128
+ // Opened here too, so a caller using getSignatures directly also gets the linear path.
1129
+ // Only whoever opened it closes it — `sign()` wraps both loops in one window.
1130
+ var ownsCache = !this._sighashMidstates
1131
+ if (ownsCache) this._sighashMidstates = {}
1132
+ try {
1133
+ _.each(this.inputs, function forEachInput (input, index) {
1134
+ _.each(input.getSignatures(transaction, privKey, index, sigtype, hashData), function (signature) {
1135
+ results.push(signature)
1136
+ })
1099
1137
  })
1100
- })
1138
+ } finally {
1139
+ if (ownsCache) delete this._sighashMidstates
1140
+ }
1101
1141
  return results
1102
1142
  }
1103
1143
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@smartledger/bsv",
3
- "version": "9.21.0",
3
+ "version": "9.22.1",
4
4
  "description": "Bitcoin SV library with an interpreter-verified script engine: OP_PUSH_TX covenants, BIP-143 preimage tooling, and consensus flags that match what miners actually enforce. Also ships DID:web / W3C VC-JWT credentials and the Legal Token Protocol.",
5
5
  "author": "SmartLedger Technology <hello@smartledger.technology> (https://smartledger.technology)",
6
6
  "homepage": "https://github.com/codenlighten/smartledger-bsv#readme",
package/version.js CHANGED
@@ -1,3 +1,3 @@
1
1
  'use strict'
2
2
  // GENERATED by scripts/sync-version.js on `npm version` — do not edit.
3
- module.exports = '9.21.0'
3
+ module.exports = '9.22.1'