@vbyte/btc-dev 1.1.3 → 1.1.5

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 (66) hide show
  1. package/dist/const.d.ts +16 -0
  2. package/dist/const.js +22 -6
  3. package/dist/lib/address/api.d.ts +4 -0
  4. package/dist/lib/address/api.js +32 -0
  5. package/dist/lib/address/encode.d.ts +3 -3
  6. package/dist/lib/address/index.d.ts +1 -15
  7. package/dist/lib/address/index.js +1 -16
  8. package/dist/lib/address/p2pkh.d.ts +14 -7
  9. package/dist/lib/address/p2pkh.js +34 -16
  10. package/dist/lib/address/p2sh.d.ts +14 -7
  11. package/dist/lib/address/p2sh.js +33 -14
  12. package/dist/lib/address/p2tr.d.ts +14 -5
  13. package/dist/lib/address/p2tr.js +34 -11
  14. package/dist/lib/address/p2wpkh.d.ts +14 -7
  15. package/dist/lib/address/p2wpkh.js +32 -15
  16. package/dist/lib/address/p2wsh.d.ts +14 -7
  17. package/dist/lib/address/p2wsh.js +31 -14
  18. package/dist/lib/address/script.d.ts +2 -5
  19. package/dist/lib/address/script.js +12 -12
  20. package/dist/lib/address/util.d.ts +3 -4
  21. package/dist/lib/address/util.js +10 -14
  22. package/dist/lib/script/decode.d.ts +2 -0
  23. package/dist/lib/script/decode.js +8 -1
  24. package/dist/lib/script/index.d.ts +3 -116
  25. package/dist/lib/script/index.js +3 -6
  26. package/dist/lib/script/lock.d.ts +12 -0
  27. package/dist/lib/script/lock.js +52 -0
  28. package/dist/lib/tx/util.d.ts +1 -6
  29. package/dist/lib/tx/util.js +1 -27
  30. package/dist/lib/witness/parse.js +11 -9
  31. package/dist/main.cjs +345 -194
  32. package/dist/main.cjs.map +1 -1
  33. package/dist/module.mjs +345 -194
  34. package/dist/module.mjs.map +1 -1
  35. package/dist/package.json +1 -1
  36. package/dist/script.js +8 -8
  37. package/dist/script.js.map +1 -1
  38. package/dist/types/address.d.ts +6 -10
  39. package/dist/types/index.d.ts +1 -0
  40. package/dist/types/index.js +1 -0
  41. package/dist/types/meta.d.ts +0 -14
  42. package/dist/types/script.d.ts +15 -0
  43. package/dist/types/script.js +1 -0
  44. package/dist/types/witness.d.ts +7 -8
  45. package/package.json +1 -1
  46. package/src/const.ts +25 -7
  47. package/src/lib/address/api.ts +50 -0
  48. package/src/lib/address/encode.ts +9 -9
  49. package/src/lib/address/index.ts +1 -18
  50. package/src/lib/address/p2pkh.ts +54 -25
  51. package/src/lib/address/p2sh.ts +55 -24
  52. package/src/lib/address/p2tr.ts +59 -19
  53. package/src/lib/address/p2wpkh.ts +53 -26
  54. package/src/lib/address/p2wsh.ts +53 -26
  55. package/src/lib/address/script.ts +14 -14
  56. package/src/lib/address/util.ts +16 -31
  57. package/src/lib/script/decode.ts +11 -1
  58. package/src/lib/script/index.ts +7 -13
  59. package/src/lib/script/lock.ts +73 -0
  60. package/src/lib/tx/util.ts +3 -41
  61. package/src/lib/witness/parse.ts +17 -13
  62. package/src/types/address.ts +7 -11
  63. package/src/types/index.ts +1 -0
  64. package/src/types/meta.ts +0 -18
  65. package/src/types/script.ts +18 -0
  66. package/src/types/witness.ts +8 -8
package/dist/script.js CHANGED
@@ -1,14 +1,14 @@
1
- var btc_dev=function(e){"use strict";var t,n;!function(e){function t(e){return null===e.match(/[^a-fA-F0-9]/)&&e.length%2==0}e.is_hex=t,e.is_bytes=function(e){return!("string"!=typeof e||!t(e))||(e instanceof Uint8Array||!(!Array.isArray(e)||!e.every(e=>"number"==typeof e)))}}(t||(t={})),function(e){e.within_size=function(e,t){if(e.length>t)throw new TypeError(`Data is larger than array size: ${e.length} > ${t}`)},e.is_hex=function(e){if(null!==e.match(/[^a-fA-f0-9]/))throw new TypeError("Invalid characters in hex string: "+e);if(e.length%2!=0)throw new Error(`Length of hex string is invalid: ${e.length}`)},e.is_bytes=function(e){if(!t.is_bytes(e))throw new Error("Bytes contains invalid elements: "+String(e))},e.is_json=function(e){try{JSON.parse(e)}catch{throw new TypeError("JSON string is invalid!")}},e.is_safe_int=function(e){if(e>Number.MAX_SAFE_INTEGER)throw new TypeError("Number exceeds safe bounds!")}}(n||(n={}));const r=BigInt(0),i=BigInt(255),o=BigInt(256);function s(e,t,n="be"){void 0===t&&(t=function(e){if(e<=0xffn)return 1;if(e<=0xffffn)return 2;if(e<=0xffffffffn)return 4;if(e<=0xffffffffffffffffn)return 8;if(e<=0xffffffffffffffffffffffffffffffffn)return 16;if(e<=0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffn)return 32;throw new TypeError("Must specify a fixed buffer size for bigints greater than 32 bytes.")}(e));const s="le"===n,u=new ArrayBuffer(t),a=new DataView(u);let c=s?0:t-1;for(;e>r;){const t=e&i,n=Number(t);s?a.setUint8(c++,n):a.setUint8(c--,n),e=(e-t)/o}return new Uint8Array(u)}function u(e,t){return"bigint"==typeof t?`${t}n`:t}function a(e,t){return"string"==typeof t&&/^[0-9]+n$/.test(t)?BigInt(t.slice(0,-1)):t}function c(e,t,n="be"){void 0===t&&(t=function(e){if(e<=255)return 1;if(e<=65535)return 2;if(e<=4294967295)return 4;throw new TypeError("Numbers larger than 4 bytes must specify a fixed size!")}(e));const r="le"===n,i=new ArrayBuffer(t),o=new DataView(i);let s=r?0:t-1;for(;e>0;){const t=255&e;r?o.setUint8(s++,e):o.setUint8(s--,e),e=(e-t)/256}return new Uint8Array(i)}function f(e,t,r="be"){t=function(e,t){n.is_hex(e);const r=e.length/2;void 0===t&&(t=r);if(r>t)throw new TypeError(`Hex string is larger than array size: ${r} > ${t}`);return t}(e,t);const i="be"===r,o=new ArrayBuffer(t),s=new DataView(o);let u=i?0:t-1;for(let t=0;t<e.length;t+=2){const n=e.substring(t,t+2),r=parseInt(n,16);i?s.setUint8(u++,r):s.setUint8(u--,r)}return new Uint8Array(o)}function d(e,t,r){if(e instanceof ArrayBuffer)return new Uint8Array(e);if(e instanceof Uint8Array)return function(e,t,r="le"){void 0===t&&(t=e.length);n.within_size(e,t);const i=new Uint8Array(t).fill(0),o="be"===r?0:t-e.length;return i.set(e,o),i}(e,t,r);if("string"==typeof e)return n.is_hex(e),f(e,t,r);if("bigint"==typeof e)return s(e,t,r);if("number"==typeof e)return c(e,t,r);throw new TypeError("Input type not supported:"+typeof e)}const l=new TextEncoder,h=new TextDecoder;function p(e){return l.encode(e)}function m(e){return h.decode(e)}class g extends Uint8Array{static{this.num=(e,t,n)=>new g(e,t,n)}static{this.big=(e,t,n)=>new g(e,t,n)}static{this.bin=(e,t,n)=>{const r=function(e){const t=e.split("").map(Number);if(t.length%8!=0)throw new Error(`Binary array is invalid length: ${e.length}`);const n=new Uint8Array(t.length/8);for(let e=0,r=0;e<t.length;e+=8,r++){let i=0;for(let n=0;n<8;n++)i|=t[e+n]<<7-n;n[r]=i}return n}(e);return new g(r,t,n)}}static{this.uint=(e,t,n)=>new g(e,t,n)}static{this.str=(e,t,n)=>{const r=p(e);return new g(r,t,n)}}static{this.hex=(e,t,r)=>(n.is_hex(e),new g(e,t,r))}static{this.bytes=(e,t,r)=>(n.is_bytes(e),new g(e,t,r))}static{this.json=(e,t)=>{t=t??u;const n=p(JSON.stringify(e,t));return new g(n)}}static{this.blob=(e,t,n)=>{const r=function(e,t,n){const r=e.length,i=n/t;if(n%t!==0)throw new TypeError(`Invalid parameters: ${n} % ${t} !== 0`);if(r!==n)throw new TypeError(`Invalid data stream: ${r} !== ${n}`);if(r%t!==0)throw new TypeError(`Invalid data stream: ${r} % ${t} !== 0`);const o=new Array(i);for(let n=0;n<i;n++){const r=n*t;o[n]=e.subarray(r,r+t)}return o}(d(e),t,n);return r.map(e=>new g(e))}}static{this.is_equal=(e,t)=>new g(e).hex===new g(t).hex}static{this.is_bytes=t.is_bytes}static{this.is_hex=t.is_hex}static random(e=32){const t=function(e=32){if(crypto&&"function"==typeof crypto.getRandomValues)return crypto.getRandomValues(new Uint8Array(e));const t=crypto;if(t&&void 0!==t.randomBytes&&"function"==typeof t.randomBytes)return t.randomBytes(e);throw new Error("getRandomValues from crypto library is undefined")}(e);return new g(t,e)}static now(){const e=Math.floor(Date.now()/1e3);return new g(e,4)}constructor(e,t,n){if(e instanceof g&&void 0===t)return e;super(d(e,t,n))}get arr(){return this.to_arr()}get big(){return this.to_big()}get bin(){return this.to_bin()}get hex(){return this.to_hex()}get num(){return this.to_num()}get str(){return this.to_str()}get uint(){return this.to_uint()}to_big(e="be"){return function(e){let t=BigInt(0);for(let n=e.length-1;n>=0;n--)t=t*o+BigInt(e[n]);return BigInt(t)}("be"===e?this.uint.reverse():this.uint)}to_hex(e="be"){return function(e){let t="";for(let n=0;n<e.length;n++)t+=e[n].toString(16).padStart(2,"0");return t}("be"===e?this.uint:this.uint.reverse())}to_json(e){void 0===e&&(e=a);const t=m(this);return JSON.parse(t,e)}to_num(e="be"){return function(e){let t=0;for(let r=e.length-1;r>=0;r--)t=256*t+e[r],n.is_safe_int(t);return t}("be"===e?this.uint.reverse():this.uint)}to_arr(){return[...this]}to_bin(){return function(e){const t=new Array(8*e.length);let n=0;for(const r of e){if(r>255)throw new Error(`Invalid byte value: ${r}. Byte values must be between 0 and 255.`);for(let e=7;e>=0;e--,n++)t[n]=r>>e&1}return t.join("")}(this)}to_str(){return m(this)}to_uint(){return new Uint8Array(this)}append(e){return g.join([this,new g(e)])}equals(e){return new g(e).hex===this.hex}prepend(e){return g.join([new g(e),this])}prefix_varint(e){if(0===this.length)throw new Error("buffer is empty");const t=g.varint(this.length,e);return this.prepend(t)}reverse(){return super.reverse(),this}set(e,t){this.set(e,t)}slice(e,t){const n=new Uint8Array(this).slice(e,t);return new g(n)}subarray(e,t){const n=new Uint8Array(this).subarray(e,t);return new g(n)}toJSON(){return this.hex}toString(){return this.hex}static from(e){return new g(Uint8Array.from(e))}static of(...e){return new g(Uint8Array.of(...e))}static join(e){const t=function(e){let t,n=0;const r=e.reduce((e,t)=>e+t.length,0),i=new Uint8Array(r);for(t=0;t<e.length;t++){const r=e[t];i.set(r,n),n+=r.length}return i}(e.map(e=>new g(e)));return new g(t)}static sort(e,t){const n=e.map(e=>new g(e,t).hex);return n.sort(),n.map(e=>g.hex(e,t))}static varint(e,t){if(e<253)return g.num(e,1);if(e<65536)return g.of(253,...g.num(e,2,t));if(e<4294967296)return g.of(254,...g.num(e,4,t));if(BigInt(e)<0x10000000000000000n)return g.of(255,...g.num(e,8,t));throw new Error(`Value is too large: ${e}`)}}class w{constructor(e){this.data=new g(e),this.size=this.data.length}peek(e){if(e>this.size)throw new Error(`Size greater than stream: ${e} > ${this.size}`);return new g(this.data.slice(0,e))}read(e){const t=this.peek(e);return this.data=this.data.slice(e),this.size=this.data.length,t}varint(e){const t=this.read(1).num;switch(!0){case t>=0&&t<253:return t;case 253===t:return this.read(2).to_num(e);case 254===t:return this.read(4).to_num(e);case 255===t:return this.read(8).to_num(e);default:throw new Error(`Varint is out of range: ${t}`)}}}function _(e){return e instanceof Map||Array.isArray(e)||"object"!=typeof e?e:Object.keys(e).sort().filter(([e,t])=>void 0!==t).reduce((t,n)=>(t[n]=e[n],t),{})}function y(e){return e instanceof Error?e.message:"string"==typeof e?e:String(e)}var v,b;!function(e){function t(e){return"object"==typeof e&&null!==e&&!Array.isArray(e)}function n(e){return"string"==typeof e}function r(e){return Number.isInteger(e)&&!Number.isNaN(e)}function i(e){return!!n(e)&&(null===e.match(/[^a-fA-F0-9]/)&&e.length%2==0)}e.exists=function(e){return null!=e},e.is_equal=function(e,t){return e===t},e.is_object=t,e.is_deep_equal=function(e,n){return t(e)&&(e=_(e)),t(n)&&(n=_(n)),String(e)===String(n)},e.has_items=function(e){return Array.isArray(e)&&e.length>0},e.is_string=n,e.is_number=r,e.is_bigint=function(e){return"bigint"==typeof e},e.is_uchar=function(e){return r(e)&&e>=0&&e<=255},e.is_ushort=function(e){return r(e)&&e>=0&&e<=65535},e.is_uint=function(e){return r(e)&&e>=0&&e<=4294967295},e.is_u8a=function(e){return e instanceof Uint8Array},e.is_bytes=function(e){return g.is_bytes(e)},e.is_base58=function(e){return"string"==typeof e&&/^[123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz]+$/.test(e)},e.is_base64=function(e){return"string"==typeof e&&/^[a-zA-Z0-9+/]+={0,2}$/.test(e)},e.is_b64url=function(e){return"string"==typeof e&&/^[a-zA-Z0-9\-_]+={0,2}$/.test(e)},e.is_bech32=function(e){return"string"==typeof e&&/^[a-z]+1[023456789acdefghjklmnpqrstuvwxyz]+$/.test(e)},e.is_hex=i,e.is_hash=function(e){return n(e)&&i(e)&&64===e.length}}(v||(v={})),function(e){e.ok=function(e,t){if(!1===e)throw new Error(t??"Assertion failed!")},e.exists=function(e,t){if(!v.exists(e))throw new Error(t??"Value is null or undefined!")},e.is_empty=function(e,t){if(null!=e)throw new Error(t??"value is not null or undefined!")},e.is_instance=function(e,t,n){if(!(e instanceof t))throw new Error(n??`value is not an instance of ${t.name}`)},e.is_equal=function(e,t,n){if(!v.is_equal(e,t))throw new Error(n??`values are not equal: ${String(e)} !== ${String(t)}`)},e.is_object=function(e,t){if(!v.is_object(e))throw new Error(t??`value is not an object: ${String(e)}`)},e.is_deep_equal=function(e,t,n){if(!v.is_deep_equal(e,t))throw new Error(n??`values are not deep equal: ${String(e)} !== ${String(t)}`)},e.is_number=function(e){if(!v.is_number(e))throw new TypeError(`invalid number: ${String(e)}`)},e.is_bigint=function(e){if(!v.is_bigint(e))throw new TypeError(`invalid bigint: ${String(e)}`)},e.is_hex=function(e){if(!v.is_hex(e))throw new TypeError(`invalid hex: ${String(e)}`)},e.is_uchar=function(e){if(!v.is_uchar(e))throw new TypeError(`invalid unsignedchar: ${String(e)}`)},e.is_ushort=function(e){if(!v.is_ushort(e))throw new TypeError(`invalid unsigned short: ${String(e)}`)},e.is_uint=function(e){if(!v.is_uint(e))throw new TypeError(`invalid unsigned int: ${String(e)}`)},e.is_u8a=function(e){if(!v.is_u8a(e))throw new TypeError(`invalid Uint8Array: ${String(e)}`)},e.is_hash=function(e,t){if(!v.is_hash(e))throw new TypeError(t??`invalid hash: ${String(e)}`)},e.is_bytes=function(e,t){if(!v.is_bytes(e))throw new TypeError(t??`invalid bytes: ${String(e)}`)},e.size=function(e,t,n){const r=g.bytes(e);if(r.length!==t)throw new Error(n??`invalid input size: ${r.length} !== ${t}`)},e.has_items=function(e,t){if(!v.has_items(e))throw new Error(t??"array does not contain any items")},e.is_base58=function(e){if(!v.is_base58(e))throw new Error("invalid base58 string")},e.is_base64=function(e){if(!v.is_base64(e))throw new Error("invalid base64 string")},e.is_b64url=function(e){if(!v.is_b64url(e))throw new Error("invalid base64url string")},e.is_bech32=function(e){if(!v.is_bech32(e))throw new Error("invalid bech32 string")}}(b||(b={}));const E="object"==typeof globalThis&&"crypto"in globalThis?globalThis.crypto:void 0;
2
- /*! noble-hashes - MIT License (c) 2022 Paul Miller (paulmillr.com) */function x(e){return e instanceof Uint8Array||ArrayBuffer.isView(e)&&"Uint8Array"===e.constructor.name}function z(e){if(!Number.isSafeInteger(e)||e<0)throw new Error("positive integer expected, got "+e)}function k(e,...t){if(!x(e))throw new Error("Uint8Array expected");if(t.length>0&&!t.includes(e.length))throw new Error("Uint8Array expected of length "+t+", got length="+e.length)}function O(e){if("function"!=typeof e||"function"!=typeof e.create)throw new Error("Hash should be wrapped by utils.createHasher");z(e.outputLen),z(e.blockLen)}function A(e,t=!0){if(e.destroyed)throw new Error("Hash instance has been destroyed");if(t&&e.finished)throw new Error("Hash#digest() has already been called")}function S(...e){for(let t=0;t<e.length;t++)e[t].fill(0)}function P(e){return new DataView(e.buffer,e.byteOffset,e.byteLength)}function $(e,t){return e<<32-t|e>>>t}function I(e,t){return e<<t|e>>>32-t>>>0}const T=(()=>"function"==typeof Uint8Array.from([]).toHex&&"function"==typeof Uint8Array.fromHex)(),N=Array.from({length:256},(e,t)=>t.toString(16).padStart(2,"0"));function B(e){if(k(e),T)return e.toHex();let t="";for(let n=0;n<e.length;n++)t+=N[e[n]];return t}const U=48,Z=57,R=65,C=70,j=97,F=102;function D(e){return e>=U&&e<=Z?e-U:e>=R&&e<=C?e-(R-10):e>=j&&e<=F?e-(j-10):void 0}function L(e){if("string"!=typeof e)throw new Error("hex string expected, got "+typeof e);if(T)return Uint8Array.fromHex(e);const t=e.length,n=t/2;if(t%2)throw new Error("hex string expected, got unpadded hex of length "+t);const r=new Uint8Array(n);for(let t=0,i=0;t<n;t++,i+=2){const n=D(e.charCodeAt(i)),o=D(e.charCodeAt(i+1));if(void 0===n||void 0===o){const t=e[i]+e[i+1];throw new Error('hex string expected, got non-hex character "'+t+'" at index '+i)}r[t]=16*n+o}return r}function H(e){return"string"==typeof e&&(e=function(e){if("string"!=typeof e)throw new Error("string expected");return new Uint8Array((new TextEncoder).encode(e))}(e)),k(e),e}function V(...e){let t=0;for(let n=0;n<e.length;n++){const r=e[n];k(r),t+=r.length}const n=new Uint8Array(t);for(let t=0,r=0;t<e.length;t++){const i=e[t];n.set(i,r),r+=i.length}return n}class q{}function M(e){const t=t=>e().update(H(t)).digest(),n=e();return t.outputLen=n.outputLen,t.blockLen=n.blockLen,t.create=()=>e(),t}function K(e=32){if(E&&"function"==typeof E.getRandomValues)return E.getRandomValues(new Uint8Array(e));if(E&&"function"==typeof E.randomBytes)return Uint8Array.from(E.randomBytes(e));throw new Error("crypto.getRandomValues must be defined")}function G(e,t,n){return e&t^~e&n}function W(e,t,n){return e&t^e&n^t&n}class Y extends q{constructor(e,t,n,r){super(),this.finished=!1,this.length=0,this.pos=0,this.destroyed=!1,this.blockLen=e,this.outputLen=t,this.padOffset=n,this.isLE=r,this.buffer=new Uint8Array(e),this.view=P(this.buffer)}update(e){A(this),k(e=H(e));const{view:t,buffer:n,blockLen:r}=this,i=e.length;for(let o=0;o<i;){const s=Math.min(r-this.pos,i-o);if(s===r){const t=P(e);for(;r<=i-o;o+=r)this.process(t,o);continue}n.set(e.subarray(o,o+s),this.pos),this.pos+=s,o+=s,this.pos===r&&(this.process(t,0),this.pos=0)}return this.length+=e.length,this.roundClean(),this}digestInto(e){A(this),function(e,t){k(e);const n=t.outputLen;if(e.length<n)throw new Error("digestInto() expects output buffer of length at least "+n)}(e,this),this.finished=!0;const{buffer:t,view:n,blockLen:r,isLE:i}=this;let{pos:o}=this;t[o++]=128,S(this.buffer.subarray(o)),this.padOffset>r-o&&(this.process(n,0),o=0);for(let e=o;e<r;e++)t[e]=0;!function(e,t,n,r){if("function"==typeof e.setBigUint64)return e.setBigUint64(t,n,r);const i=BigInt(32),o=BigInt(4294967295),s=Number(n>>i&o),u=Number(n&o),a=r?4:0,c=r?0:4;e.setUint32(t+a,s,r),e.setUint32(t+c,u,r)}(n,r-8,BigInt(8*this.length),i),this.process(n,0);const s=P(e),u=this.outputLen;if(u%4)throw new Error("_sha2: outputLen should be aligned to 32bit");const a=u/4,c=this.get();if(a>c.length)throw new Error("_sha2: outputLen bigger than state");for(let e=0;e<a;e++)s.setUint32(4*e,c[e],i)}digest(){const{buffer:e,outputLen:t}=this;this.digestInto(e);const n=e.slice(0,t);return this.destroy(),n}_cloneInto(e){e||(e=new this.constructor),e.set(...this.get());const{blockLen:t,buffer:n,length:r,finished:i,destroyed:o,pos:s}=this;return e.destroyed=o,e.finished=i,e.length=r,e.pos=s,r%t&&e.buffer.set(n),e}clone(){return this._cloneInto()}}const X=Uint32Array.from([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]),J=Uint32Array.from([1116352408,1899447441,3049323471,3921009573,961987163,1508970993,2453635748,2870763221,3624381080,310598401,607225278,1426881987,1925078388,2162078206,2614888103,3248222580,3835390401,4022224774,264347078,604807628,770255983,1249150122,1555081692,1996064986,2554220882,2821834349,2952996808,3210313671,3336571891,3584528711,113926993,338241895,666307205,773529912,1294757372,1396182291,1695183700,1986661051,2177026350,2456956037,2730485921,2820302411,3259730800,3345764771,3516065817,3600352804,4094571909,275423344,430227734,506948616,659060556,883997877,958139571,1322822218,1537002063,1747873779,1955562222,2024104815,2227730452,2361852424,2428436474,2756734187,3204031479,3329325298]),Q=new Uint32Array(64);class ee extends Y{constructor(e=32){super(64,e,8,!1),this.A=0|X[0],this.B=0|X[1],this.C=0|X[2],this.D=0|X[3],this.E=0|X[4],this.F=0|X[5],this.G=0|X[6],this.H=0|X[7]}get(){const{A:e,B:t,C:n,D:r,E:i,F:o,G:s,H:u}=this;return[e,t,n,r,i,o,s,u]}set(e,t,n,r,i,o,s,u){this.A=0|e,this.B=0|t,this.C=0|n,this.D=0|r,this.E=0|i,this.F=0|o,this.G=0|s,this.H=0|u}process(e,t){for(let n=0;n<16;n++,t+=4)Q[n]=e.getUint32(t,!1);for(let e=16;e<64;e++){const t=Q[e-15],n=Q[e-2],r=$(t,7)^$(t,18)^t>>>3,i=$(n,17)^$(n,19)^n>>>10;Q[e]=i+Q[e-7]+r+Q[e-16]|0}let{A:n,B:r,C:i,D:o,E:s,F:u,G:a,H:c}=this;for(let e=0;e<64;e++){const t=c+($(s,6)^$(s,11)^$(s,25))+G(s,u,a)+J[e]+Q[e]|0,f=($(n,2)^$(n,13)^$(n,22))+W(n,r,i)|0;c=a,a=u,u=s,s=o+t|0,o=i,i=r,r=n,n=t+f|0}n=n+this.A|0,r=r+this.B|0,i=i+this.C|0,o=o+this.D|0,s=s+this.E|0,u=u+this.F|0,a=a+this.G|0,c=c+this.H|0,this.set(n,r,i,o,s,u,a,c)}roundClean(){S(Q)}destroy(){this.set(0,0,0,0,0,0,0,0),S(this.buffer)}}const te=M(()=>new ee);class ne extends q{constructor(e,t){super(),this.finished=!1,this.destroyed=!1,O(e);const n=H(t);if(this.iHash=e.create(),"function"!=typeof this.iHash.update)throw new Error("Expected instance of class which extends utils.Hash");this.blockLen=this.iHash.blockLen,this.outputLen=this.iHash.outputLen;const r=this.blockLen,i=new Uint8Array(r);i.set(n.length>r?e.create().update(n).digest():n);for(let e=0;e<i.length;e++)i[e]^=54;this.iHash.update(i),this.oHash=e.create();for(let e=0;e<i.length;e++)i[e]^=106;this.oHash.update(i),S(i)}update(e){return A(this),this.iHash.update(e),this}digestInto(e){A(this),k(e,this.outputLen),this.finished=!0,this.iHash.digestInto(e),this.oHash.update(e),this.oHash.digestInto(e),this.destroy()}digest(){const e=new Uint8Array(this.oHash.outputLen);return this.digestInto(e),e}_cloneInto(e){e||(e=Object.create(Object.getPrototypeOf(this),{}));const{oHash:t,iHash:n,finished:r,destroyed:i,blockLen:o,outputLen:s}=this;return e.finished=r,e.destroyed=i,e.blockLen=o,e.outputLen=s,e.oHash=t._cloneInto(e.oHash),e.iHash=n._cloneInto(e.iHash),e}clone(){return this._cloneInto()}destroy(){this.destroyed=!0,this.oHash.destroy(),this.iHash.destroy()}}const re=(e,t,n)=>new ne(e,t).update(n).digest();re.create=(e,t)=>new ne(e,t);
1
+ var btc_dev=function(e){"use strict";var t,n;!function(e){function t(e){return null===e.match(/[^a-fA-F0-9]/)&&e.length%2==0}e.is_hex=t,e.is_bytes=function(e){return!("string"!=typeof e||!t(e))||(e instanceof Uint8Array||!(!Array.isArray(e)||!e.every(e=>"number"==typeof e)))}}(t||(t={})),function(e){e.within_size=function(e,t){if(e.length>t)throw new TypeError(`Data is larger than array size: ${e.length} > ${t}`)},e.is_hex=function(e){if(null!==e.match(/[^a-fA-f0-9]/))throw new TypeError("Invalid characters in hex string: "+e);if(e.length%2!=0)throw new Error(`Length of hex string is invalid: ${e.length}`)},e.is_bytes=function(e){if(!t.is_bytes(e))throw new Error("Bytes contains invalid elements: "+String(e))},e.is_json=function(e){try{JSON.parse(e)}catch{throw new TypeError("JSON string is invalid!")}},e.is_safe_int=function(e){if(e>Number.MAX_SAFE_INTEGER)throw new TypeError("Number exceeds safe bounds!")}}(n||(n={}));const r=BigInt(0),i=BigInt(255),o=BigInt(256);function s(e,t,n="be"){void 0===t&&(t=function(e){if(e<=0xffn)return 1;if(e<=0xffffn)return 2;if(e<=0xffffffffn)return 4;if(e<=0xffffffffffffffffn)return 8;if(e<=0xffffffffffffffffffffffffffffffffn)return 16;if(e<=0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffn)return 32;throw new TypeError("Must specify a fixed buffer size for bigints greater than 32 bytes.")}(e));const s="le"===n,u=new ArrayBuffer(t),c=new DataView(u);let a=s?0:t-1;for(;e>r;){const t=e&i,n=Number(t);s?c.setUint8(a++,n):c.setUint8(a--,n),e=(e-t)/o}return new Uint8Array(u)}function u(e,t){return"bigint"==typeof t?`${t}n`:t}function c(e,t){return"string"==typeof t&&/^[0-9]+n$/.test(t)?BigInt(t.slice(0,-1)):t}function a(e,t,n="be"){void 0===t&&(t=function(e){if(e<=255)return 1;if(e<=65535)return 2;if(e<=4294967295)return 4;throw new TypeError("Numbers larger than 4 bytes must specify a fixed size!")}(e));const r="le"===n,i=new ArrayBuffer(t),o=new DataView(i);let s=r?0:t-1;for(;e>0;){const t=255&e;r?o.setUint8(s++,e):o.setUint8(s--,e),e=(e-t)/256}return new Uint8Array(i)}function f(e,t,r="be"){t=function(e,t){n.is_hex(e);const r=e.length/2;void 0===t&&(t=r);if(r>t)throw new TypeError(`Hex string is larger than array size: ${r} > ${t}`);return t}(e,t);const i="be"===r,o=new ArrayBuffer(t),s=new DataView(o);let u=i?0:t-1;for(let t=0;t<e.length;t+=2){const n=e.substring(t,t+2),r=parseInt(n,16);i?s.setUint8(u++,r):s.setUint8(u--,r)}return new Uint8Array(o)}function d(e,t,r){if(e instanceof ArrayBuffer)return new Uint8Array(e);if(e instanceof Uint8Array)return function(e,t,r="le"){void 0===t&&(t=e.length);n.within_size(e,t);const i=new Uint8Array(t).fill(0),o="be"===r?0:t-e.length;return i.set(e,o),i}(e,t,r);if("string"==typeof e)return n.is_hex(e),f(e,t,r);if("bigint"==typeof e)return s(e,t,r);if("number"==typeof e)return a(e,t,r);throw new TypeError("Input type not supported:"+typeof e)}const l=new TextEncoder,h=new TextDecoder;function p(e){return l.encode(e)}function m(e){return h.decode(e)}class g extends Uint8Array{static{this.num=(e,t,n)=>new g(e,t,n)}static{this.big=(e,t,n)=>new g(e,t,n)}static{this.bin=(e,t,n)=>{const r=function(e){const t=e.split("").map(Number);if(t.length%8!=0)throw new Error(`Binary array is invalid length: ${e.length}`);const n=new Uint8Array(t.length/8);for(let e=0,r=0;e<t.length;e+=8,r++){let i=0;for(let n=0;n<8;n++)i|=t[e+n]<<7-n;n[r]=i}return n}(e);return new g(r,t,n)}}static{this.uint=(e,t,n)=>new g(e,t,n)}static{this.str=(e,t,n)=>{const r=p(e);return new g(r,t,n)}}static{this.hex=(e,t,r)=>(n.is_hex(e),new g(e,t,r))}static{this.bytes=(e,t,r)=>(n.is_bytes(e),new g(e,t,r))}static{this.json=(e,t)=>{t=t??u;const n=p(JSON.stringify(e,t));return new g(n)}}static{this.blob=(e,t,n)=>{const r=function(e,t,n){const r=e.length,i=n/t;if(n%t!==0)throw new TypeError(`Invalid parameters: ${n} % ${t} !== 0`);if(r!==n)throw new TypeError(`Invalid data stream: ${r} !== ${n}`);if(r%t!==0)throw new TypeError(`Invalid data stream: ${r} % ${t} !== 0`);const o=new Array(i);for(let n=0;n<i;n++){const r=n*t;o[n]=e.subarray(r,r+t)}return o}(d(e),t,n);return r.map(e=>new g(e))}}static{this.is_equal=(e,t)=>new g(e).hex===new g(t).hex}static{this.is_bytes=t.is_bytes}static{this.is_hex=t.is_hex}static random(e=32){const t=function(e=32){if(crypto&&"function"==typeof crypto.getRandomValues)return crypto.getRandomValues(new Uint8Array(e));const t=crypto;if(t&&void 0!==t.randomBytes&&"function"==typeof t.randomBytes)return t.randomBytes(e);throw new Error("getRandomValues from crypto library is undefined")}(e);return new g(t,e)}static now(){const e=Math.floor(Date.now()/1e3);return new g(e,4)}constructor(e,t,n){if(e instanceof g&&void 0===t)return e;super(d(e,t,n))}get arr(){return this.to_arr()}get big(){return this.to_big()}get bin(){return this.to_bin()}get hex(){return this.to_hex()}get num(){return this.to_num()}get str(){return this.to_str()}get uint(){return this.to_uint()}to_big(e="be"){return function(e){let t=BigInt(0);for(let n=e.length-1;n>=0;n--)t=t*o+BigInt(e[n]);return BigInt(t)}("be"===e?this.uint.reverse():this.uint)}to_hex(e="be"){return function(e){let t="";for(let n=0;n<e.length;n++)t+=e[n].toString(16).padStart(2,"0");return t}("be"===e?this.uint:this.uint.reverse())}to_json(e){void 0===e&&(e=c);const t=m(this);return JSON.parse(t,e)}to_num(e="be"){return function(e){let t=0;for(let r=e.length-1;r>=0;r--)t=256*t+e[r],n.is_safe_int(t);return t}("be"===e?this.uint.reverse():this.uint)}to_arr(){return[...this]}to_bin(){return function(e){const t=new Array(8*e.length);let n=0;for(const r of e){if(r>255)throw new Error(`Invalid byte value: ${r}. Byte values must be between 0 and 255.`);for(let e=7;e>=0;e--,n++)t[n]=r>>e&1}return t.join("")}(this)}to_str(){return m(this)}to_uint(){return new Uint8Array(this)}append(e){return g.join([this,new g(e)])}equals(e){return new g(e).hex===this.hex}prepend(e){return g.join([new g(e),this])}prefix_varint(e){if(0===this.length)throw new Error("buffer is empty");const t=g.varint(this.length,e);return this.prepend(t)}reverse(){return super.reverse(),this}set(e,t){this.set(e,t)}slice(e,t){const n=new Uint8Array(this).slice(e,t);return new g(n)}subarray(e,t){const n=new Uint8Array(this).subarray(e,t);return new g(n)}toJSON(){return this.hex}toString(){return this.hex}static from(e){return new g(Uint8Array.from(e))}static of(...e){return new g(Uint8Array.of(...e))}static join(e){const t=function(e){let t,n=0;const r=e.reduce((e,t)=>e+t.length,0),i=new Uint8Array(r);for(t=0;t<e.length;t++){const r=e[t];i.set(r,n),n+=r.length}return i}(e.map(e=>new g(e)));return new g(t)}static sort(e,t){const n=e.map(e=>new g(e,t).hex);return n.sort(),n.map(e=>g.hex(e,t))}static varint(e,t){if(e<253)return g.num(e,1);if(e<65536)return g.of(253,...g.num(e,2,t));if(e<4294967296)return g.of(254,...g.num(e,4,t));if(BigInt(e)<0x10000000000000000n)return g.of(255,...g.num(e,8,t));throw new Error(`Value is too large: ${e}`)}}class _{constructor(e){this.data=new g(e),this.size=this.data.length}peek(e){if(e>this.size)throw new Error(`Size greater than stream: ${e} > ${this.size}`);return new g(this.data.slice(0,e))}read(e){const t=this.peek(e);return this.data=this.data.slice(e),this.size=this.data.length,t}varint(e){const t=this.read(1).num;switch(!0){case t>=0&&t<253:return t;case 253===t:return this.read(2).to_num(e);case 254===t:return this.read(4).to_num(e);case 255===t:return this.read(8).to_num(e);default:throw new Error(`Varint is out of range: ${t}`)}}}function w(e){return e instanceof Map||Array.isArray(e)||"object"!=typeof e?e:Object.keys(e).sort().filter(([e,t])=>void 0!==t).reduce((t,n)=>(t[n]=e[n],t),{})}function y(e){return e instanceof Error?e.message:"string"==typeof e?e:String(e)}var v,b;!function(e){function t(e){return"object"==typeof e&&null!==e&&!Array.isArray(e)}function n(e){return"string"==typeof e}function r(e){return Number.isInteger(e)&&!Number.isNaN(e)}function i(e){return!!n(e)&&(null===e.match(/[^a-fA-F0-9]/)&&e.length%2==0)}e.exists=function(e){return null!=e},e.is_equal=function(e,t){return e===t},e.is_object=t,e.is_deep_equal=function(e,n){return t(e)&&(e=w(e)),t(n)&&(n=w(n)),String(e)===String(n)},e.has_items=function(e){return Array.isArray(e)&&e.length>0},e.is_string=n,e.is_number=r,e.is_bigint=function(e){return"bigint"==typeof e},e.is_uchar=function(e){return r(e)&&e>=0&&e<=255},e.is_ushort=function(e){return r(e)&&e>=0&&e<=65535},e.is_uint=function(e){return r(e)&&e>=0&&e<=4294967295},e.is_u8a=function(e){return e instanceof Uint8Array},e.is_bytes=function(e){return g.is_bytes(e)},e.is_base58=function(e){return"string"==typeof e&&/^[123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz]+$/.test(e)},e.is_base64=function(e){return"string"==typeof e&&/^[a-zA-Z0-9+/]+={0,2}$/.test(e)},e.is_b64url=function(e){return"string"==typeof e&&/^[a-zA-Z0-9\-_]+={0,2}$/.test(e)},e.is_bech32=function(e){return"string"==typeof e&&/^[a-z]+1[023456789acdefghjklmnpqrstuvwxyz]+$/.test(e)},e.is_hex=i,e.is_hash=function(e){return n(e)&&i(e)&&64===e.length}}(v||(v={})),function(e){e.ok=function(e,t){if(!1===e)throw new Error(t??"Assertion failed!")},e.exists=function(e,t){if(!v.exists(e))throw new Error(t??"Value is null or undefined!")},e.is_empty=function(e,t){if(null!=e)throw new Error(t??"value is not null or undefined!")},e.is_instance=function(e,t,n){if(!(e instanceof t))throw new Error(n??`value is not an instance of ${t.name}`)},e.is_equal=function(e,t,n){if(!v.is_equal(e,t))throw new Error(n??`values are not equal: ${String(e)} !== ${String(t)}`)},e.is_object=function(e,t){if(!v.is_object(e))throw new Error(t??`value is not an object: ${String(e)}`)},e.is_deep_equal=function(e,t,n){if(!v.is_deep_equal(e,t))throw new Error(n??`values are not deep equal: ${String(e)} !== ${String(t)}`)},e.is_number=function(e){if(!v.is_number(e))throw new TypeError(`invalid number: ${String(e)}`)},e.is_bigint=function(e){if(!v.is_bigint(e))throw new TypeError(`invalid bigint: ${String(e)}`)},e.is_hex=function(e){if(!v.is_hex(e))throw new TypeError(`invalid hex: ${String(e)}`)},e.is_uchar=function(e){if(!v.is_uchar(e))throw new TypeError(`invalid unsignedchar: ${String(e)}`)},e.is_ushort=function(e){if(!v.is_ushort(e))throw new TypeError(`invalid unsigned short: ${String(e)}`)},e.is_uint=function(e){if(!v.is_uint(e))throw new TypeError(`invalid unsigned int: ${String(e)}`)},e.is_u8a=function(e){if(!v.is_u8a(e))throw new TypeError(`invalid Uint8Array: ${String(e)}`)},e.is_hash=function(e,t){if(!v.is_hash(e))throw new TypeError(t??`invalid hash: ${String(e)}`)},e.is_bytes=function(e,t){if(!v.is_bytes(e))throw new TypeError(t??`invalid bytes: ${String(e)}`)},e.size=function(e,t,n){const r=g.bytes(e);if(r.length!==t)throw new Error(n??`invalid input size: ${r.length} !== ${t}`)},e.has_items=function(e,t){if(!v.has_items(e))throw new Error(t??"array does not contain any items")},e.is_base58=function(e){if(!v.is_base58(e))throw new Error("invalid base58 string")},e.is_base64=function(e){if(!v.is_base64(e))throw new Error("invalid base64 string")},e.is_b64url=function(e){if(!v.is_b64url(e))throw new Error("invalid base64url string")},e.is_bech32=function(e){if(!v.is_bech32(e))throw new Error("invalid bech32 string")}}(b||(b={}));const E="object"==typeof globalThis&&"crypto"in globalThis?globalThis.crypto:void 0;
2
+ /*! noble-hashes - MIT License (c) 2022 Paul Miller (paulmillr.com) */function x(e){return e instanceof Uint8Array||ArrayBuffer.isView(e)&&"Uint8Array"===e.constructor.name}function z(e){if(!Number.isSafeInteger(e)||e<0)throw new Error("positive integer expected, got "+e)}function k(e,...t){if(!x(e))throw new Error("Uint8Array expected");if(t.length>0&&!t.includes(e.length))throw new Error("Uint8Array expected of length "+t+", got length="+e.length)}function O(e){if("function"!=typeof e||"function"!=typeof e.create)throw new Error("Hash should be wrapped by utils.createHasher");z(e.outputLen),z(e.blockLen)}function P(e,t=!0){if(e.destroyed)throw new Error("Hash instance has been destroyed");if(t&&e.finished)throw new Error("Hash#digest() has already been called")}function S(...e){for(let t=0;t<e.length;t++)e[t].fill(0)}function A(e){return new DataView(e.buffer,e.byteOffset,e.byteLength)}function I(e,t){return e<<32-t|e>>>t}function $(e,t){return e<<t|e>>>32-t>>>0}const T=(()=>"function"==typeof Uint8Array.from([]).toHex&&"function"==typeof Uint8Array.fromHex)(),N=Array.from({length:256},(e,t)=>t.toString(16).padStart(2,"0"));function B(e){if(k(e),T)return e.toHex();let t="";for(let n=0;n<e.length;n++)t+=N[e[n]];return t}const U=48,Z=57,R=65,C=70,j=97,F=102;function H(e){return e>=U&&e<=Z?e-U:e>=R&&e<=C?e-(R-10):e>=j&&e<=F?e-(j-10):void 0}function D(e){if("string"!=typeof e)throw new Error("hex string expected, got "+typeof e);if(T)return Uint8Array.fromHex(e);const t=e.length,n=t/2;if(t%2)throw new Error("hex string expected, got unpadded hex of length "+t);const r=new Uint8Array(n);for(let t=0,i=0;t<n;t++,i+=2){const n=H(e.charCodeAt(i)),o=H(e.charCodeAt(i+1));if(void 0===n||void 0===o){const t=e[i]+e[i+1];throw new Error('hex string expected, got non-hex character "'+t+'" at index '+i)}r[t]=16*n+o}return r}function L(e){return"string"==typeof e&&(e=function(e){if("string"!=typeof e)throw new Error("string expected");return new Uint8Array((new TextEncoder).encode(e))}(e)),k(e),e}function V(...e){let t=0;for(let n=0;n<e.length;n++){const r=e[n];k(r),t+=r.length}const n=new Uint8Array(t);for(let t=0,r=0;t<e.length;t++){const i=e[t];n.set(i,r),r+=i.length}return n}class q{}function M(e){const t=t=>e().update(L(t)).digest(),n=e();return t.outputLen=n.outputLen,t.blockLen=n.blockLen,t.create=()=>e(),t}function K(e=32){if(E&&"function"==typeof E.getRandomValues)return E.getRandomValues(new Uint8Array(e));if(E&&"function"==typeof E.randomBytes)return Uint8Array.from(E.randomBytes(e));throw new Error("crypto.getRandomValues must be defined")}function W(e,t,n){return e&t^~e&n}function G(e,t,n){return e&t^e&n^t&n}class Y extends q{constructor(e,t,n,r){super(),this.finished=!1,this.length=0,this.pos=0,this.destroyed=!1,this.blockLen=e,this.outputLen=t,this.padOffset=n,this.isLE=r,this.buffer=new Uint8Array(e),this.view=A(this.buffer)}update(e){P(this),k(e=L(e));const{view:t,buffer:n,blockLen:r}=this,i=e.length;for(let o=0;o<i;){const s=Math.min(r-this.pos,i-o);if(s===r){const t=A(e);for(;r<=i-o;o+=r)this.process(t,o);continue}n.set(e.subarray(o,o+s),this.pos),this.pos+=s,o+=s,this.pos===r&&(this.process(t,0),this.pos=0)}return this.length+=e.length,this.roundClean(),this}digestInto(e){P(this),function(e,t){k(e);const n=t.outputLen;if(e.length<n)throw new Error("digestInto() expects output buffer of length at least "+n)}(e,this),this.finished=!0;const{buffer:t,view:n,blockLen:r,isLE:i}=this;let{pos:o}=this;t[o++]=128,S(this.buffer.subarray(o)),this.padOffset>r-o&&(this.process(n,0),o=0);for(let e=o;e<r;e++)t[e]=0;!function(e,t,n,r){if("function"==typeof e.setBigUint64)return e.setBigUint64(t,n,r);const i=BigInt(32),o=BigInt(4294967295),s=Number(n>>i&o),u=Number(n&o),c=r?4:0,a=r?0:4;e.setUint32(t+c,s,r),e.setUint32(t+a,u,r)}(n,r-8,BigInt(8*this.length),i),this.process(n,0);const s=A(e),u=this.outputLen;if(u%4)throw new Error("_sha2: outputLen should be aligned to 32bit");const c=u/4,a=this.get();if(c>a.length)throw new Error("_sha2: outputLen bigger than state");for(let e=0;e<c;e++)s.setUint32(4*e,a[e],i)}digest(){const{buffer:e,outputLen:t}=this;this.digestInto(e);const n=e.slice(0,t);return this.destroy(),n}_cloneInto(e){e||(e=new this.constructor),e.set(...this.get());const{blockLen:t,buffer:n,length:r,finished:i,destroyed:o,pos:s}=this;return e.destroyed=o,e.finished=i,e.length=r,e.pos=s,r%t&&e.buffer.set(n),e}clone(){return this._cloneInto()}}const X=Uint32Array.from([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]),J=Uint32Array.from([1116352408,1899447441,3049323471,3921009573,961987163,1508970993,2453635748,2870763221,3624381080,310598401,607225278,1426881987,1925078388,2162078206,2614888103,3248222580,3835390401,4022224774,264347078,604807628,770255983,1249150122,1555081692,1996064986,2554220882,2821834349,2952996808,3210313671,3336571891,3584528711,113926993,338241895,666307205,773529912,1294757372,1396182291,1695183700,1986661051,2177026350,2456956037,2730485921,2820302411,3259730800,3345764771,3516065817,3600352804,4094571909,275423344,430227734,506948616,659060556,883997877,958139571,1322822218,1537002063,1747873779,1955562222,2024104815,2227730452,2361852424,2428436474,2756734187,3204031479,3329325298]),Q=new Uint32Array(64);class ee extends Y{constructor(e=32){super(64,e,8,!1),this.A=0|X[0],this.B=0|X[1],this.C=0|X[2],this.D=0|X[3],this.E=0|X[4],this.F=0|X[5],this.G=0|X[6],this.H=0|X[7]}get(){const{A:e,B:t,C:n,D:r,E:i,F:o,G:s,H:u}=this;return[e,t,n,r,i,o,s,u]}set(e,t,n,r,i,o,s,u){this.A=0|e,this.B=0|t,this.C=0|n,this.D=0|r,this.E=0|i,this.F=0|o,this.G=0|s,this.H=0|u}process(e,t){for(let n=0;n<16;n++,t+=4)Q[n]=e.getUint32(t,!1);for(let e=16;e<64;e++){const t=Q[e-15],n=Q[e-2],r=I(t,7)^I(t,18)^t>>>3,i=I(n,17)^I(n,19)^n>>>10;Q[e]=i+Q[e-7]+r+Q[e-16]|0}let{A:n,B:r,C:i,D:o,E:s,F:u,G:c,H:a}=this;for(let e=0;e<64;e++){const t=a+(I(s,6)^I(s,11)^I(s,25))+W(s,u,c)+J[e]+Q[e]|0,f=(I(n,2)^I(n,13)^I(n,22))+G(n,r,i)|0;a=c,c=u,u=s,s=o+t|0,o=i,i=r,r=n,n=t+f|0}n=n+this.A|0,r=r+this.B|0,i=i+this.C|0,o=o+this.D|0,s=s+this.E|0,u=u+this.F|0,c=c+this.G|0,a=a+this.H|0,this.set(n,r,i,o,s,u,c,a)}roundClean(){S(Q)}destroy(){this.set(0,0,0,0,0,0,0,0),S(this.buffer)}}const te=M(()=>new ee);class ne extends q{constructor(e,t){super(),this.finished=!1,this.destroyed=!1,O(e);const n=L(t);if(this.iHash=e.create(),"function"!=typeof this.iHash.update)throw new Error("Expected instance of class which extends utils.Hash");this.blockLen=this.iHash.blockLen,this.outputLen=this.iHash.outputLen;const r=this.blockLen,i=new Uint8Array(r);i.set(n.length>r?e.create().update(n).digest():n);for(let e=0;e<i.length;e++)i[e]^=54;this.iHash.update(i),this.oHash=e.create();for(let e=0;e<i.length;e++)i[e]^=106;this.oHash.update(i),S(i)}update(e){return P(this),this.iHash.update(e),this}digestInto(e){P(this),k(e,this.outputLen),this.finished=!0,this.iHash.digestInto(e),this.oHash.update(e),this.oHash.digestInto(e),this.destroy()}digest(){const e=new Uint8Array(this.oHash.outputLen);return this.digestInto(e),e}_cloneInto(e){e||(e=Object.create(Object.getPrototypeOf(this),{}));const{oHash:t,iHash:n,finished:r,destroyed:i,blockLen:o,outputLen:s}=this;return e.finished=r,e.destroyed=i,e.blockLen=o,e.outputLen=s,e.oHash=t._cloneInto(e.oHash),e.iHash=n._cloneInto(e.iHash),e}clone(){return this._cloneInto()}destroy(){this.destroyed=!0,this.oHash.destroy(),this.iHash.destroy()}}const re=(e,t,n)=>new ne(e,t).update(n).digest();re.create=(e,t)=>new ne(e,t);
3
3
  /*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */
4
- const ie=BigInt(0),oe=BigInt(1);function se(e,t){if("boolean"!=typeof t)throw new Error(e+" boolean expected, got "+t)}function ue(e){const t=e.toString(16);return 1&t.length?"0"+t:t}function ae(e){if("string"!=typeof e)throw new Error("hex string expected, got "+typeof e);return""===e?ie:BigInt("0x"+e)}function ce(e){return ae(B(e))}function fe(e){return k(e),ae(B(Uint8Array.from(e).reverse()))}function de(e,t){return L(e.toString(16).padStart(2*t,"0"))}function le(e,t){return de(e,t).reverse()}function he(e,t,n){let r;if("string"==typeof t)try{r=L(t)}catch(t){throw new Error(e+" must be hex string or Uint8Array, cause: "+t)}else{if(!x(t))throw new Error(e+" must be hex string or Uint8Array");r=Uint8Array.from(t)}const i=r.length;if("number"==typeof n&&i!==n)throw new Error(e+" of length "+n+" expected, got "+i);return r}const pe=e=>"bigint"==typeof e&&ie<=e;function me(e,t,n){return pe(e)&&pe(t)&&pe(n)&&t<=e&&e<n}function ge(e,t,n,r){if(!me(t,n,r))throw new Error("expected valid "+e+": "+n+" <= n < "+r+", got "+t)}function we(e){let t;for(t=0;e>ie;e>>=oe,t+=1);return t}const _e=e=>(oe<<BigInt(e))-oe;function ye(e,t,n={}){if(!e||"object"!=typeof e)throw new Error("expected valid options object");function r(t,n,r){const i=e[t];if(r&&void 0===i)return;const o=typeof i;if(o!==n||null===i)throw new Error(`param "${t}" is invalid: expected ${n}, got ${o}`)}Object.entries(t).forEach(([e,t])=>r(e,t,!1)),Object.entries(n).forEach(([e,t])=>r(e,t,!0))}function ve(e){const t=new WeakMap;return(n,...r)=>{const i=t.get(n);if(void 0!==i)return i;const o=e(n,...r);return t.set(n,o),o}}
5
- /*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */const be=BigInt(0),Ee=BigInt(1),xe=BigInt(2),ze=BigInt(3),ke=BigInt(4),Oe=BigInt(5),Ae=BigInt(7),Se=BigInt(8),Pe=BigInt(9),$e=BigInt(16);function Ie(e,t){const n=e%t;return n>=be?n:t+n}function Te(e,t,n){let r=e;for(;t-- >be;)r*=r,r%=n;return r}function Ne(e,t){if(e===be)throw new Error("invert: expected non-zero number");if(t<=be)throw new Error("invert: expected positive modulus, got "+t);let n=Ie(e,t),r=t,i=be,o=Ee;for(;n!==be;){const e=r%n,t=i-o*(r/n);r=n,n=e,i=o,o=t}if(r!==Ee)throw new Error("invert: does not exist");return Ie(i,t)}function Be(e,t,n){if(!e.eql(e.sqr(t),n))throw new Error("Cannot find square root")}function Ue(e,t){const n=(e.ORDER+Ee)/ke,r=e.pow(t,n);return Be(e,r,t),r}function Ze(e,t){const n=(e.ORDER-Oe)/Se,r=e.mul(t,xe),i=e.pow(r,n),o=e.mul(t,i),s=e.mul(e.mul(o,xe),i),u=e.mul(o,e.sub(s,e.ONE));return Be(e,u,t),u}function Re(e){if(e<ze)throw new Error("sqrt is not defined for small field");let t=e-Ee,n=0;for(;t%xe===be;)t/=xe,n++;let r=xe;const i=Le(e);for(;1===De(i,r);)if(r++>1e3)throw new Error("Cannot find square root: probably non-prime P");if(1===n)return Ue;let o=i.pow(r,t);const s=(t+Ee)/xe;return function(e,r){if(e.is0(r))return r;if(1!==De(e,r))throw new Error("Cannot find square root");let i=n,u=e.mul(e.ONE,o),a=e.pow(r,t),c=e.pow(r,s);for(;!e.eql(a,e.ONE);){if(e.is0(a))return e.ZERO;let t=1,n=e.sqr(a);for(;!e.eql(n,e.ONE);)if(t++,n=e.sqr(n),t===i)throw new Error("Cannot find square root");const r=Ee<<BigInt(i-t-1),o=e.pow(u,r);i=t,u=e.sqr(o),a=e.mul(a,u),c=e.mul(c,o)}return c}}function Ce(e){return e%ke===ze?Ue:e%Se===Oe?Ze:e%$e===Pe?function(e){const t=Le(e),n=Re(e),r=n(t,t.neg(t.ONE)),i=n(t,r),o=n(t,t.neg(r)),s=(e+Ae)/$e;return(e,t)=>{let n=e.pow(t,s),u=e.mul(n,r);const a=e.mul(n,i),c=e.mul(n,o),f=e.eql(e.sqr(u),t),d=e.eql(e.sqr(a),t);n=e.cmov(n,u,f),u=e.cmov(c,a,d);const l=e.eql(e.sqr(u),t),h=e.cmov(n,u,l);return Be(e,h,t),h}}(e):Re(e)}const je=["create","isValid","is0","neg","inv","sqrt","sqr","eql","add","sub","mul","pow","div","addN","subN","mulN","sqrN"];function Fe(e,t,n=!1){const r=new Array(t.length).fill(n?e.ZERO:void 0),i=t.reduce((t,n,i)=>e.is0(n)?t:(r[i]=t,e.mul(t,n)),e.ONE),o=e.inv(i);return t.reduceRight((t,n,i)=>e.is0(n)?t:(r[i]=e.mul(t,r[i]),e.mul(t,n)),o),r}function De(e,t){const n=(e.ORDER-Ee)/xe,r=e.pow(t,n),i=e.eql(r,e.ONE),o=e.eql(r,e.ZERO),s=e.eql(r,e.neg(e.ONE));if(!i&&!o&&!s)throw new Error("invalid Legendre symbol result");return i?1:o?0:-1}function Le(e,t,n=!1,r={}){if(e<=be)throw new Error("invalid field: expected ORDER > 0, got "+e);let i,o,s,u=!1;if("object"==typeof t&&null!=t){if(r.sqrt||n)throw new Error("cannot specify opts in two arguments");const e=t;e.BITS&&(i=e.BITS),e.sqrt&&(o=e.sqrt),"boolean"==typeof e.isLE&&(n=e.isLE),"boolean"==typeof e.modOnDecode&&(u=e.modOnDecode),s=e.allowedLengths}else"number"==typeof t&&(i=t),r.sqrt&&(o=r.sqrt);const{nBitLength:a,nByteLength:c}=function(e,t){void 0!==t&&z(t);const n=void 0!==t?t:e.toString(2).length;return{nBitLength:n,nByteLength:Math.ceil(n/8)}}(e,i);if(c>2048)throw new Error("invalid field: expected ORDER of <= 2048 bytes");let f;const d=Object.freeze({ORDER:e,isLE:n,BITS:a,BYTES:c,MASK:_e(a),ZERO:be,ONE:Ee,allowedLengths:s,create:t=>Ie(t,e),isValid:t=>{if("bigint"!=typeof t)throw new Error("invalid field element: expected bigint, got "+typeof t);return be<=t&&t<e},is0:e=>e===be,isValidNot0:e=>!d.is0(e)&&d.isValid(e),isOdd:e=>(e&Ee)===Ee,neg:t=>Ie(-t,e),eql:(e,t)=>e===t,sqr:t=>Ie(t*t,e),add:(t,n)=>Ie(t+n,e),sub:(t,n)=>Ie(t-n,e),mul:(t,n)=>Ie(t*n,e),pow:(e,t)=>function(e,t,n){if(n<be)throw new Error("invalid exponent, negatives unsupported");if(n===be)return e.ONE;if(n===Ee)return t;let r=e.ONE,i=t;for(;n>be;)n&Ee&&(r=e.mul(r,i)),i=e.sqr(i),n>>=Ee;return r}(d,e,t),div:(t,n)=>Ie(t*Ne(n,e),e),sqrN:e=>e*e,addN:(e,t)=>e+t,subN:(e,t)=>e-t,mulN:(e,t)=>e*t,inv:t=>Ne(t,e),sqrt:o||(t=>(f||(f=Ce(e)),f(d,t))),toBytes:e=>n?le(e,c):de(e,c),fromBytes:(t,r=!0)=>{if(s){if(!s.includes(t.length)||t.length>c)throw new Error("Field.fromBytes: expected "+s+" bytes, got "+t.length);const e=new Uint8Array(c);e.set(t,n?0:e.length-t.length),t=e}if(t.length!==c)throw new Error("Field.fromBytes: expected "+c+" bytes, got "+t.length);let i=n?fe(t):ce(t);if(u&&(i=Ie(i,e)),!r&&!d.isValid(i))throw new Error("invalid field element: outside of range 0..ORDER");return i},invertBatch:e=>Fe(d,e),cmov:(e,t,n)=>n?t:e});return Object.freeze(d)}function He(e){if("bigint"!=typeof e)throw new Error("field order must be bigint");const t=e.toString(2).length;return Math.ceil(t/8)}function Ve(e){const t=He(e);return t+Math.ceil(t/2)}function qe(e,t,n=!1){const r=e.length,i=He(t),o=Ve(t);if(r<16||r<o||r>1024)throw new Error("expected "+o+"-1024 bytes of input, got "+r);const s=Ie(n?fe(e):ce(e),t-Ee)+Ee;return n?le(s,i):de(s,i)}
6
- /*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */const Me=BigInt(0),Ke=BigInt(1);function Ge(e,t){const n=t.negate();return e?n:t}function We(e,t){const n=Fe(e.Fp,t.map(e=>e.Z));return t.map((t,r)=>e.fromAffine(t.toAffine(n[r])))}function Ye(e,t){if(!Number.isSafeInteger(e)||e<=0||e>t)throw new Error("invalid window size, expected [1.."+t+"], got W="+e)}function Xe(e,t){Ye(e,t);const n=2**e;return{windows:Math.ceil(t/e)+1,windowSize:2**(e-1),mask:_e(e),maxNumber:n,shiftBy:BigInt(e)}}function Je(e,t,n){const{windowSize:r,mask:i,maxNumber:o,shiftBy:s}=n;let u=Number(e&i),a=e>>s;u>r&&(u-=o,a+=Ke);const c=t*r;return{nextN:a,offset:c+Math.abs(u)-1,isZero:0===u,isNeg:u<0,isNegF:t%2!=0,offsetF:c}}const Qe=new WeakMap,et=new WeakMap;function tt(e){return et.get(e)||1}function nt(e){if(e!==Me)throw new Error("invalid wNAF")}class rt{constructor(e,t){this.BASE=e.BASE,this.ZERO=e.ZERO,this.Fn=e.Fn,this.bits=t}_unsafeLadder(e,t,n=this.ZERO){let r=e;for(;t>Me;)t&Ke&&(n=n.add(r)),r=r.double(),t>>=Ke;return n}precomputeWindow(e,t){const{windows:n,windowSize:r}=Xe(t,this.bits),i=[];let o=e,s=o;for(let e=0;e<n;e++){s=o,i.push(s);for(let e=1;e<r;e++)s=s.add(o),i.push(s);o=s.double()}return i}wNAF(e,t,n){if(!this.Fn.isValid(n))throw new Error("invalid scalar");let r=this.ZERO,i=this.BASE;const o=Xe(e,this.bits);for(let e=0;e<o.windows;e++){const{nextN:s,offset:u,isZero:a,isNeg:c,isNegF:f,offsetF:d}=Je(n,e,o);n=s,a?i=i.add(Ge(f,t[d])):r=r.add(Ge(c,t[u]))}return nt(n),{p:r,f:i}}wNAFUnsafe(e,t,n,r=this.ZERO){const i=Xe(e,this.bits);for(let e=0;e<i.windows&&n!==Me;e++){const{nextN:o,offset:s,isZero:u,isNeg:a}=Je(n,e,i);if(n=o,!u){const e=t[s];r=r.add(a?e.negate():e)}}return nt(n),r}getPrecomputes(e,t,n){let r=Qe.get(t);return r||(r=this.precomputeWindow(t,e),1!==e&&("function"==typeof n&&(r=n(r)),Qe.set(t,r))),r}cached(e,t,n){const r=tt(e);return this.wNAF(r,this.getPrecomputes(r,e,n),t)}unsafe(e,t,n,r){const i=tt(e);return 1===i?this._unsafeLadder(e,t,r):this.wNAFUnsafe(i,this.getPrecomputes(i,e,n),t,r)}createCache(e,t){Ye(t,this.bits),et.set(e,t),Qe.delete(e)}hasCache(e){return 1!==tt(e)}}function it(e,t,n,r){!function(e,t){if(!Array.isArray(e))throw new Error("array expected");e.forEach((e,n)=>{if(!(e instanceof t))throw new Error("invalid point at index "+n)})}(n,e),function(e,t){if(!Array.isArray(e))throw new Error("array of scalars expected");e.forEach((e,n)=>{if(!t.isValid(e))throw new Error("invalid scalar at index "+n)})}(r,t);const i=n.length,o=r.length;if(i!==o)throw new Error("arrays of points and scalars must have equal length");const s=e.ZERO,u=we(BigInt(i));let a=1;u>12?a=u-3:u>4?a=u-2:u>0&&(a=2);const c=_e(a),f=new Array(Number(c)+1).fill(s);let d=s;for(let e=Math.floor((t.BITS-1)/a)*a;e>=0;e-=a){f.fill(s);for(let t=0;t<o;t++){const i=r[t],o=Number(i>>BigInt(e)&c);f[o]=f[o].add(n[t])}let t=s;for(let e=f.length-1,n=s;e>0;e--)n=n.add(f[e]),t=t.add(n);if(d=d.add(t),0!==e)for(let e=0;e<a;e++)d=d.double()}return d}function ot(e,t){if(t){if(t.ORDER!==e)throw new Error("Field.ORDER must match order: Fp == p, Fn == n");return function(e){ye(e,je.reduce((e,t)=>(e[t]="function",e),{ORDER:"bigint",MASK:"bigint",BYTES:"number",BITS:"number"}))}(t),t}return Le(e)}
4
+ const ie=BigInt(0),oe=BigInt(1);function se(e,t){if("boolean"!=typeof t)throw new Error(e+" boolean expected, got "+t)}function ue(e){const t=e.toString(16);return 1&t.length?"0"+t:t}function ce(e){if("string"!=typeof e)throw new Error("hex string expected, got "+typeof e);return""===e?ie:BigInt("0x"+e)}function ae(e){return ce(B(e))}function fe(e){return k(e),ce(B(Uint8Array.from(e).reverse()))}function de(e,t){return D(e.toString(16).padStart(2*t,"0"))}function le(e,t){return de(e,t).reverse()}function he(e,t,n){let r;if("string"==typeof t)try{r=D(t)}catch(t){throw new Error(e+" must be hex string or Uint8Array, cause: "+t)}else{if(!x(t))throw new Error(e+" must be hex string or Uint8Array");r=Uint8Array.from(t)}const i=r.length;if("number"==typeof n&&i!==n)throw new Error(e+" of length "+n+" expected, got "+i);return r}const pe=e=>"bigint"==typeof e&&ie<=e;function me(e,t,n){return pe(e)&&pe(t)&&pe(n)&&t<=e&&e<n}function ge(e,t,n,r){if(!me(t,n,r))throw new Error("expected valid "+e+": "+n+" <= n < "+r+", got "+t)}function _e(e){let t;for(t=0;e>ie;e>>=oe,t+=1);return t}const we=e=>(oe<<BigInt(e))-oe;function ye(e,t,n={}){if(!e||"object"!=typeof e)throw new Error("expected valid options object");function r(t,n,r){const i=e[t];if(r&&void 0===i)return;const o=typeof i;if(o!==n||null===i)throw new Error(`param "${t}" is invalid: expected ${n}, got ${o}`)}Object.entries(t).forEach(([e,t])=>r(e,t,!1)),Object.entries(n).forEach(([e,t])=>r(e,t,!0))}function ve(e){const t=new WeakMap;return(n,...r)=>{const i=t.get(n);if(void 0!==i)return i;const o=e(n,...r);return t.set(n,o),o}}
5
+ /*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */const be=BigInt(0),Ee=BigInt(1),xe=BigInt(2),ze=BigInt(3),ke=BigInt(4),Oe=BigInt(5),Pe=BigInt(7),Se=BigInt(8),Ae=BigInt(9),Ie=BigInt(16);function $e(e,t){const n=e%t;return n>=be?n:t+n}function Te(e,t,n){let r=e;for(;t-- >be;)r*=r,r%=n;return r}function Ne(e,t){if(e===be)throw new Error("invert: expected non-zero number");if(t<=be)throw new Error("invert: expected positive modulus, got "+t);let n=$e(e,t),r=t,i=be,o=Ee;for(;n!==be;){const e=r%n,t=i-o*(r/n);r=n,n=e,i=o,o=t}if(r!==Ee)throw new Error("invert: does not exist");return $e(i,t)}function Be(e,t,n){if(!e.eql(e.sqr(t),n))throw new Error("Cannot find square root")}function Ue(e,t){const n=(e.ORDER+Ee)/ke,r=e.pow(t,n);return Be(e,r,t),r}function Ze(e,t){const n=(e.ORDER-Oe)/Se,r=e.mul(t,xe),i=e.pow(r,n),o=e.mul(t,i),s=e.mul(e.mul(o,xe),i),u=e.mul(o,e.sub(s,e.ONE));return Be(e,u,t),u}function Re(e){if(e<ze)throw new Error("sqrt is not defined for small field");let t=e-Ee,n=0;for(;t%xe===be;)t/=xe,n++;let r=xe;const i=De(e);for(;1===He(i,r);)if(r++>1e3)throw new Error("Cannot find square root: probably non-prime P");if(1===n)return Ue;let o=i.pow(r,t);const s=(t+Ee)/xe;return function(e,r){if(e.is0(r))return r;if(1!==He(e,r))throw new Error("Cannot find square root");let i=n,u=e.mul(e.ONE,o),c=e.pow(r,t),a=e.pow(r,s);for(;!e.eql(c,e.ONE);){if(e.is0(c))return e.ZERO;let t=1,n=e.sqr(c);for(;!e.eql(n,e.ONE);)if(t++,n=e.sqr(n),t===i)throw new Error("Cannot find square root");const r=Ee<<BigInt(i-t-1),o=e.pow(u,r);i=t,u=e.sqr(o),c=e.mul(c,u),a=e.mul(a,o)}return a}}function Ce(e){return e%ke===ze?Ue:e%Se===Oe?Ze:e%Ie===Ae?function(e){const t=De(e),n=Re(e),r=n(t,t.neg(t.ONE)),i=n(t,r),o=n(t,t.neg(r)),s=(e+Pe)/Ie;return(e,t)=>{let n=e.pow(t,s),u=e.mul(n,r);const c=e.mul(n,i),a=e.mul(n,o),f=e.eql(e.sqr(u),t),d=e.eql(e.sqr(c),t);n=e.cmov(n,u,f),u=e.cmov(a,c,d);const l=e.eql(e.sqr(u),t),h=e.cmov(n,u,l);return Be(e,h,t),h}}(e):Re(e)}const je=["create","isValid","is0","neg","inv","sqrt","sqr","eql","add","sub","mul","pow","div","addN","subN","mulN","sqrN"];function Fe(e,t,n=!1){const r=new Array(t.length).fill(n?e.ZERO:void 0),i=t.reduce((t,n,i)=>e.is0(n)?t:(r[i]=t,e.mul(t,n)),e.ONE),o=e.inv(i);return t.reduceRight((t,n,i)=>e.is0(n)?t:(r[i]=e.mul(t,r[i]),e.mul(t,n)),o),r}function He(e,t){const n=(e.ORDER-Ee)/xe,r=e.pow(t,n),i=e.eql(r,e.ONE),o=e.eql(r,e.ZERO),s=e.eql(r,e.neg(e.ONE));if(!i&&!o&&!s)throw new Error("invalid Legendre symbol result");return i?1:o?0:-1}function De(e,t,n=!1,r={}){if(e<=be)throw new Error("invalid field: expected ORDER > 0, got "+e);let i,o,s,u=!1;if("object"==typeof t&&null!=t){if(r.sqrt||n)throw new Error("cannot specify opts in two arguments");const e=t;e.BITS&&(i=e.BITS),e.sqrt&&(o=e.sqrt),"boolean"==typeof e.isLE&&(n=e.isLE),"boolean"==typeof e.modOnDecode&&(u=e.modOnDecode),s=e.allowedLengths}else"number"==typeof t&&(i=t),r.sqrt&&(o=r.sqrt);const{nBitLength:c,nByteLength:a}=function(e,t){void 0!==t&&z(t);const n=void 0!==t?t:e.toString(2).length;return{nBitLength:n,nByteLength:Math.ceil(n/8)}}(e,i);if(a>2048)throw new Error("invalid field: expected ORDER of <= 2048 bytes");let f;const d=Object.freeze({ORDER:e,isLE:n,BITS:c,BYTES:a,MASK:we(c),ZERO:be,ONE:Ee,allowedLengths:s,create:t=>$e(t,e),isValid:t=>{if("bigint"!=typeof t)throw new Error("invalid field element: expected bigint, got "+typeof t);return be<=t&&t<e},is0:e=>e===be,isValidNot0:e=>!d.is0(e)&&d.isValid(e),isOdd:e=>(e&Ee)===Ee,neg:t=>$e(-t,e),eql:(e,t)=>e===t,sqr:t=>$e(t*t,e),add:(t,n)=>$e(t+n,e),sub:(t,n)=>$e(t-n,e),mul:(t,n)=>$e(t*n,e),pow:(e,t)=>function(e,t,n){if(n<be)throw new Error("invalid exponent, negatives unsupported");if(n===be)return e.ONE;if(n===Ee)return t;let r=e.ONE,i=t;for(;n>be;)n&Ee&&(r=e.mul(r,i)),i=e.sqr(i),n>>=Ee;return r}(d,e,t),div:(t,n)=>$e(t*Ne(n,e),e),sqrN:e=>e*e,addN:(e,t)=>e+t,subN:(e,t)=>e-t,mulN:(e,t)=>e*t,inv:t=>Ne(t,e),sqrt:o||(t=>(f||(f=Ce(e)),f(d,t))),toBytes:e=>n?le(e,a):de(e,a),fromBytes:(t,r=!0)=>{if(s){if(!s.includes(t.length)||t.length>a)throw new Error("Field.fromBytes: expected "+s+" bytes, got "+t.length);const e=new Uint8Array(a);e.set(t,n?0:e.length-t.length),t=e}if(t.length!==a)throw new Error("Field.fromBytes: expected "+a+" bytes, got "+t.length);let i=n?fe(t):ae(t);if(u&&(i=$e(i,e)),!r&&!d.isValid(i))throw new Error("invalid field element: outside of range 0..ORDER");return i},invertBatch:e=>Fe(d,e),cmov:(e,t,n)=>n?t:e});return Object.freeze(d)}function Le(e){if("bigint"!=typeof e)throw new Error("field order must be bigint");const t=e.toString(2).length;return Math.ceil(t/8)}function Ve(e){const t=Le(e);return t+Math.ceil(t/2)}function qe(e,t,n=!1){const r=e.length,i=Le(t),o=Ve(t);if(r<16||r<o||r>1024)throw new Error("expected "+o+"-1024 bytes of input, got "+r);const s=$e(n?fe(e):ae(e),t-Ee)+Ee;return n?le(s,i):de(s,i)}
6
+ /*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */const Me=BigInt(0),Ke=BigInt(1);function We(e,t){const n=t.negate();return e?n:t}function Ge(e,t){const n=Fe(e.Fp,t.map(e=>e.Z));return t.map((t,r)=>e.fromAffine(t.toAffine(n[r])))}function Ye(e,t){if(!Number.isSafeInteger(e)||e<=0||e>t)throw new Error("invalid window size, expected [1.."+t+"], got W="+e)}function Xe(e,t){Ye(e,t);const n=2**e;return{windows:Math.ceil(t/e)+1,windowSize:2**(e-1),mask:we(e),maxNumber:n,shiftBy:BigInt(e)}}function Je(e,t,n){const{windowSize:r,mask:i,maxNumber:o,shiftBy:s}=n;let u=Number(e&i),c=e>>s;u>r&&(u-=o,c+=Ke);const a=t*r;return{nextN:c,offset:a+Math.abs(u)-1,isZero:0===u,isNeg:u<0,isNegF:t%2!=0,offsetF:a}}const Qe=new WeakMap,et=new WeakMap;function tt(e){return et.get(e)||1}function nt(e){if(e!==Me)throw new Error("invalid wNAF")}class rt{constructor(e,t){this.BASE=e.BASE,this.ZERO=e.ZERO,this.Fn=e.Fn,this.bits=t}_unsafeLadder(e,t,n=this.ZERO){let r=e;for(;t>Me;)t&Ke&&(n=n.add(r)),r=r.double(),t>>=Ke;return n}precomputeWindow(e,t){const{windows:n,windowSize:r}=Xe(t,this.bits),i=[];let o=e,s=o;for(let e=0;e<n;e++){s=o,i.push(s);for(let e=1;e<r;e++)s=s.add(o),i.push(s);o=s.double()}return i}wNAF(e,t,n){if(!this.Fn.isValid(n))throw new Error("invalid scalar");let r=this.ZERO,i=this.BASE;const o=Xe(e,this.bits);for(let e=0;e<o.windows;e++){const{nextN:s,offset:u,isZero:c,isNeg:a,isNegF:f,offsetF:d}=Je(n,e,o);n=s,c?i=i.add(We(f,t[d])):r=r.add(We(a,t[u]))}return nt(n),{p:r,f:i}}wNAFUnsafe(e,t,n,r=this.ZERO){const i=Xe(e,this.bits);for(let e=0;e<i.windows&&n!==Me;e++){const{nextN:o,offset:s,isZero:u,isNeg:c}=Je(n,e,i);if(n=o,!u){const e=t[s];r=r.add(c?e.negate():e)}}return nt(n),r}getPrecomputes(e,t,n){let r=Qe.get(t);return r||(r=this.precomputeWindow(t,e),1!==e&&("function"==typeof n&&(r=n(r)),Qe.set(t,r))),r}cached(e,t,n){const r=tt(e);return this.wNAF(r,this.getPrecomputes(r,e,n),t)}unsafe(e,t,n,r){const i=tt(e);return 1===i?this._unsafeLadder(e,t,r):this.wNAFUnsafe(i,this.getPrecomputes(i,e,n),t,r)}createCache(e,t){Ye(t,this.bits),et.set(e,t),Qe.delete(e)}hasCache(e){return 1!==tt(e)}}function it(e,t,n,r){!function(e,t){if(!Array.isArray(e))throw new Error("array expected");e.forEach((e,n)=>{if(!(e instanceof t))throw new Error("invalid point at index "+n)})}(n,e),function(e,t){if(!Array.isArray(e))throw new Error("array of scalars expected");e.forEach((e,n)=>{if(!t.isValid(e))throw new Error("invalid scalar at index "+n)})}(r,t);const i=n.length,o=r.length;if(i!==o)throw new Error("arrays of points and scalars must have equal length");const s=e.ZERO,u=_e(BigInt(i));let c=1;u>12?c=u-3:u>4?c=u-2:u>0&&(c=2);const a=we(c),f=new Array(Number(a)+1).fill(s);let d=s;for(let e=Math.floor((t.BITS-1)/c)*c;e>=0;e-=c){f.fill(s);for(let t=0;t<o;t++){const i=r[t],o=Number(i>>BigInt(e)&a);f[o]=f[o].add(n[t])}let t=s;for(let e=f.length-1,n=s;e>0;e--)n=n.add(f[e]),t=t.add(n);if(d=d.add(t),0!==e)for(let e=0;e<c;e++)d=d.double()}return d}function ot(e,t){if(t){if(t.ORDER!==e)throw new Error("Field.ORDER must match order: Fp == p, Fn == n");return function(e){ye(e,je.reduce((e,t)=>(e[t]="function",e),{ORDER:"bigint",MASK:"bigint",BYTES:"number",BITS:"number"}))}(t),t}return De(e)}
7
7
  /*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */
8
- const st=(e,t)=>(e+(e>=0?t:-t)/lt)/t;function ut(e){void 0!==e.lowS&&se("lowS",e.lowS),void 0!==e.prehash&&se("prehash",e.prehash)}class at extends Error{constructor(e=""){super(e)}}const ct={Err:at,_tlv:{encode:(e,t)=>{const{Err:n}=ct;if(e<0||e>256)throw new n("tlv.encode: wrong tag");if(1&t.length)throw new n("tlv.encode: unpadded data");const r=t.length/2,i=ue(r);if(i.length/2&128)throw new n("tlv.encode: long form length too big");const o=r>127?ue(i.length/2|128):"";return ue(e)+o+i+t},decode(e,t){const{Err:n}=ct;let r=0;if(e<0||e>256)throw new n("tlv.encode: wrong tag");if(t.length<2||t[r++]!==e)throw new n("tlv.decode: wrong tlv");const i=t[r++];let o=0;if(!!(128&i)){const e=127&i;if(!e)throw new n("tlv.decode(long): indefinite length not supported");if(e>4)throw new n("tlv.decode(long): byte length is too big");const s=t.subarray(r,r+e);if(s.length!==e)throw new n("tlv.decode: length bytes not complete");if(0===s[0])throw new n("tlv.decode(long): zero leftmost byte");for(const e of s)o=o<<8|e;if(r+=e,o<128)throw new n("tlv.decode(long): not minimal encoding")}else o=i;const s=t.subarray(r,r+o);if(s.length!==o)throw new n("tlv.decode: wrong value length");return{v:s,l:t.subarray(r+o)}}},_int:{encode(e){const{Err:t}=ct;if(e<ft)throw new t("integer: negative integers are not allowed");let n=ue(e);if(8&Number.parseInt(n[0],16)&&(n="00"+n),1&n.length)throw new t("unexpected DER parsing assertion: unpadded hex");return n},decode(e){const{Err:t}=ct;if(128&e[0])throw new t("invalid signature integer: negative");if(0===e[0]&&!(128&e[1]))throw new t("invalid signature integer: unnecessary leading zero");return ce(e)}},toSig(e){const{Err:t,_int:n,_tlv:r}=ct,i=he("signature",e),{v:o,l:s}=r.decode(48,i);if(s.length)throw new t("invalid signature: left bytes after parsing");const{v:u,l:a}=r.decode(2,o),{v:c,l:f}=r.decode(2,a);if(f.length)throw new t("invalid signature: left bytes after parsing");return{r:n.decode(u),s:n.decode(c)}},hexFromSig(e){const{_tlv:t,_int:n}=ct,r=t.encode(2,n.encode(e.r))+t.encode(2,n.encode(e.s));return t.encode(48,r)}},ft=BigInt(0),dt=BigInt(1),lt=BigInt(2),ht=BigInt(3),pt=BigInt(4);function mt(e,t){const{BYTES:n}=e;let r;if("bigint"==typeof t)r=t;else{let i=he("private key",t);try{r=e.fromBytes(i)}catch(e){throw new Error(`invalid private key: expected ui8a of size ${n}, got ${typeof t}`)}}if(!e.isValidNot0(r))throw new Error("invalid private key: out of range [1..N-1]");return r}function gt(e,t={}){const{Fp:n,Fn:r}=function(e,t,n={}){if(!t||"object"!=typeof t)throw new Error(`expected valid ${e} CURVE object`);for(const e of["p","n","h"]){const n=t[e];if(!("bigint"==typeof n&&n>Me))throw new Error(`CURVE.${e} must be positive bigint`)}const r=ot(t.p,n.Fp),i=ot(t.n,n.Fn),o=["Gx","Gy","a","b"];for(const e of o)if(!r.isValid(t[e]))throw new Error(`CURVE.${e} must be valid field element of CURVE.Fp`);return{Fp:r,Fn:i}}("weierstrass",e,t),{h:i,n:o}=e;ye(t,{},{allowInfinityPoint:"boolean",clearCofactor:"function",isTorsionFree:"function",fromBytes:"function",toBytes:"function",endo:"object",wrapPrivateKey:"boolean"});const{endo:s}=t;if(s&&(!n.is0(e.a)||"bigint"!=typeof s.beta||!Array.isArray(s.basises)))throw new Error('invalid endo: expected "beta": bigint and "basises": array');function u(){if(!n.isOdd)throw new Error("compression is not supported: Field does not have .isOdd()")}const a=t.toBytes||function(e,t,r){const{x:i,y:o}=t.toAffine(),s=n.toBytes(i);if(se("isCompressed",r),r){u();return V(wt(!n.isOdd(o)),s)}return V(Uint8Array.of(4),s,n.toBytes(o))},c=t.fromBytes||function(e){k(e);const t=n.BYTES,r=t+1,i=2*t+1,o=e.length,s=e[0],a=e.subarray(1);if(o!==r||2!==s&&3!==s){if(o===i&&4===s){const e=n.fromBytes(a.subarray(0*t,1*t)),r=n.fromBytes(a.subarray(1*t,2*t));if(!d(e,r))throw new Error("bad point: is not on curve");return{x:e,y:r}}throw new Error(`bad point: got length ${o}, expected compressed=${r} or uncompressed=${i}`)}{const e=n.fromBytes(a);if(!n.isValid(e))throw new Error("bad point: is not on curve, wrong x");const t=f(e);let r;try{r=n.sqrt(t)}catch(e){const t=e instanceof Error?": "+e.message:"";throw new Error("bad point: is not on curve, sqrt error"+t)}u();return!(1&~s)!==n.isOdd(r)&&(r=n.neg(r)),{x:e,y:r}}},f=function(e,t,n){return function(r){const i=e.sqr(r),o=e.mul(i,r);return e.add(e.add(o,e.mul(r,t)),n)}}(n,e.a,e.b);function d(e,t){const r=n.sqr(t),i=f(e);return n.eql(r,i)}if(!d(e.Gx,e.Gy))throw new Error("bad curve params: generator point");const l=n.mul(n.pow(e.a,ht),pt),h=n.mul(n.sqr(e.b),BigInt(27));if(n.is0(n.add(l,h)))throw new Error("bad curve params: a or b");function p(e,t,r=!1){if(!n.isValid(t)||r&&n.is0(t))throw new Error(`bad point coordinate ${e}`);return t}function m(e){if(!(e instanceof v))throw new Error("ProjectivePoint expected")}function g(e){if(!s||!s.basises)throw new Error("no endo");return function(e,t,n){const[[r,i],[o,s]]=t,u=st(s*e,n),a=st(-i*e,n);let c=e-u*r-a*o,f=-u*i-a*s;const d=c<ft,l=f<ft;d&&(c=-c),l&&(f=-f);const h=_e(Math.ceil(we(n)/2))+dt;if(c<ft||c>=h||f<ft||f>=h)throw new Error("splitScalar (endomorphism): failed, k="+e);return{k1neg:d,k1:c,k2neg:l,k2:f}}(e,s.basises,r.ORDER)}const w=ve((e,t)=>{const{X:r,Y:i,Z:o}=e;if(n.eql(o,n.ONE))return{x:r,y:i};const s=e.is0();null==t&&(t=s?n.ONE:n.inv(o));const u=n.mul(r,t),a=n.mul(i,t),c=n.mul(o,t);if(s)return{x:n.ZERO,y:n.ZERO};if(!n.eql(c,n.ONE))throw new Error("invZ was invalid");return{x:u,y:a}}),_=ve(e=>{if(e.is0()){if(t.allowInfinityPoint&&!n.is0(e.Y))return;throw new Error("bad point: ZERO")}const{x:r,y:i}=e.toAffine();if(!n.isValid(r)||!n.isValid(i))throw new Error("bad point: x or y not field elements");if(!d(r,i))throw new Error("bad point: equation left != right");if(!e.isTorsionFree())throw new Error("bad point: not in prime-order subgroup");return!0});function y(e,t,r,i,o){return r=new v(n.mul(r.X,e),r.Y,r.Z),t=Ge(i,t),r=Ge(o,r),t.add(r)}class v{constructor(e,t,n){this.X=p("x",e),this.Y=p("y",t,!0),this.Z=p("z",n),Object.freeze(this)}static fromAffine(e){const{x:t,y:r}=e||{};if(!e||!n.isValid(t)||!n.isValid(r))throw new Error("invalid affine point");if(e instanceof v)throw new Error("projective point not allowed");return n.is0(t)&&n.is0(r)?v.ZERO:new v(t,r,n.ONE)}get x(){return this.toAffine().x}get y(){return this.toAffine().y}get px(){return this.X}get py(){return this.X}get pz(){return this.Z}static normalizeZ(e){return We(v,e)}static fromBytes(e){return k(e),v.fromHex(e)}static fromHex(e){const t=v.fromAffine(c(he("pointHex",e)));return t.assertValidity(),t}static fromPrivateKey(e){return v.BASE.multiply(mt(r,e))}static msm(e,t){return it(v,r,e,t)}_setWindowSize(e){this.precompute(e)}precompute(e=8,t=!0){return E.createCache(this,e),t||this.multiply(ht),this}assertValidity(){_(this)}hasEvenY(){const{y:e}=this.toAffine();if(!n.isOdd)throw new Error("Field doesn't support isOdd");return!n.isOdd(e)}equals(e){m(e);const{X:t,Y:r,Z:i}=this,{X:o,Y:s,Z:u}=e,a=n.eql(n.mul(t,u),n.mul(o,i)),c=n.eql(n.mul(r,u),n.mul(s,i));return a&&c}negate(){return new v(this.X,n.neg(this.Y),this.Z)}double(){const{a:t,b:r}=e,i=n.mul(r,ht),{X:o,Y:s,Z:u}=this;let a=n.ZERO,c=n.ZERO,f=n.ZERO,d=n.mul(o,o),l=n.mul(s,s),h=n.mul(u,u),p=n.mul(o,s);return p=n.add(p,p),f=n.mul(o,u),f=n.add(f,f),a=n.mul(t,f),c=n.mul(i,h),c=n.add(a,c),a=n.sub(l,c),c=n.add(l,c),c=n.mul(a,c),a=n.mul(p,a),f=n.mul(i,f),h=n.mul(t,h),p=n.sub(d,h),p=n.mul(t,p),p=n.add(p,f),f=n.add(d,d),d=n.add(f,d),d=n.add(d,h),d=n.mul(d,p),c=n.add(c,d),h=n.mul(s,u),h=n.add(h,h),d=n.mul(h,p),a=n.sub(a,d),f=n.mul(h,l),f=n.add(f,f),f=n.add(f,f),new v(a,c,f)}add(t){m(t);const{X:r,Y:i,Z:o}=this,{X:s,Y:u,Z:a}=t;let c=n.ZERO,f=n.ZERO,d=n.ZERO;const l=e.a,h=n.mul(e.b,ht);let p=n.mul(r,s),g=n.mul(i,u),w=n.mul(o,a),_=n.add(r,i),y=n.add(s,u);_=n.mul(_,y),y=n.add(p,g),_=n.sub(_,y),y=n.add(r,o);let b=n.add(s,a);return y=n.mul(y,b),b=n.add(p,w),y=n.sub(y,b),b=n.add(i,o),c=n.add(u,a),b=n.mul(b,c),c=n.add(g,w),b=n.sub(b,c),d=n.mul(l,y),c=n.mul(h,w),d=n.add(c,d),c=n.sub(g,d),d=n.add(g,d),f=n.mul(c,d),g=n.add(p,p),g=n.add(g,p),w=n.mul(l,w),y=n.mul(h,y),g=n.add(g,w),w=n.sub(p,w),w=n.mul(l,w),y=n.add(y,w),p=n.mul(g,y),f=n.add(f,p),p=n.mul(b,y),c=n.mul(_,c),c=n.sub(c,p),p=n.mul(_,g),d=n.mul(b,d),d=n.add(d,p),new v(c,f,d)}subtract(e){return this.add(e.negate())}is0(){return this.equals(v.ZERO)}multiply(e){const{endo:n}=t;if(!r.isValidNot0(e))throw new Error("invalid scalar: out of range");let i,o;const s=e=>E.cached(this,e,e=>We(v,e));if(n){const{k1neg:t,k1:r,k2neg:u,k2:a}=g(e),{p:c,f:f}=s(r),{p:d,f:l}=s(a);o=f.add(l),i=y(n.beta,c,d,t,u)}else{const{p:t,f:n}=s(e);i=t,o=n}return We(v,[i,o])[0]}multiplyUnsafe(e){const{endo:n}=t,i=this;if(!r.isValid(e))throw new Error("invalid scalar: out of range");if(e===ft||i.is0())return v.ZERO;if(e===dt)return i;if(E.hasCache(this))return this.multiply(e);if(n){const{k1neg:t,k1:r,k2neg:o,k2:s}=g(e),{p1:u,p2:a}=function(e,t,n,r){let i=t,o=e.ZERO,s=e.ZERO;for(;n>Me||r>Me;)n&Ke&&(o=o.add(i)),r&Ke&&(s=s.add(i)),i=i.double(),n>>=Ke,r>>=Ke;return{p1:o,p2:s}}(v,i,r,s);return y(n.beta,u,a,t,o)}return E.unsafe(i,e)}multiplyAndAddUnsafe(e,t,n){const r=this.multiplyUnsafe(t).add(e.multiplyUnsafe(n));return r.is0()?void 0:r}toAffine(e){return w(this,e)}isTorsionFree(){const{isTorsionFree:e}=t;return i===dt||(e?e(v,this):E.unsafe(this,o).is0())}clearCofactor(){const{clearCofactor:e}=t;return i===dt?this:e?e(v,this):this.multiplyUnsafe(i)}isSmallOrder(){return this.multiplyUnsafe(i).is0()}toBytes(e=!0){return se("isCompressed",e),this.assertValidity(),a(v,this,e)}toRawBytes(e=!0){return this.toBytes(e)}toHex(e=!0){return B(this.toBytes(e))}toString(){return`<Point ${this.is0()?"ZERO":this.toHex()}>`}}v.BASE=new v(e.Gx,e.Gy,n.ONE),v.ZERO=new v(n.ZERO,n.ONE,n.ZERO),v.Fp=n,v.Fn=r;const b=r.BITS,E=new rt(v,t.endo?Math.ceil(b/2):b);return v}function wt(e){return Uint8Array.of(e?2:3)}function _t(e,t,n={}){O(t),ye(n,{},{hmac:"function",lowS:"boolean",randomBytes:"function",bits2int:"function",bits2int_modN:"function"});const r=n.randomBytes||K,i=n.hmac||((e,...n)=>re(t,e,V(...n))),{Fp:o,Fn:s}=e,{ORDER:u,BITS:a}=s,c=Ve(u),f={secret:s.BYTES,public:1+o.BYTES,publicUncompressed:1+2*o.BYTES,signature:2*s.BYTES,seed:c};function d(e){return e>u>>dt}function l(e,t){if(!s.isValidNot0(t))throw new Error(`invalid signature ${e}: out of range 1..CURVE.n`)}class h{constructor(e,t,n){l("r",e),l("s",t),this.r=e,this.s=t,null!=n&&(this.recovery=n),Object.freeze(this)}static fromBytes(e,t="compact"){if("compact"===t){const t=s.BYTES;k(e,2*t);const n=e.subarray(0,t),r=e.subarray(t,2*t);return new h(s.fromBytes(n),s.fromBytes(r))}if("der"===t){k(e);const{r:t,s:n}=ct.toSig(e);return new h(t,n)}throw new Error("invalid format")}static fromHex(e,t){return this.fromBytes(L(e),t)}addRecoveryBit(e){return new h(this.r,this.s,e)}recoverPublicKey(t){const n=o.ORDER,{r:r,s:i,recovery:a}=this;if(null==a||![0,1,2,3].includes(a))throw new Error("recovery id invalid");if(u*lt<n&&a>1)throw new Error("recovery id is ambiguous for h>1 curve");const c=2===a||3===a?r+u:r;if(!o.isValid(c))throw new Error("recovery id 2 or 3 invalid");const f=o.toBytes(c),d=e.fromHex(V(wt(!(1&a)),f)),l=s.inv(c),h=v(he("msgHash",t)),p=s.create(-h*l),m=s.create(i*l),g=e.BASE.multiplyUnsafe(p).add(d.multiplyUnsafe(m));if(g.is0())throw new Error("point at infinify");return g.assertValidity(),g}hasHighS(){return d(this.s)}normalizeS(){return this.hasHighS()?new h(this.r,s.neg(this.s),this.recovery):this}toBytes(e="compact"){if("compact"===e)return V(s.toBytes(this.r),s.toBytes(this.s));if("der"===e)return L(ct.hexFromSig(this));throw new Error("invalid format")}toHex(e){return B(this.toBytes(e))}assertValidity(){}static fromCompact(e){return h.fromBytes(he("sig",e),"compact")}static fromDER(e){return h.fromBytes(he("sig",e),"der")}toDERRawBytes(){return this.toBytes("der")}toDERHex(){return B(this.toBytes("der"))}toCompactRawBytes(){return this.toBytes("compact")}toCompactHex(){return B(this.toBytes("compact"))}}function p(e){try{return!!mt(s,e)}catch(e){return!1}}function m(e=r(c)){return qe(e,u)}const g={isValidSecretKey:p,isValidPublicKey:function(t,n){try{const r=t.length;return(!0!==n||r===f.public)&&((!1!==n||r===f.publicUncompressed)&&!!e.fromBytes(t))}catch(e){return!1}},randomSecretKey:m,isValidPrivateKey:p,randomPrivateKey:m,normPrivateKeyToScalar:e=>mt(s,e),precompute:(t=8,n=e.BASE)=>n.precompute(t,!1)};function w(t,n=!0){return e.BASE.multiply(mt(s,t)).toBytes(n)}function _(t){if("bigint"==typeof t)return!1;if(t instanceof e)return!0;if(s.allowedLengths||f.secret===f.public)return;const n=he("key",t).length;return n===f.public||n===f.publicUncompressed}const y=n.bits2int||function(e){if(e.length>8192)throw new Error("input is too large");const t=ce(e),n=8*e.length-a;return n>0?t>>BigInt(n):t},v=n.bits2int_modN||function(e){return s.create(y(e))},b=_e(a);function E(e){return ge("num < 2^"+a,e,ft,b),s.toBytes(e)}function z(n,i,o=A){if(["recovered","canonical"].some(e=>e in o))throw new Error("sign() legacy options not supported");let{lowS:u,prehash:a,extraEntropy:c}=o;null==u&&(u=!0),n=he("msgHash",n),ut(o),a&&(n=he("prehashed msgHash",t(n)));const l=v(n),p=mt(s,i),m=[E(p),E(l)];if(null!=c&&!1!==c){const e=!0===c?r(f.secret):c;m.push(he("extraEntropy",e))}const g=V(...m),w=l;return{seed:g,k2sig:function(t){const n=y(t);if(!s.isValidNot0(n))return;const r=s.inv(n),i=e.BASE.multiply(n).toAffine(),o=s.create(i.x);if(o===ft)return;const a=s.create(r*s.create(w+o*p));if(a===ft)return;let c=(i.x===o?0:2)|Number(i.y&dt),f=a;return u&&d(a)&&(f=function(e){return d(e)?s.neg(e):e}(a),c^=1),new h(o,f,c)}}}const A={lowS:n.lowS,prehash:!1},S={lowS:n.lowS,prehash:!1};return e.BASE.precompute(8),Object.freeze({keygen:function(e){const t=g.randomSecretKey(e);return{secretKey:t,publicKey:w(t)}},getPublicKey:w,sign:function(e,n,r=A){const{seed:o,k2sig:u}=z(e,n,r);return function(e,t,n){if("number"!=typeof e||e<2)throw new Error("hashLen must be a number");if("number"!=typeof t||t<2)throw new Error("qByteLen must be a number");if("function"!=typeof n)throw new Error("hmacFn must be a function");const r=e=>new Uint8Array(e),i=e=>Uint8Array.of(e);let o=r(e),s=r(e),u=0;const a=()=>{o.fill(1),s.fill(0),u=0},c=(...e)=>n(s,o,...e),f=(e=r(0))=>{s=c(i(0),e),o=c(),0!==e.length&&(s=c(i(1),e),o=c())},d=()=>{if(u++>=1e3)throw new Error("drbg: tried 1000 values");let e=0;const n=[];for(;e<t;){o=c();const t=o.slice();n.push(t),e+=o.length}return V(...n)};return(e,t)=>{let n;for(a(),f(e);!(n=t(d()));)f();return a(),n}}(t.outputLen,s.BYTES,i)(o,u)},verify:function(n,r,i,o=S){const u=n;r=he("msgHash",r),i=he("publicKey",i),ut(o);const{lowS:a,prehash:c,format:f}=o;if("strict"in o)throw new Error("options.strict was renamed to lowS");let d,l;if(void 0===f){const e="string"==typeof u||x(u),t=!e&&null!==u&&"object"==typeof u&&"bigint"==typeof u.r&&"bigint"==typeof u.s;if(!e&&!t)throw new Error("invalid signature, expected Uint8Array, hex string or Signature instance");if(t)d=new h(u.r,u.s);else if(e){try{d=h.fromDER(u)}catch(e){if(!(e instanceof ct.Err))throw e}if(!d)try{d=h.fromCompact(u)}catch(e){return!1}}}else if("compact"===f||"der"===f){if("string"!=typeof u&&!x(u))throw new Error('"der" / "compact" format expects Uint8Array signature');d=h.fromBytes(he("sig",u),f)}else{if("js"!==f)throw new Error('format must be "compact", "der" or "js"');if(!(u instanceof h))throw new Error('"js" format expects Signature instance');d=u}if(!d)return!1;try{if(l=e.fromHex(i),a&&d.hasHighS())return!1;c&&(r=t(r));const{r:n,s:o}=d,u=v(r),f=s.inv(o),h=s.create(u*f),p=s.create(n*f),m=e.BASE.multiplyUnsafe(h).add(l.multiplyUnsafe(p));if(m.is0())return!1;return s.create(m.x)===n}catch(e){return!1}},getSharedSecret:function(t,n,r=!0){if(!0===_(t))throw new Error("first arg must be private key");if(!1===_(n))throw new Error("second arg must be public key");const i=mt(s,t);return e.fromHex(n).multiply(i).toBytes(r)},utils:g,Point:e,Signature:h,info:{type:"weierstrass",lengths:f,publicKeyHasPrefix:!0}})}function yt(e){const{CURVE:t,curveOpts:n}=function(e){const t={a:e.a,b:e.b,p:e.Fp.ORDER,n:e.n,h:e.h,Gx:e.Gx,Gy:e.Gy},n=e.Fp;let r=e.allowedPrivateKeyLengths?Array.from(new Set(e.allowedPrivateKeyLengths.map(e=>Math.ceil(e/2)))):void 0;return{CURVE:t,curveOpts:{Fp:n,Fn:Le(t.n,{BITS:e.nBitLength,allowedLengths:r,modOnDecode:e.wrapPrivateKey}),allowInfinityPoint:e.allowInfinityPoint,endo:e.endo,isTorsionFree:e.isTorsionFree,clearCofactor:e.clearCofactor,fromBytes:e.fromBytes,toBytes:e.toBytes}}}(e),r={hmac:e.hmac,randomBytes:e.randomBytes,lowS:e.lowS,bits2int:e.bits2int,bits2int_modN:e.bits2int_modN};return{CURVE:t,curveOpts:n,hash:e.hash,ecdsaOpts:r}}function vt(e){const{CURVE:t,curveOpts:n,hash:r,ecdsaOpts:i}=yt(e);return function(e,t){return Object.assign({},t,{ProjectivePoint:t.Point,CURVE:e})}(e,_t(gt(t,n),r,i))}
8
+ const st=(e,t)=>(e+(e>=0?t:-t)/lt)/t;function ut(e){void 0!==e.lowS&&se("lowS",e.lowS),void 0!==e.prehash&&se("prehash",e.prehash)}class ct extends Error{constructor(e=""){super(e)}}const at={Err:ct,_tlv:{encode:(e,t)=>{const{Err:n}=at;if(e<0||e>256)throw new n("tlv.encode: wrong tag");if(1&t.length)throw new n("tlv.encode: unpadded data");const r=t.length/2,i=ue(r);if(i.length/2&128)throw new n("tlv.encode: long form length too big");const o=r>127?ue(i.length/2|128):"";return ue(e)+o+i+t},decode(e,t){const{Err:n}=at;let r=0;if(e<0||e>256)throw new n("tlv.encode: wrong tag");if(t.length<2||t[r++]!==e)throw new n("tlv.decode: wrong tlv");const i=t[r++];let o=0;if(!!(128&i)){const e=127&i;if(!e)throw new n("tlv.decode(long): indefinite length not supported");if(e>4)throw new n("tlv.decode(long): byte length is too big");const s=t.subarray(r,r+e);if(s.length!==e)throw new n("tlv.decode: length bytes not complete");if(0===s[0])throw new n("tlv.decode(long): zero leftmost byte");for(const e of s)o=o<<8|e;if(r+=e,o<128)throw new n("tlv.decode(long): not minimal encoding")}else o=i;const s=t.subarray(r,r+o);if(s.length!==o)throw new n("tlv.decode: wrong value length");return{v:s,l:t.subarray(r+o)}}},_int:{encode(e){const{Err:t}=at;if(e<ft)throw new t("integer: negative integers are not allowed");let n=ue(e);if(8&Number.parseInt(n[0],16)&&(n="00"+n),1&n.length)throw new t("unexpected DER parsing assertion: unpadded hex");return n},decode(e){const{Err:t}=at;if(128&e[0])throw new t("invalid signature integer: negative");if(0===e[0]&&!(128&e[1]))throw new t("invalid signature integer: unnecessary leading zero");return ae(e)}},toSig(e){const{Err:t,_int:n,_tlv:r}=at,i=he("signature",e),{v:o,l:s}=r.decode(48,i);if(s.length)throw new t("invalid signature: left bytes after parsing");const{v:u,l:c}=r.decode(2,o),{v:a,l:f}=r.decode(2,c);if(f.length)throw new t("invalid signature: left bytes after parsing");return{r:n.decode(u),s:n.decode(a)}},hexFromSig(e){const{_tlv:t,_int:n}=at,r=t.encode(2,n.encode(e.r))+t.encode(2,n.encode(e.s));return t.encode(48,r)}},ft=BigInt(0),dt=BigInt(1),lt=BigInt(2),ht=BigInt(3),pt=BigInt(4);function mt(e,t){const{BYTES:n}=e;let r;if("bigint"==typeof t)r=t;else{let i=he("private key",t);try{r=e.fromBytes(i)}catch(e){throw new Error(`invalid private key: expected ui8a of size ${n}, got ${typeof t}`)}}if(!e.isValidNot0(r))throw new Error("invalid private key: out of range [1..N-1]");return r}function gt(e,t={}){const{Fp:n,Fn:r}=function(e,t,n={}){if(!t||"object"!=typeof t)throw new Error(`expected valid ${e} CURVE object`);for(const e of["p","n","h"]){const n=t[e];if(!("bigint"==typeof n&&n>Me))throw new Error(`CURVE.${e} must be positive bigint`)}const r=ot(t.p,n.Fp),i=ot(t.n,n.Fn),o=["Gx","Gy","a","b"];for(const e of o)if(!r.isValid(t[e]))throw new Error(`CURVE.${e} must be valid field element of CURVE.Fp`);return{Fp:r,Fn:i}}("weierstrass",e,t),{h:i,n:o}=e;ye(t,{},{allowInfinityPoint:"boolean",clearCofactor:"function",isTorsionFree:"function",fromBytes:"function",toBytes:"function",endo:"object",wrapPrivateKey:"boolean"});const{endo:s}=t;if(s&&(!n.is0(e.a)||"bigint"!=typeof s.beta||!Array.isArray(s.basises)))throw new Error('invalid endo: expected "beta": bigint and "basises": array');function u(){if(!n.isOdd)throw new Error("compression is not supported: Field does not have .isOdd()")}const c=t.toBytes||function(e,t,r){const{x:i,y:o}=t.toAffine(),s=n.toBytes(i);if(se("isCompressed",r),r){u();return V(_t(!n.isOdd(o)),s)}return V(Uint8Array.of(4),s,n.toBytes(o))},a=t.fromBytes||function(e){k(e);const t=n.BYTES,r=t+1,i=2*t+1,o=e.length,s=e[0],c=e.subarray(1);if(o!==r||2!==s&&3!==s){if(o===i&&4===s){const e=n.fromBytes(c.subarray(0*t,1*t)),r=n.fromBytes(c.subarray(1*t,2*t));if(!d(e,r))throw new Error("bad point: is not on curve");return{x:e,y:r}}throw new Error(`bad point: got length ${o}, expected compressed=${r} or uncompressed=${i}`)}{const e=n.fromBytes(c);if(!n.isValid(e))throw new Error("bad point: is not on curve, wrong x");const t=f(e);let r;try{r=n.sqrt(t)}catch(e){const t=e instanceof Error?": "+e.message:"";throw new Error("bad point: is not on curve, sqrt error"+t)}u();return!(1&~s)!==n.isOdd(r)&&(r=n.neg(r)),{x:e,y:r}}},f=function(e,t,n){return function(r){const i=e.sqr(r),o=e.mul(i,r);return e.add(e.add(o,e.mul(r,t)),n)}}(n,e.a,e.b);function d(e,t){const r=n.sqr(t),i=f(e);return n.eql(r,i)}if(!d(e.Gx,e.Gy))throw new Error("bad curve params: generator point");const l=n.mul(n.pow(e.a,ht),pt),h=n.mul(n.sqr(e.b),BigInt(27));if(n.is0(n.add(l,h)))throw new Error("bad curve params: a or b");function p(e,t,r=!1){if(!n.isValid(t)||r&&n.is0(t))throw new Error(`bad point coordinate ${e}`);return t}function m(e){if(!(e instanceof v))throw new Error("ProjectivePoint expected")}function g(e){if(!s||!s.basises)throw new Error("no endo");return function(e,t,n){const[[r,i],[o,s]]=t,u=st(s*e,n),c=st(-i*e,n);let a=e-u*r-c*o,f=-u*i-c*s;const d=a<ft,l=f<ft;d&&(a=-a),l&&(f=-f);const h=we(Math.ceil(_e(n)/2))+dt;if(a<ft||a>=h||f<ft||f>=h)throw new Error("splitScalar (endomorphism): failed, k="+e);return{k1neg:d,k1:a,k2neg:l,k2:f}}(e,s.basises,r.ORDER)}const _=ve((e,t)=>{const{X:r,Y:i,Z:o}=e;if(n.eql(o,n.ONE))return{x:r,y:i};const s=e.is0();null==t&&(t=s?n.ONE:n.inv(o));const u=n.mul(r,t),c=n.mul(i,t),a=n.mul(o,t);if(s)return{x:n.ZERO,y:n.ZERO};if(!n.eql(a,n.ONE))throw new Error("invZ was invalid");return{x:u,y:c}}),w=ve(e=>{if(e.is0()){if(t.allowInfinityPoint&&!n.is0(e.Y))return;throw new Error("bad point: ZERO")}const{x:r,y:i}=e.toAffine();if(!n.isValid(r)||!n.isValid(i))throw new Error("bad point: x or y not field elements");if(!d(r,i))throw new Error("bad point: equation left != right");if(!e.isTorsionFree())throw new Error("bad point: not in prime-order subgroup");return!0});function y(e,t,r,i,o){return r=new v(n.mul(r.X,e),r.Y,r.Z),t=We(i,t),r=We(o,r),t.add(r)}class v{constructor(e,t,n){this.X=p("x",e),this.Y=p("y",t,!0),this.Z=p("z",n),Object.freeze(this)}static fromAffine(e){const{x:t,y:r}=e||{};if(!e||!n.isValid(t)||!n.isValid(r))throw new Error("invalid affine point");if(e instanceof v)throw new Error("projective point not allowed");return n.is0(t)&&n.is0(r)?v.ZERO:new v(t,r,n.ONE)}get x(){return this.toAffine().x}get y(){return this.toAffine().y}get px(){return this.X}get py(){return this.X}get pz(){return this.Z}static normalizeZ(e){return Ge(v,e)}static fromBytes(e){return k(e),v.fromHex(e)}static fromHex(e){const t=v.fromAffine(a(he("pointHex",e)));return t.assertValidity(),t}static fromPrivateKey(e){return v.BASE.multiply(mt(r,e))}static msm(e,t){return it(v,r,e,t)}_setWindowSize(e){this.precompute(e)}precompute(e=8,t=!0){return E.createCache(this,e),t||this.multiply(ht),this}assertValidity(){w(this)}hasEvenY(){const{y:e}=this.toAffine();if(!n.isOdd)throw new Error("Field doesn't support isOdd");return!n.isOdd(e)}equals(e){m(e);const{X:t,Y:r,Z:i}=this,{X:o,Y:s,Z:u}=e,c=n.eql(n.mul(t,u),n.mul(o,i)),a=n.eql(n.mul(r,u),n.mul(s,i));return c&&a}negate(){return new v(this.X,n.neg(this.Y),this.Z)}double(){const{a:t,b:r}=e,i=n.mul(r,ht),{X:o,Y:s,Z:u}=this;let c=n.ZERO,a=n.ZERO,f=n.ZERO,d=n.mul(o,o),l=n.mul(s,s),h=n.mul(u,u),p=n.mul(o,s);return p=n.add(p,p),f=n.mul(o,u),f=n.add(f,f),c=n.mul(t,f),a=n.mul(i,h),a=n.add(c,a),c=n.sub(l,a),a=n.add(l,a),a=n.mul(c,a),c=n.mul(p,c),f=n.mul(i,f),h=n.mul(t,h),p=n.sub(d,h),p=n.mul(t,p),p=n.add(p,f),f=n.add(d,d),d=n.add(f,d),d=n.add(d,h),d=n.mul(d,p),a=n.add(a,d),h=n.mul(s,u),h=n.add(h,h),d=n.mul(h,p),c=n.sub(c,d),f=n.mul(h,l),f=n.add(f,f),f=n.add(f,f),new v(c,a,f)}add(t){m(t);const{X:r,Y:i,Z:o}=this,{X:s,Y:u,Z:c}=t;let a=n.ZERO,f=n.ZERO,d=n.ZERO;const l=e.a,h=n.mul(e.b,ht);let p=n.mul(r,s),g=n.mul(i,u),_=n.mul(o,c),w=n.add(r,i),y=n.add(s,u);w=n.mul(w,y),y=n.add(p,g),w=n.sub(w,y),y=n.add(r,o);let b=n.add(s,c);return y=n.mul(y,b),b=n.add(p,_),y=n.sub(y,b),b=n.add(i,o),a=n.add(u,c),b=n.mul(b,a),a=n.add(g,_),b=n.sub(b,a),d=n.mul(l,y),a=n.mul(h,_),d=n.add(a,d),a=n.sub(g,d),d=n.add(g,d),f=n.mul(a,d),g=n.add(p,p),g=n.add(g,p),_=n.mul(l,_),y=n.mul(h,y),g=n.add(g,_),_=n.sub(p,_),_=n.mul(l,_),y=n.add(y,_),p=n.mul(g,y),f=n.add(f,p),p=n.mul(b,y),a=n.mul(w,a),a=n.sub(a,p),p=n.mul(w,g),d=n.mul(b,d),d=n.add(d,p),new v(a,f,d)}subtract(e){return this.add(e.negate())}is0(){return this.equals(v.ZERO)}multiply(e){const{endo:n}=t;if(!r.isValidNot0(e))throw new Error("invalid scalar: out of range");let i,o;const s=e=>E.cached(this,e,e=>Ge(v,e));if(n){const{k1neg:t,k1:r,k2neg:u,k2:c}=g(e),{p:a,f:f}=s(r),{p:d,f:l}=s(c);o=f.add(l),i=y(n.beta,a,d,t,u)}else{const{p:t,f:n}=s(e);i=t,o=n}return Ge(v,[i,o])[0]}multiplyUnsafe(e){const{endo:n}=t,i=this;if(!r.isValid(e))throw new Error("invalid scalar: out of range");if(e===ft||i.is0())return v.ZERO;if(e===dt)return i;if(E.hasCache(this))return this.multiply(e);if(n){const{k1neg:t,k1:r,k2neg:o,k2:s}=g(e),{p1:u,p2:c}=function(e,t,n,r){let i=t,o=e.ZERO,s=e.ZERO;for(;n>Me||r>Me;)n&Ke&&(o=o.add(i)),r&Ke&&(s=s.add(i)),i=i.double(),n>>=Ke,r>>=Ke;return{p1:o,p2:s}}(v,i,r,s);return y(n.beta,u,c,t,o)}return E.unsafe(i,e)}multiplyAndAddUnsafe(e,t,n){const r=this.multiplyUnsafe(t).add(e.multiplyUnsafe(n));return r.is0()?void 0:r}toAffine(e){return _(this,e)}isTorsionFree(){const{isTorsionFree:e}=t;return i===dt||(e?e(v,this):E.unsafe(this,o).is0())}clearCofactor(){const{clearCofactor:e}=t;return i===dt?this:e?e(v,this):this.multiplyUnsafe(i)}isSmallOrder(){return this.multiplyUnsafe(i).is0()}toBytes(e=!0){return se("isCompressed",e),this.assertValidity(),c(v,this,e)}toRawBytes(e=!0){return this.toBytes(e)}toHex(e=!0){return B(this.toBytes(e))}toString(){return`<Point ${this.is0()?"ZERO":this.toHex()}>`}}v.BASE=new v(e.Gx,e.Gy,n.ONE),v.ZERO=new v(n.ZERO,n.ONE,n.ZERO),v.Fp=n,v.Fn=r;const b=r.BITS,E=new rt(v,t.endo?Math.ceil(b/2):b);return v}function _t(e){return Uint8Array.of(e?2:3)}function wt(e,t,n={}){O(t),ye(n,{},{hmac:"function",lowS:"boolean",randomBytes:"function",bits2int:"function",bits2int_modN:"function"});const r=n.randomBytes||K,i=n.hmac||((e,...n)=>re(t,e,V(...n))),{Fp:o,Fn:s}=e,{ORDER:u,BITS:c}=s,a=Ve(u),f={secret:s.BYTES,public:1+o.BYTES,publicUncompressed:1+2*o.BYTES,signature:2*s.BYTES,seed:a};function d(e){return e>u>>dt}function l(e,t){if(!s.isValidNot0(t))throw new Error(`invalid signature ${e}: out of range 1..CURVE.n`)}class h{constructor(e,t,n){l("r",e),l("s",t),this.r=e,this.s=t,null!=n&&(this.recovery=n),Object.freeze(this)}static fromBytes(e,t="compact"){if("compact"===t){const t=s.BYTES;k(e,2*t);const n=e.subarray(0,t),r=e.subarray(t,2*t);return new h(s.fromBytes(n),s.fromBytes(r))}if("der"===t){k(e);const{r:t,s:n}=at.toSig(e);return new h(t,n)}throw new Error("invalid format")}static fromHex(e,t){return this.fromBytes(D(e),t)}addRecoveryBit(e){return new h(this.r,this.s,e)}recoverPublicKey(t){const n=o.ORDER,{r:r,s:i,recovery:c}=this;if(null==c||![0,1,2,3].includes(c))throw new Error("recovery id invalid");if(u*lt<n&&c>1)throw new Error("recovery id is ambiguous for h>1 curve");const a=2===c||3===c?r+u:r;if(!o.isValid(a))throw new Error("recovery id 2 or 3 invalid");const f=o.toBytes(a),d=e.fromHex(V(_t(!(1&c)),f)),l=s.inv(a),h=v(he("msgHash",t)),p=s.create(-h*l),m=s.create(i*l),g=e.BASE.multiplyUnsafe(p).add(d.multiplyUnsafe(m));if(g.is0())throw new Error("point at infinify");return g.assertValidity(),g}hasHighS(){return d(this.s)}normalizeS(){return this.hasHighS()?new h(this.r,s.neg(this.s),this.recovery):this}toBytes(e="compact"){if("compact"===e)return V(s.toBytes(this.r),s.toBytes(this.s));if("der"===e)return D(at.hexFromSig(this));throw new Error("invalid format")}toHex(e){return B(this.toBytes(e))}assertValidity(){}static fromCompact(e){return h.fromBytes(he("sig",e),"compact")}static fromDER(e){return h.fromBytes(he("sig",e),"der")}toDERRawBytes(){return this.toBytes("der")}toDERHex(){return B(this.toBytes("der"))}toCompactRawBytes(){return this.toBytes("compact")}toCompactHex(){return B(this.toBytes("compact"))}}function p(e){try{return!!mt(s,e)}catch(e){return!1}}function m(e=r(a)){return qe(e,u)}const g={isValidSecretKey:p,isValidPublicKey:function(t,n){try{const r=t.length;return(!0!==n||r===f.public)&&((!1!==n||r===f.publicUncompressed)&&!!e.fromBytes(t))}catch(e){return!1}},randomSecretKey:m,isValidPrivateKey:p,randomPrivateKey:m,normPrivateKeyToScalar:e=>mt(s,e),precompute:(t=8,n=e.BASE)=>n.precompute(t,!1)};function _(t,n=!0){return e.BASE.multiply(mt(s,t)).toBytes(n)}function w(t){if("bigint"==typeof t)return!1;if(t instanceof e)return!0;if(s.allowedLengths||f.secret===f.public)return;const n=he("key",t).length;return n===f.public||n===f.publicUncompressed}const y=n.bits2int||function(e){if(e.length>8192)throw new Error("input is too large");const t=ae(e),n=8*e.length-c;return n>0?t>>BigInt(n):t},v=n.bits2int_modN||function(e){return s.create(y(e))},b=we(c);function E(e){return ge("num < 2^"+c,e,ft,b),s.toBytes(e)}function z(n,i,o=P){if(["recovered","canonical"].some(e=>e in o))throw new Error("sign() legacy options not supported");let{lowS:u,prehash:c,extraEntropy:a}=o;null==u&&(u=!0),n=he("msgHash",n),ut(o),c&&(n=he("prehashed msgHash",t(n)));const l=v(n),p=mt(s,i),m=[E(p),E(l)];if(null!=a&&!1!==a){const e=!0===a?r(f.secret):a;m.push(he("extraEntropy",e))}const g=V(...m),_=l;return{seed:g,k2sig:function(t){const n=y(t);if(!s.isValidNot0(n))return;const r=s.inv(n),i=e.BASE.multiply(n).toAffine(),o=s.create(i.x);if(o===ft)return;const c=s.create(r*s.create(_+o*p));if(c===ft)return;let a=(i.x===o?0:2)|Number(i.y&dt),f=c;return u&&d(c)&&(f=function(e){return d(e)?s.neg(e):e}(c),a^=1),new h(o,f,a)}}}const P={lowS:n.lowS,prehash:!1},S={lowS:n.lowS,prehash:!1};return e.BASE.precompute(8),Object.freeze({keygen:function(e){const t=g.randomSecretKey(e);return{secretKey:t,publicKey:_(t)}},getPublicKey:_,sign:function(e,n,r=P){const{seed:o,k2sig:u}=z(e,n,r);return function(e,t,n){if("number"!=typeof e||e<2)throw new Error("hashLen must be a number");if("number"!=typeof t||t<2)throw new Error("qByteLen must be a number");if("function"!=typeof n)throw new Error("hmacFn must be a function");const r=e=>new Uint8Array(e),i=e=>Uint8Array.of(e);let o=r(e),s=r(e),u=0;const c=()=>{o.fill(1),s.fill(0),u=0},a=(...e)=>n(s,o,...e),f=(e=r(0))=>{s=a(i(0),e),o=a(),0!==e.length&&(s=a(i(1),e),o=a())},d=()=>{if(u++>=1e3)throw new Error("drbg: tried 1000 values");let e=0;const n=[];for(;e<t;){o=a();const t=o.slice();n.push(t),e+=o.length}return V(...n)};return(e,t)=>{let n;for(c(),f(e);!(n=t(d()));)f();return c(),n}}(t.outputLen,s.BYTES,i)(o,u)},verify:function(n,r,i,o=S){const u=n;r=he("msgHash",r),i=he("publicKey",i),ut(o);const{lowS:c,prehash:a,format:f}=o;if("strict"in o)throw new Error("options.strict was renamed to lowS");let d,l;if(void 0===f){const e="string"==typeof u||x(u),t=!e&&null!==u&&"object"==typeof u&&"bigint"==typeof u.r&&"bigint"==typeof u.s;if(!e&&!t)throw new Error("invalid signature, expected Uint8Array, hex string or Signature instance");if(t)d=new h(u.r,u.s);else if(e){try{d=h.fromDER(u)}catch(e){if(!(e instanceof at.Err))throw e}if(!d)try{d=h.fromCompact(u)}catch(e){return!1}}}else if("compact"===f||"der"===f){if("string"!=typeof u&&!x(u))throw new Error('"der" / "compact" format expects Uint8Array signature');d=h.fromBytes(he("sig",u),f)}else{if("js"!==f)throw new Error('format must be "compact", "der" or "js"');if(!(u instanceof h))throw new Error('"js" format expects Signature instance');d=u}if(!d)return!1;try{if(l=e.fromHex(i),c&&d.hasHighS())return!1;a&&(r=t(r));const{r:n,s:o}=d,u=v(r),f=s.inv(o),h=s.create(u*f),p=s.create(n*f),m=e.BASE.multiplyUnsafe(h).add(l.multiplyUnsafe(p));if(m.is0())return!1;return s.create(m.x)===n}catch(e){return!1}},getSharedSecret:function(t,n,r=!0){if(!0===w(t))throw new Error("first arg must be private key");if(!1===w(n))throw new Error("second arg must be public key");const i=mt(s,t);return e.fromHex(n).multiply(i).toBytes(r)},utils:g,Point:e,Signature:h,info:{type:"weierstrass",lengths:f,publicKeyHasPrefix:!0}})}function yt(e){const{CURVE:t,curveOpts:n}=function(e){const t={a:e.a,b:e.b,p:e.Fp.ORDER,n:e.n,h:e.h,Gx:e.Gx,Gy:e.Gy},n=e.Fp;let r=e.allowedPrivateKeyLengths?Array.from(new Set(e.allowedPrivateKeyLengths.map(e=>Math.ceil(e/2)))):void 0;return{CURVE:t,curveOpts:{Fp:n,Fn:De(t.n,{BITS:e.nBitLength,allowedLengths:r,modOnDecode:e.wrapPrivateKey}),allowInfinityPoint:e.allowInfinityPoint,endo:e.endo,isTorsionFree:e.isTorsionFree,clearCofactor:e.clearCofactor,fromBytes:e.fromBytes,toBytes:e.toBytes}}}(e),r={hmac:e.hmac,randomBytes:e.randomBytes,lowS:e.lowS,bits2int:e.bits2int,bits2int_modN:e.bits2int_modN};return{CURVE:t,curveOpts:n,hash:e.hash,ecdsaOpts:r}}function vt(e){const{CURVE:t,curveOpts:n,hash:r,ecdsaOpts:i}=yt(e);return function(e,t){return Object.assign({},t,{ProjectivePoint:t.Point,CURVE:e})}(e,wt(gt(t,n),r,i))}
9
9
  /*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */
10
10
  /*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */
11
- const bt={p:BigInt("0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f"),n:BigInt("0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141"),h:BigInt(1),a:BigInt(0),b:BigInt(7),Gx:BigInt("0x79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798"),Gy:BigInt("0x483ada7726a3c4655da4fbfc0e1108a8fd17b448a68554199c47d08ffb10d4b8")},Et={beta:BigInt("0x7ae96a2b657c07106e64479eac3434e99cf0497512f58995c1396c28719501ee"),basises:[[BigInt("0x3086d221a7d46bcde86c90e49284eb15"),-BigInt("0xe4437ed6010e88286f547fa90abfe4c3")],[BigInt("0x114ca50f7a8e2f3f657c1108d9d44cfd8"),BigInt("0x3086d221a7d46bcde86c90e49284eb15")]]},xt=BigInt(0),zt=BigInt(1),kt=BigInt(2);function Ot(e){const t=bt.p,n=BigInt(3),r=BigInt(6),i=BigInt(11),o=BigInt(22),s=BigInt(23),u=BigInt(44),a=BigInt(88),c=e*e*e%t,f=c*c*e%t,d=Te(f,n,t)*f%t,l=Te(d,n,t)*f%t,h=Te(l,kt,t)*c%t,p=Te(h,i,t)*h%t,m=Te(p,o,t)*p%t,g=Te(m,u,t)*m%t,w=Te(g,a,t)*g%t,_=Te(w,u,t)*m%t,y=Te(_,n,t)*f%t,v=Te(y,s,t)*p%t,b=Te(v,r,t)*c%t,E=Te(b,kt,t);if(!At.eql(At.sqr(E),e))throw new Error("Cannot find square root");return E}const At=Le(bt.p,void 0,void 0,{sqrt:Ot}),St=function(e,t){const n=t=>vt({...e,hash:t});return{...n(t),create:n}}({...bt,Fp:At,lowS:!0,endo:Et},te),Pt={};function $t(e,...t){let n=Pt[e];if(void 0===n){const t=te(Uint8Array.from(e,e=>e.charCodeAt(0)));n=V(t,t),Pt[e]=n}return te(V(n,...t))}const It=e=>e.toBytes(!0).slice(1),Tt=e=>de(e,32),Nt=e=>Ie(e,bt.p),Bt=e=>Ie(e,bt.n),Ut=(()=>St.Point)(),Zt=e=>e%kt===xt;function Rt(e){let t=mt(Ut.Fn,e),n=Ut.BASE.multiply(t);return{scalar:Zt(n.y)?t:Bt(-t),bytes:It(n)}}function Ct(e){ge("x",e,zt,bt.p);const t=Nt(e*e);let n=Ot(Nt(t*e+BigInt(7)));Zt(n)||(n=Nt(-n));const r=Ut.fromAffine({x:e,y:n});return r.assertValidity(),r}const jt=ce;function Ft(...e){return Bt(jt($t("BIP0340/challenge",...e)))}function Dt(e){return Rt(e).bytes}function Lt(e,t,n=K(32)){const r=he("message",e),{bytes:i,scalar:o}=Rt(t),s=he("auxRand",n,32),u=Tt(o^jt($t("BIP0340/aux",s))),a=$t("BIP0340/nonce",u,i,r),c=Bt(jt(a));if(c===xt)throw new Error("sign failed: k is zero");const{bytes:f,scalar:d}=Rt(c),l=Ft(f,i,r),h=new Uint8Array(64);if(h.set(f,0),h.set(Tt(Bt(d+l*o)),32),!Ht(h,r,i))throw new Error("sign: Invalid signature produced");return h}function Ht(e,t,n){const r=he("signature",e,64),i=he("message",t),o=he("publicKey",n,32);try{const e=Ct(jt(o)),t=jt(r.subarray(0,32));if(!me(t,zt,bt.p))return!1;const n=jt(r.subarray(32,64));if(!me(n,zt,bt.n))return!1;const s=Ft(Tt(t),It(e),i),u=Ut.BASE.multiplyUnsafe(n).add(e.multiplyUnsafe(Bt(-s))),{x:a,y:c}=u.toAffine();return!(u.is0()||!Zt(c)||a!==t)}catch(e){return!1}}const Vt=(()=>{const e=(e=K(48))=>qe(e,bt.n);return{keygen:function(t){const n=e(t);return{secretKey:n,publicKey:Dt(n)}},getPublicKey:Dt,sign:Lt,verify:Ht,Point:Ut,utils:{randomSecretKey:e,randomPrivateKey:e,taggedHash:$t,lift_x:Ct,pointToBytes:It,numberToBytesBE:de,bytesToNumberBE:ce,mod:Ie},info:{type:"weierstrass",publicKeyHasPrefix:!1,lengths:{secret:32,public:32,signature:64,seed:48}}}})(),qt=BigInt(0),Mt=BigInt(2);Le(St.CURVE.n,32,!0);const Kt=St.Point.BASE;function Gt(e,t,n,r=!1){const i=Yt(t).big,o=function(e){try{const t=Wt(e,"ecdsa");return St.Point.fromHex(t)}catch(t){throw new Error("invalid pubkey: "+e)}}(e),s=Kt.multiply(i);let u=o.add(s);r&&u.y%Mt!==qt&&(u=u.negate());return Wt(u.toHex(!0),n)}function Wt(e,t){try{const n=Yt(e);if(33===n.length&&"bip340"===t)return n.slice(1);if(32===n.length&&"ecdsa"===t){const e=g.num(2,1);return g.join([e,n])}return n}catch(t){throw new Error("invalid pubkey: "+String(e))}}function Yt(e){try{return g.bytes(e)}catch(t){throw new Error("invalid bytes: "+String(e))}}const Xt=Uint8Array.from([7,4,13,1,10,6,15,3,12,0,9,5,2,14,11,8]),Jt=(()=>Uint8Array.from(new Array(16).fill(0).map((e,t)=>t)))(),Qt=(()=>Jt.map(e=>(9*e+5)%16))(),en=(()=>{const e=[[Jt],[Qt]];for(let t=0;t<4;t++)for(let n of e)n.push(n[t].map(e=>Xt[e]));return e})(),tn=(()=>en[0])(),nn=(()=>en[1])(),rn=[[11,14,15,12,5,8,7,9,11,13,14,15,6,7,9,8],[12,13,11,15,6,9,9,7,12,15,11,13,7,8,7,7],[13,15,14,11,7,7,6,8,13,14,13,12,5,5,6,9],[14,11,12,14,8,6,5,5,15,12,15,14,9,9,8,6],[15,12,13,13,9,5,8,6,14,11,12,11,8,6,5,5]].map(e=>Uint8Array.from(e)),on=tn.map((e,t)=>e.map(e=>rn[t][e])),sn=nn.map((e,t)=>e.map(e=>rn[t][e])),un=Uint32Array.from([0,1518500249,1859775393,2400959708,2840853838]),an=Uint32Array.from([1352829926,1548603684,1836072691,2053994217,0]);function cn(e,t,n,r){return 0===e?t^n^r:1===e?t&n|~t&r:2===e?(t|~n)^r:3===e?t&r|n&~r:t^(n|~r)}const fn=new Uint32Array(16);class dn extends Y{constructor(){super(64,20,8,!0),this.h0=1732584193,this.h1=-271733879,this.h2=-1732584194,this.h3=271733878,this.h4=-1009589776}get(){const{h0:e,h1:t,h2:n,h3:r,h4:i}=this;return[e,t,n,r,i]}set(e,t,n,r,i){this.h0=0|e,this.h1=0|t,this.h2=0|n,this.h3=0|r,this.h4=0|i}process(e,t){for(let n=0;n<16;n++,t+=4)fn[n]=e.getUint32(t,!0);let n=0|this.h0,r=n,i=0|this.h1,o=i,s=0|this.h2,u=s,a=0|this.h3,c=a,f=0|this.h4,d=f;for(let e=0;e<5;e++){const t=4-e,l=un[e],h=an[e],p=tn[e],m=nn[e],g=on[e],w=sn[e];for(let t=0;t<16;t++){const r=I(n+cn(e,i,s,a)+fn[p[t]]+l,g[t])+f|0;n=f,f=a,a=0|I(s,10),s=i,i=r}for(let e=0;e<16;e++){const n=I(r+cn(t,o,u,c)+fn[m[e]]+h,w[e])+d|0;r=d,d=c,c=0|I(u,10),u=o,o=n}}this.set(this.h1+s+c|0,this.h2+a+d|0,this.h3+f+r|0,this.h4+n+o|0,this.h0+i+u|0)}roundClean(){S(fn)}destroy(){this.destroyed=!0,S(this.buffer),this.set(0,0,0,0,0)}}const ln=M(()=>new dn);function hn(...e){const t=g.join(e),n=ln(te(t));return new g(n)}function pn(...e){const t=g.join(e),n=te(t);return new g(n)}function mn(...e){const t=g.join(e),n=te(te(t));return new g(n)}function gn(e,...t){const n=function(e){const t=pn(g.str(e));return g.join([t,t])}(e),r=t.map(e=>new g(e));return pn(g.join([n,...r]))}function wn(e,t,n){function r(n,r){var i;Object.defineProperty(n,"_zod",{value:n._zod??{},enumerable:!1}),(i=n._zod).traits??(i.traits=new Set),n._zod.traits.add(e),t(n,r);for(const e in s.prototype)e in n||Object.defineProperty(n,e,{value:s.prototype[e].bind(n)});n._zod.constr=s,n._zod.def=r}const i=n?.Parent??Object;class o extends i{}function s(e){var t;const i=n?.Parent?new o:this;r(i,e),(t=i._zod).deferred??(t.deferred=[]);for(const e of i._zod.deferred)e();return i}return Object.defineProperty(o,"name",{value:e}),Object.defineProperty(s,"init",{value:r}),Object.defineProperty(s,Symbol.hasInstance,{value:t=>!!(n?.Parent&&t instanceof n.Parent)||t?._zod?.traits?.has(e)}),Object.defineProperty(s,"name",{value:e}),s}class _n extends Error{constructor(){super("Encountered Promise during synchronous parse. Use .parseAsync() instead.")}}const yn={};function vn(e){return yn}function bn(e,t){return"bigint"==typeof t?t.toString():t}function En(e){return{get value(){{const t=e();return Object.defineProperty(this,"value",{value:t}),t}}}}function xn(e){return null==e}function zn(e){const t=e.startsWith("^")?1:0,n=e.endsWith("$")?e.length-1:e.length;return e.slice(t,n)}function kn(e,t,n){Object.defineProperty(e,t,{get(){{const r=n();return e[t]=r,r}},set(n){Object.defineProperty(e,t,{value:n})},configurable:!0})}function On(e,t,n){Object.defineProperty(e,t,{value:n,writable:!0,enumerable:!0,configurable:!0})}function An(e){return JSON.stringify(e)}const Sn=Error.captureStackTrace?Error.captureStackTrace:(...e)=>{};function Pn(e){return"object"==typeof e&&null!==e&&!Array.isArray(e)}const $n=En(()=>{if("undefined"!=typeof navigator&&navigator?.userAgent?.includes("Cloudflare"))return!1;try{return new Function(""),!0}catch(e){return!1}});function In(e){if(!1===Pn(e))return!1;const t=e.constructor;if(void 0===t)return!0;const n=t.prototype;return!1!==Pn(n)&&!1!==Object.prototype.hasOwnProperty.call(n,"isPrototypeOf")}const Tn=new Set(["string","number","symbol"]);function Nn(e){return e.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}function Bn(e,t,n){const r=new e._zod.constr(t??e._zod.def);return t&&!n?.parent||(r._zod.parent=e),r}function Un(e){const t=e;if(!t)return{};if("string"==typeof t)return{error:()=>t};if(void 0!==t?.message){if(void 0!==t?.error)throw new Error("Cannot specify both `message` and `error` params");t.error=t.message}return delete t.message,"string"==typeof t.error?{...t,error:()=>t.error}:t}const Zn={safeint:[Number.MIN_SAFE_INTEGER,Number.MAX_SAFE_INTEGER],int32:[-2147483648,2147483647],uint32:[0,4294967295],float32:[-34028234663852886e22,34028234663852886e22],float64:[-Number.MAX_VALUE,Number.MAX_VALUE]};function Rn(e,t=0){for(let n=t;n<e.issues.length;n++)if(!0!==e.issues[n]?.continue)return!0;return!1}function Cn(e,t){return t.map(t=>{var n;return(n=t).path??(n.path=[]),t.path.unshift(e),t})}function jn(e){return"string"==typeof e?e:e?.message}function Fn(e,t,n){const r={...e,path:e.path??[]};if(!e.message){const i=jn(e.inst?._zod.def?.error?.(e))??jn(t?.error?.(e))??jn(n.customError?.(e))??jn(n.localeError?.(e))??"Invalid input";r.message=i}return delete r.inst,delete r.continue,t?.reportInput||delete r.input,r}function Dn(e){return Array.isArray(e)?"array":"string"==typeof e?"string":"unknown"}function Ln(...e){const[t,n,r]=e;return"string"==typeof t?{message:t,code:"custom",input:n,inst:r}:{...t}}const Hn=(e,t)=>{e.name="$ZodError",Object.defineProperty(e,"_zod",{value:e._zod,enumerable:!1}),Object.defineProperty(e,"issues",{value:t,enumerable:!1}),Object.defineProperty(e,"message",{get:()=>JSON.stringify(t,bn,2),enumerable:!0}),Object.defineProperty(e,"toString",{value:()=>e.message,enumerable:!1})},Vn=wn("$ZodError",Hn),qn=wn("$ZodError",Hn,{Parent:Error});const Mn=e=>(t,n,r,i)=>{const o=r?Object.assign(r,{async:!1}):{async:!1},s=t._zod.run({value:n,issues:[]},o);if(s instanceof Promise)throw new _n;if(s.issues.length){const t=new(i?.Err??e)(s.issues.map(e=>Fn(e,o,vn())));throw Sn(t,i?.callee),t}return s.value},Kn=e=>async(t,n,r,i)=>{const o=r?Object.assign(r,{async:!0}):{async:!0};let s=t._zod.run({value:n,issues:[]},o);if(s instanceof Promise&&(s=await s),s.issues.length){const t=new(i?.Err??e)(s.issues.map(e=>Fn(e,o,vn())));throw Sn(t,i?.callee),t}return s.value},Gn=e=>(t,n,r)=>{const i=r?{...r,async:!1}:{async:!1},o=t._zod.run({value:n,issues:[]},i);if(o instanceof Promise)throw new _n;return o.issues.length?{success:!1,error:new(e??Vn)(o.issues.map(e=>Fn(e,i,vn())))}:{success:!0,data:o.value}},Wn=Gn(qn),Yn=e=>async(t,n,r)=>{const i=r?Object.assign(r,{async:!0}):{async:!0};let o=t._zod.run({value:n,issues:[]},i);return o instanceof Promise&&(o=await o),o.issues.length?{success:!1,error:new e(o.issues.map(e=>Fn(e,i,vn())))}:{success:!0,data:o.value}},Xn=Yn(qn),Jn=/^[cC][^\s-]{8,}$/,Qn=/^[0-9a-z]+$/,er=/^[0-9A-HJKMNP-TV-Za-hjkmnp-tv-z]{26}$/,tr=/^[0-9a-vA-V]{20}$/,nr=/^[A-Za-z0-9]{27}$/,rr=/^[a-zA-Z0-9_-]{21}$/,ir=/^P(?:(\d+W)|(?!.*W)(?=\d|T\d)(\d+Y)?(\d+M)?(\d+D)?(T(?=\d)(\d+H)?(\d+M)?(\d+([.,]\d+)?S)?)?)$/,or=/^([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12})$/,sr=e=>e?new RegExp(`^([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-${e}[0-9a-fA-F]{3}-[89abAB][0-9a-fA-F]{3}-[0-9a-fA-F]{12})$`):/^([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[1-8][0-9a-fA-F]{3}-[89abAB][0-9a-fA-F]{3}-[0-9a-fA-F]{12}|00000000-0000-0000-0000-000000000000)$/,ur=/^(?!\.)(?!.*\.\.)([A-Za-z0-9_'+\-\.]*)[A-Za-z0-9_+-]@([A-Za-z0-9][A-Za-z0-9\-]*\.)+[A-Za-z]{2,}$/;const ar=/^(?:(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\.){3}(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])$/,cr=/^(([0-9a-fA-F]{1,4}:){7}[0-9a-fA-F]{1,4}|::|([0-9a-fA-F]{1,4})?::([0-9a-fA-F]{1,4}:?){0,6})$/,fr=/^((25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\.){3}(25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\/([0-9]|[1-2][0-9]|3[0-2])$/,dr=/^(([0-9a-fA-F]{1,4}:){7}[0-9a-fA-F]{1,4}|::|([0-9a-fA-F]{1,4})?::([0-9a-fA-F]{1,4}:?){0,6})\/(12[0-8]|1[01][0-9]|[1-9]?[0-9])$/,lr=/^$|^(?:[0-9a-zA-Z+/]{4})*(?:(?:[0-9a-zA-Z+/]{2}==)|(?:[0-9a-zA-Z+/]{3}=))?$/,hr=/^[A-Za-z0-9_-]*$/,pr=/^([a-zA-Z0-9-]+\.)*[a-zA-Z0-9-]+$/,mr=/^\+(?:[0-9]){6,14}[0-9]$/,gr="(?:(?:\\d\\d[2468][048]|\\d\\d[13579][26]|\\d\\d0[48]|[02468][048]00|[13579][26]00)-02-29|\\d{4}-(?:(?:0[13578]|1[02])-(?:0[1-9]|[12]\\d|3[01])|(?:0[469]|11)-(?:0[1-9]|[12]\\d|30)|(?:02)-(?:0[1-9]|1\\d|2[0-8])))",wr=new RegExp(`^${gr}$`);function _r(e){const t="(?:[01]\\d|2[0-3]):[0-5]\\d";return"number"==typeof e.precision?-1===e.precision?`${t}`:0===e.precision?`${t}:[0-5]\\d`:`${t}:[0-5]\\d\\.\\d{${e.precision}}`:`${t}(?::[0-5]\\d(?:\\.\\d+)?)?`}const yr=/^\d+n?$/,vr=/^\d+$/,br=/^-?\d+(?:\.\d+)?/i,Er=/true|false/i,xr=/null/i,zr=/^[^A-Z]*$/,kr=/^[^a-z]*$/,Or=wn("$ZodCheck",(e,t)=>{var n;e._zod??(e._zod={}),e._zod.def=t,(n=e._zod).onattach??(n.onattach=[])}),Ar={number:"number",bigint:"bigint",object:"date"},Sr=wn("$ZodCheckLessThan",(e,t)=>{Or.init(e,t);const n=Ar[typeof t.value];e._zod.onattach.push(e=>{const n=e._zod.bag,r=(t.inclusive?n.maximum:n.exclusiveMaximum)??Number.POSITIVE_INFINITY;t.value<r&&(t.inclusive?n.maximum=t.value:n.exclusiveMaximum=t.value)}),e._zod.check=r=>{(t.inclusive?r.value<=t.value:r.value<t.value)||r.issues.push({origin:n,code:"too_big",maximum:t.value,input:r.value,inclusive:t.inclusive,inst:e,continue:!t.abort})}}),Pr=wn("$ZodCheckGreaterThan",(e,t)=>{Or.init(e,t);const n=Ar[typeof t.value];e._zod.onattach.push(e=>{const n=e._zod.bag,r=(t.inclusive?n.minimum:n.exclusiveMinimum)??Number.NEGATIVE_INFINITY;t.value>r&&(t.inclusive?n.minimum=t.value:n.exclusiveMinimum=t.value)}),e._zod.check=r=>{(t.inclusive?r.value>=t.value:r.value>t.value)||r.issues.push({origin:n,code:"too_small",minimum:t.value,input:r.value,inclusive:t.inclusive,inst:e,continue:!t.abort})}}),$r=wn("$ZodCheckMultipleOf",(e,t)=>{Or.init(e,t),e._zod.onattach.push(e=>{var n;(n=e._zod.bag).multipleOf??(n.multipleOf=t.value)}),e._zod.check=n=>{if(typeof n.value!=typeof t.value)throw new Error("Cannot mix number and bigint in multiple_of check.");("bigint"==typeof n.value?n.value%t.value===BigInt(0):0===function(e,t){const n=(e.toString().split(".")[1]||"").length,r=(t.toString().split(".")[1]||"").length,i=n>r?n:r;return Number.parseInt(e.toFixed(i).replace(".",""))%Number.parseInt(t.toFixed(i).replace(".",""))/10**i}(n.value,t.value))||n.issues.push({origin:typeof n.value,code:"not_multiple_of",divisor:t.value,input:n.value,inst:e,continue:!t.abort})}}),Ir=wn("$ZodCheckNumberFormat",(e,t)=>{Or.init(e,t),t.format=t.format||"float64";const n=t.format?.includes("int"),r=n?"int":"number",[i,o]=Zn[t.format];e._zod.onattach.push(e=>{const r=e._zod.bag;r.format=t.format,r.minimum=i,r.maximum=o,n&&(r.pattern=vr)}),e._zod.check=s=>{const u=s.value;if(n){if(!Number.isInteger(u))return void s.issues.push({expected:r,format:t.format,code:"invalid_type",input:u,inst:e});if(!Number.isSafeInteger(u))return void(u>0?s.issues.push({input:u,code:"too_big",maximum:Number.MAX_SAFE_INTEGER,note:"Integers must be within the safe integer range.",inst:e,origin:r,continue:!t.abort}):s.issues.push({input:u,code:"too_small",minimum:Number.MIN_SAFE_INTEGER,note:"Integers must be within the safe integer range.",inst:e,origin:r,continue:!t.abort}))}u<i&&s.issues.push({origin:"number",input:u,code:"too_small",minimum:i,inclusive:!0,inst:e,continue:!t.abort}),u>o&&s.issues.push({origin:"number",input:u,code:"too_big",maximum:o,inst:e})}}),Tr=wn("$ZodCheckMaxLength",(e,t)=>{var n;Or.init(e,t),(n=e._zod.def).when??(n.when=e=>{const t=e.value;return!xn(t)&&void 0!==t.length}),e._zod.onattach.push(e=>{const n=e._zod.bag.maximum??Number.POSITIVE_INFINITY;t.maximum<n&&(e._zod.bag.maximum=t.maximum)}),e._zod.check=n=>{const r=n.value;if(r.length<=t.maximum)return;const i=Dn(r);n.issues.push({origin:i,code:"too_big",maximum:t.maximum,inclusive:!0,input:r,inst:e,continue:!t.abort})}}),Nr=wn("$ZodCheckMinLength",(e,t)=>{var n;Or.init(e,t),(n=e._zod.def).when??(n.when=e=>{const t=e.value;return!xn(t)&&void 0!==t.length}),e._zod.onattach.push(e=>{const n=e._zod.bag.minimum??Number.NEGATIVE_INFINITY;t.minimum>n&&(e._zod.bag.minimum=t.minimum)}),e._zod.check=n=>{const r=n.value;if(r.length>=t.minimum)return;const i=Dn(r);n.issues.push({origin:i,code:"too_small",minimum:t.minimum,inclusive:!0,input:r,inst:e,continue:!t.abort})}}),Br=wn("$ZodCheckLengthEquals",(e,t)=>{var n;Or.init(e,t),(n=e._zod.def).when??(n.when=e=>{const t=e.value;return!xn(t)&&void 0!==t.length}),e._zod.onattach.push(e=>{const n=e._zod.bag;n.minimum=t.length,n.maximum=t.length,n.length=t.length}),e._zod.check=n=>{const r=n.value,i=r.length;if(i===t.length)return;const o=Dn(r),s=i>t.length;n.issues.push({origin:o,...s?{code:"too_big",maximum:t.length}:{code:"too_small",minimum:t.length},inclusive:!0,exact:!0,input:n.value,inst:e,continue:!t.abort})}}),Ur=wn("$ZodCheckStringFormat",(e,t)=>{var n,r;Or.init(e,t),e._zod.onattach.push(e=>{const n=e._zod.bag;n.format=t.format,t.pattern&&(n.patterns??(n.patterns=new Set),n.patterns.add(t.pattern))}),t.pattern?(n=e._zod).check??(n.check=n=>{t.pattern.lastIndex=0,t.pattern.test(n.value)||n.issues.push({origin:"string",code:"invalid_format",format:t.format,input:n.value,...t.pattern?{pattern:t.pattern.toString()}:{},inst:e,continue:!t.abort})}):(r=e._zod).check??(r.check=()=>{})}),Zr=wn("$ZodCheckRegex",(e,t)=>{Ur.init(e,t),e._zod.check=n=>{t.pattern.lastIndex=0,t.pattern.test(n.value)||n.issues.push({origin:"string",code:"invalid_format",format:"regex",input:n.value,pattern:t.pattern.toString(),inst:e,continue:!t.abort})}}),Rr=wn("$ZodCheckLowerCase",(e,t)=>{t.pattern??(t.pattern=zr),Ur.init(e,t)}),Cr=wn("$ZodCheckUpperCase",(e,t)=>{t.pattern??(t.pattern=kr),Ur.init(e,t)}),jr=wn("$ZodCheckIncludes",(e,t)=>{Or.init(e,t);const n=Nn(t.includes),r=new RegExp("number"==typeof t.position?`^.{${t.position}}${n}`:n);t.pattern=r,e._zod.onattach.push(e=>{const t=e._zod.bag;t.patterns??(t.patterns=new Set),t.patterns.add(r)}),e._zod.check=n=>{n.value.includes(t.includes,t.position)||n.issues.push({origin:"string",code:"invalid_format",format:"includes",includes:t.includes,input:n.value,inst:e,continue:!t.abort})}}),Fr=wn("$ZodCheckStartsWith",(e,t)=>{Or.init(e,t);const n=new RegExp(`^${Nn(t.prefix)}.*`);t.pattern??(t.pattern=n),e._zod.onattach.push(e=>{const t=e._zod.bag;t.patterns??(t.patterns=new Set),t.patterns.add(n)}),e._zod.check=n=>{n.value.startsWith(t.prefix)||n.issues.push({origin:"string",code:"invalid_format",format:"starts_with",prefix:t.prefix,input:n.value,inst:e,continue:!t.abort})}}),Dr=wn("$ZodCheckEndsWith",(e,t)=>{Or.init(e,t);const n=new RegExp(`.*${Nn(t.suffix)}$`);t.pattern??(t.pattern=n),e._zod.onattach.push(e=>{const t=e._zod.bag;t.patterns??(t.patterns=new Set),t.patterns.add(n)}),e._zod.check=n=>{n.value.endsWith(t.suffix)||n.issues.push({origin:"string",code:"invalid_format",format:"ends_with",suffix:t.suffix,input:n.value,inst:e,continue:!t.abort})}}),Lr=wn("$ZodCheckOverwrite",(e,t)=>{Or.init(e,t),e._zod.check=e=>{e.value=t.tx(e.value)}});class Hr{constructor(e=[]){this.content=[],this.indent=0,this&&(this.args=e)}indented(e){this.indent+=1,e(this),this.indent-=1}write(e){if("function"==typeof e)return e(this,{execution:"sync"}),void e(this,{execution:"async"});const t=e.split("\n").filter(e=>e),n=Math.min(...t.map(e=>e.length-e.trimStart().length)),r=t.map(e=>e.slice(n)).map(e=>" ".repeat(2*this.indent)+e);for(const e of r)this.content.push(e)}compile(){const e=Function,t=this?.args;return new e(...t,[...(this?.content??[""]).map(e=>` ${e}`)].join("\n"))}}const Vr={major:4,minor:0,patch:5},qr=wn("$ZodType",(e,t)=>{var n;e??(e={}),e._zod.def=t,e._zod.bag=e._zod.bag||{},e._zod.version=Vr;const r=[...e._zod.def.checks??[]];e._zod.traits.has("$ZodCheck")&&r.unshift(e);for(const t of r)for(const n of t._zod.onattach)n(e);if(0===r.length)(n=e._zod).deferred??(n.deferred=[]),e._zod.deferred?.push(()=>{e._zod.run=e._zod.parse});else{const t=(e,t,n)=>{let r,i=Rn(e);for(const o of t){if(o._zod.def.when){if(!o._zod.def.when(e))continue}else if(i)continue;const t=e.issues.length,s=o._zod.check(e);if(s instanceof Promise&&!1===n?.async)throw new _n;if(r||s instanceof Promise)r=(r??Promise.resolve()).then(async()=>{await s;e.issues.length!==t&&(i||(i=Rn(e,t)))});else{if(e.issues.length===t)continue;i||(i=Rn(e,t))}}return r?r.then(()=>e):e};e._zod.run=(n,i)=>{const o=e._zod.parse(n,i);if(o instanceof Promise){if(!1===i.async)throw new _n;return o.then(e=>t(e,r,i))}return t(o,r,i)}}e["~standard"]={validate:t=>{try{const n=Wn(e,t);return n.success?{value:n.data}:{issues:n.error?.issues}}catch(n){return Xn(e,t).then(e=>e.success?{value:e.data}:{issues:e.error?.issues})}},vendor:"zod",version:1}}),Mr=wn("$ZodString",(e,t)=>{var n;qr.init(e,t),e._zod.pattern=[...e?._zod.bag?.patterns??[]].pop()??(n=e._zod.bag,new RegExp(`^${n?`[\\s\\S]{${n?.minimum??0},${n?.maximum??""}}`:"[\\s\\S]*"}$`)),e._zod.parse=(n,r)=>{if(t.coerce)try{n.value=String(n.value)}catch(r){}return"string"==typeof n.value||n.issues.push({expected:"string",code:"invalid_type",input:n.value,inst:e}),n}}),Kr=wn("$ZodStringFormat",(e,t)=>{Ur.init(e,t),Mr.init(e,t)}),Gr=wn("$ZodGUID",(e,t)=>{t.pattern??(t.pattern=or),Kr.init(e,t)}),Wr=wn("$ZodUUID",(e,t)=>{if(t.version){const e={v1:1,v2:2,v3:3,v4:4,v5:5,v6:6,v7:7,v8:8}[t.version];if(void 0===e)throw new Error(`Invalid UUID version: "${t.version}"`);t.pattern??(t.pattern=sr(e))}else t.pattern??(t.pattern=sr());Kr.init(e,t)}),Yr=wn("$ZodEmail",(e,t)=>{t.pattern??(t.pattern=ur),Kr.init(e,t)}),Xr=wn("$ZodURL",(e,t)=>{Kr.init(e,t),e._zod.check=n=>{try{const r=n.value,i=new URL(r),o=i.href;return t.hostname&&(t.hostname.lastIndex=0,t.hostname.test(i.hostname)||n.issues.push({code:"invalid_format",format:"url",note:"Invalid hostname",pattern:pr.source,input:n.value,inst:e,continue:!t.abort})),t.protocol&&(t.protocol.lastIndex=0,t.protocol.test(i.protocol.endsWith(":")?i.protocol.slice(0,-1):i.protocol)||n.issues.push({code:"invalid_format",format:"url",note:"Invalid protocol",pattern:t.protocol.source,input:n.value,inst:e,continue:!t.abort})),void(!r.endsWith("/")&&o.endsWith("/")?n.value=o.slice(0,-1):n.value=o)}catch(r){n.issues.push({code:"invalid_format",format:"url",input:n.value,inst:e,continue:!t.abort})}}}),Jr=wn("$ZodEmoji",(e,t)=>{t.pattern??(t.pattern=new RegExp("^(\\p{Extended_Pictographic}|\\p{Emoji_Component})+$","u")),Kr.init(e,t)}),Qr=wn("$ZodNanoID",(e,t)=>{t.pattern??(t.pattern=rr),Kr.init(e,t)}),ei=wn("$ZodCUID",(e,t)=>{t.pattern??(t.pattern=Jn),Kr.init(e,t)}),ti=wn("$ZodCUID2",(e,t)=>{t.pattern??(t.pattern=Qn),Kr.init(e,t)}),ni=wn("$ZodULID",(e,t)=>{t.pattern??(t.pattern=er),Kr.init(e,t)}),ri=wn("$ZodXID",(e,t)=>{t.pattern??(t.pattern=tr),Kr.init(e,t)}),ii=wn("$ZodKSUID",(e,t)=>{t.pattern??(t.pattern=nr),Kr.init(e,t)}),oi=wn("$ZodISODateTime",(e,t)=>{t.pattern??(t.pattern=function(e){const t=_r({precision:e.precision}),n=["Z"];e.local&&n.push(""),e.offset&&n.push("([+-]\\d{2}:\\d{2})");const r=`${t}(?:${n.join("|")})`;return new RegExp(`^${gr}T(?:${r})$`)}(t)),Kr.init(e,t)}),si=wn("$ZodISODate",(e,t)=>{t.pattern??(t.pattern=wr),Kr.init(e,t)}),ui=wn("$ZodISOTime",(e,t)=>{t.pattern??(t.pattern=new RegExp(`^${_r(t)}$`)),Kr.init(e,t)}),ai=wn("$ZodISODuration",(e,t)=>{t.pattern??(t.pattern=ir),Kr.init(e,t)}),ci=wn("$ZodIPv4",(e,t)=>{t.pattern??(t.pattern=ar),Kr.init(e,t),e._zod.onattach.push(e=>{e._zod.bag.format="ipv4"})}),fi=wn("$ZodIPv6",(e,t)=>{t.pattern??(t.pattern=cr),Kr.init(e,t),e._zod.onattach.push(e=>{e._zod.bag.format="ipv6"}),e._zod.check=n=>{try{new URL(`http://[${n.value}]`)}catch{n.issues.push({code:"invalid_format",format:"ipv6",input:n.value,inst:e,continue:!t.abort})}}}),di=wn("$ZodCIDRv4",(e,t)=>{t.pattern??(t.pattern=fr),Kr.init(e,t)}),li=wn("$ZodCIDRv6",(e,t)=>{t.pattern??(t.pattern=dr),Kr.init(e,t),e._zod.check=n=>{const[r,i]=n.value.split("/");try{if(!i)throw new Error;const e=Number(i);if(`${e}`!==i)throw new Error;if(e<0||e>128)throw new Error;new URL(`http://[${r}]`)}catch{n.issues.push({code:"invalid_format",format:"cidrv6",input:n.value,inst:e,continue:!t.abort})}}});function hi(e){if(""===e)return!0;if(e.length%4!=0)return!1;try{return atob(e),!0}catch{return!1}}const pi=wn("$ZodBase64",(e,t)=>{t.pattern??(t.pattern=lr),Kr.init(e,t),e._zod.onattach.push(e=>{e._zod.bag.contentEncoding="base64"}),e._zod.check=n=>{hi(n.value)||n.issues.push({code:"invalid_format",format:"base64",input:n.value,inst:e,continue:!t.abort})}});const mi=wn("$ZodBase64URL",(e,t)=>{t.pattern??(t.pattern=hr),Kr.init(e,t),e._zod.onattach.push(e=>{e._zod.bag.contentEncoding="base64url"}),e._zod.check=n=>{(function(e){if(!hr.test(e))return!1;const t=e.replace(/[-_]/g,e=>"-"===e?"+":"/");return hi(t.padEnd(4*Math.ceil(t.length/4),"="))})(n.value)||n.issues.push({code:"invalid_format",format:"base64url",input:n.value,inst:e,continue:!t.abort})}}),gi=wn("$ZodE164",(e,t)=>{t.pattern??(t.pattern=mr),Kr.init(e,t)});const wi=wn("$ZodJWT",(e,t)=>{Kr.init(e,t),e._zod.check=n=>{(function(e,t=null){try{const n=e.split(".");if(3!==n.length)return!1;const[r]=n;if(!r)return!1;const i=JSON.parse(atob(r));return!("typ"in i&&"JWT"!==i?.typ||!i.alg||t&&(!("alg"in i)||i.alg!==t))}catch{return!1}})(n.value,t.alg)||n.issues.push({code:"invalid_format",format:"jwt",input:n.value,inst:e,continue:!t.abort})}}),_i=wn("$ZodNumber",(e,t)=>{qr.init(e,t),e._zod.pattern=e._zod.bag.pattern??br,e._zod.parse=(n,r)=>{if(t.coerce)try{n.value=Number(n.value)}catch(e){}const i=n.value;if("number"==typeof i&&!Number.isNaN(i)&&Number.isFinite(i))return n;const o="number"==typeof i?Number.isNaN(i)?"NaN":Number.isFinite(i)?void 0:"Infinity":void 0;return n.issues.push({expected:"number",code:"invalid_type",input:i,inst:e,...o?{received:o}:{}}),n}}),yi=wn("$ZodNumber",(e,t)=>{Ir.init(e,t),_i.init(e,t)}),vi=wn("$ZodBoolean",(e,t)=>{qr.init(e,t),e._zod.pattern=Er,e._zod.parse=(n,r)=>{if(t.coerce)try{n.value=Boolean(n.value)}catch(e){}const i=n.value;return"boolean"==typeof i||n.issues.push({expected:"boolean",code:"invalid_type",input:i,inst:e}),n}}),bi=wn("$ZodBigInt",(e,t)=>{qr.init(e,t),e._zod.pattern=yr,e._zod.parse=(n,r)=>{if(t.coerce)try{n.value=BigInt(n.value)}catch(e){}return"bigint"==typeof n.value||n.issues.push({expected:"bigint",code:"invalid_type",input:n.value,inst:e}),n}}),Ei=wn("$ZodNull",(e,t)=>{qr.init(e,t),e._zod.pattern=xr,e._zod.values=new Set([null]),e._zod.parse=(t,n)=>{const r=t.value;return null===r||t.issues.push({expected:"null",code:"invalid_type",input:r,inst:e}),t}}),xi=wn("$ZodAny",(e,t)=>{qr.init(e,t),e._zod.parse=e=>e}),zi=wn("$ZodUnknown",(e,t)=>{qr.init(e,t),e._zod.parse=e=>e}),ki=wn("$ZodNever",(e,t)=>{qr.init(e,t),e._zod.parse=(t,n)=>(t.issues.push({expected:"never",code:"invalid_type",input:t.value,inst:e}),t)}),Oi=wn("$ZodDate",(e,t)=>{qr.init(e,t),e._zod.parse=(n,r)=>{if(t.coerce)try{n.value=new Date(n.value)}catch(e){}const i=n.value,o=i instanceof Date;return o&&!Number.isNaN(i.getTime())||n.issues.push({expected:"date",code:"invalid_type",input:i,...o?{received:"Invalid Date"}:{},inst:e}),n}});function Ai(e,t,n){e.issues.length&&t.issues.push(...Cn(n,e.issues)),t.value[n]=e.value}const Si=wn("$ZodArray",(e,t)=>{qr.init(e,t),e._zod.parse=(n,r)=>{const i=n.value;if(!Array.isArray(i))return n.issues.push({expected:"array",code:"invalid_type",input:i,inst:e}),n;n.value=Array(i.length);const o=[];for(let e=0;e<i.length;e++){const s=i[e],u=t.element._zod.run({value:s,issues:[]},r);u instanceof Promise?o.push(u.then(t=>Ai(t,n,e))):Ai(u,n,e)}return o.length?Promise.all(o).then(()=>n):n}});function Pi(e,t,n){e.issues.length&&t.issues.push(...Cn(n,e.issues)),t.value[n]=e.value}function $i(e,t,n,r){e.issues.length?void 0===r[n]?t.value[n]=n in r?void 0:e.value:t.issues.push(...Cn(n,e.issues)):void 0===e.value?n in r&&(t.value[n]=void 0):t.value[n]=e.value}const Ii=wn("$ZodObject",(e,t)=>{qr.init(e,t);const n=En(()=>{const e=Object.keys(t.shape);for(const n of e)if(!(t.shape[n]instanceof qr))throw new Error(`Invalid element at key "${n}": expected a Zod schema`);const n=(r=t.shape,Object.keys(r).filter(e=>"optional"===r[e]._zod.optin&&"optional"===r[e]._zod.optout));var r;return{shape:t.shape,keys:e,keySet:new Set(e),numKeys:e.length,optionalKeys:new Set(n)}});kn(e._zod,"propValues",()=>{const e=t.shape,n={};for(const t in e){const r=e[t]._zod;if(r.values){n[t]??(n[t]=new Set);for(const e of r.values)n[t].add(e)}}return n});let r;const i=Pn,o=!yn.jitless,s=o&&$n.value,u=t.catchall;let a;e._zod.parse=(c,f)=>{a??(a=n.value);const d=c.value;if(!i(d))return c.issues.push({expected:"object",code:"invalid_type",input:d,inst:e}),c;const l=[];if(o&&s&&!1===f?.async&&!0!==f.jitless)r||(r=(e=>{const t=new Hr(["shape","payload","ctx"]),r=n.value,i=e=>{const t=An(e);return`shape[${t}]._zod.run({ value: input[${t}], issues: [] }, ctx)`};t.write("const input = payload.value;");const o=Object.create(null);let s=0;for(const e of r.keys)o[e]="key_"+s++;t.write("const newResult = {}");for(const e of r.keys)if(r.optionalKeys.has(e)){const n=o[e];t.write(`const ${n} = ${i(e)};`);const r=An(e);t.write(`\n if (${n}.issues.length) {\n if (input[${r}] === undefined) {\n if (${r} in input) {\n newResult[${r}] = undefined;\n }\n } else {\n payload.issues = payload.issues.concat(\n ${n}.issues.map((iss) => ({\n ...iss,\n path: iss.path ? [${r}, ...iss.path] : [${r}],\n }))\n );\n }\n } else if (${n}.value === undefined) {\n if (${r} in input) newResult[${r}] = undefined;\n } else {\n newResult[${r}] = ${n}.value;\n }\n `)}else{const n=o[e];t.write(`const ${n} = ${i(e)};`),t.write(`\n if (${n}.issues.length) payload.issues = payload.issues.concat(${n}.issues.map(iss => ({\n ...iss,\n path: iss.path ? [${An(e)}, ...iss.path] : [${An(e)}]\n })));`),t.write(`newResult[${An(e)}] = ${n}.value`)}t.write("payload.value = newResult;"),t.write("return payload;");const u=t.compile();return(t,n)=>u(e,t,n)})(t.shape)),c=r(c,f);else{c.value={};const e=a.shape;for(const t of a.keys){const n=e[t],r=n._zod.run({value:d[t],issues:[]},f),i="optional"===n._zod.optin&&"optional"===n._zod.optout;r instanceof Promise?l.push(r.then(e=>i?$i(e,c,t,d):Pi(e,c,t))):i?$i(r,c,t,d):Pi(r,c,t)}}if(!u)return l.length?Promise.all(l).then(()=>c):c;const h=[],p=a.keySet,m=u._zod,g=m.def.type;for(const e of Object.keys(d)){if(p.has(e))continue;if("never"===g){h.push(e);continue}const t=m.run({value:d[e],issues:[]},f);t instanceof Promise?l.push(t.then(t=>Pi(t,c,e))):Pi(t,c,e)}return h.length&&c.issues.push({code:"unrecognized_keys",keys:h,input:d,inst:e}),l.length?Promise.all(l).then(()=>c):c}});function Ti(e,t,n,r){for(const n of e)if(0===n.issues.length)return t.value=n.value,t;return t.issues.push({code:"invalid_union",input:t.value,inst:n,errors:e.map(e=>e.issues.map(e=>Fn(e,r,vn())))}),t}const Ni=wn("$ZodUnion",(e,t)=>{qr.init(e,t),kn(e._zod,"optin",()=>t.options.some(e=>"optional"===e._zod.optin)?"optional":void 0),kn(e._zod,"optout",()=>t.options.some(e=>"optional"===e._zod.optout)?"optional":void 0),kn(e._zod,"values",()=>{if(t.options.every(e=>e._zod.values))return new Set(t.options.flatMap(e=>Array.from(e._zod.values)))}),kn(e._zod,"pattern",()=>{if(t.options.every(e=>e._zod.pattern)){const e=t.options.map(e=>e._zod.pattern);return new RegExp(`^(${e.map(e=>zn(e.source)).join("|")})$`)}}),e._zod.parse=(n,r)=>{let i=!1;const o=[];for(const e of t.options){const t=e._zod.run({value:n.value,issues:[]},r);if(t instanceof Promise)o.push(t),i=!0;else{if(0===t.issues.length)return t;o.push(t)}}return i?Promise.all(o).then(t=>Ti(t,n,e,r)):Ti(o,n,e,r)}}),Bi=wn("$ZodIntersection",(e,t)=>{qr.init(e,t),e._zod.parse=(e,n)=>{const r=e.value,i=t.left._zod.run({value:r,issues:[]},n),o=t.right._zod.run({value:r,issues:[]},n);return i instanceof Promise||o instanceof Promise?Promise.all([i,o]).then(([t,n])=>Zi(e,t,n)):Zi(e,i,o)}});function Ui(e,t){if(e===t)return{valid:!0,data:e};if(e instanceof Date&&t instanceof Date&&+e===+t)return{valid:!0,data:e};if(In(e)&&In(t)){const n=Object.keys(t),r=Object.keys(e).filter(e=>-1!==n.indexOf(e)),i={...e,...t};for(const n of r){const r=Ui(e[n],t[n]);if(!r.valid)return{valid:!1,mergeErrorPath:[n,...r.mergeErrorPath]};i[n]=r.data}return{valid:!0,data:i}}if(Array.isArray(e)&&Array.isArray(t)){if(e.length!==t.length)return{valid:!1,mergeErrorPath:[]};const n=[];for(let r=0;r<e.length;r++){const i=Ui(e[r],t[r]);if(!i.valid)return{valid:!1,mergeErrorPath:[r,...i.mergeErrorPath]};n.push(i.data)}return{valid:!0,data:n}}return{valid:!1,mergeErrorPath:[]}}function Zi(e,t,n){if(t.issues.length&&e.issues.push(...t.issues),n.issues.length&&e.issues.push(...n.issues),Rn(e))return e;const r=Ui(t.value,n.value);if(!r.valid)throw new Error(`Unmergable intersection. Error path: ${JSON.stringify(r.mergeErrorPath)}`);return e.value=r.data,e}const Ri=wn("$ZodRecord",(e,t)=>{qr.init(e,t),e._zod.parse=(n,r)=>{const i=n.value;if(!In(i))return n.issues.push({expected:"record",code:"invalid_type",input:i,inst:e}),n;const o=[];if(t.keyType._zod.values){const s=t.keyType._zod.values;n.value={};for(const e of s)if("string"==typeof e||"number"==typeof e||"symbol"==typeof e){const s=t.valueType._zod.run({value:i[e],issues:[]},r);s instanceof Promise?o.push(s.then(t=>{t.issues.length&&n.issues.push(...Cn(e,t.issues)),n.value[e]=t.value})):(s.issues.length&&n.issues.push(...Cn(e,s.issues)),n.value[e]=s.value)}let u;for(const e in i)s.has(e)||(u=u??[],u.push(e));u&&u.length>0&&n.issues.push({code:"unrecognized_keys",input:i,inst:e,keys:u})}else{n.value={};for(const s of Reflect.ownKeys(i)){if("__proto__"===s)continue;const u=t.keyType._zod.run({value:s,issues:[]},r);if(u instanceof Promise)throw new Error("Async schemas not supported in object keys currently");if(u.issues.length){n.issues.push({origin:"record",code:"invalid_key",issues:u.issues.map(e=>Fn(e,r,vn())),input:s,path:[s],inst:e}),n.value[u.value]=u.value;continue}const a=t.valueType._zod.run({value:i[s],issues:[]},r);a instanceof Promise?o.push(a.then(e=>{e.issues.length&&n.issues.push(...Cn(s,e.issues)),n.value[u.value]=e.value})):(a.issues.length&&n.issues.push(...Cn(s,a.issues)),n.value[u.value]=a.value)}}return o.length?Promise.all(o).then(()=>n):n}}),Ci=wn("$ZodEnum",(e,t)=>{qr.init(e,t);const n=function(e){const t=Object.values(e).filter(e=>"number"==typeof e);return Object.entries(e).filter(([e,n])=>-1===t.indexOf(+e)).map(([e,t])=>t)}(t.entries);e._zod.values=new Set(n),e._zod.pattern=new RegExp(`^(${n.filter(e=>Tn.has(typeof e)).map(e=>"string"==typeof e?Nn(e):e.toString()).join("|")})$`),e._zod.parse=(t,r)=>{const i=t.value;return e._zod.values.has(i)||t.issues.push({code:"invalid_value",values:n,input:i,inst:e}),t}}),ji=wn("$ZodTransform",(e,t)=>{qr.init(e,t),e._zod.parse=(e,n)=>{const r=t.transform(e.value,e);if(n.async){return(r instanceof Promise?r:Promise.resolve(r)).then(t=>(e.value=t,e))}if(r instanceof Promise)throw new _n;return e.value=r,e}}),Fi=wn("$ZodOptional",(e,t)=>{qr.init(e,t),e._zod.optin="optional",e._zod.optout="optional",kn(e._zod,"values",()=>t.innerType._zod.values?new Set([...t.innerType._zod.values,void 0]):void 0),kn(e._zod,"pattern",()=>{const e=t.innerType._zod.pattern;return e?new RegExp(`^(${zn(e.source)})?$`):void 0}),e._zod.parse=(e,n)=>"optional"===t.innerType._zod.optin?t.innerType._zod.run(e,n):void 0===e.value?e:t.innerType._zod.run(e,n)}),Di=wn("$ZodNullable",(e,t)=>{qr.init(e,t),kn(e._zod,"optin",()=>t.innerType._zod.optin),kn(e._zod,"optout",()=>t.innerType._zod.optout),kn(e._zod,"pattern",()=>{const e=t.innerType._zod.pattern;return e?new RegExp(`^(${zn(e.source)}|null)$`):void 0}),kn(e._zod,"values",()=>t.innerType._zod.values?new Set([...t.innerType._zod.values,null]):void 0),e._zod.parse=(e,n)=>null===e.value?e:t.innerType._zod.run(e,n)}),Li=wn("$ZodDefault",(e,t)=>{qr.init(e,t),e._zod.optin="optional",kn(e._zod,"values",()=>t.innerType._zod.values),e._zod.parse=(e,n)=>{if(void 0===e.value)return e.value=t.defaultValue,e;const r=t.innerType._zod.run(e,n);return r instanceof Promise?r.then(e=>Hi(e,t)):Hi(r,t)}});function Hi(e,t){return void 0===e.value&&(e.value=t.defaultValue),e}const Vi=wn("$ZodPrefault",(e,t)=>{qr.init(e,t),e._zod.optin="optional",kn(e._zod,"values",()=>t.innerType._zod.values),e._zod.parse=(e,n)=>(void 0===e.value&&(e.value=t.defaultValue),t.innerType._zod.run(e,n))}),qi=wn("$ZodNonOptional",(e,t)=>{qr.init(e,t),kn(e._zod,"values",()=>{const e=t.innerType._zod.values;return e?new Set([...e].filter(e=>void 0!==e)):void 0}),e._zod.parse=(n,r)=>{const i=t.innerType._zod.run(n,r);return i instanceof Promise?i.then(t=>Mi(t,e)):Mi(i,e)}});function Mi(e,t){return e.issues.length||void 0!==e.value||e.issues.push({code:"invalid_type",expected:"nonoptional",input:e.value,inst:t}),e}const Ki=wn("$ZodCatch",(e,t)=>{qr.init(e,t),e._zod.optin="optional",kn(e._zod,"optout",()=>t.innerType._zod.optout),kn(e._zod,"values",()=>t.innerType._zod.values),e._zod.parse=(e,n)=>{const r=t.innerType._zod.run(e,n);return r instanceof Promise?r.then(r=>(e.value=r.value,r.issues.length&&(e.value=t.catchValue({...e,error:{issues:r.issues.map(e=>Fn(e,n,vn()))},input:e.value}),e.issues=[]),e)):(e.value=r.value,r.issues.length&&(e.value=t.catchValue({...e,error:{issues:r.issues.map(e=>Fn(e,n,vn()))},input:e.value}),e.issues=[]),e)}}),Gi=wn("$ZodPipe",(e,t)=>{qr.init(e,t),kn(e._zod,"values",()=>t.in._zod.values),kn(e._zod,"optin",()=>t.in._zod.optin),kn(e._zod,"optout",()=>t.out._zod.optout),kn(e._zod,"propValues",()=>t.in._zod.propValues),e._zod.parse=(e,n)=>{const r=t.in._zod.run(e,n);return r instanceof Promise?r.then(e=>Wi(e,t,n)):Wi(r,t,n)}});function Wi(e,t,n){return Rn(e)?e:t.out._zod.run({value:e.value,issues:e.issues},n)}const Yi=wn("$ZodReadonly",(e,t)=>{qr.init(e,t),kn(e._zod,"propValues",()=>t.innerType._zod.propValues),kn(e._zod,"values",()=>t.innerType._zod.values),kn(e._zod,"optin",()=>t.innerType._zod.optin),kn(e._zod,"optout",()=>t.innerType._zod.optout),e._zod.parse=(e,n)=>{const r=t.innerType._zod.run(e,n);return r instanceof Promise?r.then(Xi):Xi(r)}});function Xi(e){return e.value=Object.freeze(e.value),e}const Ji=wn("$ZodLazy",(e,t)=>{qr.init(e,t),kn(e._zod,"innerType",()=>t.getter()),kn(e._zod,"pattern",()=>e._zod.innerType._zod.pattern),kn(e._zod,"propValues",()=>e._zod.innerType._zod.propValues),kn(e._zod,"optin",()=>e._zod.innerType._zod.optin),kn(e._zod,"optout",()=>e._zod.innerType._zod.optout),e._zod.parse=(t,n)=>e._zod.innerType._zod.run(t,n)}),Qi=wn("$ZodCustom",(e,t)=>{Or.init(e,t),qr.init(e,t),e._zod.parse=(e,t)=>e,e._zod.check=n=>{const r=n.value,i=t.fn(r);if(i instanceof Promise)return i.then(t=>eo(t,n,r,e));eo(i,n,r,e)}});function eo(e,t,n,r){if(!e){const e={code:"custom",input:n,inst:r,path:[...r._zod.def.path??[]],continue:!r._zod.def.abort};r._zod.def.params&&(e.params=r._zod.def.params),t.issues.push(Ln(e))}}class to{constructor(){this._map=new Map,this._idmap=new Map}add(e,...t){const n=t[0];if(this._map.set(e,n),n&&"object"==typeof n&&"id"in n){if(this._idmap.has(n.id))throw new Error(`ID ${n.id} already exists in the registry`);this._idmap.set(n.id,e)}return this}clear(){return this._map=new Map,this._idmap=new Map,this}remove(e){const t=this._map.get(e);return t&&"object"==typeof t&&"id"in t&&this._idmap.delete(t.id),this._map.delete(e),this}get(e){const t=e._zod.parent;if(t){const n={...this.get(t)??{}};return delete n.id,{...n,...this._map.get(e)}}return this._map.get(e)}has(e){return this._map.has(e)}}function no(){return new to}const ro=no();function io(e,t){return new e({type:"string",format:"guid",check:"string_format",abort:!1,...Un(t)})}function oo(e,t){return new Sr({check:"less_than",...Un(t),value:e,inclusive:!1})}function so(e,t){return new Sr({check:"less_than",...Un(t),value:e,inclusive:!0})}function uo(e,t){return new Pr({check:"greater_than",...Un(t),value:e,inclusive:!1})}function ao(e,t){return new Pr({check:"greater_than",...Un(t),value:e,inclusive:!0})}function co(e,t){return new $r({check:"multiple_of",...Un(t),value:e})}function fo(e,t){return new Tr({check:"max_length",...Un(t),maximum:e})}function lo(e,t){return new Nr({check:"min_length",...Un(t),minimum:e})}function ho(e,t){return new Br({check:"length_equals",...Un(t),length:e})}function po(e){return new Lr({check:"overwrite",tx:e})}const mo=wn("ZodISODateTime",(e,t)=>{oi.init(e,t),To.init(e,t)});function go(e){return function(e,t){return new e({type:"string",format:"datetime",check:"string_format",offset:!1,local:!1,precision:null,...Un(t)})}(mo,e)}const wo=wn("ZodISODate",(e,t)=>{si.init(e,t),To.init(e,t)});function _o(e){return function(e,t){return new e({type:"string",format:"date",check:"string_format",...Un(t)})}(wo,e)}const yo=wn("ZodISOTime",(e,t)=>{ui.init(e,t),To.init(e,t)});function vo(e){return function(e,t){return new e({type:"string",format:"time",check:"string_format",precision:null,...Un(t)})}(yo,e)}const bo=wn("ZodISODuration",(e,t)=>{ai.init(e,t),To.init(e,t)});function Eo(e){return function(e,t){return new e({type:"string",format:"duration",check:"string_format",...Un(t)})}(bo,e)}const xo=wn("ZodError",(e,t)=>{Vn.init(e,t),e.name="ZodError",Object.defineProperties(e,{format:{value:t=>function(e,t){const n=t||function(e){return e.message},r={_errors:[]},i=e=>{for(const t of e.issues)if("invalid_union"===t.code&&t.errors.length)t.errors.map(e=>i({issues:e}));else if("invalid_key"===t.code)i({issues:t.issues});else if("invalid_element"===t.code)i({issues:t.issues});else if(0===t.path.length)r._errors.push(n(t));else{let e=r,i=0;for(;i<t.path.length;){const r=t.path[i];i===t.path.length-1?(e[r]=e[r]||{_errors:[]},e[r]._errors.push(n(t))):e[r]=e[r]||{_errors:[]},e=e[r],i++}}};return i(e),r}(e,t)},flatten:{value:t=>function(e,t=e=>e.message){const n={},r=[];for(const i of e.issues)i.path.length>0?(n[i.path[0]]=n[i.path[0]]||[],n[i.path[0]].push(t(i))):r.push(t(i));return{formErrors:r,fieldErrors:n}}(e,t)},addIssue:{value:t=>e.issues.push(t)},addIssues:{value:t=>e.issues.push(...t)},isEmpty:{get:()=>0===e.issues.length}})},{Parent:Error}),zo=Mn(xo),ko=Kn(xo),Oo=Gn(xo),Ao=Yn(xo),So=wn("ZodType",(e,t)=>(qr.init(e,t),e.def=t,Object.defineProperty(e,"_def",{value:t}),e.check=(...n)=>e.clone({...t,checks:[...t.checks??[],...n.map(e=>"function"==typeof e?{_zod:{check:e,def:{check:"custom"},onattach:[]}}:e)]}),e.clone=(t,n)=>Bn(e,t,n),e.brand=()=>e,e.register=(t,n)=>(t.add(e,n),e),e.parse=(t,n)=>zo(e,t,n,{callee:e.parse}),e.safeParse=(t,n)=>Oo(e,t,n),e.parseAsync=async(t,n)=>ko(e,t,n,{callee:e.parseAsync}),e.safeParseAsync=async(t,n)=>Ao(e,t,n),e.spa=e.safeParseAsync,e.refine=(t,n)=>e.check(function(e,t={}){return function(e,t,n){return new e({type:"custom",check:"custom",fn:t,...Un(n)})}(Zs,e,t)}(t,n)),e.superRefine=t=>e.check(function(e){const t=function(e){const t=new Or({check:"custom"});return t._zod.check=e,t}(n=>(n.addIssue=e=>{if("string"==typeof e)n.issues.push(Ln(e,n.value,t._zod.def));else{const r=e;r.fatal&&(r.continue=!1),r.code??(r.code="custom"),r.input??(r.input=n.value),r.inst??(r.inst=t),r.continue??(r.continue=!t._zod.def.abort),n.issues.push(Ln(r))}},e(n.value,n)));return t}(t)),e.overwrite=t=>e.check(po(t)),e.optional=()=>ks(e),e.nullable=()=>As(e),e.nullish=()=>ks(As(e)),e.nonoptional=t=>function(e,t){return new $s({type:"nonoptional",innerType:e,...Un(t)})}(e,t),e.array=()=>ps(e),e.or=t=>_s([e,t]),e.and=t=>new ys({type:"intersection",left:e,right:t}),e.transform=t=>Ns(e,new xs({type:"transform",transform:t})),e.default=t=>{return n=t,new Ss({type:"default",innerType:e,get defaultValue(){return"function"==typeof n?n():n}});var n},e.prefault=t=>{return n=t,new Ps({type:"prefault",innerType:e,get defaultValue(){return"function"==typeof n?n():n}});var n},e.catch=t=>{return new Is({type:"catch",innerType:e,catchValue:"function"==typeof(n=t)?n:()=>n});var n},e.pipe=t=>Ns(e,t),e.readonly=()=>new Bs({type:"readonly",innerType:e}),e.describe=t=>{const n=e.clone();return ro.add(n,{description:t}),n},Object.defineProperty(e,"description",{get:()=>ro.get(e)?.description,configurable:!0}),e.meta=(...t)=>{if(0===t.length)return ro.get(e);const n=e.clone();return ro.add(n,t[0]),n},e.isOptional=()=>e.safeParse(void 0).success,e.isNullable=()=>e.safeParse(null).success,e)),Po=wn("_ZodString",(e,t)=>{Mr.init(e,t),So.init(e,t);const n=e._zod.bag;e.format=n.format??null,e.minLength=n.minimum??null,e.maxLength=n.maximum??null,e.regex=(...t)=>e.check(function(e,t){return new Zr({check:"string_format",format:"regex",...Un(t),pattern:e})}(...t)),e.includes=(...t)=>e.check(function(e,t){return new jr({check:"string_format",format:"includes",...Un(t),includes:e})}(...t)),e.startsWith=(...t)=>e.check(function(e,t){return new Fr({check:"string_format",format:"starts_with",...Un(t),prefix:e})}(...t)),e.endsWith=(...t)=>e.check(function(e,t){return new Dr({check:"string_format",format:"ends_with",...Un(t),suffix:e})}(...t)),e.min=(...t)=>e.check(lo(...t)),e.max=(...t)=>e.check(fo(...t)),e.length=(...t)=>e.check(ho(...t)),e.nonempty=(...t)=>e.check(lo(1,...t)),e.lowercase=t=>e.check(function(e){return new Rr({check:"string_format",format:"lowercase",...Un(e)})}(t)),e.uppercase=t=>e.check(function(e){return new Cr({check:"string_format",format:"uppercase",...Un(e)})}(t)),e.trim=()=>e.check(po(e=>e.trim())),e.normalize=(...t)=>e.check(function(e){return po(t=>t.normalize(e))}(...t)),e.toLowerCase=()=>e.check(po(e=>e.toLowerCase())),e.toUpperCase=()=>e.check(po(e=>e.toUpperCase()))}),$o=wn("ZodString",(e,t)=>{Mr.init(e,t),Po.init(e,t),e.email=t=>e.check(function(e,t){return new e({type:"string",format:"email",check:"string_format",abort:!1,...Un(t)})}(No,t)),e.url=t=>e.check(function(e,t){return new e({type:"string",format:"url",check:"string_format",abort:!1,...Un(t)})}(Zo,t)),e.jwt=t=>e.check(function(e,t){return new e({type:"string",format:"jwt",check:"string_format",abort:!1,...Un(t)})}(Xo,t)),e.emoji=t=>e.check(function(e,t){return new e({type:"string",format:"emoji",check:"string_format",abort:!1,...Un(t)})}(Ro,t)),e.guid=t=>e.check(io(Bo,t)),e.uuid=t=>e.check(function(e,t){return new e({type:"string",format:"uuid",check:"string_format",abort:!1,...Un(t)})}(Uo,t)),e.uuidv4=t=>e.check(function(e,t){return new e({type:"string",format:"uuid",check:"string_format",abort:!1,version:"v4",...Un(t)})}(Uo,t)),e.uuidv6=t=>e.check(function(e,t){return new e({type:"string",format:"uuid",check:"string_format",abort:!1,version:"v6",...Un(t)})}(Uo,t)),e.uuidv7=t=>e.check(function(e,t){return new e({type:"string",format:"uuid",check:"string_format",abort:!1,version:"v7",...Un(t)})}(Uo,t)),e.nanoid=t=>e.check(function(e,t){return new e({type:"string",format:"nanoid",check:"string_format",abort:!1,...Un(t)})}(Co,t)),e.guid=t=>e.check(io(Bo,t)),e.cuid=t=>e.check(function(e,t){return new e({type:"string",format:"cuid",check:"string_format",abort:!1,...Un(t)})}(jo,t)),e.cuid2=t=>e.check(function(e,t){return new e({type:"string",format:"cuid2",check:"string_format",abort:!1,...Un(t)})}(Fo,t)),e.ulid=t=>e.check(function(e,t){return new e({type:"string",format:"ulid",check:"string_format",abort:!1,...Un(t)})}(Do,t)),e.base64=t=>e.check(function(e,t){return new e({type:"string",format:"base64",check:"string_format",abort:!1,...Un(t)})}(Go,t)),e.base64url=t=>e.check(function(e,t){return new e({type:"string",format:"base64url",check:"string_format",abort:!1,...Un(t)})}(Wo,t)),e.xid=t=>e.check(function(e,t){return new e({type:"string",format:"xid",check:"string_format",abort:!1,...Un(t)})}(Lo,t)),e.ksuid=t=>e.check(function(e,t){return new e({type:"string",format:"ksuid",check:"string_format",abort:!1,...Un(t)})}(Ho,t)),e.ipv4=t=>e.check(function(e,t){return new e({type:"string",format:"ipv4",check:"string_format",abort:!1,...Un(t)})}(Vo,t)),e.ipv6=t=>e.check(function(e,t){return new e({type:"string",format:"ipv6",check:"string_format",abort:!1,...Un(t)})}(qo,t)),e.cidrv4=t=>e.check(function(e,t){return new e({type:"string",format:"cidrv4",check:"string_format",abort:!1,...Un(t)})}(Mo,t)),e.cidrv6=t=>e.check(function(e,t){return new e({type:"string",format:"cidrv6",check:"string_format",abort:!1,...Un(t)})}(Ko,t)),e.e164=t=>e.check(function(e,t){return new e({type:"string",format:"e164",check:"string_format",abort:!1,...Un(t)})}(Yo,t)),e.datetime=t=>e.check(go(t)),e.date=t=>e.check(_o(t)),e.time=t=>e.check(vo(t)),e.duration=t=>e.check(Eo(t))});function Io(e){return function(e,t){return new e({type:"string",...Un(t)})}($o,e)}const To=wn("ZodStringFormat",(e,t)=>{Kr.init(e,t),Po.init(e,t)}),No=wn("ZodEmail",(e,t)=>{Yr.init(e,t),To.init(e,t)}),Bo=wn("ZodGUID",(e,t)=>{Gr.init(e,t),To.init(e,t)}),Uo=wn("ZodUUID",(e,t)=>{Wr.init(e,t),To.init(e,t)}),Zo=wn("ZodURL",(e,t)=>{Xr.init(e,t),To.init(e,t)}),Ro=wn("ZodEmoji",(e,t)=>{Jr.init(e,t),To.init(e,t)}),Co=wn("ZodNanoID",(e,t)=>{Qr.init(e,t),To.init(e,t)}),jo=wn("ZodCUID",(e,t)=>{ei.init(e,t),To.init(e,t)}),Fo=wn("ZodCUID2",(e,t)=>{ti.init(e,t),To.init(e,t)}),Do=wn("ZodULID",(e,t)=>{ni.init(e,t),To.init(e,t)}),Lo=wn("ZodXID",(e,t)=>{ri.init(e,t),To.init(e,t)}),Ho=wn("ZodKSUID",(e,t)=>{ii.init(e,t),To.init(e,t)}),Vo=wn("ZodIPv4",(e,t)=>{ci.init(e,t),To.init(e,t)}),qo=wn("ZodIPv6",(e,t)=>{fi.init(e,t),To.init(e,t)}),Mo=wn("ZodCIDRv4",(e,t)=>{di.init(e,t),To.init(e,t)}),Ko=wn("ZodCIDRv6",(e,t)=>{li.init(e,t),To.init(e,t)}),Go=wn("ZodBase64",(e,t)=>{pi.init(e,t),To.init(e,t)}),Wo=wn("ZodBase64URL",(e,t)=>{mi.init(e,t),To.init(e,t)}),Yo=wn("ZodE164",(e,t)=>{gi.init(e,t),To.init(e,t)}),Xo=wn("ZodJWT",(e,t)=>{wi.init(e,t),To.init(e,t)}),Jo=wn("ZodNumber",(e,t)=>{_i.init(e,t),So.init(e,t),e.gt=(t,n)=>e.check(uo(t,n)),e.gte=(t,n)=>e.check(ao(t,n)),e.min=(t,n)=>e.check(ao(t,n)),e.lt=(t,n)=>e.check(oo(t,n)),e.lte=(t,n)=>e.check(so(t,n)),e.max=(t,n)=>e.check(so(t,n)),e.int=t=>e.check(ts(t)),e.safe=t=>e.check(ts(t)),e.positive=t=>e.check(uo(0,t)),e.nonnegative=t=>e.check(ao(0,t)),e.negative=t=>e.check(oo(0,t)),e.nonpositive=t=>e.check(so(0,t)),e.multipleOf=(t,n)=>e.check(co(t,n)),e.step=(t,n)=>e.check(co(t,n)),e.finite=()=>e;const n=e._zod.bag;e.minValue=Math.max(n.minimum??Number.NEGATIVE_INFINITY,n.exclusiveMinimum??Number.NEGATIVE_INFINITY)??null,e.maxValue=Math.min(n.maximum??Number.POSITIVE_INFINITY,n.exclusiveMaximum??Number.POSITIVE_INFINITY)??null,e.isInt=(n.format??"").includes("int")||Number.isSafeInteger(n.multipleOf??.5),e.isFinite=!0,e.format=n.format??null});function Qo(e){return function(e,t){return new e({type:"number",checks:[],...Un(t)})}(Jo,e)}const es=wn("ZodNumberFormat",(e,t)=>{yi.init(e,t),Jo.init(e,t)});function ts(e){return function(e,t){return new e({type:"number",check:"number_format",abort:!1,format:"safeint",...Un(t)})}(es,e)}const ns=wn("ZodBoolean",(e,t)=>{vi.init(e,t),So.init(e,t)});function rs(e){return function(e,t){return new e({type:"boolean",...Un(t)})}(ns,e)}const is=wn("ZodBigInt",(e,t)=>{bi.init(e,t),So.init(e,t),e.gte=(t,n)=>e.check(ao(t,n)),e.min=(t,n)=>e.check(ao(t,n)),e.gt=(t,n)=>e.check(uo(t,n)),e.gte=(t,n)=>e.check(ao(t,n)),e.min=(t,n)=>e.check(ao(t,n)),e.lt=(t,n)=>e.check(oo(t,n)),e.lte=(t,n)=>e.check(so(t,n)),e.max=(t,n)=>e.check(so(t,n)),e.positive=t=>e.check(uo(BigInt(0),t)),e.negative=t=>e.check(oo(BigInt(0),t)),e.nonpositive=t=>e.check(so(BigInt(0),t)),e.nonnegative=t=>e.check(ao(BigInt(0),t)),e.multipleOf=(t,n)=>e.check(co(t,n));const n=e._zod.bag;e.minValue=n.minimum??null,e.maxValue=n.maximum??null,e.format=n.format??null});function os(e){return function(e,t){return new e({type:"bigint",...Un(t)})}(is,e)}const ss=wn("ZodNull",(e,t)=>{Ei.init(e,t),So.init(e,t)});const us=wn("ZodAny",(e,t)=>{xi.init(e,t),So.init(e,t)});const as=wn("ZodUnknown",(e,t)=>{zi.init(e,t),So.init(e,t)});function cs(){return new as({type:"unknown"})}const fs=wn("ZodNever",(e,t)=>{ki.init(e,t),So.init(e,t)});function ds(e){return function(e,t){return new e({type:"never",...Un(t)})}(fs,e)}const ls=wn("ZodDate",(e,t)=>{Oi.init(e,t),So.init(e,t),e.min=(t,n)=>e.check(ao(t,n)),e.max=(t,n)=>e.check(so(t,n));const n=e._zod.bag;e.minDate=n.minimum?new Date(n.minimum):null,e.maxDate=n.maximum?new Date(n.maximum):null});const hs=wn("ZodArray",(e,t)=>{Si.init(e,t),So.init(e,t),e.element=t.element,e.min=(t,n)=>e.check(lo(t,n)),e.nonempty=t=>e.check(lo(1,t)),e.max=(t,n)=>e.check(fo(t,n)),e.length=(t,n)=>e.check(ho(t,n)),e.unwrap=()=>e.element});function ps(e,t){return function(e,t,n){return new e({type:"array",element:t,...Un(n)})}(hs,e,t)}const ms=wn("ZodObject",(e,t)=>{Ii.init(e,t),So.init(e,t),kn(e,"shape",()=>t.shape),e.keyof=()=>function(e,t){const n=Array.isArray(e)?Object.fromEntries(e.map(e=>[e,e])):e;return new Es({type:"enum",entries:n,...Un(t)})}(Object.keys(e._zod.def.shape)),e.catchall=t=>e.clone({...e._zod.def,catchall:t}),e.passthrough=()=>e.clone({...e._zod.def,catchall:cs()}),e.loose=()=>e.clone({...e._zod.def,catchall:cs()}),e.strict=()=>e.clone({...e._zod.def,catchall:ds()}),e.strip=()=>e.clone({...e._zod.def,catchall:void 0}),e.extend=t=>function(e,t){if(!In(t))throw new Error("Invalid input to extend: expected a plain object");const n={...e._zod.def,get shape(){const n={...e._zod.def.shape,...t};return On(this,"shape",n),n},checks:[]};return Bn(e,n)}(e,t),e.merge=t=>{return r=t,Bn(n=e,{...n._zod.def,get shape(){const e={...n._zod.def.shape,...r._zod.def.shape};return On(this,"shape",e),e},catchall:r._zod.def.catchall,checks:[]});var n,r},e.pick=t=>function(e,t){const n={},r=e._zod.def;for(const e in t){if(!(e in r.shape))throw new Error(`Unrecognized key: "${e}"`);t[e]&&(n[e]=r.shape[e])}return Bn(e,{...e._zod.def,shape:n,checks:[]})}(e,t),e.omit=t=>function(e,t){const n={...e._zod.def.shape},r=e._zod.def;for(const e in t){if(!(e in r.shape))throw new Error(`Unrecognized key: "${e}"`);t[e]&&delete n[e]}return Bn(e,{...e._zod.def,shape:n,checks:[]})}(e,t),e.partial=(...t)=>function(e,t,n){const r=t._zod.def.shape,i={...r};if(n)for(const t in n){if(!(t in r))throw new Error(`Unrecognized key: "${t}"`);n[t]&&(i[t]=e?new e({type:"optional",innerType:r[t]}):r[t])}else for(const t in r)i[t]=e?new e({type:"optional",innerType:r[t]}):r[t];return Bn(t,{...t._zod.def,shape:i,checks:[]})}(zs,e,t[0]),e.required=(...t)=>function(e,t,n){const r=t._zod.def.shape,i={...r};if(n)for(const t in n){if(!(t in i))throw new Error(`Unrecognized key: "${t}"`);n[t]&&(i[t]=new e({type:"nonoptional",innerType:r[t]}))}else for(const t in r)i[t]=new e({type:"nonoptional",innerType:r[t]});return Bn(t,{...t._zod.def,shape:i,checks:[]})}($s,e,t[0])});function gs(e,t){const n={type:"object",get shape(){return On(this,"shape",{...e}),this.shape},...Un(t)};return new ms(n)}const ws=wn("ZodUnion",(e,t)=>{Ni.init(e,t),So.init(e,t),e.options=t.options});function _s(e,t){return new ws({type:"union",options:e,...Un(t)})}const ys=wn("ZodIntersection",(e,t)=>{Bi.init(e,t),So.init(e,t)});const vs=wn("ZodRecord",(e,t)=>{Ri.init(e,t),So.init(e,t),e.keyType=t.keyType,e.valueType=t.valueType});function bs(e,t,n){return new vs({type:"record",keyType:e,valueType:t,...Un(n)})}const Es=wn("ZodEnum",(e,t)=>{Ci.init(e,t),So.init(e,t),e.enum=t.entries,e.options=Object.values(t.entries);const n=new Set(Object.keys(t.entries));e.extract=(e,r)=>{const i={};for(const r of e){if(!n.has(r))throw new Error(`Key ${r} not found in enum`);i[r]=t.entries[r]}return new Es({...t,checks:[],...Un(r),entries:i})},e.exclude=(e,r)=>{const i={...t.entries};for(const t of e){if(!n.has(t))throw new Error(`Key ${t} not found in enum`);delete i[t]}return new Es({...t,checks:[],...Un(r),entries:i})}});const xs=wn("ZodTransform",(e,t)=>{ji.init(e,t),So.init(e,t),e._zod.parse=(n,r)=>{n.addIssue=r=>{if("string"==typeof r)n.issues.push(Ln(r,n.value,t));else{const t=r;t.fatal&&(t.continue=!1),t.code??(t.code="custom"),t.input??(t.input=n.value),t.inst??(t.inst=e),t.continue??(t.continue=!0),n.issues.push(Ln(t))}};const i=t.transform(n.value,n);return i instanceof Promise?i.then(e=>(n.value=e,n)):(n.value=i,n)}});const zs=wn("ZodOptional",(e,t)=>{Fi.init(e,t),So.init(e,t),e.unwrap=()=>e._zod.def.innerType});function ks(e){return new zs({type:"optional",innerType:e})}const Os=wn("ZodNullable",(e,t)=>{Di.init(e,t),So.init(e,t),e.unwrap=()=>e._zod.def.innerType});function As(e){return new Os({type:"nullable",innerType:e})}const Ss=wn("ZodDefault",(e,t)=>{Li.init(e,t),So.init(e,t),e.unwrap=()=>e._zod.def.innerType,e.removeDefault=e.unwrap});const Ps=wn("ZodPrefault",(e,t)=>{Vi.init(e,t),So.init(e,t),e.unwrap=()=>e._zod.def.innerType});const $s=wn("ZodNonOptional",(e,t)=>{qi.init(e,t),So.init(e,t),e.unwrap=()=>e._zod.def.innerType});const Is=wn("ZodCatch",(e,t)=>{Ki.init(e,t),So.init(e,t),e.unwrap=()=>e._zod.def.innerType,e.removeCatch=e.unwrap});const Ts=wn("ZodPipe",(e,t)=>{Gi.init(e,t),So.init(e,t),e.in=t.in,e.out=t.out});function Ns(e,t){return new Ts({type:"pipe",in:e,out:t})}const Bs=wn("ZodReadonly",(e,t)=>{Yi.init(e,t),So.init(e,t)});const Us=wn("ZodLazy",(e,t)=>{Ji.init(e,t),So.init(e,t),e.unwrap=()=>e._zod.def.getter()});const Zs=wn("ZodCustom",(e,t)=>{Qi.init(e,t),So.init(e,t)});var Rs;os(),rs(),function(e,t){new e({type:"date",...Un(t)})}(ls,Rs);const Cs=Qo().min(Number.MIN_SAFE_INTEGER).max(Number.MAX_SAFE_INTEGER).int(),js=function(e,t={error:`Input not instance of ${e.name}`}){const n=new Zs({type:"custom",check:"custom",fn:t=>t instanceof e,abort:!0,...Un(t)});return n._zod.bag.Class=e,n}(Uint8Array),Fs=Io();Cs.min(5e8),new us({type:"any"}),Cs.min(0).max(255),Cs.min(0).max(65535);const Ds=Cs.min(0).max(4294967295);Qo().refine(e=>String(e).includes(".")).refine(e=>{const t=String(e).split(".").at(1);return void 0!==t&&t.length<=2});const Ls=Io().regex(/^[0-9a-fA-F]*$/).refine(e=>e.length%2==0),Hs=_s([Io(),Qo(),rs(),function(e){return function(e,t){return new e({type:"null",...Un(t)})}(ss,e)}()]),Vs=new Us({type:"lazy",getter:()=>_s([Hs,ps(Vs),bs(Fs,Vs)])});js.refine(e=>20===e.length);const qs=js.refine(e=>32===e.length),Ms=js.refine(e=>33===e.length),Ks=js.refine(e=>64===e.length);Ls.refine(e=>40===e.length);const Gs=Ls.refine(e=>64===e.length),Ws=Ls.refine(e=>66===e.length),Ys=Ls.refine(e=>128===e.length);_s([Ls,js]);const Xs=_s([Gs,qs]);
11
+ const bt={p:BigInt("0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f"),n:BigInt("0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141"),h:BigInt(1),a:BigInt(0),b:BigInt(7),Gx:BigInt("0x79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798"),Gy:BigInt("0x483ada7726a3c4655da4fbfc0e1108a8fd17b448a68554199c47d08ffb10d4b8")},Et={beta:BigInt("0x7ae96a2b657c07106e64479eac3434e99cf0497512f58995c1396c28719501ee"),basises:[[BigInt("0x3086d221a7d46bcde86c90e49284eb15"),-BigInt("0xe4437ed6010e88286f547fa90abfe4c3")],[BigInt("0x114ca50f7a8e2f3f657c1108d9d44cfd8"),BigInt("0x3086d221a7d46bcde86c90e49284eb15")]]},xt=BigInt(0),zt=BigInt(1),kt=BigInt(2);function Ot(e){const t=bt.p,n=BigInt(3),r=BigInt(6),i=BigInt(11),o=BigInt(22),s=BigInt(23),u=BigInt(44),c=BigInt(88),a=e*e*e%t,f=a*a*e%t,d=Te(f,n,t)*f%t,l=Te(d,n,t)*f%t,h=Te(l,kt,t)*a%t,p=Te(h,i,t)*h%t,m=Te(p,o,t)*p%t,g=Te(m,u,t)*m%t,_=Te(g,c,t)*g%t,w=Te(_,u,t)*m%t,y=Te(w,n,t)*f%t,v=Te(y,s,t)*p%t,b=Te(v,r,t)*a%t,E=Te(b,kt,t);if(!Pt.eql(Pt.sqr(E),e))throw new Error("Cannot find square root");return E}const Pt=De(bt.p,void 0,void 0,{sqrt:Ot}),St=function(e,t){const n=t=>vt({...e,hash:t});return{...n(t),create:n}}({...bt,Fp:Pt,lowS:!0,endo:Et},te),At={};function It(e,...t){let n=At[e];if(void 0===n){const t=te(Uint8Array.from(e,e=>e.charCodeAt(0)));n=V(t,t),At[e]=n}return te(V(n,...t))}const $t=e=>e.toBytes(!0).slice(1),Tt=e=>de(e,32),Nt=e=>$e(e,bt.p),Bt=e=>$e(e,bt.n),Ut=(()=>St.Point)(),Zt=e=>e%kt===xt;function Rt(e){let t=mt(Ut.Fn,e),n=Ut.BASE.multiply(t);return{scalar:Zt(n.y)?t:Bt(-t),bytes:$t(n)}}function Ct(e){ge("x",e,zt,bt.p);const t=Nt(e*e);let n=Ot(Nt(t*e+BigInt(7)));Zt(n)||(n=Nt(-n));const r=Ut.fromAffine({x:e,y:n});return r.assertValidity(),r}const jt=ae;function Ft(...e){return Bt(jt(It("BIP0340/challenge",...e)))}function Ht(e){return Rt(e).bytes}function Dt(e,t,n=K(32)){const r=he("message",e),{bytes:i,scalar:o}=Rt(t),s=he("auxRand",n,32),u=Tt(o^jt(It("BIP0340/aux",s))),c=It("BIP0340/nonce",u,i,r),a=Bt(jt(c));if(a===xt)throw new Error("sign failed: k is zero");const{bytes:f,scalar:d}=Rt(a),l=Ft(f,i,r),h=new Uint8Array(64);if(h.set(f,0),h.set(Tt(Bt(d+l*o)),32),!Lt(h,r,i))throw new Error("sign: Invalid signature produced");return h}function Lt(e,t,n){const r=he("signature",e,64),i=he("message",t),o=he("publicKey",n,32);try{const e=Ct(jt(o)),t=jt(r.subarray(0,32));if(!me(t,zt,bt.p))return!1;const n=jt(r.subarray(32,64));if(!me(n,zt,bt.n))return!1;const s=Ft(Tt(t),$t(e),i),u=Ut.BASE.multiplyUnsafe(n).add(e.multiplyUnsafe(Bt(-s))),{x:c,y:a}=u.toAffine();return!(u.is0()||!Zt(a)||c!==t)}catch(e){return!1}}const Vt=(()=>{const e=(e=K(48))=>qe(e,bt.n);return{keygen:function(t){const n=e(t);return{secretKey:n,publicKey:Ht(n)}},getPublicKey:Ht,sign:Dt,verify:Lt,Point:Ut,utils:{randomSecretKey:e,randomPrivateKey:e,taggedHash:It,lift_x:Ct,pointToBytes:$t,numberToBytesBE:de,bytesToNumberBE:ae,mod:$e},info:{type:"weierstrass",publicKeyHasPrefix:!1,lengths:{secret:32,public:32,signature:64,seed:48}}}})(),qt=BigInt(0),Mt=BigInt(2);De(St.CURVE.n,32,!0);const Kt=St.Point.BASE;function Wt(e,t,n,r=!1){const i=Yt(t).big,o=function(e){try{const t=Gt(e,"ecdsa");return St.Point.fromHex(t)}catch(t){throw new Error("invalid pubkey: "+e)}}(e),s=Kt.multiply(i);let u=o.add(s);r&&u.y%Mt!==qt&&(u=u.negate());return Gt(u.toHex(!0),n)}function Gt(e,t){try{const n=Yt(e);if(33===n.length&&"bip340"===t)return n.slice(1);if(32===n.length&&"ecdsa"===t){const e=g.num(2,1);return g.join([e,n])}return n}catch(t){throw new Error("invalid pubkey: "+String(e))}}function Yt(e){try{return g.bytes(e)}catch(t){throw new Error("invalid bytes: "+String(e))}}const Xt=Uint8Array.from([7,4,13,1,10,6,15,3,12,0,9,5,2,14,11,8]),Jt=(()=>Uint8Array.from(new Array(16).fill(0).map((e,t)=>t)))(),Qt=(()=>Jt.map(e=>(9*e+5)%16))(),en=(()=>{const e=[[Jt],[Qt]];for(let t=0;t<4;t++)for(let n of e)n.push(n[t].map(e=>Xt[e]));return e})(),tn=(()=>en[0])(),nn=(()=>en[1])(),rn=[[11,14,15,12,5,8,7,9,11,13,14,15,6,7,9,8],[12,13,11,15,6,9,9,7,12,15,11,13,7,8,7,7],[13,15,14,11,7,7,6,8,13,14,13,12,5,5,6,9],[14,11,12,14,8,6,5,5,15,12,15,14,9,9,8,6],[15,12,13,13,9,5,8,6,14,11,12,11,8,6,5,5]].map(e=>Uint8Array.from(e)),on=tn.map((e,t)=>e.map(e=>rn[t][e])),sn=nn.map((e,t)=>e.map(e=>rn[t][e])),un=Uint32Array.from([0,1518500249,1859775393,2400959708,2840853838]),cn=Uint32Array.from([1352829926,1548603684,1836072691,2053994217,0]);function an(e,t,n,r){return 0===e?t^n^r:1===e?t&n|~t&r:2===e?(t|~n)^r:3===e?t&r|n&~r:t^(n|~r)}const fn=new Uint32Array(16);class dn extends Y{constructor(){super(64,20,8,!0),this.h0=1732584193,this.h1=-271733879,this.h2=-1732584194,this.h3=271733878,this.h4=-1009589776}get(){const{h0:e,h1:t,h2:n,h3:r,h4:i}=this;return[e,t,n,r,i]}set(e,t,n,r,i){this.h0=0|e,this.h1=0|t,this.h2=0|n,this.h3=0|r,this.h4=0|i}process(e,t){for(let n=0;n<16;n++,t+=4)fn[n]=e.getUint32(t,!0);let n=0|this.h0,r=n,i=0|this.h1,o=i,s=0|this.h2,u=s,c=0|this.h3,a=c,f=0|this.h4,d=f;for(let e=0;e<5;e++){const t=4-e,l=un[e],h=cn[e],p=tn[e],m=nn[e],g=on[e],_=sn[e];for(let t=0;t<16;t++){const r=$(n+an(e,i,s,c)+fn[p[t]]+l,g[t])+f|0;n=f,f=c,c=0|$(s,10),s=i,i=r}for(let e=0;e<16;e++){const n=$(r+an(t,o,u,a)+fn[m[e]]+h,_[e])+d|0;r=d,d=a,a=0|$(u,10),u=o,o=n}}this.set(this.h1+s+a|0,this.h2+c+d|0,this.h3+f+r|0,this.h4+n+o|0,this.h0+i+u|0)}roundClean(){S(fn)}destroy(){this.destroyed=!0,S(this.buffer),this.set(0,0,0,0,0)}}const ln=M(()=>new dn);function hn(...e){const t=g.join(e),n=ln(te(t));return new g(n)}function pn(...e){const t=g.join(e),n=te(t);return new g(n)}function mn(...e){const t=g.join(e),n=te(te(t));return new g(n)}function gn(e,...t){const n=function(e){const t=pn(g.str(e));return g.join([t,t])}(e),r=t.map(e=>new g(e));return pn(g.join([n,...r]))}function _n(e,t,n){function r(n,r){var i;Object.defineProperty(n,"_zod",{value:n._zod??{},enumerable:!1}),(i=n._zod).traits??(i.traits=new Set),n._zod.traits.add(e),t(n,r);for(const e in s.prototype)e in n||Object.defineProperty(n,e,{value:s.prototype[e].bind(n)});n._zod.constr=s,n._zod.def=r}const i=n?.Parent??Object;class o extends i{}function s(e){var t;const i=n?.Parent?new o:this;r(i,e),(t=i._zod).deferred??(t.deferred=[]);for(const e of i._zod.deferred)e();return i}return Object.defineProperty(o,"name",{value:e}),Object.defineProperty(s,"init",{value:r}),Object.defineProperty(s,Symbol.hasInstance,{value:t=>!!(n?.Parent&&t instanceof n.Parent)||t?._zod?.traits?.has(e)}),Object.defineProperty(s,"name",{value:e}),s}class wn extends Error{constructor(){super("Encountered Promise during synchronous parse. Use .parseAsync() instead.")}}const yn={};function vn(e){return yn}function bn(e,t){return"bigint"==typeof t?t.toString():t}function En(e){return{get value(){{const t=e();return Object.defineProperty(this,"value",{value:t}),t}}}}function xn(e){return null==e}function zn(e){const t=e.startsWith("^")?1:0,n=e.endsWith("$")?e.length-1:e.length;return e.slice(t,n)}function kn(e,t,n){Object.defineProperty(e,t,{get(){{const r=n();return e[t]=r,r}},set(n){Object.defineProperty(e,t,{value:n})},configurable:!0})}function On(e,t,n){Object.defineProperty(e,t,{value:n,writable:!0,enumerable:!0,configurable:!0})}function Pn(e){return JSON.stringify(e)}const Sn=Error.captureStackTrace?Error.captureStackTrace:(...e)=>{};function An(e){return"object"==typeof e&&null!==e&&!Array.isArray(e)}const In=En(()=>{if("undefined"!=typeof navigator&&navigator?.userAgent?.includes("Cloudflare"))return!1;try{return new Function(""),!0}catch(e){return!1}});function $n(e){if(!1===An(e))return!1;const t=e.constructor;if(void 0===t)return!0;const n=t.prototype;return!1!==An(n)&&!1!==Object.prototype.hasOwnProperty.call(n,"isPrototypeOf")}const Tn=new Set(["string","number","symbol"]);function Nn(e){return e.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}function Bn(e,t,n){const r=new e._zod.constr(t??e._zod.def);return t&&!n?.parent||(r._zod.parent=e),r}function Un(e){const t=e;if(!t)return{};if("string"==typeof t)return{error:()=>t};if(void 0!==t?.message){if(void 0!==t?.error)throw new Error("Cannot specify both `message` and `error` params");t.error=t.message}return delete t.message,"string"==typeof t.error?{...t,error:()=>t.error}:t}const Zn={safeint:[Number.MIN_SAFE_INTEGER,Number.MAX_SAFE_INTEGER],int32:[-2147483648,2147483647],uint32:[0,4294967295],float32:[-34028234663852886e22,34028234663852886e22],float64:[-Number.MAX_VALUE,Number.MAX_VALUE]};function Rn(e,t=0){for(let n=t;n<e.issues.length;n++)if(!0!==e.issues[n]?.continue)return!0;return!1}function Cn(e,t){return t.map(t=>{var n;return(n=t).path??(n.path=[]),t.path.unshift(e),t})}function jn(e){return"string"==typeof e?e:e?.message}function Fn(e,t,n){const r={...e,path:e.path??[]};if(!e.message){const i=jn(e.inst?._zod.def?.error?.(e))??jn(t?.error?.(e))??jn(n.customError?.(e))??jn(n.localeError?.(e))??"Invalid input";r.message=i}return delete r.inst,delete r.continue,t?.reportInput||delete r.input,r}function Hn(e){return Array.isArray(e)?"array":"string"==typeof e?"string":"unknown"}function Dn(...e){const[t,n,r]=e;return"string"==typeof t?{message:t,code:"custom",input:n,inst:r}:{...t}}const Ln=(e,t)=>{e.name="$ZodError",Object.defineProperty(e,"_zod",{value:e._zod,enumerable:!1}),Object.defineProperty(e,"issues",{value:t,enumerable:!1}),Object.defineProperty(e,"message",{get:()=>JSON.stringify(t,bn,2),enumerable:!0}),Object.defineProperty(e,"toString",{value:()=>e.message,enumerable:!1})},Vn=_n("$ZodError",Ln),qn=_n("$ZodError",Ln,{Parent:Error});const Mn=e=>(t,n,r,i)=>{const o=r?Object.assign(r,{async:!1}):{async:!1},s=t._zod.run({value:n,issues:[]},o);if(s instanceof Promise)throw new wn;if(s.issues.length){const t=new(i?.Err??e)(s.issues.map(e=>Fn(e,o,vn())));throw Sn(t,i?.callee),t}return s.value},Kn=e=>async(t,n,r,i)=>{const o=r?Object.assign(r,{async:!0}):{async:!0};let s=t._zod.run({value:n,issues:[]},o);if(s instanceof Promise&&(s=await s),s.issues.length){const t=new(i?.Err??e)(s.issues.map(e=>Fn(e,o,vn())));throw Sn(t,i?.callee),t}return s.value},Wn=e=>(t,n,r)=>{const i=r?{...r,async:!1}:{async:!1},o=t._zod.run({value:n,issues:[]},i);if(o instanceof Promise)throw new wn;return o.issues.length?{success:!1,error:new(e??Vn)(o.issues.map(e=>Fn(e,i,vn())))}:{success:!0,data:o.value}},Gn=Wn(qn),Yn=e=>async(t,n,r)=>{const i=r?Object.assign(r,{async:!0}):{async:!0};let o=t._zod.run({value:n,issues:[]},i);return o instanceof Promise&&(o=await o),o.issues.length?{success:!1,error:new e(o.issues.map(e=>Fn(e,i,vn())))}:{success:!0,data:o.value}},Xn=Yn(qn),Jn=/^[cC][^\s-]{8,}$/,Qn=/^[0-9a-z]+$/,er=/^[0-9A-HJKMNP-TV-Za-hjkmnp-tv-z]{26}$/,tr=/^[0-9a-vA-V]{20}$/,nr=/^[A-Za-z0-9]{27}$/,rr=/^[a-zA-Z0-9_-]{21}$/,ir=/^P(?:(\d+W)|(?!.*W)(?=\d|T\d)(\d+Y)?(\d+M)?(\d+D)?(T(?=\d)(\d+H)?(\d+M)?(\d+([.,]\d+)?S)?)?)$/,or=/^([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12})$/,sr=e=>e?new RegExp(`^([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-${e}[0-9a-fA-F]{3}-[89abAB][0-9a-fA-F]{3}-[0-9a-fA-F]{12})$`):/^([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[1-8][0-9a-fA-F]{3}-[89abAB][0-9a-fA-F]{3}-[0-9a-fA-F]{12}|00000000-0000-0000-0000-000000000000)$/,ur=/^(?!\.)(?!.*\.\.)([A-Za-z0-9_'+\-\.]*)[A-Za-z0-9_+-]@([A-Za-z0-9][A-Za-z0-9\-]*\.)+[A-Za-z]{2,}$/;const cr=/^(?:(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\.){3}(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])$/,ar=/^(([0-9a-fA-F]{1,4}:){7}[0-9a-fA-F]{1,4}|::|([0-9a-fA-F]{1,4})?::([0-9a-fA-F]{1,4}:?){0,6})$/,fr=/^((25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\.){3}(25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\/([0-9]|[1-2][0-9]|3[0-2])$/,dr=/^(([0-9a-fA-F]{1,4}:){7}[0-9a-fA-F]{1,4}|::|([0-9a-fA-F]{1,4})?::([0-9a-fA-F]{1,4}:?){0,6})\/(12[0-8]|1[01][0-9]|[1-9]?[0-9])$/,lr=/^$|^(?:[0-9a-zA-Z+/]{4})*(?:(?:[0-9a-zA-Z+/]{2}==)|(?:[0-9a-zA-Z+/]{3}=))?$/,hr=/^[A-Za-z0-9_-]*$/,pr=/^([a-zA-Z0-9-]+\.)*[a-zA-Z0-9-]+$/,mr=/^\+(?:[0-9]){6,14}[0-9]$/,gr="(?:(?:\\d\\d[2468][048]|\\d\\d[13579][26]|\\d\\d0[48]|[02468][048]00|[13579][26]00)-02-29|\\d{4}-(?:(?:0[13578]|1[02])-(?:0[1-9]|[12]\\d|3[01])|(?:0[469]|11)-(?:0[1-9]|[12]\\d|30)|(?:02)-(?:0[1-9]|1\\d|2[0-8])))",_r=new RegExp(`^${gr}$`);function wr(e){const t="(?:[01]\\d|2[0-3]):[0-5]\\d";return"number"==typeof e.precision?-1===e.precision?`${t}`:0===e.precision?`${t}:[0-5]\\d`:`${t}:[0-5]\\d\\.\\d{${e.precision}}`:`${t}(?::[0-5]\\d(?:\\.\\d+)?)?`}const yr=/^\d+n?$/,vr=/^\d+$/,br=/^-?\d+(?:\.\d+)?/i,Er=/true|false/i,xr=/null/i,zr=/^[^A-Z]*$/,kr=/^[^a-z]*$/,Or=_n("$ZodCheck",(e,t)=>{var n;e._zod??(e._zod={}),e._zod.def=t,(n=e._zod).onattach??(n.onattach=[])}),Pr={number:"number",bigint:"bigint",object:"date"},Sr=_n("$ZodCheckLessThan",(e,t)=>{Or.init(e,t);const n=Pr[typeof t.value];e._zod.onattach.push(e=>{const n=e._zod.bag,r=(t.inclusive?n.maximum:n.exclusiveMaximum)??Number.POSITIVE_INFINITY;t.value<r&&(t.inclusive?n.maximum=t.value:n.exclusiveMaximum=t.value)}),e._zod.check=r=>{(t.inclusive?r.value<=t.value:r.value<t.value)||r.issues.push({origin:n,code:"too_big",maximum:t.value,input:r.value,inclusive:t.inclusive,inst:e,continue:!t.abort})}}),Ar=_n("$ZodCheckGreaterThan",(e,t)=>{Or.init(e,t);const n=Pr[typeof t.value];e._zod.onattach.push(e=>{const n=e._zod.bag,r=(t.inclusive?n.minimum:n.exclusiveMinimum)??Number.NEGATIVE_INFINITY;t.value>r&&(t.inclusive?n.minimum=t.value:n.exclusiveMinimum=t.value)}),e._zod.check=r=>{(t.inclusive?r.value>=t.value:r.value>t.value)||r.issues.push({origin:n,code:"too_small",minimum:t.value,input:r.value,inclusive:t.inclusive,inst:e,continue:!t.abort})}}),Ir=_n("$ZodCheckMultipleOf",(e,t)=>{Or.init(e,t),e._zod.onattach.push(e=>{var n;(n=e._zod.bag).multipleOf??(n.multipleOf=t.value)}),e._zod.check=n=>{if(typeof n.value!=typeof t.value)throw new Error("Cannot mix number and bigint in multiple_of check.");("bigint"==typeof n.value?n.value%t.value===BigInt(0):0===function(e,t){const n=(e.toString().split(".")[1]||"").length,r=(t.toString().split(".")[1]||"").length,i=n>r?n:r;return Number.parseInt(e.toFixed(i).replace(".",""))%Number.parseInt(t.toFixed(i).replace(".",""))/10**i}(n.value,t.value))||n.issues.push({origin:typeof n.value,code:"not_multiple_of",divisor:t.value,input:n.value,inst:e,continue:!t.abort})}}),$r=_n("$ZodCheckNumberFormat",(e,t)=>{Or.init(e,t),t.format=t.format||"float64";const n=t.format?.includes("int"),r=n?"int":"number",[i,o]=Zn[t.format];e._zod.onattach.push(e=>{const r=e._zod.bag;r.format=t.format,r.minimum=i,r.maximum=o,n&&(r.pattern=vr)}),e._zod.check=s=>{const u=s.value;if(n){if(!Number.isInteger(u))return void s.issues.push({expected:r,format:t.format,code:"invalid_type",input:u,inst:e});if(!Number.isSafeInteger(u))return void(u>0?s.issues.push({input:u,code:"too_big",maximum:Number.MAX_SAFE_INTEGER,note:"Integers must be within the safe integer range.",inst:e,origin:r,continue:!t.abort}):s.issues.push({input:u,code:"too_small",minimum:Number.MIN_SAFE_INTEGER,note:"Integers must be within the safe integer range.",inst:e,origin:r,continue:!t.abort}))}u<i&&s.issues.push({origin:"number",input:u,code:"too_small",minimum:i,inclusive:!0,inst:e,continue:!t.abort}),u>o&&s.issues.push({origin:"number",input:u,code:"too_big",maximum:o,inst:e})}}),Tr=_n("$ZodCheckMaxLength",(e,t)=>{var n;Or.init(e,t),(n=e._zod.def).when??(n.when=e=>{const t=e.value;return!xn(t)&&void 0!==t.length}),e._zod.onattach.push(e=>{const n=e._zod.bag.maximum??Number.POSITIVE_INFINITY;t.maximum<n&&(e._zod.bag.maximum=t.maximum)}),e._zod.check=n=>{const r=n.value;if(r.length<=t.maximum)return;const i=Hn(r);n.issues.push({origin:i,code:"too_big",maximum:t.maximum,inclusive:!0,input:r,inst:e,continue:!t.abort})}}),Nr=_n("$ZodCheckMinLength",(e,t)=>{var n;Or.init(e,t),(n=e._zod.def).when??(n.when=e=>{const t=e.value;return!xn(t)&&void 0!==t.length}),e._zod.onattach.push(e=>{const n=e._zod.bag.minimum??Number.NEGATIVE_INFINITY;t.minimum>n&&(e._zod.bag.minimum=t.minimum)}),e._zod.check=n=>{const r=n.value;if(r.length>=t.minimum)return;const i=Hn(r);n.issues.push({origin:i,code:"too_small",minimum:t.minimum,inclusive:!0,input:r,inst:e,continue:!t.abort})}}),Br=_n("$ZodCheckLengthEquals",(e,t)=>{var n;Or.init(e,t),(n=e._zod.def).when??(n.when=e=>{const t=e.value;return!xn(t)&&void 0!==t.length}),e._zod.onattach.push(e=>{const n=e._zod.bag;n.minimum=t.length,n.maximum=t.length,n.length=t.length}),e._zod.check=n=>{const r=n.value,i=r.length;if(i===t.length)return;const o=Hn(r),s=i>t.length;n.issues.push({origin:o,...s?{code:"too_big",maximum:t.length}:{code:"too_small",minimum:t.length},inclusive:!0,exact:!0,input:n.value,inst:e,continue:!t.abort})}}),Ur=_n("$ZodCheckStringFormat",(e,t)=>{var n,r;Or.init(e,t),e._zod.onattach.push(e=>{const n=e._zod.bag;n.format=t.format,t.pattern&&(n.patterns??(n.patterns=new Set),n.patterns.add(t.pattern))}),t.pattern?(n=e._zod).check??(n.check=n=>{t.pattern.lastIndex=0,t.pattern.test(n.value)||n.issues.push({origin:"string",code:"invalid_format",format:t.format,input:n.value,...t.pattern?{pattern:t.pattern.toString()}:{},inst:e,continue:!t.abort})}):(r=e._zod).check??(r.check=()=>{})}),Zr=_n("$ZodCheckRegex",(e,t)=>{Ur.init(e,t),e._zod.check=n=>{t.pattern.lastIndex=0,t.pattern.test(n.value)||n.issues.push({origin:"string",code:"invalid_format",format:"regex",input:n.value,pattern:t.pattern.toString(),inst:e,continue:!t.abort})}}),Rr=_n("$ZodCheckLowerCase",(e,t)=>{t.pattern??(t.pattern=zr),Ur.init(e,t)}),Cr=_n("$ZodCheckUpperCase",(e,t)=>{t.pattern??(t.pattern=kr),Ur.init(e,t)}),jr=_n("$ZodCheckIncludes",(e,t)=>{Or.init(e,t);const n=Nn(t.includes),r=new RegExp("number"==typeof t.position?`^.{${t.position}}${n}`:n);t.pattern=r,e._zod.onattach.push(e=>{const t=e._zod.bag;t.patterns??(t.patterns=new Set),t.patterns.add(r)}),e._zod.check=n=>{n.value.includes(t.includes,t.position)||n.issues.push({origin:"string",code:"invalid_format",format:"includes",includes:t.includes,input:n.value,inst:e,continue:!t.abort})}}),Fr=_n("$ZodCheckStartsWith",(e,t)=>{Or.init(e,t);const n=new RegExp(`^${Nn(t.prefix)}.*`);t.pattern??(t.pattern=n),e._zod.onattach.push(e=>{const t=e._zod.bag;t.patterns??(t.patterns=new Set),t.patterns.add(n)}),e._zod.check=n=>{n.value.startsWith(t.prefix)||n.issues.push({origin:"string",code:"invalid_format",format:"starts_with",prefix:t.prefix,input:n.value,inst:e,continue:!t.abort})}}),Hr=_n("$ZodCheckEndsWith",(e,t)=>{Or.init(e,t);const n=new RegExp(`.*${Nn(t.suffix)}$`);t.pattern??(t.pattern=n),e._zod.onattach.push(e=>{const t=e._zod.bag;t.patterns??(t.patterns=new Set),t.patterns.add(n)}),e._zod.check=n=>{n.value.endsWith(t.suffix)||n.issues.push({origin:"string",code:"invalid_format",format:"ends_with",suffix:t.suffix,input:n.value,inst:e,continue:!t.abort})}}),Dr=_n("$ZodCheckOverwrite",(e,t)=>{Or.init(e,t),e._zod.check=e=>{e.value=t.tx(e.value)}});class Lr{constructor(e=[]){this.content=[],this.indent=0,this&&(this.args=e)}indented(e){this.indent+=1,e(this),this.indent-=1}write(e){if("function"==typeof e)return e(this,{execution:"sync"}),void e(this,{execution:"async"});const t=e.split("\n").filter(e=>e),n=Math.min(...t.map(e=>e.length-e.trimStart().length)),r=t.map(e=>e.slice(n)).map(e=>" ".repeat(2*this.indent)+e);for(const e of r)this.content.push(e)}compile(){const e=Function,t=this?.args;return new e(...t,[...(this?.content??[""]).map(e=>` ${e}`)].join("\n"))}}const Vr={major:4,minor:0,patch:5},qr=_n("$ZodType",(e,t)=>{var n;e??(e={}),e._zod.def=t,e._zod.bag=e._zod.bag||{},e._zod.version=Vr;const r=[...e._zod.def.checks??[]];e._zod.traits.has("$ZodCheck")&&r.unshift(e);for(const t of r)for(const n of t._zod.onattach)n(e);if(0===r.length)(n=e._zod).deferred??(n.deferred=[]),e._zod.deferred?.push(()=>{e._zod.run=e._zod.parse});else{const t=(e,t,n)=>{let r,i=Rn(e);for(const o of t){if(o._zod.def.when){if(!o._zod.def.when(e))continue}else if(i)continue;const t=e.issues.length,s=o._zod.check(e);if(s instanceof Promise&&!1===n?.async)throw new wn;if(r||s instanceof Promise)r=(r??Promise.resolve()).then(async()=>{await s;e.issues.length!==t&&(i||(i=Rn(e,t)))});else{if(e.issues.length===t)continue;i||(i=Rn(e,t))}}return r?r.then(()=>e):e};e._zod.run=(n,i)=>{const o=e._zod.parse(n,i);if(o instanceof Promise){if(!1===i.async)throw new wn;return o.then(e=>t(e,r,i))}return t(o,r,i)}}e["~standard"]={validate:t=>{try{const n=Gn(e,t);return n.success?{value:n.data}:{issues:n.error?.issues}}catch(n){return Xn(e,t).then(e=>e.success?{value:e.data}:{issues:e.error?.issues})}},vendor:"zod",version:1}}),Mr=_n("$ZodString",(e,t)=>{var n;qr.init(e,t),e._zod.pattern=[...e?._zod.bag?.patterns??[]].pop()??(n=e._zod.bag,new RegExp(`^${n?`[\\s\\S]{${n?.minimum??0},${n?.maximum??""}}`:"[\\s\\S]*"}$`)),e._zod.parse=(n,r)=>{if(t.coerce)try{n.value=String(n.value)}catch(r){}return"string"==typeof n.value||n.issues.push({expected:"string",code:"invalid_type",input:n.value,inst:e}),n}}),Kr=_n("$ZodStringFormat",(e,t)=>{Ur.init(e,t),Mr.init(e,t)}),Wr=_n("$ZodGUID",(e,t)=>{t.pattern??(t.pattern=or),Kr.init(e,t)}),Gr=_n("$ZodUUID",(e,t)=>{if(t.version){const e={v1:1,v2:2,v3:3,v4:4,v5:5,v6:6,v7:7,v8:8}[t.version];if(void 0===e)throw new Error(`Invalid UUID version: "${t.version}"`);t.pattern??(t.pattern=sr(e))}else t.pattern??(t.pattern=sr());Kr.init(e,t)}),Yr=_n("$ZodEmail",(e,t)=>{t.pattern??(t.pattern=ur),Kr.init(e,t)}),Xr=_n("$ZodURL",(e,t)=>{Kr.init(e,t),e._zod.check=n=>{try{const r=n.value,i=new URL(r),o=i.href;return t.hostname&&(t.hostname.lastIndex=0,t.hostname.test(i.hostname)||n.issues.push({code:"invalid_format",format:"url",note:"Invalid hostname",pattern:pr.source,input:n.value,inst:e,continue:!t.abort})),t.protocol&&(t.protocol.lastIndex=0,t.protocol.test(i.protocol.endsWith(":")?i.protocol.slice(0,-1):i.protocol)||n.issues.push({code:"invalid_format",format:"url",note:"Invalid protocol",pattern:t.protocol.source,input:n.value,inst:e,continue:!t.abort})),void(!r.endsWith("/")&&o.endsWith("/")?n.value=o.slice(0,-1):n.value=o)}catch(r){n.issues.push({code:"invalid_format",format:"url",input:n.value,inst:e,continue:!t.abort})}}}),Jr=_n("$ZodEmoji",(e,t)=>{t.pattern??(t.pattern=new RegExp("^(\\p{Extended_Pictographic}|\\p{Emoji_Component})+$","u")),Kr.init(e,t)}),Qr=_n("$ZodNanoID",(e,t)=>{t.pattern??(t.pattern=rr),Kr.init(e,t)}),ei=_n("$ZodCUID",(e,t)=>{t.pattern??(t.pattern=Jn),Kr.init(e,t)}),ti=_n("$ZodCUID2",(e,t)=>{t.pattern??(t.pattern=Qn),Kr.init(e,t)}),ni=_n("$ZodULID",(e,t)=>{t.pattern??(t.pattern=er),Kr.init(e,t)}),ri=_n("$ZodXID",(e,t)=>{t.pattern??(t.pattern=tr),Kr.init(e,t)}),ii=_n("$ZodKSUID",(e,t)=>{t.pattern??(t.pattern=nr),Kr.init(e,t)}),oi=_n("$ZodISODateTime",(e,t)=>{t.pattern??(t.pattern=function(e){const t=wr({precision:e.precision}),n=["Z"];e.local&&n.push(""),e.offset&&n.push("([+-]\\d{2}:\\d{2})");const r=`${t}(?:${n.join("|")})`;return new RegExp(`^${gr}T(?:${r})$`)}(t)),Kr.init(e,t)}),si=_n("$ZodISODate",(e,t)=>{t.pattern??(t.pattern=_r),Kr.init(e,t)}),ui=_n("$ZodISOTime",(e,t)=>{t.pattern??(t.pattern=new RegExp(`^${wr(t)}$`)),Kr.init(e,t)}),ci=_n("$ZodISODuration",(e,t)=>{t.pattern??(t.pattern=ir),Kr.init(e,t)}),ai=_n("$ZodIPv4",(e,t)=>{t.pattern??(t.pattern=cr),Kr.init(e,t),e._zod.onattach.push(e=>{e._zod.bag.format="ipv4"})}),fi=_n("$ZodIPv6",(e,t)=>{t.pattern??(t.pattern=ar),Kr.init(e,t),e._zod.onattach.push(e=>{e._zod.bag.format="ipv6"}),e._zod.check=n=>{try{new URL(`http://[${n.value}]`)}catch{n.issues.push({code:"invalid_format",format:"ipv6",input:n.value,inst:e,continue:!t.abort})}}}),di=_n("$ZodCIDRv4",(e,t)=>{t.pattern??(t.pattern=fr),Kr.init(e,t)}),li=_n("$ZodCIDRv6",(e,t)=>{t.pattern??(t.pattern=dr),Kr.init(e,t),e._zod.check=n=>{const[r,i]=n.value.split("/");try{if(!i)throw new Error;const e=Number(i);if(`${e}`!==i)throw new Error;if(e<0||e>128)throw new Error;new URL(`http://[${r}]`)}catch{n.issues.push({code:"invalid_format",format:"cidrv6",input:n.value,inst:e,continue:!t.abort})}}});function hi(e){if(""===e)return!0;if(e.length%4!=0)return!1;try{return atob(e),!0}catch{return!1}}const pi=_n("$ZodBase64",(e,t)=>{t.pattern??(t.pattern=lr),Kr.init(e,t),e._zod.onattach.push(e=>{e._zod.bag.contentEncoding="base64"}),e._zod.check=n=>{hi(n.value)||n.issues.push({code:"invalid_format",format:"base64",input:n.value,inst:e,continue:!t.abort})}});const mi=_n("$ZodBase64URL",(e,t)=>{t.pattern??(t.pattern=hr),Kr.init(e,t),e._zod.onattach.push(e=>{e._zod.bag.contentEncoding="base64url"}),e._zod.check=n=>{(function(e){if(!hr.test(e))return!1;const t=e.replace(/[-_]/g,e=>"-"===e?"+":"/");return hi(t.padEnd(4*Math.ceil(t.length/4),"="))})(n.value)||n.issues.push({code:"invalid_format",format:"base64url",input:n.value,inst:e,continue:!t.abort})}}),gi=_n("$ZodE164",(e,t)=>{t.pattern??(t.pattern=mr),Kr.init(e,t)});const _i=_n("$ZodJWT",(e,t)=>{Kr.init(e,t),e._zod.check=n=>{(function(e,t=null){try{const n=e.split(".");if(3!==n.length)return!1;const[r]=n;if(!r)return!1;const i=JSON.parse(atob(r));return!("typ"in i&&"JWT"!==i?.typ||!i.alg||t&&(!("alg"in i)||i.alg!==t))}catch{return!1}})(n.value,t.alg)||n.issues.push({code:"invalid_format",format:"jwt",input:n.value,inst:e,continue:!t.abort})}}),wi=_n("$ZodNumber",(e,t)=>{qr.init(e,t),e._zod.pattern=e._zod.bag.pattern??br,e._zod.parse=(n,r)=>{if(t.coerce)try{n.value=Number(n.value)}catch(e){}const i=n.value;if("number"==typeof i&&!Number.isNaN(i)&&Number.isFinite(i))return n;const o="number"==typeof i?Number.isNaN(i)?"NaN":Number.isFinite(i)?void 0:"Infinity":void 0;return n.issues.push({expected:"number",code:"invalid_type",input:i,inst:e,...o?{received:o}:{}}),n}}),yi=_n("$ZodNumber",(e,t)=>{$r.init(e,t),wi.init(e,t)}),vi=_n("$ZodBoolean",(e,t)=>{qr.init(e,t),e._zod.pattern=Er,e._zod.parse=(n,r)=>{if(t.coerce)try{n.value=Boolean(n.value)}catch(e){}const i=n.value;return"boolean"==typeof i||n.issues.push({expected:"boolean",code:"invalid_type",input:i,inst:e}),n}}),bi=_n("$ZodBigInt",(e,t)=>{qr.init(e,t),e._zod.pattern=yr,e._zod.parse=(n,r)=>{if(t.coerce)try{n.value=BigInt(n.value)}catch(e){}return"bigint"==typeof n.value||n.issues.push({expected:"bigint",code:"invalid_type",input:n.value,inst:e}),n}}),Ei=_n("$ZodNull",(e,t)=>{qr.init(e,t),e._zod.pattern=xr,e._zod.values=new Set([null]),e._zod.parse=(t,n)=>{const r=t.value;return null===r||t.issues.push({expected:"null",code:"invalid_type",input:r,inst:e}),t}}),xi=_n("$ZodAny",(e,t)=>{qr.init(e,t),e._zod.parse=e=>e}),zi=_n("$ZodUnknown",(e,t)=>{qr.init(e,t),e._zod.parse=e=>e}),ki=_n("$ZodNever",(e,t)=>{qr.init(e,t),e._zod.parse=(t,n)=>(t.issues.push({expected:"never",code:"invalid_type",input:t.value,inst:e}),t)}),Oi=_n("$ZodDate",(e,t)=>{qr.init(e,t),e._zod.parse=(n,r)=>{if(t.coerce)try{n.value=new Date(n.value)}catch(e){}const i=n.value,o=i instanceof Date;return o&&!Number.isNaN(i.getTime())||n.issues.push({expected:"date",code:"invalid_type",input:i,...o?{received:"Invalid Date"}:{},inst:e}),n}});function Pi(e,t,n){e.issues.length&&t.issues.push(...Cn(n,e.issues)),t.value[n]=e.value}const Si=_n("$ZodArray",(e,t)=>{qr.init(e,t),e._zod.parse=(n,r)=>{const i=n.value;if(!Array.isArray(i))return n.issues.push({expected:"array",code:"invalid_type",input:i,inst:e}),n;n.value=Array(i.length);const o=[];for(let e=0;e<i.length;e++){const s=i[e],u=t.element._zod.run({value:s,issues:[]},r);u instanceof Promise?o.push(u.then(t=>Pi(t,n,e))):Pi(u,n,e)}return o.length?Promise.all(o).then(()=>n):n}});function Ai(e,t,n){e.issues.length&&t.issues.push(...Cn(n,e.issues)),t.value[n]=e.value}function Ii(e,t,n,r){e.issues.length?void 0===r[n]?t.value[n]=n in r?void 0:e.value:t.issues.push(...Cn(n,e.issues)):void 0===e.value?n in r&&(t.value[n]=void 0):t.value[n]=e.value}const $i=_n("$ZodObject",(e,t)=>{qr.init(e,t);const n=En(()=>{const e=Object.keys(t.shape);for(const n of e)if(!(t.shape[n]instanceof qr))throw new Error(`Invalid element at key "${n}": expected a Zod schema`);const n=(r=t.shape,Object.keys(r).filter(e=>"optional"===r[e]._zod.optin&&"optional"===r[e]._zod.optout));var r;return{shape:t.shape,keys:e,keySet:new Set(e),numKeys:e.length,optionalKeys:new Set(n)}});kn(e._zod,"propValues",()=>{const e=t.shape,n={};for(const t in e){const r=e[t]._zod;if(r.values){n[t]??(n[t]=new Set);for(const e of r.values)n[t].add(e)}}return n});let r;const i=An,o=!yn.jitless,s=o&&In.value,u=t.catchall;let c;e._zod.parse=(a,f)=>{c??(c=n.value);const d=a.value;if(!i(d))return a.issues.push({expected:"object",code:"invalid_type",input:d,inst:e}),a;const l=[];if(o&&s&&!1===f?.async&&!0!==f.jitless)r||(r=(e=>{const t=new Lr(["shape","payload","ctx"]),r=n.value,i=e=>{const t=Pn(e);return`shape[${t}]._zod.run({ value: input[${t}], issues: [] }, ctx)`};t.write("const input = payload.value;");const o=Object.create(null);let s=0;for(const e of r.keys)o[e]="key_"+s++;t.write("const newResult = {}");for(const e of r.keys)if(r.optionalKeys.has(e)){const n=o[e];t.write(`const ${n} = ${i(e)};`);const r=Pn(e);t.write(`\n if (${n}.issues.length) {\n if (input[${r}] === undefined) {\n if (${r} in input) {\n newResult[${r}] = undefined;\n }\n } else {\n payload.issues = payload.issues.concat(\n ${n}.issues.map((iss) => ({\n ...iss,\n path: iss.path ? [${r}, ...iss.path] : [${r}],\n }))\n );\n }\n } else if (${n}.value === undefined) {\n if (${r} in input) newResult[${r}] = undefined;\n } else {\n newResult[${r}] = ${n}.value;\n }\n `)}else{const n=o[e];t.write(`const ${n} = ${i(e)};`),t.write(`\n if (${n}.issues.length) payload.issues = payload.issues.concat(${n}.issues.map(iss => ({\n ...iss,\n path: iss.path ? [${Pn(e)}, ...iss.path] : [${Pn(e)}]\n })));`),t.write(`newResult[${Pn(e)}] = ${n}.value`)}t.write("payload.value = newResult;"),t.write("return payload;");const u=t.compile();return(t,n)=>u(e,t,n)})(t.shape)),a=r(a,f);else{a.value={};const e=c.shape;for(const t of c.keys){const n=e[t],r=n._zod.run({value:d[t],issues:[]},f),i="optional"===n._zod.optin&&"optional"===n._zod.optout;r instanceof Promise?l.push(r.then(e=>i?Ii(e,a,t,d):Ai(e,a,t))):i?Ii(r,a,t,d):Ai(r,a,t)}}if(!u)return l.length?Promise.all(l).then(()=>a):a;const h=[],p=c.keySet,m=u._zod,g=m.def.type;for(const e of Object.keys(d)){if(p.has(e))continue;if("never"===g){h.push(e);continue}const t=m.run({value:d[e],issues:[]},f);t instanceof Promise?l.push(t.then(t=>Ai(t,a,e))):Ai(t,a,e)}return h.length&&a.issues.push({code:"unrecognized_keys",keys:h,input:d,inst:e}),l.length?Promise.all(l).then(()=>a):a}});function Ti(e,t,n,r){for(const n of e)if(0===n.issues.length)return t.value=n.value,t;return t.issues.push({code:"invalid_union",input:t.value,inst:n,errors:e.map(e=>e.issues.map(e=>Fn(e,r,vn())))}),t}const Ni=_n("$ZodUnion",(e,t)=>{qr.init(e,t),kn(e._zod,"optin",()=>t.options.some(e=>"optional"===e._zod.optin)?"optional":void 0),kn(e._zod,"optout",()=>t.options.some(e=>"optional"===e._zod.optout)?"optional":void 0),kn(e._zod,"values",()=>{if(t.options.every(e=>e._zod.values))return new Set(t.options.flatMap(e=>Array.from(e._zod.values)))}),kn(e._zod,"pattern",()=>{if(t.options.every(e=>e._zod.pattern)){const e=t.options.map(e=>e._zod.pattern);return new RegExp(`^(${e.map(e=>zn(e.source)).join("|")})$`)}}),e._zod.parse=(n,r)=>{let i=!1;const o=[];for(const e of t.options){const t=e._zod.run({value:n.value,issues:[]},r);if(t instanceof Promise)o.push(t),i=!0;else{if(0===t.issues.length)return t;o.push(t)}}return i?Promise.all(o).then(t=>Ti(t,n,e,r)):Ti(o,n,e,r)}}),Bi=_n("$ZodIntersection",(e,t)=>{qr.init(e,t),e._zod.parse=(e,n)=>{const r=e.value,i=t.left._zod.run({value:r,issues:[]},n),o=t.right._zod.run({value:r,issues:[]},n);return i instanceof Promise||o instanceof Promise?Promise.all([i,o]).then(([t,n])=>Zi(e,t,n)):Zi(e,i,o)}});function Ui(e,t){if(e===t)return{valid:!0,data:e};if(e instanceof Date&&t instanceof Date&&+e===+t)return{valid:!0,data:e};if($n(e)&&$n(t)){const n=Object.keys(t),r=Object.keys(e).filter(e=>-1!==n.indexOf(e)),i={...e,...t};for(const n of r){const r=Ui(e[n],t[n]);if(!r.valid)return{valid:!1,mergeErrorPath:[n,...r.mergeErrorPath]};i[n]=r.data}return{valid:!0,data:i}}if(Array.isArray(e)&&Array.isArray(t)){if(e.length!==t.length)return{valid:!1,mergeErrorPath:[]};const n=[];for(let r=0;r<e.length;r++){const i=Ui(e[r],t[r]);if(!i.valid)return{valid:!1,mergeErrorPath:[r,...i.mergeErrorPath]};n.push(i.data)}return{valid:!0,data:n}}return{valid:!1,mergeErrorPath:[]}}function Zi(e,t,n){if(t.issues.length&&e.issues.push(...t.issues),n.issues.length&&e.issues.push(...n.issues),Rn(e))return e;const r=Ui(t.value,n.value);if(!r.valid)throw new Error(`Unmergable intersection. Error path: ${JSON.stringify(r.mergeErrorPath)}`);return e.value=r.data,e}const Ri=_n("$ZodRecord",(e,t)=>{qr.init(e,t),e._zod.parse=(n,r)=>{const i=n.value;if(!$n(i))return n.issues.push({expected:"record",code:"invalid_type",input:i,inst:e}),n;const o=[];if(t.keyType._zod.values){const s=t.keyType._zod.values;n.value={};for(const e of s)if("string"==typeof e||"number"==typeof e||"symbol"==typeof e){const s=t.valueType._zod.run({value:i[e],issues:[]},r);s instanceof Promise?o.push(s.then(t=>{t.issues.length&&n.issues.push(...Cn(e,t.issues)),n.value[e]=t.value})):(s.issues.length&&n.issues.push(...Cn(e,s.issues)),n.value[e]=s.value)}let u;for(const e in i)s.has(e)||(u=u??[],u.push(e));u&&u.length>0&&n.issues.push({code:"unrecognized_keys",input:i,inst:e,keys:u})}else{n.value={};for(const s of Reflect.ownKeys(i)){if("__proto__"===s)continue;const u=t.keyType._zod.run({value:s,issues:[]},r);if(u instanceof Promise)throw new Error("Async schemas not supported in object keys currently");if(u.issues.length){n.issues.push({origin:"record",code:"invalid_key",issues:u.issues.map(e=>Fn(e,r,vn())),input:s,path:[s],inst:e}),n.value[u.value]=u.value;continue}const c=t.valueType._zod.run({value:i[s],issues:[]},r);c instanceof Promise?o.push(c.then(e=>{e.issues.length&&n.issues.push(...Cn(s,e.issues)),n.value[u.value]=e.value})):(c.issues.length&&n.issues.push(...Cn(s,c.issues)),n.value[u.value]=c.value)}}return o.length?Promise.all(o).then(()=>n):n}}),Ci=_n("$ZodEnum",(e,t)=>{qr.init(e,t);const n=function(e){const t=Object.values(e).filter(e=>"number"==typeof e);return Object.entries(e).filter(([e,n])=>-1===t.indexOf(+e)).map(([e,t])=>t)}(t.entries);e._zod.values=new Set(n),e._zod.pattern=new RegExp(`^(${n.filter(e=>Tn.has(typeof e)).map(e=>"string"==typeof e?Nn(e):e.toString()).join("|")})$`),e._zod.parse=(t,r)=>{const i=t.value;return e._zod.values.has(i)||t.issues.push({code:"invalid_value",values:n,input:i,inst:e}),t}}),ji=_n("$ZodTransform",(e,t)=>{qr.init(e,t),e._zod.parse=(e,n)=>{const r=t.transform(e.value,e);if(n.async){return(r instanceof Promise?r:Promise.resolve(r)).then(t=>(e.value=t,e))}if(r instanceof Promise)throw new wn;return e.value=r,e}}),Fi=_n("$ZodOptional",(e,t)=>{qr.init(e,t),e._zod.optin="optional",e._zod.optout="optional",kn(e._zod,"values",()=>t.innerType._zod.values?new Set([...t.innerType._zod.values,void 0]):void 0),kn(e._zod,"pattern",()=>{const e=t.innerType._zod.pattern;return e?new RegExp(`^(${zn(e.source)})?$`):void 0}),e._zod.parse=(e,n)=>"optional"===t.innerType._zod.optin?t.innerType._zod.run(e,n):void 0===e.value?e:t.innerType._zod.run(e,n)}),Hi=_n("$ZodNullable",(e,t)=>{qr.init(e,t),kn(e._zod,"optin",()=>t.innerType._zod.optin),kn(e._zod,"optout",()=>t.innerType._zod.optout),kn(e._zod,"pattern",()=>{const e=t.innerType._zod.pattern;return e?new RegExp(`^(${zn(e.source)}|null)$`):void 0}),kn(e._zod,"values",()=>t.innerType._zod.values?new Set([...t.innerType._zod.values,null]):void 0),e._zod.parse=(e,n)=>null===e.value?e:t.innerType._zod.run(e,n)}),Di=_n("$ZodDefault",(e,t)=>{qr.init(e,t),e._zod.optin="optional",kn(e._zod,"values",()=>t.innerType._zod.values),e._zod.parse=(e,n)=>{if(void 0===e.value)return e.value=t.defaultValue,e;const r=t.innerType._zod.run(e,n);return r instanceof Promise?r.then(e=>Li(e,t)):Li(r,t)}});function Li(e,t){return void 0===e.value&&(e.value=t.defaultValue),e}const Vi=_n("$ZodPrefault",(e,t)=>{qr.init(e,t),e._zod.optin="optional",kn(e._zod,"values",()=>t.innerType._zod.values),e._zod.parse=(e,n)=>(void 0===e.value&&(e.value=t.defaultValue),t.innerType._zod.run(e,n))}),qi=_n("$ZodNonOptional",(e,t)=>{qr.init(e,t),kn(e._zod,"values",()=>{const e=t.innerType._zod.values;return e?new Set([...e].filter(e=>void 0!==e)):void 0}),e._zod.parse=(n,r)=>{const i=t.innerType._zod.run(n,r);return i instanceof Promise?i.then(t=>Mi(t,e)):Mi(i,e)}});function Mi(e,t){return e.issues.length||void 0!==e.value||e.issues.push({code:"invalid_type",expected:"nonoptional",input:e.value,inst:t}),e}const Ki=_n("$ZodCatch",(e,t)=>{qr.init(e,t),e._zod.optin="optional",kn(e._zod,"optout",()=>t.innerType._zod.optout),kn(e._zod,"values",()=>t.innerType._zod.values),e._zod.parse=(e,n)=>{const r=t.innerType._zod.run(e,n);return r instanceof Promise?r.then(r=>(e.value=r.value,r.issues.length&&(e.value=t.catchValue({...e,error:{issues:r.issues.map(e=>Fn(e,n,vn()))},input:e.value}),e.issues=[]),e)):(e.value=r.value,r.issues.length&&(e.value=t.catchValue({...e,error:{issues:r.issues.map(e=>Fn(e,n,vn()))},input:e.value}),e.issues=[]),e)}}),Wi=_n("$ZodPipe",(e,t)=>{qr.init(e,t),kn(e._zod,"values",()=>t.in._zod.values),kn(e._zod,"optin",()=>t.in._zod.optin),kn(e._zod,"optout",()=>t.out._zod.optout),kn(e._zod,"propValues",()=>t.in._zod.propValues),e._zod.parse=(e,n)=>{const r=t.in._zod.run(e,n);return r instanceof Promise?r.then(e=>Gi(e,t,n)):Gi(r,t,n)}});function Gi(e,t,n){return Rn(e)?e:t.out._zod.run({value:e.value,issues:e.issues},n)}const Yi=_n("$ZodReadonly",(e,t)=>{qr.init(e,t),kn(e._zod,"propValues",()=>t.innerType._zod.propValues),kn(e._zod,"values",()=>t.innerType._zod.values),kn(e._zod,"optin",()=>t.innerType._zod.optin),kn(e._zod,"optout",()=>t.innerType._zod.optout),e._zod.parse=(e,n)=>{const r=t.innerType._zod.run(e,n);return r instanceof Promise?r.then(Xi):Xi(r)}});function Xi(e){return e.value=Object.freeze(e.value),e}const Ji=_n("$ZodLazy",(e,t)=>{qr.init(e,t),kn(e._zod,"innerType",()=>t.getter()),kn(e._zod,"pattern",()=>e._zod.innerType._zod.pattern),kn(e._zod,"propValues",()=>e._zod.innerType._zod.propValues),kn(e._zod,"optin",()=>e._zod.innerType._zod.optin),kn(e._zod,"optout",()=>e._zod.innerType._zod.optout),e._zod.parse=(t,n)=>e._zod.innerType._zod.run(t,n)}),Qi=_n("$ZodCustom",(e,t)=>{Or.init(e,t),qr.init(e,t),e._zod.parse=(e,t)=>e,e._zod.check=n=>{const r=n.value,i=t.fn(r);if(i instanceof Promise)return i.then(t=>eo(t,n,r,e));eo(i,n,r,e)}});function eo(e,t,n,r){if(!e){const e={code:"custom",input:n,inst:r,path:[...r._zod.def.path??[]],continue:!r._zod.def.abort};r._zod.def.params&&(e.params=r._zod.def.params),t.issues.push(Dn(e))}}class to{constructor(){this._map=new Map,this._idmap=new Map}add(e,...t){const n=t[0];if(this._map.set(e,n),n&&"object"==typeof n&&"id"in n){if(this._idmap.has(n.id))throw new Error(`ID ${n.id} already exists in the registry`);this._idmap.set(n.id,e)}return this}clear(){return this._map=new Map,this._idmap=new Map,this}remove(e){const t=this._map.get(e);return t&&"object"==typeof t&&"id"in t&&this._idmap.delete(t.id),this._map.delete(e),this}get(e){const t=e._zod.parent;if(t){const n={...this.get(t)??{}};return delete n.id,{...n,...this._map.get(e)}}return this._map.get(e)}has(e){return this._map.has(e)}}function no(){return new to}const ro=no();function io(e,t){return new e({type:"string",format:"guid",check:"string_format",abort:!1,...Un(t)})}function oo(e,t){return new Sr({check:"less_than",...Un(t),value:e,inclusive:!1})}function so(e,t){return new Sr({check:"less_than",...Un(t),value:e,inclusive:!0})}function uo(e,t){return new Ar({check:"greater_than",...Un(t),value:e,inclusive:!1})}function co(e,t){return new Ar({check:"greater_than",...Un(t),value:e,inclusive:!0})}function ao(e,t){return new Ir({check:"multiple_of",...Un(t),value:e})}function fo(e,t){return new Tr({check:"max_length",...Un(t),maximum:e})}function lo(e,t){return new Nr({check:"min_length",...Un(t),minimum:e})}function ho(e,t){return new Br({check:"length_equals",...Un(t),length:e})}function po(e){return new Dr({check:"overwrite",tx:e})}const mo=_n("ZodISODateTime",(e,t)=>{oi.init(e,t),To.init(e,t)});function go(e){return function(e,t){return new e({type:"string",format:"datetime",check:"string_format",offset:!1,local:!1,precision:null,...Un(t)})}(mo,e)}const _o=_n("ZodISODate",(e,t)=>{si.init(e,t),To.init(e,t)});function wo(e){return function(e,t){return new e({type:"string",format:"date",check:"string_format",...Un(t)})}(_o,e)}const yo=_n("ZodISOTime",(e,t)=>{ui.init(e,t),To.init(e,t)});function vo(e){return function(e,t){return new e({type:"string",format:"time",check:"string_format",precision:null,...Un(t)})}(yo,e)}const bo=_n("ZodISODuration",(e,t)=>{ci.init(e,t),To.init(e,t)});function Eo(e){return function(e,t){return new e({type:"string",format:"duration",check:"string_format",...Un(t)})}(bo,e)}const xo=_n("ZodError",(e,t)=>{Vn.init(e,t),e.name="ZodError",Object.defineProperties(e,{format:{value:t=>function(e,t){const n=t||function(e){return e.message},r={_errors:[]},i=e=>{for(const t of e.issues)if("invalid_union"===t.code&&t.errors.length)t.errors.map(e=>i({issues:e}));else if("invalid_key"===t.code)i({issues:t.issues});else if("invalid_element"===t.code)i({issues:t.issues});else if(0===t.path.length)r._errors.push(n(t));else{let e=r,i=0;for(;i<t.path.length;){const r=t.path[i];i===t.path.length-1?(e[r]=e[r]||{_errors:[]},e[r]._errors.push(n(t))):e[r]=e[r]||{_errors:[]},e=e[r],i++}}};return i(e),r}(e,t)},flatten:{value:t=>function(e,t=e=>e.message){const n={},r=[];for(const i of e.issues)i.path.length>0?(n[i.path[0]]=n[i.path[0]]||[],n[i.path[0]].push(t(i))):r.push(t(i));return{formErrors:r,fieldErrors:n}}(e,t)},addIssue:{value:t=>e.issues.push(t)},addIssues:{value:t=>e.issues.push(...t)},isEmpty:{get:()=>0===e.issues.length}})},{Parent:Error}),zo=Mn(xo),ko=Kn(xo),Oo=Wn(xo),Po=Yn(xo),So=_n("ZodType",(e,t)=>(qr.init(e,t),e.def=t,Object.defineProperty(e,"_def",{value:t}),e.check=(...n)=>e.clone({...t,checks:[...t.checks??[],...n.map(e=>"function"==typeof e?{_zod:{check:e,def:{check:"custom"},onattach:[]}}:e)]}),e.clone=(t,n)=>Bn(e,t,n),e.brand=()=>e,e.register=(t,n)=>(t.add(e,n),e),e.parse=(t,n)=>zo(e,t,n,{callee:e.parse}),e.safeParse=(t,n)=>Oo(e,t,n),e.parseAsync=async(t,n)=>ko(e,t,n,{callee:e.parseAsync}),e.safeParseAsync=async(t,n)=>Po(e,t,n),e.spa=e.safeParseAsync,e.refine=(t,n)=>e.check(function(e,t={}){return function(e,t,n){return new e({type:"custom",check:"custom",fn:t,...Un(n)})}(Zs,e,t)}(t,n)),e.superRefine=t=>e.check(function(e){const t=function(e){const t=new Or({check:"custom"});return t._zod.check=e,t}(n=>(n.addIssue=e=>{if("string"==typeof e)n.issues.push(Dn(e,n.value,t._zod.def));else{const r=e;r.fatal&&(r.continue=!1),r.code??(r.code="custom"),r.input??(r.input=n.value),r.inst??(r.inst=t),r.continue??(r.continue=!t._zod.def.abort),n.issues.push(Dn(r))}},e(n.value,n)));return t}(t)),e.overwrite=t=>e.check(po(t)),e.optional=()=>ks(e),e.nullable=()=>Ps(e),e.nullish=()=>ks(Ps(e)),e.nonoptional=t=>function(e,t){return new Is({type:"nonoptional",innerType:e,...Un(t)})}(e,t),e.array=()=>ps(e),e.or=t=>ws([e,t]),e.and=t=>new ys({type:"intersection",left:e,right:t}),e.transform=t=>Ns(e,new xs({type:"transform",transform:t})),e.default=t=>{return n=t,new Ss({type:"default",innerType:e,get defaultValue(){return"function"==typeof n?n():n}});var n},e.prefault=t=>{return n=t,new As({type:"prefault",innerType:e,get defaultValue(){return"function"==typeof n?n():n}});var n},e.catch=t=>{return new $s({type:"catch",innerType:e,catchValue:"function"==typeof(n=t)?n:()=>n});var n},e.pipe=t=>Ns(e,t),e.readonly=()=>new Bs({type:"readonly",innerType:e}),e.describe=t=>{const n=e.clone();return ro.add(n,{description:t}),n},Object.defineProperty(e,"description",{get:()=>ro.get(e)?.description,configurable:!0}),e.meta=(...t)=>{if(0===t.length)return ro.get(e);const n=e.clone();return ro.add(n,t[0]),n},e.isOptional=()=>e.safeParse(void 0).success,e.isNullable=()=>e.safeParse(null).success,e)),Ao=_n("_ZodString",(e,t)=>{Mr.init(e,t),So.init(e,t);const n=e._zod.bag;e.format=n.format??null,e.minLength=n.minimum??null,e.maxLength=n.maximum??null,e.regex=(...t)=>e.check(function(e,t){return new Zr({check:"string_format",format:"regex",...Un(t),pattern:e})}(...t)),e.includes=(...t)=>e.check(function(e,t){return new jr({check:"string_format",format:"includes",...Un(t),includes:e})}(...t)),e.startsWith=(...t)=>e.check(function(e,t){return new Fr({check:"string_format",format:"starts_with",...Un(t),prefix:e})}(...t)),e.endsWith=(...t)=>e.check(function(e,t){return new Hr({check:"string_format",format:"ends_with",...Un(t),suffix:e})}(...t)),e.min=(...t)=>e.check(lo(...t)),e.max=(...t)=>e.check(fo(...t)),e.length=(...t)=>e.check(ho(...t)),e.nonempty=(...t)=>e.check(lo(1,...t)),e.lowercase=t=>e.check(function(e){return new Rr({check:"string_format",format:"lowercase",...Un(e)})}(t)),e.uppercase=t=>e.check(function(e){return new Cr({check:"string_format",format:"uppercase",...Un(e)})}(t)),e.trim=()=>e.check(po(e=>e.trim())),e.normalize=(...t)=>e.check(function(e){return po(t=>t.normalize(e))}(...t)),e.toLowerCase=()=>e.check(po(e=>e.toLowerCase())),e.toUpperCase=()=>e.check(po(e=>e.toUpperCase()))}),Io=_n("ZodString",(e,t)=>{Mr.init(e,t),Ao.init(e,t),e.email=t=>e.check(function(e,t){return new e({type:"string",format:"email",check:"string_format",abort:!1,...Un(t)})}(No,t)),e.url=t=>e.check(function(e,t){return new e({type:"string",format:"url",check:"string_format",abort:!1,...Un(t)})}(Zo,t)),e.jwt=t=>e.check(function(e,t){return new e({type:"string",format:"jwt",check:"string_format",abort:!1,...Un(t)})}(Xo,t)),e.emoji=t=>e.check(function(e,t){return new e({type:"string",format:"emoji",check:"string_format",abort:!1,...Un(t)})}(Ro,t)),e.guid=t=>e.check(io(Bo,t)),e.uuid=t=>e.check(function(e,t){return new e({type:"string",format:"uuid",check:"string_format",abort:!1,...Un(t)})}(Uo,t)),e.uuidv4=t=>e.check(function(e,t){return new e({type:"string",format:"uuid",check:"string_format",abort:!1,version:"v4",...Un(t)})}(Uo,t)),e.uuidv6=t=>e.check(function(e,t){return new e({type:"string",format:"uuid",check:"string_format",abort:!1,version:"v6",...Un(t)})}(Uo,t)),e.uuidv7=t=>e.check(function(e,t){return new e({type:"string",format:"uuid",check:"string_format",abort:!1,version:"v7",...Un(t)})}(Uo,t)),e.nanoid=t=>e.check(function(e,t){return new e({type:"string",format:"nanoid",check:"string_format",abort:!1,...Un(t)})}(Co,t)),e.guid=t=>e.check(io(Bo,t)),e.cuid=t=>e.check(function(e,t){return new e({type:"string",format:"cuid",check:"string_format",abort:!1,...Un(t)})}(jo,t)),e.cuid2=t=>e.check(function(e,t){return new e({type:"string",format:"cuid2",check:"string_format",abort:!1,...Un(t)})}(Fo,t)),e.ulid=t=>e.check(function(e,t){return new e({type:"string",format:"ulid",check:"string_format",abort:!1,...Un(t)})}(Ho,t)),e.base64=t=>e.check(function(e,t){return new e({type:"string",format:"base64",check:"string_format",abort:!1,...Un(t)})}(Wo,t)),e.base64url=t=>e.check(function(e,t){return new e({type:"string",format:"base64url",check:"string_format",abort:!1,...Un(t)})}(Go,t)),e.xid=t=>e.check(function(e,t){return new e({type:"string",format:"xid",check:"string_format",abort:!1,...Un(t)})}(Do,t)),e.ksuid=t=>e.check(function(e,t){return new e({type:"string",format:"ksuid",check:"string_format",abort:!1,...Un(t)})}(Lo,t)),e.ipv4=t=>e.check(function(e,t){return new e({type:"string",format:"ipv4",check:"string_format",abort:!1,...Un(t)})}(Vo,t)),e.ipv6=t=>e.check(function(e,t){return new e({type:"string",format:"ipv6",check:"string_format",abort:!1,...Un(t)})}(qo,t)),e.cidrv4=t=>e.check(function(e,t){return new e({type:"string",format:"cidrv4",check:"string_format",abort:!1,...Un(t)})}(Mo,t)),e.cidrv6=t=>e.check(function(e,t){return new e({type:"string",format:"cidrv6",check:"string_format",abort:!1,...Un(t)})}(Ko,t)),e.e164=t=>e.check(function(e,t){return new e({type:"string",format:"e164",check:"string_format",abort:!1,...Un(t)})}(Yo,t)),e.datetime=t=>e.check(go(t)),e.date=t=>e.check(wo(t)),e.time=t=>e.check(vo(t)),e.duration=t=>e.check(Eo(t))});function $o(e){return function(e,t){return new e({type:"string",...Un(t)})}(Io,e)}const To=_n("ZodStringFormat",(e,t)=>{Kr.init(e,t),Ao.init(e,t)}),No=_n("ZodEmail",(e,t)=>{Yr.init(e,t),To.init(e,t)}),Bo=_n("ZodGUID",(e,t)=>{Wr.init(e,t),To.init(e,t)}),Uo=_n("ZodUUID",(e,t)=>{Gr.init(e,t),To.init(e,t)}),Zo=_n("ZodURL",(e,t)=>{Xr.init(e,t),To.init(e,t)}),Ro=_n("ZodEmoji",(e,t)=>{Jr.init(e,t),To.init(e,t)}),Co=_n("ZodNanoID",(e,t)=>{Qr.init(e,t),To.init(e,t)}),jo=_n("ZodCUID",(e,t)=>{ei.init(e,t),To.init(e,t)}),Fo=_n("ZodCUID2",(e,t)=>{ti.init(e,t),To.init(e,t)}),Ho=_n("ZodULID",(e,t)=>{ni.init(e,t),To.init(e,t)}),Do=_n("ZodXID",(e,t)=>{ri.init(e,t),To.init(e,t)}),Lo=_n("ZodKSUID",(e,t)=>{ii.init(e,t),To.init(e,t)}),Vo=_n("ZodIPv4",(e,t)=>{ai.init(e,t),To.init(e,t)}),qo=_n("ZodIPv6",(e,t)=>{fi.init(e,t),To.init(e,t)}),Mo=_n("ZodCIDRv4",(e,t)=>{di.init(e,t),To.init(e,t)}),Ko=_n("ZodCIDRv6",(e,t)=>{li.init(e,t),To.init(e,t)}),Wo=_n("ZodBase64",(e,t)=>{pi.init(e,t),To.init(e,t)}),Go=_n("ZodBase64URL",(e,t)=>{mi.init(e,t),To.init(e,t)}),Yo=_n("ZodE164",(e,t)=>{gi.init(e,t),To.init(e,t)}),Xo=_n("ZodJWT",(e,t)=>{_i.init(e,t),To.init(e,t)}),Jo=_n("ZodNumber",(e,t)=>{wi.init(e,t),So.init(e,t),e.gt=(t,n)=>e.check(uo(t,n)),e.gte=(t,n)=>e.check(co(t,n)),e.min=(t,n)=>e.check(co(t,n)),e.lt=(t,n)=>e.check(oo(t,n)),e.lte=(t,n)=>e.check(so(t,n)),e.max=(t,n)=>e.check(so(t,n)),e.int=t=>e.check(ts(t)),e.safe=t=>e.check(ts(t)),e.positive=t=>e.check(uo(0,t)),e.nonnegative=t=>e.check(co(0,t)),e.negative=t=>e.check(oo(0,t)),e.nonpositive=t=>e.check(so(0,t)),e.multipleOf=(t,n)=>e.check(ao(t,n)),e.step=(t,n)=>e.check(ao(t,n)),e.finite=()=>e;const n=e._zod.bag;e.minValue=Math.max(n.minimum??Number.NEGATIVE_INFINITY,n.exclusiveMinimum??Number.NEGATIVE_INFINITY)??null,e.maxValue=Math.min(n.maximum??Number.POSITIVE_INFINITY,n.exclusiveMaximum??Number.POSITIVE_INFINITY)??null,e.isInt=(n.format??"").includes("int")||Number.isSafeInteger(n.multipleOf??.5),e.isFinite=!0,e.format=n.format??null});function Qo(e){return function(e,t){return new e({type:"number",checks:[],...Un(t)})}(Jo,e)}const es=_n("ZodNumberFormat",(e,t)=>{yi.init(e,t),Jo.init(e,t)});function ts(e){return function(e,t){return new e({type:"number",check:"number_format",abort:!1,format:"safeint",...Un(t)})}(es,e)}const ns=_n("ZodBoolean",(e,t)=>{vi.init(e,t),So.init(e,t)});function rs(e){return function(e,t){return new e({type:"boolean",...Un(t)})}(ns,e)}const is=_n("ZodBigInt",(e,t)=>{bi.init(e,t),So.init(e,t),e.gte=(t,n)=>e.check(co(t,n)),e.min=(t,n)=>e.check(co(t,n)),e.gt=(t,n)=>e.check(uo(t,n)),e.gte=(t,n)=>e.check(co(t,n)),e.min=(t,n)=>e.check(co(t,n)),e.lt=(t,n)=>e.check(oo(t,n)),e.lte=(t,n)=>e.check(so(t,n)),e.max=(t,n)=>e.check(so(t,n)),e.positive=t=>e.check(uo(BigInt(0),t)),e.negative=t=>e.check(oo(BigInt(0),t)),e.nonpositive=t=>e.check(so(BigInt(0),t)),e.nonnegative=t=>e.check(co(BigInt(0),t)),e.multipleOf=(t,n)=>e.check(ao(t,n));const n=e._zod.bag;e.minValue=n.minimum??null,e.maxValue=n.maximum??null,e.format=n.format??null});function os(e){return function(e,t){return new e({type:"bigint",...Un(t)})}(is,e)}const ss=_n("ZodNull",(e,t)=>{Ei.init(e,t),So.init(e,t)});const us=_n("ZodAny",(e,t)=>{xi.init(e,t),So.init(e,t)});const cs=_n("ZodUnknown",(e,t)=>{zi.init(e,t),So.init(e,t)});function as(){return new cs({type:"unknown"})}const fs=_n("ZodNever",(e,t)=>{ki.init(e,t),So.init(e,t)});function ds(e){return function(e,t){return new e({type:"never",...Un(t)})}(fs,e)}const ls=_n("ZodDate",(e,t)=>{Oi.init(e,t),So.init(e,t),e.min=(t,n)=>e.check(co(t,n)),e.max=(t,n)=>e.check(so(t,n));const n=e._zod.bag;e.minDate=n.minimum?new Date(n.minimum):null,e.maxDate=n.maximum?new Date(n.maximum):null});const hs=_n("ZodArray",(e,t)=>{Si.init(e,t),So.init(e,t),e.element=t.element,e.min=(t,n)=>e.check(lo(t,n)),e.nonempty=t=>e.check(lo(1,t)),e.max=(t,n)=>e.check(fo(t,n)),e.length=(t,n)=>e.check(ho(t,n)),e.unwrap=()=>e.element});function ps(e,t){return function(e,t,n){return new e({type:"array",element:t,...Un(n)})}(hs,e,t)}const ms=_n("ZodObject",(e,t)=>{$i.init(e,t),So.init(e,t),kn(e,"shape",()=>t.shape),e.keyof=()=>function(e,t){const n=Array.isArray(e)?Object.fromEntries(e.map(e=>[e,e])):e;return new Es({type:"enum",entries:n,...Un(t)})}(Object.keys(e._zod.def.shape)),e.catchall=t=>e.clone({...e._zod.def,catchall:t}),e.passthrough=()=>e.clone({...e._zod.def,catchall:as()}),e.loose=()=>e.clone({...e._zod.def,catchall:as()}),e.strict=()=>e.clone({...e._zod.def,catchall:ds()}),e.strip=()=>e.clone({...e._zod.def,catchall:void 0}),e.extend=t=>function(e,t){if(!$n(t))throw new Error("Invalid input to extend: expected a plain object");const n={...e._zod.def,get shape(){const n={...e._zod.def.shape,...t};return On(this,"shape",n),n},checks:[]};return Bn(e,n)}(e,t),e.merge=t=>{return r=t,Bn(n=e,{...n._zod.def,get shape(){const e={...n._zod.def.shape,...r._zod.def.shape};return On(this,"shape",e),e},catchall:r._zod.def.catchall,checks:[]});var n,r},e.pick=t=>function(e,t){const n={},r=e._zod.def;for(const e in t){if(!(e in r.shape))throw new Error(`Unrecognized key: "${e}"`);t[e]&&(n[e]=r.shape[e])}return Bn(e,{...e._zod.def,shape:n,checks:[]})}(e,t),e.omit=t=>function(e,t){const n={...e._zod.def.shape},r=e._zod.def;for(const e in t){if(!(e in r.shape))throw new Error(`Unrecognized key: "${e}"`);t[e]&&delete n[e]}return Bn(e,{...e._zod.def,shape:n,checks:[]})}(e,t),e.partial=(...t)=>function(e,t,n){const r=t._zod.def.shape,i={...r};if(n)for(const t in n){if(!(t in r))throw new Error(`Unrecognized key: "${t}"`);n[t]&&(i[t]=e?new e({type:"optional",innerType:r[t]}):r[t])}else for(const t in r)i[t]=e?new e({type:"optional",innerType:r[t]}):r[t];return Bn(t,{...t._zod.def,shape:i,checks:[]})}(zs,e,t[0]),e.required=(...t)=>function(e,t,n){const r=t._zod.def.shape,i={...r};if(n)for(const t in n){if(!(t in i))throw new Error(`Unrecognized key: "${t}"`);n[t]&&(i[t]=new e({type:"nonoptional",innerType:r[t]}))}else for(const t in r)i[t]=new e({type:"nonoptional",innerType:r[t]});return Bn(t,{...t._zod.def,shape:i,checks:[]})}(Is,e,t[0])});function gs(e,t){const n={type:"object",get shape(){return On(this,"shape",{...e}),this.shape},...Un(t)};return new ms(n)}const _s=_n("ZodUnion",(e,t)=>{Ni.init(e,t),So.init(e,t),e.options=t.options});function ws(e,t){return new _s({type:"union",options:e,...Un(t)})}const ys=_n("ZodIntersection",(e,t)=>{Bi.init(e,t),So.init(e,t)});const vs=_n("ZodRecord",(e,t)=>{Ri.init(e,t),So.init(e,t),e.keyType=t.keyType,e.valueType=t.valueType});function bs(e,t,n){return new vs({type:"record",keyType:e,valueType:t,...Un(n)})}const Es=_n("ZodEnum",(e,t)=>{Ci.init(e,t),So.init(e,t),e.enum=t.entries,e.options=Object.values(t.entries);const n=new Set(Object.keys(t.entries));e.extract=(e,r)=>{const i={};for(const r of e){if(!n.has(r))throw new Error(`Key ${r} not found in enum`);i[r]=t.entries[r]}return new Es({...t,checks:[],...Un(r),entries:i})},e.exclude=(e,r)=>{const i={...t.entries};for(const t of e){if(!n.has(t))throw new Error(`Key ${t} not found in enum`);delete i[t]}return new Es({...t,checks:[],...Un(r),entries:i})}});const xs=_n("ZodTransform",(e,t)=>{ji.init(e,t),So.init(e,t),e._zod.parse=(n,r)=>{n.addIssue=r=>{if("string"==typeof r)n.issues.push(Dn(r,n.value,t));else{const t=r;t.fatal&&(t.continue=!1),t.code??(t.code="custom"),t.input??(t.input=n.value),t.inst??(t.inst=e),t.continue??(t.continue=!0),n.issues.push(Dn(t))}};const i=t.transform(n.value,n);return i instanceof Promise?i.then(e=>(n.value=e,n)):(n.value=i,n)}});const zs=_n("ZodOptional",(e,t)=>{Fi.init(e,t),So.init(e,t),e.unwrap=()=>e._zod.def.innerType});function ks(e){return new zs({type:"optional",innerType:e})}const Os=_n("ZodNullable",(e,t)=>{Hi.init(e,t),So.init(e,t),e.unwrap=()=>e._zod.def.innerType});function Ps(e){return new Os({type:"nullable",innerType:e})}const Ss=_n("ZodDefault",(e,t)=>{Di.init(e,t),So.init(e,t),e.unwrap=()=>e._zod.def.innerType,e.removeDefault=e.unwrap});const As=_n("ZodPrefault",(e,t)=>{Vi.init(e,t),So.init(e,t),e.unwrap=()=>e._zod.def.innerType});const Is=_n("ZodNonOptional",(e,t)=>{qi.init(e,t),So.init(e,t),e.unwrap=()=>e._zod.def.innerType});const $s=_n("ZodCatch",(e,t)=>{Ki.init(e,t),So.init(e,t),e.unwrap=()=>e._zod.def.innerType,e.removeCatch=e.unwrap});const Ts=_n("ZodPipe",(e,t)=>{Wi.init(e,t),So.init(e,t),e.in=t.in,e.out=t.out});function Ns(e,t){return new Ts({type:"pipe",in:e,out:t})}const Bs=_n("ZodReadonly",(e,t)=>{Yi.init(e,t),So.init(e,t)});const Us=_n("ZodLazy",(e,t)=>{Ji.init(e,t),So.init(e,t),e.unwrap=()=>e._zod.def.getter()});const Zs=_n("ZodCustom",(e,t)=>{Qi.init(e,t),So.init(e,t)});var Rs;os(),rs(),function(e,t){new e({type:"date",...Un(t)})}(ls,Rs);const Cs=Qo().min(Number.MIN_SAFE_INTEGER).max(Number.MAX_SAFE_INTEGER).int(),js=function(e,t={error:`Input not instance of ${e.name}`}){const n=new Zs({type:"custom",check:"custom",fn:t=>t instanceof e,abort:!0,...Un(t)});return n._zod.bag.Class=e,n}(Uint8Array),Fs=$o();Cs.min(5e8),new us({type:"any"}),Cs.min(0).max(255),Cs.min(0).max(65535);const Hs=Cs.min(0).max(4294967295);Qo().refine(e=>String(e).includes(".")).refine(e=>{const t=String(e).split(".").at(1);return void 0!==t&&t.length<=2});const Ds=$o().regex(/^[0-9a-fA-F]*$/).refine(e=>e.length%2==0),Ls=ws([$o(),Qo(),rs(),function(e){return function(e,t){return new e({type:"null",...Un(t)})}(ss,e)}()]),Vs=new Us({type:"lazy",getter:()=>ws([Ls,ps(Vs),bs(Fs,Vs)])});js.refine(e=>20===e.length);const qs=js.refine(e=>32===e.length),Ms=js.refine(e=>33===e.length),Ks=js.refine(e=>64===e.length);Ds.refine(e=>40===e.length);const Ws=Ds.refine(e=>64===e.length),Gs=Ds.refine(e=>66===e.length),Ys=Ds.refine(e=>128===e.length);ws([Ds,js]);const Xs=ws([Ws,qs]);
12
12
  /*! scure-base - MIT License (c) 2022 Paul Miller (paulmillr.com) */
13
- function Js(e){return e instanceof Uint8Array||ArrayBuffer.isView(e)&&"Uint8Array"===e.constructor.name}function Qs(e,t){return!!Array.isArray(t)&&(0===t.length||(e?t.every(e=>"string"==typeof e):t.every(e=>Number.isSafeInteger(e))))}function eu(e){if("function"!=typeof e)throw new Error("function expected");return!0}function tu(e,t){if("string"!=typeof t)throw new Error(`${e}: string expected`);return!0}function nu(e){if(!Number.isSafeInteger(e))throw new Error(`invalid integer: ${e}`)}function ru(e){if(!Array.isArray(e))throw new Error("array expected")}function iu(e,t){if(!Qs(!0,t))throw new Error(`${e}: array of strings expected`)}function ou(e,t){if(!Qs(!1,t))throw new Error(`${e}: array of numbers expected`)}function su(...e){const t=e=>e,n=(e,t)=>n=>e(t(n));return{encode:e.map(e=>e.encode).reduceRight(n,t),decode:e.map(e=>e.decode).reduce(n,t)}}function uu(e){const t="string"==typeof e?e.split(""):e,n=t.length;iu("alphabet",t);const r=new Map(t.map((e,t)=>[e,t]));return{encode:r=>(ru(r),r.map(r=>{if(!Number.isSafeInteger(r)||r<0||r>=n)throw new Error(`alphabet.encode: digit index outside alphabet "${r}". Allowed: ${e}`);return t[r]})),decode:t=>(ru(t),t.map(t=>{tu("alphabet.decode",t);const n=r.get(t);if(void 0===n)throw new Error(`Unknown letter: "${t}". Allowed: ${e}`);return n}))}}function au(e=""){return tu("join",e),{encode:t=>(iu("join.decode",t),t.join(e)),decode:t=>(tu("join.decode",t),t.split(e))}}function cu(e,t,n){if(t<2)throw new Error(`convertRadix: invalid from=${t}, base cannot be less than 2`);if(n<2)throw new Error(`convertRadix: invalid to=${n}, base cannot be less than 2`);if(ru(e),!e.length)return[];let r=0;const i=[],o=Array.from(e,e=>{if(nu(e),e<0||e>=t)throw new Error(`invalid integer: ${e}`);return e}),s=o.length;for(;;){let e=0,u=!0;for(let i=r;i<s;i++){const s=o[i],a=t*e,c=a+s;if(!Number.isSafeInteger(c)||a/t!==e||c-s!==a)throw new Error("convertRadix: carry overflow");const f=c/n;e=c%n;const d=Math.floor(f);if(o[i]=d,!Number.isSafeInteger(d)||d*n+e!==c)throw new Error("convertRadix: carry overflow");u&&(d?u=!1:r=i)}if(i.push(e),u)break}for(let t=0;t<e.length-1&&0===e[t];t++)i.push(0);return i.reverse()}_s([Ws,Ms]),_s([Ys,Ks]),Io().regex(/^[1-9A-HJ-NP-Za-km-z]+$/),Io().regex(/^[a-zA-Z0-9+/]+={0,2}$/),Io().regex(/^[a-zA-Z0-9\-_]+={0,2}$/),Io().regex(/^[a-z]+1[023456789acdefghjklmnpqrstuvwxyz]+$/);const fu=(e,t)=>0===t?e:fu(t,e%t),du=(e,t)=>e+(t-fu(e,t)),lu=(()=>{let e=[];for(let t=0;t<40;t++)e.push(2**t);return e})();function hu(e,t,n,r){if(ru(e),t<=0||t>32)throw new Error(`convertRadix2: wrong from=${t}`);if(n<=0||n>32)throw new Error(`convertRadix2: wrong to=${n}`);if(du(t,n)>32)throw new Error(`convertRadix2: carry overflow from=${t} to=${n} carryBits=${du(t,n)}`);let i=0,o=0;const s=lu[t],u=lu[n]-1,a=[];for(const r of e){if(nu(r),r>=s)throw new Error(`convertRadix2: invalid data word=${r} from=${t}`);if(i=i<<t|r,o+t>32)throw new Error(`convertRadix2: carry overflow pos=${o} from=${t}`);for(o+=t;o>=n;o-=n)a.push((i>>o-n&u)>>>0);const e=lu[o];if(void 0===e)throw new Error("invalid carry");i&=e-1}if(i=i<<n-o&u,!r&&o>=t)throw new Error("Excess padding");if(!r&&i>0)throw new Error(`Non-zero padding: ${i}`);return r&&o>0&&a.push(i>>>0),a}function pu(e,t=!1){if(nu(e),e<=0||e>32)throw new Error("radix2: bits should be in (0..32]");if(du(8,e)>32||du(e,8)>32)throw new Error("radix2: carry overflow");return{encode:n=>{if(!Js(n))throw new Error("radix2.encode input should be Uint8Array");return hu(Array.from(n),8,e,!t)},decode:n=>(ou("radix2.decode",n),Uint8Array.from(hu(n,e,8,t)))}}function mu(e){return eu(e),function(...t){try{return e.apply(null,t)}catch(e){}}}const gu=(()=>"function"==typeof Uint8Array.from([]).toBase64&&"function"==typeof Uint8Array.fromBase64)()?{encode:e=>(function(e,...t){if(!Js(e))throw new Error("Uint8Array expected");if(t.length>0&&!t.includes(e.length))throw new Error("Uint8Array expected of length "+t+", got length="+e.length)}(e),e.toBase64()),decode:e=>(e=>{if(tu("base64",e),e.length>0&&!/^[A-Za-z0-9=+/]+$/.test(e))throw new Error("invalid base64");return Uint8Array.fromBase64(e,{alphabet:"base64",lastChunkHandling:"strict"})})(e)}:su(pu(6),uu("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"),function(e,t="="){return nu(e),tu("padding",t),{encode(n){for(iu("padding.encode",n);n.length*e%8;)n.push(t);return n},decode(n){iu("padding.decode",n);let r=n.length;if(r*e%8)throw new Error("padding: invalid, string should have whole number of bytes");for(;r>0&&n[r-1]===t;r--){if((r-1)*e%8==0)throw new Error("padding: invalid, string has too much padding")}return n.slice(0,r)}}}(6),au("")),wu=su(pu(6),uu("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_"),au("")),_u=(yu="123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz",su(function(e){return nu(e),{encode:t=>{if(!Js(t))throw new Error("radix.encode input should be Uint8Array");return cu(Array.from(t),256,e)},decode:t=>(ou("radix.decode",t),Uint8Array.from(cu(t,e,256)))}}(58),uu(yu),au("")));var yu;const vu=e=>{return su((n=t=>e(e(t)),nu(t=4),eu(n),{encode(e){if(!Js(e))throw new Error("checksum.encode: input should be Uint8Array");const r=n(e).slice(0,t),i=new Uint8Array(e.length+t);return i.set(e),i.set(r,e.length),i},decode(e){if(!Js(e))throw new Error("checksum.decode: input should be Uint8Array");const r=e.slice(0,-t),i=e.slice(-t),o=n(r).slice(0,t);for(let e=0;e<t;e++)if(o[e]!==i[e])throw new Error("Invalid checksum");return r}}),_u);var t,n},bu=su(uu("qpzry9x8gf2tvdw0s3jn54khce6mua7l"),au("")),Eu=[996825010,642813549,513874426,1027748829,705979059];function xu(e){const t=e>>25;let n=(33554431&e)<<5;for(let e=0;e<Eu.length;e++)1==(t>>e&1)&&(n^=Eu[e]);return n}function zu(e,t,n=1){const r=e.length;let i=1;for(let t=0;t<r;t++){const n=e.charCodeAt(t);if(n<33||n>126)throw new Error(`Invalid prefix (${e})`);i=xu(i)^n>>5}i=xu(i);for(let t=0;t<r;t++)i=xu(i)^31&e.charCodeAt(t);for(let e of t)i=xu(i)^e;for(let e=0;e<6;e++)i=xu(i);return i^=n,bu.encode(hu([i%lu[30]],30,5,!1))}function ku(e){const t="bech32"===e?1:734539939,n=pu(5),r=n.decode,i=n.encode,o=mu(r);function s(e,n,r=90){tu("bech32.encode prefix",e),Js(n)&&(n=Array.from(n)),ou("bech32.encode",n);const i=e.length;if(0===i)throw new TypeError(`Invalid prefix length ${i}`);const o=i+7+n.length;if(!1!==r&&o>r)throw new TypeError(`Length ${o} exceeds limit ${r}`);const s=e.toLowerCase(),u=zu(s,n,t);return`${s}1${bu.encode(n)}${u}`}function u(e,n=90){tu("bech32.decode input",e);const r=e.length;if(r<8||!1!==n&&r>n)throw new TypeError(`invalid string length: ${r} (${e}). Expected (8..${n})`);const i=e.toLowerCase();if(e!==i&&e!==e.toUpperCase())throw new Error("String must be lowercase or uppercase");const o=i.lastIndexOf("1");if(0===o||-1===o)throw new Error('Letter "1" must be present between prefix and data only');const s=i.slice(0,o),u=i.slice(o+1);if(u.length<6)throw new Error("Data must be at least 6 characters long");const a=bu.decode(u).slice(0,-6),c=zu(s,a,t);if(!u.endsWith(c))throw new Error(`Invalid checksum in ${e}: expected "${c}"`);return{prefix:s,words:a}}return{encode:s,decode:u,encodeFromBytes:function(e,t){return s(e,i(t))},decodeToBytes:function(e){const{prefix:t,words:n}=u(e,!1);return{prefix:t,words:n,bytes:r(n)}},decodeUnsafe:mu(u),fromWords:r,fromWordsUnsafe:o,toWords:i}}const Ou=ku("bech32"),Au=ku("bech32m");var Su,Pu,$u,Iu,Tu;function Nu(e){if("string"!=typeof e||0===e.length)throw new Error(`invalid prefix: ${String(e)}`)}function Bu(e){if(!Array.isArray(e)||!e.every(e=>"number"==typeof e))throw new Error(`invalid words: ${String(e)}`)}!function(e){e.encode=e=>(b.is_u8a(e),vu(te).encode(e)),e.decode=e=>(b.is_base58(e),vu(te).decode(e))}(Su||(Su={})),function(e){e.encode=e=>(b.is_u8a(e),gu.encode(e)),e.decode=e=>(b.is_base64(e),gu.decode(e))}(Pu||(Pu={})),function(e){e.encode=e=>(b.is_u8a(e),wu.encode(e)),e.decode=e=>(b.is_b64url(e),wu.decode(e))}($u||($u={})),function(e){e.to_words=Ou.toWords,e.to_bytes=Ou.fromWords,e.encode=(e,t,n=!1)=>(Nu(e),Bu(t),Ou.encode(e,t,n)),e.decode=(e,t=!1)=>(b.is_bech32(e),Ou.decode(e,t))}(Iu||(Iu={})),function(e){e.to_words=Au.toWords,e.to_bytes=Au.fromWords,e.encode=(e,t,n=!1)=>(Nu(e),Bu(t),Au.encode(e,t,n)),e.decode=(e,t=!1)=>(b.is_bech32(e),Au.decode(e,t))}(Tu||(Tu={}));const Uu={base58:/^[13mn2][a-km-zA-HJ-NP-Z1-9]{25,34}$/,bech32:/^(bc|tb|bcrt)1q[ac-hj-np-z02-9]{6,87}$/,bech32m:/^(bc|tb|bcrt)1p[ac-hj-np-z02-9]{6,87}$/},Zu=0,Ru=1;function Cu(e){const t=function(e){for(const[t,n]of Object.entries(Uu))if(n.test(e))return t;return null}(e);if(null===t)throw new Error("unrecognized address format: "+t);if("base58"===t)return function(e){const t=Su.decode(e),n=t.slice(1),r=t[0];return{data:n,format:"base58",version:r}}(e);if("bech32"===t)return function(e){const{prefix:t,words:n}=Iu.decode(e),[r,...i]=n;b.ok(r===Zu,"bech32 version mismatch");return{data:Iu.to_bytes(i),format:"bech32",prefix:t,version:r}}(e);if("bech32m"===t)return function(e){const{prefix:t,words:n}=Tu.decode(e),[r,...i]=n;b.ok(r===Ru,"bech32m version mismatch");return{data:Tu.to_bytes(i),format:"bech32m",prefix:t,version:r}}(e);throw new Error("unable to find a matching address configuration")}function ju(e){if("base58"===e.format)return function(e){b.ok("base58"===e.format,"encoding mismatch"),b.exists(e.version,"must specify a version");const t=g.join([e.version,e.data]);return Su.encode(t)}(e);if("bech32"===e.format)return function(e){b.ok("bech32"===e.format,"encoding mismatch"),b.exists(e.prefix,"prefix is required");const t=g.bytes(e.data),n=Iu.to_words(t);return Iu.encode(e.prefix,[Zu,...n])}(e);if("bech32m"===e.format)return function(e){b.ok("bech32m"===e.format,"encoding mismatch"),b.exists(e.prefix,"prefix is required");const t=g.bytes(e.data),n=Tu.to_words(t);return Tu.encode(e.prefix,[Ru,...n])}(e);throw new Error("unrecognized encoding format: "+e.format)}const Fu=[["1","p2pkh","main",20,"base58",0],["3","p2sh","main",20,"base58",5],["m","p2pkh","testnet",20,"base58",111],["n","p2pkh","testnet",20,"base58",111],["2","p2sh","testnet",20,"base58",196],["m","p2pkh","regtest",20,"base58",111],["n","p2pkh","regtest",20,"base58",111],["2","p2sh","regtest",20,"base58",196],["bc","p2w-pkh","main",20,"bech32",0],["tb","p2w-pkh","testnet",20,"bech32",0],["bcrt","p2w-pkh","regtest",20,"bech32",0],["bc","p2w-sh","main",32,"bech32",0],["tb","p2w-sh","testnet",32,"bech32",0],["bcrt","p2w-sh","regtest",32,"bech32",0],["bc","p2tr","main",32,"bech32m",1],["tb","p2tr","testnet",32,"bech32m",1],["bcrt","p2tr","regtest",32,"bech32m",1]];function Du(e,t){for(const[n,r,i,o,s,u]of Fu)if(r===t&&i===e)return{type:r,prefix:n,network:i,size:o,format:s,version:u};return null}function Lu(e){const t=function(e){const t=Cu(e);for(const[n,r,i,o,s,u]of Fu){if(s!==t.format)continue;if(o!==t.data.length)continue;if(u!==t.version)continue;if(t.prefix){if(n!==t.prefix)continue}else if(!e.startsWith(n))continue;const a=g.uint(t.data).hex;return{data:t.data,hex:a,type:r,prefix:n,network:i,size:o,format:s,version:u}}throw new Error("address configuration is invalid")}(e),n=function(e,t){switch(t){case"p2pkh":return function(e){return{script_hex:"76a914"+e+"88ac",script_asm:["OP_DUP","OP_HASH160",e,"OP_EQUALVERIFY","OP_CHECKSIG"]}}(e);case"p2sh":return function(e){return{script_hex:"a914"+e+"87",script_asm:["OP_HASH160",e,"OP_EQUAL"]}}(e);case"p2w-pkh":return function(e){return{script_hex:"0014"+e,script_asm:["OP_0",e]}}(e);case"p2w-sh":return function(e){return{script_hex:"0020"+e,script_asm:["OP_0",e]}}(e);case"p2tr":return function(e){return{script_hex:"5120"+e,script_asm:["OP_1",e]}}(e);default:throw new Error("unrecognized script type: "+t)}}(t.hex,t.type);return{...t,...n}}const Hu="p2pkh";var Vu;function qu(e,t="main"){return Mu(hn(g.bytes(e)),t)}function Mu(e,t="main"){const n=g.bytes(e),r=Du(t,Hu);return b.exists(r,`unrecognized address config: ${Hu} on ${t}`),b.size(n,r.size,`invalid payload size: ${n.length} !== ${r.size}`),ju({data:n,format:"base58",version:r.version})}function Ku(e){const t=Lu(e);return b.ok("p2pkh"===t.type,`address type mismatch: ${t.type} !== ${Hu}`),t}!function(e){e.create=qu,e.encode=Mu,e.decode=Ku}(Vu||(Vu={}));const Gu="p2sh";var Wu;function Yu(e,t="main"){return Xu(hn(g.bytes(e)),t)}function Xu(e,t="main"){const n=g.bytes(e),r=Du(t,Gu);return b.exists(r,`unrecognized address config: ${Gu} on ${t}`),b.size(n,r.size,`invalid payload size: ${n.length} !== ${r.size}`),ju({data:n,format:"base58",version:r.version})}function Ju(e){const t=Lu(e);return b.ok("p2sh"===t.type,`address type mismatch: ${t.type} !== ${Gu}`),t}!function(e){e.create=Yu,e.encode=Xu,e.decode=Ju}(Wu||(Wu={}));const Qu="p2w-pkh";var ea;function ta(e,t="main"){const n=g.bytes(e);b.size(n,33,`invalid payload size: ${n.length} !== 33`);return na(hn(n),t)}function na(e,t="main"){const n=g.bytes(e),r=Du(t,Qu);return b.exists(r,`unrecognized address config: ${Qu} on ${t}`),b.size(n,r.size,`invalid payload size: ${n.length} !== ${r.size}`),ju({data:n,format:"bech32",prefix:r.prefix})}function ra(e){const t=Lu(e);return b.ok("p2w-pkh"===t.type,`address type mismatch: ${t.type} !== ${Qu}`),t}!function(e){e.create=ta,e.encode=na,e.decode=ra}(ea||(ea={}));const ia="p2w-sh";var oa;function sa(e,t="main"){return ua(pn(g.bytes(e)),t)}function ua(e,t="main"){const n=g.bytes(e),r=Du(t,ia);return b.exists(r,`unrecognized address config: ${ia} on ${t}`),b.size(n,r.size,`invalid payload size: ${n.length} !== ${r.size}`),ju({data:n,format:"bech32",prefix:r.prefix})}function aa(e){const t=Lu(e);return b.ok("p2w-sh"===t.type,`address type mismatch: ${t.type} !== ${ia}`),t}!function(e){e.create=sa,e.encode=ua,e.decode=aa}(oa||(oa={}));const ca="p2tr";var fa,da;function la(e,t="main"){const n=g.bytes(e),r=Du(t,ca);return b.exists(r,`unrecognized address config: ${ca} on ${t}`),b.size(n,r.size,`invalid payload size: ${n.length} !== ${r.size}`),ju({data:n,format:"bech32m",prefix:r.prefix})}function ha(e){const t=Lu(e);return b.ok("p2tr"===t.type,`address type mismatch: ${t.type} !== ${ca}`),t}!function(e){e.encode=la,e.decode=ha}(fa||(fa={})),function(e){e.P2PKH=Vu,e.P2SH=Wu,e.P2WPKH=ea,e.P2WSH=oa,e.P2TR=fa,e.parse=Lu}(da||(da={}));var pa=Object.freeze({__proto__:null,get AddressTool(){return da},get P2PKH(){return Vu},get P2SH(){return Wu},get P2TR(){return fa},get P2WPKH(){return ea},get P2WSH(){return oa},parse_address:Lu});const ma=5e8;var ga,wa;function _a(e){switch(e.type){case"timelock":return b.ok(e.stamp>=ma,"Invalid timestamp"),e.stamp;case"heightlock":return b.ok(e.height>0,"height must be greater than 0"),b.ok(e.height<ma,"invalid block height"),e.height;default:throw new Error("Invalid locktime type")}}function ya(e){return isNaN(e)||e<=0?null:e<ma?{type:"heightlock",height:e}:{type:"timelock",stamp:e}}function va(e,t=0){return`${e}i${t}`}function ba(e){xa(e);const[t,n]=e.split("i");return{txid:t,order:parseInt(n)}}function Ea(e){return null!==e.match(/^[a-f0-9]{64}i\d+$/)}function xa(e){if(!Ea(e))throw new Error(`invalid inscription id: ${e}`)}function za(e,t){return`${e}:${t}`}function ka(e){Aa(e);const[t,n]=e.split(":");return{block_height:parseInt(t),block_index:parseInt(n)}}function Oa(e){return null!==e.match(/^\d+:\d+$/)}function Aa(e){if(!Oa(e))throw new Error(`invalid rune id: ${e}`)}function Sa(e,t){return`${e}:${t}`}function Pa(e){Ia(e);const[t,n]=e.split(":");return{txid:t,vout:parseInt(n)}}function $a(e){return null!==e.match(/^[a-f0-9]{64}:[0-9]+$/)}function Ia(e){if(!$a(e))throw new Error(`invalid outpoint: ${e}`)}!function(e){e.encode=_a,e.decode=ya}(ga||(ga={})),function(e){e.outpoint={encode:Sa,decode:Pa,verify:$a,assert:Ia},e.record_id={encode:va,decode:ba,verify:Ea,assert:xa},e.rune_id={encode:za,decode:ka,verify:Oa,assert:Aa}}(wa||(wa={}));const Ta={OP_0:0,OP_PUSHDATA1:76,OP_PUSHDATA2:77,OP_PUSHDATA4:78,OP_1NEGATE:79,OP_SUCCESS80:80,OP_1:81,OP_2:82,OP_3:83,OP_4:84,OP_5:85,OP_6:86,OP_7:87,OP_8:88,OP_9:89,OP_10:90,OP_11:91,OP_12:92,OP_13:93,OP_14:94,OP_15:95,OP_16:96,OP_NOP:97,OP_SUCCESS98:98,OP_IF:99,OP_NOTIF:100,OP_ELSE:103,OP_ENDIF:104,OP_VERIFY:105,OP_RETURN:106,OP_TOALTSTACK:107,OP_FROMALTSTACK:108,OP_2DROP:109,OP_2DUP:110,OP_3DUP:111,OP_2OVER:112,OP_2ROT:113,OP_2SWAP:114,OP_IFDUP:115,OP_DEPTH:116,OP_DROP:117,OP_DUP:118,OP_NIP:119,OP_OVER:120,OP_PICK:121,OP_ROLL:122,OP_ROT:123,OP_SWAP:124,OP_TUCK:125,OP_SUCCESS126:126,OP_SUCCESS127:127,OP_SUCCESS128:128,OP_SUCCESS129:129,OP_SIZE:130,OP_SUCCESS131:131,OP_SUCCESS132:132,OP_SUCCESS133:133,OP_SUCCESS134:134,OP_EQUAL:135,OP_EQUALVERIFY:136,OP_SUCCESS137:137,OP_SUCCESS138:138,OP_1ADD:139,OP_1SUB:140,OP_SUCCESS141:141,OP_SUCCESS142:142,OP_NEGATE:143,OP_ABS:144,OP_NOT:145,OP_0NOTEQUAL:146,OP_ADD:147,OP_SUB:148,OP_SUCCESS149:149,OP_SUCCESS150:150,OP_SUCCESS151:151,OP_SUCCESS152:152,OP_SUCCESS153:153,OP_BOOLAND:154,OP_BOOLOR:155,OP_NUMEQUAL:156,OP_NUMEQUALVERIFY:157,OP_NUMNOTEQUAL:158,OP_LESSTHAN:159,OP_GREATERTHAN:160,OP_LESSTHANOREQUAL:161,OP_GREATERTHANOREQUAL:162,OP_MIN:163,OP_MAX:164,OP_WITHIN:165,OP_RIPEMD160:166,OP_SHA1:167,OP_SHA256:168,OP_HASH160:169,OP_HASH256:170,OP_CODESEPARATOR:171,OP_CHECKSIG:172,OP_CHECKSIGVERIFY:173,OP_CHECKMULTISIG:174,OP_CHECKMULTISIGVERIFY:175,OP_NOP1:176,OP_CHECKLOCKTIMEVERIFY:177,OP_CHECKSEQUENCEVERIFY:178,OP_NOP4:179,OP_NOP5:180,OP_NOP6:181,OP_NOP7:182,OP_NOP8:183,OP_NOP9:184,OP_NOP10:185,OP_CHECKSIGADD:186};function Na(e){if(e>186&&e<255)return"OP_SUCCESS"+String(e);for(const[t,n]of Object.entries(Ta))if(n===e)return t;throw new Error("OPCODE not found:"+String(e))}function Ba(e){for(const[t,n]of Object.entries(Ta))if(t===e)return Number(n);throw new Error("OPCODE not found:"+e)}function Ua(e){switch(!0){case 0===e:return"opcode";case e>=1&&e<=75:return"varint";case 76===e:return"pushdata1";case 77===e:return"pushdata2";case 78===e:return"pushdata4";case e<=254:return"opcode";default:throw new Error(`Invalid word range: ${e}`)}}function Za(e){switch(!0){case"number"!=typeof e:return!1;case 0===e:return!0;case[].includes(e):return!1;case 75<e&&e<254:return!0;default:return!1}}const Ra=520;function Ca(e,t=!1){if(0===e.length)return g.num(0,1);const n=[];for(const t of e)n.push(ja(t));const r=g.join(n);return t?r.prepend(g.varint(r.length,"le")):r}function ja(e){let t;if("string"==typeof e){if(e.startsWith("OP_")){const t=Ba(e);return g.num(t,1)}t=g.is_hex(e)?g.hex(e):g.str(e)}else if("number"==typeof e)t=g.num(e);else{if(!(e instanceof Uint8Array))throw new Error("invalid word type:"+typeof e);t=new g(e)}if(1===t.length&&t[0]<=16)0!==t[0]&&(t[0]+=80);else if(t.length>Ra){let e;e=Fa(t),e=e.map(e=>Da(e)),t=g.join(e)}else t=Da(t);return t}function Fa(e){const t=[],n=new w(e);for(;n.size>Ra;)t.push(n.read(Ra));return t.push(n.read(n.size)),t}function Da(e){const t=La(e.length);return g.join([t,e])}function La(e){const t=g.num(76,1),n=g.num(77,1);switch(!0){case e<=75:return g.num(e);case e>75&&e<256:return g.join([t,g.num(e,1,"le")]);case e>=256&&e<=Ra:return g.join([n,g.num(e,2,"le")]);default:throw new Error("Invalid word size:"+e.toString())}}function Ha(e){const t=new w(e),n=[],r=t.size;let i,o,s,u=0;for(;u<r;)switch(i=t.read(1).num,o=Ua(i),u++,o){case"varint":n.push(t.read(i).hex),u+=i;break;case"pushdata1":s=t.read(1).reverse().num,n.push(t.read(s).hex),u+=s+1;break;case"pushdata2":s=t.read(2).reverse().num,n.push(t.read(s).hex),u+=s+2;break;case"pushdata4":s=t.read(4).reverse().num,n.push(t.read(s).hex),u+=s+4;break;case"opcode":if(!Za(i))throw new Error(`Invalid OPCODE: ${i}`);n.push(Na(i));break;default:throw new Error(`Word type undefined: ${i}`)}return n}function Va(e){try{return Ha(e).length>0}catch{return!1}}const qa=BigInt(0),Ma=BigInt(1),Ka=BigInt(26);var Ga;function Wa(e){const t=function(e){const t=Ha(e),n=t.findIndex(e=>"OP_0"===e);b.ok(-1!==n,"inscription envelope not found");const r=[];for(let e=n;e<t.length;e++){b.ok("OP_IF"===t[e+1],"OP_IF missing from envelope"),b.ok("6f7264"===t[e+2],"magic bytes missing from envelope");const n=t.findIndex(e=>"OP_ENDIF"===e);b.ok(-1!==n,"inscription envelope missing END_IF statement");const i=t.slice(e+3,n);r.push(i),e+=n}return r}(e);return t.map(Ja)}function Ya(e){return g.join(e.map(Xa))}function Xa(e){let t=["OP_0","OP_IF","6f7264"];if("string"==typeof e.delegate){const n=ec(e.delegate);t.push("OP_11",n)}if("string"==typeof e.ref&&t.push("OP_WITHIN",e.ref),"string"==typeof e.parent){const n=ec(e.parent);t.push("OP_3",n)}if("number"==typeof e.opcode){const n=nc(e.opcode);t.push("OP_NOP",n)}if("number"==typeof e.pointer){const n=nc(e.pointer);t.push("OP_2",n)}if("string"==typeof e.rune){const n=function(e){const t=e.toUpperCase();let n=qa;for(const e of t)e>="A"&&e<="Z"&&(n=n*Ka+BigInt(e.charCodeAt(0)-("A".charCodeAt(0)-1)));return n-=Ma,g.big(n).reverse().hex}(e.rune);t.push("OP_13",n)}if("string"==typeof e.mimetype){const n=function(e){return g.str(e).hex}(e.mimetype);t.push("OP_1",n)}if("string"==typeof e.content){const n=function(e){const t=g.is_hex(e)?g.hex(e):g.str(e),n=new w(t),r=[];for(;n.size>0;)if(n.size>520){const e=n.read(520);r.push(e.hex)}else{const e=n.read(n.size);r.push(e.hex)}return r}(e.content);t.push("OP_0",...n)}return t.push("OP_ENDIF"),Ca(t)}function Ja(e){const t={};for(let n=0;n<e.length;n++)switch(e[n]){case"OP_1":t.mimetype=ic(e[n+1]),n+=1;break;case"OP_2":t.pointer=rc(e[n+1]),n+=1;break;case"OP_3":t.parent=tc(e[n+1]),n+=1;break;case"OP_11":t.delegate=tc(e[n+1]),n+=1;break;case"OP_13":t.rune=sc(e[n+1]),n+=1;break;case"OP_WITHIN":t.ref=Qa(e[n+1]),n+=1;break;case"OP_NOP":t.opcode=rc(e[n+1]),n+=1;break;case"OP_0":return t.content=oc(e.slice(n+1)),t}return t}function Qa(e){return g.bytes(e).hex}function ec(e){b.ok(e.includes("i"),"identifier must include an index");const t=e.split("i"),n=g.hex(t[0]),r=Number(t[1]),i=n.reverse().hex;return 0!==r?i+g.num(r).hex:i}function tc(e){const t=g.bytes(e),n=t.at(-1)??0;return t.slice(0,-1).reverse().hex+"i"+String(n)}function nc(e){return g.num(e).reverse().hex}function rc(e){return g.bytes(e).reverse().num}function ic(e){return g.bytes(e).str}function oc(e,t="hex"){const n=g.join(e);return"hex"===t?n.hex:n.str}function sc(e){let t=g.bytes(e).reverse().big;t+=Ma;let n="";for(;t>qa;){const e=t%Ka;if(e===qa)n="Z"+n,t=t/Ka-Ma;else{const r=Number(e)+"A".charCodeAt(0)-1;n=String.fromCharCode(r)+n,t/=Ka}}return n}!function(e){e.encode=Ya,e.decode=Wa}(Ga||(Ga={}));const uc=4194304,ac=65535,cc=65535;var fc;function dc(e){if("height"===e.mode){return(function(e){if(void 0===e||!Number.isInteger(e)||e<0||e>cc)throw new Error("Heightlock value must be an integer between 0 and 65535");return e}(e.height)&ac)>>>0}if("stamp"===e.mode){const t=function(e){if(void 0===e||!Number.isInteger(e))throw new Error("timestamp must be a number");const t=Math.floor(e/512);if(!Number.isInteger(t)||t<0||t>cc)throw new Error("timelock value must be an integer between 0 and 65535 (in 512-second increments)");return t}(e.stamp);return(uc|t&ac)>>>0}throw new Error("invalid timelock mode: "+e.mode)}function lc(e){const t=function(e){const t="string"==typeof e?parseInt(e,16):e;if(!Number.isInteger(t)||t<0||t>4294967295)throw new Error(`invalid sequence value: ${t}`);return t}(e);if(2147483648&t)return null;const n=t&ac;if(t&uc){const e=512*n;if(e>4294967295)throw new Error("Decoded timestamp exceeds 32-bit limit");return{mode:"stamp",stamp:e}}if(n>cc)throw new Error("Decoded height exceeds maximum");return{mode:"height",height:n}}!function(e){e.encode=dc,e.decode=lc}(fc||(fc={}));var hc,pc=Object.freeze({__proto__:null,get InscriptionUtil(){return Ga},get LocktimeField(){return ga},get RefPointer(){return wa},get SequenceField(){return fc},decode_inscription:Wa,decode_locktime:ya,decode_sequence:lc,encode_inscription:Ya,encode_locktime:_a,encode_sequence:dc});function mc(e){return g.bytes(e).prefix_varint("le").hex}function gc(e){return[...("string"==typeof e?e:g.bytes(e).hex).matchAll(/20([0-9a-f]{64})(ac|ad|ba)/gi)].map(e=>e[1])}!function(e){e.prefix_size=mc,e.decode=Ha,e.encode=Ca,e.is_valid=Va,e.get_pubkeys=gc,e.OPCODES=Ta}(hc||(hc={}));var wc=Object.freeze({__proto__:null,OPCODE_MAP:Ta,get ScriptUtil(){return hc},decode_script:Ha,encode_script:Ca,encode_script_word:ja,get_asm_code:Ba,get_op_code:Na,get_op_type:Ua,get_size_varint:La,is_valid_op:Za,is_valid_script:Va,parse_script_pubkeys:gc,prefix_script_size:mc,prefix_word_size:Da,split_script_word:Fa});function _c(e){return b.exists(e.prevout,"Prevout data missing for input: "+String(e.txid)),e.prevout}function yc(e,t){let{txindex:n,txinput:r}=t??{};if(void 0!==n){if(n>=e.vin.length)throw new Error("Input index out of bounds: "+String(n));r=e.vin.at(n)}return b.ok(void 0!==r),r}function vc(e){if(void 0===e)return;if(e.length<2)return;const t=e.at(-1);if("string"==typeof t&&t.startsWith("50")){return pn(g.hex(t).prefix_varint("be"))}}const bc={TXID:"00".repeat(32),VOUT:4294967295},Ec={LOCKTIME:0,SEQUENCE:4294967295,VERSION:2},xc=[192,194,196,198,200,202,204,206,208,210,212,214,216,218,220,222,224,226,228,230,232,234,236,238,240,242,244,246,248,250,252,254,102,126,128,132,150,152,186,188,190],zc={p2pkh:/^76a914[0-9a-f]{40}88ac$/i,p2sh:/^a914[0-9a-f]{40}87$/i,p2wpkh:/^0014[0-9a-f]{40}$/i,p2wsh:/^0020[0-9a-f]{64}$/i,p2tr:/^5120[0-9a-f]{64}$/i,opreturn:/^6a[0-9a-f]{2,}$/i},kc=[1,2,3,129,130,131],Oc=[0,...kc];var Ac=Object.freeze({__proto__:null,COINBASE:bc,DEFAULT:Ec,LOCK_SCRIPT_REGEX:zc,SCRIPT_INT_KEY:"",SIGHASH_DEFAULT:1,SIGHASH_SEGWIT:kc,SIGHASH_TAPROOT:Oc,TAPLEAF_DEFAULT_VERSION:192,TAPLEAF_VERSIONS:xc,TX_SIZE:{GLOBAL_BASE:8,GLOBAL_WIT:10,TXIN_BASE:40,TXOUT_BASE:8}});const Sc=_s([ps(Xs),Xs]),Pc=gs({pubkey:Xs,leaves:Sc.array().optional(),target:Xs.optional(),version:Ds.optional()});var $c=Object.freeze({__proto__:null,config:Pc,taptree:Sc});const Ic=os().min(0n).max(2100000000000000n),Tc=gs({value:Ic,script_pk:Ls}),Nc=gs({coinbase:Ls.nullable(),txid:Gs,vout:Ds,prevout:Tc.nullable(),script_sig:Ls.nullable(),sequence:Ds,witness:ps(Ls)}),Bc=gs({version:Ds,vin:ps(Nc),vout:ps(Tc),locktime:Ds}),Uc=Tc.extend({value:_s([Ds,Ic])}),Zc=Nc.extend({coinbase:Ls.nullable().optional(),prevout:Uc.nullable().optional(),script_sig:Ls.nullable().optional(),sequence:_s([Ls,Ds]).optional(),witness:ps(Ls).optional()}),Rc=gs({version:Ds.optional(),vin:ps(Zc),vout:ps(Uc),locktime:Ds.optional()});var Cc=Object.freeze({__proto__:null,tx_data:Bc,tx_input:Nc,tx_output:Tc,tx_template:Rc,vin_template:Zc,vout_template:Uc}),jc=Object.freeze({__proto__:null,taproot:$c,tx:Cc});function Fc(e){Rc.parse(e)}function Dc(e){if(e.some(e=>null===e.prevout))throw new Error("transaction missing prevouts")}function Lc(e){Bc.parse(e)}function Hc(e){Zc.parse(e)}function Vc(e){Uc.parse(e)}function qc(e,t=!0){Lc(e);const{version:n,vin:r,vout:i,locktime:o}=e,s=[Mc(n)];if(t&&s.push(g.hex("0001")),s.push(Yc(r)),s.push(Qc(i)),t)for(const e of r)s.push(tf(e.witness));return s.push(nf(o)),g.join(s)}function Mc(e){return g.num(e,4).reverse()}function Kc(e){return g.hex(e,32).reverse()}function Gc(e){return g.num(e,4).reverse()}function Wc(e){return g.num(e,4).reverse()}function Yc(e){const t=[g.varint(e.length,"le")];for(const n of e)t.push(Xc(n));return g.join(t)}function Xc(e){return null!==e.coinbase?g.join([Kc(bc.TXID),Gc(bc.VOUT),rf(e.coinbase),Wc(e.sequence)]):g.join([Kc(e.txid),Gc(e.vout),rf(e.script_sig),Wc(e.sequence)])}function Jc(e){return g.big(e,8).reverse()}function Qc(e){const t=[g.varint(e.length,"le")];for(const n of e)t.push(ef(n));return g.join(t)}function ef(e){const{value:t,script_pk:n}=e;return g.join([Jc(t),rf(n)])}function tf(e){const t=[g.varint(e.length)];for(const n of e)t.push(rf(n));return g.join(t)}function nf(e){return g.num(e,4).reverse()}function rf(e){return null!==e?(b.is_hex(e),g.hex(e).prefix_varint("le")):g.hex("00")}function of(e,t=!0){b.is_bytes(e,"txdata must be hex or bytes");const n=new w(e),r=function(e){return e.read(4).reverse().to_num()}(n),i=!!t&&function(e){const[t,n]=[...e.peek(2)];if(0===t){if(e.read(2),1===n)return!0;throw new Error(`Invalid witness flag: ${n}`)}return!1}(n),o=function(e){const t=[],n=e.varint();for(let r=0;r<n;r++){const n=sf(e);t.push(n)}return t}(n),s=function(e){const t=[],n=e.varint();for(let r=0;r<n;r++)try{t.push(uf(e))}catch(e){throw new Error(`failed to decode output: ${r}: ${y(e)}`)}return t}(n);if(i)for(const e of o)e.witness=af(n);const u=function(e){return e.read(4).reverse().to_num()}(n);return{version:r,vin:o,vout:s,locktime:u}}function sf(e){const t=e.read(32).reverse().hex,n=e.read(4).reverse().num,r=cf(e),i=e.read(4).reverse().num,o=[];return t===bc.TXID&&n===bc.VOUT?{coinbase:r,prevout:null,script_sig:null,sequence:i,txid:t,vout:n,witness:o}:{coinbase:null,prevout:null,script_sig:r,sequence:i,txid:t,vout:n,witness:o}}function uf(e){const t=e.read(8).reverse().big,n=cf(e);return b.exists(n,"failed to decode script_pk"),{value:t,script_pk:n}}function af(e){const t=[],n=e.varint();for(let r=0;r<n;r++){const n=cf(e);if(null===n)throw new Error("failed to decode witness element: "+r);t.push(n)}return t}function cf(e){const t=e.varint("le");return t>0?e.read(t).hex:null}function ff(e,t){let n;if("string"==typeof e||e instanceof Uint8Array?n=of(e):(Fc(e),n=bf(e)),t){b.has_items(t,"prevouts must be a non-empty array");for(const[e,r]of n.vin.entries()){const n=t.at(e);b.exists(n,"prevout not found for input index: "+e),r.prevout=vf(n)}}return n}function df(e){const t=g.bytes(e).hex;for(const[e,n]of Object.entries(zc))if(n.test(t))return e;return null}function lf(e){switch(g.bytes(e).at(0)){case 0:return 0;case 81:return 1;default:return null}}function hf(e){if(!v.exists(e))return Ec.SEQUENCE;if(v.is_hex(e))return g.hex(e,4).reverse().num;if(v.is_uint(e))return e;throw new Error("invalid sequence value: "+String(e))}function pf(e){if(v.is_uint(e))return BigInt(e);if("bigint"==typeof e)return e;throw new TypeError("invalid output value: "+String(e))}function mf(e){return{script_pk:e.script_pk,value:pf(e.value)}}function gf(e){Hc(e),b.exists(e.coinbase,"coinbase is required");const t=bc.TXID,n=bc.VOUT,r=e.coinbase,i=e.witness??[];return{coinbase:r,prevout:null,script_sig:null,sequence:hf(e.sequence),witness:i,txid:t,vout:n}}function wf(e){Hc(e),b.is_empty(e.coinbase,"coinbase is not allowed"),b.is_empty(e.prevout,"prevout is not allowed");const{txid:t,vout:n,script_sig:r=null,witness:i=[]}=e;return{txid:t,vout:n,coinbase:null,prevout:null,script_sig:r,sequence:hf(e.sequence),witness:i}}function _f(e){Hc(e),b.exists(e.prevout,"prevout is required");const{txid:t,vout:n,script_sig:r=null,witness:i=[]}=e;return{txid:t,vout:n,coinbase:null,prevout:mf(e.prevout),script_sig:r,sequence:hf(e.sequence),witness:i}}function yf(e){return e.coinbase?gf(e):e.prevout?_f(e):wf(e)}function vf(e){Vc(e);return{script_pk:e.script_pk,value:pf(e.value)}}function bf(e){Fc(e);const{vin:t=[],vout:n=[]}=e??{vin:[],vout:[]},r=e.locktime??Ec.LOCKTIME,i=e.version??Ec.VERSION;return{locktime:r,vin:t.map(e=>yf(e)),vout:n.map(e=>vf(e)),version:i}}var Ef=Object.freeze({__proto__:null,assert_has_prevouts:Dc,assert_tx_data:Lc,assert_tx_input:function(e){Nc.parse(e)},assert_tx_output:function(e){Tc.parse(e)},assert_tx_spend_data:function(e){Lc(e),Dc(e.vin)},assert_tx_template:Fc,assert_vin_template:Hc,assert_vout_template:Vc,create_coinbase_input:gf,create_spend_input:_f,create_tx:bf,create_tx_input:yf,create_tx_output:vf,create_virtual_input:wf,decode_tx:of,encode_script_data:rf,encode_tx:qc,encode_tx_inputs:Yc,encode_tx_locktime:nf,encode_tx_outputs:Qc,encode_tx_version:Mc,encode_tx_vout:ef,encode_txin_sequence:Wc,encode_txin_txid:Kc,encode_txin_vout:Gc,encode_vin:Xc,encode_vin_witness:tf,encode_vout_value:Jc,get_prevouts:function(e){Fc(e);const t=e.vin.map(e=>e.prevout);return b.ok(t.every(e=>null!==e),"prevouts missing from tx"),t},get_segwit_size:function(e){return 2+e.filter(e=>e.witness.length>0).map(e=>e.witness).reduce((e,t)=>e+tf(t).length,0)},get_tx_value:function(e){const t=ff(e);Fc(t);const n=t.vin.reduce((e,t)=>e+(t.prevout?.value??0n),0n),r=t.vout.reduce((e,t)=>e+t.value,0n);return{fees:n>r?n-r:0n,vin:n,vout:r}},get_txhash:function(e){return"object"==typeof e&&(Fc(e),e=qc(e,!0)),mn(e).reverse().hex},get_txid:function(e){return"object"==typeof e&&(Fc(e),e=qc(e,!1)),mn(e).reverse().hex},get_txin_size:function(e){return Xc(e).length},get_txout_size:function(e){return ef(e).length},get_txsize:function(e){const t=ff(e),n=qc(t,!1).length,r=qc(t,!0).length,i=3*n+r,o=i%4>0?1:0;return{base:n,total:r,vsize:Math.ceil(i/4)+o,weight:i}},get_vin_size:function(e){return Yc(e).length},get_vout_script_info:function(e){return{type:df(e),version:lf(e)}},get_vout_script_type:df,get_vout_script_version:lf,get_vout_size:function(e){return Qc(e).length},get_vsize:function(e){const t=g.bytes(e).length,n=t%4>0?1:0;return Math.ceil(t/4)+n},is_return_script:function(e){return 106===g.bytes(e).at(0)},normalize_prevout:mf,normalize_sequence:hf,normalize_value:pf,parse_tx:ff,read_payload:cf,serialize_tx:function(e){const t=ff(e),n=t.version,r=t.locktime,i=[],o=[];for(const e of t.vin)null!==e.prevout&&i.push({script_pk:e.prevout.script_pk,value:Number(e.prevout.value)});for(const e of t.vout)o.push({script_pk:e.script_pk,value:Number(e.value)});return{version:n,locktime:r,vin:i,vout:o}}});function xf(e,t={}){const{sigflag:n=1,txindex:r}=t,i=ff(e),o=!(128&~n),s=n%128;if(!kc.includes(s))throw new Error("Invalid hash type: "+String(n));const{version:u,vin:a,vout:c,locktime:f}=i,d=yc(i,t),{txid:l,vout:h,prevout:p,sequence:m}=d,{value:w}=p??{};if(void 0===w)throw new Error("Prevout value is empty!");let{pubkey:_,script:y}=t;if(void 0===y&&void 0!==_){const e=hn(_).hex;y=`76a914${String(e)}88ac`}if(void 0===y)throw new Error("No pubkey / script has been set!");if(Ha(y).includes("OP_CODESEPARATOR"))throw new Error("This library does not currently support the use of OP_CODESEPARATOR in segwit scripts.");const v=[Mc(u),zf(a,o),kf(a,s,o),Kc(l),Gc(h),mc(y),Jc(w),Wc(m),Of(c,s,r),nf(f),g.num(n,4).reverse()];return mn(g.join(v))}function zf(e,t){if(!0===t)return g.num(0,32);const n=[];for(const{txid:t,vout:r}of e)n.push(Kc(t)),n.push(Gc(r));return mn(g.join(n))}function kf(e,t,n){if(n||1!==t)return g.num(0,32);const r=[];for(const{sequence:t}of e)r.push(Wc(t));return mn(g.join(r))}function Of(e,t,n){const r=[];if(1===t){for(const{value:t,script_pk:n}of e)r.push(Jc(t)),r.push(mc(n));return mn(g.join(r))}if(3===t&&(b.ok(void 0!==n),n<e.length)){const{value:t,script_pk:i}=e[n];return r.push(Jc(t)),r.push(mc(i)),mn(g.join(r))}return g.num(0,32)}function Af(e,t=192){return Sf(mc(e),t)}function Sf(e,t=192){return gn("TapLeaf",$f(t),e)}function Pf(e,t){return t<e&&([e,t]=[t,e]),gn("TapBranch",e,t)}function $f(e=192){return 254&e}function If(e,t=new Uint8Array){return b.size(e,32),gn("TapTweak",e,t)}function Tf(e,t={}){return gn("TapSighash",Nf(e,t))}function Nf(e,t={}){const{script:n,txindex:r,sigflag:i=0,extflag:o=0,key_version:s=0,separator_pos:u=4294967295}=t,a=ff(e),{version:c,vin:f,vout:d,locktime:l}=a,h=yc(a,t),{txid:p,vout:m,sequence:w,witness:_=[]}=h;if(!Oc.includes(i))throw new Error("Invalid hash type: "+String(i));if(o<0||o>127)throw new Error("Extention flag out of range: "+String(o));let{extension:y}=t;void 0!==n&&(y=Af(n).hex);const v=!(128&~i),E=vc(_),x=2*(o+(void 0!==y?1:0))+(void 0!==E?1:0),z=[g.num(0,1),g.num(i,1),Mc(c),nf(l)];if(!v){const e=f.map(e=>_c(e));z.push(Bf(f),Zf(e),Rf(e),Uf(f))}if(((3&i)<2||(3&i)>3)&&z.push(Cf(d)),z.push(g.num(x,1)),v){const{value:e,script_pk:t}=_c(h);z.push(Kc(p),Gc(m),Jc(e),rf(t),Wc(w))}else b.ok("number"==typeof r),z.push(g.num(r,4).reverse());return void 0!==E&&z.push(E),3&~i||(b.ok("number"==typeof r),z.push(jf(d[r]))),void 0!==y&&z.push(g.bytes(y),g.num(s),g.num(u,4,"le")),g.join(z)}function Bf(e){const t=[];for(const{txid:n,vout:r}of e)t.push(Kc(n)),t.push(Gc(r));return pn(g.join(t))}function Uf(e){return pn(...e.map(e=>Wc(e.sequence)))}function Zf(e){return pn(...e.map(e=>Jc(e.value)))}function Rf(e){return pn(...e.map(e=>rf(e.script_pk)))}function Cf(e){const t=[];for(const{value:n,script_pk:r}of e)t.push(Jc(n)),t.push(rf(r));return pn(...t)}function jf(e){return pn(Jc(e.value),rf(e.script_pk))}var Ff=Object.freeze({__proto__:null,bip143_hash_outputs:Of,bip143_hash_prevouts:zf,bip143_hash_sequence:kf,bip341_hash_amounts:Zf,bip341_hash_outpoints:Bf,bip341_hash_output:jf,bip341_hash_outputs:Cf,bip341_hash_scripts:Rf,bip341_hash_sequence:Uf,get_annex_data:vc,get_prevout:_c,get_taproot_tx_preimage:Nf,hash_segwit_tx:xf,hash_taproot_tx:Tf,parse_txinput:yc});function Df(e){return 0!==e?g.num(e,1).hex:""}var Lf=Object.freeze({__proto__:null,sign_segwit_tx:function(e,t,n){return function(e,t){const n=Yt(t),r=St.sign(n,e).toDERRawBytes();return g.bytes(r)}(e,xf(ff(t),n)).hex+Df(n.sigflag??1)},sign_taproot_tx:function(e,t,n){return function(e,t){const n=Yt(t);return Yt(Vt.sign(n,e))}(e,Tf(ff(t),n)).hex+Df(n.sigflag??0)},verify_tx:function(e,t={}){return console.warn("verify_segwit_tx is not implemented"),!0}});function Hf(e,t,n=[]){const r=[],i=[];if(e.length<1)throw new Error("Tree is empty!");for(let i=0;i<e.length;i++){const o=e[i];if(Array.isArray(o)){let[e,i,s]=Hf(o,t);t=i,r.push(e);for(const e of s)n.push(e)}else{const e=g.bytes(o).hex;r.push(e)}}if(1===r.length)return[r[0],t,n];r.sort(),r.length%2!=0&&r.push(r[r.length-1]);for(let e=0;e<r.length-1;e+=2){const o=Pf(r[e],r[e+1]).hex;i.push(o),"string"==typeof t&&(t===r[e]?(n.push(r[e+1]),t=o):t===r[e+1]&&(n.push(r[e]),t=o))}return Hf(i,t,n)}function Vf(e){const t=e.map(e=>g.bytes(e)),n=e.map(e=>g.bytes(e).hex),r=function(e){let t=e.at(-1);return e.length>1&&t instanceof Uint8Array&&80===t[0]?new g(t).hex:null}(t);null!==r&&t.pop();const i=function(e){let t=e.at(-1);return e.length>1&&t instanceof Uint8Array&&t.length>32&&xc.includes(254&t[0])?new g(t).hex:null}(t);null!==i&&t.pop();const o=function(e,t){let n=e.at(0),r=e.at(1),i=e.at(-1);return null!==t&&void 0!==i?"p2tr-ts":2===e.length&&void 0!==n&&void 0!==r&&n.length>=64&&33===r.length?"p2w-pkh":1===e.length&&void 0!==n&&64===n.length?"p2tr-pk":e.length>1&&void 0!==i&&Va(i)?"p2w-sh":"unknown"}(t,i),s=function(e){return e.startsWith("p2tr")?1:e.startsWith("p2w")?0:null}(o),u=function(e,t){let n;switch(t){case"p2tr-ts":n=e.at(-1);case"p2w-sh":n=e.at(-1)}return void 0!==n?new g(n).hex:null}(t,o);null!==u&&t.pop();return{annex:r,cblock:i,params:t.map(e=>e.hex),script:u,stack:n,type:o,version:s}}function qf(e){const t=new w(e),n=t.read(1).num,r=t.read(32).hex,[i,o]=Mf(n),s=[];for(;t.size>=32;)s.push(t.read(32).hex);if(0!==t.size)throw new Error("Non-empty buffer on control block: "+String(t));return{int_key:r,path:s,parity:o,version:i}}function Mf(e){return e%2==0?[e-0,2]:[e-1,3]}function Kf(e){b.size(e,33,"invalid pubkey size");const[t]=g.bytes(e);if(2===t)return 0;if(3===t)return 1;throw new Error("Invalid parity bit: "+String(t))}const Gf=192;var Wf=Object.freeze({__proto__:null,create_taproot:function(e){Pc.parse(e);const{pubkey:t,version:n=Gf}=e,r=e.leaves??[],i=void 0!==e.target?g.bytes(e.target).hex:void 0;let o,s=[];if(r.length>0){const[e,t,n]=Hf(r,i);s=n,o=e}else o=i;const u=If(t,o),a=Gt(t,u,"ecdsa"),c=Kf(a),f=Wt(a,"bip340"),d=[g.num(n+c),g.bytes(t)];s.length>0&&s.forEach(e=>d.push(e));const l=g.join(d);return{int_key:g.bytes(t).hex,path:s,parity:c,taproot:o??null,cblock:l.hex,tapkey:f.hex,taptweak:u.hex}},encode_leaf_version:$f,encode_tapbranch:Pf,encode_tapleaf:Sf,encode_tapscript:Af,encode_taptweak:If,get_merkle_root:function(e){return Hf(e)[0]},merkleize:Hf,parse_cblock:qf,parse_cblock_parity:Mf,parse_pubkey_parity:Kf,parse_taproot_witness:function(e){const{cblock:t,params:n,script:r}=Vf(e);b.exists(t,"cblock is null"),b.exists(r,"script is null");const i=qf(t);let o=Af(r,i.version).hex;for(const e of i.path)o=Pf(o,e).hex;const s=If(i.int_key,o),u=Gt(i.int_key,s,"bip340");return n.map(e=>g.bytes(e).hex),{cblock:i,params:n,script:r,tapkey:u.hex,tweak:s.hex}},verify_taproot:function(e,t,n){b.size(e,32);const{parity:r,path:i,int_key:o}=qf(n),s=g.join([r,e]);let u=g.bytes(t).hex;for(const e of i)u=Pf(u,e).hex;const a=Gt(o,If(o,u),"ecdsa");return s.hex===a.hex}});var Yf=Object.freeze({__proto__:null,assert_witness:function(e){b.ok(Array.isArray(e),"witness must be an array"),b.ok(e.every(e=>g.is_bytes(e)),"witness must be an array of strings or bytes")},get_witness_size:function(e){const t=e.map(e=>g.bytes(e)).reduce((e,t)=>e+t.length,0);return{total:t,vsize:Math.ceil(1+t/4)}},parse_witness:Vf});return e.ADDRESS=pa,e.CONST=Ac,e.META=pc,e.SCHEMA=jc,e.SCRIPT=wc,e.SIGHASH=Ff,e.SIGNER=Lf,e.TAPROOT=Wf,e.TX=Ef,e.WITNESS=Yf,e}({});
13
+ function Js(e){return e instanceof Uint8Array||ArrayBuffer.isView(e)&&"Uint8Array"===e.constructor.name}function Qs(e,t){return!!Array.isArray(t)&&(0===t.length||(e?t.every(e=>"string"==typeof e):t.every(e=>Number.isSafeInteger(e))))}function eu(e){if("function"!=typeof e)throw new Error("function expected");return!0}function tu(e,t){if("string"!=typeof t)throw new Error(`${e}: string expected`);return!0}function nu(e){if(!Number.isSafeInteger(e))throw new Error(`invalid integer: ${e}`)}function ru(e){if(!Array.isArray(e))throw new Error("array expected")}function iu(e,t){if(!Qs(!0,t))throw new Error(`${e}: array of strings expected`)}function ou(e,t){if(!Qs(!1,t))throw new Error(`${e}: array of numbers expected`)}function su(...e){const t=e=>e,n=(e,t)=>n=>e(t(n));return{encode:e.map(e=>e.encode).reduceRight(n,t),decode:e.map(e=>e.decode).reduce(n,t)}}function uu(e){const t="string"==typeof e?e.split(""):e,n=t.length;iu("alphabet",t);const r=new Map(t.map((e,t)=>[e,t]));return{encode:r=>(ru(r),r.map(r=>{if(!Number.isSafeInteger(r)||r<0||r>=n)throw new Error(`alphabet.encode: digit index outside alphabet "${r}". Allowed: ${e}`);return t[r]})),decode:t=>(ru(t),t.map(t=>{tu("alphabet.decode",t);const n=r.get(t);if(void 0===n)throw new Error(`Unknown letter: "${t}". Allowed: ${e}`);return n}))}}function cu(e=""){return tu("join",e),{encode:t=>(iu("join.decode",t),t.join(e)),decode:t=>(tu("join.decode",t),t.split(e))}}function au(e,t,n){if(t<2)throw new Error(`convertRadix: invalid from=${t}, base cannot be less than 2`);if(n<2)throw new Error(`convertRadix: invalid to=${n}, base cannot be less than 2`);if(ru(e),!e.length)return[];let r=0;const i=[],o=Array.from(e,e=>{if(nu(e),e<0||e>=t)throw new Error(`invalid integer: ${e}`);return e}),s=o.length;for(;;){let e=0,u=!0;for(let i=r;i<s;i++){const s=o[i],c=t*e,a=c+s;if(!Number.isSafeInteger(a)||c/t!==e||a-s!==c)throw new Error("convertRadix: carry overflow");const f=a/n;e=a%n;const d=Math.floor(f);if(o[i]=d,!Number.isSafeInteger(d)||d*n+e!==a)throw new Error("convertRadix: carry overflow");u&&(d?u=!1:r=i)}if(i.push(e),u)break}for(let t=0;t<e.length-1&&0===e[t];t++)i.push(0);return i.reverse()}ws([Gs,Ms]),ws([Ys,Ks]),$o().regex(/^[1-9A-HJ-NP-Za-km-z]+$/),$o().regex(/^[a-zA-Z0-9+/]+={0,2}$/),$o().regex(/^[a-zA-Z0-9\-_]+={0,2}$/),$o().regex(/^[a-z]+1[023456789acdefghjklmnpqrstuvwxyz]+$/);const fu=(e,t)=>0===t?e:fu(t,e%t),du=(e,t)=>e+(t-fu(e,t)),lu=(()=>{let e=[];for(let t=0;t<40;t++)e.push(2**t);return e})();function hu(e,t,n,r){if(ru(e),t<=0||t>32)throw new Error(`convertRadix2: wrong from=${t}`);if(n<=0||n>32)throw new Error(`convertRadix2: wrong to=${n}`);if(du(t,n)>32)throw new Error(`convertRadix2: carry overflow from=${t} to=${n} carryBits=${du(t,n)}`);let i=0,o=0;const s=lu[t],u=lu[n]-1,c=[];for(const r of e){if(nu(r),r>=s)throw new Error(`convertRadix2: invalid data word=${r} from=${t}`);if(i=i<<t|r,o+t>32)throw new Error(`convertRadix2: carry overflow pos=${o} from=${t}`);for(o+=t;o>=n;o-=n)c.push((i>>o-n&u)>>>0);const e=lu[o];if(void 0===e)throw new Error("invalid carry");i&=e-1}if(i=i<<n-o&u,!r&&o>=t)throw new Error("Excess padding");if(!r&&i>0)throw new Error(`Non-zero padding: ${i}`);return r&&o>0&&c.push(i>>>0),c}function pu(e,t=!1){if(nu(e),e<=0||e>32)throw new Error("radix2: bits should be in (0..32]");if(du(8,e)>32||du(e,8)>32)throw new Error("radix2: carry overflow");return{encode:n=>{if(!Js(n))throw new Error("radix2.encode input should be Uint8Array");return hu(Array.from(n),8,e,!t)},decode:n=>(ou("radix2.decode",n),Uint8Array.from(hu(n,e,8,t)))}}function mu(e){return eu(e),function(...t){try{return e.apply(null,t)}catch(e){}}}const gu=(()=>"function"==typeof Uint8Array.from([]).toBase64&&"function"==typeof Uint8Array.fromBase64)()?{encode:e=>(function(e,...t){if(!Js(e))throw new Error("Uint8Array expected");if(t.length>0&&!t.includes(e.length))throw new Error("Uint8Array expected of length "+t+", got length="+e.length)}(e),e.toBase64()),decode:e=>(e=>{if(tu("base64",e),e.length>0&&!/^[A-Za-z0-9=+/]+$/.test(e))throw new Error("invalid base64");return Uint8Array.fromBase64(e,{alphabet:"base64",lastChunkHandling:"strict"})})(e)}:su(pu(6),uu("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"),function(e,t="="){return nu(e),tu("padding",t),{encode(n){for(iu("padding.encode",n);n.length*e%8;)n.push(t);return n},decode(n){iu("padding.decode",n);let r=n.length;if(r*e%8)throw new Error("padding: invalid, string should have whole number of bytes");for(;r>0&&n[r-1]===t;r--){if((r-1)*e%8==0)throw new Error("padding: invalid, string has too much padding")}return n.slice(0,r)}}}(6),cu("")),_u=su(pu(6),uu("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_"),cu("")),wu=(yu="123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz",su(function(e){return nu(e),{encode:t=>{if(!Js(t))throw new Error("radix.encode input should be Uint8Array");return au(Array.from(t),256,e)},decode:t=>(ou("radix.decode",t),Uint8Array.from(au(t,e,256)))}}(58),uu(yu),cu("")));var yu;const vu=e=>{return su((n=t=>e(e(t)),nu(t=4),eu(n),{encode(e){if(!Js(e))throw new Error("checksum.encode: input should be Uint8Array");const r=n(e).slice(0,t),i=new Uint8Array(e.length+t);return i.set(e),i.set(r,e.length),i},decode(e){if(!Js(e))throw new Error("checksum.decode: input should be Uint8Array");const r=e.slice(0,-t),i=e.slice(-t),o=n(r).slice(0,t);for(let e=0;e<t;e++)if(o[e]!==i[e])throw new Error("Invalid checksum");return r}}),wu);var t,n},bu=su(uu("qpzry9x8gf2tvdw0s3jn54khce6mua7l"),cu("")),Eu=[996825010,642813549,513874426,1027748829,705979059];function xu(e){const t=e>>25;let n=(33554431&e)<<5;for(let e=0;e<Eu.length;e++)1==(t>>e&1)&&(n^=Eu[e]);return n}function zu(e,t,n=1){const r=e.length;let i=1;for(let t=0;t<r;t++){const n=e.charCodeAt(t);if(n<33||n>126)throw new Error(`Invalid prefix (${e})`);i=xu(i)^n>>5}i=xu(i);for(let t=0;t<r;t++)i=xu(i)^31&e.charCodeAt(t);for(let e of t)i=xu(i)^e;for(let e=0;e<6;e++)i=xu(i);return i^=n,bu.encode(hu([i%lu[30]],30,5,!1))}function ku(e){const t="bech32"===e?1:734539939,n=pu(5),r=n.decode,i=n.encode,o=mu(r);function s(e,n,r=90){tu("bech32.encode prefix",e),Js(n)&&(n=Array.from(n)),ou("bech32.encode",n);const i=e.length;if(0===i)throw new TypeError(`Invalid prefix length ${i}`);const o=i+7+n.length;if(!1!==r&&o>r)throw new TypeError(`Length ${o} exceeds limit ${r}`);const s=e.toLowerCase(),u=zu(s,n,t);return`${s}1${bu.encode(n)}${u}`}function u(e,n=90){tu("bech32.decode input",e);const r=e.length;if(r<8||!1!==n&&r>n)throw new TypeError(`invalid string length: ${r} (${e}). Expected (8..${n})`);const i=e.toLowerCase();if(e!==i&&e!==e.toUpperCase())throw new Error("String must be lowercase or uppercase");const o=i.lastIndexOf("1");if(0===o||-1===o)throw new Error('Letter "1" must be present between prefix and data only');const s=i.slice(0,o),u=i.slice(o+1);if(u.length<6)throw new Error("Data must be at least 6 characters long");const c=bu.decode(u).slice(0,-6),a=zu(s,c,t);if(!u.endsWith(a))throw new Error(`Invalid checksum in ${e}: expected "${a}"`);return{prefix:s,words:c}}return{encode:s,decode:u,encodeFromBytes:function(e,t){return s(e,i(t))},decodeToBytes:function(e){const{prefix:t,words:n}=u(e,!1);return{prefix:t,words:n,bytes:r(n)}},decodeUnsafe:mu(u),fromWords:r,fromWordsUnsafe:o,toWords:i}}const Ou=ku("bech32"),Pu=ku("bech32m");var Su,Au,Iu,$u,Tu;function Nu(e){if("string"!=typeof e||0===e.length)throw new Error(`invalid prefix: ${String(e)}`)}function Bu(e){if(!Array.isArray(e)||!e.every(e=>"number"==typeof e))throw new Error(`invalid words: ${String(e)}`)}!function(e){e.encode=e=>(b.is_u8a(e),vu(te).encode(e)),e.decode=e=>(b.is_base58(e),vu(te).decode(e))}(Su||(Su={})),function(e){e.encode=e=>(b.is_u8a(e),gu.encode(e)),e.decode=e=>(b.is_base64(e),gu.decode(e))}(Au||(Au={})),function(e){e.encode=e=>(b.is_u8a(e),_u.encode(e)),e.decode=e=>(b.is_b64url(e),_u.decode(e))}(Iu||(Iu={})),function(e){e.to_words=Ou.toWords,e.to_bytes=Ou.fromWords,e.encode=(e,t,n=!1)=>(Nu(e),Bu(t),Ou.encode(e,t,n)),e.decode=(e,t=!1)=>(b.is_bech32(e),Ou.decode(e,t))}($u||($u={})),function(e){e.to_words=Pu.toWords,e.to_bytes=Pu.fromWords,e.encode=(e,t,n=!1)=>(Nu(e),Bu(t),Pu.encode(e,t,n)),e.decode=(e,t=!1)=>(b.is_bech32(e),Pu.decode(e,t))}(Tu||(Tu={}));const Uu={base58:/^[13mn2][a-km-zA-HJ-NP-Z1-9]{25,34}$/,bech32:/^(bc|tb|bcrt)1q[ac-hj-np-z02-9]{6,87}$/,bech32m:/^(bc|tb|bcrt)1p[ac-hj-np-z02-9]{6,87}$/},Zu=0,Ru=1;function Cu(e){const t=function(e){for(const[t,n]of Object.entries(Uu))if(n.test(e))return t;return null}(e);if(null===t)throw new Error("unrecognized address format: "+t);if("base58"===t)return function(e){const t=Su.decode(e),n=t.slice(1),r=t[0];return{data:n,format:"base58",version:r}}(e);if("bech32"===t)return function(e){const{prefix:t,words:n}=$u.decode(e),[r,...i]=n;b.ok(r===Zu,"bech32 version mismatch");return{data:$u.to_bytes(i),format:"bech32",prefix:t,version:r}}(e);if("bech32m"===t)return function(e){const{prefix:t,words:n}=Tu.decode(e),[r,...i]=n;b.ok(r===Ru,"bech32m version mismatch");return{data:Tu.to_bytes(i),format:"bech32m",prefix:t,version:r}}(e);throw new Error("unable to find a matching address configuration")}function ju(e){if("base58"===e.format)return function(e){b.ok("base58"===e.format,"encoding mismatch"),b.exists(e.version,"must specify a version");const t=g.join([e.version,e.data]);return Su.encode(t)}(e);if("bech32"===e.format)return function(e){b.ok("bech32"===e.format,"encoding mismatch"),b.exists(e.prefix,"prefix is required");const t=g.bytes(e.data),n=$u.to_words(t);return $u.encode(e.prefix,[Zu,...n])}(e);if("bech32m"===e.format)return function(e){b.ok("bech32m"===e.format,"encoding mismatch"),b.exists(e.prefix,"prefix is required");const t=g.bytes(e.data),n=Tu.to_words(t);return Tu.encode(e.prefix,[Ru,...n])}(e);throw new Error("unrecognized encoding format: "+e.format)}const Fu={TXID:"00".repeat(32),VOUT:4294967295},Hu={LOCKTIME:0,SEQUENCE:4294967295,VERSION:2},Du=[192,194,196,198,200,202,204,206,208,210,212,214,216,218,220,222,224,226,228,230,232,234,236,238,240,242,244,246,248,250,252,254,102,126,128,132,150,152,186,188,190],Lu={P2PKH:"p2pkh",P2SH:"p2sh",P2WPKH:"p2wpkh",P2WSH:"p2wsh",P2TR:"p2tr",OPRETURN:"opreturn"},Vu={[Lu.P2PKH]:/^76a914[0-9a-f]{40}88ac$/i,[Lu.P2SH]:/^a914[0-9a-f]{40}87$/i,[Lu.P2WPKH]:/^0014[0-9a-f]{40}$/i,[Lu.P2WSH]:/^0020[0-9a-f]{64}$/i,[Lu.P2TR]:/^5120[0-9a-f]{64}$/i,[Lu.OPRETURN]:/^6a[0-9a-f]{2,}$/i},qu=[1,2,3,129,130,131],Mu=[0,...qu];var Ku=Object.freeze({__proto__:null,COINBASE:Fu,DEFAULT:Hu,LOCK_SCRIPT_REGEX:Vu,LOCK_SCRIPT_TYPE:Lu,SCRIPT_INT_KEY:"",SIGHASH_DEFAULT:1,SIGHASH_SEGWIT:qu,SIGHASH_TAPROOT:Mu,SPEND_SCRIPT_TYPE:{P2PKH:"p2pkh",P2SH:"p2sh",P2WPKH:"p2wpkh",P2WSH:"p2wsh",P2TR:"p2tr",P2TS:"p2ts"},TAPLEAF_DEFAULT_VERSION:192,TAPLEAF_VERSIONS:Du,TX_SIZE:{GLOBAL_BASE:8,GLOBAL_WIT:10,TXIN_BASE:40,TXOUT_BASE:8}});function Wu(e){const t=g.bytes(e).hex;for(const[e,n]of Object.entries(Vu))if(n.test(t))return e;return null}function Gu(e){switch(g.bytes(e).at(0)){case 0:return 0;case 81:return 1;default:return null}}function Yu(e){const t=g.bytes(e).hex;return Vu.p2pkh.test(t)}function Xu(e){const t=g.bytes(e).hex;return Vu.p2sh.test(t)}function Ju(e){const t=g.bytes(e).hex;return Vu.p2wpkh.test(t)}function Qu(e){const t=g.bytes(e).hex;return Vu.p2wsh.test(t)}function ec(e){const t=g.bytes(e).hex;return Vu.p2tr.test(t)}function tc(e,t){switch(t){case"p2pkh":return function(e){return{hex:"76a914"+e+"88ac",asm:["OP_DUP","OP_HASH160",e,"OP_EQUALVERIFY","OP_CHECKSIG"]}}(e);case"p2sh":return function(e){return{hex:"a914"+e+"87",asm:["OP_HASH160",e,"OP_EQUAL"]}}(e);case"p2wpkh":return function(e){return{hex:"0014"+e,asm:["OP_0",e]}}(e);case"p2wsh":return function(e){return{hex:"0020"+e,asm:["OP_0",e]}}(e);case"p2tr":return function(e){return{hex:"5120"+e,asm:["OP_1",e]}}(e);default:throw new Error("unrecognized script type: "+t)}}const nc=[["1","p2pkh","main",20,"base58",0],["3","p2sh","main",20,"base58",5],["m","p2pkh","testnet",20,"base58",111],["n","p2pkh","testnet",20,"base58",111],["2","p2sh","testnet",20,"base58",196],["m","p2pkh","regtest",20,"base58",111],["n","p2pkh","regtest",20,"base58",111],["2","p2sh","regtest",20,"base58",196],["bc","p2wpkh","main",20,"bech32",0],["tb","p2wpkh","testnet",20,"bech32",0],["bcrt","p2wpkh","regtest",20,"bech32",0],["bc","p2wsh","main",32,"bech32",0],["tb","p2wsh","testnet",32,"bech32",0],["bcrt","p2wsh","regtest",32,"bech32",0],["bc","p2tr","main",32,"bech32m",1],["tb","p2tr","testnet",32,"bech32m",1],["bcrt","p2tr","regtest",32,"bech32m",1]];function rc(e,t){for(const[n,r,i,o,s,u]of nc)if(r===t&&i===e)return{type:r,prefix:n,network:i,size:o,format:s,version:u};return null}function ic(e){const t=Cu(e);for(const[n,r,i,o,s,u]of nc){if(s!==t.format)continue;if(o!==t.data.length)continue;if(u!==t.version)continue;if(t.prefix){if(n!==t.prefix)continue}else if(!e.startsWith(n))continue;const c=g.uint(t.data).hex;return{data:c,script:tc(c,r),type:r,prefix:n,network:i,size:o,format:s,version:u}}throw new Error("address configuration is invalid")}const oc=Lu.P2PKH;var sc;function uc(e,t="main"){return fc(cc(e),t)}function cc(e){const t=g.bytes(e);b.size(t,33,"invalid pubkey size");return ac(hn(t))}function ac(e){return g.join(["76a914",e,"88ac"])}function fc(e,t="main"){const n=lc(e),r=rc(t,oc);return b.exists(r,`unrecognized address config: ${oc} on ${t}`),b.size(n,r.size,`invalid payload size: ${n.length} !== ${r.size}`),ju({data:n,format:"base58",version:r.version})}function dc(e){const t=ic(e);return b.ok("p2pkh"===t.type,`address type mismatch: ${t.type} !== ${oc}`),t}function lc(e){const t=g.bytes(e);return b.ok(Yu(e),"invalid p2pkh script"),t.slice(3,23)}!function(e){e.create_address=uc,e.create_script=cc,e.encode_address=fc,e.encode_script=ac,e.decode_address=dc,e.decode_script=lc}(sc||(sc={}));const hc=Lu.P2SH;var pc;function mc(e,t="main"){return wc(_c(hn(g.bytes(e))),t)}function gc(e){return _c(hn(g.bytes(e)))}function _c(e){return g.join(["a914",e,"87"])}function wc(e,t="main"){const n=vc(e),r=rc(t,hc);return b.exists(r,`unrecognized address config: ${hc} on ${t}`),b.size(n,r.size,`invalid payload size: ${n.length} !== ${r.size}`),ju({data:n,format:"base58",version:r.version})}function yc(e){const t=ic(e);return b.ok("p2sh"===t.type,`address type mismatch: ${t.type} !== ${hc}`),t}function vc(e){b.ok(Xu(e),"invalid p2sh script");return g.bytes(e).slice(2,22)}!function(e){e.create_address=mc,e.create_script=gc,e.encode_address=wc,e.encode_script=_c,e.decode_address=yc,e.decode_script=vc}(pc||(pc={}));const bc=Lu.P2WPKH;var Ec;function xc(e,t="main"){return Oc(zc(e),t)}function zc(e){const t=g.bytes(e);b.size(t,33,"invalid pubkey size");return kc(hn(t))}function kc(e){return g.join(["0014",e])}function Oc(e,t="main"){const n=Sc(e),r=rc(t,bc);return b.exists(r,`unrecognized address config: ${bc} on ${t}`),b.size(n,r.size,`invalid payload size: ${n.length} !== ${r.size}`),ju({data:n,format:"bech32",prefix:r.prefix})}function Pc(e){const t=ic(e);return b.ok("p2wpkh"===t.type,`address type mismatch: ${t.type} !== ${bc}`),t}function Sc(e){b.ok(Ju(e),"invalid p2wpkh script");return g.bytes(e).slice(2,22)}!function(e){e.create_address=xc,e.create_script=zc,e.encode_address=Oc,e.encode_script=kc,e.decode_address=Pc,e.decode_script=Sc}(Ec||(Ec={}));const Ac=Lu.P2WSH;var Ic;function $c(e,t="main"){return Bc(Tc(e),t)}function Tc(e){return Nc(pn(g.bytes(e)))}function Nc(e){return g.join(["0020",e])}function Bc(e,t="main"){const n=Zc(e),r=rc(t,Ac);return b.exists(r,`unrecognized address config: ${Ac} on ${t}`),b.size(n,r.size,`invalid payload size: ${n.length} !== ${r.size}`),ju({data:n,format:"bech32",prefix:r.prefix})}function Uc(e){const t=ic(e);return b.ok("p2wsh"===t.type,`address type mismatch: ${t.type} !== ${Ac}`),t}function Zc(e){b.ok(Qu(e),"invalid p2wsh script");return g.bytes(e).slice(2,34)}!function(e){e.create_address=$c,e.create_script=Tc,e.encode_address=Bc,e.encode_script=Nc,e.decode_address=Uc,e.decode_script=Zc}(Ic||(Ic={}));const Rc=Lu.P2TR;var Cc;function jc(e,t="main"){return Dc(Fc(e),t)}function Fc(e){const t=g.bytes(e);return b.size(t,32,"invalid pubkey size"),Hc(t)}function Hc(e){return g.join(["5120",e])}function Dc(e,t="main"){const n=Vc(e),r=rc(t,Rc);return b.exists(r,`unrecognized address config: ${Rc} on ${t}`),b.size(n,r.size,`invalid payload size: ${n.length} !== ${r.size}`),ju({data:n,format:"bech32m",prefix:r.prefix})}function Lc(e){const t=ic(e);return b.ok("p2tr"===t.type,`address type mismatch: ${t.type} !== ${Rc}`),t}function Vc(e){b.ok(ec(e),"invalid p2tr script");return g.bytes(e).slice(2,34)}!function(e){e.create_address=jc,e.create_script=Fc,e.encode_address=Dc,e.encode_script=Hc,e.decode_address=Lc,e.decode_script=Vc}(Cc||(Cc={}));var qc=Object.freeze({__proto__:null,get P2PKH(){return sc},get P2SH(){return pc},get P2TR(){return Cc},get P2WPKH(){return Ec},get P2WSH(){return Ic},create_address:function(e,t="main"){const n=g.bytes(e),r=Wu(n);if(null===r)throw new Error("unrecognized script type: "+n.hex);switch(r){case Lu.P2PKH:return sc.create_address(e,t);case Lu.P2SH:return pc.create_address(e,t);case Lu.P2WPKH:return Ec.create_address(e,t);case Lu.P2WSH:return Ic.create_address(e,t);case Lu.P2TR:return Cc.create_address(e,t);default:throw new Error("unrecognized script type: "+r)}},parse_address:function(e){return ic(e)}});const Mc=5e8;var Kc,Wc;function Gc(e){switch(e.type){case"timelock":return b.ok(e.stamp>=Mc,"Invalid timestamp"),e.stamp;case"heightlock":return b.ok(e.height>0,"height must be greater than 0"),b.ok(e.height<Mc,"invalid block height"),e.height;default:throw new Error("Invalid locktime type")}}function Yc(e){return isNaN(e)||e<=0?null:e<Mc?{type:"heightlock",height:e}:{type:"timelock",stamp:e}}function Xc(e,t=0){return`${e}i${t}`}function Jc(e){ea(e);const[t,n]=e.split("i");return{txid:t,order:parseInt(n)}}function Qc(e){return null!==e.match(/^[a-f0-9]{64}i\d+$/)}function ea(e){if(!Qc(e))throw new Error(`invalid inscription id: ${e}`)}function ta(e,t){return`${e}:${t}`}function na(e){ia(e);const[t,n]=e.split(":");return{block_height:parseInt(t),block_index:parseInt(n)}}function ra(e){return null!==e.match(/^\d+:\d+$/)}function ia(e){if(!ra(e))throw new Error(`invalid rune id: ${e}`)}function oa(e,t){return`${e}:${t}`}function sa(e){ca(e);const[t,n]=e.split(":");return{txid:t,vout:parseInt(n)}}function ua(e){return null!==e.match(/^[a-f0-9]{64}:[0-9]+$/)}function ca(e){if(!ua(e))throw new Error(`invalid outpoint: ${e}`)}!function(e){e.encode=Gc,e.decode=Yc}(Kc||(Kc={})),function(e){e.outpoint={encode:oa,decode:sa,verify:ua,assert:ca},e.record_id={encode:Xc,decode:Jc,verify:Qc,assert:ea},e.rune_id={encode:ta,decode:na,verify:ra,assert:ia}}(Wc||(Wc={}));const aa={OP_0:0,OP_PUSHDATA1:76,OP_PUSHDATA2:77,OP_PUSHDATA4:78,OP_1NEGATE:79,OP_SUCCESS80:80,OP_1:81,OP_2:82,OP_3:83,OP_4:84,OP_5:85,OP_6:86,OP_7:87,OP_8:88,OP_9:89,OP_10:90,OP_11:91,OP_12:92,OP_13:93,OP_14:94,OP_15:95,OP_16:96,OP_NOP:97,OP_SUCCESS98:98,OP_IF:99,OP_NOTIF:100,OP_ELSE:103,OP_ENDIF:104,OP_VERIFY:105,OP_RETURN:106,OP_TOALTSTACK:107,OP_FROMALTSTACK:108,OP_2DROP:109,OP_2DUP:110,OP_3DUP:111,OP_2OVER:112,OP_2ROT:113,OP_2SWAP:114,OP_IFDUP:115,OP_DEPTH:116,OP_DROP:117,OP_DUP:118,OP_NIP:119,OP_OVER:120,OP_PICK:121,OP_ROLL:122,OP_ROT:123,OP_SWAP:124,OP_TUCK:125,OP_SUCCESS126:126,OP_SUCCESS127:127,OP_SUCCESS128:128,OP_SUCCESS129:129,OP_SIZE:130,OP_SUCCESS131:131,OP_SUCCESS132:132,OP_SUCCESS133:133,OP_SUCCESS134:134,OP_EQUAL:135,OP_EQUALVERIFY:136,OP_SUCCESS137:137,OP_SUCCESS138:138,OP_1ADD:139,OP_1SUB:140,OP_SUCCESS141:141,OP_SUCCESS142:142,OP_NEGATE:143,OP_ABS:144,OP_NOT:145,OP_0NOTEQUAL:146,OP_ADD:147,OP_SUB:148,OP_SUCCESS149:149,OP_SUCCESS150:150,OP_SUCCESS151:151,OP_SUCCESS152:152,OP_SUCCESS153:153,OP_BOOLAND:154,OP_BOOLOR:155,OP_NUMEQUAL:156,OP_NUMEQUALVERIFY:157,OP_NUMNOTEQUAL:158,OP_LESSTHAN:159,OP_GREATERTHAN:160,OP_LESSTHANOREQUAL:161,OP_GREATERTHANOREQUAL:162,OP_MIN:163,OP_MAX:164,OP_WITHIN:165,OP_RIPEMD160:166,OP_SHA1:167,OP_SHA256:168,OP_HASH160:169,OP_HASH256:170,OP_CODESEPARATOR:171,OP_CHECKSIG:172,OP_CHECKSIGVERIFY:173,OP_CHECKMULTISIG:174,OP_CHECKMULTISIGVERIFY:175,OP_NOP1:176,OP_CHECKLOCKTIMEVERIFY:177,OP_CHECKSEQUENCEVERIFY:178,OP_NOP4:179,OP_NOP5:180,OP_NOP6:181,OP_NOP7:182,OP_NOP8:183,OP_NOP9:184,OP_NOP10:185,OP_CHECKSIGADD:186};function fa(e){if(e>186&&e<255)return"OP_SUCCESS"+String(e);for(const[t,n]of Object.entries(aa))if(n===e)return t;throw new Error("OPCODE not found:"+String(e))}function da(e){for(const[t,n]of Object.entries(aa))if(t===e)return Number(n);throw new Error("OPCODE not found:"+e)}function la(e){switch(!0){case 0===e:return"opcode";case e>=1&&e<=75:return"varint";case 76===e:return"pushdata1";case 77===e:return"pushdata2";case 78===e:return"pushdata4";case e<=254:return"opcode";default:throw new Error(`Invalid word range: ${e}`)}}function ha(e){switch(!0){case"number"!=typeof e:return!1;case 0===e:return!0;case[].includes(e):return!1;case 75<e&&e<254:return!0;default:return!1}}const pa=520;function ma(e,t=!1){if(0===e.length)return g.num(0,1);const n=[];for(const t of e)n.push(ga(t));const r=g.join(n);return t?r.prepend(g.varint(r.length,"le")):r}function ga(e){let t;if("string"==typeof e){if(e.startsWith("OP_")){const t=da(e);return g.num(t,1)}t=g.is_hex(e)?g.hex(e):g.str(e)}else if("number"==typeof e)t=g.num(e);else{if(!(e instanceof Uint8Array))throw new Error("invalid word type:"+typeof e);t=new g(e)}if(1===t.length&&t[0]<=16)0!==t[0]&&(t[0]+=80);else if(t.length>pa){let e;e=_a(t),e=e.map(e=>wa(e)),t=g.join(e)}else t=wa(t);return t}function _a(e){const t=[],n=new _(e);for(;n.size>pa;)t.push(n.read(pa));return t.push(n.read(n.size)),t}function wa(e){const t=ya(e.length);return g.join([t,e])}function ya(e){const t=g.num(76,1),n=g.num(77,1);switch(!0){case e<=75:return g.num(e);case e>75&&e<256:return g.join([t,g.num(e,1,"le")]);case e>=256&&e<=pa:return g.join([n,g.num(e,2,"le")]);default:throw new Error("Invalid word size:"+e.toString())}}function va(e){const t=g.bytes(e);return{asm:ba(t),hex:t.hex}}function ba(e){const t=new _(e),n=[],r=t.size;let i,o,s,u=0;for(;u<r;)switch(i=t.read(1).num,o=la(i),u++,o){case"varint":n.push(t.read(i).hex),u+=i;break;case"pushdata1":s=t.read(1).reverse().num,n.push(t.read(s).hex),u+=s+1;break;case"pushdata2":s=t.read(2).reverse().num,n.push(t.read(s).hex),u+=s+2;break;case"pushdata4":s=t.read(4).reverse().num,n.push(t.read(s).hex),u+=s+4;break;case"opcode":if(!ha(i))throw new Error(`Invalid OPCODE: ${i}`);n.push(fa(i));break;default:throw new Error(`Word type undefined: ${i}`)}return n}function Ea(e){try{return ba(e).length>0}catch{return!1}}const xa=BigInt(0),za=BigInt(1),ka=BigInt(26);var Oa;function Pa(e){const t=function(e){const t=ba(e),n=t.findIndex(e=>"OP_0"===e);b.ok(-1!==n,"inscription envelope not found");const r=[];for(let e=n;e<t.length;e++){b.ok("OP_IF"===t[e+1],"OP_IF missing from envelope"),b.ok("6f7264"===t[e+2],"magic bytes missing from envelope");const n=t.findIndex(e=>"OP_ENDIF"===e);b.ok(-1!==n,"inscription envelope missing END_IF statement");const i=t.slice(e+3,n);r.push(i),e+=n}return r}(e);return t.map(Ia)}function Sa(e){return g.join(e.map(Aa))}function Aa(e){let t=["OP_0","OP_IF","6f7264"];if("string"==typeof e.delegate){const n=Ta(e.delegate);t.push("OP_11",n)}if("string"==typeof e.ref&&t.push("OP_WITHIN",e.ref),"string"==typeof e.parent){const n=Ta(e.parent);t.push("OP_3",n)}if("number"==typeof e.opcode){const n=Ba(e.opcode);t.push("OP_NOP",n)}if("number"==typeof e.pointer){const n=Ba(e.pointer);t.push("OP_2",n)}if("string"==typeof e.rune){const n=function(e){const t=e.toUpperCase();let n=xa;for(const e of t)e>="A"&&e<="Z"&&(n=n*ka+BigInt(e.charCodeAt(0)-("A".charCodeAt(0)-1)));return n-=za,g.big(n).reverse().hex}(e.rune);t.push("OP_13",n)}if("string"==typeof e.mimetype){const n=function(e){return g.str(e).hex}(e.mimetype);t.push("OP_1",n)}if("string"==typeof e.content){const n=function(e){const t=g.is_hex(e)?g.hex(e):g.str(e),n=new _(t),r=[];for(;n.size>0;)if(n.size>520){const e=n.read(520);r.push(e.hex)}else{const e=n.read(n.size);r.push(e.hex)}return r}(e.content);t.push("OP_0",...n)}return t.push("OP_ENDIF"),ma(t)}function Ia(e){const t={};for(let n=0;n<e.length;n++)switch(e[n]){case"OP_1":t.mimetype=Za(e[n+1]),n+=1;break;case"OP_2":t.pointer=Ua(e[n+1]),n+=1;break;case"OP_3":t.parent=Na(e[n+1]),n+=1;break;case"OP_11":t.delegate=Na(e[n+1]),n+=1;break;case"OP_13":t.rune=Ca(e[n+1]),n+=1;break;case"OP_WITHIN":t.ref=$a(e[n+1]),n+=1;break;case"OP_NOP":t.opcode=Ua(e[n+1]),n+=1;break;case"OP_0":return t.content=Ra(e.slice(n+1)),t}return t}function $a(e){return g.bytes(e).hex}function Ta(e){b.ok(e.includes("i"),"identifier must include an index");const t=e.split("i"),n=g.hex(t[0]),r=Number(t[1]),i=n.reverse().hex;return 0!==r?i+g.num(r).hex:i}function Na(e){const t=g.bytes(e),n=t.at(-1)??0;return t.slice(0,-1).reverse().hex+"i"+String(n)}function Ba(e){return g.num(e).reverse().hex}function Ua(e){return g.bytes(e).reverse().num}function Za(e){return g.bytes(e).str}function Ra(e,t="hex"){const n=g.join(e);return"hex"===t?n.hex:n.str}function Ca(e){let t=g.bytes(e).reverse().big;t+=za;let n="";for(;t>xa;){const e=t%ka;if(e===xa)n="Z"+n,t=t/ka-za;else{const r=Number(e)+"A".charCodeAt(0)-1;n=String.fromCharCode(r)+n,t/=ka}}return n}!function(e){e.encode=Sa,e.decode=Pa}(Oa||(Oa={}));const ja=4194304,Fa=65535,Ha=65535;var Da;function La(e){if("height"===e.mode){return(function(e){if(void 0===e||!Number.isInteger(e)||e<0||e>Ha)throw new Error("Heightlock value must be an integer between 0 and 65535");return e}(e.height)&Fa)>>>0}if("stamp"===e.mode){const t=function(e){if(void 0===e||!Number.isInteger(e))throw new Error("timestamp must be a number");const t=Math.floor(e/512);if(!Number.isInteger(t)||t<0||t>Ha)throw new Error("timelock value must be an integer between 0 and 65535 (in 512-second increments)");return t}(e.stamp);return(ja|t&Fa)>>>0}throw new Error("invalid timelock mode: "+e.mode)}function Va(e){const t=function(e){const t="string"==typeof e?parseInt(e,16):e;if(!Number.isInteger(t)||t<0||t>4294967295)throw new Error(`invalid sequence value: ${t}`);return t}(e);if(2147483648&t)return null;const n=t&Fa;if(t&ja){const e=512*n;if(e>4294967295)throw new Error("Decoded timestamp exceeds 32-bit limit");return{mode:"stamp",stamp:e}}if(n>Ha)throw new Error("Decoded height exceeds maximum");return{mode:"height",height:n}}!function(e){e.encode=La,e.decode=Va}(Da||(Da={}));var qa,Ma=Object.freeze({__proto__:null,get InscriptionUtil(){return Oa},get LocktimeField(){return Kc},get RefPointer(){return Wc},get SequenceField(){return Da},decode_inscription:Pa,decode_locktime:Yc,decode_sequence:Va,encode_inscription:Sa,encode_locktime:Gc,encode_sequence:La});function Ka(e){return g.bytes(e).prefix_varint("le").hex}!function(e){e.parse=va,e.decode=ba,e.encode=ma,e.is_valid=Ea}(qa||(qa={}));var Wa=Object.freeze({__proto__:null,OPCODE_MAP:aa,get ScriptUtil(){return qa},decode_script:ba,encode_script:ma,encode_script_word:ga,get_asm_code:da,get_lock_script_info:function(e){return{type:Wu(e),version:Gu(e)}},get_lock_script_type:Wu,get_lock_script_version:Gu,get_op_code:fa,get_op_type:la,get_size_varint:ya,is_opreturn_script:function(e){const t=g.bytes(e).hex;return Vu.opreturn.test(t)},is_p2pkh_script:Yu,is_p2sh_script:Xu,is_p2tr_script:ec,is_p2wpkh_script:Ju,is_p2wsh_script:Qu,is_return_script:function(e){return 106===g.bytes(e).at(0)},is_valid_op:ha,is_valid_script:Ea,parse_script:va,parse_script_pubkeys:function(e){return[...("string"==typeof e?e:g.bytes(e).hex).matchAll(/20([0-9a-f]{64})(ac|ad|ba)/gi)].map(e=>e[1])},prefix_script_size:Ka,prefix_word_size:wa,split_script_word:_a});function Ga(e){return b.exists(e.prevout,"Prevout data missing for input: "+String(e.txid)),e.prevout}function Ya(e,t){let{txindex:n,txinput:r}=t??{};if(void 0!==n){if(n>=e.vin.length)throw new Error("Input index out of bounds: "+String(n));r=e.vin.at(n)}return b.ok(void 0!==r),r}function Xa(e){if(void 0===e)return;if(e.length<2)return;const t=e.at(-1);if("string"==typeof t&&t.startsWith("50")){return pn(g.hex(t).prefix_varint("be"))}}const Ja=ws([ps(Xs),Xs]),Qa=gs({pubkey:Xs,leaves:Ja.array().optional(),target:Xs.optional(),version:Hs.optional()});var ef=Object.freeze({__proto__:null,config:Qa,taptree:Ja});const tf=os().min(0n).max(2100000000000000n),nf=gs({value:tf,script_pk:Ds}),rf=gs({coinbase:Ds.nullable(),txid:Ws,vout:Hs,prevout:nf.nullable(),script_sig:Ds.nullable(),sequence:Hs,witness:ps(Ds)}),of=gs({version:Hs,vin:ps(rf),vout:ps(nf),locktime:Hs}),sf=nf.extend({value:ws([Hs,tf])}),uf=rf.extend({coinbase:Ds.nullable().optional(),prevout:sf.nullable().optional(),script_sig:Ds.nullable().optional(),sequence:ws([Ds,Hs]).optional(),witness:ps(Ds).optional()}),cf=gs({version:Hs.optional(),vin:ps(uf),vout:ps(sf),locktime:Hs.optional()});var af=Object.freeze({__proto__:null,tx_data:of,tx_input:rf,tx_output:nf,tx_template:cf,vin_template:uf,vout_template:sf}),ff=Object.freeze({__proto__:null,taproot:ef,tx:af});function df(e){cf.parse(e)}function lf(e){if(e.some(e=>null===e.prevout))throw new Error("transaction missing prevouts")}function hf(e){of.parse(e)}function pf(e){uf.parse(e)}function mf(e){sf.parse(e)}function gf(e,t=!0){hf(e);const{version:n,vin:r,vout:i,locktime:o}=e,s=[_f(n)];if(t&&s.push(g.hex("0001")),s.push(bf(r)),s.push(zf(i)),t)for(const e of r)s.push(Of(e.witness));return s.push(Pf(o)),g.join(s)}function _f(e){return g.num(e,4).reverse()}function wf(e){return g.hex(e,32).reverse()}function yf(e){return g.num(e,4).reverse()}function vf(e){return g.num(e,4).reverse()}function bf(e){const t=[g.varint(e.length,"le")];for(const n of e)t.push(Ef(n));return g.join(t)}function Ef(e){return null!==e.coinbase?g.join([wf(Fu.TXID),yf(Fu.VOUT),Sf(e.coinbase),vf(e.sequence)]):g.join([wf(e.txid),yf(e.vout),Sf(e.script_sig),vf(e.sequence)])}function xf(e){return g.big(e,8).reverse()}function zf(e){const t=[g.varint(e.length,"le")];for(const n of e)t.push(kf(n));return g.join(t)}function kf(e){const{value:t,script_pk:n}=e;return g.join([xf(t),Sf(n)])}function Of(e){const t=[g.varint(e.length)];for(const n of e)t.push(Sf(n));return g.join(t)}function Pf(e){return g.num(e,4).reverse()}function Sf(e){return null!==e?(b.is_hex(e),g.hex(e).prefix_varint("le")):g.hex("00")}function Af(e,t=!0){b.is_bytes(e,"txdata must be hex or bytes");const n=new _(e),r=function(e){return e.read(4).reverse().to_num()}(n),i=!!t&&function(e){const[t,n]=[...e.peek(2)];if(0===t){if(e.read(2),1===n)return!0;throw new Error(`Invalid witness flag: ${n}`)}return!1}(n),o=function(e){const t=[],n=e.varint();for(let r=0;r<n;r++){const n=If(e);t.push(n)}return t}(n),s=function(e){const t=[],n=e.varint();for(let r=0;r<n;r++)try{t.push($f(e))}catch(e){throw new Error(`failed to decode output: ${r}: ${y(e)}`)}return t}(n);if(i)for(const e of o)e.witness=Tf(n);const u=function(e){return e.read(4).reverse().to_num()}(n);return{version:r,vin:o,vout:s,locktime:u}}function If(e){const t=e.read(32).reverse().hex,n=e.read(4).reverse().num,r=Nf(e),i=e.read(4).reverse().num,o=[];return t===Fu.TXID&&n===Fu.VOUT?{coinbase:r,prevout:null,script_sig:null,sequence:i,txid:t,vout:n,witness:o}:{coinbase:null,prevout:null,script_sig:r,sequence:i,txid:t,vout:n,witness:o}}function $f(e){const t=e.read(8).reverse().big,n=Nf(e);return b.exists(n,"failed to decode script_pk"),{value:t,script_pk:n}}function Tf(e){const t=[],n=e.varint();for(let r=0;r<n;r++){const n=Nf(e);if(null===n)throw new Error("failed to decode witness element: "+r);t.push(n)}return t}function Nf(e){const t=e.varint("le");return t>0?e.read(t).hex:null}function Bf(e,t){let n;if("string"==typeof e||e instanceof Uint8Array?n=Af(e):(df(e),n=Lf(e)),t){b.has_items(t,"prevouts must be a non-empty array");for(const[e,r]of n.vin.entries()){const n=t.at(e);b.exists(n,"prevout not found for input index: "+e),r.prevout=Df(n)}}return n}function Uf(e){if(!v.exists(e))return Hu.SEQUENCE;if(v.is_hex(e))return g.hex(e,4).reverse().num;if(v.is_uint(e))return e;throw new Error("invalid sequence value: "+String(e))}function Zf(e){if(v.is_uint(e))return BigInt(e);if("bigint"==typeof e)return e;throw new TypeError("invalid output value: "+String(e))}function Rf(e){return{script_pk:e.script_pk,value:Zf(e.value)}}function Cf(e){pf(e),b.exists(e.coinbase,"coinbase is required");const t=Fu.TXID,n=Fu.VOUT,r=e.coinbase,i=e.witness??[];return{coinbase:r,prevout:null,script_sig:null,sequence:Uf(e.sequence),witness:i,txid:t,vout:n}}function jf(e){pf(e),b.is_empty(e.coinbase,"coinbase is not allowed"),b.is_empty(e.prevout,"prevout is not allowed");const{txid:t,vout:n,script_sig:r=null,witness:i=[]}=e;return{txid:t,vout:n,coinbase:null,prevout:null,script_sig:r,sequence:Uf(e.sequence),witness:i}}function Ff(e){pf(e),b.exists(e.prevout,"prevout is required");const{txid:t,vout:n,script_sig:r=null,witness:i=[]}=e;return{txid:t,vout:n,coinbase:null,prevout:Rf(e.prevout),script_sig:r,sequence:Uf(e.sequence),witness:i}}function Hf(e){return e.coinbase?Cf(e):e.prevout?Ff(e):jf(e)}function Df(e){mf(e);return{script_pk:e.script_pk,value:Zf(e.value)}}function Lf(e){df(e);const{vin:t=[],vout:n=[]}=e??{vin:[],vout:[]},r=e.locktime??Hu.LOCKTIME,i=e.version??Hu.VERSION;return{locktime:r,vin:t.map(e=>Hf(e)),vout:n.map(e=>Df(e)),version:i}}var Vf=Object.freeze({__proto__:null,assert_has_prevouts:lf,assert_tx_data:hf,assert_tx_input:function(e){rf.parse(e)},assert_tx_output:function(e){nf.parse(e)},assert_tx_spend_data:function(e){hf(e),lf(e.vin)},assert_tx_template:df,assert_vin_template:pf,assert_vout_template:mf,create_coinbase_input:Cf,create_spend_input:Ff,create_tx:Lf,create_tx_input:Hf,create_tx_output:Df,create_virtual_input:jf,decode_tx:Af,encode_script_data:Sf,encode_tx:gf,encode_tx_inputs:bf,encode_tx_locktime:Pf,encode_tx_outputs:zf,encode_tx_version:_f,encode_tx_vout:kf,encode_txin_sequence:vf,encode_txin_txid:wf,encode_txin_vout:yf,encode_vin:Ef,encode_vin_witness:Of,encode_vout_value:xf,get_prevouts:function(e){df(e);const t=e.vin.map(e=>e.prevout);return b.ok(t.every(e=>null!==e),"prevouts missing from tx"),t},get_segwit_size:function(e){return 2+e.filter(e=>e.witness.length>0).map(e=>e.witness).reduce((e,t)=>e+Of(t).length,0)},get_tx_value:function(e){const t=Bf(e);df(t);const n=t.vin.reduce((e,t)=>e+(t.prevout?.value??0n),0n),r=t.vout.reduce((e,t)=>e+t.value,0n);return{fees:n>r?n-r:0n,vin:n,vout:r}},get_txhash:function(e){return"object"==typeof e&&(df(e),e=gf(e,!0)),mn(e).reverse().hex},get_txid:function(e){return"object"==typeof e&&(df(e),e=gf(e,!1)),mn(e).reverse().hex},get_txin_size:function(e){return Ef(e).length},get_txout_size:function(e){return kf(e).length},get_txsize:function(e){const t=Bf(e),n=gf(t,!1).length,r=gf(t,!0).length,i=3*n+r,o=i%4>0?1:0;return{base:n,total:r,vsize:Math.ceil(i/4)+o,weight:i}},get_vin_size:function(e){return bf(e).length},get_vout_size:function(e){return zf(e).length},get_vsize:function(e){const t=g.bytes(e).length,n=t%4>0?1:0;return Math.ceil(t/4)+n},normalize_prevout:Rf,normalize_sequence:Uf,normalize_value:Zf,parse_tx:Bf,read_payload:Nf,serialize_tx:function(e){const t=Bf(e),n=t.version,r=t.locktime,i=[],o=[];for(const e of t.vin)null!==e.prevout&&i.push({script_pk:e.prevout.script_pk,value:Number(e.prevout.value)});for(const e of t.vout)o.push({script_pk:e.script_pk,value:Number(e.value)});return{version:n,locktime:r,vin:i,vout:o}}});function qf(e,t={}){const{sigflag:n=1,txindex:r}=t,i=Bf(e),o=!(128&~n),s=n%128;if(!qu.includes(s))throw new Error("Invalid hash type: "+String(n));const{version:u,vin:c,vout:a,locktime:f}=i,d=Ya(i,t),{txid:l,vout:h,prevout:p,sequence:m}=d,{value:_}=p??{};if(void 0===_)throw new Error("Prevout value is empty!");let{pubkey:w,script:y}=t;if(void 0===y&&void 0!==w){const e=hn(w).hex;y=`76a914${String(e)}88ac`}if(void 0===y)throw new Error("No pubkey / script has been set!");if(ba(y).includes("OP_CODESEPARATOR"))throw new Error("This library does not currently support the use of OP_CODESEPARATOR in segwit scripts.");const v=[_f(u),Mf(c,o),Kf(c,s,o),wf(l),yf(h),Ka(y),xf(_),vf(m),Wf(a,s,r),Pf(f),g.num(n,4).reverse()];return mn(g.join(v))}function Mf(e,t){if(!0===t)return g.num(0,32);const n=[];for(const{txid:t,vout:r}of e)n.push(wf(t)),n.push(yf(r));return mn(g.join(n))}function Kf(e,t,n){if(n||1!==t)return g.num(0,32);const r=[];for(const{sequence:t}of e)r.push(vf(t));return mn(g.join(r))}function Wf(e,t,n){const r=[];if(1===t){for(const{value:t,script_pk:n}of e)r.push(xf(t)),r.push(Ka(n));return mn(g.join(r))}if(3===t&&(b.ok(void 0!==n),n<e.length)){const{value:t,script_pk:i}=e[n];return r.push(xf(t)),r.push(Ka(i)),mn(g.join(r))}return g.num(0,32)}function Gf(e,t=192){return Yf(Ka(e),t)}function Yf(e,t=192){return gn("TapLeaf",Jf(t),e)}function Xf(e,t){return t<e&&([e,t]=[t,e]),gn("TapBranch",e,t)}function Jf(e=192){return 254&e}function Qf(e,t=new Uint8Array){return b.size(e,32),gn("TapTweak",e,t)}function ed(e,t={}){return gn("TapSighash",td(e,t))}function td(e,t={}){const{script:n,txindex:r,sigflag:i=0,extflag:o=0,key_version:s=0,separator_pos:u=4294967295}=t,c=Bf(e),{version:a,vin:f,vout:d,locktime:l}=c,h=Ya(c,t),{txid:p,vout:m,sequence:_,witness:w=[]}=h;if(!Mu.includes(i))throw new Error("Invalid hash type: "+String(i));if(o<0||o>127)throw new Error("Extention flag out of range: "+String(o));let{extension:y}=t;void 0!==n&&(y=Gf(n).hex);const v=!(128&~i),E=Xa(w),x=2*(o+(void 0!==y?1:0))+(void 0!==E?1:0),z=[g.num(0,1),g.num(i,1),_f(a),Pf(l)];if(!v){const e=f.map(e=>Ga(e));z.push(nd(f),id(e),od(e),rd(f))}if(((3&i)<2||(3&i)>3)&&z.push(sd(d)),z.push(g.num(x,1)),v){const{value:e,script_pk:t}=Ga(h);z.push(wf(p),yf(m),xf(e),Sf(t),vf(_))}else b.ok("number"==typeof r),z.push(g.num(r,4).reverse());return void 0!==E&&z.push(E),3&~i||(b.ok("number"==typeof r),z.push(ud(d[r]))),void 0!==y&&z.push(g.bytes(y),g.num(s),g.num(u,4,"le")),g.join(z)}function nd(e){const t=[];for(const{txid:n,vout:r}of e)t.push(wf(n)),t.push(yf(r));return pn(g.join(t))}function rd(e){return pn(...e.map(e=>vf(e.sequence)))}function id(e){return pn(...e.map(e=>xf(e.value)))}function od(e){return pn(...e.map(e=>Sf(e.script_pk)))}function sd(e){const t=[];for(const{value:n,script_pk:r}of e)t.push(xf(n)),t.push(Sf(r));return pn(...t)}function ud(e){return pn(xf(e.value),Sf(e.script_pk))}var cd=Object.freeze({__proto__:null,bip143_hash_outputs:Wf,bip143_hash_prevouts:Mf,bip143_hash_sequence:Kf,bip341_hash_amounts:id,bip341_hash_outpoints:nd,bip341_hash_output:ud,bip341_hash_outputs:sd,bip341_hash_scripts:od,bip341_hash_sequence:rd,get_annex_data:Xa,get_prevout:Ga,get_taproot_tx_preimage:td,hash_segwit_tx:qf,hash_taproot_tx:ed,parse_txinput:Ya});function ad(e){return 0!==e?g.num(e,1).hex:""}var fd=Object.freeze({__proto__:null,sign_segwit_tx:function(e,t,n){return function(e,t){const n=Yt(t),r=St.sign(n,e).toDERRawBytes();return g.bytes(r)}(e,qf(Bf(t),n)).hex+ad(n.sigflag??1)},sign_taproot_tx:function(e,t,n){return function(e,t){const n=Yt(t);return Yt(Vt.sign(n,e))}(e,ed(Bf(t),n)).hex+ad(n.sigflag??0)},verify_tx:function(e,t={}){return console.warn("verify_segwit_tx is not implemented"),!0}});function dd(e,t,n=[]){const r=[],i=[];if(e.length<1)throw new Error("Tree is empty!");for(let i=0;i<e.length;i++){const o=e[i];if(Array.isArray(o)){let[e,i,s]=dd(o,t);t=i,r.push(e);for(const e of s)n.push(e)}else{const e=g.bytes(o).hex;r.push(e)}}if(1===r.length)return[r[0],t,n];r.sort(),r.length%2!=0&&r.push(r[r.length-1]);for(let e=0;e<r.length-1;e+=2){const o=Xf(r[e],r[e+1]).hex;i.push(o),"string"==typeof t&&(t===r[e]?(n.push(r[e+1]),t=o):t===r[e+1]&&(n.push(r[e]),t=o))}return dd(i,t,n)}function ld(e){const t=e.map(e=>g.bytes(e)),n=e.map(e=>g.bytes(e).hex),r=function(e){let t=e.at(-1);return e.length>1&&t instanceof Uint8Array&&80===t[0]?new g(t).hex:null}(t);null!==r&&t.pop();const i=function(e){let t=e.at(-1);return e.length>1&&t instanceof Uint8Array&&t.length>32&&Du.includes(254&t[0])?new g(t).hex:null}(t);null!==i&&t.pop();const o=function(e,t){let n=e.at(0),r=e.at(1),i=e.at(-1);return null!==t&&void 0!==i?"p2ts":2===e.length&&void 0!==n&&void 0!==r&&n.length>=64&&33===r.length?"p2wpkh":1===e.length&&void 0!==n&&64===n.length?"p2tr":e.length>1&&void 0!==i&&Ea(i)?"p2wsh":null}(t,i),s=function(e){return null===e?null:e.startsWith("p2w")?0:e.startsWith("p2t")?1:null}(o),u=function(e,t){let n;switch(t){case"p2ts":n=e.at(-1);case"p2wsh":n=e.at(-1)}return void 0!==n?new g(n).hex:null}(t,o);null!==u&&t.pop();return{annex:r,cblock:i,params:t.map(e=>e.hex),script:u,stack:n,type:o,version:s}}function hd(e){const t=new _(e),n=t.read(1).num,r=t.read(32).hex,[i,o]=pd(n),s=[];for(;t.size>=32;)s.push(t.read(32).hex);if(0!==t.size)throw new Error("Non-empty buffer on control block: "+String(t));return{int_key:r,path:s,parity:o,version:i}}function pd(e){return e%2==0?[e-0,2]:[e-1,3]}function md(e){b.size(e,33,"invalid pubkey size");const[t]=g.bytes(e);if(2===t)return 0;if(3===t)return 1;throw new Error("Invalid parity bit: "+String(t))}const gd=192;var _d=Object.freeze({__proto__:null,create_taproot:function(e){Qa.parse(e);const{pubkey:t,version:n=gd}=e,r=e.leaves??[],i=void 0!==e.target?g.bytes(e.target).hex:void 0;let o,s=[];if(r.length>0){const[e,t,n]=dd(r,i);s=n,o=e}else o=i;const u=Qf(t,o),c=Wt(t,u,"ecdsa"),a=md(c),f=Gt(c,"bip340"),d=[g.num(n+a),g.bytes(t)];s.length>0&&s.forEach(e=>d.push(e));const l=g.join(d);return{int_key:g.bytes(t).hex,path:s,parity:a,taproot:o??null,cblock:l.hex,tapkey:f.hex,taptweak:u.hex}},encode_leaf_version:Jf,encode_tapbranch:Xf,encode_tapleaf:Yf,encode_tapscript:Gf,encode_taptweak:Qf,get_merkle_root:function(e){return dd(e)[0]},merkleize:dd,parse_cblock:hd,parse_cblock_parity:pd,parse_pubkey_parity:md,parse_taproot_witness:function(e){const{cblock:t,params:n,script:r}=ld(e);b.exists(t,"cblock is null"),b.exists(r,"script is null");const i=hd(t);let o=Gf(r,i.version).hex;for(const e of i.path)o=Xf(o,e).hex;const s=Qf(i.int_key,o),u=Wt(i.int_key,s,"bip340");return n.map(e=>g.bytes(e).hex),{cblock:i,params:n,script:r,tapkey:u.hex,tweak:s.hex}},verify_taproot:function(e,t,n){b.size(e,32);const{parity:r,path:i,int_key:o}=hd(n),s=g.join([r,e]);let u=g.bytes(t).hex;for(const e of i)u=Xf(u,e).hex;const c=Wt(o,Qf(o,u),"ecdsa");return s.hex===c.hex}});var wd=Object.freeze({__proto__:null,assert_witness:function(e){b.ok(Array.isArray(e),"witness must be an array"),b.ok(e.every(e=>g.is_bytes(e)),"witness must be an array of strings or bytes")},get_witness_size:function(e){const t=e.map(e=>g.bytes(e)).reduce((e,t)=>e+t.length,0);return{total:t,vsize:Math.ceil(1+t/4)}},parse_witness:ld});return e.ADDRESS=qc,e.CONST=Ku,e.META=Ma,e.SCHEMA=ff,e.SCRIPT=Wa,e.SIGHASH=cd,e.SIGNER=fd,e.TAPROOT=_d,e.TX=Vf,e.WITNESS=wd,e}({});
14
14
  //# sourceMappingURL=script.js.map