@smartledger/bsv 8.0.1 → 8.2.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 +118 -0
- package/README.md +38 -38
- package/bsv-gdaf.min.js +47 -47
- package/bsv-ltp.min.js +1 -1
- package/bsv-smartcontract.min.js +1 -1
- package/bsv.bundle.js +48 -48
- package/bsv.min.js +48 -48
- package/docs/AUDIT_SCOPE.md +13 -13
- 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/gdaf/attestation-signer.js +90 -2
- package/lib/gdaf/attestation-verifier.js +41 -25
- package/lib/gdaf/zk-prover.js +143 -46
- package/lib/script/interpreter.js +20 -1
- package/package.json +3 -2
- package/test/gdaf/canonicalization.js +106 -0
- package/test/gdaf/zk_prover.js +204 -0
- package/test/script/genesis_limits.js +37 -6
- package/tools/minimal_reproduction.js +119 -0
- package/tools/opcode_map.js +342 -0
- package/tools/server.js +97 -0
- package/tools/simple_real_tx.js +136 -0
- package/tools/sv-sighash-harness.js +123 -0
- package/tools/sv-sighash-report.js +71 -0
- package/tools/sv-tx-harness.js +172 -0
- package/tools/sv-tx-report.js +43 -0
- package/tools/sv-vector-harness.js +304 -0
- package/tools/sv-vector-report.js +88 -0
- package/version.js +1 -1
package/docs/AUDIT_SCOPE.md
CHANGED
|
@@ -5,7 +5,7 @@ cryptographic core, and carries the enquiry text to send to vendors. It exists s
|
|
|
5
5
|
every vendor prices the *same* thing, and so that the reasoning behind the scope
|
|
6
6
|
boundary survives past the engagement that prompted it.
|
|
7
7
|
|
|
8
|
-
Measured against **v8.0
|
|
8
|
+
Measured against **v8.2.0**, 2026-08-15. Re-measure before sending if the version has
|
|
9
9
|
moved (`docs/AUDIT_SCOPE.md` is not covered by a drift gate).
|
|
10
10
|
|
|
11
11
|
## 1. The question we are asking
|
|
@@ -29,11 +29,11 @@ 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
|
-
### Tier 1 — core, 12,
|
|
32
|
+
### Tier 1 — core, 12,268 lines across 33 files
|
|
33
33
|
|
|
34
34
|
| Module | Lines | Why it matters |
|
|
35
35
|
| --- | ---: | --- |
|
|
36
|
-
| `lib/script/` | 3,
|
|
36
|
+
| `lib/script/` | 3,751 | Consensus script interpreter. Divergence from the node means accepting a transaction the network rejects, or the reverse. |
|
|
37
37
|
| `lib/transaction/` | 2,779 | Sighash construction and signing — both BIP-143 and the Original Transaction Digest Algorithm. |
|
|
38
38
|
| `lib/crypto/` | 2,519 | ECDSA, nonce derivation, signature encoding, the script-number type. |
|
|
39
39
|
| `lib/hdprivatekey.js`, `lib/hdpublickey.js` | 1,168 | BIP-32 derivation, including hardened paths. |
|
|
@@ -58,19 +58,19 @@ is not.
|
|
|
58
58
|
| Component | Status | Reason |
|
|
59
59
|
| --- | --- | --- |
|
|
60
60
|
| `@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
|
-
| `lib/smart_contract/`, `lib/ltp/`, `lib/gdaf/`, `lib/ordinals/`, `lib/block/`, plus 9 further directories and 6 top-level files | Excluded | Application layer,
|
|
61
|
+
| `lib/smart_contract/`, `lib/ltp/`, `lib/gdaf/`, `lib/ordinals/`, `lib/block/`, plus 9 further directories and 6 top-level files | Excluded | Application layer, 23,016 lines — 18,636 in the five named modules and 4,380 in the remainder. Written in-house and covered by adversarial tests. Worth a separate engagement; including it here would blur the question in §1. |
|
|
62
62
|
|
|
63
|
-
Totals reconcile against `lib/`, which is 36,
|
|
63
|
+
Totals reconcile against `lib/`, which is 36,891 lines across 123 files:
|
|
64
64
|
|
|
65
65
|
```
|
|
66
|
-
tier 1 12,
|
|
66
|
+
tier 1 12,268
|
|
67
67
|
tier 2 1,607
|
|
68
|
-
excluded
|
|
68
|
+
excluded 23,016
|
|
69
69
|
------
|
|
70
|
-
total 36,
|
|
70
|
+
total 36,891
|
|
71
71
|
```
|
|
72
72
|
|
|
73
|
-
Core + optional = 13,
|
|
73
|
+
Core + optional = 13,875.
|
|
74
74
|
|
|
75
75
|
## 4. What an auditor gets on day one
|
|
76
76
|
|
|
@@ -94,7 +94,7 @@ Each of these should *reduce* the quote — they remove discovery work.
|
|
|
94
94
|
- **`npm run conformance`** — 452 cases across 13 suites, freezing observable behaviour
|
|
95
95
|
so any change surfaces as a diff. A second, independently written implementation
|
|
96
96
|
(`smartledger-bsv-core`, the TypeScript port) agrees on all 452.
|
|
97
|
-
- **4,
|
|
97
|
+
- **4,503 passing tests**, plus a reproducible-bundle gate, a require-cycle gate, and a
|
|
98
98
|
type-drift gate that parses the published types against the runtime.
|
|
99
99
|
- **`SECURITY.md`** — a published advisory (GHSA-gw63-x79h-mhjc) and a changelog of
|
|
100
100
|
security fixes with the reasoning for each.
|
|
@@ -133,7 +133,7 @@ seeking a quote for an independent security review of its cryptographic core.
|
|
|
133
133
|
|
|
134
134
|
Scope, and we would like these priced separately:
|
|
135
135
|
|
|
136
|
-
Tier 1 — 12,
|
|
136
|
+
Tier 1 — 12,268 lines, 33 files. Script interpreter, sighash and signing,
|
|
137
137
|
ECDSA and signature encoding, BIP-32 derivation, key and address
|
|
138
138
|
construction.
|
|
139
139
|
|
|
@@ -143,7 +143,7 @@ Scope, and we would like these priced separately:
|
|
|
143
143
|
JavaScript (CommonJS), Node >= 20.19. The code is public.
|
|
144
144
|
|
|
145
145
|
Explicitly out of scope: elliptic-curve and hash primitives, which are supplied
|
|
146
|
-
by the Noble libraries and already audited; and our
|
|
146
|
+
by the Noble libraries and already audited; and our 23,016-line application
|
|
147
147
|
layer (credentials, tokens, ordinals), which we would treat as a separate
|
|
148
148
|
engagement.
|
|
149
149
|
|
|
@@ -171,7 +171,7 @@ SmartLedger Technology
|
|
|
171
171
|
Every figure in this document, including the excluded total, must come out of this
|
|
172
172
|
script. **Derive the excluded count as the complement — never by subtracting tier 1
|
|
173
173
|
alone.** The first draft did exactly that, double-counted tier 2, and published parts
|
|
174
|
-
summing to 37,430 against a 36,
|
|
174
|
+
summing to 37,430 against a 36,891 whole; §7 could not catch it because it reproduced
|
|
175
175
|
every figure except the wrong one.
|
|
176
176
|
|
|
177
177
|
```sh
|
|
@@ -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@8.0
|
|
58
|
+
- **CDN**: `unpkg.com/@smartledger/bsv@8.2.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@8.0
|
|
64
|
+
- **CDN**: `unpkg.com/@smartledger/bsv@8.2.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@8.0
|
|
70
|
+
- **CDN**: `unpkg.com/@smartledger/bsv@8.2.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@8.0
|
|
85
|
-
| **bsv.bundle.js** | 937KB | Everything in one file | `unpkg.com/@smartledger/bsv@8.0
|
|
86
|
-
| **bsv-smartcontract.min.js** | 937KB | Covenant development | `unpkg.com/@smartledger/bsv@8.0
|
|
87
|
-
| **bsv-covenant.min.js** | 913KB | Covenant operations | `unpkg.com/@smartledger/bsv@8.0
|
|
88
|
-
| **bsv-script-helper.min.js** | 26KB | Custom script tools | `unpkg.com/@smartledger/bsv@8.0
|
|
89
|
-
| **bsv-security.min.js** | 26KB | Security enhancements (opt-in helpers — see README › Security) | `unpkg.com/@smartledger/bsv@8.0
|
|
90
|
-
| **bsv-ecies.min.js** | 71KB | Encryption | `unpkg.com/@smartledger/bsv@8.0
|
|
91
|
-
| **bsv-message.min.js** | 26KB | Message signing | `unpkg.com/@smartledger/bsv@8.0
|
|
92
|
-
| **bsv-mnemonic.min.js** | 681KB | HD wallets | `unpkg.com/@smartledger/bsv@8.0
|
|
93
|
-
| **🆕 bsv-shamir.min.js** | 432KB | **Secret sharing** | `unpkg.com/@smartledger/bsv@8.0
|
|
94
|
-
| **🆕 bsv-gdaf.min.js** | 1184KB | **Digital attestation** | `unpkg.com/@smartledger/bsv@8.0
|
|
95
|
-
| **🆕 bsv-ltp.min.js** | 1184KB | **Legal tokens** | `unpkg.com/@smartledger/bsv@8.0
|
|
84
|
+
| **bsv.min.js** | 937KB | Core BSV + SmartContract | `unpkg.com/@smartledger/bsv@8.2.0/bsv.min.js` |
|
|
85
|
+
| **bsv.bundle.js** | 937KB | Everything in one file | `unpkg.com/@smartledger/bsv@8.2.0/bsv.bundle.js` |
|
|
86
|
+
| **bsv-smartcontract.min.js** | 937KB | Covenant development | `unpkg.com/@smartledger/bsv@8.2.0/bsv-smartcontract.min.js` |
|
|
87
|
+
| **bsv-covenant.min.js** | 913KB | Covenant operations | `unpkg.com/@smartledger/bsv@8.2.0/bsv-covenant.min.js` |
|
|
88
|
+
| **bsv-script-helper.min.js** | 26KB | Custom script tools | `unpkg.com/@smartledger/bsv@8.2.0/bsv-script-helper.min.js` |
|
|
89
|
+
| **bsv-security.min.js** | 26KB | Security enhancements (opt-in helpers — see README › Security) | `unpkg.com/@smartledger/bsv@8.2.0/bsv-security.min.js` |
|
|
90
|
+
| **bsv-ecies.min.js** | 71KB | Encryption | `unpkg.com/@smartledger/bsv@8.2.0/bsv-ecies.min.js` |
|
|
91
|
+
| **bsv-message.min.js** | 26KB | Message signing | `unpkg.com/@smartledger/bsv@8.2.0/bsv-message.min.js` |
|
|
92
|
+
| **bsv-mnemonic.min.js** | 681KB | HD wallets | `unpkg.com/@smartledger/bsv@8.2.0/bsv-mnemonic.min.js` |
|
|
93
|
+
| **🆕 bsv-shamir.min.js** | 432KB | **Secret sharing** | `unpkg.com/@smartledger/bsv@8.2.0/bsv-shamir.min.js` |
|
|
94
|
+
| **🆕 bsv-gdaf.min.js** | 1184KB | **Digital attestation** | `unpkg.com/@smartledger/bsv@8.2.0/bsv-gdaf.min.js` |
|
|
95
|
+
| **🆕 bsv-ltp.min.js** | 1184KB | **Legal tokens** | `unpkg.com/@smartledger/bsv@8.2.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@8.0
|
|
104
|
-
<script src="https://unpkg.com/@smartledger/bsv@8.0
|
|
103
|
+
<script src="https://unpkg.com/@smartledger/bsv@8.2.0/bsv.min.js"></script>
|
|
104
|
+
<script src="https://unpkg.com/@smartledger/bsv@8.2.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@8.0
|
|
110
|
-
<script src="https://unpkg.com/@smartledger/bsv@8.0
|
|
111
|
-
<script src="https://unpkg.com/@smartledger/bsv@8.0
|
|
109
|
+
<script src="https://unpkg.com/@smartledger/bsv@8.2.0/bsv.min.js"></script>
|
|
110
|
+
<script src="https://unpkg.com/@smartledger/bsv@8.2.0/bsv-covenant.min.js"></script>
|
|
111
|
+
<script src="https://unpkg.com/@smartledger/bsv@8.2.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@8.0
|
|
117
|
-
<script src="https://unpkg.com/@smartledger/bsv@8.0
|
|
118
|
-
<script src="https://unpkg.com/@smartledger/bsv@8.0
|
|
116
|
+
<script src="https://unpkg.com/@smartledger/bsv@8.2.0/bsv.min.js"></script>
|
|
117
|
+
<script src="https://unpkg.com/@smartledger/bsv@8.2.0/bsv-ltp.min.js"></script>
|
|
118
|
+
<script src="https://unpkg.com/@smartledger/bsv@8.2.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@8.0
|
|
136
|
-
<script src="https://unpkg.com/@smartledger/bsv@8.0
|
|
137
|
-
<script src="https://unpkg.com/@smartledger/bsv@8.0
|
|
135
|
+
<script src="https://unpkg.com/@smartledger/bsv@8.2.0/bsv.min.js"></script>
|
|
136
|
+
<script src="https://unpkg.com/@smartledger/bsv@8.2.0/bsv-security.min.js"></script>
|
|
137
|
+
<script src="https://unpkg.com/@smartledger/bsv@8.2.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@8.0
|
|
149
|
+
<script src="https://unpkg.com/@smartledger/bsv@8.2.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@8.0
|
|
725
|
+
<script src="https://cdn.jsdelivr.net/npm/@smartledger/bsv@8.2.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@8.0
|
|
51
|
+
<script src="https://unpkg.com/@smartledger/bsv@8.2.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@8.0
|
|
61
|
+
<script src="https://unpkg.com/@smartledger/bsv@8.2.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@8.0
|
|
75
|
-
<script src="https://unpkg.com/@smartledger/bsv@8.0
|
|
76
|
-
<script src="https://unpkg.com/@smartledger/bsv@8.0
|
|
74
|
+
<script src="https://unpkg.com/@smartledger/bsv@8.2.0/bsv.min.js"></script>
|
|
75
|
+
<script src="https://unpkg.com/@smartledger/bsv@8.2.0/bsv-covenant.min.js"></script>
|
|
76
|
+
<script src="https://unpkg.com/@smartledger/bsv@8.2.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@8.0
|
|
86
|
-
<script src="https://unpkg.com/@smartledger/bsv@8.0
|
|
87
|
-
<script src="https://unpkg.com/@smartledger/bsv@8.0
|
|
85
|
+
<script src="https://unpkg.com/@smartledger/bsv@8.2.0/bsv.min.js"></script>
|
|
86
|
+
<script src="https://unpkg.com/@smartledger/bsv@8.2.0/bsv-ltp.min.js"></script>
|
|
87
|
+
<script src="https://unpkg.com/@smartledger/bsv@8.2.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@8.0
|
|
102
|
-
<script src="https://unpkg.com/@smartledger/bsv@8.0
|
|
103
|
-
<script src="https://unpkg.com/@smartledger/bsv@8.0
|
|
101
|
+
<script src="https://unpkg.com/@smartledger/bsv@8.2.0/bsv.min.js"></script>
|
|
102
|
+
<script src="https://unpkg.com/@smartledger/bsv@8.2.0/bsv-security.min.js"></script>
|
|
103
|
+
<script src="https://unpkg.com/@smartledger/bsv@8.2.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@8.0
|
|
118
|
-
| **bsv.bundle.js** | 937KB | Everything in one file | `unpkg.com/@smartledger/bsv@8.0
|
|
119
|
-
| **bsv-smartcontract.min.js** | 937KB | Complete covenant framework | `unpkg.com/@smartledger/bsv@8.0
|
|
120
|
-
| **bsv-ltp.min.js** | 1184KB | **Legal Token Protocol** | `unpkg.com/@smartledger/bsv@8.0
|
|
121
|
-
| **bsv-gdaf.min.js** | 1184KB | **Digital Identity & Attestation** | `unpkg.com/@smartledger/bsv@8.0
|
|
122
|
-
| **bsv-shamir.min.js** | 432KB | **Threshold Cryptography** | `unpkg.com/@smartledger/bsv@8.0
|
|
123
|
-
| **bsv-security.min.js** | 26KB | Security enhancements (opt-in helpers — see README › Security) | `unpkg.com/@smartledger/bsv@8.0
|
|
124
|
-
| **bsv-mnemonic.min.js** | 681KB | HD wallets | `unpkg.com/@smartledger/bsv@8.0
|
|
125
|
-
| **bsv-ecies.min.js** | 71KB | Encryption | `unpkg.com/@smartledger/bsv@8.0
|
|
126
|
-
| **bsv-covenant.min.js** | 913KB | Covenant operations | `unpkg.com/@smartledger/bsv@8.0
|
|
127
|
-
| **bsv-script-helper.min.js** | 26KB | Custom script tools | `unpkg.com/@smartledger/bsv@8.0
|
|
128
|
-
| **bsv-message.min.js** | 26KB | Message signing | `unpkg.com/@smartledger/bsv@8.0
|
|
117
|
+
| **bsv.min.js** | 937KB | Core BSV + SmartContract | `unpkg.com/@smartledger/bsv@8.2.0/bsv.min.js` |
|
|
118
|
+
| **bsv.bundle.js** | 937KB | Everything in one file | `unpkg.com/@smartledger/bsv@8.2.0/bsv.bundle.js` |
|
|
119
|
+
| **bsv-smartcontract.min.js** | 937KB | Complete covenant framework | `unpkg.com/@smartledger/bsv@8.2.0/bsv-smartcontract.min.js` |
|
|
120
|
+
| **bsv-ltp.min.js** | 1184KB | **Legal Token Protocol** | `unpkg.com/@smartledger/bsv@8.2.0/bsv-ltp.min.js` |
|
|
121
|
+
| **bsv-gdaf.min.js** | 1184KB | **Digital Identity & Attestation** | `unpkg.com/@smartledger/bsv@8.2.0/bsv-gdaf.min.js` |
|
|
122
|
+
| **bsv-shamir.min.js** | 432KB | **Threshold Cryptography** | `unpkg.com/@smartledger/bsv@8.2.0/bsv-shamir.min.js` |
|
|
123
|
+
| **bsv-security.min.js** | 26KB | Security enhancements (opt-in helpers — see README › Security) | `unpkg.com/@smartledger/bsv@8.2.0/bsv-security.min.js` |
|
|
124
|
+
| **bsv-mnemonic.min.js** | 681KB | HD wallets | `unpkg.com/@smartledger/bsv@8.2.0/bsv-mnemonic.min.js` |
|
|
125
|
+
| **bsv-ecies.min.js** | 71KB | Encryption | `unpkg.com/@smartledger/bsv@8.2.0/bsv-ecies.min.js` |
|
|
126
|
+
| **bsv-covenant.min.js** | 913KB | Covenant operations | `unpkg.com/@smartledger/bsv@8.2.0/bsv-covenant.min.js` |
|
|
127
|
+
| **bsv-script-helper.min.js** | 26KB | Custom script tools | `unpkg.com/@smartledger/bsv@8.2.0/bsv-script-helper.min.js` |
|
|
128
|
+
| **bsv-message.min.js** | 26KB | Message signing | `unpkg.com/@smartledger/bsv@8.2.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@8.0
|
|
17
|
+
<script src="https://unpkg.com/@smartledger/bsv@8.2.0/bsv.min.js"></script>
|
|
18
18
|
|
|
19
19
|
<!-- Everything included (937KB) -->
|
|
20
|
-
<script src="https://unpkg.com/@smartledger/bsv@8.0
|
|
20
|
+
<script src="https://unpkg.com/@smartledger/bsv@8.2.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@8.0
|
|
130
|
+
<script src="https://unpkg.com/@smartledger/bsv@8.2.0/bsv.min.js"></script>
|
|
131
131
|
|
|
132
132
|
<!-- Smart contracts (937KB) -->
|
|
133
|
-
<script src="https://unpkg.com/@smartledger/bsv@8.0
|
|
133
|
+
<script src="https://unpkg.com/@smartledger/bsv@8.2.0/bsv-smartcontract.min.js"></script>
|
|
134
134
|
|
|
135
135
|
<!-- Legal tokens (1.16MB) -->
|
|
136
|
-
<script src="https://unpkg.com/@smartledger/bsv@8.0
|
|
136
|
+
<script src="https://unpkg.com/@smartledger/bsv@8.2.0/bsv-ltp.min.js"></script>
|
|
137
137
|
|
|
138
138
|
<!-- Digital identity (1.16MB) -->
|
|
139
|
-
<script src="https://unpkg.com/@smartledger/bsv@8.0
|
|
139
|
+
<script src="https://unpkg.com/@smartledger/bsv@8.2.0/bsv-gdaf.min.js"></script>
|
|
140
140
|
|
|
141
141
|
<!-- Everything (937KB) -->
|
|
142
|
-
<script src="https://unpkg.com/@smartledger/bsv@8.0
|
|
142
|
+
<script src="https://unpkg.com/@smartledger/bsv@8.2.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@8.0
|
|
162
|
+
<script src="https://unpkg.com/@smartledger/bsv@8.2.0/bsv.min.js"></script>
|
|
163
163
|
|
|
164
164
|
<!-- Add smart contracts when ready -->
|
|
165
|
-
<script src="https://unpkg.com/@smartledger/bsv@8.0
|
|
165
|
+
<script src="https://unpkg.com/@smartledger/bsv@8.2.0/bsv-smartcontract.min.js"></script>
|
|
166
166
|
|
|
167
167
|
<!-- Add advanced features as needed -->
|
|
168
|
-
<script src="https://unpkg.com/@smartledger/bsv@8.0
|
|
169
|
-
<script src="https://unpkg.com/@smartledger/bsv@8.0
|
|
168
|
+
<script src="https://unpkg.com/@smartledger/bsv@8.2.0/bsv-ltp.min.js"></script>
|
|
169
|
+
<script src="https://unpkg.com/@smartledger/bsv@8.2.0/bsv-gdaf.min.js"></script>
|
|
170
170
|
|
|
171
171
|
<!-- Everything in one file -->
|
|
172
|
-
<script src="https://unpkg.com/@smartledger/bsv@8.0
|
|
172
|
+
<script src="https://unpkg.com/@smartledger/bsv@8.2.0/bsv.bundle.js"></script>
|
|
173
173
|
```
|
|
174
174
|
|
|
175
175
|
## 🔍 **Testing Your Migration**
|
|
@@ -94,16 +94,104 @@ AttestationSigner._canonicalizeJSON = function(obj) {
|
|
|
94
94
|
return JSON.stringify(AttestationSigner._sortValue(obj))
|
|
95
95
|
}
|
|
96
96
|
|
|
97
|
+
/**
|
|
98
|
+
* RFC 8785 (JCS) canonical JSON.
|
|
99
|
+
*
|
|
100
|
+
* `_canonicalizeJSON` above sorts keys and then REBUILDS an object, which loses the
|
|
101
|
+
* sort: V8 orders integer-like own properties numerically ahead of string keys whatever
|
|
102
|
+
* order they were inserted in. So `{ '10': …, '2': … }` serialized as
|
|
103
|
+
*
|
|
104
|
+
* ours {"2":"two","10":"ten"}
|
|
105
|
+
* JCS {"10":"ten","2":"two"} (UTF-16 code-unit order)
|
|
106
|
+
*
|
|
107
|
+
* Within this library that is merely deterministic-but-nonstandard: signing and
|
|
108
|
+
* verification agree, and no forgery follows from it. Across implementations it is a
|
|
109
|
+
* verification failure — GDAF credentials exist to be checked by other parties, and a
|
|
110
|
+
* JCS-conformant verifier in any language computes a different hash and rejects a valid
|
|
111
|
+
* signature. The previous implementation acknowledged this with "do not feed integer-like
|
|
112
|
+
* keys here", which is a constraint the data cannot be relied upon to honour.
|
|
113
|
+
*
|
|
114
|
+
* This serializes directly instead of round-tripping through an object, so the order
|
|
115
|
+
* actually survives. Array.prototype.sort already compares strings by UTF-16 code unit,
|
|
116
|
+
* which is exactly what JCS specifies; the bug was never the sort.
|
|
117
|
+
*
|
|
118
|
+
* JSON.stringify is used for the leaf types on purpose: for finite numbers it produces
|
|
119
|
+
* ECMAScript Number::toString, which is what JCS mandates, and since ES2019 it emits
|
|
120
|
+
* well-formed output for lone surrogates. Both are hard to reproduce by hand and easy to
|
|
121
|
+
* get subtly wrong.
|
|
122
|
+
*
|
|
123
|
+
* @param {*} value - Value to serialize
|
|
124
|
+
* @returns {String} RFC 8785 canonical JSON
|
|
125
|
+
*/
|
|
126
|
+
AttestationSigner._canonicalizeJCS = function (value) {
|
|
127
|
+
if (value === null) return 'null'
|
|
128
|
+
|
|
129
|
+
var type = typeof value
|
|
130
|
+
|
|
131
|
+
if (type === 'boolean') return value ? 'true' : 'false'
|
|
132
|
+
|
|
133
|
+
if (type === 'number') {
|
|
134
|
+
// JCS has no representation for these; refuse rather than emit `null`, which is what
|
|
135
|
+
// JSON.stringify does and which would silently sign a different document.
|
|
136
|
+
if (!isFinite(value)) {
|
|
137
|
+
throw new Error('Cannot canonicalize non-finite number: ' + value)
|
|
138
|
+
}
|
|
139
|
+
return JSON.stringify(value)
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
if (type === 'string') return JSON.stringify(value)
|
|
143
|
+
|
|
144
|
+
if (Array.isArray(value)) {
|
|
145
|
+
// Arrays are order-significant. `undefined` has no JSON form and becomes null in an
|
|
146
|
+
// array, matching JSON.stringify.
|
|
147
|
+
return '[' + value.map(function (item) {
|
|
148
|
+
return item === undefined ? 'null' : AttestationSigner._canonicalizeJCS(item)
|
|
149
|
+
}).join(',') + ']'
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
if (type === 'object') {
|
|
153
|
+
var keys = Object.keys(value).filter(function (key) {
|
|
154
|
+
// Absent and explicitly-undefined are indistinguishable in JSON, so both are
|
|
155
|
+
// dropped — as JSON.stringify does.
|
|
156
|
+
return value[key] !== undefined && typeof value[key] !== 'function'
|
|
157
|
+
}).sort()
|
|
158
|
+
|
|
159
|
+
return '{' + keys.map(function (key) {
|
|
160
|
+
return JSON.stringify(key) + ':' + AttestationSigner._canonicalizeJCS(value[key])
|
|
161
|
+
}).join(',') + '}'
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
throw new Error('Cannot canonicalize value of type: ' + type)
|
|
165
|
+
}
|
|
166
|
+
|
|
97
167
|
/**
|
|
98
168
|
* Create hash of credential for signing
|
|
99
169
|
* @param {Object} credential - Credential object
|
|
100
170
|
* @returns {Buffer} SHA256 hash
|
|
101
171
|
*/
|
|
102
|
-
AttestationSigner._hashCredential = function(credential) {
|
|
103
|
-
|
|
172
|
+
AttestationSigner._hashCredential = function (credential, canonicalization) {
|
|
173
|
+
// RFC 8785 by default. `'legacy'` selects the pre-JCS sorted-key form, which is kept
|
|
174
|
+
// ONLY so credentials signed before the change still verify — see
|
|
175
|
+
// AttestationSigner.CANONICALIZATION. New signatures must never use it.
|
|
176
|
+
var canonical = canonicalization === AttestationSigner.CANONICALIZATION.LEGACY
|
|
177
|
+
? AttestationSigner._canonicalizeJSON(credential)
|
|
178
|
+
: AttestationSigner._canonicalizeJCS(credential)
|
|
104
179
|
return Hash.sha256(Buffer.from(canonical, 'utf8'))
|
|
105
180
|
}
|
|
106
181
|
|
|
182
|
+
/**
|
|
183
|
+
* Canonicalization forms understood when hashing a credential.
|
|
184
|
+
*
|
|
185
|
+
* JCS is RFC 8785 and is what everything signs with now. LEGACY is the sorted-key form
|
|
186
|
+
* this library used before, retained so existing credentials keep verifying: it is
|
|
187
|
+
* deterministic but not interoperable, because rebuilding the object let V8 reorder
|
|
188
|
+
* integer-like keys ahead of the sort.
|
|
189
|
+
*/
|
|
190
|
+
AttestationSigner.CANONICALIZATION = {
|
|
191
|
+
JCS: 'jcs',
|
|
192
|
+
LEGACY: 'legacy'
|
|
193
|
+
}
|
|
194
|
+
|
|
107
195
|
/**
|
|
108
196
|
* Create base credential structure
|
|
109
197
|
* @param {Object} credentialSubject - Subject data
|
|
@@ -306,18 +306,23 @@ AttestationVerifier._verifySignature = async function(credential) {
|
|
|
306
306
|
delete credentialCopy.proof
|
|
307
307
|
delete credentialCopy.rootHash
|
|
308
308
|
|
|
309
|
-
//
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
//
|
|
309
|
+
// Signatures are made over RFC 8785 canonical JSON. Credentials signed before that
|
|
310
|
+
// change used the older sorted-key form, so both are tried — JCS first, so a
|
|
311
|
+
// current credential never pays for the legacy attempt. This is a compatibility
|
|
312
|
+
// path, not a weakening: each form is a complete, deterministic serialization and
|
|
313
|
+
// the signature must verify against one of them exactly.
|
|
313
314
|
var signature = AttestationVerifier._parseJWSSignature(proof.jws)
|
|
314
|
-
|
|
315
|
-
var ecdsa = new ECDSA()
|
|
316
|
-
ecdsa.hashbuf = credentialHash
|
|
317
|
-
ecdsa.pubkey = publicKey
|
|
318
|
-
ecdsa.sig = signature
|
|
319
315
|
|
|
320
|
-
var valid =
|
|
316
|
+
var valid = [
|
|
317
|
+
AttestationSigner.CANONICALIZATION.JCS,
|
|
318
|
+
AttestationSigner.CANONICALIZATION.LEGACY
|
|
319
|
+
].some(function (form) {
|
|
320
|
+
var ecdsa = new ECDSA()
|
|
321
|
+
ecdsa.hashbuf = AttestationSigner._hashCredential(credentialCopy, form)
|
|
322
|
+
ecdsa.pubkey = publicKey
|
|
323
|
+
ecdsa.sig = signature
|
|
324
|
+
return ecdsa.verify() === true
|
|
325
|
+
})
|
|
321
326
|
|
|
322
327
|
if (valid) {
|
|
323
328
|
return {
|
|
@@ -369,22 +374,24 @@ AttestationVerifier._verifyPresentationSignature = async function(presentation)
|
|
|
369
374
|
var presentationCopy = JSON.parse(JSON.stringify(presentation))
|
|
370
375
|
delete presentationCopy.proof
|
|
371
376
|
|
|
372
|
-
//
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
// Verify signature
|
|
377
|
+
// Both canonicalizations, for the reason given on the credential path above:
|
|
378
|
+
// presentations signed before the move to RFC 8785 must keep verifying.
|
|
376
379
|
var signature = AttestationVerifier._parseJWSSignature(proof.jws)
|
|
377
|
-
|
|
378
|
-
var ecdsa = new ECDSA()
|
|
379
|
-
ecdsa.hashbuf = presentationHash
|
|
380
|
-
ecdsa.pubkey = publicKey
|
|
381
|
-
ecdsa.sig = signature
|
|
382
380
|
|
|
383
|
-
var
|
|
381
|
+
var presentationValid = [
|
|
382
|
+
AttestationSigner.CANONICALIZATION.JCS,
|
|
383
|
+
AttestationSigner.CANONICALIZATION.LEGACY
|
|
384
|
+
].some(function (form) {
|
|
385
|
+
var e = new ECDSA()
|
|
386
|
+
e.hashbuf = AttestationSigner._hashCredential(presentationCopy, form)
|
|
387
|
+
e.pubkey = publicKey
|
|
388
|
+
e.sig = signature
|
|
389
|
+
return e.verify() === true
|
|
390
|
+
})
|
|
384
391
|
|
|
385
392
|
return {
|
|
386
|
-
valid:
|
|
387
|
-
errors:
|
|
393
|
+
valid: presentationValid,
|
|
394
|
+
errors: presentationValid ? [] : ['Presentation signature verification failed']
|
|
388
395
|
}
|
|
389
396
|
|
|
390
397
|
} catch (error) {
|
|
@@ -541,10 +548,19 @@ AttestationVerifier.verifyCredentialHash = function(credential) {
|
|
|
541
548
|
delete credentialCopy.proof
|
|
542
549
|
delete credentialCopy.rootHash
|
|
543
550
|
|
|
544
|
-
|
|
551
|
+
// A rootHash written before the move to RFC 8785 was computed over the legacy
|
|
552
|
+
// form, so both are accepted. Buffer.compare on each is still an exact match —
|
|
553
|
+
// this widens which serialization is recognised, not what counts as equal.
|
|
545
554
|
var storedHash = Buffer.from(credential.rootHash, 'hex')
|
|
546
|
-
|
|
547
|
-
return
|
|
555
|
+
|
|
556
|
+
return [
|
|
557
|
+
AttestationSigner.CANONICALIZATION.JCS,
|
|
558
|
+
AttestationSigner.CANONICALIZATION.LEGACY
|
|
559
|
+
].some(function (form) {
|
|
560
|
+
return Buffer.compare(
|
|
561
|
+
AttestationSigner._hashCredential(credentialCopy, form), storedHash
|
|
562
|
+
) === 0
|
|
563
|
+
})
|
|
548
564
|
} catch (error) {
|
|
549
565
|
return false
|
|
550
566
|
}
|