smartledger-bsv 3.2.1 → 3.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/README.md CHANGED
@@ -1,72 +1,244 @@
1
1
  # SmartLedger-BSV
2
2
 
3
- **Advanced Bitcoin SV Library with Enterprise Covenant Framework**
3
+ **🚀 Complete Bitcoin SV Development Framework with 9 Flexible Loading Options**
4
4
 
5
- [![Version](https://img.shields.io/badge/version-3.1.1-blue.svg)](https://www.npmjs.com/package/@smartledger/bsv)
5
+ [![Version](https://img.shields.io/badge/version-3.2.1-blue.svg)](https://www.npmjs.com/package/@smartledger/bsv)
6
6
  [![License](https://img.shields.io/badge/license-MIT-green.svg)](LICENSE)
7
7
  [![BSV](https://img.shields.io/badge/BSV-Compatible-orange.svg)](https://bitcoinsv.com/)
8
- [![Covenant](https://img.shields.io/badge/Covenants-Advanced-purple.svg)](#covenant-framework)
9
-
10
- SmartLedger-BSV is a comprehensive Bitcoin SV library that provides both high-level abstractions and granular control for advanced blockchain development. Built on the foundation of BSV library with enhanced covenant capabilities, custom script framework, and enterprise-grade features.
11
-
12
- ## 🚀 Key Features
13
-
14
- ### Core Library
15
- - ✅ **Complete BSV API**: Full compatibility with BSV blockchain operations
16
- - ✅ **Ultra-Low Fees**: 0.01 sats/byte configuration (91% fee reduction)
17
- - ✅ **UTXO Management**: Advanced state management with change output handling
18
- - ✅ **CDN Distribution**: Multiple webpack bundles for web development
19
- - ✅ **NPM Ready**: Published as `smartledger-bsv` and `@smartledger/bsv`
20
-
21
- ### Advanced Covenant Framework
22
- - 🔒 **BIP143 Compliant**: Complete preimage parsing with field-by-field access
23
- - 🔒 **PUSHTX Integration**: nChain WP1605 in-script signature generation
24
- - 🔒 **PELS Support**: Perpetually Enforcing Locking Scripts
25
- - 🔒 **JavaScript-to-Script**: Write covenant logic in JavaScript, get Bitcoin Script ASM
26
- - 🔒 **Complete Opcode Mapping**: All 121 Bitcoin Script opcodes with JavaScript equivalents
27
- - 🔒 **Covenant Builder**: High-level API for rapid covenant development
28
- - 🔒 **Script Simulation**: Real-time debugging with stack visualization
29
- - 🔒 **Template Patterns**: Pre-built covenant templates for common use cases
30
- - 🔒 **Dual-Level API**: High-level abstractions + granular BSV control
31
- - 🔒 **Production Ready**: Comprehensive validation and error handling
32
-
33
- ### Custom Script Development
34
- - 🛠️ **Multi-signature Scripts**: Advanced m-of-n signature schemes
35
- - 🛠️ **Timelock Contracts**: Block height and timestamp constraints
36
- - 🛠️ **Conditional Logic**: Complex branching and validation rules
37
- - 🛠️ **Template System**: Pre-built patterns for common use cases
38
- - 🛠️ **Developer API**: Simplified interface for rapid development
39
-
40
- ## � Table of Contents
41
-
42
- - [Quick Start](#quick-start)
43
- - [Installation](#installation)
44
- - [Basic Usage](#basic-usage)
45
- - [Covenant Framework](#covenant-framework)
46
- - [Custom Scripts](#custom-scripts)
47
- - [Examples](#examples)
48
- - [Documentation](#documentation)
49
- - [API Reference](#api-reference)
50
- - [Contributing](#contributing)
51
- - [License](#license)
52
-
53
- ## ⚡ Quick Start
8
+ [![Modular](https://img.shields.io/badge/Loading-Modular-purple.svg)](#loading-options)
54
9
 
10
+ The most comprehensive and flexible Bitcoin SV library available. Choose from 9 different distribution methods: standalone modules, complete bundle, or mix-and-match approach. Perfect for everything from simple transactions to complex DeFi protocols and smart contracts.
11
+
12
+ ## 🎯 **9 Loading Options - Choose Your Approach**
13
+
14
+ | Module | Size | Use Case | CDN |
15
+ |--------|------|----------|-----|
16
+ | **bsv.min.js** | 449KB | Core BSV + SmartContract | `unpkg.com/@smartledger/bsv@3.2.1/bsv.min.js` |
17
+ | **bsv.bundle.js** | 764KB | Everything in one file | `unpkg.com/@smartledger/bsv@3.2.1/bsv.bundle.js` |
18
+ | **bsv-covenant.min.js** | 32KB | Covenant development | `unpkg.com/@smartledger/bsv@3.2.1/bsv-covenant.min.js` |
19
+ | **bsv-script-helper.min.js** | 27KB | Custom script tools | `unpkg.com/@smartledger/bsv@3.2.1/bsv-script-helper.min.js` |
20
+ | **bsv-security.min.js** | 290KB | Security enhancements | `unpkg.com/@smartledger/bsv@3.2.1/bsv-security.min.js` |
21
+ | **bsv-smartcontract.min.js** | 451KB | Debug tools | `unpkg.com/@smartledger/bsv@3.2.1/bsv-smartcontract.min.js` |
22
+ | **bsv-ecies.min.js** | 71KB | Encryption | `unpkg.com/@smartledger/bsv@3.2.1/bsv-ecies.min.js` |
23
+ | **bsv-message.min.js** | 26KB | Message signing | `unpkg.com/@smartledger/bsv@3.2.1/bsv-message.min.js` |
24
+ | **bsv-mnemonic.min.js** | 670KB | HD wallets | `unpkg.com/@smartledger/bsv@3.2.1/bsv-mnemonic.min.js` |
25
+
26
+ ## ⚡ **2-Minute Quick Start**
27
+
28
+ Get started with Bitcoin SV development in under 2 minutes:
29
+
30
+ ```bash
31
+ # Install via npm
32
+ npm install @smartledger/bsv
33
+
34
+ # Or include in HTML
35
+ <script src="https://unpkg.com/@smartledger/bsv@3.2.1/bsv.min.js"></script>
36
+ ```
37
+
38
+ **Basic Transaction (30 seconds):**
39
+ ```javascript
40
+ const bsv = require('@smartledger/bsv'); // Node.js
41
+ // const bsv = window.bsv; // Browser
42
+
43
+ // 1. Generate keys
44
+ const privateKey = new bsv.PrivateKey();
45
+ const address = privateKey.toAddress();
46
+
47
+ // 2. Create transaction
48
+ const tx = new bsv.Transaction()
49
+ .from(utxo) // Add input
50
+ .to(targetAddress, 50000) // Send 50,000 satoshis
51
+ .change(address) // Send change back
52
+ .sign(privateKey); // Sign transaction
53
+
54
+ console.log('Transaction ID:', tx.id);
55
+ ```
56
+
57
+ **Covenant Development (90 seconds):**
58
+ ```javascript
59
+ // Load covenant interface
60
+ const covenant = new bsv.CovenantInterface();
61
+
62
+ // Create covenant transaction with preimage access
63
+ const covenantTx = covenant.createCovenantTransaction({
64
+ inputs: [utxo],
65
+ outputs: [{ address: targetAddress, satoshis: 99000 }]
66
+ });
67
+
68
+ // Get BIP143 preimage for validation
69
+ const preimage = covenantTx.getPreimage(0, lockingScript, satoshis);
70
+
71
+ // Create manual signature
72
+ const signature = covenant.createSignature(tx, privateKey, 0, script, satoshis);
73
+ ```
74
+
75
+ **Next Steps:**
76
+ - 📖 [Advanced Covenant Guide](docs/ADVANCED_COVENANT_DEVELOPMENT.md)
77
+ - 🛠️ [Custom Script Development](docs/CUSTOM_SCRIPT_DEVELOPMENT.md)
78
+ - 🔧 [API Reference](#api-reference)
79
+ - 💡 [Examples Directory](examples/)
80
+
81
+ ## 🔧 **API Reference**
82
+
83
+ | Component | Method | Purpose | Example |
84
+ |-----------|--------|---------|---------|
85
+ | **Core** | `new PrivateKey()` | Generate private key | `const key = new bsv.PrivateKey()` |
86
+ | | `new Transaction()` | Create transaction | `const tx = new bsv.Transaction()` |
87
+ | | `Script.fromASM()` | Parse script | `const script = bsv.Script.fromASM('OP_DUP')` |
88
+ | **Covenant** | `CovenantInterface()` | Covenant development | `const covenant = new bsv.CovenantInterface()` |
89
+ | | `createCovenantTransaction()` | Covenant transaction | `covenant.createCovenantTransaction(config)` |
90
+ | | `getPreimage()` | BIP143 preimage | `covenant.getPreimage(tx, 0, script, sats)` |
91
+ | **Custom Scripts** | `CustomScriptHelper()` | Script utilities | `const helper = new bsv.CustomScriptHelper()` |
92
+ | | `createSignature()` | Manual signature | `helper.createSignature(tx, key, 0, script, sats)` |
93
+ | | `createMultisigScript()` | Multi-signature | `helper.createMultisigScript([pk1, pk2], 2)` |
94
+ | **Debug Tools** | `SmartContract.examineStack()` | Analyze script | `SmartContract.examineStack(script)` |
95
+ | | `interpretScript()` | Execute script | `SmartContract.interpretScript(script)` |
96
+ | | `getScriptMetrics()` | Performance data | `SmartContract.getScriptMetrics(script)` |
97
+ | **Security** | `SmartVerify.verify()` | Enhanced verification | `SmartVerify.verify(sig, hash, pubkey)` |
98
+ | | `EllipticFixed.sign()` | Secure signing | `EllipticFixed.sign(hash, privateKey)` |
99
+
100
+ > 💡 **Tip:** All methods include comprehensive error handling and validation. See [documentation links](#documentation) for detailed guides.
101
+
102
+ ## 📚 **Quick Start Examples**
103
+
104
+ ### Minimal Setup (476KB total)
105
+ ```html
106
+ <script src="https://unpkg.com/@smartledger/bsv@3.2.1/bsv.min.js"></script>
107
+ <script src="https://unpkg.com/@smartledger/bsv@3.2.1/bsv-script-helper.min.js"></script>
108
+ <script>
109
+ const privateKey = new bsv.PrivateKey();
110
+ const signature = bsvScriptHelper.createSignature(tx, privateKey, 0, script, satoshis);
111
+ </script>
112
+ ```
113
+
114
+ ### Advanced Development (932KB total)
115
+ ```html
116
+ <script src="https://unpkg.com/@smartledger/bsv@3.2.1/bsv.min.js"></script>
117
+ <script src="https://unpkg.com/@smartledger/bsv@3.2.1/bsv-covenant.min.js"></script>
118
+ <script src="https://unpkg.com/@smartledger/bsv@3.2.1/bsv-smartcontract.min.js"></script>
119
+ <script>
120
+ const covenant = new bsvCovenant.CovenantInterface();
121
+ const contractTx = covenant.createCovenantTransaction(config);
122
+ const debugInfo = SmartContract.examineStack(script);
123
+ </script>
124
+ ```
125
+
126
+ ### Everything Bundle (764KB)
127
+ ```html
128
+ <script src="https://unpkg.com/@smartledger/bsv@3.2.1/bsv.bundle.js"></script>
129
+ <script>
130
+ // Everything available immediately
131
+ const keys = bsv.SmartLedgerBundle.generateKeys();
132
+ const covenant = new bsv.CovenantInterface();
133
+ const encrypted = bsv.ECIES.encrypt(data, publicKey);
134
+ </script>
55
135
  ```
56
136
 
57
- ## 📦 Installation
137
+ ## 🎯 **Key Features**
138
+
139
+ ### Core Library
140
+ - ✅ **Complete BSV API**: Full Bitcoin SV blockchain operations → [API Reference](#api-reference)
141
+ - ✅ **SmartContract Framework**: 59+ methods for script development and debugging → [SmartContract Integration](SMARTCONTRACT_INTEGRATION.md)
142
+ - ✅ **Security Hardened**: SmartLedger elliptic curve fixes and enhanced validation → [Security Features](#smart-security)
143
+ - ✅ **Browser + Node.js**: Universal compatibility with proper polyfills → [Loading Options](#9-loading-options--choose-your-approach)
144
+ - ✅ **TypeScript Ready**: Complete type definitions included
145
+
146
+ ### Advanced Development Tools
147
+ - � **Covenant Interface**: High-level covenant development framework → [Covenant Guide](docs/ADVANCED_COVENANT_DEVELOPMENT.md)
148
+ - � **Custom Script Helper**: Simplified API for script creation and signing → [Script Development](docs/CUSTOM_SCRIPT_DEVELOPMENT.md)
149
+ - 🔒 **Debug Tools**: Script interpreter, stack examiner, metrics, and optimizer → [Debug Examples](tests/smartcontract-test.html)
150
+ - 🔒 **BIP143 Compliant**: Complete preimage parsing and manipulation → [Preimage Tools](examples/preimage/)
151
+ - 🔒 **PUSHTX Integration**: nChain techniques for advanced covenant patterns → [PUSHTX Insights](docs/pushtx-key-insights.md)
152
+
153
+ ### Flexible Architecture
154
+ - 📦 **Modular Loading**: Load only what you need → [Loading Strategy](#loading-strategy-examples)
155
+ - 📦 **Standalone Modules**: Independent security and utility modules → [Standalone Test](tests/standalone-modules-test.html)
156
+ - 📦 **Complete Bundle**: Everything in one file for convenience → [Bundle Demo](tests/bundle-demo.html)
157
+ - 📦 **CDN Ready**: All modules available via unpkg and jsDelivr
158
+ - 📦 **Webpack Optimized**: Tree-shakeable and build-tool friendly
159
+
160
+ ## ⚡ **Installation & Usage**
161
+
162
+ > 💡 **Quick Start**: Jump to [2-Minute Quick Start](#2-minute-quick-start) for instant setup examples
58
163
 
59
164
  ### NPM Installation
60
165
  ```bash
61
166
  # Main package
62
167
  npm install @smartledger/bsv
63
168
 
64
- # Alternative package name
169
+ # Alternative package name (legacy)
65
170
  npm install smartledger-bsv
66
171
  ```
67
172
 
68
- ### CDN Usage
173
+ > 📖 **Next Steps**: After installation, see [Loading Options](#9-loading-options--choose-your-approach) to choose your distribution method
174
+
175
+ ### Node.js Usage
176
+ ```javascript
177
+ const bsv = require('@smartledger/bsv');
178
+
179
+ // Basic transaction
180
+ const privateKey = new bsv.PrivateKey();
181
+ const publicKey = privateKey.toPublicKey();
182
+ const address = privateKey.toAddress();
183
+
184
+ // SmartContract debugging
185
+ const script = bsv.Script.fromASM('OP_1 OP_2 OP_ADD OP_3 OP_EQUAL');
186
+ const metrics = bsv.SmartContract.getScriptMetrics(script);
187
+ const stackInfo = bsv.SmartContract.examineStack(script);
188
+
189
+ // Covenant development
190
+ const covenant = new bsv.CovenantInterface();
191
+ const contractTx = covenant.createCovenantTransaction({
192
+ inputs: [...],
193
+ outputs: [...]
194
+ });
195
+ ```
196
+
197
+ ### Browser CDN (Choose Your Loading Strategy)
198
+
199
+ #### 1. **Minimal Setup** - Core + Script Helper (476KB)
69
200
  ```html
201
+ <script src="https://unpkg.com/@smartledger/bsv@3.2.1/bsv.min.js"></script>
202
+ <script src="https://unpkg.com/@smartledger/bsv@3.2.1/bsv-script-helper.min.js"></script>
203
+ <script>
204
+ const tx = new bsv.Transaction();
205
+ const sig = bsvScriptHelper.createSignature(tx, privateKey, 0, script, satoshis);
206
+ </script>
207
+ ```
208
+
209
+ #### 2. **DeFi Development** - Core + Covenants + Debug (932KB)
210
+ ```html
211
+ <script src="https://unpkg.com/@smartledger/bsv@3.2.1/bsv.min.js"></script>
212
+ <script src="https://unpkg.com/@smartledger/bsv@3.2.1/bsv-covenant.min.js"></script>
213
+ <script src="https://unpkg.com/@smartledger/bsv@3.2.1/bsv-smartcontract.min.js"></script>
214
+ <script>
215
+ const covenant = new bsvCovenant.CovenantInterface();
216
+ const debugInfo = SmartContract.interpretScript(script);
217
+ const optimized = SmartContract.optimizeScript(script);
218
+ </script>
219
+ ```
220
+
221
+ #### 3. **Security First** - Core + Enhanced Security (739KB)
222
+ ```html
223
+ <script src="https://unpkg.com/@smartledger/bsv@3.2.1/bsv.min.js"></script>
224
+ <script src="https://unpkg.com/@smartledger/bsv@3.2.1/bsv-security.min.js"></script>
225
+ <script>
226
+ const verified = bsvSecurity.SmartVerify.verify(signature, hash, publicKey);
227
+ const enhanced = bsvSecurity.EllipticFixed.createSignature(privateKey, hash);
228
+ </script>
229
+ ```
230
+
231
+ #### 4. **Everything Bundle** - One File Solution (764KB)
232
+ ```html
233
+ <script src="https://unpkg.com/@smartledger/bsv@3.2.1/bsv.bundle.js"></script>
234
+ <script>
235
+ // Everything available under bsv namespace
236
+ const keys = bsv.SmartLedgerBundle.generateKeys();
237
+ const covenant = new bsv.CovenantInterface();
238
+ const message = new bsv.Message('Hello BSV');
239
+ const encrypted = bsv.ECIES.encrypt('secret', publicKey);
240
+ </script>
241
+ ```
70
242
  <!-- Main library -->
71
243
  <script src="https://unpkg.com/@smartledger/bsv@latest/dist/bsv.bundle.js"></script>
72
244
 
@@ -270,20 +442,82 @@ const timelockScript = helper.createTimelockScript(
270
442
 
271
443
  ## 📄 License
272
444
 
445
+ ---
446
+
447
+ ## 📚 **Complete Documentation**
448
+
449
+ ### 🚀 **Getting Started**
450
+ - **[2-Minute Quick Start](#2-minute-quick-start)** - Get up and running fast
451
+ - **[Loading Options](#9-loading-options--choose-your-approach)** - Choose your distribution method
452
+ - **[API Reference](#api-reference)** - Quick method lookup
453
+ - **[Installation Guide](#installation)** - npm, CDN, and browser setup
454
+
455
+ ### 🎯 **Development Guides**
456
+ - **[Advanced Covenant Development](docs/ADVANCED_COVENANT_DEVELOPMENT.md)** - Complete BIP143 + PUSHTX guide
457
+ - **[Custom Script Development](docs/CUSTOM_SCRIPT_DEVELOPMENT.md)** - Multi-sig, timelock, and custom patterns
458
+ - **[Covenant Development Resolved](docs/COVENANT_DEVELOPMENT_RESOLVED.md)** - Solutions to common issues
459
+ - **[PUSHTX Key Insights](docs/pushtx-key-insights.md)** - nChain research implementation
460
+
461
+ ### 🔧 **Technical Resources**
462
+ - **[SmartContract Integration](SMARTCONTRACT_INTEGRATION.md)** - Debug tools and analysis
463
+ - **[Examples Directory](examples/)** - Working code samples
464
+ - **[Test Suite](tests/)** - Comprehensive testing examples
465
+ - **[Build System](build/)** - Webpack configurations
466
+
467
+ ### 🌐 **Loading Strategy Examples**
468
+
469
+ | **Use Case** | **Recommended Load** | **Size** | **Features** |
470
+ |--------------|---------------------|----------|--------------|
471
+ | **Simple Transactions** | `bsv.min.js` | 449KB | Core BSV + SmartContract |
472
+ | **DeFi Development** | Core + Covenant + Debug | 932KB | Advanced contracts + tools |
473
+ | **Enterprise Apps** | `bsv.bundle.js` | 764KB | Everything included |
474
+ | **Mobile/Lightweight** | Core + Script Helper | 476KB | Essential tools only |
475
+ | **Research/Analysis** | Core + SmartContract | 900KB | Full debug capabilities |
476
+
477
+ ### 🔗 **Cross-References**
478
+
479
+ **From Quick Start → Deep Dive:**
480
+ - [Basic Transaction](#2-minute-quick-start) → [Transaction API](docs/transaction.md)
481
+ - [Covenant Example](#2-minute-quick-start) → [Advanced Covenant Guide](docs/ADVANCED_COVENANT_DEVELOPMENT.md)
482
+ - [API Reference](#api-reference) → [Method Documentation](docs/)
483
+
484
+ **From Examples → Implementation:**
485
+ - [Covenant Examples](examples/covenants/) → [Production Guide](docs/ADVANCED_COVENANT_DEVELOPMENT.md#production-guidelines)
486
+ - [Script Examples](examples/scripts/) → [Custom Script Guide](docs/CUSTOM_SCRIPT_DEVELOPMENT.md)
487
+ - [Test Files](tests/) → [Integration Examples](examples/)
488
+
489
+ **From Concepts → Code:**
490
+ - [PUSHTX Theory](docs/pushtx-key-insights.md) → [Covenant Implementation](examples/covenants/advanced_covenant_demo.js)
491
+ - [Security Features](#smart-security) → [Implementation](lib/crypto/smartledger_verify.js)
492
+ - [Debug Tools](#debug-tools) → [Usage Examples](tests/smartcontract-test.html)
493
+
494
+ ### 🎓 **Learning Path**
495
+
496
+ 1. **Start**: [2-Minute Quick Start](#2-minute-quick-start)
497
+ 2. **Practice**: [Examples Directory](examples/)
498
+ 3. **Build**: [Custom Script Guide](docs/CUSTOM_SCRIPT_DEVELOPMENT.md)
499
+ 4. **Advanced**: [Covenant Development](docs/ADVANCED_COVENANT_DEVELOPMENT.md)
500
+ 5. **Deploy**: [Production Guidelines](docs/ADVANCED_COVENANT_DEVELOPMENT.md#production-guidelines)
501
+
502
+ ---
503
+
504
+ ## 📄 **License**
505
+
273
506
  This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.
274
507
 
275
- ## 🤝 Contributing
508
+ ## 🤝 **Contributing**
276
509
 
277
510
  We welcome contributions to SmartLedger-BSV! Please see our [Contributing Guide](CONTRIBUTING.md) for details.
278
511
 
279
- ## 🏢 Enterprise Support
512
+ ## 🏢 **Enterprise Support**
280
513
 
281
514
  - **GitHub**: [github.com/codenlighten/smartledger-bsv](https://github.com/codenlighten/smartledger-bsv)
282
515
  - **NPM**: [@smartledger/bsv](https://www.npmjs.com/package/@smartledger/bsv)
283
516
  - **Issues**: [GitHub Issues](https://github.com/codenlighten/smartledger-bsv/issues)
517
+ - **Documentation**: [Complete Docs](#complete-documentation)
284
518
 
285
519
  ---
286
520
 
287
- **SmartLedger-BSV v3.1.1** - *Advanced Bitcoin SV Library with Enterprise Covenant Framework*
521
+ **SmartLedger-BSV v3.2.1** - *Complete Bitcoin SV Development Framework*
288
522
 
289
- Built with ❤️ for the Bitcoin SV ecosystem
523
+ Built with ❤️ for the Bitcoin SV ecosystem • 9 Loading Options • Enterprise Ready
@@ -0,0 +1,10 @@
1
+ var bsvCovenant=function(t){var e={};function r(n){if(e[n])return e[n].exports;var o=e[n]={i:n,l:!1,exports:{}};return t[n].call(o.exports,o,o.exports,r),o.l=!0,o.exports}return r.m=t,r.c=e,r.d=function(t,e,n){r.o(t,e)||Object.defineProperty(t,e,{enumerable:!0,get:n})},r.r=function(t){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})},r.t=function(t,e){if(1&e&&(t=r(t)),8&e)return t;if(4&e&&"object"==typeof t&&t&&t.__esModule)return t;var n=Object.create(null);if(r.r(n),Object.defineProperty(n,"default",{enumerable:!0,value:t}),2&e&&"string"!=typeof t)for(var o in t)r.d(n,o,function(e){return t[e]}.bind(null,o));return n},r.n=function(t){var e=t&&t.__esModule?function(){return t.default}:function(){return t};return r.d(e,"a",e),e},r.o=function(t,e){return Object.prototype.hasOwnProperty.call(t,e)},r.p="",r(r.s=0)}([function(t,e,r){"use strict";if("undefined"==typeof bsv)throw new Error("CovenantInterface requires BSV library. Load bsv.min.js first.");const n=r(1);"undefined"!=typeof window&&(window.bsvCovenant={CovenantInterface:n,version:bsv.version||"unknown"},"undefined"!=typeof bsv&&(bsv.CovenantInterface=n),console.log("CovenantInterface standalone module loaded")),t.exports={CovenantInterface:n,version:bsv.version||"unknown"}},function(t,e,r){(function(e){const n=r(7);class o{constructor(t,e){this.tx=t,this.covenant=e,this.preimages=new Map}getPreimage(t,e,r){const n=`${t}-${e.toHex()}-${r}`;if(!this.preimages.has(n)){const o=this.covenant.getPreimage(this.tx,t,e,r);this.preimages.set(n,o)}return this.preimages.get(n)}signInput(t,e,r,o){const i=this.covenant.createSignature(this.tx,e,t,r,o),a=(new n.Script).add(i).add(e.publicKey.toBuffer());return this.tx.inputs[t].setScript(a),this}getTransaction(){return this.tx}verify(){try{return this.tx.verify()}catch(t){return console.error("Transaction validation error:",t.message),!1}}}class i{constructor(t){this.hex=t,this.buffer=e.from(t,"hex"),this.parseFields()}parseFields(){let t=0;this.nVersion=this.buffer.subarray(t,t+4),this.nVersionValue=this.buffer.readUInt32LE(t),t+=4,this.hashPrevouts=this.buffer.subarray(t,t+32),t+=32,this.hashSequence=this.buffer.subarray(t,t+32),t+=32,this.outpoint=this.buffer.subarray(t,t+36),this.prevTxId=this.buffer.subarray(t,t+32),t+=32,this.outputIndex=this.buffer.subarray(t,t+4),this.outputIndexValue=this.buffer.readUInt32LE(t),t+=4;const e=this.readVarInt(t);t+=this.getVarIntLength(e),this.scriptCode=this.buffer.subarray(t,t+e),t+=e,this.amount=this.buffer.subarray(t,t+8),this.amountValue=this.buffer.readBigUInt64LE(t),t+=8,this.nSequence=this.buffer.subarray(t,t+4),this.nSequenceValue=this.buffer.readUInt32LE(t),t+=4,this.hashOutputs=this.buffer.subarray(t,t+32),t+=32,this.nLockTime=this.buffer.subarray(t,t+4),this.nLockTimeValue=this.buffer.readUInt32LE(t),t+=4,this.sighashType=this.buffer.subarray(t,t+4),this.sighashTypeValue=this.buffer.readUInt32LE(t),t+=4,this.isValid=t===this.buffer.length&&this.buffer.length>=108}readVarInt(t){const e=this.buffer.readUInt8(t);return e<253?e:253===e?this.buffer.readUInt16LE(t+1):254===e?this.buffer.readUInt32LE(t+1):255===e?this.buffer.readBigUInt64LE(t+1):void 0}getVarIntLength(t){return t<253?1:t<=65535?3:t<=4294967295?5:9}}class a{constructor(t,e){this.isValid=t,this.message=e}toString(){return`${this.isValid?"VALID":"INVALID"}: ${this.message}`}}t.exports={CovenantInterface:class{constructor(){this.bsv=n}createCovenantTransaction(t){const e=new n.Transaction;return t.inputs&&t.inputs.forEach(t=>e.from(t)),t.outputs&&t.outputs.forEach(t=>{t.script?e.addOutput(new n.Transaction.Output({script:t.script,satoshis:t.satoshis})):e.to(t.address,t.satoshis)}),t.feePerKb&&e.feePerKb(t.feePerKb),new o(e,this)}createSignature(t,r,o,i,a,f=null){f=f||n.crypto.Signature.SIGHASH_ALL|n.crypto.Signature.SIGHASH_FORKID;const s=n.Transaction.sighash.sign(t,r,f,o,i,new n.crypto.BN(a));return e.concat([s.toDER(),e.from([f])])}getPreimage(t,e,r,o,a=null){a=a||n.crypto.Signature.SIGHASH_ALL|n.crypto.Signature.SIGHASH_FORKID;const f=n.Transaction.sighash.sighash(t,a,e,r,new n.crypto.BN(o));return new i(f)}createStateMachine(t,r,o){const i=new n.Script;i.add(e.from([r])),i.add(n.Opcode.OP_EQUAL),i.add(n.Opcode.OP_VERIFY);for(let o=0;o<t.length-1;o++)o===r&&t[o].nextStates.forEach(t=>{i.add(e.from([t])),i.add(n.Opcode.OP_EQUAL),i.add(n.Opcode.OP_IF),i.add(n.Opcode.OP_ENDIF)});return i.add(n.Opcode.OP_DUP),i.add(n.Opcode.OP_HASH160),i.add(o.toAddress().hashBuffer),i.add(n.Opcode.OP_EQUALVERIFY),i.add(n.Opcode.OP_CHECKSIG),i}createEscrow(t,r,o,i=null){const a=new n.Script;return i&&(a.add(n.Opcode.OP_IF),a.add(e.from(i.toString(16).padStart(8,"0"),"hex").reverse()),a.add(n.Opcode.OP_CHECKLOCKTIMEVERIFY),a.add(n.Opcode.OP_DROP),a.add(t.toBuffer()),a.add(n.Opcode.OP_CHECKSIG),a.add(n.Opcode.OP_ELSE)),a.add(n.Opcode.OP_2),a.add(t.toBuffer()),a.add(r.toBuffer()),a.add(o.toBuffer()),a.add(n.Opcode.OP_3),a.add(n.Opcode.OP_CHECKMULTISIG),i&&a.add(n.Opcode.OP_ENDIF),a}createTokenTransfer(t,r,o=null){const i=new n.Script;return r>0&&(i.add(n.Opcode.OP_DUP),i.add(e.from(r.toString(16),"hex")),i.add(n.Opcode.OP_GREATERTHANOREQUAL),i.add(n.Opcode.OP_VERIFY)),o&&i.add(o.toBuffer()),i.add(n.Opcode.OP_DUP),i.add(n.Opcode.OP_HASH160),i.add(t.toAddress().hashBuffer),i.add(n.Opcode.OP_EQUALVERIFY),i.add(n.Opcode.OP_CHECKSIG),i}validateCovenant(t,e,r,o){try{const i=new n.Script.Interpreter,f=n.Script.Interpreter.SCRIPT_VERIFY_P2SH|n.Script.Interpreter.SCRIPT_VERIFY_STRICTENC|n.Script.Interpreter.SCRIPT_ENABLE_SIGHASH_FORKID|n.Script.Interpreter.SCRIPT_ENABLE_MAGNETIC_OPCODES|n.Script.Interpreter.SCRIPT_ENABLE_MONOLITH_OPCODES,s=i.verify(r,o,t,e,f);return new a(s,i.errstr||"Success")}catch(t){return new a(!1,t.message)}}createAdvancedCovenant(t,e={}){const r={pushtx:this.createPushtxCovenant,perpetual:this.createPerpetualCovenant,pels:this.createPerpetualCovenant,introspection:this.createIntrospectionCovenant},n=r[t];if(!n)throw new Error(`Unknown advanced covenant type: ${t}. Available types: ${Object.keys(r).join(", ")}`);return n.call(this,e)}createPushtxCovenant(t={}){const{publicKey:r="0279be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798",enforceOutputs:o=!0,sighashType:i=65}=t,a=new n.Script;a.add(n.Opcode.OP_2DUP).add(n.Opcode.OP_HASH256).add(n.Opcode.OP_SWAP),a.add(e.from("ffffffff","hex")).add(n.Opcode.OP_CAT).add(n.Opcode.OP_SWAP).add(n.Opcode.OP_CAT),a.add(e.from("00000000","hex")).add(e.from("41000000","hex")).add(n.Opcode.OP_CAT).add(n.Opcode.OP_CAT),a.add(n.Opcode.OP_HASH256);a.add(e.from("79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798","hex")).add(n.Opcode.OP_ADD);return a.add(e.from("fffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141","hex")).add(n.Opcode.OP_MOD),this._addDERConversion(a),a.add(e.from([i])).add(n.Opcode.OP_CAT).add(e.from(r,"hex")),a.add(n.Opcode.OP_CHECKSIGVERIFY),o&&this._addOutputValidation(a,t),a}createPerpetualCovenant(t={}){const{publicKeyHash:r,feeDeduction:o=512,enforceScript:i=!0,enforceValue:a=!0}=t;if(!r)throw new Error("publicKeyHash required for perpetual covenant");const f=new n.Script;return f.add(n.Opcode.OP_2DUP).add(n.Opcode.OP_BIN2NUM),o>0&&f.add(e.from(o.toString(16).padStart(4,"0"),"hex")).add(n.Opcode.OP_SUB),f.add(e.from([8])).add(n.Opcode.OP_NUM2BIN).add(n.Opcode.OP_SWAP).add(n.Opcode.OP_CAT),f.add(n.Opcode.OP_HASH256),this._addPreimageConstruction(f,t),this._addPushtxSignature(f,t),f.add(n.Opcode.OP_SWAP).add(e.from([104])).add(n.Opcode.OP_SPLIT).add(n.Opcode.OP_NIP).add(n.Opcode.OP_SWAP).add(e.from([8])).add(n.Opcode.OP_SPLIT).add(n.Opcode.OP_SWAP).add(n.Opcode.OP_CAT),(a||i)&&f.add(n.Opcode.OP_EQUALVERIFY),f.add(n.Opcode.OP_DUP).add(n.Opcode.OP_HASH160).add(e.from(r,"hex")).add(n.Opcode.OP_EQUALVERIFY).add(n.Opcode.OP_CHECKSIG),f}createIntrospectionCovenant(t={}){const{validateInputs:r=!1,validateOutputs:o=!0,validateSequence:i=!1,validateLocktime:a=!1}=t,f=new n.Script;return this._addPushtxSignature(f,t),r&&f.add(n.Opcode.OP_DUP).add(e.from([4,36])).add(n.Opcode.OP_SPLIT).add(n.Opcode.OP_DROP),o&&f.add(n.Opcode.OP_DUP).add(e.from([100])).add(n.Opcode.OP_SPLIT).add(n.Opcode.OP_NIP).add(e.from([32])).add(n.Opcode.OP_SPLIT).add(n.Opcode.OP_DROP),f}_addDERConversion(t){t.add(n.Opcode.OP_DUP).add(e.from("7fffffffffffffffffffffffffffffff5d576e7357a4501ddfe92f46681b20a0","hex")).add(n.Opcode.OP_GREATERTHAN).add(n.Opcode.OP_IF);t.add(e.from("fffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141","hex")).add(n.Opcode.OP_SWAP).add(n.Opcode.OP_SUB),t.add(n.Opcode.OP_ENDIF),t.add(n.Opcode.OP_SIZE).add(n.Opcode.OP_DUP).add(e.from([36])).add(n.Opcode.OP_ADD).add(e.from([48])).add(n.Opcode.OP_SWAP).add(n.Opcode.OP_CAT),t.add(e.from("022079be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f8179802","hex")).add(n.Opcode.OP_CAT).add(n.Opcode.OP_SWAP).add(n.Opcode.OP_CAT).add(n.Opcode.OP_SWAP).add(n.Opcode.OP_CAT)}_addOutputValidation(t,r){const{enforceValue:o,enforceScript:i,enforceCount:a}=r;o&&t.add(n.Opcode.OP_DUP).add(e.from([8])).add(n.Opcode.OP_SPLIT),i&&t.add(n.Opcode.OP_DUP).add(n.Opcode.OP_SIZE).add(e.from([9])).add(n.Opcode.OP_SUB).add(n.Opcode.OP_SPLIT).add(n.Opcode.OP_NIP)}_addPreimageConstruction(t,r){const{version:o=1,locktime:i=0,sighashType:a=65,sequence:f=4294967295}=r;t.add(e.from(f.toString(16).padStart(8,"0"),"hex")).add(n.Opcode.OP_CAT).add(n.Opcode.OP_SWAP).add(n.Opcode.OP_CAT).add(e.from(i.toString(16).padStart(8,"0"),"hex")).add(n.Opcode.OP_CAT).add(e.from(a.toString(16).padStart(8,"0"),"hex")).add(n.Opcode.OP_CAT)}_addPushtxSignature(t,r){const{publicKey:o="0279be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798",sighashType:i=65}=r;t.add(n.Opcode.OP_HASH256);t.add(e.from("79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798","hex")).add(n.Opcode.OP_ADD);t.add(e.from("fffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141","hex")).add(n.Opcode.OP_MOD),this._addDERConversion(t),t.add(e.from([i])).add(n.Opcode.OP_CAT).add(e.from(o,"hex")).add(n.Opcode.OP_CHECKSIGVERIFY)}},CovenantTransaction:o,CovenantPreimage:i,CovenantValidation:a}}).call(this,r(2).Buffer)},function(t,e,r){"use strict";(function(t){
2
+ /*!
3
+ * The buffer module from node.js, for the browser.
4
+ *
5
+ * @author Feross Aboukhadijeh <http://feross.org>
6
+ * @license MIT
7
+ */
8
+ var n=r(4),o=r(5),i=r(6);function a(){return s.TYPED_ARRAY_SUPPORT?2147483647:1073741823}function f(t,e){if(a()<e)throw new RangeError("Invalid typed array length");return s.TYPED_ARRAY_SUPPORT?(t=new Uint8Array(e)).__proto__=s.prototype:(null===t&&(t=new s(e)),t.length=e),t}function s(t,e,r){if(!(s.TYPED_ARRAY_SUPPORT||this instanceof s))return new s(t,e,r);if("number"==typeof t){if("string"==typeof e)throw new Error("If encoding is specified then the first argument must be a string");return h(this,t)}return u(this,t,e,r)}function u(t,e,r,n){if("number"==typeof e)throw new TypeError('"value" argument must not be a number');return"undefined"!=typeof ArrayBuffer&&e instanceof ArrayBuffer?function(t,e,r,n){if(e.byteLength,r<0||e.byteLength<r)throw new RangeError("'offset' is out of bounds");if(e.byteLength<r+(n||0))throw new RangeError("'length' is out of bounds");e=void 0===r&&void 0===n?new Uint8Array(e):void 0===n?new Uint8Array(e,r):new Uint8Array(e,r,n);s.TYPED_ARRAY_SUPPORT?(t=e).__proto__=s.prototype:t=c(t,e);return t}(t,e,r,n):"string"==typeof e?function(t,e,r){"string"==typeof r&&""!==r||(r="utf8");if(!s.isEncoding(r))throw new TypeError('"encoding" must be a valid string encoding');var n=0|l(e,r),o=(t=f(t,n)).write(e,r);o!==n&&(t=t.slice(0,o));return t}(t,e,r):function(t,e){if(s.isBuffer(e)){var r=0|p(e.length);return 0===(t=f(t,r)).length||e.copy(t,0,0,r),t}if(e){if("undefined"!=typeof ArrayBuffer&&e.buffer instanceof ArrayBuffer||"length"in e)return"number"!=typeof e.length||(n=e.length)!=n?f(t,0):c(t,e);if("Buffer"===e.type&&i(e.data))return c(t,e.data)}var n;throw new TypeError("First argument must be a string, Buffer, ArrayBuffer, Array, or array-like object.")}(t,e)}function d(t){if("number"!=typeof t)throw new TypeError('"size" argument must be a number');if(t<0)throw new RangeError('"size" argument must not be negative')}function h(t,e){if(d(e),t=f(t,e<0?0:0|p(e)),!s.TYPED_ARRAY_SUPPORT)for(var r=0;r<e;++r)t[r]=0;return t}function c(t,e){var r=e.length<0?0:0|p(e.length);t=f(t,r);for(var n=0;n<r;n+=1)t[n]=255&e[n];return t}function p(t){if(t>=a())throw new RangeError("Attempt to allocate Buffer larger than maximum size: 0x"+a().toString(16)+" bytes");return 0|t}function l(t,e){if(s.isBuffer(t))return t.length;if("undefined"!=typeof ArrayBuffer&&"function"==typeof ArrayBuffer.isView&&(ArrayBuffer.isView(t)||t instanceof ArrayBuffer))return t.byteLength;"string"!=typeof t&&(t=""+t);var r=t.length;if(0===r)return 0;for(var n=!1;;)switch(e){case"ascii":case"latin1":case"binary":return r;case"utf8":case"utf-8":case void 0:return V(t).length;case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return 2*r;case"hex":return r>>>1;case"base64":return F(t).length;default:if(n)return V(t).length;e=(""+e).toLowerCase(),n=!0}}function g(t,e,r){var n=!1;if((void 0===e||e<0)&&(e=0),e>this.length)return"";if((void 0===r||r>this.length)&&(r=this.length),r<=0)return"";if((r>>>=0)<=(e>>>=0))return"";for(t||(t="utf8");;)switch(t){case"hex":return R(this,e,r);case"utf8":case"utf-8":return m(this,e,r);case"ascii":return I(this,e,r);case"latin1":case"binary":return T(this,e,r);case"base64":return S(this,e,r);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return C(this,e,r);default:if(n)throw new TypeError("Unknown encoding: "+t);t=(t+"").toLowerCase(),n=!0}}function O(t,e,r){var n=t[e];t[e]=t[r],t[r]=n}function y(t,e,r,n,o){if(0===t.length)return-1;if("string"==typeof r?(n=r,r=0):r>2147483647?r=2147483647:r<-2147483648&&(r=-2147483648),r=+r,isNaN(r)&&(r=o?0:t.length-1),r<0&&(r=t.length+r),r>=t.length){if(o)return-1;r=t.length-1}else if(r<0){if(!o)return-1;r=0}if("string"==typeof e&&(e=s.from(e,n)),s.isBuffer(e))return 0===e.length?-1:P(t,e,r,n,o);if("number"==typeof e)return e&=255,s.TYPED_ARRAY_SUPPORT&&"function"==typeof Uint8Array.prototype.indexOf?o?Uint8Array.prototype.indexOf.call(t,e,r):Uint8Array.prototype.lastIndexOf.call(t,e,r):P(t,[e],r,n,o);throw new TypeError("val must be string, number or Buffer")}function P(t,e,r,n,o){var i,a=1,f=t.length,s=e.length;if(void 0!==n&&("ucs2"===(n=String(n).toLowerCase())||"ucs-2"===n||"utf16le"===n||"utf-16le"===n)){if(t.length<2||e.length<2)return-1;a=2,f/=2,s/=2,r/=2}function u(t,e){return 1===a?t[e]:t.readUInt16BE(e*a)}if(o){var d=-1;for(i=r;i<f;i++)if(u(t,i)===u(e,-1===d?0:i-d)){if(-1===d&&(d=i),i-d+1===s)return d*a}else-1!==d&&(i-=i-d),d=-1}else for(r+s>f&&(r=f-s),i=r;i>=0;i--){for(var h=!0,c=0;c<s;c++)if(u(t,i+c)!==u(e,c)){h=!1;break}if(h)return i}return-1}function _(t,e,r,n){r=Number(r)||0;var o=t.length-r;n?(n=Number(n))>o&&(n=o):n=o;var i=e.length;if(i%2!=0)throw new TypeError("Invalid hex string");n>i/2&&(n=i/2);for(var a=0;a<n;++a){var f=parseInt(e.substr(2*a,2),16);if(isNaN(f))return a;t[r+a]=f}return a}function b(t,e,r,n){return k(V(e,t.length-r),t,r,n)}function w(t,e,r,n){return k(function(t){for(var e=[],r=0;r<t.length;++r)e.push(255&t.charCodeAt(r));return e}(e),t,r,n)}function v(t,e,r,n){return w(t,e,r,n)}function E(t,e,r,n){return k(F(e),t,r,n)}function A(t,e,r,n){return k(function(t,e){for(var r,n,o,i=[],a=0;a<t.length&&!((e-=2)<0);++a)r=t.charCodeAt(a),n=r>>8,o=r%256,i.push(o),i.push(n);return i}(e,t.length-r),t,r,n)}function S(t,e,r){return 0===e&&r===t.length?n.fromByteArray(t):n.fromByteArray(t.slice(e,r))}function m(t,e,r){r=Math.min(t.length,r);for(var n=[],o=e;o<r;){var i,a,f,s,u=t[o],d=null,h=u>239?4:u>223?3:u>191?2:1;if(o+h<=r)switch(h){case 1:u<128&&(d=u);break;case 2:128==(192&(i=t[o+1]))&&(s=(31&u)<<6|63&i)>127&&(d=s);break;case 3:i=t[o+1],a=t[o+2],128==(192&i)&&128==(192&a)&&(s=(15&u)<<12|(63&i)<<6|63&a)>2047&&(s<55296||s>57343)&&(d=s);break;case 4:i=t[o+1],a=t[o+2],f=t[o+3],128==(192&i)&&128==(192&a)&&128==(192&f)&&(s=(15&u)<<18|(63&i)<<12|(63&a)<<6|63&f)>65535&&s<1114112&&(d=s)}null===d?(d=65533,h=1):d>65535&&(d-=65536,n.push(d>>>10&1023|55296),d=56320|1023&d),n.push(d),o+=h}return function(t){var e=t.length;if(e<=4096)return String.fromCharCode.apply(String,t);var r="",n=0;for(;n<e;)r+=String.fromCharCode.apply(String,t.slice(n,n+=4096));return r}(n)}e.Buffer=s,e.SlowBuffer=function(t){+t!=t&&(t=0);return s.alloc(+t)},e.INSPECT_MAX_BYTES=50,s.TYPED_ARRAY_SUPPORT=void 0!==t.TYPED_ARRAY_SUPPORT?t.TYPED_ARRAY_SUPPORT:function(){try{var t=new Uint8Array(1);return t.__proto__={__proto__:Uint8Array.prototype,foo:function(){return 42}},42===t.foo()&&"function"==typeof t.subarray&&0===t.subarray(1,1).byteLength}catch(t){return!1}}(),e.kMaxLength=a(),s.poolSize=8192,s._augment=function(t){return t.__proto__=s.prototype,t},s.from=function(t,e,r){return u(null,t,e,r)},s.TYPED_ARRAY_SUPPORT&&(s.prototype.__proto__=Uint8Array.prototype,s.__proto__=Uint8Array,"undefined"!=typeof Symbol&&Symbol.species&&s[Symbol.species]===s&&Object.defineProperty(s,Symbol.species,{value:null,configurable:!0})),s.alloc=function(t,e,r){return function(t,e,r,n){return d(e),e<=0?f(t,e):void 0!==r?"string"==typeof n?f(t,e).fill(r,n):f(t,e).fill(r):f(t,e)}(null,t,e,r)},s.allocUnsafe=function(t){return h(null,t)},s.allocUnsafeSlow=function(t){return h(null,t)},s.isBuffer=function(t){return!(null==t||!t._isBuffer)},s.compare=function(t,e){if(!s.isBuffer(t)||!s.isBuffer(e))throw new TypeError("Arguments must be Buffers");if(t===e)return 0;for(var r=t.length,n=e.length,o=0,i=Math.min(r,n);o<i;++o)if(t[o]!==e[o]){r=t[o],n=e[o];break}return r<n?-1:n<r?1:0},s.isEncoding=function(t){switch(String(t).toLowerCase()){case"hex":case"utf8":case"utf-8":case"ascii":case"latin1":case"binary":case"base64":case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return!0;default:return!1}},s.concat=function(t,e){if(!i(t))throw new TypeError('"list" argument must be an Array of Buffers');if(0===t.length)return s.alloc(0);var r;if(void 0===e)for(e=0,r=0;r<t.length;++r)e+=t[r].length;var n=s.allocUnsafe(e),o=0;for(r=0;r<t.length;++r){var a=t[r];if(!s.isBuffer(a))throw new TypeError('"list" argument must be an Array of Buffers');a.copy(n,o),o+=a.length}return n},s.byteLength=l,s.prototype._isBuffer=!0,s.prototype.swap16=function(){var t=this.length;if(t%2!=0)throw new RangeError("Buffer size must be a multiple of 16-bits");for(var e=0;e<t;e+=2)O(this,e,e+1);return this},s.prototype.swap32=function(){var t=this.length;if(t%4!=0)throw new RangeError("Buffer size must be a multiple of 32-bits");for(var e=0;e<t;e+=4)O(this,e,e+3),O(this,e+1,e+2);return this},s.prototype.swap64=function(){var t=this.length;if(t%8!=0)throw new RangeError("Buffer size must be a multiple of 64-bits");for(var e=0;e<t;e+=8)O(this,e,e+7),O(this,e+1,e+6),O(this,e+2,e+5),O(this,e+3,e+4);return this},s.prototype.toString=function(){var t=0|this.length;return 0===t?"":0===arguments.length?m(this,0,t):g.apply(this,arguments)},s.prototype.equals=function(t){if(!s.isBuffer(t))throw new TypeError("Argument must be a Buffer");return this===t||0===s.compare(this,t)},s.prototype.inspect=function(){var t="",r=e.INSPECT_MAX_BYTES;return this.length>0&&(t=this.toString("hex",0,r).match(/.{2}/g).join(" "),this.length>r&&(t+=" ... ")),"<Buffer "+t+">"},s.prototype.compare=function(t,e,r,n,o){if(!s.isBuffer(t))throw new TypeError("Argument must be a Buffer");if(void 0===e&&(e=0),void 0===r&&(r=t?t.length:0),void 0===n&&(n=0),void 0===o&&(o=this.length),e<0||r>t.length||n<0||o>this.length)throw new RangeError("out of range index");if(n>=o&&e>=r)return 0;if(n>=o)return-1;if(e>=r)return 1;if(this===t)return 0;for(var i=(o>>>=0)-(n>>>=0),a=(r>>>=0)-(e>>>=0),f=Math.min(i,a),u=this.slice(n,o),d=t.slice(e,r),h=0;h<f;++h)if(u[h]!==d[h]){i=u[h],a=d[h];break}return i<a?-1:a<i?1:0},s.prototype.includes=function(t,e,r){return-1!==this.indexOf(t,e,r)},s.prototype.indexOf=function(t,e,r){return y(this,t,e,r,!0)},s.prototype.lastIndexOf=function(t,e,r){return y(this,t,e,r,!1)},s.prototype.write=function(t,e,r,n){if(void 0===e)n="utf8",r=this.length,e=0;else if(void 0===r&&"string"==typeof e)n=e,r=this.length,e=0;else{if(!isFinite(e))throw new Error("Buffer.write(string, encoding, offset[, length]) is no longer supported");e|=0,isFinite(r)?(r|=0,void 0===n&&(n="utf8")):(n=r,r=void 0)}var o=this.length-e;if((void 0===r||r>o)&&(r=o),t.length>0&&(r<0||e<0)||e>this.length)throw new RangeError("Attempt to write outside buffer bounds");n||(n="utf8");for(var i=!1;;)switch(n){case"hex":return _(this,t,e,r);case"utf8":case"utf-8":return b(this,t,e,r);case"ascii":return w(this,t,e,r);case"latin1":case"binary":return v(this,t,e,r);case"base64":return E(this,t,e,r);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return A(this,t,e,r);default:if(i)throw new TypeError("Unknown encoding: "+n);n=(""+n).toLowerCase(),i=!0}},s.prototype.toJSON=function(){return{type:"Buffer",data:Array.prototype.slice.call(this._arr||this,0)}};function I(t,e,r){var n="";r=Math.min(t.length,r);for(var o=e;o<r;++o)n+=String.fromCharCode(127&t[o]);return n}function T(t,e,r){var n="";r=Math.min(t.length,r);for(var o=e;o<r;++o)n+=String.fromCharCode(t[o]);return n}function R(t,e,r){var n=t.length;(!e||e<0)&&(e=0),(!r||r<0||r>n)&&(r=n);for(var o="",i=e;i<r;++i)o+=N(t[i]);return o}function C(t,e,r){for(var n=t.slice(e,r),o="",i=0;i<n.length;i+=2)o+=String.fromCharCode(n[i]+256*n[i+1]);return o}function U(t,e,r){if(t%1!=0||t<0)throw new RangeError("offset is not uint");if(t+e>r)throw new RangeError("Trying to access beyond buffer length")}function B(t,e,r,n,o,i){if(!s.isBuffer(t))throw new TypeError('"buffer" argument must be a Buffer instance');if(e>o||e<i)throw new RangeError('"value" argument is out of bounds');if(r+n>t.length)throw new RangeError("Index out of range")}function L(t,e,r,n){e<0&&(e=65535+e+1);for(var o=0,i=Math.min(t.length-r,2);o<i;++o)t[r+o]=(e&255<<8*(n?o:1-o))>>>8*(n?o:1-o)}function x(t,e,r,n){e<0&&(e=4294967295+e+1);for(var o=0,i=Math.min(t.length-r,4);o<i;++o)t[r+o]=e>>>8*(n?o:3-o)&255}function D(t,e,r,n,o,i){if(r+n>t.length)throw new RangeError("Index out of range");if(r<0)throw new RangeError("Index out of range")}function Y(t,e,r,n,i){return i||D(t,0,r,4),o.write(t,e,r,n,23,4),r+4}function M(t,e,r,n,i){return i||D(t,0,r,8),o.write(t,e,r,n,52,8),r+8}s.prototype.slice=function(t,e){var r,n=this.length;if((t=~~t)<0?(t+=n)<0&&(t=0):t>n&&(t=n),(e=void 0===e?n:~~e)<0?(e+=n)<0&&(e=0):e>n&&(e=n),e<t&&(e=t),s.TYPED_ARRAY_SUPPORT)(r=this.subarray(t,e)).__proto__=s.prototype;else{var o=e-t;r=new s(o,void 0);for(var i=0;i<o;++i)r[i]=this[i+t]}return r},s.prototype.readUIntLE=function(t,e,r){t|=0,e|=0,r||U(t,e,this.length);for(var n=this[t],o=1,i=0;++i<e&&(o*=256);)n+=this[t+i]*o;return n},s.prototype.readUIntBE=function(t,e,r){t|=0,e|=0,r||U(t,e,this.length);for(var n=this[t+--e],o=1;e>0&&(o*=256);)n+=this[t+--e]*o;return n},s.prototype.readUInt8=function(t,e){return e||U(t,1,this.length),this[t]},s.prototype.readUInt16LE=function(t,e){return e||U(t,2,this.length),this[t]|this[t+1]<<8},s.prototype.readUInt16BE=function(t,e){return e||U(t,2,this.length),this[t]<<8|this[t+1]},s.prototype.readUInt32LE=function(t,e){return e||U(t,4,this.length),(this[t]|this[t+1]<<8|this[t+2]<<16)+16777216*this[t+3]},s.prototype.readUInt32BE=function(t,e){return e||U(t,4,this.length),16777216*this[t]+(this[t+1]<<16|this[t+2]<<8|this[t+3])},s.prototype.readIntLE=function(t,e,r){t|=0,e|=0,r||U(t,e,this.length);for(var n=this[t],o=1,i=0;++i<e&&(o*=256);)n+=this[t+i]*o;return n>=(o*=128)&&(n-=Math.pow(2,8*e)),n},s.prototype.readIntBE=function(t,e,r){t|=0,e|=0,r||U(t,e,this.length);for(var n=e,o=1,i=this[t+--n];n>0&&(o*=256);)i+=this[t+--n]*o;return i>=(o*=128)&&(i-=Math.pow(2,8*e)),i},s.prototype.readInt8=function(t,e){return e||U(t,1,this.length),128&this[t]?-1*(255-this[t]+1):this[t]},s.prototype.readInt16LE=function(t,e){e||U(t,2,this.length);var r=this[t]|this[t+1]<<8;return 32768&r?4294901760|r:r},s.prototype.readInt16BE=function(t,e){e||U(t,2,this.length);var r=this[t+1]|this[t]<<8;return 32768&r?4294901760|r:r},s.prototype.readInt32LE=function(t,e){return e||U(t,4,this.length),this[t]|this[t+1]<<8|this[t+2]<<16|this[t+3]<<24},s.prototype.readInt32BE=function(t,e){return e||U(t,4,this.length),this[t]<<24|this[t+1]<<16|this[t+2]<<8|this[t+3]},s.prototype.readFloatLE=function(t,e){return e||U(t,4,this.length),o.read(this,t,!0,23,4)},s.prototype.readFloatBE=function(t,e){return e||U(t,4,this.length),o.read(this,t,!1,23,4)},s.prototype.readDoubleLE=function(t,e){return e||U(t,8,this.length),o.read(this,t,!0,52,8)},s.prototype.readDoubleBE=function(t,e){return e||U(t,8,this.length),o.read(this,t,!1,52,8)},s.prototype.writeUIntLE=function(t,e,r,n){(t=+t,e|=0,r|=0,n)||B(this,t,e,r,Math.pow(2,8*r)-1,0);var o=1,i=0;for(this[e]=255&t;++i<r&&(o*=256);)this[e+i]=t/o&255;return e+r},s.prototype.writeUIntBE=function(t,e,r,n){(t=+t,e|=0,r|=0,n)||B(this,t,e,r,Math.pow(2,8*r)-1,0);var o=r-1,i=1;for(this[e+o]=255&t;--o>=0&&(i*=256);)this[e+o]=t/i&255;return e+r},s.prototype.writeUInt8=function(t,e,r){return t=+t,e|=0,r||B(this,t,e,1,255,0),s.TYPED_ARRAY_SUPPORT||(t=Math.floor(t)),this[e]=255&t,e+1},s.prototype.writeUInt16LE=function(t,e,r){return t=+t,e|=0,r||B(this,t,e,2,65535,0),s.TYPED_ARRAY_SUPPORT?(this[e]=255&t,this[e+1]=t>>>8):L(this,t,e,!0),e+2},s.prototype.writeUInt16BE=function(t,e,r){return t=+t,e|=0,r||B(this,t,e,2,65535,0),s.TYPED_ARRAY_SUPPORT?(this[e]=t>>>8,this[e+1]=255&t):L(this,t,e,!1),e+2},s.prototype.writeUInt32LE=function(t,e,r){return t=+t,e|=0,r||B(this,t,e,4,4294967295,0),s.TYPED_ARRAY_SUPPORT?(this[e+3]=t>>>24,this[e+2]=t>>>16,this[e+1]=t>>>8,this[e]=255&t):x(this,t,e,!0),e+4},s.prototype.writeUInt32BE=function(t,e,r){return t=+t,e|=0,r||B(this,t,e,4,4294967295,0),s.TYPED_ARRAY_SUPPORT?(this[e]=t>>>24,this[e+1]=t>>>16,this[e+2]=t>>>8,this[e+3]=255&t):x(this,t,e,!1),e+4},s.prototype.writeIntLE=function(t,e,r,n){if(t=+t,e|=0,!n){var o=Math.pow(2,8*r-1);B(this,t,e,r,o-1,-o)}var i=0,a=1,f=0;for(this[e]=255&t;++i<r&&(a*=256);)t<0&&0===f&&0!==this[e+i-1]&&(f=1),this[e+i]=(t/a>>0)-f&255;return e+r},s.prototype.writeIntBE=function(t,e,r,n){if(t=+t,e|=0,!n){var o=Math.pow(2,8*r-1);B(this,t,e,r,o-1,-o)}var i=r-1,a=1,f=0;for(this[e+i]=255&t;--i>=0&&(a*=256);)t<0&&0===f&&0!==this[e+i+1]&&(f=1),this[e+i]=(t/a>>0)-f&255;return e+r},s.prototype.writeInt8=function(t,e,r){return t=+t,e|=0,r||B(this,t,e,1,127,-128),s.TYPED_ARRAY_SUPPORT||(t=Math.floor(t)),t<0&&(t=255+t+1),this[e]=255&t,e+1},s.prototype.writeInt16LE=function(t,e,r){return t=+t,e|=0,r||B(this,t,e,2,32767,-32768),s.TYPED_ARRAY_SUPPORT?(this[e]=255&t,this[e+1]=t>>>8):L(this,t,e,!0),e+2},s.prototype.writeInt16BE=function(t,e,r){return t=+t,e|=0,r||B(this,t,e,2,32767,-32768),s.TYPED_ARRAY_SUPPORT?(this[e]=t>>>8,this[e+1]=255&t):L(this,t,e,!1),e+2},s.prototype.writeInt32LE=function(t,e,r){return t=+t,e|=0,r||B(this,t,e,4,2147483647,-2147483648),s.TYPED_ARRAY_SUPPORT?(this[e]=255&t,this[e+1]=t>>>8,this[e+2]=t>>>16,this[e+3]=t>>>24):x(this,t,e,!0),e+4},s.prototype.writeInt32BE=function(t,e,r){return t=+t,e|=0,r||B(this,t,e,4,2147483647,-2147483648),t<0&&(t=4294967295+t+1),s.TYPED_ARRAY_SUPPORT?(this[e]=t>>>24,this[e+1]=t>>>16,this[e+2]=t>>>8,this[e+3]=255&t):x(this,t,e,!1),e+4},s.prototype.writeFloatLE=function(t,e,r){return Y(this,t,e,!0,r)},s.prototype.writeFloatBE=function(t,e,r){return Y(this,t,e,!1,r)},s.prototype.writeDoubleLE=function(t,e,r){return M(this,t,e,!0,r)},s.prototype.writeDoubleBE=function(t,e,r){return M(this,t,e,!1,r)},s.prototype.copy=function(t,e,r,n){if(r||(r=0),n||0===n||(n=this.length),e>=t.length&&(e=t.length),e||(e=0),n>0&&n<r&&(n=r),n===r)return 0;if(0===t.length||0===this.length)return 0;if(e<0)throw new RangeError("targetStart out of bounds");if(r<0||r>=this.length)throw new RangeError("sourceStart out of bounds");if(n<0)throw new RangeError("sourceEnd out of bounds");n>this.length&&(n=this.length),t.length-e<n-r&&(n=t.length-e+r);var o,i=n-r;if(this===t&&r<e&&e<n)for(o=i-1;o>=0;--o)t[o+e]=this[o+r];else if(i<1e3||!s.TYPED_ARRAY_SUPPORT)for(o=0;o<i;++o)t[o+e]=this[o+r];else Uint8Array.prototype.set.call(t,this.subarray(r,r+i),e);return i},s.prototype.fill=function(t,e,r,n){if("string"==typeof t){if("string"==typeof e?(n=e,e=0,r=this.length):"string"==typeof r&&(n=r,r=this.length),1===t.length){var o=t.charCodeAt(0);o<256&&(t=o)}if(void 0!==n&&"string"!=typeof n)throw new TypeError("encoding must be a string");if("string"==typeof n&&!s.isEncoding(n))throw new TypeError("Unknown encoding: "+n)}else"number"==typeof t&&(t&=255);if(e<0||this.length<e||this.length<r)throw new RangeError("Out of range index");if(r<=e)return this;var i;if(e>>>=0,r=void 0===r?this.length:r>>>0,t||(t=0),"number"==typeof t)for(i=e;i<r;++i)this[i]=t;else{var a=s.isBuffer(t)?t:V(new s(t,n).toString()),f=a.length;for(i=0;i<r-e;++i)this[i+e]=a[i%f]}return this};var H=/[^+\/0-9A-Za-z-_]/g;function N(t){return t<16?"0"+t.toString(16):t.toString(16)}function V(t,e){var r;e=e||1/0;for(var n=t.length,o=null,i=[],a=0;a<n;++a){if((r=t.charCodeAt(a))>55295&&r<57344){if(!o){if(r>56319){(e-=3)>-1&&i.push(239,191,189);continue}if(a+1===n){(e-=3)>-1&&i.push(239,191,189);continue}o=r;continue}if(r<56320){(e-=3)>-1&&i.push(239,191,189),o=r;continue}r=65536+(o-55296<<10|r-56320)}else o&&(e-=3)>-1&&i.push(239,191,189);if(o=null,r<128){if((e-=1)<0)break;i.push(r)}else if(r<2048){if((e-=2)<0)break;i.push(r>>6|192,63&r|128)}else if(r<65536){if((e-=3)<0)break;i.push(r>>12|224,r>>6&63|128,63&r|128)}else{if(!(r<1114112))throw new Error("Invalid code point");if((e-=4)<0)break;i.push(r>>18|240,r>>12&63|128,r>>6&63|128,63&r|128)}}return i}function F(t){return n.toByteArray(function(t){if((t=function(t){return t.trim?t.trim():t.replace(/^\s+|\s+$/g,"")}(t).replace(H,"")).length<2)return"";for(;t.length%4!=0;)t+="=";return t}(t))}function k(t,e,r,n){for(var o=0;o<n&&!(o+r>=e.length||o>=t.length);++o)e[o+r]=t[o];return o}}).call(this,r(3))},function(t,e){var r;r=function(){return this}();try{r=r||new Function("return this")()}catch(t){"object"==typeof window&&(r=window)}t.exports=r},function(t,e,r){"use strict";e.byteLength=function(t){var e=u(t),r=e[0],n=e[1];return 3*(r+n)/4-n},e.toByteArray=function(t){var e,r,n=u(t),a=n[0],f=n[1],s=new i(function(t,e,r){return 3*(e+r)/4-r}(0,a,f)),d=0,h=f>0?a-4:a;for(r=0;r<h;r+=4)e=o[t.charCodeAt(r)]<<18|o[t.charCodeAt(r+1)]<<12|o[t.charCodeAt(r+2)]<<6|o[t.charCodeAt(r+3)],s[d++]=e>>16&255,s[d++]=e>>8&255,s[d++]=255&e;2===f&&(e=o[t.charCodeAt(r)]<<2|o[t.charCodeAt(r+1)]>>4,s[d++]=255&e);1===f&&(e=o[t.charCodeAt(r)]<<10|o[t.charCodeAt(r+1)]<<4|o[t.charCodeAt(r+2)]>>2,s[d++]=e>>8&255,s[d++]=255&e);return s},e.fromByteArray=function(t){for(var e,r=t.length,o=r%3,i=[],a=0,f=r-o;a<f;a+=16383)i.push(d(t,a,a+16383>f?f:a+16383));1===o?(e=t[r-1],i.push(n[e>>2]+n[e<<4&63]+"==")):2===o&&(e=(t[r-2]<<8)+t[r-1],i.push(n[e>>10]+n[e>>4&63]+n[e<<2&63]+"="));return i.join("")};for(var n=[],o=[],i="undefined"!=typeof Uint8Array?Uint8Array:Array,a="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",f=0,s=a.length;f<s;++f)n[f]=a[f],o[a.charCodeAt(f)]=f;function u(t){var e=t.length;if(e%4>0)throw new Error("Invalid string. Length must be a multiple of 4");var r=t.indexOf("=");return-1===r&&(r=e),[r,r===e?0:4-r%4]}function d(t,e,r){for(var o,i,a=[],f=e;f<r;f+=3)o=(t[f]<<16&16711680)+(t[f+1]<<8&65280)+(255&t[f+2]),a.push(n[(i=o)>>18&63]+n[i>>12&63]+n[i>>6&63]+n[63&i]);return a.join("")}o["-".charCodeAt(0)]=62,o["_".charCodeAt(0)]=63},function(t,e){
9
+ /*! ieee754. BSD-3-Clause License. Feross Aboukhadijeh <https://feross.org/opensource> */
10
+ e.read=function(t,e,r,n,o){var i,a,f=8*o-n-1,s=(1<<f)-1,u=s>>1,d=-7,h=r?o-1:0,c=r?-1:1,p=t[e+h];for(h+=c,i=p&(1<<-d)-1,p>>=-d,d+=f;d>0;i=256*i+t[e+h],h+=c,d-=8);for(a=i&(1<<-d)-1,i>>=-d,d+=n;d>0;a=256*a+t[e+h],h+=c,d-=8);if(0===i)i=1-u;else{if(i===s)return a?NaN:1/0*(p?-1:1);a+=Math.pow(2,n),i-=u}return(p?-1:1)*a*Math.pow(2,i-n)},e.write=function(t,e,r,n,o,i){var a,f,s,u=8*i-o-1,d=(1<<u)-1,h=d>>1,c=23===o?Math.pow(2,-24)-Math.pow(2,-77):0,p=n?0:i-1,l=n?1:-1,g=e<0||0===e&&1/e<0?1:0;for(e=Math.abs(e),isNaN(e)||e===1/0?(f=isNaN(e)?1:0,a=d):(a=Math.floor(Math.log(e)/Math.LN2),e*(s=Math.pow(2,-a))<1&&(a--,s*=2),(e+=a+h>=1?c/s:c*Math.pow(2,1-h))*s>=2&&(a++,s/=2),a+h>=d?(f=0,a=d):a+h>=1?(f=(e*s-1)*Math.pow(2,o),a+=h):(f=e*Math.pow(2,h-1)*Math.pow(2,o),a=0));o>=8;t[r+p]=255&f,p+=l,f/=256,o-=8);for(a=a<<o|f,u+=o;u>0;t[r+p]=255&a,p+=l,a/=256,u-=8);t[r+p-l]|=128*g}},function(t,e){var r={}.toString;t.exports=Array.isArray||function(t){return"[object Array]"==r.call(t)}},function(t,e){t.exports=bsv}]);
@@ -0,0 +1,10 @@
1
+ var bsvScriptHelper=function(t){var r={};function e(n){if(r[n])return r[n].exports;var i=r[n]={i:n,l:!1,exports:{}};return t[n].call(i.exports,i,i.exports,e),i.l=!0,i.exports}return e.m=t,e.c=r,e.d=function(t,r,n){e.o(t,r)||Object.defineProperty(t,r,{enumerable:!0,get:n})},e.r=function(t){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})},e.t=function(t,r){if(1&r&&(t=e(t)),8&r)return t;if(4&r&&"object"==typeof t&&t&&t.__esModule)return t;var n=Object.create(null);if(e.r(n),Object.defineProperty(n,"default",{enumerable:!0,value:t}),2&r&&"string"!=typeof t)for(var i in t)e.d(n,i,function(r){return t[r]}.bind(null,i));return n},e.n=function(t){var r=t&&t.__esModule?function(){return t.default}:function(){return t};return e.d(r,"a",r),r},e.o=function(t,r){return Object.prototype.hasOwnProperty.call(t,r)},e.p="",e(e.s=0)}([function(t,r,e){"use strict";if("undefined"==typeof bsv)throw new Error("CustomScriptHelper requires BSV library. Load bsv.min.js first.");const n=e(1);"undefined"!=typeof window&&(window.bsvScriptHelper={CustomScriptHelper:n,createSignature:n.createSignature,verifySignature:n.verifySignature,createMultisigSignature:n.createMultisigSignature,version:bsv.version||"unknown"},"undefined"!=typeof bsv&&(bsv.CustomScriptHelper=n),console.log("CustomScriptHelper standalone module loaded")),t.exports={CustomScriptHelper:n,createSignature:n.createSignature,verifySignature:n.verifySignature,createMultisigSignature:n.createMultisigSignature,version:bsv.version||"unknown"}},function(t,r,e){(function(r){const n=e(7);class i{static createSignature(t,e,i,o,u,f=null){f=f||n.crypto.Signature.SIGHASH_ALL|n.crypto.Signature.SIGHASH_FORKID;const a=n.Transaction.sighash.sign(t,e,f,i,o,new n.crypto.BN(u));return r.concat([a.toDER(),r.from([f])])}static createMultisigScript(t,r){let e=(new n.Script).add(n.Opcode["OP_"+t]);for(const t of r)e=e.add(t.toBuffer());return e.add(n.Opcode["OP_"+r.length]).add(n.Opcode.OP_CHECKMULTISIG)}static createMultisigUnlocking(t){let r=(new n.Script).add(n.Opcode.OP_0);for(const e of t)r=r.add(e);return r}static createTimelockScript(t,e){const i=r.from(t.toString(16).padStart(8,"0"),"hex").reverse();return(new n.Script).add(i).add(n.Opcode.OP_CHECKLOCKTIMEVERIFY).add(n.Opcode.OP_DROP).add(e.toBuffer())}static createConditionalScript(t,r=null){let e=(new n.Script).add(n.Opcode.OP_IF).add(t.toBuffer());return r&&(e=e.add(n.Opcode.OP_ELSE).add(r.toBuffer())),e.add(n.Opcode.OP_ENDIF)}static createP2PKHScript(t){return(new n.Script).add(n.Opcode.OP_DUP).add(n.Opcode.OP_HASH160).add(t.toAddress().hashBuffer).add(n.Opcode.OP_EQUALVERIFY).add(n.Opcode.OP_CHECKSIG)}static createP2PKHUnlocking(t,r){return(new n.Script).add(t).add(r.toBuffer())}static getPreimage(t,r,e,i,o=null){return o=o||n.crypto.Signature.SIGHASH_ALL|n.crypto.Signature.SIGHASH_FORKID,n.Transaction.sighash.sighash(t,o,r,e,new n.crypto.BN(i))}static createDataScript(t){return"string"==typeof t&&(t=r.from(t,"utf8")),(new n.Script).add(t)}static createOpReturnScript(t){return"string"==typeof t&&(t=r.from(t,"utf8")),(new n.Script).add(n.Opcode.OP_FALSE).add(n.Opcode.OP_RETURN).add(t)}static validateTransaction(t){try{return t.verify()}catch(t){return console.error("Transaction validation error:",t.message),!1}}static validateScript(t,r,e,i){try{return(new n.Script.Interpreter).verify(t,r,e,i,n.Script.Interpreter.SCRIPT_VERIFY_P2SH|n.Script.Interpreter.SCRIPT_VERIFY_STRICTENC|n.Script.Interpreter.SCRIPT_ENABLE_SIGHASH_FORKID|n.Script.Interpreter.SCRIPT_ENABLE_MAGNETIC_OPCODES|n.Script.Interpreter.SCRIPT_ENABLE_MONOLITH_OPCODES)}catch(t){return console.error("Script validation error:",t.message),!1}}static createLowFeeTransaction(t,r,e=10){let i=(new n.Transaction).feePerKb(e);for(const r of t)i=i.from(r);for(const t of r)i=i.to(t.address,t.satoshis);return i}}i.SIGHASH_ALL=n.crypto.Signature.SIGHASH_ALL|n.crypto.Signature.SIGHASH_FORKID,i.SIGHASH_NONE=n.crypto.Signature.SIGHASH_NONE|n.crypto.Signature.SIGHASH_FORKID,i.SIGHASH_SINGLE=n.crypto.Signature.SIGHASH_SINGLE|n.crypto.Signature.SIGHASH_FORKID,t.exports=i}).call(this,e(2).Buffer)},function(t,r,e){"use strict";(function(t){
2
+ /*!
3
+ * The buffer module from node.js, for the browser.
4
+ *
5
+ * @author Feross Aboukhadijeh <http://feross.org>
6
+ * @license MIT
7
+ */
8
+ var n=e(4),i=e(5),o=e(6);function u(){return a.TYPED_ARRAY_SUPPORT?2147483647:1073741823}function f(t,r){if(u()<r)throw new RangeError("Invalid typed array length");return a.TYPED_ARRAY_SUPPORT?(t=new Uint8Array(r)).__proto__=a.prototype:(null===t&&(t=new a(r)),t.length=r),t}function a(t,r,e){if(!(a.TYPED_ARRAY_SUPPORT||this instanceof a))return new a(t,r,e);if("number"==typeof t){if("string"==typeof r)throw new Error("If encoding is specified then the first argument must be a string");return c(this,t)}return s(this,t,r,e)}function s(t,r,e,n){if("number"==typeof r)throw new TypeError('"value" argument must not be a number');return"undefined"!=typeof ArrayBuffer&&r instanceof ArrayBuffer?function(t,r,e,n){if(r.byteLength,e<0||r.byteLength<e)throw new RangeError("'offset' is out of bounds");if(r.byteLength<e+(n||0))throw new RangeError("'length' is out of bounds");r=void 0===e&&void 0===n?new Uint8Array(r):void 0===n?new Uint8Array(r,e):new Uint8Array(r,e,n);a.TYPED_ARRAY_SUPPORT?(t=r).__proto__=a.prototype:t=p(t,r);return t}(t,r,e,n):"string"==typeof r?function(t,r,e){"string"==typeof e&&""!==e||(e="utf8");if(!a.isEncoding(e))throw new TypeError('"encoding" must be a valid string encoding');var n=0|g(r,e),i=(t=f(t,n)).write(r,e);i!==n&&(t=t.slice(0,i));return t}(t,r,e):function(t,r){if(a.isBuffer(r)){var e=0|l(r.length);return 0===(t=f(t,e)).length||r.copy(t,0,0,e),t}if(r){if("undefined"!=typeof ArrayBuffer&&r.buffer instanceof ArrayBuffer||"length"in r)return"number"!=typeof r.length||(n=r.length)!=n?f(t,0):p(t,r);if("Buffer"===r.type&&o(r.data))return p(t,r.data)}var n;throw new TypeError("First argument must be a string, Buffer, ArrayBuffer, Array, or array-like object.")}(t,r)}function h(t){if("number"!=typeof t)throw new TypeError('"size" argument must be a number');if(t<0)throw new RangeError('"size" argument must not be negative')}function c(t,r){if(h(r),t=f(t,r<0?0:0|l(r)),!a.TYPED_ARRAY_SUPPORT)for(var e=0;e<r;++e)t[e]=0;return t}function p(t,r){var e=r.length<0?0:0|l(r.length);t=f(t,e);for(var n=0;n<e;n+=1)t[n]=255&r[n];return t}function l(t){if(t>=u())throw new RangeError("Attempt to allocate Buffer larger than maximum size: 0x"+u().toString(16)+" bytes");return 0|t}function g(t,r){if(a.isBuffer(t))return t.length;if("undefined"!=typeof ArrayBuffer&&"function"==typeof ArrayBuffer.isView&&(ArrayBuffer.isView(t)||t instanceof ArrayBuffer))return t.byteLength;"string"!=typeof t&&(t=""+t);var e=t.length;if(0===e)return 0;for(var n=!1;;)switch(r){case"ascii":case"latin1":case"binary":return e;case"utf8":case"utf-8":case void 0:return F(t).length;case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return 2*e;case"hex":return e>>>1;case"base64":return k(t).length;default:if(n)return F(t).length;r=(""+r).toLowerCase(),n=!0}}function d(t,r,e){var n=!1;if((void 0===r||r<0)&&(r=0),r>this.length)return"";if((void 0===e||e>this.length)&&(e=this.length),e<=0)return"";if((e>>>=0)<=(r>>>=0))return"";for(t||(t="utf8");;)switch(t){case"hex":return T(this,r,e);case"utf8":case"utf-8":return m(this,r,e);case"ascii":return I(this,r,e);case"latin1":case"binary":return O(this,r,e);case"base64":return P(this,r,e);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return B(this,r,e);default:if(n)throw new TypeError("Unknown encoding: "+t);t=(t+"").toLowerCase(),n=!0}}function y(t,r,e){var n=t[r];t[r]=t[e],t[e]=n}function w(t,r,e,n,i){if(0===t.length)return-1;if("string"==typeof e?(n=e,e=0):e>2147483647?e=2147483647:e<-2147483648&&(e=-2147483648),e=+e,isNaN(e)&&(e=i?0:t.length-1),e<0&&(e=t.length+e),e>=t.length){if(i)return-1;e=t.length-1}else if(e<0){if(!i)return-1;e=0}if("string"==typeof r&&(r=a.from(r,n)),a.isBuffer(r))return 0===r.length?-1:S(t,r,e,n,i);if("number"==typeof r)return r&=255,a.TYPED_ARRAY_SUPPORT&&"function"==typeof Uint8Array.prototype.indexOf?i?Uint8Array.prototype.indexOf.call(t,r,e):Uint8Array.prototype.lastIndexOf.call(t,r,e):S(t,[r],e,n,i);throw new TypeError("val must be string, number or Buffer")}function S(t,r,e,n,i){var o,u=1,f=t.length,a=r.length;if(void 0!==n&&("ucs2"===(n=String(n).toLowerCase())||"ucs-2"===n||"utf16le"===n||"utf-16le"===n)){if(t.length<2||r.length<2)return-1;u=2,f/=2,a/=2,e/=2}function s(t,r){return 1===u?t[r]:t.readUInt16BE(r*u)}if(i){var h=-1;for(o=e;o<f;o++)if(s(t,o)===s(r,-1===h?0:o-h)){if(-1===h&&(h=o),o-h+1===a)return h*u}else-1!==h&&(o-=o-h),h=-1}else for(e+a>f&&(e=f-a),o=e;o>=0;o--){for(var c=!0,p=0;p<a;p++)if(s(t,o+p)!==s(r,p)){c=!1;break}if(c)return o}return-1}function v(t,r,e,n){e=Number(e)||0;var i=t.length-e;n?(n=Number(n))>i&&(n=i):n=i;var o=r.length;if(o%2!=0)throw new TypeError("Invalid hex string");n>o/2&&(n=o/2);for(var u=0;u<n;++u){var f=parseInt(r.substr(2*u,2),16);if(isNaN(f))return u;t[e+u]=f}return u}function E(t,r,e,n){return G(F(r,t.length-e),t,e,n)}function _(t,r,e,n){return G(function(t){for(var r=[],e=0;e<t.length;++e)r.push(255&t.charCodeAt(e));return r}(r),t,e,n)}function A(t,r,e,n){return _(t,r,e,n)}function b(t,r,e,n){return G(k(r),t,e,n)}function R(t,r,e,n){return G(function(t,r){for(var e,n,i,o=[],u=0;u<t.length&&!((r-=2)<0);++u)e=t.charCodeAt(u),n=e>>8,i=e%256,o.push(i),o.push(n);return o}(r,t.length-e),t,e,n)}function P(t,r,e){return 0===r&&e===t.length?n.fromByteArray(t):n.fromByteArray(t.slice(r,e))}function m(t,r,e){e=Math.min(t.length,e);for(var n=[],i=r;i<e;){var o,u,f,a,s=t[i],h=null,c=s>239?4:s>223?3:s>191?2:1;if(i+c<=e)switch(c){case 1:s<128&&(h=s);break;case 2:128==(192&(o=t[i+1]))&&(a=(31&s)<<6|63&o)>127&&(h=a);break;case 3:o=t[i+1],u=t[i+2],128==(192&o)&&128==(192&u)&&(a=(15&s)<<12|(63&o)<<6|63&u)>2047&&(a<55296||a>57343)&&(h=a);break;case 4:o=t[i+1],u=t[i+2],f=t[i+3],128==(192&o)&&128==(192&u)&&128==(192&f)&&(a=(15&s)<<18|(63&o)<<12|(63&u)<<6|63&f)>65535&&a<1114112&&(h=a)}null===h?(h=65533,c=1):h>65535&&(h-=65536,n.push(h>>>10&1023|55296),h=56320|1023&h),n.push(h),i+=c}return function(t){var r=t.length;if(r<=4096)return String.fromCharCode.apply(String,t);var e="",n=0;for(;n<r;)e+=String.fromCharCode.apply(String,t.slice(n,n+=4096));return e}(n)}r.Buffer=a,r.SlowBuffer=function(t){+t!=t&&(t=0);return a.alloc(+t)},r.INSPECT_MAX_BYTES=50,a.TYPED_ARRAY_SUPPORT=void 0!==t.TYPED_ARRAY_SUPPORT?t.TYPED_ARRAY_SUPPORT:function(){try{var t=new Uint8Array(1);return t.__proto__={__proto__:Uint8Array.prototype,foo:function(){return 42}},42===t.foo()&&"function"==typeof t.subarray&&0===t.subarray(1,1).byteLength}catch(t){return!1}}(),r.kMaxLength=u(),a.poolSize=8192,a._augment=function(t){return t.__proto__=a.prototype,t},a.from=function(t,r,e){return s(null,t,r,e)},a.TYPED_ARRAY_SUPPORT&&(a.prototype.__proto__=Uint8Array.prototype,a.__proto__=Uint8Array,"undefined"!=typeof Symbol&&Symbol.species&&a[Symbol.species]===a&&Object.defineProperty(a,Symbol.species,{value:null,configurable:!0})),a.alloc=function(t,r,e){return function(t,r,e,n){return h(r),r<=0?f(t,r):void 0!==e?"string"==typeof n?f(t,r).fill(e,n):f(t,r).fill(e):f(t,r)}(null,t,r,e)},a.allocUnsafe=function(t){return c(null,t)},a.allocUnsafeSlow=function(t){return c(null,t)},a.isBuffer=function(t){return!(null==t||!t._isBuffer)},a.compare=function(t,r){if(!a.isBuffer(t)||!a.isBuffer(r))throw new TypeError("Arguments must be Buffers");if(t===r)return 0;for(var e=t.length,n=r.length,i=0,o=Math.min(e,n);i<o;++i)if(t[i]!==r[i]){e=t[i],n=r[i];break}return e<n?-1:n<e?1:0},a.isEncoding=function(t){switch(String(t).toLowerCase()){case"hex":case"utf8":case"utf-8":case"ascii":case"latin1":case"binary":case"base64":case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return!0;default:return!1}},a.concat=function(t,r){if(!o(t))throw new TypeError('"list" argument must be an Array of Buffers');if(0===t.length)return a.alloc(0);var e;if(void 0===r)for(r=0,e=0;e<t.length;++e)r+=t[e].length;var n=a.allocUnsafe(r),i=0;for(e=0;e<t.length;++e){var u=t[e];if(!a.isBuffer(u))throw new TypeError('"list" argument must be an Array of Buffers');u.copy(n,i),i+=u.length}return n},a.byteLength=g,a.prototype._isBuffer=!0,a.prototype.swap16=function(){var t=this.length;if(t%2!=0)throw new RangeError("Buffer size must be a multiple of 16-bits");for(var r=0;r<t;r+=2)y(this,r,r+1);return this},a.prototype.swap32=function(){var t=this.length;if(t%4!=0)throw new RangeError("Buffer size must be a multiple of 32-bits");for(var r=0;r<t;r+=4)y(this,r,r+3),y(this,r+1,r+2);return this},a.prototype.swap64=function(){var t=this.length;if(t%8!=0)throw new RangeError("Buffer size must be a multiple of 64-bits");for(var r=0;r<t;r+=8)y(this,r,r+7),y(this,r+1,r+6),y(this,r+2,r+5),y(this,r+3,r+4);return this},a.prototype.toString=function(){var t=0|this.length;return 0===t?"":0===arguments.length?m(this,0,t):d.apply(this,arguments)},a.prototype.equals=function(t){if(!a.isBuffer(t))throw new TypeError("Argument must be a Buffer");return this===t||0===a.compare(this,t)},a.prototype.inspect=function(){var t="",e=r.INSPECT_MAX_BYTES;return this.length>0&&(t=this.toString("hex",0,e).match(/.{2}/g).join(" "),this.length>e&&(t+=" ... ")),"<Buffer "+t+">"},a.prototype.compare=function(t,r,e,n,i){if(!a.isBuffer(t))throw new TypeError("Argument must be a Buffer");if(void 0===r&&(r=0),void 0===e&&(e=t?t.length:0),void 0===n&&(n=0),void 0===i&&(i=this.length),r<0||e>t.length||n<0||i>this.length)throw new RangeError("out of range index");if(n>=i&&r>=e)return 0;if(n>=i)return-1;if(r>=e)return 1;if(this===t)return 0;for(var o=(i>>>=0)-(n>>>=0),u=(e>>>=0)-(r>>>=0),f=Math.min(o,u),s=this.slice(n,i),h=t.slice(r,e),c=0;c<f;++c)if(s[c]!==h[c]){o=s[c],u=h[c];break}return o<u?-1:u<o?1:0},a.prototype.includes=function(t,r,e){return-1!==this.indexOf(t,r,e)},a.prototype.indexOf=function(t,r,e){return w(this,t,r,e,!0)},a.prototype.lastIndexOf=function(t,r,e){return w(this,t,r,e,!1)},a.prototype.write=function(t,r,e,n){if(void 0===r)n="utf8",e=this.length,r=0;else if(void 0===e&&"string"==typeof r)n=r,e=this.length,r=0;else{if(!isFinite(r))throw new Error("Buffer.write(string, encoding, offset[, length]) is no longer supported");r|=0,isFinite(e)?(e|=0,void 0===n&&(n="utf8")):(n=e,e=void 0)}var i=this.length-r;if((void 0===e||e>i)&&(e=i),t.length>0&&(e<0||r<0)||r>this.length)throw new RangeError("Attempt to write outside buffer bounds");n||(n="utf8");for(var o=!1;;)switch(n){case"hex":return v(this,t,r,e);case"utf8":case"utf-8":return E(this,t,r,e);case"ascii":return _(this,t,r,e);case"latin1":case"binary":return A(this,t,r,e);case"base64":return b(this,t,r,e);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return R(this,t,r,e);default:if(o)throw new TypeError("Unknown encoding: "+n);n=(""+n).toLowerCase(),o=!0}},a.prototype.toJSON=function(){return{type:"Buffer",data:Array.prototype.slice.call(this._arr||this,0)}};function I(t,r,e){var n="";e=Math.min(t.length,e);for(var i=r;i<e;++i)n+=String.fromCharCode(127&t[i]);return n}function O(t,r,e){var n="";e=Math.min(t.length,e);for(var i=r;i<e;++i)n+=String.fromCharCode(t[i]);return n}function T(t,r,e){var n=t.length;(!r||r<0)&&(r=0),(!e||e<0||e>n)&&(e=n);for(var i="",o=r;o<e;++o)i+=N(t[o]);return i}function B(t,r,e){for(var n=t.slice(r,e),i="",o=0;o<n.length;o+=2)i+=String.fromCharCode(n[o]+256*n[o+1]);return i}function U(t,r,e){if(t%1!=0||t<0)throw new RangeError("offset is not uint");if(t+r>e)throw new RangeError("Trying to access beyond buffer length")}function C(t,r,e,n,i,o){if(!a.isBuffer(t))throw new TypeError('"buffer" argument must be a Buffer instance');if(r>i||r<o)throw new RangeError('"value" argument is out of bounds');if(e+n>t.length)throw new RangeError("Index out of range")}function L(t,r,e,n){r<0&&(r=65535+r+1);for(var i=0,o=Math.min(t.length-e,2);i<o;++i)t[e+i]=(r&255<<8*(n?i:1-i))>>>8*(n?i:1-i)}function Y(t,r,e,n){r<0&&(r=4294967295+r+1);for(var i=0,o=Math.min(t.length-e,4);i<o;++i)t[e+i]=r>>>8*(n?i:3-i)&255}function M(t,r,e,n,i,o){if(e+n>t.length)throw new RangeError("Index out of range");if(e<0)throw new RangeError("Index out of range")}function H(t,r,e,n,o){return o||M(t,0,e,4),i.write(t,r,e,n,23,4),e+4}function D(t,r,e,n,o){return o||M(t,0,e,8),i.write(t,r,e,n,52,8),e+8}a.prototype.slice=function(t,r){var e,n=this.length;if((t=~~t)<0?(t+=n)<0&&(t=0):t>n&&(t=n),(r=void 0===r?n:~~r)<0?(r+=n)<0&&(r=0):r>n&&(r=n),r<t&&(r=t),a.TYPED_ARRAY_SUPPORT)(e=this.subarray(t,r)).__proto__=a.prototype;else{var i=r-t;e=new a(i,void 0);for(var o=0;o<i;++o)e[o]=this[o+t]}return e},a.prototype.readUIntLE=function(t,r,e){t|=0,r|=0,e||U(t,r,this.length);for(var n=this[t],i=1,o=0;++o<r&&(i*=256);)n+=this[t+o]*i;return n},a.prototype.readUIntBE=function(t,r,e){t|=0,r|=0,e||U(t,r,this.length);for(var n=this[t+--r],i=1;r>0&&(i*=256);)n+=this[t+--r]*i;return n},a.prototype.readUInt8=function(t,r){return r||U(t,1,this.length),this[t]},a.prototype.readUInt16LE=function(t,r){return r||U(t,2,this.length),this[t]|this[t+1]<<8},a.prototype.readUInt16BE=function(t,r){return r||U(t,2,this.length),this[t]<<8|this[t+1]},a.prototype.readUInt32LE=function(t,r){return r||U(t,4,this.length),(this[t]|this[t+1]<<8|this[t+2]<<16)+16777216*this[t+3]},a.prototype.readUInt32BE=function(t,r){return r||U(t,4,this.length),16777216*this[t]+(this[t+1]<<16|this[t+2]<<8|this[t+3])},a.prototype.readIntLE=function(t,r,e){t|=0,r|=0,e||U(t,r,this.length);for(var n=this[t],i=1,o=0;++o<r&&(i*=256);)n+=this[t+o]*i;return n>=(i*=128)&&(n-=Math.pow(2,8*r)),n},a.prototype.readIntBE=function(t,r,e){t|=0,r|=0,e||U(t,r,this.length);for(var n=r,i=1,o=this[t+--n];n>0&&(i*=256);)o+=this[t+--n]*i;return o>=(i*=128)&&(o-=Math.pow(2,8*r)),o},a.prototype.readInt8=function(t,r){return r||U(t,1,this.length),128&this[t]?-1*(255-this[t]+1):this[t]},a.prototype.readInt16LE=function(t,r){r||U(t,2,this.length);var e=this[t]|this[t+1]<<8;return 32768&e?4294901760|e:e},a.prototype.readInt16BE=function(t,r){r||U(t,2,this.length);var e=this[t+1]|this[t]<<8;return 32768&e?4294901760|e:e},a.prototype.readInt32LE=function(t,r){return r||U(t,4,this.length),this[t]|this[t+1]<<8|this[t+2]<<16|this[t+3]<<24},a.prototype.readInt32BE=function(t,r){return r||U(t,4,this.length),this[t]<<24|this[t+1]<<16|this[t+2]<<8|this[t+3]},a.prototype.readFloatLE=function(t,r){return r||U(t,4,this.length),i.read(this,t,!0,23,4)},a.prototype.readFloatBE=function(t,r){return r||U(t,4,this.length),i.read(this,t,!1,23,4)},a.prototype.readDoubleLE=function(t,r){return r||U(t,8,this.length),i.read(this,t,!0,52,8)},a.prototype.readDoubleBE=function(t,r){return r||U(t,8,this.length),i.read(this,t,!1,52,8)},a.prototype.writeUIntLE=function(t,r,e,n){(t=+t,r|=0,e|=0,n)||C(this,t,r,e,Math.pow(2,8*e)-1,0);var i=1,o=0;for(this[r]=255&t;++o<e&&(i*=256);)this[r+o]=t/i&255;return r+e},a.prototype.writeUIntBE=function(t,r,e,n){(t=+t,r|=0,e|=0,n)||C(this,t,r,e,Math.pow(2,8*e)-1,0);var i=e-1,o=1;for(this[r+i]=255&t;--i>=0&&(o*=256);)this[r+i]=t/o&255;return r+e},a.prototype.writeUInt8=function(t,r,e){return t=+t,r|=0,e||C(this,t,r,1,255,0),a.TYPED_ARRAY_SUPPORT||(t=Math.floor(t)),this[r]=255&t,r+1},a.prototype.writeUInt16LE=function(t,r,e){return t=+t,r|=0,e||C(this,t,r,2,65535,0),a.TYPED_ARRAY_SUPPORT?(this[r]=255&t,this[r+1]=t>>>8):L(this,t,r,!0),r+2},a.prototype.writeUInt16BE=function(t,r,e){return t=+t,r|=0,e||C(this,t,r,2,65535,0),a.TYPED_ARRAY_SUPPORT?(this[r]=t>>>8,this[r+1]=255&t):L(this,t,r,!1),r+2},a.prototype.writeUInt32LE=function(t,r,e){return t=+t,r|=0,e||C(this,t,r,4,4294967295,0),a.TYPED_ARRAY_SUPPORT?(this[r+3]=t>>>24,this[r+2]=t>>>16,this[r+1]=t>>>8,this[r]=255&t):Y(this,t,r,!0),r+4},a.prototype.writeUInt32BE=function(t,r,e){return t=+t,r|=0,e||C(this,t,r,4,4294967295,0),a.TYPED_ARRAY_SUPPORT?(this[r]=t>>>24,this[r+1]=t>>>16,this[r+2]=t>>>8,this[r+3]=255&t):Y(this,t,r,!1),r+4},a.prototype.writeIntLE=function(t,r,e,n){if(t=+t,r|=0,!n){var i=Math.pow(2,8*e-1);C(this,t,r,e,i-1,-i)}var o=0,u=1,f=0;for(this[r]=255&t;++o<e&&(u*=256);)t<0&&0===f&&0!==this[r+o-1]&&(f=1),this[r+o]=(t/u>>0)-f&255;return r+e},a.prototype.writeIntBE=function(t,r,e,n){if(t=+t,r|=0,!n){var i=Math.pow(2,8*e-1);C(this,t,r,e,i-1,-i)}var o=e-1,u=1,f=0;for(this[r+o]=255&t;--o>=0&&(u*=256);)t<0&&0===f&&0!==this[r+o+1]&&(f=1),this[r+o]=(t/u>>0)-f&255;return r+e},a.prototype.writeInt8=function(t,r,e){return t=+t,r|=0,e||C(this,t,r,1,127,-128),a.TYPED_ARRAY_SUPPORT||(t=Math.floor(t)),t<0&&(t=255+t+1),this[r]=255&t,r+1},a.prototype.writeInt16LE=function(t,r,e){return t=+t,r|=0,e||C(this,t,r,2,32767,-32768),a.TYPED_ARRAY_SUPPORT?(this[r]=255&t,this[r+1]=t>>>8):L(this,t,r,!0),r+2},a.prototype.writeInt16BE=function(t,r,e){return t=+t,r|=0,e||C(this,t,r,2,32767,-32768),a.TYPED_ARRAY_SUPPORT?(this[r]=t>>>8,this[r+1]=255&t):L(this,t,r,!1),r+2},a.prototype.writeInt32LE=function(t,r,e){return t=+t,r|=0,e||C(this,t,r,4,2147483647,-2147483648),a.TYPED_ARRAY_SUPPORT?(this[r]=255&t,this[r+1]=t>>>8,this[r+2]=t>>>16,this[r+3]=t>>>24):Y(this,t,r,!0),r+4},a.prototype.writeInt32BE=function(t,r,e){return t=+t,r|=0,e||C(this,t,r,4,2147483647,-2147483648),t<0&&(t=4294967295+t+1),a.TYPED_ARRAY_SUPPORT?(this[r]=t>>>24,this[r+1]=t>>>16,this[r+2]=t>>>8,this[r+3]=255&t):Y(this,t,r,!1),r+4},a.prototype.writeFloatLE=function(t,r,e){return H(this,t,r,!0,e)},a.prototype.writeFloatBE=function(t,r,e){return H(this,t,r,!1,e)},a.prototype.writeDoubleLE=function(t,r,e){return D(this,t,r,!0,e)},a.prototype.writeDoubleBE=function(t,r,e){return D(this,t,r,!1,e)},a.prototype.copy=function(t,r,e,n){if(e||(e=0),n||0===n||(n=this.length),r>=t.length&&(r=t.length),r||(r=0),n>0&&n<e&&(n=e),n===e)return 0;if(0===t.length||0===this.length)return 0;if(r<0)throw new RangeError("targetStart out of bounds");if(e<0||e>=this.length)throw new RangeError("sourceStart out of bounds");if(n<0)throw new RangeError("sourceEnd out of bounds");n>this.length&&(n=this.length),t.length-r<n-e&&(n=t.length-r+e);var i,o=n-e;if(this===t&&e<r&&r<n)for(i=o-1;i>=0;--i)t[i+r]=this[i+e];else if(o<1e3||!a.TYPED_ARRAY_SUPPORT)for(i=0;i<o;++i)t[i+r]=this[i+e];else Uint8Array.prototype.set.call(t,this.subarray(e,e+o),r);return o},a.prototype.fill=function(t,r,e,n){if("string"==typeof t){if("string"==typeof r?(n=r,r=0,e=this.length):"string"==typeof e&&(n=e,e=this.length),1===t.length){var i=t.charCodeAt(0);i<256&&(t=i)}if(void 0!==n&&"string"!=typeof n)throw new TypeError("encoding must be a string");if("string"==typeof n&&!a.isEncoding(n))throw new TypeError("Unknown encoding: "+n)}else"number"==typeof t&&(t&=255);if(r<0||this.length<r||this.length<e)throw new RangeError("Out of range index");if(e<=r)return this;var o;if(r>>>=0,e=void 0===e?this.length:e>>>0,t||(t=0),"number"==typeof t)for(o=r;o<e;++o)this[o]=t;else{var u=a.isBuffer(t)?t:F(new a(t,n).toString()),f=u.length;for(o=0;o<e-r;++o)this[o+r]=u[o%f]}return this};var x=/[^+\/0-9A-Za-z-_]/g;function N(t){return t<16?"0"+t.toString(16):t.toString(16)}function F(t,r){var e;r=r||1/0;for(var n=t.length,i=null,o=[],u=0;u<n;++u){if((e=t.charCodeAt(u))>55295&&e<57344){if(!i){if(e>56319){(r-=3)>-1&&o.push(239,191,189);continue}if(u+1===n){(r-=3)>-1&&o.push(239,191,189);continue}i=e;continue}if(e<56320){(r-=3)>-1&&o.push(239,191,189),i=e;continue}e=65536+(i-55296<<10|e-56320)}else i&&(r-=3)>-1&&o.push(239,191,189);if(i=null,e<128){if((r-=1)<0)break;o.push(e)}else if(e<2048){if((r-=2)<0)break;o.push(e>>6|192,63&e|128)}else if(e<65536){if((r-=3)<0)break;o.push(e>>12|224,e>>6&63|128,63&e|128)}else{if(!(e<1114112))throw new Error("Invalid code point");if((r-=4)<0)break;o.push(e>>18|240,e>>12&63|128,e>>6&63|128,63&e|128)}}return o}function k(t){return n.toByteArray(function(t){if((t=function(t){return t.trim?t.trim():t.replace(/^\s+|\s+$/g,"")}(t).replace(x,"")).length<2)return"";for(;t.length%4!=0;)t+="=";return t}(t))}function G(t,r,e,n){for(var i=0;i<n&&!(i+e>=r.length||i>=t.length);++i)r[i+e]=t[i];return i}}).call(this,e(3))},function(t,r){var e;e=function(){return this}();try{e=e||new Function("return this")()}catch(t){"object"==typeof window&&(e=window)}t.exports=e},function(t,r,e){"use strict";r.byteLength=function(t){var r=s(t),e=r[0],n=r[1];return 3*(e+n)/4-n},r.toByteArray=function(t){var r,e,n=s(t),u=n[0],f=n[1],a=new o(function(t,r,e){return 3*(r+e)/4-e}(0,u,f)),h=0,c=f>0?u-4:u;for(e=0;e<c;e+=4)r=i[t.charCodeAt(e)]<<18|i[t.charCodeAt(e+1)]<<12|i[t.charCodeAt(e+2)]<<6|i[t.charCodeAt(e+3)],a[h++]=r>>16&255,a[h++]=r>>8&255,a[h++]=255&r;2===f&&(r=i[t.charCodeAt(e)]<<2|i[t.charCodeAt(e+1)]>>4,a[h++]=255&r);1===f&&(r=i[t.charCodeAt(e)]<<10|i[t.charCodeAt(e+1)]<<4|i[t.charCodeAt(e+2)]>>2,a[h++]=r>>8&255,a[h++]=255&r);return a},r.fromByteArray=function(t){for(var r,e=t.length,i=e%3,o=[],u=0,f=e-i;u<f;u+=16383)o.push(h(t,u,u+16383>f?f:u+16383));1===i?(r=t[e-1],o.push(n[r>>2]+n[r<<4&63]+"==")):2===i&&(r=(t[e-2]<<8)+t[e-1],o.push(n[r>>10]+n[r>>4&63]+n[r<<2&63]+"="));return o.join("")};for(var n=[],i=[],o="undefined"!=typeof Uint8Array?Uint8Array:Array,u="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",f=0,a=u.length;f<a;++f)n[f]=u[f],i[u.charCodeAt(f)]=f;function s(t){var r=t.length;if(r%4>0)throw new Error("Invalid string. Length must be a multiple of 4");var e=t.indexOf("=");return-1===e&&(e=r),[e,e===r?0:4-e%4]}function h(t,r,e){for(var i,o,u=[],f=r;f<e;f+=3)i=(t[f]<<16&16711680)+(t[f+1]<<8&65280)+(255&t[f+2]),u.push(n[(o=i)>>18&63]+n[o>>12&63]+n[o>>6&63]+n[63&o]);return u.join("")}i["-".charCodeAt(0)]=62,i["_".charCodeAt(0)]=63},function(t,r){
9
+ /*! ieee754. BSD-3-Clause License. Feross Aboukhadijeh <https://feross.org/opensource> */
10
+ r.read=function(t,r,e,n,i){var o,u,f=8*i-n-1,a=(1<<f)-1,s=a>>1,h=-7,c=e?i-1:0,p=e?-1:1,l=t[r+c];for(c+=p,o=l&(1<<-h)-1,l>>=-h,h+=f;h>0;o=256*o+t[r+c],c+=p,h-=8);for(u=o&(1<<-h)-1,o>>=-h,h+=n;h>0;u=256*u+t[r+c],c+=p,h-=8);if(0===o)o=1-s;else{if(o===a)return u?NaN:1/0*(l?-1:1);u+=Math.pow(2,n),o-=s}return(l?-1:1)*u*Math.pow(2,o-n)},r.write=function(t,r,e,n,i,o){var u,f,a,s=8*o-i-1,h=(1<<s)-1,c=h>>1,p=23===i?Math.pow(2,-24)-Math.pow(2,-77):0,l=n?0:o-1,g=n?1:-1,d=r<0||0===r&&1/r<0?1:0;for(r=Math.abs(r),isNaN(r)||r===1/0?(f=isNaN(r)?1:0,u=h):(u=Math.floor(Math.log(r)/Math.LN2),r*(a=Math.pow(2,-u))<1&&(u--,a*=2),(r+=u+c>=1?p/a:p*Math.pow(2,1-c))*a>=2&&(u++,a/=2),u+c>=h?(f=0,u=h):u+c>=1?(f=(r*a-1)*Math.pow(2,i),u+=c):(f=r*Math.pow(2,c-1)*Math.pow(2,i),u=0));i>=8;t[e+l]=255&f,l+=g,f/=256,i-=8);for(u=u<<i|f,s+=i;s>0;t[e+l]=255&u,l+=g,u/=256,s-=8);t[e+l-g]|=128*d}},function(t,r){var e={}.toString;t.exports=Array.isArray||function(t){return"[object Array]"==e.call(t)}},function(t,r){t.exports=bsv}]);