@smartledger/bsv 7.1.0 → 7.3.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 +179 -0
- package/README.md +38 -38
- package/bsv-gdaf.min.js +34 -34
- package/bsv-ltp.min.js +34 -34
- package/bsv-smartcontract.min.js +1 -1
- package/bsv.bundle.js +34 -34
- package/bsv.d.ts +17 -1
- package/bsv.min.js +34 -34
- 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/ordinals/README.md +61 -5
- package/lib/ordinals/bsv20.js +119 -12
- package/lib/ordinals/inscription.js +113 -23
- package/lib/ordinals/ordlock.js +28 -1
- package/package.json +1 -1
- package/test/ordinals/bsv20.js +98 -2
- package/test/ordinals/inscription.js +154 -0
- package/test/ordinals/ordlock.js +71 -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@7.
|
|
58
|
+
- **CDN**: `unpkg.com/@smartledger/bsv@7.3.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@7.
|
|
64
|
+
- **CDN**: `unpkg.com/@smartledger/bsv@7.3.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@7.
|
|
70
|
+
- **CDN**: `unpkg.com/@smartledger/bsv@7.3.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@7.
|
|
85
|
-
| **bsv.bundle.js** | 937KB | Everything in one file | `unpkg.com/@smartledger/bsv@7.
|
|
86
|
-
| **bsv-smartcontract.min.js** | 937KB | Covenant development | `unpkg.com/@smartledger/bsv@7.
|
|
87
|
-
| **bsv-covenant.min.js** | 913KB | Covenant operations | `unpkg.com/@smartledger/bsv@7.
|
|
88
|
-
| **bsv-script-helper.min.js** | 26KB | Custom script tools | `unpkg.com/@smartledger/bsv@7.
|
|
89
|
-
| **bsv-security.min.js** | 26KB | Security enhancements (opt-in helpers — see README › Security) | `unpkg.com/@smartledger/bsv@7.
|
|
90
|
-
| **bsv-ecies.min.js** | 71KB | Encryption | `unpkg.com/@smartledger/bsv@7.
|
|
91
|
-
| **bsv-message.min.js** | 26KB | Message signing | `unpkg.com/@smartledger/bsv@7.
|
|
92
|
-
| **bsv-mnemonic.min.js** | 681KB | HD wallets | `unpkg.com/@smartledger/bsv@7.
|
|
93
|
-
| **🆕 bsv-shamir.min.js** | 432KB | **Secret sharing** | `unpkg.com/@smartledger/bsv@7.
|
|
94
|
-
| **🆕 bsv-gdaf.min.js** | 1184KB | **Digital attestation** | `unpkg.com/@smartledger/bsv@7.
|
|
95
|
-
| **🆕 bsv-ltp.min.js** | 1184KB | **Legal tokens** | `unpkg.com/@smartledger/bsv@7.
|
|
84
|
+
| **bsv.min.js** | 937KB | Core BSV + SmartContract | `unpkg.com/@smartledger/bsv@7.3.0/bsv.min.js` |
|
|
85
|
+
| **bsv.bundle.js** | 937KB | Everything in one file | `unpkg.com/@smartledger/bsv@7.3.0/bsv.bundle.js` |
|
|
86
|
+
| **bsv-smartcontract.min.js** | 937KB | Covenant development | `unpkg.com/@smartledger/bsv@7.3.0/bsv-smartcontract.min.js` |
|
|
87
|
+
| **bsv-covenant.min.js** | 913KB | Covenant operations | `unpkg.com/@smartledger/bsv@7.3.0/bsv-covenant.min.js` |
|
|
88
|
+
| **bsv-script-helper.min.js** | 26KB | Custom script tools | `unpkg.com/@smartledger/bsv@7.3.0/bsv-script-helper.min.js` |
|
|
89
|
+
| **bsv-security.min.js** | 26KB | Security enhancements (opt-in helpers — see README › Security) | `unpkg.com/@smartledger/bsv@7.3.0/bsv-security.min.js` |
|
|
90
|
+
| **bsv-ecies.min.js** | 71KB | Encryption | `unpkg.com/@smartledger/bsv@7.3.0/bsv-ecies.min.js` |
|
|
91
|
+
| **bsv-message.min.js** | 26KB | Message signing | `unpkg.com/@smartledger/bsv@7.3.0/bsv-message.min.js` |
|
|
92
|
+
| **bsv-mnemonic.min.js** | 681KB | HD wallets | `unpkg.com/@smartledger/bsv@7.3.0/bsv-mnemonic.min.js` |
|
|
93
|
+
| **🆕 bsv-shamir.min.js** | 432KB | **Secret sharing** | `unpkg.com/@smartledger/bsv@7.3.0/bsv-shamir.min.js` |
|
|
94
|
+
| **🆕 bsv-gdaf.min.js** | 1184KB | **Digital attestation** | `unpkg.com/@smartledger/bsv@7.3.0/bsv-gdaf.min.js` |
|
|
95
|
+
| **🆕 bsv-ltp.min.js** | 1184KB | **Legal tokens** | `unpkg.com/@smartledger/bsv@7.3.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@7.
|
|
104
|
-
<script src="https://unpkg.com/@smartledger/bsv@7.
|
|
103
|
+
<script src="https://unpkg.com/@smartledger/bsv@7.3.0/bsv.min.js"></script>
|
|
104
|
+
<script src="https://unpkg.com/@smartledger/bsv@7.3.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@7.
|
|
110
|
-
<script src="https://unpkg.com/@smartledger/bsv@7.
|
|
111
|
-
<script src="https://unpkg.com/@smartledger/bsv@7.
|
|
109
|
+
<script src="https://unpkg.com/@smartledger/bsv@7.3.0/bsv.min.js"></script>
|
|
110
|
+
<script src="https://unpkg.com/@smartledger/bsv@7.3.0/bsv-covenant.min.js"></script>
|
|
111
|
+
<script src="https://unpkg.com/@smartledger/bsv@7.3.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@7.
|
|
117
|
-
<script src="https://unpkg.com/@smartledger/bsv@7.
|
|
118
|
-
<script src="https://unpkg.com/@smartledger/bsv@7.
|
|
116
|
+
<script src="https://unpkg.com/@smartledger/bsv@7.3.0/bsv.min.js"></script>
|
|
117
|
+
<script src="https://unpkg.com/@smartledger/bsv@7.3.0/bsv-ltp.min.js"></script>
|
|
118
|
+
<script src="https://unpkg.com/@smartledger/bsv@7.3.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@7.
|
|
136
|
-
<script src="https://unpkg.com/@smartledger/bsv@7.
|
|
137
|
-
<script src="https://unpkg.com/@smartledger/bsv@7.
|
|
135
|
+
<script src="https://unpkg.com/@smartledger/bsv@7.3.0/bsv.min.js"></script>
|
|
136
|
+
<script src="https://unpkg.com/@smartledger/bsv@7.3.0/bsv-security.min.js"></script>
|
|
137
|
+
<script src="https://unpkg.com/@smartledger/bsv@7.3.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@7.
|
|
149
|
+
<script src="https://unpkg.com/@smartledger/bsv@7.3.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@7.
|
|
725
|
+
<script src="https://cdn.jsdelivr.net/npm/@smartledger/bsv@7.3.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@7.
|
|
51
|
+
<script src="https://unpkg.com/@smartledger/bsv@7.3.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@7.
|
|
61
|
+
<script src="https://unpkg.com/@smartledger/bsv@7.3.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@7.
|
|
75
|
-
<script src="https://unpkg.com/@smartledger/bsv@7.
|
|
76
|
-
<script src="https://unpkg.com/@smartledger/bsv@7.
|
|
74
|
+
<script src="https://unpkg.com/@smartledger/bsv@7.3.0/bsv.min.js"></script>
|
|
75
|
+
<script src="https://unpkg.com/@smartledger/bsv@7.3.0/bsv-covenant.min.js"></script>
|
|
76
|
+
<script src="https://unpkg.com/@smartledger/bsv@7.3.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@7.
|
|
86
|
-
<script src="https://unpkg.com/@smartledger/bsv@7.
|
|
87
|
-
<script src="https://unpkg.com/@smartledger/bsv@7.
|
|
85
|
+
<script src="https://unpkg.com/@smartledger/bsv@7.3.0/bsv.min.js"></script>
|
|
86
|
+
<script src="https://unpkg.com/@smartledger/bsv@7.3.0/bsv-ltp.min.js"></script>
|
|
87
|
+
<script src="https://unpkg.com/@smartledger/bsv@7.3.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@7.
|
|
102
|
-
<script src="https://unpkg.com/@smartledger/bsv@7.
|
|
103
|
-
<script src="https://unpkg.com/@smartledger/bsv@7.
|
|
101
|
+
<script src="https://unpkg.com/@smartledger/bsv@7.3.0/bsv.min.js"></script>
|
|
102
|
+
<script src="https://unpkg.com/@smartledger/bsv@7.3.0/bsv-security.min.js"></script>
|
|
103
|
+
<script src="https://unpkg.com/@smartledger/bsv@7.3.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@7.
|
|
118
|
-
| **bsv.bundle.js** | 937KB | Everything in one file | `unpkg.com/@smartledger/bsv@7.
|
|
119
|
-
| **bsv-smartcontract.min.js** | 937KB | Complete covenant framework | `unpkg.com/@smartledger/bsv@7.
|
|
120
|
-
| **bsv-ltp.min.js** | 1184KB | **Legal Token Protocol** | `unpkg.com/@smartledger/bsv@7.
|
|
121
|
-
| **bsv-gdaf.min.js** | 1184KB | **Digital Identity & Attestation** | `unpkg.com/@smartledger/bsv@7.
|
|
122
|
-
| **bsv-shamir.min.js** | 432KB | **Threshold Cryptography** | `unpkg.com/@smartledger/bsv@7.
|
|
123
|
-
| **bsv-security.min.js** | 26KB | Security enhancements (opt-in helpers — see README › Security) | `unpkg.com/@smartledger/bsv@7.
|
|
124
|
-
| **bsv-mnemonic.min.js** | 681KB | HD wallets | `unpkg.com/@smartledger/bsv@7.
|
|
125
|
-
| **bsv-ecies.min.js** | 71KB | Encryption | `unpkg.com/@smartledger/bsv@7.
|
|
126
|
-
| **bsv-covenant.min.js** | 913KB | Covenant operations | `unpkg.com/@smartledger/bsv@7.
|
|
127
|
-
| **bsv-script-helper.min.js** | 26KB | Custom script tools | `unpkg.com/@smartledger/bsv@7.
|
|
128
|
-
| **bsv-message.min.js** | 26KB | Message signing | `unpkg.com/@smartledger/bsv@7.
|
|
117
|
+
| **bsv.min.js** | 937KB | Core BSV + SmartContract | `unpkg.com/@smartledger/bsv@7.3.0/bsv.min.js` |
|
|
118
|
+
| **bsv.bundle.js** | 937KB | Everything in one file | `unpkg.com/@smartledger/bsv@7.3.0/bsv.bundle.js` |
|
|
119
|
+
| **bsv-smartcontract.min.js** | 937KB | Complete covenant framework | `unpkg.com/@smartledger/bsv@7.3.0/bsv-smartcontract.min.js` |
|
|
120
|
+
| **bsv-ltp.min.js** | 1184KB | **Legal Token Protocol** | `unpkg.com/@smartledger/bsv@7.3.0/bsv-ltp.min.js` |
|
|
121
|
+
| **bsv-gdaf.min.js** | 1184KB | **Digital Identity & Attestation** | `unpkg.com/@smartledger/bsv@7.3.0/bsv-gdaf.min.js` |
|
|
122
|
+
| **bsv-shamir.min.js** | 432KB | **Threshold Cryptography** | `unpkg.com/@smartledger/bsv@7.3.0/bsv-shamir.min.js` |
|
|
123
|
+
| **bsv-security.min.js** | 26KB | Security enhancements (opt-in helpers — see README › Security) | `unpkg.com/@smartledger/bsv@7.3.0/bsv-security.min.js` |
|
|
124
|
+
| **bsv-mnemonic.min.js** | 681KB | HD wallets | `unpkg.com/@smartledger/bsv@7.3.0/bsv-mnemonic.min.js` |
|
|
125
|
+
| **bsv-ecies.min.js** | 71KB | Encryption | `unpkg.com/@smartledger/bsv@7.3.0/bsv-ecies.min.js` |
|
|
126
|
+
| **bsv-covenant.min.js** | 913KB | Covenant operations | `unpkg.com/@smartledger/bsv@7.3.0/bsv-covenant.min.js` |
|
|
127
|
+
| **bsv-script-helper.min.js** | 26KB | Custom script tools | `unpkg.com/@smartledger/bsv@7.3.0/bsv-script-helper.min.js` |
|
|
128
|
+
| **bsv-message.min.js** | 26KB | Message signing | `unpkg.com/@smartledger/bsv@7.3.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@7.
|
|
17
|
+
<script src="https://unpkg.com/@smartledger/bsv@7.3.0/bsv.min.js"></script>
|
|
18
18
|
|
|
19
19
|
<!-- Everything included (937KB) -->
|
|
20
|
-
<script src="https://unpkg.com/@smartledger/bsv@7.
|
|
20
|
+
<script src="https://unpkg.com/@smartledger/bsv@7.3.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@7.
|
|
130
|
+
<script src="https://unpkg.com/@smartledger/bsv@7.3.0/bsv.min.js"></script>
|
|
131
131
|
|
|
132
132
|
<!-- Smart contracts (937KB) -->
|
|
133
|
-
<script src="https://unpkg.com/@smartledger/bsv@7.
|
|
133
|
+
<script src="https://unpkg.com/@smartledger/bsv@7.3.0/bsv-smartcontract.min.js"></script>
|
|
134
134
|
|
|
135
135
|
<!-- Legal tokens (1.16MB) -->
|
|
136
|
-
<script src="https://unpkg.com/@smartledger/bsv@7.
|
|
136
|
+
<script src="https://unpkg.com/@smartledger/bsv@7.3.0/bsv-ltp.min.js"></script>
|
|
137
137
|
|
|
138
138
|
<!-- Digital identity (1.16MB) -->
|
|
139
|
-
<script src="https://unpkg.com/@smartledger/bsv@7.
|
|
139
|
+
<script src="https://unpkg.com/@smartledger/bsv@7.3.0/bsv-gdaf.min.js"></script>
|
|
140
140
|
|
|
141
141
|
<!-- Everything (937KB) -->
|
|
142
|
-
<script src="https://unpkg.com/@smartledger/bsv@7.
|
|
142
|
+
<script src="https://unpkg.com/@smartledger/bsv@7.3.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@7.
|
|
162
|
+
<script src="https://unpkg.com/@smartledger/bsv@7.3.0/bsv.min.js"></script>
|
|
163
163
|
|
|
164
164
|
<!-- Add smart contracts when ready -->
|
|
165
|
-
<script src="https://unpkg.com/@smartledger/bsv@7.
|
|
165
|
+
<script src="https://unpkg.com/@smartledger/bsv@7.3.0/bsv-smartcontract.min.js"></script>
|
|
166
166
|
|
|
167
167
|
<!-- Add advanced features as needed -->
|
|
168
|
-
<script src="https://unpkg.com/@smartledger/bsv@7.
|
|
169
|
-
<script src="https://unpkg.com/@smartledger/bsv@7.
|
|
168
|
+
<script src="https://unpkg.com/@smartledger/bsv@7.3.0/bsv-ltp.min.js"></script>
|
|
169
|
+
<script src="https://unpkg.com/@smartledger/bsv@7.3.0/bsv-gdaf.min.js"></script>
|
|
170
170
|
|
|
171
171
|
<!-- Everything in one file -->
|
|
172
|
-
<script src="https://unpkg.com/@smartledger/bsv@7.
|
|
172
|
+
<script src="https://unpkg.com/@smartledger/bsv@7.3.0/bsv.bundle.js"></script>
|
|
173
173
|
```
|
|
174
174
|
|
|
175
175
|
## 🔍 **Testing Your Migration**
|
package/lib/ordinals/README.md
CHANGED
|
@@ -29,7 +29,8 @@ var script = Ord.buildInscription({
|
|
|
29
29
|
})
|
|
30
30
|
var output = Ord.createInscriptionOutput({ address: ownerAddress, contentType: 'image/png', content: pngBuffer })
|
|
31
31
|
|
|
32
|
-
// Parse it back.
|
|
32
|
+
// Parse it back. `lock` is the whole script minus the envelope: the 1Sat spec allows the
|
|
33
|
+
// locking script to be prepended OR appended, and both are recovered.
|
|
33
34
|
var insc = Ord.parseInscription(script) // { contentType, content, contentText, lock }
|
|
34
35
|
Ord.isInscription(script) // true
|
|
35
36
|
|
|
@@ -40,6 +41,28 @@ var outs = Ord.batchInscriptionOutputs([
|
|
|
40
41
|
])
|
|
41
42
|
```
|
|
42
43
|
|
|
44
|
+
### Arguments are checked, because an inscription is permanent
|
|
45
|
+
|
|
46
|
+
`content` may be any data — a string or a `Buffer` of arbitrary bytes, under any MIME
|
|
47
|
+
type. What the builder will not do is guess, because every guess it used to make wrote
|
|
48
|
+
something other than what the caller asked for onto a permanent record:
|
|
49
|
+
|
|
50
|
+
| Call | Before | Now |
|
|
51
|
+
| --- | --- | --- |
|
|
52
|
+
| `content` omitted | built a valid-looking script inscribing **nothing** | throws, and names the field you passed instead (`data`, `body`, `payload`, …) |
|
|
53
|
+
| `content: {…}` or a number | inscribed `[object Object]` / `"42"` | throws; encode it yourself (`JSON.stringify`, `Buffer.from`) |
|
|
54
|
+
| `Buffer` content, no `contentType` | labelled it `text/plain` | throws — bytes carry no hint about what they are |
|
|
55
|
+
| empty `lock` | emitted an **anyone-can-spend** ordinal | throws unless you pass `allowEmptyLock: true` |
|
|
56
|
+
| both `lock` and `address` | silently used `lock` | throws — they name different owners |
|
|
57
|
+
| `satoshis: 0` | built a 0-sat output carrying no ordinal | throws; must be a positive integer |
|
|
58
|
+
|
|
59
|
+
Deliberate cases are still expressible: pass `content: ''` for an empty payload, and
|
|
60
|
+
`allowEmptyLock: true` when you are appending the envelope to a lock you supply yourself
|
|
61
|
+
(this is how the OrdLock listing carries its inline inscription).
|
|
62
|
+
|
|
63
|
+
The default `contentType` of `text/plain` still applies to **string** content, which is
|
|
64
|
+
the common case and is truthfully described by it.
|
|
65
|
+
|
|
43
66
|
## Marketplace: the OrdLock covenant
|
|
44
67
|
|
|
45
68
|
A listing locks the 1-sat ordinal behind a script with two spend paths:
|
|
@@ -90,6 +113,22 @@ var terms = Ord.parseOrdLock(script)
|
|
|
90
113
|
// }
|
|
91
114
|
```
|
|
92
115
|
|
|
116
|
+
**`parseOrdLock` verifies, it does not pattern-match.** The terms are recovered from the
|
|
117
|
+
script's shape and then checked by reconstruction: the listing is rebuilt from the recovered
|
|
118
|
+
seller / payments / inscription and must match the input byte-for-byte. A script that merely
|
|
119
|
+
wears the same arrangement of opcodes — without the `OP_PUSH_TX` covenant that actually binds
|
|
120
|
+
the payment into `hashOutputs` — is rejected. So a non-null result means the purchase branch
|
|
121
|
+
really does enforce payment, and a UI can display the price without inventing a listing that
|
|
122
|
+
does not exist.
|
|
123
|
+
|
|
124
|
+
> **Interoperability.** This is *this library's* OrdLock. Semantically it is the widely
|
|
125
|
+
> deployed ordinal-lock pattern — `hash256(destOutput ‖ payOutput ‖ trailingOutputs) ==
|
|
126
|
+
> hashOutputs` under `SIGHASH_ALL|ANYONECANPAY` — generalized to multiple payment outputs.
|
|
127
|
+
> But it is built on our audited `OP_PUSH_TX` core rather than compiled from the sCrypt
|
|
128
|
+
> `OrdinalLock` contract, so **the script bytes differ and listings are not interchangeable
|
|
129
|
+
> with that template**: `parseOrdLock` reads listings this library built, not arbitrary
|
|
130
|
+
> marketplace listings.
|
|
131
|
+
|
|
93
132
|
### Buy (purchase side)
|
|
94
133
|
|
|
95
134
|
```js
|
|
@@ -148,9 +187,26 @@ B.parseBsv20(script) // { p:'bsv-20', op:'mint', tick:'ORDI', a
|
|
|
148
187
|
B.parseBsv20('{"p":"bsv-20","op":"mint","tick":"ORDI","amt":"1"}') // also accepts JSON / objects
|
|
149
188
|
```
|
|
150
189
|
|
|
151
|
-
Builders validate their inputs
|
|
152
|
-
well-formed BSV-21 `id
|
|
153
|
-
|
|
190
|
+
Builders validate their inputs against the specification and throw on bad data: ticker ≤ 4
|
|
191
|
+
bytes, `dec` 0–18, well-formed BSV-21 `id`, and amounts that are non-negative integers
|
|
192
|
+
**within uint64** (`amt`/`max`/`lim` are "strings representing uint64" — a larger value is
|
|
193
|
+
valid JSON that indexers discard, burning the tokens). A numeric amount past
|
|
194
|
+
`Number.MAX_SAFE_INTEGER` is rejected rather than silently rounded; pass a string. `sym` and
|
|
195
|
+
`icon` must be strings — `icon` an outpoint reference (`<txid>_<vout>`), as the spec defines
|
|
196
|
+
it — so a stray object can no longer be written as the literal text `[object Object]`.
|
|
197
|
+
|
|
198
|
+
`lim: 0` is accepted and means *unlimited*, per the spec ("0 or omitted = unlimited"); only
|
|
199
|
+
`max`/`amt` must be greater than zero.
|
|
200
|
+
|
|
201
|
+
**`parseBsv20` / `isBsv20` enforce validity rather than assuming it.** The operation must be
|
|
202
|
+
one the spec defines and must carry the fields that operation requires — a `transfer` with no
|
|
203
|
+
amount and no token, an `auth` carrying `amt` (which the spec forbids), an over-uint64 amount,
|
|
204
|
+
or an unknown `op` all return `null`. Operations this library does not yet *build* are still
|
|
205
|
+
*read*: `burn`, `auth`, and `deploy+auth` parse correctly. Non-canonical amounts (leading
|
|
206
|
+
zeros) are tolerated when reading other people's payloads, though our builders always emit
|
|
207
|
+
canonical ones.
|
|
208
|
+
|
|
209
|
+
Balance tracking is an indexer concern — this module builds and reads the on-chain payloads.
|
|
154
210
|
|
|
155
211
|
## API
|
|
156
212
|
|
|
@@ -159,7 +215,7 @@ this module builds and reads the on-chain payloads.
|
|
|
159
215
|
| `buildInscription`, `createInscriptionOutput`, `batchInscriptionOutputs` | build inscription scripts / outputs |
|
|
160
216
|
| `parseInscription`, `isInscription` | read an inscription back |
|
|
161
217
|
| `buildOrdLock`, `listInscriptionOutput` | build an OrdLock listing script / 1-sat output |
|
|
162
|
-
| `parseOrdLock`, `isOrdLock` | recover a listing's seller, payments, price, inscription |
|
|
218
|
+
| `parseOrdLock`, `isOrdLock` | recover a listing's seller, payments, price, inscription — **verified**, see below |
|
|
163
219
|
| `buildListingTx` | assemble a signed listing tx (P2PKH ordinal → OrdLock) |
|
|
164
220
|
| `buildPurchaseTx` | assemble a signed purchase tx from a listing UTXO + buyer coins |
|
|
165
221
|
| `purchaseOrdLock`, `cancelOrdLock` | build unlock scripts for a spend you assemble |
|
package/lib/ordinals/bsv20.js
CHANGED
|
@@ -21,19 +21,41 @@ var inscription = require('./inscription')
|
|
|
21
21
|
var CONTENT_TYPE = 'application/bsv-20'
|
|
22
22
|
var MAX_DEC = 18
|
|
23
23
|
|
|
24
|
+
// "Amounts in BSV-21: strings representing uint64" — amt/max/lim are bounded by 2^64-1.
|
|
25
|
+
// A larger value is emitted happily by JSON but rejected by indexers, burning the tokens.
|
|
26
|
+
var MAX_UINT64 = '18446744073709551615'
|
|
27
|
+
|
|
24
28
|
/** A non-negative integer string (no sign, no decimal point). */
|
|
25
29
|
function isIntString (v) { return typeof v === 'string' && /^\d+$/.test(v) }
|
|
26
30
|
|
|
31
|
+
/** True if the CANONICAL decimal string `s` is greater than 2^64-1. */
|
|
32
|
+
function exceedsUint64 (s) {
|
|
33
|
+
return s.length > MAX_UINT64.length || (s.length === MAX_UINT64.length && s > MAX_UINT64)
|
|
34
|
+
}
|
|
35
|
+
|
|
27
36
|
/** Normalize an amount-like field to a CANONICAL non-negative integer string (no leading zeros). */
|
|
28
37
|
function normInt (v, name) {
|
|
38
|
+
var s
|
|
29
39
|
if (typeof v === 'number') {
|
|
30
40
|
if (!Number.isInteger(v) || v < 0) throw new Error(name + ' must be a non-negative integer')
|
|
31
|
-
|
|
41
|
+
// Beyond 2^53 a JS number is already an approximation, so String(v) would silently
|
|
42
|
+
// emit a *different* amount than the caller believes they passed.
|
|
43
|
+
if (v > Number.MAX_SAFE_INTEGER) {
|
|
44
|
+
throw new Error(name + ' exceeds Number.MAX_SAFE_INTEGER and would lose precision — ' +
|
|
45
|
+
'pass it as a string')
|
|
46
|
+
}
|
|
47
|
+
s = String(v)
|
|
48
|
+
} else if (isIntString(v)) {
|
|
49
|
+
// Strip leading zeros ("007" -> "7", "000" -> "0") so the emitted payload is canonical
|
|
50
|
+
// and not rejected by indexers that expect canonical decimal integers.
|
|
51
|
+
s = v.replace(/^0+(?=\d)/, '')
|
|
52
|
+
} else {
|
|
53
|
+
throw new Error(name + ' must be a non-negative integer (string or number)')
|
|
54
|
+
}
|
|
55
|
+
if (exceedsUint64(s)) {
|
|
56
|
+
throw new Error(name + ' exceeds the uint64 maximum (' + MAX_UINT64 + ')')
|
|
32
57
|
}
|
|
33
|
-
|
|
34
|
-
// and not rejected by indexers that expect canonical decimal integers.
|
|
35
|
-
if (isIntString(v)) return v.replace(/^0+(?=\d)/, '')
|
|
36
|
-
throw new Error(name + ' must be a non-negative integer (string or number)')
|
|
58
|
+
return s
|
|
37
59
|
}
|
|
38
60
|
|
|
39
61
|
/** Normalize a strictly-positive amount (mint/transfer/supply must move > 0). */
|
|
@@ -57,14 +79,39 @@ function normDec (dec) {
|
|
|
57
79
|
return String(d)
|
|
58
80
|
}
|
|
59
81
|
|
|
82
|
+
var OUTPOINT_RE = /^[0-9a-fA-F]{64}_\d+$/
|
|
83
|
+
|
|
60
84
|
/** Validate a BSV-21 token id: `<64-hex-txid>_<vout>`. */
|
|
61
85
|
function assertId (id) {
|
|
62
|
-
if (typeof id !== 'string' ||
|
|
86
|
+
if (typeof id !== 'string' || !OUTPOINT_RE.test(id)) {
|
|
63
87
|
throw new Error('id must be "<txid>_<vout>" (64-hex txid, underscore, output index)')
|
|
64
88
|
}
|
|
65
89
|
return id
|
|
66
90
|
}
|
|
67
91
|
|
|
92
|
+
/**
|
|
93
|
+
* Validate a free-text field (`sym`). Rejects non-strings rather than running them through
|
|
94
|
+
* `String()`, which wrote the literal text `[object Object]` into a permanent payload.
|
|
95
|
+
*/
|
|
96
|
+
function assertText (v, name) {
|
|
97
|
+
if (typeof v !== 'string') {
|
|
98
|
+
var t = v === null ? 'null' : Array.isArray(v) ? 'an array' : (typeof v === 'object' ? 'an ' : 'a ') + typeof v
|
|
99
|
+
throw new Error(name + ' must be a string, got ' + t)
|
|
100
|
+
}
|
|
101
|
+
if (!v.length) throw new Error(name + ' must not be empty')
|
|
102
|
+
return v
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
/** Validate `icon`, which the spec defines as an outpoint reference (`<txid>_<vout>`). */
|
|
106
|
+
function assertIcon (v) {
|
|
107
|
+
assertText(v, 'icon')
|
|
108
|
+
if (!OUTPOINT_RE.test(v)) {
|
|
109
|
+
throw new Error('icon must be an outpoint reference "<txid>_<vout>" (64-hex txid, ' +
|
|
110
|
+
'underscore, output index)')
|
|
111
|
+
}
|
|
112
|
+
return v
|
|
113
|
+
}
|
|
114
|
+
|
|
68
115
|
/** Wrap a BSV-20 JSON payload in an inscription locking script (P2PKH owner by default). */
|
|
69
116
|
function buildBsv20 (payload, params) {
|
|
70
117
|
params = params || {}
|
|
@@ -84,7 +131,9 @@ function buildBsv20 (payload, params) {
|
|
|
84
131
|
function buildDeploy (params) {
|
|
85
132
|
params = params || {}
|
|
86
133
|
var p = { p: 'bsv-20', op: 'deploy', tick: assertTick(params.tick), max: normPositive(params.max, 'max') }
|
|
87
|
-
|
|
134
|
+
// `lim` is "0 or omitted = unlimited" per the spec, so 0 is a meaningful value here and
|
|
135
|
+
// must not be rejected the way a zero `max`/`amt` is.
|
|
136
|
+
if (params.lim != null) p.lim = normInt(params.lim, 'lim')
|
|
88
137
|
if (params.dec != null) p.dec = normDec(params.dec)
|
|
89
138
|
return buildBsv20(p, params)
|
|
90
139
|
}
|
|
@@ -122,8 +171,8 @@ function buildDeployMint (params) {
|
|
|
122
171
|
params = params || {}
|
|
123
172
|
var p = { p: 'bsv-20', op: 'deploy+mint', amt: normPositive(params.amt, 'amt') }
|
|
124
173
|
if (params.dec != null) p.dec = normDec(params.dec)
|
|
125
|
-
if (params.sym != null) p.sym =
|
|
126
|
-
if (params.icon != null) p.icon =
|
|
174
|
+
if (params.sym != null) p.sym = assertText(params.sym, 'sym')
|
|
175
|
+
if (params.icon != null) p.icon = assertIcon(params.icon)
|
|
127
176
|
return buildBsv20(p, params)
|
|
128
177
|
}
|
|
129
178
|
|
|
@@ -149,10 +198,69 @@ function bodyOf (input) {
|
|
|
149
198
|
return insc ? insc.contentText : null
|
|
150
199
|
}
|
|
151
200
|
|
|
201
|
+
/**
|
|
202
|
+
* Required-field rules per operation, from the BSV-20 / BSV-21 specification.
|
|
203
|
+
*
|
|
204
|
+
* `tickOrId` means the operation must carry exactly one of `tick` (v1) or `id` (v2/BSV-21).
|
|
205
|
+
* `noAmt` marks the operations the spec says must NOT carry an `amt` at all.
|
|
206
|
+
*/
|
|
207
|
+
var OP_RULES = {
|
|
208
|
+
deploy: { need: ['tick', 'max'] },
|
|
209
|
+
mint: { need: ['amt'], tickOrId: true },
|
|
210
|
+
transfer: { need: ['amt'], tickOrId: true },
|
|
211
|
+
'deploy+mint': { need: ['amt'] },
|
|
212
|
+
'deploy+auth': { need: [], noAmt: true },
|
|
213
|
+
auth: { need: ['id'], noAmt: true },
|
|
214
|
+
burn: { need: ['id', 'amt'] }
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
/**
|
|
218
|
+
* Is `v` a uint64 amount as it may appear ON CHAIN? Leading zeros are tolerated here even
|
|
219
|
+
* though the builder emits canonical values: this reads other people's payloads, and a
|
|
220
|
+
* non-canonical amount is still an amount.
|
|
221
|
+
*/
|
|
222
|
+
function isParsedAmount (v) {
|
|
223
|
+
var s = typeof v === 'number' ? (Number.isInteger(v) && v >= 0 ? String(v) : null) : (isIntString(v) ? v : null)
|
|
224
|
+
if (s == null) return false
|
|
225
|
+
return !exceedsUint64(s.replace(/^0+(?=\d)/, ''))
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
/** Validate a parsed payload against the spec's per-operation field rules. */
|
|
229
|
+
function isValidPayload (obj) {
|
|
230
|
+
if (!obj || obj.p !== 'bsv-20' || typeof obj.op !== 'string') return false
|
|
231
|
+
var rule = OP_RULES[obj.op]
|
|
232
|
+
if (!rule) return false // unknown operation: we cannot vouch for it
|
|
233
|
+
for (var i = 0; i < rule.need.length; i++) {
|
|
234
|
+
if (obj[rule.need[i]] == null) return false
|
|
235
|
+
}
|
|
236
|
+
if (rule.tickOrId && (obj.tick == null) === (obj.id == null)) return false
|
|
237
|
+
if (rule.noAmt && obj.amt != null) return false
|
|
238
|
+
if (obj.tick != null) {
|
|
239
|
+
if (typeof obj.tick !== 'string' || !obj.tick.length || Buffer.byteLength(obj.tick, 'utf8') > 4) return false
|
|
240
|
+
}
|
|
241
|
+
if (obj.id != null && (typeof obj.id !== 'string' || !OUTPOINT_RE.test(obj.id))) return false
|
|
242
|
+
var amounts = ['amt', 'max', 'lim']
|
|
243
|
+
for (var j = 0; j < amounts.length; j++) {
|
|
244
|
+
if (obj[amounts[j]] != null && !isParsedAmount(obj[amounts[j]])) return false
|
|
245
|
+
}
|
|
246
|
+
if (obj.dec != null) {
|
|
247
|
+
var d = typeof obj.dec === 'string' ? Number(obj.dec) : obj.dec
|
|
248
|
+
if (!Number.isInteger(d) || d < 0 || d > MAX_DEC) return false
|
|
249
|
+
}
|
|
250
|
+
return true
|
|
251
|
+
}
|
|
252
|
+
|
|
152
253
|
/**
|
|
153
254
|
* Parse a BSV-20 payload from a locking script (Script/Buffer/hex), a JSON string, or an
|
|
154
255
|
* already-parsed object. Returns the payload object (with `p:'bsv-20'`) or null if the
|
|
155
256
|
* input carries no valid BSV-20 inscription.
|
|
257
|
+
*
|
|
258
|
+
* "Valid" is enforced, not assumed: the operation must be one the spec defines and must
|
|
259
|
+
* carry the fields that operation requires, with `tick`/`id`/amount/`dec` well-formed.
|
|
260
|
+
* A payload this returns is one an indexer will act on; previously any JSON object with
|
|
261
|
+
* `p: 'bsv-20'` and a string `op` was returned, including `{p:'bsv-20', op:'transfer'}`
|
|
262
|
+
* with no amount and no token — which an indexer discards.
|
|
263
|
+
*
|
|
156
264
|
* @returns {null|{ p:'bsv-20', op:string, tick?:string, id?:string, amt?:string, max?:string, lim?:string, dec?:string, sym?:string, icon?:string }}
|
|
157
265
|
*/
|
|
158
266
|
function parseBsv20 (input) {
|
|
@@ -160,14 +268,13 @@ function parseBsv20 (input) {
|
|
|
160
268
|
var body = bodyOf(input)
|
|
161
269
|
if (body == null) return null
|
|
162
270
|
var obj = (typeof body === 'object') ? body : JSON.parse(body)
|
|
163
|
-
|
|
164
|
-
return obj
|
|
271
|
+
return isValidPayload(obj) ? obj : null
|
|
165
272
|
} catch (e) {
|
|
166
273
|
return null
|
|
167
274
|
}
|
|
168
275
|
}
|
|
169
276
|
|
|
170
|
-
/** True if the input carries a valid BSV-20 inscription. */
|
|
277
|
+
/** True if the input carries a valid BSV-20 inscription (see parseBsv20 for what that means). */
|
|
171
278
|
function isBsv20 (input) { return parseBsv20(input) !== null }
|
|
172
279
|
|
|
173
280
|
module.exports = {
|