@vbyte/btc-dev 1.0.14 → 1.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/script.js CHANGED
@@ -1,15 +1,15 @@
1
- var btc_devkit=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),s=BigInt(256);function o(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 o="le"===n,a=new ArrayBuffer(t),u=new DataView(a);let c=o?0:t-1;for(;e>r;){const t=e&i,n=Number(t);o?u.setUint8(c++,n):u.setUint8(c--,n),e=(e-t)/s}return new Uint8Array(a)}function a(e,t){return"bigint"==typeof t?`${t}n`:t}function u(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),s=new DataView(i);let o=r?0:t-1;for(;e>0;){const t=255&e;r?s.setUint8(o++,e):s.setUint8(o--,e),e=(e-t)/256}return new Uint8Array(i)}function d(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,s=new ArrayBuffer(t),o=new DataView(s);let a=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?o.setUint8(a++,r):o.setUint8(a--,r)}return new Uint8Array(s)}function f(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),s="be"===r?0:t-e.length;return i.set(e,s),i}(e,t,r);if("string"==typeof e)return n.is_hex(e),d(e,t,r);if("bigint"==typeof e)return o(e,t,r);if("number"==typeof e)return c(e,t,r);throw new TypeError("Input type not supported:"+typeof e)}const h=new TextEncoder,l=new TextDecoder;function p(e){return h.encode(e)}function g(e){return l.decode(e)}class m extends Uint8Array{static{this.num=(e,t,n)=>new m(e,t,n)}static{this.big=(e,t,n)=>new m(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 m(r,t,n)}}static{this.uint=(e,t,n)=>new m(e,t,n)}static{this.str=(e,t,n)=>{const r=p(e);return new m(r,t,n)}}static{this.hex=(e,t,r)=>(n.is_hex(e),new m(e,t,r))}static{this.bytes=(e,t,r)=>(n.is_bytes(e),new m(e,t,r))}static{this.json=(e,t)=>{t=t??a;const n=p(JSON.stringify(e,t));return new m(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 s=new Array(i);for(let n=0;n<i;n++){const r=n*t;s[n]=e.subarray(r,r+t)}return s}(f(e),t,n);return r.map(e=>new m(e))}}static{this.is_equal=(e,t)=>new m(e).hex===new m(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 m(t,e)}static now(){const e=Math.floor(Date.now()/1e3);return new m(e,4)}constructor(e,t,n){if(e instanceof m&&void 0===t)return e;super(f(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*s+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=u);const t=g(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 g(this)}to_uint(){return new Uint8Array(this)}append(e){return m.join([this,new m(e)])}equals(e){return new m(e).hex===this.hex}prepend(e){return m.join([new m(e),this])}prefix_varint(e){if(0===this.length)throw new Error("buffer is empty");const t=m.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 m(n)}subarray(e,t){const n=new Uint8Array(this).subarray(e,t);return new m(n)}toJSON(){return this.hex}toString(){return this.hex}static from(e){return new m(Uint8Array.from(e))}static of(...e){return new m(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 m(e)));return new m(t)}static sort(e,t){const n=e.map(e=>new m(e,t).hex);return n.sort(),n.map(e=>m.hex(e,t))}static varint(e,t){if(e<253)return m.num(e,1);if(e<65536)return m.of(253,...m.num(e,2,t));if(e<4294967296)return m.of(254,...m.num(e,4,t));if(BigInt(e)<0x10000000000000000n)return m.of(255,...m.num(e,8,t));throw new Error(`Value is too large: ${e}`)}}class y{constructor(e){this.data=new m(e),this.size=this.data.length}peek(e){if(e>this.size)throw new Error(`Size greater than stream: ${e} > ${this.size}`);return new m(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 v(e){return e instanceof Error?e.message:"string"==typeof e?e:String(e)}var _,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 m.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}}(_||(_={})),function(e){e.ok=function(e,t){if(!1===e)throw new Error(t??"Assertion failed!")},e.exists=function(e,t){if(!_.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(!_.is_equal(e,t))throw new Error(n??`values are not equal: ${String(e)} !== ${String(t)}`)},e.is_object=function(e,t){if(!_.is_object(e))throw new Error(t??`value is not an object: ${String(e)}`)},e.is_deep_equal=function(e,t,n){if(!_.is_deep_equal(e,t))throw new Error(n??`values are not deep equal: ${String(e)} !== ${String(t)}`)},e.is_number=function(e){if(!_.is_number(e))throw new TypeError(`invalid number: ${String(e)}`)},e.is_bigint=function(e){if(!_.is_bigint(e))throw new TypeError(`invalid bigint: ${String(e)}`)},e.is_hex=function(e){if(!_.is_hex(e))throw new TypeError(`invalid hex: ${String(e)}`)},e.is_uchar=function(e){if(!_.is_uchar(e))throw new TypeError(`invalid unsignedchar: ${String(e)}`)},e.is_ushort=function(e){if(!_.is_ushort(e))throw new TypeError(`invalid unsigned short: ${String(e)}`)},e.is_uint=function(e){if(!_.is_uint(e))throw new TypeError(`invalid unsigned int: ${String(e)}`)},e.is_u8a=function(e){if(!_.is_u8a(e))throw new TypeError(`invalid Uint8Array: ${String(e)}`)},e.is_hash=function(e,t){if(!_.is_hash(e))throw new TypeError(t??`invalid hash: ${String(e)}`)},e.is_bytes=function(e,t){if(!_.is_bytes(e))throw new TypeError(t??`invalid bytes: ${String(e)}`)},e.size=function(e,t,n){const r=m.bytes(e);if(r.length!==t)throw new Error(n??`invalid input size: ${r.length} !== ${t}`)},e.has_items=function(e,t){if(!_.has_items(e))throw new Error(t??"array does not contain any items")},e.is_base58=function(e){if(!_.is_base58(e))throw new Error("invalid base58 string")},e.is_base64=function(e){if(!_.is_base64(e))throw new Error("invalid base64 string")},e.is_b64url=function(e){if(!_.is_b64url(e))throw new Error("invalid base64url string")},e.is_bech32=function(e){if(!_.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 S(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,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 A(...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 T(e,t){return e<<32-t|e>>>t}function I(e,t){return e<<t|e>>>32-t>>>0}const N=(()=>"function"==typeof Uint8Array.from([]).toHex&&"function"==typeof Uint8Array.fromHex)(),$=Array.from({length:256},(e,t)=>t.toString(16).padStart(2,"0"));function U(e){if(k(e),N)return e.toHex();let t="";for(let n=0;n<e.length;n++)t+=$[e[n]];return t}const C=48,B=57,R=65,L=70,z=97,j=102;function H(e){return e>=C&&e<=B?e-C:e>=R&&e<=L?e-(R-10):e>=z&&e<=j?e-(z-10):void 0}function D(e){if("string"!=typeof e)throw new Error("hex string expected, got "+typeof e);if(N)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)),s=H(e.charCodeAt(i+1));if(void 0===n||void 0===s){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+s}return r}function F(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 Z{}function K(e){const t=t=>e().update(F(t)).digest(),n=e();return t.outputLen=n.outputLen,t.blockLen=n.blockLen,t.create=()=>e(),t}function W(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 M(e,t,n){return e&t^~e&n}function q(e,t,n){return e&t^e&n^t&n}class G extends Z{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){O(this),k(e=F(e));const{view:t,buffer:n,blockLen:r}=this,i=e.length;for(let s=0;s<i;){const o=Math.min(r-this.pos,i-s);if(o===r){const t=P(e);for(;r<=i-s;s+=r)this.process(t,s);continue}n.set(e.subarray(s,s+o),this.pos),this.pos+=o,s+=o,this.pos===r&&(this.process(t,0),this.pos=0)}return this.length+=e.length,this.roundClean(),this}digestInto(e){O(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:s}=this;t[s++]=128,A(this.buffer.subarray(s)),this.padOffset>r-s&&(this.process(n,0),s=0);for(let e=s;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),s=BigInt(4294967295),o=Number(n>>i&s),a=Number(n&s),u=r?4:0,c=r?0:4;e.setUint32(t+u,o,r),e.setUint32(t+c,a,r)}(n,r-8,BigInt(8*this.length),i),this.process(n,0);const o=P(e),a=this.outputLen;if(a%4)throw new Error("_sha2: outputLen should be aligned to 32bit");const u=a/4,c=this.get();if(u>c.length)throw new Error("_sha2: outputLen bigger than state");for(let e=0;e<u;e++)o.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:s,pos:o}=this;return e.destroyed=s,e.finished=i,e.length=r,e.pos=o,r%t&&e.buffer.set(n),e}clone(){return this._cloneInto()}}const Y=Uint32Array.from([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]),Q=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]),X=new Uint32Array(64);class J extends G{constructor(e=32){super(64,e,8,!1),this.A=0|Y[0],this.B=0|Y[1],this.C=0|Y[2],this.D=0|Y[3],this.E=0|Y[4],this.F=0|Y[5],this.G=0|Y[6],this.H=0|Y[7]}get(){const{A:e,B:t,C:n,D:r,E:i,F:s,G:o,H:a}=this;return[e,t,n,r,i,s,o,a]}set(e,t,n,r,i,s,o,a){this.A=0|e,this.B=0|t,this.C=0|n,this.D=0|r,this.E=0|i,this.F=0|s,this.G=0|o,this.H=0|a}process(e,t){for(let n=0;n<16;n++,t+=4)X[n]=e.getUint32(t,!1);for(let e=16;e<64;e++){const t=X[e-15],n=X[e-2],r=T(t,7)^T(t,18)^t>>>3,i=T(n,17)^T(n,19)^n>>>10;X[e]=i+X[e-7]+r+X[e-16]|0}let{A:n,B:r,C:i,D:s,E:o,F:a,G:u,H:c}=this;for(let e=0;e<64;e++){const t=c+(T(o,6)^T(o,11)^T(o,25))+M(o,a,u)+Q[e]+X[e]|0,d=(T(n,2)^T(n,13)^T(n,22))+q(n,r,i)|0;c=u,u=a,a=o,o=s+t|0,s=i,i=r,r=n,n=t+d|0}n=n+this.A|0,r=r+this.B|0,i=i+this.C|0,s=s+this.D|0,o=o+this.E|0,a=a+this.F|0,u=u+this.G|0,c=c+this.H|0,this.set(n,r,i,s,o,a,u,c)}roundClean(){A(X)}destroy(){this.set(0,0,0,0,0,0,0,0),A(this.buffer)}}const ee=K(()=>new J);class te extends Z{constructor(e,t){super(),this.finished=!1,this.destroyed=!1,function(e){if("function"!=typeof e||"function"!=typeof e.create)throw new Error("Hash should be wrapped by utils.createHasher");S(e.outputLen),S(e.blockLen)}(e);const n=F(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),A(i)}update(e){return O(this),this.iHash.update(e),this}digestInto(e){O(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:s,outputLen:o}=this;return e.finished=r,e.destroyed=i,e.blockLen=s,e.outputLen=o,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 ne=(e,t,n)=>new te(e,t).update(n).digest();ne.create=(e,t)=>new te(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),s=BigInt(256);function o(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 o="le"===n,a=new ArrayBuffer(t),u=new DataView(a);let c=o?0:t-1;for(;e>r;){const t=e&i,n=Number(t);o?u.setUint8(c++,n):u.setUint8(c--,n),e=(e-t)/s}return new Uint8Array(a)}function a(e,t){return"bigint"==typeof t?`${t}n`:t}function u(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),s=new DataView(i);let o=r?0:t-1;for(;e>0;){const t=255&e;r?s.setUint8(o++,e):s.setUint8(o--,e),e=(e-t)/256}return new Uint8Array(i)}function d(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,s=new ArrayBuffer(t),o=new DataView(s);let a=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?o.setUint8(a++,r):o.setUint8(a--,r)}return new Uint8Array(s)}function f(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),s="be"===r?0:t-e.length;return i.set(e,s),i}(e,t,r);if("string"==typeof e)return n.is_hex(e),d(e,t,r);if("bigint"==typeof e)return o(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??a;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 s=new Array(i);for(let n=0;n<i;n++){const r=n*t;s[n]=e.subarray(r,r+t)}return s}(f(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(f(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*s+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=u);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 y{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 v(e){return e instanceof Error?e.message:"string"==typeof e?e:String(e)}var w,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}}(w||(w={})),function(e){e.ok=function(e,t){if(!1===e)throw new Error(t??"Assertion failed!")},e.exists=function(e,t){if(!w.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(!w.is_equal(e,t))throw new Error(n??`values are not equal: ${String(e)} !== ${String(t)}`)},e.is_object=function(e,t){if(!w.is_object(e))throw new Error(t??`value is not an object: ${String(e)}`)},e.is_deep_equal=function(e,t,n){if(!w.is_deep_equal(e,t))throw new Error(n??`values are not deep equal: ${String(e)} !== ${String(t)}`)},e.is_number=function(e){if(!w.is_number(e))throw new TypeError(`invalid number: ${String(e)}`)},e.is_bigint=function(e){if(!w.is_bigint(e))throw new TypeError(`invalid bigint: ${String(e)}`)},e.is_hex=function(e){if(!w.is_hex(e))throw new TypeError(`invalid hex: ${String(e)}`)},e.is_uchar=function(e){if(!w.is_uchar(e))throw new TypeError(`invalid unsignedchar: ${String(e)}`)},e.is_ushort=function(e){if(!w.is_ushort(e))throw new TypeError(`invalid unsigned short: ${String(e)}`)},e.is_uint=function(e){if(!w.is_uint(e))throw new TypeError(`invalid unsigned int: ${String(e)}`)},e.is_u8a=function(e){if(!w.is_u8a(e))throw new TypeError(`invalid Uint8Array: ${String(e)}`)},e.is_hash=function(e,t){if(!w.is_hash(e))throw new TypeError(t??`invalid hash: ${String(e)}`)},e.is_bytes=function(e,t){if(!w.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(!w.has_items(e))throw new Error(t??"array does not contain any items")},e.is_base58=function(e){if(!w.is_base58(e))throw new Error("invalid base58 string")},e.is_base64=function(e){if(!w.is_base64(e))throw new Error("invalid base64 string")},e.is_b64url=function(e){if(!w.is_b64url(e))throw new Error("invalid base64url string")},e.is_bech32=function(e){if(!w.is_bech32(e))throw new Error("invalid bech32 string")}}(b||(b={}));const x="object"==typeof globalThis&&"crypto"in globalThis?globalThis.crypto:void 0;
2
+ /*! noble-hashes - MIT License (c) 2022 Paul Miller (paulmillr.com) */function E(e){return e instanceof Uint8Array||ArrayBuffer.isView(e)&&"Uint8Array"===e.constructor.name}function k(e){if(!Number.isSafeInteger(e)||e<0)throw new Error("positive integer expected, got "+e)}function O(e,...t){if(!E(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 S(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 A(...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 I(e,t){return e<<32-t|e>>>t}function T(e,t){return e<<t|e>>>32-t>>>0}const N=(()=>"function"==typeof Uint8Array.from([]).toHex&&"function"==typeof Uint8Array.fromHex)(),C=Array.from({length:256},(e,t)=>t.toString(16).padStart(2,"0"));function $(e){if(O(e),N)return e.toHex();let t="";for(let n=0;n<e.length;n++)t+=C[e[n]];return t}const R=48,B=57,U=65,j=70,Z=97,z=102;function L(e){return e>=R&&e<=B?e-R:e>=U&&e<=j?e-(U-10):e>=Z&&e<=z?e-(Z-10):void 0}function F(e){if("string"!=typeof e)throw new Error("hex string expected, got "+typeof e);if(N)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=L(e.charCodeAt(i)),s=L(e.charCodeAt(i+1));if(void 0===n||void 0===s){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+s}return r}function D(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)),O(e),e}function H(...e){let t=0;for(let n=0;n<e.length;n++){const r=e[n];O(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 V(e){const t=t=>e().update(D(t)).digest(),n=e();return t.outputLen=n.outputLen,t.blockLen=n.blockLen,t.create=()=>e(),t}function M(e=32){if(x&&"function"==typeof x.getRandomValues)return x.getRandomValues(new Uint8Array(e));if(x&&"function"==typeof x.randomBytes)return Uint8Array.from(x.randomBytes(e));throw new Error("crypto.getRandomValues must be defined")}function K(e,t,n){return e&t^~e&n}function W(e,t,n){return e&t^e&n^t&n}class G 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){S(this),O(e=D(e));const{view:t,buffer:n,blockLen:r}=this,i=e.length;for(let s=0;s<i;){const o=Math.min(r-this.pos,i-s);if(o===r){const t=P(e);for(;r<=i-s;s+=r)this.process(t,s);continue}n.set(e.subarray(s,s+o),this.pos),this.pos+=o,s+=o,this.pos===r&&(this.process(t,0),this.pos=0)}return this.length+=e.length,this.roundClean(),this}digestInto(e){S(this),function(e,t){O(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:s}=this;t[s++]=128,A(this.buffer.subarray(s)),this.padOffset>r-s&&(this.process(n,0),s=0);for(let e=s;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),s=BigInt(4294967295),o=Number(n>>i&s),a=Number(n&s),u=r?4:0,c=r?0:4;e.setUint32(t+u,o,r),e.setUint32(t+c,a,r)}(n,r-8,BigInt(8*this.length),i),this.process(n,0);const o=P(e),a=this.outputLen;if(a%4)throw new Error("_sha2: outputLen should be aligned to 32bit");const u=a/4,c=this.get();if(u>c.length)throw new Error("_sha2: outputLen bigger than state");for(let e=0;e<u;e++)o.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:s,pos:o}=this;return e.destroyed=s,e.finished=i,e.length=r,e.pos=o,r%t&&e.buffer.set(n),e}clone(){return this._cloneInto()}}const Y=Uint32Array.from([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]),Q=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]),X=new Uint32Array(64);class J extends G{constructor(e=32){super(64,e,8,!1),this.A=0|Y[0],this.B=0|Y[1],this.C=0|Y[2],this.D=0|Y[3],this.E=0|Y[4],this.F=0|Y[5],this.G=0|Y[6],this.H=0|Y[7]}get(){const{A:e,B:t,C:n,D:r,E:i,F:s,G:o,H:a}=this;return[e,t,n,r,i,s,o,a]}set(e,t,n,r,i,s,o,a){this.A=0|e,this.B=0|t,this.C=0|n,this.D=0|r,this.E=0|i,this.F=0|s,this.G=0|o,this.H=0|a}process(e,t){for(let n=0;n<16;n++,t+=4)X[n]=e.getUint32(t,!1);for(let e=16;e<64;e++){const t=X[e-15],n=X[e-2],r=I(t,7)^I(t,18)^t>>>3,i=I(n,17)^I(n,19)^n>>>10;X[e]=i+X[e-7]+r+X[e-16]|0}let{A:n,B:r,C:i,D:s,E:o,F:a,G:u,H:c}=this;for(let e=0;e<64;e++){const t=c+(I(o,6)^I(o,11)^I(o,25))+K(o,a,u)+Q[e]+X[e]|0,d=(I(n,2)^I(n,13)^I(n,22))+W(n,r,i)|0;c=u,u=a,a=o,o=s+t|0,s=i,i=r,r=n,n=t+d|0}n=n+this.A|0,r=r+this.B|0,i=i+this.C|0,s=s+this.D|0,o=o+this.E|0,a=a+this.F|0,u=u+this.G|0,c=c+this.H|0,this.set(n,r,i,s,o,a,u,c)}roundClean(){A(X)}destroy(){this.set(0,0,0,0,0,0,0,0),A(this.buffer)}}const ee=V(()=>new J);class te extends q{constructor(e,t){super(),this.finished=!1,this.destroyed=!1,function(e){if("function"!=typeof e||"function"!=typeof e.create)throw new Error("Hash should be wrapped by utils.createHasher");k(e.outputLen),k(e.blockLen)}(e);const n=D(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),A(i)}update(e){return S(this),this.iHash.update(e),this}digestInto(e){S(this),O(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:s,outputLen:o}=this;return e.finished=r,e.destroyed=i,e.blockLen=s,e.outputLen=o,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 ne=(e,t,n)=>new te(e,t).update(n).digest();ne.create=(e,t)=>new te(e,t);
3
3
  /*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */
4
- const re=BigInt(0),ie=BigInt(1);function se(e,t){if("boolean"!=typeof t)throw new Error(e+" boolean expected, got "+t)}function oe(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?re:BigInt("0x"+e)}function ue(e){return ae(U(e))}function ce(e){return k(e),ae(U(Uint8Array.from(e).reverse()))}function de(e,t){return D(e.toString(16).padStart(2*t,"0"))}function fe(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 le=e=>"bigint"==typeof e&&re<=e;function pe(e,t,n){return le(e)&&le(t)&&le(n)&&t<=e&&e<n}function ge(e,t,n,r){if(!pe(t,n,r))throw new Error("expected valid "+e+": "+n+" <= n < "+r+", got "+t)}const me=e=>(ie<<BigInt(e))-ie;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 s=typeof i;if(s!==n||null===i)throw new Error(`param "${t}" is invalid: expected ${n}, got ${s}`)}Object.entries(t).forEach(([e,t])=>r(e,t,!1)),Object.entries(n).forEach(([e,t])=>r(e,t,!0))}function we(e){const t=new WeakMap;return(n,...r)=>{const i=t.get(n);if(void 0!==i)return i;const s=e(n,...r);return t.set(n,s),s}}
5
- /*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */const ve=BigInt(0),_e=BigInt(1),be=BigInt(2),Ee=BigInt(3),xe=BigInt(4),Se=BigInt(5),ke=BigInt(8);function Oe(e,t){const n=e%t;return n>=ve?n:t+n}function Ae(e,t,n){let r=e;for(;t-- >ve;)r*=r,r%=n;return r}function Pe(e,t){if(e===ve)throw new Error("invert: expected non-zero number");if(t<=ve)throw new Error("invert: expected positive modulus, got "+t);let n=Oe(e,t),r=t,i=ve,s=_e;for(;n!==ve;){const e=r%n,t=i-s*(r/n);r=n,n=e,i=s,s=t}if(r!==_e)throw new Error("invert: does not exist");return Oe(i,t)}function Te(e,t){const n=(e.ORDER+_e)/xe,r=e.pow(t,n);if(!e.eql(e.sqr(r),t))throw new Error("Cannot find square root");return r}function Ie(e,t){const n=(e.ORDER-Se)/ke,r=e.mul(t,be),i=e.pow(r,n),s=e.mul(t,i),o=e.mul(e.mul(s,be),i),a=e.mul(s,e.sub(o,e.ONE));if(!e.eql(e.sqr(a),t))throw new Error("Cannot find square root");return a}function Ne(e){return e%xe===Ee?Te:e%ke===Se?Ie:function(e){if(e<BigInt(3))throw new Error("sqrt is not defined for small field");let t=e-_e,n=0;for(;t%be===ve;)t/=be,n++;let r=be;const i=Be(e);for(;1===Ce(i,r);)if(r++>1e3)throw new Error("Cannot find square root: probably non-prime P");if(1===n)return Te;let s=i.pow(r,t);const o=(t+_e)/be;return function(e,r){if(e.is0(r))return r;if(1!==Ce(e,r))throw new Error("Cannot find square root");let i=n,a=e.mul(e.ONE,s),u=e.pow(r,t),c=e.pow(r,o);for(;!e.eql(u,e.ONE);){if(e.is0(u))return e.ZERO;let t=1,n=e.sqr(u);for(;!e.eql(n,e.ONE);)if(t++,n=e.sqr(n),t===i)throw new Error("Cannot find square root");const r=_e<<BigInt(i-t-1),s=e.pow(a,r);i=t,a=e.sqr(s),u=e.mul(u,a),c=e.mul(c,s)}return c}}(e)}const $e=["create","isValid","is0","neg","inv","sqrt","sqr","eql","add","sub","mul","pow","div","addN","subN","mulN","sqrN"];function Ue(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),s=e.inv(i);return t.reduceRight((t,n,i)=>e.is0(n)?t:(r[i]=e.mul(t,r[i]),e.mul(t,n)),s),r}function Ce(e,t){const n=(e.ORDER-_e)/be,r=e.pow(t,n),i=e.eql(r,e.ONE),s=e.eql(r,e.ZERO),o=e.eql(r,e.neg(e.ONE));if(!i&&!s&&!o)throw new Error("invalid Legendre symbol result");return i?1:s?0:-1}function Be(e,t,n=!1,r={}){if(e<=ve)throw new Error("invalid field: expected ORDER > 0, got "+e);let i,s;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&&(s=e.sqrt),"boolean"==typeof e.isLE&&(n=e.isLE)}else"number"==typeof t&&(i=t),r.sqrt&&(s=r.sqrt);const{nBitLength:o,nByteLength:a}=function(e,t){void 0!==t&&S(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 u;const c=Object.freeze({ORDER:e,isLE:n,BITS:o,BYTES:a,MASK:me(o),ZERO:ve,ONE:_e,create:t=>Oe(t,e),isValid:t=>{if("bigint"!=typeof t)throw new Error("invalid field element: expected bigint, got "+typeof t);return ve<=t&&t<e},is0:e=>e===ve,isValidNot0:e=>!c.is0(e)&&c.isValid(e),isOdd:e=>(e&_e)===_e,neg:t=>Oe(-t,e),eql:(e,t)=>e===t,sqr:t=>Oe(t*t,e),add:(t,n)=>Oe(t+n,e),sub:(t,n)=>Oe(t-n,e),mul:(t,n)=>Oe(t*n,e),pow:(e,t)=>function(e,t,n){if(n<ve)throw new Error("invalid exponent, negatives unsupported");if(n===ve)return e.ONE;if(n===_e)return t;let r=e.ONE,i=t;for(;n>ve;)n&_e&&(r=e.mul(r,i)),i=e.sqr(i),n>>=_e;return r}(c,e,t),div:(t,n)=>Oe(t*Pe(n,e),e),sqrN:e=>e*e,addN:(e,t)=>e+t,subN:(e,t)=>e-t,mulN:(e,t)=>e*t,inv:t=>Pe(t,e),sqrt:s||(t=>(u||(u=Ne(e)),u(c,t))),toBytes:e=>n?fe(e,a):de(e,a),fromBytes:e=>{if(e.length!==a)throw new Error("Field.fromBytes: expected "+a+" bytes, got "+e.length);return n?ce(e):ue(e)},invertBatch:e=>Ue(c,e),cmov:(e,t,n)=>n?t:e});return Object.freeze(c)}function Re(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 Le(e){const t=Re(e);return t+Math.ceil(t/2)}
4
+ const re=BigInt(0),ie=BigInt(1);function se(e,t){if("boolean"!=typeof t)throw new Error(e+" boolean expected, got "+t)}function oe(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?re:BigInt("0x"+e)}function ue(e){return ae($(e))}function ce(e){return O(e),ae($(Uint8Array.from(e).reverse()))}function de(e,t){return F(e.toString(16).padStart(2*t,"0"))}function fe(e,t){return de(e,t).reverse()}function le(e,t,n){let r;if("string"==typeof t)try{r=F(t)}catch(t){throw new Error(e+" must be hex string or Uint8Array, cause: "+t)}else{if(!E(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 he=e=>"bigint"==typeof e&&re<=e;function pe(e,t,n){return he(e)&&he(t)&&he(n)&&t<=e&&e<n}function me(e,t,n,r){if(!pe(t,n,r))throw new Error("expected valid "+e+": "+n+" <= n < "+r+", got "+t)}const ge=e=>(ie<<BigInt(e))-ie;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 s=typeof i;if(s!==n||null===i)throw new Error(`param "${t}" is invalid: expected ${n}, got ${s}`)}Object.entries(t).forEach(([e,t])=>r(e,t,!1)),Object.entries(n).forEach(([e,t])=>r(e,t,!0))}function _e(e){const t=new WeakMap;return(n,...r)=>{const i=t.get(n);if(void 0!==i)return i;const s=e(n,...r);return t.set(n,s),s}}
5
+ /*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */const ve=BigInt(0),we=BigInt(1),be=BigInt(2),xe=BigInt(3),Ee=BigInt(4),ke=BigInt(5),Oe=BigInt(8);function Se(e,t){const n=e%t;return n>=ve?n:t+n}function Ae(e,t,n){let r=e;for(;t-- >ve;)r*=r,r%=n;return r}function Pe(e,t){if(e===ve)throw new Error("invert: expected non-zero number");if(t<=ve)throw new Error("invert: expected positive modulus, got "+t);let n=Se(e,t),r=t,i=ve,s=we;for(;n!==ve;){const e=r%n,t=i-s*(r/n);r=n,n=e,i=s,s=t}if(r!==we)throw new Error("invert: does not exist");return Se(i,t)}function Ie(e,t){const n=(e.ORDER+we)/Ee,r=e.pow(t,n);if(!e.eql(e.sqr(r),t))throw new Error("Cannot find square root");return r}function Te(e,t){const n=(e.ORDER-ke)/Oe,r=e.mul(t,be),i=e.pow(r,n),s=e.mul(t,i),o=e.mul(e.mul(s,be),i),a=e.mul(s,e.sub(o,e.ONE));if(!e.eql(e.sqr(a),t))throw new Error("Cannot find square root");return a}function Ne(e){return e%Ee===xe?Ie:e%Oe===ke?Te:function(e){if(e<BigInt(3))throw new Error("sqrt is not defined for small field");let t=e-we,n=0;for(;t%be===ve;)t/=be,n++;let r=be;const i=Be(e);for(;1===Re(i,r);)if(r++>1e3)throw new Error("Cannot find square root: probably non-prime P");if(1===n)return Ie;let s=i.pow(r,t);const o=(t+we)/be;return function(e,r){if(e.is0(r))return r;if(1!==Re(e,r))throw new Error("Cannot find square root");let i=n,a=e.mul(e.ONE,s),u=e.pow(r,t),c=e.pow(r,o);for(;!e.eql(u,e.ONE);){if(e.is0(u))return e.ZERO;let t=1,n=e.sqr(u);for(;!e.eql(n,e.ONE);)if(t++,n=e.sqr(n),t===i)throw new Error("Cannot find square root");const r=we<<BigInt(i-t-1),s=e.pow(a,r);i=t,a=e.sqr(s),u=e.mul(u,a),c=e.mul(c,s)}return c}}(e)}const Ce=["create","isValid","is0","neg","inv","sqrt","sqr","eql","add","sub","mul","pow","div","addN","subN","mulN","sqrN"];function $e(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),s=e.inv(i);return t.reduceRight((t,n,i)=>e.is0(n)?t:(r[i]=e.mul(t,r[i]),e.mul(t,n)),s),r}function Re(e,t){const n=(e.ORDER-we)/be,r=e.pow(t,n),i=e.eql(r,e.ONE),s=e.eql(r,e.ZERO),o=e.eql(r,e.neg(e.ONE));if(!i&&!s&&!o)throw new Error("invalid Legendre symbol result");return i?1:s?0:-1}function Be(e,t,n=!1,r={}){if(e<=ve)throw new Error("invalid field: expected ORDER > 0, got "+e);let i,s;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&&(s=e.sqrt),"boolean"==typeof e.isLE&&(n=e.isLE)}else"number"==typeof t&&(i=t),r.sqrt&&(s=r.sqrt);const{nBitLength:o,nByteLength:a}=function(e,t){void 0!==t&&k(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 u;const c=Object.freeze({ORDER:e,isLE:n,BITS:o,BYTES:a,MASK:ge(o),ZERO:ve,ONE:we,create:t=>Se(t,e),isValid:t=>{if("bigint"!=typeof t)throw new Error("invalid field element: expected bigint, got "+typeof t);return ve<=t&&t<e},is0:e=>e===ve,isValidNot0:e=>!c.is0(e)&&c.isValid(e),isOdd:e=>(e&we)===we,neg:t=>Se(-t,e),eql:(e,t)=>e===t,sqr:t=>Se(t*t,e),add:(t,n)=>Se(t+n,e),sub:(t,n)=>Se(t-n,e),mul:(t,n)=>Se(t*n,e),pow:(e,t)=>function(e,t,n){if(n<ve)throw new Error("invalid exponent, negatives unsupported");if(n===ve)return e.ONE;if(n===we)return t;let r=e.ONE,i=t;for(;n>ve;)n&we&&(r=e.mul(r,i)),i=e.sqr(i),n>>=we;return r}(c,e,t),div:(t,n)=>Se(t*Pe(n,e),e),sqrN:e=>e*e,addN:(e,t)=>e+t,subN:(e,t)=>e-t,mulN:(e,t)=>e*t,inv:t=>Pe(t,e),sqrt:s||(t=>(u||(u=Ne(e)),u(c,t))),toBytes:e=>n?fe(e,a):de(e,a),fromBytes:e=>{if(e.length!==a)throw new Error("Field.fromBytes: expected "+a+" bytes, got "+e.length);return n?ce(e):ue(e)},invertBatch:e=>$e(c,e),cmov:(e,t,n)=>n?t:e});return Object.freeze(c)}function Ue(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 je(e){const t=Ue(e);return t+Math.ceil(t/2)}
6
6
  /*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */
7
- const ze=BigInt(0),je=BigInt(1);function He(e,t){const n=t.negate();return e?n:t}function De(e,t){if(!Number.isSafeInteger(e)||e<=0||e>t)throw new Error("invalid window size, expected [1.."+t+"], got W="+e)}function Fe(e,t){De(e,t);const n=2**e;return{windows:Math.ceil(t/e)+1,windowSize:2**(e-1),mask:me(e),maxNumber:n,shiftBy:BigInt(e)}}function Ve(e,t,n){const{windowSize:r,mask:i,maxNumber:s,shiftBy:o}=n;let a=Number(e&i),u=e>>o;a>r&&(a-=s,u+=je);const c=t*r;return{nextN:u,offset:c+Math.abs(a)-1,isZero:0===a,isNeg:a<0,isNegF:t%2!=0,offsetF:c}}const Ze=new WeakMap,Ke=new WeakMap;function We(e){return Ke.get(e)||1}function Me(e){if(e!==ze)throw new Error("invalid wNAF")}function qe(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,s=r.length;if(i!==s)throw new Error("arrays of points and scalars must have equal length");const o=e.ZERO,a=function(e){let t;for(t=0;e>re;e>>=ie,t+=1);return t}(BigInt(i));let u=1;a>12?u=a-3:a>4?u=a-2:a>0&&(u=2);const c=me(u),d=new Array(Number(c)+1).fill(o);let f=o;for(let e=Math.floor((t.BITS-1)/u)*u;e>=0;e-=u){d.fill(o);for(let t=0;t<s;t++){const i=r[t],s=Number(i>>BigInt(e)&c);d[s]=d[s].add(n[t])}let t=o;for(let e=d.length-1,n=o;e>0;e--)n=n.add(d[e]),t=t.add(n);if(f=f.add(t),0!==e)for(let e=0;e<u;e++)f=f.double()}return f}function Ge(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,$e.reduce((e,t)=>(e[t]="function",e),{ORDER:"bigint",MASK:"bigint",BYTES:"number",BITS:"number"}))}(t),t}return Be(e)}
7
+ const Ze=BigInt(0),ze=BigInt(1);function Le(e,t){const n=t.negate();return e?n:t}function Fe(e,t){if(!Number.isSafeInteger(e)||e<=0||e>t)throw new Error("invalid window size, expected [1.."+t+"], got W="+e)}function De(e,t){Fe(e,t);const n=2**e;return{windows:Math.ceil(t/e)+1,windowSize:2**(e-1),mask:ge(e),maxNumber:n,shiftBy:BigInt(e)}}function He(e,t,n){const{windowSize:r,mask:i,maxNumber:s,shiftBy:o}=n;let a=Number(e&i),u=e>>o;a>r&&(a-=s,u+=ze);const c=t*r;return{nextN:u,offset:c+Math.abs(a)-1,isZero:0===a,isNeg:a<0,isNegF:t%2!=0,offsetF:c}}const qe=new WeakMap,Ve=new WeakMap;function Me(e){return Ve.get(e)||1}function Ke(e){if(e!==Ze)throw new Error("invalid wNAF")}function We(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,s=r.length;if(i!==s)throw new Error("arrays of points and scalars must have equal length");const o=e.ZERO,a=function(e){let t;for(t=0;e>re;e>>=ie,t+=1);return t}(BigInt(i));let u=1;a>12?u=a-3:a>4?u=a-2:a>0&&(u=2);const c=ge(u),d=new Array(Number(c)+1).fill(o);let f=o;for(let e=Math.floor((t.BITS-1)/u)*u;e>=0;e-=u){d.fill(o);for(let t=0;t<s;t++){const i=r[t],s=Number(i>>BigInt(e)&c);d[s]=d[s].add(n[t])}let t=o;for(let e=d.length-1,n=o;e>0;e--)n=n.add(d[e]),t=t.add(n);if(f=f.add(t),0!==e)for(let e=0;e<u;e++)f=f.double()}return f}function Ge(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,Ce.reduce((e,t)=>(e[t]="function",e),{ORDER:"bigint",MASK:"bigint",BYTES:"number",BITS:"number"}))}(t),t}return Be(e)}
8
8
  /*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */
9
- function Ye(e){void 0!==e.lowS&&se("lowS",e.lowS),void 0!==e.prehash&&se("prehash",e.prehash)}class Qe extends Error{constructor(e=""){super(e)}}const Xe={Err:Qe,_tlv:{encode:(e,t)=>{const{Err:n}=Xe;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=oe(r);if(i.length/2&128)throw new n("tlv.encode: long form length too big");const s=r>127?oe(i.length/2|128):"";return oe(e)+s+i+t},decode(e,t){const{Err:n}=Xe;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 s=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 o=t.subarray(r,r+e);if(o.length!==e)throw new n("tlv.decode: length bytes not complete");if(0===o[0])throw new n("tlv.decode(long): zero leftmost byte");for(const e of o)s=s<<8|e;if(r+=e,s<128)throw new n("tlv.decode(long): not minimal encoding")}else s=i;const o=t.subarray(r,r+s);if(o.length!==s)throw new n("tlv.decode: wrong value length");return{v:o,l:t.subarray(r+s)}}},_int:{encode(e){const{Err:t}=Xe;if(e<Je)throw new t("integer: negative integers are not allowed");let n=oe(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}=Xe;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 ue(e)}},toSig(e){const{Err:t,_int:n,_tlv:r}=Xe,i=he("signature",e),{v:s,l:o}=r.decode(48,i);if(o.length)throw new t("invalid signature: left bytes after parsing");const{v:a,l:u}=r.decode(2,s),{v:c,l:d}=r.decode(2,u);if(d.length)throw new t("invalid signature: left bytes after parsing");return{r:n.decode(a),s:n.decode(c)}},hexFromSig(e){const{_tlv:t,_int:n}=Xe,r=t.encode(2,n.encode(e.r))+t.encode(2,n.encode(e.s));return t.encode(48,r)}},Je=BigInt(0),et=BigInt(1),tt=BigInt(2),nt=BigInt(3),rt=BigInt(4);function it(e,t,n){const{BYTES:r}=e;return function(i){let s;if("bigint"==typeof i)s=i;else{let n=he("private key",i);if(t){if(!t.includes(2*n.length))throw new Error("invalid private key");const e=new Uint8Array(r);e.set(n,e.length-n.length),n=e}try{s=e.fromBytes(n)}catch(e){throw new Error(`invalid private key: expected ui8a of size ${r}, got ${typeof i}`)}}if(n&&(s=e.create(s)),!e.isValidNot0(s))throw new Error("invalid private key: out of range [1..N-1]");return s}}function st(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>ze))throw new Error(`CURVE.${e} must be positive bigint`)}const r=Ge(t.p,n.Fp),i=Ge(t.n,n.Fn),s=["Gx","Gy","a","b"];for(const e of s)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:s}=e;ye(t,{},{allowInfinityPoint:"boolean",clearCofactor:"function",isTorsionFree:"function",fromBytes:"function",toBytes:"function",endo:"object",wrapPrivateKey:"boolean"});const{endo:o}=t;if(o&&(!n.is0(e.a)||"bigint"!=typeof o.beta||"function"!=typeof o.splitScalar))throw new Error('invalid endo: expected "beta": bigint and "splitScalar": function');function a(){if(!n.isOdd)throw new Error("compression is not supported: Field does not have .isOdd()")}const u=t.toBytes||function(e,t,r){const{x:i,y:s}=t.toAffine(),o=n.toBytes(i);if(se("isCompressed",r),r){a();return V(ot(!n.isOdd(s)),o)}return V(Uint8Array.of(4),o,n.toBytes(s))},c=t.fromBytes||function(e){k(e);const t=n.BYTES,r=t+1,i=2*t+1,s=e.length,o=e[0],u=e.subarray(1);if(s!==r||2!==o&&3!==o){if(s===i&&4===o){const e=n.fromBytes(u.subarray(0*t,1*t)),r=n.fromBytes(u.subarray(1*t,2*t));if(!f(e,r))throw new Error("bad point: is not on curve");return{x:e,y:r}}throw new Error(`bad point: got length ${s}, expected compressed=${r} or uncompressed=${i}`)}{const e=n.fromBytes(u);if(!n.isValid(e))throw new Error("bad point: is not on curve, wrong x");const t=d(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)}a();return!(1&~o)!==n.isOdd(r)&&(r=n.neg(r)),{x:e,y:r}}},d=function(e,t,n){return function(r){const i=e.sqr(r),s=e.mul(i,r);return e.add(e.add(s,e.mul(r,t)),n)}}(n,e.a,e.b);function f(e,t){const r=n.sqr(t),i=d(e);return n.eql(r,i)}if(!f(e.Gx,e.Gy))throw new Error("bad curve params: generator point");const h=n.mul(n.pow(e.a,nt),rt),l=n.mul(n.sqr(e.b),BigInt(27));if(n.is0(n.add(h,l)))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 g(e){if(!(e instanceof v))throw new Error("ProjectivePoint expected")}const m=we((e,t)=>{const{px:r,py:i,pz:s}=e;if(n.eql(s,n.ONE))return{x:r,y:i};const o=e.is0();null==t&&(t=o?n.ONE:n.inv(s));const a=n.mul(r,t),u=n.mul(i,t),c=n.mul(s,t);if(o)return{x:n.ZERO,y:n.ZERO};if(!n.eql(c,n.ONE))throw new Error("invZ was invalid");return{x:a,y:u}}),y=we(e=>{if(e.is0()){if(t.allowInfinityPoint&&!n.is0(e.py))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(!f(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 w(e,t,r,i,s){return r=new v(n.mul(r.px,e),r.py,r.pz),t=He(i,t),r=He(s,r),t.add(r)}class v{constructor(e,t,n){this.px=p("x",e),this.py=p("y",t,!0),this.pz=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}static normalizeZ(e){return function(e,t,n){const r=Ue(e.Fp,n.map(e=>e.pz));return n.map((e,t)=>e.toAffine(r[t])).map(e.fromAffine)}(v,0,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){const n=it(r,t.allowedPrivateKeyLengths,t.wrapPrivateKey);return v.BASE.multiply(n(e))}static msm(e,t){return qe(v,r,e,t)}precompute(e=8,t=!0){return b.setWindowSize(this,e),t||this.multiply(nt),this}_setWindowSize(e){this.precompute(e)}assertValidity(){y(this)}hasEvenY(){const{y:e}=this.toAffine();if(!n.isOdd)throw new Error("Field doesn't support isOdd");return!n.isOdd(e)}equals(e){g(e);const{px:t,py:r,pz:i}=this,{px:s,py:o,pz:a}=e,u=n.eql(n.mul(t,a),n.mul(s,i)),c=n.eql(n.mul(r,a),n.mul(o,i));return u&&c}negate(){return new v(this.px,n.neg(this.py),this.pz)}double(){const{a:t,b:r}=e,i=n.mul(r,nt),{px:s,py:o,pz:a}=this;let u=n.ZERO,c=n.ZERO,d=n.ZERO,f=n.mul(s,s),h=n.mul(o,o),l=n.mul(a,a),p=n.mul(s,o);return p=n.add(p,p),d=n.mul(s,a),d=n.add(d,d),u=n.mul(t,d),c=n.mul(i,l),c=n.add(u,c),u=n.sub(h,c),c=n.add(h,c),c=n.mul(u,c),u=n.mul(p,u),d=n.mul(i,d),l=n.mul(t,l),p=n.sub(f,l),p=n.mul(t,p),p=n.add(p,d),d=n.add(f,f),f=n.add(d,f),f=n.add(f,l),f=n.mul(f,p),c=n.add(c,f),l=n.mul(o,a),l=n.add(l,l),f=n.mul(l,p),u=n.sub(u,f),d=n.mul(l,h),d=n.add(d,d),d=n.add(d,d),new v(u,c,d)}add(t){g(t);const{px:r,py:i,pz:s}=this,{px:o,py:a,pz:u}=t;let c=n.ZERO,d=n.ZERO,f=n.ZERO;const h=e.a,l=n.mul(e.b,nt);let p=n.mul(r,o),m=n.mul(i,a),y=n.mul(s,u),w=n.add(r,i),_=n.add(o,a);w=n.mul(w,_),_=n.add(p,m),w=n.sub(w,_),_=n.add(r,s);let b=n.add(o,u);return _=n.mul(_,b),b=n.add(p,y),_=n.sub(_,b),b=n.add(i,s),c=n.add(a,u),b=n.mul(b,c),c=n.add(m,y),b=n.sub(b,c),f=n.mul(h,_),c=n.mul(l,y),f=n.add(c,f),c=n.sub(m,f),f=n.add(m,f),d=n.mul(c,f),m=n.add(p,p),m=n.add(m,p),y=n.mul(h,y),_=n.mul(l,_),m=n.add(m,y),y=n.sub(p,y),y=n.mul(h,y),_=n.add(_,y),p=n.mul(m,_),d=n.add(d,p),p=n.mul(b,_),c=n.mul(w,c),c=n.sub(c,p),p=n.mul(w,m),f=n.mul(b,f),f=n.add(f,p),new v(c,d,f)}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,s;const o=e=>b.wNAFCached(this,e,v.normalizeZ);if(n){const{k1neg:t,k1:r,k2neg:a,k2:u}=n.splitScalar(e),{p:c,f:d}=o(r),{p:f,f:h}=o(u);s=d.add(h),i=w(n.beta,c,f,t,a)}else{const{p:t,f:n}=o(e);i=t,s=n}return v.normalizeZ([i,s])[0]}multiplyUnsafe(e){const{endo:n}=t,i=this;if(!r.isValid(e))throw new Error("invalid scalar: out of range");if(e===Je||i.is0())return v.ZERO;if(e===et)return i;if(b.hasPrecomputes(this))return this.multiply(e);if(n){const{k1neg:t,k1:r,k2neg:s,k2:o}=n.splitScalar(e),{p1:a,p2:u}=function(e,t,n,r){let i=t,s=e.ZERO,o=e.ZERO;for(;n>ze||r>ze;)n&je&&(s=s.add(i)),r&je&&(o=o.add(i)),i=i.double(),n>>=je,r>>=je;return{p1:s,p2:o}}(v,i,r,o);return w(n.beta,a,u,t,s)}return b.wNAFCachedUnsafe(i,e)}multiplyAndAddUnsafe(e,t,n){const r=this.multiplyUnsafe(t).add(e.multiplyUnsafe(n));return r.is0()?void 0:r}toAffine(e){return m(this,e)}isTorsionFree(){const{isTorsionFree:e}=t;return i===et||(e?e(v,this):b.wNAFCachedUnsafe(this,s).is0())}clearCofactor(){const{clearCofactor:e}=t;return i===et?this:e?e(v,this):this.multiplyUnsafe(i)}toBytes(e=!0){return se("isCompressed",e),this.assertValidity(),u(v,this,e)}toRawBytes(e=!0){return this.toBytes(e)}toHex(e=!0){return U(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 _=r.BITS,b=function(e,t){return{constTimeNegate:He,hasPrecomputes:e=>1!==We(e),unsafeLadder(t,n,r=e.ZERO){let i=t;for(;n>ze;)n&je&&(r=r.add(i)),i=i.double(),n>>=je;return r},precomputeWindow(e,n){const{windows:r,windowSize:i}=Fe(n,t),s=[];let o=e,a=o;for(let e=0;e<r;e++){a=o,s.push(a);for(let e=1;e<i;e++)a=a.add(o),s.push(a);o=a.double()}return s},wNAF(n,r,i){let s=e.ZERO,o=e.BASE;const a=Fe(n,t);for(let e=0;e<a.windows;e++){const{nextN:t,offset:n,isZero:u,isNeg:c,isNegF:d,offsetF:f}=Ve(i,e,a);i=t,u?o=o.add(He(d,r[f])):s=s.add(He(c,r[n]))}return Me(i),{p:s,f:o}},wNAFUnsafe(n,r,i,s=e.ZERO){const o=Fe(n,t);for(let e=0;e<o.windows&&i!==ze;e++){const{nextN:t,offset:n,isZero:a,isNeg:u}=Ve(i,e,o);if(i=t,!a){const e=r[n];s=s.add(u?e.negate():e)}}return Me(i),s},getPrecomputes(e,t,n){let r=Ze.get(t);return r||(r=this.precomputeWindow(t,e),1!==e&&("function"==typeof n&&(r=n(r)),Ze.set(t,r))),r},wNAFCached(e,t,n){const r=We(e);return this.wNAF(r,this.getPrecomputes(r,e,n),t)},wNAFCachedUnsafe(e,t,n,r){const i=We(e);return 1===i?this.unsafeLadder(e,t,r):this.wNAFUnsafe(i,this.getPrecomputes(i,e,n),t,r)},setWindowSize(e,n){De(n,t),Ke.set(e,n),Ze.delete(e)}}}(v,t.endo?Math.ceil(_/2):_);return v}function ot(e){return Uint8Array.of(e?2:3)}function at(e,t,n={}){ye(t,{hash:"function"},{hmac:"function",lowS:"boolean",randomBytes:"function",bits2int:"function",bits2int_modN:"function"});const r=t.randomBytes||W,i=t.hmac||((e,...n)=>ne(t.hash,e,V(...n))),{Fp:s,Fn:o}=e,{ORDER:a,BITS:u}=o;function c(e){return e>a>>et}function d(e,t){if(!o.isValidNot0(t))throw new Error(`invalid signature ${e}: out of range 1..CURVE.n`)}class f{constructor(e,t,n){d("r",e),d("s",t),this.r=e,this.s=t,null!=n&&(this.recovery=n),Object.freeze(this)}static fromCompact(e){const t=o.BYTES,n=he("compactSignature",e,2*t);return new f(o.fromBytes(n.subarray(0,t)),o.fromBytes(n.subarray(t,2*t)))}static fromDER(e){const{r:t,s:n}=Xe.toSig(he("DER",e));return new f(t,n)}assertValidity(){}addRecoveryBit(e){return new f(this.r,this.s,e)}recoverPublicKey(t){const n=s.ORDER,{r:r,s:i,recovery:u}=this;if(null==u||![0,1,2,3].includes(u))throw new Error("recovery id invalid");if(a*tt<n&&u>1)throw new Error("recovery id is ambiguous for h>1 curve");const c=2===u||3===u?r+a:r;if(!s.isValid(c))throw new Error("recovery id 2 or 3 invalid");const d=s.toBytes(c),f=e.fromHex(V(ot(!(1&u)),d)),h=o.inv(c),l=m(he("msgHash",t)),p=o.create(-l*h),g=o.create(i*h),y=e.BASE.multiplyUnsafe(p).add(f.multiplyUnsafe(g));if(y.is0())throw new Error("point at infinify");return y.assertValidity(),y}hasHighS(){return c(this.s)}normalizeS(){return this.hasHighS()?new f(this.r,o.neg(this.s),this.recovery):this}toBytes(e){if("compact"===e)return V(o.toBytes(this.r),o.toBytes(this.s));if("der"===e)return D(Xe.hexFromSig(this));throw new Error("invalid format")}toDERRawBytes(){return this.toBytes("der")}toDERHex(){return U(this.toBytes("der"))}toCompactRawBytes(){return this.toBytes("compact")}toCompactHex(){return U(this.toBytes("compact"))}}const h=it(o,n.allowedPrivateKeyLengths,n.wrapPrivateKey),l={isValidPrivateKey(e){try{return h(e),!0}catch(e){return!1}},normPrivateKeyToScalar:h,randomPrivateKey:()=>{const e=a;return function(e,t,n=!1){const r=e.length,i=Re(t),s=Le(t);if(r<16||r<s||r>1024)throw new Error("expected "+s+"-1024 bytes of input, got "+r);const o=Oe(n?ce(e):ue(e),t-_e)+_e;return n?fe(o,i):de(o,i)}(r(Le(e)),e)},precompute:(t=8,n=e.BASE)=>n.precompute(t,!1)};function p(t){if("bigint"==typeof t)return!1;if(t instanceof e)return!0;const r=he("key",t).length,i=s.BYTES,a=i+1,u=2*i+1;return n.allowedPrivateKeyLengths||o.BYTES===a?void 0:r===a||r===u}const g=t.bits2int||function(e){if(e.length>8192)throw new Error("input is too large");const t=ue(e),n=8*e.length-u;return n>0?t>>BigInt(n):t},m=t.bits2int_modN||function(e){return o.create(g(e))},y=me(u);function w(e){return ge("num < 2^"+u,e,Je,y),o.toBytes(e)}function v(n,i,a=_){if(["recovered","canonical"].some(e=>e in a))throw new Error("sign() legacy options not supported");const{hash:u}=t;let{lowS:d,prehash:l,extraEntropy:p}=a;null==d&&(d=!0),n=he("msgHash",n),Ye(a),l&&(n=he("prehashed msgHash",u(n)));const y=m(n),v=h(i),b=[w(v),w(y)];if(null!=p&&!1!==p){const e=!0===p?r(s.BYTES):p;b.push(he("extraEntropy",e))}const E=V(...b),x=y;return{seed:E,k2sig:function(t){const n=g(t);if(!o.isValidNot0(n))return;const r=o.inv(n),i=e.BASE.multiply(n).toAffine(),s=o.create(i.x);if(s===Je)return;const a=o.create(r*o.create(x+s*v));if(a===Je)return;let u=(i.x===s?0:2)|Number(i.y&et),h=a;return d&&c(a)&&(h=function(e){return c(e)?o.neg(e):e}(a),u^=1),new f(s,h,u)}}}const _={lowS:t.lowS,prehash:!1},b={lowS:t.lowS,prehash:!1};return e.BASE.precompute(8),Object.freeze({getPublicKey:function(t,n=!0){return e.fromPrivateKey(t).toBytes(n)},getSharedSecret:function(t,n,r=!0){if(!0===p(t))throw new Error("first arg must be private key");if(!1===p(n))throw new Error("second arg must be public key");return e.fromHex(n).multiply(h(t)).toBytes(r)},sign:function(e,n,r=_){const{seed:s,k2sig:a}=v(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 s=r(e),o=r(e),a=0;const u=()=>{s.fill(1),o.fill(0),a=0},c=(...e)=>n(o,s,...e),d=(e=r(0))=>{o=c(i(0),e),s=c(),0!==e.length&&(o=c(i(1),e),s=c())},f=()=>{if(a++>=1e3)throw new Error("drbg: tried 1000 values");let e=0;const n=[];for(;e<t;){s=c();const t=s.slice();n.push(t),e+=s.length}return V(...n)};return(e,t)=>{let n;for(u(),d(e);!(n=t(f()));)d();return u(),n}}(t.hash.outputLen,o.BYTES,i)(s,a)},verify:function(n,r,i,s=b){const a=n;r=he("msgHash",r),i=he("publicKey",i),Ye(s);const{lowS:u,prehash:c,format:d}=s;if("strict"in s)throw new Error("options.strict was renamed to lowS");if(void 0!==d&&!["compact","der","js"].includes(d))throw new Error('format must be "compact", "der" or "js"');const h="string"==typeof a||x(a),l=!h&&!d&&"object"==typeof a&&null!==a&&"bigint"==typeof a.r&&"bigint"==typeof a.s;if(!h&&!l)throw new Error("invalid signature, expected Uint8Array, hex string or Signature instance");let p,g;try{if(l){if(void 0!==d&&"js"!==d)throw new Error("invalid format");p=new f(a.r,a.s)}if(h){try{"compact"!==d&&(p=f.fromDER(a))}catch(e){if(!(e instanceof Xe.Err))throw e}p||"der"===d||(p=f.fromCompact(a))}g=e.fromHex(i)}catch(e){return!1}if(!p)return!1;if(u&&p.hasHighS())return!1;c&&(r=t.hash(r));const{r:y,s:w}=p,v=m(r),_=o.inv(w),E=o.create(v*_),S=o.create(y*_),k=e.BASE.multiplyUnsafe(E).add(g.multiplyUnsafe(S));return!k.is0()&&o.create(k.x)===y},utils:l,Point:e,Signature:f})}function ut(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};return{CURVE:t,curveOpts:{Fp:e.Fp,Fn:Be(t.n,e.nBitLength),allowedPrivateKeyLengths:e.allowedPrivateKeyLengths,allowInfinityPoint:e.allowInfinityPoint,endo:e.endo,wrapPrivateKey:e.wrapPrivateKey,isTorsionFree:e.isTorsionFree,clearCofactor:e.clearCofactor,fromBytes:e.fromBytes,toBytes:e.toBytes}}}(e);return{CURVE:t,curveOpts:n,ecdsaOpts:{hash:e.hash,hmac:e.hmac,randomBytes:e.randomBytes,lowS:e.lowS,bits2int:e.bits2int,bits2int_modN:e.bits2int_modN}}}function ct(e){const{CURVE:t,curveOpts:n,ecdsaOpts:r}=ut(e);return function(e,t){return Object.assign({},t,{ProjectivePoint:t.Point,CURVE:e})}(e,at(st(t,n),r,n))}
9
+ function Ye(e){void 0!==e.lowS&&se("lowS",e.lowS),void 0!==e.prehash&&se("prehash",e.prehash)}class Qe extends Error{constructor(e=""){super(e)}}const Xe={Err:Qe,_tlv:{encode:(e,t)=>{const{Err:n}=Xe;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=oe(r);if(i.length/2&128)throw new n("tlv.encode: long form length too big");const s=r>127?oe(i.length/2|128):"";return oe(e)+s+i+t},decode(e,t){const{Err:n}=Xe;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 s=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 o=t.subarray(r,r+e);if(o.length!==e)throw new n("tlv.decode: length bytes not complete");if(0===o[0])throw new n("tlv.decode(long): zero leftmost byte");for(const e of o)s=s<<8|e;if(r+=e,s<128)throw new n("tlv.decode(long): not minimal encoding")}else s=i;const o=t.subarray(r,r+s);if(o.length!==s)throw new n("tlv.decode: wrong value length");return{v:o,l:t.subarray(r+s)}}},_int:{encode(e){const{Err:t}=Xe;if(e<Je)throw new t("integer: negative integers are not allowed");let n=oe(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}=Xe;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 ue(e)}},toSig(e){const{Err:t,_int:n,_tlv:r}=Xe,i=le("signature",e),{v:s,l:o}=r.decode(48,i);if(o.length)throw new t("invalid signature: left bytes after parsing");const{v:a,l:u}=r.decode(2,s),{v:c,l:d}=r.decode(2,u);if(d.length)throw new t("invalid signature: left bytes after parsing");return{r:n.decode(a),s:n.decode(c)}},hexFromSig(e){const{_tlv:t,_int:n}=Xe,r=t.encode(2,n.encode(e.r))+t.encode(2,n.encode(e.s));return t.encode(48,r)}},Je=BigInt(0),et=BigInt(1),tt=BigInt(2),nt=BigInt(3),rt=BigInt(4);function it(e,t,n){const{BYTES:r}=e;return function(i){let s;if("bigint"==typeof i)s=i;else{let n=le("private key",i);if(t){if(!t.includes(2*n.length))throw new Error("invalid private key");const e=new Uint8Array(r);e.set(n,e.length-n.length),n=e}try{s=e.fromBytes(n)}catch(e){throw new Error(`invalid private key: expected ui8a of size ${r}, got ${typeof i}`)}}if(n&&(s=e.create(s)),!e.isValidNot0(s))throw new Error("invalid private key: out of range [1..N-1]");return s}}function st(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>Ze))throw new Error(`CURVE.${e} must be positive bigint`)}const r=Ge(t.p,n.Fp),i=Ge(t.n,n.Fn),s=["Gx","Gy","a","b"];for(const e of s)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:s}=e;ye(t,{},{allowInfinityPoint:"boolean",clearCofactor:"function",isTorsionFree:"function",fromBytes:"function",toBytes:"function",endo:"object",wrapPrivateKey:"boolean"});const{endo:o}=t;if(o&&(!n.is0(e.a)||"bigint"!=typeof o.beta||"function"!=typeof o.splitScalar))throw new Error('invalid endo: expected "beta": bigint and "splitScalar": function');function a(){if(!n.isOdd)throw new Error("compression is not supported: Field does not have .isOdd()")}const u=t.toBytes||function(e,t,r){const{x:i,y:s}=t.toAffine(),o=n.toBytes(i);if(se("isCompressed",r),r){a();return H(ot(!n.isOdd(s)),o)}return H(Uint8Array.of(4),o,n.toBytes(s))},c=t.fromBytes||function(e){O(e);const t=n.BYTES,r=t+1,i=2*t+1,s=e.length,o=e[0],u=e.subarray(1);if(s!==r||2!==o&&3!==o){if(s===i&&4===o){const e=n.fromBytes(u.subarray(0*t,1*t)),r=n.fromBytes(u.subarray(1*t,2*t));if(!f(e,r))throw new Error("bad point: is not on curve");return{x:e,y:r}}throw new Error(`bad point: got length ${s}, expected compressed=${r} or uncompressed=${i}`)}{const e=n.fromBytes(u);if(!n.isValid(e))throw new Error("bad point: is not on curve, wrong x");const t=d(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)}a();return!(1&~o)!==n.isOdd(r)&&(r=n.neg(r)),{x:e,y:r}}},d=function(e,t,n){return function(r){const i=e.sqr(r),s=e.mul(i,r);return e.add(e.add(s,e.mul(r,t)),n)}}(n,e.a,e.b);function f(e,t){const r=n.sqr(t),i=d(e);return n.eql(r,i)}if(!f(e.Gx,e.Gy))throw new Error("bad curve params: generator point");const l=n.mul(n.pow(e.a,nt),rt),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")}const g=_e((e,t)=>{const{px:r,py:i,pz:s}=e;if(n.eql(s,n.ONE))return{x:r,y:i};const o=e.is0();null==t&&(t=o?n.ONE:n.inv(s));const a=n.mul(r,t),u=n.mul(i,t),c=n.mul(s,t);if(o)return{x:n.ZERO,y:n.ZERO};if(!n.eql(c,n.ONE))throw new Error("invZ was invalid");return{x:a,y:u}}),y=_e(e=>{if(e.is0()){if(t.allowInfinityPoint&&!n.is0(e.py))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(!f(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 _(e,t,r,i,s){return r=new v(n.mul(r.px,e),r.py,r.pz),t=Le(i,t),r=Le(s,r),t.add(r)}class v{constructor(e,t,n){this.px=p("x",e),this.py=p("y",t,!0),this.pz=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}static normalizeZ(e){return function(e,t,n){const r=$e(e.Fp,n.map(e=>e.pz));return n.map((e,t)=>e.toAffine(r[t])).map(e.fromAffine)}(v,0,e)}static fromBytes(e){return O(e),v.fromHex(e)}static fromHex(e){const t=v.fromAffine(c(le("pointHex",e)));return t.assertValidity(),t}static fromPrivateKey(e){const n=it(r,t.allowedPrivateKeyLengths,t.wrapPrivateKey);return v.BASE.multiply(n(e))}static msm(e,t){return We(v,r,e,t)}precompute(e=8,t=!0){return b.setWindowSize(this,e),t||this.multiply(nt),this}_setWindowSize(e){this.precompute(e)}assertValidity(){y(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{px:t,py:r,pz:i}=this,{px:s,py:o,pz:a}=e,u=n.eql(n.mul(t,a),n.mul(s,i)),c=n.eql(n.mul(r,a),n.mul(o,i));return u&&c}negate(){return new v(this.px,n.neg(this.py),this.pz)}double(){const{a:t,b:r}=e,i=n.mul(r,nt),{px:s,py:o,pz:a}=this;let u=n.ZERO,c=n.ZERO,d=n.ZERO,f=n.mul(s,s),l=n.mul(o,o),h=n.mul(a,a),p=n.mul(s,o);return p=n.add(p,p),d=n.mul(s,a),d=n.add(d,d),u=n.mul(t,d),c=n.mul(i,h),c=n.add(u,c),u=n.sub(l,c),c=n.add(l,c),c=n.mul(u,c),u=n.mul(p,u),d=n.mul(i,d),h=n.mul(t,h),p=n.sub(f,h),p=n.mul(t,p),p=n.add(p,d),d=n.add(f,f),f=n.add(d,f),f=n.add(f,h),f=n.mul(f,p),c=n.add(c,f),h=n.mul(o,a),h=n.add(h,h),f=n.mul(h,p),u=n.sub(u,f),d=n.mul(h,l),d=n.add(d,d),d=n.add(d,d),new v(u,c,d)}add(t){m(t);const{px:r,py:i,pz:s}=this,{px:o,py:a,pz:u}=t;let c=n.ZERO,d=n.ZERO,f=n.ZERO;const l=e.a,h=n.mul(e.b,nt);let p=n.mul(r,o),g=n.mul(i,a),y=n.mul(s,u),_=n.add(r,i),w=n.add(o,a);_=n.mul(_,w),w=n.add(p,g),_=n.sub(_,w),w=n.add(r,s);let b=n.add(o,u);return w=n.mul(w,b),b=n.add(p,y),w=n.sub(w,b),b=n.add(i,s),c=n.add(a,u),b=n.mul(b,c),c=n.add(g,y),b=n.sub(b,c),f=n.mul(l,w),c=n.mul(h,y),f=n.add(c,f),c=n.sub(g,f),f=n.add(g,f),d=n.mul(c,f),g=n.add(p,p),g=n.add(g,p),y=n.mul(l,y),w=n.mul(h,w),g=n.add(g,y),y=n.sub(p,y),y=n.mul(l,y),w=n.add(w,y),p=n.mul(g,w),d=n.add(d,p),p=n.mul(b,w),c=n.mul(_,c),c=n.sub(c,p),p=n.mul(_,g),f=n.mul(b,f),f=n.add(f,p),new v(c,d,f)}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,s;const o=e=>b.wNAFCached(this,e,v.normalizeZ);if(n){const{k1neg:t,k1:r,k2neg:a,k2:u}=n.splitScalar(e),{p:c,f:d}=o(r),{p:f,f:l}=o(u);s=d.add(l),i=_(n.beta,c,f,t,a)}else{const{p:t,f:n}=o(e);i=t,s=n}return v.normalizeZ([i,s])[0]}multiplyUnsafe(e){const{endo:n}=t,i=this;if(!r.isValid(e))throw new Error("invalid scalar: out of range");if(e===Je||i.is0())return v.ZERO;if(e===et)return i;if(b.hasPrecomputes(this))return this.multiply(e);if(n){const{k1neg:t,k1:r,k2neg:s,k2:o}=n.splitScalar(e),{p1:a,p2:u}=function(e,t,n,r){let i=t,s=e.ZERO,o=e.ZERO;for(;n>Ze||r>Ze;)n&ze&&(s=s.add(i)),r&ze&&(o=o.add(i)),i=i.double(),n>>=ze,r>>=ze;return{p1:s,p2:o}}(v,i,r,o);return _(n.beta,a,u,t,s)}return b.wNAFCachedUnsafe(i,e)}multiplyAndAddUnsafe(e,t,n){const r=this.multiplyUnsafe(t).add(e.multiplyUnsafe(n));return r.is0()?void 0:r}toAffine(e){return g(this,e)}isTorsionFree(){const{isTorsionFree:e}=t;return i===et||(e?e(v,this):b.wNAFCachedUnsafe(this,s).is0())}clearCofactor(){const{clearCofactor:e}=t;return i===et?this:e?e(v,this):this.multiplyUnsafe(i)}toBytes(e=!0){return se("isCompressed",e),this.assertValidity(),u(v,this,e)}toRawBytes(e=!0){return this.toBytes(e)}toHex(e=!0){return $(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 w=r.BITS,b=function(e,t){return{constTimeNegate:Le,hasPrecomputes:e=>1!==Me(e),unsafeLadder(t,n,r=e.ZERO){let i=t;for(;n>Ze;)n&ze&&(r=r.add(i)),i=i.double(),n>>=ze;return r},precomputeWindow(e,n){const{windows:r,windowSize:i}=De(n,t),s=[];let o=e,a=o;for(let e=0;e<r;e++){a=o,s.push(a);for(let e=1;e<i;e++)a=a.add(o),s.push(a);o=a.double()}return s},wNAF(n,r,i){let s=e.ZERO,o=e.BASE;const a=De(n,t);for(let e=0;e<a.windows;e++){const{nextN:t,offset:n,isZero:u,isNeg:c,isNegF:d,offsetF:f}=He(i,e,a);i=t,u?o=o.add(Le(d,r[f])):s=s.add(Le(c,r[n]))}return Ke(i),{p:s,f:o}},wNAFUnsafe(n,r,i,s=e.ZERO){const o=De(n,t);for(let e=0;e<o.windows&&i!==Ze;e++){const{nextN:t,offset:n,isZero:a,isNeg:u}=He(i,e,o);if(i=t,!a){const e=r[n];s=s.add(u?e.negate():e)}}return Ke(i),s},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},wNAFCached(e,t,n){const r=Me(e);return this.wNAF(r,this.getPrecomputes(r,e,n),t)},wNAFCachedUnsafe(e,t,n,r){const i=Me(e);return 1===i?this.unsafeLadder(e,t,r):this.wNAFUnsafe(i,this.getPrecomputes(i,e,n),t,r)},setWindowSize(e,n){Fe(n,t),Ve.set(e,n),qe.delete(e)}}}(v,t.endo?Math.ceil(w/2):w);return v}function ot(e){return Uint8Array.of(e?2:3)}function at(e,t,n={}){ye(t,{hash:"function"},{hmac:"function",lowS:"boolean",randomBytes:"function",bits2int:"function",bits2int_modN:"function"});const r=t.randomBytes||M,i=t.hmac||((e,...n)=>ne(t.hash,e,H(...n))),{Fp:s,Fn:o}=e,{ORDER:a,BITS:u}=o;function c(e){return e>a>>et}function d(e,t){if(!o.isValidNot0(t))throw new Error(`invalid signature ${e}: out of range 1..CURVE.n`)}class f{constructor(e,t,n){d("r",e),d("s",t),this.r=e,this.s=t,null!=n&&(this.recovery=n),Object.freeze(this)}static fromCompact(e){const t=o.BYTES,n=le("compactSignature",e,2*t);return new f(o.fromBytes(n.subarray(0,t)),o.fromBytes(n.subarray(t,2*t)))}static fromDER(e){const{r:t,s:n}=Xe.toSig(le("DER",e));return new f(t,n)}assertValidity(){}addRecoveryBit(e){return new f(this.r,this.s,e)}recoverPublicKey(t){const n=s.ORDER,{r:r,s:i,recovery:u}=this;if(null==u||![0,1,2,3].includes(u))throw new Error("recovery id invalid");if(a*tt<n&&u>1)throw new Error("recovery id is ambiguous for h>1 curve");const c=2===u||3===u?r+a:r;if(!s.isValid(c))throw new Error("recovery id 2 or 3 invalid");const d=s.toBytes(c),f=e.fromHex(H(ot(!(1&u)),d)),l=o.inv(c),h=g(le("msgHash",t)),p=o.create(-h*l),m=o.create(i*l),y=e.BASE.multiplyUnsafe(p).add(f.multiplyUnsafe(m));if(y.is0())throw new Error("point at infinify");return y.assertValidity(),y}hasHighS(){return c(this.s)}normalizeS(){return this.hasHighS()?new f(this.r,o.neg(this.s),this.recovery):this}toBytes(e){if("compact"===e)return H(o.toBytes(this.r),o.toBytes(this.s));if("der"===e)return F(Xe.hexFromSig(this));throw new Error("invalid format")}toDERRawBytes(){return this.toBytes("der")}toDERHex(){return $(this.toBytes("der"))}toCompactRawBytes(){return this.toBytes("compact")}toCompactHex(){return $(this.toBytes("compact"))}}const l=it(o,n.allowedPrivateKeyLengths,n.wrapPrivateKey),h={isValidPrivateKey(e){try{return l(e),!0}catch(e){return!1}},normPrivateKeyToScalar:l,randomPrivateKey:()=>{const e=a;return function(e,t,n=!1){const r=e.length,i=Ue(t),s=je(t);if(r<16||r<s||r>1024)throw new Error("expected "+s+"-1024 bytes of input, got "+r);const o=Se(n?ce(e):ue(e),t-we)+we;return n?fe(o,i):de(o,i)}(r(je(e)),e)},precompute:(t=8,n=e.BASE)=>n.precompute(t,!1)};function p(t){if("bigint"==typeof t)return!1;if(t instanceof e)return!0;const r=le("key",t).length,i=s.BYTES,a=i+1,u=2*i+1;return n.allowedPrivateKeyLengths||o.BYTES===a?void 0:r===a||r===u}const m=t.bits2int||function(e){if(e.length>8192)throw new Error("input is too large");const t=ue(e),n=8*e.length-u;return n>0?t>>BigInt(n):t},g=t.bits2int_modN||function(e){return o.create(m(e))},y=ge(u);function _(e){return me("num < 2^"+u,e,Je,y),o.toBytes(e)}function v(n,i,a=w){if(["recovered","canonical"].some(e=>e in a))throw new Error("sign() legacy options not supported");const{hash:u}=t;let{lowS:d,prehash:h,extraEntropy:p}=a;null==d&&(d=!0),n=le("msgHash",n),Ye(a),h&&(n=le("prehashed msgHash",u(n)));const y=g(n),v=l(i),b=[_(v),_(y)];if(null!=p&&!1!==p){const e=!0===p?r(s.BYTES):p;b.push(le("extraEntropy",e))}const x=H(...b),E=y;return{seed:x,k2sig:function(t){const n=m(t);if(!o.isValidNot0(n))return;const r=o.inv(n),i=e.BASE.multiply(n).toAffine(),s=o.create(i.x);if(s===Je)return;const a=o.create(r*o.create(E+s*v));if(a===Je)return;let u=(i.x===s?0:2)|Number(i.y&et),l=a;return d&&c(a)&&(l=function(e){return c(e)?o.neg(e):e}(a),u^=1),new f(s,l,u)}}}const w={lowS:t.lowS,prehash:!1},b={lowS:t.lowS,prehash:!1};return e.BASE.precompute(8),Object.freeze({getPublicKey:function(t,n=!0){return e.fromPrivateKey(t).toBytes(n)},getSharedSecret:function(t,n,r=!0){if(!0===p(t))throw new Error("first arg must be private key");if(!1===p(n))throw new Error("second arg must be public key");return e.fromHex(n).multiply(l(t)).toBytes(r)},sign:function(e,n,r=w){const{seed:s,k2sig:a}=v(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 s=r(e),o=r(e),a=0;const u=()=>{s.fill(1),o.fill(0),a=0},c=(...e)=>n(o,s,...e),d=(e=r(0))=>{o=c(i(0),e),s=c(),0!==e.length&&(o=c(i(1),e),s=c())},f=()=>{if(a++>=1e3)throw new Error("drbg: tried 1000 values");let e=0;const n=[];for(;e<t;){s=c();const t=s.slice();n.push(t),e+=s.length}return H(...n)};return(e,t)=>{let n;for(u(),d(e);!(n=t(f()));)d();return u(),n}}(t.hash.outputLen,o.BYTES,i)(s,a)},verify:function(n,r,i,s=b){const a=n;r=le("msgHash",r),i=le("publicKey",i),Ye(s);const{lowS:u,prehash:c,format:d}=s;if("strict"in s)throw new Error("options.strict was renamed to lowS");if(void 0!==d&&!["compact","der","js"].includes(d))throw new Error('format must be "compact", "der" or "js"');const l="string"==typeof a||E(a),h=!l&&!d&&"object"==typeof a&&null!==a&&"bigint"==typeof a.r&&"bigint"==typeof a.s;if(!l&&!h)throw new Error("invalid signature, expected Uint8Array, hex string or Signature instance");let p,m;try{if(h){if(void 0!==d&&"js"!==d)throw new Error("invalid format");p=new f(a.r,a.s)}if(l){try{"compact"!==d&&(p=f.fromDER(a))}catch(e){if(!(e instanceof Xe.Err))throw e}p||"der"===d||(p=f.fromCompact(a))}m=e.fromHex(i)}catch(e){return!1}if(!p)return!1;if(u&&p.hasHighS())return!1;c&&(r=t.hash(r));const{r:y,s:_}=p,v=g(r),w=o.inv(_),x=o.create(v*w),k=o.create(y*w),O=e.BASE.multiplyUnsafe(x).add(m.multiplyUnsafe(k));return!O.is0()&&o.create(O.x)===y},utils:h,Point:e,Signature:f})}function ut(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};return{CURVE:t,curveOpts:{Fp:e.Fp,Fn:Be(t.n,e.nBitLength),allowedPrivateKeyLengths:e.allowedPrivateKeyLengths,allowInfinityPoint:e.allowInfinityPoint,endo:e.endo,wrapPrivateKey:e.wrapPrivateKey,isTorsionFree:e.isTorsionFree,clearCofactor:e.clearCofactor,fromBytes:e.fromBytes,toBytes:e.toBytes}}}(e);return{CURVE:t,curveOpts:n,ecdsaOpts:{hash:e.hash,hmac:e.hmac,randomBytes:e.randomBytes,lowS:e.lowS,bits2int:e.bits2int,bits2int_modN:e.bits2int_modN}}}function ct(e){const{CURVE:t,curveOpts:n,ecdsaOpts:r}=ut(e);return function(e,t){return Object.assign({},t,{ProjectivePoint:t.Point,CURVE:e})}(e,at(st(t,n),r,n))}
10
10
  /*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */
11
11
  /*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */
12
- const dt={p:BigInt("0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f"),n:BigInt("0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141"),h:BigInt(1),a:BigInt(0),b:BigInt(7),Gx:BigInt("0x79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798"),Gy:BigInt("0x483ada7726a3c4655da4fbfc0e1108a8fd17b448a68554199c47d08ffb10d4b8")},ft=BigInt(0),ht=BigInt(1),lt=BigInt(2),pt=(e,t)=>(e+t/lt)/t;function gt(e){const t=dt.p,n=BigInt(3),r=BigInt(6),i=BigInt(11),s=BigInt(22),o=BigInt(23),a=BigInt(44),u=BigInt(88),c=e*e*e%t,d=c*c*e%t,f=Ae(d,n,t)*d%t,h=Ae(f,n,t)*d%t,l=Ae(h,lt,t)*c%t,p=Ae(l,i,t)*l%t,g=Ae(p,s,t)*p%t,m=Ae(g,a,t)*g%t,y=Ae(m,u,t)*m%t,w=Ae(y,a,t)*g%t,v=Ae(w,n,t)*d%t,_=Ae(v,o,t)*p%t,b=Ae(_,r,t)*c%t,E=Ae(b,lt,t);if(!mt.eql(mt.sqr(E),e))throw new Error("Cannot find square root");return E}const mt=Be(dt.p,void 0,void 0,{sqrt:gt}),yt=function(e,t){const n=t=>ct({...e,hash:t});return{...n(t),create:n}}({...dt,Fp:mt,lowS:!0,endo:{beta:BigInt("0x7ae96a2b657c07106e64479eac3434e99cf0497512f58995c1396c28719501ee"),splitScalar:e=>{const t=dt.n,n=BigInt("0x3086d221a7d46bcde86c90e49284eb15"),r=-ht*BigInt("0xe4437ed6010e88286f547fa90abfe4c3"),i=BigInt("0x114ca50f7a8e2f3f657c1108d9d44cfd8"),s=n,o=BigInt("0x100000000000000000000000000000000"),a=pt(s*e,t),u=pt(-r*e,t);let c=Oe(e-a*n-u*i,t),d=Oe(-a*r-u*s,t);const f=c>o,h=d>o;if(f&&(c=t-c),h&&(d=t-d),c>o||d>o)throw new Error("splitScalar: Endomorphism failed, k="+e);return{k1neg:f,k1:c,k2neg:h,k2:d}}}},ee),wt={};function vt(e,...t){let n=wt[e];if(void 0===n){const t=ee(Uint8Array.from(e,e=>e.charCodeAt(0)));n=V(t,t),wt[e]=n}return ee(V(n,...t))}const _t=e=>e.toBytes(!0).slice(1),bt=e=>de(e,32),Et=e=>Oe(e,dt.p),xt=e=>Oe(e,dt.n),St=(()=>yt.Point)(),kt=e=>e%lt===ft;function Ot(e){let t=yt.utils.normPrivateKeyToScalar(e),n=St.fromPrivateKey(t);return{scalar:kt(n.y)?t:xt(-t),bytes:_t(n)}}function At(e){ge("x",e,ht,dt.p);const t=Et(e*e);let n=gt(Et(t*e+BigInt(7)));kt(n)||(n=Et(-n));const r=St.fromAffine({x:e,y:n});return r.assertValidity(),r}const Pt=ue;function Tt(...e){return xt(Pt(vt("BIP0340/challenge",...e)))}function It(e){return Ot(e).bytes}function Nt(e,t,n=W(32)){const r=he("message",e),{bytes:i,scalar:s}=Ot(t),o=he("auxRand",n,32),a=bt(s^Pt(vt("BIP0340/aux",o))),u=vt("BIP0340/nonce",a,i,r),c=xt(Pt(u));if(c===ft)throw new Error("sign failed: k is zero");const{bytes:d,scalar:f}=Ot(c),h=Tt(d,i,r),l=new Uint8Array(64);if(l.set(d,0),l.set(bt(xt(f+h*s)),32),!$t(l,r,i))throw new Error("sign: Invalid signature produced");return l}function $t(e,t,n){const r=he("signature",e,64),i=he("message",t),s=he("publicKey",n,32);try{const e=At(Pt(s)),t=Pt(r.subarray(0,32));if(!pe(t,ht,dt.p))return!1;const n=Pt(r.subarray(32,64));if(!pe(n,ht,dt.n))return!1;const o=Tt(bt(t),_t(e),i),a=St.BASE.multiplyUnsafe(n).add(e.multiplyUnsafe(xt(-o))),{x:u,y:c}=a.toAffine();return!(a.is0()||!kt(c)||u!==t)}catch(e){return!1}}const Ut=(()=>({getPublicKey:It,sign:Nt,verify:$t,utils:{randomPrivateKey:yt.utils.randomPrivateKey,lift_x:At,pointToBytes:_t,numberToBytesBE:de,bytesToNumberBE:ue,taggedHash:vt,mod:Oe}}))();BigInt(0),BigInt(2);Be(yt.CURVE.n,32,!0);const Ct=yt.Point.BASE;function Bt(e,t,n,r=!1){const i=Lt(t).big,s=function(e){try{const t=Rt(e,"ecdsa");return yt.Point.fromHex(t)}catch(t){throw new Error("invalid pubkey: "+e)}}(e),o=Ct.multiply(i);let a=s.add(o);r&&!a.hasEvenY()&&(a=a.negate());return Rt(a.toHex(!0),n)}function Rt(e,t){try{const n=Lt(e);if(33===n.length&&"bip340"===t)return n.slice(1);if(32===n.length&&"ecdsa"===t){const e=m.num(2,1);return m.join([e,n])}return n}catch(t){throw new Error("invalid pubkey: "+String(e))}}function Lt(e){try{return m.bytes(e)}catch(t){throw new Error("invalid bytes: "+String(e))}}const zt=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)))(),Ht=(()=>jt.map(e=>(9*e+5)%16))(),Dt=(()=>{const e=[[jt],[Ht]];for(let t=0;t<4;t++)for(let n of e)n.push(n[t].map(e=>zt[e]));return e})(),Ft=(()=>Dt[0])(),Vt=(()=>Dt[1])(),Zt=[[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)),Kt=Ft.map((e,t)=>e.map(e=>Zt[t][e])),Wt=Vt.map((e,t)=>e.map(e=>Zt[t][e])),Mt=Uint32Array.from([0,1518500249,1859775393,2400959708,2840853838]),qt=Uint32Array.from([1352829926,1548603684,1836072691,2053994217,0]);function Gt(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 Yt=new Uint32Array(16);class Qt extends G{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)Yt[n]=e.getUint32(t,!0);let n=0|this.h0,r=n,i=0|this.h1,s=i,o=0|this.h2,a=o,u=0|this.h3,c=u,d=0|this.h4,f=d;for(let e=0;e<5;e++){const t=4-e,h=Mt[e],l=qt[e],p=Ft[e],g=Vt[e],m=Kt[e],y=Wt[e];for(let t=0;t<16;t++){const r=I(n+Gt(e,i,o,u)+Yt[p[t]]+h,m[t])+d|0;n=d,d=u,u=0|I(o,10),o=i,i=r}for(let e=0;e<16;e++){const n=I(r+Gt(t,s,a,c)+Yt[g[e]]+l,y[e])+f|0;r=f,f=c,c=0|I(a,10),a=s,s=n}}this.set(this.h1+o+c|0,this.h2+u+f|0,this.h3+d+r|0,this.h4+n+s|0,this.h0+i+a|0)}roundClean(){A(Yt)}destroy(){this.destroyed=!0,A(this.buffer),this.set(0,0,0,0,0)}}const Xt=K(()=>new Qt);function Jt(...e){const t=m.join(e),n=Xt(ee(t));return new m(n)}function en(...e){const t=m.join(e),n=ee(t);return new m(n)}function tn(...e){const t=m.join(e),n=ee(ee(t));return new m(n)}function nn(e,...t){const n=function(e){const t=en(m.str(e));return m.join([t,t])}(e),r=t.map(e=>new m(e));return en(m.join([n,...r]))}var rn,sn;!function(e){e.assertEqual=e=>{},e.assertIs=function(e){},e.assertNever=function(e){throw new Error},e.arrayToEnum=e=>{const t={};for(const n of e)t[n]=n;return t},e.getValidEnumValues=t=>{const n=e.objectKeys(t).filter(e=>"number"!=typeof t[t[e]]),r={};for(const e of n)r[e]=t[e];return e.objectValues(r)},e.objectValues=t=>e.objectKeys(t).map(function(e){return t[e]}),e.objectKeys="function"==typeof Object.keys?e=>Object.keys(e):e=>{const t=[];for(const n in e)Object.prototype.hasOwnProperty.call(e,n)&&t.push(n);return t},e.find=(e,t)=>{for(const n of e)if(t(n))return n},e.isInteger="function"==typeof Number.isInteger?e=>Number.isInteger(e):e=>"number"==typeof e&&Number.isFinite(e)&&Math.floor(e)===e,e.joinValues=function(e,t=" | "){return e.map(e=>"string"==typeof e?`'${e}'`:e).join(t)},e.jsonStringifyReplacer=(e,t)=>"bigint"==typeof t?t.toString():t}(rn||(rn={})),function(e){e.mergeShapes=(e,t)=>({...e,...t})}(sn||(sn={}));const on=rn.arrayToEnum(["string","nan","number","integer","float","boolean","date","bigint","symbol","function","undefined","null","array","object","unknown","promise","void","never","map","set"]),an=e=>{switch(typeof e){case"undefined":return on.undefined;case"string":return on.string;case"number":return Number.isNaN(e)?on.nan:on.number;case"boolean":return on.boolean;case"function":return on.function;case"bigint":return on.bigint;case"symbol":return on.symbol;case"object":return Array.isArray(e)?on.array:null===e?on.null:e.then&&"function"==typeof e.then&&e.catch&&"function"==typeof e.catch?on.promise:"undefined"!=typeof Map&&e instanceof Map?on.map:"undefined"!=typeof Set&&e instanceof Set?on.set:"undefined"!=typeof Date&&e instanceof Date?on.date:on.object;default:return on.unknown}},un=rn.arrayToEnum(["invalid_type","invalid_literal","custom","invalid_union","invalid_union_discriminator","invalid_enum_value","unrecognized_keys","invalid_arguments","invalid_return_type","invalid_date","invalid_string","too_small","too_big","invalid_intersection_types","not_multiple_of","not_finite"]);class cn extends Error{get errors(){return this.issues}constructor(e){super(),this.issues=[],this.addIssue=e=>{this.issues=[...this.issues,e]},this.addIssues=(e=[])=>{this.issues=[...this.issues,...e]};const t=new.target.prototype;Object.setPrototypeOf?Object.setPrototypeOf(this,t):this.__proto__=t,this.name="ZodError",this.issues=e}format(e){const t=e||function(e){return e.message},n={_errors:[]},r=e=>{for(const i of e.issues)if("invalid_union"===i.code)i.unionErrors.map(r);else if("invalid_return_type"===i.code)r(i.returnTypeError);else if("invalid_arguments"===i.code)r(i.argumentsError);else if(0===i.path.length)n._errors.push(t(i));else{let e=n,r=0;for(;r<i.path.length;){const n=i.path[r];r===i.path.length-1?(e[n]=e[n]||{_errors:[]},e[n]._errors.push(t(i))):e[n]=e[n]||{_errors:[]},e=e[n],r++}}};return r(this),n}static assert(e){if(!(e instanceof cn))throw new Error(`Not a ZodError: ${e}`)}toString(){return this.message}get message(){return JSON.stringify(this.issues,rn.jsonStringifyReplacer,2)}get isEmpty(){return 0===this.issues.length}flatten(e=e=>e.message){const t={},n=[];for(const r of this.issues)if(r.path.length>0){const n=r.path[0];t[n]=t[n]||[],t[n].push(e(r))}else n.push(e(r));return{formErrors:n,fieldErrors:t}}get formErrors(){return this.flatten()}}cn.create=e=>new cn(e);const dn=(e,t)=>{let n;switch(e.code){case un.invalid_type:n=e.received===on.undefined?"Required":`Expected ${e.expected}, received ${e.received}`;break;case un.invalid_literal:n=`Invalid literal value, expected ${JSON.stringify(e.expected,rn.jsonStringifyReplacer)}`;break;case un.unrecognized_keys:n=`Unrecognized key(s) in object: ${rn.joinValues(e.keys,", ")}`;break;case un.invalid_union:n="Invalid input";break;case un.invalid_union_discriminator:n=`Invalid discriminator value. Expected ${rn.joinValues(e.options)}`;break;case un.invalid_enum_value:n=`Invalid enum value. Expected ${rn.joinValues(e.options)}, received '${e.received}'`;break;case un.invalid_arguments:n="Invalid function arguments";break;case un.invalid_return_type:n="Invalid function return type";break;case un.invalid_date:n="Invalid date";break;case un.invalid_string:"object"==typeof e.validation?"includes"in e.validation?(n=`Invalid input: must include "${e.validation.includes}"`,"number"==typeof e.validation.position&&(n=`${n} at one or more positions greater than or equal to ${e.validation.position}`)):"startsWith"in e.validation?n=`Invalid input: must start with "${e.validation.startsWith}"`:"endsWith"in e.validation?n=`Invalid input: must end with "${e.validation.endsWith}"`:rn.assertNever(e.validation):n="regex"!==e.validation?`Invalid ${e.validation}`:"Invalid";break;case un.too_small:n="array"===e.type?`Array must contain ${e.exact?"exactly":e.inclusive?"at least":"more than"} ${e.minimum} element(s)`:"string"===e.type?`String must contain ${e.exact?"exactly":e.inclusive?"at least":"over"} ${e.minimum} character(s)`:"number"===e.type||"bigint"===e.type?`Number must be ${e.exact?"exactly equal to ":e.inclusive?"greater than or equal to ":"greater than "}${e.minimum}`:"date"===e.type?`Date must be ${e.exact?"exactly equal to ":e.inclusive?"greater than or equal to ":"greater than "}${new Date(Number(e.minimum))}`:"Invalid input";break;case un.too_big:n="array"===e.type?`Array must contain ${e.exact?"exactly":e.inclusive?"at most":"less than"} ${e.maximum} element(s)`:"string"===e.type?`String must contain ${e.exact?"exactly":e.inclusive?"at most":"under"} ${e.maximum} character(s)`:"number"===e.type?`Number must be ${e.exact?"exactly":e.inclusive?"less than or equal to":"less than"} ${e.maximum}`:"bigint"===e.type?`BigInt must be ${e.exact?"exactly":e.inclusive?"less than or equal to":"less than"} ${e.maximum}`:"date"===e.type?`Date must be ${e.exact?"exactly":e.inclusive?"smaller than or equal to":"smaller than"} ${new Date(Number(e.maximum))}`:"Invalid input";break;case un.custom:n="Invalid input";break;case un.invalid_intersection_types:n="Intersection results could not be merged";break;case un.not_multiple_of:n=`Number must be a multiple of ${e.multipleOf}`;break;case un.not_finite:n="Number must be finite";break;default:n=t.defaultError,rn.assertNever(e)}return{message:n}};let fn=dn;function hn(e,t){const n=fn,r=(e=>{const{data:t,path:n,errorMaps:r,issueData:i}=e,s=[...n,...i.path||[]],o={...i,path:s};if(void 0!==i.message)return{...i,path:s,message:i.message};let a="";const u=r.filter(e=>!!e).slice().reverse();for(const e of u)a=e(o,{data:t,defaultError:a}).message;return{...i,path:s,message:a}})({issueData:t,data:e.data,path:e.path,errorMaps:[e.common.contextualErrorMap,e.schemaErrorMap,n,n===dn?void 0:dn].filter(e=>!!e)});e.common.issues.push(r)}class ln{constructor(){this.value="valid"}dirty(){"valid"===this.value&&(this.value="dirty")}abort(){"aborted"!==this.value&&(this.value="aborted")}static mergeArray(e,t){const n=[];for(const r of t){if("aborted"===r.status)return pn;"dirty"===r.status&&e.dirty(),n.push(r.value)}return{status:e.value,value:n}}static async mergeObjectAsync(e,t){const n=[];for(const e of t){const t=await e.key,r=await e.value;n.push({key:t,value:r})}return ln.mergeObjectSync(e,n)}static mergeObjectSync(e,t){const n={};for(const r of t){const{key:t,value:i}=r;if("aborted"===t.status)return pn;if("aborted"===i.status)return pn;"dirty"===t.status&&e.dirty(),"dirty"===i.status&&e.dirty(),"__proto__"===t.value||void 0===i.value&&!r.alwaysSet||(n[t.value]=i.value)}return{status:e.value,value:n}}}const pn=Object.freeze({status:"aborted"}),gn=e=>({status:"dirty",value:e}),mn=e=>({status:"valid",value:e}),yn=e=>"aborted"===e.status,wn=e=>"dirty"===e.status,vn=e=>"valid"===e.status,_n=e=>"undefined"!=typeof Promise&&e instanceof Promise;var bn;!function(e){e.errToObj=e=>"string"==typeof e?{message:e}:e||{},e.toString=e=>"string"==typeof e?e:e?.message}(bn||(bn={}));class En{constructor(e,t,n,r){this._cachedPath=[],this.parent=e,this.data=t,this._path=n,this._key=r}get path(){return this._cachedPath.length||(Array.isArray(this._key)?this._cachedPath.push(...this._path,...this._key):this._cachedPath.push(...this._path,this._key)),this._cachedPath}}const xn=(e,t)=>{if(vn(t))return{success:!0,data:t.value};if(!e.common.issues.length)throw new Error("Validation failed but no issues detected.");return{success:!1,get error(){if(this._error)return this._error;const t=new cn(e.common.issues);return this._error=t,this._error}}};function Sn(e){if(!e)return{};const{errorMap:t,invalid_type_error:n,required_error:r,description:i}=e;if(t&&(n||r))throw new Error('Can\'t use "invalid_type_error" or "required_error" in conjunction with custom error map.');if(t)return{errorMap:t,description:i};return{errorMap:(t,i)=>{const{message:s}=e;return"invalid_enum_value"===t.code?{message:s??i.defaultError}:void 0===i.data?{message:s??r??i.defaultError}:"invalid_type"!==t.code?{message:i.defaultError}:{message:s??n??i.defaultError}},description:i}}class kn{get description(){return this._def.description}_getType(e){return an(e.data)}_getOrReturnCtx(e,t){return t||{common:e.parent.common,data:e.data,parsedType:an(e.data),schemaErrorMap:this._def.errorMap,path:e.path,parent:e.parent}}_processInputParams(e){return{status:new ln,ctx:{common:e.parent.common,data:e.data,parsedType:an(e.data),schemaErrorMap:this._def.errorMap,path:e.path,parent:e.parent}}}_parseSync(e){const t=this._parse(e);if(_n(t))throw new Error("Synchronous parse encountered promise.");return t}_parseAsync(e){const t=this._parse(e);return Promise.resolve(t)}parse(e,t){const n=this.safeParse(e,t);if(n.success)return n.data;throw n.error}safeParse(e,t){const n={common:{issues:[],async:t?.async??!1,contextualErrorMap:t?.errorMap},path:t?.path||[],schemaErrorMap:this._def.errorMap,parent:null,data:e,parsedType:an(e)},r=this._parseSync({data:e,path:n.path,parent:n});return xn(n,r)}"~validate"(e){const t={common:{issues:[],async:!!this["~standard"].async},path:[],schemaErrorMap:this._def.errorMap,parent:null,data:e,parsedType:an(e)};if(!this["~standard"].async)try{const n=this._parseSync({data:e,path:[],parent:t});return vn(n)?{value:n.value}:{issues:t.common.issues}}catch(e){e?.message?.toLowerCase()?.includes("encountered")&&(this["~standard"].async=!0),t.common={issues:[],async:!0}}return this._parseAsync({data:e,path:[],parent:t}).then(e=>vn(e)?{value:e.value}:{issues:t.common.issues})}async parseAsync(e,t){const n=await this.safeParseAsync(e,t);if(n.success)return n.data;throw n.error}async safeParseAsync(e,t){const n={common:{issues:[],contextualErrorMap:t?.errorMap,async:!0},path:t?.path||[],schemaErrorMap:this._def.errorMap,parent:null,data:e,parsedType:an(e)},r=this._parse({data:e,path:n.path,parent:n}),i=await(_n(r)?r:Promise.resolve(r));return xn(n,i)}refine(e,t){const n=e=>"string"==typeof t||void 0===t?{message:t}:"function"==typeof t?t(e):t;return this._refinement((t,r)=>{const i=e(t),s=()=>r.addIssue({code:un.custom,...n(t)});return"undefined"!=typeof Promise&&i instanceof Promise?i.then(e=>!!e||(s(),!1)):!!i||(s(),!1)})}refinement(e,t){return this._refinement((n,r)=>!!e(n)||(r.addIssue("function"==typeof t?t(n,r):t),!1))}_refinement(e){return new Sr({schema:this,typeName:Cr.ZodEffects,effect:{type:"refinement",refinement:e}})}superRefine(e){return this._refinement(e)}constructor(e){this.spa=this.safeParseAsync,this._def=e,this.parse=this.parse.bind(this),this.safeParse=this.safeParse.bind(this),this.parseAsync=this.parseAsync.bind(this),this.safeParseAsync=this.safeParseAsync.bind(this),this.spa=this.spa.bind(this),this.refine=this.refine.bind(this),this.refinement=this.refinement.bind(this),this.superRefine=this.superRefine.bind(this),this.optional=this.optional.bind(this),this.nullable=this.nullable.bind(this),this.nullish=this.nullish.bind(this),this.array=this.array.bind(this),this.promise=this.promise.bind(this),this.or=this.or.bind(this),this.and=this.and.bind(this),this.transform=this.transform.bind(this),this.brand=this.brand.bind(this),this.default=this.default.bind(this),this.catch=this.catch.bind(this),this.describe=this.describe.bind(this),this.pipe=this.pipe.bind(this),this.readonly=this.readonly.bind(this),this.isNullable=this.isNullable.bind(this),this.isOptional=this.isOptional.bind(this),this["~standard"]={version:1,vendor:"zod",validate:e=>this["~validate"](e)}}optional(){return kr.create(this,this._def)}nullable(){return Or.create(this,this._def)}nullish(){return this.nullable().optional()}array(){return ur.create(this)}promise(){return xr.create(this,this._def)}or(e){return fr.create([this,e],this._def)}and(e){return lr.create(this,e,this._def)}transform(e){return new Sr({...Sn(this._def),schema:this,typeName:Cr.ZodEffects,effect:{type:"transform",transform:e}})}default(e){const t="function"==typeof e?e:()=>e;return new Ar({...Sn(this._def),innerType:this,defaultValue:t,typeName:Cr.ZodDefault})}brand(){return new Ir({typeName:Cr.ZodBranded,type:this,...Sn(this._def)})}catch(e){const t="function"==typeof e?e:()=>e;return new Pr({...Sn(this._def),innerType:this,catchValue:t,typeName:Cr.ZodCatch})}describe(e){return new(0,this.constructor)({...this._def,description:e})}pipe(e){return Nr.create(this,e)}readonly(){return $r.create(this)}isOptional(){return this.safeParse(void 0).success}isNullable(){return this.safeParse(null).success}}const On=/^c[^\s-]{8,}$/i,An=/^[0-9a-z]+$/,Pn=/^[0-9A-HJKMNP-TV-Z]{26}$/i,Tn=/^[0-9a-fA-F]{8}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{12}$/i,In=/^[a-z0-9_-]{21}$/i,Nn=/^[A-Za-z0-9-_]+\.[A-Za-z0-9-_]+\.[A-Za-z0-9-_]*$/,$n=/^[-+]?P(?!$)(?:(?:[-+]?\d+Y)|(?:[-+]?\d+[.,]\d+Y$))?(?:(?:[-+]?\d+M)|(?:[-+]?\d+[.,]\d+M$))?(?:(?:[-+]?\d+W)|(?:[-+]?\d+[.,]\d+W$))?(?:(?:[-+]?\d+D)|(?:[-+]?\d+[.,]\d+D$))?(?:T(?=[\d+-])(?:(?:[-+]?\d+H)|(?:[-+]?\d+[.,]\d+H$))?(?:(?:[-+]?\d+M)|(?:[-+]?\d+[.,]\d+M$))?(?:[-+]?\d+(?:[.,]\d+)?S)?)??$/,Un=/^(?!\.)(?!.*\.\.)([A-Z0-9_'+\-\.]*)[A-Z0-9_+-]@([A-Z0-9][A-Z0-9\-]*\.)+[A-Z]{2,}$/i;let Cn;const Bn=/^(?:(?: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])$/,Rn=/^(?:(?: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])\/(3[0-2]|[12]?[0-9])$/,Ln=/^(([0-9a-fA-F]{1,4}:){7,7}[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,7}:|([0-9a-fA-F]{1,4}:){1,6}:[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,5}(:[0-9a-fA-F]{1,4}){1,2}|([0-9a-fA-F]{1,4}:){1,4}(:[0-9a-fA-F]{1,4}){1,3}|([0-9a-fA-F]{1,4}:){1,3}(:[0-9a-fA-F]{1,4}){1,4}|([0-9a-fA-F]{1,4}:){1,2}(:[0-9a-fA-F]{1,4}){1,5}|[0-9a-fA-F]{1,4}:((:[0-9a-fA-F]{1,4}){1,6})|:((:[0-9a-fA-F]{1,4}){1,7}|:)|fe80:(:[0-9a-fA-F]{0,4}){0,4}%[0-9a-zA-Z]{1,}|::(ffff(:0{1,4}){0,1}:){0,1}((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])|([0-9a-fA-F]{1,4}:){1,4}:((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9]))$/,zn=/^(([0-9a-fA-F]{1,4}:){7,7}[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,7}:|([0-9a-fA-F]{1,4}:){1,6}:[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,5}(:[0-9a-fA-F]{1,4}){1,2}|([0-9a-fA-F]{1,4}:){1,4}(:[0-9a-fA-F]{1,4}){1,3}|([0-9a-fA-F]{1,4}:){1,3}(:[0-9a-fA-F]{1,4}){1,4}|([0-9a-fA-F]{1,4}:){1,2}(:[0-9a-fA-F]{1,4}){1,5}|[0-9a-fA-F]{1,4}:((:[0-9a-fA-F]{1,4}){1,6})|:((:[0-9a-fA-F]{1,4}){1,7}|:)|fe80:(:[0-9a-fA-F]{0,4}){0,4}%[0-9a-zA-Z]{1,}|::(ffff(:0{1,4}){0,1}:){0,1}((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])|([0-9a-fA-F]{1,4}:){1,4}:((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9]))\/(12[0-8]|1[01][0-9]|[1-9]?[0-9])$/,jn=/^([0-9a-zA-Z+/]{4})*(([0-9a-zA-Z+/]{2}==)|([0-9a-zA-Z+/]{3}=))?$/,Hn=/^([0-9a-zA-Z-_]{4})*(([0-9a-zA-Z-_]{2}(==)?)|([0-9a-zA-Z-_]{3}(=)?))?$/,Dn="((\\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])))",Fn=new RegExp(`^${Dn}$`);function Vn(e){let t="[0-5]\\d";e.precision?t=`${t}\\.\\d{${e.precision}}`:null==e.precision&&(t=`${t}(\\.\\d+)?`);return`([01]\\d|2[0-3]):[0-5]\\d(:${t})${e.precision?"+":"?"}`}function Zn(e){return new RegExp(`^${Vn(e)}$`)}function Kn(e){let t=`${Dn}T${Vn(e)}`;const n=[];return n.push(e.local?"Z?":"Z"),e.offset&&n.push("([+-]\\d{2}:?\\d{2})"),t=`${t}(${n.join("|")})`,new RegExp(`^${t}$`)}function Wn(e,t){return!("v4"!==t&&t||!Bn.test(e))||!("v6"!==t&&t||!Ln.test(e))}function Mn(e,t){if(!Nn.test(e))return!1;try{const[n]=e.split(".");if(!n)return!1;const r=n.replace(/-/g,"+").replace(/_/g,"/").padEnd(n.length+(4-n.length%4)%4,"="),i=JSON.parse(atob(r));return"object"==typeof i&&null!==i&&((!("typ"in i)||"JWT"===i?.typ)&&(!!i.alg&&(!t||i.alg===t)))}catch{return!1}}function qn(e,t){return!("v4"!==t&&t||!Rn.test(e))||!("v6"!==t&&t||!zn.test(e))}class Gn extends kn{_parse(e){this._def.coerce&&(e.data=String(e.data));if(this._getType(e)!==on.string){const t=this._getOrReturnCtx(e);return hn(t,{code:un.invalid_type,expected:on.string,received:t.parsedType}),pn}const t=new ln;let n;for(const r of this._def.checks)if("min"===r.kind)e.data.length<r.value&&(n=this._getOrReturnCtx(e,n),hn(n,{code:un.too_small,minimum:r.value,type:"string",inclusive:!0,exact:!1,message:r.message}),t.dirty());else if("max"===r.kind)e.data.length>r.value&&(n=this._getOrReturnCtx(e,n),hn(n,{code:un.too_big,maximum:r.value,type:"string",inclusive:!0,exact:!1,message:r.message}),t.dirty());else if("length"===r.kind){const i=e.data.length>r.value,s=e.data.length<r.value;(i||s)&&(n=this._getOrReturnCtx(e,n),i?hn(n,{code:un.too_big,maximum:r.value,type:"string",inclusive:!0,exact:!0,message:r.message}):s&&hn(n,{code:un.too_small,minimum:r.value,type:"string",inclusive:!0,exact:!0,message:r.message}),t.dirty())}else if("email"===r.kind)Un.test(e.data)||(n=this._getOrReturnCtx(e,n),hn(n,{validation:"email",code:un.invalid_string,message:r.message}),t.dirty());else if("emoji"===r.kind)Cn||(Cn=new RegExp("^(\\p{Extended_Pictographic}|\\p{Emoji_Component})+$","u")),Cn.test(e.data)||(n=this._getOrReturnCtx(e,n),hn(n,{validation:"emoji",code:un.invalid_string,message:r.message}),t.dirty());else if("uuid"===r.kind)Tn.test(e.data)||(n=this._getOrReturnCtx(e,n),hn(n,{validation:"uuid",code:un.invalid_string,message:r.message}),t.dirty());else if("nanoid"===r.kind)In.test(e.data)||(n=this._getOrReturnCtx(e,n),hn(n,{validation:"nanoid",code:un.invalid_string,message:r.message}),t.dirty());else if("cuid"===r.kind)On.test(e.data)||(n=this._getOrReturnCtx(e,n),hn(n,{validation:"cuid",code:un.invalid_string,message:r.message}),t.dirty());else if("cuid2"===r.kind)An.test(e.data)||(n=this._getOrReturnCtx(e,n),hn(n,{validation:"cuid2",code:un.invalid_string,message:r.message}),t.dirty());else if("ulid"===r.kind)Pn.test(e.data)||(n=this._getOrReturnCtx(e,n),hn(n,{validation:"ulid",code:un.invalid_string,message:r.message}),t.dirty());else if("url"===r.kind)try{new URL(e.data)}catch{n=this._getOrReturnCtx(e,n),hn(n,{validation:"url",code:un.invalid_string,message:r.message}),t.dirty()}else if("regex"===r.kind){r.regex.lastIndex=0;r.regex.test(e.data)||(n=this._getOrReturnCtx(e,n),hn(n,{validation:"regex",code:un.invalid_string,message:r.message}),t.dirty())}else if("trim"===r.kind)e.data=e.data.trim();else if("includes"===r.kind)e.data.includes(r.value,r.position)||(n=this._getOrReturnCtx(e,n),hn(n,{code:un.invalid_string,validation:{includes:r.value,position:r.position},message:r.message}),t.dirty());else if("toLowerCase"===r.kind)e.data=e.data.toLowerCase();else if("toUpperCase"===r.kind)e.data=e.data.toUpperCase();else if("startsWith"===r.kind)e.data.startsWith(r.value)||(n=this._getOrReturnCtx(e,n),hn(n,{code:un.invalid_string,validation:{startsWith:r.value},message:r.message}),t.dirty());else if("endsWith"===r.kind)e.data.endsWith(r.value)||(n=this._getOrReturnCtx(e,n),hn(n,{code:un.invalid_string,validation:{endsWith:r.value},message:r.message}),t.dirty());else if("datetime"===r.kind){Kn(r).test(e.data)||(n=this._getOrReturnCtx(e,n),hn(n,{code:un.invalid_string,validation:"datetime",message:r.message}),t.dirty())}else if("date"===r.kind){Fn.test(e.data)||(n=this._getOrReturnCtx(e,n),hn(n,{code:un.invalid_string,validation:"date",message:r.message}),t.dirty())}else if("time"===r.kind){Zn(r).test(e.data)||(n=this._getOrReturnCtx(e,n),hn(n,{code:un.invalid_string,validation:"time",message:r.message}),t.dirty())}else"duration"===r.kind?$n.test(e.data)||(n=this._getOrReturnCtx(e,n),hn(n,{validation:"duration",code:un.invalid_string,message:r.message}),t.dirty()):"ip"===r.kind?Wn(e.data,r.version)||(n=this._getOrReturnCtx(e,n),hn(n,{validation:"ip",code:un.invalid_string,message:r.message}),t.dirty()):"jwt"===r.kind?Mn(e.data,r.alg)||(n=this._getOrReturnCtx(e,n),hn(n,{validation:"jwt",code:un.invalid_string,message:r.message}),t.dirty()):"cidr"===r.kind?qn(e.data,r.version)||(n=this._getOrReturnCtx(e,n),hn(n,{validation:"cidr",code:un.invalid_string,message:r.message}),t.dirty()):"base64"===r.kind?jn.test(e.data)||(n=this._getOrReturnCtx(e,n),hn(n,{validation:"base64",code:un.invalid_string,message:r.message}),t.dirty()):"base64url"===r.kind?Hn.test(e.data)||(n=this._getOrReturnCtx(e,n),hn(n,{validation:"base64url",code:un.invalid_string,message:r.message}),t.dirty()):rn.assertNever(r);return{status:t.value,value:e.data}}_regex(e,t,n){return this.refinement(t=>e.test(t),{validation:t,code:un.invalid_string,...bn.errToObj(n)})}_addCheck(e){return new Gn({...this._def,checks:[...this._def.checks,e]})}email(e){return this._addCheck({kind:"email",...bn.errToObj(e)})}url(e){return this._addCheck({kind:"url",...bn.errToObj(e)})}emoji(e){return this._addCheck({kind:"emoji",...bn.errToObj(e)})}uuid(e){return this._addCheck({kind:"uuid",...bn.errToObj(e)})}nanoid(e){return this._addCheck({kind:"nanoid",...bn.errToObj(e)})}cuid(e){return this._addCheck({kind:"cuid",...bn.errToObj(e)})}cuid2(e){return this._addCheck({kind:"cuid2",...bn.errToObj(e)})}ulid(e){return this._addCheck({kind:"ulid",...bn.errToObj(e)})}base64(e){return this._addCheck({kind:"base64",...bn.errToObj(e)})}base64url(e){return this._addCheck({kind:"base64url",...bn.errToObj(e)})}jwt(e){return this._addCheck({kind:"jwt",...bn.errToObj(e)})}ip(e){return this._addCheck({kind:"ip",...bn.errToObj(e)})}cidr(e){return this._addCheck({kind:"cidr",...bn.errToObj(e)})}datetime(e){return"string"==typeof e?this._addCheck({kind:"datetime",precision:null,offset:!1,local:!1,message:e}):this._addCheck({kind:"datetime",precision:void 0===e?.precision?null:e?.precision,offset:e?.offset??!1,local:e?.local??!1,...bn.errToObj(e?.message)})}date(e){return this._addCheck({kind:"date",message:e})}time(e){return"string"==typeof e?this._addCheck({kind:"time",precision:null,message:e}):this._addCheck({kind:"time",precision:void 0===e?.precision?null:e?.precision,...bn.errToObj(e?.message)})}duration(e){return this._addCheck({kind:"duration",...bn.errToObj(e)})}regex(e,t){return this._addCheck({kind:"regex",regex:e,...bn.errToObj(t)})}includes(e,t){return this._addCheck({kind:"includes",value:e,position:t?.position,...bn.errToObj(t?.message)})}startsWith(e,t){return this._addCheck({kind:"startsWith",value:e,...bn.errToObj(t)})}endsWith(e,t){return this._addCheck({kind:"endsWith",value:e,...bn.errToObj(t)})}min(e,t){return this._addCheck({kind:"min",value:e,...bn.errToObj(t)})}max(e,t){return this._addCheck({kind:"max",value:e,...bn.errToObj(t)})}length(e,t){return this._addCheck({kind:"length",value:e,...bn.errToObj(t)})}nonempty(e){return this.min(1,bn.errToObj(e))}trim(){return new Gn({...this._def,checks:[...this._def.checks,{kind:"trim"}]})}toLowerCase(){return new Gn({...this._def,checks:[...this._def.checks,{kind:"toLowerCase"}]})}toUpperCase(){return new Gn({...this._def,checks:[...this._def.checks,{kind:"toUpperCase"}]})}get isDatetime(){return!!this._def.checks.find(e=>"datetime"===e.kind)}get isDate(){return!!this._def.checks.find(e=>"date"===e.kind)}get isTime(){return!!this._def.checks.find(e=>"time"===e.kind)}get isDuration(){return!!this._def.checks.find(e=>"duration"===e.kind)}get isEmail(){return!!this._def.checks.find(e=>"email"===e.kind)}get isURL(){return!!this._def.checks.find(e=>"url"===e.kind)}get isEmoji(){return!!this._def.checks.find(e=>"emoji"===e.kind)}get isUUID(){return!!this._def.checks.find(e=>"uuid"===e.kind)}get isNANOID(){return!!this._def.checks.find(e=>"nanoid"===e.kind)}get isCUID(){return!!this._def.checks.find(e=>"cuid"===e.kind)}get isCUID2(){return!!this._def.checks.find(e=>"cuid2"===e.kind)}get isULID(){return!!this._def.checks.find(e=>"ulid"===e.kind)}get isIP(){return!!this._def.checks.find(e=>"ip"===e.kind)}get isCIDR(){return!!this._def.checks.find(e=>"cidr"===e.kind)}get isBase64(){return!!this._def.checks.find(e=>"base64"===e.kind)}get isBase64url(){return!!this._def.checks.find(e=>"base64url"===e.kind)}get minLength(){let e=null;for(const t of this._def.checks)"min"===t.kind&&(null===e||t.value>e)&&(e=t.value);return e}get maxLength(){let e=null;for(const t of this._def.checks)"max"===t.kind&&(null===e||t.value<e)&&(e=t.value);return e}}function Yn(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}Gn.create=e=>new Gn({checks:[],typeName:Cr.ZodString,coerce:e?.coerce??!1,...Sn(e)});class Qn extends kn{constructor(){super(...arguments),this.min=this.gte,this.max=this.lte,this.step=this.multipleOf}_parse(e){this._def.coerce&&(e.data=Number(e.data));if(this._getType(e)!==on.number){const t=this._getOrReturnCtx(e);return hn(t,{code:un.invalid_type,expected:on.number,received:t.parsedType}),pn}let t;const n=new ln;for(const r of this._def.checks)if("int"===r.kind)rn.isInteger(e.data)||(t=this._getOrReturnCtx(e,t),hn(t,{code:un.invalid_type,expected:"integer",received:"float",message:r.message}),n.dirty());else if("min"===r.kind){(r.inclusive?e.data<r.value:e.data<=r.value)&&(t=this._getOrReturnCtx(e,t),hn(t,{code:un.too_small,minimum:r.value,type:"number",inclusive:r.inclusive,exact:!1,message:r.message}),n.dirty())}else if("max"===r.kind){(r.inclusive?e.data>r.value:e.data>=r.value)&&(t=this._getOrReturnCtx(e,t),hn(t,{code:un.too_big,maximum:r.value,type:"number",inclusive:r.inclusive,exact:!1,message:r.message}),n.dirty())}else"multipleOf"===r.kind?0!==Yn(e.data,r.value)&&(t=this._getOrReturnCtx(e,t),hn(t,{code:un.not_multiple_of,multipleOf:r.value,message:r.message}),n.dirty()):"finite"===r.kind?Number.isFinite(e.data)||(t=this._getOrReturnCtx(e,t),hn(t,{code:un.not_finite,message:r.message}),n.dirty()):rn.assertNever(r);return{status:n.value,value:e.data}}gte(e,t){return this.setLimit("min",e,!0,bn.toString(t))}gt(e,t){return this.setLimit("min",e,!1,bn.toString(t))}lte(e,t){return this.setLimit("max",e,!0,bn.toString(t))}lt(e,t){return this.setLimit("max",e,!1,bn.toString(t))}setLimit(e,t,n,r){return new Qn({...this._def,checks:[...this._def.checks,{kind:e,value:t,inclusive:n,message:bn.toString(r)}]})}_addCheck(e){return new Qn({...this._def,checks:[...this._def.checks,e]})}int(e){return this._addCheck({kind:"int",message:bn.toString(e)})}positive(e){return this._addCheck({kind:"min",value:0,inclusive:!1,message:bn.toString(e)})}negative(e){return this._addCheck({kind:"max",value:0,inclusive:!1,message:bn.toString(e)})}nonpositive(e){return this._addCheck({kind:"max",value:0,inclusive:!0,message:bn.toString(e)})}nonnegative(e){return this._addCheck({kind:"min",value:0,inclusive:!0,message:bn.toString(e)})}multipleOf(e,t){return this._addCheck({kind:"multipleOf",value:e,message:bn.toString(t)})}finite(e){return this._addCheck({kind:"finite",message:bn.toString(e)})}safe(e){return this._addCheck({kind:"min",inclusive:!0,value:Number.MIN_SAFE_INTEGER,message:bn.toString(e)})._addCheck({kind:"max",inclusive:!0,value:Number.MAX_SAFE_INTEGER,message:bn.toString(e)})}get minValue(){let e=null;for(const t of this._def.checks)"min"===t.kind&&(null===e||t.value>e)&&(e=t.value);return e}get maxValue(){let e=null;for(const t of this._def.checks)"max"===t.kind&&(null===e||t.value<e)&&(e=t.value);return e}get isInt(){return!!this._def.checks.find(e=>"int"===e.kind||"multipleOf"===e.kind&&rn.isInteger(e.value))}get isFinite(){let e=null,t=null;for(const n of this._def.checks){if("finite"===n.kind||"int"===n.kind||"multipleOf"===n.kind)return!0;"min"===n.kind?(null===t||n.value>t)&&(t=n.value):"max"===n.kind&&(null===e||n.value<e)&&(e=n.value)}return Number.isFinite(t)&&Number.isFinite(e)}}Qn.create=e=>new Qn({checks:[],typeName:Cr.ZodNumber,coerce:e?.coerce||!1,...Sn(e)});class Xn extends kn{constructor(){super(...arguments),this.min=this.gte,this.max=this.lte}_parse(e){if(this._def.coerce)try{e.data=BigInt(e.data)}catch{return this._getInvalidInput(e)}if(this._getType(e)!==on.bigint)return this._getInvalidInput(e);let t;const n=new ln;for(const r of this._def.checks)if("min"===r.kind){(r.inclusive?e.data<r.value:e.data<=r.value)&&(t=this._getOrReturnCtx(e,t),hn(t,{code:un.too_small,type:"bigint",minimum:r.value,inclusive:r.inclusive,message:r.message}),n.dirty())}else if("max"===r.kind){(r.inclusive?e.data>r.value:e.data>=r.value)&&(t=this._getOrReturnCtx(e,t),hn(t,{code:un.too_big,type:"bigint",maximum:r.value,inclusive:r.inclusive,message:r.message}),n.dirty())}else"multipleOf"===r.kind?e.data%r.value!==BigInt(0)&&(t=this._getOrReturnCtx(e,t),hn(t,{code:un.not_multiple_of,multipleOf:r.value,message:r.message}),n.dirty()):rn.assertNever(r);return{status:n.value,value:e.data}}_getInvalidInput(e){const t=this._getOrReturnCtx(e);return hn(t,{code:un.invalid_type,expected:on.bigint,received:t.parsedType}),pn}gte(e,t){return this.setLimit("min",e,!0,bn.toString(t))}gt(e,t){return this.setLimit("min",e,!1,bn.toString(t))}lte(e,t){return this.setLimit("max",e,!0,bn.toString(t))}lt(e,t){return this.setLimit("max",e,!1,bn.toString(t))}setLimit(e,t,n,r){return new Xn({...this._def,checks:[...this._def.checks,{kind:e,value:t,inclusive:n,message:bn.toString(r)}]})}_addCheck(e){return new Xn({...this._def,checks:[...this._def.checks,e]})}positive(e){return this._addCheck({kind:"min",value:BigInt(0),inclusive:!1,message:bn.toString(e)})}negative(e){return this._addCheck({kind:"max",value:BigInt(0),inclusive:!1,message:bn.toString(e)})}nonpositive(e){return this._addCheck({kind:"max",value:BigInt(0),inclusive:!0,message:bn.toString(e)})}nonnegative(e){return this._addCheck({kind:"min",value:BigInt(0),inclusive:!0,message:bn.toString(e)})}multipleOf(e,t){return this._addCheck({kind:"multipleOf",value:e,message:bn.toString(t)})}get minValue(){let e=null;for(const t of this._def.checks)"min"===t.kind&&(null===e||t.value>e)&&(e=t.value);return e}get maxValue(){let e=null;for(const t of this._def.checks)"max"===t.kind&&(null===e||t.value<e)&&(e=t.value);return e}}Xn.create=e=>new Xn({checks:[],typeName:Cr.ZodBigInt,coerce:e?.coerce??!1,...Sn(e)});class Jn extends kn{_parse(e){this._def.coerce&&(e.data=Boolean(e.data));if(this._getType(e)!==on.boolean){const t=this._getOrReturnCtx(e);return hn(t,{code:un.invalid_type,expected:on.boolean,received:t.parsedType}),pn}return mn(e.data)}}Jn.create=e=>new Jn({typeName:Cr.ZodBoolean,coerce:e?.coerce||!1,...Sn(e)});class er extends kn{_parse(e){this._def.coerce&&(e.data=new Date(e.data));if(this._getType(e)!==on.date){const t=this._getOrReturnCtx(e);return hn(t,{code:un.invalid_type,expected:on.date,received:t.parsedType}),pn}if(Number.isNaN(e.data.getTime())){return hn(this._getOrReturnCtx(e),{code:un.invalid_date}),pn}const t=new ln;let n;for(const r of this._def.checks)"min"===r.kind?e.data.getTime()<r.value&&(n=this._getOrReturnCtx(e,n),hn(n,{code:un.too_small,message:r.message,inclusive:!0,exact:!1,minimum:r.value,type:"date"}),t.dirty()):"max"===r.kind?e.data.getTime()>r.value&&(n=this._getOrReturnCtx(e,n),hn(n,{code:un.too_big,message:r.message,inclusive:!0,exact:!1,maximum:r.value,type:"date"}),t.dirty()):rn.assertNever(r);return{status:t.value,value:new Date(e.data.getTime())}}_addCheck(e){return new er({...this._def,checks:[...this._def.checks,e]})}min(e,t){return this._addCheck({kind:"min",value:e.getTime(),message:bn.toString(t)})}max(e,t){return this._addCheck({kind:"max",value:e.getTime(),message:bn.toString(t)})}get minDate(){let e=null;for(const t of this._def.checks)"min"===t.kind&&(null===e||t.value>e)&&(e=t.value);return null!=e?new Date(e):null}get maxDate(){let e=null;for(const t of this._def.checks)"max"===t.kind&&(null===e||t.value<e)&&(e=t.value);return null!=e?new Date(e):null}}er.create=e=>new er({checks:[],coerce:e?.coerce||!1,typeName:Cr.ZodDate,...Sn(e)});class tr extends kn{_parse(e){if(this._getType(e)!==on.symbol){const t=this._getOrReturnCtx(e);return hn(t,{code:un.invalid_type,expected:on.symbol,received:t.parsedType}),pn}return mn(e.data)}}tr.create=e=>new tr({typeName:Cr.ZodSymbol,...Sn(e)});class nr extends kn{_parse(e){if(this._getType(e)!==on.undefined){const t=this._getOrReturnCtx(e);return hn(t,{code:un.invalid_type,expected:on.undefined,received:t.parsedType}),pn}return mn(e.data)}}nr.create=e=>new nr({typeName:Cr.ZodUndefined,...Sn(e)});class rr extends kn{_parse(e){if(this._getType(e)!==on.null){const t=this._getOrReturnCtx(e);return hn(t,{code:un.invalid_type,expected:on.null,received:t.parsedType}),pn}return mn(e.data)}}rr.create=e=>new rr({typeName:Cr.ZodNull,...Sn(e)});class ir extends kn{constructor(){super(...arguments),this._any=!0}_parse(e){return mn(e.data)}}ir.create=e=>new ir({typeName:Cr.ZodAny,...Sn(e)});class sr extends kn{constructor(){super(...arguments),this._unknown=!0}_parse(e){return mn(e.data)}}sr.create=e=>new sr({typeName:Cr.ZodUnknown,...Sn(e)});class or extends kn{_parse(e){const t=this._getOrReturnCtx(e);return hn(t,{code:un.invalid_type,expected:on.never,received:t.parsedType}),pn}}or.create=e=>new or({typeName:Cr.ZodNever,...Sn(e)});class ar extends kn{_parse(e){if(this._getType(e)!==on.undefined){const t=this._getOrReturnCtx(e);return hn(t,{code:un.invalid_type,expected:on.void,received:t.parsedType}),pn}return mn(e.data)}}ar.create=e=>new ar({typeName:Cr.ZodVoid,...Sn(e)});class ur extends kn{_parse(e){const{ctx:t,status:n}=this._processInputParams(e),r=this._def;if(t.parsedType!==on.array)return hn(t,{code:un.invalid_type,expected:on.array,received:t.parsedType}),pn;if(null!==r.exactLength){const e=t.data.length>r.exactLength.value,i=t.data.length<r.exactLength.value;(e||i)&&(hn(t,{code:e?un.too_big:un.too_small,minimum:i?r.exactLength.value:void 0,maximum:e?r.exactLength.value:void 0,type:"array",inclusive:!0,exact:!0,message:r.exactLength.message}),n.dirty())}if(null!==r.minLength&&t.data.length<r.minLength.value&&(hn(t,{code:un.too_small,minimum:r.minLength.value,type:"array",inclusive:!0,exact:!1,message:r.minLength.message}),n.dirty()),null!==r.maxLength&&t.data.length>r.maxLength.value&&(hn(t,{code:un.too_big,maximum:r.maxLength.value,type:"array",inclusive:!0,exact:!1,message:r.maxLength.message}),n.dirty()),t.common.async)return Promise.all([...t.data].map((e,n)=>r.type._parseAsync(new En(t,e,t.path,n)))).then(e=>ln.mergeArray(n,e));const i=[...t.data].map((e,n)=>r.type._parseSync(new En(t,e,t.path,n)));return ln.mergeArray(n,i)}get element(){return this._def.type}min(e,t){return new ur({...this._def,minLength:{value:e,message:bn.toString(t)}})}max(e,t){return new ur({...this._def,maxLength:{value:e,message:bn.toString(t)}})}length(e,t){return new ur({...this._def,exactLength:{value:e,message:bn.toString(t)}})}nonempty(e){return this.min(1,e)}}function cr(e){if(e instanceof dr){const t={};for(const n in e.shape){const r=e.shape[n];t[n]=kr.create(cr(r))}return new dr({...e._def,shape:()=>t})}return e instanceof ur?new ur({...e._def,type:cr(e.element)}):e instanceof kr?kr.create(cr(e.unwrap())):e instanceof Or?Or.create(cr(e.unwrap())):e instanceof pr?pr.create(e.items.map(e=>cr(e))):e}ur.create=(e,t)=>new ur({type:e,minLength:null,maxLength:null,exactLength:null,typeName:Cr.ZodArray,...Sn(t)});class dr extends kn{constructor(){super(...arguments),this._cached=null,this.nonstrict=this.passthrough,this.augment=this.extend}_getCached(){if(null!==this._cached)return this._cached;const e=this._def.shape(),t=rn.objectKeys(e);return this._cached={shape:e,keys:t},this._cached}_parse(e){if(this._getType(e)!==on.object){const t=this._getOrReturnCtx(e);return hn(t,{code:un.invalid_type,expected:on.object,received:t.parsedType}),pn}const{status:t,ctx:n}=this._processInputParams(e),{shape:r,keys:i}=this._getCached(),s=[];if(!(this._def.catchall instanceof or&&"strip"===this._def.unknownKeys))for(const e in n.data)i.includes(e)||s.push(e);const o=[];for(const e of i){const t=r[e],i=n.data[e];o.push({key:{status:"valid",value:e},value:t._parse(new En(n,i,n.path,e)),alwaysSet:e in n.data})}if(this._def.catchall instanceof or){const e=this._def.unknownKeys;if("passthrough"===e)for(const e of s)o.push({key:{status:"valid",value:e},value:{status:"valid",value:n.data[e]}});else if("strict"===e)s.length>0&&(hn(n,{code:un.unrecognized_keys,keys:s}),t.dirty());else if("strip"!==e)throw new Error("Internal ZodObject error: invalid unknownKeys value.")}else{const e=this._def.catchall;for(const t of s){const r=n.data[t];o.push({key:{status:"valid",value:t},value:e._parse(new En(n,r,n.path,t)),alwaysSet:t in n.data})}}return n.common.async?Promise.resolve().then(async()=>{const e=[];for(const t of o){const n=await t.key,r=await t.value;e.push({key:n,value:r,alwaysSet:t.alwaysSet})}return e}).then(e=>ln.mergeObjectSync(t,e)):ln.mergeObjectSync(t,o)}get shape(){return this._def.shape()}strict(e){return new dr({...this._def,unknownKeys:"strict",...void 0!==e?{errorMap:(t,n)=>{const r=this._def.errorMap?.(t,n).message??n.defaultError;return"unrecognized_keys"===t.code?{message:bn.errToObj(e).message??r}:{message:r}}}:{}})}strip(){return new dr({...this._def,unknownKeys:"strip"})}passthrough(){return new dr({...this._def,unknownKeys:"passthrough"})}extend(e){return new dr({...this._def,shape:()=>({...this._def.shape(),...e})})}merge(e){return new dr({unknownKeys:e._def.unknownKeys,catchall:e._def.catchall,shape:()=>({...this._def.shape(),...e._def.shape()}),typeName:Cr.ZodObject})}setKey(e,t){return this.augment({[e]:t})}catchall(e){return new dr({...this._def,catchall:e})}pick(e){const t={};for(const n of rn.objectKeys(e))e[n]&&this.shape[n]&&(t[n]=this.shape[n]);return new dr({...this._def,shape:()=>t})}omit(e){const t={};for(const n of rn.objectKeys(this.shape))e[n]||(t[n]=this.shape[n]);return new dr({...this._def,shape:()=>t})}deepPartial(){return cr(this)}partial(e){const t={};for(const n of rn.objectKeys(this.shape)){const r=this.shape[n];e&&!e[n]?t[n]=r:t[n]=r.optional()}return new dr({...this._def,shape:()=>t})}required(e){const t={};for(const n of rn.objectKeys(this.shape))if(e&&!e[n])t[n]=this.shape[n];else{let e=this.shape[n];for(;e instanceof kr;)e=e._def.innerType;t[n]=e}return new dr({...this._def,shape:()=>t})}keyof(){return _r(rn.objectKeys(this.shape))}}dr.create=(e,t)=>new dr({shape:()=>e,unknownKeys:"strip",catchall:or.create(),typeName:Cr.ZodObject,...Sn(t)}),dr.strictCreate=(e,t)=>new dr({shape:()=>e,unknownKeys:"strict",catchall:or.create(),typeName:Cr.ZodObject,...Sn(t)}),dr.lazycreate=(e,t)=>new dr({shape:e,unknownKeys:"strip",catchall:or.create(),typeName:Cr.ZodObject,...Sn(t)});class fr extends kn{_parse(e){const{ctx:t}=this._processInputParams(e),n=this._def.options;if(t.common.async)return Promise.all(n.map(async e=>{const n={...t,common:{...t.common,issues:[]},parent:null};return{result:await e._parseAsync({data:t.data,path:t.path,parent:n}),ctx:n}})).then(function(e){for(const t of e)if("valid"===t.result.status)return t.result;for(const n of e)if("dirty"===n.result.status)return t.common.issues.push(...n.ctx.common.issues),n.result;const n=e.map(e=>new cn(e.ctx.common.issues));return hn(t,{code:un.invalid_union,unionErrors:n}),pn});{let e;const r=[];for(const i of n){const n={...t,common:{...t.common,issues:[]},parent:null},s=i._parseSync({data:t.data,path:t.path,parent:n});if("valid"===s.status)return s;"dirty"!==s.status||e||(e={result:s,ctx:n}),n.common.issues.length&&r.push(n.common.issues)}if(e)return t.common.issues.push(...e.ctx.common.issues),e.result;const i=r.map(e=>new cn(e));return hn(t,{code:un.invalid_union,unionErrors:i}),pn}}get options(){return this._def.options}}function hr(e,t){const n=an(e),r=an(t);if(e===t)return{valid:!0,data:e};if(n===on.object&&r===on.object){const n=rn.objectKeys(t),r=rn.objectKeys(e).filter(e=>-1!==n.indexOf(e)),i={...e,...t};for(const n of r){const r=hr(e[n],t[n]);if(!r.valid)return{valid:!1};i[n]=r.data}return{valid:!0,data:i}}if(n===on.array&&r===on.array){if(e.length!==t.length)return{valid:!1};const n=[];for(let r=0;r<e.length;r++){const i=hr(e[r],t[r]);if(!i.valid)return{valid:!1};n.push(i.data)}return{valid:!0,data:n}}return n===on.date&&r===on.date&&+e===+t?{valid:!0,data:e}:{valid:!1}}fr.create=(e,t)=>new fr({options:e,typeName:Cr.ZodUnion,...Sn(t)});class lr extends kn{_parse(e){const{status:t,ctx:n}=this._processInputParams(e),r=(e,r)=>{if(yn(e)||yn(r))return pn;const i=hr(e.value,r.value);return i.valid?((wn(e)||wn(r))&&t.dirty(),{status:t.value,value:i.data}):(hn(n,{code:un.invalid_intersection_types}),pn)};return n.common.async?Promise.all([this._def.left._parseAsync({data:n.data,path:n.path,parent:n}),this._def.right._parseAsync({data:n.data,path:n.path,parent:n})]).then(([e,t])=>r(e,t)):r(this._def.left._parseSync({data:n.data,path:n.path,parent:n}),this._def.right._parseSync({data:n.data,path:n.path,parent:n}))}}lr.create=(e,t,n)=>new lr({left:e,right:t,typeName:Cr.ZodIntersection,...Sn(n)});class pr extends kn{_parse(e){const{status:t,ctx:n}=this._processInputParams(e);if(n.parsedType!==on.array)return hn(n,{code:un.invalid_type,expected:on.array,received:n.parsedType}),pn;if(n.data.length<this._def.items.length)return hn(n,{code:un.too_small,minimum:this._def.items.length,inclusive:!0,exact:!1,type:"array"}),pn;!this._def.rest&&n.data.length>this._def.items.length&&(hn(n,{code:un.too_big,maximum:this._def.items.length,inclusive:!0,exact:!1,type:"array"}),t.dirty());const r=[...n.data].map((e,t)=>{const r=this._def.items[t]||this._def.rest;return r?r._parse(new En(n,e,n.path,t)):null}).filter(e=>!!e);return n.common.async?Promise.all(r).then(e=>ln.mergeArray(t,e)):ln.mergeArray(t,r)}get items(){return this._def.items}rest(e){return new pr({...this._def,rest:e})}}pr.create=(e,t)=>{if(!Array.isArray(e))throw new Error("You must pass an array of schemas to z.tuple([ ... ])");return new pr({items:e,typeName:Cr.ZodTuple,rest:null,...Sn(t)})};class gr extends kn{get keySchema(){return this._def.keyType}get valueSchema(){return this._def.valueType}_parse(e){const{status:t,ctx:n}=this._processInputParams(e);if(n.parsedType!==on.object)return hn(n,{code:un.invalid_type,expected:on.object,received:n.parsedType}),pn;const r=[],i=this._def.keyType,s=this._def.valueType;for(const e in n.data)r.push({key:i._parse(new En(n,e,n.path,e)),value:s._parse(new En(n,n.data[e],n.path,e)),alwaysSet:e in n.data});return n.common.async?ln.mergeObjectAsync(t,r):ln.mergeObjectSync(t,r)}get element(){return this._def.valueType}static create(e,t,n){return new gr(t instanceof kn?{keyType:e,valueType:t,typeName:Cr.ZodRecord,...Sn(n)}:{keyType:Gn.create(),valueType:e,typeName:Cr.ZodRecord,...Sn(t)})}}class mr extends kn{get keySchema(){return this._def.keyType}get valueSchema(){return this._def.valueType}_parse(e){const{status:t,ctx:n}=this._processInputParams(e);if(n.parsedType!==on.map)return hn(n,{code:un.invalid_type,expected:on.map,received:n.parsedType}),pn;const r=this._def.keyType,i=this._def.valueType,s=[...n.data.entries()].map(([e,t],s)=>({key:r._parse(new En(n,e,n.path,[s,"key"])),value:i._parse(new En(n,t,n.path,[s,"value"]))}));if(n.common.async){const e=new Map;return Promise.resolve().then(async()=>{for(const n of s){const r=await n.key,i=await n.value;if("aborted"===r.status||"aborted"===i.status)return pn;"dirty"!==r.status&&"dirty"!==i.status||t.dirty(),e.set(r.value,i.value)}return{status:t.value,value:e}})}{const e=new Map;for(const n of s){const r=n.key,i=n.value;if("aborted"===r.status||"aborted"===i.status)return pn;"dirty"!==r.status&&"dirty"!==i.status||t.dirty(),e.set(r.value,i.value)}return{status:t.value,value:e}}}}mr.create=(e,t,n)=>new mr({valueType:t,keyType:e,typeName:Cr.ZodMap,...Sn(n)});class yr extends kn{_parse(e){const{status:t,ctx:n}=this._processInputParams(e);if(n.parsedType!==on.set)return hn(n,{code:un.invalid_type,expected:on.set,received:n.parsedType}),pn;const r=this._def;null!==r.minSize&&n.data.size<r.minSize.value&&(hn(n,{code:un.too_small,minimum:r.minSize.value,type:"set",inclusive:!0,exact:!1,message:r.minSize.message}),t.dirty()),null!==r.maxSize&&n.data.size>r.maxSize.value&&(hn(n,{code:un.too_big,maximum:r.maxSize.value,type:"set",inclusive:!0,exact:!1,message:r.maxSize.message}),t.dirty());const i=this._def.valueType;function s(e){const n=new Set;for(const r of e){if("aborted"===r.status)return pn;"dirty"===r.status&&t.dirty(),n.add(r.value)}return{status:t.value,value:n}}const o=[...n.data.values()].map((e,t)=>i._parse(new En(n,e,n.path,t)));return n.common.async?Promise.all(o).then(e=>s(e)):s(o)}min(e,t){return new yr({...this._def,minSize:{value:e,message:bn.toString(t)}})}max(e,t){return new yr({...this._def,maxSize:{value:e,message:bn.toString(t)}})}size(e,t){return this.min(e,t).max(e,t)}nonempty(e){return this.min(1,e)}}yr.create=(e,t)=>new yr({valueType:e,minSize:null,maxSize:null,typeName:Cr.ZodSet,...Sn(t)});class wr extends kn{get schema(){return this._def.getter()}_parse(e){const{ctx:t}=this._processInputParams(e);return this._def.getter()._parse({data:t.data,path:t.path,parent:t})}}wr.create=(e,t)=>new wr({getter:e,typeName:Cr.ZodLazy,...Sn(t)});class vr extends kn{_parse(e){if(e.data!==this._def.value){const t=this._getOrReturnCtx(e);return hn(t,{received:t.data,code:un.invalid_literal,expected:this._def.value}),pn}return{status:"valid",value:e.data}}get value(){return this._def.value}}function _r(e,t){return new br({values:e,typeName:Cr.ZodEnum,...Sn(t)})}vr.create=(e,t)=>new vr({value:e,typeName:Cr.ZodLiteral,...Sn(t)});class br extends kn{_parse(e){if("string"!=typeof e.data){const t=this._getOrReturnCtx(e),n=this._def.values;return hn(t,{expected:rn.joinValues(n),received:t.parsedType,code:un.invalid_type}),pn}if(this._cache||(this._cache=new Set(this._def.values)),!this._cache.has(e.data)){const t=this._getOrReturnCtx(e),n=this._def.values;return hn(t,{received:t.data,code:un.invalid_enum_value,options:n}),pn}return mn(e.data)}get options(){return this._def.values}get enum(){const e={};for(const t of this._def.values)e[t]=t;return e}get Values(){const e={};for(const t of this._def.values)e[t]=t;return e}get Enum(){const e={};for(const t of this._def.values)e[t]=t;return e}extract(e,t=this._def){return br.create(e,{...this._def,...t})}exclude(e,t=this._def){return br.create(this.options.filter(t=>!e.includes(t)),{...this._def,...t})}}br.create=_r;class Er extends kn{_parse(e){const t=rn.getValidEnumValues(this._def.values),n=this._getOrReturnCtx(e);if(n.parsedType!==on.string&&n.parsedType!==on.number){const e=rn.objectValues(t);return hn(n,{expected:rn.joinValues(e),received:n.parsedType,code:un.invalid_type}),pn}if(this._cache||(this._cache=new Set(rn.getValidEnumValues(this._def.values))),!this._cache.has(e.data)){const e=rn.objectValues(t);return hn(n,{received:n.data,code:un.invalid_enum_value,options:e}),pn}return mn(e.data)}get enum(){return this._def.values}}Er.create=(e,t)=>new Er({values:e,typeName:Cr.ZodNativeEnum,...Sn(t)});class xr extends kn{unwrap(){return this._def.type}_parse(e){const{ctx:t}=this._processInputParams(e);if(t.parsedType!==on.promise&&!1===t.common.async)return hn(t,{code:un.invalid_type,expected:on.promise,received:t.parsedType}),pn;const n=t.parsedType===on.promise?t.data:Promise.resolve(t.data);return mn(n.then(e=>this._def.type.parseAsync(e,{path:t.path,errorMap:t.common.contextualErrorMap})))}}xr.create=(e,t)=>new xr({type:e,typeName:Cr.ZodPromise,...Sn(t)});class Sr extends kn{innerType(){return this._def.schema}sourceType(){return this._def.schema._def.typeName===Cr.ZodEffects?this._def.schema.sourceType():this._def.schema}_parse(e){const{status:t,ctx:n}=this._processInputParams(e),r=this._def.effect||null,i={addIssue:e=>{hn(n,e),e.fatal?t.abort():t.dirty()},get path(){return n.path}};if(i.addIssue=i.addIssue.bind(i),"preprocess"===r.type){const e=r.transform(n.data,i);if(n.common.async)return Promise.resolve(e).then(async e=>{if("aborted"===t.value)return pn;const r=await this._def.schema._parseAsync({data:e,path:n.path,parent:n});return"aborted"===r.status?pn:"dirty"===r.status||"dirty"===t.value?gn(r.value):r});{if("aborted"===t.value)return pn;const r=this._def.schema._parseSync({data:e,path:n.path,parent:n});return"aborted"===r.status?pn:"dirty"===r.status||"dirty"===t.value?gn(r.value):r}}if("refinement"===r.type){const e=e=>{const t=r.refinement(e,i);if(n.common.async)return Promise.resolve(t);if(t instanceof Promise)throw new Error("Async refinement encountered during synchronous parse operation. Use .parseAsync instead.");return e};if(!1===n.common.async){const r=this._def.schema._parseSync({data:n.data,path:n.path,parent:n});return"aborted"===r.status?pn:("dirty"===r.status&&t.dirty(),e(r.value),{status:t.value,value:r.value})}return this._def.schema._parseAsync({data:n.data,path:n.path,parent:n}).then(n=>"aborted"===n.status?pn:("dirty"===n.status&&t.dirty(),e(n.value).then(()=>({status:t.value,value:n.value}))))}if("transform"===r.type){if(!1===n.common.async){const e=this._def.schema._parseSync({data:n.data,path:n.path,parent:n});if(!vn(e))return pn;const s=r.transform(e.value,i);if(s instanceof Promise)throw new Error("Asynchronous transform encountered during synchronous parse operation. Use .parseAsync instead.");return{status:t.value,value:s}}return this._def.schema._parseAsync({data:n.data,path:n.path,parent:n}).then(e=>vn(e)?Promise.resolve(r.transform(e.value,i)).then(e=>({status:t.value,value:e})):pn)}rn.assertNever(r)}}Sr.create=(e,t,n)=>new Sr({schema:e,typeName:Cr.ZodEffects,effect:t,...Sn(n)}),Sr.createWithPreprocess=(e,t,n)=>new Sr({schema:t,effect:{type:"preprocess",transform:e},typeName:Cr.ZodEffects,...Sn(n)});class kr extends kn{_parse(e){return this._getType(e)===on.undefined?mn(void 0):this._def.innerType._parse(e)}unwrap(){return this._def.innerType}}kr.create=(e,t)=>new kr({innerType:e,typeName:Cr.ZodOptional,...Sn(t)});class Or extends kn{_parse(e){return this._getType(e)===on.null?mn(null):this._def.innerType._parse(e)}unwrap(){return this._def.innerType}}Or.create=(e,t)=>new Or({innerType:e,typeName:Cr.ZodNullable,...Sn(t)});class Ar extends kn{_parse(e){const{ctx:t}=this._processInputParams(e);let n=t.data;return t.parsedType===on.undefined&&(n=this._def.defaultValue()),this._def.innerType._parse({data:n,path:t.path,parent:t})}removeDefault(){return this._def.innerType}}Ar.create=(e,t)=>new Ar({innerType:e,typeName:Cr.ZodDefault,defaultValue:"function"==typeof t.default?t.default:()=>t.default,...Sn(t)});class Pr extends kn{_parse(e){const{ctx:t}=this._processInputParams(e),n={...t,common:{...t.common,issues:[]}},r=this._def.innerType._parse({data:n.data,path:n.path,parent:{...n}});return _n(r)?r.then(e=>({status:"valid",value:"valid"===e.status?e.value:this._def.catchValue({get error(){return new cn(n.common.issues)},input:n.data})})):{status:"valid",value:"valid"===r.status?r.value:this._def.catchValue({get error(){return new cn(n.common.issues)},input:n.data})}}removeCatch(){return this._def.innerType}}Pr.create=(e,t)=>new Pr({innerType:e,typeName:Cr.ZodCatch,catchValue:"function"==typeof t.catch?t.catch:()=>t.catch,...Sn(t)});class Tr extends kn{_parse(e){if(this._getType(e)!==on.nan){const t=this._getOrReturnCtx(e);return hn(t,{code:un.invalid_type,expected:on.nan,received:t.parsedType}),pn}return{status:"valid",value:e.data}}}Tr.create=e=>new Tr({typeName:Cr.ZodNaN,...Sn(e)});class Ir extends kn{_parse(e){const{ctx:t}=this._processInputParams(e),n=t.data;return this._def.type._parse({data:n,path:t.path,parent:t})}unwrap(){return this._def.type}}class Nr extends kn{_parse(e){const{status:t,ctx:n}=this._processInputParams(e);if(n.common.async){return(async()=>{const e=await this._def.in._parseAsync({data:n.data,path:n.path,parent:n});return"aborted"===e.status?pn:"dirty"===e.status?(t.dirty(),gn(e.value)):this._def.out._parseAsync({data:e.value,path:n.path,parent:n})})()}{const e=this._def.in._parseSync({data:n.data,path:n.path,parent:n});return"aborted"===e.status?pn:"dirty"===e.status?(t.dirty(),{status:"dirty",value:e.value}):this._def.out._parseSync({data:e.value,path:n.path,parent:n})}}static create(e,t){return new Nr({in:e,out:t,typeName:Cr.ZodPipeline})}}class $r extends kn{_parse(e){const t=this._def.innerType._parse(e),n=e=>(vn(e)&&(e.value=Object.freeze(e.value)),e);return _n(t)?t.then(e=>n(e)):n(t)}unwrap(){return this._def.innerType}}function Ur(e,t){const n="function"==typeof e?e(t):"string"==typeof e?{message:e}:e;return"string"==typeof n?{message:n}:n}var Cr;$r.create=(e,t)=>new $r({innerType:e,typeName:Cr.ZodReadonly,...Sn(t)}),function(e){e.ZodString="ZodString",e.ZodNumber="ZodNumber",e.ZodNaN="ZodNaN",e.ZodBigInt="ZodBigInt",e.ZodBoolean="ZodBoolean",e.ZodDate="ZodDate",e.ZodSymbol="ZodSymbol",e.ZodUndefined="ZodUndefined",e.ZodNull="ZodNull",e.ZodAny="ZodAny",e.ZodUnknown="ZodUnknown",e.ZodNever="ZodNever",e.ZodVoid="ZodVoid",e.ZodArray="ZodArray",e.ZodObject="ZodObject",e.ZodUnion="ZodUnion",e.ZodDiscriminatedUnion="ZodDiscriminatedUnion",e.ZodIntersection="ZodIntersection",e.ZodTuple="ZodTuple",e.ZodRecord="ZodRecord",e.ZodMap="ZodMap",e.ZodSet="ZodSet",e.ZodFunction="ZodFunction",e.ZodLazy="ZodLazy",e.ZodLiteral="ZodLiteral",e.ZodEnum="ZodEnum",e.ZodEffects="ZodEffects",e.ZodNativeEnum="ZodNativeEnum",e.ZodOptional="ZodOptional",e.ZodNullable="ZodNullable",e.ZodDefault="ZodDefault",e.ZodCatch="ZodCatch",e.ZodPromise="ZodPromise",e.ZodBranded="ZodBranded",e.ZodPipeline="ZodPipeline",e.ZodReadonly="ZodReadonly"}(Cr||(Cr={}));const Br=Gn.create,Rr=Qn.create,Lr=Xn.create,zr=Jn.create,jr=er.create,Hr=rr.create,Dr=ir.create,Fr=ur.create,Vr=dr.create,Zr=fr.create,Kr=gr.create,Wr=wr.create;Lr(),zr(),jr();const Mr=Rr().min(Number.MIN_SAFE_INTEGER).max(Number.MAX_SAFE_INTEGER).int(),qr=((e,t={message:`Input not instance of ${e.name}`})=>function(e,t={},n){return e?ir.create().superRefine((r,i)=>{const s=e(r);if(s instanceof Promise)return s.then(e=>{if(!e){const e=Ur(t,r),s=e.fatal??n??!0;i.addIssue({code:"custom",...e,fatal:s})}});if(!s){const e=Ur(t,r),s=e.fatal??n??!0;i.addIssue({code:"custom",...e,fatal:s})}}):ir.create()}(t=>t instanceof e,t))(Uint8Array);Br(),Mr.min(5e8),Dr(),Mr.min(0).max(255),Mr.min(0).max(65535);const Gr=Mr.min(0).max(4294967295);Rr().refine(e=>String(e).includes(".")).refine(e=>{const t=String(e).split(".").at(1);return void 0!==t&&t.length<=2});const Yr=Br().regex(/^[0-9a-fA-F]*$/).refine(e=>e.length%2==0),Qr=Zr([Br(),Rr(),zr(),Hr()]),Xr=Wr(()=>Zr([Qr,Fr(Xr),Kr(Xr)]));qr.refine(e=>20===e.length);const Jr=qr.refine(e=>32===e.length),ei=qr.refine(e=>33===e.length),ti=qr.refine(e=>64===e.length);Yr.refine(e=>40===e.length);const ni=Yr.refine(e=>64===e.length),ri=Yr.refine(e=>66===e.length),ii=Yr.refine(e=>128===e.length);Zr([Yr,qr]);const si=Zr([ni,Jr]);
12
+ const dt={p:BigInt("0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f"),n:BigInt("0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141"),h:BigInt(1),a:BigInt(0),b:BigInt(7),Gx:BigInt("0x79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798"),Gy:BigInt("0x483ada7726a3c4655da4fbfc0e1108a8fd17b448a68554199c47d08ffb10d4b8")},ft=BigInt(0),lt=BigInt(1),ht=BigInt(2),pt=(e,t)=>(e+t/ht)/t;function mt(e){const t=dt.p,n=BigInt(3),r=BigInt(6),i=BigInt(11),s=BigInt(22),o=BigInt(23),a=BigInt(44),u=BigInt(88),c=e*e*e%t,d=c*c*e%t,f=Ae(d,n,t)*d%t,l=Ae(f,n,t)*d%t,h=Ae(l,ht,t)*c%t,p=Ae(h,i,t)*h%t,m=Ae(p,s,t)*p%t,g=Ae(m,a,t)*m%t,y=Ae(g,u,t)*g%t,_=Ae(y,a,t)*m%t,v=Ae(_,n,t)*d%t,w=Ae(v,o,t)*p%t,b=Ae(w,r,t)*c%t,x=Ae(b,ht,t);if(!gt.eql(gt.sqr(x),e))throw new Error("Cannot find square root");return x}const gt=Be(dt.p,void 0,void 0,{sqrt:mt}),yt=function(e,t){const n=t=>ct({...e,hash:t});return{...n(t),create:n}}({...dt,Fp:gt,lowS:!0,endo:{beta:BigInt("0x7ae96a2b657c07106e64479eac3434e99cf0497512f58995c1396c28719501ee"),splitScalar:e=>{const t=dt.n,n=BigInt("0x3086d221a7d46bcde86c90e49284eb15"),r=-lt*BigInt("0xe4437ed6010e88286f547fa90abfe4c3"),i=BigInt("0x114ca50f7a8e2f3f657c1108d9d44cfd8"),s=n,o=BigInt("0x100000000000000000000000000000000"),a=pt(s*e,t),u=pt(-r*e,t);let c=Se(e-a*n-u*i,t),d=Se(-a*r-u*s,t);const f=c>o,l=d>o;if(f&&(c=t-c),l&&(d=t-d),c>o||d>o)throw new Error("splitScalar: Endomorphism failed, k="+e);return{k1neg:f,k1:c,k2neg:l,k2:d}}}},ee),_t={};function vt(e,...t){let n=_t[e];if(void 0===n){const t=ee(Uint8Array.from(e,e=>e.charCodeAt(0)));n=H(t,t),_t[e]=n}return ee(H(n,...t))}const wt=e=>e.toBytes(!0).slice(1),bt=e=>de(e,32),xt=e=>Se(e,dt.p),Et=e=>Se(e,dt.n),kt=(()=>yt.Point)(),Ot=e=>e%ht===ft;function St(e){let t=yt.utils.normPrivateKeyToScalar(e),n=kt.fromPrivateKey(t);return{scalar:Ot(n.y)?t:Et(-t),bytes:wt(n)}}function At(e){me("x",e,lt,dt.p);const t=xt(e*e);let n=mt(xt(t*e+BigInt(7)));Ot(n)||(n=xt(-n));const r=kt.fromAffine({x:e,y:n});return r.assertValidity(),r}const Pt=ue;function It(...e){return Et(Pt(vt("BIP0340/challenge",...e)))}function Tt(e){return St(e).bytes}function Nt(e,t,n=M(32)){const r=le("message",e),{bytes:i,scalar:s}=St(t),o=le("auxRand",n,32),a=bt(s^Pt(vt("BIP0340/aux",o))),u=vt("BIP0340/nonce",a,i,r),c=Et(Pt(u));if(c===ft)throw new Error("sign failed: k is zero");const{bytes:d,scalar:f}=St(c),l=It(d,i,r),h=new Uint8Array(64);if(h.set(d,0),h.set(bt(Et(f+l*s)),32),!Ct(h,r,i))throw new Error("sign: Invalid signature produced");return h}function Ct(e,t,n){const r=le("signature",e,64),i=le("message",t),s=le("publicKey",n,32);try{const e=At(Pt(s)),t=Pt(r.subarray(0,32));if(!pe(t,lt,dt.p))return!1;const n=Pt(r.subarray(32,64));if(!pe(n,lt,dt.n))return!1;const o=It(bt(t),wt(e),i),a=kt.BASE.multiplyUnsafe(n).add(e.multiplyUnsafe(Et(-o))),{x:u,y:c}=a.toAffine();return!(a.is0()||!Ot(c)||u!==t)}catch(e){return!1}}const $t=(()=>({getPublicKey:Tt,sign:Nt,verify:Ct,utils:{randomPrivateKey:yt.utils.randomPrivateKey,lift_x:At,pointToBytes:wt,numberToBytesBE:de,bytesToNumberBE:ue,taggedHash:vt,mod:Se}}))();BigInt(0),BigInt(2);Be(yt.CURVE.n,32,!0);const Rt=yt.Point.BASE;function Bt(e,t,n,r=!1){const i=jt(t).big,s=function(e){try{const t=Ut(e,"ecdsa");return yt.Point.fromHex(t)}catch(t){throw new Error("invalid pubkey: "+e)}}(e),o=Rt.multiply(i);let a=s.add(o);r&&!a.hasEvenY()&&(a=a.negate());return Ut(a.toHex(!0),n)}function Ut(e,t){try{const n=jt(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 jt(e){try{return g.bytes(e)}catch(t){throw new Error("invalid bytes: "+String(e))}}const Zt=Uint8Array.from([7,4,13,1,10,6,15,3,12,0,9,5,2,14,11,8]),zt=(()=>Uint8Array.from(new Array(16).fill(0).map((e,t)=>t)))(),Lt=(()=>zt.map(e=>(9*e+5)%16))(),Ft=(()=>{const e=[[zt],[Lt]];for(let t=0;t<4;t++)for(let n of e)n.push(n[t].map(e=>Zt[e]));return e})(),Dt=(()=>Ft[0])(),Ht=(()=>Ft[1])(),qt=[[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)),Vt=Dt.map((e,t)=>e.map(e=>qt[t][e])),Mt=Ht.map((e,t)=>e.map(e=>qt[t][e])),Kt=Uint32Array.from([0,1518500249,1859775393,2400959708,2840853838]),Wt=Uint32Array.from([1352829926,1548603684,1836072691,2053994217,0]);function Gt(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 Yt=new Uint32Array(16);class Qt extends G{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)Yt[n]=e.getUint32(t,!0);let n=0|this.h0,r=n,i=0|this.h1,s=i,o=0|this.h2,a=o,u=0|this.h3,c=u,d=0|this.h4,f=d;for(let e=0;e<5;e++){const t=4-e,l=Kt[e],h=Wt[e],p=Dt[e],m=Ht[e],g=Vt[e],y=Mt[e];for(let t=0;t<16;t++){const r=T(n+Gt(e,i,o,u)+Yt[p[t]]+l,g[t])+d|0;n=d,d=u,u=0|T(o,10),o=i,i=r}for(let e=0;e<16;e++){const n=T(r+Gt(t,s,a,c)+Yt[m[e]]+h,y[e])+f|0;r=f,f=c,c=0|T(a,10),a=s,s=n}}this.set(this.h1+o+c|0,this.h2+u+f|0,this.h3+d+r|0,this.h4+n+s|0,this.h0+i+a|0)}roundClean(){A(Yt)}destroy(){this.destroyed=!0,A(this.buffer),this.set(0,0,0,0,0)}}const Xt=V(()=>new Qt);function Jt(...e){const t=g.join(e),n=Xt(ee(t));return new g(n)}function en(...e){const t=g.join(e),n=ee(t);return new g(n)}function tn(...e){const t=g.join(e),n=ee(ee(t));return new g(n)}function nn(e,...t){const n=function(e){const t=en(g.str(e));return g.join([t,t])}(e),r=t.map(e=>new g(e));return en(g.join([n,...r]))}var rn,sn;!function(e){e.assertEqual=e=>{},e.assertIs=function(e){},e.assertNever=function(e){throw new Error},e.arrayToEnum=e=>{const t={};for(const n of e)t[n]=n;return t},e.getValidEnumValues=t=>{const n=e.objectKeys(t).filter(e=>"number"!=typeof t[t[e]]),r={};for(const e of n)r[e]=t[e];return e.objectValues(r)},e.objectValues=t=>e.objectKeys(t).map(function(e){return t[e]}),e.objectKeys="function"==typeof Object.keys?e=>Object.keys(e):e=>{const t=[];for(const n in e)Object.prototype.hasOwnProperty.call(e,n)&&t.push(n);return t},e.find=(e,t)=>{for(const n of e)if(t(n))return n},e.isInteger="function"==typeof Number.isInteger?e=>Number.isInteger(e):e=>"number"==typeof e&&Number.isFinite(e)&&Math.floor(e)===e,e.joinValues=function(e,t=" | "){return e.map(e=>"string"==typeof e?`'${e}'`:e).join(t)},e.jsonStringifyReplacer=(e,t)=>"bigint"==typeof t?t.toString():t}(rn||(rn={})),function(e){e.mergeShapes=(e,t)=>({...e,...t})}(sn||(sn={}));const on=rn.arrayToEnum(["string","nan","number","integer","float","boolean","date","bigint","symbol","function","undefined","null","array","object","unknown","promise","void","never","map","set"]),an=e=>{switch(typeof e){case"undefined":return on.undefined;case"string":return on.string;case"number":return Number.isNaN(e)?on.nan:on.number;case"boolean":return on.boolean;case"function":return on.function;case"bigint":return on.bigint;case"symbol":return on.symbol;case"object":return Array.isArray(e)?on.array:null===e?on.null:e.then&&"function"==typeof e.then&&e.catch&&"function"==typeof e.catch?on.promise:"undefined"!=typeof Map&&e instanceof Map?on.map:"undefined"!=typeof Set&&e instanceof Set?on.set:"undefined"!=typeof Date&&e instanceof Date?on.date:on.object;default:return on.unknown}},un=rn.arrayToEnum(["invalid_type","invalid_literal","custom","invalid_union","invalid_union_discriminator","invalid_enum_value","unrecognized_keys","invalid_arguments","invalid_return_type","invalid_date","invalid_string","too_small","too_big","invalid_intersection_types","not_multiple_of","not_finite"]);class cn extends Error{get errors(){return this.issues}constructor(e){super(),this.issues=[],this.addIssue=e=>{this.issues=[...this.issues,e]},this.addIssues=(e=[])=>{this.issues=[...this.issues,...e]};const t=new.target.prototype;Object.setPrototypeOf?Object.setPrototypeOf(this,t):this.__proto__=t,this.name="ZodError",this.issues=e}format(e){const t=e||function(e){return e.message},n={_errors:[]},r=e=>{for(const i of e.issues)if("invalid_union"===i.code)i.unionErrors.map(r);else if("invalid_return_type"===i.code)r(i.returnTypeError);else if("invalid_arguments"===i.code)r(i.argumentsError);else if(0===i.path.length)n._errors.push(t(i));else{let e=n,r=0;for(;r<i.path.length;){const n=i.path[r];r===i.path.length-1?(e[n]=e[n]||{_errors:[]},e[n]._errors.push(t(i))):e[n]=e[n]||{_errors:[]},e=e[n],r++}}};return r(this),n}static assert(e){if(!(e instanceof cn))throw new Error(`Not a ZodError: ${e}`)}toString(){return this.message}get message(){return JSON.stringify(this.issues,rn.jsonStringifyReplacer,2)}get isEmpty(){return 0===this.issues.length}flatten(e=e=>e.message){const t={},n=[];for(const r of this.issues)if(r.path.length>0){const n=r.path[0];t[n]=t[n]||[],t[n].push(e(r))}else n.push(e(r));return{formErrors:n,fieldErrors:t}}get formErrors(){return this.flatten()}}cn.create=e=>new cn(e);const dn=(e,t)=>{let n;switch(e.code){case un.invalid_type:n=e.received===on.undefined?"Required":`Expected ${e.expected}, received ${e.received}`;break;case un.invalid_literal:n=`Invalid literal value, expected ${JSON.stringify(e.expected,rn.jsonStringifyReplacer)}`;break;case un.unrecognized_keys:n=`Unrecognized key(s) in object: ${rn.joinValues(e.keys,", ")}`;break;case un.invalid_union:n="Invalid input";break;case un.invalid_union_discriminator:n=`Invalid discriminator value. Expected ${rn.joinValues(e.options)}`;break;case un.invalid_enum_value:n=`Invalid enum value. Expected ${rn.joinValues(e.options)}, received '${e.received}'`;break;case un.invalid_arguments:n="Invalid function arguments";break;case un.invalid_return_type:n="Invalid function return type";break;case un.invalid_date:n="Invalid date";break;case un.invalid_string:"object"==typeof e.validation?"includes"in e.validation?(n=`Invalid input: must include "${e.validation.includes}"`,"number"==typeof e.validation.position&&(n=`${n} at one or more positions greater than or equal to ${e.validation.position}`)):"startsWith"in e.validation?n=`Invalid input: must start with "${e.validation.startsWith}"`:"endsWith"in e.validation?n=`Invalid input: must end with "${e.validation.endsWith}"`:rn.assertNever(e.validation):n="regex"!==e.validation?`Invalid ${e.validation}`:"Invalid";break;case un.too_small:n="array"===e.type?`Array must contain ${e.exact?"exactly":e.inclusive?"at least":"more than"} ${e.minimum} element(s)`:"string"===e.type?`String must contain ${e.exact?"exactly":e.inclusive?"at least":"over"} ${e.minimum} character(s)`:"number"===e.type||"bigint"===e.type?`Number must be ${e.exact?"exactly equal to ":e.inclusive?"greater than or equal to ":"greater than "}${e.minimum}`:"date"===e.type?`Date must be ${e.exact?"exactly equal to ":e.inclusive?"greater than or equal to ":"greater than "}${new Date(Number(e.minimum))}`:"Invalid input";break;case un.too_big:n="array"===e.type?`Array must contain ${e.exact?"exactly":e.inclusive?"at most":"less than"} ${e.maximum} element(s)`:"string"===e.type?`String must contain ${e.exact?"exactly":e.inclusive?"at most":"under"} ${e.maximum} character(s)`:"number"===e.type?`Number must be ${e.exact?"exactly":e.inclusive?"less than or equal to":"less than"} ${e.maximum}`:"bigint"===e.type?`BigInt must be ${e.exact?"exactly":e.inclusive?"less than or equal to":"less than"} ${e.maximum}`:"date"===e.type?`Date must be ${e.exact?"exactly":e.inclusive?"smaller than or equal to":"smaller than"} ${new Date(Number(e.maximum))}`:"Invalid input";break;case un.custom:n="Invalid input";break;case un.invalid_intersection_types:n="Intersection results could not be merged";break;case un.not_multiple_of:n=`Number must be a multiple of ${e.multipleOf}`;break;case un.not_finite:n="Number must be finite";break;default:n=t.defaultError,rn.assertNever(e)}return{message:n}};let fn=dn;function ln(e,t){const n=fn,r=(e=>{const{data:t,path:n,errorMaps:r,issueData:i}=e,s=[...n,...i.path||[]],o={...i,path:s};if(void 0!==i.message)return{...i,path:s,message:i.message};let a="";const u=r.filter(e=>!!e).slice().reverse();for(const e of u)a=e(o,{data:t,defaultError:a}).message;return{...i,path:s,message:a}})({issueData:t,data:e.data,path:e.path,errorMaps:[e.common.contextualErrorMap,e.schemaErrorMap,n,n===dn?void 0:dn].filter(e=>!!e)});e.common.issues.push(r)}class hn{constructor(){this.value="valid"}dirty(){"valid"===this.value&&(this.value="dirty")}abort(){"aborted"!==this.value&&(this.value="aborted")}static mergeArray(e,t){const n=[];for(const r of t){if("aborted"===r.status)return pn;"dirty"===r.status&&e.dirty(),n.push(r.value)}return{status:e.value,value:n}}static async mergeObjectAsync(e,t){const n=[];for(const e of t){const t=await e.key,r=await e.value;n.push({key:t,value:r})}return hn.mergeObjectSync(e,n)}static mergeObjectSync(e,t){const n={};for(const r of t){const{key:t,value:i}=r;if("aborted"===t.status)return pn;if("aborted"===i.status)return pn;"dirty"===t.status&&e.dirty(),"dirty"===i.status&&e.dirty(),"__proto__"===t.value||void 0===i.value&&!r.alwaysSet||(n[t.value]=i.value)}return{status:e.value,value:n}}}const pn=Object.freeze({status:"aborted"}),mn=e=>({status:"dirty",value:e}),gn=e=>({status:"valid",value:e}),yn=e=>"aborted"===e.status,_n=e=>"dirty"===e.status,vn=e=>"valid"===e.status,wn=e=>"undefined"!=typeof Promise&&e instanceof Promise;var bn;!function(e){e.errToObj=e=>"string"==typeof e?{message:e}:e||{},e.toString=e=>"string"==typeof e?e:e?.message}(bn||(bn={}));class xn{constructor(e,t,n,r){this._cachedPath=[],this.parent=e,this.data=t,this._path=n,this._key=r}get path(){return this._cachedPath.length||(Array.isArray(this._key)?this._cachedPath.push(...this._path,...this._key):this._cachedPath.push(...this._path,this._key)),this._cachedPath}}const En=(e,t)=>{if(vn(t))return{success:!0,data:t.value};if(!e.common.issues.length)throw new Error("Validation failed but no issues detected.");return{success:!1,get error(){if(this._error)return this._error;const t=new cn(e.common.issues);return this._error=t,this._error}}};function kn(e){if(!e)return{};const{errorMap:t,invalid_type_error:n,required_error:r,description:i}=e;if(t&&(n||r))throw new Error('Can\'t use "invalid_type_error" or "required_error" in conjunction with custom error map.');if(t)return{errorMap:t,description:i};return{errorMap:(t,i)=>{const{message:s}=e;return"invalid_enum_value"===t.code?{message:s??i.defaultError}:void 0===i.data?{message:s??r??i.defaultError}:"invalid_type"!==t.code?{message:i.defaultError}:{message:s??n??i.defaultError}},description:i}}class On{get description(){return this._def.description}_getType(e){return an(e.data)}_getOrReturnCtx(e,t){return t||{common:e.parent.common,data:e.data,parsedType:an(e.data),schemaErrorMap:this._def.errorMap,path:e.path,parent:e.parent}}_processInputParams(e){return{status:new hn,ctx:{common:e.parent.common,data:e.data,parsedType:an(e.data),schemaErrorMap:this._def.errorMap,path:e.path,parent:e.parent}}}_parseSync(e){const t=this._parse(e);if(wn(t))throw new Error("Synchronous parse encountered promise.");return t}_parseAsync(e){const t=this._parse(e);return Promise.resolve(t)}parse(e,t){const n=this.safeParse(e,t);if(n.success)return n.data;throw n.error}safeParse(e,t){const n={common:{issues:[],async:t?.async??!1,contextualErrorMap:t?.errorMap},path:t?.path||[],schemaErrorMap:this._def.errorMap,parent:null,data:e,parsedType:an(e)},r=this._parseSync({data:e,path:n.path,parent:n});return En(n,r)}"~validate"(e){const t={common:{issues:[],async:!!this["~standard"].async},path:[],schemaErrorMap:this._def.errorMap,parent:null,data:e,parsedType:an(e)};if(!this["~standard"].async)try{const n=this._parseSync({data:e,path:[],parent:t});return vn(n)?{value:n.value}:{issues:t.common.issues}}catch(e){e?.message?.toLowerCase()?.includes("encountered")&&(this["~standard"].async=!0),t.common={issues:[],async:!0}}return this._parseAsync({data:e,path:[],parent:t}).then(e=>vn(e)?{value:e.value}:{issues:t.common.issues})}async parseAsync(e,t){const n=await this.safeParseAsync(e,t);if(n.success)return n.data;throw n.error}async safeParseAsync(e,t){const n={common:{issues:[],contextualErrorMap:t?.errorMap,async:!0},path:t?.path||[],schemaErrorMap:this._def.errorMap,parent:null,data:e,parsedType:an(e)},r=this._parse({data:e,path:n.path,parent:n}),i=await(wn(r)?r:Promise.resolve(r));return En(n,i)}refine(e,t){const n=e=>"string"==typeof t||void 0===t?{message:t}:"function"==typeof t?t(e):t;return this._refinement((t,r)=>{const i=e(t),s=()=>r.addIssue({code:un.custom,...n(t)});return"undefined"!=typeof Promise&&i instanceof Promise?i.then(e=>!!e||(s(),!1)):!!i||(s(),!1)})}refinement(e,t){return this._refinement((n,r)=>!!e(n)||(r.addIssue("function"==typeof t?t(n,r):t),!1))}_refinement(e){return new kr({schema:this,typeName:Rr.ZodEffects,effect:{type:"refinement",refinement:e}})}superRefine(e){return this._refinement(e)}constructor(e){this.spa=this.safeParseAsync,this._def=e,this.parse=this.parse.bind(this),this.safeParse=this.safeParse.bind(this),this.parseAsync=this.parseAsync.bind(this),this.safeParseAsync=this.safeParseAsync.bind(this),this.spa=this.spa.bind(this),this.refine=this.refine.bind(this),this.refinement=this.refinement.bind(this),this.superRefine=this.superRefine.bind(this),this.optional=this.optional.bind(this),this.nullable=this.nullable.bind(this),this.nullish=this.nullish.bind(this),this.array=this.array.bind(this),this.promise=this.promise.bind(this),this.or=this.or.bind(this),this.and=this.and.bind(this),this.transform=this.transform.bind(this),this.brand=this.brand.bind(this),this.default=this.default.bind(this),this.catch=this.catch.bind(this),this.describe=this.describe.bind(this),this.pipe=this.pipe.bind(this),this.readonly=this.readonly.bind(this),this.isNullable=this.isNullable.bind(this),this.isOptional=this.isOptional.bind(this),this["~standard"]={version:1,vendor:"zod",validate:e=>this["~validate"](e)}}optional(){return Or.create(this,this._def)}nullable(){return Sr.create(this,this._def)}nullish(){return this.nullable().optional()}array(){return ur.create(this)}promise(){return Er.create(this,this._def)}or(e){return fr.create([this,e],this._def)}and(e){return hr.create(this,e,this._def)}transform(e){return new kr({...kn(this._def),schema:this,typeName:Rr.ZodEffects,effect:{type:"transform",transform:e}})}default(e){const t="function"==typeof e?e:()=>e;return new Ar({...kn(this._def),innerType:this,defaultValue:t,typeName:Rr.ZodDefault})}brand(){return new Tr({typeName:Rr.ZodBranded,type:this,...kn(this._def)})}catch(e){const t="function"==typeof e?e:()=>e;return new Pr({...kn(this._def),innerType:this,catchValue:t,typeName:Rr.ZodCatch})}describe(e){return new(0,this.constructor)({...this._def,description:e})}pipe(e){return Nr.create(this,e)}readonly(){return Cr.create(this)}isOptional(){return this.safeParse(void 0).success}isNullable(){return this.safeParse(null).success}}const Sn=/^c[^\s-]{8,}$/i,An=/^[0-9a-z]+$/,Pn=/^[0-9A-HJKMNP-TV-Z]{26}$/i,In=/^[0-9a-fA-F]{8}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{12}$/i,Tn=/^[a-z0-9_-]{21}$/i,Nn=/^[A-Za-z0-9-_]+\.[A-Za-z0-9-_]+\.[A-Za-z0-9-_]*$/,Cn=/^[-+]?P(?!$)(?:(?:[-+]?\d+Y)|(?:[-+]?\d+[.,]\d+Y$))?(?:(?:[-+]?\d+M)|(?:[-+]?\d+[.,]\d+M$))?(?:(?:[-+]?\d+W)|(?:[-+]?\d+[.,]\d+W$))?(?:(?:[-+]?\d+D)|(?:[-+]?\d+[.,]\d+D$))?(?:T(?=[\d+-])(?:(?:[-+]?\d+H)|(?:[-+]?\d+[.,]\d+H$))?(?:(?:[-+]?\d+M)|(?:[-+]?\d+[.,]\d+M$))?(?:[-+]?\d+(?:[.,]\d+)?S)?)??$/,$n=/^(?!\.)(?!.*\.\.)([A-Z0-9_'+\-\.]*)[A-Z0-9_+-]@([A-Z0-9][A-Z0-9\-]*\.)+[A-Z]{2,}$/i;let Rn;const Bn=/^(?:(?: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])$/,Un=/^(?:(?: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])\/(3[0-2]|[12]?[0-9])$/,jn=/^(([0-9a-fA-F]{1,4}:){7,7}[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,7}:|([0-9a-fA-F]{1,4}:){1,6}:[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,5}(:[0-9a-fA-F]{1,4}){1,2}|([0-9a-fA-F]{1,4}:){1,4}(:[0-9a-fA-F]{1,4}){1,3}|([0-9a-fA-F]{1,4}:){1,3}(:[0-9a-fA-F]{1,4}){1,4}|([0-9a-fA-F]{1,4}:){1,2}(:[0-9a-fA-F]{1,4}){1,5}|[0-9a-fA-F]{1,4}:((:[0-9a-fA-F]{1,4}){1,6})|:((:[0-9a-fA-F]{1,4}){1,7}|:)|fe80:(:[0-9a-fA-F]{0,4}){0,4}%[0-9a-zA-Z]{1,}|::(ffff(:0{1,4}){0,1}:){0,1}((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])|([0-9a-fA-F]{1,4}:){1,4}:((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9]))$/,Zn=/^(([0-9a-fA-F]{1,4}:){7,7}[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,7}:|([0-9a-fA-F]{1,4}:){1,6}:[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,5}(:[0-9a-fA-F]{1,4}){1,2}|([0-9a-fA-F]{1,4}:){1,4}(:[0-9a-fA-F]{1,4}){1,3}|([0-9a-fA-F]{1,4}:){1,3}(:[0-9a-fA-F]{1,4}){1,4}|([0-9a-fA-F]{1,4}:){1,2}(:[0-9a-fA-F]{1,4}){1,5}|[0-9a-fA-F]{1,4}:((:[0-9a-fA-F]{1,4}){1,6})|:((:[0-9a-fA-F]{1,4}){1,7}|:)|fe80:(:[0-9a-fA-F]{0,4}){0,4}%[0-9a-zA-Z]{1,}|::(ffff(:0{1,4}){0,1}:){0,1}((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])|([0-9a-fA-F]{1,4}:){1,4}:((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9]))\/(12[0-8]|1[01][0-9]|[1-9]?[0-9])$/,zn=/^([0-9a-zA-Z+/]{4})*(([0-9a-zA-Z+/]{2}==)|([0-9a-zA-Z+/]{3}=))?$/,Ln=/^([0-9a-zA-Z-_]{4})*(([0-9a-zA-Z-_]{2}(==)?)|([0-9a-zA-Z-_]{3}(=)?))?$/,Fn="((\\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])))",Dn=new RegExp(`^${Fn}$`);function Hn(e){let t="[0-5]\\d";e.precision?t=`${t}\\.\\d{${e.precision}}`:null==e.precision&&(t=`${t}(\\.\\d+)?`);return`([01]\\d|2[0-3]):[0-5]\\d(:${t})${e.precision?"+":"?"}`}function qn(e){return new RegExp(`^${Hn(e)}$`)}function Vn(e){let t=`${Fn}T${Hn(e)}`;const n=[];return n.push(e.local?"Z?":"Z"),e.offset&&n.push("([+-]\\d{2}:?\\d{2})"),t=`${t}(${n.join("|")})`,new RegExp(`^${t}$`)}function Mn(e,t){return!("v4"!==t&&t||!Bn.test(e))||!("v6"!==t&&t||!jn.test(e))}function Kn(e,t){if(!Nn.test(e))return!1;try{const[n]=e.split(".");if(!n)return!1;const r=n.replace(/-/g,"+").replace(/_/g,"/").padEnd(n.length+(4-n.length%4)%4,"="),i=JSON.parse(atob(r));return"object"==typeof i&&null!==i&&((!("typ"in i)||"JWT"===i?.typ)&&(!!i.alg&&(!t||i.alg===t)))}catch{return!1}}function Wn(e,t){return!("v4"!==t&&t||!Un.test(e))||!("v6"!==t&&t||!Zn.test(e))}class Gn extends On{_parse(e){this._def.coerce&&(e.data=String(e.data));if(this._getType(e)!==on.string){const t=this._getOrReturnCtx(e);return ln(t,{code:un.invalid_type,expected:on.string,received:t.parsedType}),pn}const t=new hn;let n;for(const r of this._def.checks)if("min"===r.kind)e.data.length<r.value&&(n=this._getOrReturnCtx(e,n),ln(n,{code:un.too_small,minimum:r.value,type:"string",inclusive:!0,exact:!1,message:r.message}),t.dirty());else if("max"===r.kind)e.data.length>r.value&&(n=this._getOrReturnCtx(e,n),ln(n,{code:un.too_big,maximum:r.value,type:"string",inclusive:!0,exact:!1,message:r.message}),t.dirty());else if("length"===r.kind){const i=e.data.length>r.value,s=e.data.length<r.value;(i||s)&&(n=this._getOrReturnCtx(e,n),i?ln(n,{code:un.too_big,maximum:r.value,type:"string",inclusive:!0,exact:!0,message:r.message}):s&&ln(n,{code:un.too_small,minimum:r.value,type:"string",inclusive:!0,exact:!0,message:r.message}),t.dirty())}else if("email"===r.kind)$n.test(e.data)||(n=this._getOrReturnCtx(e,n),ln(n,{validation:"email",code:un.invalid_string,message:r.message}),t.dirty());else if("emoji"===r.kind)Rn||(Rn=new RegExp("^(\\p{Extended_Pictographic}|\\p{Emoji_Component})+$","u")),Rn.test(e.data)||(n=this._getOrReturnCtx(e,n),ln(n,{validation:"emoji",code:un.invalid_string,message:r.message}),t.dirty());else if("uuid"===r.kind)In.test(e.data)||(n=this._getOrReturnCtx(e,n),ln(n,{validation:"uuid",code:un.invalid_string,message:r.message}),t.dirty());else if("nanoid"===r.kind)Tn.test(e.data)||(n=this._getOrReturnCtx(e,n),ln(n,{validation:"nanoid",code:un.invalid_string,message:r.message}),t.dirty());else if("cuid"===r.kind)Sn.test(e.data)||(n=this._getOrReturnCtx(e,n),ln(n,{validation:"cuid",code:un.invalid_string,message:r.message}),t.dirty());else if("cuid2"===r.kind)An.test(e.data)||(n=this._getOrReturnCtx(e,n),ln(n,{validation:"cuid2",code:un.invalid_string,message:r.message}),t.dirty());else if("ulid"===r.kind)Pn.test(e.data)||(n=this._getOrReturnCtx(e,n),ln(n,{validation:"ulid",code:un.invalid_string,message:r.message}),t.dirty());else if("url"===r.kind)try{new URL(e.data)}catch{n=this._getOrReturnCtx(e,n),ln(n,{validation:"url",code:un.invalid_string,message:r.message}),t.dirty()}else if("regex"===r.kind){r.regex.lastIndex=0;r.regex.test(e.data)||(n=this._getOrReturnCtx(e,n),ln(n,{validation:"regex",code:un.invalid_string,message:r.message}),t.dirty())}else if("trim"===r.kind)e.data=e.data.trim();else if("includes"===r.kind)e.data.includes(r.value,r.position)||(n=this._getOrReturnCtx(e,n),ln(n,{code:un.invalid_string,validation:{includes:r.value,position:r.position},message:r.message}),t.dirty());else if("toLowerCase"===r.kind)e.data=e.data.toLowerCase();else if("toUpperCase"===r.kind)e.data=e.data.toUpperCase();else if("startsWith"===r.kind)e.data.startsWith(r.value)||(n=this._getOrReturnCtx(e,n),ln(n,{code:un.invalid_string,validation:{startsWith:r.value},message:r.message}),t.dirty());else if("endsWith"===r.kind)e.data.endsWith(r.value)||(n=this._getOrReturnCtx(e,n),ln(n,{code:un.invalid_string,validation:{endsWith:r.value},message:r.message}),t.dirty());else if("datetime"===r.kind){Vn(r).test(e.data)||(n=this._getOrReturnCtx(e,n),ln(n,{code:un.invalid_string,validation:"datetime",message:r.message}),t.dirty())}else if("date"===r.kind){Dn.test(e.data)||(n=this._getOrReturnCtx(e,n),ln(n,{code:un.invalid_string,validation:"date",message:r.message}),t.dirty())}else if("time"===r.kind){qn(r).test(e.data)||(n=this._getOrReturnCtx(e,n),ln(n,{code:un.invalid_string,validation:"time",message:r.message}),t.dirty())}else"duration"===r.kind?Cn.test(e.data)||(n=this._getOrReturnCtx(e,n),ln(n,{validation:"duration",code:un.invalid_string,message:r.message}),t.dirty()):"ip"===r.kind?Mn(e.data,r.version)||(n=this._getOrReturnCtx(e,n),ln(n,{validation:"ip",code:un.invalid_string,message:r.message}),t.dirty()):"jwt"===r.kind?Kn(e.data,r.alg)||(n=this._getOrReturnCtx(e,n),ln(n,{validation:"jwt",code:un.invalid_string,message:r.message}),t.dirty()):"cidr"===r.kind?Wn(e.data,r.version)||(n=this._getOrReturnCtx(e,n),ln(n,{validation:"cidr",code:un.invalid_string,message:r.message}),t.dirty()):"base64"===r.kind?zn.test(e.data)||(n=this._getOrReturnCtx(e,n),ln(n,{validation:"base64",code:un.invalid_string,message:r.message}),t.dirty()):"base64url"===r.kind?Ln.test(e.data)||(n=this._getOrReturnCtx(e,n),ln(n,{validation:"base64url",code:un.invalid_string,message:r.message}),t.dirty()):rn.assertNever(r);return{status:t.value,value:e.data}}_regex(e,t,n){return this.refinement(t=>e.test(t),{validation:t,code:un.invalid_string,...bn.errToObj(n)})}_addCheck(e){return new Gn({...this._def,checks:[...this._def.checks,e]})}email(e){return this._addCheck({kind:"email",...bn.errToObj(e)})}url(e){return this._addCheck({kind:"url",...bn.errToObj(e)})}emoji(e){return this._addCheck({kind:"emoji",...bn.errToObj(e)})}uuid(e){return this._addCheck({kind:"uuid",...bn.errToObj(e)})}nanoid(e){return this._addCheck({kind:"nanoid",...bn.errToObj(e)})}cuid(e){return this._addCheck({kind:"cuid",...bn.errToObj(e)})}cuid2(e){return this._addCheck({kind:"cuid2",...bn.errToObj(e)})}ulid(e){return this._addCheck({kind:"ulid",...bn.errToObj(e)})}base64(e){return this._addCheck({kind:"base64",...bn.errToObj(e)})}base64url(e){return this._addCheck({kind:"base64url",...bn.errToObj(e)})}jwt(e){return this._addCheck({kind:"jwt",...bn.errToObj(e)})}ip(e){return this._addCheck({kind:"ip",...bn.errToObj(e)})}cidr(e){return this._addCheck({kind:"cidr",...bn.errToObj(e)})}datetime(e){return"string"==typeof e?this._addCheck({kind:"datetime",precision:null,offset:!1,local:!1,message:e}):this._addCheck({kind:"datetime",precision:void 0===e?.precision?null:e?.precision,offset:e?.offset??!1,local:e?.local??!1,...bn.errToObj(e?.message)})}date(e){return this._addCheck({kind:"date",message:e})}time(e){return"string"==typeof e?this._addCheck({kind:"time",precision:null,message:e}):this._addCheck({kind:"time",precision:void 0===e?.precision?null:e?.precision,...bn.errToObj(e?.message)})}duration(e){return this._addCheck({kind:"duration",...bn.errToObj(e)})}regex(e,t){return this._addCheck({kind:"regex",regex:e,...bn.errToObj(t)})}includes(e,t){return this._addCheck({kind:"includes",value:e,position:t?.position,...bn.errToObj(t?.message)})}startsWith(e,t){return this._addCheck({kind:"startsWith",value:e,...bn.errToObj(t)})}endsWith(e,t){return this._addCheck({kind:"endsWith",value:e,...bn.errToObj(t)})}min(e,t){return this._addCheck({kind:"min",value:e,...bn.errToObj(t)})}max(e,t){return this._addCheck({kind:"max",value:e,...bn.errToObj(t)})}length(e,t){return this._addCheck({kind:"length",value:e,...bn.errToObj(t)})}nonempty(e){return this.min(1,bn.errToObj(e))}trim(){return new Gn({...this._def,checks:[...this._def.checks,{kind:"trim"}]})}toLowerCase(){return new Gn({...this._def,checks:[...this._def.checks,{kind:"toLowerCase"}]})}toUpperCase(){return new Gn({...this._def,checks:[...this._def.checks,{kind:"toUpperCase"}]})}get isDatetime(){return!!this._def.checks.find(e=>"datetime"===e.kind)}get isDate(){return!!this._def.checks.find(e=>"date"===e.kind)}get isTime(){return!!this._def.checks.find(e=>"time"===e.kind)}get isDuration(){return!!this._def.checks.find(e=>"duration"===e.kind)}get isEmail(){return!!this._def.checks.find(e=>"email"===e.kind)}get isURL(){return!!this._def.checks.find(e=>"url"===e.kind)}get isEmoji(){return!!this._def.checks.find(e=>"emoji"===e.kind)}get isUUID(){return!!this._def.checks.find(e=>"uuid"===e.kind)}get isNANOID(){return!!this._def.checks.find(e=>"nanoid"===e.kind)}get isCUID(){return!!this._def.checks.find(e=>"cuid"===e.kind)}get isCUID2(){return!!this._def.checks.find(e=>"cuid2"===e.kind)}get isULID(){return!!this._def.checks.find(e=>"ulid"===e.kind)}get isIP(){return!!this._def.checks.find(e=>"ip"===e.kind)}get isCIDR(){return!!this._def.checks.find(e=>"cidr"===e.kind)}get isBase64(){return!!this._def.checks.find(e=>"base64"===e.kind)}get isBase64url(){return!!this._def.checks.find(e=>"base64url"===e.kind)}get minLength(){let e=null;for(const t of this._def.checks)"min"===t.kind&&(null===e||t.value>e)&&(e=t.value);return e}get maxLength(){let e=null;for(const t of this._def.checks)"max"===t.kind&&(null===e||t.value<e)&&(e=t.value);return e}}function Yn(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}Gn.create=e=>new Gn({checks:[],typeName:Rr.ZodString,coerce:e?.coerce??!1,...kn(e)});class Qn extends On{constructor(){super(...arguments),this.min=this.gte,this.max=this.lte,this.step=this.multipleOf}_parse(e){this._def.coerce&&(e.data=Number(e.data));if(this._getType(e)!==on.number){const t=this._getOrReturnCtx(e);return ln(t,{code:un.invalid_type,expected:on.number,received:t.parsedType}),pn}let t;const n=new hn;for(const r of this._def.checks)if("int"===r.kind)rn.isInteger(e.data)||(t=this._getOrReturnCtx(e,t),ln(t,{code:un.invalid_type,expected:"integer",received:"float",message:r.message}),n.dirty());else if("min"===r.kind){(r.inclusive?e.data<r.value:e.data<=r.value)&&(t=this._getOrReturnCtx(e,t),ln(t,{code:un.too_small,minimum:r.value,type:"number",inclusive:r.inclusive,exact:!1,message:r.message}),n.dirty())}else if("max"===r.kind){(r.inclusive?e.data>r.value:e.data>=r.value)&&(t=this._getOrReturnCtx(e,t),ln(t,{code:un.too_big,maximum:r.value,type:"number",inclusive:r.inclusive,exact:!1,message:r.message}),n.dirty())}else"multipleOf"===r.kind?0!==Yn(e.data,r.value)&&(t=this._getOrReturnCtx(e,t),ln(t,{code:un.not_multiple_of,multipleOf:r.value,message:r.message}),n.dirty()):"finite"===r.kind?Number.isFinite(e.data)||(t=this._getOrReturnCtx(e,t),ln(t,{code:un.not_finite,message:r.message}),n.dirty()):rn.assertNever(r);return{status:n.value,value:e.data}}gte(e,t){return this.setLimit("min",e,!0,bn.toString(t))}gt(e,t){return this.setLimit("min",e,!1,bn.toString(t))}lte(e,t){return this.setLimit("max",e,!0,bn.toString(t))}lt(e,t){return this.setLimit("max",e,!1,bn.toString(t))}setLimit(e,t,n,r){return new Qn({...this._def,checks:[...this._def.checks,{kind:e,value:t,inclusive:n,message:bn.toString(r)}]})}_addCheck(e){return new Qn({...this._def,checks:[...this._def.checks,e]})}int(e){return this._addCheck({kind:"int",message:bn.toString(e)})}positive(e){return this._addCheck({kind:"min",value:0,inclusive:!1,message:bn.toString(e)})}negative(e){return this._addCheck({kind:"max",value:0,inclusive:!1,message:bn.toString(e)})}nonpositive(e){return this._addCheck({kind:"max",value:0,inclusive:!0,message:bn.toString(e)})}nonnegative(e){return this._addCheck({kind:"min",value:0,inclusive:!0,message:bn.toString(e)})}multipleOf(e,t){return this._addCheck({kind:"multipleOf",value:e,message:bn.toString(t)})}finite(e){return this._addCheck({kind:"finite",message:bn.toString(e)})}safe(e){return this._addCheck({kind:"min",inclusive:!0,value:Number.MIN_SAFE_INTEGER,message:bn.toString(e)})._addCheck({kind:"max",inclusive:!0,value:Number.MAX_SAFE_INTEGER,message:bn.toString(e)})}get minValue(){let e=null;for(const t of this._def.checks)"min"===t.kind&&(null===e||t.value>e)&&(e=t.value);return e}get maxValue(){let e=null;for(const t of this._def.checks)"max"===t.kind&&(null===e||t.value<e)&&(e=t.value);return e}get isInt(){return!!this._def.checks.find(e=>"int"===e.kind||"multipleOf"===e.kind&&rn.isInteger(e.value))}get isFinite(){let e=null,t=null;for(const n of this._def.checks){if("finite"===n.kind||"int"===n.kind||"multipleOf"===n.kind)return!0;"min"===n.kind?(null===t||n.value>t)&&(t=n.value):"max"===n.kind&&(null===e||n.value<e)&&(e=n.value)}return Number.isFinite(t)&&Number.isFinite(e)}}Qn.create=e=>new Qn({checks:[],typeName:Rr.ZodNumber,coerce:e?.coerce||!1,...kn(e)});class Xn extends On{constructor(){super(...arguments),this.min=this.gte,this.max=this.lte}_parse(e){if(this._def.coerce)try{e.data=BigInt(e.data)}catch{return this._getInvalidInput(e)}if(this._getType(e)!==on.bigint)return this._getInvalidInput(e);let t;const n=new hn;for(const r of this._def.checks)if("min"===r.kind){(r.inclusive?e.data<r.value:e.data<=r.value)&&(t=this._getOrReturnCtx(e,t),ln(t,{code:un.too_small,type:"bigint",minimum:r.value,inclusive:r.inclusive,message:r.message}),n.dirty())}else if("max"===r.kind){(r.inclusive?e.data>r.value:e.data>=r.value)&&(t=this._getOrReturnCtx(e,t),ln(t,{code:un.too_big,type:"bigint",maximum:r.value,inclusive:r.inclusive,message:r.message}),n.dirty())}else"multipleOf"===r.kind?e.data%r.value!==BigInt(0)&&(t=this._getOrReturnCtx(e,t),ln(t,{code:un.not_multiple_of,multipleOf:r.value,message:r.message}),n.dirty()):rn.assertNever(r);return{status:n.value,value:e.data}}_getInvalidInput(e){const t=this._getOrReturnCtx(e);return ln(t,{code:un.invalid_type,expected:on.bigint,received:t.parsedType}),pn}gte(e,t){return this.setLimit("min",e,!0,bn.toString(t))}gt(e,t){return this.setLimit("min",e,!1,bn.toString(t))}lte(e,t){return this.setLimit("max",e,!0,bn.toString(t))}lt(e,t){return this.setLimit("max",e,!1,bn.toString(t))}setLimit(e,t,n,r){return new Xn({...this._def,checks:[...this._def.checks,{kind:e,value:t,inclusive:n,message:bn.toString(r)}]})}_addCheck(e){return new Xn({...this._def,checks:[...this._def.checks,e]})}positive(e){return this._addCheck({kind:"min",value:BigInt(0),inclusive:!1,message:bn.toString(e)})}negative(e){return this._addCheck({kind:"max",value:BigInt(0),inclusive:!1,message:bn.toString(e)})}nonpositive(e){return this._addCheck({kind:"max",value:BigInt(0),inclusive:!0,message:bn.toString(e)})}nonnegative(e){return this._addCheck({kind:"min",value:BigInt(0),inclusive:!0,message:bn.toString(e)})}multipleOf(e,t){return this._addCheck({kind:"multipleOf",value:e,message:bn.toString(t)})}get minValue(){let e=null;for(const t of this._def.checks)"min"===t.kind&&(null===e||t.value>e)&&(e=t.value);return e}get maxValue(){let e=null;for(const t of this._def.checks)"max"===t.kind&&(null===e||t.value<e)&&(e=t.value);return e}}Xn.create=e=>new Xn({checks:[],typeName:Rr.ZodBigInt,coerce:e?.coerce??!1,...kn(e)});class Jn extends On{_parse(e){this._def.coerce&&(e.data=Boolean(e.data));if(this._getType(e)!==on.boolean){const t=this._getOrReturnCtx(e);return ln(t,{code:un.invalid_type,expected:on.boolean,received:t.parsedType}),pn}return gn(e.data)}}Jn.create=e=>new Jn({typeName:Rr.ZodBoolean,coerce:e?.coerce||!1,...kn(e)});class er extends On{_parse(e){this._def.coerce&&(e.data=new Date(e.data));if(this._getType(e)!==on.date){const t=this._getOrReturnCtx(e);return ln(t,{code:un.invalid_type,expected:on.date,received:t.parsedType}),pn}if(Number.isNaN(e.data.getTime())){return ln(this._getOrReturnCtx(e),{code:un.invalid_date}),pn}const t=new hn;let n;for(const r of this._def.checks)"min"===r.kind?e.data.getTime()<r.value&&(n=this._getOrReturnCtx(e,n),ln(n,{code:un.too_small,message:r.message,inclusive:!0,exact:!1,minimum:r.value,type:"date"}),t.dirty()):"max"===r.kind?e.data.getTime()>r.value&&(n=this._getOrReturnCtx(e,n),ln(n,{code:un.too_big,message:r.message,inclusive:!0,exact:!1,maximum:r.value,type:"date"}),t.dirty()):rn.assertNever(r);return{status:t.value,value:new Date(e.data.getTime())}}_addCheck(e){return new er({...this._def,checks:[...this._def.checks,e]})}min(e,t){return this._addCheck({kind:"min",value:e.getTime(),message:bn.toString(t)})}max(e,t){return this._addCheck({kind:"max",value:e.getTime(),message:bn.toString(t)})}get minDate(){let e=null;for(const t of this._def.checks)"min"===t.kind&&(null===e||t.value>e)&&(e=t.value);return null!=e?new Date(e):null}get maxDate(){let e=null;for(const t of this._def.checks)"max"===t.kind&&(null===e||t.value<e)&&(e=t.value);return null!=e?new Date(e):null}}er.create=e=>new er({checks:[],coerce:e?.coerce||!1,typeName:Rr.ZodDate,...kn(e)});class tr extends On{_parse(e){if(this._getType(e)!==on.symbol){const t=this._getOrReturnCtx(e);return ln(t,{code:un.invalid_type,expected:on.symbol,received:t.parsedType}),pn}return gn(e.data)}}tr.create=e=>new tr({typeName:Rr.ZodSymbol,...kn(e)});class nr extends On{_parse(e){if(this._getType(e)!==on.undefined){const t=this._getOrReturnCtx(e);return ln(t,{code:un.invalid_type,expected:on.undefined,received:t.parsedType}),pn}return gn(e.data)}}nr.create=e=>new nr({typeName:Rr.ZodUndefined,...kn(e)});class rr extends On{_parse(e){if(this._getType(e)!==on.null){const t=this._getOrReturnCtx(e);return ln(t,{code:un.invalid_type,expected:on.null,received:t.parsedType}),pn}return gn(e.data)}}rr.create=e=>new rr({typeName:Rr.ZodNull,...kn(e)});class ir extends On{constructor(){super(...arguments),this._any=!0}_parse(e){return gn(e.data)}}ir.create=e=>new ir({typeName:Rr.ZodAny,...kn(e)});class sr extends On{constructor(){super(...arguments),this._unknown=!0}_parse(e){return gn(e.data)}}sr.create=e=>new sr({typeName:Rr.ZodUnknown,...kn(e)});class or extends On{_parse(e){const t=this._getOrReturnCtx(e);return ln(t,{code:un.invalid_type,expected:on.never,received:t.parsedType}),pn}}or.create=e=>new or({typeName:Rr.ZodNever,...kn(e)});class ar extends On{_parse(e){if(this._getType(e)!==on.undefined){const t=this._getOrReturnCtx(e);return ln(t,{code:un.invalid_type,expected:on.void,received:t.parsedType}),pn}return gn(e.data)}}ar.create=e=>new ar({typeName:Rr.ZodVoid,...kn(e)});class ur extends On{_parse(e){const{ctx:t,status:n}=this._processInputParams(e),r=this._def;if(t.parsedType!==on.array)return ln(t,{code:un.invalid_type,expected:on.array,received:t.parsedType}),pn;if(null!==r.exactLength){const e=t.data.length>r.exactLength.value,i=t.data.length<r.exactLength.value;(e||i)&&(ln(t,{code:e?un.too_big:un.too_small,minimum:i?r.exactLength.value:void 0,maximum:e?r.exactLength.value:void 0,type:"array",inclusive:!0,exact:!0,message:r.exactLength.message}),n.dirty())}if(null!==r.minLength&&t.data.length<r.minLength.value&&(ln(t,{code:un.too_small,minimum:r.minLength.value,type:"array",inclusive:!0,exact:!1,message:r.minLength.message}),n.dirty()),null!==r.maxLength&&t.data.length>r.maxLength.value&&(ln(t,{code:un.too_big,maximum:r.maxLength.value,type:"array",inclusive:!0,exact:!1,message:r.maxLength.message}),n.dirty()),t.common.async)return Promise.all([...t.data].map((e,n)=>r.type._parseAsync(new xn(t,e,t.path,n)))).then(e=>hn.mergeArray(n,e));const i=[...t.data].map((e,n)=>r.type._parseSync(new xn(t,e,t.path,n)));return hn.mergeArray(n,i)}get element(){return this._def.type}min(e,t){return new ur({...this._def,minLength:{value:e,message:bn.toString(t)}})}max(e,t){return new ur({...this._def,maxLength:{value:e,message:bn.toString(t)}})}length(e,t){return new ur({...this._def,exactLength:{value:e,message:bn.toString(t)}})}nonempty(e){return this.min(1,e)}}function cr(e){if(e instanceof dr){const t={};for(const n in e.shape){const r=e.shape[n];t[n]=Or.create(cr(r))}return new dr({...e._def,shape:()=>t})}return e instanceof ur?new ur({...e._def,type:cr(e.element)}):e instanceof Or?Or.create(cr(e.unwrap())):e instanceof Sr?Sr.create(cr(e.unwrap())):e instanceof pr?pr.create(e.items.map(e=>cr(e))):e}ur.create=(e,t)=>new ur({type:e,minLength:null,maxLength:null,exactLength:null,typeName:Rr.ZodArray,...kn(t)});class dr extends On{constructor(){super(...arguments),this._cached=null,this.nonstrict=this.passthrough,this.augment=this.extend}_getCached(){if(null!==this._cached)return this._cached;const e=this._def.shape(),t=rn.objectKeys(e);return this._cached={shape:e,keys:t},this._cached}_parse(e){if(this._getType(e)!==on.object){const t=this._getOrReturnCtx(e);return ln(t,{code:un.invalid_type,expected:on.object,received:t.parsedType}),pn}const{status:t,ctx:n}=this._processInputParams(e),{shape:r,keys:i}=this._getCached(),s=[];if(!(this._def.catchall instanceof or&&"strip"===this._def.unknownKeys))for(const e in n.data)i.includes(e)||s.push(e);const o=[];for(const e of i){const t=r[e],i=n.data[e];o.push({key:{status:"valid",value:e},value:t._parse(new xn(n,i,n.path,e)),alwaysSet:e in n.data})}if(this._def.catchall instanceof or){const e=this._def.unknownKeys;if("passthrough"===e)for(const e of s)o.push({key:{status:"valid",value:e},value:{status:"valid",value:n.data[e]}});else if("strict"===e)s.length>0&&(ln(n,{code:un.unrecognized_keys,keys:s}),t.dirty());else if("strip"!==e)throw new Error("Internal ZodObject error: invalid unknownKeys value.")}else{const e=this._def.catchall;for(const t of s){const r=n.data[t];o.push({key:{status:"valid",value:t},value:e._parse(new xn(n,r,n.path,t)),alwaysSet:t in n.data})}}return n.common.async?Promise.resolve().then(async()=>{const e=[];for(const t of o){const n=await t.key,r=await t.value;e.push({key:n,value:r,alwaysSet:t.alwaysSet})}return e}).then(e=>hn.mergeObjectSync(t,e)):hn.mergeObjectSync(t,o)}get shape(){return this._def.shape()}strict(e){return new dr({...this._def,unknownKeys:"strict",...void 0!==e?{errorMap:(t,n)=>{const r=this._def.errorMap?.(t,n).message??n.defaultError;return"unrecognized_keys"===t.code?{message:bn.errToObj(e).message??r}:{message:r}}}:{}})}strip(){return new dr({...this._def,unknownKeys:"strip"})}passthrough(){return new dr({...this._def,unknownKeys:"passthrough"})}extend(e){return new dr({...this._def,shape:()=>({...this._def.shape(),...e})})}merge(e){return new dr({unknownKeys:e._def.unknownKeys,catchall:e._def.catchall,shape:()=>({...this._def.shape(),...e._def.shape()}),typeName:Rr.ZodObject})}setKey(e,t){return this.augment({[e]:t})}catchall(e){return new dr({...this._def,catchall:e})}pick(e){const t={};for(const n of rn.objectKeys(e))e[n]&&this.shape[n]&&(t[n]=this.shape[n]);return new dr({...this._def,shape:()=>t})}omit(e){const t={};for(const n of rn.objectKeys(this.shape))e[n]||(t[n]=this.shape[n]);return new dr({...this._def,shape:()=>t})}deepPartial(){return cr(this)}partial(e){const t={};for(const n of rn.objectKeys(this.shape)){const r=this.shape[n];e&&!e[n]?t[n]=r:t[n]=r.optional()}return new dr({...this._def,shape:()=>t})}required(e){const t={};for(const n of rn.objectKeys(this.shape))if(e&&!e[n])t[n]=this.shape[n];else{let e=this.shape[n];for(;e instanceof Or;)e=e._def.innerType;t[n]=e}return new dr({...this._def,shape:()=>t})}keyof(){return wr(rn.objectKeys(this.shape))}}dr.create=(e,t)=>new dr({shape:()=>e,unknownKeys:"strip",catchall:or.create(),typeName:Rr.ZodObject,...kn(t)}),dr.strictCreate=(e,t)=>new dr({shape:()=>e,unknownKeys:"strict",catchall:or.create(),typeName:Rr.ZodObject,...kn(t)}),dr.lazycreate=(e,t)=>new dr({shape:e,unknownKeys:"strip",catchall:or.create(),typeName:Rr.ZodObject,...kn(t)});class fr extends On{_parse(e){const{ctx:t}=this._processInputParams(e),n=this._def.options;if(t.common.async)return Promise.all(n.map(async e=>{const n={...t,common:{...t.common,issues:[]},parent:null};return{result:await e._parseAsync({data:t.data,path:t.path,parent:n}),ctx:n}})).then(function(e){for(const t of e)if("valid"===t.result.status)return t.result;for(const n of e)if("dirty"===n.result.status)return t.common.issues.push(...n.ctx.common.issues),n.result;const n=e.map(e=>new cn(e.ctx.common.issues));return ln(t,{code:un.invalid_union,unionErrors:n}),pn});{let e;const r=[];for(const i of n){const n={...t,common:{...t.common,issues:[]},parent:null},s=i._parseSync({data:t.data,path:t.path,parent:n});if("valid"===s.status)return s;"dirty"!==s.status||e||(e={result:s,ctx:n}),n.common.issues.length&&r.push(n.common.issues)}if(e)return t.common.issues.push(...e.ctx.common.issues),e.result;const i=r.map(e=>new cn(e));return ln(t,{code:un.invalid_union,unionErrors:i}),pn}}get options(){return this._def.options}}function lr(e,t){const n=an(e),r=an(t);if(e===t)return{valid:!0,data:e};if(n===on.object&&r===on.object){const n=rn.objectKeys(t),r=rn.objectKeys(e).filter(e=>-1!==n.indexOf(e)),i={...e,...t};for(const n of r){const r=lr(e[n],t[n]);if(!r.valid)return{valid:!1};i[n]=r.data}return{valid:!0,data:i}}if(n===on.array&&r===on.array){if(e.length!==t.length)return{valid:!1};const n=[];for(let r=0;r<e.length;r++){const i=lr(e[r],t[r]);if(!i.valid)return{valid:!1};n.push(i.data)}return{valid:!0,data:n}}return n===on.date&&r===on.date&&+e===+t?{valid:!0,data:e}:{valid:!1}}fr.create=(e,t)=>new fr({options:e,typeName:Rr.ZodUnion,...kn(t)});class hr extends On{_parse(e){const{status:t,ctx:n}=this._processInputParams(e),r=(e,r)=>{if(yn(e)||yn(r))return pn;const i=lr(e.value,r.value);return i.valid?((_n(e)||_n(r))&&t.dirty(),{status:t.value,value:i.data}):(ln(n,{code:un.invalid_intersection_types}),pn)};return n.common.async?Promise.all([this._def.left._parseAsync({data:n.data,path:n.path,parent:n}),this._def.right._parseAsync({data:n.data,path:n.path,parent:n})]).then(([e,t])=>r(e,t)):r(this._def.left._parseSync({data:n.data,path:n.path,parent:n}),this._def.right._parseSync({data:n.data,path:n.path,parent:n}))}}hr.create=(e,t,n)=>new hr({left:e,right:t,typeName:Rr.ZodIntersection,...kn(n)});class pr extends On{_parse(e){const{status:t,ctx:n}=this._processInputParams(e);if(n.parsedType!==on.array)return ln(n,{code:un.invalid_type,expected:on.array,received:n.parsedType}),pn;if(n.data.length<this._def.items.length)return ln(n,{code:un.too_small,minimum:this._def.items.length,inclusive:!0,exact:!1,type:"array"}),pn;!this._def.rest&&n.data.length>this._def.items.length&&(ln(n,{code:un.too_big,maximum:this._def.items.length,inclusive:!0,exact:!1,type:"array"}),t.dirty());const r=[...n.data].map((e,t)=>{const r=this._def.items[t]||this._def.rest;return r?r._parse(new xn(n,e,n.path,t)):null}).filter(e=>!!e);return n.common.async?Promise.all(r).then(e=>hn.mergeArray(t,e)):hn.mergeArray(t,r)}get items(){return this._def.items}rest(e){return new pr({...this._def,rest:e})}}pr.create=(e,t)=>{if(!Array.isArray(e))throw new Error("You must pass an array of schemas to z.tuple([ ... ])");return new pr({items:e,typeName:Rr.ZodTuple,rest:null,...kn(t)})};class mr extends On{get keySchema(){return this._def.keyType}get valueSchema(){return this._def.valueType}_parse(e){const{status:t,ctx:n}=this._processInputParams(e);if(n.parsedType!==on.object)return ln(n,{code:un.invalid_type,expected:on.object,received:n.parsedType}),pn;const r=[],i=this._def.keyType,s=this._def.valueType;for(const e in n.data)r.push({key:i._parse(new xn(n,e,n.path,e)),value:s._parse(new xn(n,n.data[e],n.path,e)),alwaysSet:e in n.data});return n.common.async?hn.mergeObjectAsync(t,r):hn.mergeObjectSync(t,r)}get element(){return this._def.valueType}static create(e,t,n){return new mr(t instanceof On?{keyType:e,valueType:t,typeName:Rr.ZodRecord,...kn(n)}:{keyType:Gn.create(),valueType:e,typeName:Rr.ZodRecord,...kn(t)})}}class gr extends On{get keySchema(){return this._def.keyType}get valueSchema(){return this._def.valueType}_parse(e){const{status:t,ctx:n}=this._processInputParams(e);if(n.parsedType!==on.map)return ln(n,{code:un.invalid_type,expected:on.map,received:n.parsedType}),pn;const r=this._def.keyType,i=this._def.valueType,s=[...n.data.entries()].map(([e,t],s)=>({key:r._parse(new xn(n,e,n.path,[s,"key"])),value:i._parse(new xn(n,t,n.path,[s,"value"]))}));if(n.common.async){const e=new Map;return Promise.resolve().then(async()=>{for(const n of s){const r=await n.key,i=await n.value;if("aborted"===r.status||"aborted"===i.status)return pn;"dirty"!==r.status&&"dirty"!==i.status||t.dirty(),e.set(r.value,i.value)}return{status:t.value,value:e}})}{const e=new Map;for(const n of s){const r=n.key,i=n.value;if("aborted"===r.status||"aborted"===i.status)return pn;"dirty"!==r.status&&"dirty"!==i.status||t.dirty(),e.set(r.value,i.value)}return{status:t.value,value:e}}}}gr.create=(e,t,n)=>new gr({valueType:t,keyType:e,typeName:Rr.ZodMap,...kn(n)});class yr extends On{_parse(e){const{status:t,ctx:n}=this._processInputParams(e);if(n.parsedType!==on.set)return ln(n,{code:un.invalid_type,expected:on.set,received:n.parsedType}),pn;const r=this._def;null!==r.minSize&&n.data.size<r.minSize.value&&(ln(n,{code:un.too_small,minimum:r.minSize.value,type:"set",inclusive:!0,exact:!1,message:r.minSize.message}),t.dirty()),null!==r.maxSize&&n.data.size>r.maxSize.value&&(ln(n,{code:un.too_big,maximum:r.maxSize.value,type:"set",inclusive:!0,exact:!1,message:r.maxSize.message}),t.dirty());const i=this._def.valueType;function s(e){const n=new Set;for(const r of e){if("aborted"===r.status)return pn;"dirty"===r.status&&t.dirty(),n.add(r.value)}return{status:t.value,value:n}}const o=[...n.data.values()].map((e,t)=>i._parse(new xn(n,e,n.path,t)));return n.common.async?Promise.all(o).then(e=>s(e)):s(o)}min(e,t){return new yr({...this._def,minSize:{value:e,message:bn.toString(t)}})}max(e,t){return new yr({...this._def,maxSize:{value:e,message:bn.toString(t)}})}size(e,t){return this.min(e,t).max(e,t)}nonempty(e){return this.min(1,e)}}yr.create=(e,t)=>new yr({valueType:e,minSize:null,maxSize:null,typeName:Rr.ZodSet,...kn(t)});class _r extends On{get schema(){return this._def.getter()}_parse(e){const{ctx:t}=this._processInputParams(e);return this._def.getter()._parse({data:t.data,path:t.path,parent:t})}}_r.create=(e,t)=>new _r({getter:e,typeName:Rr.ZodLazy,...kn(t)});class vr extends On{_parse(e){if(e.data!==this._def.value){const t=this._getOrReturnCtx(e);return ln(t,{received:t.data,code:un.invalid_literal,expected:this._def.value}),pn}return{status:"valid",value:e.data}}get value(){return this._def.value}}function wr(e,t){return new br({values:e,typeName:Rr.ZodEnum,...kn(t)})}vr.create=(e,t)=>new vr({value:e,typeName:Rr.ZodLiteral,...kn(t)});class br extends On{_parse(e){if("string"!=typeof e.data){const t=this._getOrReturnCtx(e),n=this._def.values;return ln(t,{expected:rn.joinValues(n),received:t.parsedType,code:un.invalid_type}),pn}if(this._cache||(this._cache=new Set(this._def.values)),!this._cache.has(e.data)){const t=this._getOrReturnCtx(e),n=this._def.values;return ln(t,{received:t.data,code:un.invalid_enum_value,options:n}),pn}return gn(e.data)}get options(){return this._def.values}get enum(){const e={};for(const t of this._def.values)e[t]=t;return e}get Values(){const e={};for(const t of this._def.values)e[t]=t;return e}get Enum(){const e={};for(const t of this._def.values)e[t]=t;return e}extract(e,t=this._def){return br.create(e,{...this._def,...t})}exclude(e,t=this._def){return br.create(this.options.filter(t=>!e.includes(t)),{...this._def,...t})}}br.create=wr;class xr extends On{_parse(e){const t=rn.getValidEnumValues(this._def.values),n=this._getOrReturnCtx(e);if(n.parsedType!==on.string&&n.parsedType!==on.number){const e=rn.objectValues(t);return ln(n,{expected:rn.joinValues(e),received:n.parsedType,code:un.invalid_type}),pn}if(this._cache||(this._cache=new Set(rn.getValidEnumValues(this._def.values))),!this._cache.has(e.data)){const e=rn.objectValues(t);return ln(n,{received:n.data,code:un.invalid_enum_value,options:e}),pn}return gn(e.data)}get enum(){return this._def.values}}xr.create=(e,t)=>new xr({values:e,typeName:Rr.ZodNativeEnum,...kn(t)});class Er extends On{unwrap(){return this._def.type}_parse(e){const{ctx:t}=this._processInputParams(e);if(t.parsedType!==on.promise&&!1===t.common.async)return ln(t,{code:un.invalid_type,expected:on.promise,received:t.parsedType}),pn;const n=t.parsedType===on.promise?t.data:Promise.resolve(t.data);return gn(n.then(e=>this._def.type.parseAsync(e,{path:t.path,errorMap:t.common.contextualErrorMap})))}}Er.create=(e,t)=>new Er({type:e,typeName:Rr.ZodPromise,...kn(t)});class kr extends On{innerType(){return this._def.schema}sourceType(){return this._def.schema._def.typeName===Rr.ZodEffects?this._def.schema.sourceType():this._def.schema}_parse(e){const{status:t,ctx:n}=this._processInputParams(e),r=this._def.effect||null,i={addIssue:e=>{ln(n,e),e.fatal?t.abort():t.dirty()},get path(){return n.path}};if(i.addIssue=i.addIssue.bind(i),"preprocess"===r.type){const e=r.transform(n.data,i);if(n.common.async)return Promise.resolve(e).then(async e=>{if("aborted"===t.value)return pn;const r=await this._def.schema._parseAsync({data:e,path:n.path,parent:n});return"aborted"===r.status?pn:"dirty"===r.status||"dirty"===t.value?mn(r.value):r});{if("aborted"===t.value)return pn;const r=this._def.schema._parseSync({data:e,path:n.path,parent:n});return"aborted"===r.status?pn:"dirty"===r.status||"dirty"===t.value?mn(r.value):r}}if("refinement"===r.type){const e=e=>{const t=r.refinement(e,i);if(n.common.async)return Promise.resolve(t);if(t instanceof Promise)throw new Error("Async refinement encountered during synchronous parse operation. Use .parseAsync instead.");return e};if(!1===n.common.async){const r=this._def.schema._parseSync({data:n.data,path:n.path,parent:n});return"aborted"===r.status?pn:("dirty"===r.status&&t.dirty(),e(r.value),{status:t.value,value:r.value})}return this._def.schema._parseAsync({data:n.data,path:n.path,parent:n}).then(n=>"aborted"===n.status?pn:("dirty"===n.status&&t.dirty(),e(n.value).then(()=>({status:t.value,value:n.value}))))}if("transform"===r.type){if(!1===n.common.async){const e=this._def.schema._parseSync({data:n.data,path:n.path,parent:n});if(!vn(e))return pn;const s=r.transform(e.value,i);if(s instanceof Promise)throw new Error("Asynchronous transform encountered during synchronous parse operation. Use .parseAsync instead.");return{status:t.value,value:s}}return this._def.schema._parseAsync({data:n.data,path:n.path,parent:n}).then(e=>vn(e)?Promise.resolve(r.transform(e.value,i)).then(e=>({status:t.value,value:e})):pn)}rn.assertNever(r)}}kr.create=(e,t,n)=>new kr({schema:e,typeName:Rr.ZodEffects,effect:t,...kn(n)}),kr.createWithPreprocess=(e,t,n)=>new kr({schema:t,effect:{type:"preprocess",transform:e},typeName:Rr.ZodEffects,...kn(n)});class Or extends On{_parse(e){return this._getType(e)===on.undefined?gn(void 0):this._def.innerType._parse(e)}unwrap(){return this._def.innerType}}Or.create=(e,t)=>new Or({innerType:e,typeName:Rr.ZodOptional,...kn(t)});class Sr extends On{_parse(e){return this._getType(e)===on.null?gn(null):this._def.innerType._parse(e)}unwrap(){return this._def.innerType}}Sr.create=(e,t)=>new Sr({innerType:e,typeName:Rr.ZodNullable,...kn(t)});class Ar extends On{_parse(e){const{ctx:t}=this._processInputParams(e);let n=t.data;return t.parsedType===on.undefined&&(n=this._def.defaultValue()),this._def.innerType._parse({data:n,path:t.path,parent:t})}removeDefault(){return this._def.innerType}}Ar.create=(e,t)=>new Ar({innerType:e,typeName:Rr.ZodDefault,defaultValue:"function"==typeof t.default?t.default:()=>t.default,...kn(t)});class Pr extends On{_parse(e){const{ctx:t}=this._processInputParams(e),n={...t,common:{...t.common,issues:[]}},r=this._def.innerType._parse({data:n.data,path:n.path,parent:{...n}});return wn(r)?r.then(e=>({status:"valid",value:"valid"===e.status?e.value:this._def.catchValue({get error(){return new cn(n.common.issues)},input:n.data})})):{status:"valid",value:"valid"===r.status?r.value:this._def.catchValue({get error(){return new cn(n.common.issues)},input:n.data})}}removeCatch(){return this._def.innerType}}Pr.create=(e,t)=>new Pr({innerType:e,typeName:Rr.ZodCatch,catchValue:"function"==typeof t.catch?t.catch:()=>t.catch,...kn(t)});class Ir extends On{_parse(e){if(this._getType(e)!==on.nan){const t=this._getOrReturnCtx(e);return ln(t,{code:un.invalid_type,expected:on.nan,received:t.parsedType}),pn}return{status:"valid",value:e.data}}}Ir.create=e=>new Ir({typeName:Rr.ZodNaN,...kn(e)});class Tr extends On{_parse(e){const{ctx:t}=this._processInputParams(e),n=t.data;return this._def.type._parse({data:n,path:t.path,parent:t})}unwrap(){return this._def.type}}class Nr extends On{_parse(e){const{status:t,ctx:n}=this._processInputParams(e);if(n.common.async){return(async()=>{const e=await this._def.in._parseAsync({data:n.data,path:n.path,parent:n});return"aborted"===e.status?pn:"dirty"===e.status?(t.dirty(),mn(e.value)):this._def.out._parseAsync({data:e.value,path:n.path,parent:n})})()}{const e=this._def.in._parseSync({data:n.data,path:n.path,parent:n});return"aborted"===e.status?pn:"dirty"===e.status?(t.dirty(),{status:"dirty",value:e.value}):this._def.out._parseSync({data:e.value,path:n.path,parent:n})}}static create(e,t){return new Nr({in:e,out:t,typeName:Rr.ZodPipeline})}}class Cr extends On{_parse(e){const t=this._def.innerType._parse(e),n=e=>(vn(e)&&(e.value=Object.freeze(e.value)),e);return wn(t)?t.then(e=>n(e)):n(t)}unwrap(){return this._def.innerType}}function $r(e,t){const n="function"==typeof e?e(t):"string"==typeof e?{message:e}:e;return"string"==typeof n?{message:n}:n}var Rr;Cr.create=(e,t)=>new Cr({innerType:e,typeName:Rr.ZodReadonly,...kn(t)}),function(e){e.ZodString="ZodString",e.ZodNumber="ZodNumber",e.ZodNaN="ZodNaN",e.ZodBigInt="ZodBigInt",e.ZodBoolean="ZodBoolean",e.ZodDate="ZodDate",e.ZodSymbol="ZodSymbol",e.ZodUndefined="ZodUndefined",e.ZodNull="ZodNull",e.ZodAny="ZodAny",e.ZodUnknown="ZodUnknown",e.ZodNever="ZodNever",e.ZodVoid="ZodVoid",e.ZodArray="ZodArray",e.ZodObject="ZodObject",e.ZodUnion="ZodUnion",e.ZodDiscriminatedUnion="ZodDiscriminatedUnion",e.ZodIntersection="ZodIntersection",e.ZodTuple="ZodTuple",e.ZodRecord="ZodRecord",e.ZodMap="ZodMap",e.ZodSet="ZodSet",e.ZodFunction="ZodFunction",e.ZodLazy="ZodLazy",e.ZodLiteral="ZodLiteral",e.ZodEnum="ZodEnum",e.ZodEffects="ZodEffects",e.ZodNativeEnum="ZodNativeEnum",e.ZodOptional="ZodOptional",e.ZodNullable="ZodNullable",e.ZodDefault="ZodDefault",e.ZodCatch="ZodCatch",e.ZodPromise="ZodPromise",e.ZodBranded="ZodBranded",e.ZodPipeline="ZodPipeline",e.ZodReadonly="ZodReadonly"}(Rr||(Rr={}));const Br=Gn.create,Ur=Qn.create,jr=Xn.create,Zr=Jn.create,zr=er.create,Lr=rr.create,Fr=ir.create,Dr=ur.create,Hr=dr.create,qr=fr.create,Vr=mr.create,Mr=_r.create;jr(),Zr(),zr();const Kr=Ur().min(Number.MIN_SAFE_INTEGER).max(Number.MAX_SAFE_INTEGER).int(),Wr=((e,t={message:`Input not instance of ${e.name}`})=>function(e,t={},n){return e?ir.create().superRefine((r,i)=>{const s=e(r);if(s instanceof Promise)return s.then(e=>{if(!e){const e=$r(t,r),s=e.fatal??n??!0;i.addIssue({code:"custom",...e,fatal:s})}});if(!s){const e=$r(t,r),s=e.fatal??n??!0;i.addIssue({code:"custom",...e,fatal:s})}}):ir.create()}(t=>t instanceof e,t))(Uint8Array);Br(),Kr.min(5e8),Fr(),Kr.min(0).max(255),Kr.min(0).max(65535);const Gr=Kr.min(0).max(4294967295);Ur().refine(e=>String(e).includes(".")).refine(e=>{const t=String(e).split(".").at(1);return void 0!==t&&t.length<=2});const Yr=Br().regex(/^[0-9a-fA-F]*$/).refine(e=>e.length%2==0),Qr=qr([Br(),Ur(),Zr(),Lr()]),Xr=Mr(()=>qr([Qr,Dr(Xr),Vr(Xr)]));Wr.refine(e=>20===e.length);const Jr=Wr.refine(e=>32===e.length),ei=Wr.refine(e=>33===e.length),ti=Wr.refine(e=>64===e.length);Yr.refine(e=>40===e.length);const ni=Yr.refine(e=>64===e.length),ri=Yr.refine(e=>66===e.length),ii=Yr.refine(e=>128===e.length);qr([Yr,Wr]);const si=qr([ni,Jr]);
13
13
  /*! scure-base - MIT License (c) 2022 Paul Miller (paulmillr.com) */
14
- function oi(e){return e instanceof Uint8Array||ArrayBuffer.isView(e)&&"Uint8Array"===e.constructor.name}function ai(e,...t){if(!oi(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 ui(e,t){return!!Array.isArray(t)&&(0===t.length||(e?t.every(e=>"string"==typeof e):t.every(e=>Number.isSafeInteger(e))))}function ci(e){if("function"!=typeof e)throw new Error("function expected");return!0}function di(e,t){if("string"!=typeof t)throw new Error(`${e}: string expected`);return!0}function fi(e){if(!Number.isSafeInteger(e))throw new Error(`invalid integer: ${e}`)}function hi(e){if(!Array.isArray(e))throw new Error("array expected")}function li(e,t){if(!ui(!0,t))throw new Error(`${e}: array of strings expected`)}function pi(e,t){if(!ui(!1,t))throw new Error(`${e}: array of numbers expected`)}function gi(...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 mi(e){const t="string"==typeof e?e.split(""):e,n=t.length;li("alphabet",t);const r=new Map(t.map((e,t)=>[e,t]));return{encode:r=>(hi(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=>(hi(t),t.map(t=>{di("alphabet.decode",t);const n=r.get(t);if(void 0===n)throw new Error(`Unknown letter: "${t}". Allowed: ${e}`);return n}))}}function yi(e=""){return di("join",e),{encode:t=>(li("join.decode",t),t.join(e)),decode:t=>(di("join.decode",t),t.split(e))}}function wi(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(hi(e),!e.length)return[];let r=0;const i=[],s=Array.from(e,e=>{if(fi(e),e<0||e>=t)throw new Error(`invalid integer: ${e}`);return e}),o=s.length;for(;;){let e=0,a=!0;for(let i=r;i<o;i++){const o=s[i],u=t*e,c=u+o;if(!Number.isSafeInteger(c)||u/t!==e||c-o!==u)throw new Error("convertRadix: carry overflow");const d=c/n;e=c%n;const f=Math.floor(d);if(s[i]=f,!Number.isSafeInteger(f)||f*n+e!==c)throw new Error("convertRadix: carry overflow");a&&(f?a=!1:r=i)}if(i.push(e),a)break}for(let t=0;t<e.length-1&&0===e[t];t++)i.push(0);return i.reverse()}Zr([ri,ei]),Zr([ii,ti]),Br().regex(/^[1-9A-HJ-NP-Za-km-z]+$/),Br().regex(/^[a-zA-Z0-9+/]+={0,2}$/),Br().regex(/^[a-zA-Z0-9\-_]+={0,2}$/),Br().regex(/^[a-z]+1[023456789acdefghjklmnpqrstuvwxyz]+$/);const vi=(e,t)=>0===t?e:vi(t,e%t),_i=(e,t)=>e+(t-vi(e,t)),bi=(()=>{let e=[];for(let t=0;t<40;t++)e.push(2**t);return e})();function Ei(e,t,n,r){if(hi(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(_i(t,n)>32)throw new Error(`convertRadix2: carry overflow from=${t} to=${n} carryBits=${_i(t,n)}`);let i=0,s=0;const o=bi[t],a=bi[n]-1,u=[];for(const r of e){if(fi(r),r>=o)throw new Error(`convertRadix2: invalid data word=${r} from=${t}`);if(i=i<<t|r,s+t>32)throw new Error(`convertRadix2: carry overflow pos=${s} from=${t}`);for(s+=t;s>=n;s-=n)u.push((i>>s-n&a)>>>0);const e=bi[s];if(void 0===e)throw new Error("invalid carry");i&=e-1}if(i=i<<n-s&a,!r&&s>=t)throw new Error("Excess padding");if(!r&&i>0)throw new Error(`Non-zero padding: ${i}`);return r&&s>0&&u.push(i>>>0),u}function xi(e,t=!1){if(fi(e),e<=0||e>32)throw new Error("radix2: bits should be in (0..32]");if(_i(8,e)>32||_i(e,8)>32)throw new Error("radix2: carry overflow");return{encode:n=>{if(!oi(n))throw new Error("radix2.encode input should be Uint8Array");return Ei(Array.from(n),8,e,!t)},decode:n=>(pi("radix2.decode",n),Uint8Array.from(Ei(n,e,8,t)))}}function Si(e){return ci(e),function(...t){try{return e.apply(null,t)}catch(e){}}}const ki=(()=>"function"==typeof Uint8Array.from([]).toBase64&&"function"==typeof Uint8Array.fromBase64)()?{encode:e=>(ai(e),e.toBase64()),decode:e=>(e=>{if(di("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)}:gi(xi(6),mi("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"),function(e,t="="){return fi(e),di("padding",t),{encode(n){for(li("padding.encode",n);n.length*e%8;)n.push(t);return n},decode(n){li("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),yi("")),Oi=gi(xi(6),mi("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_"),yi("")),Ai=(Pi="123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz",gi(function(e){return fi(e),{encode:t=>{if(!oi(t))throw new Error("radix.encode input should be Uint8Array");return wi(Array.from(t),256,e)},decode:t=>(pi("radix.decode",t),Uint8Array.from(wi(t,e,256)))}}(58),mi(Pi),yi("")));var Pi;const Ti=e=>{return gi((n=t=>e(e(t)),fi(t=4),ci(n),{encode(e){if(!oi(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(!oi(e))throw new Error("checksum.decode: input should be Uint8Array");const r=e.slice(0,-t),i=e.slice(-t),s=n(r).slice(0,t);for(let e=0;e<t;e++)if(s[e]!==i[e])throw new Error("Invalid checksum");return r}}),Ai);var t,n},Ii=gi(mi("qpzry9x8gf2tvdw0s3jn54khce6mua7l"),yi("")),Ni=[996825010,642813549,513874426,1027748829,705979059];function $i(e){const t=e>>25;let n=(33554431&e)<<5;for(let e=0;e<Ni.length;e++)1==(t>>e&1)&&(n^=Ni[e]);return n}function Ui(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=$i(i)^n>>5}i=$i(i);for(let t=0;t<r;t++)i=$i(i)^31&e.charCodeAt(t);for(let e of t)i=$i(i)^e;for(let e=0;e<6;e++)i=$i(i);return i^=n,Ii.encode(Ei([i%bi[30]],30,5,!1))}function Ci(e){const t="bech32"===e?1:734539939,n=xi(5),r=n.decode,i=n.encode,s=Si(r);function o(e,n,r=90){di("bech32.encode prefix",e),oi(n)&&(n=Array.from(n)),pi("bech32.encode",n);const i=e.length;if(0===i)throw new TypeError(`Invalid prefix length ${i}`);const s=i+7+n.length;if(!1!==r&&s>r)throw new TypeError(`Length ${s} exceeds limit ${r}`);const o=e.toLowerCase(),a=Ui(o,n,t);return`${o}1${Ii.encode(n)}${a}`}function a(e,n=90){di("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 s=i.lastIndexOf("1");if(0===s||-1===s)throw new Error('Letter "1" must be present between prefix and data only');const o=i.slice(0,s),a=i.slice(s+1);if(a.length<6)throw new Error("Data must be at least 6 characters long");const u=Ii.decode(a).slice(0,-6),c=Ui(o,u,t);if(!a.endsWith(c))throw new Error(`Invalid checksum in ${e}: expected "${c}"`);return{prefix:o,words:u}}return{encode:o,decode:a,encodeFromBytes:function(e,t){return o(e,i(t))},decodeToBytes:function(e){const{prefix:t,words:n}=a(e,!1);return{prefix:t,words:n,bytes:r(n)}},decodeUnsafe:Si(a),fromWords:r,fromWordsUnsafe:s,toWords:i}}const Bi=Ci("bech32"),Ri=Ci("bech32m"),Li={encode:e=>(new TextDecoder).decode(e),decode:e=>(new TextEncoder).encode(e)},zi=(()=>"function"==typeof Uint8Array.from([]).toHex&&"function"==typeof Uint8Array.fromHex)()?{encode:e=>(ai(e),e.toHex()),decode:e=>(di("hex",e),Uint8Array.fromHex(e))}:gi(xi(4),mi("0123456789abcdef"),yi(""),(ci(ji=e=>{if("string"!=typeof e||e.length%2!=0)throw new TypeError(`hex.decode: expected string, got ${typeof e} with length ${e.length}`);return e.toLowerCase()}),{encode:e=>e,decode:e=>ji(e)}));var ji,Hi,Di,Fi,Vi,Zi;function Ki(e){if("string"!=typeof e||0===e.length)throw new Error(`invalid prefix: ${String(e)}`)}function Wi(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),Ti(ee).encode(e)),e.decode=e=>(b.is_base58(e),Ti(ee).decode(e))}(Hi||(Hi={})),function(e){e.encode=e=>(b.is_u8a(e),ki.encode(e)),e.decode=e=>(b.is_base64(e),ki.decode(e))}(Di||(Di={})),function(e){e.encode=e=>(b.is_u8a(e),Oi.encode(e)),e.decode=e=>(b.is_b64url(e),Oi.decode(e))}(Fi||(Fi={})),function(e){e.to_words=Bi.toWords,e.to_bytes=Bi.fromWords,e.encode=(e,t,n=!1)=>(Ki(e),Wi(t),Bi.encode(e,t,n)),e.decode=(e,t=!1)=>(b.is_bech32(e),Bi.decode(e,t))}(Vi||(Vi={})),function(e){e.to_words=Ri.toWords,e.to_bytes=Ri.fromWords,e.encode=(e,t,n=!1)=>(Ki(e),Wi(t),Ri.encode(e,t,n)),e.decode=(e,t=!1)=>(b.is_bech32(e),Ri.decode(e,t))}(Zi||(Zi={}));const Mi={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}$/},qi=0,Gi=1;function Yi(e){const t=function(e){for(const[t,n]of Object.entries(Mi))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=Hi.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}=Vi.decode(e),[r,...i]=n;b.ok(r===qi,"bech32 version mismatch");return{data:Vi.to_bytes(i),format:"bech32",prefix:t,version:r}}(e);if("bech32m"===t)return function(e){const{prefix:t,words:n}=Zi.decode(e),[r,...i]=n;b.ok(r===Gi,"bech32m version mismatch");return{data:Zi.to_bytes(i),format:"bech32m",prefix:t,version:r}}(e);throw new Error("unable to find a matching address configuration")}function Qi(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=m.join([e.version,e.data]);return Hi.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=m.bytes(e.data),n=Vi.to_words(t);return Vi.encode(e.prefix,[qi,...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=m.bytes(e.data),n=Zi.to_words(t);return Zi.encode(e.prefix,[Gi,...n])}(e);throw new Error("unrecognized encoding format: "+e.format)}const Xi=[["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 Ji(e,t){for(const[n,r,i,s,o,a]of Xi)if(r===t&&i===e)return{type:r,prefix:n,network:i,size:s,format:o,version:a};return null}function es(e){const t=function(e){const t=Yi(e);for(const[n,r,i,s,o,a]of Xi){if(o!==t.format)continue;if(s!==t.data.length)continue;if(a!==t.version)continue;if(t.prefix){if(n!==t.prefix)continue}else if(!e.startsWith(n))continue;const u=m.uint(t.data).hex;return{data:t.data,hex:u,type:r,prefix:n,network:i,size:s,format:o,version:a}}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 ts="p2pkh";var ns;function rs(e,t="main"){return is(Jt(m.bytes(e)),t)}function is(e,t="main"){const n=m.bytes(e),r=Ji(t,ts);return b.exists(r,`unrecognized address config: ${ts} on ${t}`),b.size(n,r.size,`invalid payload size: ${n.length} !== ${r.size}`),Qi({data:n,format:"base58",version:r.version})}function ss(e){const t=es(e);return b.ok("p2pkh"===t.type,`address type mismatch: ${t.type} !== ${ts}`),t}!function(e){e.create=rs,e.encode=is,e.decode=ss}(ns||(ns={}));const os="p2sh";var as;function us(e,t="main"){return cs(Jt(m.bytes(e)),t)}function cs(e,t="main"){const n=m.bytes(e),r=Ji(t,os);return b.exists(r,`unrecognized address config: ${os} on ${t}`),b.size(n,r.size,`invalid payload size: ${n.length} !== ${r.size}`),Qi({data:n,format:"base58",version:r.version})}function ds(e){const t=es(e);return b.ok("p2sh"===t.type,`address type mismatch: ${t.type} !== ${os}`),t}!function(e){e.create=us,e.encode=cs,e.decode=ds}(as||(as={}));const fs="p2w-pkh";var hs;function ls(e,t="main"){const n=m.bytes(e);b.size(n,33,`invalid payload size: ${n.length} !== 33`);return ps(Jt(n),t)}function ps(e,t="main"){const n=m.bytes(e),r=Ji(t,fs);return b.exists(r,`unrecognized address config: ${fs} on ${t}`),b.size(n,r.size,`invalid payload size: ${n.length} !== ${r.size}`),Qi({data:n,format:"bech32",prefix:r.prefix})}function gs(e){const t=es(e);return b.ok("p2w-pkh"===t.type,`address type mismatch: ${t.type} !== ${fs}`),t}!function(e){e.create=ls,e.encode=ps,e.decode=gs}(hs||(hs={}));const ms="p2w-sh";var ys;function ws(e,t="main"){return vs(en(m.bytes(e)),t)}function vs(e,t="main"){const n=m.bytes(e),r=Ji(t,ms);return b.exists(r,`unrecognized address config: ${ms} on ${t}`),b.size(n,r.size,`invalid payload size: ${n.length} !== ${r.size}`),Qi({data:n,format:"bech32",prefix:r.prefix})}function _s(e){const t=es(e);return b.ok("p2w-sh"===t.type,`address type mismatch: ${t.type} !== ${ms}`),t}!function(e){e.create=ws,e.encode=vs,e.decode=_s}(ys||(ys={}));const bs="p2tr";var Es,xs;function Ss(e,t="main"){const n=m.bytes(e),r=Ji(t,bs);return b.exists(r,`unrecognized address config: ${bs} on ${t}`),b.size(n,r.size,`invalid payload size: ${n.length} !== ${r.size}`),Qi({data:n,format:"bech32m",prefix:r.prefix})}function ks(e){const t=es(e);return b.ok("p2tr"===t.type,`address type mismatch: ${t.type} !== ${bs}`),t}!function(e){e.encode=Ss,e.decode=ks}(Es||(Es={})),function(e){e.P2PKH=ns,e.P2SH=as,e.P2WPKH=hs,e.P2WSH=ys,e.P2TR=Es,e.parse=es}(xs||(xs={}));var Os=Object.freeze({__proto__:null,get AddressTool(){return xs},get P2PKH(){return ns},get P2SH(){return as},get P2TR(){return Es},get P2WPKH(){return hs},get P2WSH(){return ys},parse_address:es});const As=5e8;var Ps,Ts;function Is(e){switch(e.type){case"timelock":return b.ok(e.stamp>=As,"Invalid timestamp"),e.stamp;case"heightlock":return b.ok(e.height>0,"height must be greater than 0"),b.ok(e.height<As,"invalid block height"),e.height;default:throw new Error("Invalid locktime type")}}function Ns(e){return isNaN(e)||e<=0?null:e<As?{type:"heightlock",height:e}:{type:"timelock",stamp:e}}function $s(e,t=0){return`${e}i${t}`}function Us(e){Bs(e);const[t,n]=e.split("i");return{txid:t,order:parseInt(n)}}function Cs(e){return null!==e.match(/^[a-f0-9]{64}i\d+$/)}function Bs(e){if(!Cs(e))throw new Error(`invalid inscription id: ${e}`)}function Rs(e,t){return`${e}:${t}`}function Ls(e){js(e);const[t,n]=e.split(":");return{block_height:parseInt(t),block_index:parseInt(n)}}function zs(e){return null!==e.match(/^\d+:\d+$/)}function js(e){if(!zs(e))throw new Error(`invalid rune id: ${e}`)}function Hs(e,t){return`${e}:${t}`}function Ds(e){Vs(e);const[t,n]=e.split(":");return{txid:t,vout:parseInt(n)}}function Fs(e){return null!==e.match(/^[a-f0-9]{64}:[0-9]+$/)}function Vs(e){if(!Fs(e))throw new Error(`invalid outpoint: ${e}`)}!function(e){e.encode=Is,e.decode=Ns}(Ps||(Ps={})),function(e){e.outpoint={encode:Hs,decode:Ds,verify:Fs,assert:Vs},e.record_id={encode:$s,decode:Us,verify:Cs,assert:Bs},e.rune_id={encode:Rs,decode:Ls,verify:zs,assert:js}}(Ts||(Ts={}));const Zs={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 Ks(e){if(e>186&&e<255)return"OP_SUCCESS"+String(e);for(const[t,n]of Object.entries(Zs))if(n===e)return t;throw new Error("OPCODE not found:"+String(e))}function Ws(e){for(const[t,n]of Object.entries(Zs))if(t===e)return Number(n);throw new Error("OPCODE not found:"+e)}function Ms(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 qs(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 Gs=520;function Ys(e,t=!1){if(0===e.length)return"00";const n=[];for(const t of e)n.push(Qs(t));const r=m.join(n);return t?r.prepend(m.varint(r.length,"le")).hex:r.hex}function Qs(e){let t;if("string"==typeof e){if(e.startsWith("OP_")){const t=Ws(e);return m.num(t,1)}t=m.is_hex(e)?m.hex(e):m.str(e)}else if("number"==typeof e)t=m.num(e);else{if(!(e instanceof Uint8Array))throw new Error("invalid word type:"+typeof e);t=new m(e)}if(1===t.length&&t[0]<=16)0!==t[0]&&(t[0]+=80);else if(t.length>Gs){let e;e=Xs(t),e=e.map(e=>Js(e)),t=m.join(e)}else t=Js(t);return t}function Xs(e){const t=[],n=new y(e);for(;n.size>Gs;)t.push(n.read(Gs));return t.push(n.read(n.size)),t}function Js(e){const t=eo(e.length);return m.join([t,e])}function eo(e){const t=m.num(76,1),n=m.num(77,1);switch(!0){case e<=75:return m.num(e);case e>75&&e<256:return m.join([t,m.num(e,1,"le")]);case e>=256&&e<=Gs:return m.join([n,m.num(e,2,"le")]);default:throw new Error("Invalid word size:"+e.toString())}}function to(e){const t=new y(e),n=[],r=t.size;let i,s,o,a=0;for(;a<r;)switch(i=t.read(1).num,s=Ms(i),a++,s){case"varint":n.push(t.read(i).hex),a+=i;break;case"pushdata1":o=t.read(1).reverse().num,n.push(t.read(o).hex),a+=o+1;break;case"pushdata2":o=t.read(2).reverse().num,n.push(t.read(o).hex),a+=o+2;break;case"pushdata4":o=t.read(4).reverse().num,n.push(t.read(o).hex),a+=o+4;break;case"opcode":if(!qs(i))throw new Error(`Invalid OPCODE: ${i}`);n.push(Ks(i));break;default:throw new Error(`Word type undefined: ${i}`)}return n}function no(e){try{return to(e).length>0}catch{return!1}}const ro=BigInt(0),io=BigInt(1),so=BigInt(26);var oo;function ao(e){const t=function(e){const t=to(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(fo)}function uo(e){return e.map(co).join("")}function co(e){let t=["OP_0","OP_IF","6f7264"];if("string"==typeof e.delegate){const n=ho(e.delegate);t.push("OP_11",n)}if("string"==typeof e.ref&&t.push("OP_WITHIN",e.ref),"string"==typeof e.parent){const n=ho(e.parent);t.push("OP_3",n)}if("number"==typeof e.opcode){const n=po(e.opcode);t.push("OP_NOP",n)}if("number"==typeof e.pointer){const n=po(e.pointer);t.push("OP_2",n)}if("string"==typeof e.rune){const n=function(e){const t=e.toUpperCase();let n=ro;for(const e of t)e>="A"&&e<="Z"&&(n=n*so+BigInt(e.charCodeAt(0)-("A".charCodeAt(0)-1)));return n-=io,m.big(n).reverse().hex}(e.rune);t.push("OP_13",n)}if("string"==typeof e.mimetype){const n=function(e){return m.str(e).hex}(e.mimetype);t.push("OP_1",n)}if("string"==typeof e.content){const n=function(e){const t=m.is_hex(e)?m.hex(e):m.str(e),n=new y(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"),Ys(t)}function fo(e){const t={};for(let n=0;n<e.length;n++)switch(e[n]){case"OP_1":t.mimetype=mo(e[n+1]),n+=1;break;case"OP_2":t.pointer=go(e[n+1]),n+=1;break;case"OP_3":t.parent=lo(e[n+1]),n+=1;break;case"OP_11":t.delegate=lo(e[n+1]),n+=1;break;case"OP_13":t.rune=wo(e[n+1]),n+=1;break;case"OP_WITHIN":t.ref=e[n+1],n+=1;break;case"OP_NOP":t.opcode=go(e[n+1]),n+=1;break;case"OP_0":return t.content=yo(e.slice(n+1)),t}return t}function ho(e){b.ok(e.includes("i"),"identifier must include an index");const t=e.split("i"),n=m.hex(t[0]),r=Number(t[1]),i=n.reverse().hex;return 0!==r?i+m.num(r).hex:i}function lo(e){const t=m.hex(e),n=t.at(-1)??0;return t.slice(0,-1).reverse().hex+"i"+String(n)}function po(e){return m.num(e).reverse().hex}function go(e){return m.hex(e).reverse().num}function mo(e){return m.hex(e).str}function yo(e,t="hex"){const n=m.join(e);return"hex"===t?n.hex:n.str}function wo(e){let t=m.hex(e).reverse().big;t+=io;let n="";for(;t>ro;){const e=t%so;if(e===ro)n="Z"+n,t=t/so-io;else{const r=Number(e)+"A".charCodeAt(0)-1;n=String.fromCharCode(r)+n,t/=so}}return n}!function(e){e.encode=uo,e.decode=ao}(oo||(oo={}));const vo=4194304,_o=65535,bo=65535;var Eo;function xo(e){if("height"===e.mode){return(function(e){if(void 0===e||!Number.isInteger(e)||e<0||e>bo)throw new Error("Heightlock value must be an integer between 0 and 65535");return e}(e.height)&_o)>>>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>bo)throw new Error("timelock value must be an integer between 0 and 65535 (in 512-second increments)");return t}(e.stamp);return(vo|t&_o)>>>0}throw new Error("invalid timelock mode: "+e.mode)}function So(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&_o;if(t&vo){const e=512*n;if(e>4294967295)throw new Error("Decoded timestamp exceeds 32-bit limit");return{mode:"stamp",stamp:e}}if(n>bo)throw new Error("Decoded height exceeds maximum");return{mode:"height",height:n}}!function(e){e.encode=xo,e.decode=So}(Eo||(Eo={}));var ko=Object.freeze({__proto__:null,get LocktimeUtil(){return Ps},get RefEncoder(){return Ts},get ScribeEncoder(){return oo},get SequenceUtil(){return Eo},decode_inscription:ao,decode_locktime:Ns,decode_sequence:So,encode_inscription:uo,encode_locktime:Is,encode_sequence:xo});const Oo=new Uint8Array,Ao=new Uint8Array([0]);function Po(e,t){if(e.length!==t.length)return!1;for(let n=0;n<e.length;n++)if(e[n]!==t[n])return!1;return!0}function To(e){return e instanceof Uint8Array||ArrayBuffer.isView(e)&&"Uint8Array"===e.constructor.name}const Io=e=>new DataView(e.buffer,e.byteOffset,e.byteLength);function No(e){return"[object Object]"===Object.prototype.toString.call(e)}function $o(e){return Number.isSafeInteger(e)}const Uo=Po,Co=To,Bo=function(...e){let t=0;for(let n=0;n<e.length;n++){const r=e[n];if(!To(r))throw new Error("Uint8Array expected");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},Ro=e=>{if(null!==e&&"string"!=typeof e&&!Wo(e)&&!To(e)&&!$o(e))throw new Error(`lengthCoder: expected null | number | Uint8Array | CoderType, got ${e} (${typeof e})`);return{encodeStream(t,n){if(null===e)return;if(Wo(e))return e.encodeStream(t,n);let r;if("number"==typeof e?r=e:"string"==typeof e&&(r=zo.resolve(t.stack,e)),"bigint"==typeof r&&(r=Number(r)),void 0===r||r!==n)throw t.err(`Wrong length: ${r} len=${e} exp=${n} (${typeof n})`)},decodeStream(t){let n;if(Wo(e)?n=Number(e.decodeStream(t)):"number"==typeof e?n=e:"string"==typeof e&&(n=zo.resolve(t.stack,e)),"bigint"==typeof n&&(n=Number(n)),"number"!=typeof n)throw t.err(`Wrong length: ${n}`);return n}}},Lo={BITS:32,FULL_MASK:-1>>>0,len:e=>Math.ceil(e/32),create:e=>new Uint32Array(Lo.len(e)),clean:e=>e.fill(0),debug:e=>Array.from(e).map(e=>(e>>>0).toString(2).padStart(32,"0")),checkLen:(e,t)=>{if(Lo.len(t)!==e.length)throw new Error(`wrong length=${e.length}. Expected: ${Lo.len(t)}`)},chunkLen:(e,t,n)=>{if(t<0)throw new Error(`wrong pos=${t}`);if(t+n>e)throw new Error(`wrong range=${t}/${n} of ${e}`)},set:(e,t,n,r=!0)=>!(!r&&0!==(e[t]&n))&&(e[t]|=n,!0),pos:(e,t)=>({chunk:Math.floor((e+t)/32),mask:1<<32-(e+t)%32-1}),indices:(e,t,n=!1)=>{Lo.checkLen(e,t);const{FULL_MASK:r,BITS:i}=Lo,s=i-t%i,o=s?r>>>s<<s:r,a=[];for(let t=0;t<e.length;t++){let r=e[t];if(n&&(r=~r),t===e.length-1&&(r&=o),0!==r)for(let e=0;e<i;e++){r&1<<i-e-1&&a.push(t*i+e)}}return a},range:e=>{const t=[];let n;for(const r of e)void 0===n||r!==n.pos+n.length?t.push(n={pos:r,length:1}):n.length+=1;return t},rangeDebug:(e,t,n=!1)=>`[${Lo.range(Lo.indices(e,t,n)).map(e=>`(${e.pos}/${e.length})`).join(", ")}]`,setRange:(e,t,n,r,i=!0)=>{Lo.chunkLen(t,n,r);const{FULL_MASK:s,BITS:o}=Lo,a=n%o?Math.floor(n/o):void 0,u=n+r,c=u%o?Math.floor(u/o):void 0;if(void 0!==a&&a===c)return Lo.set(e,a,s>>>o-r<<o-r-n,i);if(void 0!==a&&!Lo.set(e,a,s>>>n%o,i))return!1;const d=void 0!==c?c:u/o;for(let t=void 0!==a?a+1:n/o;t<d;t++)if(!Lo.set(e,t,s,i))return!1;return!(void 0!==c&&a!==c&&!Lo.set(e,c,s<<o-u%o,i))}},zo={pushObj:(e,t,n)=>{const r={obj:t};e.push(r),n((e,t)=>{r.field=e,t(),r.field=void 0}),e.pop()},path:e=>{const t=[];for(const n of e)void 0!==n.field&&t.push(n.field);return t.join("/")},err:(e,t,n)=>{const r=new Error(`${e}(${zo.path(t)}): ${"string"==typeof n?n:n.message}`);return n instanceof Error&&n.stack&&(r.stack=n.stack),r},resolve:(e,t)=>{const n=t.split("/"),r=e.map(e=>e.obj);let i=0;for(;i<n.length&&".."===n[i];i++)r.pop();let s=r.pop();for(;i<n.length;i++){if(!s||void 0===s[n[i]])return;s=s[n[i]]}return s}};class jo{constructor(e,t={},n=[],r=void 0,i=0){this.pos=0,this.bitBuf=0,this.bitPos=0,this.data=e,this.opts=t,this.stack=n,this.parent=r,this.parentOffset=i,this.view=Io(e)}_enablePointers(){if(this.parent)return this.parent._enablePointers();this.bs||(this.bs=Lo.create(this.data.length),Lo.setRange(this.bs,this.data.length,0,this.pos,this.opts.allowMultipleReads))}markBytesBS(e,t){return this.parent?this.parent.markBytesBS(this.parentOffset+e,t):!t||(!this.bs||Lo.setRange(this.bs,this.data.length,e,t,!1))}markBytes(e){const t=this.pos;this.pos+=e;const n=this.markBytesBS(t,e);if(!this.opts.allowMultipleReads&&!n)throw this.err(`multiple read pos=${this.pos} len=${e}`);return n}pushObj(e,t){return zo.pushObj(this.stack,e,t)}readView(e,t){if(!Number.isFinite(e))throw this.err(`readView: wrong length=${e}`);if(this.pos+e>this.data.length)throw this.err("readView: Unexpected end of buffer");const n=t(this.view,this.pos);return this.markBytes(e),n}absBytes(e){if(e>this.data.length)throw new Error("Unexpected end of buffer");return this.data.subarray(e)}finish(){if(!this.opts.allowUnreadBytes){if(this.bitPos)throw this.err(`${this.bitPos} bits left after unpack: ${zi.encode(this.data.slice(this.pos))}`);if(this.bs&&!this.parent){const e=Lo.indices(this.bs,this.data.length,!0);if(e.length){const t=Lo.range(e).map(({pos:e,length:t})=>`(${e}/${t})[${zi.encode(this.data.subarray(e,e+t))}]`).join(", ");throw this.err(`unread byte ranges: ${t} (total=${this.data.length})`)}return}if(!this.isEnd())throw this.err(`${this.leftBytes} bytes ${this.bitPos} bits left after unpack: ${zi.encode(this.data.slice(this.pos))}`)}}err(e){return zo.err("Reader",this.stack,e)}offsetReader(e){if(e>this.data.length)throw this.err("offsetReader: Unexpected end of buffer");return new jo(this.absBytes(e),this.opts,this.stack,this,e)}bytes(e,t=!1){if(this.bitPos)throw this.err("readBytes: bitPos not empty");if(!Number.isFinite(e))throw this.err(`readBytes: wrong length=${e}`);if(this.pos+e>this.data.length)throw this.err("readBytes: Unexpected end of buffer");const n=this.data.subarray(this.pos,this.pos+e);return t||this.markBytes(e),n}byte(e=!1){if(this.bitPos)throw this.err("readByte: bitPos not empty");if(this.pos+1>this.data.length)throw this.err("readBytes: Unexpected end of buffer");const t=this.data[this.pos];return e||this.markBytes(1),t}get leftBytes(){return this.data.length-this.pos}get totalBytes(){return this.data.length}isEnd(){return this.pos>=this.data.length&&!this.bitPos}bits(e){if(e>32)throw this.err("BitReader: cannot read more than 32 bits in single call");let t=0;for(;e;){this.bitPos||(this.bitBuf=this.byte(),this.bitPos=8);const n=Math.min(e,this.bitPos);this.bitPos-=n,t=t<<n|this.bitBuf>>this.bitPos&2**n-1,this.bitBuf&=2**this.bitPos-1,e-=n}return t>>>0}find(e,t=this.pos){if(!To(e))throw this.err(`find: needle is not bytes! ${e}`);if(this.bitPos)throw this.err("findByte: bitPos not empty");if(!e.length)throw this.err("find: needle is empty");for(let n=t;-1!==(n=this.data.indexOf(e[0],n));n++){if(-1===n)return;if(this.data.length-n<e.length)return;if(Po(e,this.data.subarray(n,n+e.length)))return n}}}class Ho{constructor(e=[]){this.pos=0,this.buffers=[],this.ptrs=[],this.bitBuf=0,this.bitPos=0,this.viewBuf=new Uint8Array(8),this.finished=!1,this.stack=e,this.view=Io(this.viewBuf)}pushObj(e,t){return zo.pushObj(this.stack,e,t)}writeView(e,t){if(this.finished)throw this.err("buffer: finished");if(!$o(e)||e>8)throw new Error(`wrong writeView length=${e}`);t(this.view),this.bytes(this.viewBuf.slice(0,e)),this.viewBuf.fill(0)}err(e){if(this.finished)throw this.err("buffer: finished");return zo.err("Reader",this.stack,e)}bytes(e){if(this.finished)throw this.err("buffer: finished");if(this.bitPos)throw this.err("writeBytes: ends with non-empty bit buffer");this.buffers.push(e),this.pos+=e.length}byte(e){if(this.finished)throw this.err("buffer: finished");if(this.bitPos)throw this.err("writeByte: ends with non-empty bit buffer");this.buffers.push(new Uint8Array([e])),this.pos++}finish(e=!0){if(this.finished)throw this.err("buffer: finished");if(this.bitPos)throw this.err("buffer: ends with non-empty bit buffer");const t=this.buffers.concat(this.ptrs.map(e=>e.buffer)),n=t.map(e=>e.length).reduce((e,t)=>e+t,0),r=new Uint8Array(n);for(let e=0,n=0;e<t.length;e++){const i=t[e];r.set(i,n),n+=i.length}for(let e=this.pos,t=0;t<this.ptrs.length;t++){const n=this.ptrs[t];r.set(n.ptr.encode(e),n.pos),e+=n.buffer.length}if(e){this.buffers=[];for(const e of this.ptrs)e.buffer.fill(0);this.ptrs=[],this.finished=!0,this.bitBuf=0}return r}bits(e,t){if(t>32)throw this.err("writeBits: cannot write more than 32 bits in single call");if(e>=2**t)throw this.err(`writeBits: value (${e}) >= 2**bits (${t})`);for(;t;){const n=Math.min(t,8-this.bitPos);this.bitBuf=this.bitBuf<<n|e>>t-n,this.bitPos+=n,e&=2**(t-=n)-1,8===this.bitPos&&(this.bitPos=0,this.buffers.push(new Uint8Array([this.bitBuf])),this.pos++)}}}const Do=e=>Uint8Array.from(e).reverse();function Fo(e){return{encodeStream:e.encodeStream,decodeStream:e.decodeStream,size:e.size,encode:t=>{const n=new Ho;return e.encodeStream(n,t),n.finish()},decode:(t,n={})=>{const r=new jo(t,n),i=e.decodeStream(r);return r.finish(),i}}}function Vo(e,t){if(!Wo(e))throw new Error(`validate: invalid inner value ${e}`);if("function"!=typeof t)throw new Error("validate: fn should be function");return Fo({size:e.size,encodeStream:(n,r)=>{let i;try{i=t(r)}catch(e){throw n.err(e)}e.encodeStream(n,i)},decodeStream:n=>{const r=e.decodeStream(n);try{return t(r)}catch(e){throw n.err(e)}}})}const Zo=e=>{const t=Fo(e);return e.validate?Vo(t,e.validate):t},Ko=e=>No(e)&&"function"==typeof e.decode&&"function"==typeof e.encode;function Wo(e){return No(e)&&Ko(e)&&"function"==typeof e.encodeStream&&"function"==typeof e.decodeStream&&(void 0===e.size||$o(e.size))}const Mo=e=>{if(!Ko(e))throw new Error("BaseCoder expected");return{encode:e.decode,decode:e.encode}},qo={dict:function(){return{encode:e=>{if(!Array.isArray(e))throw new Error("array expected");const t={};for(const n of e){if(!Array.isArray(n)||2!==n.length)throw new Error("array of two elements expected");const e=n[0],r=n[1];if(void 0!==t[e])throw new Error(`key(${e}) appears twice in struct`);t[e]=r}return t},decode:e=>{if(!No(e))throw new Error(`expected plain object, got ${e}`);return Object.entries(e)}}},numberBigint:{encode:e=>{if("bigint"!=typeof e)throw new Error("expected bigint, got "+typeof e);if(e>BigInt(Number.MAX_SAFE_INTEGER))throw new Error(`element bigger than MAX_SAFE_INTEGER=${e}`);return Number(e)},decode:e=>{if(!$o(e))throw new Error("element is not a safe integer");return BigInt(e)}},tsEnum:function(e){if(!No(e))throw new Error("plain object expected");return{encode:t=>{if(!$o(t)||!(t in e))throw new Error(`wrong value ${t}`);return e[t]},decode:t=>{if("string"!=typeof t)throw new Error("wrong value "+typeof t);return e[t]}}},decimal:function(e,t=!1){if(!$o(e))throw new Error(`decimal/precision: wrong value ${e}`);if("boolean"!=typeof t)throw new Error("decimal/round: expected boolean, got "+typeof t);const n=10n**BigInt(e);return{encode:t=>{if("bigint"!=typeof t)throw new Error("expected bigint, got "+typeof t);let n=(t<0n?-t:t).toString(10),r=n.length-e;r<0&&(n=n.padStart(n.length-r,"0"),r=0);let i=n.length-1;for(;i>=r&&"0"===n[i];i--);let s=n.slice(0,r),o=n.slice(r,i+1);return s||(s="0"),t<0n&&(s="-"+s),o?`${s}.${o}`:s},decode:r=>{if("string"!=typeof r)throw new Error("expected string, got "+typeof r);if("-0"===r)throw new Error("negative zero is not allowed");let i=!1;if(r.startsWith("-")&&(i=!0,r=r.slice(1)),!/^(0|[1-9]\d*)(\.\d+)?$/.test(r))throw new Error(`wrong string value=${r}`);let s=r.indexOf(".");s=-1===s?r.length:s;const o=r.slice(0,s),a=r.slice(s+1).replace(/0+$/,""),u=BigInt(o)*n;if(!t&&a.length>e)throw new Error(`fractional part cannot be represented with this precision (num=${r}, prec=${e})`);const c=Math.min(a.length,e),d=u+BigInt(a.slice(0,c))*10n**BigInt(e-c);return i?-d:d}}},match:function(e){if(!Array.isArray(e))throw new Error("expected array, got "+typeof e);for(const t of e)if(!Ko(t))throw new Error(`wrong base coder ${t}`);return{encode:t=>{for(const n of e){const e=n.encode(t);if(void 0!==e)return e}throw new Error(`match/encode: cannot find match in ${t}`)},decode:t=>{for(const n of e){const e=n.decode(t);if(void 0!==e)return e}throw new Error(`match/decode: cannot find match in ${t}`)}}},reverse:Mo},Go=(e,t=!1,n=!1,r=!0)=>{if(!$o(e))throw new Error(`bigint/size: wrong value ${e}`);if("boolean"!=typeof t)throw new Error("bigint/le: expected boolean, got "+typeof t);if("boolean"!=typeof n)throw new Error("bigint/signed: expected boolean, got "+typeof n);if("boolean"!=typeof r)throw new Error("bigint/sized: expected boolean, got "+typeof r);const i=BigInt(e),s=2n**(8n*i-1n);return Zo({size:r?e:void 0,encodeStream:(i,o)=>{n&&o<0&&(o|=s);const a=[];for(let t=0;t<e;t++)a.push(Number(255n&o)),o>>=8n;let u=new Uint8Array(a).reverse();if(!r){let e=0;for(e=0;e<u.length&&0===u[e];e++);u=u.subarray(e)}i.bytes(t?u.reverse():u)},decodeStream:i=>{const o=i.bytes(r?e:Math.min(e,i.leftBytes)),a=t?o:Do(o);let u=0n;for(let e=0;e<a.length;e++)u|=BigInt(a[e])<<8n*BigInt(e);return n&&u&s&&(u=(u^s)-s),u},validate:e=>{if("bigint"!=typeof e)throw new Error(`bigint: invalid value: ${e}`);return function(e,t,n){if(n){const n=2n**(t-1n);if(e<-n||e>=n)throw new Error(`value out of signed bounds. Expected ${-n} <= ${e} < ${n}`)}else if(0n>e||e>=2n**t)throw new Error(`value out of unsigned bounds. Expected 0 <= ${e} < ${2n**t}`)}(e,8n*i,!!n),e}})},Yo=Go(32,!1),Qo=Go(8,!0),Xo=Go(8,!0,!0),Jo=(e,t,n)=>{const r=8*e,i=2**(r-1),s=2**r;return((e,t)=>Zo({size:e,encodeStream:(n,r)=>n.writeView(e,e=>t.write(e,r)),decodeStream:n=>n.readView(e,t.read),validate:e=>{if("number"!=typeof e)throw new Error("viewCoder: expected number, got "+typeof e);return t.validate&&t.validate(e),e}}))(e,{write:n.write,read:n.read,validate:t?e=>{if(!$o(e))throw new Error(`sintView: value is not safe integer: ${e}`);if(e<-i||e>=i)throw new Error(`sintView: value out of bounds. Expected ${-i} <= ${e} < ${i}`)}:e=>{if(!$o(e))throw new Error(`uintView: value is not safe integer: ${e}`);if(0>e||e>=s)throw new Error(`uintView: value out of bounds. Expected 0 <= ${e} < ${s}`)}})},ea=Jo(4,!1,{read:(e,t)=>e.getUint32(t,!0),write:(e,t)=>e.setUint32(0,t,!0)}),ta=Jo(4,!1,{read:(e,t)=>e.getUint32(t,!1),write:(e,t)=>e.setUint32(0,t,!1)}),na=Jo(4,!0,{read:(e,t)=>e.getInt32(t,!0),write:(e,t)=>e.setInt32(0,t,!0)}),ra=Jo(2,!1,{read:(e,t)=>e.getUint16(t,!0),write:(e,t)=>e.setUint16(0,t,!0)}),ia=Jo(1,!1,{read:(e,t)=>e.getUint8(t),write:(e,t)=>e.setUint8(0,t)}),sa=(e,t=!1)=>{if("boolean"!=typeof t)throw new Error("bytes/le: expected boolean, got "+typeof t);const n=Ro(e),r=To(e);return Zo({size:"number"==typeof e?e:void 0,encodeStream:(i,s)=>{r||n.encodeStream(i,s.length),i.bytes(t?Do(s):s),r&&i.bytes(e)},decodeStream:i=>{let s;if(r){const t=i.find(e);if(!t)throw i.err("bytes: cannot find terminator");s=i.bytes(t-i.pos),i.bytes(e.length)}else s=i.bytes(null===e?i.leftBytes:n.decodeStream(i));return t?Do(s):s},validate:e=>{if(!To(e))throw new Error(`bytes: invalid value ${e}`);return e}})};const oa=(e,t=!1)=>Vo(aa(sa(e,t),Li),e=>{if("string"!=typeof e)throw new Error("expected string, got "+typeof e);return e});function aa(e,t){if(!Wo(e))throw new Error(`apply: invalid inner value ${e}`);if(!Ko(t))throw new Error(`apply: invalid base value ${e}`);return Zo({size:e.size,encodeStream:(n,r)=>{let i;try{i=t.decode(r)}catch(e){throw n.err(""+e)}return e.encodeStream(n,i)},decodeStream:n=>{const r=e.decodeStream(n);try{return t.encode(r)}catch(e){throw n.err(""+e)}}})}function ua(e,t,n=!0){if(!Wo(e))throw new Error(`magic: invalid inner value ${e}`);if("boolean"!=typeof n)throw new Error("magic: expected boolean, got "+typeof n);return Zo({size:e.size,encodeStream:(n,r)=>e.encodeStream(n,t),decodeStream:r=>{const i=e.decodeStream(r);if(n&&"object"!=typeof i&&i!==t||To(t)&&!Po(t,i))throw r.err(`magic: invalid value: ${i} !== ${t}`)},validate:e=>{if(void 0!==e)throw new Error("magic: wrong value="+typeof e);return e}})}function ca(e){let t=0;for(const n of e){if(void 0===n.size)return;if(!$o(n.size))throw new Error(`sizeof: wrong element size=${t}`);t+=n.size}return t}function da(e){if(!No(e))throw new Error(`struct: expected plain object, got ${e}`);for(const t in e)if(!Wo(e[t]))throw new Error(`struct: field ${t} is not CoderType`);return Zo({size:ca(Object.values(e)),encodeStream:(t,n)=>{t.pushObj(n,r=>{for(const i in e)r(i,()=>e[i].encodeStream(t,n[i]))})},decodeStream:t=>{const n={};return t.pushObj(n,r=>{for(const i in e)r(i,()=>n[i]=e[i].decodeStream(t))}),n},validate:e=>{if("object"!=typeof e||null===e)throw new Error(`struct: invalid value ${e}`);return e}})}function fa(e,t){if(!Wo(t))throw new Error(`array: invalid inner value ${t}`);const n=Ro("string"==typeof e?`../${e}`:e);return Zo({size:"number"==typeof e&&t.size?e*t.size:void 0,encodeStream:(r,i)=>{const s=r;s.pushObj(i,o=>{To(e)||n.encodeStream(r,i.length);for(let n=0;n<i.length;n++)o(`${n}`,()=>{const o=i[n],a=r.pos;if(t.encodeStream(r,o),To(e)){if(e.length>s.pos-a)return;const t=s.finish(!1).subarray(a,s.pos);if(Po(t.subarray(0,e.length),e))throw s.err(`array: inner element encoding same as separator. elm=${o} data=${t}`)}})}),To(e)&&r.bytes(e)},decodeStream:r=>{const i=[];return r.pushObj(i,s=>{if(null===e)for(let e=0;!r.isEnd()&&(s(`${e}`,()=>i.push(t.decodeStream(r))),!(t.size&&r.leftBytes<t.size));e++);else if(To(e))for(let n=0;;n++){if(Po(r.bytes(e.length,!0),e)){r.bytes(e.length);break}s(`${n}`,()=>i.push(t.decodeStream(r)))}else{let e;s("arrayLen",()=>e=n.decodeStream(r));for(let n=0;n<e;n++)s(`${n}`,()=>i.push(t.decodeStream(r)))}}),i},validate:e=>{if(!Array.isArray(e))throw new Error(`array: invalid value ${e}`);return e}})}const ha=yt.ProjectivePoint,la=yt.CURVE.n,pa=Co,ga=Bo,ma=Uo,ya=e=>Xt(ee(e)),wa=(...e)=>ee(ee(ga(...e))),va=Ut.getPublicKey,_a=yt.getPublicKey,ba=e=>e.r<la/2n;const Ea=Ut.sign,xa=Ut.utils.taggedHash;var Sa;function ka(e,t){const n=e.length;if(t===Sa.ecdsa){if(32===n)throw new Error("Expected non-Schnorr key");return ha.fromHex(e),e}if(t===Sa.schnorr){if(32!==n)throw new Error("Expected 32-byte Schnorr key");return Ut.utils.lift_x(Ut.utils.bytesToNumberBE(e)),e}throw new Error("Unknown key type")}function Oa(e,t){const n=Ut.utils,r=n.taggedHash("TapTweak",e,t),i=n.bytesToNumberBE(r);if(i>=la)throw new Error("tweak higher than curve order");return i}!function(e){e[e.ecdsa=0]="ecdsa",e[e.schnorr=1]="schnorr"}(Sa||(Sa={})),ee(ha.BASE.toRawBytes(!1));const Aa={bech32:"bc",pubKeyHash:0,scriptHash:5,wif:128};function Pa(e,t){if(!pa(e)||!pa(t))throw new Error(`cmp: wrong type a=${typeof e} b=${typeof t}`);const n=Math.min(e.length,t.length);for(let r=0;r<n;r++)if(e[r]!=t[r])return Math.sign(e[r]-t[r]);return Math.sign(e.length-t.length)}var Ta;function Ia(e=6,t=!1){return Zo({encodeStream:(e,t)=>{if(0n===t)return;const n=t<0,r=BigInt(t),i=[];for(let e=n?-r:r;e;e>>=8n)i.push(Number(0xffn&e));i[i.length-1]>=128?i.push(n?128:0):n&&(i[i.length-1]|=128),e.bytes(new Uint8Array(i))},decodeStream:n=>{const r=n.leftBytes;if(r>e)throw new Error(`ScriptNum: number (${r}) bigger than limit=${e}`);if(0===r)return 0n;if(t){const e=n.bytes(r,!0);if(!(127&e[e.length-1]||!(r<=1)&&128&e[e.length-2]))throw new Error("Non-minimally encoded ScriptNum")}let i=0,s=0n;for(let e=0;e<r;++e)i=n.byte(),s|=BigInt(i)<<8n*BigInt(e);return i>=128&&(s&=2n**BigInt(8*r)-1n>>1n,s=-s),s}})}!function(e){e[e.OP_0=0]="OP_0",e[e.PUSHDATA1=76]="PUSHDATA1",e[e.PUSHDATA2=77]="PUSHDATA2",e[e.PUSHDATA4=78]="PUSHDATA4",e[e["1NEGATE"]=79]="1NEGATE",e[e.RESERVED=80]="RESERVED",e[e.OP_1=81]="OP_1",e[e.OP_2=82]="OP_2",e[e.OP_3=83]="OP_3",e[e.OP_4=84]="OP_4",e[e.OP_5=85]="OP_5",e[e.OP_6=86]="OP_6",e[e.OP_7=87]="OP_7",e[e.OP_8=88]="OP_8",e[e.OP_9=89]="OP_9",e[e.OP_10=90]="OP_10",e[e.OP_11=91]="OP_11",e[e.OP_12=92]="OP_12",e[e.OP_13=93]="OP_13",e[e.OP_14=94]="OP_14",e[e.OP_15=95]="OP_15",e[e.OP_16=96]="OP_16",e[e.NOP=97]="NOP",e[e.VER=98]="VER",e[e.IF=99]="IF",e[e.NOTIF=100]="NOTIF",e[e.VERIF=101]="VERIF",e[e.VERNOTIF=102]="VERNOTIF",e[e.ELSE=103]="ELSE",e[e.ENDIF=104]="ENDIF",e[e.VERIFY=105]="VERIFY",e[e.RETURN=106]="RETURN",e[e.TOALTSTACK=107]="TOALTSTACK",e[e.FROMALTSTACK=108]="FROMALTSTACK",e[e["2DROP"]=109]="2DROP",e[e["2DUP"]=110]="2DUP",e[e["3DUP"]=111]="3DUP",e[e["2OVER"]=112]="2OVER",e[e["2ROT"]=113]="2ROT",e[e["2SWAP"]=114]="2SWAP",e[e.IFDUP=115]="IFDUP",e[e.DEPTH=116]="DEPTH",e[e.DROP=117]="DROP",e[e.DUP=118]="DUP",e[e.NIP=119]="NIP",e[e.OVER=120]="OVER",e[e.PICK=121]="PICK",e[e.ROLL=122]="ROLL",e[e.ROT=123]="ROT",e[e.SWAP=124]="SWAP",e[e.TUCK=125]="TUCK",e[e.CAT=126]="CAT",e[e.SUBSTR=127]="SUBSTR",e[e.LEFT=128]="LEFT",e[e.RIGHT=129]="RIGHT",e[e.SIZE=130]="SIZE",e[e.INVERT=131]="INVERT",e[e.AND=132]="AND",e[e.OR=133]="OR",e[e.XOR=134]="XOR",e[e.EQUAL=135]="EQUAL",e[e.EQUALVERIFY=136]="EQUALVERIFY",e[e.RESERVED1=137]="RESERVED1",e[e.RESERVED2=138]="RESERVED2",e[e["1ADD"]=139]="1ADD",e[e["1SUB"]=140]="1SUB",e[e["2MUL"]=141]="2MUL",e[e["2DIV"]=142]="2DIV",e[e.NEGATE=143]="NEGATE",e[e.ABS=144]="ABS",e[e.NOT=145]="NOT",e[e["0NOTEQUAL"]=146]="0NOTEQUAL",e[e.ADD=147]="ADD",e[e.SUB=148]="SUB",e[e.MUL=149]="MUL",e[e.DIV=150]="DIV",e[e.MOD=151]="MOD",e[e.LSHIFT=152]="LSHIFT",e[e.RSHIFT=153]="RSHIFT",e[e.BOOLAND=154]="BOOLAND",e[e.BOOLOR=155]="BOOLOR",e[e.NUMEQUAL=156]="NUMEQUAL",e[e.NUMEQUALVERIFY=157]="NUMEQUALVERIFY",e[e.NUMNOTEQUAL=158]="NUMNOTEQUAL",e[e.LESSTHAN=159]="LESSTHAN",e[e.GREATERTHAN=160]="GREATERTHAN",e[e.LESSTHANOREQUAL=161]="LESSTHANOREQUAL",e[e.GREATERTHANOREQUAL=162]="GREATERTHANOREQUAL",e[e.MIN=163]="MIN",e[e.MAX=164]="MAX",e[e.WITHIN=165]="WITHIN",e[e.RIPEMD160=166]="RIPEMD160",e[e.SHA1=167]="SHA1",e[e.SHA256=168]="SHA256",e[e.HASH160=169]="HASH160",e[e.HASH256=170]="HASH256",e[e.CODESEPARATOR=171]="CODESEPARATOR",e[e.CHECKSIG=172]="CHECKSIG",e[e.CHECKSIGVERIFY=173]="CHECKSIGVERIFY",e[e.CHECKMULTISIG=174]="CHECKMULTISIG",e[e.CHECKMULTISIGVERIFY=175]="CHECKMULTISIGVERIFY",e[e.NOP1=176]="NOP1",e[e.CHECKLOCKTIMEVERIFY=177]="CHECKLOCKTIMEVERIFY",e[e.CHECKSEQUENCEVERIFY=178]="CHECKSEQUENCEVERIFY",e[e.NOP4=179]="NOP4",e[e.NOP5=180]="NOP5",e[e.NOP6=181]="NOP6",e[e.NOP7=182]="NOP7",e[e.NOP8=183]="NOP8",e[e.NOP9=184]="NOP9",e[e.NOP10=185]="NOP10",e[e.CHECKSIGADD=186]="CHECKSIGADD",e[e.INVALID=255]="INVALID"}(Ta||(Ta={}));const Na=Zo({encodeStream:(e,t)=>{for(let n of t){if("string"==typeof n){if(void 0===Ta[n])throw new Error(`Unknown opcode=${n}`);e.byte(Ta[n]);continue}if("number"==typeof n){if(0===n){e.byte(0);continue}if(1<=n&&n<=16){e.byte(Ta.OP_1-1+n);continue}}if("number"==typeof n&&(n=Ia().encode(BigInt(n))),!pa(n))throw new Error(`Wrong Script OP=${n} (${typeof n})`);const t=n.length;t<Ta.PUSHDATA1?e.byte(t):t<=255?(e.byte(Ta.PUSHDATA1),e.byte(t)):t<=65535?(e.byte(Ta.PUSHDATA2),e.bytes(ra.encode(t))):(e.byte(Ta.PUSHDATA4),e.bytes(ea.encode(t))),e.bytes(n)}},decodeStream:e=>{const t=[];for(;!e.isEnd();){const n=e.byte();if(Ta.OP_0<n&&n<=Ta.PUSHDATA4){let r;if(n<Ta.PUSHDATA1)r=n;else if(n===Ta.PUSHDATA1)r=ia.decodeStream(e);else if(n===Ta.PUSHDATA2)r=ra.decodeStream(e);else{if(n!==Ta.PUSHDATA4)throw new Error("Should be not possible");r=ea.decodeStream(e)}t.push(e.bytes(r))}else if(0===n)t.push(0);else if(Ta.OP_1<=n&&n<=Ta.OP_16)t.push(n-(Ta.OP_1-1));else{const e=Ta[n];if(void 0===e)throw new Error(`Unknown opcode=${n.toString(16)}`);t.push(e)}}return t}}),$a={253:[253,2,253n,65535n],254:[254,4,65536n,4294967295n],255:[255,8,4294967296n,18446744073709551615n]},Ua=Zo({encodeStream:(e,t)=>{if("number"==typeof t&&(t=BigInt(t)),0n<=t&&t<=252n)return e.byte(Number(t));for(const[n,r,i,s]of Object.values($a))if(!(i>t||t>s)){e.byte(n);for(let n=0;n<r;n++)e.byte(Number(t>>8n*BigInt(n)&0xffn));return}throw e.err(`VarInt too big: ${t}`)},decodeStream:e=>{const t=e.byte();if(t<=252)return BigInt(t);const[n,r,i]=$a[t];let s=0n;for(let t=0;t<r;t++)s|=BigInt(e.byte())<<8n*BigInt(t);if(s<i)throw e.err(`Wrong CompactSize(${8*r})`);return s}}),Ca=aa(Ua,qo.numberBigint),Ba=sa(Ua),Ra=fa(Ca,Ba),La=e=>fa(Ua,e),za=da({txid:sa(32,!0),index:ea,finalScriptSig:Ba,sequence:ea}),ja=da({amount:Qo,script:Ba});const Ha=Vo(da({version:na,segwitFlag:((e,t=!1)=>{if(!To(e))throw new Error("flag/flagValue: expected Uint8Array, got "+typeof e);if("boolean"!=typeof t)throw new Error("flag/xor: expected boolean, got "+typeof t);return Zo({size:e.length,encodeStream:(n,r)=>{!!r!==t&&n.bytes(e)},decodeStream:n=>{let r=n.leftBytes>=e.length;return r&&(r=Po(n.bytes(e.length,!0),e),r&&n.bytes(e.length)),r!==t},validate:e=>{if(void 0!==e&&"boolean"!=typeof e)throw new Error("flag: expected boolean value or undefined, got "+typeof e);return e}})})(new Uint8Array([0,1])),inputs:La(za),outputs:La(ja),witnesses:function(e,t){if(!Wo(t))throw new Error(`flagged: invalid inner value ${t}`);return Zo({encodeStream:(n,r)=>{zo.resolve(n.stack,e)&&t.encodeStream(n,r)},decodeStream:n=>{let r=!1;if(r=!!zo.resolve(n.stack,e),r)return t.decodeStream(n)}})}("segwitFlag",fa("inputs/length",Ra)),lockTime:ea}),function(e){if(e.segwitFlag&&e.witnesses&&!e.witnesses.length)throw new Error("Segwit flag with empty witnesses array");return e}),Da=da({version:na,inputs:La(za),outputs:La(ja),lockTime:ea}),Fa=Vo(sa(null),e=>ka(e,Sa.ecdsa)),Va=Vo(sa(32),e=>ka(e,Sa.schnorr)),Za=Vo(sa(null),e=>{if(64!==e.length&&65!==e.length)throw new Error("Schnorr signature should be 64 or 65 bytes long");return e}),Ka=da({fingerprint:ta,path:fa(null,ea)}),Wa=da({hashes:fa(Ca,sa(32)),der:Ka}),Ma=sa(78),qa=da({pubKey:Va,leafHash:sa(32)}),Ga=Vo(da({version:ia,internalKey:sa(32),merklePath:fa(null,sa(32))}),e=>{if(e.merklePath.length>128)throw new Error("TaprootControlBlock: merklePath should be of length 0..128 (inclusive)");return e}),Ya=fa(null,da({depth:ia,version:ia,script:Ba})),Qa=sa(null),Xa=sa(20),Ja=sa(32),eu={unsignedTx:[0,!1,Da,[0],[0],!1],xpub:[1,Ma,Ka,[],[0,2],!1],txVersion:[2,!1,ea,[2],[2],!1],fallbackLocktime:[3,!1,ea,[],[2],!1],inputCount:[4,!1,Ca,[2],[2],!1],outputCount:[5,!1,Ca,[2],[2],!1],txModifiable:[6,!1,ia,[],[2],!1],version:[251,!1,ea,[],[0,2],!1],proprietary:[252,Qa,Qa,[],[0,2],!1]},tu={nonWitnessUtxo:[0,!1,Ha,[],[0,2],!1],witnessUtxo:[1,!1,ja,[],[0,2],!1],partialSig:[2,Fa,Qa,[],[0,2],!1],sighashType:[3,!1,ea,[],[0,2],!1],redeemScript:[4,!1,Qa,[],[0,2],!1],witnessScript:[5,!1,Qa,[],[0,2],!1],bip32Derivation:[6,Fa,Ka,[],[0,2],!1],finalScriptSig:[7,!1,Qa,[],[0,2],!1],finalScriptWitness:[8,!1,Ra,[],[0,2],!1],porCommitment:[9,!1,Qa,[],[0,2],!1],ripemd160:[10,Xa,Qa,[],[0,2],!1],sha256:[11,Ja,Qa,[],[0,2],!1],hash160:[12,Xa,Qa,[],[0,2],!1],hash256:[13,Ja,Qa,[],[0,2],!1],txid:[14,!1,Ja,[2],[2],!0],index:[15,!1,ea,[2],[2],!0],sequence:[16,!1,ea,[],[2],!0],requiredTimeLocktime:[17,!1,ea,[],[2],!1],requiredHeightLocktime:[18,!1,ea,[],[2],!1],tapKeySig:[19,!1,Za,[],[0,2],!1],tapScriptSig:[20,qa,Za,[],[0,2],!1],tapLeafScript:[21,Ga,Qa,[],[0,2],!1],tapBip32Derivation:[22,Ja,Wa,[],[0,2],!1],tapInternalKey:[23,!1,Va,[],[0,2],!1],tapMerkleRoot:[24,!1,Ja,[],[0,2],!1],proprietary:[252,Qa,Qa,[],[0,2],!1]},nu=["txid","sequence","index","witnessUtxo","nonWitnessUtxo","finalScriptSig","finalScriptWitness","unknown"],ru=["partialSig","finalScriptSig","finalScriptWitness","tapKeySig","tapScriptSig"],iu={redeemScript:[0,!1,Qa,[],[0,2],!1],witnessScript:[1,!1,Qa,[],[0,2],!1],bip32Derivation:[2,Fa,Ka,[],[0,2],!1],amount:[3,!1,Xo,[2],[2],!0],script:[4,!1,Qa,[2],[2],!0],tapInternalKey:[5,!1,Va,[],[0,2],!1],tapTree:[6,!1,Ya,[],[0,2],!1],tapBip32Derivation:[7,Va,Wa,[],[0,2],!1],proprietary:[252,Qa,Qa,[],[0,2],!1]},su=[],ou=fa(Ao,da({key:function(e,t){if(!Wo(t))throw new Error(`prefix: invalid inner value ${t}`);return aa(sa(e),Mo(t))}(Ca,da({type:Ca,key:sa(null)})),value:sa(Ca)}));function au(e){const[t,n,r,i,s,o]=e;return{type:t,kc:n,vc:r,reqInc:i,allowInc:s,silentIgnore:o}}function uu(e){const t={};for(const n in e){const[r,i,s]=e[n];t[r]=[n,i,s]}return Zo({encodeStream:(t,n)=>{let r=[];for(const t in e){const i=n[t];if(void 0===i)continue;const[s,o,a]=e[t];if(o){const e=i.map(([e,t])=>[o.encode(e),a.encode(t)]);e.sort((e,t)=>Pa(e[0],t[0]));for(const[t,n]of e)r.push({key:{key:t,type:s},value:n})}else r.push({key:{type:s,key:Oo},value:a.encode(i)})}if(n.unknown){n.unknown.sort((e,t)=>Pa(e[0].key,t[0].key));for(const[e,t]of n.unknown)r.push({key:e,value:t})}ou.encodeStream(t,r)},decodeStream:e=>{const n=ou.decodeStream(e),r={},i={};for(const e of n){let n="unknown",s=e.key.key,o=e.value;if(t[e.key.type]){const[a,u,c]=t[e.key.type];if(n=a,!u&&s.length)throw new Error(`PSBT: Non-empty key for ${n} (key=${zi.encode(s)} value=${zi.encode(o)}`);if(s=u?u.decode(s):void 0,o=c.decode(o),!u){if(r[n])throw new Error(`PSBT: Same keys: ${n} (key=${s} value=${o})`);r[n]=o,i[n]=!0;continue}}else s={type:e.key.type,key:e.key.key};if(i[n])throw new Error(`PSBT: Key type with empty key and no key=${n} val=${o}`);r[n]||(r[n]=[]),r[n].push([s,o])}return r}})}da({type:Ca,key:sa(null)});const cu=Vo(uu(tu),e=>{if(e.finalScriptWitness&&!e.finalScriptWitness.length)throw new Error("validateInput: empty finalScriptWitness");if(e.partialSig&&!e.partialSig.length)throw new Error("Empty partialSig");if(e.partialSig)for(const[t]of e.partialSig)ka(t,Sa.ecdsa);if(e.bip32Derivation)for(const[t]of e.bip32Derivation)ka(t,Sa.ecdsa);if(void 0!==e.requiredTimeLocktime&&e.requiredTimeLocktime<5e8)throw new Error(`validateInput: wrong timeLocktime=${e.requiredTimeLocktime}`);if(void 0!==e.requiredHeightLocktime&&(e.requiredHeightLocktime<=0||e.requiredHeightLocktime>=5e8))throw new Error(`validateInput: wrong heighLocktime=${e.requiredHeightLocktime}`);if(e.tapLeafScript)for(const[t,n]of e.tapLeafScript){if((254&t.version)!==n[n.length-1])throw new Error("validateInput: tapLeafScript version mimatch");if(1&n[n.length-1])throw new Error("validateInput: tapLeafScript version has parity bit!")}return e}),du=Vo(uu(iu),e=>{if(e.bip32Derivation)for(const[t]of e.bip32Derivation)ka(t,Sa.ecdsa);return e}),fu=Vo(uu(eu),e=>{if(0===(e.version||0)){if(!e.unsignedTx)throw new Error("PSBTv0: missing unsignedTx");for(const t of e.unsignedTx.inputs)if(t.finalScriptSig&&t.finalScriptSig.length)throw new Error("PSBTv0: input scriptSig found in unsignedTx")}return e}),hu=da({magic:ua(oa(new Uint8Array([255])),"psbt"),global:fu,inputs:fa("global/unsignedTx/inputs/length",cu),outputs:fa(null,du)}),lu=da({magic:ua(oa(new Uint8Array([255])),"psbt"),global:fu,inputs:fa("global/inputCount",cu),outputs:fa("global/outputCount",du)});function pu(e,t,n){for(const r in n){if("unknown"===r)continue;if(!t[r])continue;const{allowInc:n}=au(t[r]);if(!n.includes(e))throw new Error(`PSBTv${e}: field ${r} is not allowed`)}for(const r in t){const{reqInc:i}=au(t[r]);if(i.includes(e)&&void 0===n[r])throw new Error(`PSBTv${e}: missing required field ${r}`)}}function gu(e,t,n){const r={};for(const i in n){const s=i;if("unknown"!==s){if(!t[s])continue;const{allowInc:n,silentIgnore:r}=au(t[s]);if(!n.includes(e)){if(r)continue;throw new Error(`Failed to serialize in PSBTv${e}: ${s} but versions allows inclusion=${n}`)}}r[s]=n[s]}return r}function mu(e){const t=e&&e.global&&e.global.version||0;pu(t,eu,e.global);for(const n of e.inputs)pu(t,tu,n);for(const n of e.outputs)pu(t,iu,n);const n=t?e.global.inputCount:e.global.unsignedTx.inputs.length;if(e.inputs.length<n)throw new Error("Not enough inputs");const r=e.inputs.slice(n);if(r.length>1||r.length&&Object.keys(r[0]).length)throw new Error(`Unexpected inputs left in tx=${r}`);const i=t?e.global.outputCount:e.global.unsignedTx.outputs.length;if(e.outputs.length<i)throw new Error("Not outputs inputs");const s=e.outputs.slice(i);if(s.length>1||s.length&&Object.keys(s[0]).length)throw new Error(`Unexpected outputs left in tx=${s}`);return e}function yu(e,t,n,r,i){const s={...n,...t};for(const i in e){const o=i,[a,u,c]=e[o],d=r&&!r.includes(i);if(void 0===t[i]&&i in t){if(d)throw new Error(`Cannot remove signed field=${i}`);delete s[i]}else if(u){const e=n&&n[i]?n[i]:[];let r=t[o];if(r){if(!Array.isArray(r))throw new Error(`keyMap(${i}): KV pairs should be [k, v][]`);r=r.map(e=>{if(2!==e.length)throw new Error(`keyMap(${i}): KV pairs should be [k, v][]`);return["string"==typeof e[0]?u.decode(zi.decode(e[0])):e[0],"string"==typeof e[1]?c.decode(zi.decode(e[1])):e[1]]});const t={},n=(e,n,r)=>{if(void 0===t[e])return void(t[e]=[n,r]);const i=zi.encode(c.encode(t[e][1])),s=zi.encode(c.encode(r));if(i!==s)throw new Error(`keyMap(${o}): same key=${e} oldVal=${i} newVal=${s}`)};for(const[t,r]of e){n(zi.encode(u.encode(t)),t,r)}for(const[e,i]of r){const r=zi.encode(u.encode(e));if(void 0===i){if(d)throw new Error(`Cannot remove signed field=${o}/${e}`);delete t[r]}else n(r,e,i)}s[o]=Object.values(t)}}else if("string"==typeof s[i])s[i]=c.decode(zi.decode(s[i]));else if(d&&i in t&&n&&void 0!==n[i]&&!ma(c.encode(t[i]),c.encode(n[i])))throw new Error(`Cannot change signed field=${i}`)}for(const t in s)if(!e[t]){if(i&&"unknown"===t)continue;delete s[t]}return s}da({magic:ua(oa(new Uint8Array([255])),"psbt"),items:fa(null,aa(fa(Ao,function(e){if(!Array.isArray(e))throw new Error(`Packed.Tuple: got ${typeof e} instead of array`);for(let t=0;t<e.length;t++)if(!Wo(e[t]))throw new Error(`tuple: field ${t} is not CoderType`);return Zo({size:ca(e),encodeStream:(t,n)=>{if(!Array.isArray(n))throw t.err(`tuple: invalid value ${n}`);t.pushObj(n,r=>{for(let i=0;i<e.length;i++)r(`${i}`,()=>e[i].encodeStream(t,n[i]))})},decodeStream:t=>{const n=[];return t.pushObj(n,r=>{for(let i=0;i<e.length;i++)r(`${i}`,()=>n.push(e[i].decodeStream(t)))}),n},validate:t=>{if(!Array.isArray(t))throw new Error(`tuple: invalid value ${t}`);if(t.length!==e.length)throw new Error(`tuple: wrong length=${t.length}, expected ${e.length}`);return t}})}([((e,t={isLE:!1,with0x:!1})=>{let n=aa(sa(e,t.isLE),zi);const r=t.with0x;if("boolean"!=typeof r)throw new Error("hex/with0x: expected boolean, got "+typeof r);return r&&(n=aa(n,{encode:e=>`0x${e}`,decode:e=>{if(!e.startsWith("0x"))throw new Error("hex(with0x=true).encode input should start with 0x");return e.slice(2)}})),n})(Ca),sa(Ua)])),qo.dict()))});const wu=Vo(hu,mu),vu=Vo(lu,mu);function _u(e,t){try{return ka(e,t),!0}catch(e){return!1}}const bu=[{encode(e){if(2===e.length&&1===e[0]&&pa(e[1])&&"4e73"===zi.encode(e[1]))return{type:"p2a",script:Na.encode(e)}},decode:e=>{if("p2a"===e.type)return[1,zi.decode("4e73")]}},{encode(e){if(2===e.length&&pa(e[0])&&_u(e[0],Sa.ecdsa)&&"CHECKSIG"===e[1])return{type:"pk",pubkey:e[0]}},decode:e=>"pk"===e.type?[e.pubkey,"CHECKSIG"]:void 0},{encode(e){if(5===e.length&&"DUP"===e[0]&&"HASH160"===e[1]&&pa(e[2])&&"EQUALVERIFY"===e[3]&&"CHECKSIG"===e[4])return{type:"pkh",hash:e[2]}},decode:e=>"pkh"===e.type?["DUP","HASH160",e.hash,"EQUALVERIFY","CHECKSIG"]:void 0},{encode(e){if(3===e.length&&"HASH160"===e[0]&&pa(e[1])&&"EQUAL"===e[2])return{type:"sh",hash:e[1]}},decode:e=>"sh"===e.type?["HASH160",e.hash,"EQUAL"]:void 0},{encode(e){if(2===e.length&&0===e[0]&&pa(e[1])&&32===e[1].length)return{type:"wsh",hash:e[1]}},decode:e=>"wsh"===e.type?[0,e.hash]:void 0},{encode(e){if(2===e.length&&0===e[0]&&pa(e[1])&&20===e[1].length)return{type:"wpkh",hash:e[1]}},decode:e=>"wpkh"===e.type?[0,e.hash]:void 0},{encode(e){const t=e.length-1;if("CHECKMULTISIG"!==e[t])return;const n=e[0],r=e[t-1];if("number"!=typeof n||"number"!=typeof r)return;const i=e.slice(1,-2);if(r===i.length){for(const e of i)if(!pa(e))return;return{type:"ms",m:n,pubkeys:i}}},decode:e=>"ms"===e.type?[e.m,...e.pubkeys,e.pubkeys.length,"CHECKMULTISIG"]:void 0},{encode(e){if(2===e.length&&1===e[0]&&pa(e[1]))return{type:"tr",pubkey:e[1]}},decode:e=>"tr"===e.type?[1,e.pubkey]:void 0},{encode(e){const t=e.length-1;if("CHECKSIG"!==e[t])return;const n=[];for(let r=0;r<t;r++){const i=e[r];if(1&r){if("CHECKSIGVERIFY"!==i||r===t-1)return}else{if(!pa(i))return;n.push(i)}}return{type:"tr_ns",pubkeys:n}},decode:e=>{if("tr_ns"!==e.type)return;const t=[];for(let n=0;n<e.pubkeys.length-1;n++)t.push(e.pubkeys[n],"CHECKSIGVERIFY");return t.push(e.pubkeys[e.pubkeys.length-1],"CHECKSIG"),t}},{encode(e){const t=e.length-1;if("NUMEQUAL"!==e[t]||"CHECKSIG"!==e[1])return;const n=[],r=function(e,t=4,n=!0){if("number"==typeof e)return e;if(pa(e))try{const r=Ia(t,n).decode(e);if(r>Number.MAX_SAFE_INTEGER)return;return Number(r)}catch(e){return}}(e[t-1]);if("number"==typeof r){for(let r=0;r<t-1;r++){const t=e[r];if(1&r){if(t!==(1===r?"CHECKSIG":"CHECKSIGADD"))throw new Error("OutScript.encode/tr_ms: wrong element")}else{if(!pa(t))throw new Error("OutScript.encode/tr_ms: wrong key element");n.push(t)}}return{type:"tr_ms",pubkeys:n,m:r}}},decode:e=>{if("tr_ms"!==e.type)return;const t=[e.pubkeys[0],"CHECKSIG"];for(let n=1;n<e.pubkeys.length;n++)t.push(e.pubkeys[n],"CHECKSIGADD");return t.push(e.m,"NUMEQUAL"),t}},{encode:e=>({type:"unknown",script:Na.encode(e)}),decode:e=>"unknown"===e.type?Na.decode(e.script):void 0}],Eu=Vo(aa(Na,qo.match(bu)),e=>{if("pk"===e.type&&!_u(e.pubkey,Sa.ecdsa))throw new Error("OutScript/pk: wrong key");if(!("pkh"!==e.type&&"sh"!==e.type&&"wpkh"!==e.type||pa(e.hash)&&20===e.hash.length))throw new Error(`OutScript/${e.type}: wrong hash`);if("wsh"===e.type&&(!pa(e.hash)||32!==e.hash.length))throw new Error("OutScript/wsh: wrong hash");if(!("tr"!==e.type||pa(e.pubkey)&&_u(e.pubkey,Sa.schnorr)))throw new Error("OutScript/tr: wrong taproot public key");if(("ms"===e.type||"tr_ns"===e.type||"tr_ms"===e.type)&&!Array.isArray(e.pubkeys))throw new Error("OutScript/multisig: wrong pubkeys array");if("ms"===e.type){const t=e.pubkeys.length;for(const t of e.pubkeys)if(!_u(t,Sa.ecdsa))throw new Error("OutScript/multisig: wrong pubkey");if(e.m<=0||t>16||e.m>t)throw new Error("OutScript/multisig: invalid params")}if("tr_ns"===e.type||"tr_ms"===e.type)for(const t of e.pubkeys)if(!_u(t,Sa.schnorr))throw new Error(`OutScript/${e.type}: wrong pubkey`);if("tr_ms"===e.type){const t=e.pubkeys.length;if(e.m<=0||t>999||e.m>t)throw new Error("OutScript/tr_ms: invalid params")}return e});function xu(e,t){if(!ma(e.hash,ee(t)))throw new Error("checkScript: wsh wrong witnessScript hash");const n=Eu.decode(t);if("tr"===n.type||"tr_ns"===n.type||"tr_ms"===n.type)throw new Error(`checkScript: P2${n.type} cannot be wrapped in P2SH`);if("wpkh"===n.type||"sh"===n.type)throw new Error(`checkScript: P2${n.type} cannot be wrapped in P2WSH`)}function Su(e,t,n){if(e){const r=Eu.decode(e);if("tr_ns"===r.type||"tr_ms"===r.type||"ms"===r.type||"pk"==r.type)throw new Error(`checkScript: non-wrapped ${r.type}`);if("sh"===r.type&&t){if(!ma(r.hash,ya(t)))throw new Error("checkScript: sh wrong redeemScript hash");const e=Eu.decode(t);if("tr"===e.type||"tr_ns"===e.type||"tr_ms"===e.type)throw new Error(`checkScript: P2${e.type} cannot be wrapped in P2SH`);if("sh"===e.type)throw new Error("checkScript: P2SH cannot be wrapped in P2SH")}"wsh"===r.type&&n&&xu(r,n)}if(t){const e=Eu.decode(t);"wsh"===e.type&&n&&xu(e,n)}}const ku=(e,t=192)=>xa("TapLeaf",new Uint8Array([t]),Ba.encode(e)),Ou=Ti(ee);function Au(e,t){if(t.length<2||t.length>40)throw new Error("Witness: invalid length");if(e>16)throw new Error("Witness: invalid version");if(0===e&&20!==t.length&&32!==t.length)throw new Error("Witness: invalid length for version")}function Pu(e,t,n=Aa){Au(e,t);const r=0===e?Bi:Ri;return r.encode(n.bech32,[e].concat(r.toWords(t)))}function Tu(e,t){return Ou.encode(ga(Uint8Array.from(t),e))}function Iu(e=Aa){return{encode(t){const{type:n}=t;if("wpkh"===n)return Pu(0,t.hash,e);if("wsh"===n)return Pu(0,t.hash,e);if("tr"===n)return Pu(1,t.pubkey,e);if("pkh"===n)return Tu(t.hash,[e.pubKeyHash]);if("sh"===n)return Tu(t.hash,[e.scriptHash]);throw new Error(`Unknown address type=${n}`)},decode(t){if(t.length<14||t.length>74)throw new Error("Invalid address length");if(e.bech32&&t.toLowerCase().startsWith(`${e.bech32}1`)){let n;try{if(n=Bi.decode(t),0!==n.words[0])throw new Error(`bech32: wrong version=${n.words[0]}`)}catch(e){if(n=Ri.decode(t),0===n.words[0])throw new Error(`bech32m: wrong version=${n.words[0]}`)}if(n.prefix!==e.bech32)throw new Error(`wrong bech32 prefix=${n.prefix}`);const[r,...i]=n.words,s=Bi.fromWords(i);if(Au(r,s),0===r&&32===s.length)return{type:"wsh",hash:s};if(0===r&&20===s.length)return{type:"wpkh",hash:s};if(1===r&&32===s.length)return{type:"tr",pubkey:s};throw new Error("Unknown witness program")}const n=Ou.decode(t);if(21!==n.length)throw new Error("Invalid base58 address");if(n[0]===e.pubKeyHash)return{type:"pkh",hash:n.slice(1)};if(n[0]===e.scriptHash)return{type:"sh",hash:n.slice(1)};throw new Error(`Invalid address prefix=${n[0]}`)}}}const Nu=new Uint8Array(32),$u={amount:0xffffffffffffffffn,script:Oo},Uu=4294967295;qo.decimal(8);const Cu=(e,t)=>void 0===e?t:e;function Bu(e){if(Array.isArray(e))return e.map(e=>Bu(e));if(pa(e))return Uint8Array.from(e);if(["number","bigint","boolean","string","undefined"].includes(typeof e))return e;if(null===e)return e;if("object"==typeof e)return Object.fromEntries(Object.entries(e).map(([e,t])=>[e,Bu(t)]));throw new Error(`cloneDeep: unknown type=${e} (${typeof e})`)}var Ru,Lu;function zu(e,t,n,r=Oo){return ma(n,t)&&(e=function(e,t=Uint8Array.of()){const n=Ut.utils,r=n.bytesToNumberBE(e),i=ha.fromPrivateKey(r),s=i.hasEvenY()?r:n.mod(-r,la),o=Oa(n.pointToBytes(i),t);return n.numberToBytesBE(n.mod(s+o,la),32)}(e,r),t=va(e)),{privKey:e,pubKey:t}}function ju(e){if(void 0===e.script||void 0===e.amount)throw new Error("Transaction/output: script and amount required");return{script:e.script,amount:e.amount}}function Hu(e){if(void 0===e.txid||void 0===e.index)throw new Error("Transaction/input: txid and index required");return{txid:e.txid,index:e.index,sequence:Cu(e.sequence,Uu),finalScriptSig:Cu(e.finalScriptSig,Oo)}}function Du(e){for(const t in e){const n=t;nu.includes(n)||delete e[n]}}!function(e){e[e.DEFAULT=0]="DEFAULT",e[e.ALL=1]="ALL",e[e.NONE=2]="NONE",e[e.SINGLE=3]="SINGLE",e[e.ANYONECANPAY=128]="ANYONECANPAY"}(Ru||(Ru={})),function(e){e[e.DEFAULT=0]="DEFAULT",e[e.ALL=1]="ALL",e[e.NONE=2]="NONE",e[e.SINGLE=3]="SINGLE",e[e.DEFAULT_ANYONECANPAY=128]="DEFAULT_ANYONECANPAY",e[e.ALL_ANYONECANPAY=129]="ALL_ANYONECANPAY",e[e.NONE_ANYONECANPAY=130]="NONE_ANYONECANPAY",e[e.SINGLE_ANYONECANPAY=131]="SINGLE_ANYONECANPAY"}(Lu||(Lu={}));const Fu=da({txid:sa(32,!0),index:ea});function Vu(e){if("number"!=typeof e||"string"!=typeof Lu[e])throw new Error(`Invalid SigHash=${e}`);return e}function Zu(e){const t=31&e;return{isAny:!!(e&Ru.ANYONECANPAY),isNone:t===Ru.NONE,isSingle:t===Ru.SINGLE}}function Ku(e){if(e.nonWitnessUtxo&&void 0!==e.index){const t=e.nonWitnessUtxo.outputs.length-1;if(e.index>t)throw new Error(`validateInput: index(${e.index}) not in nonWitnessUtxo`);const n=e.nonWitnessUtxo.outputs[e.index];if(e.witnessUtxo&&(!ma(e.witnessUtxo.script,n.script)||e.witnessUtxo.amount!==n.amount))throw new Error("validateInput: witnessUtxo different from nonWitnessUtxo");if(e.txid){if(e.nonWitnessUtxo.outputs.length-1<e.index)throw new Error("nonWitnessUtxo: incorect output index");const t=Gu.fromRaw(Ha.encode(e.nonWitnessUtxo),{allowUnknownOutputs:!0,disableScriptCheck:!0,allowUnknownInputs:!0}),n=zi.encode(e.txid);if(t.isFinal&&t.id!==n)throw new Error(`nonWitnessUtxo: wrong txid, exp=${n} got=${t.id}`)}}return e}function Wu(e){if(e.nonWitnessUtxo){if(void 0===e.index)throw new Error("Unknown input index");return e.nonWitnessUtxo.outputs[e.index]}if(e.witnessUtxo)return e.witnessUtxo;throw new Error("Cannot find previous output info")}function Mu(e,t,n,r=!1,i=!1){let{nonWitnessUtxo:s,txid:o}=e;"string"==typeof s&&(s=zi.decode(s)),pa(s)&&(s=Ha.decode(s)),"nonWitnessUtxo"in e||void 0!==s||(s=t?.nonWitnessUtxo),"string"==typeof o&&(o=zi.decode(o)),void 0===o&&(o=t?.txid);let a,u={...t,...e,nonWitnessUtxo:s,txid:o};return"nonWitnessUtxo"in e||void 0!==u.nonWitnessUtxo||delete u.nonWitnessUtxo,void 0===u.sequence&&(u.sequence=Uu),null===u.tapMerkleRoot&&delete u.tapMerkleRoot,u=yu(tu,u,t,n,i),cu.encode(u),u.nonWitnessUtxo&&void 0!==u.index?a=u.nonWitnessUtxo.outputs[u.index]:u.witnessUtxo&&(a=u.witnessUtxo),a&&!r&&Su(a&&a.script,u.redeemScript,u.witnessScript),u}function qu(e,t=!1){let n="legacy",r=Ru.ALL;const i=Wu(e),s=Eu.decode(i.script);let o=s.type,a=s;const u=[s];if("tr"===s.type)return r=Ru.DEFAULT,{txType:"taproot",type:"tr",last:s,lastScript:i.script,defaultSighash:r,sighash:e.sighashType||r};{if("wpkh"!==s.type&&"wsh"!==s.type||(n="segwit"),"sh"===s.type){if(!e.redeemScript)throw new Error("inputType: sh without redeemScript");let t=Eu.decode(e.redeemScript);"wpkh"!==t.type&&"wsh"!==t.type||(n="segwit"),u.push(t),a=t,o+=`-${t.type}`}if("wsh"===a.type){if(!e.witnessScript)throw new Error("inputType: wsh without witnessScript");let t=Eu.decode(e.witnessScript);"wsh"===t.type&&(n="segwit"),u.push(t),a=t,o+=`-${t.type}`}const i=u[u.length-1];if("sh"===i.type||"wsh"===i.type)throw new Error("inputType: sh/wsh cannot be terminal type");const c={type:o,txType:n,last:i,lastScript:Eu.encode(i),defaultSighash:r,sighash:e.sighashType||r};if("legacy"===n&&!t&&!e.nonWitnessUtxo)throw new Error("Transaction/sign: legacy input without nonWitnessUtxo, can result in attack that forces paying higher fees. Pass allowLegacyWitnessUtxo=true, if you sure");return c}}class Gu{constructor(e={}){this.global={},this.inputs=[],this.outputs=[];const t=this.opts=function(e){if(void 0!==e&&"[object Object]"!=={}.toString.call(e))throw new Error(`Wrong object type for transaction options: ${e}`);const t={...e,version:Cu(e.version,2),lockTime:Cu(e.lockTime,0),PSBTVersion:Cu(e.PSBTVersion,0)};if(void 0!==t.allowUnknowInput&&(e.allowUnknownInputs=t.allowUnknowInput),void 0!==t.allowUnknowOutput&&(e.allowUnknownOutputs=t.allowUnknowOutput),"number"!=typeof t.lockTime)throw new Error("Transaction lock time should be number");if(ea.encode(t.lockTime),0!==t.PSBTVersion&&2!==t.PSBTVersion)throw new Error(`Unknown PSBT version ${t.PSBTVersion}`);for(const e of["allowUnknownVersion","allowUnknownOutputs","allowUnknownInputs","disableScriptCheck","bip174jsCompat","allowLegacyWitnessUtxo","lowR"]){const n=t[e];if(void 0!==n&&"boolean"!=typeof n)throw new Error(`Transation options wrong type: ${e}=${n} (${typeof n})`)}if(t.allowUnknownVersion?"number"==typeof t.version:![-1,0,1,2,3].includes(t.version))throw new Error(`Unknown version: ${t.version}`);if(void 0!==t.customScripts){const e=t.customScripts;if(!Array.isArray(e))throw new Error(`wrong custom scripts type (expected array): customScripts=${e} (${typeof e})`);for(const t of e){if("function"!=typeof t.encode||"function"!=typeof t.decode)throw new Error(`wrong script=${t} (${typeof t})`);if(void 0!==t.finalizeTaproot&&"function"!=typeof t.finalizeTaproot)throw new Error(`wrong script=${t} (${typeof t})`)}}return Object.freeze(t)}(e);0!==t.lockTime&&(this.global.fallbackLocktime=t.lockTime),this.global.txVersion=t.version}static fromRaw(e,t={}){const n=Ha.decode(e),r=new Gu({...t,version:n.version,lockTime:n.lockTime});for(const e of n.outputs)r.addOutput(e);if(r.outputs=n.outputs,r.inputs=n.inputs,n.witnesses)for(let e=0;e<n.witnesses.length;e++)r.inputs[e].finalScriptWitness=n.witnesses[e];return r}static fromPSBT(e,t={}){let n;try{n=wu.decode(e)}catch(t){try{n=vu.decode(e)}catch(e){throw t}}const r=n.global.version||0;if(0!==r&&2!==r)throw new Error(`Wrong PSBT version=${r}`);const i=n.global.unsignedTx,s=0===r?i?.version:n.global.txVersion,o=0===r?i?.lockTime:n.global.fallbackLocktime,a=new Gu({...t,version:s,lockTime:o,PSBTVersion:r}),u=0===r?i?.inputs.length:n.global.inputCount;a.inputs=n.inputs.slice(0,u).map((e,t)=>Ku({finalScriptSig:Oo,...n.global.unsignedTx?.inputs[t],...e}));const c=0===r?i?.outputs.length:n.global.outputCount;return a.outputs=n.outputs.slice(0,c).map((e,t)=>({...e,...n.global.unsignedTx?.outputs[t]})),a.global={...n.global,txVersion:s},0!==o&&(a.global.fallbackLocktime=o),a}toPSBT(e=this.opts.PSBTVersion){if(0!==e&&2!==e)throw new Error(`Wrong PSBT version=${e}`);const t=this.inputs.map(t=>Ku(gu(e,tu,t)));for(const e of t)e.partialSig&&!e.partialSig.length&&delete e.partialSig,e.finalScriptSig&&!e.finalScriptSig.length&&delete e.finalScriptSig,e.finalScriptWitness&&!e.finalScriptWitness.length&&delete e.finalScriptWitness;const n=this.outputs.map(t=>gu(e,iu,t)),r={...this.global};return 0===e?(r.unsignedTx=Da.decode(Da.encode({version:this.version,lockTime:this.lockTime,inputs:this.inputs.map(Hu).map(e=>({...e,finalScriptSig:Oo})),outputs:this.outputs.map(ju)})),delete r.fallbackLocktime,delete r.txVersion):(r.version=e,r.txVersion=this.version,r.inputCount=this.inputs.length,r.outputCount=this.outputs.length,r.fallbackLocktime&&0===r.fallbackLocktime&&delete r.fallbackLocktime),this.opts.bip174jsCompat&&(t.length||t.push({}),n.length||n.push({})),(0===e?wu:vu).encode({global:r,inputs:t,outputs:n})}get lockTime(){let e=0,t=0,n=0,r=0;for(const i of this.inputs)i.requiredHeightLocktime&&(e=Math.max(e,i.requiredHeightLocktime),t++),i.requiredTimeLocktime&&(n=Math.max(n,i.requiredTimeLocktime),r++);return t&&t>=r?e:0!==n?n:this.global.fallbackLocktime||0}get version(){if(void 0===this.global.txVersion)throw new Error("No global.txVersion");return this.global.txVersion}inputStatus(e){this.checkInputIdx(e);const t=this.inputs[e];return t.finalScriptSig&&t.finalScriptSig.length||t.finalScriptWitness&&t.finalScriptWitness.length?"finalized":t.tapKeySig||t.tapScriptSig&&t.tapScriptSig.length||t.partialSig&&t.partialSig.length?"signed":"unsigned"}inputSighash(e){this.checkInputIdx(e);const t=this.inputs[e].sighashType,n=void 0===t?Ru.DEFAULT:t,r=n===Ru.DEFAULT?Ru.ALL:3&n;return{sigInputs:n&Ru.ANYONECANPAY,sigOutputs:r}}signStatus(){let e=!0,t=!0,n=[],r=[];for(let i=0;i<this.inputs.length;i++){if("unsigned"===this.inputStatus(i))continue;const{sigInputs:s,sigOutputs:o}=this.inputSighash(i);if(s===Ru.ANYONECANPAY?n.push(i):e=!1,o===Ru.ALL)t=!1;else if(o===Ru.SINGLE)r.push(i);else if(o!==Ru.NONE)throw new Error(`Wrong signature hash output type: ${o}`)}return{addInput:e,addOutput:t,inputs:n,outputs:r}}get isFinal(){for(let e=0;e<this.inputs.length;e++)if("finalized"!==this.inputStatus(e))return!1;return!0}get hasWitnesses(){let e=!1;for(const t of this.inputs)t.finalScriptWitness&&t.finalScriptWitness.length&&(e=!0);return e}get weight(){if(!this.isFinal)throw new Error("Transaction is not finalized");let e=32;const t=this.outputs.map(ju);e+=4*Ca.encode(this.outputs.length).length;for(const n of t)e+=32+4*Ba.encode(n.script).length;this.hasWitnesses&&(e+=2),e+=4*Ca.encode(this.inputs.length).length;for(const t of this.inputs)e+=160+4*Ba.encode(t.finalScriptSig||Oo).length,this.hasWitnesses&&t.finalScriptWitness&&(e+=Ra.encode(t.finalScriptWitness).length);return e}get vsize(){return e=this.weight,Math.ceil(e/4);var e}toBytes(e=!1,t=!1){return Ha.encode({version:this.version,lockTime:this.lockTime,inputs:this.inputs.map(Hu).map(t=>({...t,finalScriptSig:e&&t.finalScriptSig||Oo})),outputs:this.outputs.map(ju),witnesses:this.inputs.map(e=>e.finalScriptWitness||[]),segwitFlag:t&&this.hasWitnesses})}get unsignedTx(){return this.toBytes(!1,!1)}get hex(){return zi.encode(this.toBytes(!0,this.hasWitnesses))}get hash(){if(!this.isFinal)throw new Error("Transaction is not finalized");return zi.encode(wa(this.toBytes(!0)))}get id(){if(!this.isFinal)throw new Error("Transaction is not finalized");return zi.encode(wa(this.toBytes(!0)).reverse())}checkInputIdx(e){if(!Number.isSafeInteger(e)||0>e||e>=this.inputs.length)throw new Error(`Wrong input index=${e}`)}getInput(e){return this.checkInputIdx(e),Bu(this.inputs[e])}get inputsLength(){return this.inputs.length}addInput(e,t=!1){if(!t&&!this.signStatus().addInput)throw new Error("Tx has signed inputs, cannot add new one");return this.inputs.push(Mu(e,void 0,void 0,this.opts.disableScriptCheck)),this.inputs.length-1}updateInput(e,t,n=!1){let r;if(this.checkInputIdx(e),!n){const t=this.signStatus();t.addInput&&!t.inputs.includes(e)||(r=ru)}this.inputs[e]=Mu(t,this.inputs[e],r,this.opts.disableScriptCheck,this.opts.allowUnknown)}checkOutputIdx(e){if(!Number.isSafeInteger(e)||0>e||e>=this.outputs.length)throw new Error(`Wrong output index=${e}`)}getOutput(e){return this.checkOutputIdx(e),Bu(this.outputs[e])}getOutputAddress(e,t=Aa){const n=this.getOutput(e);if(n.script)return Iu(t).encode(Eu.decode(n.script))}get outputsLength(){return this.outputs.length}normalizeOutput(e,t,n){let{amount:r,script:i}=e;if(void 0===r&&(r=t?.amount),"bigint"!=typeof r)throw new Error(`Wrong amount type, should be of type bigint in sats, but got ${r} of type ${typeof r}`);"string"==typeof i&&(i=zi.decode(i)),void 0===i&&(i=t?.script);let s={...t,...e,amount:r,script:i};if(void 0===s.amount&&delete s.amount,s=yu(iu,s,t,n,this.opts.allowUnknown),du.encode(s),s.script&&!this.opts.allowUnknownOutputs&&"unknown"===Eu.decode(s.script).type)throw new Error("Transaction/output: unknown output script type, there is a chance that input is unspendable. Pass allowUnknownOutputs=true, if you sure");return this.opts.disableScriptCheck||Su(s.script,s.redeemScript,s.witnessScript),s}addOutput(e,t=!1){if(!t&&!this.signStatus().addOutput)throw new Error("Tx has signed outputs, cannot add new one");return this.outputs.push(this.normalizeOutput(e)),this.outputs.length-1}updateOutput(e,t,n=!1){let r;if(this.checkOutputIdx(e),!n){const t=this.signStatus();t.addOutput&&!t.outputs.includes(e)||(r=su)}this.outputs[e]=this.normalizeOutput(t,this.outputs[e],r)}addOutputAddress(e,t,n=Aa){return this.addOutput({script:Eu.encode(Iu(n).decode(e)),amount:t})}get fee(){let e=0n;for(const t of this.inputs){const n=Wu(t);if(!n)throw new Error("Empty input amount");e+=n.amount}const t=this.outputs.map(ju);for(const n of t)e-=n.amount;return e}preimageLegacy(e,t,n){const{isAny:r,isNone:i,isSingle:s}=Zu(n);if(e<0||!Number.isSafeInteger(e))throw new Error(`Invalid input idx=${e}`);if(s&&e>=this.outputs.length||e>=this.inputs.length)return Yo.encode(1n);t=Na.encode(Na.decode(t).filter(e=>"CODESEPARATOR"!==e));let o=this.inputs.map(Hu).map((n,r)=>({...n,finalScriptSig:r===e?t:Oo}));r?o=[o[e]]:(i||s)&&(o=o.map((t,n)=>({...t,sequence:n===e?t.sequence:0})));let a=this.outputs.map(ju);i?a=[]:s&&(a=a.slice(0,e).fill($u).concat([a[e]]));const u=Ha.encode({lockTime:this.lockTime,version:this.version,segwitFlag:!1,inputs:o,outputs:a});return wa(u,na.encode(n))}preimageWitnessV0(e,t,n,r){const{isAny:i,isNone:s,isSingle:o}=Zu(n);let a=Nu,u=Nu,c=Nu;const d=this.inputs.map(Hu),f=this.outputs.map(ju);i||(a=wa(...d.map(Fu.encode))),i||o||s||(u=wa(...d.map(e=>ea.encode(e.sequence)))),o||s?o&&e<f.length&&(c=wa(ja.encode(f[e]))):c=wa(...f.map(ja.encode));const h=d[e];return wa(na.encode(this.version),a,u,sa(32,!0).encode(h.txid),ea.encode(h.index),Ba.encode(t),Qo.encode(r),ea.encode(h.sequence),c,ea.encode(this.lockTime),ea.encode(n))}preimageWitnessV1(e,t,n,r,i=-1,s,o=192,a){if(!Array.isArray(r)||this.inputs.length!==r.length)throw new Error(`Invalid amounts array=${r}`);if(!Array.isArray(t)||this.inputs.length!==t.length)throw new Error(`Invalid prevOutScript array=${t}`);const u=[ia.encode(0),ia.encode(n),na.encode(this.version),ea.encode(this.lockTime)],c=n===Ru.DEFAULT?Ru.ALL:3&n,d=n&Ru.ANYONECANPAY,f=this.inputs.map(Hu),h=this.outputs.map(ju);d!==Ru.ANYONECANPAY&&u.push(...[f.map(Fu.encode),r.map(Qo.encode),t.map(Ba.encode),f.map(e=>ea.encode(e.sequence))].map(e=>ee(ga(...e)))),c===Ru.ALL&&u.push(ee(ga(...h.map(ja.encode))));const l=(a?1:0)|(s?2:0);if(u.push(new Uint8Array([l])),d===Ru.ANYONECANPAY){const n=f[e];u.push(Fu.encode(n),Qo.encode(r[e]),Ba.encode(t[e]),ea.encode(n.sequence))}else u.push(ea.encode(e));return 1&l&&u.push(ee(Ba.encode(a||Oo))),c===Ru.SINGLE&&u.push(e<h.length?ee(ja.encode(h[e])):Nu),s&&u.push(ku(s,o),ia.encode(0),na.encode(i)),xa("TapSighash",...u)}signIdx(e,t,n,r){this.checkInputIdx(t);const i=this.inputs[t],s=qu(i,this.opts.allowLegacyWitnessUtxo);if(!pa(e)){if(!i.bip32Derivation||!i.bip32Derivation.length)throw new Error("bip32Derivation: empty");const n=i.bip32Derivation.filter(t=>t[1].fingerprint==e.fingerprint).map(([t,{path:n}])=>{let r=e;for(const e of n)r=r.deriveChild(e);if(!ma(r.publicKey,t))throw new Error("bip32Derivation: wrong pubKey");if(!r.privateKey)throw new Error("bip32Derivation: no privateKey");return r});if(!n.length)throw new Error(`bip32Derivation: no items with fingerprint=${e.fingerprint}`);let r=!1;for(const e of n)this.signIdx(e.privateKey,t)&&(r=!0);return r}n?n.forEach(Vu):n=[s.defaultSighash];const o=s.sighash;if(!n.includes(o))throw new Error(`Input with not allowed sigHash=${o}. Allowed: ${n.join(", ")}`);const{sigOutputs:a}=this.inputSighash(t);if(a===Ru.SINGLE&&t>=this.outputs.length)throw new Error(`Input with sighash SINGLE, but there is no output with corresponding index=${t}`);const u=Wu(i);if("taproot"===s.txType){const n=this.inputs.map(Wu),s=n.map(e=>e.script),a=n.map(e=>e.amount);let u=!1,c=va(e),d=i.tapMerkleRoot||Oo;if(i.tapInternalKey){const{pubKey:n,privKey:f}=zu(e,c,i.tapInternalKey,d),[h,l]=function(e,t){const n=Ut.utils,r=Oa(e,t),i=n.lift_x(n.bytesToNumberBE(e)).add(ha.fromPrivateKey(r)),s=i.hasEvenY()?0:1;return[n.pointToBytes(i),s]}(i.tapInternalKey,d);if(ma(h,n)){const e=this.preimageWitnessV1(t,s,o,a),n=ga(Ea(e,f,r),o!==Ru.DEFAULT?new Uint8Array([o]):Oo);this.updateInput(t,{tapKeySig:n},!0),u=!0}}if(i.tapLeafScript){i.tapScriptSig=i.tapScriptSig||[];for(const[n,d]of i.tapLeafScript){const n=d.subarray(0,-1),i=Na.decode(n),f=d[d.length-1],h=ku(n,f);if(-1===i.findIndex(e=>pa(e)&&ma(e,c)))continue;const l=this.preimageWitnessV1(t,s,o,a,void 0,n,f),p=ga(Ea(l,e,r),o!==Ru.DEFAULT?new Uint8Array([o]):Oo);this.updateInput(t,{tapScriptSig:[[{pubKey:c,leafHash:h},p]]},!0),u=!0}}if(!u)throw new Error("No taproot scripts signed");return!0}{const n=_a(e);let r=!1;const i=ya(n);for(const e of Na.decode(s.lastScript))pa(e)&&(ma(e,n)||ma(e,i))&&(r=!0);if(!r)throw new Error(`Input script doesn't have pubKey: ${s.lastScript}`);let a;if("legacy"===s.txType)a=this.preimageLegacy(t,s.lastScript,o);else{if("segwit"!==s.txType)throw new Error(`Transaction/sign: unknown tx type: ${s.txType}`);{let e=s.lastScript;"wpkh"===s.last.type&&(e=Eu.encode({type:"pkh",hash:s.last.hash})),a=this.preimageWitnessV0(t,e,o,u.amount)}}const c=function(e,t,n=!1){let r=yt.sign(e,t);if(n&&!ba(r)){const n=new Uint8Array(32);let i=0;for(;!ba(r);)if(n.set(ea.encode(i++)),r=yt.sign(e,t,{extraEntropy:n}),i>4294967295)throw new Error("lowR counter overflow: report the error")}return r.toDERRawBytes()}(a,e,this.opts.lowR);this.updateInput(t,{partialSig:[[n,ga(c,new Uint8Array([o]))]]},!0)}return!0}sign(e,t,n){let r=0;for(let i=0;i<this.inputs.length;i++)try{this.signIdx(e,i,t,n)&&r++}catch(e){}if(!r)throw new Error("No inputs signed");return r}finalizeIdx(e){if(this.checkInputIdx(e),this.fee<0n)throw new Error("Outputs spends more than inputs amount");const t=this.inputs[e],n=qu(t,this.opts.allowLegacyWitnessUtxo);if("taproot"===n.txType){if(t.tapKeySig)t.finalScriptWitness=[t.tapKeySig];else{if(!t.tapLeafScript||!t.tapScriptSig)throw new Error("finalize/taproot: unknown input");{const e=t.tapLeafScript.sort((e,t)=>Ga.encode(e[0]).length-Ga.encode(t[0]).length);for(const[n,r]of e){const e=r.slice(0,-1),i=r[r.length-1],s=Eu.decode(e),o=ku(e,i),a=t.tapScriptSig.filter(e=>ma(e[0].leafHash,o));let u=[];if("tr_ms"===s.type){const e=s.m,t=s.pubkeys;let n=0;for(const r of t){const t=a.findIndex(e=>ma(e[0].pubKey,r));n!==e&&-1!==t?(u.push(a[t][1]),n++):u.push(Oo)}if(n!==e)continue}else if("tr_ns"===s.type){for(const e of s.pubkeys){const t=a.findIndex(t=>ma(t[0].pubKey,e));-1!==t&&u.push(a[t][1])}if(u.length!==s.pubkeys.length)continue}else{if("unknown"!==s.type||!this.opts.allowUnknownInputs){const r=this.opts.customScripts;if(r)for(const i of r){if(!i.finalizeTaproot)continue;const r=Na.decode(e),s=i.encode(r);if(void 0===s)continue;const o=i.finalizeTaproot(e,s,a);if(o)return t.finalScriptWitness=o.concat(Ga.encode(n)),t.finalScriptSig=Oo,void Du(t)}throw new Error("Finalize: Unknown tapLeafScript")}{const t=Na.decode(e);if(u=a.map(([{pubKey:e},n])=>{const r=t.findIndex(t=>pa(t)&&ma(t,e));if(-1===r)throw new Error("finalize/taproot: cannot find position of pubkey in script");return{signature:n,pos:r}}).sort((e,t)=>e.pos-t.pos).map(e=>e.signature),!u.length)continue}}t.finalScriptWitness=u.reverse().concat([e,Ga.encode(n)]);break}if(!t.finalScriptWitness)throw new Error("finalize/taproot: empty witness")}}return t.finalScriptSig=Oo,void Du(t)}if(!t.partialSig||!t.partialSig.length)throw new Error("Not enough partial sign");let r,i,s=Oo,o=[];if("ms"===n.last.type){const e=n.last.m,r=n.last.pubkeys;let i=[];for(const e of r){const n=t.partialSig.find(t=>ma(e,t[0]));n&&i.push(n[1])}if(i=i.slice(0,e),i.length!==e)throw new Error(`Multisig: wrong signatures count, m=${e} n=${r.length} signatures=${i.length}`);s=Na.encode([0,...i])}else if("pk"===n.last.type)s=Na.encode([t.partialSig[0][1]]);else if("pkh"===n.last.type)s=Na.encode([t.partialSig[0][1],t.partialSig[0][0]]);else if("wpkh"===n.last.type)s=Oo,o=[t.partialSig[0][1],t.partialSig[0][0]];else if("unknown"===n.last.type&&!this.opts.allowUnknownInputs)throw new Error("Unknown inputs not allowed");if(n.type.includes("wsh-")&&(s.length&&n.lastScript.length&&(o=Na.decode(s).map(e=>{if(0===e)return Oo;if(pa(e))return e;throw new Error(`Wrong witness op=${e}`)})),o=o.concat(n.lastScript)),"segwit"===n.txType&&(i=o),n.type.startsWith("sh-wsh-")?r=Na.encode([Na.encode([0,ee(n.lastScript)])]):n.type.startsWith("sh-")?r=Na.encode([...Na.decode(s),n.lastScript]):n.type.startsWith("wsh-")||"segwit"!==n.txType&&(r=s),!r&&!i)throw new Error("Unknown error finalizing input");r&&(t.finalScriptSig=r),i&&(t.finalScriptWitness=i),Du(t)}finalize(){for(let e=0;e<this.inputs.length;e++)this.finalizeIdx(e)}extract(){if(!this.isFinal)throw new Error("Transaction has unfinalized inputs");if(!this.outputs.length)throw new Error("Transaction has no outputs");if(this.fee<0n)throw new Error("Outputs spends more than inputs amount");return this.toBytes(!0,!0)}combine(e){for(const t of["PSBTVersion","version","lockTime"])if(this.opts[t]!==e.opts[t])throw new Error(`Transaction/combine: different ${t} this=${this.opts[t]} other=${e.opts[t]}`);for(const t of["inputs","outputs"])if(this[t].length!==e[t].length)throw new Error(`Transaction/combine: different ${t} length this=${this[t].length} other=${e[t].length}`);const t=this.global.unsignedTx?Da.encode(this.global.unsignedTx):Oo,n=e.global.unsignedTx?Da.encode(e.global.unsignedTx):Oo;if(!ma(t,n))throw new Error("Transaction/combine: different unsigned tx");this.global=yu(eu,this.global,e.global,void 0,this.opts.allowUnknown);for(let t=0;t<this.inputs.length;t++)this.updateInput(t,e.inputs[t],!0);for(let t=0;t<this.outputs.length;t++)this.updateOutput(t,e.outputs[t],!0);return this}clone(){return Gu.fromPSBT(this.toPSBT(this.opts.PSBTVersion),this.opts)}}function Yu(e){const t=Di.decode(e);return Gu.fromPSBT(t,{allowUnknownOutputs:!0})}function Qu(e){if(e instanceof Gu)return e;if("string"==typeof e)return Yu(e);throw new Error("invalid psbt input: "+e)}function Xu(e){const t=Qu(e),n=t.inputsLength,r=[];for(let e=0;e<n;e++){const n=t.getInput(e);r.push(n)}return r}function Ju(e){const t=Qu(e),n=t.outputsLength,r=[];for(let e=0;e<n;e++){const n=t.getOutput(e);r.push(n)}return r}function ec(e){for(let t=0;t<e.inputsLength;t++){const n=e.getInput(t),r=n.redeemScript,i=n.partialSig?.at(0);void 0!==r&&void 0!==i&&e.finalizeIdx(t)}return e}var tc,nc=Object.freeze({__proto__:null,assert_psbt_is_funded:function(e){const t=Qu(e),n=Xu(t),r=Ju(t),i=n.reduce((e,t)=>e+Number(t.witnessUtxo?.amount??0),0),s=r.reduce((e,t)=>e+Number(t.amount??0),0);b.ok(i>=s,`value in (${i}) < value out (${s})`)},collect_prevouts:function(e){const t=[],n=[],r=Qu(e);for(let e=0;e<r.inputsLength;e++){const i=r.getInput(e);b.exists(i.witnessUtxo,`witness utxo does not exist for input ${e}`),t.push(i.witnessUtxo.amount),n.push(i.witnessUtxo.script)}return{amounts:t,scripts:n}},collect_vins:Xu,collect_vouts:Ju,decode_psbt:Yu,encode_psbt:function(e){const t=e.toPSBT(0);return Di.encode(t)},finalize_legacy_inputs:ec,get_txhex:function(e){let t=Qu(e);return t=ec(t),t.hex},get_vsize:function(e){return Qu(e).vsize},parse_psbt:Qu});function rc(e){return m.bytes(e).prefix_varint("le").hex}function ic(e){return[...("string"==typeof e?e:m.bytes(e).hex).matchAll(/20([0-9a-f]{64})(ac|ad|ba)/gi)].map(e=>e[1])}!function(e){e.prefix_size=rc,e.decode=to,e.encode=Ys,e.is_valid=no,e.get_pubkeys=ic,e.OPCODES=Zs}(tc||(tc={}));var sc=Object.freeze({__proto__:null,OPCODE_MAP:Zs,get ScriptUtil(){return tc},decode_script:to,encode_script:Ys,encode_script_word:Qs,get_asm_code:Ws,get_op_code:Ks,get_op_type:Ms,get_size_varint:eo,is_valid_op:qs,is_valid_script:no,parse_script_pubkeys:ic,prefix_script_size:rc,prefix_word_size:Js,split_script_word:Xs});function oc(e){return b.exists(e.prevout,"Prevout data missing for input: "+String(e.txid)),e.prevout}function ac(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 uc(e){if(void 0===e)return;if(e.length<2)return;const t=e.at(-1);if("string"==typeof t&&t.startsWith("50")){return en(m.hex(t).prefix_varint("be"))}}const cc={TXID:"00".repeat(32),VOUT:4294967295},dc={LOCKTIME:0,SEQUENCE:4294967295,VERSION:2},fc=[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],hc={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},lc=[1,2,3,129,130,131],pc=[0,...lc];var gc=Object.freeze({__proto__:null,COINBASE:cc,DEFAULT:dc,LOCK_SCRIPT_REGEX:hc,SCRIPT_INT_KEY:"",SIGHASH_DEFAULT:1,SIGHASH_SEGWIT:lc,SIGHASH_TAPROOT:pc,TAPLEAF_DEFAULT_VERSION:192,TAPLEAF_VERSIONS:fc,TX_SIZE:{GLOBAL_BASE:8,GLOBAL_WIT:10,TXIN_BASE:40,TXOUT_BASE:8}});const mc=Zr([Fr(si),si]),yc=Vr({pubkey:si,leaves:mc.array().optional(),target:si.optional(),version:Gr.optional()});var wc=Object.freeze({__proto__:null,config:yc,taptree:mc});const vc=Lr().positive().max(2100000000000000n),_c=Vr({value:vc,script_pk:Yr}),bc=Vr({coinbase:Yr.nullable(),txid:ni,vout:Gr,prevout:_c.nullable(),script_sig:Yr.nullable(),sequence:Gr,witness:Fr(Yr)}),Ec=Vr({version:Gr,vin:Fr(bc),vout:Fr(_c),locktime:Gr}),xc=_c.extend({value:Zr([Gr,vc])}),Sc=bc.extend({coinbase:Yr.nullable().optional(),prevout:xc.nullable().optional(),script_sig:Yr.nullable().optional(),sequence:Zr([Yr,Gr]).optional(),witness:Fr(Yr).optional()}),kc=Vr({version:Gr.default(1),vin:Fr(Sc).default([]),vout:Fr(xc).default([]),locktime:Gr.optional()});var Oc=Object.freeze({__proto__:null,tx_data:Ec,tx_input:bc,tx_output:_c,tx_template:kc,vin_template:Sc,vout_template:xc}),Ac=Object.freeze({__proto__:null,taproot:wc,tx:Oc});function Pc(e){kc.parse(e)}function Tc(e){if(e.some(e=>null===e.prevout))throw new Error("transaction missing prevouts")}function Ic(e){Ec.parse(e)}function Nc(e){Sc.parse(e)}function $c(e){xc.parse(e)}function Uc(e,t=!0){Ic(e);const{version:n,vin:r,vout:i,locktime:s}=e,o=[Cc(n)];if(t&&o.push(m.hex("0001")),o.push(zc(r)),o.push(Dc(i)),t)for(const e of r)o.push(Vc(e.witness));return o.push(Zc(s)),m.join(o)}function Cc(e){return m.num(e,4).reverse()}function Bc(e){return m.hex(e,32).reverse()}function Rc(e){return m.num(e,4).reverse()}function Lc(e){return m.num(e,4).reverse()}function zc(e){const t=[m.varint(e.length,"le")];for(const n of e)t.push(jc(n));return m.join(t)}function jc(e){return null!==e.coinbase?m.join([Bc(cc.TXID),Rc(cc.VOUT),Kc(e.coinbase),Lc(e.sequence)]):m.join([Bc(e.txid),Rc(e.vout),Kc(e.script_sig),Lc(e.sequence)])}function Hc(e){return m.big(e,8).reverse()}function Dc(e){const t=[m.varint(e.length,"le")];for(const n of e)t.push(Fc(n));return m.join(t)}function Fc(e){const{value:t,script_pk:n}=e;return m.join([Hc(t),Kc(n)])}function Vc(e){const t=[m.varint(e.length)];for(const n of e)t.push(Kc(n));return m.join(t)}function Zc(e){return m.num(e,4).reverse()}function Kc(e){return null!==e?(b.is_hex(e),m.hex(e).prefix_varint("le")):m.hex("00")}function Wc(e){for(const[t,n]of Object.entries(hc))if(n.test(e))return t;return"unknown"}function Mc(e){switch(e.slice(0,4)){case"0014":return 0;case"5120":return 1;default:return null}}function qc(e){if(!_.exists(e))return dc.SEQUENCE;if(_.is_hex(e))return m.hex(e,4).reverse().num;if(_.is_uint(e))return e;throw new Error("invalid sequence value: "+String(e))}function Gc(e){if(_.is_uint(e))return BigInt(e);if("bigint"==typeof e)return e;throw new TypeError("invalid output value: "+String(e))}function Yc(e){return{script_pk:e.script_pk,value:Gc(e.value)}}function Qc(e){Nc(e),b.exists(e.coinbase,"coinbase is required");const t=cc.TXID,n=cc.VOUT,r=e.coinbase,i=e.witness??[];return{coinbase:r,prevout:null,script_sig:null,sequence:qc(e.sequence),witness:i,txid:t,vout:n}}function Xc(e){Nc(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:qc(e.sequence),witness:i}}function Jc(e){Nc(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:Yc(e.prevout),script_sig:r,sequence:qc(e.sequence),witness:i}}function ed(e){return e.coinbase?Qc(e):e.prevout?Jc(e):Xc(e)}function td(e){$c(e);return{script_pk:e.script_pk,value:Gc(e.value)}}function nd(e){Pc(e);const{vin:t=[],vout:n=[]}=e??{vin:[],vout:[]},r=e.locktime??dc.LOCKTIME,i=e.version??dc.VERSION;return{locktime:r,vin:t.map(e=>ed(e)),vout:n.map(e=>td(e)),version:i}}function rd(e,t=!0){b.is_bytes(e,"txdata must be hex or bytes");const n=new y(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),s=function(e){const t=[],n=e.varint();for(let r=0;r<n;r++){const n=id(e);t.push(n)}return t}(n),o=function(e){const t=[],n=e.varint();for(let r=0;r<n;r++)try{t.push(sd(e))}catch(e){throw new Error(`failed to decode output: ${r}: ${v(e)}`)}return t}(n);if(i)for(const e of s)e.witness=od(n);const a=function(e){return e.read(4).reverse().to_num()}(n);return{version:r,vin:s,vout:o,locktime:a}}function id(e){const t=e.read(32).reverse().hex,n=e.read(4).reverse().num,r=ad(e),i=e.read(4).reverse().num,s=[];return t===cc.TXID&&n===cc.VOUT?{coinbase:r,prevout:null,script_sig:null,sequence:i,txid:t,vout:n,witness:s}:{coinbase:null,prevout:null,script_sig:r,sequence:i,txid:t,vout:n,witness:s}}function sd(e){const t=e.read(8).reverse().big,n=ad(e);return b.exists(n,"failed to decode script_pk"),{value:t,script_pk:n}}function od(e){const t=[],n=e.varint();for(let r=0;r<n;r++){const n=ad(e);if(null===n)throw new Error("failed to decode witness element: "+r);t.push(n)}return t}function ad(e){const t=e.varint("le");return t>0?e.read(t).hex:null}function ud(e,t){let n;if("string"==typeof e||e instanceof Uint8Array?n=rd(e):(Pc(e),n=nd(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=td(n)}}return n}var cd=Object.freeze({__proto__:null,assert_has_prevouts:Tc,assert_tx_data:Ic,assert_tx_input:function(e){bc.parse(e)},assert_tx_output:function(e){_c.parse(e)},assert_tx_spend_data:function(e){Ic(e),Tc(e.vin)},assert_tx_template:Pc,assert_vin_template:Nc,assert_vout_template:$c,create_coinbase_input:Qc,create_spend_input:Jc,create_tx:nd,create_tx_input:ed,create_tx_output:td,create_virtual_input:Xc,decode_tx:rd,encode_script_data:Kc,encode_tx:Uc,encode_tx_inputs:zc,encode_tx_locktime:Zc,encode_tx_outputs:Dc,encode_tx_version:Cc,encode_tx_vout:Fc,encode_txin_sequence:Lc,encode_txin_txid:Bc,encode_txin_vout:Rc,encode_vin:jc,encode_vin_witness:Vc,encode_vout_value:Hc,get_prevouts:function(e){Pc(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+Vc(t).length,0)},get_tx_value:function(e){const t=e.vin.reduce((e,t)=>e+(t.prevout?.value??0n),0n),n=e.vout.reduce((e,t)=>e+t.value,0n);return{fees:t>n?t-n:0n,vin:t,vout:n}},get_txhash:function(e){return Pc(e),tn(Uc(e,!0)).reverse().hex},get_txid:function(e){return Pc(e),tn(Uc(e,!1)).reverse().hex},get_txin_size:function(e){return jc(e).length},get_txout_size:function(e){return Fc(e).length},get_txsize:function(e){const t=ud(e),n=Uc(t,!1).length,r=Uc(t,!0).length,i=3*n+r,s=i%4>0?1:0;return{base:n,total:r,vsize:Math.ceil(i/4)+s,weight:i}},get_vin_size:function(e){return zc(e).length},get_vout_info:function(e){return{type:Wc(e.script_pk),version:Mc(e.script_pk)}},get_vout_size:function(e){return Dc(e).length},get_vout_type:Wc,get_vout_version:Mc,get_vsize:function(e){const t=m.bytes(e).length,n=t%4>0?1:0;return Math.ceil(t/4)+n},is_return_script:function(e){return e.startsWith("6a")},normalize_prevout:Yc,normalize_sequence:qc,normalize_value:Gc,parse_tx:ud,read_payload:ad,serialize_tx:function(e){const t=ud(e),n=t.version,r=t.locktime,i=[],s=[];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)s.push({script_pk:e.script_pk,value:Number(e.value)});return{version:n,locktime:r,vin:i,vout:s}}});function dd(e,t={}){const{sigflag:n=1,txindex:r}=t,i=ud(e),s=!(128&~n),o=n%128;if(!lc.includes(o))throw new Error("Invalid hash type: "+String(n));const{version:a,vin:u,vout:c,locktime:d}=i,f=ac(i,t),{txid:h,vout:l,prevout:p,sequence:g}=f,{value:y}=p??{};if(void 0===y)throw new Error("Prevout value is empty!");let{pubkey:w,script:v}=t;if(void 0===v&&void 0!==w){const e=Jt(w).hex;v=`76a914${String(e)}88ac`}if(void 0===v)throw new Error("No pubkey / script has been set!");if(to(v).includes("OP_CODESEPARATOR"))throw new Error("This library does not currently support the use of OP_CODESEPARATOR in segwit scripts.");const _=[Cc(a),fd(u,s),hd(u,o,s),Bc(h),Rc(l),rc(v),Hc(y),Lc(g),ld(c,o,r),Zc(d),m.num(n,4).reverse()];return tn(m.join(_))}function fd(e,t){if(!0===t)return m.num(0,32);const n=[];for(const{txid:t,vout:r}of e)n.push(Bc(t)),n.push(Rc(r));return tn(m.join(n))}function hd(e,t,n){if(n||1!==t)return m.num(0,32);const r=[];for(const{sequence:t}of e)r.push(Lc(t));return tn(m.join(r))}function ld(e,t,n){const r=[];if(1===t){for(const{value:t,script_pk:n}of e)r.push(Hc(t)),r.push(rc(n));return tn(m.join(r))}if(3===t&&(b.ok(void 0!==n),n<e.length)){const{value:t,script_pk:i}=e[n];return r.push(Hc(t)),r.push(rc(i)),tn(m.join(r))}return m.num(0,32)}function pd(e,t=192){return gd(rc(e),t)}function gd(e,t=192){return nn("TapLeaf",yd(t),e)}function md(e,t){return t<e&&([e,t]=[t,e]),nn("TapBranch",e,t)}function yd(e=192){return 254&e}function wd(e,t=new Uint8Array){return b.size(e,32),nn("TapTweak",e,t)}function vd(e,t={}){return nn("TapSighash",_d(e,t))}function _d(e,t={}){const{script:n,txindex:r,sigflag:i=0,extflag:s=0,key_version:o=0,separator_pos:a=4294967295}=t,u=ud(e),{version:c,vin:d,vout:f,locktime:h}=u,l=ac(u,t),{txid:p,vout:g,sequence:y,witness:w=[]}=l;if(!pc.includes(i))throw new Error("Invalid hash type: "+String(i));if(s<0||s>127)throw new Error("Extention flag out of range: "+String(s));let{extension:v}=t;void 0!==n&&(v=pd(n).hex);const _=!(128&~i),E=uc(w),x=2*(s+(void 0!==v?1:0))+(void 0!==E?1:0),S=[m.num(0,1),m.num(i,1),Cc(c),Zc(h)];if(!_){const e=d.map(e=>oc(e));S.push(bd(d),xd(e),Sd(e),Ed(d))}if(((3&i)<2||(3&i)>3)&&S.push(kd(f)),S.push(m.num(x,1)),_){const{value:e,script_pk:t}=oc(l);S.push(Bc(p),Rc(g),Hc(e),Kc(t),Lc(y))}else b.ok("number"==typeof r),S.push(m.num(r,4).reverse());return void 0!==E&&S.push(E),3&~i||(b.ok("number"==typeof r),S.push(Od(f[r]))),void 0!==v&&S.push(m.bytes(v),m.num(o),m.num(a,4,"le")),m.join(S)}function bd(e){const t=[];for(const{txid:n,vout:r}of e)t.push(Bc(n)),t.push(Rc(r));return en(m.join(t))}function Ed(e){return en(...e.map(e=>Lc(e.sequence)))}function xd(e){return en(...e.map(e=>Hc(e.value)))}function Sd(e){return en(...e.map(e=>Kc(e.script_pk)))}function kd(e){const t=[];for(const{value:n,script_pk:r}of e)t.push(Hc(n)),t.push(Kc(r));return en(...t)}function Od(e){return en(Hc(e.value),Kc(e.script_pk))}var Ad=Object.freeze({__proto__:null,bip143_hash_outputs:ld,bip143_hash_prevouts:fd,bip143_hash_sequence:hd,bip341_hash_amounts:xd,bip341_hash_outpoints:bd,bip341_hash_output:Od,bip341_hash_outputs:kd,bip341_hash_scripts:Sd,bip341_hash_sequence:Ed,get_annex_data:uc,get_prevout:oc,get_taproot_tx_preimage:_d,hash_segwit_tx:dd,hash_taproot_tx:vd,parse_txinput:ac});function Pd(e){return 0!==e?m.num(e,1).hex:""}var Td=Object.freeze({__proto__:null,sign_segwit_tx:function(e,t,n){return function(e,t){const n=Lt(t),r=yt.sign(n,e).toDERRawBytes();return m.bytes(r)}(e,dd(ud(t),n)).hex+Pd(n.sigflag??1)},sign_taproot_tx:function(e,t,n){return function(e,t){const n=Lt(t);return Lt(Ut.sign(n,e))}(e,vd(ud(t),n)).hex+Pd(n.sigflag??0)},verify_tx:function(e,t={}){return console.warn("verify_segwit_tx is not implemented"),!0}});function Id(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 s=e[i];if(Array.isArray(s)){let[e,i,o]=Id(s,t);t=i,r.push(e);for(const e of o)n.push(e)}else{const e=m.bytes(s).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 s=md(r[e],r[e+1]).hex;i.push(s),"string"==typeof t&&(t===r[e]?(n.push(r[e+1]),t=s):t===r[e+1]&&(n.push(r[e]),t=s))}return Id(i,t,n)}function Nd(e){const t=e.map(e=>m.bytes(e)),n=e.map(e=>m.bytes(e).hex),r=function(e){let t=e.at(-1);return e.length>1&&t instanceof Uint8Array&&80===t[0]?new m(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&&fc.includes(254&t[0])?new m(t).hex:null}(t);null!==i&&t.pop();const s=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&&no(i)?"p2w-sh":"unknown"}(t,i),o=function(e){return e.startsWith("p2tr")?1:e.startsWith("p2w")?0:null}(s),a=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 m(n).hex:null}(t,s);null!==a&&t.pop();return{annex:r,cblock:i,params:t.map(e=>e.hex),script:a,stack:n,type:s,version:o}}function $d(e){const t=new y(e),n=t.read(1).num,r=t.read(32).hex,[i,s]=Ud(n),o=[];for(;t.size>=32;)o.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:o,parity:s,version:i}}function Ud(e){return e%2==0?[e-0,2]:[e-1,3]}function Cd(e){b.size(e,33,"invalid pubkey size");const[t]=m.bytes(e);if(2===t)return 0;if(3===t)return 1;throw new Error("Invalid parity bit: "+String(t))}const Bd=192;var Rd=Object.freeze({__proto__:null,create_taproot:function(e){yc.parse(e);const{pubkey:t,version:n=Bd}=e,r=e.leaves??[],i=void 0!==e.target?m.bytes(e.target).hex:void 0;let s,o=[];if(r.length>0){const[e,t,n]=Id(r,i);o=n,s=e}else s=i;const a=wd(t,s),u=Bt(t,a,"ecdsa"),c=Cd(u),d=Rt(u,"bip340"),f=[m.num(n+c),m.bytes(t)];o.length>0&&o.forEach(e=>f.push(e));const h=m.join(f);return{int_key:m.bytes(t).hex,parity:c,taproot:s??null,cblock:h.hex,tapkey:d.hex,taptweak:a.hex}},encode_leaf_version:yd,encode_tapbranch:md,encode_tapleaf:gd,encode_tapscript:pd,encode_taptweak:wd,get_merkle_root:function(e){return Id(e)[0]},merkleize:Id,parse_cblock:$d,parse_cblock_parity:Ud,parse_pubkey_parity:Cd,parse_taproot_witness:function(e){const{cblock:t,params:n,script:r}=Nd(e);b.exists(t,"cblock is null"),b.exists(r,"script is null");const i=$d(t);let s=pd(r,i.version).hex;for(const e of i.path)s=md(s,e).hex;const o=wd(i.int_key,s),a=Bt(i.int_key,o,"bip340");return n.map(e=>m.bytes(e).hex),{cblock:i,params:n,script:r,tapkey:a.hex,tweak:o.hex}},verify_taproot:function(e,t,n){b.size(e,32);const{parity:r,path:i,int_key:s}=$d(n),o=m.join([r,e]);let a=m.bytes(t).hex;for(const e of i)a=md(a,e).hex;const u=Bt(s,wd(s,a),"ecdsa");return o.hex===u.hex}});var Ld=Object.freeze({__proto__:null,assert_witness:function(e){b.ok(Array.isArray(e),"witness must be an array"),b.ok(e.every(e=>m.is_bytes(e)),"witness must be an array of strings or bytes")},get_witness_size:function(e){const t=e.map(e=>m.bytes(e)).reduce((e,t)=>e+t.length,0);return{total:t,vsize:Math.ceil(1+t/4)}},parse_witness:Nd});return e.ADDRESS=Os,e.CONST=gc,e.META=ko,e.PSBT=nc,e.SCHEMA=Ac,e.SCRIPT=sc,e.SIGHASH=Ad,e.SIGNER=Td,e.TAPROOT=Rd,e.TX=cd,e.WITNESS=Ld,e}({});
14
+ function oi(e){return e instanceof Uint8Array||ArrayBuffer.isView(e)&&"Uint8Array"===e.constructor.name}function ai(e,t){return!!Array.isArray(t)&&(0===t.length||(e?t.every(e=>"string"==typeof e):t.every(e=>Number.isSafeInteger(e))))}function ui(e){if("function"!=typeof e)throw new Error("function expected");return!0}function ci(e,t){if("string"!=typeof t)throw new Error(`${e}: string expected`);return!0}function di(e){if(!Number.isSafeInteger(e))throw new Error(`invalid integer: ${e}`)}function fi(e){if(!Array.isArray(e))throw new Error("array expected")}function li(e,t){if(!ai(!0,t))throw new Error(`${e}: array of strings expected`)}function hi(e,t){if(!ai(!1,t))throw new Error(`${e}: array of numbers expected`)}function pi(...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 mi(e){const t="string"==typeof e?e.split(""):e,n=t.length;li("alphabet",t);const r=new Map(t.map((e,t)=>[e,t]));return{encode:r=>(fi(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=>(fi(t),t.map(t=>{ci("alphabet.decode",t);const n=r.get(t);if(void 0===n)throw new Error(`Unknown letter: "${t}". Allowed: ${e}`);return n}))}}function gi(e=""){return ci("join",e),{encode:t=>(li("join.decode",t),t.join(e)),decode:t=>(ci("join.decode",t),t.split(e))}}function yi(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(fi(e),!e.length)return[];let r=0;const i=[],s=Array.from(e,e=>{if(di(e),e<0||e>=t)throw new Error(`invalid integer: ${e}`);return e}),o=s.length;for(;;){let e=0,a=!0;for(let i=r;i<o;i++){const o=s[i],u=t*e,c=u+o;if(!Number.isSafeInteger(c)||u/t!==e||c-o!==u)throw new Error("convertRadix: carry overflow");const d=c/n;e=c%n;const f=Math.floor(d);if(s[i]=f,!Number.isSafeInteger(f)||f*n+e!==c)throw new Error("convertRadix: carry overflow");a&&(f?a=!1:r=i)}if(i.push(e),a)break}for(let t=0;t<e.length-1&&0===e[t];t++)i.push(0);return i.reverse()}qr([ri,ei]),qr([ii,ti]),Br().regex(/^[1-9A-HJ-NP-Za-km-z]+$/),Br().regex(/^[a-zA-Z0-9+/]+={0,2}$/),Br().regex(/^[a-zA-Z0-9\-_]+={0,2}$/),Br().regex(/^[a-z]+1[023456789acdefghjklmnpqrstuvwxyz]+$/);const _i=(e,t)=>0===t?e:_i(t,e%t),vi=(e,t)=>e+(t-_i(e,t)),wi=(()=>{let e=[];for(let t=0;t<40;t++)e.push(2**t);return e})();function bi(e,t,n,r){if(fi(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(vi(t,n)>32)throw new Error(`convertRadix2: carry overflow from=${t} to=${n} carryBits=${vi(t,n)}`);let i=0,s=0;const o=wi[t],a=wi[n]-1,u=[];for(const r of e){if(di(r),r>=o)throw new Error(`convertRadix2: invalid data word=${r} from=${t}`);if(i=i<<t|r,s+t>32)throw new Error(`convertRadix2: carry overflow pos=${s} from=${t}`);for(s+=t;s>=n;s-=n)u.push((i>>s-n&a)>>>0);const e=wi[s];if(void 0===e)throw new Error("invalid carry");i&=e-1}if(i=i<<n-s&a,!r&&s>=t)throw new Error("Excess padding");if(!r&&i>0)throw new Error(`Non-zero padding: ${i}`);return r&&s>0&&u.push(i>>>0),u}function xi(e,t=!1){if(di(e),e<=0||e>32)throw new Error("radix2: bits should be in (0..32]");if(vi(8,e)>32||vi(e,8)>32)throw new Error("radix2: carry overflow");return{encode:n=>{if(!oi(n))throw new Error("radix2.encode input should be Uint8Array");return bi(Array.from(n),8,e,!t)},decode:n=>(hi("radix2.decode",n),Uint8Array.from(bi(n,e,8,t)))}}function Ei(e){return ui(e),function(...t){try{return e.apply(null,t)}catch(e){}}}const ki=(()=>"function"==typeof Uint8Array.from([]).toBase64&&"function"==typeof Uint8Array.fromBase64)()?{encode:e=>(function(e,...t){if(!oi(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(ci("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)}:pi(xi(6),mi("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"),function(e,t="="){return di(e),ci("padding",t),{encode(n){for(li("padding.encode",n);n.length*e%8;)n.push(t);return n},decode(n){li("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),gi("")),Oi=pi(xi(6),mi("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_"),gi("")),Si=(Ai="123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz",pi(function(e){return di(e),{encode:t=>{if(!oi(t))throw new Error("radix.encode input should be Uint8Array");return yi(Array.from(t),256,e)},decode:t=>(hi("radix.decode",t),Uint8Array.from(yi(t,e,256)))}}(58),mi(Ai),gi("")));var Ai;const Pi=e=>{return pi((n=t=>e(e(t)),di(t=4),ui(n),{encode(e){if(!oi(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(!oi(e))throw new Error("checksum.decode: input should be Uint8Array");const r=e.slice(0,-t),i=e.slice(-t),s=n(r).slice(0,t);for(let e=0;e<t;e++)if(s[e]!==i[e])throw new Error("Invalid checksum");return r}}),Si);var t,n},Ii=pi(mi("qpzry9x8gf2tvdw0s3jn54khce6mua7l"),gi("")),Ti=[996825010,642813549,513874426,1027748829,705979059];function Ni(e){const t=e>>25;let n=(33554431&e)<<5;for(let e=0;e<Ti.length;e++)1==(t>>e&1)&&(n^=Ti[e]);return n}function Ci(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=Ni(i)^n>>5}i=Ni(i);for(let t=0;t<r;t++)i=Ni(i)^31&e.charCodeAt(t);for(let e of t)i=Ni(i)^e;for(let e=0;e<6;e++)i=Ni(i);return i^=n,Ii.encode(bi([i%wi[30]],30,5,!1))}function $i(e){const t="bech32"===e?1:734539939,n=xi(5),r=n.decode,i=n.encode,s=Ei(r);function o(e,n,r=90){ci("bech32.encode prefix",e),oi(n)&&(n=Array.from(n)),hi("bech32.encode",n);const i=e.length;if(0===i)throw new TypeError(`Invalid prefix length ${i}`);const s=i+7+n.length;if(!1!==r&&s>r)throw new TypeError(`Length ${s} exceeds limit ${r}`);const o=e.toLowerCase(),a=Ci(o,n,t);return`${o}1${Ii.encode(n)}${a}`}function a(e,n=90){ci("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 s=i.lastIndexOf("1");if(0===s||-1===s)throw new Error('Letter "1" must be present between prefix and data only');const o=i.slice(0,s),a=i.slice(s+1);if(a.length<6)throw new Error("Data must be at least 6 characters long");const u=Ii.decode(a).slice(0,-6),c=Ci(o,u,t);if(!a.endsWith(c))throw new Error(`Invalid checksum in ${e}: expected "${c}"`);return{prefix:o,words:u}}return{encode:o,decode:a,encodeFromBytes:function(e,t){return o(e,i(t))},decodeToBytes:function(e){const{prefix:t,words:n}=a(e,!1);return{prefix:t,words:n,bytes:r(n)}},decodeUnsafe:Ei(a),fromWords:r,fromWordsUnsafe:s,toWords:i}}const Ri=$i("bech32"),Bi=$i("bech32m");var Ui,ji,Zi,zi,Li;function Fi(e){if("string"!=typeof e||0===e.length)throw new Error(`invalid prefix: ${String(e)}`)}function Di(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),Pi(ee).encode(e)),e.decode=e=>(b.is_base58(e),Pi(ee).decode(e))}(Ui||(Ui={})),function(e){e.encode=e=>(b.is_u8a(e),ki.encode(e)),e.decode=e=>(b.is_base64(e),ki.decode(e))}(ji||(ji={})),function(e){e.encode=e=>(b.is_u8a(e),Oi.encode(e)),e.decode=e=>(b.is_b64url(e),Oi.decode(e))}(Zi||(Zi={})),function(e){e.to_words=Ri.toWords,e.to_bytes=Ri.fromWords,e.encode=(e,t,n=!1)=>(Fi(e),Di(t),Ri.encode(e,t,n)),e.decode=(e,t=!1)=>(b.is_bech32(e),Ri.decode(e,t))}(zi||(zi={})),function(e){e.to_words=Bi.toWords,e.to_bytes=Bi.fromWords,e.encode=(e,t,n=!1)=>(Fi(e),Di(t),Bi.encode(e,t,n)),e.decode=(e,t=!1)=>(b.is_bech32(e),Bi.decode(e,t))}(Li||(Li={}));const Hi={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}$/},qi=0,Vi=1;function Mi(e){const t=function(e){for(const[t,n]of Object.entries(Hi))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=Ui.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}=zi.decode(e),[r,...i]=n;b.ok(r===qi,"bech32 version mismatch");return{data:zi.to_bytes(i),format:"bech32",prefix:t,version:r}}(e);if("bech32m"===t)return function(e){const{prefix:t,words:n}=Li.decode(e),[r,...i]=n;b.ok(r===Vi,"bech32m version mismatch");return{data:Li.to_bytes(i),format:"bech32m",prefix:t,version:r}}(e);throw new Error("unable to find a matching address configuration")}function Ki(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 Ui.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=zi.to_words(t);return zi.encode(e.prefix,[qi,...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=Li.to_words(t);return Li.encode(e.prefix,[Vi,...n])}(e);throw new Error("unrecognized encoding format: "+e.format)}const Wi=[["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 Gi(e,t){for(const[n,r,i,s,o,a]of Wi)if(r===t&&i===e)return{type:r,prefix:n,network:i,size:s,format:o,version:a};return null}function Yi(e){const t=function(e){const t=Mi(e);for(const[n,r,i,s,o,a]of Wi){if(o!==t.format)continue;if(s!==t.data.length)continue;if(a!==t.version)continue;if(t.prefix){if(n!==t.prefix)continue}else if(!e.startsWith(n))continue;const u=g.uint(t.data).hex;return{data:t.data,hex:u,type:r,prefix:n,network:i,size:s,format:o,version:a}}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 Qi="p2pkh";var Xi;function Ji(e,t="main"){return es(Jt(g.bytes(e)),t)}function es(e,t="main"){const n=g.bytes(e),r=Gi(t,Qi);return b.exists(r,`unrecognized address config: ${Qi} on ${t}`),b.size(n,r.size,`invalid payload size: ${n.length} !== ${r.size}`),Ki({data:n,format:"base58",version:r.version})}function ts(e){const t=Yi(e);return b.ok("p2pkh"===t.type,`address type mismatch: ${t.type} !== ${Qi}`),t}!function(e){e.create=Ji,e.encode=es,e.decode=ts}(Xi||(Xi={}));const ns="p2sh";var rs;function is(e,t="main"){return ss(Jt(g.bytes(e)),t)}function ss(e,t="main"){const n=g.bytes(e),r=Gi(t,ns);return b.exists(r,`unrecognized address config: ${ns} on ${t}`),b.size(n,r.size,`invalid payload size: ${n.length} !== ${r.size}`),Ki({data:n,format:"base58",version:r.version})}function os(e){const t=Yi(e);return b.ok("p2sh"===t.type,`address type mismatch: ${t.type} !== ${ns}`),t}!function(e){e.create=is,e.encode=ss,e.decode=os}(rs||(rs={}));const as="p2w-pkh";var us;function cs(e,t="main"){const n=g.bytes(e);b.size(n,33,`invalid payload size: ${n.length} !== 33`);return ds(Jt(n),t)}function ds(e,t="main"){const n=g.bytes(e),r=Gi(t,as);return b.exists(r,`unrecognized address config: ${as} on ${t}`),b.size(n,r.size,`invalid payload size: ${n.length} !== ${r.size}`),Ki({data:n,format:"bech32",prefix:r.prefix})}function fs(e){const t=Yi(e);return b.ok("p2w-pkh"===t.type,`address type mismatch: ${t.type} !== ${as}`),t}!function(e){e.create=cs,e.encode=ds,e.decode=fs}(us||(us={}));const ls="p2w-sh";var hs;function ps(e,t="main"){return ms(en(g.bytes(e)),t)}function ms(e,t="main"){const n=g.bytes(e),r=Gi(t,ls);return b.exists(r,`unrecognized address config: ${ls} on ${t}`),b.size(n,r.size,`invalid payload size: ${n.length} !== ${r.size}`),Ki({data:n,format:"bech32",prefix:r.prefix})}function gs(e){const t=Yi(e);return b.ok("p2w-sh"===t.type,`address type mismatch: ${t.type} !== ${ls}`),t}!function(e){e.create=ps,e.encode=ms,e.decode=gs}(hs||(hs={}));const ys="p2tr";var _s,vs;function ws(e,t="main"){const n=g.bytes(e),r=Gi(t,ys);return b.exists(r,`unrecognized address config: ${ys} on ${t}`),b.size(n,r.size,`invalid payload size: ${n.length} !== ${r.size}`),Ki({data:n,format:"bech32m",prefix:r.prefix})}function bs(e){const t=Yi(e);return b.ok("p2tr"===t.type,`address type mismatch: ${t.type} !== ${ys}`),t}!function(e){e.encode=ws,e.decode=bs}(_s||(_s={})),function(e){e.P2PKH=Xi,e.P2SH=rs,e.P2WPKH=us,e.P2WSH=hs,e.P2TR=_s,e.parse=Yi}(vs||(vs={}));var xs=Object.freeze({__proto__:null,get AddressTool(){return vs},get P2PKH(){return Xi},get P2SH(){return rs},get P2TR(){return _s},get P2WPKH(){return us},get P2WSH(){return hs},parse_address:Yi});const Es=5e8;var ks,Os;function Ss(e){switch(e.type){case"timelock":return b.ok(e.stamp>=Es,"Invalid timestamp"),e.stamp;case"heightlock":return b.ok(e.height>0,"height must be greater than 0"),b.ok(e.height<Es,"invalid block height"),e.height;default:throw new Error("Invalid locktime type")}}function As(e){return isNaN(e)||e<=0?null:e<Es?{type:"heightlock",height:e}:{type:"timelock",stamp:e}}function Ps(e,t=0){return`${e}i${t}`}function Is(e){Ns(e);const[t,n]=e.split("i");return{txid:t,order:parseInt(n)}}function Ts(e){return null!==e.match(/^[a-f0-9]{64}i\d+$/)}function Ns(e){if(!Ts(e))throw new Error(`invalid inscription id: ${e}`)}function Cs(e,t){return`${e}:${t}`}function $s(e){Bs(e);const[t,n]=e.split(":");return{block_height:parseInt(t),block_index:parseInt(n)}}function Rs(e){return null!==e.match(/^\d+:\d+$/)}function Bs(e){if(!Rs(e))throw new Error(`invalid rune id: ${e}`)}function Us(e,t){return`${e}:${t}`}function js(e){zs(e);const[t,n]=e.split(":");return{txid:t,vout:parseInt(n)}}function Zs(e){return null!==e.match(/^[a-f0-9]{64}:[0-9]+$/)}function zs(e){if(!Zs(e))throw new Error(`invalid outpoint: ${e}`)}!function(e){e.encode=Ss,e.decode=As}(ks||(ks={})),function(e){e.outpoint={encode:Us,decode:js,verify:Zs,assert:zs},e.record_id={encode:Ps,decode:Is,verify:Ts,assert:Ns},e.rune_id={encode:Cs,decode:$s,verify:Rs,assert:Bs}}(Os||(Os={}));const Ls={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 Fs(e){if(e>186&&e<255)return"OP_SUCCESS"+String(e);for(const[t,n]of Object.entries(Ls))if(n===e)return t;throw new Error("OPCODE not found:"+String(e))}function Ds(e){for(const[t,n]of Object.entries(Ls))if(t===e)return Number(n);throw new Error("OPCODE not found:"+e)}function Hs(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 qs(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 Vs=520;function Ms(e,t=!1){if(0===e.length)return"00";const n=[];for(const t of e)n.push(Ks(t));const r=g.join(n);return t?r.prepend(g.varint(r.length,"le")).hex:r.hex}function Ks(e){let t;if("string"==typeof e){if(e.startsWith("OP_")){const t=Ds(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>Vs){let e;e=Ws(t),e=e.map(e=>Gs(e)),t=g.join(e)}else t=Gs(t);return t}function Ws(e){const t=[],n=new y(e);for(;n.size>Vs;)t.push(n.read(Vs));return t.push(n.read(n.size)),t}function Gs(e){const t=Ys(e.length);return g.join([t,e])}function Ys(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<=Vs:return g.join([n,g.num(e,2,"le")]);default:throw new Error("Invalid word size:"+e.toString())}}function Qs(e){const t=new y(e),n=[],r=t.size;let i,s,o,a=0;for(;a<r;)switch(i=t.read(1).num,s=Hs(i),a++,s){case"varint":n.push(t.read(i).hex),a+=i;break;case"pushdata1":o=t.read(1).reverse().num,n.push(t.read(o).hex),a+=o+1;break;case"pushdata2":o=t.read(2).reverse().num,n.push(t.read(o).hex),a+=o+2;break;case"pushdata4":o=t.read(4).reverse().num,n.push(t.read(o).hex),a+=o+4;break;case"opcode":if(!qs(i))throw new Error(`Invalid OPCODE: ${i}`);n.push(Fs(i));break;default:throw new Error(`Word type undefined: ${i}`)}return n}function Xs(e){try{return Qs(e).length>0}catch{return!1}}const Js=BigInt(0),eo=BigInt(1),to=BigInt(26);var no;function ro(e){const t=function(e){const t=Qs(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(oo)}function io(e){return e.map(so).join("")}function so(e){let t=["OP_0","OP_IF","6f7264"];if("string"==typeof e.delegate){const n=ao(e.delegate);t.push("OP_11",n)}if("string"==typeof e.ref&&t.push("OP_WITHIN",e.ref),"string"==typeof e.parent){const n=ao(e.parent);t.push("OP_3",n)}if("number"==typeof e.opcode){const n=co(e.opcode);t.push("OP_NOP",n)}if("number"==typeof e.pointer){const n=co(e.pointer);t.push("OP_2",n)}if("string"==typeof e.rune){const n=function(e){const t=e.toUpperCase();let n=Js;for(const e of t)e>="A"&&e<="Z"&&(n=n*to+BigInt(e.charCodeAt(0)-("A".charCodeAt(0)-1)));return n-=eo,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 y(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"),Ms(t)}function oo(e){const t={};for(let n=0;n<e.length;n++)switch(e[n]){case"OP_1":t.mimetype=lo(e[n+1]),n+=1;break;case"OP_2":t.pointer=fo(e[n+1]),n+=1;break;case"OP_3":t.parent=uo(e[n+1]),n+=1;break;case"OP_11":t.delegate=uo(e[n+1]),n+=1;break;case"OP_13":t.rune=po(e[n+1]),n+=1;break;case"OP_WITHIN":t.ref=e[n+1],n+=1;break;case"OP_NOP":t.opcode=fo(e[n+1]),n+=1;break;case"OP_0":return t.content=ho(e.slice(n+1)),t}return t}function ao(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 uo(e){const t=g.hex(e),n=t.at(-1)??0;return t.slice(0,-1).reverse().hex+"i"+String(n)}function co(e){return g.num(e).reverse().hex}function fo(e){return g.hex(e).reverse().num}function lo(e){return g.hex(e).str}function ho(e,t="hex"){const n=g.join(e);return"hex"===t?n.hex:n.str}function po(e){let t=g.hex(e).reverse().big;t+=eo;let n="";for(;t>Js;){const e=t%to;if(e===Js)n="Z"+n,t=t/to-eo;else{const r=Number(e)+"A".charCodeAt(0)-1;n=String.fromCharCode(r)+n,t/=to}}return n}!function(e){e.encode=io,e.decode=ro}(no||(no={}));const mo=4194304,go=65535,yo=65535;var _o;function vo(e){if("height"===e.mode){return(function(e){if(void 0===e||!Number.isInteger(e)||e<0||e>yo)throw new Error("Heightlock value must be an integer between 0 and 65535");return e}(e.height)&go)>>>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>yo)throw new Error("timelock value must be an integer between 0 and 65535 (in 512-second increments)");return t}(e.stamp);return(mo|t&go)>>>0}throw new Error("invalid timelock mode: "+e.mode)}function wo(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&go;if(t&mo){const e=512*n;if(e>4294967295)throw new Error("Decoded timestamp exceeds 32-bit limit");return{mode:"stamp",stamp:e}}if(n>yo)throw new Error("Decoded height exceeds maximum");return{mode:"height",height:n}}!function(e){e.encode=vo,e.decode=wo}(_o||(_o={}));var bo,xo=Object.freeze({__proto__:null,get LocktimeUtil(){return ks},get RefEncoder(){return Os},get ScribeEncoder(){return no},get SequenceUtil(){return _o},decode_inscription:ro,decode_locktime:As,decode_sequence:wo,encode_inscription:io,encode_locktime:Ss,encode_sequence:vo});function Eo(e){return g.bytes(e).prefix_varint("le").hex}function ko(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=Eo,e.decode=Qs,e.encode=Ms,e.is_valid=Xs,e.get_pubkeys=ko,e.OPCODES=Ls}(bo||(bo={}));var Oo=Object.freeze({__proto__:null,OPCODE_MAP:Ls,get ScriptUtil(){return bo},decode_script:Qs,encode_script:Ms,encode_script_word:Ks,get_asm_code:Ds,get_op_code:Fs,get_op_type:Hs,get_size_varint:Ys,is_valid_op:qs,is_valid_script:Xs,parse_script_pubkeys:ko,prefix_script_size:Eo,prefix_word_size:Gs,split_script_word:Ws});function So(e){return b.exists(e.prevout,"Prevout data missing for input: "+String(e.txid)),e.prevout}function Ao(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 Po(e){if(void 0===e)return;if(e.length<2)return;const t=e.at(-1);if("string"==typeof t&&t.startsWith("50")){return en(g.hex(t).prefix_varint("be"))}}const Io={TXID:"00".repeat(32),VOUT:4294967295},To={LOCKTIME:0,SEQUENCE:4294967295,VERSION:2},No=[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],Co={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},$o=[1,2,3,129,130,131],Ro=[0,...$o];var Bo=Object.freeze({__proto__:null,COINBASE:Io,DEFAULT:To,LOCK_SCRIPT_REGEX:Co,SCRIPT_INT_KEY:"",SIGHASH_DEFAULT:1,SIGHASH_SEGWIT:$o,SIGHASH_TAPROOT:Ro,TAPLEAF_DEFAULT_VERSION:192,TAPLEAF_VERSIONS:No,TX_SIZE:{GLOBAL_BASE:8,GLOBAL_WIT:10,TXIN_BASE:40,TXOUT_BASE:8}});const Uo=qr([Dr(si),si]),jo=Hr({pubkey:si,leaves:Uo.array().optional(),target:si.optional(),version:Gr.optional()});var Zo=Object.freeze({__proto__:null,config:jo,taptree:Uo});const zo=jr().min(0n).max(2100000000000000n),Lo=Hr({value:zo,script_pk:Yr}),Fo=Hr({coinbase:Yr.nullable(),txid:ni,vout:Gr,prevout:Lo.nullable(),script_sig:Yr.nullable(),sequence:Gr,witness:Dr(Yr)}),Do=Hr({version:Gr,vin:Dr(Fo),vout:Dr(Lo),locktime:Gr}),Ho=Lo.extend({value:qr([Gr,zo])}),qo=Fo.extend({coinbase:Yr.nullable().optional(),prevout:Ho.nullable().optional(),script_sig:Yr.nullable().optional(),sequence:qr([Yr,Gr]).optional(),witness:Dr(Yr).optional()}),Vo=Hr({version:Gr.optional(),vin:Dr(qo),vout:Dr(Ho),locktime:Gr.optional()});var Mo=Object.freeze({__proto__:null,tx_data:Do,tx_input:Fo,tx_output:Lo,tx_template:Vo,vin_template:qo,vout_template:Ho}),Ko=Object.freeze({__proto__:null,taproot:Zo,tx:Mo});function Wo(e){Vo.parse(e)}function Go(e){if(e.some(e=>null===e.prevout))throw new Error("transaction missing prevouts")}function Yo(e){Do.parse(e)}function Qo(e){qo.parse(e)}function Xo(e){Ho.parse(e)}function Jo(e,t=!0){Yo(e);const{version:n,vin:r,vout:i,locktime:s}=e,o=[ea(n)];if(t&&o.push(g.hex("0001")),o.push(ia(r)),o.push(aa(i)),t)for(const e of r)o.push(ca(e.witness));return o.push(da(s)),g.join(o)}function ea(e){return g.num(e,4).reverse()}function ta(e){return g.hex(e,32).reverse()}function na(e){return g.num(e,4).reverse()}function ra(e){return g.num(e,4).reverse()}function ia(e){const t=[g.varint(e.length,"le")];for(const n of e)t.push(sa(n));return g.join(t)}function sa(e){return null!==e.coinbase?g.join([ta(Io.TXID),na(Io.VOUT),fa(e.coinbase),ra(e.sequence)]):g.join([ta(e.txid),na(e.vout),fa(e.script_sig),ra(e.sequence)])}function oa(e){return g.big(e,8).reverse()}function aa(e){const t=[g.varint(e.length,"le")];for(const n of e)t.push(ua(n));return g.join(t)}function ua(e){const{value:t,script_pk:n}=e;return g.join([oa(t),fa(n)])}function ca(e){const t=[g.varint(e.length)];for(const n of e)t.push(fa(n));return g.join(t)}function da(e){return g.num(e,4).reverse()}function fa(e){return null!==e?(b.is_hex(e),g.hex(e).prefix_varint("le")):g.hex("00")}function la(e){for(const[t,n]of Object.entries(Co))if(n.test(e))return t;return"unknown"}function ha(e){switch(e.slice(0,4)){case"0014":return 0;case"5120":return 1;default:return null}}function pa(e){if(!w.exists(e))return To.SEQUENCE;if(w.is_hex(e))return g.hex(e,4).reverse().num;if(w.is_uint(e))return e;throw new Error("invalid sequence value: "+String(e))}function ma(e){if(w.is_uint(e))return BigInt(e);if("bigint"==typeof e)return e;throw new TypeError("invalid output value: "+String(e))}function ga(e){return{script_pk:e.script_pk,value:ma(e.value)}}function ya(e){Qo(e),b.exists(e.coinbase,"coinbase is required");const t=Io.TXID,n=Io.VOUT,r=e.coinbase,i=e.witness??[];return{coinbase:r,prevout:null,script_sig:null,sequence:pa(e.sequence),witness:i,txid:t,vout:n}}function _a(e){Qo(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:pa(e.sequence),witness:i}}function va(e){Qo(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:ga(e.prevout),script_sig:r,sequence:pa(e.sequence),witness:i}}function wa(e){return e.coinbase?ya(e):e.prevout?va(e):_a(e)}function ba(e){Xo(e);return{script_pk:e.script_pk,value:ma(e.value)}}function xa(e){Wo(e);const{vin:t=[],vout:n=[]}=e??{vin:[],vout:[]},r=e.locktime??To.LOCKTIME,i=e.version??To.VERSION;return{locktime:r,vin:t.map(e=>wa(e)),vout:n.map(e=>ba(e)),version:i}}function Ea(e,t=!0){b.is_bytes(e,"txdata must be hex or bytes");const n=new y(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),s=function(e){const t=[],n=e.varint();for(let r=0;r<n;r++){const n=ka(e);t.push(n)}return t}(n),o=function(e){const t=[],n=e.varint();for(let r=0;r<n;r++)try{t.push(Oa(e))}catch(e){throw new Error(`failed to decode output: ${r}: ${v(e)}`)}return t}(n);if(i)for(const e of s)e.witness=Sa(n);const a=function(e){return e.read(4).reverse().to_num()}(n);return{version:r,vin:s,vout:o,locktime:a}}function ka(e){const t=e.read(32).reverse().hex,n=e.read(4).reverse().num,r=Aa(e),i=e.read(4).reverse().num,s=[];return t===Io.TXID&&n===Io.VOUT?{coinbase:r,prevout:null,script_sig:null,sequence:i,txid:t,vout:n,witness:s}:{coinbase:null,prevout:null,script_sig:r,sequence:i,txid:t,vout:n,witness:s}}function Oa(e){const t=e.read(8).reverse().big,n=Aa(e);return b.exists(n,"failed to decode script_pk"),{value:t,script_pk:n}}function Sa(e){const t=[],n=e.varint();for(let r=0;r<n;r++){const n=Aa(e);if(null===n)throw new Error("failed to decode witness element: "+r);t.push(n)}return t}function Aa(e){const t=e.varint("le");return t>0?e.read(t).hex:null}function Pa(e,t){let n;if("string"==typeof e||e instanceof Uint8Array?n=Ea(e):(Wo(e),n=xa(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=ba(n)}}return n}var Ia=Object.freeze({__proto__:null,assert_has_prevouts:Go,assert_tx_data:Yo,assert_tx_input:function(e){Fo.parse(e)},assert_tx_output:function(e){Lo.parse(e)},assert_tx_spend_data:function(e){Yo(e),Go(e.vin)},assert_tx_template:Wo,assert_vin_template:Qo,assert_vout_template:Xo,create_coinbase_input:ya,create_spend_input:va,create_tx:xa,create_tx_input:wa,create_tx_output:ba,create_virtual_input:_a,decode_tx:Ea,encode_script_data:fa,encode_tx:Jo,encode_tx_inputs:ia,encode_tx_locktime:da,encode_tx_outputs:aa,encode_tx_version:ea,encode_tx_vout:ua,encode_txin_sequence:ra,encode_txin_txid:ta,encode_txin_vout:na,encode_vin:sa,encode_vin_witness:ca,encode_vout_value:oa,get_prevouts:function(e){Wo(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+ca(t).length,0)},get_tx_value:function(e){const t=e.vin.reduce((e,t)=>e+(t.prevout?.value??0n),0n),n=e.vout.reduce((e,t)=>e+t.value,0n);return{fees:t>n?t-n:0n,vin:t,vout:n}},get_txhash:function(e){return Wo(e),tn(Jo(e,!0)).reverse().hex},get_txid:function(e){return Wo(e),tn(Jo(e,!1)).reverse().hex},get_txin_size:function(e){return sa(e).length},get_txout_size:function(e){return ua(e).length},get_txsize:function(e){const t=Pa(e),n=Jo(t,!1).length,r=Jo(t,!0).length,i=3*n+r,s=i%4>0?1:0;return{base:n,total:r,vsize:Math.ceil(i/4)+s,weight:i}},get_vin_size:function(e){return ia(e).length},get_vout_info:function(e){return{type:la(e.script_pk),version:ha(e.script_pk)}},get_vout_size:function(e){return aa(e).length},get_vout_type:la,get_vout_version:ha,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 e.startsWith("6a")},normalize_prevout:ga,normalize_sequence:pa,normalize_value:ma,parse_tx:Pa,read_payload:Aa,serialize_tx:function(e){const t=Pa(e),n=t.version,r=t.locktime,i=[],s=[];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)s.push({script_pk:e.script_pk,value:Number(e.value)});return{version:n,locktime:r,vin:i,vout:s}}});function Ta(e,t={}){const{sigflag:n=1,txindex:r}=t,i=Pa(e),s=!(128&~n),o=n%128;if(!$o.includes(o))throw new Error("Invalid hash type: "+String(n));const{version:a,vin:u,vout:c,locktime:d}=i,f=Ao(i,t),{txid:l,vout:h,prevout:p,sequence:m}=f,{value:y}=p??{};if(void 0===y)throw new Error("Prevout value is empty!");let{pubkey:_,script:v}=t;if(void 0===v&&void 0!==_){const e=Jt(_).hex;v=`76a914${String(e)}88ac`}if(void 0===v)throw new Error("No pubkey / script has been set!");if(Qs(v).includes("OP_CODESEPARATOR"))throw new Error("This library does not currently support the use of OP_CODESEPARATOR in segwit scripts.");const w=[ea(a),Na(u,s),Ca(u,o,s),ta(l),na(h),Eo(v),oa(y),ra(m),$a(c,o,r),da(d),g.num(n,4).reverse()];return tn(g.join(w))}function Na(e,t){if(!0===t)return g.num(0,32);const n=[];for(const{txid:t,vout:r}of e)n.push(ta(t)),n.push(na(r));return tn(g.join(n))}function Ca(e,t,n){if(n||1!==t)return g.num(0,32);const r=[];for(const{sequence:t}of e)r.push(ra(t));return tn(g.join(r))}function $a(e,t,n){const r=[];if(1===t){for(const{value:t,script_pk:n}of e)r.push(oa(t)),r.push(Eo(n));return tn(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(oa(t)),r.push(Eo(i)),tn(g.join(r))}return g.num(0,32)}function Ra(e,t=192){return Ba(Eo(e),t)}function Ba(e,t=192){return nn("TapLeaf",ja(t),e)}function Ua(e,t){return t<e&&([e,t]=[t,e]),nn("TapBranch",e,t)}function ja(e=192){return 254&e}function Za(e,t=new Uint8Array){return b.size(e,32),nn("TapTweak",e,t)}function za(e,t={}){return nn("TapSighash",La(e,t))}function La(e,t={}){const{script:n,txindex:r,sigflag:i=0,extflag:s=0,key_version:o=0,separator_pos:a=4294967295}=t,u=Pa(e),{version:c,vin:d,vout:f,locktime:l}=u,h=Ao(u,t),{txid:p,vout:m,sequence:y,witness:_=[]}=h;if(!Ro.includes(i))throw new Error("Invalid hash type: "+String(i));if(s<0||s>127)throw new Error("Extention flag out of range: "+String(s));let{extension:v}=t;void 0!==n&&(v=Ra(n).hex);const w=!(128&~i),x=Po(_),E=2*(s+(void 0!==v?1:0))+(void 0!==x?1:0),k=[g.num(0,1),g.num(i,1),ea(c),da(l)];if(!w){const e=d.map(e=>So(e));k.push(Fa(d),Ha(e),qa(e),Da(d))}if(((3&i)<2||(3&i)>3)&&k.push(Va(f)),k.push(g.num(E,1)),w){const{value:e,script_pk:t}=So(h);k.push(ta(p),na(m),oa(e),fa(t),ra(y))}else b.ok("number"==typeof r),k.push(g.num(r,4).reverse());return void 0!==x&&k.push(x),3&~i||(b.ok("number"==typeof r),k.push(Ma(f[r]))),void 0!==v&&k.push(g.bytes(v),g.num(o),g.num(a,4,"le")),g.join(k)}function Fa(e){const t=[];for(const{txid:n,vout:r}of e)t.push(ta(n)),t.push(na(r));return en(g.join(t))}function Da(e){return en(...e.map(e=>ra(e.sequence)))}function Ha(e){return en(...e.map(e=>oa(e.value)))}function qa(e){return en(...e.map(e=>fa(e.script_pk)))}function Va(e){const t=[];for(const{value:n,script_pk:r}of e)t.push(oa(n)),t.push(fa(r));return en(...t)}function Ma(e){return en(oa(e.value),fa(e.script_pk))}var Ka=Object.freeze({__proto__:null,bip143_hash_outputs:$a,bip143_hash_prevouts:Na,bip143_hash_sequence:Ca,bip341_hash_amounts:Ha,bip341_hash_outpoints:Fa,bip341_hash_output:Ma,bip341_hash_outputs:Va,bip341_hash_scripts:qa,bip341_hash_sequence:Da,get_annex_data:Po,get_prevout:So,get_taproot_tx_preimage:La,hash_segwit_tx:Ta,hash_taproot_tx:za,parse_txinput:Ao});function Wa(e){return 0!==e?g.num(e,1).hex:""}var Ga=Object.freeze({__proto__:null,sign_segwit_tx:function(e,t,n){return function(e,t){const n=jt(t),r=yt.sign(n,e).toDERRawBytes();return g.bytes(r)}(e,Ta(Pa(t),n)).hex+Wa(n.sigflag??1)},sign_taproot_tx:function(e,t,n){return function(e,t){const n=jt(t);return jt($t.sign(n,e))}(e,za(Pa(t),n)).hex+Wa(n.sigflag??0)},verify_tx:function(e,t={}){return console.warn("verify_segwit_tx is not implemented"),!0}});function Ya(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 s=e[i];if(Array.isArray(s)){let[e,i,o]=Ya(s,t);t=i,r.push(e);for(const e of o)n.push(e)}else{const e=g.bytes(s).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 s=Ua(r[e],r[e+1]).hex;i.push(s),"string"==typeof t&&(t===r[e]?(n.push(r[e+1]),t=s):t===r[e+1]&&(n.push(r[e]),t=s))}return Ya(i,t,n)}function Qa(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&&No.includes(254&t[0])?new g(t).hex:null}(t);null!==i&&t.pop();const s=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&&Xs(i)?"p2w-sh":"unknown"}(t,i),o=function(e){return e.startsWith("p2tr")?1:e.startsWith("p2w")?0:null}(s),a=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,s);null!==a&&t.pop();return{annex:r,cblock:i,params:t.map(e=>e.hex),script:a,stack:n,type:s,version:o}}function Xa(e){const t=new y(e),n=t.read(1).num,r=t.read(32).hex,[i,s]=Ja(n),o=[];for(;t.size>=32;)o.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:o,parity:s,version:i}}function Ja(e){return e%2==0?[e-0,2]:[e-1,3]}function eu(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 tu=192;var nu=Object.freeze({__proto__:null,create_taproot:function(e){jo.parse(e);const{pubkey:t,version:n=tu}=e,r=e.leaves??[],i=void 0!==e.target?g.bytes(e.target).hex:void 0;let s,o=[];if(r.length>0){const[e,t,n]=Ya(r,i);o=n,s=e}else s=i;const a=Za(t,s),u=Bt(t,a,"ecdsa"),c=eu(u),d=Ut(u,"bip340"),f=[g.num(n+c),g.bytes(t)];o.length>0&&o.forEach(e=>f.push(e));const l=g.join(f);return{int_key:g.bytes(t).hex,path:o,parity:c,taproot:s??null,cblock:l.hex,tapkey:d.hex,taptweak:a.hex}},encode_leaf_version:ja,encode_tapbranch:Ua,encode_tapleaf:Ba,encode_tapscript:Ra,encode_taptweak:Za,get_merkle_root:function(e){return Ya(e)[0]},merkleize:Ya,parse_cblock:Xa,parse_cblock_parity:Ja,parse_pubkey_parity:eu,parse_taproot_witness:function(e){const{cblock:t,params:n,script:r}=Qa(e);b.exists(t,"cblock is null"),b.exists(r,"script is null");const i=Xa(t);let s=Ra(r,i.version).hex;for(const e of i.path)s=Ua(s,e).hex;const o=Za(i.int_key,s),a=Bt(i.int_key,o,"bip340");return n.map(e=>g.bytes(e).hex),{cblock:i,params:n,script:r,tapkey:a.hex,tweak:o.hex}},verify_taproot:function(e,t,n){b.size(e,32);const{parity:r,path:i,int_key:s}=Xa(n),o=g.join([r,e]);let a=g.bytes(t).hex;for(const e of i)a=Ua(a,e).hex;const u=Bt(s,Za(s,a),"ecdsa");return o.hex===u.hex}});var ru=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:Qa});return e.ADDRESS=xs,e.CONST=Bo,e.META=xo,e.SCHEMA=Ko,e.SCRIPT=Oo,e.SIGHASH=Ka,e.SIGNER=Ga,e.TAPROOT=nu,e.TX=Ia,e.WITNESS=ru,e}({});
15
15
  //# sourceMappingURL=script.js.map