@smartledger/bsv 7.5.0 → 7.5.1
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 +72 -0
- package/README.md +38 -38
- package/bsv-gdaf.min.js +33 -33
- package/bsv-ltp.min.js +33 -33
- package/bsv-smartcontract.min.js +1 -1
- package/bsv.bundle.js +33 -33
- package/bsv.d.ts +45 -11
- package/bsv.min.js +33 -33
- 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/index.js +29 -6
- package/lib/gdaf/smartledger-anchor.js +31 -1
- package/lib/privatekey.js +59 -10
- package/package.json +1 -1
- package/test/gdaf/anchor_no_key_leak.js +88 -0
- package/test/privatekey.js +79 -2
- 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@7.5.
|
|
58
|
+
- **CDN**: `unpkg.com/@smartledger/bsv@7.5.1/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@7.5.
|
|
64
|
+
- **CDN**: `unpkg.com/@smartledger/bsv@7.5.1/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@7.5.
|
|
70
|
+
- **CDN**: `unpkg.com/@smartledger/bsv@7.5.1/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@7.5.
|
|
85
|
-
| **bsv.bundle.js** | 937KB | Everything in one file | `unpkg.com/@smartledger/bsv@7.5.
|
|
86
|
-
| **bsv-smartcontract.min.js** | 937KB | Covenant development | `unpkg.com/@smartledger/bsv@7.5.
|
|
87
|
-
| **bsv-covenant.min.js** | 913KB | Covenant operations | `unpkg.com/@smartledger/bsv@7.5.
|
|
88
|
-
| **bsv-script-helper.min.js** | 26KB | Custom script tools | `unpkg.com/@smartledger/bsv@7.5.
|
|
89
|
-
| **bsv-security.min.js** | 26KB | Security enhancements (opt-in helpers — see README › Security) | `unpkg.com/@smartledger/bsv@7.5.
|
|
90
|
-
| **bsv-ecies.min.js** | 71KB | Encryption | `unpkg.com/@smartledger/bsv@7.5.
|
|
91
|
-
| **bsv-message.min.js** | 26KB | Message signing | `unpkg.com/@smartledger/bsv@7.5.
|
|
92
|
-
| **bsv-mnemonic.min.js** | 681KB | HD wallets | `unpkg.com/@smartledger/bsv@7.5.
|
|
93
|
-
| **🆕 bsv-shamir.min.js** | 432KB | **Secret sharing** | `unpkg.com/@smartledger/bsv@7.5.
|
|
94
|
-
| **🆕 bsv-gdaf.min.js** | 1184KB | **Digital attestation** | `unpkg.com/@smartledger/bsv@7.5.
|
|
95
|
-
| **🆕 bsv-ltp.min.js** | 1184KB | **Legal tokens** | `unpkg.com/@smartledger/bsv@7.5.
|
|
84
|
+
| **bsv.min.js** | 937KB | Core BSV + SmartContract | `unpkg.com/@smartledger/bsv@7.5.1/bsv.min.js` |
|
|
85
|
+
| **bsv.bundle.js** | 937KB | Everything in one file | `unpkg.com/@smartledger/bsv@7.5.1/bsv.bundle.js` |
|
|
86
|
+
| **bsv-smartcontract.min.js** | 937KB | Covenant development | `unpkg.com/@smartledger/bsv@7.5.1/bsv-smartcontract.min.js` |
|
|
87
|
+
| **bsv-covenant.min.js** | 913KB | Covenant operations | `unpkg.com/@smartledger/bsv@7.5.1/bsv-covenant.min.js` |
|
|
88
|
+
| **bsv-script-helper.min.js** | 26KB | Custom script tools | `unpkg.com/@smartledger/bsv@7.5.1/bsv-script-helper.min.js` |
|
|
89
|
+
| **bsv-security.min.js** | 26KB | Security enhancements (opt-in helpers — see README › Security) | `unpkg.com/@smartledger/bsv@7.5.1/bsv-security.min.js` |
|
|
90
|
+
| **bsv-ecies.min.js** | 71KB | Encryption | `unpkg.com/@smartledger/bsv@7.5.1/bsv-ecies.min.js` |
|
|
91
|
+
| **bsv-message.min.js** | 26KB | Message signing | `unpkg.com/@smartledger/bsv@7.5.1/bsv-message.min.js` |
|
|
92
|
+
| **bsv-mnemonic.min.js** | 681KB | HD wallets | `unpkg.com/@smartledger/bsv@7.5.1/bsv-mnemonic.min.js` |
|
|
93
|
+
| **🆕 bsv-shamir.min.js** | 432KB | **Secret sharing** | `unpkg.com/@smartledger/bsv@7.5.1/bsv-shamir.min.js` |
|
|
94
|
+
| **🆕 bsv-gdaf.min.js** | 1184KB | **Digital attestation** | `unpkg.com/@smartledger/bsv@7.5.1/bsv-gdaf.min.js` |
|
|
95
|
+
| **🆕 bsv-ltp.min.js** | 1184KB | **Legal tokens** | `unpkg.com/@smartledger/bsv@7.5.1/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@7.5.
|
|
104
|
-
<script src="https://unpkg.com/@smartledger/bsv@7.5.
|
|
103
|
+
<script src="https://unpkg.com/@smartledger/bsv@7.5.1/bsv.min.js"></script>
|
|
104
|
+
<script src="https://unpkg.com/@smartledger/bsv@7.5.1/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@7.5.
|
|
110
|
-
<script src="https://unpkg.com/@smartledger/bsv@7.5.
|
|
111
|
-
<script src="https://unpkg.com/@smartledger/bsv@7.5.
|
|
109
|
+
<script src="https://unpkg.com/@smartledger/bsv@7.5.1/bsv.min.js"></script>
|
|
110
|
+
<script src="https://unpkg.com/@smartledger/bsv@7.5.1/bsv-covenant.min.js"></script>
|
|
111
|
+
<script src="https://unpkg.com/@smartledger/bsv@7.5.1/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@7.5.
|
|
117
|
-
<script src="https://unpkg.com/@smartledger/bsv@7.5.
|
|
118
|
-
<script src="https://unpkg.com/@smartledger/bsv@7.5.
|
|
116
|
+
<script src="https://unpkg.com/@smartledger/bsv@7.5.1/bsv.min.js"></script>
|
|
117
|
+
<script src="https://unpkg.com/@smartledger/bsv@7.5.1/bsv-ltp.min.js"></script>
|
|
118
|
+
<script src="https://unpkg.com/@smartledger/bsv@7.5.1/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@7.5.
|
|
136
|
-
<script src="https://unpkg.com/@smartledger/bsv@7.5.
|
|
137
|
-
<script src="https://unpkg.com/@smartledger/bsv@7.5.
|
|
135
|
+
<script src="https://unpkg.com/@smartledger/bsv@7.5.1/bsv.min.js"></script>
|
|
136
|
+
<script src="https://unpkg.com/@smartledger/bsv@7.5.1/bsv-security.min.js"></script>
|
|
137
|
+
<script src="https://unpkg.com/@smartledger/bsv@7.5.1/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@7.5.
|
|
149
|
+
<script src="https://unpkg.com/@smartledger/bsv@7.5.1/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@7.5.
|
|
725
|
+
<script src="https://cdn.jsdelivr.net/npm/@smartledger/bsv@7.5.1/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@7.5.
|
|
51
|
+
<script src="https://unpkg.com/@smartledger/bsv@7.5.1/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@7.5.
|
|
61
|
+
<script src="https://unpkg.com/@smartledger/bsv@7.5.1/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@7.5.
|
|
75
|
-
<script src="https://unpkg.com/@smartledger/bsv@7.5.
|
|
76
|
-
<script src="https://unpkg.com/@smartledger/bsv@7.5.
|
|
74
|
+
<script src="https://unpkg.com/@smartledger/bsv@7.5.1/bsv.min.js"></script>
|
|
75
|
+
<script src="https://unpkg.com/@smartledger/bsv@7.5.1/bsv-covenant.min.js"></script>
|
|
76
|
+
<script src="https://unpkg.com/@smartledger/bsv@7.5.1/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@7.5.
|
|
86
|
-
<script src="https://unpkg.com/@smartledger/bsv@7.5.
|
|
87
|
-
<script src="https://unpkg.com/@smartledger/bsv@7.5.
|
|
85
|
+
<script src="https://unpkg.com/@smartledger/bsv@7.5.1/bsv.min.js"></script>
|
|
86
|
+
<script src="https://unpkg.com/@smartledger/bsv@7.5.1/bsv-ltp.min.js"></script>
|
|
87
|
+
<script src="https://unpkg.com/@smartledger/bsv@7.5.1/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@7.5.
|
|
102
|
-
<script src="https://unpkg.com/@smartledger/bsv@7.5.
|
|
103
|
-
<script src="https://unpkg.com/@smartledger/bsv@7.5.
|
|
101
|
+
<script src="https://unpkg.com/@smartledger/bsv@7.5.1/bsv.min.js"></script>
|
|
102
|
+
<script src="https://unpkg.com/@smartledger/bsv@7.5.1/bsv-security.min.js"></script>
|
|
103
|
+
<script src="https://unpkg.com/@smartledger/bsv@7.5.1/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@7.5.
|
|
118
|
-
| **bsv.bundle.js** | 937KB | Everything in one file | `unpkg.com/@smartledger/bsv@7.5.
|
|
119
|
-
| **bsv-smartcontract.min.js** | 937KB | Complete covenant framework | `unpkg.com/@smartledger/bsv@7.5.
|
|
120
|
-
| **bsv-ltp.min.js** | 1184KB | **Legal Token Protocol** | `unpkg.com/@smartledger/bsv@7.5.
|
|
121
|
-
| **bsv-gdaf.min.js** | 1184KB | **Digital Identity & Attestation** | `unpkg.com/@smartledger/bsv@7.5.
|
|
122
|
-
| **bsv-shamir.min.js** | 432KB | **Threshold Cryptography** | `unpkg.com/@smartledger/bsv@7.5.
|
|
123
|
-
| **bsv-security.min.js** | 26KB | Security enhancements (opt-in helpers — see README › Security) | `unpkg.com/@smartledger/bsv@7.5.
|
|
124
|
-
| **bsv-mnemonic.min.js** | 681KB | HD wallets | `unpkg.com/@smartledger/bsv@7.5.
|
|
125
|
-
| **bsv-ecies.min.js** | 71KB | Encryption | `unpkg.com/@smartledger/bsv@7.5.
|
|
126
|
-
| **bsv-covenant.min.js** | 913KB | Covenant operations | `unpkg.com/@smartledger/bsv@7.5.
|
|
127
|
-
| **bsv-script-helper.min.js** | 26KB | Custom script tools | `unpkg.com/@smartledger/bsv@7.5.
|
|
128
|
-
| **bsv-message.min.js** | 26KB | Message signing | `unpkg.com/@smartledger/bsv@7.5.
|
|
117
|
+
| **bsv.min.js** | 937KB | Core BSV + SmartContract | `unpkg.com/@smartledger/bsv@7.5.1/bsv.min.js` |
|
|
118
|
+
| **bsv.bundle.js** | 937KB | Everything in one file | `unpkg.com/@smartledger/bsv@7.5.1/bsv.bundle.js` |
|
|
119
|
+
| **bsv-smartcontract.min.js** | 937KB | Complete covenant framework | `unpkg.com/@smartledger/bsv@7.5.1/bsv-smartcontract.min.js` |
|
|
120
|
+
| **bsv-ltp.min.js** | 1184KB | **Legal Token Protocol** | `unpkg.com/@smartledger/bsv@7.5.1/bsv-ltp.min.js` |
|
|
121
|
+
| **bsv-gdaf.min.js** | 1184KB | **Digital Identity & Attestation** | `unpkg.com/@smartledger/bsv@7.5.1/bsv-gdaf.min.js` |
|
|
122
|
+
| **bsv-shamir.min.js** | 432KB | **Threshold Cryptography** | `unpkg.com/@smartledger/bsv@7.5.1/bsv-shamir.min.js` |
|
|
123
|
+
| **bsv-security.min.js** | 26KB | Security enhancements (opt-in helpers — see README › Security) | `unpkg.com/@smartledger/bsv@7.5.1/bsv-security.min.js` |
|
|
124
|
+
| **bsv-mnemonic.min.js** | 681KB | HD wallets | `unpkg.com/@smartledger/bsv@7.5.1/bsv-mnemonic.min.js` |
|
|
125
|
+
| **bsv-ecies.min.js** | 71KB | Encryption | `unpkg.com/@smartledger/bsv@7.5.1/bsv-ecies.min.js` |
|
|
126
|
+
| **bsv-covenant.min.js** | 913KB | Covenant operations | `unpkg.com/@smartledger/bsv@7.5.1/bsv-covenant.min.js` |
|
|
127
|
+
| **bsv-script-helper.min.js** | 26KB | Custom script tools | `unpkg.com/@smartledger/bsv@7.5.1/bsv-script-helper.min.js` |
|
|
128
|
+
| **bsv-message.min.js** | 26KB | Message signing | `unpkg.com/@smartledger/bsv@7.5.1/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@7.5.
|
|
17
|
+
<script src="https://unpkg.com/@smartledger/bsv@7.5.1/bsv.min.js"></script>
|
|
18
18
|
|
|
19
19
|
<!-- Everything included (937KB) -->
|
|
20
|
-
<script src="https://unpkg.com/@smartledger/bsv@7.5.
|
|
20
|
+
<script src="https://unpkg.com/@smartledger/bsv@7.5.1/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@7.5.
|
|
130
|
+
<script src="https://unpkg.com/@smartledger/bsv@7.5.1/bsv.min.js"></script>
|
|
131
131
|
|
|
132
132
|
<!-- Smart contracts (937KB) -->
|
|
133
|
-
<script src="https://unpkg.com/@smartledger/bsv@7.5.
|
|
133
|
+
<script src="https://unpkg.com/@smartledger/bsv@7.5.1/bsv-smartcontract.min.js"></script>
|
|
134
134
|
|
|
135
135
|
<!-- Legal tokens (1.16MB) -->
|
|
136
|
-
<script src="https://unpkg.com/@smartledger/bsv@7.5.
|
|
136
|
+
<script src="https://unpkg.com/@smartledger/bsv@7.5.1/bsv-ltp.min.js"></script>
|
|
137
137
|
|
|
138
138
|
<!-- Digital identity (1.16MB) -->
|
|
139
|
-
<script src="https://unpkg.com/@smartledger/bsv@7.5.
|
|
139
|
+
<script src="https://unpkg.com/@smartledger/bsv@7.5.1/bsv-gdaf.min.js"></script>
|
|
140
140
|
|
|
141
141
|
<!-- Everything (937KB) -->
|
|
142
|
-
<script src="https://unpkg.com/@smartledger/bsv@7.5.
|
|
142
|
+
<script src="https://unpkg.com/@smartledger/bsv@7.5.1/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@7.5.
|
|
162
|
+
<script src="https://unpkg.com/@smartledger/bsv@7.5.1/bsv.min.js"></script>
|
|
163
163
|
|
|
164
164
|
<!-- Add smart contracts when ready -->
|
|
165
|
-
<script src="https://unpkg.com/@smartledger/bsv@7.5.
|
|
165
|
+
<script src="https://unpkg.com/@smartledger/bsv@7.5.1/bsv-smartcontract.min.js"></script>
|
|
166
166
|
|
|
167
167
|
<!-- Add advanced features as needed -->
|
|
168
|
-
<script src="https://unpkg.com/@smartledger/bsv@7.5.
|
|
169
|
-
<script src="https://unpkg.com/@smartledger/bsv@7.5.
|
|
168
|
+
<script src="https://unpkg.com/@smartledger/bsv@7.5.1/bsv-ltp.min.js"></script>
|
|
169
|
+
<script src="https://unpkg.com/@smartledger/bsv@7.5.1/bsv-gdaf.min.js"></script>
|
|
170
170
|
|
|
171
171
|
<!-- Everything in one file -->
|
|
172
|
-
<script src="https://unpkg.com/@smartledger/bsv@7.5.
|
|
172
|
+
<script src="https://unpkg.com/@smartledger/bsv@7.5.1/bsv.bundle.js"></script>
|
|
173
173
|
```
|
|
174
174
|
|
|
175
175
|
## 🔍 **Testing Your Migration**
|
package/lib/gdaf/index.js
CHANGED
|
@@ -294,6 +294,24 @@ GDAF.prototype.verifyMembershipProof = function(proof, validSet) {
|
|
|
294
294
|
* Blockchain Anchoring Methods
|
|
295
295
|
*/
|
|
296
296
|
|
|
297
|
+
/**
|
|
298
|
+
* Normalise the `options` argument of the anchoring wrappers to `{ metadata, utxos }`.
|
|
299
|
+
*
|
|
300
|
+
* These wrappers take (payload, privateKey, options) while the underlying anchor methods
|
|
301
|
+
* take (payload, metadata, utxos) — so every one of them forwarded `privateKey` into a
|
|
302
|
+
* slot that is not a key. For registerDID/revokeCredential that landed in `utxos` and died
|
|
303
|
+
* on `utxos.reduce`; for anchorCredential/anchorBatch it landed in `metadata`, which is
|
|
304
|
+
* JSON.stringify-ed straight into the OP_RETURN, publishing the secret scalar on chain.
|
|
305
|
+
*
|
|
306
|
+
* A bare array is still accepted as the UTXO list, because that was the only shape that
|
|
307
|
+
* previously produced a transaction at all.
|
|
308
|
+
*/
|
|
309
|
+
function _anchorOpts (options) {
|
|
310
|
+
if (Array.isArray(options)) return { metadata: undefined, utxos: options }
|
|
311
|
+
options = options || {}
|
|
312
|
+
return { metadata: options.metadata, utxos: options.utxos }
|
|
313
|
+
}
|
|
314
|
+
|
|
297
315
|
/**
|
|
298
316
|
* Anchor credential to blockchain
|
|
299
317
|
* @param {Object} credential - Credential to anchor
|
|
@@ -301,9 +319,13 @@ GDAF.prototype.verifyMembershipProof = function(proof, validSet) {
|
|
|
301
319
|
* @param {Object} options - Anchoring options
|
|
302
320
|
* @returns {Object} Anchor result
|
|
303
321
|
*/
|
|
304
|
-
GDAF.prototype.anchorCredential = function(
|
|
322
|
+
GDAF.prototype.anchorCredential = function(credentialHash, privateKey, options) {
|
|
305
323
|
var anchor = new SmartLedgerAnchor(privateKey, this._anchorOptions)
|
|
306
|
-
|
|
324
|
+
var opts = _anchorOpts(options)
|
|
325
|
+
// `privateKey` is NOT forwarded: the anchor already holds it, and its second parameter
|
|
326
|
+
// is `metadata`, which is JSON-serialised into the OP_RETURN. Passing the key here
|
|
327
|
+
// published it on chain. See the note above _anchorOpts.
|
|
328
|
+
return anchor.anchorCredential(credentialHash, opts.metadata, opts.utxos)
|
|
307
329
|
}
|
|
308
330
|
|
|
309
331
|
/**
|
|
@@ -313,9 +335,10 @@ GDAF.prototype.anchorCredential = function(credential, privateKey, options) {
|
|
|
313
335
|
* @param {Object} options - Anchoring options
|
|
314
336
|
* @returns {Object} Batch anchor result
|
|
315
337
|
*/
|
|
316
|
-
GDAF.prototype.anchorBatch = function(
|
|
338
|
+
GDAF.prototype.anchorBatch = function(credentialHashes, privateKey, options) {
|
|
317
339
|
var anchor = new SmartLedgerAnchor(privateKey, this._anchorOptions)
|
|
318
|
-
|
|
340
|
+
var opts = _anchorOpts(options)
|
|
341
|
+
return anchor.anchorBatch(credentialHashes, opts.metadata, opts.utxos)
|
|
319
342
|
}
|
|
320
343
|
|
|
321
344
|
/**
|
|
@@ -328,7 +351,7 @@ GDAF.prototype.anchorBatch = function(credentials, privateKey, options) {
|
|
|
328
351
|
*/
|
|
329
352
|
GDAF.prototype.registerDID = function(did, didDocument, privateKey, options) {
|
|
330
353
|
var anchor = new SmartLedgerAnchor(privateKey, this._anchorOptions)
|
|
331
|
-
return anchor.registerDID(did, didDocument,
|
|
354
|
+
return anchor.registerDID(did, didDocument, _anchorOpts(options).utxos)
|
|
332
355
|
}
|
|
333
356
|
|
|
334
357
|
/**
|
|
@@ -341,7 +364,7 @@ GDAF.prototype.registerDID = function(did, didDocument, privateKey, options) {
|
|
|
341
364
|
*/
|
|
342
365
|
GDAF.prototype.revokeCredential = function(credentialId, reason, privateKey, options) {
|
|
343
366
|
var anchor = new SmartLedgerAnchor(privateKey, this._anchorOptions)
|
|
344
|
-
return anchor.revokeCredential(credentialId, reason,
|
|
367
|
+
return anchor.revokeCredential(credentialId, reason, _anchorOpts(options).utxos)
|
|
345
368
|
}
|
|
346
369
|
|
|
347
370
|
/**
|
|
@@ -226,9 +226,39 @@ SmartLedgerAnchor.prototype.revokeCredential = async function(credentialId, reas
|
|
|
226
226
|
* Create anchor payload
|
|
227
227
|
* @private
|
|
228
228
|
*/
|
|
229
|
+
/**
|
|
230
|
+
* Refuse to serialise anything that looks like key material.
|
|
231
|
+
*
|
|
232
|
+
* Defence in depth for the argument-order defect that put a private key in the `metadata`
|
|
233
|
+
* slot: even if a caller reaches this with a key, the anchor fails loudly instead of
|
|
234
|
+
* broadcasting the secret. Checks the shape rather than the class, because a key that has
|
|
235
|
+
* already been through JSON is a plain object by then.
|
|
236
|
+
*/
|
|
237
|
+
function assertNoKeyMaterial (metadata) {
|
|
238
|
+
var SECRET_KEYS = ['bn', 'privateKey', 'privkey', 'wif', 'privateJwk', 'd', 'seed', 'xpriv', 'xprv']
|
|
239
|
+
function walk (value, path, depth) {
|
|
240
|
+
if (!value || typeof value !== 'object' || depth > 4) return
|
|
241
|
+
if (typeof value.toWIF === 'function' && value.bn) {
|
|
242
|
+
throw new Error('Refusing to anchor: ' + (path || 'metadata') + ' is a PrivateKey. ' +
|
|
243
|
+
'Anchor metadata is published in the OP_RETURN and must never contain key material.')
|
|
244
|
+
}
|
|
245
|
+
Object.keys(value).forEach(function (k) {
|
|
246
|
+
if (SECRET_KEYS.indexOf(k) !== -1 && value[k] != null && typeof value[k] !== 'object') {
|
|
247
|
+
throw new Error('Refusing to anchor: ' + (path ? path + '.' : '') + k +
|
|
248
|
+
' looks like key material, and anchor metadata is published in the OP_RETURN.')
|
|
249
|
+
}
|
|
250
|
+
walk(value[k], path ? path + '.' + k : k, depth + 1)
|
|
251
|
+
})
|
|
252
|
+
}
|
|
253
|
+
walk(metadata, '', 0)
|
|
254
|
+
}
|
|
255
|
+
|
|
229
256
|
SmartLedgerAnchor.prototype._createAnchorPayload = function(type, hash, metadata) {
|
|
230
257
|
var timestamp = Math.floor(Date.now() / 1000) // Unix timestamp
|
|
231
|
-
|
|
258
|
+
|
|
259
|
+
// This payload goes on chain, permanently and publicly.
|
|
260
|
+
assertNoKeyMaterial(metadata)
|
|
261
|
+
|
|
232
262
|
// Create structured payload
|
|
233
263
|
var payload = Buffer.concat([
|
|
234
264
|
Buffer.from(this.PROTOCOL_ID, 'utf8'), // Protocol identifier
|
package/lib/privatekey.js
CHANGED
|
@@ -156,11 +156,18 @@ PrivateKey._transformBuffer = function (buf, network) {
|
|
|
156
156
|
* @returns {object} an Object with keys: bn, network, and compressed
|
|
157
157
|
* @private
|
|
158
158
|
*/
|
|
159
|
-
PrivateKey._transformBNBuffer = function (buf, network) {
|
|
159
|
+
PrivateKey._transformBNBuffer = function (buf, network, compressed) {
|
|
160
160
|
var info = {}
|
|
161
161
|
info.network = Networks.get(network) || Networks.defaultNetwork
|
|
162
162
|
info.bn = BN.fromBuffer(buf)
|
|
163
|
-
|
|
163
|
+
// A raw 32-byte scalar carries no compression information, so this is a choice, not a
|
|
164
|
+
// reading. It used to be `false` while every other constructor path — random keys, hex
|
|
165
|
+
// strings, compressed WIF — produced `true`, so `PrivateKey.fromHex(h)` and
|
|
166
|
+
// `new PrivateKey(h)` returned different addresses and different WIFs for identical
|
|
167
|
+
// input. Restore a key by the wrong route and you derive an address you never funded.
|
|
168
|
+
// The default now matches the rest of the library; pass `false` explicitly for the
|
|
169
|
+
// legacy uncompressed form.
|
|
170
|
+
info.compressed = compressed === undefined ? true : !!compressed
|
|
164
171
|
return info
|
|
165
172
|
}
|
|
166
173
|
|
|
@@ -182,12 +189,21 @@ PrivateKey._transformWIF = function (str, network) {
|
|
|
182
189
|
* @param {Network} network
|
|
183
190
|
* @return {PrivateKey}
|
|
184
191
|
*/
|
|
185
|
-
PrivateKey.fromBuffer = function (buf, network) {
|
|
192
|
+
PrivateKey.fromBuffer = function (buf, network, compressed) {
|
|
193
|
+
if (compressed !== undefined && buf && buf.length === 32) {
|
|
194
|
+
return new PrivateKey(PrivateKey._transformBNBuffer(buf, network, compressed))
|
|
195
|
+
}
|
|
186
196
|
return new PrivateKey(buf, network)
|
|
187
197
|
}
|
|
188
198
|
|
|
189
|
-
|
|
190
|
-
|
|
199
|
+
/**
|
|
200
|
+
* @param {string} hex - 32-byte private key scalar, hex encoded
|
|
201
|
+
* @param {Network|string=} network
|
|
202
|
+
* @param {boolean=} compressed - defaults to true, matching every other constructor path
|
|
203
|
+
* @return {PrivateKey}
|
|
204
|
+
*/
|
|
205
|
+
PrivateKey.fromHex = function (hex, network, compressed) {
|
|
206
|
+
return PrivateKey.fromBuffer(Buffer.from(hex, 'hex'), network, compressed)
|
|
191
207
|
}
|
|
192
208
|
|
|
193
209
|
/**
|
|
@@ -209,14 +225,21 @@ PrivateKey._transformObject = function (json) {
|
|
|
209
225
|
}
|
|
210
226
|
|
|
211
227
|
/**
|
|
212
|
-
* Instantiate a PrivateKey from a WIF string
|
|
228
|
+
* Instantiate a PrivateKey from a WIF string, or from a hex-encoded scalar.
|
|
229
|
+
*
|
|
230
|
+
* The `network` argument used to be accepted and silently discarded, so
|
|
231
|
+
* `fromString(hex, 'testnet')` returned a livenet key and therefore a MAINNET address —
|
|
232
|
+
* funds sent there land on the wrong network. It is now honoured. For a WIF, which
|
|
233
|
+
* already encodes its own network, a conflicting `network` throws rather than being
|
|
234
|
+
* quietly overridden.
|
|
213
235
|
*
|
|
214
|
-
* @param {string} str -
|
|
236
|
+
* @param {string} str - WIF-encoded private key, or a hex-encoded scalar
|
|
237
|
+
* @param {Network|string=} network
|
|
215
238
|
* @returns {PrivateKey} A new valid instance of PrivateKey
|
|
216
239
|
*/
|
|
217
|
-
PrivateKey.fromString = PrivateKey.fromWIF = function (str) {
|
|
240
|
+
PrivateKey.fromString = PrivateKey.fromWIF = function (str, network) {
|
|
218
241
|
$.checkArgument(_.isString(str), 'First argument is expected to be a string.')
|
|
219
|
-
return new PrivateKey(str)
|
|
242
|
+
return new PrivateKey(str, network)
|
|
220
243
|
}
|
|
221
244
|
|
|
222
245
|
/**
|
|
@@ -350,9 +373,14 @@ PrivateKey.prototype.toAddress = function (network) {
|
|
|
350
373
|
}
|
|
351
374
|
|
|
352
375
|
/**
|
|
376
|
+
* A plain object representation, including the secret scalar.
|
|
377
|
+
*
|
|
378
|
+
* This is the deliberate, explicit export — the round-trip partner of
|
|
379
|
+
* `PrivateKey.fromObject()`. It is NOT what `JSON.stringify()` calls; see `toJSON`.
|
|
380
|
+
*
|
|
353
381
|
* @returns {Object} A plain object representation
|
|
354
382
|
*/
|
|
355
|
-
PrivateKey.prototype.toObject =
|
|
383
|
+
PrivateKey.prototype.toObject = function toObject () {
|
|
356
384
|
return {
|
|
357
385
|
bn: this.bn.toString('hex'),
|
|
358
386
|
compressed: this.compressed,
|
|
@@ -360,6 +388,27 @@ PrivateKey.prototype.toObject = PrivateKey.prototype.toJSON = function toObject
|
|
|
360
388
|
}
|
|
361
389
|
}
|
|
362
390
|
|
|
391
|
+
/**
|
|
392
|
+
* What `JSON.stringify()` calls — deliberately REDACTED.
|
|
393
|
+
*
|
|
394
|
+
* `toJSON` used to be the same function as `toObject`, so the secret scalar was emitted
|
|
395
|
+
* by anything that stringified a key, or an object holding one: a log line, an error
|
|
396
|
+
* dump, a request body. That is how a private key reached an OP_RETURN in the GDAF
|
|
397
|
+
* anchor path. Serialising a key is now something you have to ask for by name.
|
|
398
|
+
*
|
|
399
|
+
* Use `toObject()` (or `toWIF()`) when you genuinely intend to export the secret;
|
|
400
|
+
* `PrivateKey.fromObject(key.toObject())` still round-trips exactly.
|
|
401
|
+
*
|
|
402
|
+
* @returns {Object} A redacted representation, safe to log
|
|
403
|
+
*/
|
|
404
|
+
PrivateKey.prototype.toJSON = function toJSON () {
|
|
405
|
+
return {
|
|
406
|
+
bn: '[REDACTED]',
|
|
407
|
+
compressed: this.compressed,
|
|
408
|
+
network: this.network.toString()
|
|
409
|
+
}
|
|
410
|
+
}
|
|
411
|
+
|
|
363
412
|
/**
|
|
364
413
|
* Will return a string formatted for the console
|
|
365
414
|
*
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@smartledger/bsv",
|
|
3
|
-
"version": "7.5.
|
|
3
|
+
"version": "7.5.1",
|
|
4
4
|
"description": "🚀 Complete Bitcoin SV development framework with legally-recognizable DID:web + W3C VC-JWT toolkit, Legal Token Protocol (LTP), Global Digital Attestation Framework (GDAF), StatusList2021 revocation, and 16 flexible loading options. Standards-based credentials with ES256/ES256K support, on-chain BSV anchoring, and comprehensive Bitcoin SV API. Perfect for legal tokens, verifiable credentials, DeFi, smart contracts, and secure Bitcoin applications.",
|
|
5
5
|
"author": "SmartLedger Technology <hello@smartledger.technology> (https://smartledger.technology)",
|
|
6
6
|
"homepage": "https://github.com/codenlighten/smartledger-bsv#readme",
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
'use strict'
|
|
2
|
+
|
|
3
|
+
/* global describe, it */
|
|
4
|
+
|
|
5
|
+
// The GDAF anchoring wrappers take (payload, privateKey, options) while the underlying
|
|
6
|
+
// SmartLedgerAnchor methods take (payload, metadata, utxos). Every wrapper forwarded
|
|
7
|
+
// `privateKey` into a slot that is not a key. For anchorCredential/anchorBatch it landed
|
|
8
|
+
// in `metadata`, which is JSON.stringify-ed straight into the OP_RETURN — so the secret
|
|
9
|
+
// scalar was broadcast, and the key was recoverable from chain data with an identical WIF.
|
|
10
|
+
|
|
11
|
+
require('chai').should()
|
|
12
|
+
var bsv = require('../..')
|
|
13
|
+
|
|
14
|
+
describe('GDAF anchoring never publishes key material', function () {
|
|
15
|
+
var key = bsv.PrivateKey.fromBuffer(Buffer.alloc(32, 7))
|
|
16
|
+
var utxos = [{
|
|
17
|
+
txId: '11'.repeat(32),
|
|
18
|
+
outputIndex: 0,
|
|
19
|
+
script: bsv.Script.buildPublicKeyHashOut(key.toAddress()).toHex(),
|
|
20
|
+
satoshis: 100000
|
|
21
|
+
}]
|
|
22
|
+
var HASH = 'ab'.repeat(32)
|
|
23
|
+
|
|
24
|
+
function gdaf () { return new bsv.GDAF() }
|
|
25
|
+
|
|
26
|
+
// Pull every OP_RETURN payload out of a built transaction, as UTF-8.
|
|
27
|
+
function payloadsOf (result) {
|
|
28
|
+
var tx = new bsv.Transaction((result.transaction || result.tx || result).toString())
|
|
29
|
+
return tx.outputs.map(function (o) {
|
|
30
|
+
var asm = o.script.toASM().split(' ')
|
|
31
|
+
return Buffer.from(asm[asm.length - 1], 'hex').toString('utf8')
|
|
32
|
+
})
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
function assertNoSecret (result) {
|
|
36
|
+
var scalarHex = key.bn.toString('hex')
|
|
37
|
+
var raw = (result.transaction || result.tx || result).toString()
|
|
38
|
+
raw.indexOf(Buffer.from(scalarHex, 'utf8').toString('hex')).should.equal(-1)
|
|
39
|
+
raw.indexOf(Buffer.from('"bn"', 'utf8').toString('hex')).should.equal(-1)
|
|
40
|
+
payloadsOf(result).forEach(function (p) {
|
|
41
|
+
p.indexOf(scalarHex).should.equal(-1)
|
|
42
|
+
p.indexOf('"bn"').should.equal(-1)
|
|
43
|
+
})
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
it('anchorCredential does not put the key in the OP_RETURN', function () {
|
|
47
|
+
return gdaf().anchorCredential(HASH, key, utxos).then(assertNoSecret)
|
|
48
|
+
})
|
|
49
|
+
|
|
50
|
+
it('anchorBatch does not put the key in the OP_RETURN', function () {
|
|
51
|
+
return gdaf().anchorBatch([HASH, 'cd'.repeat(32)], key, utxos).then(assertNoSecret)
|
|
52
|
+
})
|
|
53
|
+
|
|
54
|
+
it('accepts the documented { utxos, metadata } options shape', function () {
|
|
55
|
+
return gdaf().anchorCredential(HASH, key, { utxos: utxos, metadata: { issuer: 'did:web:example' } })
|
|
56
|
+
.then(function (r) {
|
|
57
|
+
assertNoSecret(r)
|
|
58
|
+
// The caller's own metadata still reaches the chain.
|
|
59
|
+
payloadsOf(r).join('').indexOf('did:web:example').should.not.equal(-1)
|
|
60
|
+
})
|
|
61
|
+
})
|
|
62
|
+
|
|
63
|
+
it('still accepts a bare UTXO array, the only shape that used to work', function () {
|
|
64
|
+
return gdaf().anchorCredential(HASH, key, utxos).then(function (r) {
|
|
65
|
+
r.should.be.an('object')
|
|
66
|
+
})
|
|
67
|
+
})
|
|
68
|
+
|
|
69
|
+
// Defence in depth: even reaching the payload builder with key material must fail
|
|
70
|
+
// loudly rather than broadcast it.
|
|
71
|
+
it('refuses to anchor metadata containing a PrivateKey instance', function () {
|
|
72
|
+
return gdaf().anchorCredential(HASH, key, { utxos: utxos, metadata: { signer: key } })
|
|
73
|
+
.then(function () { throw new Error('should not have anchored') },
|
|
74
|
+
function (err) { err.message.should.match(/Refusing to anchor/) })
|
|
75
|
+
})
|
|
76
|
+
|
|
77
|
+
it('refuses to anchor metadata carrying a key-shaped field', function () {
|
|
78
|
+
return gdaf().anchorCredential(HASH, key, { utxos: utxos, metadata: { wif: key.toWIF() } })
|
|
79
|
+
.then(function () { throw new Error('should not have anchored') },
|
|
80
|
+
function (err) { err.message.should.match(/looks like key material/) })
|
|
81
|
+
})
|
|
82
|
+
|
|
83
|
+
it('leaves ordinary metadata alone', function () {
|
|
84
|
+
return gdaf().anchorCredential(HASH, key, {
|
|
85
|
+
utxos: utxos, metadata: { id: 'urn:uuid:1', nested: { note: 'fine' } }
|
|
86
|
+
}).then(function (r) { assertNoSecret(r) })
|
|
87
|
+
})
|
|
88
|
+
})
|