@smartledger/bsv 6.2.1 → 6.2.2
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 +29 -0
- package/README.md +38 -38
- package/bsv-gdaf.min.js +17 -17
- package/bsv-ltp.min.js +17 -17
- package/bsv-smartcontract.min.js +18 -18
- package/bsv.bundle.js +17 -17
- package/bsv.min.js +17 -17
- 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/smart_contract/preimage.js +48 -21
- package/package.json +3 -6
- package/test/smart_contract/preimage.js +98 -0
- 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@6.2.
|
|
58
|
+
- **CDN**: `unpkg.com/@smartledger/bsv@6.2.2/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@6.2.
|
|
64
|
+
- **CDN**: `unpkg.com/@smartledger/bsv@6.2.2/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@6.2.
|
|
70
|
+
- **CDN**: `unpkg.com/@smartledger/bsv@6.2.2/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@6.2.
|
|
85
|
-
| **bsv.bundle.js** | 937KB | Everything in one file | `unpkg.com/@smartledger/bsv@6.2.
|
|
86
|
-
| **bsv-smartcontract.min.js** | 937KB | Covenant development | `unpkg.com/@smartledger/bsv@6.2.
|
|
87
|
-
| **bsv-covenant.min.js** | 913KB | Covenant operations | `unpkg.com/@smartledger/bsv@6.2.
|
|
88
|
-
| **bsv-script-helper.min.js** | 26KB | Custom script tools | `unpkg.com/@smartledger/bsv@6.2.
|
|
89
|
-
| **bsv-security.min.js** | 26KB | Security enhancements (opt-in helpers — see README › Security) | `unpkg.com/@smartledger/bsv@6.2.
|
|
90
|
-
| **bsv-ecies.min.js** | 71KB | Encryption | `unpkg.com/@smartledger/bsv@6.2.
|
|
91
|
-
| **bsv-message.min.js** | 26KB | Message signing | `unpkg.com/@smartledger/bsv@6.2.
|
|
92
|
-
| **bsv-mnemonic.min.js** | 681KB | HD wallets | `unpkg.com/@smartledger/bsv@6.2.
|
|
93
|
-
| **🆕 bsv-shamir.min.js** | 432KB | **Secret sharing** | `unpkg.com/@smartledger/bsv@6.2.
|
|
94
|
-
| **🆕 bsv-gdaf.min.js** | 1184KB | **Digital attestation** | `unpkg.com/@smartledger/bsv@6.2.
|
|
95
|
-
| **🆕 bsv-ltp.min.js** | 1184KB | **Legal tokens** | `unpkg.com/@smartledger/bsv@6.2.
|
|
84
|
+
| **bsv.min.js** | 937KB | Core BSV + SmartContract | `unpkg.com/@smartledger/bsv@6.2.2/bsv.min.js` |
|
|
85
|
+
| **bsv.bundle.js** | 937KB | Everything in one file | `unpkg.com/@smartledger/bsv@6.2.2/bsv.bundle.js` |
|
|
86
|
+
| **bsv-smartcontract.min.js** | 937KB | Covenant development | `unpkg.com/@smartledger/bsv@6.2.2/bsv-smartcontract.min.js` |
|
|
87
|
+
| **bsv-covenant.min.js** | 913KB | Covenant operations | `unpkg.com/@smartledger/bsv@6.2.2/bsv-covenant.min.js` |
|
|
88
|
+
| **bsv-script-helper.min.js** | 26KB | Custom script tools | `unpkg.com/@smartledger/bsv@6.2.2/bsv-script-helper.min.js` |
|
|
89
|
+
| **bsv-security.min.js** | 26KB | Security enhancements (opt-in helpers — see README › Security) | `unpkg.com/@smartledger/bsv@6.2.2/bsv-security.min.js` |
|
|
90
|
+
| **bsv-ecies.min.js** | 71KB | Encryption | `unpkg.com/@smartledger/bsv@6.2.2/bsv-ecies.min.js` |
|
|
91
|
+
| **bsv-message.min.js** | 26KB | Message signing | `unpkg.com/@smartledger/bsv@6.2.2/bsv-message.min.js` |
|
|
92
|
+
| **bsv-mnemonic.min.js** | 681KB | HD wallets | `unpkg.com/@smartledger/bsv@6.2.2/bsv-mnemonic.min.js` |
|
|
93
|
+
| **🆕 bsv-shamir.min.js** | 432KB | **Secret sharing** | `unpkg.com/@smartledger/bsv@6.2.2/bsv-shamir.min.js` |
|
|
94
|
+
| **🆕 bsv-gdaf.min.js** | 1184KB | **Digital attestation** | `unpkg.com/@smartledger/bsv@6.2.2/bsv-gdaf.min.js` |
|
|
95
|
+
| **🆕 bsv-ltp.min.js** | 1184KB | **Legal tokens** | `unpkg.com/@smartledger/bsv@6.2.2/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@6.2.
|
|
104
|
-
<script src="https://unpkg.com/@smartledger/bsv@6.2.
|
|
103
|
+
<script src="https://unpkg.com/@smartledger/bsv@6.2.2/bsv.min.js"></script>
|
|
104
|
+
<script src="https://unpkg.com/@smartledger/bsv@6.2.2/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@6.2.
|
|
110
|
-
<script src="https://unpkg.com/@smartledger/bsv@6.2.
|
|
111
|
-
<script src="https://unpkg.com/@smartledger/bsv@6.2.
|
|
109
|
+
<script src="https://unpkg.com/@smartledger/bsv@6.2.2/bsv.min.js"></script>
|
|
110
|
+
<script src="https://unpkg.com/@smartledger/bsv@6.2.2/bsv-covenant.min.js"></script>
|
|
111
|
+
<script src="https://unpkg.com/@smartledger/bsv@6.2.2/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@6.2.
|
|
117
|
-
<script src="https://unpkg.com/@smartledger/bsv@6.2.
|
|
118
|
-
<script src="https://unpkg.com/@smartledger/bsv@6.2.
|
|
116
|
+
<script src="https://unpkg.com/@smartledger/bsv@6.2.2/bsv.min.js"></script>
|
|
117
|
+
<script src="https://unpkg.com/@smartledger/bsv@6.2.2/bsv-ltp.min.js"></script>
|
|
118
|
+
<script src="https://unpkg.com/@smartledger/bsv@6.2.2/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@6.2.
|
|
136
|
-
<script src="https://unpkg.com/@smartledger/bsv@6.2.
|
|
137
|
-
<script src="https://unpkg.com/@smartledger/bsv@6.2.
|
|
135
|
+
<script src="https://unpkg.com/@smartledger/bsv@6.2.2/bsv.min.js"></script>
|
|
136
|
+
<script src="https://unpkg.com/@smartledger/bsv@6.2.2/bsv-security.min.js"></script>
|
|
137
|
+
<script src="https://unpkg.com/@smartledger/bsv@6.2.2/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@6.2.
|
|
149
|
+
<script src="https://unpkg.com/@smartledger/bsv@6.2.2/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@6.2.
|
|
725
|
+
<script src="https://cdn.jsdelivr.net/npm/@smartledger/bsv@6.2.2/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@6.2.
|
|
51
|
+
<script src="https://unpkg.com/@smartledger/bsv@6.2.2/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@6.2.
|
|
61
|
+
<script src="https://unpkg.com/@smartledger/bsv@6.2.2/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@6.2.
|
|
75
|
-
<script src="https://unpkg.com/@smartledger/bsv@6.2.
|
|
76
|
-
<script src="https://unpkg.com/@smartledger/bsv@6.2.
|
|
74
|
+
<script src="https://unpkg.com/@smartledger/bsv@6.2.2/bsv.min.js"></script>
|
|
75
|
+
<script src="https://unpkg.com/@smartledger/bsv@6.2.2/bsv-covenant.min.js"></script>
|
|
76
|
+
<script src="https://unpkg.com/@smartledger/bsv@6.2.2/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@6.2.
|
|
86
|
-
<script src="https://unpkg.com/@smartledger/bsv@6.2.
|
|
87
|
-
<script src="https://unpkg.com/@smartledger/bsv@6.2.
|
|
85
|
+
<script src="https://unpkg.com/@smartledger/bsv@6.2.2/bsv.min.js"></script>
|
|
86
|
+
<script src="https://unpkg.com/@smartledger/bsv@6.2.2/bsv-ltp.min.js"></script>
|
|
87
|
+
<script src="https://unpkg.com/@smartledger/bsv@6.2.2/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@6.2.
|
|
102
|
-
<script src="https://unpkg.com/@smartledger/bsv@6.2.
|
|
103
|
-
<script src="https://unpkg.com/@smartledger/bsv@6.2.
|
|
101
|
+
<script src="https://unpkg.com/@smartledger/bsv@6.2.2/bsv.min.js"></script>
|
|
102
|
+
<script src="https://unpkg.com/@smartledger/bsv@6.2.2/bsv-security.min.js"></script>
|
|
103
|
+
<script src="https://unpkg.com/@smartledger/bsv@6.2.2/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@6.2.
|
|
118
|
-
| **bsv.bundle.js** | 937KB | Everything in one file | `unpkg.com/@smartledger/bsv@6.2.
|
|
119
|
-
| **bsv-smartcontract.min.js** | 937KB | Complete covenant framework | `unpkg.com/@smartledger/bsv@6.2.
|
|
120
|
-
| **bsv-ltp.min.js** | 1184KB | **Legal Token Protocol** | `unpkg.com/@smartledger/bsv@6.2.
|
|
121
|
-
| **bsv-gdaf.min.js** | 1184KB | **Digital Identity & Attestation** | `unpkg.com/@smartledger/bsv@6.2.
|
|
122
|
-
| **bsv-shamir.min.js** | 432KB | **Threshold Cryptography** | `unpkg.com/@smartledger/bsv@6.2.
|
|
123
|
-
| **bsv-security.min.js** | 26KB | Security enhancements (opt-in helpers — see README › Security) | `unpkg.com/@smartledger/bsv@6.2.
|
|
124
|
-
| **bsv-mnemonic.min.js** | 681KB | HD wallets | `unpkg.com/@smartledger/bsv@6.2.
|
|
125
|
-
| **bsv-ecies.min.js** | 71KB | Encryption | `unpkg.com/@smartledger/bsv@6.2.
|
|
126
|
-
| **bsv-covenant.min.js** | 913KB | Covenant operations | `unpkg.com/@smartledger/bsv@6.2.
|
|
127
|
-
| **bsv-script-helper.min.js** | 26KB | Custom script tools | `unpkg.com/@smartledger/bsv@6.2.
|
|
128
|
-
| **bsv-message.min.js** | 26KB | Message signing | `unpkg.com/@smartledger/bsv@6.2.
|
|
117
|
+
| **bsv.min.js** | 937KB | Core BSV + SmartContract | `unpkg.com/@smartledger/bsv@6.2.2/bsv.min.js` |
|
|
118
|
+
| **bsv.bundle.js** | 937KB | Everything in one file | `unpkg.com/@smartledger/bsv@6.2.2/bsv.bundle.js` |
|
|
119
|
+
| **bsv-smartcontract.min.js** | 937KB | Complete covenant framework | `unpkg.com/@smartledger/bsv@6.2.2/bsv-smartcontract.min.js` |
|
|
120
|
+
| **bsv-ltp.min.js** | 1184KB | **Legal Token Protocol** | `unpkg.com/@smartledger/bsv@6.2.2/bsv-ltp.min.js` |
|
|
121
|
+
| **bsv-gdaf.min.js** | 1184KB | **Digital Identity & Attestation** | `unpkg.com/@smartledger/bsv@6.2.2/bsv-gdaf.min.js` |
|
|
122
|
+
| **bsv-shamir.min.js** | 432KB | **Threshold Cryptography** | `unpkg.com/@smartledger/bsv@6.2.2/bsv-shamir.min.js` |
|
|
123
|
+
| **bsv-security.min.js** | 26KB | Security enhancements (opt-in helpers — see README › Security) | `unpkg.com/@smartledger/bsv@6.2.2/bsv-security.min.js` |
|
|
124
|
+
| **bsv-mnemonic.min.js** | 681KB | HD wallets | `unpkg.com/@smartledger/bsv@6.2.2/bsv-mnemonic.min.js` |
|
|
125
|
+
| **bsv-ecies.min.js** | 71KB | Encryption | `unpkg.com/@smartledger/bsv@6.2.2/bsv-ecies.min.js` |
|
|
126
|
+
| **bsv-covenant.min.js** | 913KB | Covenant operations | `unpkg.com/@smartledger/bsv@6.2.2/bsv-covenant.min.js` |
|
|
127
|
+
| **bsv-script-helper.min.js** | 26KB | Custom script tools | `unpkg.com/@smartledger/bsv@6.2.2/bsv-script-helper.min.js` |
|
|
128
|
+
| **bsv-message.min.js** | 26KB | Message signing | `unpkg.com/@smartledger/bsv@6.2.2/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@6.2.
|
|
17
|
+
<script src="https://unpkg.com/@smartledger/bsv@6.2.2/bsv.min.js"></script>
|
|
18
18
|
|
|
19
19
|
<!-- Everything included (937KB) -->
|
|
20
|
-
<script src="https://unpkg.com/@smartledger/bsv@6.2.
|
|
20
|
+
<script src="https://unpkg.com/@smartledger/bsv@6.2.2/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@6.2.
|
|
130
|
+
<script src="https://unpkg.com/@smartledger/bsv@6.2.2/bsv.min.js"></script>
|
|
131
131
|
|
|
132
132
|
<!-- Smart contracts (937KB) -->
|
|
133
|
-
<script src="https://unpkg.com/@smartledger/bsv@6.2.
|
|
133
|
+
<script src="https://unpkg.com/@smartledger/bsv@6.2.2/bsv-smartcontract.min.js"></script>
|
|
134
134
|
|
|
135
135
|
<!-- Legal tokens (1.16MB) -->
|
|
136
|
-
<script src="https://unpkg.com/@smartledger/bsv@6.2.
|
|
136
|
+
<script src="https://unpkg.com/@smartledger/bsv@6.2.2/bsv-ltp.min.js"></script>
|
|
137
137
|
|
|
138
138
|
<!-- Digital identity (1.16MB) -->
|
|
139
|
-
<script src="https://unpkg.com/@smartledger/bsv@6.2.
|
|
139
|
+
<script src="https://unpkg.com/@smartledger/bsv@6.2.2/bsv-gdaf.min.js"></script>
|
|
140
140
|
|
|
141
141
|
<!-- Everything (937KB) -->
|
|
142
|
-
<script src="https://unpkg.com/@smartledger/bsv@6.2.
|
|
142
|
+
<script src="https://unpkg.com/@smartledger/bsv@6.2.2/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@6.2.
|
|
162
|
+
<script src="https://unpkg.com/@smartledger/bsv@6.2.2/bsv.min.js"></script>
|
|
163
163
|
|
|
164
164
|
<!-- Add smart contracts when ready -->
|
|
165
|
-
<script src="https://unpkg.com/@smartledger/bsv@6.2.
|
|
165
|
+
<script src="https://unpkg.com/@smartledger/bsv@6.2.2/bsv-smartcontract.min.js"></script>
|
|
166
166
|
|
|
167
167
|
<!-- Add advanced features as needed -->
|
|
168
|
-
<script src="https://unpkg.com/@smartledger/bsv@6.2.
|
|
169
|
-
<script src="https://unpkg.com/@smartledger/bsv@6.2.
|
|
168
|
+
<script src="https://unpkg.com/@smartledger/bsv@6.2.2/bsv-ltp.min.js"></script>
|
|
169
|
+
<script src="https://unpkg.com/@smartledger/bsv@6.2.2/bsv-gdaf.min.js"></script>
|
|
170
170
|
|
|
171
171
|
<!-- Everything in one file -->
|
|
172
|
-
<script src="https://unpkg.com/@smartledger/bsv@6.2.
|
|
172
|
+
<script src="https://unpkg.com/@smartledger/bsv@6.2.2/bsv.bundle.js"></script>
|
|
173
173
|
```
|
|
174
174
|
|
|
175
175
|
## 🔍 **Testing Your Migration**
|
|
@@ -40,6 +40,15 @@ function Preimage(preimage, options) {
|
|
|
40
40
|
}
|
|
41
41
|
}
|
|
42
42
|
|
|
43
|
+
// Structural minimum of a BIP-143 preimage, so a too-short buffer fails with an
|
|
44
|
+
// HONEST error instead of tripping decodeCompactSize into a misleading
|
|
45
|
+
// "8-byte CompactSize" throw. LEFT fixed (nVersion 4 + hashPrevouts 32 +
|
|
46
|
+
// hashSequence 32 + outpoint 36 = 104) + smallest scriptLen varint (1) + RIGHT
|
|
47
|
+
// fixed (amount 8 + nSequence 4 + hashOutputs 32 + nLocktime 4 + sighash 4 = 52).
|
|
48
|
+
Preimage.LEFT_FIXED_LENGTH = 4 + 32 + 32 + 36 // 104
|
|
49
|
+
Preimage.RIGHT_FIXED_LENGTH = 8 + 4 + 32 + 4 + 4 // 52
|
|
50
|
+
Preimage.MIN_PREIMAGE_LENGTH = Preimage.LEFT_FIXED_LENGTH + 1 + Preimage.RIGHT_FIXED_LENGTH // 157
|
|
51
|
+
|
|
43
52
|
/**
|
|
44
53
|
* Extract all preimage fields using bidirectional strategy
|
|
45
54
|
* @param {string} extractionStrategy - 'LEFT', 'RIGHT', or 'DYNAMIC'
|
|
@@ -141,13 +150,27 @@ Preimage.prototype.extractFields = function(fieldNames) {
|
|
|
141
150
|
* @returns {Object} Validation result
|
|
142
151
|
*/
|
|
143
152
|
Preimage.prototype.validate = function() {
|
|
153
|
+
var errors = []
|
|
154
|
+
var warnings = []
|
|
155
|
+
|
|
156
|
+
// Length first: a buffer too short to hold the fixed fields can't be
|
|
157
|
+
// field-extracted, so report it without tripping extraction. (For a
|
|
158
|
+
// non-deferred Preimage construction already threw the same error.)
|
|
159
|
+
if (this.preimage.length < Preimage.MIN_PREIMAGE_LENGTH) {
|
|
160
|
+
errors.push('Preimage too short: ' + this.preimage.length +
|
|
161
|
+
' bytes (BIP-143 preimage requires at least ' + Preimage.MIN_PREIMAGE_LENGTH + ')')
|
|
162
|
+
return {
|
|
163
|
+
valid: false,
|
|
164
|
+
errors: errors,
|
|
165
|
+
warnings: warnings,
|
|
166
|
+
sighashInfo: this.sighashInfo
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
|
|
144
170
|
if (!this.fields) {
|
|
145
171
|
this._extractFields()
|
|
146
172
|
}
|
|
147
173
|
|
|
148
|
-
var errors = []
|
|
149
|
-
var warnings = []
|
|
150
|
-
|
|
151
174
|
// Check required fields
|
|
152
175
|
var requiredFields = [
|
|
153
176
|
'version', 'hashPrevouts', 'hashSequence', 'outpoint',
|
|
@@ -165,11 +188,6 @@ Preimage.prototype.validate = function() {
|
|
|
165
188
|
warnings.push('Zero hashes detected - check SIGHASH flags: ' + this.sighashInfo.zeroFields.join(', '))
|
|
166
189
|
}
|
|
167
190
|
|
|
168
|
-
// Validate preimage length
|
|
169
|
-
if (this.preimage.length < 104) { // Minimum BIP-143 preimage size
|
|
170
|
-
errors.push('Preimage too short: ' + this.preimage.length + ' bytes (minimum 104)')
|
|
171
|
-
}
|
|
172
|
-
|
|
173
191
|
return {
|
|
174
192
|
valid: errors.length === 0,
|
|
175
193
|
errors: errors,
|
|
@@ -222,6 +240,13 @@ Preimage.prototype._extractFields = function() {
|
|
|
222
240
|
warnings: []
|
|
223
241
|
}
|
|
224
242
|
|
|
243
|
+
// Fail closed with an honest error before any slice/varint work runs on a
|
|
244
|
+
// buffer too small to hold the fixed BIP-143 fields.
|
|
245
|
+
if (this.preimage.length < Preimage.MIN_PREIMAGE_LENGTH) {
|
|
246
|
+
throw new Error('Preimage too short: ' + this.preimage.length +
|
|
247
|
+
' bytes (BIP-143 preimage requires at least ' + Preimage.MIN_PREIMAGE_LENGTH + ')')
|
|
248
|
+
}
|
|
249
|
+
|
|
225
250
|
try {
|
|
226
251
|
if (this.strategy === 'LEFT' || this.strategy === 'DYNAMIC') {
|
|
227
252
|
this._extractFromLeft()
|
|
@@ -735,6 +760,10 @@ Preimage.prototype._getExtractionStrategy = function(fieldName) {
|
|
|
735
760
|
* @returns {Object} Decoded value and next offset
|
|
736
761
|
*/
|
|
737
762
|
Preimage.decodeCompactSize = function(buffer, offset) {
|
|
763
|
+
if (offset >= buffer.length) {
|
|
764
|
+
throw new Error('CompactSize read past end of preimage buffer (offset ' +
|
|
765
|
+
offset + ', length ' + buffer.length + ')')
|
|
766
|
+
}
|
|
738
767
|
var firstByte = buffer[offset]
|
|
739
768
|
|
|
740
769
|
if (firstByte < 0xfd) {
|
|
@@ -742,24 +771,22 @@ Preimage.decodeCompactSize = function(buffer, offset) {
|
|
|
742
771
|
return { value: firstByte, nextOffset: offset + 1, bytes: 1 }
|
|
743
772
|
} else if (firstByte === 0xfd) {
|
|
744
773
|
// 2 byte encoding (253-65535)
|
|
774
|
+
if (offset + 3 > buffer.length) {
|
|
775
|
+
throw new Error('Truncated 2-byte CompactSize in preimage at offset ' + offset)
|
|
776
|
+
}
|
|
745
777
|
var value = buffer.readUInt16LE(offset + 1)
|
|
746
778
|
return { value: value, nextOffset: offset + 3, bytes: 3 }
|
|
747
779
|
} else if (firstByte === 0xfe) {
|
|
748
780
|
// 4 byte encoding (65536-4294967295) - rare for script lengths
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
} else {
|
|
752
|
-
// 8 byte encoding - extremely rare, try to handle gracefully
|
|
753
|
-
console.warn('Encountered 8-byte CompactSize - this is very unusual for script lengths')
|
|
754
|
-
// For our purposes, assume it's a reasonable script length and try to parse it
|
|
755
|
-
// This is a fallback for malformed or test data
|
|
756
|
-
try {
|
|
757
|
-
// Read as 4-byte for now since 8-byte values would be enormous for scripts
|
|
758
|
-
var value = buffer.readUInt32LE(offset + 1)
|
|
759
|
-
return { value: value, nextOffset: offset + 9, bytes: 9 } // Skip full 8 bytes + marker
|
|
760
|
-
} catch (e) {
|
|
761
|
-
throw new Error('Invalid 8-byte CompactSize encoding in preimage')
|
|
781
|
+
if (offset + 5 > buffer.length) {
|
|
782
|
+
throw new Error('Truncated 4-byte CompactSize in preimage at offset ' + offset)
|
|
762
783
|
}
|
|
784
|
+
var value4 = buffer.readUInt32LE(offset + 1)
|
|
785
|
+
return { value: value4, nextOffset: offset + 5, bytes: 5 }
|
|
786
|
+
} else {
|
|
787
|
+
// 0xff marks an 8-byte length (>4 GB) - impossible for a real script length,
|
|
788
|
+
// so this is malformed/misaligned data rather than a value to salvage.
|
|
789
|
+
throw new Error('Invalid CompactSize: 8-byte length prefix (0xff) is not a valid script length')
|
|
763
790
|
}
|
|
764
791
|
}
|
|
765
792
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@smartledger/bsv",
|
|
3
|
-
"version": "6.2.
|
|
3
|
+
"version": "6.2.2",
|
|
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",
|
|
@@ -196,12 +196,12 @@
|
|
|
196
196
|
},
|
|
197
197
|
"devDependencies": {
|
|
198
198
|
"assert": "^2.1.0",
|
|
199
|
-
"brfs": "2.0.1",
|
|
200
199
|
"browserify-zlib": "^0.2.0",
|
|
201
200
|
"buffer": "^6.0.3",
|
|
202
201
|
"chai": "4.2.0",
|
|
203
202
|
"crypto-browserify": "^3.12.1",
|
|
204
203
|
"esbuild": "^0.28.1",
|
|
204
|
+
"events": "^3.3.0",
|
|
205
205
|
"jose": "^5.10.0",
|
|
206
206
|
"mocha": "^11.7.6",
|
|
207
207
|
"nyc": "^18.0.0",
|
|
@@ -210,12 +210,9 @@
|
|
|
210
210
|
"sinon": "7.2.3",
|
|
211
211
|
"standard": "12.0.1",
|
|
212
212
|
"stream-browserify": "^3.0.0",
|
|
213
|
-
"terser-webpack-plugin": "^5.6.1",
|
|
214
213
|
"typescript": "^5.9.3",
|
|
215
214
|
"util": "^0.12.5",
|
|
216
|
-
"vm-browserify": "^1.1.2"
|
|
217
|
-
"webpack": "^5.107.2",
|
|
218
|
-
"webpack-cli": "^5.1.4"
|
|
215
|
+
"vm-browserify": "^1.1.2"
|
|
219
216
|
},
|
|
220
217
|
"license": "MIT",
|
|
221
218
|
"standard": {
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
'use strict'
|
|
2
|
+
|
|
3
|
+
/* global describe, it */
|
|
4
|
+
|
|
5
|
+
// Coverage for SmartContract.Preimage (previously untested public class).
|
|
6
|
+
// Focus: a too-short buffer must fail with an HONEST error (it used to trip
|
|
7
|
+
// decodeCompactSize into a misleading "8-byte CompactSize" throw plus console
|
|
8
|
+
// spam), while real BIP-143 preimages round-trip their fields.
|
|
9
|
+
|
|
10
|
+
require('chai').should()
|
|
11
|
+
var bsv = require('../..')
|
|
12
|
+
var Preimage = bsv.SmartContract.Preimage
|
|
13
|
+
|
|
14
|
+
describe('SmartContract.Preimage', function () {
|
|
15
|
+
describe('length guard (honest failure)', function () {
|
|
16
|
+
it('exposes the derived BIP-143 structural minimum (157)', function () {
|
|
17
|
+
Preimage.LEFT_FIXED_LENGTH.should.equal(104)
|
|
18
|
+
Preimage.RIGHT_FIXED_LENGTH.should.equal(52)
|
|
19
|
+
Preimage.MIN_PREIMAGE_LENGTH.should.equal(157)
|
|
20
|
+
})
|
|
21
|
+
|
|
22
|
+
it('throws a clear "too short" error at construction, not a CompactSize error', function () {
|
|
23
|
+
;[0, 50, 103, 156].forEach(function (n) {
|
|
24
|
+
(function () { return new Preimage(Buffer.alloc(n)) })
|
|
25
|
+
.should.throw(/Preimage too short/)
|
|
26
|
+
})
|
|
27
|
+
})
|
|
28
|
+
|
|
29
|
+
it('does NOT mention CompactSize when the real problem is length', function () {
|
|
30
|
+
var threw
|
|
31
|
+
try { threw = new Preimage(Buffer.alloc(50)) } catch (e) { threw = e.message }
|
|
32
|
+
threw.should.match(/Preimage too short/)
|
|
33
|
+
threw.should.not.match(/CompactSize/)
|
|
34
|
+
})
|
|
35
|
+
|
|
36
|
+
it('validate() reports the length gracefully for a deferred preimage (no throw)', function () {
|
|
37
|
+
var p = new Preimage(Buffer.alloc(50), { deferExtraction: true })
|
|
38
|
+
var res = p.validate()
|
|
39
|
+
res.valid.should.equal(false)
|
|
40
|
+
res.errors.join(' ').should.match(/Preimage too short: 50 bytes/)
|
|
41
|
+
})
|
|
42
|
+
|
|
43
|
+
it('accepts a buffer exactly at the minimum length', function () {
|
|
44
|
+
// 157 bytes: 104 left + 1-byte scriptLen varint (0x00 => empty script) + 52 right.
|
|
45
|
+
var buf = Buffer.alloc(Preimage.MIN_PREIMAGE_LENGTH)
|
|
46
|
+
;(function () { return new Preimage(buf) }).should.not.throw()
|
|
47
|
+
})
|
|
48
|
+
})
|
|
49
|
+
|
|
50
|
+
describe('decodeCompactSize (honest failure)', function () {
|
|
51
|
+
it('throws when reading past the end of the buffer', function () {
|
|
52
|
+
(function () { Preimage.decodeCompactSize(Buffer.alloc(4), 4) })
|
|
53
|
+
.should.throw(/past end of preimage buffer/)
|
|
54
|
+
})
|
|
55
|
+
|
|
56
|
+
it('rejects the 8-byte (0xff) length prefix as invalid for a script length', function () {
|
|
57
|
+
var buf = Buffer.concat([Buffer.from([0xff]), Buffer.alloc(8)])
|
|
58
|
+
;(function () { Preimage.decodeCompactSize(buf, 0) })
|
|
59
|
+
.should.throw(/8-byte length prefix/)
|
|
60
|
+
})
|
|
61
|
+
|
|
62
|
+
it('rejects a truncated 2-byte CompactSize', function () {
|
|
63
|
+
(function () { Preimage.decodeCompactSize(Buffer.from([0xfd, 0x01]), 0) })
|
|
64
|
+
.should.throw(/Truncated 2-byte CompactSize/)
|
|
65
|
+
})
|
|
66
|
+
|
|
67
|
+
it('decodes a plain 1-byte length', function () {
|
|
68
|
+
var r = Preimage.decodeCompactSize(Buffer.from([0x19]), 0)
|
|
69
|
+
r.value.should.equal(0x19)
|
|
70
|
+
r.bytes.should.equal(1)
|
|
71
|
+
r.nextOffset.should.equal(1)
|
|
72
|
+
})
|
|
73
|
+
})
|
|
74
|
+
|
|
75
|
+
describe('real preimage round-trip', function () {
|
|
76
|
+
it('constructs, extracts fields, and validates a genuine preimage', function () {
|
|
77
|
+
var ex = Preimage.createExample(0x41) // SIGHASH_ALL | FORKID
|
|
78
|
+
ex.preimage.length.should.be.above(Preimage.MIN_PREIMAGE_LENGTH)
|
|
79
|
+
|
|
80
|
+
// Fixed-width fields come back at their BIP-143 sizes.
|
|
81
|
+
ex.getField('version').length.should.equal(4)
|
|
82
|
+
ex.getField('hashPrevouts').length.should.equal(32)
|
|
83
|
+
ex.getField('hashOutputs').length.should.equal(32)
|
|
84
|
+
ex.getField('sighash').length.should.equal(4)
|
|
85
|
+
|
|
86
|
+
var v = ex.validate()
|
|
87
|
+
v.valid.should.equal(true)
|
|
88
|
+
v.errors.length.should.equal(0)
|
|
89
|
+
})
|
|
90
|
+
|
|
91
|
+
it('reports SIGHASH flag info for the extracted sighash', function () {
|
|
92
|
+
var ex = Preimage.createExample(0x41)
|
|
93
|
+
var info = ex.getSighashInfo()
|
|
94
|
+
info.flagName.should.match(/ALL/)
|
|
95
|
+
info.flagName.should.match(/FORKID/)
|
|
96
|
+
})
|
|
97
|
+
})
|
|
98
|
+
})
|
package/version.js
CHANGED