@smartledger/bsv 8.1.0 → 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.
@@ -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.1.0**, 2026-08-13. Re-measure before sending if the version has
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
@@ -58,16 +58,16 @@ 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, 22,815 lines — 18,435 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. |
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,690 lines across 123 files:
63
+ Totals reconcile against `lib/`, which is 36,891 lines across 123 files:
64
64
 
65
65
  ```
66
66
  tier 1 12,268
67
67
  tier 2 1,607
68
- excluded 22,815
68
+ excluded 23,016
69
69
  ------
70
- total 36,690
70
+ total 36,891
71
71
  ```
72
72
 
73
73
  Core + optional = 13,875.
@@ -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,461 passing tests**, plus a reproducible-bundle gate, a require-cycle gate, and a
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.
@@ -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 22,815-line application
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,690 whole; §7 could not catch it because it reproduced
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.1.0/bsv-shamir.min.js`
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.1.0/bsv-gdaf.min.js`
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.1.0/bsv-ltp.min.js`
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.1.0/bsv.min.js` |
85
- | **bsv.bundle.js** | 937KB | Everything in one file | `unpkg.com/@smartledger/bsv@8.1.0/bsv.bundle.js` |
86
- | **bsv-smartcontract.min.js** | 937KB | Covenant development | `unpkg.com/@smartledger/bsv@8.1.0/bsv-smartcontract.min.js` |
87
- | **bsv-covenant.min.js** | 913KB | Covenant operations | `unpkg.com/@smartledger/bsv@8.1.0/bsv-covenant.min.js` |
88
- | **bsv-script-helper.min.js** | 26KB | Custom script tools | `unpkg.com/@smartledger/bsv@8.1.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.1.0/bsv-security.min.js` |
90
- | **bsv-ecies.min.js** | 71KB | Encryption | `unpkg.com/@smartledger/bsv@8.1.0/bsv-ecies.min.js` |
91
- | **bsv-message.min.js** | 26KB | Message signing | `unpkg.com/@smartledger/bsv@8.1.0/bsv-message.min.js` |
92
- | **bsv-mnemonic.min.js** | 681KB | HD wallets | `unpkg.com/@smartledger/bsv@8.1.0/bsv-mnemonic.min.js` |
93
- | **🆕 bsv-shamir.min.js** | 432KB | **Secret sharing** | `unpkg.com/@smartledger/bsv@8.1.0/bsv-shamir.min.js` |
94
- | **🆕 bsv-gdaf.min.js** | 1184KB | **Digital attestation** | `unpkg.com/@smartledger/bsv@8.1.0/bsv-gdaf.min.js` |
95
- | **🆕 bsv-ltp.min.js** | 1184KB | **Legal tokens** | `unpkg.com/@smartledger/bsv@8.1.0/bsv-ltp.min.js` |
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.1.0/bsv.min.js"></script>
104
- <script src="https://unpkg.com/@smartledger/bsv@8.1.0/bsv-script-helper.min.js"></script>
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.1.0/bsv.min.js"></script>
110
- <script src="https://unpkg.com/@smartledger/bsv@8.1.0/bsv-covenant.min.js"></script>
111
- <script src="https://unpkg.com/@smartledger/bsv@8.1.0/bsv-smartcontract.min.js"></script>
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.1.0/bsv.min.js"></script>
117
- <script src="https://unpkg.com/@smartledger/bsv@8.1.0/bsv-ltp.min.js"></script>
118
- <script src="https://unpkg.com/@smartledger/bsv@8.1.0/bsv-gdaf.min.js"></script>
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.1.0/bsv.min.js"></script>
136
- <script src="https://unpkg.com/@smartledger/bsv@8.1.0/bsv-security.min.js"></script>
137
- <script src="https://unpkg.com/@smartledger/bsv@8.1.0/bsv-shamir.min.js"></script>
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.1.0/bsv.bundle.js"></script>
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.1.0/bsv.min.js"></script>
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.1.0/bsv.min.js"></script>
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.1.0/bsv.bundle.js"></script>
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.1.0/bsv.min.js"></script>
75
- <script src="https://unpkg.com/@smartledger/bsv@8.1.0/bsv-covenant.min.js"></script>
76
- <script src="https://unpkg.com/@smartledger/bsv@8.1.0/bsv-smartcontract.min.js"></script>
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.1.0/bsv.min.js"></script>
86
- <script src="https://unpkg.com/@smartledger/bsv@8.1.0/bsv-ltp.min.js"></script>
87
- <script src="https://unpkg.com/@smartledger/bsv@8.1.0/bsv-gdaf.min.js"></script>
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.1.0/bsv.min.js"></script>
102
- <script src="https://unpkg.com/@smartledger/bsv@8.1.0/bsv-security.min.js"></script>
103
- <script src="https://unpkg.com/@smartledger/bsv@8.1.0/bsv-shamir.min.js"></script>
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.1.0/bsv.min.js` |
118
- | **bsv.bundle.js** | 937KB | Everything in one file | `unpkg.com/@smartledger/bsv@8.1.0/bsv.bundle.js` |
119
- | **bsv-smartcontract.min.js** | 937KB | Complete covenant framework | `unpkg.com/@smartledger/bsv@8.1.0/bsv-smartcontract.min.js` |
120
- | **bsv-ltp.min.js** | 1184KB | **Legal Token Protocol** | `unpkg.com/@smartledger/bsv@8.1.0/bsv-ltp.min.js` |
121
- | **bsv-gdaf.min.js** | 1184KB | **Digital Identity & Attestation** | `unpkg.com/@smartledger/bsv@8.1.0/bsv-gdaf.min.js` |
122
- | **bsv-shamir.min.js** | 432KB | **Threshold Cryptography** | `unpkg.com/@smartledger/bsv@8.1.0/bsv-shamir.min.js` |
123
- | **bsv-security.min.js** | 26KB | Security enhancements (opt-in helpers — see README › Security) | `unpkg.com/@smartledger/bsv@8.1.0/bsv-security.min.js` |
124
- | **bsv-mnemonic.min.js** | 681KB | HD wallets | `unpkg.com/@smartledger/bsv@8.1.0/bsv-mnemonic.min.js` |
125
- | **bsv-ecies.min.js** | 71KB | Encryption | `unpkg.com/@smartledger/bsv@8.1.0/bsv-ecies.min.js` |
126
- | **bsv-covenant.min.js** | 913KB | Covenant operations | `unpkg.com/@smartledger/bsv@8.1.0/bsv-covenant.min.js` |
127
- | **bsv-script-helper.min.js** | 26KB | Custom script tools | `unpkg.com/@smartledger/bsv@8.1.0/bsv-script-helper.min.js` |
128
- | **bsv-message.min.js** | 26KB | Message signing | `unpkg.com/@smartledger/bsv@8.1.0/bsv-message.min.js` |
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.1.0/bsv.min.js"></script>
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.1.0/bsv.bundle.js"></script>
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.1.0/bsv.min.js"></script>
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.1.0/bsv-smartcontract.min.js"></script>
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.1.0/bsv-ltp.min.js"></script>
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.1.0/bsv-gdaf.min.js"></script>
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.1.0/bsv.bundle.js"></script>
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.1.0/bsv.min.js"></script>
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.1.0/bsv-smartcontract.min.js"></script>
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.1.0/bsv-ltp.min.js"></script>
169
- <script src="https://unpkg.com/@smartledger/bsv@8.1.0/bsv-gdaf.min.js"></script>
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.1.0/bsv.bundle.js"></script>
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
- var canonical = AttestationSigner._canonicalizeJSON(credential)
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
- // Create hash
310
- var credentialHash = AttestationSigner._hashCredential(credentialCopy)
311
-
312
- // Verify signature
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 = ecdsa.verify()
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
- // Create hash
373
- var presentationHash = AttestationSigner._hashCredential(presentationCopy)
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 valid = ecdsa.verify()
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: valid,
387
- errors: valid ? [] : ['Presentation signature verification failed']
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
- var computedHash = AttestationSigner._hashCredential(credentialCopy)
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 Buffer.compare(computedHash, storedHash) === 0
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
  }