@smartledger/bsv 9.12.0 → 9.14.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 +56 -0
- package/README.md +19 -19
- package/bsv-gdaf.min.js +44 -44
- package/bsv-smartcontract.min.js +1 -1
- package/bsv.bundle.js +44 -44
- package/bsv.d.ts +30 -2
- package/bsv.min.js +44 -44
- package/docs/AUDIT_SCOPE.md +7 -7
- package/docs/MODULE_REFERENCE_COMPLETE.md +27 -27
- package/docs/advanced/UTXO_MANAGER_GUIDE.md +1 -1
- package/docs/audit-rfq/cure53.txt +2 -2
- package/docs/audit-rfq/ncc-group.txt +2 -2
- package/docs/audit-rfq/trail-of-bits.txt +2 -2
- 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/notaryhash/index.js +26 -2
- package/lib/spv/merkleproof.js +75 -7
- package/package.json +1 -1
- package/version.js +1 -1
package/docs/AUDIT_SCOPE.md
CHANGED
|
@@ -34,14 +34,14 @@ module sounds. That is a deliberate revision: an earlier version of this documen
|
|
|
34
34
|
scoped Tier 1 as "the cryptographic core" and would have excluded four of the six real
|
|
35
35
|
defects this codebase has produced. See §2.1.
|
|
36
36
|
|
|
37
|
-
### Tier 1 — 12,
|
|
37
|
+
### Tier 1 — 12,089 lines
|
|
38
38
|
|
|
39
39
|
| Module | Lines | Why it matters |
|
|
40
40
|
| --- | ---: | --- |
|
|
41
41
|
| `lib/transaction/` | 2,786 | Sighash construction and signing — both BIP-143 and the Original Transaction Digest Algorithm. |
|
|
42
42
|
| `lib/script/interpreter.js` | 2,851 | **Scoped to the flag and era surface, not opcode execution.** Consensus-flag selection and defaults, era derivation (Genesis/Chronicle), the limits derived from them, and the semantics of the exported `verify()`. Opcode execution is excluded — see §2.2. |
|
|
43
43
|
| `lib/crypto/` | 2,519 | ECDSA, nonce derivation, signature encoding, the script-number type. **Scope this for an architectural judgement as well as for bugs** — see §2.3. |
|
|
44
|
-
| `lib/notaryhash/` | 2,
|
|
44
|
+
| `lib/notaryhash/` | 2,104 | BRC-220 signing and verification. Publicly reachable and relied on downstream. |
|
|
45
45
|
| `lib/privatekey.js`, `lib/publickey.js` | 843 | Key construction, serialisation, WIF. Recent defects here produced a *different* key without error. |
|
|
46
46
|
| `lib/smart_contract/` (targeted) | 472 | `locks.js` and the covenant-facing entrypoints in `index.js`: CLTV and HTLC locking semantics, flag plumbing, and any wrapper claiming mainnet-equivalent verification. Not the whole 6,908-line module. |
|
|
47
47
|
| `lib/covenant/` | 409 | The verification harness. Its flag word is what made covenants verify under 2019 rules while claiming to mirror mainnet. |
|
|
@@ -150,14 +150,14 @@ this repository.
|
|
|
150
150
|
| `lib/address.js`, `lib/networks.js`, `lib/opcode.js`, `lib/hdprivatekey.js`, `lib/hdpublickey.js` (2,391 lines) | Cut to pay for §2.1 | Formatting, network constants and BIP-32 derivation. No defect has originated here, and `networks.js` in particular defines addressing constants — pubkey hashes, xpub prefixes, ports, DNS seeds — and contains **no consensus-flag logic at all**. |
|
|
151
151
|
| The rest of the application layer — `lib/gdaf/`, `lib/ltp/`, `lib/ordinals/`, `lib/block/`, `lib/didweb/`, `lib/vcjwt/`, `lib/statuslist/`, most of `lib/smart_contract/`, plus assorted top-level files | Excluded | ~26,000 lines. Worth a separate engagement; including it here would blur the question in §1. Note the parts of it with a demonstrated defect history have been pulled *into* Tier 1 rather than left here — see §2.1. |
|
|
152
152
|
|
|
153
|
-
Totals reconcile against `lib/`, which is 40,
|
|
153
|
+
Totals reconcile against `lib/`, which is 40,112 lines across 131 files:
|
|
154
154
|
|
|
155
155
|
```
|
|
156
|
-
tier 1 12,
|
|
156
|
+
tier 1 12,089
|
|
157
157
|
tier 2 1,607
|
|
158
|
-
excluded 26,
|
|
158
|
+
excluded 26,416
|
|
159
159
|
------
|
|
160
|
-
total 40,
|
|
160
|
+
total 40,112
|
|
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,
|
|
231
|
+
Tier 1 — 12,089 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.
|
|
58
|
+
- **CDN**: `unpkg.com/@smartledger/bsv@9.14.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.14.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.14.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.14.0/bsv.min.js` |
|
|
85
|
+
| **bsv.bundle.js** | 937KB | Everything in one file | `unpkg.com/@smartledger/bsv@9.14.0/bsv.bundle.js` |
|
|
86
|
+
| **bsv-smartcontract.min.js** | 937KB | Covenant development | `unpkg.com/@smartledger/bsv@9.14.0/bsv-smartcontract.min.js` |
|
|
87
|
+
| **bsv-covenant.min.js** | 913KB | Covenant operations | `unpkg.com/@smartledger/bsv@9.14.0/bsv-covenant.min.js` |
|
|
88
|
+
| **bsv-script-helper.min.js** | 26KB | Custom script tools | `unpkg.com/@smartledger/bsv@9.14.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.14.0/bsv-security.min.js` |
|
|
90
|
+
| **bsv-ecies.min.js** | 71KB | Encryption | `unpkg.com/@smartledger/bsv@9.14.0/bsv-ecies.min.js` |
|
|
91
|
+
| **bsv-message.min.js** | 26KB | Message signing | `unpkg.com/@smartledger/bsv@9.14.0/bsv-message.min.js` |
|
|
92
|
+
| **bsv-mnemonic.min.js** | 681KB | HD wallets | `unpkg.com/@smartledger/bsv@9.14.0/bsv-mnemonic.min.js` |
|
|
93
|
+
| **🆕 bsv-shamir.min.js** | 432KB | **Secret sharing** | `unpkg.com/@smartledger/bsv@9.14.0/bsv-shamir.min.js` |
|
|
94
|
+
| **🆕 bsv-gdaf.min.js** | 1184KB | **Digital attestation** | `unpkg.com/@smartledger/bsv@9.14.0/bsv-gdaf.min.js` |
|
|
95
|
+
| **🆕 bsv-ltp.min.js** | 1184KB | **Legal tokens** | `unpkg.com/@smartledger/bsv@9.14.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.14.0/bsv.min.js"></script>
|
|
104
|
+
<script src="https://unpkg.com/@smartledger/bsv@9.14.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.14.0/bsv.min.js"></script>
|
|
110
|
+
<script src="https://unpkg.com/@smartledger/bsv@9.14.0/bsv-covenant.min.js"></script>
|
|
111
|
+
<script src="https://unpkg.com/@smartledger/bsv@9.14.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.14.0/bsv.min.js"></script>
|
|
117
|
+
<script src="https://unpkg.com/@smartledger/bsv@9.14.0/bsv-ltp.min.js"></script>
|
|
118
|
+
<script src="https://unpkg.com/@smartledger/bsv@9.14.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.14.0/bsv.min.js"></script>
|
|
136
|
+
<script src="https://unpkg.com/@smartledger/bsv@9.14.0/bsv-security.min.js"></script>
|
|
137
|
+
<script src="https://unpkg.com/@smartledger/bsv@9.14.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.14.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.14.0/bsv.min.js"></script>
|
|
726
726
|
</head>
|
|
727
727
|
<body>
|
|
728
728
|
<script>
|
|
@@ -15,7 +15,7 @@ seeking a quote for an independent security review of its cryptographic core.
|
|
|
15
15
|
|
|
16
16
|
Scope, and we would like these priced separately:
|
|
17
17
|
|
|
18
|
-
Tier 1 — 12,
|
|
18
|
+
Tier 1 — 12,089 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,
|
|
33
|
+
26,416-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,
|
|
18
|
+
Tier 1 — 12,089 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,
|
|
33
|
+
26,416-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,
|
|
18
|
+
Tier 1 — 12,089 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,
|
|
33
|
+
26,416-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.
|
|
51
|
+
<script src="https://unpkg.com/@smartledger/bsv@9.14.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.14.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.14.0/bsv.min.js"></script>
|
|
75
|
+
<script src="https://unpkg.com/@smartledger/bsv@9.14.0/bsv-covenant.min.js"></script>
|
|
76
|
+
<script src="https://unpkg.com/@smartledger/bsv@9.14.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.14.0/bsv.min.js"></script>
|
|
86
|
+
<script src="https://unpkg.com/@smartledger/bsv@9.14.0/bsv-ltp.min.js"></script>
|
|
87
|
+
<script src="https://unpkg.com/@smartledger/bsv@9.14.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.14.0/bsv.min.js"></script>
|
|
102
|
+
<script src="https://unpkg.com/@smartledger/bsv@9.14.0/bsv-security.min.js"></script>
|
|
103
|
+
<script src="https://unpkg.com/@smartledger/bsv@9.14.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.14.0/bsv.min.js` |
|
|
118
|
+
| **bsv.bundle.js** | 937KB | Everything in one file | `unpkg.com/@smartledger/bsv@9.14.0/bsv.bundle.js` |
|
|
119
|
+
| **bsv-smartcontract.min.js** | 937KB | Complete covenant framework | `unpkg.com/@smartledger/bsv@9.14.0/bsv-smartcontract.min.js` |
|
|
120
|
+
| **bsv-ltp.min.js** | 1184KB | **Legal Token Protocol** | `unpkg.com/@smartledger/bsv@9.14.0/bsv-ltp.min.js` |
|
|
121
|
+
| **bsv-gdaf.min.js** | 1184KB | **Digital Identity & Attestation** | `unpkg.com/@smartledger/bsv@9.14.0/bsv-gdaf.min.js` |
|
|
122
|
+
| **bsv-shamir.min.js** | 432KB | **Threshold Cryptography** | `unpkg.com/@smartledger/bsv@9.14.0/bsv-shamir.min.js` |
|
|
123
|
+
| **bsv-security.min.js** | 26KB | Security enhancements (opt-in helpers — see README › Security) | `unpkg.com/@smartledger/bsv@9.14.0/bsv-security.min.js` |
|
|
124
|
+
| **bsv-mnemonic.min.js** | 681KB | HD wallets | `unpkg.com/@smartledger/bsv@9.14.0/bsv-mnemonic.min.js` |
|
|
125
|
+
| **bsv-ecies.min.js** | 71KB | Encryption | `unpkg.com/@smartledger/bsv@9.14.0/bsv-ecies.min.js` |
|
|
126
|
+
| **bsv-covenant.min.js** | 913KB | Covenant operations | `unpkg.com/@smartledger/bsv@9.14.0/bsv-covenant.min.js` |
|
|
127
|
+
| **bsv-script-helper.min.js** | 26KB | Custom script tools | `unpkg.com/@smartledger/bsv@9.14.0/bsv-script-helper.min.js` |
|
|
128
|
+
| **bsv-message.min.js** | 26KB | Message signing | `unpkg.com/@smartledger/bsv@9.14.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.14.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.14.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.14.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.14.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.14.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.14.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.14.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.14.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.14.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.14.0/bsv-ltp.min.js"></script>
|
|
169
|
+
<script src="https://unpkg.com/@smartledger/bsv@9.14.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.14.0/bsv.bundle.js"></script>
|
|
173
173
|
```
|
|
174
174
|
|
|
175
175
|
## 🔍 **Testing Your Migration**
|
package/lib/notaryhash/index.js
CHANGED
|
@@ -6,6 +6,7 @@ var SPV = require('../spv')
|
|
|
6
6
|
var Encoding = require('./encoding')
|
|
7
7
|
var NotaryScript = require('./script')
|
|
8
8
|
var Certificate = require('./certificate')
|
|
9
|
+
var deprecate = require('../util/deprecate')
|
|
9
10
|
var Suites = require('./suites')
|
|
10
11
|
var Merkle = require('./merkle')
|
|
11
12
|
|
|
@@ -178,8 +179,10 @@ NotaryHash.recordMatchesCertificate = function (record, certificate) {
|
|
|
178
179
|
* has at that height. Rejects an orphaned block, which no header check can detect.
|
|
179
180
|
* @param {Number|String} [opts.powLimit] - easiest target a header may declare, as compact
|
|
180
181
|
* bits. Default 0x1d00ffff, the limit of mainnet and testnet; regtest is 0x207fffff.
|
|
181
|
-
* @param {Number|String} [opts.minWork] - minimum work the header must represent.
|
|
182
|
+
* @param {Number|String} [opts.minWork] - minimum work the header must represent, in HASHES.
|
|
182
183
|
* Difficulty 1 is about 4.295e9.
|
|
184
|
+
* @param {Number|String} [opts.minDifficulty] - the same floor in DIFFICULTY, the unit
|
|
185
|
+
* difficulty is quoted in: a real BSV header is about 2.6e10. Exactly one of the two.
|
|
183
186
|
* @param {Boolean} [opts.requirePow=true] - pass false only for test fixtures
|
|
184
187
|
* @returns {Object} { valid, errors }
|
|
185
188
|
*/
|
|
@@ -213,6 +216,26 @@ NotaryHash.verifyAnchorSPV = function (certificate, opts) {
|
|
|
213
216
|
errors.push('on-chain record does not match the certificate')
|
|
214
217
|
}
|
|
215
218
|
|
|
219
|
+
// The cap rules out a FREE forgery, not a cheap one. A header at difficulty 1 costs
|
|
220
|
+
// about 4.3e9 double-SHA256 attempts — seconds on one GPU — while a real mainnet header
|
|
221
|
+
// carries around 1e20. So a caller whose only input is "a header" has proved inclusion
|
|
222
|
+
// in something that cost very little, unless it came from a source it trusts. Per
|
|
223
|
+
// STABILITY.md this is marked in a minor and becomes required in the major.
|
|
224
|
+
if (opts.requirePow !== false && opts.minWork === undefined &&
|
|
225
|
+
opts.minDifficulty === undefined &&
|
|
226
|
+
(opts.blockHashAtHeight === undefined || opts.blockHashAtHeight === null)) {
|
|
227
|
+
deprecate({
|
|
228
|
+
what: 'NotaryHash.verify() with a header but no minWork or blockHashAtHeight',
|
|
229
|
+
since: '9.13.0',
|
|
230
|
+
removeIn: '10.0.0',
|
|
231
|
+
use: 'verify(certificate, { header, blockHashAtHeight }) with the block hash your own ' +
|
|
232
|
+
'chain source has at spv.blockHeight, or { header, minDifficulty } with the ' +
|
|
233
|
+
'difficulty you require',
|
|
234
|
+
why: 'the proof-of-work limit only rules out a free forgery: a header at difficulty 1 ' +
|
|
235
|
+
'costs about 4.3e9 hashes, while a real mainnet header carries about 1e20'
|
|
236
|
+
})
|
|
237
|
+
}
|
|
238
|
+
|
|
216
239
|
var proof = spv.merkleProof || {}
|
|
217
240
|
var inclusion
|
|
218
241
|
try {
|
|
@@ -223,7 +246,8 @@ NotaryHash.verifyAnchorSPV = function (certificate, opts) {
|
|
|
223
246
|
nodes: proof.nodes,
|
|
224
247
|
requirePow: opts.requirePow !== false,
|
|
225
248
|
powLimit: opts.powLimit,
|
|
226
|
-
minWork: opts.minWork
|
|
249
|
+
minWork: opts.minWork,
|
|
250
|
+
minDifficulty: opts.minDifficulty
|
|
227
251
|
})
|
|
228
252
|
} catch (inputError) {
|
|
229
253
|
// Something the caller passed cannot be used: a header that is not 80 bytes (often an
|
package/lib/spv/merkleproof.js
CHANGED
|
@@ -70,8 +70,14 @@ function targetLimit (powLimit) {
|
|
|
70
70
|
if (powLimit === undefined || powLimit === null) powLimit = POW_LIMIT_BITS
|
|
71
71
|
// A BN is taken as the target itself. The node's limit is a uint256 (2^224 - 1 on
|
|
72
72
|
// mainnet), and for compact bits the two agree, because 0x1d00ffff is the largest
|
|
73
|
-
// compact target at or below it; a BN limit can sit anywhere between them.
|
|
74
|
-
|
|
73
|
+
// compact target at or below it; a BN limit can sit anywhere between them. It still has
|
|
74
|
+
// to be a target: 2^256 or above is not a limit at all, and zero admits nothing.
|
|
75
|
+
if (BN.isBN(powLimit)) {
|
|
76
|
+
if (powLimit.isNeg() || powLimit.isZero() || powLimit.cmp(TWO_256) >= 0) {
|
|
77
|
+
throw new Error('powLimit as a BN must be a target above zero and below 2^256')
|
|
78
|
+
}
|
|
79
|
+
return powLimit
|
|
80
|
+
}
|
|
75
81
|
var bits
|
|
76
82
|
if (typeof powLimit === 'string') {
|
|
77
83
|
// parseInt stops at the first character it dislikes: '1d00ffzz' would silently
|
|
@@ -93,13 +99,60 @@ function targetLimit (powLimit) {
|
|
|
93
99
|
return target
|
|
94
100
|
}
|
|
95
101
|
|
|
102
|
+
/**
|
|
103
|
+
* A floor given in DIFFICULTY as the work it means: difficulty x 4,295,032,833, exactly.
|
|
104
|
+
*
|
|
105
|
+
* `minWork` counts hashes, and difficulty is the unit people actually quote — a real BSV
|
|
106
|
+
* header is "difficulty 2.6e10", not "1.1e20 hashes". Reading one as the other sets a floor
|
|
107
|
+
* 4.3 billion times too low and fails OPEN, which is why the unit is in the name. The
|
|
108
|
+
* multiplication is done on integers so a fractional difficulty keeps its digits instead of
|
|
109
|
+
* drifting through a float.
|
|
110
|
+
*/
|
|
111
|
+
function workFromDifficulty (difficulty) {
|
|
112
|
+
var text = typeof difficulty === 'number' ? numberToDecimal(difficulty) : String(difficulty)
|
|
113
|
+
// `1e19` is how a floor this size is written, by hand and by JSON, so both a Number and a
|
|
114
|
+
// string may arrive in exponent form. Expanded by moving the point, never through a float.
|
|
115
|
+
if (/^[0-9]+(\.[0-9]+)?[eE][+]?[0-9]+$/.test(text)) text = expandExponent(text)
|
|
116
|
+
if (!/^[0-9]+(\.[0-9]+)?$/.test(text)) {
|
|
117
|
+
throw new Error('minDifficulty must be a non-negative decimal number, not ' +
|
|
118
|
+
JSON.stringify(difficulty))
|
|
119
|
+
}
|
|
120
|
+
var parts = text.split('.')
|
|
121
|
+
var frac = parts[1] || ''
|
|
122
|
+
var scaled = new BN(parts[0] + frac, 10).mul(workFromTarget(targetFromBits(POW_LIMIT_BITS)))
|
|
123
|
+
return frac.length ? scaled.div(new BN(10).pow(new BN(frac.length))) : scaled
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
/** `2.557e10` as `25570000000`, by moving the decimal point, with no float in the path. */
|
|
127
|
+
function expandExponent (text) {
|
|
128
|
+
var halves = text.split(/[eE]/)
|
|
129
|
+
var exp = parseInt(halves[1].replace('+', ''), 10)
|
|
130
|
+
var digits = halves[0].split('.')
|
|
131
|
+
var intPart = digits[0]
|
|
132
|
+
var frac = digits[1] || ''
|
|
133
|
+
if (exp >= frac.length) return intPart + frac + new Array(exp - frac.length + 1).join('0')
|
|
134
|
+
return intPart + frac.slice(0, exp) + '.' + frac.slice(exp)
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
/** A Number as plain decimal digits, so 2.6e10 does not reach the parser as "2.6e+10". */
|
|
138
|
+
function numberToDecimal (n) {
|
|
139
|
+
if (!Number.isFinite(n) || n < 0) {
|
|
140
|
+
throw new Error('minDifficulty must be a non-negative finite number, not ' + String(n))
|
|
141
|
+
}
|
|
142
|
+
if (!/e/i.test(String(n))) return String(n)
|
|
143
|
+
return n.toLocaleString('en-US', { useGrouping: false, maximumFractionDigits: 20 })
|
|
144
|
+
}
|
|
145
|
+
|
|
96
146
|
/**
|
|
97
147
|
* `minWork` as a BN, refusing anything bn.js would read loosely. It parses `1e21` as
|
|
98
148
|
* 23521, `'4.3e9'` as 4 and `'abc'` as 1122, so a floor set from a Number near the
|
|
99
149
|
* chain's work would silently become a few thousand — a floor nothing fails.
|
|
100
150
|
*/
|
|
101
151
|
function minWorkBN (minWork) {
|
|
102
|
-
if (BN.isBN(minWork))
|
|
152
|
+
if (BN.isBN(minWork)) {
|
|
153
|
+
if (minWork.isNeg()) throw new Error('minWork as a BN must not be negative')
|
|
154
|
+
return minWork
|
|
155
|
+
}
|
|
103
156
|
if (typeof minWork === 'number') {
|
|
104
157
|
if (!Number.isSafeInteger(minWork) || minWork < 0) {
|
|
105
158
|
throw new Error('minWork as a number must be a non-negative safe integer; for larger ' +
|
|
@@ -207,8 +260,10 @@ function verifyMerkleProof (proof) {
|
|
|
207
260
|
* header: a bsv.BlockHeader, an 80-byte Buffer, or 80-byte hex.
|
|
208
261
|
* powLimit: the easiest target a header may declare, as compact bits (number or hex
|
|
209
262
|
* string) or a BN target. Default 0x1d00ffff. Regtest needs 0x207fffff.
|
|
210
|
-
* minWork: minimum work the header must represent (number, decimal string or
|
|
211
|
-
* 2^256 / (target + 1). Difficulty 1 is about 4.295e9.
|
|
263
|
+
* minWork: minimum work the header must represent, in HASHES (number, decimal string or
|
|
264
|
+
* BN): 2^256 / (target + 1). Difficulty 1 is about 4.295e9.
|
|
265
|
+
* minDifficulty: the same floor in DIFFICULTY, which is the unit difficulty is quoted in
|
|
266
|
+
* (a real BSV header is about 2.6e10). Exactly one of the two, or neither.
|
|
212
267
|
* With `requirePow: false` the work checks are not performed at all: `targetAllowed` and
|
|
213
268
|
* `workSufficient` report true because nothing objected, and `powLimit`/`minWork` are not
|
|
214
269
|
* even read.
|
|
@@ -231,8 +286,20 @@ function verifyTxInclusion (params) {
|
|
|
231
286
|
// when the work checks are off.
|
|
232
287
|
var targetAllowed = target !== null &&
|
|
233
288
|
(!requirePow || target.cmp(targetLimit(params.powLimit)) <= 0)
|
|
234
|
-
var
|
|
235
|
-
|
|
289
|
+
var floor = null
|
|
290
|
+
if (requirePow) {
|
|
291
|
+
// One floor, named for its unit. Accepting both would leave the caller guessing which
|
|
292
|
+
// one bit, and the two are 4.3e9 apart.
|
|
293
|
+
if (params.minWork !== undefined && params.minWork !== null &&
|
|
294
|
+
params.minDifficulty !== undefined && params.minDifficulty !== null) {
|
|
295
|
+
throw new Error('pass minWork (hashes) or minDifficulty (difficulty), not both')
|
|
296
|
+
}
|
|
297
|
+
if (params.minWork !== undefined && params.minWork !== null) floor = minWorkBN(params.minWork)
|
|
298
|
+
else if (params.minDifficulty !== undefined && params.minDifficulty !== null) {
|
|
299
|
+
floor = workFromDifficulty(params.minDifficulty)
|
|
300
|
+
}
|
|
301
|
+
}
|
|
302
|
+
var workSufficient = floor === null || work.cmp(floor) >= 0
|
|
236
303
|
|
|
237
304
|
return {
|
|
238
305
|
valid: rootMatches && (!requirePow || (powValid && targetAllowed && workSufficient)),
|
|
@@ -253,6 +320,7 @@ module.exports = {
|
|
|
253
320
|
targetFromBits: targetFromBits,
|
|
254
321
|
targetLimit: targetLimit,
|
|
255
322
|
workFromTarget: workFromTarget,
|
|
323
|
+
workFromDifficulty: workFromDifficulty,
|
|
256
324
|
headerSnapshot: headerSnapshot,
|
|
257
325
|
merkleRootFromBranch: merkleRootFromBranch,
|
|
258
326
|
verifyMerkleProof: verifyMerkleProof,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@smartledger/bsv",
|
|
3
|
-
"version": "9.
|
|
3
|
+
"version": "9.14.0",
|
|
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