@smartledger/bsv 7.8.1 → 7.10.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.
Files changed (76) hide show
  1. package/CHANGELOG.md +117 -6
  2. package/README.md +38 -38
  3. package/bsv-covenant.min.js +1 -1
  4. package/bsv-ecies.min.js +1 -1
  5. package/bsv-gdaf.min.js +54 -54
  6. package/bsv-ltp.min.js +58 -85
  7. package/bsv-message.min.js +2 -2
  8. package/bsv-mnemonic.min.js +12 -14
  9. package/bsv-script-helper.min.js +1 -1
  10. package/bsv-shamir.min.js +14 -16
  11. package/bsv-smartcontract.min.js +23 -25
  12. package/bsv.bundle.js +54 -54
  13. package/bsv.min.js +54 -54
  14. package/build/esbuild.js +84 -4
  15. package/docs/MODULE_REFERENCE_COMPLETE.md +27 -27
  16. package/docs/advanced/UTXO_MANAGER_GUIDE.md +1 -1
  17. package/docs/getting-started/INSTALLATION.md +23 -23
  18. package/docs/getting-started/QUICK_START.md +7 -7
  19. package/docs/migration/FROM_BSV_1_5_6.md +5 -5
  20. package/index.js +9 -1
  21. package/lib/covenant/helpers.js +146 -0
  22. package/lib/covenant/index.js +21 -0
  23. package/lib/covenant/pushtx.js +243 -0
  24. package/lib/covenant-interface.js +408 -397
  25. package/lib/custom-script-helper.js +44 -38
  26. package/lib/ecies/bitcore-ecies.js +3 -4
  27. package/lib/ecies/electrum-ecies.js +4 -6
  28. package/lib/ecies/errors.js +1 -1
  29. package/lib/gdaf/attestation-signer.js +7 -7
  30. package/lib/gdaf/attestation-verifier.js +5 -6
  31. package/lib/gdaf/did-resolver.js +10 -9
  32. package/lib/gdaf/smartledger-anchor.js +13 -12
  33. package/lib/gdaf/zk-prover.js +8 -8
  34. package/lib/ltp/anchor.js +2 -3
  35. package/lib/ltp/claim.js +2 -3
  36. package/lib/ltp/index.js +2 -3
  37. package/lib/ltp/obligation.js +9 -9
  38. package/lib/ltp/proof.js +7 -7
  39. package/lib/ltp/registry.js +4 -5
  40. package/lib/ltp/right.js +11 -11
  41. package/lib/message/index.js +5 -4
  42. package/lib/message/message.js +11 -11
  43. package/lib/mnemonic/errors.js +1 -1
  44. package/lib/mnemonic/index.js +5 -4
  45. package/lib/mnemonic/mnemonic.js +22 -10
  46. package/lib/ordinals/bsv20.js +4 -4
  47. package/lib/ordinals/inscription.js +8 -12
  48. package/lib/ordinals/ordlock.js +26 -21
  49. package/lib/script/interpreter.js +96 -31
  50. package/lib/smart_contract/authorizers.js +8 -6
  51. package/lib/smart_contract/builder.js +32 -26
  52. package/lib/smart_contract/covenant.js +32 -25
  53. package/lib/smart_contract/covenant_helpers.js +8 -128
  54. package/lib/smart_contract/debugger.js +9 -6
  55. package/lib/smart_contract/dsl.js +5 -6
  56. package/lib/smart_contract/index.js +11 -8
  57. package/lib/smart_contract/locks.js +3 -4
  58. package/lib/smart_contract/opcode_list.js +2 -3
  59. package/lib/smart_contract/pels.js +4 -5
  60. package/lib/smart_contract/preimage.js +11 -7
  61. package/lib/smart_contract/pushtx.js +8 -263
  62. package/lib/smart_contract/script_interpreter.js +112 -105
  63. package/lib/smart_contract/script_tester.js +24 -18
  64. package/lib/smart_contract/script_utils.js +15 -14
  65. package/lib/smart_contract/sighash.js +23 -15
  66. package/lib/smart_contract/stack_examiner.js +70 -63
  67. package/lib/smart_contract/token.js +6 -6
  68. package/lib/smart_contract/utxo_generator.js +21 -15
  69. package/lib/smartutxo.js +27 -21
  70. package/lib/spv/headerchain.js +3 -3
  71. package/lib/spv/merkleproof.js +3 -3
  72. package/package.json +4 -2
  73. package/test/script/chronicle.js +53 -10
  74. package/test/script/interpreter.js +9 -6
  75. package/test/script/string_ops.js +26 -10
  76. package/version.js +1 -1
package/CHANGELOG.md CHANGED
@@ -7,14 +7,125 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
7
7
 
8
8
  ## [Unreleased]
9
9
 
10
- ## [7.8.1] - 2026-08-10
10
+ ## [7.10.0] - 2026-08-10
11
11
 
12
- Bundle-only re-release of 7.8.0. No source, API or behaviour change — see
13
- [7.7.1] for the full explanation; the same stale `bn.js@4.12.3` in a local
14
- `node_modules` produced non-reproducible bundles here too.
12
+ Internal restructuring with no API change, plus a conformance corpus and two
13
+ repairs to the gate that guards it.
15
14
 
16
- Published under the `bundles-7.8` dist-tag so `latest` continues to point at the
17
- newest release.
15
+ ### Changed
16
+
17
+ - **The 45 package-root require cycles in `lib/` are gone.** Modules now require
18
+ each other directly instead of reaching back through the package root
19
+ (`require('../..')`). That pattern is what made module load order matter: a
20
+ consumer who reached `lib/script` before `lib/address` got a partially
21
+ initialised namespace, which is the class of bug 7.5.7 fixed for one file. This
22
+ removes the cause rather than another symptom — `check-address-load-order`
23
+ passes on this branch independently of that fix.
24
+
25
+ - **OP_PUSH_TX primitives moved to `lib/covenant/`**, breaking the last dependency
26
+ from core code into the application layer (`lib/ordinals` needed them too). The
27
+ old paths remain as shims, because deep imports such as
28
+ `require('@smartledger/bsv/lib/smart_contract/covenant_helpers')` are public API
29
+ through the `exports` map. `./lib/covenant` is a new public subpath.
30
+
31
+ - **Feature bundles are thin again.** Each externalises the shared primitives per
32
+ module rather than embedding a second copy.
33
+
34
+ - **`aes-js` dropped** — it was an unused dependency.
35
+
36
+ ### Added
37
+
38
+ - **A conformance corpus** (`npm run conformance`): 371 cases across 11 suites,
39
+ freezing observable behaviour so a change to it surfaces as a diff. Rejections
40
+ are recorded as first-class outcomes, so a fix of the form "reject what used to
41
+ be accepted" shows up as an outcome flip rather than disappearing.
42
+
43
+ Worth stating its limit plainly, because this release is a good illustration: a
44
+ frozen corpus detects a **change**, never a pre-existing wrong assumption. It is
45
+ a regression net, not a correctness oracle.
46
+
47
+ ### Fixed
48
+
49
+ - **`conformance/verify.js` passed when a fixture was missing.** A suite with no
50
+ fixture was noted and skipped, so the run still printed `PASS` and exited 0.
51
+ With the corpus a blocking CI gate, a fixture that was deleted or never
52
+ committed would have dropped silently out of it. It now fails, as does a
53
+ mistyped `--suite`, and `PASS` is no longer printed on a failed run.
54
+
55
+ - **`conformance/generate.js` corrupted its own manifest.** `MANIFEST.json` was
56
+ written from the *filtered* suite list, so regenerating a single suite replaced
57
+ the whole-corpus record with `suiteCount: 1` — erasing the only artifact that
58
+ would reveal a fixture had gone missing. It is now derived from the fixtures on
59
+ disk, carrying per-suite provenance and `lastVerifiedBy`.
60
+
61
+ - **The corpus harness could not parse Core's `NOP4`..`NOP8` names**, which
62
+ surfaced as `threw:Error` on eighteen vendored vectors. Left unfixed, the
63
+ regenerated fixtures would have frozen a *harness* defect as expected library
64
+ behaviour.
65
+
66
+ Suite 4641. In-repo corpus 371/371; the independent corpus in
67
+ `@smartledger/bsv-core` reports 452/452.
68
+
69
+ ## [7.9.0] - 2026-08-10
70
+
71
+ Five divergences from the SV Node source (checked at tag **v1.2.0**), and the
72
+ consequence closing one of them exposed.
73
+
74
+ ### Fixed (consensus)
75
+
76
+ - **`OP_SUBSTR`/`OP_LEFT`/`OP_RIGHT` ran unconditionally.** The node treats bytes
77
+ `0xb3`–`0xb5` as upgradable NOPs until Chronicle activates. This library executed
78
+ them regardless, consuming stack where the network does nothing — reachable today,
79
+ since those bytes are live NOPs.
80
+
81
+ - **Out-of-range string-op arguments were clamped instead of rejected.** The node:
82
+ `if(offset < 0 || offset >= size || len < 0 || len > size - offset) return
83
+ SCRIPT_ERR_INVALID_NUMBER_RANGE`. Measured before the fix, `'hi' 1 9 OP_SUBSTR`
84
+ yielded `'i'` and the script **succeeded**. Note `offset >= size` is strict — a begin
85
+ index at the end is an error, not an empty result.
86
+
87
+ - **`OP_VER` pushed a script number** where the node builds a `sizeof(tx_version)`
88
+ vector and `to_le`s into it: `01000000`, not `01`.
89
+
90
+ - **`OP_VERIF` compared numerically.** The node requires exactly four bytes and
91
+ compares byte-wise (`if(vch.size() == 4) … std::ranges::equal(val, vch)`), so a
92
+ 1-byte script number never matches however equal it looks. `OP_2 OP_VERIF` against
93
+ version 2 was true here and false on the node; `OP_VER OP_VERIF` is the idiomatic
94
+ form.
95
+
96
+ - **`OP_VERIF` in an unexecuted branch returned `BAD_OPCODE`.** Core treats it as
97
+ illegal everywhere — a rule it applies to no other opcode — but BSV drops that at
98
+ Genesis and the node breaks instead. Asserting the Core rule made this library reject
99
+ scripts the network accepts. (This corrects an assertion added in 7.7.0.)
100
+
101
+ Also taken from the source: MINIMALIF applies only to `OP_IF`/`OP_NOTIF`, never to the
102
+ `OP_VER` family.
103
+
104
+ ### Consequence worth reading
105
+
106
+ Closing the gating divergence surfaced something the old behaviour was hiding.
107
+ `pushTxCore` emits `OP_RIGHT`/`OP_LEFT` — see `extractHashOutputs` and
108
+ `assertSighashType` — so **OP_PUSH_TX covenants built by this library cannot be spent
109
+ on a pre-Chronicle chain**. Confirmed end to end: an OrdLock purchase verifies with
110
+ `SCRIPT_ENABLE_CHRONICLE` and fails `SCRIPT_ERR_EQUALVERIFY` without it.
111
+
112
+ That was invisible *because* the interpreter ran the string opcodes unconditionally:
113
+ the library was more permissive than the network, so the covenant and OrdLock suites
114
+ passed against a validator that did not match consensus. `covenant_helpers.flags()` now
115
+ sets the flag explicitly, so the dependency is stated rather than assumed. Whether that
116
+ tooling should target pre- or post-activation is a product decision this does not make.
117
+
118
+ ### Breaking
119
+
120
+ Scripts using `OP_SUBSTR`/`OP_LEFT`/`OP_RIGHT` now require `SCRIPT_ENABLE_CHRONICLE` to
121
+ execute; without it they are no-ops, as on the network. Out-of-range arguments error
122
+ rather than clamping. `OP_VER` pushes four bytes. `OP_VERIF` needs a 4-byte operand.
123
+
124
+ With this release the independent conformance corpus in `@smartledger/bsv-core` — whose
125
+ Chronicle fixtures have been regenerated against the same source — reports
126
+ **PASS: 452/452** across all 13 suites. The two implementations agree completely.
127
+
128
+ Suite 4638 → 4641.
18
129
 
19
130
  ## [7.8.0] - 2026-08-10
20
131
 
package/README.md CHANGED
@@ -186,42 +186,42 @@ console.log('Status:', status) // 'revoked'
186
186
  ### **Core Modules**
187
187
  | Module | Size | Use Case | CDN |
188
188
  |--------|------|----------|-----|
189
- | **bsv.min.js** | 1149KB | Core BSV + SmartContract | `unpkg.com/@smartledger/bsv@7.8.1/bsv.min.js` |
190
- | **bsv.bundle.js** | 1149KB | Everything in one file | `unpkg.com/@smartledger/bsv@7.8.1/bsv.bundle.js` |
189
+ | **bsv.min.js** | 1149KB | Core BSV + SmartContract | `unpkg.com/@smartledger/bsv@7.10.0/bsv.min.js` |
190
+ | **bsv.bundle.js** | 1149KB | Everything in one file | `unpkg.com/@smartledger/bsv@7.10.0/bsv.bundle.js` |
191
191
 
192
192
  ### **W3C Verifiable Credentials**
193
193
  | Module | Size | Use Case | CDN |
194
194
  |--------|------|----------|-----|
195
- | **🟢 bsv-didweb.min.js** | 315KB | **DID:web generation** | `unpkg.com/@smartledger/bsv@7.8.1/bsv-didweb.min.js` |
196
- | **🟢 bsv-vcjwt.min.js** | 315KB | **VC-JWT issue/verify** | `unpkg.com/@smartledger/bsv@7.8.1/bsv-vcjwt.min.js` |
197
- | **🟢 bsv-statuslist.min.js** | 415KB | **StatusList2021 revocation** | `unpkg.com/@smartledger/bsv@7.8.1/bsv-statuslist.min.js` |
198
- | **🟢 bsv-anchor.min.js** | 314KB | **BSV anchoring (hash-only)** | `unpkg.com/@smartledger/bsv@7.8.1/bsv-anchor.min.js` |
195
+ | **🟢 bsv-didweb.min.js** | 315KB | **DID:web generation** | `unpkg.com/@smartledger/bsv@7.10.0/bsv-didweb.min.js` |
196
+ | **🟢 bsv-vcjwt.min.js** | 315KB | **VC-JWT issue/verify** | `unpkg.com/@smartledger/bsv@7.10.0/bsv-vcjwt.min.js` |
197
+ | **🟢 bsv-statuslist.min.js** | 415KB | **StatusList2021 revocation** | `unpkg.com/@smartledger/bsv@7.10.0/bsv-statuslist.min.js` |
198
+ | **🟢 bsv-anchor.min.js** | 314KB | **BSV anchoring (hash-only)** | `unpkg.com/@smartledger/bsv@7.10.0/bsv-anchor.min.js` |
199
199
 
200
200
  ### **Smart Contract & Development**
201
201
  | Module | Size | Use Case | CDN |
202
202
  |--------|------|----------|-----|
203
- | **bsv-smartcontract.min.js** | 873KB | Complete covenant framework | `unpkg.com/@smartledger/bsv@7.8.1/bsv-smartcontract.min.js` |
204
- | **bsv-covenant.min.js** | 873KB | Covenant operations | `unpkg.com/@smartledger/bsv@7.8.1/bsv-covenant.min.js` |
205
- | **bsv-script-helper.min.js** | 30KB | Custom script tools | `unpkg.com/@smartledger/bsv@7.8.1/bsv-script-helper.min.js` |
206
- | **bsv-security.min.js** | 30KB | Security enhancements | `unpkg.com/@smartledger/bsv@7.8.1/bsv-security.min.js` |
203
+ | **bsv-smartcontract.min.js** | 873KB | Complete covenant framework | `unpkg.com/@smartledger/bsv@7.10.0/bsv-smartcontract.min.js` |
204
+ | **bsv-covenant.min.js** | 873KB | Covenant operations | `unpkg.com/@smartledger/bsv@7.10.0/bsv-covenant.min.js` |
205
+ | **bsv-script-helper.min.js** | 30KB | Custom script tools | `unpkg.com/@smartledger/bsv@7.10.0/bsv-script-helper.min.js` |
206
+ | **bsv-security.min.js** | 30KB | Security enhancements | `unpkg.com/@smartledger/bsv@7.10.0/bsv-security.min.js` |
207
207
 
208
208
  ### **Legal & Compliance**
209
209
  | Module | Size | Use Case | CDN |
210
210
  |--------|------|----------|-----|
211
- | **bsv-ltp.min.js** | 1149KB | Legal Token Protocol | `unpkg.com/@smartledger/bsv@7.8.1/bsv-ltp.min.js` |
212
- | **bsv-gdaf.min.js** | 1149KB | Digital Identity & Attestation | `unpkg.com/@smartledger/bsv@7.8.1/bsv-gdaf.min.js` |
211
+ | **bsv-ltp.min.js** | 1149KB | Legal Token Protocol | `unpkg.com/@smartledger/bsv@7.10.0/bsv-ltp.min.js` |
212
+ | **bsv-gdaf.min.js** | 1149KB | Digital Identity & Attestation | `unpkg.com/@smartledger/bsv@7.10.0/bsv-gdaf.min.js` |
213
213
 
214
214
  ### **Advanced Cryptography**
215
215
  | Module | Size | Use Case | CDN |
216
216
  |--------|------|----------|-----|
217
- | **bsv-shamir.min.js** | 353KB | Threshold Cryptography | `unpkg.com/@smartledger/bsv@7.8.1/bsv-shamir.min.js` |
217
+ | **bsv-shamir.min.js** | 353KB | Threshold Cryptography | `unpkg.com/@smartledger/bsv@7.10.0/bsv-shamir.min.js` |
218
218
 
219
219
  ### **Utilities**
220
220
  | Module | Size | Use Case | CDN |
221
221
  |--------|------|----------|-----|
222
- | **bsv-ecies.min.js** | 79KB | Encryption | `unpkg.com/@smartledger/bsv@7.8.1/bsv-ecies.min.js` |
223
- | **bsv-message.min.js** | 30KB | Message signing | `unpkg.com/@smartledger/bsv@7.8.1/bsv-message.min.js` |
224
- | **bsv-mnemonic.min.js** | 592KB | HD wallets | `unpkg.com/@smartledger/bsv@7.8.1/bsv-mnemonic.min.js` |
222
+ | **bsv-ecies.min.js** | 79KB | Encryption | `unpkg.com/@smartledger/bsv@7.10.0/bsv-ecies.min.js` |
223
+ | **bsv-message.min.js** | 30KB | Message signing | `unpkg.com/@smartledger/bsv@7.10.0/bsv-message.min.js` |
224
+ | **bsv-mnemonic.min.js** | 592KB | HD wallets | `unpkg.com/@smartledger/bsv@7.10.0/bsv-mnemonic.min.js` |
225
225
 
226
226
  ## ⚡ **2-Minute Quick Start**
227
227
 
@@ -232,7 +232,7 @@ Get started with Bitcoin SV development in under 2 minutes:
232
232
  npm install @smartledger/bsv
233
233
 
234
234
  # Or include in HTML
235
- <script src="https://unpkg.com/@smartledger/bsv@7.8.1/bsv.min.js"></script>
235
+ <script src="https://unpkg.com/@smartledger/bsv@7.10.0/bsv.min.js"></script>
236
236
  ```
237
237
 
238
238
  > **🔒 v5.0.0 (production hardening — has breaking changes):** Shamir secret
@@ -332,8 +332,8 @@ const covenant = bsv.SmartContract.createCovenantBuilder()
332
332
 
333
333
  ### 🔧 **Basic Development** (~1.2MB total)
334
334
  ```html
335
- <script src="https://unpkg.com/@smartledger/bsv@7.8.1/bsv.min.js"></script>
336
- <script src="https://unpkg.com/@smartledger/bsv@7.8.1/bsv-script-helper.min.js"></script>
335
+ <script src="https://unpkg.com/@smartledger/bsv@7.10.0/bsv.min.js"></script>
336
+ <script src="https://unpkg.com/@smartledger/bsv@7.10.0/bsv-script-helper.min.js"></script>
337
337
  <script>
338
338
  const privateKey = new bsv.PrivateKey();
339
339
  const utxos = new bsv.SmartContract.UTXOGenerator().createRealUTXOs(2, 100000);
@@ -342,9 +342,9 @@ const covenant = bsv.SmartContract.createCovenantBuilder()
342
342
 
343
343
  ### 🔒 **Smart Contract Development** (~2.8MB total — each bundle re-embeds core BSV)
344
344
  ```html
345
- <script src="https://unpkg.com/@smartledger/bsv@7.8.1/bsv.min.js"></script>
346
- <script src="https://unpkg.com/@smartledger/bsv@7.8.1/bsv-covenant.min.js"></script>
347
- <script src="https://unpkg.com/@smartledger/bsv@7.8.1/bsv-smartcontract.min.js"></script>
345
+ <script src="https://unpkg.com/@smartledger/bsv@7.10.0/bsv.min.js"></script>
346
+ <script src="https://unpkg.com/@smartledger/bsv@7.10.0/bsv-covenant.min.js"></script>
347
+ <script src="https://unpkg.com/@smartledger/bsv@7.10.0/bsv-smartcontract.min.js"></script>
348
348
  <script>
349
349
  const covenant = bsv.SmartContract.createCovenantBuilder()
350
350
  .extractField('amount').push(50000).greaterThanOrEqual().verify().build();
@@ -354,9 +354,9 @@ const covenant = bsv.SmartContract.createCovenantBuilder()
354
354
 
355
355
  ### 🆕 **Legal & Identity Development** (~3.4MB total — each bundle re-embeds core BSV)
356
356
  ```html
357
- <script src="https://unpkg.com/@smartledger/bsv@7.8.1/bsv.min.js"></script>
358
- <script src="https://unpkg.com/@smartledger/bsv@7.8.1/bsv-ltp.min.js"></script>
359
- <script src="https://unpkg.com/@smartledger/bsv@7.8.1/bsv-gdaf.min.js"></script>
357
+ <script src="https://unpkg.com/@smartledger/bsv@7.10.0/bsv.min.js"></script>
358
+ <script src="https://unpkg.com/@smartledger/bsv@7.10.0/bsv-ltp.min.js"></script>
359
+ <script src="https://unpkg.com/@smartledger/bsv@7.10.0/bsv-gdaf.min.js"></script>
360
360
  <script>
361
361
  // Legal Token Protocol
362
362
  const propertyToken = bsv.createPropertyToken({
@@ -370,9 +370,9 @@ const covenant = bsv.SmartContract.createCovenantBuilder()
370
370
 
371
371
  ### 🆕 **Security & Cryptography** (~1.5MB total)
372
372
  ```html
373
- <script src="https://unpkg.com/@smartledger/bsv@7.8.1/bsv.min.js"></script>
374
- <script src="https://unpkg.com/@smartledger/bsv@7.8.1/bsv-security.min.js"></script>
375
- <script src="https://unpkg.com/@smartledger/bsv@7.8.1/bsv-shamir.min.js"></script>
373
+ <script src="https://unpkg.com/@smartledger/bsv@7.10.0/bsv.min.js"></script>
374
+ <script src="https://unpkg.com/@smartledger/bsv@7.10.0/bsv-security.min.js"></script>
375
+ <script src="https://unpkg.com/@smartledger/bsv@7.10.0/bsv-shamir.min.js"></script>
376
376
  <script>
377
377
  // Threshold Cryptography
378
378
  const shares = bsv.splitSecret('my_secret_key', 5, 3); // 5 shares, 3 needed
@@ -384,7 +384,7 @@ const covenant = bsv.SmartContract.createCovenantBuilder()
384
384
 
385
385
  ### 🎯 **Everything Bundle** (~1.1MB)
386
386
  ```html
387
- <script src="https://unpkg.com/@smartledger/bsv@7.8.1/bsv.bundle.js"></script>
387
+ <script src="https://unpkg.com/@smartledger/bsv@7.10.0/bsv.bundle.js"></script>
388
388
  <script>
389
389
  // Everything available immediately
390
390
  const shares = bsv.splitSecret('secret', 5, 3); // Shamir Secret Sharing
@@ -494,8 +494,8 @@ const contractTx = covenant.createCovenantTransaction({
494
494
 
495
495
  #### 1. **Minimal Setup** - Core + Script Helper (~1.2MB)
496
496
  ```html
497
- <script src="https://unpkg.com/@smartledger/bsv@7.8.1/bsv.min.js"></script>
498
- <script src="https://unpkg.com/@smartledger/bsv@7.8.1/bsv-script-helper.min.js"></script>
497
+ <script src="https://unpkg.com/@smartledger/bsv@7.10.0/bsv.min.js"></script>
498
+ <script src="https://unpkg.com/@smartledger/bsv@7.10.0/bsv-script-helper.min.js"></script>
499
499
  <script>
500
500
  const tx = new bsv.Transaction();
501
501
  const sig = bsvScriptHelper.createSignature(tx, privateKey, 0, script, satoshis);
@@ -504,9 +504,9 @@ const contractTx = covenant.createCovenantTransaction({
504
504
 
505
505
  #### 2. **DeFi Development** - Core + Covenants + Debug (~2.8MB — each bundle re-embeds core BSV)
506
506
  ```html
507
- <script src="https://unpkg.com/@smartledger/bsv@7.8.1/bsv.min.js"></script>
508
- <script src="https://unpkg.com/@smartledger/bsv@7.8.1/bsv-covenant.min.js"></script>
509
- <script src="https://unpkg.com/@smartledger/bsv@7.8.1/bsv-smartcontract.min.js"></script>
507
+ <script src="https://unpkg.com/@smartledger/bsv@7.10.0/bsv.min.js"></script>
508
+ <script src="https://unpkg.com/@smartledger/bsv@7.10.0/bsv-covenant.min.js"></script>
509
+ <script src="https://unpkg.com/@smartledger/bsv@7.10.0/bsv-smartcontract.min.js"></script>
510
510
  <script>
511
511
  const covenant = new bsvCovenant.CovenantInterface();
512
512
  const debugInfo = SmartContract.interpretScript(script);
@@ -516,8 +516,8 @@ const contractTx = covenant.createCovenantTransaction({
516
516
 
517
517
  #### 3. **Security First** - Core + Enhanced Security (~1.2MB)
518
518
  ```html
519
- <script src="https://unpkg.com/@smartledger/bsv@7.8.1/bsv.min.js"></script>
520
- <script src="https://unpkg.com/@smartledger/bsv@7.8.1/bsv-security.min.js"></script>
519
+ <script src="https://unpkg.com/@smartledger/bsv@7.10.0/bsv.min.js"></script>
520
+ <script src="https://unpkg.com/@smartledger/bsv@7.10.0/bsv-security.min.js"></script>
521
521
  <script>
522
522
  const verified = bsvSecurity.SmartVerify.verify(signature, hash, publicKey);
523
523
  const enhanced = bsvSecurity.EllipticFixed.createSignature(privateKey, hash);
@@ -526,7 +526,7 @@ const contractTx = covenant.createCovenantTransaction({
526
526
 
527
527
  #### 4. **Everything Bundle** - One File Solution (~1.1MB)
528
528
  ```html
529
- <script src="https://unpkg.com/@smartledger/bsv@7.8.1/bsv.bundle.js"></script>
529
+ <script src="https://unpkg.com/@smartledger/bsv@7.10.0/bsv.bundle.js"></script>
530
530
  <script>
531
531
  // Everything available under bsv namespace
532
532
  const keys = bsv.SmartLedgerBundle.generateKeys();
@@ -834,7 +834,7 @@ const timelockScript = helper.createTimelockScript(
834
834
 
835
835
  See the **[16 Loading Options](#-16-loading-options---choose-your-approach)**
836
836
  table near the top for the full list of bundles with current sizes and
837
- canonical `unpkg.com/@smartledger/bsv@7.8.1/...` URLs.
837
+ canonical `unpkg.com/@smartledger/bsv@7.10.0/...` URLs.
838
838
 
839
839
  ## 🔐 Security
840
840
 
@@ -1,2 +1,2 @@
1
- var bsvCovenant=(()=>{var qr=Object.create;var cr=Object.defineProperty;var Yr=Object.getOwnPropertyDescriptor;var Kr=Object.getOwnPropertyNames;var Vr=Object.getPrototypeOf,jr=Object.prototype.hasOwnProperty;var Wr=(e,r,t)=>()=>{if(t)throw t[0];try{return e&&(r=e(e=0)),r}catch(i){throw t=[i],i}};var P=(e,r)=>()=>{try{return r||e((r={exports:{}}).exports,r),r.exports}catch(t){throw r=0,t}};var Xr=(e,r,t,i)=>{if(r&&typeof r=="object"||typeof r=="function")for(let n of Kr(r))!jr.call(e,n)&&n!==t&&cr(e,n,{get:()=>r[n],enumerable:!(i=Yr(r,n))||i.enumerable});return e};var sr=(e,r,t)=>(t=e!=null?qr(Vr(e)):{},Xr(r||!e||!e.__esModule?cr(t,"default",{value:e,enumerable:!0}):t,e));var lr=P((bt,pr)=>{d();var y=pr.exports={},F,S;function W(){throw new Error("setTimeout has not been defined")}function X(){throw new Error("clearTimeout has not been defined")}(function(){try{typeof setTimeout=="function"?F=setTimeout:F=W}catch{F=W}try{typeof clearTimeout=="function"?S=clearTimeout:S=X}catch{S=X}})();function hr(e){if(F===setTimeout)return setTimeout(e,0);if((F===W||!F)&&setTimeout)return F=setTimeout,setTimeout(e,0);try{return F(e,0)}catch{try{return F.call(null,e,0)}catch{return F.call(this,e,0)}}}function Jr(e){if(S===clearTimeout)return clearTimeout(e);if((S===X||!S)&&clearTimeout)return S=clearTimeout,clearTimeout(e);try{return S(e)}catch{try{return S.call(null,e)}catch{return S.call(this,e)}}}var U=[],M=!1,b,q=-1;function Qr(){!M||!b||(M=!1,b.length?U=b.concat(U):q=-1,U.length&&ar())}function ar(){if(!M){var e=hr(Qr);M=!0;for(var r=U.length;r;){for(b=U,U=[];++q<r;)b&&b[q].run();q=-1,r=U.length}b=null,M=!1,Jr(e)}}y.nextTick=function(e){var r=new Array(arguments.length-1);if(arguments.length>1)for(var t=1;t<arguments.length;t++)r[t-1]=arguments[t];U.push(new fr(e,r)),U.length===1&&!M&&hr(ar)};function fr(e,r){this.fun=e,this.array=r}fr.prototype.run=function(){this.fun.apply(null,this.array)};y.title="browser";y.browser=!0;y.env={};y.argv=[];y.version="";y.versions={};function R(){}y.on=R;y.addListener=R;y.once=R;y.off=R;y.removeListener=R;y.removeAllListeners=R;y.emit=R;y.prependListener=R;y.prependOnceListener=R;y.listeners=function(e){return[]};y.binding=function(e){throw new Error("process.binding is not supported")};y.cwd=function(){return"/"};y.chdir=function(e){throw new Error("process.chdir is not supported")};y.umask=function(){return 0}});var dr=P(Y=>{"use strict";d();Y.byteLength=Zr;Y.toByteArray=tt;Y.fromByteArray=nt;var A=[],E=[],zr=typeof Uint8Array<"u"?Uint8Array:Array,J="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";for(L=0,yr=J.length;L<yr;++L)A[L]=J[L],E[J.charCodeAt(L)]=L;var L,yr;E[45]=62;E[95]=63;function wr(e){var r=e.length;if(r%4>0)throw new Error("Invalid string. Length must be a multiple of 4");var t=e.indexOf("=");t===-1&&(t=r);var i=t===r?0:4-t%4;return[t,i]}function Zr(e){var r=wr(e),t=r[0],i=r[1];return(t+i)*3/4-i}function rt(e,r,t){return(r+t)*3/4-t}function tt(e){var r,t=wr(e),i=t[0],n=t[1],o=new zr(rt(e,i,n)),u=0,s=n>0?i-4:i,h;for(h=0;h<s;h+=4)r=E[e.charCodeAt(h)]<<18|E[e.charCodeAt(h+1)]<<12|E[e.charCodeAt(h+2)]<<6|E[e.charCodeAt(h+3)],o[u++]=r>>16&255,o[u++]=r>>8&255,o[u++]=r&255;return n===2&&(r=E[e.charCodeAt(h)]<<2|E[e.charCodeAt(h+1)]>>4,o[u++]=r&255),n===1&&(r=E[e.charCodeAt(h)]<<10|E[e.charCodeAt(h+1)]<<4|E[e.charCodeAt(h+2)]>>2,o[u++]=r>>8&255,o[u++]=r&255),o}function et(e){return A[e>>18&63]+A[e>>12&63]+A[e>>6&63]+A[e&63]}function it(e,r,t){for(var i,n=[],o=r;o<t;o+=3)i=(e[o]<<16&16711680)+(e[o+1]<<8&65280)+(e[o+2]&255),n.push(et(i));return n.join("")}function nt(e){for(var r,t=e.length,i=t%3,n=[],o=16383,u=0,s=t-i;u<s;u+=o)n.push(it(e,u,u+o>s?s:u+o));return i===1?(r=e[t-1],n.push(A[r>>2]+A[r<<4&63]+"==")):i===2&&(r=(e[t-2]<<8)+e[t-1],n.push(A[r>>10]+A[r>>4&63]+A[r<<2&63]+"=")),n.join("")}});var xr=P(Q=>{d();Q.read=function(e,r,t,i,n){var o,u,s=n*8-i-1,h=(1<<s)-1,p=h>>1,f=-7,a=t?n-1:0,k=t?-1:1,I=e[r+a];for(a+=k,o=I&(1<<-f)-1,I>>=-f,f+=s;f>0;o=o*256+e[r+a],a+=k,f-=8);for(u=o&(1<<-f)-1,o>>=-f,f+=i;f>0;u=u*256+e[r+a],a+=k,f-=8);if(o===0)o=1-p;else{if(o===h)return u?NaN:(I?-1:1)*(1/0);u=u+Math.pow(2,i),o=o-p}return(I?-1:1)*u*Math.pow(2,o-i)};Q.write=function(e,r,t,i,n,o){var u,s,h,p=o*8-n-1,f=(1<<p)-1,a=f>>1,k=n===23?Math.pow(2,-24)-Math.pow(2,-77):0,I=i?0:o-1,j=i?1:-1,Gr=r<0||r===0&&1/r<0?1:0;for(r=Math.abs(r),isNaN(r)||r===1/0?(s=isNaN(r)?1:0,u=f):(u=Math.floor(Math.log(r)/Math.LN2),r*(h=Math.pow(2,-u))<1&&(u--,h*=2),u+a>=1?r+=k/h:r+=k*Math.pow(2,1-a),r*h>=2&&(u++,h/=2),u+a>=f?(s=0,u=f):u+a>=1?(s=(r*h-1)*Math.pow(2,n),u=u+a):(s=r*Math.pow(2,a-1)*Math.pow(2,n),u=0));n>=8;e[t+I]=s&255,I+=j,s/=256,n-=8);for(u=u<<n|s,p+=n;p>0;e[t+I]=u&255,I+=j,u/=256,p-=8);e[t+I-j]|=Gr*128}});var Lr=P(H=>{"use strict";d();var z=dr(),$=xr(),gr=typeof Symbol=="function"&&typeof Symbol.for=="function"?Symbol.for("nodejs.util.inspect.custom"):null;H.Buffer=c;H.SlowBuffer=at;H.INSPECT_MAX_BYTES=50;var K=2147483647;H.kMaxLength=K;c.TYPED_ARRAY_SUPPORT=ot();!c.TYPED_ARRAY_SUPPORT&&typeof console<"u"&&typeof console.error=="function"&&console.error("This browser lacks typed array (Uint8Array) support which is required by `buffer` v5.x. Use `buffer` v4.x if you require old browser support.");function ot(){try{let e=new Uint8Array(1),r={foo:function(){return 42}};return Object.setPrototypeOf(r,Uint8Array.prototype),Object.setPrototypeOf(e,r),e.foo()===42}catch{return!1}}Object.defineProperty(c.prototype,"parent",{enumerable:!0,get:function(){if(c.isBuffer(this))return this.buffer}});Object.defineProperty(c.prototype,"offset",{enumerable:!0,get:function(){if(c.isBuffer(this))return this.byteOffset}});function C(e){if(e>K)throw new RangeError('The value "'+e+'" is invalid for option "size"');let r=new Uint8Array(e);return Object.setPrototypeOf(r,c.prototype),r}function c(e,r,t){if(typeof e=="number"){if(typeof r=="string")throw new TypeError('The "string" argument must be of type string. Received type number');return er(e)}return Ir(e,r,t)}c.poolSize=8192;function Ir(e,r,t){if(typeof e=="string")return ct(e,r);if(ArrayBuffer.isView(e))return st(e);if(e==null)throw new TypeError("The first argument must be one of type string, Buffer, ArrayBuffer, Array, or Array-like Object. Received type "+typeof e);if(T(e,ArrayBuffer)||e&&T(e.buffer,ArrayBuffer)||typeof SharedArrayBuffer<"u"&&(T(e,SharedArrayBuffer)||e&&T(e.buffer,SharedArrayBuffer)))return rr(e,r,t);if(typeof e=="number")throw new TypeError('The "value" argument must not be of type number. Received type number');let i=e.valueOf&&e.valueOf();if(i!=null&&i!==e)return c.from(i,r,t);let n=ht(e);if(n)return n;if(typeof Symbol<"u"&&Symbol.toPrimitive!=null&&typeof e[Symbol.toPrimitive]=="function")return c.from(e[Symbol.toPrimitive]("string"),r,t);throw new TypeError("The first argument must be one of type string, Buffer, ArrayBuffer, Array, or Array-like Object. Received type "+typeof e)}c.from=function(e,r,t){return Ir(e,r,t)};Object.setPrototypeOf(c.prototype,Uint8Array.prototype);Object.setPrototypeOf(c,Uint8Array);function Fr(e){if(typeof e!="number")throw new TypeError('"size" argument must be of type number');if(e<0)throw new RangeError('The value "'+e+'" is invalid for option "size"')}function ut(e,r,t){return Fr(e),e<=0?C(e):r!==void 0?typeof t=="string"?C(e).fill(r,t):C(e).fill(r):C(e)}c.alloc=function(e,r,t){return ut(e,r,t)};function er(e){return Fr(e),C(e<0?0:ir(e)|0)}c.allocUnsafe=function(e){return er(e)};c.allocUnsafeSlow=function(e){return er(e)};function ct(e,r){if((typeof r!="string"||r==="")&&(r="utf8"),!c.isEncoding(r))throw new TypeError("Unknown encoding: "+r);let t=Sr(e,r)|0,i=C(t),n=i.write(e,r);return n!==t&&(i=i.slice(0,n)),i}function Z(e){let r=e.length<0?0:ir(e.length)|0,t=C(r);for(let i=0;i<r;i+=1)t[i]=e[i]&255;return t}function st(e){if(T(e,Uint8Array)){let r=new Uint8Array(e);return rr(r.buffer,r.byteOffset,r.byteLength)}return Z(e)}function rr(e,r,t){if(r<0||e.byteLength<r)throw new RangeError('"offset" is outside of buffer bounds');if(e.byteLength<r+(t||0))throw new RangeError('"length" is outside of buffer bounds');let i;return r===void 0&&t===void 0?i=new Uint8Array(e):t===void 0?i=new Uint8Array(e,r):i=new Uint8Array(e,r,t),Object.setPrototypeOf(i,c.prototype),i}function ht(e){if(c.isBuffer(e)){let r=ir(e.length)|0,t=C(r);return t.length===0||e.copy(t,0,0,r),t}if(e.length!==void 0)return typeof e.length!="number"||or(e.length)?C(0):Z(e);if(e.type==="Buffer"&&Array.isArray(e.data))return Z(e.data)}function ir(e){if(e>=K)throw new RangeError("Attempt to allocate Buffer larger than maximum size: 0x"+K.toString(16)+" bytes");return e|0}function at(e){return+e!=e&&(e=0),c.alloc(+e)}c.isBuffer=function(r){return r!=null&&r._isBuffer===!0&&r!==c.prototype};c.compare=function(r,t){if(T(r,Uint8Array)&&(r=c.from(r,r.offset,r.byteLength)),T(t,Uint8Array)&&(t=c.from(t,t.offset,t.byteLength)),!c.isBuffer(r)||!c.isBuffer(t))throw new TypeError('The "buf1", "buf2" arguments must be one of type Buffer or Uint8Array');if(r===t)return 0;let i=r.length,n=t.length;for(let o=0,u=Math.min(i,n);o<u;++o)if(r[o]!==t[o]){i=r[o],n=t[o];break}return i<n?-1:n<i?1:0};c.isEncoding=function(r){switch(String(r).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}};c.concat=function(r,t){if(!Array.isArray(r))throw new TypeError('"list" argument must be an Array of Buffers');if(r.length===0)return c.alloc(0);let i;if(t===void 0)for(t=0,i=0;i<r.length;++i)t+=r[i].length;let n=c.allocUnsafe(t),o=0;for(i=0;i<r.length;++i){let u=r[i];if(T(u,Uint8Array))o+u.length>n.length?(c.isBuffer(u)||(u=c.from(u)),u.copy(n,o)):Uint8Array.prototype.set.call(n,u,o);else if(c.isBuffer(u))u.copy(n,o);else throw new TypeError('"list" argument must be an Array of Buffers');o+=u.length}return n};function Sr(e,r){if(c.isBuffer(e))return e.length;if(ArrayBuffer.isView(e)||T(e,ArrayBuffer))return e.byteLength;if(typeof e!="string")throw new TypeError('The "string" argument must be one of type string, Buffer, or ArrayBuffer. Received type '+typeof e);let t=e.length,i=arguments.length>2&&arguments[2]===!0;if(!i&&t===0)return 0;let n=!1;for(;;)switch(r){case"ascii":case"latin1":case"binary":return t;case"utf8":case"utf-8":return tr(e).length;case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return t*2;case"hex":return t>>>1;case"base64":return br(e).length;default:if(n)return i?-1:tr(e).length;r=(""+r).toLowerCase(),n=!0}}c.byteLength=Sr;function ft(e,r,t){let i=!1;if((r===void 0||r<0)&&(r=0),r>this.length||((t===void 0||t>this.length)&&(t=this.length),t<=0)||(t>>>=0,r>>>=0,t<=r))return"";for(e||(e="utf8");;)switch(e){case"hex":return mt(this,r,t);case"utf8":case"utf-8":return Tr(this,r,t);case"ascii":return Bt(this,r,t);case"latin1":case"binary":return Et(this,r,t);case"base64":return xt(this,r,t);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return It(this,r,t);default:if(i)throw new TypeError("Unknown encoding: "+e);e=(e+"").toLowerCase(),i=!0}}c.prototype._isBuffer=!0;function D(e,r,t){let i=e[r];e[r]=e[t],e[t]=i}c.prototype.swap16=function(){let r=this.length;if(r%2!==0)throw new RangeError("Buffer size must be a multiple of 16-bits");for(let t=0;t<r;t+=2)D(this,t,t+1);return this};c.prototype.swap32=function(){let r=this.length;if(r%4!==0)throw new RangeError("Buffer size must be a multiple of 32-bits");for(let t=0;t<r;t+=4)D(this,t,t+3),D(this,t+1,t+2);return this};c.prototype.swap64=function(){let r=this.length;if(r%8!==0)throw new RangeError("Buffer size must be a multiple of 64-bits");for(let t=0;t<r;t+=8)D(this,t,t+7),D(this,t+1,t+6),D(this,t+2,t+5),D(this,t+3,t+4);return this};c.prototype.toString=function(){let r=this.length;return r===0?"":arguments.length===0?Tr(this,0,r):ft.apply(this,arguments)};c.prototype.toLocaleString=c.prototype.toString;c.prototype.equals=function(r){if(!c.isBuffer(r))throw new TypeError("Argument must be a Buffer");return this===r?!0:c.compare(this,r)===0};c.prototype.inspect=function(){let r="",t=H.INSPECT_MAX_BYTES;return r=this.toString("hex",0,t).replace(/(.{2})/g,"$1 ").trim(),this.length>t&&(r+=" ... "),"<Buffer "+r+">"};gr&&(c.prototype[gr]=c.prototype.inspect);c.prototype.compare=function(r,t,i,n,o){if(T(r,Uint8Array)&&(r=c.from(r,r.offset,r.byteLength)),!c.isBuffer(r))throw new TypeError('The "target" argument must be one of type Buffer or Uint8Array. Received type '+typeof r);if(t===void 0&&(t=0),i===void 0&&(i=r?r.length:0),n===void 0&&(n=0),o===void 0&&(o=this.length),t<0||i>r.length||n<0||o>this.length)throw new RangeError("out of range index");if(n>=o&&t>=i)return 0;if(n>=o)return-1;if(t>=i)return 1;if(t>>>=0,i>>>=0,n>>>=0,o>>>=0,this===r)return 0;let u=o-n,s=i-t,h=Math.min(u,s),p=this.slice(n,o),f=r.slice(t,i);for(let a=0;a<h;++a)if(p[a]!==f[a]){u=p[a],s=f[a];break}return u<s?-1:s<u?1:0};function Ar(e,r,t,i,n){if(e.length===0)return-1;if(typeof t=="string"?(i=t,t=0):t>2147483647?t=2147483647:t<-2147483648&&(t=-2147483648),t=+t,or(t)&&(t=n?0:e.length-1),t<0&&(t=e.length+t),t>=e.length){if(n)return-1;t=e.length-1}else if(t<0)if(n)t=0;else return-1;if(typeof r=="string"&&(r=c.from(r,i)),c.isBuffer(r))return r.length===0?-1:Br(e,r,t,i,n);if(typeof r=="number")return r=r&255,typeof Uint8Array.prototype.indexOf=="function"?n?Uint8Array.prototype.indexOf.call(e,r,t):Uint8Array.prototype.lastIndexOf.call(e,r,t):Br(e,[r],t,i,n);throw new TypeError("val must be string, number or Buffer")}function Br(e,r,t,i,n){let o=1,u=e.length,s=r.length;if(i!==void 0&&(i=String(i).toLowerCase(),i==="ucs2"||i==="ucs-2"||i==="utf16le"||i==="utf-16le")){if(e.length<2||r.length<2)return-1;o=2,u/=2,s/=2,t/=2}function h(f,a){return o===1?f[a]:f.readUInt16BE(a*o)}let p;if(n){let f=-1;for(p=t;p<u;p++)if(h(e,p)===h(r,f===-1?0:p-f)){if(f===-1&&(f=p),p-f+1===s)return f*o}else f!==-1&&(p-=p-f),f=-1}else for(t+s>u&&(t=u-s),p=t;p>=0;p--){let f=!0;for(let a=0;a<s;a++)if(h(e,p+a)!==h(r,a)){f=!1;break}if(f)return p}return-1}c.prototype.includes=function(r,t,i){return this.indexOf(r,t,i)!==-1};c.prototype.indexOf=function(r,t,i){return Ar(this,r,t,i,!0)};c.prototype.lastIndexOf=function(r,t,i){return Ar(this,r,t,i,!1)};function pt(e,r,t,i){t=Number(t)||0;let n=e.length-t;i?(i=Number(i),i>n&&(i=n)):i=n;let o=r.length;i>o/2&&(i=o/2);let u;for(u=0;u<i;++u){let s=parseInt(r.substr(u*2,2),16);if(or(s))return u;e[t+u]=s}return u}function lt(e,r,t,i){return V(tr(r,e.length-t),e,t,i)}function yt(e,r,t,i){return V(Tt(r),e,t,i)}function wt(e,r,t,i){return V(br(r),e,t,i)}function dt(e,r,t,i){return V(Ut(r,e.length-t),e,t,i)}c.prototype.write=function(r,t,i,n){if(t===void 0)n="utf8",i=this.length,t=0;else if(i===void 0&&typeof t=="string")n=t,i=this.length,t=0;else if(isFinite(t))t=t>>>0,isFinite(i)?(i=i>>>0,n===void 0&&(n="utf8")):(n=i,i=void 0);else throw new Error("Buffer.write(string, encoding, offset[, length]) is no longer supported");let o=this.length-t;if((i===void 0||i>o)&&(i=o),r.length>0&&(i<0||t<0)||t>this.length)throw new RangeError("Attempt to write outside buffer bounds");n||(n="utf8");let u=!1;for(;;)switch(n){case"hex":return pt(this,r,t,i);case"utf8":case"utf-8":return lt(this,r,t,i);case"ascii":case"latin1":case"binary":return yt(this,r,t,i);case"base64":return wt(this,r,t,i);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return dt(this,r,t,i);default:if(u)throw new TypeError("Unknown encoding: "+n);n=(""+n).toLowerCase(),u=!0}};c.prototype.toJSON=function(){return{type:"Buffer",data:Array.prototype.slice.call(this._arr||this,0)}};function xt(e,r,t){return r===0&&t===e.length?z.fromByteArray(e):z.fromByteArray(e.slice(r,t))}function Tr(e,r,t){t=Math.min(e.length,t);let i=[],n=r;for(;n<t;){let o=e[n],u=null,s=o>239?4:o>223?3:o>191?2:1;if(n+s<=t){let h,p,f,a;switch(s){case 1:o<128&&(u=o);break;case 2:h=e[n+1],(h&192)===128&&(a=(o&31)<<6|h&63,a>127&&(u=a));break;case 3:h=e[n+1],p=e[n+2],(h&192)===128&&(p&192)===128&&(a=(o&15)<<12|(h&63)<<6|p&63,a>2047&&(a<55296||a>57343)&&(u=a));break;case 4:h=e[n+1],p=e[n+2],f=e[n+3],(h&192)===128&&(p&192)===128&&(f&192)===128&&(a=(o&15)<<18|(h&63)<<12|(p&63)<<6|f&63,a>65535&&a<1114112&&(u=a))}}u===null?(u=65533,s=1):u>65535&&(u-=65536,i.push(u>>>10&1023|55296),u=56320|u&1023),i.push(u),n+=s}return gt(i)}var Er=4096;function gt(e){let r=e.length;if(r<=Er)return String.fromCharCode.apply(String,e);let t="",i=0;for(;i<r;)t+=String.fromCharCode.apply(String,e.slice(i,i+=Er));return t}function Bt(e,r,t){let i="";t=Math.min(e.length,t);for(let n=r;n<t;++n)i+=String.fromCharCode(e[n]&127);return i}function Et(e,r,t){let i="";t=Math.min(e.length,t);for(let n=r;n<t;++n)i+=String.fromCharCode(e[n]);return i}function mt(e,r,t){let i=e.length;(!r||r<0)&&(r=0),(!t||t<0||t>i)&&(t=i);let n="";for(let o=r;o<t;++o)n+=Rt[e[o]];return n}function It(e,r,t){let i=e.slice(r,t),n="";for(let o=0;o<i.length-1;o+=2)n+=String.fromCharCode(i[o]+i[o+1]*256);return n}c.prototype.slice=function(r,t){let i=this.length;r=~~r,t=t===void 0?i:~~t,r<0?(r+=i,r<0&&(r=0)):r>i&&(r=i),t<0?(t+=i,t<0&&(t=0)):t>i&&(t=i),t<r&&(t=r);let n=this.subarray(r,t);return Object.setPrototypeOf(n,c.prototype),n};function w(e,r,t){if(e%1!==0||e<0)throw new RangeError("offset is not uint");if(e+r>t)throw new RangeError("Trying to access beyond buffer length")}c.prototype.readUintLE=c.prototype.readUIntLE=function(r,t,i){r=r>>>0,t=t>>>0,i||w(r,t,this.length);let n=this[r],o=1,u=0;for(;++u<t&&(o*=256);)n+=this[r+u]*o;return n};c.prototype.readUintBE=c.prototype.readUIntBE=function(r,t,i){r=r>>>0,t=t>>>0,i||w(r,t,this.length);let n=this[r+--t],o=1;for(;t>0&&(o*=256);)n+=this[r+--t]*o;return n};c.prototype.readUint8=c.prototype.readUInt8=function(r,t){return r=r>>>0,t||w(r,1,this.length),this[r]};c.prototype.readUint16LE=c.prototype.readUInt16LE=function(r,t){return r=r>>>0,t||w(r,2,this.length),this[r]|this[r+1]<<8};c.prototype.readUint16BE=c.prototype.readUInt16BE=function(r,t){return r=r>>>0,t||w(r,2,this.length),this[r]<<8|this[r+1]};c.prototype.readUint32LE=c.prototype.readUInt32LE=function(r,t){return r=r>>>0,t||w(r,4,this.length),(this[r]|this[r+1]<<8|this[r+2]<<16)+this[r+3]*16777216};c.prototype.readUint32BE=c.prototype.readUInt32BE=function(r,t){return r=r>>>0,t||w(r,4,this.length),this[r]*16777216+(this[r+1]<<16|this[r+2]<<8|this[r+3])};c.prototype.readBigUInt64LE=N(function(r){r=r>>>0,v(r,"offset");let t=this[r],i=this[r+7];(t===void 0||i===void 0)&&G(r,this.length-8);let n=t+this[++r]*2**8+this[++r]*2**16+this[++r]*2**24,o=this[++r]+this[++r]*2**8+this[++r]*2**16+i*2**24;return BigInt(n)+(BigInt(o)<<BigInt(32))});c.prototype.readBigUInt64BE=N(function(r){r=r>>>0,v(r,"offset");let t=this[r],i=this[r+7];(t===void 0||i===void 0)&&G(r,this.length-8);let n=t*2**24+this[++r]*2**16+this[++r]*2**8+this[++r],o=this[++r]*2**24+this[++r]*2**16+this[++r]*2**8+i;return(BigInt(n)<<BigInt(32))+BigInt(o)});c.prototype.readIntLE=function(r,t,i){r=r>>>0,t=t>>>0,i||w(r,t,this.length);let n=this[r],o=1,u=0;for(;++u<t&&(o*=256);)n+=this[r+u]*o;return o*=128,n>=o&&(n-=Math.pow(2,8*t)),n};c.prototype.readIntBE=function(r,t,i){r=r>>>0,t=t>>>0,i||w(r,t,this.length);let n=t,o=1,u=this[r+--n];for(;n>0&&(o*=256);)u+=this[r+--n]*o;return o*=128,u>=o&&(u-=Math.pow(2,8*t)),u};c.prototype.readInt8=function(r,t){return r=r>>>0,t||w(r,1,this.length),this[r]&128?(255-this[r]+1)*-1:this[r]};c.prototype.readInt16LE=function(r,t){r=r>>>0,t||w(r,2,this.length);let i=this[r]|this[r+1]<<8;return i&32768?i|4294901760:i};c.prototype.readInt16BE=function(r,t){r=r>>>0,t||w(r,2,this.length);let i=this[r+1]|this[r]<<8;return i&32768?i|4294901760:i};c.prototype.readInt32LE=function(r,t){return r=r>>>0,t||w(r,4,this.length),this[r]|this[r+1]<<8|this[r+2]<<16|this[r+3]<<24};c.prototype.readInt32BE=function(r,t){return r=r>>>0,t||w(r,4,this.length),this[r]<<24|this[r+1]<<16|this[r+2]<<8|this[r+3]};c.prototype.readBigInt64LE=N(function(r){r=r>>>0,v(r,"offset");let t=this[r],i=this[r+7];(t===void 0||i===void 0)&&G(r,this.length-8);let n=this[r+4]+this[r+5]*2**8+this[r+6]*2**16+(i<<24);return(BigInt(n)<<BigInt(32))+BigInt(t+this[++r]*2**8+this[++r]*2**16+this[++r]*2**24)});c.prototype.readBigInt64BE=N(function(r){r=r>>>0,v(r,"offset");let t=this[r],i=this[r+7];(t===void 0||i===void 0)&&G(r,this.length-8);let n=(t<<24)+this[++r]*2**16+this[++r]*2**8+this[++r];return(BigInt(n)<<BigInt(32))+BigInt(this[++r]*2**24+this[++r]*2**16+this[++r]*2**8+i)});c.prototype.readFloatLE=function(r,t){return r=r>>>0,t||w(r,4,this.length),$.read(this,r,!0,23,4)};c.prototype.readFloatBE=function(r,t){return r=r>>>0,t||w(r,4,this.length),$.read(this,r,!1,23,4)};c.prototype.readDoubleLE=function(r,t){return r=r>>>0,t||w(r,8,this.length),$.read(this,r,!0,52,8)};c.prototype.readDoubleBE=function(r,t){return r=r>>>0,t||w(r,8,this.length),$.read(this,r,!1,52,8)};function x(e,r,t,i,n,o){if(!c.isBuffer(e))throw new TypeError('"buffer" argument must be a Buffer instance');if(r>n||r<o)throw new RangeError('"value" argument is out of bounds');if(t+i>e.length)throw new RangeError("Index out of range")}c.prototype.writeUintLE=c.prototype.writeUIntLE=function(r,t,i,n){if(r=+r,t=t>>>0,i=i>>>0,!n){let s=Math.pow(2,8*i)-1;x(this,r,t,i,s,0)}let o=1,u=0;for(this[t]=r&255;++u<i&&(o*=256);)this[t+u]=r/o&255;return t+i};c.prototype.writeUintBE=c.prototype.writeUIntBE=function(r,t,i,n){if(r=+r,t=t>>>0,i=i>>>0,!n){let s=Math.pow(2,8*i)-1;x(this,r,t,i,s,0)}let o=i-1,u=1;for(this[t+o]=r&255;--o>=0&&(u*=256);)this[t+o]=r/u&255;return t+i};c.prototype.writeUint8=c.prototype.writeUInt8=function(r,t,i){return r=+r,t=t>>>0,i||x(this,r,t,1,255,0),this[t]=r&255,t+1};c.prototype.writeUint16LE=c.prototype.writeUInt16LE=function(r,t,i){return r=+r,t=t>>>0,i||x(this,r,t,2,65535,0),this[t]=r&255,this[t+1]=r>>>8,t+2};c.prototype.writeUint16BE=c.prototype.writeUInt16BE=function(r,t,i){return r=+r,t=t>>>0,i||x(this,r,t,2,65535,0),this[t]=r>>>8,this[t+1]=r&255,t+2};c.prototype.writeUint32LE=c.prototype.writeUInt32LE=function(r,t,i){return r=+r,t=t>>>0,i||x(this,r,t,4,4294967295,0),this[t+3]=r>>>24,this[t+2]=r>>>16,this[t+1]=r>>>8,this[t]=r&255,t+4};c.prototype.writeUint32BE=c.prototype.writeUInt32BE=function(r,t,i){return r=+r,t=t>>>0,i||x(this,r,t,4,4294967295,0),this[t]=r>>>24,this[t+1]=r>>>16,this[t+2]=r>>>8,this[t+3]=r&255,t+4};function Ur(e,r,t,i,n){Nr(r,i,n,e,t,7);let o=Number(r&BigInt(4294967295));e[t++]=o,o=o>>8,e[t++]=o,o=o>>8,e[t++]=o,o=o>>8,e[t++]=o;let u=Number(r>>BigInt(32)&BigInt(4294967295));return e[t++]=u,u=u>>8,e[t++]=u,u=u>>8,e[t++]=u,u=u>>8,e[t++]=u,t}function Rr(e,r,t,i,n){Nr(r,i,n,e,t,7);let o=Number(r&BigInt(4294967295));e[t+7]=o,o=o>>8,e[t+6]=o,o=o>>8,e[t+5]=o,o=o>>8,e[t+4]=o;let u=Number(r>>BigInt(32)&BigInt(4294967295));return e[t+3]=u,u=u>>8,e[t+2]=u,u=u>>8,e[t+1]=u,u=u>>8,e[t]=u,t+8}c.prototype.writeBigUInt64LE=N(function(r,t=0){return Ur(this,r,t,BigInt(0),BigInt("0xffffffffffffffff"))});c.prototype.writeBigUInt64BE=N(function(r,t=0){return Rr(this,r,t,BigInt(0),BigInt("0xffffffffffffffff"))});c.prototype.writeIntLE=function(r,t,i,n){if(r=+r,t=t>>>0,!n){let h=Math.pow(2,8*i-1);x(this,r,t,i,h-1,-h)}let o=0,u=1,s=0;for(this[t]=r&255;++o<i&&(u*=256);)r<0&&s===0&&this[t+o-1]!==0&&(s=1),this[t+o]=(r/u>>0)-s&255;return t+i};c.prototype.writeIntBE=function(r,t,i,n){if(r=+r,t=t>>>0,!n){let h=Math.pow(2,8*i-1);x(this,r,t,i,h-1,-h)}let o=i-1,u=1,s=0;for(this[t+o]=r&255;--o>=0&&(u*=256);)r<0&&s===0&&this[t+o+1]!==0&&(s=1),this[t+o]=(r/u>>0)-s&255;return t+i};c.prototype.writeInt8=function(r,t,i){return r=+r,t=t>>>0,i||x(this,r,t,1,127,-128),r<0&&(r=255+r+1),this[t]=r&255,t+1};c.prototype.writeInt16LE=function(r,t,i){return r=+r,t=t>>>0,i||x(this,r,t,2,32767,-32768),this[t]=r&255,this[t+1]=r>>>8,t+2};c.prototype.writeInt16BE=function(r,t,i){return r=+r,t=t>>>0,i||x(this,r,t,2,32767,-32768),this[t]=r>>>8,this[t+1]=r&255,t+2};c.prototype.writeInt32LE=function(r,t,i){return r=+r,t=t>>>0,i||x(this,r,t,4,2147483647,-2147483648),this[t]=r&255,this[t+1]=r>>>8,this[t+2]=r>>>16,this[t+3]=r>>>24,t+4};c.prototype.writeInt32BE=function(r,t,i){return r=+r,t=t>>>0,i||x(this,r,t,4,2147483647,-2147483648),r<0&&(r=4294967295+r+1),this[t]=r>>>24,this[t+1]=r>>>16,this[t+2]=r>>>8,this[t+3]=r&255,t+4};c.prototype.writeBigInt64LE=N(function(r,t=0){return Ur(this,r,t,-BigInt("0x8000000000000000"),BigInt("0x7fffffffffffffff"))});c.prototype.writeBigInt64BE=N(function(r,t=0){return Rr(this,r,t,-BigInt("0x8000000000000000"),BigInt("0x7fffffffffffffff"))});function Cr(e,r,t,i,n,o){if(t+i>e.length)throw new RangeError("Index out of range");if(t<0)throw new RangeError("Index out of range")}function _r(e,r,t,i,n){return r=+r,t=t>>>0,n||Cr(e,r,t,4,34028234663852886e22,-34028234663852886e22),$.write(e,r,t,i,23,4),t+4}c.prototype.writeFloatLE=function(r,t,i){return _r(this,r,t,!0,i)};c.prototype.writeFloatBE=function(r,t,i){return _r(this,r,t,!1,i)};function Pr(e,r,t,i,n){return r=+r,t=t>>>0,n||Cr(e,r,t,8,17976931348623157e292,-17976931348623157e292),$.write(e,r,t,i,52,8),t+8}c.prototype.writeDoubleLE=function(r,t,i){return Pr(this,r,t,!0,i)};c.prototype.writeDoubleBE=function(r,t,i){return Pr(this,r,t,!1,i)};c.prototype.copy=function(r,t,i,n){if(!c.isBuffer(r))throw new TypeError("argument should be a Buffer");if(i||(i=0),!n&&n!==0&&(n=this.length),t>=r.length&&(t=r.length),t||(t=0),n>0&&n<i&&(n=i),n===i||r.length===0||this.length===0)return 0;if(t<0)throw new RangeError("targetStart out of bounds");if(i<0||i>=this.length)throw new RangeError("Index out of range");if(n<0)throw new RangeError("sourceEnd out of bounds");n>this.length&&(n=this.length),r.length-t<n-i&&(n=r.length-t+i);let o=n-i;return this===r&&typeof Uint8Array.prototype.copyWithin=="function"?this.copyWithin(t,i,n):Uint8Array.prototype.set.call(r,this.subarray(i,n),t),o};c.prototype.fill=function(r,t,i,n){if(typeof r=="string"){if(typeof t=="string"?(n=t,t=0,i=this.length):typeof i=="string"&&(n=i,i=this.length),n!==void 0&&typeof n!="string")throw new TypeError("encoding must be a string");if(typeof n=="string"&&!c.isEncoding(n))throw new TypeError("Unknown encoding: "+n);if(r.length===1){let u=r.charCodeAt(0);(n==="utf8"&&u<128||n==="latin1")&&(r=u)}}else typeof r=="number"?r=r&255:typeof r=="boolean"&&(r=Number(r));if(t<0||this.length<t||this.length<i)throw new RangeError("Out of range index");if(i<=t)return this;t=t>>>0,i=i===void 0?this.length:i>>>0,r||(r=0);let o;if(typeof r=="number")for(o=t;o<i;++o)this[o]=r;else{let u=c.isBuffer(r)?r:c.from(r,n),s=u.length;if(s===0)throw new TypeError('The value "'+r+'" is invalid for argument "value"');for(o=0;o<i-t;++o)this[o+t]=u[o%s]}return this};var O={};function nr(e,r,t){O[e]=class extends t{constructor(){super(),Object.defineProperty(this,"message",{value:r.apply(this,arguments),writable:!0,configurable:!0}),this.name=`${this.name} [${e}]`,this.stack,delete this.name}get code(){return e}set code(n){Object.defineProperty(this,"code",{configurable:!0,enumerable:!0,value:n,writable:!0})}toString(){return`${this.name} [${e}]: ${this.message}`}}}nr("ERR_BUFFER_OUT_OF_BOUNDS",function(e){return e?`${e} is outside of buffer bounds`:"Attempt to access memory outside buffer bounds"},RangeError);nr("ERR_INVALID_ARG_TYPE",function(e,r){return`The "${e}" argument must be of type number. Received type ${typeof r}`},TypeError);nr("ERR_OUT_OF_RANGE",function(e,r,t){let i=`The value of "${e}" is out of range.`,n=t;return Number.isInteger(t)&&Math.abs(t)>2**32?n=mr(String(t)):typeof t=="bigint"&&(n=String(t),(t>BigInt(2)**BigInt(32)||t<-(BigInt(2)**BigInt(32)))&&(n=mr(n)),n+="n"),i+=` It must be ${r}. Received ${n}`,i},RangeError);function mr(e){let r="",t=e.length,i=e[0]==="-"?1:0;for(;t>=i+4;t-=3)r=`_${e.slice(t-3,t)}${r}`;return`${e.slice(0,t)}${r}`}function Ft(e,r,t){v(r,"offset"),(e[r]===void 0||e[r+t]===void 0)&&G(r,e.length-(t+1))}function Nr(e,r,t,i,n,o){if(e>t||e<r){let u=typeof r=="bigint"?"n":"",s;throw o>3?r===0||r===BigInt(0)?s=`>= 0${u} and < 2${u} ** ${(o+1)*8}${u}`:s=`>= -(2${u} ** ${(o+1)*8-1}${u}) and < 2 ** ${(o+1)*8-1}${u}`:s=`>= ${r}${u} and <= ${t}${u}`,new O.ERR_OUT_OF_RANGE("value",s,e)}Ft(i,n,o)}function v(e,r){if(typeof e!="number")throw new O.ERR_INVALID_ARG_TYPE(r,"number",e)}function G(e,r,t){throw Math.floor(e)!==e?(v(e,t),new O.ERR_OUT_OF_RANGE(t||"offset","an integer",e)):r<0?new O.ERR_BUFFER_OUT_OF_BOUNDS:new O.ERR_OUT_OF_RANGE(t||"offset",`>= ${t?1:0} and <= ${r}`,e)}var St=/[^+/0-9A-Za-z-_]/g;function At(e){if(e=e.split("=")[0],e=e.trim().replace(St,""),e.length<2)return"";for(;e.length%4!==0;)e=e+"=";return e}function tr(e,r){r=r||1/0;let t,i=e.length,n=null,o=[];for(let u=0;u<i;++u){if(t=e.charCodeAt(u),t>55295&&t<57344){if(!n){if(t>56319){(r-=3)>-1&&o.push(239,191,189);continue}else if(u+1===i){(r-=3)>-1&&o.push(239,191,189);continue}n=t;continue}if(t<56320){(r-=3)>-1&&o.push(239,191,189),n=t;continue}t=(n-55296<<10|t-56320)+65536}else n&&(r-=3)>-1&&o.push(239,191,189);if(n=null,t<128){if((r-=1)<0)break;o.push(t)}else if(t<2048){if((r-=2)<0)break;o.push(t>>6|192,t&63|128)}else if(t<65536){if((r-=3)<0)break;o.push(t>>12|224,t>>6&63|128,t&63|128)}else if(t<1114112){if((r-=4)<0)break;o.push(t>>18|240,t>>12&63|128,t>>6&63|128,t&63|128)}else throw new Error("Invalid code point")}return o}function Tt(e){let r=[];for(let t=0;t<e.length;++t)r.push(e.charCodeAt(t)&255);return r}function Ut(e,r){let t,i,n,o=[];for(let u=0;u<e.length&&!((r-=2)<0);++u)t=e.charCodeAt(u),i=t>>8,n=t%256,o.push(n),o.push(i);return o}function br(e){return z.toByteArray(At(e))}function V(e,r,t,i){let n;for(n=0;n<i&&!(n+t>=r.length||n>=e.length);++n)r[n+t]=e[n];return n}function T(e,r){return e instanceof r||e!=null&&e.constructor!=null&&e.constructor.name!=null&&e.constructor.name===r.name}function or(e){return e!==e}var Rt=(function(){let e="0123456789abcdef",r=new Array(256);for(let t=0;t<16;++t){let i=t*16;for(let n=0;n<16;++n)r[i+n]=e[t]+e[n]}return r})();function N(e){return typeof BigInt>"u"?Ct:e}function Ct(){throw new Error("BigInt not supported")}});var B,m,d=Wr(()=>{B=sr(lr()),m=sr(Lr())});var kr=P((qt,Dr)=>{d();Dr.exports=(typeof globalThis<"u"?globalThis:typeof self<"u"?self:window).bsv});var ur=P((Kt,Mr)=>{"use strict";d();Mr.exports={}});var vr=P((jt,$r)=>{"use strict";d();var l=kr(),Or=ur(),_;try{_=ur()}catch{_=null}var _t=function(){var e=typeof B.default<"u"&&B.default.env&&B.default.env.BSV_DEBUG||typeof window<"u"&&window.BSV_DEBUG;e&&console.log.apply(console,arguments)};function g(e,r){if(!(this instanceof g))return new g(e,r);this.privateKey=e,this.publicKey=e.publicKey,this.address=e.toAddress(),r=r||{},this.storageDir=r.storageDir||(typeof B.default<"u"?Or.join(B.default.cwd(),".bsv-covenants"):".bsv-covenants"),this.covenantUtxoPath=Or.join(this.storageDir,"covenant_utxos.json"),this.sighashType=l.crypto.Signature.SIGHASH_ALL|l.crypto.Signature.SIGHASH_FORKID,this.allowNonEnforcing=r.allowNonEnforcing===!0,_&&this._ensureStorageDir()}g.prototype.createFromP2PKH=function(e){if(!this.allowNonEnforcing)throw new Error("SmartContract.Covenant builds a NON-ENFORCING script that reduces to plain P2PK \u2014 it does not constrain the spend. Use SmartContract.PushTx.valueCovenant (output binding) or SmartContract.Token / perpetualCovenant (stateful covenants) for real covenants. To use this demo anyway, construct with { allowNonEnforcing: true }.");e.script||(e.script=g.reconstructP2pkhScript(this.address));var r=new l.Transaction().from({txId:e.txid,outputIndex:e.vout,script:e.script,satoshis:e.satoshis}).to(this.address,e.satoshis-1e3),t=l.Script.fromHex(e.script),i=l.Transaction.sighash.sighashPreimage(r,this.sighashType,0,t,new l.crypto.BN(e.satoshis)),n=l.crypto.Hash.sha256sha256(i),o=new l.Script().add("OP_DUP").add("OP_HASH256").add(n).add("OP_EQUALVERIFY").add("OP_DROP").add(this.publicKey.toBuffer()).add("OP_CHECKSIG");r.outputs[0].setScript(o),r.sign(this.privateKey);var u={txid:r.id,vout:0,satoshis:e.satoshis-1e3,script:o.toHex(),scriptPubKey:o.toHex(),preimageHash:n.toString("hex"),originalPreimage:i.toString("hex"),status:"local",createdAt:new Date().toISOString(),type:"preimage_covenant"};return{transaction:r,covenantUtxo:u}};g.prototype.createSpendingTx=function(e,r,t){var i=r||this.address,n=t||e.satoshis-500,o=new l.Transaction;o.addInput(new l.Transaction.Input({prevTxId:e.txid,outputIndex:e.vout,script:l.Script.empty()}),l.Script.fromHex(e.script),e.satoshis),o.to(i,n);var u=l.Script.fromHex(e.script),s=l.Transaction.sighash.sign(o,this.privateKey,this.sighashType,0,u,new l.crypto.BN(e.satoshis)),h=m.Buffer.concat([s.toDER(),m.Buffer.from([this.sighashType])]),p=m.Buffer.from(e.originalPreimage,"hex"),f=new l.Script().add(h).add(p);return o.inputs[0].setScript(f),o};g.prototype.validate=function(e,r){var t=new l.Script.Interpreter,i=l.Script.Interpreter.SCRIPT_VERIFY_P2SH|l.Script.Interpreter.SCRIPT_VERIFY_STRICTENC|l.Script.Interpreter.SCRIPT_VERIFY_DERSIG|l.Script.Interpreter.SCRIPT_VERIFY_LOW_S|l.Script.Interpreter.SCRIPT_ENABLE_SIGHASH_FORKID,n=e.inputs[0].script,o=l.Script.fromHex(r.script),u=t.verify(n,o,e,0,i,new l.crypto.BN(r.satoshis));return{valid:u,error:u?null:t.errstr}};g.prototype.save=function(e){if(!_)return _t("File system operations not available in browser environment"),e;var r=this.list();return r.push(e),_.writeFileSync(this.covenantUtxoPath,JSON.stringify(r,null,2)),e};g.prototype.load=function(e){var r=this.list();if(e){var t=r.find(function(i){return i.txid===e});if(!t)throw new Error("Covenant UTXO with TXID "+e+" not found");return t}else{var t=r.find(function(n){return n.type==="preimage_covenant"});if(!t)throw new Error("No preimage covenant UTXO found");return t}};g.prototype.list=function(){return _.existsSync(this.covenantUtxoPath)?JSON.parse(_.readFileSync(this.covenantUtxoPath,"utf8")):[]};g.prototype.getPortfolio=function(){var e=this.list(),r={total:e.length,totalValue:e.reduce(function(t,i){return t+i.satoshis},0),byStatus:{},recent:e.slice(-5)};return e.forEach(function(t){var i=t.status||"local";r.byStatus[i]||(r.byStatus[i]={count:0,value:0}),r.byStatus[i].count++,r.byStatus[i].value+=t.satoshis}),r};g.prototype.completeFlow=function(e,r){var t=this.createFromP2PKH(e),i=this.save(t.covenantUtxo);r&&r(t.transaction,"creation");var n=this.createSpendingTx(i),o=this.validate(n,i);return r&&o.valid&&r(n,"spending"),{creationTx:t.transaction,spendingTx:n,covenantUtxo:i,validation:o,success:o.valid}};g.prototype._ensureStorageDir=function(){_.existsSync(this.storageDir)||_.mkdirSync(this.storageDir,{recursive:!0})};g.reconstructP2pkhScript=function(e){return l.Script.buildPublicKeyHashOut(e).toHex()};$r.exports=g});var Pt=P((Xt,Hr)=>{d();Hr.exports=vr()});return Pt();})();
1
+ var bsvCovenant=(()=>{var ct=Object.create;var hr=Object.defineProperty;var ht=Object.getOwnPropertyDescriptor;var ft=Object.getOwnPropertyNames;var at=Object.getPrototypeOf,pt=Object.prototype.hasOwnProperty;var lt=(e,r,t)=>()=>{if(t)throw t[0];try{return e&&(r=e(e=0)),r}catch(i){throw t=[i],i}};var g=(e,r)=>()=>{try{return r||e((r={exports:{}}).exports,r),r.exports}catch(t){throw r=0,t}};var yt=(e,r,t,i)=>{if(r&&typeof r=="object"||typeof r=="function")for(let n of ft(r))!pt.call(e,n)&&n!==t&&hr(e,n,{get:()=>r[n],enumerable:!(i=ht(r,n))||i.enumerable});return e};var fr=(e,r,t)=>(t=e!=null?ct(at(e)):{},yt(r||!e||!e.__esModule?hr(t,"default",{value:e,enumerable:!0}):t,e));var dr=g((re,yr)=>{l();var y=yr.exports={},F,T;function X(){throw new Error("setTimeout has not been defined")}function J(){throw new Error("clearTimeout has not been defined")}(function(){try{typeof setTimeout=="function"?F=setTimeout:F=X}catch{F=X}try{typeof clearTimeout=="function"?T=clearTimeout:T=J}catch{T=J}})();function ar(e){if(F===setTimeout)return setTimeout(e,0);if((F===X||!F)&&setTimeout)return F=setTimeout,setTimeout(e,0);try{return F(e,0)}catch{try{return F.call(null,e,0)}catch{return F.call(this,e,0)}}}function dt(e){if(T===clearTimeout)return clearTimeout(e);if((T===J||!T)&&clearTimeout)return T=clearTimeout,clearTimeout(e);try{return T(e)}catch{try{return T.call(null,e)}catch{return T.call(this,e)}}}var S=[],k=!1,N,Y=-1;function wt(){!k||!N||(k=!1,N.length?S=N.concat(S):Y=-1,S.length&&pr())}function pr(){if(!k){var e=ar(wt);k=!0;for(var r=S.length;r;){for(N=S,S=[];++Y<r;)N&&N[Y].run();Y=-1,r=S.length}N=null,k=!1,dt(e)}}y.nextTick=function(e){var r=new Array(arguments.length-1);if(arguments.length>1)for(var t=1;t<arguments.length;t++)r[t-1]=arguments[t];S.push(new lr(e,r)),S.length===1&&!k&&ar(pr)};function lr(e,r){this.fun=e,this.array=r}lr.prototype.run=function(){this.fun.apply(null,this.array)};y.title="browser";y.browser=!0;y.env={};y.argv=[];y.version="";y.versions={};function R(){}y.on=R;y.addListener=R;y.once=R;y.off=R;y.removeListener=R;y.removeAllListeners=R;y.emit=R;y.prependListener=R;y.prependOnceListener=R;y.listeners=function(e){return[]};y.binding=function(e){throw new Error("process.binding is not supported")};y.cwd=function(){return"/"};y.chdir=function(e){throw new Error("process.chdir is not supported")};y.umask=function(){return 0}});var gr=g(K=>{"use strict";l();K.byteLength=gt;K.toByteArray=Et;K.fromByteArray=Ft;var A=[],m=[],xt=typeof Uint8Array<"u"?Uint8Array:Array,Q="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";for(L=0,wr=Q.length;L<wr;++L)A[L]=Q[L],m[Q.charCodeAt(L)]=L;var L,wr;m[45]=62;m[95]=63;function xr(e){var r=e.length;if(r%4>0)throw new Error("Invalid string. Length must be a multiple of 4");var t=e.indexOf("=");t===-1&&(t=r);var i=t===r?0:4-t%4;return[t,i]}function gt(e){var r=xr(e),t=r[0],i=r[1];return(t+i)*3/4-i}function Bt(e,r,t){return(r+t)*3/4-t}function Et(e){var r,t=xr(e),i=t[0],n=t[1],o=new xt(Bt(e,i,n)),u=0,c=n>0?i-4:i,h;for(h=0;h<c;h+=4)r=m[e.charCodeAt(h)]<<18|m[e.charCodeAt(h+1)]<<12|m[e.charCodeAt(h+2)]<<6|m[e.charCodeAt(h+3)],o[u++]=r>>16&255,o[u++]=r>>8&255,o[u++]=r&255;return n===2&&(r=m[e.charCodeAt(h)]<<2|m[e.charCodeAt(h+1)]>>4,o[u++]=r&255),n===1&&(r=m[e.charCodeAt(h)]<<10|m[e.charCodeAt(h+1)]<<4|m[e.charCodeAt(h+2)]>>2,o[u++]=r>>8&255,o[u++]=r&255),o}function mt(e){return A[e>>18&63]+A[e>>12&63]+A[e>>6&63]+A[e&63]}function It(e,r,t){for(var i,n=[],o=r;o<t;o+=3)i=(e[o]<<16&16711680)+(e[o+1]<<8&65280)+(e[o+2]&255),n.push(mt(i));return n.join("")}function Ft(e){for(var r,t=e.length,i=t%3,n=[],o=16383,u=0,c=t-i;u<c;u+=o)n.push(It(e,u,u+o>c?c:u+o));return i===1?(r=e[t-1],n.push(A[r>>2]+A[r<<4&63]+"==")):i===2&&(r=(e[t-2]<<8)+e[t-1],n.push(A[r>>10]+A[r>>4&63]+A[r<<2&63]+"=")),n.join("")}});var Br=g(z=>{l();z.read=function(e,r,t,i,n){var o,u,c=n*8-i-1,h=(1<<c)-1,p=h>>1,a=-7,f=t?n-1:0,v=t?-1:1,I=e[r+f];for(f+=v,o=I&(1<<-a)-1,I>>=-a,a+=c;a>0;o=o*256+e[r+f],f+=v,a-=8);for(u=o&(1<<-a)-1,o>>=-a,a+=i;a>0;u=u*256+e[r+f],f+=v,a-=8);if(o===0)o=1-p;else{if(o===h)return u?NaN:(I?-1:1)*(1/0);u=u+Math.pow(2,i),o=o-p}return(I?-1:1)*u*Math.pow(2,o-i)};z.write=function(e,r,t,i,n,o){var u,c,h,p=o*8-n-1,a=(1<<p)-1,f=a>>1,v=n===23?Math.pow(2,-24)-Math.pow(2,-77):0,I=i?0:o-1,W=i?1:-1,st=r<0||r===0&&1/r<0?1:0;for(r=Math.abs(r),isNaN(r)||r===1/0?(c=isNaN(r)?1:0,u=a):(u=Math.floor(Math.log(r)/Math.LN2),r*(h=Math.pow(2,-u))<1&&(u--,h*=2),u+f>=1?r+=v/h:r+=v*Math.pow(2,1-f),r*h>=2&&(u++,h/=2),u+f>=a?(c=0,u=a):u+f>=1?(c=(r*h-1)*Math.pow(2,n),u=u+f):(c=r*Math.pow(2,f-1)*Math.pow(2,n),u=0));n>=8;e[t+I]=c&255,I+=W,c/=256,n-=8);for(u=u<<n|c,p+=n;p>0;e[t+I]=u&255,I+=W,u/=256,p-=8);e[t+I-W]|=st*128}});var vr=g(H=>{"use strict";l();var Z=gr(),O=Br(),Er=typeof Symbol=="function"&&typeof Symbol.for=="function"?Symbol.for("nodejs.util.inspect.custom"):null;H.Buffer=s;H.SlowBuffer=Ct;H.INSPECT_MAX_BYTES=50;var V=2147483647;H.kMaxLength=V;s.TYPED_ARRAY_SUPPORT=Tt();!s.TYPED_ARRAY_SUPPORT&&typeof console<"u"&&typeof console.error=="function"&&console.error("This browser lacks typed array (Uint8Array) support which is required by `buffer` v5.x. Use `buffer` v4.x if you require old browser support.");function Tt(){try{let e=new Uint8Array(1),r={foo:function(){return 42}};return Object.setPrototypeOf(r,Uint8Array.prototype),Object.setPrototypeOf(e,r),e.foo()===42}catch{return!1}}Object.defineProperty(s.prototype,"parent",{enumerable:!0,get:function(){if(s.isBuffer(this))return this.buffer}});Object.defineProperty(s.prototype,"offset",{enumerable:!0,get:function(){if(s.isBuffer(this))return this.byteOffset}});function C(e){if(e>V)throw new RangeError('The value "'+e+'" is invalid for option "size"');let r=new Uint8Array(e);return Object.setPrototypeOf(r,s.prototype),r}function s(e,r,t){if(typeof e=="number"){if(typeof r=="string")throw new TypeError('The "string" argument must be of type string. Received type number');return ir(e)}return Tr(e,r,t)}s.poolSize=8192;function Tr(e,r,t){if(typeof e=="string")return Ut(e,r);if(ArrayBuffer.isView(e))return St(e);if(e==null)throw new TypeError("The first argument must be one of type string, Buffer, ArrayBuffer, Array, or Array-like Object. Received type "+typeof e);if(U(e,ArrayBuffer)||e&&U(e.buffer,ArrayBuffer)||typeof SharedArrayBuffer<"u"&&(U(e,SharedArrayBuffer)||e&&U(e.buffer,SharedArrayBuffer)))return tr(e,r,t);if(typeof e=="number")throw new TypeError('The "value" argument must not be of type number. Received type number');let i=e.valueOf&&e.valueOf();if(i!=null&&i!==e)return s.from(i,r,t);let n=Rt(e);if(n)return n;if(typeof Symbol<"u"&&Symbol.toPrimitive!=null&&typeof e[Symbol.toPrimitive]=="function")return s.from(e[Symbol.toPrimitive]("string"),r,t);throw new TypeError("The first argument must be one of type string, Buffer, ArrayBuffer, Array, or Array-like Object. Received type "+typeof e)}s.from=function(e,r,t){return Tr(e,r,t)};Object.setPrototypeOf(s.prototype,Uint8Array.prototype);Object.setPrototypeOf(s,Uint8Array);function Ar(e){if(typeof e!="number")throw new TypeError('"size" argument must be of type number');if(e<0)throw new RangeError('The value "'+e+'" is invalid for option "size"')}function At(e,r,t){return Ar(e),e<=0?C(e):r!==void 0?typeof t=="string"?C(e).fill(r,t):C(e).fill(r):C(e)}s.alloc=function(e,r,t){return At(e,r,t)};function ir(e){return Ar(e),C(e<0?0:nr(e)|0)}s.allocUnsafe=function(e){return ir(e)};s.allocUnsafeSlow=function(e){return ir(e)};function Ut(e,r){if((typeof r!="string"||r==="")&&(r="utf8"),!s.isEncoding(r))throw new TypeError("Unknown encoding: "+r);let t=Ur(e,r)|0,i=C(t),n=i.write(e,r);return n!==t&&(i=i.slice(0,n)),i}function rr(e){let r=e.length<0?0:nr(e.length)|0,t=C(r);for(let i=0;i<r;i+=1)t[i]=e[i]&255;return t}function St(e){if(U(e,Uint8Array)){let r=new Uint8Array(e);return tr(r.buffer,r.byteOffset,r.byteLength)}return rr(e)}function tr(e,r,t){if(r<0||e.byteLength<r)throw new RangeError('"offset" is outside of buffer bounds');if(e.byteLength<r+(t||0))throw new RangeError('"length" is outside of buffer bounds');let i;return r===void 0&&t===void 0?i=new Uint8Array(e):t===void 0?i=new Uint8Array(e,r):i=new Uint8Array(e,r,t),Object.setPrototypeOf(i,s.prototype),i}function Rt(e){if(s.isBuffer(e)){let r=nr(e.length)|0,t=C(r);return t.length===0||e.copy(t,0,0,r),t}if(e.length!==void 0)return typeof e.length!="number"||ur(e.length)?C(0):rr(e);if(e.type==="Buffer"&&Array.isArray(e.data))return rr(e.data)}function nr(e){if(e>=V)throw new RangeError("Attempt to allocate Buffer larger than maximum size: 0x"+V.toString(16)+" bytes");return e|0}function Ct(e){return+e!=e&&(e=0),s.alloc(+e)}s.isBuffer=function(r){return r!=null&&r._isBuffer===!0&&r!==s.prototype};s.compare=function(r,t){if(U(r,Uint8Array)&&(r=s.from(r,r.offset,r.byteLength)),U(t,Uint8Array)&&(t=s.from(t,t.offset,t.byteLength)),!s.isBuffer(r)||!s.isBuffer(t))throw new TypeError('The "buf1", "buf2" arguments must be one of type Buffer or Uint8Array');if(r===t)return 0;let i=r.length,n=t.length;for(let o=0,u=Math.min(i,n);o<u;++o)if(r[o]!==t[o]){i=r[o],n=t[o];break}return i<n?-1:n<i?1:0};s.isEncoding=function(r){switch(String(r).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(r,t){if(!Array.isArray(r))throw new TypeError('"list" argument must be an Array of Buffers');if(r.length===0)return s.alloc(0);let i;if(t===void 0)for(t=0,i=0;i<r.length;++i)t+=r[i].length;let n=s.allocUnsafe(t),o=0;for(i=0;i<r.length;++i){let u=r[i];if(U(u,Uint8Array))o+u.length>n.length?(s.isBuffer(u)||(u=s.from(u)),u.copy(n,o)):Uint8Array.prototype.set.call(n,u,o);else if(s.isBuffer(u))u.copy(n,o);else throw new TypeError('"list" argument must be an Array of Buffers');o+=u.length}return n};function Ur(e,r){if(s.isBuffer(e))return e.length;if(ArrayBuffer.isView(e)||U(e,ArrayBuffer))return e.byteLength;if(typeof e!="string")throw new TypeError('The "string" argument must be one of type string, Buffer, or ArrayBuffer. Received type '+typeof e);let t=e.length,i=arguments.length>2&&arguments[2]===!0;if(!i&&t===0)return 0;let n=!1;for(;;)switch(r){case"ascii":case"latin1":case"binary":return t;case"utf8":case"utf-8":return er(e).length;case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return t*2;case"hex":return t>>>1;case"base64":return Dr(e).length;default:if(n)return i?-1:er(e).length;r=(""+r).toLowerCase(),n=!0}}s.byteLength=Ur;function bt(e,r,t){let i=!1;if((r===void 0||r<0)&&(r=0),r>this.length||((t===void 0||t>this.length)&&(t=this.length),t<=0)||(t>>>=0,r>>>=0,t<=r))return"";for(e||(e="utf8");;)switch(e){case"hex":return $t(this,r,t);case"utf8":case"utf-8":return Rr(this,r,t);case"ascii":return Mt(this,r,t);case"latin1":case"binary":return Ot(this,r,t);case"base64":return vt(this,r,t);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return Ht(this,r,t);default:if(i)throw new TypeError("Unknown encoding: "+e);e=(e+"").toLowerCase(),i=!0}}s.prototype._isBuffer=!0;function D(e,r,t){let i=e[r];e[r]=e[t],e[t]=i}s.prototype.swap16=function(){let r=this.length;if(r%2!==0)throw new RangeError("Buffer size must be a multiple of 16-bits");for(let t=0;t<r;t+=2)D(this,t,t+1);return this};s.prototype.swap32=function(){let r=this.length;if(r%4!==0)throw new RangeError("Buffer size must be a multiple of 32-bits");for(let t=0;t<r;t+=4)D(this,t,t+3),D(this,t+1,t+2);return this};s.prototype.swap64=function(){let r=this.length;if(r%8!==0)throw new RangeError("Buffer size must be a multiple of 64-bits");for(let t=0;t<r;t+=8)D(this,t,t+7),D(this,t+1,t+6),D(this,t+2,t+5),D(this,t+3,t+4);return this};s.prototype.toString=function(){let r=this.length;return r===0?"":arguments.length===0?Rr(this,0,r):bt.apply(this,arguments)};s.prototype.toLocaleString=s.prototype.toString;s.prototype.equals=function(r){if(!s.isBuffer(r))throw new TypeError("Argument must be a Buffer");return this===r?!0:s.compare(this,r)===0};s.prototype.inspect=function(){let r="",t=H.INSPECT_MAX_BYTES;return r=this.toString("hex",0,t).replace(/(.{2})/g,"$1 ").trim(),this.length>t&&(r+=" ... "),"<Buffer "+r+">"};Er&&(s.prototype[Er]=s.prototype.inspect);s.prototype.compare=function(r,t,i,n,o){if(U(r,Uint8Array)&&(r=s.from(r,r.offset,r.byteLength)),!s.isBuffer(r))throw new TypeError('The "target" argument must be one of type Buffer or Uint8Array. Received type '+typeof r);if(t===void 0&&(t=0),i===void 0&&(i=r?r.length:0),n===void 0&&(n=0),o===void 0&&(o=this.length),t<0||i>r.length||n<0||o>this.length)throw new RangeError("out of range index");if(n>=o&&t>=i)return 0;if(n>=o)return-1;if(t>=i)return 1;if(t>>>=0,i>>>=0,n>>>=0,o>>>=0,this===r)return 0;let u=o-n,c=i-t,h=Math.min(u,c),p=this.slice(n,o),a=r.slice(t,i);for(let f=0;f<h;++f)if(p[f]!==a[f]){u=p[f],c=a[f];break}return u<c?-1:c<u?1:0};function Sr(e,r,t,i,n){if(e.length===0)return-1;if(typeof t=="string"?(i=t,t=0):t>2147483647?t=2147483647:t<-2147483648&&(t=-2147483648),t=+t,ur(t)&&(t=n?0:e.length-1),t<0&&(t=e.length+t),t>=e.length){if(n)return-1;t=e.length-1}else if(t<0)if(n)t=0;else return-1;if(typeof r=="string"&&(r=s.from(r,i)),s.isBuffer(r))return r.length===0?-1:mr(e,r,t,i,n);if(typeof r=="number")return r=r&255,typeof Uint8Array.prototype.indexOf=="function"?n?Uint8Array.prototype.indexOf.call(e,r,t):Uint8Array.prototype.lastIndexOf.call(e,r,t):mr(e,[r],t,i,n);throw new TypeError("val must be string, number or Buffer")}function mr(e,r,t,i,n){let o=1,u=e.length,c=r.length;if(i!==void 0&&(i=String(i).toLowerCase(),i==="ucs2"||i==="ucs-2"||i==="utf16le"||i==="utf-16le")){if(e.length<2||r.length<2)return-1;o=2,u/=2,c/=2,t/=2}function h(a,f){return o===1?a[f]:a.readUInt16BE(f*o)}let p;if(n){let a=-1;for(p=t;p<u;p++)if(h(e,p)===h(r,a===-1?0:p-a)){if(a===-1&&(a=p),p-a+1===c)return a*o}else a!==-1&&(p-=p-a),a=-1}else for(t+c>u&&(t=u-c),p=t;p>=0;p--){let a=!0;for(let f=0;f<c;f++)if(h(e,p+f)!==h(r,f)){a=!1;break}if(a)return p}return-1}s.prototype.includes=function(r,t,i){return this.indexOf(r,t,i)!==-1};s.prototype.indexOf=function(r,t,i){return Sr(this,r,t,i,!0)};s.prototype.lastIndexOf=function(r,t,i){return Sr(this,r,t,i,!1)};function _t(e,r,t,i){t=Number(t)||0;let n=e.length-t;i?(i=Number(i),i>n&&(i=n)):i=n;let o=r.length;i>o/2&&(i=o/2);let u;for(u=0;u<i;++u){let c=parseInt(r.substr(u*2,2),16);if(ur(c))return u;e[t+u]=c}return u}function Pt(e,r,t,i){return j(er(r,e.length-t),e,t,i)}function Nt(e,r,t,i){return j(Kt(r),e,t,i)}function Lt(e,r,t,i){return j(Dr(r),e,t,i)}function Dt(e,r,t,i){return j(Vt(r,e.length-t),e,t,i)}s.prototype.write=function(r,t,i,n){if(t===void 0)n="utf8",i=this.length,t=0;else if(i===void 0&&typeof t=="string")n=t,i=this.length,t=0;else if(isFinite(t))t=t>>>0,isFinite(i)?(i=i>>>0,n===void 0&&(n="utf8")):(n=i,i=void 0);else throw new Error("Buffer.write(string, encoding, offset[, length]) is no longer supported");let o=this.length-t;if((i===void 0||i>o)&&(i=o),r.length>0&&(i<0||t<0)||t>this.length)throw new RangeError("Attempt to write outside buffer bounds");n||(n="utf8");let u=!1;for(;;)switch(n){case"hex":return _t(this,r,t,i);case"utf8":case"utf-8":return Pt(this,r,t,i);case"ascii":case"latin1":case"binary":return Nt(this,r,t,i);case"base64":return Lt(this,r,t,i);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return Dt(this,r,t,i);default:if(u)throw new TypeError("Unknown encoding: "+n);n=(""+n).toLowerCase(),u=!0}};s.prototype.toJSON=function(){return{type:"Buffer",data:Array.prototype.slice.call(this._arr||this,0)}};function vt(e,r,t){return r===0&&t===e.length?Z.fromByteArray(e):Z.fromByteArray(e.slice(r,t))}function Rr(e,r,t){t=Math.min(e.length,t);let i=[],n=r;for(;n<t;){let o=e[n],u=null,c=o>239?4:o>223?3:o>191?2:1;if(n+c<=t){let h,p,a,f;switch(c){case 1:o<128&&(u=o);break;case 2:h=e[n+1],(h&192)===128&&(f=(o&31)<<6|h&63,f>127&&(u=f));break;case 3:h=e[n+1],p=e[n+2],(h&192)===128&&(p&192)===128&&(f=(o&15)<<12|(h&63)<<6|p&63,f>2047&&(f<55296||f>57343)&&(u=f));break;case 4:h=e[n+1],p=e[n+2],a=e[n+3],(h&192)===128&&(p&192)===128&&(a&192)===128&&(f=(o&15)<<18|(h&63)<<12|(p&63)<<6|a&63,f>65535&&f<1114112&&(u=f))}}u===null?(u=65533,c=1):u>65535&&(u-=65536,i.push(u>>>10&1023|55296),u=56320|u&1023),i.push(u),n+=c}return kt(i)}var Ir=4096;function kt(e){let r=e.length;if(r<=Ir)return String.fromCharCode.apply(String,e);let t="",i=0;for(;i<r;)t+=String.fromCharCode.apply(String,e.slice(i,i+=Ir));return t}function Mt(e,r,t){let i="";t=Math.min(e.length,t);for(let n=r;n<t;++n)i+=String.fromCharCode(e[n]&127);return i}function Ot(e,r,t){let i="";t=Math.min(e.length,t);for(let n=r;n<t;++n)i+=String.fromCharCode(e[n]);return i}function $t(e,r,t){let i=e.length;(!r||r<0)&&(r=0),(!t||t<0||t>i)&&(t=i);let n="";for(let o=r;o<t;++o)n+=jt[e[o]];return n}function Ht(e,r,t){let i=e.slice(r,t),n="";for(let o=0;o<i.length-1;o+=2)n+=String.fromCharCode(i[o]+i[o+1]*256);return n}s.prototype.slice=function(r,t){let i=this.length;r=~~r,t=t===void 0?i:~~t,r<0?(r+=i,r<0&&(r=0)):r>i&&(r=i),t<0?(t+=i,t<0&&(t=0)):t>i&&(t=i),t<r&&(t=r);let n=this.subarray(r,t);return Object.setPrototypeOf(n,s.prototype),n};function x(e,r,t){if(e%1!==0||e<0)throw new RangeError("offset is not uint");if(e+r>t)throw new RangeError("Trying to access beyond buffer length")}s.prototype.readUintLE=s.prototype.readUIntLE=function(r,t,i){r=r>>>0,t=t>>>0,i||x(r,t,this.length);let n=this[r],o=1,u=0;for(;++u<t&&(o*=256);)n+=this[r+u]*o;return n};s.prototype.readUintBE=s.prototype.readUIntBE=function(r,t,i){r=r>>>0,t=t>>>0,i||x(r,t,this.length);let n=this[r+--t],o=1;for(;t>0&&(o*=256);)n+=this[r+--t]*o;return n};s.prototype.readUint8=s.prototype.readUInt8=function(r,t){return r=r>>>0,t||x(r,1,this.length),this[r]};s.prototype.readUint16LE=s.prototype.readUInt16LE=function(r,t){return r=r>>>0,t||x(r,2,this.length),this[r]|this[r+1]<<8};s.prototype.readUint16BE=s.prototype.readUInt16BE=function(r,t){return r=r>>>0,t||x(r,2,this.length),this[r]<<8|this[r+1]};s.prototype.readUint32LE=s.prototype.readUInt32LE=function(r,t){return r=r>>>0,t||x(r,4,this.length),(this[r]|this[r+1]<<8|this[r+2]<<16)+this[r+3]*16777216};s.prototype.readUint32BE=s.prototype.readUInt32BE=function(r,t){return r=r>>>0,t||x(r,4,this.length),this[r]*16777216+(this[r+1]<<16|this[r+2]<<8|this[r+3])};s.prototype.readBigUInt64LE=_(function(r){r=r>>>0,$(r,"offset");let t=this[r],i=this[r+7];(t===void 0||i===void 0)&&G(r,this.length-8);let n=t+this[++r]*2**8+this[++r]*2**16+this[++r]*2**24,o=this[++r]+this[++r]*2**8+this[++r]*2**16+i*2**24;return BigInt(n)+(BigInt(o)<<BigInt(32))});s.prototype.readBigUInt64BE=_(function(r){r=r>>>0,$(r,"offset");let t=this[r],i=this[r+7];(t===void 0||i===void 0)&&G(r,this.length-8);let n=t*2**24+this[++r]*2**16+this[++r]*2**8+this[++r],o=this[++r]*2**24+this[++r]*2**16+this[++r]*2**8+i;return(BigInt(n)<<BigInt(32))+BigInt(o)});s.prototype.readIntLE=function(r,t,i){r=r>>>0,t=t>>>0,i||x(r,t,this.length);let n=this[r],o=1,u=0;for(;++u<t&&(o*=256);)n+=this[r+u]*o;return o*=128,n>=o&&(n-=Math.pow(2,8*t)),n};s.prototype.readIntBE=function(r,t,i){r=r>>>0,t=t>>>0,i||x(r,t,this.length);let n=t,o=1,u=this[r+--n];for(;n>0&&(o*=256);)u+=this[r+--n]*o;return o*=128,u>=o&&(u-=Math.pow(2,8*t)),u};s.prototype.readInt8=function(r,t){return r=r>>>0,t||x(r,1,this.length),this[r]&128?(255-this[r]+1)*-1:this[r]};s.prototype.readInt16LE=function(r,t){r=r>>>0,t||x(r,2,this.length);let i=this[r]|this[r+1]<<8;return i&32768?i|4294901760:i};s.prototype.readInt16BE=function(r,t){r=r>>>0,t||x(r,2,this.length);let i=this[r+1]|this[r]<<8;return i&32768?i|4294901760:i};s.prototype.readInt32LE=function(r,t){return r=r>>>0,t||x(r,4,this.length),this[r]|this[r+1]<<8|this[r+2]<<16|this[r+3]<<24};s.prototype.readInt32BE=function(r,t){return r=r>>>0,t||x(r,4,this.length),this[r]<<24|this[r+1]<<16|this[r+2]<<8|this[r+3]};s.prototype.readBigInt64LE=_(function(r){r=r>>>0,$(r,"offset");let t=this[r],i=this[r+7];(t===void 0||i===void 0)&&G(r,this.length-8);let n=this[r+4]+this[r+5]*2**8+this[r+6]*2**16+(i<<24);return(BigInt(n)<<BigInt(32))+BigInt(t+this[++r]*2**8+this[++r]*2**16+this[++r]*2**24)});s.prototype.readBigInt64BE=_(function(r){r=r>>>0,$(r,"offset");let t=this[r],i=this[r+7];(t===void 0||i===void 0)&&G(r,this.length-8);let n=(t<<24)+this[++r]*2**16+this[++r]*2**8+this[++r];return(BigInt(n)<<BigInt(32))+BigInt(this[++r]*2**24+this[++r]*2**16+this[++r]*2**8+i)});s.prototype.readFloatLE=function(r,t){return r=r>>>0,t||x(r,4,this.length),O.read(this,r,!0,23,4)};s.prototype.readFloatBE=function(r,t){return r=r>>>0,t||x(r,4,this.length),O.read(this,r,!1,23,4)};s.prototype.readDoubleLE=function(r,t){return r=r>>>0,t||x(r,8,this.length),O.read(this,r,!0,52,8)};s.prototype.readDoubleBE=function(r,t){return r=r>>>0,t||x(r,8,this.length),O.read(this,r,!1,52,8)};function B(e,r,t,i,n,o){if(!s.isBuffer(e))throw new TypeError('"buffer" argument must be a Buffer instance');if(r>n||r<o)throw new RangeError('"value" argument is out of bounds');if(t+i>e.length)throw new RangeError("Index out of range")}s.prototype.writeUintLE=s.prototype.writeUIntLE=function(r,t,i,n){if(r=+r,t=t>>>0,i=i>>>0,!n){let c=Math.pow(2,8*i)-1;B(this,r,t,i,c,0)}let o=1,u=0;for(this[t]=r&255;++u<i&&(o*=256);)this[t+u]=r/o&255;return t+i};s.prototype.writeUintBE=s.prototype.writeUIntBE=function(r,t,i,n){if(r=+r,t=t>>>0,i=i>>>0,!n){let c=Math.pow(2,8*i)-1;B(this,r,t,i,c,0)}let o=i-1,u=1;for(this[t+o]=r&255;--o>=0&&(u*=256);)this[t+o]=r/u&255;return t+i};s.prototype.writeUint8=s.prototype.writeUInt8=function(r,t,i){return r=+r,t=t>>>0,i||B(this,r,t,1,255,0),this[t]=r&255,t+1};s.prototype.writeUint16LE=s.prototype.writeUInt16LE=function(r,t,i){return r=+r,t=t>>>0,i||B(this,r,t,2,65535,0),this[t]=r&255,this[t+1]=r>>>8,t+2};s.prototype.writeUint16BE=s.prototype.writeUInt16BE=function(r,t,i){return r=+r,t=t>>>0,i||B(this,r,t,2,65535,0),this[t]=r>>>8,this[t+1]=r&255,t+2};s.prototype.writeUint32LE=s.prototype.writeUInt32LE=function(r,t,i){return r=+r,t=t>>>0,i||B(this,r,t,4,4294967295,0),this[t+3]=r>>>24,this[t+2]=r>>>16,this[t+1]=r>>>8,this[t]=r&255,t+4};s.prototype.writeUint32BE=s.prototype.writeUInt32BE=function(r,t,i){return r=+r,t=t>>>0,i||B(this,r,t,4,4294967295,0),this[t]=r>>>24,this[t+1]=r>>>16,this[t+2]=r>>>8,this[t+3]=r&255,t+4};function Cr(e,r,t,i,n){Lr(r,i,n,e,t,7);let o=Number(r&BigInt(4294967295));e[t++]=o,o=o>>8,e[t++]=o,o=o>>8,e[t++]=o,o=o>>8,e[t++]=o;let u=Number(r>>BigInt(32)&BigInt(4294967295));return e[t++]=u,u=u>>8,e[t++]=u,u=u>>8,e[t++]=u,u=u>>8,e[t++]=u,t}function br(e,r,t,i,n){Lr(r,i,n,e,t,7);let o=Number(r&BigInt(4294967295));e[t+7]=o,o=o>>8,e[t+6]=o,o=o>>8,e[t+5]=o,o=o>>8,e[t+4]=o;let u=Number(r>>BigInt(32)&BigInt(4294967295));return e[t+3]=u,u=u>>8,e[t+2]=u,u=u>>8,e[t+1]=u,u=u>>8,e[t]=u,t+8}s.prototype.writeBigUInt64LE=_(function(r,t=0){return Cr(this,r,t,BigInt(0),BigInt("0xffffffffffffffff"))});s.prototype.writeBigUInt64BE=_(function(r,t=0){return br(this,r,t,BigInt(0),BigInt("0xffffffffffffffff"))});s.prototype.writeIntLE=function(r,t,i,n){if(r=+r,t=t>>>0,!n){let h=Math.pow(2,8*i-1);B(this,r,t,i,h-1,-h)}let o=0,u=1,c=0;for(this[t]=r&255;++o<i&&(u*=256);)r<0&&c===0&&this[t+o-1]!==0&&(c=1),this[t+o]=(r/u>>0)-c&255;return t+i};s.prototype.writeIntBE=function(r,t,i,n){if(r=+r,t=t>>>0,!n){let h=Math.pow(2,8*i-1);B(this,r,t,i,h-1,-h)}let o=i-1,u=1,c=0;for(this[t+o]=r&255;--o>=0&&(u*=256);)r<0&&c===0&&this[t+o+1]!==0&&(c=1),this[t+o]=(r/u>>0)-c&255;return t+i};s.prototype.writeInt8=function(r,t,i){return r=+r,t=t>>>0,i||B(this,r,t,1,127,-128),r<0&&(r=255+r+1),this[t]=r&255,t+1};s.prototype.writeInt16LE=function(r,t,i){return r=+r,t=t>>>0,i||B(this,r,t,2,32767,-32768),this[t]=r&255,this[t+1]=r>>>8,t+2};s.prototype.writeInt16BE=function(r,t,i){return r=+r,t=t>>>0,i||B(this,r,t,2,32767,-32768),this[t]=r>>>8,this[t+1]=r&255,t+2};s.prototype.writeInt32LE=function(r,t,i){return r=+r,t=t>>>0,i||B(this,r,t,4,2147483647,-2147483648),this[t]=r&255,this[t+1]=r>>>8,this[t+2]=r>>>16,this[t+3]=r>>>24,t+4};s.prototype.writeInt32BE=function(r,t,i){return r=+r,t=t>>>0,i||B(this,r,t,4,2147483647,-2147483648),r<0&&(r=4294967295+r+1),this[t]=r>>>24,this[t+1]=r>>>16,this[t+2]=r>>>8,this[t+3]=r&255,t+4};s.prototype.writeBigInt64LE=_(function(r,t=0){return Cr(this,r,t,-BigInt("0x8000000000000000"),BigInt("0x7fffffffffffffff"))});s.prototype.writeBigInt64BE=_(function(r,t=0){return br(this,r,t,-BigInt("0x8000000000000000"),BigInt("0x7fffffffffffffff"))});function _r(e,r,t,i,n,o){if(t+i>e.length)throw new RangeError("Index out of range");if(t<0)throw new RangeError("Index out of range")}function Pr(e,r,t,i,n){return r=+r,t=t>>>0,n||_r(e,r,t,4,34028234663852886e22,-34028234663852886e22),O.write(e,r,t,i,23,4),t+4}s.prototype.writeFloatLE=function(r,t,i){return Pr(this,r,t,!0,i)};s.prototype.writeFloatBE=function(r,t,i){return Pr(this,r,t,!1,i)};function Nr(e,r,t,i,n){return r=+r,t=t>>>0,n||_r(e,r,t,8,17976931348623157e292,-17976931348623157e292),O.write(e,r,t,i,52,8),t+8}s.prototype.writeDoubleLE=function(r,t,i){return Nr(this,r,t,!0,i)};s.prototype.writeDoubleBE=function(r,t,i){return Nr(this,r,t,!1,i)};s.prototype.copy=function(r,t,i,n){if(!s.isBuffer(r))throw new TypeError("argument should be a Buffer");if(i||(i=0),!n&&n!==0&&(n=this.length),t>=r.length&&(t=r.length),t||(t=0),n>0&&n<i&&(n=i),n===i||r.length===0||this.length===0)return 0;if(t<0)throw new RangeError("targetStart out of bounds");if(i<0||i>=this.length)throw new RangeError("Index out of range");if(n<0)throw new RangeError("sourceEnd out of bounds");n>this.length&&(n=this.length),r.length-t<n-i&&(n=r.length-t+i);let o=n-i;return this===r&&typeof Uint8Array.prototype.copyWithin=="function"?this.copyWithin(t,i,n):Uint8Array.prototype.set.call(r,this.subarray(i,n),t),o};s.prototype.fill=function(r,t,i,n){if(typeof r=="string"){if(typeof t=="string"?(n=t,t=0,i=this.length):typeof i=="string"&&(n=i,i=this.length),n!==void 0&&typeof n!="string")throw new TypeError("encoding must be a string");if(typeof n=="string"&&!s.isEncoding(n))throw new TypeError("Unknown encoding: "+n);if(r.length===1){let u=r.charCodeAt(0);(n==="utf8"&&u<128||n==="latin1")&&(r=u)}}else typeof r=="number"?r=r&255:typeof r=="boolean"&&(r=Number(r));if(t<0||this.length<t||this.length<i)throw new RangeError("Out of range index");if(i<=t)return this;t=t>>>0,i=i===void 0?this.length:i>>>0,r||(r=0);let o;if(typeof r=="number")for(o=t;o<i;++o)this[o]=r;else{let u=s.isBuffer(r)?r:s.from(r,n),c=u.length;if(c===0)throw new TypeError('The value "'+r+'" is invalid for argument "value"');for(o=0;o<i-t;++o)this[o+t]=u[o%c]}return this};var M={};function or(e,r,t){M[e]=class extends t{constructor(){super(),Object.defineProperty(this,"message",{value:r.apply(this,arguments),writable:!0,configurable:!0}),this.name=`${this.name} [${e}]`,this.stack,delete this.name}get code(){return e}set code(n){Object.defineProperty(this,"code",{configurable:!0,enumerable:!0,value:n,writable:!0})}toString(){return`${this.name} [${e}]: ${this.message}`}}}or("ERR_BUFFER_OUT_OF_BOUNDS",function(e){return e?`${e} is outside of buffer bounds`:"Attempt to access memory outside buffer bounds"},RangeError);or("ERR_INVALID_ARG_TYPE",function(e,r){return`The "${e}" argument must be of type number. Received type ${typeof r}`},TypeError);or("ERR_OUT_OF_RANGE",function(e,r,t){let i=`The value of "${e}" is out of range.`,n=t;return Number.isInteger(t)&&Math.abs(t)>2**32?n=Fr(String(t)):typeof t=="bigint"&&(n=String(t),(t>BigInt(2)**BigInt(32)||t<-(BigInt(2)**BigInt(32)))&&(n=Fr(n)),n+="n"),i+=` It must be ${r}. Received ${n}`,i},RangeError);function Fr(e){let r="",t=e.length,i=e[0]==="-"?1:0;for(;t>=i+4;t-=3)r=`_${e.slice(t-3,t)}${r}`;return`${e.slice(0,t)}${r}`}function qt(e,r,t){$(r,"offset"),(e[r]===void 0||e[r+t]===void 0)&&G(r,e.length-(t+1))}function Lr(e,r,t,i,n,o){if(e>t||e<r){let u=typeof r=="bigint"?"n":"",c;throw o>3?r===0||r===BigInt(0)?c=`>= 0${u} and < 2${u} ** ${(o+1)*8}${u}`:c=`>= -(2${u} ** ${(o+1)*8-1}${u}) and < 2 ** ${(o+1)*8-1}${u}`:c=`>= ${r}${u} and <= ${t}${u}`,new M.ERR_OUT_OF_RANGE("value",c,e)}qt(i,n,o)}function $(e,r){if(typeof e!="number")throw new M.ERR_INVALID_ARG_TYPE(r,"number",e)}function G(e,r,t){throw Math.floor(e)!==e?($(e,t),new M.ERR_OUT_OF_RANGE(t||"offset","an integer",e)):r<0?new M.ERR_BUFFER_OUT_OF_BOUNDS:new M.ERR_OUT_OF_RANGE(t||"offset",`>= ${t?1:0} and <= ${r}`,e)}var Gt=/[^+/0-9A-Za-z-_]/g;function Yt(e){if(e=e.split("=")[0],e=e.trim().replace(Gt,""),e.length<2)return"";for(;e.length%4!==0;)e=e+"=";return e}function er(e,r){r=r||1/0;let t,i=e.length,n=null,o=[];for(let u=0;u<i;++u){if(t=e.charCodeAt(u),t>55295&&t<57344){if(!n){if(t>56319){(r-=3)>-1&&o.push(239,191,189);continue}else if(u+1===i){(r-=3)>-1&&o.push(239,191,189);continue}n=t;continue}if(t<56320){(r-=3)>-1&&o.push(239,191,189),n=t;continue}t=(n-55296<<10|t-56320)+65536}else n&&(r-=3)>-1&&o.push(239,191,189);if(n=null,t<128){if((r-=1)<0)break;o.push(t)}else if(t<2048){if((r-=2)<0)break;o.push(t>>6|192,t&63|128)}else if(t<65536){if((r-=3)<0)break;o.push(t>>12|224,t>>6&63|128,t&63|128)}else if(t<1114112){if((r-=4)<0)break;o.push(t>>18|240,t>>12&63|128,t>>6&63|128,t&63|128)}else throw new Error("Invalid code point")}return o}function Kt(e){let r=[];for(let t=0;t<e.length;++t)r.push(e.charCodeAt(t)&255);return r}function Vt(e,r){let t,i,n,o=[];for(let u=0;u<e.length&&!((r-=2)<0);++u)t=e.charCodeAt(u),i=t>>8,n=t%256,o.push(n),o.push(i);return o}function Dr(e){return Z.toByteArray(Yt(e))}function j(e,r,t,i){let n;for(n=0;n<i&&!(n+t>=r.length||n>=e.length);++n)r[n+t]=e[n];return n}function U(e,r){return e instanceof r||e!=null&&e.constructor!=null&&e.constructor.name!=null&&e.constructor.name===r.name}function ur(e){return e!==e}var jt=(function(){let e="0123456789abcdef",r=new Array(256);for(let t=0;t<16;++t){let i=t*16;for(let n=0;n<16;++n)r[i+n]=e[t]+e[n]}return r})();function _(e){return typeof BigInt>"u"?Wt:e}function Wt(){throw new Error("BigInt not supported")}});var d,w,l=lt(()=>{d=fr(dr()),w=fr(vr())});var Mr=g((fe,kr)=>{l();kr.exports=(typeof globalThis<"u"?globalThis:typeof self<"u"?self:window).bsv.Transaction.sighash});var $r=g((pe,Or)=>{l();Or.exports=(typeof globalThis<"u"?globalThis:typeof self<"u"?self:window).bsv.Transaction.Input});var qr=g((ye,Hr)=>{l();Hr.exports=(typeof globalThis<"u"?globalThis:typeof self<"u"?self:window).bsv.Script.Interpreter});var Yr=g((we,Gr)=>{l();Gr.exports=(typeof globalThis<"u"?globalThis:typeof self<"u"?self:window).bsv.crypto.Signature});var Vr=g((ge,Kr)=>{l();Kr.exports=(typeof globalThis<"u"?globalThis:typeof self<"u"?self:window).bsv.crypto.Hash});var Wr=g((Ee,jr)=>{l();jr.exports=(typeof globalThis<"u"?globalThis:typeof self<"u"?self:window).bsv.crypto.BN});var Jr=g((Ie,Xr)=>{l();Xr.exports=(typeof globalThis<"u"?globalThis:typeof self<"u"?self:window).bsv.Transaction});var zr=g((Te,Qr)=>{l();Qr.exports=(typeof globalThis<"u"?globalThis:typeof self<"u"?self:window).bsv.Script});var sr=g((Ue,Zr)=>{"use strict";l();Zr.exports={}});var ot=g((Re,nt)=>{"use strict";l();var et=Mr(),Xt=$r(),q=qr(),rt=Yr(),Jt=Vr(),cr=Wr(),it=Jr(),P=zr(),tt=sr(),b;try{b=sr()}catch{b=null}var Qt=function(){var e=typeof d.default<"u"&&d.default.env&&d.default.env.BSV_DEBUG||typeof window<"u"&&window.BSV_DEBUG;e&&console.log.apply(console,arguments)};function E(e,r){if(!(this instanceof E))return new E(e,r);this.privateKey=e,this.publicKey=e.publicKey,this.address=e.toAddress(),r=r||{},this.storageDir=r.storageDir||(typeof d.default<"u"?tt.join(d.default.cwd(),".bsv-covenants"):".bsv-covenants"),this.covenantUtxoPath=tt.join(this.storageDir,"covenant_utxos.json"),this.sighashType=rt.SIGHASH_ALL|rt.SIGHASH_FORKID,this.allowNonEnforcing=r.allowNonEnforcing===!0,b&&this._ensureStorageDir()}E.prototype.createFromP2PKH=function(e){if(!this.allowNonEnforcing)throw new Error("SmartContract.Covenant builds a NON-ENFORCING script that reduces to plain P2PK \u2014 it does not constrain the spend. Use SmartContract.PushTx.valueCovenant (output binding) or SmartContract.Token / perpetualCovenant (stateful covenants) for real covenants. To use this demo anyway, construct with { allowNonEnforcing: true }.");e.script||(e.script=E.reconstructP2pkhScript(this.address));var r=new it().from({txId:e.txid,outputIndex:e.vout,script:e.script,satoshis:e.satoshis}).to(this.address,e.satoshis-1e3),t=P.fromHex(e.script),i=et.sighashPreimage(r,this.sighashType,0,t,new cr(e.satoshis)),n=Jt.sha256sha256(i),o=new P().add("OP_DUP").add("OP_HASH256").add(n).add("OP_EQUALVERIFY").add("OP_DROP").add(this.publicKey.toBuffer()).add("OP_CHECKSIG");r.outputs[0].setScript(o),r.sign(this.privateKey);var u={txid:r.id,vout:0,satoshis:e.satoshis-1e3,script:o.toHex(),scriptPubKey:o.toHex(),preimageHash:n.toString("hex"),originalPreimage:i.toString("hex"),status:"local",createdAt:new Date().toISOString(),type:"preimage_covenant"};return{transaction:r,covenantUtxo:u}};E.prototype.createSpendingTx=function(e,r,t){var i=r||this.address,n=t||e.satoshis-500,o=new it;o.addInput(new Xt({prevTxId:e.txid,outputIndex:e.vout,script:P.empty()}),P.fromHex(e.script),e.satoshis),o.to(i,n);var u=P.fromHex(e.script),c=et.sign(o,this.privateKey,this.sighashType,0,u,new cr(e.satoshis)),h=w.Buffer.concat([c.toDER(),w.Buffer.from([this.sighashType])]),p=w.Buffer.from(e.originalPreimage,"hex"),a=new P().add(h).add(p);return o.inputs[0].setScript(a),o};E.prototype.validate=function(e,r){var t=new q,i=q.SCRIPT_VERIFY_P2SH|q.SCRIPT_VERIFY_STRICTENC|q.SCRIPT_VERIFY_DERSIG|q.SCRIPT_VERIFY_LOW_S|q.SCRIPT_ENABLE_SIGHASH_FORKID,n=e.inputs[0].script,o=P.fromHex(r.script),u=t.verify(n,o,e,0,i,new cr(r.satoshis));return{valid:u,error:u?null:t.errstr}};E.prototype.save=function(e){if(!b)return Qt("File system operations not available in browser environment"),e;var r=this.list();return r.push(e),b.writeFileSync(this.covenantUtxoPath,JSON.stringify(r,null,2)),e};E.prototype.load=function(e){var r=this.list();if(e){var t=r.find(function(i){return i.txid===e});if(!t)throw new Error("Covenant UTXO with TXID "+e+" not found");return t}else{var t=r.find(function(n){return n.type==="preimage_covenant"});if(!t)throw new Error("No preimage covenant UTXO found");return t}};E.prototype.list=function(){return b.existsSync(this.covenantUtxoPath)?JSON.parse(b.readFileSync(this.covenantUtxoPath,"utf8")):[]};E.prototype.getPortfolio=function(){var e=this.list(),r={total:e.length,totalValue:e.reduce(function(t,i){return t+i.satoshis},0),byStatus:{},recent:e.slice(-5)};return e.forEach(function(t){var i=t.status||"local";r.byStatus[i]||(r.byStatus[i]={count:0,value:0}),r.byStatus[i].count++,r.byStatus[i].value+=t.satoshis}),r};E.prototype.completeFlow=function(e,r){var t=this.createFromP2PKH(e),i=this.save(t.covenantUtxo);r&&r(t.transaction,"creation");var n=this.createSpendingTx(i),o=this.validate(n,i);return r&&o.valid&&r(n,"spending"),{creationTx:t.transaction,spendingTx:n,covenantUtxo:i,validation:o,success:o.valid}};E.prototype._ensureStorageDir=function(){b.existsSync(this.storageDir)||b.mkdirSync(this.storageDir,{recursive:!0})};E.reconstructP2pkhScript=function(e){return P.buildPublicKeyHashOut(e).toHex()};nt.exports=E});var zt=g((be,ut)=>{l();ut.exports=ot()});return zt();})();
2
2
  if(typeof module!=="undefined"&&module.exports){module.exports=bsvCovenant}else if(typeof define==="function"&&define.amd){define([],function(){return bsvCovenant})}