@smartledger/bsv 9.1.0 → 9.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 +86 -0
- package/README.md +19 -19
- package/bsv-gdaf.min.js +44 -44
- package/bsv-ltp.min.js +28 -28
- package/bsv-smartcontract.min.js +1 -1
- package/bsv.bundle.js +44 -44
- package/bsv.d.ts +53 -3
- package/bsv.min.js +44 -44
- 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/index.js +5 -4
- package/index.mjs +1 -0
- package/jcs-entry.d.ts +12 -0
- package/jcs-entry.js +1 -0
- package/lib/block/merkleblock.js +34 -4
- package/lib/ltp/claim.js +105 -14
- package/lib/util/jcs.js +44 -14
- package/package.json +6 -1
- package/version.js +1 -1
|
@@ -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.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@9.
|
|
64
|
+
- **CDN**: `unpkg.com/@smartledger/bsv@9.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@9.
|
|
70
|
+
- **CDN**: `unpkg.com/@smartledger/bsv@9.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@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.2.0/bsv.min.js` |
|
|
85
|
+
| **bsv.bundle.js** | 937KB | Everything in one file | `unpkg.com/@smartledger/bsv@9.2.0/bsv.bundle.js` |
|
|
86
|
+
| **bsv-smartcontract.min.js** | 937KB | Covenant development | `unpkg.com/@smartledger/bsv@9.2.0/bsv-smartcontract.min.js` |
|
|
87
|
+
| **bsv-covenant.min.js** | 913KB | Covenant operations | `unpkg.com/@smartledger/bsv@9.2.0/bsv-covenant.min.js` |
|
|
88
|
+
| **bsv-script-helper.min.js** | 26KB | Custom script tools | `unpkg.com/@smartledger/bsv@9.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@9.2.0/bsv-security.min.js` |
|
|
90
|
+
| **bsv-ecies.min.js** | 71KB | Encryption | `unpkg.com/@smartledger/bsv@9.2.0/bsv-ecies.min.js` |
|
|
91
|
+
| **bsv-message.min.js** | 26KB | Message signing | `unpkg.com/@smartledger/bsv@9.2.0/bsv-message.min.js` |
|
|
92
|
+
| **bsv-mnemonic.min.js** | 681KB | HD wallets | `unpkg.com/@smartledger/bsv@9.2.0/bsv-mnemonic.min.js` |
|
|
93
|
+
| **🆕 bsv-shamir.min.js** | 432KB | **Secret sharing** | `unpkg.com/@smartledger/bsv@9.2.0/bsv-shamir.min.js` |
|
|
94
|
+
| **🆕 bsv-gdaf.min.js** | 1184KB | **Digital attestation** | `unpkg.com/@smartledger/bsv@9.2.0/bsv-gdaf.min.js` |
|
|
95
|
+
| **🆕 bsv-ltp.min.js** | 1184KB | **Legal tokens** | `unpkg.com/@smartledger/bsv@9.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@9.
|
|
104
|
-
<script src="https://unpkg.com/@smartledger/bsv@9.
|
|
103
|
+
<script src="https://unpkg.com/@smartledger/bsv@9.2.0/bsv.min.js"></script>
|
|
104
|
+
<script src="https://unpkg.com/@smartledger/bsv@9.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@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.2.0/bsv.min.js"></script>
|
|
110
|
+
<script src="https://unpkg.com/@smartledger/bsv@9.2.0/bsv-covenant.min.js"></script>
|
|
111
|
+
<script src="https://unpkg.com/@smartledger/bsv@9.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@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.2.0/bsv.min.js"></script>
|
|
117
|
+
<script src="https://unpkg.com/@smartledger/bsv@9.2.0/bsv-ltp.min.js"></script>
|
|
118
|
+
<script src="https://unpkg.com/@smartledger/bsv@9.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@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.2.0/bsv.min.js"></script>
|
|
136
|
+
<script src="https://unpkg.com/@smartledger/bsv@9.2.0/bsv-security.min.js"></script>
|
|
137
|
+
<script src="https://unpkg.com/@smartledger/bsv@9.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@9.
|
|
149
|
+
<script src="https://unpkg.com/@smartledger/bsv@9.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@9.
|
|
725
|
+
<script src="https://cdn.jsdelivr.net/npm/@smartledger/bsv@9.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@9.
|
|
51
|
+
<script src="https://unpkg.com/@smartledger/bsv@9.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@9.
|
|
61
|
+
<script src="https://unpkg.com/@smartledger/bsv@9.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@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.2.0/bsv.min.js"></script>
|
|
75
|
+
<script src="https://unpkg.com/@smartledger/bsv@9.2.0/bsv-covenant.min.js"></script>
|
|
76
|
+
<script src="https://unpkg.com/@smartledger/bsv@9.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@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.2.0/bsv.min.js"></script>
|
|
86
|
+
<script src="https://unpkg.com/@smartledger/bsv@9.2.0/bsv-ltp.min.js"></script>
|
|
87
|
+
<script src="https://unpkg.com/@smartledger/bsv@9.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@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.2.0/bsv.min.js"></script>
|
|
102
|
+
<script src="https://unpkg.com/@smartledger/bsv@9.2.0/bsv-security.min.js"></script>
|
|
103
|
+
<script src="https://unpkg.com/@smartledger/bsv@9.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@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.2.0/bsv.min.js` |
|
|
118
|
+
| **bsv.bundle.js** | 937KB | Everything in one file | `unpkg.com/@smartledger/bsv@9.2.0/bsv.bundle.js` |
|
|
119
|
+
| **bsv-smartcontract.min.js** | 937KB | Complete covenant framework | `unpkg.com/@smartledger/bsv@9.2.0/bsv-smartcontract.min.js` |
|
|
120
|
+
| **bsv-ltp.min.js** | 1184KB | **Legal Token Protocol** | `unpkg.com/@smartledger/bsv@9.2.0/bsv-ltp.min.js` |
|
|
121
|
+
| **bsv-gdaf.min.js** | 1184KB | **Digital Identity & Attestation** | `unpkg.com/@smartledger/bsv@9.2.0/bsv-gdaf.min.js` |
|
|
122
|
+
| **bsv-shamir.min.js** | 432KB | **Threshold Cryptography** | `unpkg.com/@smartledger/bsv@9.2.0/bsv-shamir.min.js` |
|
|
123
|
+
| **bsv-security.min.js** | 26KB | Security enhancements (opt-in helpers — see README › Security) | `unpkg.com/@smartledger/bsv@9.2.0/bsv-security.min.js` |
|
|
124
|
+
| **bsv-mnemonic.min.js** | 681KB | HD wallets | `unpkg.com/@smartledger/bsv@9.2.0/bsv-mnemonic.min.js` |
|
|
125
|
+
| **bsv-ecies.min.js** | 71KB | Encryption | `unpkg.com/@smartledger/bsv@9.2.0/bsv-ecies.min.js` |
|
|
126
|
+
| **bsv-covenant.min.js** | 913KB | Covenant operations | `unpkg.com/@smartledger/bsv@9.2.0/bsv-covenant.min.js` |
|
|
127
|
+
| **bsv-script-helper.min.js** | 26KB | Custom script tools | `unpkg.com/@smartledger/bsv@9.2.0/bsv-script-helper.min.js` |
|
|
128
|
+
| **bsv-message.min.js** | 26KB | Message signing | `unpkg.com/@smartledger/bsv@9.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@9.
|
|
17
|
+
<script src="https://unpkg.com/@smartledger/bsv@9.2.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.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@9.
|
|
130
|
+
<script src="https://unpkg.com/@smartledger/bsv@9.2.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.2.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.2.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.2.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.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@9.
|
|
162
|
+
<script src="https://unpkg.com/@smartledger/bsv@9.2.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.2.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.2.0/bsv-ltp.min.js"></script>
|
|
169
|
+
<script src="https://unpkg.com/@smartledger/bsv@9.2.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.2.0/bsv.bundle.js"></script>
|
|
173
173
|
```
|
|
174
174
|
|
|
175
175
|
## 🔍 **Testing Your Migration**
|
package/index.js
CHANGED
|
@@ -307,6 +307,7 @@ bsv.createCredentialTemplate = function(credentialType) {
|
|
|
307
307
|
|
|
308
308
|
// Legal Token Protocol (LTP) - Primitives-Only Interface
|
|
309
309
|
bsv.LTP = require('./lib/ltp')
|
|
310
|
+
bsv.JCS = require('./lib/util/jcs')
|
|
310
311
|
|
|
311
312
|
// LTP Right Token Primitives
|
|
312
313
|
bsv.prepareRightToken = function(type, issuerDID, subjectDID, claim, issuerPrivateKey, options) {
|
|
@@ -508,12 +509,12 @@ bsv.createClaimTemplate = function(schemaName) {
|
|
|
508
509
|
}
|
|
509
510
|
|
|
510
511
|
// LTP Utility Functions
|
|
511
|
-
bsv.canonicalizeClaim = function(claim) {
|
|
512
|
-
return bsv.LTP.Claim.canonicalize(claim)
|
|
512
|
+
bsv.canonicalizeClaim = function(claim, canonicalization) {
|
|
513
|
+
return bsv.LTP.Claim.canonicalize(claim, canonicalization)
|
|
513
514
|
}
|
|
514
515
|
|
|
515
|
-
bsv.hashClaim = function(claim) {
|
|
516
|
-
return bsv.LTP.Claim.hash(claim)
|
|
516
|
+
bsv.hashClaim = function(claim, canonicalization) {
|
|
517
|
+
return bsv.LTP.Claim.hash(claim, canonicalization)
|
|
517
518
|
}
|
|
518
519
|
|
|
519
520
|
bsv.addCustomClaimSchema = function(name, schema) {
|
package/index.mjs
CHANGED
package/jcs-entry.d.ts
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* RFC 8785 (JSON Canonicalization Scheme).
|
|
3
|
+
*
|
|
4
|
+
* Object keys sort by UTF-16 code unit, applied during serialization rather than by
|
|
5
|
+
* rebuilding an object — rebuilding lets V8 reorder integer-like keys ahead of the
|
|
6
|
+
* sort, producing `{"2":…,"10":…}` where the RFC requires `{"10":…,"2":…}`.
|
|
7
|
+
*
|
|
8
|
+
* Throws on non-finite numbers, bigint, circular structures, and values with no JSON
|
|
9
|
+
* representation, rather than coercing them: a canonicalizer that silently serializes
|
|
10
|
+
* a different document than the one supplied defeats its own purpose.
|
|
11
|
+
*/
|
|
12
|
+
export declare function stringify(value: any): string;
|
package/jcs-entry.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
module.exports = require('./lib/util/jcs')
|
package/lib/block/merkleblock.js
CHANGED
|
@@ -10,6 +10,32 @@ var errors = require('../errors')
|
|
|
10
10
|
var $ = require('../util/preconditions')
|
|
11
11
|
var deprecate = require('../util/deprecate')
|
|
12
12
|
|
|
13
|
+
/**
|
|
14
|
+
* Shallow-copy an array so the caller's array and ours are not the same object.
|
|
15
|
+
*
|
|
16
|
+
* The constructor used to store `arg.hashes` and `arg.flags` directly, and
|
|
17
|
+
* `toObject()` used to hand the same arrays back out. Both directions aliased, so a
|
|
18
|
+
* MerkleBlock and the object it was built from — or the object it produced — shared
|
|
19
|
+
* mutable state. Mutating either changed the other at a distance:
|
|
20
|
+
*
|
|
21
|
+
* var mb = new MerkleBlock(obj)
|
|
22
|
+
* mb.hashes.push(x) // obj.hashes grew too
|
|
23
|
+
* var out = mb.toObject()
|
|
24
|
+
* out.flags.pop() // mb.flags shrank too
|
|
25
|
+
*
|
|
26
|
+
* This surfaced as order-dependence in this library's own suite: tests that mutate a
|
|
27
|
+
* block built from a shared fixture corrupted that fixture for every test after them,
|
|
28
|
+
* so a new test passed alone and failed in the full run. The tests were the messenger;
|
|
29
|
+
* the aliasing is the defect, and a caller hits it the same way.
|
|
30
|
+
*
|
|
31
|
+
* Non-arrays are passed through untouched rather than coerced. The constructor never
|
|
32
|
+
* validated these fields, and turning a previously-tolerated input into a throw would
|
|
33
|
+
* be a breaking change — which 9.x is committed against. See STABILITY.md.
|
|
34
|
+
*/
|
|
35
|
+
function copyArray (value) {
|
|
36
|
+
return Array.isArray(value) ? value.slice() : value
|
|
37
|
+
}
|
|
38
|
+
|
|
13
39
|
/**
|
|
14
40
|
* Instantiate a MerkleBlock from a Buffer, JSON object, or Object with
|
|
15
41
|
* the properties of the Block
|
|
@@ -48,12 +74,12 @@ function MerkleBlock (arg) {
|
|
|
48
74
|
* @name MerkleBlock#hashes
|
|
49
75
|
* @type {String[]}
|
|
50
76
|
*/
|
|
51
|
-
hashes: arg.hashes,
|
|
77
|
+
hashes: copyArray(arg.hashes),
|
|
52
78
|
/**
|
|
53
79
|
* @name MerkleBlock#flags
|
|
54
80
|
* @type {Number[]}
|
|
55
81
|
*/
|
|
56
|
-
flags: arg.flags
|
|
82
|
+
flags: copyArray(arg.flags)
|
|
57
83
|
}
|
|
58
84
|
} else {
|
|
59
85
|
throw new TypeError('Unrecognized argument for MerkleBlock')
|
|
@@ -116,8 +142,12 @@ MerkleBlock.prototype.toObject = MerkleBlock.prototype.toJSON = function toObjec
|
|
|
116
142
|
return {
|
|
117
143
|
header: this.header.toObject(),
|
|
118
144
|
numTransactions: this.numTransactions,
|
|
119
|
-
|
|
120
|
-
|
|
145
|
+
// Copies, not the live arrays. Handing out the internals meant a caller who
|
|
146
|
+
// mutated the result of toObject() silently changed the MerkleBlock it came
|
|
147
|
+
// from — and `toObject` reads as a serializer, which is exactly the API you
|
|
148
|
+
// expect to be able to modify freely.
|
|
149
|
+
hashes: copyArray(this.hashes),
|
|
150
|
+
flags: copyArray(this.flags)
|
|
121
151
|
}
|
|
122
152
|
}
|
|
123
153
|
|
package/lib/ltp/claim.js
CHANGED
|
@@ -3,6 +3,8 @@
|
|
|
3
3
|
var Hash = require('../crypto/hash')
|
|
4
4
|
var $ = require('../util/preconditions')
|
|
5
5
|
var Id = require('../util/id')
|
|
6
|
+
var JCS = require('../util/jcs')
|
|
7
|
+
var deprecate = require('../util/deprecate')
|
|
6
8
|
|
|
7
9
|
/**
|
|
8
10
|
* Legal Token Protocol - Claim Preparation Primitives
|
|
@@ -282,8 +284,14 @@ var ClaimValidator = {
|
|
|
282
284
|
errors: errors,
|
|
283
285
|
warnings: warnings,
|
|
284
286
|
schema: schemaName,
|
|
285
|
-
|
|
286
|
-
|
|
287
|
+
// Both pinned to LEGACY, not inheriting the deprecated default: these are
|
|
288
|
+
// stored as identifiers by callers who cannot pass an argument here, and a
|
|
289
|
+
// warning naming a function they did not call is noise. 10.0.0 moves them to
|
|
290
|
+
// JCS as one documented change rather than a silent one.
|
|
291
|
+
claimHash: Hash.sha256(Buffer.from(
|
|
292
|
+
this._canonicalizeWith(claim, this.CANONICALIZATION.LEGACY)
|
|
293
|
+
)).toString('hex'),
|
|
294
|
+
canonical: this._canonicalizeWith(claim, this.CANONICALIZATION.LEGACY)
|
|
287
295
|
}
|
|
288
296
|
|
|
289
297
|
return {
|
|
@@ -360,7 +368,10 @@ var ClaimValidator = {
|
|
|
360
368
|
}
|
|
361
369
|
|
|
362
370
|
// Create attestation hash
|
|
363
|
-
|
|
371
|
+
// Pinned to LEGACY — see the note on validateClaim's canonical field.
|
|
372
|
+
var attestationHash = Hash.sha256(Buffer.from(
|
|
373
|
+
this._canonicalizeWith(attestation, this.CANONICALIZATION.LEGACY)
|
|
374
|
+
)).toString('hex')
|
|
364
375
|
attestation.attestationHash = attestationHash
|
|
365
376
|
|
|
366
377
|
return {
|
|
@@ -426,7 +437,10 @@ var ClaimValidator = {
|
|
|
426
437
|
}
|
|
427
438
|
|
|
428
439
|
// Create dispute hash
|
|
429
|
-
|
|
440
|
+
// Pinned to LEGACY — see the note on validateClaim's canonical field.
|
|
441
|
+
var disputeHash = Hash.sha256(Buffer.from(
|
|
442
|
+
this._canonicalizeWith(disputeRecord, this.CANONICALIZATION.LEGACY)
|
|
443
|
+
)).toString('hex')
|
|
430
444
|
disputeRecord.disputeHash = disputeHash
|
|
431
445
|
|
|
432
446
|
return {
|
|
@@ -541,29 +555,106 @@ var ClaimValidator = {
|
|
|
541
555
|
}
|
|
542
556
|
},
|
|
543
557
|
|
|
558
|
+
/**
|
|
559
|
+
* Canonicalization forms understood when hashing a claim.
|
|
560
|
+
*
|
|
561
|
+
* JCS is RFC 8785 and is what a claim hash should be computed with: two independent
|
|
562
|
+
* implementations produce identical bytes, which is the only property that makes a
|
|
563
|
+
* hash meaningful to anyone but us.
|
|
564
|
+
*
|
|
565
|
+
* LEGACY is the sorted-key form this module has always used. It sorts keys and then
|
|
566
|
+
* REBUILDS an object, which loses the sort — V8 orders integer-like own properties
|
|
567
|
+
* numerically ahead of string keys whatever order they were inserted in:
|
|
568
|
+
*
|
|
569
|
+
* LEGACY {"2":"two","10":"ten"}
|
|
570
|
+
* JCS {"10":"ten","2":"two"} (RFC 8785, UTF-16 code unit order)
|
|
571
|
+
*
|
|
572
|
+
* Deterministic, so nothing already hashed is wrong or forgeable. Not interoperable,
|
|
573
|
+
* so an RFC 8785 verifier in any other language computes a different claim hash.
|
|
574
|
+
*/
|
|
575
|
+
CANONICALIZATION: {
|
|
576
|
+
JCS: 'jcs',
|
|
577
|
+
LEGACY: 'legacy'
|
|
578
|
+
},
|
|
579
|
+
|
|
544
580
|
/**
|
|
545
581
|
* Canonicalize claim for hashing
|
|
582
|
+
*
|
|
546
583
|
* @param {Object} claim - Claim to canonicalize
|
|
584
|
+
* @param {String} [canonicalization] - CANONICALIZATION.JCS or .LEGACY. Omitting it
|
|
585
|
+
* selects LEGACY and emits a deprecation notice; the default becomes JCS in
|
|
586
|
+
* 10.0.0. Pass one explicitly to pin the behaviour across that change.
|
|
547
587
|
* @returns {String} Canonical JSON string
|
|
548
588
|
*/
|
|
549
|
-
canonicalize: function(claim) {
|
|
589
|
+
canonicalize: function(claim, canonicalization) {
|
|
590
|
+
return this._canonicalizeWith(
|
|
591
|
+
claim,
|
|
592
|
+
this._resolveCanonicalization(canonicalization, 'LTP.Claim.canonicalize')
|
|
593
|
+
)
|
|
594
|
+
},
|
|
595
|
+
|
|
596
|
+
/**
|
|
597
|
+
* Hash claim
|
|
598
|
+
*
|
|
599
|
+
* @param {Object} claim - Claim to hash
|
|
600
|
+
* @param {String} [canonicalization] - see canonicalize()
|
|
601
|
+
* @returns {String} SHA256 hash
|
|
602
|
+
*/
|
|
603
|
+
hash: function(claim, canonicalization) {
|
|
604
|
+
var canonical = this._canonicalizeWith(
|
|
605
|
+
claim,
|
|
606
|
+
this._resolveCanonicalization(canonicalization, 'LTP.Claim.hash')
|
|
607
|
+
)
|
|
608
|
+
return Hash.sha256(Buffer.from(canonical)).toString('hex')
|
|
609
|
+
},
|
|
610
|
+
|
|
611
|
+
/**
|
|
612
|
+
* Canonicalize with the form already decided. No deprecation notice: the caller has
|
|
613
|
+
* chosen, either explicitly or on its behalf by _resolveCanonicalization.
|
|
614
|
+
*/
|
|
615
|
+
_canonicalizeWith: function(claim, canonicalization) {
|
|
550
616
|
$.checkArgument(claim && typeof claim === 'object', 'Invalid claim')
|
|
551
|
-
|
|
617
|
+
|
|
618
|
+
if (canonicalization === this.CANONICALIZATION.JCS) {
|
|
619
|
+
return JCS.stringify(claim)
|
|
620
|
+
}
|
|
621
|
+
|
|
552
622
|
// Sort keys recursively
|
|
553
623
|
var canonical = this._sortObjectKeys(claim)
|
|
554
|
-
|
|
624
|
+
|
|
555
625
|
// Return deterministic JSON
|
|
556
626
|
return JSON.stringify(canonical)
|
|
557
627
|
},
|
|
558
|
-
|
|
628
|
+
|
|
559
629
|
/**
|
|
560
|
-
*
|
|
561
|
-
*
|
|
562
|
-
*
|
|
630
|
+
* Resolve an optional canonicalization argument to a concrete form.
|
|
631
|
+
*
|
|
632
|
+
* An unrecognised value throws rather than falling back. A silent fallback would
|
|
633
|
+
* turn a typo such as `'JCS'` into a differently-hashed claim that still looks
|
|
634
|
+
* successful, which is the failure mode this whole change exists to remove.
|
|
563
635
|
*/
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
636
|
+
_resolveCanonicalization: function(canonicalization, caller) {
|
|
637
|
+
if (canonicalization === undefined) {
|
|
638
|
+
// Per STABILITY.md: mark it in a minor, flip it in a major. 9.x does not break
|
|
639
|
+
// callers, so the default stays LEGACY and the notice carries the migration.
|
|
640
|
+
deprecate({
|
|
641
|
+
what: caller + '() without a canonicalization argument',
|
|
642
|
+
since: '9.2.0',
|
|
643
|
+
removeIn: '10.0.0',
|
|
644
|
+
use: caller + '(claim, bsv.LTP.Claim.CANONICALIZATION.JCS)',
|
|
645
|
+
why: 'the default sorted-key form is not RFC 8785, so other implementations compute a different claim hash'
|
|
646
|
+
})
|
|
647
|
+
return this.CANONICALIZATION.LEGACY
|
|
648
|
+
}
|
|
649
|
+
|
|
650
|
+
$.checkArgument(
|
|
651
|
+
canonicalization === this.CANONICALIZATION.JCS ||
|
|
652
|
+
canonicalization === this.CANONICALIZATION.LEGACY,
|
|
653
|
+
'Unknown canonicalization: ' + canonicalization +
|
|
654
|
+
". Expected 'jcs' or 'legacy' (bsv.LTP.Claim.CANONICALIZATION)"
|
|
655
|
+
)
|
|
656
|
+
|
|
657
|
+
return canonicalization
|
|
567
658
|
},
|
|
568
659
|
|
|
569
660
|
/**
|
package/lib/util/jcs.js
CHANGED
|
@@ -35,6 +35,21 @@ var JCS = {}
|
|
|
35
35
|
* @returns {String}
|
|
36
36
|
*/
|
|
37
37
|
JCS.stringify = function (value) {
|
|
38
|
+
return serialize(value, [])
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* `stack` carries the containers currently being serialized, so a cycle throws a
|
|
43
|
+
* typed error instead of recursing until the call stack is exhausted. That matters
|
|
44
|
+
* now the function is public API reachable from a verifier: verification input is by
|
|
45
|
+
* definition untrusted, and a RangeError raised at an arbitrary depth is a worse
|
|
46
|
+
* failure than a deliberate one. A linear scan beats a Set here because these
|
|
47
|
+
* structures are shallow and the array avoids the allocation entirely for the common
|
|
48
|
+
* acyclic case.
|
|
49
|
+
*
|
|
50
|
+
* No acyclic input changes behaviour, so nothing already signed is affected.
|
|
51
|
+
*/
|
|
52
|
+
function serialize (value, stack) {
|
|
38
53
|
if (value === null) return 'null'
|
|
39
54
|
|
|
40
55
|
var type = typeof value
|
|
@@ -50,23 +65,38 @@ JCS.stringify = function (value) {
|
|
|
50
65
|
|
|
51
66
|
if (type === 'string') return JSON.stringify(value)
|
|
52
67
|
|
|
53
|
-
if (
|
|
54
|
-
//
|
|
55
|
-
//
|
|
56
|
-
|
|
57
|
-
return item === undefined ? 'null' : JCS.stringify(item)
|
|
58
|
-
}).join(',') + ']'
|
|
68
|
+
if (type === 'bigint') {
|
|
69
|
+
// JSON has no bigint form and coercing one would silently canonicalize a
|
|
70
|
+
// different document than the caller supplied. Carry it as a string.
|
|
71
|
+
throw new Error('Cannot canonicalize bigint; represent it as a string')
|
|
59
72
|
}
|
|
60
73
|
|
|
61
|
-
if (type === 'object') {
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
74
|
+
if (Array.isArray(value) || type === 'object') {
|
|
75
|
+
if (stack.indexOf(value) !== -1) {
|
|
76
|
+
throw new Error('Cannot canonicalize a circular structure')
|
|
77
|
+
}
|
|
78
|
+
stack.push(value)
|
|
79
|
+
|
|
80
|
+
var out
|
|
81
|
+
if (Array.isArray(value)) {
|
|
82
|
+
// Arrays are order-significant. `undefined` has no JSON form and becomes null in an
|
|
83
|
+
// array, matching JSON.stringify.
|
|
84
|
+
out = '[' + value.map(function (item) {
|
|
85
|
+
return item === undefined ? 'null' : serialize(item, stack)
|
|
86
|
+
}).join(',') + ']'
|
|
87
|
+
} else {
|
|
88
|
+
// Absent and explicitly-undefined are indistinguishable in JSON, so both are dropped.
|
|
89
|
+
var keys = Object.keys(value).filter(function (key) {
|
|
90
|
+
return value[key] !== undefined && typeof value[key] !== 'function'
|
|
91
|
+
}).sort()
|
|
92
|
+
|
|
93
|
+
out = '{' + keys.map(function (key) {
|
|
94
|
+
return JSON.stringify(key) + ':' + serialize(value[key], stack)
|
|
95
|
+
}).join(',') + '}'
|
|
96
|
+
}
|
|
66
97
|
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
}).join(',') + '}'
|
|
98
|
+
stack.pop()
|
|
99
|
+
return out
|
|
70
100
|
}
|
|
71
101
|
|
|
72
102
|
throw new Error('Cannot canonicalize value of type: ' + type)
|