@smartledger/bsv 9.3.0 → 9.4.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.
- package/CHANGELOG.md +66 -0
- package/README.md +19 -19
- package/bsv-gdaf.min.js +52 -52
- package/bsv-ltp.min.js +1 -1
- package/bsv-smartcontract.min.js +18 -18
- package/bsv.bundle.js +52 -52
- package/bsv.d.ts +8 -0
- package/bsv.min.js +52 -52
- package/docs/AUDIT_SCOPE.md +135 -34
- package/docs/MODULE_REFERENCE_COMPLETE.md +27 -27
- package/docs/advanced/UTXO_MANAGER_GUIDE.md +1 -1
- package/docs/getting-started/INSTALLATION.md +23 -23
- package/docs/getting-started/QUICK_START.md +7 -7
- package/docs/migration/FROM_BSV_1_5_6.md +5 -5
- package/lib/script/interpreter.js +7 -2
- package/lib/smart_contract/dsl.js +55 -3
- package/package.json +3 -3
- package/version.js +1 -1
package/docs/AUDIT_SCOPE.md
CHANGED
|
@@ -29,17 +29,23 @@ testing.
|
|
|
29
29
|
Two tiers, to be **priced separately** so the boundary can be drawn against a number
|
|
30
30
|
rather than before seeing one.
|
|
31
31
|
|
|
32
|
-
|
|
32
|
+
The boundary is drawn by **where defects have actually occurred**, not by how core a
|
|
33
|
+
module sounds. That is a deliberate revision: an earlier version of this document
|
|
34
|
+
scoped Tier 1 as "the cryptographic core" and would have excluded four of the six real
|
|
35
|
+
defects this codebase has produced. See §2.1.
|
|
36
|
+
|
|
37
|
+
### Tier 1 — 11,247 lines
|
|
33
38
|
|
|
34
39
|
| Module | Lines | Why it matters |
|
|
35
40
|
| --- | ---: | --- |
|
|
36
|
-
| `lib/script/` | 3,859 | Consensus script interpreter. Divergence from the node means accepting a transaction the network rejects, or the reverse. |
|
|
37
41
|
| `lib/transaction/` | 2,779 | Sighash construction and signing — both BIP-143 and the Original Transaction Digest Algorithm. |
|
|
38
|
-
| `lib/
|
|
39
|
-
| `lib/
|
|
42
|
+
| `lib/script/interpreter.js` | 2,684 | **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
|
+
| `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/` | 1,436 | BRC-220 signing and verification. Publicly reachable and relied on downstream. |
|
|
40
45
|
| `lib/privatekey.js`, `lib/publickey.js` | 843 | Key construction, serialisation, WIF. Recent defects here produced a *different* key without error. |
|
|
41
|
-
| `lib/
|
|
42
|
-
| `lib/
|
|
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
|
+
| `lib/covenant/` | 409 | The verification harness. Its flag word is what made covenants verify under 2019 rules while claiming to mirror mainnet. |
|
|
48
|
+
| `lib/util/jcs.js` | 105 | RFC 8785 canonicalization, now a public export and the estate's single implementation. |
|
|
43
49
|
|
|
44
50
|
### Tier 2 — optional, 1,607 lines
|
|
45
51
|
|
|
@@ -53,30 +59,87 @@ Tier 2 is cryptographic rather than application code, so excluding it is a **bud
|
|
|
53
59
|
decision, not a risk judgement**. Priced as an add-on it is cheap; discovered later it
|
|
54
60
|
is not.
|
|
55
61
|
|
|
62
|
+
### 2.1 Why the boundary moved
|
|
63
|
+
|
|
64
|
+
Six defects have been found in this codebase and fixed. Four of them were in code the
|
|
65
|
+
previous version of this scope **excluded**:
|
|
66
|
+
|
|
67
|
+
| Defect | Module | Was it in the old scope? |
|
|
68
|
+
| --- | --- | --- |
|
|
69
|
+
| Covenant verification applied pre-Genesis limits while claiming to mirror mainnet | `lib/covenant`, `lib/smart_contract` | no |
|
|
70
|
+
| `timeLockCLTV` and the HTLC timeout enforced nothing on mainnet — Genesis reverted `OP_CLTV` to a NOP, so the funds were spendable immediately | `lib/smart_contract` | no |
|
|
71
|
+
| A BRC-220 suite verified against a byte-reversed digest, rejecting every conformant signature | `lib/notaryhash` | no |
|
|
72
|
+
| The reachable RFC 8785 canonicalizer was non-conformant while a correct one sat private; three downstream packages copied the wrong one | `lib/util/jcs.js`, `lib/ltp` | partly |
|
|
73
|
+
| `ECDSA.verify()` returned the instance, so `if (verify())` was always truthy — a fail-open accepting forged signatures | `lib/crypto` | yes |
|
|
74
|
+
| ECDSA nonce reuse across two signings on one instance, leaking the private key | `lib/crypto` | yes |
|
|
75
|
+
|
|
76
|
+
The pattern is not "the primitives are weak". It is that **code making claims about
|
|
77
|
+
consensus behaviour was wrong about it**, and the tests agreed because they shared the
|
|
78
|
+
same assumption. Scope has been moved onto that surface.
|
|
79
|
+
|
|
80
|
+
### 2.2 Why `lib/script` shrinks rather than leaves
|
|
81
|
+
|
|
82
|
+
`lib/script` has the strongest external evidence in the repository: 1,483/1,483 of the
|
|
83
|
+
reference node's own consensus vectors, zero false accepts and zero false rejects. That
|
|
84
|
+
is evidence about **opcode execution**, and re-auditing it by hand is the least
|
|
85
|
+
productive money in this engagement.
|
|
86
|
+
|
|
87
|
+
It is not evidence about which flags a caller ends up with. Both consensus defects above
|
|
88
|
+
were flag-selection and era-derivation failures reachable through `interpreter.js`, and
|
|
89
|
+
no vector covers them because every vector states its own flags. So the interpreter stays
|
|
90
|
+
in scope, scoped to that surface, and the remaining 1,175 lines of `lib/script` leave.
|
|
91
|
+
|
|
92
|
+
### 2.3 A specific instruction for `lib/crypto`
|
|
93
|
+
|
|
94
|
+
Both in-scope defects — a fail-open `verify()` and nonce reuse across signings — are
|
|
95
|
+
symptoms of a **stateful object wrapper around a stateless primitive library**. The
|
|
96
|
+
curve arithmetic beneath is `@noble/curves`, which is already audited and offers
|
|
97
|
+
stateless signing, RFC 6979 nonces and a strict boolean verify.
|
|
98
|
+
|
|
99
|
+
So do not only ask whether `lib/crypto` has bugs. Ask whether the wrapper should exist:
|
|
100
|
+
what would it cost to route the signing and verification paths directly at `@noble`, and
|
|
101
|
+
which parts genuinely cannot go? `bn.js`, `Point`, `Signature` and `Shamir` are public
|
|
102
|
+
API (`bsv.crypto.*`) and cannot simply be deleted, so this is a question with a real
|
|
103
|
+
answer rather than a rhetorical one. An answer either way is worth more than a list of
|
|
104
|
+
findings inside code that should not be there.
|
|
105
|
+
|
|
106
|
+
### 2.4 The requirement that matters most
|
|
107
|
+
|
|
108
|
+
Whatever the final line count, the statement of work should carry this:
|
|
109
|
+
|
|
110
|
+
> **Audit exported security claims, defaults, and the tests that assert them as a unit,
|
|
111
|
+
> against an independent oracle or specification — not each in isolation.**
|
|
112
|
+
|
|
113
|
+
Every defect above shares one shape. The code was wrong, and its tests passed, because
|
|
114
|
+
the tests were written from the same assumption. A file-by-file review finds none of
|
|
115
|
+
them. Checking a claim against something outside this repository finds all of them —
|
|
116
|
+
which is exactly how each was eventually caught.
|
|
117
|
+
|
|
56
118
|
## 3. Out of scope, and why
|
|
57
119
|
|
|
58
120
|
| Component | Status | Reason |
|
|
59
121
|
| --- | --- | --- |
|
|
60
122
|
| `@noble/curves`, `@noble/hashes`, `@noble/ciphers` | Already audited | The primitives come from the Noble libraries, which **Cure53 has audited and published on**. We do not implement curve or hash arithmetic ourselves. State this explicitly to vendors — otherwise they price work we do not need. |
|
|
61
|
-
|
|
|
123
|
+
| Opcode execution in `lib/script/` (1,175 lines outside `interpreter.js`) | Excluded, with evidence | 1,483/1,483 of the reference node's own consensus vectors pass, with zero false accepts and zero false rejects. See §2.2 — the flag surface stays in, the execution does not. |
|
|
124
|
+
| `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**. |
|
|
125
|
+
| 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. |
|
|
62
126
|
|
|
63
|
-
Totals reconcile against `lib/`, which is 38,
|
|
127
|
+
Totals reconcile against `lib/`, which is 38,879 lines across 131 files:
|
|
64
128
|
|
|
65
129
|
```
|
|
66
|
-
tier 1
|
|
130
|
+
tier 1 11,247
|
|
67
131
|
tier 2 1,607
|
|
68
|
-
excluded
|
|
132
|
+
excluded 26,025
|
|
69
133
|
------
|
|
70
|
-
total 38,
|
|
134
|
+
total 38,879
|
|
71
135
|
```
|
|
72
136
|
|
|
73
|
-
Measured 2026-08-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
the date above with the commit measured.
|
|
137
|
+
Measured 2026-08-29 at `a954c27`. These figures drift as the library changes — an
|
|
138
|
+
earlier set was 445 lines light by the time it was read, most of it in
|
|
139
|
+
`lib/script/interpreter.js`, which is priced against. **Re-run §7 immediately before
|
|
140
|
+
sending**, and update the date above with the commit measured.
|
|
78
141
|
|
|
79
|
-
Core + optional =
|
|
142
|
+
Core + optional = 12,854.
|
|
80
143
|
|
|
81
144
|
## 4. What an auditor gets on day one
|
|
82
145
|
|
|
@@ -130,37 +193,56 @@ any single number.
|
|
|
130
193
|
## 6. Enquiry text
|
|
131
194
|
|
|
132
195
|
```text
|
|
133
|
-
Subject: Audit enquiry — BSV
|
|
196
|
+
Subject: Audit enquiry — BSV library, consensus and signing surface (~13k LOC JavaScript)
|
|
134
197
|
|
|
135
198
|
Hello,
|
|
136
199
|
|
|
137
200
|
We maintain @smartledger/bsv, a Bitcoin SV library published on npm. We are
|
|
138
|
-
seeking a quote for an independent security review
|
|
201
|
+
seeking a quote for an independent security review.
|
|
139
202
|
|
|
140
203
|
Scope, and we would like these priced separately:
|
|
141
204
|
|
|
142
|
-
Tier 1 —
|
|
143
|
-
|
|
144
|
-
|
|
205
|
+
Tier 1 — 11,247 lines. Sighash construction and signing; ECDSA, nonce
|
|
206
|
+
derivation and signature encoding; the consensus-flag and era-derivation
|
|
207
|
+
surface of the script interpreter; BRC-220 signing and verification;
|
|
208
|
+
key construction and serialisation; the covenant verification harness and
|
|
209
|
+
the locking-script semantics built on it; RFC 8785 canonicalization.
|
|
145
210
|
|
|
146
211
|
Tier 2 — 1,607 lines. BIP-39 mnemonics, ECIES, and the Base58Check/varint
|
|
147
212
|
decoding surface.
|
|
148
213
|
|
|
149
214
|
JavaScript (CommonJS), Node >= 20.19. The code is public.
|
|
150
215
|
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
216
|
+
Two things we would ask you to scope deliberately rather than by line count:
|
|
217
|
+
|
|
218
|
+
1. Please audit exported security claims, their defaults, and the tests that
|
|
219
|
+
assert them AS A UNIT, against an independent oracle or specification.
|
|
220
|
+
Every defect we have found shared one shape: the code was wrong and its
|
|
221
|
+
tests passed, because both were written from the same assumption. A
|
|
222
|
+
file-by-file review would have found none of them.
|
|
223
|
+
|
|
224
|
+
2. In lib/crypto, we would value a judgement on whether the wrapper should
|
|
225
|
+
exist at all. Our two worst defects there — a verify() that returned a
|
|
226
|
+
truthy object instead of a boolean, and nonce reuse across two signings
|
|
227
|
+
on one instance — are symptoms of a stateful wrapper around a stateless
|
|
228
|
+
primitive library (@noble/curves) that already offers stateless signing,
|
|
229
|
+
RFC 6979 nonces and a strict boolean verify. An answer on the cost of
|
|
230
|
+
removing the wrapper is worth more to us than a list of findings inside it.
|
|
231
|
+
|
|
232
|
+
Explicitly out of scope: elliptic-curve and hash primitives, supplied by the
|
|
233
|
+
Noble libraries and already audited by Cure53; opcode execution in the script
|
|
234
|
+
interpreter, which passes 1,483/1,483 of the reference node's own consensus
|
|
235
|
+
vectors with zero false accepts; and roughly 26,000 lines of application layer
|
|
236
|
+
(credentials, tokens, ordinals), which we would treat as a separate engagement.
|
|
155
237
|
|
|
156
238
|
Context that should shorten discovery: the core is inherited from bitcore and
|
|
157
239
|
has been fixed reactively but never independently reviewed. We can provide a
|
|
158
240
|
test-backed threat model, a 452-case behavioural conformance corpus that a
|
|
159
|
-
second independent implementation agrees with,
|
|
160
|
-
defects we have found ourselves.
|
|
241
|
+
second independent implementation agrees with, the node's own consensus vectors
|
|
242
|
+
run as a gate, and a documented history of the defects we have found ourselves.
|
|
161
243
|
|
|
162
244
|
The failure mode we most want examined is code that reports a check as passed
|
|
163
|
-
without performing it —
|
|
245
|
+
without performing it — every finding of ours has had that shape.
|
|
164
246
|
|
|
165
247
|
Could you indicate availability, an approximate cost range, and what you would
|
|
166
248
|
need from us to firm that up?
|
|
@@ -176,21 +258,32 @@ SmartLedger Technology
|
|
|
176
258
|
|
|
177
259
|
Every figure in this document, including the excluded total, must come out of this
|
|
178
260
|
script. **Derive the excluded count as the complement — never by subtracting tier 1
|
|
179
|
-
alone.**
|
|
261
|
+
alone.** An early draft did exactly that, double-counted tier 2, and published parts
|
|
180
262
|
summing to 37,430 against a 38,322 whole; §7 could not catch it because it reproduced
|
|
181
263
|
every figure except the wrong one.
|
|
182
264
|
|
|
265
|
+
Tier 1 is no longer whole directories. Three entries are partial — the interpreter is
|
|
266
|
+
scoped to its flag surface, `smart_contract` to its locking semantics — so those are
|
|
267
|
+
counted by file and the reason is in §2. A partial scope that is measured as a whole
|
|
268
|
+
directory is how a vendor prices 6,908 lines when you meant 472.
|
|
269
|
+
|
|
183
270
|
```sh
|
|
184
271
|
lines () { find "$@" -name '*.js' -exec cat {} + | wc -l; }
|
|
185
272
|
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
273
|
+
# Whole directories in tier 1
|
|
274
|
+
TIER1_DIRS="lib/crypto lib/transaction lib/notaryhash lib/covenant"
|
|
275
|
+
|
|
276
|
+
# Individual files — including the PARTIAL entries (§2.2, §2.3)
|
|
277
|
+
TIER1_FILES="lib/privatekey.js lib/publickey.js \
|
|
278
|
+
lib/script/interpreter.js \
|
|
279
|
+
lib/smart_contract/locks.js lib/smart_contract/index.js \
|
|
280
|
+
lib/util/jcs.js"
|
|
281
|
+
|
|
189
282
|
TIER2_DIRS="lib/encoding lib/mnemonic lib/ecies"
|
|
190
283
|
|
|
191
284
|
# Per-module breakdown for the scope tables
|
|
192
285
|
for d in $TIER1_DIRS $TIER2_DIRS; do
|
|
193
|
-
printf '%-
|
|
286
|
+
printf '%-20s %3s files %6s lines\n' "$d" \
|
|
194
287
|
"$(find $d -name '*.js' | wc -l)" "$(lines $d)"
|
|
195
288
|
done
|
|
196
289
|
wc -l $TIER1_FILES
|
|
@@ -209,5 +302,13 @@ printf 'tier 1 %6s\ntier 2 %6s\nexcluded %6s\n ------\ntotal
|
|
|
209
302
|
[ "$TOTAL" -gt 0 ] || echo "MISMATCH — run this from the repo root"
|
|
210
303
|
[ $(( T1 + T2 + EXCLUDED )) -eq "$TOTAL" ] || echo "MISMATCH — do not send"
|
|
211
304
|
|
|
305
|
+
# The cut list from §3, so the saving can be stated rather than asserted
|
|
306
|
+
wc -l lib/address.js lib/networks.js lib/opcode.js \
|
|
307
|
+
lib/hdprivatekey.js lib/hdpublickey.js
|
|
308
|
+
|
|
309
|
+
# networks.js carries no consensus-flag logic — the claim §3 rests on.
|
|
310
|
+
# Expect 0. A non-zero result means the cut needs re-arguing.
|
|
311
|
+
grep -cE 'SCRIPT_|GENESIS|CHRONICLE|consensus' lib/networks.js
|
|
312
|
+
|
|
212
313
|
find lib -name '*.js' | wc -l # file count
|
|
213
314
|
```
|
|
@@ -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.
|
|
58
|
+
- **CDN**: `unpkg.com/@smartledger/bsv@9.4.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.
|
|
64
|
+
- **CDN**: `unpkg.com/@smartledger/bsv@9.4.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.
|
|
70
|
+
- **CDN**: `unpkg.com/@smartledger/bsv@9.4.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.
|
|
85
|
-
| **bsv.bundle.js** | 937KB | Everything in one file | `unpkg.com/@smartledger/bsv@9.
|
|
86
|
-
| **bsv-smartcontract.min.js** | 937KB | Covenant development | `unpkg.com/@smartledger/bsv@9.
|
|
87
|
-
| **bsv-covenant.min.js** | 913KB | Covenant operations | `unpkg.com/@smartledger/bsv@9.
|
|
88
|
-
| **bsv-script-helper.min.js** | 26KB | Custom script tools | `unpkg.com/@smartledger/bsv@9.
|
|
89
|
-
| **bsv-security.min.js** | 26KB | Security enhancements (opt-in helpers — see README › Security) | `unpkg.com/@smartledger/bsv@9.
|
|
90
|
-
| **bsv-ecies.min.js** | 71KB | Encryption | `unpkg.com/@smartledger/bsv@9.
|
|
91
|
-
| **bsv-message.min.js** | 26KB | Message signing | `unpkg.com/@smartledger/bsv@9.
|
|
92
|
-
| **bsv-mnemonic.min.js** | 681KB | HD wallets | `unpkg.com/@smartledger/bsv@9.
|
|
93
|
-
| **🆕 bsv-shamir.min.js** | 432KB | **Secret sharing** | `unpkg.com/@smartledger/bsv@9.
|
|
94
|
-
| **🆕 bsv-gdaf.min.js** | 1184KB | **Digital attestation** | `unpkg.com/@smartledger/bsv@9.
|
|
95
|
-
| **🆕 bsv-ltp.min.js** | 1184KB | **Legal tokens** | `unpkg.com/@smartledger/bsv@9.
|
|
84
|
+
| **bsv.min.js** | 937KB | Core BSV + SmartContract | `unpkg.com/@smartledger/bsv@9.4.0/bsv.min.js` |
|
|
85
|
+
| **bsv.bundle.js** | 937KB | Everything in one file | `unpkg.com/@smartledger/bsv@9.4.0/bsv.bundle.js` |
|
|
86
|
+
| **bsv-smartcontract.min.js** | 937KB | Covenant development | `unpkg.com/@smartledger/bsv@9.4.0/bsv-smartcontract.min.js` |
|
|
87
|
+
| **bsv-covenant.min.js** | 913KB | Covenant operations | `unpkg.com/@smartledger/bsv@9.4.0/bsv-covenant.min.js` |
|
|
88
|
+
| **bsv-script-helper.min.js** | 26KB | Custom script tools | `unpkg.com/@smartledger/bsv@9.4.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.4.0/bsv-security.min.js` |
|
|
90
|
+
| **bsv-ecies.min.js** | 71KB | Encryption | `unpkg.com/@smartledger/bsv@9.4.0/bsv-ecies.min.js` |
|
|
91
|
+
| **bsv-message.min.js** | 26KB | Message signing | `unpkg.com/@smartledger/bsv@9.4.0/bsv-message.min.js` |
|
|
92
|
+
| **bsv-mnemonic.min.js** | 681KB | HD wallets | `unpkg.com/@smartledger/bsv@9.4.0/bsv-mnemonic.min.js` |
|
|
93
|
+
| **🆕 bsv-shamir.min.js** | 432KB | **Secret sharing** | `unpkg.com/@smartledger/bsv@9.4.0/bsv-shamir.min.js` |
|
|
94
|
+
| **🆕 bsv-gdaf.min.js** | 1184KB | **Digital attestation** | `unpkg.com/@smartledger/bsv@9.4.0/bsv-gdaf.min.js` |
|
|
95
|
+
| **🆕 bsv-ltp.min.js** | 1184KB | **Legal tokens** | `unpkg.com/@smartledger/bsv@9.4.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.
|
|
104
|
-
<script src="https://unpkg.com/@smartledger/bsv@9.
|
|
103
|
+
<script src="https://unpkg.com/@smartledger/bsv@9.4.0/bsv.min.js"></script>
|
|
104
|
+
<script src="https://unpkg.com/@smartledger/bsv@9.4.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.
|
|
110
|
-
<script src="https://unpkg.com/@smartledger/bsv@9.
|
|
111
|
-
<script src="https://unpkg.com/@smartledger/bsv@9.
|
|
109
|
+
<script src="https://unpkg.com/@smartledger/bsv@9.4.0/bsv.min.js"></script>
|
|
110
|
+
<script src="https://unpkg.com/@smartledger/bsv@9.4.0/bsv-covenant.min.js"></script>
|
|
111
|
+
<script src="https://unpkg.com/@smartledger/bsv@9.4.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.
|
|
117
|
-
<script src="https://unpkg.com/@smartledger/bsv@9.
|
|
118
|
-
<script src="https://unpkg.com/@smartledger/bsv@9.
|
|
116
|
+
<script src="https://unpkg.com/@smartledger/bsv@9.4.0/bsv.min.js"></script>
|
|
117
|
+
<script src="https://unpkg.com/@smartledger/bsv@9.4.0/bsv-ltp.min.js"></script>
|
|
118
|
+
<script src="https://unpkg.com/@smartledger/bsv@9.4.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.
|
|
136
|
-
<script src="https://unpkg.com/@smartledger/bsv@9.
|
|
137
|
-
<script src="https://unpkg.com/@smartledger/bsv@9.
|
|
135
|
+
<script src="https://unpkg.com/@smartledger/bsv@9.4.0/bsv.min.js"></script>
|
|
136
|
+
<script src="https://unpkg.com/@smartledger/bsv@9.4.0/bsv-security.min.js"></script>
|
|
137
|
+
<script src="https://unpkg.com/@smartledger/bsv@9.4.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.
|
|
149
|
+
<script src="https://unpkg.com/@smartledger/bsv@9.4.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.
|
|
725
|
+
<script src="https://cdn.jsdelivr.net/npm/@smartledger/bsv@9.4.0/bsv.min.js"></script>
|
|
726
726
|
</head>
|
|
727
727
|
<body>
|
|
728
728
|
<script>
|
|
@@ -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.
|
|
51
|
+
<script src="https://unpkg.com/@smartledger/bsv@9.4.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.
|
|
61
|
+
<script src="https://unpkg.com/@smartledger/bsv@9.4.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.
|
|
75
|
-
<script src="https://unpkg.com/@smartledger/bsv@9.
|
|
76
|
-
<script src="https://unpkg.com/@smartledger/bsv@9.
|
|
74
|
+
<script src="https://unpkg.com/@smartledger/bsv@9.4.0/bsv.min.js"></script>
|
|
75
|
+
<script src="https://unpkg.com/@smartledger/bsv@9.4.0/bsv-covenant.min.js"></script>
|
|
76
|
+
<script src="https://unpkg.com/@smartledger/bsv@9.4.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.
|
|
86
|
-
<script src="https://unpkg.com/@smartledger/bsv@9.
|
|
87
|
-
<script src="https://unpkg.com/@smartledger/bsv@9.
|
|
85
|
+
<script src="https://unpkg.com/@smartledger/bsv@9.4.0/bsv.min.js"></script>
|
|
86
|
+
<script src="https://unpkg.com/@smartledger/bsv@9.4.0/bsv-ltp.min.js"></script>
|
|
87
|
+
<script src="https://unpkg.com/@smartledger/bsv@9.4.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.
|
|
102
|
-
<script src="https://unpkg.com/@smartledger/bsv@9.
|
|
103
|
-
<script src="https://unpkg.com/@smartledger/bsv@9.
|
|
101
|
+
<script src="https://unpkg.com/@smartledger/bsv@9.4.0/bsv.min.js"></script>
|
|
102
|
+
<script src="https://unpkg.com/@smartledger/bsv@9.4.0/bsv-security.min.js"></script>
|
|
103
|
+
<script src="https://unpkg.com/@smartledger/bsv@9.4.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.
|
|
118
|
-
| **bsv.bundle.js** | 937KB | Everything in one file | `unpkg.com/@smartledger/bsv@9.
|
|
119
|
-
| **bsv-smartcontract.min.js** | 937KB | Complete covenant framework | `unpkg.com/@smartledger/bsv@9.
|
|
120
|
-
| **bsv-ltp.min.js** | 1184KB | **Legal Token Protocol** | `unpkg.com/@smartledger/bsv@9.
|
|
121
|
-
| **bsv-gdaf.min.js** | 1184KB | **Digital Identity & Attestation** | `unpkg.com/@smartledger/bsv@9.
|
|
122
|
-
| **bsv-shamir.min.js** | 432KB | **Threshold Cryptography** | `unpkg.com/@smartledger/bsv@9.
|
|
123
|
-
| **bsv-security.min.js** | 26KB | Security enhancements (opt-in helpers — see README › Security) | `unpkg.com/@smartledger/bsv@9.
|
|
124
|
-
| **bsv-mnemonic.min.js** | 681KB | HD wallets | `unpkg.com/@smartledger/bsv@9.
|
|
125
|
-
| **bsv-ecies.min.js** | 71KB | Encryption | `unpkg.com/@smartledger/bsv@9.
|
|
126
|
-
| **bsv-covenant.min.js** | 913KB | Covenant operations | `unpkg.com/@smartledger/bsv@9.
|
|
127
|
-
| **bsv-script-helper.min.js** | 26KB | Custom script tools | `unpkg.com/@smartledger/bsv@9.
|
|
128
|
-
| **bsv-message.min.js** | 26KB | Message signing | `unpkg.com/@smartledger/bsv@9.
|
|
117
|
+
| **bsv.min.js** | 937KB | Core BSV + SmartContract | `unpkg.com/@smartledger/bsv@9.4.0/bsv.min.js` |
|
|
118
|
+
| **bsv.bundle.js** | 937KB | Everything in one file | `unpkg.com/@smartledger/bsv@9.4.0/bsv.bundle.js` |
|
|
119
|
+
| **bsv-smartcontract.min.js** | 937KB | Complete covenant framework | `unpkg.com/@smartledger/bsv@9.4.0/bsv-smartcontract.min.js` |
|
|
120
|
+
| **bsv-ltp.min.js** | 1184KB | **Legal Token Protocol** | `unpkg.com/@smartledger/bsv@9.4.0/bsv-ltp.min.js` |
|
|
121
|
+
| **bsv-gdaf.min.js** | 1184KB | **Digital Identity & Attestation** | `unpkg.com/@smartledger/bsv@9.4.0/bsv-gdaf.min.js` |
|
|
122
|
+
| **bsv-shamir.min.js** | 432KB | **Threshold Cryptography** | `unpkg.com/@smartledger/bsv@9.4.0/bsv-shamir.min.js` |
|
|
123
|
+
| **bsv-security.min.js** | 26KB | Security enhancements (opt-in helpers — see README › Security) | `unpkg.com/@smartledger/bsv@9.4.0/bsv-security.min.js` |
|
|
124
|
+
| **bsv-mnemonic.min.js** | 681KB | HD wallets | `unpkg.com/@smartledger/bsv@9.4.0/bsv-mnemonic.min.js` |
|
|
125
|
+
| **bsv-ecies.min.js** | 71KB | Encryption | `unpkg.com/@smartledger/bsv@9.4.0/bsv-ecies.min.js` |
|
|
126
|
+
| **bsv-covenant.min.js** | 913KB | Covenant operations | `unpkg.com/@smartledger/bsv@9.4.0/bsv-covenant.min.js` |
|
|
127
|
+
| **bsv-script-helper.min.js** | 26KB | Custom script tools | `unpkg.com/@smartledger/bsv@9.4.0/bsv-script-helper.min.js` |
|
|
128
|
+
| **bsv-message.min.js** | 26KB | Message signing | `unpkg.com/@smartledger/bsv@9.4.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.
|
|
17
|
+
<script src="https://unpkg.com/@smartledger/bsv@9.4.0/bsv.min.js"></script>
|
|
18
18
|
|
|
19
19
|
<!-- Everything included (937KB) -->
|
|
20
|
-
<script src="https://unpkg.com/@smartledger/bsv@9.
|
|
20
|
+
<script src="https://unpkg.com/@smartledger/bsv@9.4.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.
|
|
130
|
+
<script src="https://unpkg.com/@smartledger/bsv@9.4.0/bsv.min.js"></script>
|
|
131
131
|
|
|
132
132
|
<!-- Smart contracts (937KB) -->
|
|
133
|
-
<script src="https://unpkg.com/@smartledger/bsv@9.
|
|
133
|
+
<script src="https://unpkg.com/@smartledger/bsv@9.4.0/bsv-smartcontract.min.js"></script>
|
|
134
134
|
|
|
135
135
|
<!-- Legal tokens (1.16MB) -->
|
|
136
|
-
<script src="https://unpkg.com/@smartledger/bsv@9.
|
|
136
|
+
<script src="https://unpkg.com/@smartledger/bsv@9.4.0/bsv-ltp.min.js"></script>
|
|
137
137
|
|
|
138
138
|
<!-- Digital identity (1.16MB) -->
|
|
139
|
-
<script src="https://unpkg.com/@smartledger/bsv@9.
|
|
139
|
+
<script src="https://unpkg.com/@smartledger/bsv@9.4.0/bsv-gdaf.min.js"></script>
|
|
140
140
|
|
|
141
141
|
<!-- Everything (937KB) -->
|
|
142
|
-
<script src="https://unpkg.com/@smartledger/bsv@9.
|
|
142
|
+
<script src="https://unpkg.com/@smartledger/bsv@9.4.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.
|
|
162
|
+
<script src="https://unpkg.com/@smartledger/bsv@9.4.0/bsv.min.js"></script>
|
|
163
163
|
|
|
164
164
|
<!-- Add smart contracts when ready -->
|
|
165
|
-
<script src="https://unpkg.com/@smartledger/bsv@9.
|
|
165
|
+
<script src="https://unpkg.com/@smartledger/bsv@9.4.0/bsv-smartcontract.min.js"></script>
|
|
166
166
|
|
|
167
167
|
<!-- Add advanced features as needed -->
|
|
168
|
-
<script src="https://unpkg.com/@smartledger/bsv@9.
|
|
169
|
-
<script src="https://unpkg.com/@smartledger/bsv@9.
|
|
168
|
+
<script src="https://unpkg.com/@smartledger/bsv@9.4.0/bsv-ltp.min.js"></script>
|
|
169
|
+
<script src="https://unpkg.com/@smartledger/bsv@9.4.0/bsv-gdaf.min.js"></script>
|
|
170
170
|
|
|
171
171
|
<!-- Everything in one file -->
|
|
172
|
-
<script src="https://unpkg.com/@smartledger/bsv@9.
|
|
172
|
+
<script src="https://unpkg.com/@smartledger/bsv@9.4.0/bsv.bundle.js"></script>
|
|
173
173
|
```
|
|
174
174
|
|
|
175
175
|
## 🔍 **Testing Your Migration**
|
|
@@ -2667,8 +2667,13 @@ Interpreter.prototype.step = function () {
|
|
|
2667
2667
|
|
|
2668
2668
|
this.stack[this.stack.length - 1] = buf2
|
|
2669
2669
|
|
|
2670
|
-
// The resulting number must be a valid number.
|
|
2671
|
-
|
|
2670
|
+
// The resulting number must be a valid number. The width is the era's,
|
|
2671
|
+
// not a constant: `_isMinimallyEncoded` defaults to MAXIMUM_ELEMENT_SIZE
|
|
2672
|
+
// (4), so omitting the argument capped every era at the pre-Genesis
|
|
2673
|
+
// width. No vector caught it because every BIN2NUM vector in the node's
|
|
2674
|
+
// corpus runs under P2SH,STRICTENC alone — pre-Genesis, where 4 is the
|
|
2675
|
+
// right answer either way.
|
|
2676
|
+
if (!Interpreter._isMinimallyEncoded(buf2, this.maxScriptNumLength())) {
|
|
2672
2677
|
this.errstr = 'SCRIPT_ERR_INVALID_NUMBER_RANGE'
|
|
2673
2678
|
return false
|
|
2674
2679
|
}
|
|
@@ -28,6 +28,11 @@ var Opcode = require('../opcode')
|
|
|
28
28
|
var Transaction = require('../transaction')
|
|
29
29
|
var n = helpers.scriptNum
|
|
30
30
|
|
|
31
|
+
// Consensus constants, named so the compiled script can be read against the node.
|
|
32
|
+
var LOCKTIME_THRESHOLD = 500000000 // below: block height. at or above: unix time.
|
|
33
|
+
var SEQUENCE_FINAL = Buffer.from([0xff, 0xff, 0xff, 0xff])
|
|
34
|
+
var SIGN_PAD = Buffer.from([0x00]) // makes an unsigned 32-bit field read positive
|
|
35
|
+
|
|
31
36
|
function toOutput (dest, satoshis) {
|
|
32
37
|
if (dest instanceof Transaction.Output) return dest
|
|
33
38
|
if (dest instanceof Script) return new Transaction.Output({ script: dest, satoshis: satoshis })
|
|
@@ -59,8 +64,22 @@ Policy.prototype.payTo = function (dest, satoshis) {
|
|
|
59
64
|
return this
|
|
60
65
|
}
|
|
61
66
|
|
|
62
|
-
/**
|
|
67
|
+
/**
|
|
68
|
+
* Require the spend's nLockTime to be >= height.
|
|
69
|
+
*
|
|
70
|
+
* Below LOCKTIME_THRESHOLD (500000000) the value is a BLOCK HEIGHT; at or above
|
|
71
|
+
* it, a UNIX TIMESTAMP. The compiled script enforces the same unit the floor
|
|
72
|
+
* uses, so a height floor cannot be satisfied by a timestamp.
|
|
73
|
+
*
|
|
74
|
+
* 0 is rejected: consensus reads nLockTime 0 as "no lock" and treats the
|
|
75
|
+
* transaction as final regardless of any input's sequence, so a floor of 0
|
|
76
|
+
* would compile to a lock that binds nothing.
|
|
77
|
+
*/
|
|
63
78
|
Policy.prototype.lockUntil = function (height) {
|
|
79
|
+
if (!Number.isInteger(height) || height < 1 || height > 0xffffffff) {
|
|
80
|
+
throw new Error('lockUntil: expected an integer in 1..4294967295, got ' + height +
|
|
81
|
+
' (nLockTime 0 means "no lock" — consensus treats such a transaction as final)')
|
|
82
|
+
}
|
|
64
83
|
this._minLockTime = height
|
|
65
84
|
return this
|
|
66
85
|
}
|
|
@@ -75,7 +94,11 @@ Policy.prototype.describe = function () {
|
|
|
75
94
|
this._outputs.forEach(function (o, i) {
|
|
76
95
|
parts.push('output[' + i + '] = ' + o.satoshis + ' sat to ' + o.script.toASM().slice(0, 24) + '...')
|
|
77
96
|
})
|
|
78
|
-
if (this._minLockTime !== null)
|
|
97
|
+
if (this._minLockTime !== null) {
|
|
98
|
+
var unit = this._minLockTime < LOCKTIME_THRESHOLD ? 'block height' : 'unix time'
|
|
99
|
+
parts.push('nLockTime >= ' + this._minLockTime + ' as a ' + unit)
|
|
100
|
+
parts.push('this input is non-final (nSequence != 0xffffffff)')
|
|
101
|
+
}
|
|
79
102
|
return 'spend allowed iff: ' + parts.join(' AND ')
|
|
80
103
|
}
|
|
81
104
|
|
|
@@ -97,9 +120,38 @@ Policy.prototype.compile = function () {
|
|
|
97
120
|
}
|
|
98
121
|
|
|
99
122
|
if (this._minLockTime !== null) {
|
|
123
|
+
// A time lock is three consensus rules, not one comparison. All three are in
|
|
124
|
+
// the node's CheckLockTime; checking only the number reproduces none of them.
|
|
125
|
+
|
|
126
|
+
// 1. nSequence of THIS input must be non-final. IsFinalTx() ignores nLockTime
|
|
127
|
+
// outright when every input is 0xffffffff, so without this the spend is
|
|
128
|
+
// minable in the next block no matter how large a locktime it declares.
|
|
129
|
+
// One non-final input is enough to make the whole transaction non-final,
|
|
130
|
+
// and this input is the only one the preimage lets us see.
|
|
131
|
+
s.add(Opcode.OP_DUP)
|
|
132
|
+
s.add(n(44)).add(Opcode.OP_RIGHT).add(n(4)).add(Opcode.OP_LEFT) // last 44, first 4 = nSequence
|
|
133
|
+
s.add(SEQUENCE_FINAL).add(Opcode.OP_EQUAL).add(Opcode.OP_NOT).add(Opcode.OP_VERIFY)
|
|
134
|
+
|
|
135
|
+
// 2. nLockTime is an UNSIGNED 32-bit field, and OP_BIN2NUM reads a SIGNED
|
|
136
|
+
// one. From 19 Jan 2038 the high bit is set, and 0x80000000 minimally
|
|
137
|
+
// encodes to negative zero — the floor would be compared against 0 and no
|
|
138
|
+
// spend would ever satisfy it. Sign-pad to five bytes first. That push is
|
|
139
|
+
// only legal because OP_BIN2NUM now honours the era's script-number width.
|
|
100
140
|
s.add(Opcode.OP_DUP)
|
|
101
141
|
s.add(n(8)).add(Opcode.OP_RIGHT).add(n(4)).add(Opcode.OP_LEFT) // last 8, first 4 = nLockTime
|
|
102
|
-
s.add(
|
|
142
|
+
s.add(SIGN_PAD).add(Opcode.OP_CAT).add(Opcode.OP_BIN2NUM)
|
|
143
|
+
|
|
144
|
+
// 3. Units must match the floor's. Consensus reads nLockTime below
|
|
145
|
+
// LOCKTIME_THRESHOLD as a height and at or above it as a timestamp, so a
|
|
146
|
+
// bare `>=` lets a long-past timestamp clear a future height floor —
|
|
147
|
+
// 1500000000 >= 900000 is true, and that transaction is minable today.
|
|
148
|
+
// A floor already at or above the threshold needs no guard: `>= floor`
|
|
149
|
+
// implies `>= threshold`.
|
|
150
|
+
if (this._minLockTime < LOCKTIME_THRESHOLD) {
|
|
151
|
+
s.add(Opcode.OP_DUP).add(n(LOCKTIME_THRESHOLD)).add(Opcode.OP_LESSTHAN).add(Opcode.OP_VERIFY)
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
s.add(n(this._minLockTime)).add(Opcode.OP_GREATERTHANOREQUAL).add(Opcode.OP_VERIFY)
|
|
103
155
|
}
|
|
104
156
|
|
|
105
157
|
s.add(Opcode.OP_DROP).add(Opcode.OP_1) // drop preimage; succeed
|