@smartledger/bsv 9.10.1 → 9.11.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,12 +34,12 @@ 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 — 11,989 lines
37
+ ### Tier 1 — 12,013 lines
38
38
 
39
39
  | Module | Lines | Why it matters |
40
40
  | --- | ---: | --- |
41
- | `lib/transaction/` | 2,779 | Sighash construction and signing — both BIP-143 and the Original Transaction Digest Algorithm. |
42
- | `lib/script/interpreter.js` | 2,834 | **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. |
41
+ | `lib/transaction/` | 2,786 | Sighash construction and signing — both BIP-143 and the Original Transaction Digest Algorithm. |
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
44
  | `lib/notaryhash/` | 2,028 | 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. |
@@ -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,673 lines across 131 files:
153
+ Totals reconcile against `lib/`, which is 39,779 lines across 131 files:
154
154
 
155
155
  ```
156
- tier 1 11,989
156
+ tier 1 12,013
157
157
  tier 2 1,607
158
- excluded 26,077
158
+ excluded 26,159
159
159
  ------
160
- total 39,673
160
+ total 39,779
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 — 11,989 lines. Sighash construction and signing; ECDSA, nonce
231
+ Tier 1 — 12,013 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.10.1/bsv-shamir.min.js`
58
+ - **CDN**: `unpkg.com/@smartledger/bsv@9.11.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.10.1/bsv-gdaf.min.js`
64
+ - **CDN**: `unpkg.com/@smartledger/bsv@9.11.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.10.1/bsv-ltp.min.js`
70
+ - **CDN**: `unpkg.com/@smartledger/bsv@9.11.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.10.1/bsv.min.js` |
85
- | **bsv.bundle.js** | 937KB | Everything in one file | `unpkg.com/@smartledger/bsv@9.10.1/bsv.bundle.js` |
86
- | **bsv-smartcontract.min.js** | 937KB | Covenant development | `unpkg.com/@smartledger/bsv@9.10.1/bsv-smartcontract.min.js` |
87
- | **bsv-covenant.min.js** | 913KB | Covenant operations | `unpkg.com/@smartledger/bsv@9.10.1/bsv-covenant.min.js` |
88
- | **bsv-script-helper.min.js** | 26KB | Custom script tools | `unpkg.com/@smartledger/bsv@9.10.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.10.1/bsv-security.min.js` |
90
- | **bsv-ecies.min.js** | 71KB | Encryption | `unpkg.com/@smartledger/bsv@9.10.1/bsv-ecies.min.js` |
91
- | **bsv-message.min.js** | 26KB | Message signing | `unpkg.com/@smartledger/bsv@9.10.1/bsv-message.min.js` |
92
- | **bsv-mnemonic.min.js** | 681KB | HD wallets | `unpkg.com/@smartledger/bsv@9.10.1/bsv-mnemonic.min.js` |
93
- | **🆕 bsv-shamir.min.js** | 432KB | **Secret sharing** | `unpkg.com/@smartledger/bsv@9.10.1/bsv-shamir.min.js` |
94
- | **🆕 bsv-gdaf.min.js** | 1184KB | **Digital attestation** | `unpkg.com/@smartledger/bsv@9.10.1/bsv-gdaf.min.js` |
95
- | **🆕 bsv-ltp.min.js** | 1184KB | **Legal tokens** | `unpkg.com/@smartledger/bsv@9.10.1/bsv-ltp.min.js` |
84
+ | **bsv.min.js** | 937KB | Core BSV + SmartContract | `unpkg.com/@smartledger/bsv@9.11.1/bsv.min.js` |
85
+ | **bsv.bundle.js** | 937KB | Everything in one file | `unpkg.com/@smartledger/bsv@9.11.1/bsv.bundle.js` |
86
+ | **bsv-smartcontract.min.js** | 937KB | Covenant development | `unpkg.com/@smartledger/bsv@9.11.1/bsv-smartcontract.min.js` |
87
+ | **bsv-covenant.min.js** | 913KB | Covenant operations | `unpkg.com/@smartledger/bsv@9.11.1/bsv-covenant.min.js` |
88
+ | **bsv-script-helper.min.js** | 26KB | Custom script tools | `unpkg.com/@smartledger/bsv@9.11.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.11.1/bsv-security.min.js` |
90
+ | **bsv-ecies.min.js** | 71KB | Encryption | `unpkg.com/@smartledger/bsv@9.11.1/bsv-ecies.min.js` |
91
+ | **bsv-message.min.js** | 26KB | Message signing | `unpkg.com/@smartledger/bsv@9.11.1/bsv-message.min.js` |
92
+ | **bsv-mnemonic.min.js** | 681KB | HD wallets | `unpkg.com/@smartledger/bsv@9.11.1/bsv-mnemonic.min.js` |
93
+ | **🆕 bsv-shamir.min.js** | 432KB | **Secret sharing** | `unpkg.com/@smartledger/bsv@9.11.1/bsv-shamir.min.js` |
94
+ | **🆕 bsv-gdaf.min.js** | 1184KB | **Digital attestation** | `unpkg.com/@smartledger/bsv@9.11.1/bsv-gdaf.min.js` |
95
+ | **🆕 bsv-ltp.min.js** | 1184KB | **Legal tokens** | `unpkg.com/@smartledger/bsv@9.11.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.10.1/bsv.min.js"></script>
104
- <script src="https://unpkg.com/@smartledger/bsv@9.10.1/bsv-script-helper.min.js"></script>
103
+ <script src="https://unpkg.com/@smartledger/bsv@9.11.1/bsv.min.js"></script>
104
+ <script src="https://unpkg.com/@smartledger/bsv@9.11.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.10.1/bsv.min.js"></script>
110
- <script src="https://unpkg.com/@smartledger/bsv@9.10.1/bsv-covenant.min.js"></script>
111
- <script src="https://unpkg.com/@smartledger/bsv@9.10.1/bsv-smartcontract.min.js"></script>
109
+ <script src="https://unpkg.com/@smartledger/bsv@9.11.1/bsv.min.js"></script>
110
+ <script src="https://unpkg.com/@smartledger/bsv@9.11.1/bsv-covenant.min.js"></script>
111
+ <script src="https://unpkg.com/@smartledger/bsv@9.11.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.10.1/bsv.min.js"></script>
117
- <script src="https://unpkg.com/@smartledger/bsv@9.10.1/bsv-ltp.min.js"></script>
118
- <script src="https://unpkg.com/@smartledger/bsv@9.10.1/bsv-gdaf.min.js"></script>
116
+ <script src="https://unpkg.com/@smartledger/bsv@9.11.1/bsv.min.js"></script>
117
+ <script src="https://unpkg.com/@smartledger/bsv@9.11.1/bsv-ltp.min.js"></script>
118
+ <script src="https://unpkg.com/@smartledger/bsv@9.11.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.10.1/bsv.min.js"></script>
136
- <script src="https://unpkg.com/@smartledger/bsv@9.10.1/bsv-security.min.js"></script>
137
- <script src="https://unpkg.com/@smartledger/bsv@9.10.1/bsv-shamir.min.js"></script>
135
+ <script src="https://unpkg.com/@smartledger/bsv@9.11.1/bsv.min.js"></script>
136
+ <script src="https://unpkg.com/@smartledger/bsv@9.11.1/bsv-security.min.js"></script>
137
+ <script src="https://unpkg.com/@smartledger/bsv@9.11.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.10.1/bsv.bundle.js"></script>
149
+ <script src="https://unpkg.com/@smartledger/bsv@9.11.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.10.1/bsv.min.js"></script>
725
+ <script src="https://cdn.jsdelivr.net/npm/@smartledger/bsv@9.11.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 — 11,989 lines. Sighash construction and signing; ECDSA, nonce
18
+ Tier 1 — 12,013 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,077-line application layer (credentials, tokens, ordinals), which we would
33
+ 26,159-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 — 11,989 lines. Sighash construction and signing; ECDSA, nonce
18
+ Tier 1 — 12,013 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,077-line application layer (credentials, tokens, ordinals), which we would
33
+ 26,159-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 — 11,989 lines. Sighash construction and signing; ECDSA, nonce
18
+ Tier 1 — 12,013 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,077-line application layer (credentials, tokens, ordinals), which we would
33
+ 26,159-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.10.1/bsv.min.js"></script>
51
+ <script src="https://unpkg.com/@smartledger/bsv@9.11.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.10.1/bsv.bundle.js"></script>
61
+ <script src="https://unpkg.com/@smartledger/bsv@9.11.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.10.1/bsv.min.js"></script>
75
- <script src="https://unpkg.com/@smartledger/bsv@9.10.1/bsv-covenant.min.js"></script>
76
- <script src="https://unpkg.com/@smartledger/bsv@9.10.1/bsv-smartcontract.min.js"></script>
74
+ <script src="https://unpkg.com/@smartledger/bsv@9.11.1/bsv.min.js"></script>
75
+ <script src="https://unpkg.com/@smartledger/bsv@9.11.1/bsv-covenant.min.js"></script>
76
+ <script src="https://unpkg.com/@smartledger/bsv@9.11.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.10.1/bsv.min.js"></script>
86
- <script src="https://unpkg.com/@smartledger/bsv@9.10.1/bsv-ltp.min.js"></script>
87
- <script src="https://unpkg.com/@smartledger/bsv@9.10.1/bsv-gdaf.min.js"></script>
85
+ <script src="https://unpkg.com/@smartledger/bsv@9.11.1/bsv.min.js"></script>
86
+ <script src="https://unpkg.com/@smartledger/bsv@9.11.1/bsv-ltp.min.js"></script>
87
+ <script src="https://unpkg.com/@smartledger/bsv@9.11.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.10.1/bsv.min.js"></script>
102
- <script src="https://unpkg.com/@smartledger/bsv@9.10.1/bsv-security.min.js"></script>
103
- <script src="https://unpkg.com/@smartledger/bsv@9.10.1/bsv-shamir.min.js"></script>
101
+ <script src="https://unpkg.com/@smartledger/bsv@9.11.1/bsv.min.js"></script>
102
+ <script src="https://unpkg.com/@smartledger/bsv@9.11.1/bsv-security.min.js"></script>
103
+ <script src="https://unpkg.com/@smartledger/bsv@9.11.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.10.1/bsv.min.js` |
118
- | **bsv.bundle.js** | 937KB | Everything in one file | `unpkg.com/@smartledger/bsv@9.10.1/bsv.bundle.js` |
119
- | **bsv-smartcontract.min.js** | 937KB | Complete covenant framework | `unpkg.com/@smartledger/bsv@9.10.1/bsv-smartcontract.min.js` |
120
- | **bsv-ltp.min.js** | 1184KB | **Legal Token Protocol** | `unpkg.com/@smartledger/bsv@9.10.1/bsv-ltp.min.js` |
121
- | **bsv-gdaf.min.js** | 1184KB | **Digital Identity & Attestation** | `unpkg.com/@smartledger/bsv@9.10.1/bsv-gdaf.min.js` |
122
- | **bsv-shamir.min.js** | 432KB | **Threshold Cryptography** | `unpkg.com/@smartledger/bsv@9.10.1/bsv-shamir.min.js` |
123
- | **bsv-security.min.js** | 26KB | Security enhancements (opt-in helpers — see README › Security) | `unpkg.com/@smartledger/bsv@9.10.1/bsv-security.min.js` |
124
- | **bsv-mnemonic.min.js** | 681KB | HD wallets | `unpkg.com/@smartledger/bsv@9.10.1/bsv-mnemonic.min.js` |
125
- | **bsv-ecies.min.js** | 71KB | Encryption | `unpkg.com/@smartledger/bsv@9.10.1/bsv-ecies.min.js` |
126
- | **bsv-covenant.min.js** | 913KB | Covenant operations | `unpkg.com/@smartledger/bsv@9.10.1/bsv-covenant.min.js` |
127
- | **bsv-script-helper.min.js** | 26KB | Custom script tools | `unpkg.com/@smartledger/bsv@9.10.1/bsv-script-helper.min.js` |
128
- | **bsv-message.min.js** | 26KB | Message signing | `unpkg.com/@smartledger/bsv@9.10.1/bsv-message.min.js` |
117
+ | **bsv.min.js** | 937KB | Core BSV + SmartContract | `unpkg.com/@smartledger/bsv@9.11.1/bsv.min.js` |
118
+ | **bsv.bundle.js** | 937KB | Everything in one file | `unpkg.com/@smartledger/bsv@9.11.1/bsv.bundle.js` |
119
+ | **bsv-smartcontract.min.js** | 937KB | Complete covenant framework | `unpkg.com/@smartledger/bsv@9.11.1/bsv-smartcontract.min.js` |
120
+ | **bsv-ltp.min.js** | 1184KB | **Legal Token Protocol** | `unpkg.com/@smartledger/bsv@9.11.1/bsv-ltp.min.js` |
121
+ | **bsv-gdaf.min.js** | 1184KB | **Digital Identity & Attestation** | `unpkg.com/@smartledger/bsv@9.11.1/bsv-gdaf.min.js` |
122
+ | **bsv-shamir.min.js** | 432KB | **Threshold Cryptography** | `unpkg.com/@smartledger/bsv@9.11.1/bsv-shamir.min.js` |
123
+ | **bsv-security.min.js** | 26KB | Security enhancements (opt-in helpers — see README › Security) | `unpkg.com/@smartledger/bsv@9.11.1/bsv-security.min.js` |
124
+ | **bsv-mnemonic.min.js** | 681KB | HD wallets | `unpkg.com/@smartledger/bsv@9.11.1/bsv-mnemonic.min.js` |
125
+ | **bsv-ecies.min.js** | 71KB | Encryption | `unpkg.com/@smartledger/bsv@9.11.1/bsv-ecies.min.js` |
126
+ | **bsv-covenant.min.js** | 913KB | Covenant operations | `unpkg.com/@smartledger/bsv@9.11.1/bsv-covenant.min.js` |
127
+ | **bsv-script-helper.min.js** | 26KB | Custom script tools | `unpkg.com/@smartledger/bsv@9.11.1/bsv-script-helper.min.js` |
128
+ | **bsv-message.min.js** | 26KB | Message signing | `unpkg.com/@smartledger/bsv@9.11.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.10.1/bsv.min.js"></script>
17
+ <script src="https://unpkg.com/@smartledger/bsv@9.11.1/bsv.min.js"></script>
18
18
 
19
19
  <!-- Everything included (937KB) -->
20
- <script src="https://unpkg.com/@smartledger/bsv@9.10.1/bsv.bundle.js"></script>
20
+ <script src="https://unpkg.com/@smartledger/bsv@9.11.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.10.1/bsv.min.js"></script>
130
+ <script src="https://unpkg.com/@smartledger/bsv@9.11.1/bsv.min.js"></script>
131
131
 
132
132
  <!-- Smart contracts (937KB) -->
133
- <script src="https://unpkg.com/@smartledger/bsv@9.10.1/bsv-smartcontract.min.js"></script>
133
+ <script src="https://unpkg.com/@smartledger/bsv@9.11.1/bsv-smartcontract.min.js"></script>
134
134
 
135
135
  <!-- Legal tokens (1.16MB) -->
136
- <script src="https://unpkg.com/@smartledger/bsv@9.10.1/bsv-ltp.min.js"></script>
136
+ <script src="https://unpkg.com/@smartledger/bsv@9.11.1/bsv-ltp.min.js"></script>
137
137
 
138
138
  <!-- Digital identity (1.16MB) -->
139
- <script src="https://unpkg.com/@smartledger/bsv@9.10.1/bsv-gdaf.min.js"></script>
139
+ <script src="https://unpkg.com/@smartledger/bsv@9.11.1/bsv-gdaf.min.js"></script>
140
140
 
141
141
  <!-- Everything (937KB) -->
142
- <script src="https://unpkg.com/@smartledger/bsv@9.10.1/bsv.bundle.js"></script>
142
+ <script src="https://unpkg.com/@smartledger/bsv@9.11.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.10.1/bsv.min.js"></script>
162
+ <script src="https://unpkg.com/@smartledger/bsv@9.11.1/bsv.min.js"></script>
163
163
 
164
164
  <!-- Add smart contracts when ready -->
165
- <script src="https://unpkg.com/@smartledger/bsv@9.10.1/bsv-smartcontract.min.js"></script>
165
+ <script src="https://unpkg.com/@smartledger/bsv@9.11.1/bsv-smartcontract.min.js"></script>
166
166
 
167
167
  <!-- Add advanced features as needed -->
168
- <script src="https://unpkg.com/@smartledger/bsv@9.10.1/bsv-ltp.min.js"></script>
169
- <script src="https://unpkg.com/@smartledger/bsv@9.10.1/bsv-gdaf.min.js"></script>
168
+ <script src="https://unpkg.com/@smartledger/bsv@9.11.1/bsv-ltp.min.js"></script>
169
+ <script src="https://unpkg.com/@smartledger/bsv@9.11.1/bsv-gdaf.min.js"></script>
170
170
 
171
171
  <!-- Everything in one file -->
172
- <script src="https://unpkg.com/@smartledger/bsv@9.10.1/bsv.bundle.js"></script>
172
+ <script src="https://unpkg.com/@smartledger/bsv@9.11.1/bsv.bundle.js"></script>
173
173
  ```
174
174
 
175
175
  ## 🔍 **Testing Your Migration**
@@ -896,6 +896,20 @@ Interpreter.prototype.checkSignatureEncoding = function (buf) {
896
896
  return true
897
897
  }
898
898
 
899
+ /**
900
+ * The node's CleanupScriptCode: remove the signature from the scriptCode it
901
+ * signs, unless it is a FORKID signature and FORKID is enabled. An empty
902
+ * signature has hash type 0, so without FORKID it removes every OP_0, as the
903
+ * node's does.
904
+ */
905
+ function cleanupScriptCode (subscript, bufSig, flags) {
906
+ var hashType = bufSig.length ? bufSig[bufSig.length - 1] : 0
907
+ if (!(flags & Interpreter.SCRIPT_ENABLE_SIGHASH_FORKID) || !(hashType & Signature.SIGHASH_FORKID)) {
908
+ subscript.findAndDelete(new Script().add(bufSig))
909
+ }
910
+ return subscript
911
+ }
912
+
899
913
  /**
900
914
  * Translated from bitcoind's CheckPubKeyEncoding
901
915
  */
@@ -2425,9 +2439,12 @@ Interpreter.prototype.step = function () {
2425
2439
  chunks: this.script.chunks.slice(this.pbegincodehash)
2426
2440
  })
2427
2441
 
2428
- // Drop the signature, since there's no way for a signature to sign itself
2429
- var tmpScript = new Script().add(bufSig)
2430
- subscript.findAndDelete(tmpScript)
2442
+ // Drop the signature, since there's no way for a signature to sign
2443
+ // itself — but only where the node does: not for a FORKID signature
2444
+ // when FORKID is enabled (CleanupScriptCode). Removing it there let a
2445
+ // signature over the script minus a pushed copy of itself verify here
2446
+ // and fail on the network.
2447
+ cleanupScriptCode(subscript, bufSig, this.flags)
2431
2448
 
2432
2449
  try {
2433
2450
  sig = Signature.fromTxFormat(bufSig)
@@ -2525,7 +2542,7 @@ Interpreter.prototype.step = function () {
2525
2542
  // Drop the signatures, since there's no way for a signature to sign itself
2526
2543
  for (var k = 0; k < nSigsCount; k++) {
2527
2544
  bufSig = stacktop(-isig - k)
2528
- subscript.findAndDelete(new Script().add(bufSig))
2545
+ cleanupScriptCode(subscript, bufSig, this.flags)
2529
2546
  }
2530
2547
 
2531
2548
  fSuccess = true
@@ -1,8 +1,9 @@
1
1
  'use strict'
2
2
 
3
+ var assert = require('assert')
4
+
3
5
  var Address = require('../address')
4
6
  var BufferReader = require('../encoding/bufferreader')
5
- var BufferWriter = require('../encoding/bufferwriter')
6
7
  var Hash = require('../crypto/hash')
7
8
  var Opcode = require('../opcode')
8
9
  var PublicKey = require('../publickey')
@@ -107,45 +108,100 @@ Script.fromBuffer = function (buffer) {
107
108
  }
108
109
 
109
110
  Script.prototype.toBuffer = function () {
110
- var bw = new BufferWriter()
111
+ // Sized first and written into one allocation. A locking script can have
112
+ // hundreds of thousands of chunks, and this runs for every signature check
113
+ // over it; a writer that allocates per chunk made that the dominant cost.
114
+ // Writes go through Buffer's checked writers, so a malformed chunk throws
115
+ // exactly where the per-chunk writer threw.
116
+ var chunks = this.chunks
117
+ var size = 0
118
+ var i, chunk, opcodenum
119
+ for (i = 0; i < chunks.length; i++) {
120
+ chunk = chunks[i]
121
+ opcodenum = chunk.opcodenum
122
+ size += 1
123
+ if (chunk.buf) {
124
+ if (opcodenum < Opcode.OP_PUSHDATA1) {
125
+ size += bufLength(chunk.buf)
126
+ } else if (opcodenum === Opcode.OP_PUSHDATA1) {
127
+ size += 1 + bufLength(chunk.buf)
128
+ } else if (opcodenum === Opcode.OP_PUSHDATA2) {
129
+ size += 2 + bufLength(chunk.buf)
130
+ } else if (opcodenum === Opcode.OP_PUSHDATA4) {
131
+ size += 4 + bufLength(chunk.buf)
132
+ }
133
+ }
134
+ }
111
135
 
112
- for (var i = 0; i < this.chunks.length; i++) {
113
- var chunk = this.chunks[i]
114
- var opcodenum = chunk.opcodenum
115
- bw.writeUInt8(chunk.opcodenum)
136
+ var out = Buffer.alloc(size)
137
+ var o = 0
138
+ for (i = 0; i < chunks.length; i++) {
139
+ chunk = chunks[i]
140
+ opcodenum = chunk.opcodenum
141
+ o = out.writeUInt8(chunk.opcodenum, o)
116
142
  if (chunk.buf) {
117
143
  if (opcodenum < Opcode.OP_PUSHDATA1) {
118
- bw.write(chunk.buf)
144
+ o += chunk.buf.copy(out, o)
119
145
  } else if (opcodenum === Opcode.OP_PUSHDATA1) {
120
- bw.writeUInt8(chunk.len)
121
- bw.write(chunk.buf)
146
+ o = out.writeUInt8(chunk.len, o)
147
+ o += chunk.buf.copy(out, o)
122
148
  } else if (opcodenum === Opcode.OP_PUSHDATA2) {
123
- bw.writeUInt16LE(chunk.len)
124
- bw.write(chunk.buf)
149
+ o = out.writeUInt16LE(chunk.len, o)
150
+ o += chunk.buf.copy(out, o)
125
151
  } else if (opcodenum === Opcode.OP_PUSHDATA4) {
126
- bw.writeUInt32LE(chunk.len)
127
- bw.write(chunk.buf)
152
+ o = out.writeUInt32LE(chunk.len, o)
153
+ o += chunk.buf.copy(out, o)
128
154
  }
129
155
  }
130
156
  }
157
+ return out
158
+ }
159
+
160
+ // A chunk's data must be a Buffer; BufferWriter#write asserted as much.
161
+ function bufLength (buf) {
162
+ if (!Buffer.isBuffer(buf)) throw new assert.AssertionError({ message: 'chunk data must be a Buffer', actual: buf, expected: 'Buffer', operator: 'isBuffer' })
163
+ return buf.length
164
+ }
131
165
 
132
- return bw.concat()
166
+ /**
167
+ * An opcode written as a single raw byte, `0xba`: how toASM and toString write an
168
+ * opcode that has no name, and how bitcoind's script test format writes raw bytes.
169
+ * Only a non-push byte qualifies. A push byte on its own is an incomplete push.
170
+ *
171
+ * @returns {number|undefined} the opcode, or undefined if the token is not one
172
+ */
173
+ function rawOpcodeToken (token) {
174
+ if (!/^0x[0-9a-fA-F]{2}$/.test(token)) return undefined
175
+ var num = parseInt(token.slice(2), 16)
176
+ return num > Opcode.OP_PUSHDATA4 ? num : undefined
133
177
  }
134
178
 
135
179
  Script.fromASM = function (str) {
136
180
  var script = new Script()
137
181
  script.chunks = []
138
182
 
183
+ // toASM writes an empty script as ''. Splitting it would yield one empty token,
184
+ // which the data branch below reads as an empty push: OP_0, a different script.
185
+ if (str === '') {
186
+ return script
187
+ }
188
+
139
189
  var tokens = str.split(' ')
140
190
  var i = 0
141
191
  while (i < tokens.length) {
142
192
  var token = tokens[i]
143
193
  var opcode = Opcode(token)
144
194
  var opcodenum = opcode.toNumber()
195
+ var raw = rawOpcodeToken(token)
145
196
 
146
197
  // we start with two special cases, 0 and -1, which are handled specially in
147
198
  // toASM. see _chunkToString.
148
- if (token === '0') {
199
+ if (raw !== undefined) {
200
+ script.chunks.push({
201
+ opcodenum: raw
202
+ })
203
+ i = i + 1
204
+ } else if (token === '0') {
149
205
  opcodenum = 0
150
206
  script.chunks.push({
151
207
  opcodenum: opcodenum
@@ -205,8 +261,15 @@ Script.fromString = function (str) {
205
261
  var token = tokens[i]
206
262
  var opcode = Opcode(token)
207
263
  var opcodenum = opcode.toNumber()
264
+ var raw = rawOpcodeToken(token)
208
265
 
209
- if (_.isUndefined(opcodenum)) {
266
+ if (raw !== undefined) {
267
+ // An opcode with no name, as toString writes it.
268
+ script.chunks.push({
269
+ opcodenum: raw
270
+ })
271
+ i = i + 1
272
+ } else if (_.isUndefined(opcodenum)) {
210
273
  opcodenum = parseInt(token)
211
274
  if (opcodenum > 0 && opcodenum < Opcode.OP_PUSHDATA1) {
212
275
  script.chunks.push({
@@ -267,11 +330,10 @@ Script.prototype._chunkToString = function (chunk, type) {
267
330
  if (numstr.length % 2 !== 0) {
268
331
  numstr = '0' + numstr
269
332
  }
270
- if (asm) {
271
- str = str + ' ' + numstr
272
- } else {
273
- str = str + ' ' + '0x' + numstr
274
- }
333
+ // An opcode with no name is written as its raw byte, 0xba, in both forms. ASM
334
+ // used to write it as bare hex, `ba`, which is also how ASM writes a one-byte
335
+ // data push, so fromASM read it back as a push: a different script.
336
+ str = str + ' ' + '0x' + numstr
275
337
  }
276
338
  } else {
277
339
  // data chunk
@@ -1081,20 +1143,40 @@ Script.prototype.toAddress = function (network) {
1081
1143
  */
1082
1144
  Script.prototype.findAndDelete = function (script) {
1083
1145
  var buf = script.toBuffer()
1084
- var hex = buf.toString('hex')
1146
+ // A chunk serializes to bytes starting with its opcode, so only chunks whose
1147
+ // opcode is the first byte of `buf` can match. Every other chunk is still
1148
+ // serialized when its encoding would throw, so malformed input fails as it
1149
+ // always did.
1150
+ var first = buf.length ? buf[0] : -1
1085
1151
  for (var i = 0; i < this.chunks.length; i++) {
1086
- var script2 = Script({
1087
- chunks: [this.chunks[i]]
1088
- })
1089
- var buf2 = script2.toBuffer()
1090
- var hex2 = buf2.toString('hex')
1091
- if (hex === hex2) {
1152
+ var chunk = this.chunks[i]
1153
+ if (chunk.opcodenum !== first && serializesCleanly(chunk)) continue
1154
+ var buf2 = Script({
1155
+ chunks: [chunk]
1156
+ }).toBuffer()
1157
+ if (buf.equals(buf2)) {
1158
+ // Look at the chunk that slid into this position too: CScript::FindAndDelete
1159
+ // removes consecutive occurrences.
1092
1160
  this.chunks.splice(i, 1)
1161
+ i--
1093
1162
  }
1094
1163
  }
1095
1164
  return this
1096
1165
  }
1097
1166
 
1167
+ function serializesCleanly (chunk) {
1168
+ var op = chunk.opcodenum
1169
+ if (typeof op !== 'number' || !Number.isInteger(op) || op < 0 || op > 255) return false
1170
+ if (!chunk.buf) return true
1171
+ if (op > Opcode.OP_PUSHDATA4) return true
1172
+ if (!Buffer.isBuffer(chunk.buf)) return false
1173
+ var len = chunk.len
1174
+ if (op === Opcode.OP_PUSHDATA1) return Number.isInteger(len) && len >= 0 && len <= 0xff
1175
+ if (op === Opcode.OP_PUSHDATA2) return Number.isInteger(len) && len >= 0 && len <= 0xffff
1176
+ if (op === Opcode.OP_PUSHDATA4) return Number.isInteger(len) && len >= 0 && len <= 0xffffffff
1177
+ return true
1178
+ }
1179
+
1098
1180
  /**
1099
1181
  * Comes from bitcoind's script interpreter CheckMinimalPush function
1100
1182
  * @returns {boolean} if the chunk {i} is the smallest way to push that particular data.