smartledger-bsv 4.1.0 → 4.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -136,9 +136,9 @@ node custom_script_signature_test.js
136
136
  ## 📦 Installation
137
137
 
138
138
  ```bash
139
- npm install smartledger-bsv@4.1.0
139
+ npm install smartledger-bsv@4.2.0
140
140
  # or
141
- npm install @smartledger/bsv@4.1.0
141
+ npm install @smartledger/bsv@4.2.0
142
142
  ```
143
143
 
144
144
  ## ✅ Verification Results
@@ -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@4.1.0/bsv-shamir.min.js`
58
+ - **CDN**: `unpkg.com/@smartledger/bsv@4.2.0/bsv-shamir.min.js`
59
59
 
60
60
  #### **🌐 Global Digital Attestation Framework - GDAF (1184KB)**
61
61
  - **Purpose**: W3C Verifiable Credentials and decentralized identity
62
62
  - **Use Cases**: Identity verification, attestations, zero-knowledge proofs
63
63
  - **Features**: DID creation, credential issuance, selective disclosure
64
- - **CDN**: `unpkg.com/@smartledger/bsv@4.1.0/bsv-gdaf.min.js`
64
+ - **CDN**: `unpkg.com/@smartledger/bsv@4.2.0/bsv-gdaf.min.js`
65
65
 
66
66
  #### **⚖️ Legal Token Protocol - LTP (1184KB)**
67
67
  - **Purpose**: Legal compliance framework for tokenized assets
68
68
  - **Use Cases**: Property rights, obligations, compliant tokenization
69
69
  - **Features**: Legal primitives, compliance checking, attestation anchoring
70
- - **CDN**: `unpkg.com/@smartledger/bsv@4.1.0/bsv-ltp.min.js`
70
+ - **CDN**: `unpkg.com/@smartledger/bsv@4.2.0/bsv-ltp.min.js`
71
71
 
72
72
  ### **2. Incorrect File Sizes in Documentation**
73
73
 
@@ -81,18 +81,18 @@ Three advanced modules totaling **~2.7MB** of functionality:
81
81
 
82
82
  | Module | Size | Use Case | CDN Link |
83
83
  |--------|------|----------|----------|
84
- | **bsv.min.js** | 937KB | Core BSV + SmartContract | `unpkg.com/@smartledger/bsv@4.1.0/bsv.min.js` |
85
- | **bsv.bundle.js** | 937KB | Everything in one file | `unpkg.com/@smartledger/bsv@4.1.0/bsv.bundle.js` |
86
- | **bsv-smartcontract.min.js** | 937KB | Covenant development | `unpkg.com/@smartledger/bsv@4.1.0/bsv-smartcontract.min.js` |
87
- | **bsv-covenant.min.js** | 913KB | Covenant operations | `unpkg.com/@smartledger/bsv@4.1.0/bsv-covenant.min.js` |
88
- | **bsv-script-helper.min.js** | 26KB | Custom script tools | `unpkg.com/@smartledger/bsv@4.1.0/bsv-script-helper.min.js` |
89
- | **bsv-security.min.js** | 26KB | Security enhancements (opt-in helpers — see README › Security) | `unpkg.com/@smartledger/bsv@4.1.0/bsv-security.min.js` |
90
- | **bsv-ecies.min.js** | 71KB | Encryption | `unpkg.com/@smartledger/bsv@4.1.0/bsv-ecies.min.js` |
91
- | **bsv-message.min.js** | 26KB | Message signing | `unpkg.com/@smartledger/bsv@4.1.0/bsv-message.min.js` |
92
- | **bsv-mnemonic.min.js** | 681KB | HD wallets | `unpkg.com/@smartledger/bsv@4.1.0/bsv-mnemonic.min.js` |
93
- | **🆕 bsv-shamir.min.js** | 432KB | **Secret sharing** | `unpkg.com/@smartledger/bsv@4.1.0/bsv-shamir.min.js` |
94
- | **🆕 bsv-gdaf.min.js** | 1184KB | **Digital attestation** | `unpkg.com/@smartledger/bsv@4.1.0/bsv-gdaf.min.js` |
95
- | **🆕 bsv-ltp.min.js** | 1184KB | **Legal tokens** | `unpkg.com/@smartledger/bsv@4.1.0/bsv-ltp.min.js` |
84
+ | **bsv.min.js** | 937KB | Core BSV + SmartContract | `unpkg.com/@smartledger/bsv@4.2.0/bsv.min.js` |
85
+ | **bsv.bundle.js** | 937KB | Everything in one file | `unpkg.com/@smartledger/bsv@4.2.0/bsv.bundle.js` |
86
+ | **bsv-smartcontract.min.js** | 937KB | Covenant development | `unpkg.com/@smartledger/bsv@4.2.0/bsv-smartcontract.min.js` |
87
+ | **bsv-covenant.min.js** | 913KB | Covenant operations | `unpkg.com/@smartledger/bsv@4.2.0/bsv-covenant.min.js` |
88
+ | **bsv-script-helper.min.js** | 26KB | Custom script tools | `unpkg.com/@smartledger/bsv@4.2.0/bsv-script-helper.min.js` |
89
+ | **bsv-security.min.js** | 26KB | Security enhancements (opt-in helpers — see README › Security) | `unpkg.com/@smartledger/bsv@4.2.0/bsv-security.min.js` |
90
+ | **bsv-ecies.min.js** | 71KB | Encryption | `unpkg.com/@smartledger/bsv@4.2.0/bsv-ecies.min.js` |
91
+ | **bsv-message.min.js** | 26KB | Message signing | `unpkg.com/@smartledger/bsv@4.2.0/bsv-message.min.js` |
92
+ | **bsv-mnemonic.min.js** | 681KB | HD wallets | `unpkg.com/@smartledger/bsv@4.2.0/bsv-mnemonic.min.js` |
93
+ | **🆕 bsv-shamir.min.js** | 432KB | **Secret sharing** | `unpkg.com/@smartledger/bsv@4.2.0/bsv-shamir.min.js` |
94
+ | **🆕 bsv-gdaf.min.js** | 1184KB | **Digital attestation** | `unpkg.com/@smartledger/bsv@4.2.0/bsv-gdaf.min.js` |
95
+ | **🆕 bsv-ltp.min.js** | 1184KB | **Legal tokens** | `unpkg.com/@smartledger/bsv@4.2.0/bsv-ltp.min.js` |
96
96
 
97
97
  ## 🎯 **Updated Usage Examples**
98
98
 
@@ -100,22 +100,22 @@ Three advanced modules totaling **~2.7MB** of functionality:
100
100
 
101
101
  #### **1. Basic Development (~963KB)**
102
102
  ```html
103
- <script src="https://unpkg.com/@smartledger/bsv@4.1.0/bsv.min.js"></script>
104
- <script src="https://unpkg.com/@smartledger/bsv@4.1.0/bsv-script-helper.min.js"></script>
103
+ <script src="https://unpkg.com/@smartledger/bsv@4.2.0/bsv.min.js"></script>
104
+ <script src="https://unpkg.com/@smartledger/bsv@4.2.0/bsv-script-helper.min.js"></script>
105
105
  ```
106
106
 
107
107
  #### **2. Smart Contract Development (~2.7MB — each bundle re-embeds core BSV)**
108
108
  ```html
109
- <script src="https://unpkg.com/@smartledger/bsv@4.1.0/bsv.min.js"></script>
110
- <script src="https://unpkg.com/@smartledger/bsv@4.1.0/bsv-covenant.min.js"></script>
111
- <script src="https://unpkg.com/@smartledger/bsv@4.1.0/bsv-smartcontract.min.js"></script>
109
+ <script src="https://unpkg.com/@smartledger/bsv@4.2.0/bsv.min.js"></script>
110
+ <script src="https://unpkg.com/@smartledger/bsv@4.2.0/bsv-covenant.min.js"></script>
111
+ <script src="https://unpkg.com/@smartledger/bsv@4.2.0/bsv-smartcontract.min.js"></script>
112
112
  ```
113
113
 
114
114
  #### **3. 🆕 Legal & Compliance Development (~3.2MB — each bundle re-embeds core BSV)**
115
115
  ```html
116
- <script src="https://unpkg.com/@smartledger/bsv@4.1.0/bsv.min.js"></script>
117
- <script src="https://unpkg.com/@smartledger/bsv@4.1.0/bsv-ltp.min.js"></script>
118
- <script src="https://unpkg.com/@smartledger/bsv@4.1.0/bsv-gdaf.min.js"></script>
116
+ <script src="https://unpkg.com/@smartledger/bsv@4.2.0/bsv.min.js"></script>
117
+ <script src="https://unpkg.com/@smartledger/bsv@4.2.0/bsv-ltp.min.js"></script>
118
+ <script src="https://unpkg.com/@smartledger/bsv@4.2.0/bsv-gdaf.min.js"></script>
119
119
  <script>
120
120
  // Legal Token Protocol
121
121
  const legalToken = bsv.createLegalToken({
@@ -132,9 +132,9 @@ Three advanced modules totaling **~2.7MB** of functionality:
132
132
 
133
133
  #### **4. 🆕 Security & Cryptography (~1.4MB)**
134
134
  ```html
135
- <script src="https://unpkg.com/@smartledger/bsv@4.1.0/bsv.min.js"></script>
136
- <script src="https://unpkg.com/@smartledger/bsv@4.1.0/bsv-security.min.js"></script>
137
- <script src="https://unpkg.com/@smartledger/bsv@4.1.0/bsv-shamir.min.js"></script>
135
+ <script src="https://unpkg.com/@smartledger/bsv@4.2.0/bsv.min.js"></script>
136
+ <script src="https://unpkg.com/@smartledger/bsv@4.2.0/bsv-security.min.js"></script>
137
+ <script src="https://unpkg.com/@smartledger/bsv@4.2.0/bsv-shamir.min.js"></script>
138
138
  <script>
139
139
  // Shamir Secret Sharing
140
140
  const shares = bsv.splitSecret('my_secret_key', 5, 3); // 5 shares, 3 needed
@@ -146,7 +146,7 @@ Three advanced modules totaling **~2.7MB** of functionality:
146
146
 
147
147
  #### **5. Everything Bundle (937KB)**
148
148
  ```html
149
- <script src="https://unpkg.com/@smartledger/bsv@4.1.0/bsv.bundle.js"></script>
149
+ <script src="https://unpkg.com/@smartledger/bsv@4.2.0/bsv.bundle.js"></script>
150
150
  <script>
151
151
  // Everything available immediately
152
152
  const shares = bsv.splitSecret('secret', 5, 3);
@@ -722,7 +722,7 @@ interface UTXO {
722
722
  <html>
723
723
  <head>
724
724
  <title>UTXO Manager Demo</title>
725
- <script src="https://cdn.jsdelivr.net/npm/@smartledger/bsv@4.1.0/bsv.min.js"></script>
725
+ <script src="https://cdn.jsdelivr.net/npm/@smartledger/bsv@4.2.0/bsv.min.js"></script>
726
726
  </head>
727
727
  <body>
728
728
  <script>
@@ -12,10 +12,10 @@ SmartLedger-BSV offers multiple installation methods to suit different developme
12
12
  npm install @smartledger/bsv
13
13
 
14
14
  # Install specific version
15
- npm install @smartledger/bsv@4.1.0
15
+ npm install @smartledger/bsv@4.2.0
16
16
 
17
17
  # Install with exact version lock
18
- npm install --save-exact @smartledger/bsv@4.1.0
18
+ npm install --save-exact @smartledger/bsv@4.2.0
19
19
  ```
20
20
 
21
21
  ### **Usage in Node.js**
@@ -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@4.1.0/bsv.min.js"></script>
51
+ <script src="https://unpkg.com/@smartledger/bsv@4.2.0/bsv.min.js"></script>
52
52
  <script>
53
53
  const privateKey = new bsv.PrivateKey();
54
54
  const address = privateKey.toAddress();
@@ -58,7 +58,7 @@ For basic Bitcoin SV operations:
58
58
  #### **Complete Bundle (937KB)**
59
59
  Everything in one file:
60
60
  ```html
61
- <script src="https://unpkg.com/@smartledger/bsv@4.1.0/bsv.bundle.js"></script>
61
+ <script src="https://unpkg.com/@smartledger/bsv@4.2.0/bsv.bundle.js"></script>
62
62
  <script>
63
63
  // All features available immediately
64
64
  const shares = bsv.splitSecret('secret', 5, 3);
@@ -71,9 +71,9 @@ Everything in one file:
71
71
 
72
72
  #### **Smart Contract Development (~2.7MB total — each bundle is self-contained and re-embeds core BSV)**
73
73
  ```html
74
- <script src="https://unpkg.com/@smartledger/bsv@4.1.0/bsv.min.js"></script>
75
- <script src="https://unpkg.com/@smartledger/bsv@4.1.0/bsv-covenant.min.js"></script>
76
- <script src="https://unpkg.com/@smartledger/bsv@4.1.0/bsv-smartcontract.min.js"></script>
74
+ <script src="https://unpkg.com/@smartledger/bsv@4.2.0/bsv.min.js"></script>
75
+ <script src="https://unpkg.com/@smartledger/bsv@4.2.0/bsv-covenant.min.js"></script>
76
+ <script src="https://unpkg.com/@smartledger/bsv@4.2.0/bsv-smartcontract.min.js"></script>
77
77
  <script>
78
78
  const covenant = bsv.SmartContract.createCovenantBuilder()
79
79
  .extractField('amount').push(50000).greaterThanOrEqual().build();
@@ -82,9 +82,9 @@ Everything in one file:
82
82
 
83
83
  #### **Legal & Identity Development (~3.2MB total — each bundle is self-contained and re-embeds core BSV)**
84
84
  ```html
85
- <script src="https://unpkg.com/@smartledger/bsv@4.1.0/bsv.min.js"></script>
86
- <script src="https://unpkg.com/@smartledger/bsv@4.1.0/bsv-ltp.min.js"></script>
87
- <script src="https://unpkg.com/@smartledger/bsv@4.1.0/bsv-gdaf.min.js"></script>
85
+ <script src="https://unpkg.com/@smartledger/bsv@4.2.0/bsv.min.js"></script>
86
+ <script src="https://unpkg.com/@smartledger/bsv@4.2.0/bsv-ltp.min.js"></script>
87
+ <script src="https://unpkg.com/@smartledger/bsv@4.2.0/bsv-gdaf.min.js"></script>
88
88
  <script>
89
89
  // Legal Token Protocol
90
90
  const propertyToken = bsv.createPropertyToken({
@@ -98,9 +98,9 @@ Everything in one file:
98
98
 
99
99
  #### **Security & Cryptography (~1.4MB total — each bundle is self-contained and re-embeds core BSV)**
100
100
  ```html
101
- <script src="https://unpkg.com/@smartledger/bsv@4.1.0/bsv.min.js"></script>
102
- <script src="https://unpkg.com/@smartledger/bsv@4.1.0/bsv-security.min.js"></script>
103
- <script src="https://unpkg.com/@smartledger/bsv@4.1.0/bsv-shamir.min.js"></script>
101
+ <script src="https://unpkg.com/@smartledger/bsv@4.2.0/bsv.min.js"></script>
102
+ <script src="https://unpkg.com/@smartledger/bsv@4.2.0/bsv-security.min.js"></script>
103
+ <script src="https://unpkg.com/@smartledger/bsv@4.2.0/bsv-shamir.min.js"></script>
104
104
  <script>
105
105
  // Threshold Cryptography
106
106
  const shares = bsv.splitSecret('my_secret_key', 5, 3);
@@ -114,18 +114,18 @@ Everything in one file:
114
114
 
115
115
  | Module | Size | Purpose | CDN Link |
116
116
  |--------|------|---------|----------|
117
- | **bsv.min.js** | 937KB | Core BSV + SmartContract | `unpkg.com/@smartledger/bsv@4.1.0/bsv.min.js` |
118
- | **bsv.bundle.js** | 937KB | Everything in one file | `unpkg.com/@smartledger/bsv@4.1.0/bsv.bundle.js` |
119
- | **bsv-smartcontract.min.js** | 937KB | Complete covenant framework | `unpkg.com/@smartledger/bsv@4.1.0/bsv-smartcontract.min.js` |
120
- | **bsv-ltp.min.js** | 1184KB | **Legal Token Protocol** | `unpkg.com/@smartledger/bsv@4.1.0/bsv-ltp.min.js` |
121
- | **bsv-gdaf.min.js** | 1184KB | **Digital Identity & Attestation** | `unpkg.com/@smartledger/bsv@4.1.0/bsv-gdaf.min.js` |
122
- | **bsv-shamir.min.js** | 432KB | **Threshold Cryptography** | `unpkg.com/@smartledger/bsv@4.1.0/bsv-shamir.min.js` |
123
- | **bsv-security.min.js** | 26KB | Security enhancements (opt-in helpers — see README › Security) | `unpkg.com/@smartledger/bsv@4.1.0/bsv-security.min.js` |
124
- | **bsv-mnemonic.min.js** | 681KB | HD wallets | `unpkg.com/@smartledger/bsv@4.1.0/bsv-mnemonic.min.js` |
125
- | **bsv-ecies.min.js** | 71KB | Encryption | `unpkg.com/@smartledger/bsv@4.1.0/bsv-ecies.min.js` |
126
- | **bsv-covenant.min.js** | 913KB | Covenant operations | `unpkg.com/@smartledger/bsv@4.1.0/bsv-covenant.min.js` |
127
- | **bsv-script-helper.min.js** | 26KB | Custom script tools | `unpkg.com/@smartledger/bsv@4.1.0/bsv-script-helper.min.js` |
128
- | **bsv-message.min.js** | 26KB | Message signing | `unpkg.com/@smartledger/bsv@4.1.0/bsv-message.min.js` |
117
+ | **bsv.min.js** | 937KB | Core BSV + SmartContract | `unpkg.com/@smartledger/bsv@4.2.0/bsv.min.js` |
118
+ | **bsv.bundle.js** | 937KB | Everything in one file | `unpkg.com/@smartledger/bsv@4.2.0/bsv.bundle.js` |
119
+ | **bsv-smartcontract.min.js** | 937KB | Complete covenant framework | `unpkg.com/@smartledger/bsv@4.2.0/bsv-smartcontract.min.js` |
120
+ | **bsv-ltp.min.js** | 1184KB | **Legal Token Protocol** | `unpkg.com/@smartledger/bsv@4.2.0/bsv-ltp.min.js` |
121
+ | **bsv-gdaf.min.js** | 1184KB | **Digital Identity & Attestation** | `unpkg.com/@smartledger/bsv@4.2.0/bsv-gdaf.min.js` |
122
+ | **bsv-shamir.min.js** | 432KB | **Threshold Cryptography** | `unpkg.com/@smartledger/bsv@4.2.0/bsv-shamir.min.js` |
123
+ | **bsv-security.min.js** | 26KB | Security enhancements (opt-in helpers — see README › Security) | `unpkg.com/@smartledger/bsv@4.2.0/bsv-security.min.js` |
124
+ | **bsv-mnemonic.min.js** | 681KB | HD wallets | `unpkg.com/@smartledger/bsv@4.2.0/bsv-mnemonic.min.js` |
125
+ | **bsv-ecies.min.js** | 71KB | Encryption | `unpkg.com/@smartledger/bsv@4.2.0/bsv-ecies.min.js` |
126
+ | **bsv-covenant.min.js** | 913KB | Covenant operations | `unpkg.com/@smartledger/bsv@4.2.0/bsv-covenant.min.js` |
127
+ | **bsv-script-helper.min.js** | 26KB | Custom script tools | `unpkg.com/@smartledger/bsv@4.2.0/bsv-script-helper.min.js` |
128
+ | **bsv-message.min.js** | 26KB | Message signing | `unpkg.com/@smartledger/bsv@4.2.0/bsv-message.min.js` |
129
129
 
130
130
  ## ⚙️ **Development Environment Setup**
131
131
 
@@ -14,10 +14,10 @@ npm install @smartledger/bsv
14
14
  ### Browser CDN (Instant)
15
15
  ```html
16
16
  <!-- Core library (937KB) -->
17
- <script src="https://unpkg.com/@smartledger/bsv@4.1.0/bsv.min.js"></script>
17
+ <script src="https://unpkg.com/@smartledger/bsv@4.2.0/bsv.min.js"></script>
18
18
 
19
19
  <!-- Everything included (937KB) -->
20
- <script src="https://unpkg.com/@smartledger/bsv@4.1.0/bsv.bundle.js"></script>
20
+ <script src="https://unpkg.com/@smartledger/bsv@4.2.0/bsv.bundle.js"></script>
21
21
  ```
22
22
 
23
23
  ## 💰 **Your First Transaction (60 seconds)**
@@ -127,19 +127,19 @@ SmartLedger-BSV offers 12 different loading options - use only what you need:
127
127
 
128
128
  ```html
129
129
  <!-- Core BSV only (937KB) -->
130
- <script src="https://unpkg.com/@smartledger/bsv@4.1.0/bsv.min.js"></script>
130
+ <script src="https://unpkg.com/@smartledger/bsv@4.2.0/bsv.min.js"></script>
131
131
 
132
132
  <!-- Smart contracts (937KB) -->
133
- <script src="https://unpkg.com/@smartledger/bsv@4.1.0/bsv-smartcontract.min.js"></script>
133
+ <script src="https://unpkg.com/@smartledger/bsv@4.2.0/bsv-smartcontract.min.js"></script>
134
134
 
135
135
  <!-- Legal tokens (1.16MB) -->
136
- <script src="https://unpkg.com/@smartledger/bsv@4.1.0/bsv-ltp.min.js"></script>
136
+ <script src="https://unpkg.com/@smartledger/bsv@4.2.0/bsv-ltp.min.js"></script>
137
137
 
138
138
  <!-- Digital identity (1.16MB) -->
139
- <script src="https://unpkg.com/@smartledger/bsv@4.1.0/bsv-gdaf.min.js"></script>
139
+ <script src="https://unpkg.com/@smartledger/bsv@4.2.0/bsv-gdaf.min.js"></script>
140
140
 
141
141
  <!-- Everything (937KB) -->
142
- <script src="https://unpkg.com/@smartledger/bsv@4.1.0/bsv.bundle.js"></script>
142
+ <script src="https://unpkg.com/@smartledger/bsv@4.2.0/bsv.bundle.js"></script>
143
143
  ```
144
144
 
145
145
  ## ⚡ **Key Advantages**
@@ -159,17 +159,17 @@ const recovered = bsv.reconstructSecret([shares[0], shares[2], shares[4]]);
159
159
  ### **New Modular Options**
160
160
  ```html
161
161
  <!-- Core compatibility (same size as bsv@1.5.6) -->
162
- <script src="https://unpkg.com/@smartledger/bsv@4.1.0/bsv.min.js"></script>
162
+ <script src="https://unpkg.com/@smartledger/bsv@4.2.0/bsv.min.js"></script>
163
163
 
164
164
  <!-- Add smart contracts when ready -->
165
- <script src="https://unpkg.com/@smartledger/bsv@4.1.0/bsv-smartcontract.min.js"></script>
165
+ <script src="https://unpkg.com/@smartledger/bsv@4.2.0/bsv-smartcontract.min.js"></script>
166
166
 
167
167
  <!-- Add advanced features as needed -->
168
- <script src="https://unpkg.com/@smartledger/bsv@4.1.0/bsv-ltp.min.js"></script>
169
- <script src="https://unpkg.com/@smartledger/bsv@4.1.0/bsv-gdaf.min.js"></script>
168
+ <script src="https://unpkg.com/@smartledger/bsv@4.2.0/bsv-ltp.min.js"></script>
169
+ <script src="https://unpkg.com/@smartledger/bsv@4.2.0/bsv-gdaf.min.js"></script>
170
170
 
171
171
  <!-- Everything in one file -->
172
- <script src="https://unpkg.com/@smartledger/bsv@4.1.0/bsv.bundle.js"></script>
172
+ <script src="https://unpkg.com/@smartledger/bsv@4.2.0/bsv.bundle.js"></script>
173
173
  ```
174
174
 
175
175
  ## 🔍 **Testing Your Migration**
@@ -0,0 +1,118 @@
1
+ 'use strict'
2
+ /**
3
+ * SmartContract covenant helpers
4
+ * ==============================
5
+ *
6
+ * Shared utilities for building and verifying custom locking scripts &
7
+ * OP_PUSH_TX covenants: a consensus-flag verify() harness, raw BIP-143 preimage
8
+ * access, signing, and fund/spend scaffolding. Used by ./pushtx, ./pels, ./token
9
+ * and ./locks.
10
+ */
11
+
12
+ var bsv = require('../..')
13
+ var BN = require('../crypto/bn')
14
+ var Hash = require('../crypto/hash')
15
+ var Signature = require('../crypto/signature')
16
+
17
+ // SIGHASH_ALL | SIGHASH_FORKID — the BSV default these covenants are built for.
18
+ var SIGHASH = Signature.SIGHASH_ALL | Signature.SIGHASH_FORKID // 0x41
19
+
20
+ // Post-Genesis consensus flags (big numbers, OP_CAT/OP_SPLIT/OP_MUL, FORKID,
21
+ // CLTV/CSV). LOW_S is intentionally omitted so the in-script OP_PUSH_TX
22
+ // signature (which may be high-S) verifies.
23
+ function flags () {
24
+ var I = bsv.Script.Interpreter
25
+ return I.SCRIPT_VERIFY_P2SH |
26
+ I.SCRIPT_VERIFY_STRICTENC |
27
+ I.SCRIPT_VERIFY_DERSIG |
28
+ I.SCRIPT_VERIFY_CHECKLOCKTIMEVERIFY |
29
+ I.SCRIPT_VERIFY_CHECKSEQUENCEVERIFY |
30
+ I.SCRIPT_ENABLE_SIGHASH_FORKID |
31
+ I.SCRIPT_ENABLE_MAGNETIC_OPCODES |
32
+ I.SCRIPT_ENABLE_MONOLITH_OPCODES
33
+ }
34
+
35
+ /**
36
+ * Opt into post-Genesis script limits (needed by OP_PUSH_TX covenants).
37
+ * Thin wrapper over Interpreter.useGenesisLimits (added in 4.1.0).
38
+ */
39
+ function enableGenesis (max) {
40
+ return bsv.Script.Interpreter.useGenesisLimits(max)
41
+ }
42
+
43
+ /**
44
+ * Verify an unlocking script against a locking script through the consensus
45
+ * interpreter. @returns {{ok:boolean, err:string}}
46
+ */
47
+ function verify (unlockingScript, lockingScript, opts) {
48
+ opts = opts || {}
49
+ var interp = new bsv.Script.Interpreter()
50
+ var ok = interp.verify(
51
+ unlockingScript,
52
+ lockingScript,
53
+ opts.tx || new bsv.Transaction(),
54
+ opts.inputIndex || 0,
55
+ opts.flags || flags(),
56
+ new BN(opts.satoshis || 0)
57
+ )
58
+ return { ok: ok, err: interp.errstr || '' }
59
+ }
60
+
61
+ /** Raw BIP-143 preimage (the serialization that is double-SHA256'd), not the digest. */
62
+ function rawPreimage (tx, inputIndex, lockingScript, satoshis, sighashType) {
63
+ return bsv.Transaction.sighash.sighashPreimage(
64
+ tx, sighashType || SIGHASH, inputIndex, lockingScript, new BN(satoshis))
65
+ }
66
+
67
+ /** Sighash digest = HASH256(rawPreimage) — useful for asserting OP_PUSH_TX linkage in JS. */
68
+ function sighashDigest (tx, inputIndex, lockingScript, satoshis, sighashType) {
69
+ return Hash.sha256sha256(rawPreimage(tx, inputIndex, lockingScript, satoshis, sighashType))
70
+ }
71
+
72
+ /** DER+sighash-byte signature over `lockingScript` for `inputIndex`. */
73
+ function signInput (tx, privateKey, inputIndex, lockingScript, satoshis, sighashType) {
74
+ sighashType = sighashType || SIGHASH
75
+ var sig = bsv.Transaction.sighash.sign(tx, privateKey, sighashType, inputIndex, lockingScript, new BN(satoshis))
76
+ return Buffer.concat([sig.toDER(), Buffer.from([sighashType])])
77
+ }
78
+
79
+ /**
80
+ * Build a funding tx paying `satoshis` into `lockingScript`, plus a spending tx
81
+ * consuming it with the supplied outputs. Returns { funding, spend }; the caller
82
+ * sets spend.inputs[0] script.
83
+ */
84
+ function fundAndSpend (lockingScript, satoshis, opts) {
85
+ opts = opts || {}
86
+ var funding = new bsv.Transaction().addOutput(
87
+ new bsv.Transaction.Output({ script: lockingScript, satoshis: satoshis }))
88
+ var spend = new bsv.Transaction()
89
+ spend.addInput(
90
+ new bsv.Transaction.Input({ prevTxId: funding.hash, outputIndex: 0, script: bsv.Script.empty() }),
91
+ lockingScript, satoshis)
92
+ if (opts.outputs) opts.outputs.forEach(function (o) { spend.addOutput(o) })
93
+ return { funding: funding, spend: spend }
94
+ }
95
+
96
+ /** A P2PKH Output object for an address or public key. */
97
+ function p2pkhOutput (addressOrPubKey, satoshis) {
98
+ var addr = addressOrPubKey.toAddress ? addressOrPubKey.toAddress() : addressOrPubKey
99
+ return new bsv.Transaction.Output({ script: bsv.Script.buildPublicKeyHashOut(addr), satoshis: satoshis })
100
+ }
101
+
102
+ /** Minimal little-endian script-number Buffer (push as data to put a number on-stack). */
103
+ function scriptNum (n) {
104
+ return new BN(n).toScriptNumBuffer()
105
+ }
106
+
107
+ module.exports = {
108
+ SIGHASH: SIGHASH,
109
+ flags: flags,
110
+ enableGenesis: enableGenesis,
111
+ verify: verify,
112
+ rawPreimage: rawPreimage,
113
+ sighashDigest: sighashDigest,
114
+ signInput: signInput,
115
+ fundAndSpend: fundAndSpend,
116
+ p2pkhOutput: p2pkhOutput,
117
+ scriptNum: scriptNum
118
+ }
@@ -36,7 +36,36 @@ var SmartContract = {
36
36
  OpcodeMap: require('./opcode_map'),
37
37
  ScriptUtils: require('./script_utils'),
38
38
  StackExaminer: require('./stack_examiner'),
39
- ScriptInterpreter: require('./script_interpreter')
39
+ ScriptInterpreter: require('./script_interpreter'),
40
+
41
+ // Interpreter-verified custom locking scripts & OP_PUSH_TX covenants (v4.2.0)
42
+ CovenantHelpers: require('./covenant_helpers'),
43
+ Locks: require('./locks'),
44
+ PushTx: require('./pushtx'),
45
+ PELS: require('./pels'),
46
+ Token: require('./token')
47
+ }
48
+
49
+ // --- Covenant convenience API (v4.2.0) ---
50
+ // Opt into post-Genesis script limits (required by OP_PUSH_TX covenants).
51
+ SmartContract.enableGenesis = function (max) {
52
+ return SmartContract.CovenantHelpers.enableGenesis(max)
53
+ }
54
+ // Verify an unlocking/locking pair through the consensus interpreter.
55
+ SmartContract.verifyScript = function (unlockingScript, lockingScript, opts) {
56
+ return SmartContract.CovenantHelpers.verify(unlockingScript, lockingScript, opts)
57
+ }
58
+ // Perpetually Enforcing Locking Script: every spend recreates the same script.
59
+ SmartContract.perpetualCovenant = function (fee) {
60
+ return SmartContract.PELS.pelsCovenant(fee)
61
+ }
62
+ // Stateful ownership token (NFT) locking script.
63
+ SmartContract.ownershipToken = function (fee, ownerHash) {
64
+ return SmartContract.Token.ownershipToken(fee, ownerHash)
65
+ }
66
+ // OP_PUSH_TX value/output covenant: coins can only go where the covenant says.
67
+ SmartContract.valueCovenant = function (expectedHashOutputs) {
68
+ return SmartContract.PushTx.valueCovenant(expectedHashOutputs)
40
69
  }
41
70
 
42
71
  // Convenience constructor methods
@@ -0,0 +1,101 @@
1
+ 'use strict'
2
+ /**
3
+ * SmartContract.Locks — basic interpreter-verified lock primitives.
4
+ * Each factory returns { lock: Script, unlock: fn, meta }.
5
+ */
6
+
7
+ var bsv = require('../..')
8
+ var Hash = require('../crypto/hash')
9
+ var H = require('./covenant_helpers')
10
+
11
+ var Script = bsv.Script
12
+ var Opcode = bsv.Opcode
13
+ var signInput = H.signInput
14
+ var n = H.scriptNum
15
+
16
+ /** Hash-lock: reveal a preimage whose SHA-256 matches a digest. */
17
+ function hashLock (secret) {
18
+ var digest = Hash.sha256(secret)
19
+ var lock = new Script().add(Opcode.OP_SHA256).add(digest).add(Opcode.OP_EQUAL)
20
+ return {
21
+ lock: lock,
22
+ meta: { name: 'hash-lock', digest: digest.toString('hex') },
23
+ unlock: function (_spend, _sats, preimage) { return new Script().add(preimage || secret) }
24
+ }
25
+ }
26
+
27
+ /** P2PKH baseline. */
28
+ function p2pkh (privateKey) {
29
+ var pub = privateKey.toPublicKey()
30
+ var lock = Script.buildPublicKeyHashOut(pub.toAddress())
31
+ return {
32
+ lock: lock,
33
+ meta: { name: 'p2pkh', address: pub.toAddress().toString() },
34
+ unlock: function (spend, sats) {
35
+ return new Script().add(signInput(spend, privateKey, 0, lock, sats)).add(pub.toBuffer())
36
+ }
37
+ }
38
+ }
39
+
40
+ /** CLTV absolute time-lock: <locktime> CLTV DROP <pk> CHECKSIG. */
41
+ function timeLockCLTV (privateKey, locktime) {
42
+ var pub = privateKey.toPublicKey()
43
+ var lock = new Script()
44
+ .add(n(locktime)).add(Opcode.OP_CHECKLOCKTIMEVERIFY).add(Opcode.OP_DROP)
45
+ .add(pub.toBuffer()).add(Opcode.OP_CHECKSIG)
46
+ return {
47
+ lock: lock,
48
+ meta: { name: 'cltv-timelock', locktime: locktime },
49
+ // Caller must set spend.nLockTime >= locktime and input sequence < 0xffffffff.
50
+ unlock: function (spend, sats) { return new Script().add(signInput(spend, privateKey, 0, lock, sats)) }
51
+ }
52
+ }
53
+
54
+ /** m-of-n multisig. */
55
+ function multisig (m, privateKeys) {
56
+ var pubs = privateKeys.map(function (k) { return k.toPublicKey() })
57
+ var lock = new Script().add(Opcode['OP_' + m])
58
+ pubs.forEach(function (p) { lock.add(p.toBuffer()) })
59
+ lock.add(Opcode['OP_' + pubs.length]).add(Opcode.OP_CHECKMULTISIG)
60
+ return {
61
+ lock: lock,
62
+ meta: { name: m + '-of-' + pubs.length + '-multisig' },
63
+ unlock: function (spend, sats, signWith) {
64
+ signWith = signWith || privateKeys.slice(0, m)
65
+ var s = new Script().add(Opcode.OP_0)
66
+ signWith.forEach(function (k) { s.add(signInput(spend, k, 0, lock, sats)) })
67
+ return s
68
+ }
69
+ }
70
+ }
71
+
72
+ /** HTLC: hash-OR-timeout. */
73
+ function htlc (opts) {
74
+ var digest = Hash.sha256(opts.secret)
75
+ var lock = new Script()
76
+ .add(Opcode.OP_IF)
77
+ .add(Opcode.OP_SHA256).add(digest).add(Opcode.OP_EQUALVERIFY)
78
+ .add(opts.receiver.toPublicKey().toBuffer()).add(Opcode.OP_CHECKSIG)
79
+ .add(Opcode.OP_ELSE)
80
+ .add(n(opts.timeout)).add(Opcode.OP_CHECKLOCKTIMEVERIFY).add(Opcode.OP_DROP)
81
+ .add(opts.sender.toPublicKey().toBuffer()).add(Opcode.OP_CHECKSIG)
82
+ .add(Opcode.OP_ENDIF)
83
+ return {
84
+ lock: lock,
85
+ meta: { name: 'htlc', digest: digest.toString('hex'), timeout: opts.timeout },
86
+ unlockClaim: function (spend, sats) {
87
+ return new Script().add(signInput(spend, opts.receiver, 0, lock, sats)).add(opts.secret).add(Opcode.OP_1)
88
+ },
89
+ unlockRefund: function (spend, sats) {
90
+ return new Script().add(signInput(spend, opts.sender, 0, lock, sats)).add(Opcode.OP_0)
91
+ }
92
+ }
93
+ }
94
+
95
+ module.exports = {
96
+ hashLock: hashLock,
97
+ p2pkh: p2pkh,
98
+ timeLockCLTV: timeLockCLTV,
99
+ multisig: multisig,
100
+ htlc: htlc
101
+ }
@@ -0,0 +1,62 @@
1
+ 'use strict'
2
+ /**
3
+ * SmartContract.PELS — a Perpetually Enforcing Locking Script (nChain WP1605).
4
+ *
5
+ * A covenant that forces every spend to recreate itself: the single output must
6
+ * pay (inputValue - fee) back into the SAME locking script. Coins never leave
7
+ * the covenant — they flow forward through identical UTXOs, shrinking by the fee.
8
+ *
9
+ * It avoids self-hash circularity by reading its own script out of the
10
+ * authenticated BIP-143 preimage's `scriptCode` field. With layout
11
+ * version(4) hashPrevouts(32) hashSequence(32) outpoint(36) = 104
12
+ * scriptCode(varint||script)
13
+ * value(8) nSequence(4) hashOutputs(32) nLockTime(4) sighash(4) = 52 (tail)
14
+ * the slice preimage[104 : len-52] is exactly the `scriptlen||script` half of a
15
+ * TxOut, so the next output is `<newValue:8-LE> || preimage[104:len-52]`.
16
+ *
17
+ * Requires post-Genesis limits (SmartContract.enableGenesis()).
18
+ */
19
+
20
+ var bsv = require('../..')
21
+ var P = require('./pushtx')
22
+ var H = require('./covenant_helpers')
23
+
24
+ var Script = bsv.Script
25
+ var Opcode = bsv.Opcode
26
+ var n = H.scriptNum
27
+
28
+ /**
29
+ * @param {number} fee satoshis deducted at each hop.
30
+ * @returns {Script} the perpetual locking script.
31
+ */
32
+ function pelsCovenant (fee) {
33
+ var s = new Script()
34
+
35
+ // 1. authenticate the pushed preimage
36
+ s.add(Opcode.OP_DUP)
37
+ P.pushTxCore(s)
38
+ s.add(Opcode.OP_VERIFY) // stack: [preimage]
39
+
40
+ // 2. scriptChunk = preimage[104 : len-52]
41
+ s.add(Opcode.OP_DUP)
42
+ s.add(n(104)).add(Opcode.OP_SPLIT).add(Opcode.OP_NIP)
43
+ s.add(Opcode.OP_SIZE).add(n(52)).add(Opcode.OP_SUB).add(Opcode.OP_SPLIT).add(Opcode.OP_DROP)
44
+
45
+ // 3. value (8B @ offsetFromEnd 52); newValue = value - fee, as 8-byte LE
46
+ s.add(Opcode.OP_OVER)
47
+ s.add(Opcode.OP_SIZE).add(n(52)).add(Opcode.OP_SUB).add(Opcode.OP_SPLIT).add(Opcode.OP_NIP)
48
+ s.add(n(8)).add(Opcode.OP_SPLIT).add(Opcode.OP_DROP)
49
+ s.add(Opcode.OP_BIN2NUM).add(n(fee)).add(Opcode.OP_SUB)
50
+ s.add(n(8)).add(Opcode.OP_NUM2BIN)
51
+
52
+ // 4. nextOutput = newValue8 || scriptChunk ; require HASH256(it) == hashOutputs
53
+ s.add(Opcode.OP_SWAP).add(Opcode.OP_CAT)
54
+ s.add(Opcode.OP_HASH256)
55
+ s.add(Opcode.OP_SWAP)
56
+ P.extractHashOutputs(s)
57
+ s.add(Opcode.OP_EQUAL)
58
+
59
+ return s
60
+ }
61
+
62
+ module.exports = { pelsCovenant: pelsCovenant }