@vbyte/btc-dev 2.0.0 → 2.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/CHANGELOG.md +33 -0
- package/LICENSE +21 -121
- package/README.md +36 -227
- package/dist/error.d.ts +11 -0
- package/dist/error.js +20 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/lib/address/api.js +3 -2
- package/dist/lib/address/encode.js +6 -4
- package/dist/lib/address/p2pkh.js +4 -4
- package/dist/lib/address/p2sh.js +3 -3
- package/dist/lib/address/p2tr.js +3 -3
- package/dist/lib/address/p2wpkh.js +4 -4
- package/dist/lib/address/p2wsh.js +3 -3
- package/dist/lib/address/util.js +3 -1
- package/dist/lib/meta/locktime.js +3 -2
- package/dist/lib/meta/ref.js +4 -3
- package/dist/lib/meta/scribe.js +26 -6
- package/dist/lib/meta/sequence.js +8 -7
- package/dist/lib/script/decode.js +10 -9
- package/dist/lib/script/encode.js +4 -3
- package/dist/lib/script/words.js +4 -3
- package/dist/lib/sighash/segwit.js +9 -6
- package/dist/lib/sighash/taproot.js +7 -4
- package/dist/lib/sighash/util.js +4 -3
- package/dist/lib/signer/sign.js +7 -6
- package/dist/lib/signer/verify.js +8 -9
- package/dist/lib/taproot/cblock.js +3 -2
- package/dist/lib/taproot/encode.d.ts +1 -1
- package/dist/lib/taproot/encode.js +4 -3
- package/dist/lib/taproot/parse.js +9 -7
- package/dist/lib/taproot/tree.js +3 -2
- package/dist/lib/tx/create.js +1 -1
- package/dist/lib/tx/decode.js +13 -11
- package/dist/lib/tx/encode.js +1 -1
- package/dist/lib/tx/parse.js +3 -3
- package/dist/lib/tx/size.js +2 -4
- package/dist/lib/tx/util.js +2 -3
- package/dist/lib/tx/validate.js +36 -8
- package/dist/lib/witness/util.js +1 -1
- package/dist/main.cjs +1127 -1160
- package/dist/main.cjs.map +1 -1
- package/dist/module.mjs +1125 -1161
- package/dist/module.mjs.map +1 -1
- package/dist/package.json +13 -11
- package/dist/script.js +10 -12
- package/dist/script.js.map +1 -1
- package/docs/API.md +1145 -0
- package/docs/CONVENTIONS.md +316 -0
- package/docs/FAQ.md +396 -0
- package/docs/GUIDE.md +1102 -0
- package/package.json +13 -11
package/dist/script.js
CHANGED
|
@@ -1,13 +1,11 @@
|
|
|
1
|
-
var btc_dev=function(e){"use strict";const t={TXID:"00".repeat(32),VOUT:4294967295},n={LOCKTIME:0,SEQUENCE:4294967295,VERSION:2},r=[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],o={P2PKH:"p2pkh",P2SH:"p2sh",P2WPKH:"p2wpkh",P2WSH:"p2wsh",P2TR:"p2tr",OPRETURN:"opreturn"},i={[o.P2PKH]:/^76a914[0-9a-f]{40}88ac$/i,[o.P2SH]:/^a914[0-9a-f]{40}87$/i,[o.P2WPKH]:/^0014[0-9a-f]{40}$/i,[o.P2WSH]:/^0020[0-9a-f]{64}$/i,[o.P2TR]:/^5120[0-9a-f]{64}$/i,[o.OPRETURN]:/^6a[0-9a-f]{2,}$/i},s=[1,2,3,129,130,131],a=[0,...s],c=1e4,u=52e4;var f,d,l=Object.freeze({__proto__:null,COINBASE:t,DEFAULT:n,LOCK_SCRIPT_REGEX:i,LOCK_SCRIPT_TYPE:o,MAX_SCRIPT_SIZE:c,MAX_VARINT_SIZE:u,OP_1_OFFSET:80,SCRIPT_INT_KEY:"",SIGHASH_DEFAULT:1,SIGHASH_SEGWIT:s,SIGHASH_TAPROOT:a,SPEND_SCRIPT_TYPE:{P2PKH:"p2pkh",P2SH:"p2sh",P2WPKH:"p2wpkh",P2WSH:"p2wsh",P2TR:"p2tr",P2TS:"p2ts"},TAPLEAF_DEFAULT_VERSION:192,TAPLEAF_VERSIONS:r,TX_SIZE:{GLOBAL_BASE:8,GLOBAL_WIT:10,TXIN_BASE:40,TXOUT_BASE:8}});!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)))}}(f||(f={})),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(!f.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!")}}(d||(d={}));const p=BigInt(0),h=BigInt(255),m=BigInt(256);function g(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 r="le"===n,o=new ArrayBuffer(t),i=new DataView(o);let s=r?0:t-1;for(;e>p;){const t=e&h,n=Number(t);r?i.setUint8(s++,n):i.setUint8(s--,n),e=(e-t)/m}return new Uint8Array(o)}function y(e,t){return"bigint"==typeof t?`${t}n`:t}function _(e,t){return"string"==typeof t&&/^[0-9]+n$/.test(t)?BigInt(t.slice(0,-1)):t}function w(e,t,n="be"){void 0===t&&(t=function(e){if(e<0)throw new TypeError("Number must be non-negative");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,o=new ArrayBuffer(t),i=new DataView(o);let s=r?0:t-1;for(;e>0;){const t=255&e;r?i.setUint8(s++,t):i.setUint8(s--,t),e=(e-t)/256}return new Uint8Array(o)}function v(e,t,n="be"){t=function(e,t){d.is_hex(e);const n=e.length/2;void 0===t&&(t=n);if(n>t)throw new TypeError(`Hex string is larger than array size: ${n} > ${t}`);return t}(e,t);const r="be"===n,o=new ArrayBuffer(t),i=new DataView(o);let s=r?0:t-1;for(let t=0;t<e.length;t+=2){const n=e.substring(t,t+2),o=parseInt(n,16);r?i.setUint8(s++,o):i.setUint8(s--,o)}return new Uint8Array(o)}function b(e,t,n){if(e instanceof ArrayBuffer)return new Uint8Array(e);if(e instanceof Uint8Array)return function(e,t,n="le"){void 0===t&&(t=e.length);d.within_size(e,t);const r=new Uint8Array(t).fill(0),o="be"===n?0:t-e.length;return r.set(e,o),r}(e,t,n);if("string"==typeof e)return d.is_hex(e),v(e,t,n);if("bigint"==typeof e)return g(e,t,n);if("number"==typeof e)return w(e,t,n);throw new TypeError("Input type not supported: "+typeof e)}const E=new TextEncoder,x=new TextDecoder;function z(e){return E.encode(e)}function O(e){return x.decode(e)}class k extends Uint8Array{static{this.num=(e,t,n)=>new k(e,t,n)}static{this.big=(e,t,n)=>new k(e,t,n)}static{this.bin=(e,t,n)=>{const r=function(e){if(!/^[01]*$/.test(e))throw new TypeError("Binary string must contain only 0 and 1 characters");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 o=0;for(let n=0;n<8;n++)o|=t[e+n]<<7-n;n[r]=o}return n}(e);return new k(r,t,n)}}static{this.u8a=(e,t,n)=>new k(e,t,n)}static{this.str=(e,t,n)=>{const r=z(e);return new k(r,t,n)}}static{this.hex=(e,t,n)=>(d.is_hex(e),new k(e,t,n))}static{this.bytes=(e,t,n)=>(d.is_bytes(e),new k(e,t,n))}static{this.json=(e,t)=>{t=t??y;const n=z(JSON.stringify(e,t));return new k(n)}}static{this.chunk=(e,t,n)=>{const r=function(e,t,n){const r=e.length,o=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 i=new Array(o);for(let n=0;n<o;n++){const r=n*t;i[n]=e.subarray(r,r+t)}return i}(b(e),t,n);return r.map(e=>new k(e))}}static{this.is_equal=(e,t)=>new k(e).hex===new k(t).hex}static{this.is_bytes=f.is_bytes}static{this.is_hex=f.is_hex}static random(e=32){const t=function(e=32){if(!Number.isInteger(e)||e<0)throw new TypeError("Length must be a non-negative integer");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 k(t,e)}static now(){const e=Math.floor(Date.now()/1e3);return new k(e,4)}constructor(e,t,n){super(b(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 u8a(){return this.to_u8a()}to_big(e="be"){return function(e){let t=BigInt(0);for(let n=e.length-1;n>=0;n--)t=t*m+BigInt(e[n]);return BigInt(t)}("be"===e?this.u8a.reverse():this.u8a)}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.u8a:this.u8a.reverse())}to_json(e){void 0===e&&(e=_);const t=O(this);return JSON.parse(t,e)}to_num(e="be"){return function(e){let t=0;for(let n=e.length-1;n>=0;n--)t=256*t+e[n],d.is_safe_int(t);return t}("be"===e?this.u8a.reverse():this.u8a)}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 O(this)}to_u8a(){return new Uint8Array(this)}append(e){return k.join([this,new k(e)])}equals(e){return new k(e).hex===this.hex}prepend(e){return k.join([new k(e),this])}prefix_varint(e){if(0===this.length)throw new Error("buffer is empty");const t=k.create_varint(this.length,e);return this.prepend(t)}reverse(){return super.reverse(),this}set(e,t){super.set(e,t)}slice(e,t){const n=new Uint8Array(this).slice(e,t);return new k(n)}subarray(e,t){const n=new Uint8Array(this).subarray(e,t);return new k(n)}toJSON(){return this.hex}toString(){return this.hex}static from(e){return new k(Uint8Array.from(e))}static of(...e){return new k(Uint8Array.of(...e))}static join(e){const t=function(e){let t,n=0;const r=e.reduce((e,t)=>e+t.length,0),o=new Uint8Array(r);for(t=0;t<e.length;t++){const r=e[t];o.set(r,n),n+=r.length}return o}(e.map(e=>new k(e)));return new k(t)}static sort(e,t){const n=e.map(e=>new k(e,t).hex);return n.sort(),n.map(e=>k.hex(e,t))}static create_varint(e,t){if(e<253)return k.num(e,1);if(e<65536)return k.of(253,...k.num(e,2,t));if(e<4294967296)return k.of(254,...k.num(e,4,t));if(BigInt(e)<0x10000000000000000n)return k.of(255,...k.num(e,8,t));throw new Error(`Value is too large: ${e}`)}}class S{constructor(e){this.data=new k(e),this.size=this.data.length}peek(e){if(e>this.size)throw new Error(`Size greater than stream: ${e} > ${this.size}`);return new k(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}read_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 P(e){const t=k.bytes(e).hex;for(const[e,n]of Object.entries(i))if(n.test(t))return e;return null}function $(e){switch(k.bytes(e).at(0)){case 0:return 0;case 81:return 1;default:return null}}function A(e){const t=k.bytes(e).hex;return i.p2pkh.test(t)}function I(e){const t=k.bytes(e).hex;return i.p2sh.test(t)}function T(e){const t=k.bytes(e).hex;return i.p2wpkh.test(t)}function N(e){const t=k.bytes(e).hex;return i.p2wsh.test(t)}function B(e){const t=k.bytes(e).hex;return i.p2tr.test(t)}function U(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),{})}var R,j;!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 o(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=U(e)),t(n)&&(n=U(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 k.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=o,e.is_hash=function(e){return n(e)&&o(e)&&64===e.length}}(R||(R={})),function(e){e.ok=function(e,t){if(!1===e)throw new Error(t??"Assertion failed!")},e.exists=function(e,t){if(!R.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(!R.is_equal(e,t))throw new Error(n??`values are not equal: ${String(e)} !== ${String(t)}`)},e.is_object=function(e,t){if(!R.is_object(e))throw new Error(t??`value is not an object: ${String(e)}`)},e.is_deep_equal=function(e,t,n){if(!R.is_deep_equal(e,t))throw new Error(n??`values are not deep equal: ${String(e)} !== ${String(t)}`)},e.is_number=function(e){if(!R.is_number(e))throw new TypeError(`invalid number: ${String(e)}`)},e.is_bigint=function(e){if(!R.is_bigint(e))throw new TypeError(`invalid bigint: ${String(e)}`)},e.is_hex=function(e){if(!R.is_hex(e))throw new TypeError(`invalid hex: ${String(e)}`)},e.is_uchar=function(e){if(!R.is_uchar(e))throw new TypeError(`invalid unsignedchar: ${String(e)}`)},e.is_ushort=function(e){if(!R.is_ushort(e))throw new TypeError(`invalid unsigned short: ${String(e)}`)},e.is_uint=function(e){if(!R.is_uint(e))throw new TypeError(`invalid unsigned int: ${String(e)}`)},e.is_u8a=function(e){if(!R.is_u8a(e))throw new TypeError(`invalid Uint8Array: ${String(e)}`)},e.is_hash=function(e,t){if(!R.is_hash(e))throw new TypeError(t??`invalid hash: ${String(e)}`)},e.is_bytes=function(e,t){if(!R.is_bytes(e))throw new TypeError(t??`invalid bytes: ${String(e)}`)},e.size=function(e,t,n){const r=k.bytes(e);if(r.length!==t)throw new Error(n??`invalid input size: ${r.length} !== ${t}`)},e.has_items=function(e,t){if(!R.has_items(e))throw new Error(t??"array does not contain any items")},e.is_base58=function(e){if(!R.is_base58(e))throw new Error("invalid base58 string")},e.is_base64=function(e){if(!R.is_base64(e))throw new Error("invalid base64 string")},e.is_b64url=function(e){if(!R.is_b64url(e))throw new Error("invalid base64url string")},e.is_bech32=function(e){if(!R.is_bech32(e))throw new Error("invalid bech32 string")}}(j||(j={}));const Z="object"==typeof globalThis&&"crypto"in globalThis?globalThis.crypto:void 0;
|
|
2
|
-
/*! noble-hashes - MIT License (c) 2022 Paul Miller (paulmillr.com) */
|
|
3
|
-
/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */const
|
|
7
|
-
/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */
|
|
8
|
-
const zt=(e,t)=>(e+(e>=0?t:-t)/It)/t;function Ot(e){if(!["compact","recovered","der"].includes(e))throw new Error('Signature format must be "compact", "recovered", or "der"');return e}function kt(e,t){const n={};for(let r of Object.keys(t))n[r]=void 0===e[r]?t[r]:e[r];return xe(n.lowS,"lowS"),xe(n.prehash,"prehash"),void 0!==n.format&&Ot(n.format),n}class St extends Error{constructor(e=""){super(e)}}const Pt={Err:St,_tlv:{encode:(e,t)=>{const{Err:n}=Pt;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,o=Oe(r);if(o.length/2&128)throw new n("tlv.encode: long form length too big");const i=r>127?Oe(o.length/2|128):"";return Oe(e)+i+o+t},decode(e,t){const{Err:n}=Pt;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 o=t[r++];let i=0;if(!!(128&o)){const e=127&o;if(!e)throw new n("tlv.decode(long): indefinite length not supported");if(e>4)throw new n("tlv.decode(long): byte length is too big");const s=t.subarray(r,r+e);if(s.length!==e)throw new n("tlv.decode: length bytes not complete");if(0===s[0])throw new n("tlv.decode(long): zero leftmost byte");for(const e of s)i=i<<8|e;if(r+=e,i<128)throw new n("tlv.decode(long): not minimal encoding")}else i=o;const s=t.subarray(r,r+i);if(s.length!==i)throw new n("tlv.decode: wrong value length");return{v:s,l:t.subarray(r+i)}}},_int:{encode(e){const{Err:t}=Pt;if(e<$t)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}=Pt;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 Se(e)}},toSig(e){const{Err:t,_int:n,_tlv:r}=Pt,o=Ie("signature",e),{v:i,l:s}=r.decode(48,o);if(s.length)throw new t("invalid signature: left bytes after parsing");const{v:a,l:c}=r.decode(2,i),{v:u,l:f}=r.decode(2,c);if(f.length)throw new t("invalid signature: left bytes after parsing");return{r:n.decode(a),s:n.decode(u)}},hexFromSig(e){const{_tlv:t,_int:n}=Pt,r=t.encode(2,n.encode(e.r))+t.encode(2,n.encode(e.s));return t.encode(48,r)}},$t=BigInt(0),At=BigInt(1),It=BigInt(2),Tt=BigInt(3),Nt=BigInt(4);function Bt(e,t){const{BYTES:n}=e;let r;if("bigint"==typeof t)r=t;else{let o=Ie("private key",t);try{r=e.fromBytes(o)}catch(e){throw new Error(`invalid private key: expected ui8a of size ${n}, got ${typeof t}`)}}if(!e.isValidNot0(r))throw new Error("invalid private key: out of range [1..N-1]");return r}function Ut(e,t={}){const n=function(e,t,n={},r){if(void 0===r&&(r="edwards"===e),!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>ft))throw new Error(`CURVE.${e} must be positive bigint`)}const o=xt(t.p,n.Fp,r),i=xt(t.n,n.Fn,r),s=["Gx","Gy","a","b"];for(const e of s)if(!o.isValid(t[e]))throw new Error(`CURVE.${e} must be valid field element of CURVE.Fp`);return{CURVE:t=Object.freeze(Object.assign({},t)),Fp:o,Fn:i}}("weierstrass",e,t),{Fp:r,Fn:o}=n;let i=n.CURVE;const{h:s,n:a}=i;Re(t,{},{allowInfinityPoint:"boolean",clearCofactor:"function",isTorsionFree:"function",fromBytes:"function",toBytes:"function",endo:"object",wrapPrivateKey:"boolean"});const{endo:c}=t;if(c&&(!r.is0(i.a)||"bigint"!=typeof c.beta||!Array.isArray(c.basises)))throw new Error('invalid endo: expected "beta": bigint and "basises": array');const u=jt(r,o);function f(){if(!r.isOdd)throw new Error("compression is not supported: Field does not have .isOdd()")}const d=t.toBytes||function(e,t,n){const{x:o,y:i}=t.toAffine(),s=r.toBytes(o);if(xe(n,"isCompressed"),n){f();return ae(Rt(!r.isOdd(i)),s)}return ae(Uint8Array.of(4),s,r.toBytes(i))},l=t.fromBytes||function(e){ze(e,void 0,"Point");const{publicKey:t,publicKeyUncompressed:n}=u,o=e.length,i=e[0],s=e.subarray(1);if(o!==t||2!==i&&3!==i){if(o===n&&4===i){const e=r.BYTES,t=r.fromBytes(s.subarray(0,e)),n=r.fromBytes(s.subarray(e,2*e));if(!h(t,n))throw new Error("bad point: is not on curve");return{x:t,y:n}}throw new Error(`bad point: got length ${o}, expected compressed=${t} or uncompressed=${n}`)}{const e=r.fromBytes(s);if(!r.isValid(e))throw new Error("bad point: is not on curve, wrong x");const t=p(e);let n;try{n=r.sqrt(t)}catch(e){const t=e instanceof Error?": "+e.message:"";throw new Error("bad point: is not on curve, sqrt error"+t)}f();return!(1&~i)!==r.isOdd(n)&&(n=r.neg(n)),{x:e,y:n}}};function p(e){const t=r.sqr(e),n=r.mul(t,e);return r.add(r.add(n,r.mul(e,i.a)),i.b)}function h(e,t){const n=r.sqr(t),o=p(e);return r.eql(n,o)}if(!h(i.Gx,i.Gy))throw new Error("bad curve params: generator point");const m=r.mul(r.pow(i.a,Tt),Nt),g=r.mul(r.sqr(i.b),BigInt(27));if(r.is0(r.add(m,g)))throw new Error("bad curve params: a or b");function y(e,t,n=!1){if(!r.isValid(t)||n&&r.is0(t))throw new Error(`bad point coordinate ${e}`);return t}function _(e){if(!(e instanceof x))throw new Error("ProjectivePoint expected")}function w(e){if(!c||!c.basises)throw new Error("no endo");return function(e,t,n){const[[r,o],[i,s]]=t,a=zt(s*e,n),c=zt(-o*e,n);let u=e-a*r-c*i,f=-a*o-c*s;const d=u<$t,l=f<$t;d&&(u=-u),l&&(f=-f);const p=Ue(Math.ceil(Be(n)/2))+At;if(u<$t||u>=p||f<$t||f>=p)throw new Error("splitScalar (endomorphism): failed, k="+e);return{k1neg:d,k1:u,k2neg:l,k2:f}}(e,c.basises,o.ORDER)}const v=je((e,t)=>{const{X:n,Y:o,Z:i}=e;if(r.eql(i,r.ONE))return{x:n,y:o};const s=e.is0();null==t&&(t=s?r.ONE:r.inv(i));const a=r.mul(n,t),c=r.mul(o,t),u=r.mul(i,t);if(s)return{x:r.ZERO,y:r.ZERO};if(!r.eql(u,r.ONE))throw new Error("invZ was invalid");return{x:a,y:c}}),b=je(e=>{if(e.is0()){if(t.allowInfinityPoint&&!r.is0(e.Y))return;throw new Error("bad point: ZERO")}const{x:n,y:o}=e.toAffine();if(!r.isValid(n)||!r.isValid(o))throw new Error("bad point: x or y not field elements");if(!h(n,o))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(e,t,n,o,i){return n=new x(r.mul(n.X,e),n.Y,n.Z),t=lt(o,t),n=lt(i,n),t.add(n)}class x{constructor(e,t,n){this.X=y("x",e),this.Y=y("y",t,!0),this.Z=y("z",n),Object.freeze(this)}static CURVE(){return i}static fromAffine(e){const{x:t,y:n}=e||{};if(!e||!r.isValid(t)||!r.isValid(n))throw new Error("invalid affine point");if(e instanceof x)throw new Error("projective point not allowed");return r.is0(t)&&r.is0(n)?x.ZERO:new x(t,n,r.ONE)}static fromBytes(e){const t=x.fromAffine(l(ze(e,void 0,"point")));return t.assertValidity(),t}static fromHex(e){return x.fromBytes(Ie("pointHex",e))}get x(){return this.toAffine().x}get y(){return this.toAffine().y}precompute(e=8,t=!0){return O.createCache(this,e),t||this.multiply(Tt),this}assertValidity(){b(this)}hasEvenY(){const{y:e}=this.toAffine();if(!r.isOdd)throw new Error("Field doesn't support isOdd");return!r.isOdd(e)}equals(e){_(e);const{X:t,Y:n,Z:o}=this,{X:i,Y:s,Z:a}=e,c=r.eql(r.mul(t,a),r.mul(i,o)),u=r.eql(r.mul(n,a),r.mul(s,o));return c&&u}negate(){return new x(this.X,r.neg(this.Y),this.Z)}double(){const{a:e,b:t}=i,n=r.mul(t,Tt),{X:o,Y:s,Z:a}=this;let c=r.ZERO,u=r.ZERO,f=r.ZERO,d=r.mul(o,o),l=r.mul(s,s),p=r.mul(a,a),h=r.mul(o,s);return h=r.add(h,h),f=r.mul(o,a),f=r.add(f,f),c=r.mul(e,f),u=r.mul(n,p),u=r.add(c,u),c=r.sub(l,u),u=r.add(l,u),u=r.mul(c,u),c=r.mul(h,c),f=r.mul(n,f),p=r.mul(e,p),h=r.sub(d,p),h=r.mul(e,h),h=r.add(h,f),f=r.add(d,d),d=r.add(f,d),d=r.add(d,p),d=r.mul(d,h),u=r.add(u,d),p=r.mul(s,a),p=r.add(p,p),d=r.mul(p,h),c=r.sub(c,d),f=r.mul(p,l),f=r.add(f,f),f=r.add(f,f),new x(c,u,f)}add(e){_(e);const{X:t,Y:n,Z:o}=this,{X:s,Y:a,Z:c}=e;let u=r.ZERO,f=r.ZERO,d=r.ZERO;const l=i.a,p=r.mul(i.b,Tt);let h=r.mul(t,s),m=r.mul(n,a),g=r.mul(o,c),y=r.add(t,n),w=r.add(s,a);y=r.mul(y,w),w=r.add(h,m),y=r.sub(y,w),w=r.add(t,o);let v=r.add(s,c);return w=r.mul(w,v),v=r.add(h,g),w=r.sub(w,v),v=r.add(n,o),u=r.add(a,c),v=r.mul(v,u),u=r.add(m,g),v=r.sub(v,u),d=r.mul(l,w),u=r.mul(p,g),d=r.add(u,d),u=r.sub(m,d),d=r.add(m,d),f=r.mul(u,d),m=r.add(h,h),m=r.add(m,h),g=r.mul(l,g),w=r.mul(p,w),m=r.add(m,g),g=r.sub(h,g),g=r.mul(l,g),w=r.add(w,g),h=r.mul(m,w),f=r.add(f,h),h=r.mul(v,w),u=r.mul(y,u),u=r.sub(u,h),h=r.mul(y,m),d=r.mul(v,d),d=r.add(d,h),new x(u,f,d)}subtract(e){return this.add(e.negate())}is0(){return this.equals(x.ZERO)}multiply(e){const{endo:n}=t;if(!o.isValidNot0(e))throw new Error("invalid scalar: out of range");let r,i;const s=e=>O.cached(this,e,e=>pt(x,e));if(n){const{k1neg:t,k1:o,k2neg:a,k2:c}=w(e),{p:u,f:f}=s(o),{p:d,f:l}=s(c);i=f.add(l),r=E(n.beta,u,d,t,a)}else{const{p:t,f:n}=s(e);r=t,i=n}return pt(x,[r,i])[0]}multiplyUnsafe(e){const{endo:n}=t,r=this;if(!o.isValid(e))throw new Error("invalid scalar: out of range");if(e===$t||r.is0())return x.ZERO;if(e===At)return r;if(O.hasCache(this))return this.multiply(e);if(n){const{k1neg:t,k1:o,k2neg:i,k2:s}=w(e),{p1:a,p2:c}=function(e,t,n,r){let o=t,i=e.ZERO,s=e.ZERO;for(;n>ft||r>ft;)n&dt&&(i=i.add(o)),r&dt&&(s=s.add(o)),o=o.double(),n>>=dt,r>>=dt;return{p1:i,p2:s}}(x,r,o,s);return E(n.beta,a,c,t,i)}return O.unsafe(r,e)}multiplyAndAddUnsafe(e,t,n){const r=this.multiplyUnsafe(t).add(e.multiplyUnsafe(n));return r.is0()?void 0:r}toAffine(e){return v(this,e)}isTorsionFree(){const{isTorsionFree:e}=t;return s===At||(e?e(x,this):O.unsafe(this,a).is0())}clearCofactor(){const{clearCofactor:e}=t;return s===At?this:e?e(x,this):this.multiplyUnsafe(s)}isSmallOrder(){return this.multiplyUnsafe(s).is0()}toBytes(e=!0){return xe(e,"isCompressed"),this.assertValidity(),d(x,this,e)}toHex(e=!0){return G(this.toBytes(e))}toString(){return`<Point ${this.is0()?"ZERO":this.toHex()}>`}get px(){return this.X}get py(){return this.X}get pz(){return this.Z}toRawBytes(e=!0){return this.toBytes(e)}_setWindowSize(e){this.precompute(e)}static normalizeZ(e){return pt(x,e)}static msm(e,t){return Et(x,o,e,t)}static fromPrivateKey(e){return x.BASE.multiply(Bt(o,e))}}x.BASE=new x(i.Gx,i.Gy,r.ONE),x.ZERO=new x(r.ZERO,r.ONE,r.ZERO),x.Fp=r,x.Fn=o;const z=o.BITS,O=new bt(x,t.endo?Math.ceil(z/2):z);return x.BASE.precompute(8),x}function Rt(e){return Uint8Array.of(e?2:3)}function jt(e,t){return{secretKey:t.BYTES,publicKey:1+e.BYTES,publicKeyUncompressed:1+2*e.BYTES,publicKeyHasPrefix:!0,signature:2*t.BYTES}}function Zt(e,t,n={}){D(t),Re(n,{},{hmac:"function",lowS:"boolean",randomBytes:"function",bits2int:"function",bits2int_modN:"function"});const r=n.randomBytes||fe,o=n.hmac||((e,...n)=>ve(t,e,ae(...n))),{Fp:i,Fn:s}=e,{ORDER:a,BITS:c}=s,{keygen:u,getPublicKey:f,getSharedSecret:d,utils:l,lengths:p}=function(e,t={}){const{Fn:n}=e,r=t.randomBytes||fe,o=Object.assign(jt(e.Fp,n),{seed:ct(n.ORDER)});function i(e){try{return!!Bt(n,e)}catch(e){return!1}}function s(e=r(o.seed)){return ut(ze(e,o.seed,"seed"),n.ORDER)}function a(t,r=!0){return e.BASE.multiply(Bt(n,t)).toBytes(r)}function c(t){if("bigint"==typeof t)return!1;if(t instanceof e)return!0;const{secretKey:r,publicKey:i,publicKeyUncompressed:s}=o;if(n.allowedLengths||r===i)return;const a=Ie("key",t).length;return a===i||a===s}const u={isValidSecretKey:i,isValidPublicKey:function(t,n){const{publicKey:r,publicKeyUncompressed:i}=o;try{const o=t.length;return!(!0===n&&o!==r||!1===n&&o!==i||!e.fromBytes(t))}catch(e){return!1}},randomSecretKey:s,isValidPrivateKey:i,randomPrivateKey:s,normPrivateKeyToScalar:e=>Bt(n,e),precompute:(t=8,n=e.BASE)=>n.precompute(t,!1)};return Object.freeze({getPublicKey:a,getSharedSecret:function(t,r,o=!0){if(!0===c(t))throw new Error("first arg must be private key");if(!1===c(r))throw new Error("second arg must be public key");const i=Bt(n,t);return e.fromHex(r).multiply(i).toBytes(o)},keygen:function(e){const t=s(e);return{secretKey:t,publicKey:a(t)}},Point:e,utils:u,lengths:o})}(e,n),h={prehash:!1,lowS:"boolean"==typeof n.lowS&&n.lowS,format:void 0,extraEntropy:!1},m="compact";function g(e){return e>a>>At}function y(e,t){if(!s.isValidNot0(t))throw new Error(`invalid signature ${e}: out of range 1..Point.Fn.ORDER`);return t}class _{constructor(e,t,n){this.r=y("r",e),this.s=y("s",t),null!=n&&(this.recovery=n),Object.freeze(this)}static fromBytes(e,t=m){let n;if(function(e,t){Ot(t);const n=p.signature;ze(e,"compact"===t?n:"recovered"===t?n+1:void 0,`${t} signature`)}(e,t),"der"===t){const{r:t,s:n}=Pt.toSig(ze(e));return new _(t,n)}"recovered"===t&&(n=e[0],t="compact",e=e.subarray(1));const r=s.BYTES,o=e.subarray(0,r),i=e.subarray(r,2*r);return new _(s.fromBytes(o),s.fromBytes(i),n)}static fromHex(e,t){return this.fromBytes(oe(e),t)}addRecoveryBit(e){return new _(this.r,this.s,e)}recoverPublicKey(t){const n=i.ORDER,{r:r,s:o,recovery:c}=this;if(null==c||![0,1,2,3].includes(c))throw new Error("recovery id invalid");if(a*It<n&&c>1)throw new Error("recovery id is ambiguous for h>1 curve");const u=2===c||3===c?r+a:r;if(!i.isValid(u))throw new Error("recovery id 2 or 3 invalid");const f=i.toBytes(u),d=e.fromBytes(ae(Rt(!(1&c)),f)),l=s.inv(u),p=v(Ie("msgHash",t)),h=s.create(-p*l),m=s.create(o*l),g=e.BASE.multiplyUnsafe(h).add(d.multiplyUnsafe(m));if(g.is0())throw new Error("point at infinify");return g.assertValidity(),g}hasHighS(){return g(this.s)}toBytes(e=m){if(Ot(e),"der"===e)return oe(Pt.hexFromSig(this));const t=s.toBytes(this.r),n=s.toBytes(this.s);if("recovered"===e){if(null==this.recovery)throw new Error("recovery bit must be present");return ae(Uint8Array.of(this.recovery),t,n)}return ae(t,n)}toHex(e){return G(this.toBytes(e))}assertValidity(){}static fromCompact(e){return _.fromBytes(Ie("sig",e),"compact")}static fromDER(e){return _.fromBytes(Ie("sig",e),"der")}normalizeS(){return this.hasHighS()?new _(this.r,s.neg(this.s),this.recovery):this}toDERRawBytes(){return this.toBytes("der")}toDERHex(){return G(this.toBytes("der"))}toCompactRawBytes(){return this.toBytes("compact")}toCompactHex(){return G(this.toBytes("compact"))}}const w=n.bits2int||function(e){if(e.length>8192)throw new Error("input is too large");const t=Se(e),n=8*e.length-c;return n>0?t>>BigInt(n):t},v=n.bits2int_modN||function(e){return s.create(w(e))},b=Ue(c);function E(e){return function(e,t,n,r){if(!Ne(t,n,r))throw new Error("expected valid "+e+": "+n+" <= n < "+r+", got "+t)}("num < 2^"+c,e,$t,b),s.toBytes(e)}function x(e,n){return ze(e,void 0,"message"),n?ze(t(e),void 0,"prehashed message"):e}return Object.freeze({keygen:u,getPublicKey:f,getSharedSecret:d,utils:l,lengths:p,Point:e,sign:function(n,i,a={}){n=Ie("message",n);const{seed:c,k2sig:u}=function(t,n,o){if(["recovered","canonical"].some(e=>e in o))throw new Error("sign() legacy options not supported");const{lowS:i,prehash:a,extraEntropy:c}=kt(o,h);t=x(t,a);const u=v(t),f=Bt(s,n),d=[E(f),E(u)];if(null!=c&&!1!==c){const e=!0===c?r(p.secretKey):c;d.push(Ie("extraEntropy",e))}const l=ae(...d),m=u;return{seed:l,k2sig:function(t){const n=w(t);if(!s.isValidNot0(n))return;const r=s.inv(n),o=e.BASE.multiply(n).toAffine(),a=s.create(o.x);if(a===$t)return;const c=s.create(r*s.create(m+a*f));if(c===$t)return;let u=(o.x===a?0:2)|Number(o.y&At),d=c;return i&&g(c)&&(d=s.neg(c),u^=1),new _(a,d,u)}}}(n,i,a);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),o=e=>Uint8Array.of(e);let i=r(e),s=r(e),a=0;const c=()=>{i.fill(1),s.fill(0),a=0},u=(...e)=>n(s,i,...e),f=(e=r(0))=>{s=u(o(0),e),i=u(),0!==e.length&&(s=u(o(1),e),i=u())},d=()=>{if(a++>=1e3)throw new Error("drbg: tried 1000 values");let e=0;const n=[];for(;e<t;){i=u();const t=i.slice();n.push(t),e+=i.length}return ae(...n)};return(e,t)=>{let n;for(c(),f(e);!(n=t(d()));)f();return c(),n}}(t.outputLen,s.BYTES,o)(c,u)},verify:function(t,n,r,o={}){const{lowS:i,prehash:a,format:c}=kt(o,h);if(r=Ie("publicKey",r),n=x(Ie("message",n),a),"strict"in o)throw new Error("options.strict was renamed to lowS");const u=void 0===c?function(e){let t;const n="string"==typeof e||C(e),r=!n&&null!==e&&"object"==typeof e&&"bigint"==typeof e.r&&"bigint"==typeof e.s;if(!n&&!r)throw new Error("invalid signature, expected Uint8Array, hex string or Signature instance");if(r)t=new _(e.r,e.s);else if(n){try{t=_.fromBytes(Ie("sig",e),"der")}catch(e){if(!(e instanceof Pt.Err))throw e}if(!t)try{t=_.fromBytes(Ie("sig",e),"compact")}catch(e){return!1}}return t||!1}(t):_.fromBytes(Ie("sig",t),c);if(!1===u)return!1;try{const t=e.fromBytes(r);if(i&&u.hasHighS())return!1;const{r:o,s:a}=u,c=v(n),f=s.inv(a),d=s.create(c*f),l=s.create(o*f),p=e.BASE.multiplyUnsafe(d).add(t.multiplyUnsafe(l));if(p.is0())return!1;return s.create(p.x)===o}catch(e){return!1}},recoverPublicKey:function(e,t,n={}){const{prehash:r}=kt(n,h);return t=x(t,r),_.fromBytes(e,"recovered").recoverPublicKey(t).toBytes()},Signature:_,hash:t})}function Ct(e){const{CURVE:t,curveOpts:n}=function(e){const t={a:e.a,b:e.b,p:e.Fp.ORDER,n:e.n,h:e.h,Gx:e.Gx,Gy:e.Gy},n=e.Fp;let r=e.allowedPrivateKeyLengths?Array.from(new Set(e.allowedPrivateKeyLengths.map(e=>Math.ceil(e/2)))):void 0;return{CURVE:t,curveOpts:{Fp:n,Fn:st(t.n,{BITS:e.nBitLength,allowedLengths:r,modFromBytes:e.wrapPrivateKey}),allowInfinityPoint:e.allowInfinityPoint,endo:e.endo,isTorsionFree:e.isTorsionFree,clearCofactor:e.clearCofactor,fromBytes:e.fromBytes,toBytes:e.toBytes}}}(e),r={hmac:e.hmac,randomBytes:e.randomBytes,lowS:e.lowS,bits2int:e.bits2int,bits2int_modN:e.bits2int_modN};return{CURVE:t,curveOpts:n,hash:e.hash,ecdsaOpts:r}}function Ft(e){const{CURVE:t,curveOpts:n,hash:r,ecdsaOpts:o}=Ct(e);return function(e,t){const n=t.Point;return Object.assign({},t,{ProjectivePoint:n,CURVE:Object.assign({},e,it(n.Fn.ORDER,n.Fn.BITS))})}(e,Zt(Ut(t,n),r,o))}
|
|
9
|
-
/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */
|
|
10
|
-
/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */
|
|
11
|
-
const Ht={p:BigInt("0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f"),n:BigInt("0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141"),h:BigInt(1),a:BigInt(0),b:BigInt(7),Gx:BigInt("0x79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798"),Gy:BigInt("0x483ada7726a3c4655da4fbfc0e1108a8fd17b448a68554199c47d08ffb10d4b8")},Dt={beta:BigInt("0x7ae96a2b657c07106e64479eac3434e99cf0497512f58995c1396c28719501ee"),basises:[[BigInt("0x3086d221a7d46bcde86c90e49284eb15"),-BigInt("0xe4437ed6010e88286f547fa90abfe4c3")],[BigInt("0x114ca50f7a8e2f3f657c1108d9d44cfd8"),BigInt("0x3086d221a7d46bcde86c90e49284eb15")]]},Lt=BigInt(0),Vt=BigInt(1),qt=BigInt(2);const Mt=st(Ht.p,{sqrt:function(e){const t=Ht.p,n=BigInt(3),r=BigInt(6),o=BigInt(11),i=BigInt(22),s=BigInt(23),a=BigInt(44),c=BigInt(88),u=e*e*e%t,f=u*u*e%t,d=We(f,n,t)*f%t,l=We(d,n,t)*f%t,p=We(l,qt,t)*u%t,h=We(p,o,t)*p%t,m=We(h,i,t)*h%t,g=We(m,a,t)*m%t,y=We(g,c,t)*g%t,_=We(y,a,t)*m%t,w=We(_,n,t)*f%t,v=We(w,s,t)*h%t,b=We(v,r,t)*u%t,E=We(b,qt,t);if(!Mt.eql(Mt.sqr(E),e))throw new Error("Cannot find square root");return E}}),Kt=function(e,t){const n=t=>Ft({...e,hash:t});return{...n(t),create:n}}({...Ht,Fp:Mt,lowS:!0,endo:Dt},_e),Jt={};function Wt(e,...t){let n=Jt[e];if(void 0===n){const t=_e(ie(e));n=ae(t,t),Jt[e]=n}return _e(ae(n,...t))}const Gt=e=>e.toBytes(!0).slice(1),Yt=(()=>Kt.Point)(),Xt=e=>e%qt===Lt;function Qt(e){const{Fn:t,BASE:n}=Yt,r=Bt(t,e),o=n.multiply(r);return{scalar:Xt(o.y)?r:t.neg(r),bytes:Gt(o)}}function en(e){const t=Mt;if(!t.isValidNot0(e))throw new Error("invalid x: Fail if x ≥ p");const n=t.create(e*e),r=t.create(n*e+BigInt(7));let o=t.sqrt(r);Xt(o)||(o=t.neg(o));const i=Yt.fromAffine({x:e,y:o});return i.assertValidity(),i}const tn=Se;function nn(...e){return Yt.Fn.create(tn(Wt("BIP0340/challenge",...e)))}function rn(e){return Qt(e).bytes}function on(e,t,n=fe(32)){const{Fn:r}=Yt,o=Ie("message",e),{bytes:i,scalar:s}=Qt(t),a=Ie("auxRand",n,32),c=r.toBytes(s^tn(Wt("BIP0340/aux",a))),u=Wt("BIP0340/nonce",c,i,o),{bytes:f,scalar:d}=Qt(u),l=nn(f,i,o),p=new Uint8Array(64);if(p.set(f,0),p.set(r.toBytes(r.create(d+l*s)),32),!sn(p,o,i))throw new Error("sign: Invalid signature produced");return p}function sn(e,t,n){const{Fn:r,BASE:o}=Yt,i=Ie("signature",e,64),s=Ie("message",t),a=Ie("publicKey",n,32);try{const e=en(tn(a)),t=tn(i.subarray(0,32));if(!Ne(t,Vt,Ht.p))return!1;const n=tn(i.subarray(32,64));if(!Ne(n,Vt,Ht.n))return!1;const c=nn(r.toBytes(t),Gt(e),s),u=o.multiplyUnsafe(n).add(e.multiplyUnsafe(r.neg(c))),{x:f,y:d}=u.toAffine();return!(u.is0()||!Xt(d)||f!==t)}catch(e){return!1}}const an=(()=>{const e=(e=fe(48))=>ut(e,Ht.n);return{keygen:function(t){const n=e(t);return{secretKey:n,publicKey:rn(n)}},getPublicKey:rn,sign:on,verify:sn,Point:Yt,utils:{randomSecretKey:e,randomPrivateKey:e,taggedHash:Wt,lift_x:en,pointToBytes:Gt,numberToBytesBE:$e,bytesToNumberBE:Se,mod:Je},lengths:{secretKey:32,publicKey:32,publicKeyHasPrefix:!1,signature:64,seed:48}}})(),cn=BigInt(0),un=BigInt(2);st(Kt.CURVE.n,32,!0);const fn=Kt.Point.BASE;function dn(e,t,n,r=!1){const o=pn(t).big,i=function(e){try{const t=ln(e,"ecdsa");return Kt.Point.fromHex(t)}catch(t){throw new Error("invalid pubkey: "+e)}}(e),s=fn.multiply(o);let a=i.add(s);r&&a.y%un!==cn&&(a=a.negate());return ln(a.toHex(!0),n)}function ln(e,t){try{const n=pn(e);if(33===n.length&&"bip340"===t)return n.slice(1);if(32===n.length&&"ecdsa"===t){const e=k.num(2,1);return k.join([e,n])}return n}catch(t){throw new Error("invalid pubkey: "+String(e))}}function pn(e){try{return k.bytes(e)}catch(t){throw new Error("invalid bytes: "+String(e))}}const hn=Uint8Array.from([7,4,13,1,10,6,15,3,12,0,9,5,2,14,11,8]),mn=(()=>Uint8Array.from(new Array(16).fill(0).map((e,t)=>t)))(),gn=(()=>mn.map(e=>(9*e+5)%16))(),yn=(()=>{const e=[[mn],[gn]];for(let t=0;t<4;t++)for(let n of e)n.push(n[t].map(e=>hn[e]));return e})(),_n=(()=>yn[0])(),wn=(()=>yn[1])(),vn=[[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)),bn=_n.map((e,t)=>e.map(e=>vn[t][e])),En=wn.map((e,t)=>e.map(e=>vn[t][e])),xn=Uint32Array.from([0,1518500249,1859775393,2400959708,2840853838]),zn=Uint32Array.from([1352829926,1548603684,1836072691,2053994217,0]);function On(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 kn=new Uint32Array(16);class Sn extends pe{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:o}=this;return[e,t,n,r,o]}set(e,t,n,r,o){this.h0=0|e,this.h1=0|t,this.h2=0|n,this.h3=0|r,this.h4=0|o}process(e,t){for(let n=0;n<16;n++,t+=4)kn[n]=e.getUint32(t,!0);let n=0|this.h0,r=n,o=0|this.h1,i=o,s=0|this.h2,a=s,c=0|this.h3,u=c,f=0|this.h4,d=f;for(let e=0;e<5;e++){const t=4-e,l=xn[e],p=zn[e],h=_n[e],m=wn[e],g=bn[e],y=En[e];for(let t=0;t<16;t++){const r=K(n+On(e,o,s,c)+kn[h[t]]+l,g[t])+f|0;n=f,f=c,c=0|K(s,10),s=o,o=r}for(let e=0;e<16;e++){const n=K(r+On(t,i,a,u)+kn[m[e]]+p,y[e])+d|0;r=d,d=u,u=0|K(a,10),a=i,i=n}}this.set(this.h1+s+u|0,this.h2+c+d|0,this.h3+f+r|0,this.h4+n+i|0,this.h0+o+a|0)}roundClean(){V(kn)}destroy(){this.destroyed=!0,V(this.buffer),this.set(0,0,0,0,0)}}const Pn=ue(()=>new Sn);function $n(...e){const t=k.join(e),n=Pn(_e(t));return new k(n)}function An(...e){const t=k.join(e),n=_e(t);return new k(n)}function In(...e){const t=k.join(e),n=_e(_e(t));return new k(n)}function Tn(e,...t){const n=function(e){const t=An(k.str(e));return k.join([t,t])}(e),r=t.map(e=>new k(e));return An(k.join([n,...r]))}
|
|
12
|
-
/*! scure-base - MIT License (c) 2022 Paul Miller (paulmillr.com) */function Nn(e){return e instanceof Uint8Array||ArrayBuffer.isView(e)&&"Uint8Array"===e.constructor.name}function Bn(e,t){return!!Array.isArray(t)&&(0===t.length||(e?t.every(e=>"string"==typeof e):t.every(e=>Number.isSafeInteger(e))))}function Un(e){if("function"!=typeof e)throw new Error("function expected");return!0}function Rn(e,t){if("string"!=typeof t)throw new Error(`${e}: string expected`);return!0}function jn(e){if(!Number.isSafeInteger(e))throw new Error(`invalid integer: ${e}`)}function Zn(e){if(!Array.isArray(e))throw new Error("array expected")}function Cn(e,t){if(!Bn(!0,t))throw new Error(`${e}: array of strings expected`)}function Fn(e,t){if(!Bn(!1,t))throw new Error(`${e}: array of numbers expected`)}function Hn(...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 Dn(e){const t="string"==typeof e?e.split(""):e,n=t.length;Cn("alphabet",t);const r=new Map(t.map((e,t)=>[e,t]));return{encode:r=>(Zn(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=>(Zn(t),t.map(t=>{Rn("alphabet.decode",t);const n=r.get(t);if(void 0===n)throw new Error(`Unknown letter: "${t}". Allowed: ${e}`);return n}))}}function Ln(e=""){return Rn("join",e),{encode:t=>(Cn("join.decode",t),t.join(e)),decode:t=>(Rn("join.decode",t),t.split(e))}}function Vn(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(Zn(e),!e.length)return[];let r=0;const o=[],i=Array.from(e,e=>{if(jn(e),e<0||e>=t)throw new Error(`invalid integer: ${e}`);return e}),s=i.length;for(;;){let e=0,a=!0;for(let o=r;o<s;o++){const s=i[o],c=t*e,u=c+s;if(!Number.isSafeInteger(u)||c/t!==e||u-s!==c)throw new Error("convertRadix: carry overflow");const f=u/n;e=u%n;const d=Math.floor(f);if(i[o]=d,!Number.isSafeInteger(d)||d*n+e!==u)throw new Error("convertRadix: carry overflow");a&&(d?a=!1:r=o)}if(o.push(e),a)break}for(let t=0;t<e.length-1&&0===e[t];t++)o.push(0);return o.reverse()}const qn=(e,t)=>0===t?e:qn(t,e%t),Mn=(e,t)=>e+(t-qn(e,t)),Kn=(()=>{let e=[];for(let t=0;t<40;t++)e.push(2**t);return e})();function Jn(e,t,n,r){if(Zn(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(Mn(t,n)>32)throw new Error(`convertRadix2: carry overflow from=${t} to=${n} carryBits=${Mn(t,n)}`);let o=0,i=0;const s=Kn[t],a=Kn[n]-1,c=[];for(const r of e){if(jn(r),r>=s)throw new Error(`convertRadix2: invalid data word=${r} from=${t}`);if(o=o<<t|r,i+t>32)throw new Error(`convertRadix2: carry overflow pos=${i} from=${t}`);for(i+=t;i>=n;i-=n)c.push((o>>i-n&a)>>>0);const e=Kn[i];if(void 0===e)throw new Error("invalid carry");o&=e-1}if(o=o<<n-i&a,!r&&i>=t)throw new Error("Excess padding");if(!r&&o>0)throw new Error(`Non-zero padding: ${o}`);return r&&i>0&&c.push(o>>>0),c}function Wn(e,t=!1){if(jn(e),e<=0||e>32)throw new Error("radix2: bits should be in (0..32]");if(Mn(8,e)>32||Mn(e,8)>32)throw new Error("radix2: carry overflow");return{encode:n=>{if(!Nn(n))throw new Error("radix2.encode input should be Uint8Array");return Jn(Array.from(n),8,e,!t)},decode:n=>(Fn("radix2.decode",n),Uint8Array.from(Jn(n,e,8,t)))}}function Gn(e){return Un(e),function(...t){try{return e.apply(null,t)}catch(e){}}}const Yn=(()=>"function"==typeof Uint8Array.from([]).toBase64&&"function"==typeof Uint8Array.fromBase64)()?{encode:e=>(function(e,...t){if(!Nn(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(Rn("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)}:Hn(Wn(6),Dn("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"),function(e,t="="){return jn(e),Rn("padding",t),{encode(n){for(Cn("padding.encode",n);n.length*e%8;)n.push(t);return n},decode(n){Cn("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),Ln("")),Xn=Hn(Wn(6),Dn("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_"),Ln("")),Qn=(er="123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz",Hn(function(e){return jn(e),{encode:t=>{if(!Nn(t))throw new Error("radix.encode input should be Uint8Array");return Vn(Array.from(t),256,e)},decode:t=>(Fn("radix.decode",t),Uint8Array.from(Vn(t,e,256)))}}(58),Dn(er),Ln("")));var er;const tr=e=>{return Hn((n=t=>e(e(t)),jn(t=4),Un(n),{encode(e){if(!Nn(e))throw new Error("checksum.encode: input should be Uint8Array");const r=n(e).slice(0,t),o=new Uint8Array(e.length+t);return o.set(e),o.set(r,e.length),o},decode(e){if(!Nn(e))throw new Error("checksum.decode: input should be Uint8Array");const r=e.slice(0,-t),o=e.slice(-t),i=n(r).slice(0,t);for(let e=0;e<t;e++)if(i[e]!==o[e])throw new Error("Invalid checksum");return r}}),Qn);var t,n},nr=Hn(Dn("qpzry9x8gf2tvdw0s3jn54khce6mua7l"),Ln("")),rr=[996825010,642813549,513874426,1027748829,705979059];function or(e){const t=e>>25;let n=(33554431&e)<<5;for(let e=0;e<rr.length;e++)1==(t>>e&1)&&(n^=rr[e]);return n}function ir(e,t,n=1){const r=e.length;let o=1;for(let t=0;t<r;t++){const n=e.charCodeAt(t);if(n<33||n>126)throw new Error(`Invalid prefix (${e})`);o=or(o)^n>>5}o=or(o);for(let t=0;t<r;t++)o=or(o)^31&e.charCodeAt(t);for(let e of t)o=or(o)^e;for(let e=0;e<6;e++)o=or(o);return o^=n,nr.encode(Jn([o%Kn[30]],30,5,!1))}function sr(e){const t="bech32"===e?1:734539939,n=Wn(5),r=n.decode,o=n.encode,i=Gn(r);function s(e,n,r=90){Rn("bech32.encode prefix",e),Nn(n)&&(n=Array.from(n)),Fn("bech32.encode",n);const o=e.length;if(0===o)throw new TypeError(`Invalid prefix length ${o}`);const i=o+7+n.length;if(!1!==r&&i>r)throw new TypeError(`Length ${i} exceeds limit ${r}`);const s=e.toLowerCase(),a=ir(s,n,t);return`${s}1${nr.encode(n)}${a}`}function a(e,n=90){Rn("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 o=e.toLowerCase();if(e!==o&&e!==e.toUpperCase())throw new Error("String must be lowercase or uppercase");const i=o.lastIndexOf("1");if(0===i||-1===i)throw new Error('Letter "1" must be present between prefix and data only');const s=o.slice(0,i),a=o.slice(i+1);if(a.length<6)throw new Error("Data must be at least 6 characters long");const c=nr.decode(a).slice(0,-6),u=ir(s,c,t);if(!a.endsWith(u))throw new Error(`Invalid checksum in ${e}: expected "${u}"`);return{prefix:s,words:c}}return{encode:s,decode:a,encodeFromBytes:function(e,t){return s(e,o(t))},decodeToBytes:function(e){const{prefix:t,words:n}=a(e,!1);return{prefix:t,words:n,bytes:r(n)}},decodeUnsafe:Gn(a),fromWords:r,fromWordsUnsafe:i,toWords:o}}const ar=sr("bech32"),cr=sr("bech32m");var ur,fr,dr,lr,pr;function hr(e){if("string"!=typeof e||0===e.length)throw new Error(`invalid prefix: ${String(e)}`)}function mr(e){if(!Array.isArray(e)||!e.every(e=>"number"==typeof e))throw new Error(`invalid words: ${String(e)}`)}!function(e){e.encode=e=>(j.is_u8a(e),tr(_e).encode(e)),e.decode=e=>(j.is_base58(e),tr(_e).decode(e))}(ur||(ur={})),function(e){e.encode=e=>(j.is_u8a(e),Yn.encode(e)),e.decode=e=>(j.is_base64(e),Yn.decode(e))}(fr||(fr={})),function(e){e.encode=e=>(j.is_u8a(e),Xn.encode(e)),e.decode=e=>(j.is_b64url(e),Xn.decode(e))}(dr||(dr={})),function(e){e.to_words=ar.toWords,e.to_bytes=ar.fromWords,e.encode=(e,t,n=!1)=>(hr(e),mr(t),ar.encode(e,t,n)),e.decode=(e,t=!1)=>(j.is_bech32(e),ar.decode(e,t))}(lr||(lr={})),function(e){e.to_words=cr.toWords,e.to_bytes=cr.fromWords,e.encode=(e,t,n=!1)=>(hr(e),mr(t),cr.encode(e,t,n)),e.decode=(e,t=!1)=>(j.is_bech32(e),cr.decode(e,t))}(pr||(pr={}));const gr={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}$/},yr=0,_r=1;function wr(e){const t=function(e){for(const[t,n]of Object.entries(gr))if(n.test(e))return t;return null}(e);if(null===t)throw new Error(`unrecognized address format: ${e}`);if("base58"===t)return function(e){const t=ur.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}=lr.decode(e),[r,...o]=n;j.ok(r===yr,"bech32 version mismatch");return{data:lr.to_bytes(o),format:"bech32",prefix:t,version:r}}(e);if("bech32m"===t)return function(e){const{prefix:t,words:n}=pr.decode(e),[r,...o]=n;j.ok(r===_r,"bech32m version mismatch");return{data:pr.to_bytes(o),format:"bech32m",prefix:t,version:r}}(e);throw new Error("unable to find a matching address configuration")}function vr(e){if("base58"===e.format)return function(e){j.ok("base58"===e.format,"encoding mismatch"),j.exists(e.version,"must specify a version");const t=k.join([e.version,e.data]);return ur.encode(t)}(e);if("bech32"===e.format)return function(e){j.ok("bech32"===e.format,"encoding mismatch"),j.exists(e.prefix,"prefix is required");const t=k.bytes(e.data),n=lr.to_words(t);return lr.encode(e.prefix,[yr,...n])}(e);if("bech32m"===e.format)return function(e){j.ok("bech32m"===e.format,"encoding mismatch"),j.exists(e.prefix,"prefix is required");const t=k.bytes(e.data),n=pr.to_words(t);return pr.encode(e.prefix,[_r,...n])}(e);throw new Error(`unrecognized encoding format: ${e.format}`)}function br(e,t){switch(t){case"p2pkh":return function(e){return{hex:`76a914${e}88ac`,asm:["OP_DUP","OP_HASH160",e,"OP_EQUALVERIFY","OP_CHECKSIG"]}}(e);case"p2sh":return function(e){return{hex:`a914${e}87`,asm:["OP_HASH160",e,"OP_EQUAL"]}}(e);case"p2wpkh":return function(e){return{hex:`0014${e}`,asm:["OP_0",e]}}(e);case"p2wsh":return function(e){return{hex:`0020${e}`,asm:["OP_0",e]}}(e);case"p2tr":return function(e){return{hex:`5120${e}`,asm:["OP_1",e]}}(e);default:throw new Error(`unrecognized script type: ${t}`)}}const Er=[["1","p2pkh","main",20,"base58",0],["3","p2sh","main",20,"base58",5],["m","p2pkh","testnet",20,"base58",111],["n","p2pkh","testnet",20,"base58",111],["2","p2sh","testnet",20,"base58",196],["m","p2pkh","regtest",20,"base58",111],["n","p2pkh","regtest",20,"base58",111],["2","p2sh","regtest",20,"base58",196],["bc","p2wpkh","main",20,"bech32",0],["tb","p2wpkh","testnet",20,"bech32",0],["bcrt","p2wpkh","regtest",20,"bech32",0],["bc","p2wsh","main",32,"bech32",0],["tb","p2wsh","testnet",32,"bech32",0],["bcrt","p2wsh","regtest",32,"bech32",0],["bc","p2tr","main",32,"bech32m",1],["tb","p2tr","testnet",32,"bech32m",1],["bcrt","p2tr","regtest",32,"bech32m",1]];function xr(e,t){for(const[n,r,o,i,s,a]of Er)if(r===t&&o===e)return{type:r,prefix:n,network:o,size:i,format:s,version:a};return null}function zr(e){const t=wr(e);for(const[n,r,o,i,s,a]of Er){if(s!==t.format)continue;if(i!==t.data.length)continue;if(a!==t.version)continue;if(t.prefix){if(n!==t.prefix)continue}else if(!e.startsWith(n))continue;const c=k.bytes(t.data).hex;return{data:c,script:br(c,r),type:r,prefix:n,network:o,size:i,format:s,version:a}}throw new Error("address configuration is invalid")}const Or=o.P2PKH;var kr;function Sr(e,t="main"){return Ar(Pr(e),t)}function Pr(e){const t=k.bytes(e);j.size(t,33,"invalid pubkey size");return $r($n(t))}function $r(e){return k.join(["76a914",e,"88ac"])}function Ar(e,t="main"){const n=Tr(e),r=xr(t,Or);return j.exists(r,`unrecognized address config: ${Or} on ${t}`),j.size(n,r.size,`invalid payload size: ${n.length} !== ${r.size}`),vr({data:n,format:"base58",version:r.version})}function Ir(e){const t=zr(e);return j.ok("p2pkh"===t.type,`address type mismatch: ${t.type} !== ${Or}`),t}function Tr(e){const t=k.bytes(e);return j.ok(A(e),"invalid p2pkh script"),t.slice(3,23)}!function(e){e.create_address=Sr,e.create_script=Pr,e.encode_address=Ar,e.encode_script=$r,e.decode_address=Ir,e.decode_script=Tr}(kr||(kr={}));const Nr=o.P2SH;var Br;function Ur(e,t="main"){return Zr(jr($n(k.bytes(e))),t)}function Rr(e){return jr($n(k.bytes(e)))}function jr(e){return k.join(["a914",e,"87"])}function Zr(e,t="main"){const n=Fr(e),r=xr(t,Nr);return j.exists(r,`unrecognized address config: ${Nr} on ${t}`),j.size(n,r.size,`invalid payload size: ${n.length} !== ${r.size}`),vr({data:n,format:"base58",version:r.version})}function Cr(e){const t=zr(e);return j.ok("p2sh"===t.type,`address type mismatch: ${t.type} !== ${Nr}`),t}function Fr(e){j.ok(I(e),"invalid p2sh script");return k.bytes(e).slice(2,22)}!function(e){e.create_address=Ur,e.create_script=Rr,e.encode_address=Zr,e.encode_script=jr,e.decode_address=Cr,e.decode_script=Fr}(Br||(Br={}));const Hr=o.P2TR;var Dr;function Lr(e,t="main"){return Mr(Vr(e),t)}function Vr(e){const t=k.bytes(e);return j.size(t,32,"invalid pubkey size"),qr(t)}function qr(e){return k.join(["5120",e])}function Mr(e,t="main"){const n=Jr(e),r=xr(t,Hr);return j.exists(r,`unrecognized address config: ${Hr} on ${t}`),j.size(n,r.size,`invalid payload size: ${n.length} !== ${r.size}`),vr({data:n,format:"bech32m",prefix:r.prefix})}function Kr(e){const t=zr(e);return j.ok("p2tr"===t.type,`address type mismatch: ${t.type} !== ${Hr}`),t}function Jr(e){j.ok(B(e),"invalid p2tr script");return k.bytes(e).slice(2,34)}!function(e){e.create_address=Lr,e.create_script=Vr,e.encode_address=Mr,e.encode_script=qr,e.decode_address=Kr,e.decode_script=Jr}(Dr||(Dr={}));const Wr=o.P2WPKH;var Gr;function Yr(e,t="main"){return eo(Xr(e),t)}function Xr(e){const t=k.bytes(e);j.size(t,33,"invalid pubkey size");return Qr($n(t))}function Qr(e){return k.join(["0014",e])}function eo(e,t="main"){const n=no(e),r=xr(t,Wr);return j.exists(r,`unrecognized address config: ${Wr} on ${t}`),j.size(n,r.size,`invalid payload size: ${n.length} !== ${r.size}`),vr({data:n,format:"bech32",prefix:r.prefix})}function to(e){const t=zr(e);return j.ok("p2wpkh"===t.type,`address type mismatch: ${t.type} !== ${Wr}`),t}function no(e){j.ok(T(e),"invalid p2wpkh script");return k.bytes(e).slice(2,22)}!function(e){e.create_address=Yr,e.create_script=Xr,e.encode_address=eo,e.encode_script=Qr,e.decode_address=to,e.decode_script=no}(Gr||(Gr={}));const ro=o.P2WSH;var oo;function io(e,t="main"){return co(so(e),t)}function so(e){return ao(An(k.bytes(e)))}function ao(e){return k.join(["0020",e])}function co(e,t="main"){const n=fo(e),r=xr(t,ro);return j.exists(r,`unrecognized address config: ${ro} on ${t}`),j.size(n,r.size,`invalid payload size: ${n.length} !== ${r.size}`),vr({data:n,format:"bech32",prefix:r.prefix})}function uo(e){const t=zr(e);return j.ok("p2wsh"===t.type,`address type mismatch: ${t.type} !== ${ro}`),t}function fo(e){j.ok(N(e),"invalid p2wsh script");return k.bytes(e).slice(2,34)}!function(e){e.create_address=io,e.create_script=so,e.encode_address=co,e.encode_script=ao,e.decode_address=uo,e.decode_script=fo}(oo||(oo={}));var lo=Object.freeze({__proto__:null,get P2PKH(){return kr},get P2SH(){return Br},get P2TR(){return Dr},get P2WPKH(){return Gr},get P2WSH(){return oo},get_address:function(e,t="main"){const n=P(k.bytes(e));if(null===n)throw new Error("Unknown or unsupported locking script type");switch(n){case o.P2PKH:return kr.encode_address(e,t);case o.P2SH:return Br.encode_address(e,t);case o.P2WPKH:return Gr.encode_address(e,t);case o.P2WSH:return oo.encode_address(e,t);case o.P2TR:return Dr.encode_address(e,t);default:throw new Error(`unknown script type: ${n}`)}},parse_address:function(e){return zr(e)}});const po=5e8;var ho,mo;function go(e){switch(e.type){case"timelock":return j.ok(e.stamp>=po,"Invalid timestamp"),e.stamp;case"heightlock":return j.ok(e.height>0,"height must be greater than 0"),j.ok(e.height<po,"invalid block height"),e.height;default:throw new Error("Invalid locktime type")}}function yo(e){return Number.isNaN(e)||e<=0?null:e<po?{type:"heightlock",height:e}:{type:"timelock",stamp:e}}function _o(e,t=0){return`${e}i${t}`}function wo(e){bo(e);const[t,n]=e.split("i");return{txid:t,order:parseInt(n,10)}}function vo(e){return null!==e.match(/^[a-f0-9]{64}i\d+$/)}function bo(e){if(!vo(e))throw new Error(`invalid inscription id: ${e}`)}function Eo(e,t){return`${e}:${t}`}function xo(e){Oo(e);const[t,n]=e.split(":");return{block_height:parseInt(t,10),block_index:parseInt(n,10)}}function zo(e){return null!==e.match(/^\d+:\d+$/)}function Oo(e){if(!zo(e))throw new Error(`invalid rune id: ${e}`)}function ko(e,t){return`${e}:${t}`}function So(e){$o(e);const[t,n]=e.split(":");return{txid:t,vout:parseInt(n,10)}}function Po(e){return null!==e.match(/^[a-f0-9]{64}:[0-9]+$/)}function $o(e){if(!Po(e))throw new Error(`invalid outpoint: ${e}`)}!function(e){e.encode=go,e.decode=yo}(ho||(ho={})),function(e){e.outpoint={encode:ko,decode:So,verify:Po,assert:$o},e.record_id={encode:_o,decode:wo,verify:vo,assert:bo},e.rune_id={encode:Eo,decode:xo,verify:zo,assert:Oo}}(mo||(mo={}));const Ao={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 Io(e){if(e>186&&e<255)return`OP_SUCCESS${String(e)}`;for(const[t,n]of Object.entries(Ao))if(n===e)return t;throw new Error(`OPCODE not found:${String(e)}`)}function To(e){for(const[t,n]of Object.entries(Ao))if(t===e)return Number(n);throw new Error(`OPCODE not found:${e}`)}function No(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 Bo(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}}function Uo(e){const t=new S(e),n=[],r=t.size;let o,i,s,a=0;for(;a<r;)switch(o=t.read(1).num,i=No(o),a++,i){case"varint":try{n.push(t.read(o).hex)}catch{throw new Error(`Malformed script: varint push at position ${a-1} requires ${o} bytes but stream exhausted`)}a+=o;break;case"pushdata1":try{s=t.read(1).reverse().num}catch{throw new Error(`Malformed script: PUSHDATA1 at position ${a-1} missing size byte`)}try{n.push(t.read(s).hex)}catch{throw new Error(`Malformed script: PUSHDATA1 at position ${a-1} requires ${s} bytes but stream exhausted`)}a+=s+1;break;case"pushdata2":try{s=t.read(2).reverse().num}catch{throw new Error(`Malformed script: PUSHDATA2 at position ${a-1} missing size bytes`)}try{n.push(t.read(s).hex)}catch{throw new Error(`Malformed script: PUSHDATA2 at position ${a-1} requires ${s} bytes but stream exhausted`)}a+=s+2;break;case"pushdata4":try{s=t.read(4).reverse().num}catch{throw new Error(`Malformed script: PUSHDATA4 at position ${a-1} missing size bytes`)}try{n.push(t.read(s).hex)}catch{throw new Error(`Malformed script: PUSHDATA4 at position ${a-1} requires ${s} bytes but stream exhausted`)}a+=s+4;break;case"opcode":if(!Bo(o))throw new Error(`Invalid OPCODE: ${o}`);n.push(Io(o));break;default:throw new Error(`Word type undefined: ${o}`)}return n}function Ro(e){try{return Uo(e).length>0}catch{return!1}}const jo=520;function Zo(e,t=!1){if(0===e.length)return k.num(0,1);const n=[];for(const t of e)n.push(Co(t));const r=k.join(n);if(r.length>c)throw new Error(`script size ${r.length} exceeds consensus limit of 10000 bytes`);return t?r.prepend(k.create_varint(r.length,"le")):r}function Co(e){let t;if("string"==typeof e){if(e.startsWith("OP_")){const t=To(e);return k.num(t,1)}t=k.is_hex(e)?k.hex(e):k.str(e)}else if("number"==typeof e)t=k.num(e);else{if(!(e instanceof Uint8Array))throw new Error("invalid word type:"+typeof e);t=new k(e)}if(1===t.length&&t[0]<=16)0!==t[0]&&(t[0]+=80);else if(t.length>jo){let e;e=Fo(t),e=e.map(e=>Ho(e)),t=k.join(e)}else t=Ho(t);return t}function Fo(e){const t=[],n=new S(e);for(;n.size>jo;)t.push(n.read(jo));return t.push(n.read(n.size)),t}function Ho(e){const t=Do(e.length);return k.join([t,e])}function Do(e){const t=k.num(76,1),n=k.num(77,1);switch(!0){case e<=75:return k.num(e);case e>75&&e<256:return k.join([t,k.num(e,1,"le")]);case e>=256&&e<=jo:return k.join([n,k.num(e,2,"le")]);default:throw new Error(`Invalid word size:${e.toString()}`)}}const Lo=BigInt(0),Vo=BigInt(1),qo=BigInt(26);var Mo;function Ko(e){const t=function(e){const t=Uo(e),n=t.indexOf("OP_0");j.ok(-1!==n,"inscription envelope not found");const r=[];for(let e=n;e<t.length;e++){j.ok("OP_IF"===t[e+1],"OP_IF missing from envelope"),j.ok("6f7264"===t[e+2],"magic bytes missing from envelope");const n=t.indexOf("OP_ENDIF");j.ok(-1!==n,"inscription envelope missing END_IF statement");const o=t.slice(e+3,n);r.push(o),e+=n}return r}(e);return t.map(Go)}function Jo(e){return k.join(e.map(Wo))}function Wo(e){const t=["OP_0","OP_IF","6f7264"];if("string"==typeof e.delegate){const n=Xo(e.delegate);t.push("OP_11",n)}if("string"==typeof e.ref&&t.push("OP_WITHIN",e.ref),"string"==typeof e.parent){const n=Xo(e.parent);t.push("OP_3",n)}if("number"==typeof e.opcode){const n=ei(e.opcode);t.push("OP_NOP",n)}if("number"==typeof e.pointer){const n=ei(e.pointer);t.push("OP_2",n)}if("string"==typeof e.rune){const n=function(e){const t=e.toUpperCase();let n=Lo;for(const e of t)e>="A"&&e<="Z"&&(n=n*qo+BigInt(e.charCodeAt(0)-("A".charCodeAt(0)-1)));return n-=Vo,k.big(n).reverse().hex}(e.rune);t.push("OP_13",n)}if("string"==typeof e.mimetype){const n=function(e){return k.str(e).hex}(e.mimetype);t.push("OP_1",n)}if("string"==typeof e.content){const n=function(e){const t=k.is_hex(e)?k.hex(e):k.str(e),n=new S(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"),Zo(t)}function Go(e){const t={};for(let n=0;n<e.length;n++)switch(e[n]){case"OP_1":t.mimetype=ni(e[n+1]),n+=1;break;case"OP_2":t.pointer=ti(e[n+1]),n+=1;break;case"OP_3":t.parent=Qo(e[n+1]),n+=1;break;case"OP_11":t.delegate=Qo(e[n+1]),n+=1;break;case"OP_13":t.rune=oi(e[n+1]),n+=1;break;case"OP_WITHIN":t.ref=Yo(e[n+1]),n+=1;break;case"OP_NOP":t.opcode=ti(e[n+1]),n+=1;break;case"OP_0":return t.content=ri(e.slice(n+1)),t}return t}function Yo(e){return k.bytes(e).hex}function Xo(e){j.ok(e.includes("i"),"identifier must include an index");const t=e.split("i"),n=k.hex(t[0]),r=Number(t[1]),o=n.reverse().hex;return 0!==r?o+k.num(r).hex:o}function Qo(e){const t=k.bytes(e),n=t.at(-1)??0;return`${t.slice(0,-1).reverse().hex}i${String(n)}`}function ei(e){return k.num(e).reverse().hex}function ti(e){return k.bytes(e).reverse().num}function ni(e){return k.bytes(e).str}function ri(e,t="hex"){const n=k.join(e);return"hex"===t?n.hex:n.str}function oi(e){let t=k.bytes(e).reverse().big;t+=Vo;let n="";for(;t>Lo;){const e=t%qo;if(e===Lo)n=`Z${n}`,t=t/qo-Vo;else{const r=Number(e)+"A".charCodeAt(0)-1;n=String.fromCharCode(r)+n,t/=qo}}return n}!function(e){e.encode=Jo,e.decode=Ko}(Mo||(Mo={}));const ii=4194304,si=65535,ai=65535;var ci;function ui(e){if("height"===e.mode){return(function(e){if(void 0===e||!Number.isInteger(e)||e<0||e>ai)throw new Error("Heightlock value must be an integer between 0 and 65535");return e}(e.height)&si)>>>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>ai)throw new Error("timelock value must be an integer between 0 and 65535 (in 512-second increments)");return t}(e.stamp);return(ii|t&si)>>>0}throw new Error(`invalid timelock mode: ${e.mode}`)}function fi(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&si;if(t&ii){const e=512*n;if(e>4294967295)throw new Error("Decoded timestamp exceeds 32-bit limit");return{mode:"stamp",stamp:e}}if(n>ai)throw new Error("Decoded height exceeds maximum");return{mode:"height",height:n}}!function(e){e.encode=ui,e.decode=fi}(ci||(ci={}));var di=Object.freeze({__proto__:null,get InscriptionUtil(){return Mo},get LocktimeField(){return ho},get RefPointer(){return mo},get SequenceField(){return ci},decode_inscription:Ko,decode_locktime:yo,decode_sequence:fi,encode_inscription:Jo,encode_locktime:go,encode_sequence:ui});function li(e){return k.bytes(e).prefix_varint("le").hex}var pi=Object.freeze({__proto__:null,OPCODE_MAP:Ao,decode_script:Uo,encode_script:Zo,encode_script_word:Co,get_asm_code:To,get_lock_script_info:function(e){return{type:P(e),version:$(e)}},get_lock_script_type:P,get_lock_script_version:$,get_op_code:Io,get_op_type:No,get_size_varint:Do,is_opreturn_script:function(e){const t=k.bytes(e).hex;return i.opreturn.test(t)},is_p2pkh_script:A,is_p2sh_script:I,is_p2tr_script:B,is_p2wpkh_script:T,is_p2wsh_script:N,is_return_script:function(e){return 106===k.bytes(e).at(0)},is_valid_op:Bo,is_valid_script:Ro,parse_script:function(e){const t=k.bytes(e);return{asm:Uo(t),hex:t.hex}},parse_script_pubkeys:function(e){return[...("string"==typeof e?e:k.bytes(e).hex).matchAll(/20([0-9a-f]{64})(ac|ad|ba)/gi)].map(e=>e[1])},prefix_script_size:li,prefix_word_size:Ho,split_script_word:Fo});const hi=4e6,mi=1e5;function gi(e,t=!0){j.is_bytes(e,"txdata must be hex or bytes");const n="string"==typeof e?e.length/2:e.length;if(n>hi)throw new Error(`Transaction size ${n} exceeds maximum 4000000 bytes`);const r=new S(e),o=function(e){return e.read(4).reverse().to_num()}(r);let i=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}(r);i=!!t&&i;const s=function(e){const t=[],n=e.read_varint();if(n>mi)throw new Error(`Input count ${n} exceeds maximum 100000`);for(let r=0;r<n;r++){const n=yi(e);t.push(n)}return t}(r),a=function(e){const t=[],n=e.read_varint();if(n>mi)throw new Error(`Output count ${n} exceeds maximum 100000`);for(let r=0;r<n;r++)try{t.push(_i(e))}catch(e){throw new Error(`failed to decode output at index ${r}`)}return t}(r);if(i)for(const e of s)e.witness=wi(r);const c=function(e){return e.read(4).reverse().to_num()}(r);return{version:o,vin:s,vout:a,locktime:c}}function yi(e){const n=e.read(32).reverse().hex,r=e.read(4).reverse().num,o=vi(e),i=e.read(4).reverse().num,s=[];return n===t.TXID&&r===t.VOUT?{coinbase:o,prevout:null,script_sig:null,sequence:i,txid:n,vout:r,witness:s}:{coinbase:null,prevout:null,script_sig:o,sequence:i,txid:n,vout:r,witness:s}}function _i(e){const t=e.read(8).reverse().big,n=vi(e);return j.exists(n,"failed to decode script_pk"),{value:t,script_pk:n}}function wi(e){const t=[],n=e.read_varint();if(n>mi)throw new Error(`Witness element count ${n} exceeds maximum 100000`);for(let r=0;r<n;r++){const n=vi(e);if(null===n)throw new Error(`failed to decode witness element at index ${r}`);t.push(n)}return t}function vi(e){const t=e.read_varint("le");if(t>u)throw new Error(`Payload size ${t} exceeds maximum 520000`);return t>0?e.read(t).hex:null}function bi(e,t,n){function r(n,r){if(n._zod||Object.defineProperty(n,"_zod",{value:{def:r,constr:s,traits:new Set},enumerable:!1}),n._zod.traits.has(e))return;n._zod.traits.add(e),t(n,r);const o=s.prototype,i=Object.keys(o);for(let e=0;e<i.length;e++){const t=i[e];t in n||(n[t]=o[t].bind(n))}}const o=n?.Parent??Object;class i extends o{}function s(e){var t;const o=n?.Parent?new i:this;r(o,e),(t=o._zod).deferred??(t.deferred=[]);for(const e of o._zod.deferred)e();return o}return Object.defineProperty(i,"name",{value:e}),Object.defineProperty(s,"init",{value:r}),Object.defineProperty(s,Symbol.hasInstance,{value:t=>!!(n?.Parent&&t instanceof n.Parent)||t?._zod?.traits?.has(e)}),Object.defineProperty(s,"name",{value:e}),s}class Ei extends Error{constructor(){super("Encountered Promise during synchronous parse. Use .parseAsync() instead.")}}class xi extends Error{constructor(e){super(`Encountered unidirectional transform during encode: ${e}`),this.name="ZodEncodeError"}}const zi={};function Oi(e){return zi}function ki(e){const t=Object.values(e).filter(e=>"number"==typeof e);return Object.entries(e).filter(([e,n])=>-1===t.indexOf(+e)).map(([e,t])=>t)}function Si(e,t){return"bigint"==typeof t?t.toString():t}function Pi(e){return{get value(){{const t=e();return Object.defineProperty(this,"value",{value:t}),t}}}}function $i(e){return null==e}function Ai(e){const t=e.startsWith("^")?1:0,n=e.endsWith("$")?e.length-1:e.length;return e.slice(t,n)}const Ii=Symbol("evaluating");function Ti(e,t,n){let r;Object.defineProperty(e,t,{get(){if(r!==Ii)return void 0===r&&(r=Ii,r=n()),r},set(n){Object.defineProperty(e,t,{value:n})},configurable:!0})}function Ni(e,t,n){Object.defineProperty(e,t,{value:n,writable:!0,enumerable:!0,configurable:!0})}function Bi(...e){const t={};for(const n of e){const e=Object.getOwnPropertyDescriptors(n);Object.assign(t,e)}return Object.defineProperties({},t)}function Ui(e){return JSON.stringify(e)}const Ri="captureStackTrace"in Error?Error.captureStackTrace:(...e)=>{};function ji(e){return"object"==typeof e&&null!==e&&!Array.isArray(e)}const Zi=Pi(()=>{if("undefined"!=typeof navigator&&navigator?.userAgent?.includes("Cloudflare"))return!1;try{return new Function(""),!0}catch(e){return!1}});function Ci(e){if(!1===ji(e))return!1;const t=e.constructor;if(void 0===t)return!0;if("function"!=typeof t)return!0;const n=t.prototype;return!1!==ji(n)&&!1!==Object.prototype.hasOwnProperty.call(n,"isPrototypeOf")}function Fi(e){return Ci(e)?{...e}:Array.isArray(e)?[...e]:e}const Hi=new Set(["string","number","symbol"]);function Di(e){return e.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}function Li(e,t,n){const r=new e._zod.constr(t??e._zod.def);return t&&!n?.parent||(r._zod.parent=e),r}function Vi(e){const t=e;if(!t)return{};if("string"==typeof t)return{error:()=>t};if(void 0!==t?.message){if(void 0!==t?.error)throw new Error("Cannot specify both `message` and `error` params");t.error=t.message}return delete t.message,"string"==typeof t.error?{...t,error:()=>t.error}:t}const qi={safeint:[Number.MIN_SAFE_INTEGER,Number.MAX_SAFE_INTEGER],int32:[-2147483648,2147483647],uint32:[0,4294967295],float32:[-34028234663852886e22,34028234663852886e22],float64:[-Number.MAX_VALUE,Number.MAX_VALUE]};function Mi(e,t=0){if(!0===e.aborted)return!0;for(let n=t;n<e.issues.length;n++)if(!0!==e.issues[n]?.continue)return!0;return!1}function Ki(e,t){return t.map(t=>{var n;return(n=t).path??(n.path=[]),t.path.unshift(e),t})}function Ji(e){return"string"==typeof e?e:e?.message}function Wi(e,t,n){const r={...e,path:e.path??[]};if(!e.message){const o=Ji(e.inst?._zod.def?.error?.(e))??Ji(t?.error?.(e))??Ji(n.customError?.(e))??Ji(n.localeError?.(e))??"Invalid input";r.message=o}return delete r.inst,delete r.continue,t?.reportInput||delete r.input,r}function Gi(e){return Array.isArray(e)?"array":"string"==typeof e?"string":"unknown"}function Yi(...e){const[t,n,r]=e;return"string"==typeof t?{message:t,code:"custom",input:n,inst:r}:{...t}}const Xi=(e,t)=>{e.name="$ZodError",Object.defineProperty(e,"_zod",{value:e._zod,enumerable:!1}),Object.defineProperty(e,"issues",{value:t,enumerable:!1}),e.message=JSON.stringify(t,Si,2),Object.defineProperty(e,"toString",{value:()=>e.message,enumerable:!1})},Qi=bi("$ZodError",Xi),es=bi("$ZodError",Xi,{Parent:Error});const ts=e=>(t,n,r,o)=>{const i=r?Object.assign(r,{async:!1}):{async:!1},s=t._zod.run({value:n,issues:[]},i);if(s instanceof Promise)throw new Ei;if(s.issues.length){const t=new(o?.Err??e)(s.issues.map(e=>Wi(e,i,Oi())));throw Ri(t,o?.callee),t}return s.value},ns=e=>async(t,n,r,o)=>{const i=r?Object.assign(r,{async:!0}):{async:!0};let s=t._zod.run({value:n,issues:[]},i);if(s instanceof Promise&&(s=await s),s.issues.length){const t=new(o?.Err??e)(s.issues.map(e=>Wi(e,i,Oi())));throw Ri(t,o?.callee),t}return s.value},rs=e=>(t,n,r)=>{const o=r?{...r,async:!1}:{async:!1},i=t._zod.run({value:n,issues:[]},o);if(i instanceof Promise)throw new Ei;return i.issues.length?{success:!1,error:new(e??Qi)(i.issues.map(e=>Wi(e,o,Oi())))}:{success:!0,data:i.value}},os=rs(es),is=e=>async(t,n,r)=>{const o=r?Object.assign(r,{async:!0}):{async:!0};let i=t._zod.run({value:n,issues:[]},o);return i instanceof Promise&&(i=await i),i.issues.length?{success:!1,error:new e(i.issues.map(e=>Wi(e,o,Oi())))}:{success:!0,data:i.value}},ss=is(es),as=e=>(t,n,r)=>{const o=r?Object.assign(r,{direction:"backward"}):{direction:"backward"};return ts(e)(t,n,o)},cs=e=>(t,n,r)=>ts(e)(t,n,r),us=e=>async(t,n,r)=>{const o=r?Object.assign(r,{direction:"backward"}):{direction:"backward"};return ns(e)(t,n,o)},fs=e=>async(t,n,r)=>ns(e)(t,n,r),ds=e=>(t,n,r)=>{const o=r?Object.assign(r,{direction:"backward"}):{direction:"backward"};return rs(e)(t,n,o)},ls=e=>(t,n,r)=>rs(e)(t,n,r),ps=e=>async(t,n,r)=>{const o=r?Object.assign(r,{direction:"backward"}):{direction:"backward"};return is(e)(t,n,o)},hs=e=>async(t,n,r)=>is(e)(t,n,r),ms=/^[cC][^\s-]{8,}$/,gs=/^[0-9a-z]+$/,ys=/^[0-9A-HJKMNP-TV-Za-hjkmnp-tv-z]{26}$/,_s=/^[0-9a-vA-V]{20}$/,ws=/^[A-Za-z0-9]{27}$/,vs=/^[a-zA-Z0-9_-]{21}$/,bs=/^P(?:(\d+W)|(?!.*W)(?=\d|T\d)(\d+Y)?(\d+M)?(\d+D)?(T(?=\d)(\d+H)?(\d+M)?(\d+([.,]\d+)?S)?)?)$/,Es=/^([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12})$/,xs=e=>e?new RegExp(`^([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-${e}[0-9a-fA-F]{3}-[89abAB][0-9a-fA-F]{3}-[0-9a-fA-F]{12})$`):/^([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[1-8][0-9a-fA-F]{3}-[89abAB][0-9a-fA-F]{3}-[0-9a-fA-F]{12}|00000000-0000-0000-0000-000000000000|ffffffff-ffff-ffff-ffff-ffffffffffff)$/,zs=/^(?!\.)(?!.*\.\.)([A-Za-z0-9_'+\-\.]*)[A-Za-z0-9_+-]@([A-Za-z0-9][A-Za-z0-9\-]*\.)+[A-Za-z]{2,}$/;const Os=/^(?:(?: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])$/,ks=/^(([0-9a-fA-F]{1,4}:){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}|:))$/,Ss=/^((25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\.){3}(25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\/([0-9]|[1-2][0-9]|3[0-2])$/,Ps=/^(([0-9a-fA-F]{1,4}:){7}[0-9a-fA-F]{1,4}|::|([0-9a-fA-F]{1,4})?::([0-9a-fA-F]{1,4}:?){0,6})\/(12[0-8]|1[01][0-9]|[1-9]?[0-9])$/,$s=/^$|^(?:[0-9a-zA-Z+/]{4})*(?:(?:[0-9a-zA-Z+/]{2}==)|(?:[0-9a-zA-Z+/]{3}=))?$/,As=/^[A-Za-z0-9_-]*$/,Is=/^\+[1-9]\d{6,14}$/,Ts="(?:(?:\\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])))",Ns=new RegExp(`^${Ts}$`);function Bs(e){const t="(?:[01]\\d|2[0-3]):[0-5]\\d";return"number"==typeof e.precision?-1===e.precision?`${t}`:0===e.precision?`${t}:[0-5]\\d`:`${t}:[0-5]\\d\\.\\d{${e.precision}}`:`${t}(?::[0-5]\\d(?:\\.\\d+)?)?`}const Us=/^-?\d+n?$/,Rs=/^-?\d+$/,js=/^-?\d+(?:\.\d+)?$/,Zs=/^(?:true|false)$/i,Cs=/^null$/i,Fs=/^[^A-Z]*$/,Hs=/^[^a-z]*$/,Ds=bi("$ZodCheck",(e,t)=>{var n;e._zod??(e._zod={}),e._zod.def=t,(n=e._zod).onattach??(n.onattach=[])}),Ls={number:"number",bigint:"bigint",object:"date"},Vs=bi("$ZodCheckLessThan",(e,t)=>{Ds.init(e,t);const n=Ls[typeof t.value];e._zod.onattach.push(e=>{const n=e._zod.bag,r=(t.inclusive?n.maximum:n.exclusiveMaximum)??Number.POSITIVE_INFINITY;t.value<r&&(t.inclusive?n.maximum=t.value:n.exclusiveMaximum=t.value)}),e._zod.check=r=>{(t.inclusive?r.value<=t.value:r.value<t.value)||r.issues.push({origin:n,code:"too_big",maximum:"object"==typeof t.value?t.value.getTime():t.value,input:r.value,inclusive:t.inclusive,inst:e,continue:!t.abort})}}),qs=bi("$ZodCheckGreaterThan",(e,t)=>{Ds.init(e,t);const n=Ls[typeof t.value];e._zod.onattach.push(e=>{const n=e._zod.bag,r=(t.inclusive?n.minimum:n.exclusiveMinimum)??Number.NEGATIVE_INFINITY;t.value>r&&(t.inclusive?n.minimum=t.value:n.exclusiveMinimum=t.value)}),e._zod.check=r=>{(t.inclusive?r.value>=t.value:r.value>t.value)||r.issues.push({origin:n,code:"too_small",minimum:"object"==typeof t.value?t.value.getTime():t.value,input:r.value,inclusive:t.inclusive,inst:e,continue:!t.abort})}}),Ms=bi("$ZodCheckMultipleOf",(e,t)=>{Ds.init(e,t),e._zod.onattach.push(e=>{var n;(n=e._zod.bag).multipleOf??(n.multipleOf=t.value)}),e._zod.check=n=>{if(typeof n.value!=typeof t.value)throw new Error("Cannot mix number and bigint in multiple_of check.");("bigint"==typeof n.value?n.value%t.value===BigInt(0):0===function(e,t){const n=(e.toString().split(".")[1]||"").length,r=t.toString();let o=(r.split(".")[1]||"").length;if(0===o&&/\d?e-\d?/.test(r)){const e=r.match(/\d?e-(\d?)/);e?.[1]&&(o=Number.parseInt(e[1]))}const i=n>o?n:o;return Number.parseInt(e.toFixed(i).replace(".",""))%Number.parseInt(t.toFixed(i).replace(".",""))/10**i}(n.value,t.value))||n.issues.push({origin:typeof n.value,code:"not_multiple_of",divisor:t.value,input:n.value,inst:e,continue:!t.abort})}}),Ks=bi("$ZodCheckNumberFormat",(e,t)=>{Ds.init(e,t),t.format=t.format||"float64";const n=t.format?.includes("int"),r=n?"int":"number",[o,i]=qi[t.format];e._zod.onattach.push(e=>{const r=e._zod.bag;r.format=t.format,r.minimum=o,r.maximum=i,n&&(r.pattern=Rs)}),e._zod.check=s=>{const a=s.value;if(n){if(!Number.isInteger(a))return void s.issues.push({expected:r,format:t.format,code:"invalid_type",continue:!1,input:a,inst:e});if(!Number.isSafeInteger(a))return void(a>0?s.issues.push({input:a,code:"too_big",maximum:Number.MAX_SAFE_INTEGER,note:"Integers must be within the safe integer range.",inst:e,origin:r,inclusive:!0,continue:!t.abort}):s.issues.push({input:a,code:"too_small",minimum:Number.MIN_SAFE_INTEGER,note:"Integers must be within the safe integer range.",inst:e,origin:r,inclusive:!0,continue:!t.abort}))}a<o&&s.issues.push({origin:"number",input:a,code:"too_small",minimum:o,inclusive:!0,inst:e,continue:!t.abort}),a>i&&s.issues.push({origin:"number",input:a,code:"too_big",maximum:i,inclusive:!0,inst:e,continue:!t.abort})}}),Js=bi("$ZodCheckMaxLength",(e,t)=>{var n;Ds.init(e,t),(n=e._zod.def).when??(n.when=e=>{const t=e.value;return!$i(t)&&void 0!==t.length}),e._zod.onattach.push(e=>{const n=e._zod.bag.maximum??Number.POSITIVE_INFINITY;t.maximum<n&&(e._zod.bag.maximum=t.maximum)}),e._zod.check=n=>{const r=n.value;if(r.length<=t.maximum)return;const o=Gi(r);n.issues.push({origin:o,code:"too_big",maximum:t.maximum,inclusive:!0,input:r,inst:e,continue:!t.abort})}}),Ws=bi("$ZodCheckMinLength",(e,t)=>{var n;Ds.init(e,t),(n=e._zod.def).when??(n.when=e=>{const t=e.value;return!$i(t)&&void 0!==t.length}),e._zod.onattach.push(e=>{const n=e._zod.bag.minimum??Number.NEGATIVE_INFINITY;t.minimum>n&&(e._zod.bag.minimum=t.minimum)}),e._zod.check=n=>{const r=n.value;if(r.length>=t.minimum)return;const o=Gi(r);n.issues.push({origin:o,code:"too_small",minimum:t.minimum,inclusive:!0,input:r,inst:e,continue:!t.abort})}}),Gs=bi("$ZodCheckLengthEquals",(e,t)=>{var n;Ds.init(e,t),(n=e._zod.def).when??(n.when=e=>{const t=e.value;return!$i(t)&&void 0!==t.length}),e._zod.onattach.push(e=>{const n=e._zod.bag;n.minimum=t.length,n.maximum=t.length,n.length=t.length}),e._zod.check=n=>{const r=n.value,o=r.length;if(o===t.length)return;const i=Gi(r),s=o>t.length;n.issues.push({origin:i,...s?{code:"too_big",maximum:t.length}:{code:"too_small",minimum:t.length},inclusive:!0,exact:!0,input:n.value,inst:e,continue:!t.abort})}}),Ys=bi("$ZodCheckStringFormat",(e,t)=>{var n,r;Ds.init(e,t),e._zod.onattach.push(e=>{const n=e._zod.bag;n.format=t.format,t.pattern&&(n.patterns??(n.patterns=new Set),n.patterns.add(t.pattern))}),t.pattern?(n=e._zod).check??(n.check=n=>{t.pattern.lastIndex=0,t.pattern.test(n.value)||n.issues.push({origin:"string",code:"invalid_format",format:t.format,input:n.value,...t.pattern?{pattern:t.pattern.toString()}:{},inst:e,continue:!t.abort})}):(r=e._zod).check??(r.check=()=>{})}),Xs=bi("$ZodCheckRegex",(e,t)=>{Ys.init(e,t),e._zod.check=n=>{t.pattern.lastIndex=0,t.pattern.test(n.value)||n.issues.push({origin:"string",code:"invalid_format",format:"regex",input:n.value,pattern:t.pattern.toString(),inst:e,continue:!t.abort})}}),Qs=bi("$ZodCheckLowerCase",(e,t)=>{t.pattern??(t.pattern=Fs),Ys.init(e,t)}),ea=bi("$ZodCheckUpperCase",(e,t)=>{t.pattern??(t.pattern=Hs),Ys.init(e,t)}),ta=bi("$ZodCheckIncludes",(e,t)=>{Ds.init(e,t);const n=Di(t.includes),r=new RegExp("number"==typeof t.position?`^.{${t.position}}${n}`:n);t.pattern=r,e._zod.onattach.push(e=>{const t=e._zod.bag;t.patterns??(t.patterns=new Set),t.patterns.add(r)}),e._zod.check=n=>{n.value.includes(t.includes,t.position)||n.issues.push({origin:"string",code:"invalid_format",format:"includes",includes:t.includes,input:n.value,inst:e,continue:!t.abort})}}),na=bi("$ZodCheckStartsWith",(e,t)=>{Ds.init(e,t);const n=new RegExp(`^${Di(t.prefix)}.*`);t.pattern??(t.pattern=n),e._zod.onattach.push(e=>{const t=e._zod.bag;t.patterns??(t.patterns=new Set),t.patterns.add(n)}),e._zod.check=n=>{n.value.startsWith(t.prefix)||n.issues.push({origin:"string",code:"invalid_format",format:"starts_with",prefix:t.prefix,input:n.value,inst:e,continue:!t.abort})}}),ra=bi("$ZodCheckEndsWith",(e,t)=>{Ds.init(e,t);const n=new RegExp(`.*${Di(t.suffix)}$`);t.pattern??(t.pattern=n),e._zod.onattach.push(e=>{const t=e._zod.bag;t.patterns??(t.patterns=new Set),t.patterns.add(n)}),e._zod.check=n=>{n.value.endsWith(t.suffix)||n.issues.push({origin:"string",code:"invalid_format",format:"ends_with",suffix:t.suffix,input:n.value,inst:e,continue:!t.abort})}}),oa=bi("$ZodCheckOverwrite",(e,t)=>{Ds.init(e,t),e._zod.check=e=>{e.value=t.tx(e.value)}});class ia{constructor(e=[]){this.content=[],this.indent=0,this&&(this.args=e)}indented(e){this.indent+=1,e(this),this.indent-=1}write(e){if("function"==typeof e)return e(this,{execution:"sync"}),void e(this,{execution:"async"});const t=e.split("\n").filter(e=>e),n=Math.min(...t.map(e=>e.length-e.trimStart().length)),r=t.map(e=>e.slice(n)).map(e=>" ".repeat(2*this.indent)+e);for(const e of r)this.content.push(e)}compile(){const e=Function,t=this?.args;return new e(...t,[...(this?.content??[""]).map(e=>` ${e}`)].join("\n"))}}const sa={major:4,minor:3,patch:5},aa=bi("$ZodType",(e,t)=>{var n;e??(e={}),e._zod.def=t,e._zod.bag=e._zod.bag||{},e._zod.version=sa;const r=[...e._zod.def.checks??[]];e._zod.traits.has("$ZodCheck")&&r.unshift(e);for(const t of r)for(const n of t._zod.onattach)n(e);if(0===r.length)(n=e._zod).deferred??(n.deferred=[]),e._zod.deferred?.push(()=>{e._zod.run=e._zod.parse});else{const t=(e,t,n)=>{let r,o=Mi(e);for(const i of t){if(i._zod.def.when){if(!i._zod.def.when(e))continue}else if(o)continue;const t=e.issues.length,s=i._zod.check(e);if(s instanceof Promise&&!1===n?.async)throw new Ei;if(r||s instanceof Promise)r=(r??Promise.resolve()).then(async()=>{await s;e.issues.length!==t&&(o||(o=Mi(e,t)))});else{if(e.issues.length===t)continue;o||(o=Mi(e,t))}}return r?r.then(()=>e):e},n=(n,o,i)=>{if(Mi(n))return n.aborted=!0,n;const s=t(o,r,i);if(s instanceof Promise){if(!1===i.async)throw new Ei;return s.then(t=>e._zod.parse(t,i))}return e._zod.parse(s,i)};e._zod.run=(o,i)=>{if(i.skipChecks)return e._zod.parse(o,i);if("backward"===i.direction){const t=e._zod.parse({value:o.value,issues:[]},{...i,skipChecks:!0});return t instanceof Promise?t.then(e=>n(e,o,i)):n(t,o,i)}const s=e._zod.parse(o,i);if(s instanceof Promise){if(!1===i.async)throw new Ei;return s.then(e=>t(e,r,i))}return t(s,r,i)}}Ti(e,"~standard",()=>({validate:t=>{try{const n=os(e,t);return n.success?{value:n.data}:{issues:n.error?.issues}}catch(n){return ss(e,t).then(e=>e.success?{value:e.data}:{issues:e.error?.issues})}},vendor:"zod",version:1}))}),ca=bi("$ZodString",(e,t)=>{var n;aa.init(e,t),e._zod.pattern=[...e?._zod.bag?.patterns??[]].pop()??(n=e._zod.bag,new RegExp(`^${n?`[\\s\\S]{${n?.minimum??0},${n?.maximum??""}}`:"[\\s\\S]*"}$`)),e._zod.parse=(n,r)=>{if(t.coerce)try{n.value=String(n.value)}catch(r){}return"string"==typeof n.value||n.issues.push({expected:"string",code:"invalid_type",input:n.value,inst:e}),n}}),ua=bi("$ZodStringFormat",(e,t)=>{Ys.init(e,t),ca.init(e,t)}),fa=bi("$ZodGUID",(e,t)=>{t.pattern??(t.pattern=Es),ua.init(e,t)}),da=bi("$ZodUUID",(e,t)=>{if(t.version){const e={v1:1,v2:2,v3:3,v4:4,v5:5,v6:6,v7:7,v8:8}[t.version];if(void 0===e)throw new Error(`Invalid UUID version: "${t.version}"`);t.pattern??(t.pattern=xs(e))}else t.pattern??(t.pattern=xs());ua.init(e,t)}),la=bi("$ZodEmail",(e,t)=>{t.pattern??(t.pattern=zs),ua.init(e,t)}),pa=bi("$ZodURL",(e,t)=>{ua.init(e,t),e._zod.check=n=>{try{const r=n.value.trim(),o=new URL(r);return t.hostname&&(t.hostname.lastIndex=0,t.hostname.test(o.hostname)||n.issues.push({code:"invalid_format",format:"url",note:"Invalid hostname",pattern:t.hostname.source,input:n.value,inst:e,continue:!t.abort})),t.protocol&&(t.protocol.lastIndex=0,t.protocol.test(o.protocol.endsWith(":")?o.protocol.slice(0,-1):o.protocol)||n.issues.push({code:"invalid_format",format:"url",note:"Invalid protocol",pattern:t.protocol.source,input:n.value,inst:e,continue:!t.abort})),void(t.normalize?n.value=o.href:n.value=r)}catch(r){n.issues.push({code:"invalid_format",format:"url",input:n.value,inst:e,continue:!t.abort})}}}),ha=bi("$ZodEmoji",(e,t)=>{t.pattern??(t.pattern=new RegExp("^(\\p{Extended_Pictographic}|\\p{Emoji_Component})+$","u")),ua.init(e,t)}),ma=bi("$ZodNanoID",(e,t)=>{t.pattern??(t.pattern=vs),ua.init(e,t)}),ga=bi("$ZodCUID",(e,t)=>{t.pattern??(t.pattern=ms),ua.init(e,t)}),ya=bi("$ZodCUID2",(e,t)=>{t.pattern??(t.pattern=gs),ua.init(e,t)}),_a=bi("$ZodULID",(e,t)=>{t.pattern??(t.pattern=ys),ua.init(e,t)}),wa=bi("$ZodXID",(e,t)=>{t.pattern??(t.pattern=_s),ua.init(e,t)}),va=bi("$ZodKSUID",(e,t)=>{t.pattern??(t.pattern=ws),ua.init(e,t)}),ba=bi("$ZodISODateTime",(e,t)=>{t.pattern??(t.pattern=function(e){const t=Bs({precision:e.precision}),n=["Z"];e.local&&n.push(""),e.offset&&n.push("([+-](?:[01]\\d|2[0-3]):[0-5]\\d)");const r=`${t}(?:${n.join("|")})`;return new RegExp(`^${Ts}T(?:${r})$`)}(t)),ua.init(e,t)}),Ea=bi("$ZodISODate",(e,t)=>{t.pattern??(t.pattern=Ns),ua.init(e,t)}),xa=bi("$ZodISOTime",(e,t)=>{t.pattern??(t.pattern=new RegExp(`^${Bs(t)}$`)),ua.init(e,t)}),za=bi("$ZodISODuration",(e,t)=>{t.pattern??(t.pattern=bs),ua.init(e,t)}),Oa=bi("$ZodIPv4",(e,t)=>{t.pattern??(t.pattern=Os),ua.init(e,t),e._zod.bag.format="ipv4"}),ka=bi("$ZodIPv6",(e,t)=>{t.pattern??(t.pattern=ks),ua.init(e,t),e._zod.bag.format="ipv6",e._zod.check=n=>{try{new URL(`http://[${n.value}]`)}catch{n.issues.push({code:"invalid_format",format:"ipv6",input:n.value,inst:e,continue:!t.abort})}}}),Sa=bi("$ZodCIDRv4",(e,t)=>{t.pattern??(t.pattern=Ss),ua.init(e,t)}),Pa=bi("$ZodCIDRv6",(e,t)=>{t.pattern??(t.pattern=Ps),ua.init(e,t),e._zod.check=n=>{const r=n.value.split("/");try{if(2!==r.length)throw new Error;const[e,t]=r;if(!t)throw new Error;const n=Number(t);if(`${n}`!==t)throw new Error;if(n<0||n>128)throw new Error;new URL(`http://[${e}]`)}catch{n.issues.push({code:"invalid_format",format:"cidrv6",input:n.value,inst:e,continue:!t.abort})}}});function $a(e){if(""===e)return!0;if(e.length%4!=0)return!1;try{return atob(e),!0}catch{return!1}}const Aa=bi("$ZodBase64",(e,t)=>{t.pattern??(t.pattern=$s),ua.init(e,t),e._zod.bag.contentEncoding="base64",e._zod.check=n=>{$a(n.value)||n.issues.push({code:"invalid_format",format:"base64",input:n.value,inst:e,continue:!t.abort})}});const Ia=bi("$ZodBase64URL",(e,t)=>{t.pattern??(t.pattern=As),ua.init(e,t),e._zod.bag.contentEncoding="base64url",e._zod.check=n=>{(function(e){if(!As.test(e))return!1;const t=e.replace(/[-_]/g,e=>"-"===e?"+":"/");return $a(t.padEnd(4*Math.ceil(t.length/4),"="))})(n.value)||n.issues.push({code:"invalid_format",format:"base64url",input:n.value,inst:e,continue:!t.abort})}}),Ta=bi("$ZodE164",(e,t)=>{t.pattern??(t.pattern=Is),ua.init(e,t)});const Na=bi("$ZodJWT",(e,t)=>{ua.init(e,t),e._zod.check=n=>{(function(e,t=null){try{const n=e.split(".");if(3!==n.length)return!1;const[r]=n;if(!r)return!1;const o=JSON.parse(atob(r));return!("typ"in o&&"JWT"!==o?.typ||!o.alg||t&&(!("alg"in o)||o.alg!==t))}catch{return!1}})(n.value,t.alg)||n.issues.push({code:"invalid_format",format:"jwt",input:n.value,inst:e,continue:!t.abort})}}),Ba=bi("$ZodNumber",(e,t)=>{aa.init(e,t),e._zod.pattern=e._zod.bag.pattern??js,e._zod.parse=(n,r)=>{if(t.coerce)try{n.value=Number(n.value)}catch(e){}const o=n.value;if("number"==typeof o&&!Number.isNaN(o)&&Number.isFinite(o))return n;const i="number"==typeof o?Number.isNaN(o)?"NaN":Number.isFinite(o)?void 0:"Infinity":void 0;return n.issues.push({expected:"number",code:"invalid_type",input:o,inst:e,...i?{received:i}:{}}),n}}),Ua=bi("$ZodNumberFormat",(e,t)=>{Ks.init(e,t),Ba.init(e,t)}),Ra=bi("$ZodBoolean",(e,t)=>{aa.init(e,t),e._zod.pattern=Zs,e._zod.parse=(n,r)=>{if(t.coerce)try{n.value=Boolean(n.value)}catch(e){}const o=n.value;return"boolean"==typeof o||n.issues.push({expected:"boolean",code:"invalid_type",input:o,inst:e}),n}}),ja=bi("$ZodBigInt",(e,t)=>{aa.init(e,t),e._zod.pattern=Us,e._zod.parse=(n,r)=>{if(t.coerce)try{n.value=BigInt(n.value)}catch(e){}return"bigint"==typeof n.value||n.issues.push({expected:"bigint",code:"invalid_type",input:n.value,inst:e}),n}}),Za=bi("$ZodNull",(e,t)=>{aa.init(e,t),e._zod.pattern=Cs,e._zod.values=new Set([null]),e._zod.parse=(t,n)=>{const r=t.value;return null===r||t.issues.push({expected:"null",code:"invalid_type",input:r,inst:e}),t}}),Ca=bi("$ZodUnknown",(e,t)=>{aa.init(e,t),e._zod.parse=e=>e}),Fa=bi("$ZodNever",(e,t)=>{aa.init(e,t),e._zod.parse=(t,n)=>(t.issues.push({expected:"never",code:"invalid_type",input:t.value,inst:e}),t)});function Ha(e,t,n){e.issues.length&&t.issues.push(...Ki(n,e.issues)),t.value[n]=e.value}const Da=bi("$ZodArray",(e,t)=>{aa.init(e,t),e._zod.parse=(n,r)=>{const o=n.value;if(!Array.isArray(o))return n.issues.push({expected:"array",code:"invalid_type",input:o,inst:e}),n;n.value=Array(o.length);const i=[];for(let e=0;e<o.length;e++){const s=o[e],a=t.element._zod.run({value:s,issues:[]},r);a instanceof Promise?i.push(a.then(t=>Ha(t,n,e))):Ha(a,n,e)}return i.length?Promise.all(i).then(()=>n):n}});function La(e,t,n,r,o){if(e.issues.length){if(o&&!(n in r))return;t.issues.push(...Ki(n,e.issues))}void 0===e.value?n in r&&(t.value[n]=void 0):t.value[n]=e.value}function Va(e){const t=Object.keys(e.shape);for(const n of t)if(!e.shape?.[n]?._zod?.traits?.has("$ZodType"))throw new Error(`Invalid element at key "${n}": expected a Zod schema`);const n=(r=e.shape,Object.keys(r).filter(e=>"optional"===r[e]._zod.optin&&"optional"===r[e]._zod.optout));var r;return{...e,keys:t,keySet:new Set(t),numKeys:t.length,optionalKeys:new Set(n)}}function qa(e,t,n,r,o,i){const s=[],a=o.keySet,c=o.catchall._zod,u=c.def.type,f="optional"===c.optout;for(const o in t){if(a.has(o))continue;if("never"===u){s.push(o);continue}const i=c.run({value:t[o],issues:[]},r);i instanceof Promise?e.push(i.then(e=>La(e,n,o,t,f))):La(i,n,o,t,f)}return s.length&&n.issues.push({code:"unrecognized_keys",keys:s,input:t,inst:i}),e.length?Promise.all(e).then(()=>n):n}const Ma=bi("$ZodObject",(e,t)=>{aa.init(e,t);const n=Object.getOwnPropertyDescriptor(t,"shape");if(!n?.get){const e=t.shape;Object.defineProperty(t,"shape",{get:()=>{const n={...e};return Object.defineProperty(t,"shape",{value:n}),n}})}const r=Pi(()=>Va(t));Ti(e._zod,"propValues",()=>{const e=t.shape,n={};for(const t in e){const r=e[t]._zod;if(r.values){n[t]??(n[t]=new Set);for(const e of r.values)n[t].add(e)}}return n});const o=ji,i=t.catchall;let s;e._zod.parse=(t,n)=>{s??(s=r.value);const a=t.value;if(!o(a))return t.issues.push({expected:"object",code:"invalid_type",input:a,inst:e}),t;t.value={};const c=[],u=s.shape;for(const e of s.keys){const r=u[e],o="optional"===r._zod.optout,i=r._zod.run({value:a[e],issues:[]},n);i instanceof Promise?c.push(i.then(n=>La(n,t,e,a,o))):La(i,t,e,a,o)}return i?qa(c,a,t,n,r.value,e):c.length?Promise.all(c).then(()=>t):t}}),Ka=bi("$ZodObjectJIT",(e,t)=>{Ma.init(e,t);const n=e._zod.parse,r=Pi(()=>Va(t));let o;const i=ji,s=!zi.jitless,a=s&&Zi.value,c=t.catchall;let u;e._zod.parse=(f,d)=>{u??(u=r.value);const l=f.value;return i(l)?s&&a&&!1===d?.async&&!0!==d.jitless?(o||(o=(e=>{const t=new ia(["shape","payload","ctx"]),n=r.value,o=e=>{const t=Ui(e);return`shape[${t}]._zod.run({ value: input[${t}], issues: [] }, ctx)`};t.write("const input = payload.value;");const i=Object.create(null);let s=0;for(const e of n.keys)i[e]="key_"+s++;t.write("const newResult = {};");for(const r of n.keys){const n=i[r],s=Ui(r),a=e[r],c="optional"===a?._zod?.optout;t.write(`const ${n} = ${o(r)};`),c?t.write(`\n if (${n}.issues.length) {\n if (${s} in input) {\n payload.issues = payload.issues.concat(${n}.issues.map(iss => ({\n ...iss,\n path: iss.path ? [${s}, ...iss.path] : [${s}]\n })));\n }\n }\n \n if (${n}.value === undefined) {\n if (${s} in input) {\n newResult[${s}] = undefined;\n }\n } else {\n newResult[${s}] = ${n}.value;\n }\n \n `):t.write(`\n if (${n}.issues.length) {\n payload.issues = payload.issues.concat(${n}.issues.map(iss => ({\n ...iss,\n path: iss.path ? [${s}, ...iss.path] : [${s}]\n })));\n }\n \n if (${n}.value === undefined) {\n if (${s} in input) {\n newResult[${s}] = undefined;\n }\n } else {\n newResult[${s}] = ${n}.value;\n }\n \n `)}t.write("payload.value = newResult;"),t.write("return payload;");const a=t.compile();return(t,n)=>a(e,t,n)})(t.shape)),f=o(f,d),c?qa([],l,f,d,u,e):f):n(f,d):(f.issues.push({expected:"object",code:"invalid_type",input:l,inst:e}),f)}});function Ja(e,t,n,r){for(const n of e)if(0===n.issues.length)return t.value=n.value,t;const o=e.filter(e=>!Mi(e));return 1===o.length?(t.value=o[0].value,o[0]):(t.issues.push({code:"invalid_union",input:t.value,inst:n,errors:e.map(e=>e.issues.map(e=>Wi(e,r,Oi())))}),t)}const Wa=bi("$ZodUnion",(e,t)=>{aa.init(e,t),Ti(e._zod,"optin",()=>t.options.some(e=>"optional"===e._zod.optin)?"optional":void 0),Ti(e._zod,"optout",()=>t.options.some(e=>"optional"===e._zod.optout)?"optional":void 0),Ti(e._zod,"values",()=>{if(t.options.every(e=>e._zod.values))return new Set(t.options.flatMap(e=>Array.from(e._zod.values)))}),Ti(e._zod,"pattern",()=>{if(t.options.every(e=>e._zod.pattern)){const e=t.options.map(e=>e._zod.pattern);return new RegExp(`^(${e.map(e=>Ai(e.source)).join("|")})$`)}});const n=1===t.options.length,r=t.options[0]._zod.run;e._zod.parse=(o,i)=>{if(n)return r(o,i);let s=!1;const a=[];for(const e of t.options){const t=e._zod.run({value:o.value,issues:[]},i);if(t instanceof Promise)a.push(t),s=!0;else{if(0===t.issues.length)return t;a.push(t)}}return s?Promise.all(a).then(t=>Ja(t,o,e,i)):Ja(a,o,e,i)}}),Ga=bi("$ZodIntersection",(e,t)=>{aa.init(e,t),e._zod.parse=(e,n)=>{const r=e.value,o=t.left._zod.run({value:r,issues:[]},n),i=t.right._zod.run({value:r,issues:[]},n);return o instanceof Promise||i instanceof Promise?Promise.all([o,i]).then(([t,n])=>Xa(e,t,n)):Xa(e,o,i)}});function Ya(e,t){if(e===t)return{valid:!0,data:e};if(e instanceof Date&&t instanceof Date&&+e===+t)return{valid:!0,data:e};if(Ci(e)&&Ci(t)){const n=Object.keys(t),r=Object.keys(e).filter(e=>-1!==n.indexOf(e)),o={...e,...t};for(const n of r){const r=Ya(e[n],t[n]);if(!r.valid)return{valid:!1,mergeErrorPath:[n,...r.mergeErrorPath]};o[n]=r.data}return{valid:!0,data:o}}if(Array.isArray(e)&&Array.isArray(t)){if(e.length!==t.length)return{valid:!1,mergeErrorPath:[]};const n=[];for(let r=0;r<e.length;r++){const o=Ya(e[r],t[r]);if(!o.valid)return{valid:!1,mergeErrorPath:[r,...o.mergeErrorPath]};n.push(o.data)}return{valid:!0,data:n}}return{valid:!1,mergeErrorPath:[]}}function Xa(e,t,n){const r=new Map;let o;for(const n of t.issues)if("unrecognized_keys"===n.code){o??(o=n);for(const e of n.keys)r.has(e)||r.set(e,{}),r.get(e).l=!0}else e.issues.push(n);for(const t of n.issues)if("unrecognized_keys"===t.code)for(const e of t.keys)r.has(e)||r.set(e,{}),r.get(e).r=!0;else e.issues.push(t);const i=[...r].filter(([,e])=>e.l&&e.r).map(([e])=>e);if(i.length&&o&&e.issues.push({...o,keys:i}),Mi(e))return e;const s=Ya(t.value,n.value);if(!s.valid)throw new Error(`Unmergable intersection. Error path: ${JSON.stringify(s.mergeErrorPath)}`);return e.value=s.data,e}const Qa=bi("$ZodRecord",(e,t)=>{aa.init(e,t),e._zod.parse=(n,r)=>{const o=n.value;if(!Ci(o))return n.issues.push({expected:"record",code:"invalid_type",input:o,inst:e}),n;const i=[],s=t.keyType._zod.values;if(s){n.value={};const a=new Set;for(const e of s)if("string"==typeof e||"number"==typeof e||"symbol"==typeof e){a.add("number"==typeof e?e.toString():e);const s=t.valueType._zod.run({value:o[e],issues:[]},r);s instanceof Promise?i.push(s.then(t=>{t.issues.length&&n.issues.push(...Ki(e,t.issues)),n.value[e]=t.value})):(s.issues.length&&n.issues.push(...Ki(e,s.issues)),n.value[e]=s.value)}let c;for(const e in o)a.has(e)||(c=c??[],c.push(e));c&&c.length>0&&n.issues.push({code:"unrecognized_keys",input:o,inst:e,keys:c})}else{n.value={};for(const s of Reflect.ownKeys(o)){if("__proto__"===s)continue;let a=t.keyType._zod.run({value:s,issues:[]},r);if(a instanceof Promise)throw new Error("Async schemas not supported in object keys currently");if("string"==typeof s&&js.test(s)&&a.issues.length&&a.issues.some(e=>"invalid_type"===e.code&&"number"===e.expected)){const e=t.keyType._zod.run({value:Number(s),issues:[]},r);if(e instanceof Promise)throw new Error("Async schemas not supported in object keys currently");0===e.issues.length&&(a=e)}if(a.issues.length){"loose"===t.mode?n.value[s]=o[s]:n.issues.push({code:"invalid_key",origin:"record",issues:a.issues.map(e=>Wi(e,r,Oi())),input:s,path:[s],inst:e});continue}const c=t.valueType._zod.run({value:o[s],issues:[]},r);c instanceof Promise?i.push(c.then(e=>{e.issues.length&&n.issues.push(...Ki(s,e.issues)),n.value[a.value]=e.value})):(c.issues.length&&n.issues.push(...Ki(s,c.issues)),n.value[a.value]=c.value)}}return i.length?Promise.all(i).then(()=>n):n}}),ec=bi("$ZodEnum",(e,t)=>{aa.init(e,t);const n=ki(t.entries),r=new Set(n);e._zod.values=r,e._zod.pattern=new RegExp(`^(${n.filter(e=>Hi.has(typeof e)).map(e=>"string"==typeof e?Di(e):e.toString()).join("|")})$`),e._zod.parse=(t,o)=>{const i=t.value;return r.has(i)||t.issues.push({code:"invalid_value",values:n,input:i,inst:e}),t}}),tc=bi("$ZodTransform",(e,t)=>{aa.init(e,t),e._zod.parse=(n,r)=>{if("backward"===r.direction)throw new xi(e.constructor.name);const o=t.transform(n.value,n);if(r.async){return(o instanceof Promise?o:Promise.resolve(o)).then(e=>(n.value=e,n))}if(o instanceof Promise)throw new Ei;return n.value=o,n}});function nc(e,t){return e.issues.length&&void 0===t?{issues:[],value:void 0}:e}const rc=bi("$ZodOptional",(e,t)=>{aa.init(e,t),e._zod.optin="optional",e._zod.optout="optional",Ti(e._zod,"values",()=>t.innerType._zod.values?new Set([...t.innerType._zod.values,void 0]):void 0),Ti(e._zod,"pattern",()=>{const e=t.innerType._zod.pattern;return e?new RegExp(`^(${Ai(e.source)})?$`):void 0}),e._zod.parse=(e,n)=>{if("optional"===t.innerType._zod.optin){const r=t.innerType._zod.run(e,n);return r instanceof Promise?r.then(t=>nc(t,e.value)):nc(r,e.value)}return void 0===e.value?e:t.innerType._zod.run(e,n)}}),oc=bi("$ZodExactOptional",(e,t)=>{rc.init(e,t),Ti(e._zod,"values",()=>t.innerType._zod.values),Ti(e._zod,"pattern",()=>t.innerType._zod.pattern),e._zod.parse=(e,n)=>t.innerType._zod.run(e,n)}),ic=bi("$ZodNullable",(e,t)=>{aa.init(e,t),Ti(e._zod,"optin",()=>t.innerType._zod.optin),Ti(e._zod,"optout",()=>t.innerType._zod.optout),Ti(e._zod,"pattern",()=>{const e=t.innerType._zod.pattern;return e?new RegExp(`^(${Ai(e.source)}|null)$`):void 0}),Ti(e._zod,"values",()=>t.innerType._zod.values?new Set([...t.innerType._zod.values,null]):void 0),e._zod.parse=(e,n)=>null===e.value?e:t.innerType._zod.run(e,n)}),sc=bi("$ZodDefault",(e,t)=>{aa.init(e,t),e._zod.optin="optional",Ti(e._zod,"values",()=>t.innerType._zod.values),e._zod.parse=(e,n)=>{if("backward"===n.direction)return t.innerType._zod.run(e,n);if(void 0===e.value)return e.value=t.defaultValue,e;const r=t.innerType._zod.run(e,n);return r instanceof Promise?r.then(e=>ac(e,t)):ac(r,t)}});function ac(e,t){return void 0===e.value&&(e.value=t.defaultValue),e}const cc=bi("$ZodPrefault",(e,t)=>{aa.init(e,t),e._zod.optin="optional",Ti(e._zod,"values",()=>t.innerType._zod.values),e._zod.parse=(e,n)=>("backward"===n.direction||void 0===e.value&&(e.value=t.defaultValue),t.innerType._zod.run(e,n))}),uc=bi("$ZodNonOptional",(e,t)=>{aa.init(e,t),Ti(e._zod,"values",()=>{const e=t.innerType._zod.values;return e?new Set([...e].filter(e=>void 0!==e)):void 0}),e._zod.parse=(n,r)=>{const o=t.innerType._zod.run(n,r);return o instanceof Promise?o.then(t=>fc(t,e)):fc(o,e)}});function fc(e,t){return e.issues.length||void 0!==e.value||e.issues.push({code:"invalid_type",expected:"nonoptional",input:e.value,inst:t}),e}const dc=bi("$ZodCatch",(e,t)=>{aa.init(e,t),Ti(e._zod,"optin",()=>t.innerType._zod.optin),Ti(e._zod,"optout",()=>t.innerType._zod.optout),Ti(e._zod,"values",()=>t.innerType._zod.values),e._zod.parse=(e,n)=>{if("backward"===n.direction)return t.innerType._zod.run(e,n);const r=t.innerType._zod.run(e,n);return r instanceof Promise?r.then(r=>(e.value=r.value,r.issues.length&&(e.value=t.catchValue({...e,error:{issues:r.issues.map(e=>Wi(e,n,Oi()))},input:e.value}),e.issues=[]),e)):(e.value=r.value,r.issues.length&&(e.value=t.catchValue({...e,error:{issues:r.issues.map(e=>Wi(e,n,Oi()))},input:e.value}),e.issues=[]),e)}}),lc=bi("$ZodPipe",(e,t)=>{aa.init(e,t),Ti(e._zod,"values",()=>t.in._zod.values),Ti(e._zod,"optin",()=>t.in._zod.optin),Ti(e._zod,"optout",()=>t.out._zod.optout),Ti(e._zod,"propValues",()=>t.in._zod.propValues),e._zod.parse=(e,n)=>{if("backward"===n.direction){const r=t.out._zod.run(e,n);return r instanceof Promise?r.then(e=>pc(e,t.in,n)):pc(r,t.in,n)}const r=t.in._zod.run(e,n);return r instanceof Promise?r.then(e=>pc(e,t.out,n)):pc(r,t.out,n)}});function pc(e,t,n){return e.issues.length?(e.aborted=!0,e):t._zod.run({value:e.value,issues:e.issues},n)}const hc=bi("$ZodReadonly",(e,t)=>{aa.init(e,t),Ti(e._zod,"propValues",()=>t.innerType._zod.propValues),Ti(e._zod,"values",()=>t.innerType._zod.values),Ti(e._zod,"optin",()=>t.innerType?._zod?.optin),Ti(e._zod,"optout",()=>t.innerType?._zod?.optout),e._zod.parse=(e,n)=>{if("backward"===n.direction)return t.innerType._zod.run(e,n);const r=t.innerType._zod.run(e,n);return r instanceof Promise?r.then(mc):mc(r)}});function mc(e){return e.value=Object.freeze(e.value),e}const gc=bi("$ZodLazy",(e,t)=>{aa.init(e,t),Ti(e._zod,"innerType",()=>t.getter()),Ti(e._zod,"pattern",()=>e._zod.innerType?._zod?.pattern),Ti(e._zod,"propValues",()=>e._zod.innerType?._zod?.propValues),Ti(e._zod,"optin",()=>e._zod.innerType?._zod?.optin??void 0),Ti(e._zod,"optout",()=>e._zod.innerType?._zod?.optout??void 0),e._zod.parse=(t,n)=>e._zod.innerType._zod.run(t,n)}),yc=bi("$ZodCustom",(e,t)=>{Ds.init(e,t),aa.init(e,t),e._zod.parse=(e,t)=>e,e._zod.check=n=>{const r=n.value,o=t.fn(r);if(o instanceof Promise)return o.then(t=>_c(t,n,r,e));_c(o,n,r,e)}});function _c(e,t,n,r){if(!e){const e={code:"custom",input:n,inst:r,path:[...r._zod.def.path??[]],continue:!r._zod.def.abort};r._zod.def.params&&(e.params=r._zod.def.params),t.issues.push(Yi(e))}}var wc;class vc{constructor(){this._map=new WeakMap,this._idmap=new Map}add(e,...t){const n=t[0];return this._map.set(e,n),n&&"object"==typeof n&&"id"in n&&this._idmap.set(n.id,e),this}clear(){return this._map=new WeakMap,this._idmap=new Map,this}remove(e){const t=this._map.get(e);return t&&"object"==typeof t&&"id"in t&&this._idmap.delete(t.id),this._map.delete(e),this}get(e){const t=e._zod.parent;if(t){const n={...this.get(t)??{}};delete n.id;const r={...n,...this._map.get(e)};return Object.keys(r).length?r:void 0}return this._map.get(e)}has(e){return this._map.has(e)}}(wc=globalThis).__zod_globalRegistry??(wc.__zod_globalRegistry=new vc);const bc=globalThis.__zod_globalRegistry;function Ec(e,t){return new e({type:"string",format:"guid",check:"string_format",abort:!1,...Vi(t)})}function xc(e,t){return new Vs({check:"less_than",...Vi(t),value:e,inclusive:!1})}function zc(e,t){return new Vs({check:"less_than",...Vi(t),value:e,inclusive:!0})}function Oc(e,t){return new qs({check:"greater_than",...Vi(t),value:e,inclusive:!1})}function kc(e,t){return new qs({check:"greater_than",...Vi(t),value:e,inclusive:!0})}function Sc(e,t){return new Ms({check:"multiple_of",...Vi(t),value:e})}function Pc(e,t){return new Js({check:"max_length",...Vi(t),maximum:e})}function $c(e,t){return new Ws({check:"min_length",...Vi(t),minimum:e})}function Ac(e,t){return new Gs({check:"length_equals",...Vi(t),length:e})}function Ic(e){return new oa({check:"overwrite",tx:e})}function Tc(e){const t=function(e,t){const n=new Ds({check:"custom",...Vi(t)});return n._zod.check=e,n}(n=>(n.addIssue=e=>{if("string"==typeof e)n.issues.push(Yi(e,n.value,t._zod.def));else{const r=e;r.fatal&&(r.continue=!1),r.code??(r.code="custom"),r.input??(r.input=n.value),r.inst??(r.inst=t),r.continue??(r.continue=!t._zod.def.abort),n.issues.push(Yi(r))}},e(n.value,n)));return t}function Nc(e){let t=e?.target??"draft-2020-12";return"draft-4"===t&&(t="draft-04"),"draft-7"===t&&(t="draft-07"),{processors:e.processors??{},metadataRegistry:e?.metadata??bc,target:t,unrepresentable:e?.unrepresentable??"throw",override:e?.override??(()=>{}),io:e?.io??"output",counter:0,seen:new Map,cycles:e?.cycles??"ref",reused:e?.reused??"inline",external:e?.external??void 0}}function Bc(e,t,n={path:[],schemaPath:[]}){var r;const o=e._zod.def,i=t.seen.get(e);if(i){i.count++;return n.schemaPath.includes(e)&&(i.cycle=n.path),i.schema}const s={schema:{},count:1,cycle:void 0,path:n.path};t.seen.set(e,s);const a=e._zod.toJSONSchema?.();if(a)s.schema=a;else{const r={...n,schemaPath:[...n.schemaPath,e],path:n.path};if(e._zod.processJSONSchema)e._zod.processJSONSchema(t,s.schema,r);else{const n=s.schema,i=t.processors[o.type];if(!i)throw new Error(`[toJSONSchema]: Non-representable type encountered: ${o.type}`);i(e,t,n,r)}const i=e._zod.parent;i&&(s.ref||(s.ref=i),Bc(i,t,r),t.seen.get(i).isParent=!0)}const c=t.metadataRegistry.get(e);c&&Object.assign(s.schema,c),"input"===t.io&&jc(e)&&(delete s.schema.examples,delete s.schema.default),"input"===t.io&&s.schema._prefault&&((r=s.schema).default??(r.default=s.schema._prefault)),delete s.schema._prefault;return t.seen.get(e).schema}function Uc(e,t){const n=e.seen.get(t);if(!n)throw new Error("Unprocessed schema. This is a bug in Zod.");const r=new Map;for(const t of e.seen.entries()){const n=e.metadataRegistry.get(t[0])?.id;if(n){const e=r.get(n);if(e&&e!==t[0])throw new Error(`Duplicate schema id "${n}" detected during JSON Schema conversion. Two different schemas cannot share the same id when converted together.`);r.set(n,t[0])}}const o=t=>{if(t[1].schema.$ref)return;const r=t[1],{ref:o,defId:i}=(t=>{const r="draft-2020-12"===e.target?"$defs":"definitions";if(e.external){const n=e.external.registry.get(t[0])?.id,o=e.external.uri??(e=>e);if(n)return{ref:o(n)};const i=t[1].defId??t[1].schema.id??"schema"+e.counter++;return t[1].defId=i,{defId:i,ref:`${o("__shared")}#/${r}/${i}`}}if(t[1]===n)return{ref:"#"};const o=`#/${r}/`,i=t[1].schema.id??"__schema"+e.counter++;return{defId:i,ref:o+i}})(t);r.def={...r.schema},i&&(r.defId=i);const s=r.schema;for(const e in s)delete s[e];s.$ref=o};if("throw"===e.cycles)for(const t of e.seen.entries()){const e=t[1];if(e.cycle)throw new Error(`Cycle detected: #/${e.cycle?.join("/")}/<root>\n\nSet the \`cycles\` parameter to \`"ref"\` to resolve cyclical schemas with defs.`)}for(const n of e.seen.entries()){const r=n[1];if(t===n[0]){o(n);continue}if(e.external){const r=e.external.registry.get(n[0])?.id;if(t!==n[0]&&r){o(n);continue}}const i=e.metadataRegistry.get(n[0])?.id;i?o(n):(r.cycle||r.count>1&&"ref"===e.reused)&&o(n)}}function Rc(e,t){const n=e.seen.get(t);if(!n)throw new Error("Unprocessed schema. This is a bug in Zod.");const r=t=>{const n=e.seen.get(t);if(null===n.ref)return;const o=n.def??n.schema,i={...o},s=n.ref;if(n.ref=null,s){r(s);const n=e.seen.get(s),a=n.schema;!a.$ref||"draft-07"!==e.target&&"draft-04"!==e.target&&"openapi-3.0"!==e.target?Object.assign(o,a):(o.allOf=o.allOf??[],o.allOf.push(a)),Object.assign(o,i);if(t._zod.parent===s)for(const e in o)"$ref"!==e&&"allOf"!==e&&(e in i||delete o[e]);if(a.$ref)for(const e in o)"$ref"!==e&&"allOf"!==e&&e in n.def&&JSON.stringify(o[e])===JSON.stringify(n.def[e])&&delete o[e]}const a=t._zod.parent;if(a&&a!==s){r(a);const t=e.seen.get(a);if(t?.schema.$ref&&(o.$ref=t.schema.$ref,t.def))for(const e in o)"$ref"!==e&&"allOf"!==e&&e in t.def&&JSON.stringify(o[e])===JSON.stringify(t.def[e])&&delete o[e]}e.override({zodSchema:t,jsonSchema:o,path:n.path??[]})};for(const t of[...e.seen.entries()].reverse())r(t[0]);const o={};if("draft-2020-12"===e.target?o.$schema="https://json-schema.org/draft/2020-12/schema":"draft-07"===e.target?o.$schema="http://json-schema.org/draft-07/schema#":"draft-04"===e.target&&(o.$schema="http://json-schema.org/draft-04/schema#"),e.external?.uri){const n=e.external.registry.get(t)?.id;if(!n)throw new Error("Schema is missing an `id` property");o.$id=e.external.uri(n)}Object.assign(o,n.def??n.schema);const i=e.external?.defs??{};for(const t of e.seen.entries()){const e=t[1];e.def&&e.defId&&(i[e.defId]=e.def)}e.external||Object.keys(i).length>0&&("draft-2020-12"===e.target?o.$defs=i:o.definitions=i);try{const n=JSON.parse(JSON.stringify(o));return Object.defineProperty(n,"~standard",{value:{...t["~standard"],jsonSchema:{input:Zc(t,"input",e.processors),output:Zc(t,"output",e.processors)}},enumerable:!1,writable:!1}),n}catch(e){throw new Error("Error converting schema to JSON.")}}function jc(e,t){const n=t??{seen:new Set};if(n.seen.has(e))return!1;n.seen.add(e);const r=e._zod.def;if("transform"===r.type)return!0;if("array"===r.type)return jc(r.element,n);if("set"===r.type)return jc(r.valueType,n);if("lazy"===r.type)return jc(r.getter(),n);if("promise"===r.type||"optional"===r.type||"nonoptional"===r.type||"nullable"===r.type||"readonly"===r.type||"default"===r.type||"prefault"===r.type)return jc(r.innerType,n);if("intersection"===r.type)return jc(r.left,n)||jc(r.right,n);if("record"===r.type||"map"===r.type)return jc(r.keyType,n)||jc(r.valueType,n);if("pipe"===r.type)return jc(r.in,n)||jc(r.out,n);if("object"===r.type){for(const e in r.shape)if(jc(r.shape[e],n))return!0;return!1}if("union"===r.type){for(const e of r.options)if(jc(e,n))return!0;return!1}if("tuple"===r.type){for(const e of r.items)if(jc(e,n))return!0;return!(!r.rest||!jc(r.rest,n))}return!1}const Zc=(e,t,n={})=>r=>{const{libraryOptions:o,target:i}=r??{},s=Nc({...o??{},target:i,io:t,processors:n});return Bc(e,s),Uc(s,e),Rc(s,e)},Cc={guid:"uuid",url:"uri",datetime:"date-time",json_string:"json-string",regex:""},Fc=(e,t,n,r)=>{const o=e._zod.def;Bc(o.innerType,t,r);t.seen.get(e).ref=o.innerType},Hc=bi("ZodISODateTime",(e,t)=>{ba.init(e,t),lu.init(e,t)});function Dc(e){return function(e,t){return new e({type:"string",format:"datetime",check:"string_format",offset:!1,local:!1,precision:null,...Vi(t)})}(Hc,e)}const Lc=bi("ZodISODate",(e,t)=>{Ea.init(e,t),lu.init(e,t)});function Vc(e){return function(e,t){return new e({type:"string",format:"date",check:"string_format",...Vi(t)})}(Lc,e)}const qc=bi("ZodISOTime",(e,t)=>{xa.init(e,t),lu.init(e,t)});function Mc(e){return function(e,t){return new e({type:"string",format:"time",check:"string_format",precision:null,...Vi(t)})}(qc,e)}const Kc=bi("ZodISODuration",(e,t)=>{za.init(e,t),lu.init(e,t)});function Jc(e){return function(e,t){return new e({type:"string",format:"duration",check:"string_format",...Vi(t)})}(Kc,e)}const Wc=bi("ZodError",(e,t)=>{Qi.init(e,t),e.name="ZodError",Object.defineProperties(e,{format:{value:t=>function(e,t=e=>e.message){const n={_errors:[]},r=e=>{for(const o of e.issues)if("invalid_union"===o.code&&o.errors.length)o.errors.map(e=>r({issues:e}));else if("invalid_key"===o.code)r({issues:o.issues});else if("invalid_element"===o.code)r({issues:o.issues});else if(0===o.path.length)n._errors.push(t(o));else{let e=n,r=0;for(;r<o.path.length;){const n=o.path[r];r===o.path.length-1?(e[n]=e[n]||{_errors:[]},e[n]._errors.push(t(o))):e[n]=e[n]||{_errors:[]},e=e[n],r++}}};return r(e),n}(e,t)},flatten:{value:t=>function(e,t=e=>e.message){const n={},r=[];for(const o of e.issues)o.path.length>0?(n[o.path[0]]=n[o.path[0]]||[],n[o.path[0]].push(t(o))):r.push(t(o));return{formErrors:r,fieldErrors:n}}(e,t)},addIssue:{value:t=>{e.issues.push(t),e.message=JSON.stringify(e.issues,Si,2)}},addIssues:{value:t=>{e.issues.push(...t),e.message=JSON.stringify(e.issues,Si,2)}},isEmpty:{get:()=>0===e.issues.length}})},{Parent:Error}),Gc=ts(Wc),Yc=ns(Wc),Xc=rs(Wc),Qc=is(Wc),eu=as(Wc),tu=cs(Wc),nu=us(Wc),ru=fs(Wc),ou=ds(Wc),iu=ls(Wc),su=ps(Wc),au=hs(Wc),cu=bi("ZodType",(e,t)=>(aa.init(e,t),Object.assign(e["~standard"],{jsonSchema:{input:Zc(e,"input"),output:Zc(e,"output")}}),e.toJSONSchema=((e,t={})=>n=>{const r=Nc({...n,processors:t});return Bc(e,r),Uc(r,e),Rc(r,e)})(e,{}),e.def=t,e.type=t.type,Object.defineProperty(e,"_def",{value:t}),e.check=(...n)=>e.clone(Bi(t,{checks:[...t.checks??[],...n.map(e=>"function"==typeof e?{_zod:{check:e,def:{check:"custom"},onattach:[]}}:e)]}),{parent:!0}),e.with=e.check,e.clone=(t,n)=>Li(e,t,n),e.brand=()=>e,e.register=(t,n)=>(t.add(e,n),e),e.parse=(t,n)=>Gc(e,t,n,{callee:e.parse}),e.safeParse=(t,n)=>Xc(e,t,n),e.parseAsync=async(t,n)=>Yc(e,t,n,{callee:e.parseAsync}),e.safeParseAsync=async(t,n)=>Qc(e,t,n),e.spa=e.safeParseAsync,e.encode=(t,n)=>eu(e,t,n),e.decode=(t,n)=>tu(e,t,n),e.encodeAsync=async(t,n)=>nu(e,t,n),e.decodeAsync=async(t,n)=>ru(e,t,n),e.safeEncode=(t,n)=>ou(e,t,n),e.safeDecode=(t,n)=>iu(e,t,n),e.safeEncodeAsync=async(t,n)=>su(e,t,n),e.safeDecodeAsync=async(t,n)=>au(e,t,n),e.refine=(t,n)=>e.check(function(e,t={}){return function(e,t,n){return new e({type:"custom",check:"custom",fn:t,...Vi(n)})}(hf,e,t)}(t,n)),e.superRefine=t=>e.check(Tc(t)),e.overwrite=t=>e.check(Ic(t)),e.optional=()=>tf(e),e.exactOptional=()=>new nf({type:"optional",innerType:e}),e.nullable=()=>of(e),e.nullish=()=>tf(of(e)),e.nonoptional=t=>function(e,t){return new cf({type:"nonoptional",innerType:e,...Vi(t)})}(e,t),e.array=()=>Vu(e),e.or=t=>Ju([e,t]),e.and=t=>new Wu({type:"intersection",left:e,right:t}),e.transform=t=>df(e,new Qu({type:"transform",transform:t})),e.default=t=>{return n=t,new sf({type:"default",innerType:e,get defaultValue(){return"function"==typeof n?n():Fi(n)}});var n},e.prefault=t=>{return n=t,new af({type:"prefault",innerType:e,get defaultValue(){return"function"==typeof n?n():Fi(n)}});var n},e.catch=t=>{return new uf({type:"catch",innerType:e,catchValue:"function"==typeof(n=t)?n:()=>n});var n},e.pipe=t=>df(e,t),e.readonly=()=>new lf({type:"readonly",innerType:e}),e.describe=t=>{const n=e.clone();return bc.add(n,{description:t}),n},Object.defineProperty(e,"description",{get:()=>bc.get(e)?.description,configurable:!0}),e.meta=(...t)=>{if(0===t.length)return bc.get(e);const n=e.clone();return bc.add(n,t[0]),n},e.isOptional=()=>e.safeParse(void 0).success,e.isNullable=()=>e.safeParse(null).success,e.apply=t=>t(e),e)),uu=bi("_ZodString",(e,t)=>{ca.init(e,t),cu.init(e,t),e._zod.processJSONSchema=(t,n,r)=>((e,t,n)=>{const r=n;r.type="string";const{minimum:o,maximum:i,format:s,patterns:a,contentEncoding:c}=e._zod.bag;if("number"==typeof o&&(r.minLength=o),"number"==typeof i&&(r.maxLength=i),s&&(r.format=Cc[s]??s,""===r.format&&delete r.format,"time"===s&&delete r.format),c&&(r.contentEncoding=c),a&&a.size>0){const e=[...a];1===e.length?r.pattern=e[0].source:e.length>1&&(r.allOf=[...e.map(e=>({..."draft-07"===t.target||"draft-04"===t.target||"openapi-3.0"===t.target?{type:"string"}:{},pattern:e.source}))])}})(e,t,n);const n=e._zod.bag;e.format=n.format??null,e.minLength=n.minimum??null,e.maxLength=n.maximum??null,e.regex=(...t)=>e.check(function(e,t){return new Xs({check:"string_format",format:"regex",...Vi(t),pattern:e})}(...t)),e.includes=(...t)=>e.check(function(e,t){return new ta({check:"string_format",format:"includes",...Vi(t),includes:e})}(...t)),e.startsWith=(...t)=>e.check(function(e,t){return new na({check:"string_format",format:"starts_with",...Vi(t),prefix:e})}(...t)),e.endsWith=(...t)=>e.check(function(e,t){return new ra({check:"string_format",format:"ends_with",...Vi(t),suffix:e})}(...t)),e.min=(...t)=>e.check($c(...t)),e.max=(...t)=>e.check(Pc(...t)),e.length=(...t)=>e.check(Ac(...t)),e.nonempty=(...t)=>e.check($c(1,...t)),e.lowercase=t=>e.check(function(e){return new Qs({check:"string_format",format:"lowercase",...Vi(e)})}(t)),e.uppercase=t=>e.check(function(e){return new ea({check:"string_format",format:"uppercase",...Vi(e)})}(t)),e.trim=()=>e.check(Ic(e=>e.trim())),e.normalize=(...t)=>e.check(function(e){return Ic(t=>t.normalize(e))}(...t)),e.toLowerCase=()=>e.check(Ic(e=>e.toLowerCase())),e.toUpperCase=()=>e.check(Ic(e=>e.toUpperCase())),e.slugify=()=>e.check(Ic(e=>function(e){return e.toLowerCase().trim().replace(/[^\w\s-]/g,"").replace(/[\s_-]+/g,"-").replace(/^-+|-+$/g,"")}(e)))}),fu=bi("ZodString",(e,t)=>{ca.init(e,t),uu.init(e,t),e.email=t=>e.check(function(e,t){return new e({type:"string",format:"email",check:"string_format",abort:!1,...Vi(t)})}(pu,t)),e.url=t=>e.check(function(e,t){return new e({type:"string",format:"url",check:"string_format",abort:!1,...Vi(t)})}(gu,t)),e.jwt=t=>e.check(function(e,t){return new e({type:"string",format:"jwt",check:"string_format",abort:!1,...Vi(t)})}(Iu,t)),e.emoji=t=>e.check(function(e,t){return new e({type:"string",format:"emoji",check:"string_format",abort:!1,...Vi(t)})}(yu,t)),e.guid=t=>e.check(Ec(hu,t)),e.uuid=t=>e.check(function(e,t){return new e({type:"string",format:"uuid",check:"string_format",abort:!1,...Vi(t)})}(mu,t)),e.uuidv4=t=>e.check(function(e,t){return new e({type:"string",format:"uuid",check:"string_format",abort:!1,version:"v4",...Vi(t)})}(mu,t)),e.uuidv6=t=>e.check(function(e,t){return new e({type:"string",format:"uuid",check:"string_format",abort:!1,version:"v6",...Vi(t)})}(mu,t)),e.uuidv7=t=>e.check(function(e,t){return new e({type:"string",format:"uuid",check:"string_format",abort:!1,version:"v7",...Vi(t)})}(mu,t)),e.nanoid=t=>e.check(function(e,t){return new e({type:"string",format:"nanoid",check:"string_format",abort:!1,...Vi(t)})}(_u,t)),e.guid=t=>e.check(Ec(hu,t)),e.cuid=t=>e.check(function(e,t){return new e({type:"string",format:"cuid",check:"string_format",abort:!1,...Vi(t)})}(wu,t)),e.cuid2=t=>e.check(function(e,t){return new e({type:"string",format:"cuid2",check:"string_format",abort:!1,...Vi(t)})}(vu,t)),e.ulid=t=>e.check(function(e,t){return new e({type:"string",format:"ulid",check:"string_format",abort:!1,...Vi(t)})}(bu,t)),e.base64=t=>e.check(function(e,t){return new e({type:"string",format:"base64",check:"string_format",abort:!1,...Vi(t)})}(Pu,t)),e.base64url=t=>e.check(function(e,t){return new e({type:"string",format:"base64url",check:"string_format",abort:!1,...Vi(t)})}($u,t)),e.xid=t=>e.check(function(e,t){return new e({type:"string",format:"xid",check:"string_format",abort:!1,...Vi(t)})}(Eu,t)),e.ksuid=t=>e.check(function(e,t){return new e({type:"string",format:"ksuid",check:"string_format",abort:!1,...Vi(t)})}(xu,t)),e.ipv4=t=>e.check(function(e,t){return new e({type:"string",format:"ipv4",check:"string_format",abort:!1,...Vi(t)})}(zu,t)),e.ipv6=t=>e.check(function(e,t){return new e({type:"string",format:"ipv6",check:"string_format",abort:!1,...Vi(t)})}(Ou,t)),e.cidrv4=t=>e.check(function(e,t){return new e({type:"string",format:"cidrv4",check:"string_format",abort:!1,...Vi(t)})}(ku,t)),e.cidrv6=t=>e.check(function(e,t){return new e({type:"string",format:"cidrv6",check:"string_format",abort:!1,...Vi(t)})}(Su,t)),e.e164=t=>e.check(function(e,t){return new e({type:"string",format:"e164",check:"string_format",abort:!1,...Vi(t)})}(Au,t)),e.datetime=t=>e.check(Dc(t)),e.date=t=>e.check(Vc(t)),e.time=t=>e.check(Mc(t)),e.duration=t=>e.check(Jc(t))});function du(e){return function(e,t){return new e({type:"string",...Vi(t)})}(fu,e)}const lu=bi("ZodStringFormat",(e,t)=>{ua.init(e,t),uu.init(e,t)}),pu=bi("ZodEmail",(e,t)=>{la.init(e,t),lu.init(e,t)}),hu=bi("ZodGUID",(e,t)=>{fa.init(e,t),lu.init(e,t)}),mu=bi("ZodUUID",(e,t)=>{da.init(e,t),lu.init(e,t)}),gu=bi("ZodURL",(e,t)=>{pa.init(e,t),lu.init(e,t)}),yu=bi("ZodEmoji",(e,t)=>{ha.init(e,t),lu.init(e,t)}),_u=bi("ZodNanoID",(e,t)=>{ma.init(e,t),lu.init(e,t)}),wu=bi("ZodCUID",(e,t)=>{ga.init(e,t),lu.init(e,t)}),vu=bi("ZodCUID2",(e,t)=>{ya.init(e,t),lu.init(e,t)}),bu=bi("ZodULID",(e,t)=>{_a.init(e,t),lu.init(e,t)}),Eu=bi("ZodXID",(e,t)=>{wa.init(e,t),lu.init(e,t)}),xu=bi("ZodKSUID",(e,t)=>{va.init(e,t),lu.init(e,t)}),zu=bi("ZodIPv4",(e,t)=>{Oa.init(e,t),lu.init(e,t)}),Ou=bi("ZodIPv6",(e,t)=>{ka.init(e,t),lu.init(e,t)}),ku=bi("ZodCIDRv4",(e,t)=>{Sa.init(e,t),lu.init(e,t)}),Su=bi("ZodCIDRv6",(e,t)=>{Pa.init(e,t),lu.init(e,t)}),Pu=bi("ZodBase64",(e,t)=>{Aa.init(e,t),lu.init(e,t)}),$u=bi("ZodBase64URL",(e,t)=>{Ia.init(e,t),lu.init(e,t)}),Au=bi("ZodE164",(e,t)=>{Ta.init(e,t),lu.init(e,t)}),Iu=bi("ZodJWT",(e,t)=>{Na.init(e,t),lu.init(e,t)}),Tu=bi("ZodNumber",(e,t)=>{Ba.init(e,t),cu.init(e,t),e._zod.processJSONSchema=(t,n,r)=>((e,t,n)=>{const r=n,{minimum:o,maximum:i,format:s,multipleOf:a,exclusiveMaximum:c,exclusiveMinimum:u}=e._zod.bag;"string"==typeof s&&s.includes("int")?r.type="integer":r.type="number","number"==typeof u&&("draft-04"===t.target||"openapi-3.0"===t.target?(r.minimum=u,r.exclusiveMinimum=!0):r.exclusiveMinimum=u),"number"==typeof o&&(r.minimum=o,"number"==typeof u&&"draft-04"!==t.target&&(u>=o?delete r.minimum:delete r.exclusiveMinimum)),"number"==typeof c&&("draft-04"===t.target||"openapi-3.0"===t.target?(r.maximum=c,r.exclusiveMaximum=!0):r.exclusiveMaximum=c),"number"==typeof i&&(r.maximum=i,"number"==typeof c&&"draft-04"!==t.target&&(c<=i?delete r.maximum:delete r.exclusiveMaximum)),"number"==typeof a&&(r.multipleOf=a)})(e,t,n),e.gt=(t,n)=>e.check(Oc(t,n)),e.gte=(t,n)=>e.check(kc(t,n)),e.min=(t,n)=>e.check(kc(t,n)),e.lt=(t,n)=>e.check(xc(t,n)),e.lte=(t,n)=>e.check(zc(t,n)),e.max=(t,n)=>e.check(zc(t,n)),e.int=t=>e.check(Uu(t)),e.safe=t=>e.check(Uu(t)),e.positive=t=>e.check(Oc(0,t)),e.nonnegative=t=>e.check(kc(0,t)),e.negative=t=>e.check(xc(0,t)),e.nonpositive=t=>e.check(zc(0,t)),e.multipleOf=(t,n)=>e.check(Sc(t,n)),e.step=(t,n)=>e.check(Sc(t,n)),e.finite=()=>e;const n=e._zod.bag;e.minValue=Math.max(n.minimum??Number.NEGATIVE_INFINITY,n.exclusiveMinimum??Number.NEGATIVE_INFINITY)??null,e.maxValue=Math.min(n.maximum??Number.POSITIVE_INFINITY,n.exclusiveMaximum??Number.POSITIVE_INFINITY)??null,e.isInt=(n.format??"").includes("int")||Number.isSafeInteger(n.multipleOf??.5),e.isFinite=!0,e.format=n.format??null});function Nu(e){return function(e,t){return new e({type:"number",checks:[],...Vi(t)})}(Tu,e)}const Bu=bi("ZodNumberFormat",(e,t)=>{Ua.init(e,t),Tu.init(e,t)});function Uu(e){return function(e,t){return new e({type:"number",check:"number_format",abort:!1,format:"safeint",...Vi(t)})}(Bu,e)}const Ru=bi("ZodBoolean",(e,t)=>{Ra.init(e,t),cu.init(e,t),e._zod.processJSONSchema=(e,t,n)=>((e,t,n)=>{n.type="boolean"})(0,0,t)});const ju=bi("ZodBigInt",(e,t)=>{ja.init(e,t),cu.init(e,t),e._zod.processJSONSchema=(e,t,n)=>((e,t)=>{if("throw"===t.unrepresentable)throw new Error("BigInt cannot be represented in JSON Schema")})(0,e),e.gte=(t,n)=>e.check(kc(t,n)),e.min=(t,n)=>e.check(kc(t,n)),e.gt=(t,n)=>e.check(Oc(t,n)),e.gte=(t,n)=>e.check(kc(t,n)),e.min=(t,n)=>e.check(kc(t,n)),e.lt=(t,n)=>e.check(xc(t,n)),e.lte=(t,n)=>e.check(zc(t,n)),e.max=(t,n)=>e.check(zc(t,n)),e.positive=t=>e.check(Oc(BigInt(0),t)),e.negative=t=>e.check(xc(BigInt(0),t)),e.nonpositive=t=>e.check(zc(BigInt(0),t)),e.nonnegative=t=>e.check(kc(BigInt(0),t)),e.multipleOf=(t,n)=>e.check(Sc(t,n));const n=e._zod.bag;e.minValue=n.minimum??null,e.maxValue=n.maximum??null,e.format=n.format??null});const Zu=bi("ZodNull",(e,t)=>{Za.init(e,t),cu.init(e,t),e._zod.processJSONSchema=(e,t,n)=>((e,t,n)=>{"openapi-3.0"===t.target?(n.type="string",n.nullable=!0,n.enum=[null]):n.type="null"})(0,e,t)});const Cu=bi("ZodUnknown",(e,t)=>{Ca.init(e,t),cu.init(e,t),e._zod.processJSONSchema=(e,t,n)=>{}});function Fu(){return new Cu({type:"unknown"})}const Hu=bi("ZodNever",(e,t)=>{Fa.init(e,t),cu.init(e,t),e._zod.processJSONSchema=(e,t,n)=>((e,t,n)=>{n.not={}})(0,0,t)});function Du(e){return function(e,t){return new e({type:"never",...Vi(t)})}(Hu,e)}const Lu=bi("ZodArray",(e,t)=>{Da.init(e,t),cu.init(e,t),e._zod.processJSONSchema=(t,n,r)=>((e,t,n,r)=>{const o=n,i=e._zod.def,{minimum:s,maximum:a}=e._zod.bag;"number"==typeof s&&(o.minItems=s),"number"==typeof a&&(o.maxItems=a),o.type="array",o.items=Bc(i.element,t,{...r,path:[...r.path,"items"]})})(e,t,n,r),e.element=t.element,e.min=(t,n)=>e.check($c(t,n)),e.nonempty=t=>e.check($c(1,t)),e.max=(t,n)=>e.check(Pc(t,n)),e.length=(t,n)=>e.check(Ac(t,n)),e.unwrap=()=>e.element});function Vu(e,t){return function(e,t,n){return new e({type:"array",element:t,...Vi(n)})}(Lu,e,t)}const qu=bi("ZodObject",(e,t)=>{Ka.init(e,t),cu.init(e,t),e._zod.processJSONSchema=(t,n,r)=>((e,t,n,r)=>{const o=n,i=e._zod.def;o.type="object",o.properties={};const s=i.shape;for(const e in s)o.properties[e]=Bc(s[e],t,{...r,path:[...r.path,"properties",e]});const a=new Set(Object.keys(s)),c=new Set([...a].filter(e=>{const n=i.shape[e]._zod;return"input"===t.io?void 0===n.optin:void 0===n.optout}));c.size>0&&(o.required=Array.from(c)),"never"===i.catchall?._zod.def.type?o.additionalProperties=!1:i.catchall?i.catchall&&(o.additionalProperties=Bc(i.catchall,t,{...r,path:[...r.path,"additionalProperties"]})):"output"===t.io&&(o.additionalProperties=!1)})(e,t,n,r),Ti(e,"shape",()=>t.shape),e.keyof=()=>function(e,t){const n=Array.isArray(e)?Object.fromEntries(e.map(e=>[e,e])):e;return new Xu({type:"enum",entries:n,...Vi(t)})}(Object.keys(e._zod.def.shape)),e.catchall=t=>e.clone({...e._zod.def,catchall:t}),e.passthrough=()=>e.clone({...e._zod.def,catchall:Fu()}),e.loose=()=>e.clone({...e._zod.def,catchall:Fu()}),e.strict=()=>e.clone({...e._zod.def,catchall:Du()}),e.strip=()=>e.clone({...e._zod.def,catchall:void 0}),e.extend=t=>function(e,t){if(!Ci(t))throw new Error("Invalid input to extend: expected a plain object");const n=e._zod.def.checks;if(n&&n.length>0){const n=e._zod.def.shape;for(const e in t)if(void 0!==Object.getOwnPropertyDescriptor(n,e))throw new Error("Cannot overwrite keys on object schemas containing refinements. Use `.safeExtend()` instead.")}const r=Bi(e._zod.def,{get shape(){const n={...e._zod.def.shape,...t};return Ni(this,"shape",n),n}});return Li(e,r)}(e,t),e.safeExtend=t=>function(e,t){if(!Ci(t))throw new Error("Invalid input to safeExtend: expected a plain object");const n=Bi(e._zod.def,{get shape(){const n={...e._zod.def.shape,...t};return Ni(this,"shape",n),n}});return Li(e,n)}(e,t),e.merge=t=>function(e,t){const n=Bi(e._zod.def,{get shape(){const n={...e._zod.def.shape,...t._zod.def.shape};return Ni(this,"shape",n),n},get catchall(){return t._zod.def.catchall},checks:[]});return Li(e,n)}(e,t),e.pick=t=>function(e,t){const n=e._zod.def,r=n.checks;if(r&&r.length>0)throw new Error(".pick() cannot be used on object schemas containing refinements");return Li(e,Bi(e._zod.def,{get shape(){const e={};for(const r in t){if(!(r in n.shape))throw new Error(`Unrecognized key: "${r}"`);t[r]&&(e[r]=n.shape[r])}return Ni(this,"shape",e),e},checks:[]}))}(e,t),e.omit=t=>function(e,t){const n=e._zod.def,r=n.checks;if(r&&r.length>0)throw new Error(".omit() cannot be used on object schemas containing refinements");const o=Bi(e._zod.def,{get shape(){const r={...e._zod.def.shape};for(const e in t){if(!(e in n.shape))throw new Error(`Unrecognized key: "${e}"`);t[e]&&delete r[e]}return Ni(this,"shape",r),r},checks:[]});return Li(e,o)}(e,t),e.partial=(...t)=>function(e,t,n){const r=t._zod.def.checks;if(r&&r.length>0)throw new Error(".partial() cannot be used on object schemas containing refinements");const o=Bi(t._zod.def,{get shape(){const r=t._zod.def.shape,o={...r};if(n)for(const t in n){if(!(t in r))throw new Error(`Unrecognized key: "${t}"`);n[t]&&(o[t]=e?new e({type:"optional",innerType:r[t]}):r[t])}else for(const t in r)o[t]=e?new e({type:"optional",innerType:r[t]}):r[t];return Ni(this,"shape",o),o},checks:[]});return Li(t,o)}(ef,e,t[0]),e.required=(...t)=>function(e,t,n){const r=Bi(t._zod.def,{get shape(){const r=t._zod.def.shape,o={...r};if(n)for(const t in n){if(!(t in o))throw new Error(`Unrecognized key: "${t}"`);n[t]&&(o[t]=new e({type:"nonoptional",innerType:r[t]}))}else for(const t in r)o[t]=new e({type:"nonoptional",innerType:r[t]});return Ni(this,"shape",o),o}});return Li(t,r)}(cf,e,t[0])});function Mu(e,t){const n={type:"object",shape:e??{},...Vi(t)};return new qu(n)}const Ku=bi("ZodUnion",(e,t)=>{Wa.init(e,t),cu.init(e,t),e._zod.processJSONSchema=(t,n,r)=>((e,t,n,r)=>{const o=e._zod.def,i=!1===o.inclusive,s=o.options.map((e,n)=>Bc(e,t,{...r,path:[...r.path,i?"oneOf":"anyOf",n]}));i?n.oneOf=s:n.anyOf=s})(e,t,n,r),e.options=t.options});function Ju(e,t){return new Ku({type:"union",options:e,...Vi(t)})}const Wu=bi("ZodIntersection",(e,t)=>{Ga.init(e,t),cu.init(e,t),e._zod.processJSONSchema=(t,n,r)=>((e,t,n,r)=>{const o=e._zod.def,i=Bc(o.left,t,{...r,path:[...r.path,"allOf",0]}),s=Bc(o.right,t,{...r,path:[...r.path,"allOf",1]}),a=e=>"allOf"in e&&1===Object.keys(e).length,c=[...a(i)?i.allOf:[i],...a(s)?s.allOf:[s]];n.allOf=c})(e,t,n,r)});const Gu=bi("ZodRecord",(e,t)=>{Qa.init(e,t),cu.init(e,t),e._zod.processJSONSchema=(t,n,r)=>((e,t,n,r)=>{const o=n,i=e._zod.def;o.type="object";const s=i.keyType,a=s._zod.bag,c=a?.patterns;if("loose"===i.mode&&c&&c.size>0){const e=Bc(i.valueType,t,{...r,path:[...r.path,"patternProperties","*"]});o.patternProperties={};for(const t of c)o.patternProperties[t.source]=e}else"draft-07"!==t.target&&"draft-2020-12"!==t.target||(o.propertyNames=Bc(i.keyType,t,{...r,path:[...r.path,"propertyNames"]})),o.additionalProperties=Bc(i.valueType,t,{...r,path:[...r.path,"additionalProperties"]});const u=s._zod.values;if(u){const e=[...u].filter(e=>"string"==typeof e||"number"==typeof e);e.length>0&&(o.required=e)}})(e,t,n,r),e.keyType=t.keyType,e.valueType=t.valueType});function Yu(e,t,n){return new Gu({type:"record",keyType:e,valueType:t,...Vi(n)})}const Xu=bi("ZodEnum",(e,t)=>{ec.init(e,t),cu.init(e,t),e._zod.processJSONSchema=(t,n,r)=>((e,t,n)=>{const r=ki(e._zod.def.entries);r.every(e=>"number"==typeof e)&&(n.type="number"),r.every(e=>"string"==typeof e)&&(n.type="string"),n.enum=r})(e,0,n),e.enum=t.entries,e.options=Object.values(t.entries);const n=new Set(Object.keys(t.entries));e.extract=(e,r)=>{const o={};for(const r of e){if(!n.has(r))throw new Error(`Key ${r} not found in enum`);o[r]=t.entries[r]}return new Xu({...t,checks:[],...Vi(r),entries:o})},e.exclude=(e,r)=>{const o={...t.entries};for(const t of e){if(!n.has(t))throw new Error(`Key ${t} not found in enum`);delete o[t]}return new Xu({...t,checks:[],...Vi(r),entries:o})}});const Qu=bi("ZodTransform",(e,t)=>{tc.init(e,t),cu.init(e,t),e._zod.processJSONSchema=(e,t,n)=>((e,t)=>{if("throw"===t.unrepresentable)throw new Error("Transforms cannot be represented in JSON Schema")})(0,e),e._zod.parse=(n,r)=>{if("backward"===r.direction)throw new xi(e.constructor.name);n.addIssue=r=>{if("string"==typeof r)n.issues.push(Yi(r,n.value,t));else{const t=r;t.fatal&&(t.continue=!1),t.code??(t.code="custom"),t.input??(t.input=n.value),t.inst??(t.inst=e),n.issues.push(Yi(t))}};const o=t.transform(n.value,n);return o instanceof Promise?o.then(e=>(n.value=e,n)):(n.value=o,n)}});const ef=bi("ZodOptional",(e,t)=>{rc.init(e,t),cu.init(e,t),e._zod.processJSONSchema=(t,n,r)=>Fc(e,t,0,r),e.unwrap=()=>e._zod.def.innerType});function tf(e){return new ef({type:"optional",innerType:e})}const nf=bi("ZodExactOptional",(e,t)=>{oc.init(e,t),cu.init(e,t),e._zod.processJSONSchema=(t,n,r)=>Fc(e,t,0,r),e.unwrap=()=>e._zod.def.innerType});const rf=bi("ZodNullable",(e,t)=>{ic.init(e,t),cu.init(e,t),e._zod.processJSONSchema=(t,n,r)=>((e,t,n,r)=>{const o=e._zod.def,i=Bc(o.innerType,t,r),s=t.seen.get(e);"openapi-3.0"===t.target?(s.ref=o.innerType,n.nullable=!0):n.anyOf=[i,{type:"null"}]})(e,t,n,r),e.unwrap=()=>e._zod.def.innerType});function of(e){return new rf({type:"nullable",innerType:e})}const sf=bi("ZodDefault",(e,t)=>{sc.init(e,t),cu.init(e,t),e._zod.processJSONSchema=(t,n,r)=>((e,t,n,r)=>{const o=e._zod.def;Bc(o.innerType,t,r),t.seen.get(e).ref=o.innerType,n.default=JSON.parse(JSON.stringify(o.defaultValue))})(e,t,n,r),e.unwrap=()=>e._zod.def.innerType,e.removeDefault=e.unwrap});const af=bi("ZodPrefault",(e,t)=>{cc.init(e,t),cu.init(e,t),e._zod.processJSONSchema=(t,n,r)=>((e,t,n,r)=>{const o=e._zod.def;Bc(o.innerType,t,r),t.seen.get(e).ref=o.innerType,"input"===t.io&&(n._prefault=JSON.parse(JSON.stringify(o.defaultValue)))})(e,t,n,r),e.unwrap=()=>e._zod.def.innerType});const cf=bi("ZodNonOptional",(e,t)=>{uc.init(e,t),cu.init(e,t),e._zod.processJSONSchema=(t,n,r)=>((e,t,n,r)=>{const o=e._zod.def;Bc(o.innerType,t,r),t.seen.get(e).ref=o.innerType})(e,t,0,r),e.unwrap=()=>e._zod.def.innerType});const uf=bi("ZodCatch",(e,t)=>{dc.init(e,t),cu.init(e,t),e._zod.processJSONSchema=(t,n,r)=>((e,t,n,r)=>{const o=e._zod.def;let i;Bc(o.innerType,t,r),t.seen.get(e).ref=o.innerType;try{i=o.catchValue(void 0)}catch{throw new Error("Dynamic catch values are not supported in JSON Schema")}n.default=i})(e,t,n,r),e.unwrap=()=>e._zod.def.innerType,e.removeCatch=e.unwrap});const ff=bi("ZodPipe",(e,t)=>{lc.init(e,t),cu.init(e,t),e._zod.processJSONSchema=(t,n,r)=>((e,t,n,r)=>{const o=e._zod.def,i="input"===t.io?"transform"===o.in._zod.def.type?o.out:o.in:o.out;Bc(i,t,r),t.seen.get(e).ref=i})(e,t,0,r),e.in=t.in,e.out=t.out});function df(e,t){return new ff({type:"pipe",in:e,out:t})}const lf=bi("ZodReadonly",(e,t)=>{hc.init(e,t),cu.init(e,t),e._zod.processJSONSchema=(t,n,r)=>((e,t,n,r)=>{const o=e._zod.def;Bc(o.innerType,t,r),t.seen.get(e).ref=o.innerType,n.readOnly=!0})(e,t,n,r),e.unwrap=()=>e._zod.def.innerType});const pf=bi("ZodLazy",(e,t)=>{gc.init(e,t),cu.init(e,t),e._zod.processJSONSchema=(t,n,r)=>((e,t,n,r)=>{const o=e._zod.innerType;Bc(o,t,r),t.seen.get(e).ref=o})(e,t,0,r),e.unwrap=()=>e._zod.def.getter()});const hf=bi("ZodCustom",(e,t)=>{yc.init(e,t),cu.init(e,t),e._zod.processJSONSchema=(e,t,n)=>((e,t)=>{if("throw"===t.unrepresentable)throw new Error("Custom types cannot be represented in JSON Schema")})(0,e)});const mf=Nu().min(Number.MIN_SAFE_INTEGER).max(Number.MAX_SAFE_INTEGER).int(),gf=function(e,t={}){const n=new hf({type:"custom",check:"custom",fn:t=>t instanceof e,abort:!0,...Vi(t)});return n._zod.bag.Class=e,n._zod.check=t=>{t.value instanceof e||t.issues.push({code:"invalid_type",expected:e.name,input:t.value,inst:n,path:[...n._zod.def.path??[]]})},n}(Uint8Array),yf=du();mf.min(5e8),mf.min(0).max(255),mf.min(0).max(65535);const _f=mf.min(0).max(4294967295);Nu().refine(e=>String(e).includes(".")).refine(e=>{const t=String(e).split(".").at(1);return void 0!==t&&t.length<=2});const wf=du().regex(/^[0-9a-fA-F]*$/).refine(e=>e.length%2==0),vf=Ju([du(),Nu(),function(e,t){return new e({type:"boolean",...Vi(t)})}(Ru,bf),function(e){return function(e,t){return new e({type:"null",...Vi(t)})}(Zu,e)}()]);var bf;const Ef=new pf({type:"lazy",getter:()=>Ju([vf,Vu(Ef),Yu(yf,Ef)])});gf.refine(e=>20===e.length);const xf=gf.refine(e=>32===e.length),zf=gf.refine(e=>33===e.length),Of=gf.refine(e=>64===e.length);wf.refine(e=>40===e.length);const kf=wf.refine(e=>64===e.length),Sf=wf.refine(e=>66===e.length),Pf=wf.refine(e=>128===e.length);Ju([wf,gf]);const $f=Ju([kf,xf]);Ju([Sf,zf]),Ju([Pf,Of]),du().regex(/^[1-9A-HJ-NP-Za-km-z]+$/),du().regex(/^[a-zA-Z0-9+/]+={0,2}$/),du().regex(/^[a-zA-Z0-9\-_]+={0,2}$/),du().regex(/^[a-z]+1[023456789acdefghjklmnpqrstuvwxyz]+$/);const Af=Ju([Vu($f),$f]),If=Mu({pubkey:$f,leaves:Af.array().optional(),target:$f.optional(),version:_f.optional()});var Tf=Object.freeze({__proto__:null,config:If,taptree:Af});const Nf=function(e){return function(e,t){return new e({type:"bigint",...Vi(t)})}(ju,e)}().min(0n).max(2100000000000000n),Bf=Mu({value:Nf,script_pk:wf}),Uf=Mu({coinbase:wf.nullable(),txid:kf,vout:_f,prevout:Bf.nullable(),script_sig:wf.nullable(),sequence:_f,witness:Vu(wf)}),Rf=Mu({version:_f,vin:Vu(Uf),vout:Vu(Bf),locktime:_f}),jf=Bf.extend({value:Ju([_f,Nf])}),Zf=Uf.extend({coinbase:wf.nullable().optional(),prevout:jf.nullable().optional(),script_sig:wf.nullable().optional(),sequence:Ju([wf,_f]).optional(),witness:Vu(wf).optional()}),Cf=Mu({version:_f.optional(),vin:Vu(Zf),vout:Vu(jf),locktime:_f.optional()});var Ff=Object.freeze({__proto__:null,tx_data:Rf,tx_input:Uf,tx_output:Bf,tx_template:Cf,vin_template:Zf,vout_template:jf}),Hf=Object.freeze({__proto__:null,taproot:Tf,tx:Ff});function Df(e){Cf.parse(e)}function Lf(e){if(e.some(e=>null===e.prevout))throw new Error("transaction missing prevouts")}function Vf(e){Rf.parse(e)}function qf(e){Zf.parse(e)}function Mf(e){jf.parse(e)}function Kf(e,t=!0){Vf(e);const{version:n,vin:r,vout:o,locktime:i}=e,s=[Jf(n)];if(t&&s.push(k.hex("0001")),s.push(Xf(r)),s.push(td(o)),t)for(const e of r)s.push(rd(e.witness));return s.push(od(i)),k.join(s)}function Jf(e){return k.num(e,4).reverse()}function Wf(e){return k.hex(e,32).reverse()}function Gf(e){return k.num(e,4).reverse()}function Yf(e){return k.num(e,4).reverse()}function Xf(e){const t=[k.create_varint(e.length,"le")];for(const n of e)t.push(Qf(n));return k.join(t)}function Qf(e){return null!==e.coinbase?k.join([Wf(t.TXID),Gf(t.VOUT),id(e.coinbase),Yf(e.sequence)]):k.join([Wf(e.txid),Gf(e.vout),id(e.script_sig),Yf(e.sequence)])}function ed(e){return k.big(e,8).reverse()}function td(e){const t=[k.create_varint(e.length,"le")];for(const n of e)t.push(nd(n));return k.join(t)}function nd(e){const{value:t,script_pk:n}=e;return k.join([ed(t),id(n)])}function rd(e){const t=[k.create_varint(e.length)];for(const n of e)t.push(id(n));return k.join(t)}function od(e){return k.num(e,4).reverse()}function id(e){return null!==e?(j.is_hex(e),k.hex(e).prefix_varint("le")):k.hex("00")}function sd(e,t){let n;if("string"==typeof e||e instanceof Uint8Array?n=gi(e):(Df(e),n=gd(e)),t){j.has_items(t,"prevouts must be a non-empty array");for(const[e,r]of n.vin.entries()){const n=t.at(e);j.exists(n,`prevout not found for input index: ${e}`),r.prevout=md(n)}}return n}function ad(e,t=!0){return Kf(gi(e),t)}function cd(e){if(!R.exists(e))return n.SEQUENCE;if(R.is_hex(e))return k.hex(e,4).reverse().num;if(R.is_uint(e))return e;throw new Error(`invalid sequence value: ${String(e)}`)}function ud(e){if(R.is_uint(e))return BigInt(e);if("bigint"==typeof e)return e;throw new TypeError(`invalid output value: ${String(e)}`)}function fd(e){return{script_pk:e.script_pk,value:ud(e.value)}}function dd(e){qf(e),j.exists(e.coinbase,"coinbase is required");const n=t.TXID,r=t.VOUT,o=e.coinbase,i=e.witness??[];return{coinbase:o,prevout:null,script_sig:null,sequence:cd(e.sequence),witness:i,txid:n,vout:r}}function ld(e){qf(e),j.is_empty(e.coinbase,"coinbase is not allowed"),j.is_empty(e.prevout,"prevout is not allowed");const{txid:t,vout:n,script_sig:r=null,witness:o=[]}=e;return{txid:t,vout:n,coinbase:null,prevout:null,script_sig:r,sequence:cd(e.sequence),witness:o}}function pd(e){qf(e),j.exists(e.prevout,"prevout is required");const{txid:t,vout:n,script_sig:r=null,witness:o=[]}=e;return{txid:t,vout:n,coinbase:null,prevout:fd(e.prevout),script_sig:r,sequence:cd(e.sequence),witness:o}}function hd(e){return e.coinbase?dd(e):e.prevout?pd(e):ld(e)}function md(e){Mf(e);return{script_pk:e.script_pk,value:ud(e.value)}}function gd(e){Df(e);const{vin:t=[],vout:r=[]}=e??{vin:[],vout:[]},o=e.locktime??n.LOCKTIME,i=e.version??n.VERSION;return{locktime:o,vin:t.map(e=>hd(e)),vout:r.map(e=>md(e)),version:i}}var yd=Object.freeze({__proto__:null,assert_has_prevouts:Lf,assert_tx_data:Vf,assert_tx_input:function(e){Uf.parse(e)},assert_tx_output:function(e){Bf.parse(e)},assert_tx_spend_data:function(e){Vf(e),Lf(e.vin)},assert_tx_template:Df,assert_vin_template:qf,assert_vout_template:Mf,create_coinbase_input:dd,create_spend_input:pd,create_tx:gd,create_tx_input:hd,create_tx_output:md,create_virtual_input:ld,decode_tx:gi,encode_script_data:id,encode_tx:Kf,encode_tx_inputs:Xf,encode_tx_locktime:od,encode_tx_outputs:td,encode_tx_version:Jf,encode_tx_vout:nd,encode_txin_sequence:Yf,encode_txin_txid:Wf,encode_txin_vout:Gf,encode_vin:Qf,encode_vin_witness:rd,encode_vout_value:ed,get_prevouts:function(e){Df(e);const t=e.vin.map(e=>e.prevout);return j.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+rd(t).length,0)},get_tx_value:function(e){const t=sd(e);Df(t);const n=t.vin.reduce((e,t)=>e+(t.prevout?.value??0n),0n),r=t.vout.reduce((e,t)=>e+t.value,0n);return{fees:n>r?n-r:0n,vin:n,vout:r}},get_txhash:function(e){return"object"==typeof e&&(Df(e),e=Kf(e,!0)),In(e).reverse().hex},get_txid:function(e){let t;if(e instanceof Uint8Array)t=ad(e,!1);else if("object"==typeof e)Df(e),t=Kf(e,!1);else{if("string"!=typeof e)throw new TypeError("invalid txdata type: "+typeof e);j.is_hex(e),t=ad(e,!1)}return In(t).reverse().hex},get_txin_size:function(e){return Qf(e).length},get_txout_size:function(e){return nd(e).length},get_txsize:function(e){const t=sd(e),n=Kf(t,!1).length,r=Kf(t,!0).length,o=3*n+r,i=o%4>0?1:0;return{base:n,total:r,vsize:Math.ceil(o/4)+i,weight:o}},get_vin_size:function(e){return Xf(e).length},get_vout_size:function(e){return td(e).length},get_vsize:function(e){const t=k.bytes(e).length,n=t%4>0?1:0;return Math.ceil(t/4)+n},normalize_prevout:fd,normalize_sequence:cd,normalize_value:ud,parse_tx:sd,read_payload:vi,serialize_tx:function(e){const t=sd(e),n=t.version,r=t.locktime,o=[],i=[];for(const e of t.vin)null!==e.prevout&&o.push({script_pk:e.prevout.script_pk,value:Number(e.prevout.value)});for(const e of t.vout)i.push({script_pk:e.script_pk,value:Number(e.value)});return{version:n,locktime:r,vin:o,vout:i}},transcode_tx:ad});function _d(e){return j.exists(e.prevout,`Prevout data missing for input: ${String(e.txid)}`),e.prevout}function wd(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 j.ok(void 0!==r),r}function vd(e){if(void 0===e)return;if(e.length<2)return;const t=e.at(-1);if("string"==typeof t&&t.startsWith("50")){return An(k.hex(t).prefix_varint("be"))}}function bd(e,t={}){const{sigflag:n=1,txindex:r}=t,o=sd(e),i=!(128&~n),a=n%128;if(!s.includes(a))throw new Error(`Invalid hash type: ${String(n)}`);const{version:c,vin:u,vout:f,locktime:d}=o,l=wd(o,t),{txid:p,vout:h,prevout:m,sequence:g}=l,{value:y}=m??{};if(void 0===y)throw new Error("Prevout value is empty!");let{pubkey:_,script:w}=t;if(void 0===w&&void 0!==_){const e=$n(_).hex;w=`76a914${String(e)}88ac`}if(void 0===w)throw new Error("No pubkey / script has been set!");if(Uo(w).includes("OP_CODESEPARATOR"))throw new Error("This library does not currently support the use of OP_CODESEPARATOR in segwit scripts.");const v=[Jf(c),Ed(u,i),xd(u,a,i),Wf(p),Gf(h),li(w),ed(y),Yf(g),zd(f,a,r),od(d),k.num(n,4).reverse()];return In(k.join(v))}function Ed(e,t){if(!0===t)return k.num(0,32);const n=[];for(const{txid:t,vout:r}of e)n.push(Wf(t)),n.push(Gf(r));return In(k.join(n))}function xd(e,t,n){if(n||1!==t)return k.num(0,32);const r=[];for(const{sequence:t}of e)r.push(Yf(t));return In(k.join(r))}function zd(e,t,n){const r=[];if(1===t){for(const{value:t,script_pk:n}of e)r.push(ed(t)),r.push(li(n));return In(k.join(r))}if(3===t&&(j.ok(void 0!==n,"txindex required for SIGHASH_SINGLE"),j.ok(n>=0,"txindex must be non-negative"),n<e.length)){const{value:t,script_pk:o}=e[n];return r.push(ed(t)),r.push(li(o)),In(k.join(r))}return k.num(0,32)}function Od(e,t=192){return kd(li(e),t)}function kd(e,t=192){return Tn("TapLeaf",Pd(t),e)}function Sd(e,t){return t<e&&([e,t]=[t,e]),Tn("TapBranch",e,t)}function Pd(e=192){return 254&e}function $d(e,t=new Uint8Array){return j.size(e,32),Tn("TapTweak",e,t)}function Ad(e,t={}){return Tn("TapSighash",Id(e,t))}function Id(e,t={}){const{script:n,txindex:r,sigflag:o=0,extflag:i=0,key_version:s=0,separator_pos:c=4294967295}=t,u=sd(e),{version:f,vin:d,vout:l,locktime:p}=u,h=wd(u,t),{txid:m,vout:g,sequence:y,witness:_=[]}=h;if(!a.includes(o))throw new Error(`Invalid hash type: ${String(o)}`);if(i<0||i>127)throw new Error(`Extention flag out of range: ${String(i)}`);let{extension:w}=t;void 0!==n&&(w=Od(n).hex);const v=!(128&~o),b=vd(_),E=2*(i+(void 0!==w?1:0))+(void 0!==b?1:0),x=[k.num(0,1),k.num(o,1),Jf(f),od(p)];if(!v){const e=d.map(e=>_d(e));x.push(Td(d),Bd(e),Ud(e),Nd(d))}if(((3&o)<2||(3&o)>3)&&x.push(Rd(l)),x.push(k.num(E,1)),v){const{value:e,script_pk:t}=_d(h);x.push(Wf(m),Gf(g),ed(e),id(t),Yf(y))}else j.ok("number"==typeof r),x.push(k.num(r,4).reverse());return void 0!==b&&x.push(b),3&~o||(j.ok("number"==typeof r,"txindex required for SIGHASH_SINGLE"),j.ok(r>=0&&r<l.length,`txindex ${r} out of bounds for ${l.length} outputs`),x.push(jd(l[r]))),void 0!==w&&x.push(k.bytes(w),k.num(s),k.num(c,4,"le")),k.join(x)}function Td(e){const t=[];for(const{txid:n,vout:r}of e)t.push(Wf(n)),t.push(Gf(r));return An(k.join(t))}function Nd(e){return An(...e.map(e=>Yf(e.sequence)))}function Bd(e){return An(...e.map(e=>ed(e.value)))}function Ud(e){return An(...e.map(e=>id(e.script_pk)))}function Rd(e){const t=[];for(const{value:n,script_pk:r}of e)t.push(ed(n)),t.push(id(r));return An(...t)}function jd(e){return An(ed(e.value),id(e.script_pk))}var Zd=Object.freeze({__proto__:null,bip143_hash_outputs:zd,bip143_hash_prevouts:Ed,bip143_hash_sequence:xd,bip341_hash_amounts:Bd,bip341_hash_outpoints:Td,bip341_hash_output:jd,bip341_hash_outputs:Rd,bip341_hash_scripts:Ud,bip341_hash_sequence:Nd,get_annex_data:vd,get_prevout:_d,get_taproot_tx_preimage:Id,hash_segwit_tx:bd,hash_taproot_tx:Ad,parse_txinput:wd});const Cd=/^[0-9a-fA-F]{64}$/;function Fd(e){if("string"!=typeof e)throw new Error("Secret key must be a string");if(!Cd.test(e))throw new Error("Invalid secret key format: expected 32-byte hex string (64 characters)")}function Hd(e,t){const{sigflag:n,txindex:r}=e;if(void 0!==n){if("number"!=typeof n||!Number.isInteger(n))throw new Error("sigflag must be an integer");const e=127&n,r=!(128&~n)?128|e:e;if(!t.includes(r)&&!t.includes(e))throw new Error(`Invalid sigflag: ${n}`)}if(void 0!==r&&("number"!=typeof r||!Number.isInteger(r)||r<0))throw new Error("txindex must be a non-negative integer")}function Dd(e){return 0!==e?k.num(e,1).hex:""}function Ld(e){const t=e.map(e=>k.bytes(e)),n=e.map(e=>k.bytes(e).hex),o=function(e){const t=e.at(-1);return e.length>1&&t instanceof Uint8Array&&80===t[0]?new k(t).hex:null}(t);null!==o&&t.pop();const i=function(e){const t=e.at(-1);return e.length>1&&t instanceof Uint8Array&&t.length>32&&r.includes(254&t[0])?new k(t).hex:null}(t);null!==i&&t.pop();const s=function(e,t){const n=e.at(0),r=e.at(1),o=e.at(-1);return null!==t&&void 0!==o?"p2ts":2===e.length&&void 0!==n&&void 0!==r&&n.length>=71&&n.length<=73&&33===r.length?"p2wpkh":1!==e.length||void 0===n||64!==n.length&&65!==n.length?e.length>1&&void 0!==o&&Ro(o)?"p2wsh":null:"p2tr"}(t,i),a=function(e){return null===e?null:e.startsWith("p2w")?0:e.startsWith("p2t")?1:null}(s),c=function(e,t){let n;switch(t){case"p2ts":case"p2wsh":n=e.at(-1)}return void 0!==n?new k(n).hex:null}(t,s);null!==c&&t.pop();return{annex:o,cblock:i,params:t.map(e=>e.hex),script:c,stack:n,type:s,version:a}}function Vd(e){const t=new S(e),n=t.read(1).num,r=t.read(32).hex,[o,i]=qd(n),s=[];for(;t.size>=32;)s.push(t.read(32).hex);if(0!==t.size)throw new Error(`Non-empty buffer on control block: ${String(t)}`);return{int_key:r,path:s,parity:i,version:o}}function qd(e){return e%2==0?[e-0,2]:[e-1,3]}function Md(e){j.size(e,33,"invalid pubkey size");const[t]=k.bytes(e);if(2===t)return 0;if(3===t)return 1;throw new Error(`Invalid parity bit: ${String(t)}`)}function Kd(e,t,n=[],r=0){if(r>128)throw new Error(`Taproot tree depth ${r} exceeds maximum 128`);const o=[],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)){const[e,i,a]=Kd(s,t,[],r+1);t=i,o.push(e);for(const e of a)n.push(e)}else{const e=k.bytes(s).hex;o.push(e)}}if(1===o.length)return[o[0],t,n];o.sort(),o.length%2!=0&&o.push(o[o.length-1]);for(let e=0;e<o.length-1;e+=2){const r=Sd(o[e],o[e+1]).hex;i.push(r),"string"==typeof t&&(t===o[e]?(n.push(o[e+1]),t=r):t===o[e+1]&&(n.push(o[e]),t=r))}return Kd(i,t,n,r+1)}const Jd=192;function Wd(e,t,n){j.size(e,32);const{parity:r,path:o,int_key:i}=Vd(n),s=k.join([r,e]);let a=k.bytes(t).hex;for(const e of o)a=Sd(a,e).hex;const c=dn(i,$d(i,a),"ecdsa");return s.hex===c.hex}function Gd(e,t,n,r){try{const{witness:o=[]}=t;if(0===o.length)return{index:n,valid:!0,type:null};const i=Ld(o.map(e=>k.hex(e))),{type:s,version:a}=i;if(null===s||null===a)return{index:n,valid:!1,type:s,error:"Unknown witness type"};const c=t.prevout;if(null==c)return{index:n,valid:!1,type:s,error:"Missing prevout data"};P(c.script_pk);return 0===a?function(e,t,n,r){const{type:o,params:i,script:s}=r;if(i.length<1)return{index:n,valid:!1,type:o,error:"Missing signature in witness"};const a=i[0],{signature:c,sigflag:u}=function(e){const t=k.hex(e),n=t.at(-1)??1,r=t.slice(0,-1).hex;return{signature:r,sigflag:n}}(a);let f,d;if("p2wpkh"===o){if(i.length<2)return{index:n,valid:!1,type:o,error:"Missing pubkey in P2WPKH witness"};f=i[1];d=`76a914${$n(f).hex}88ac`}else{if("p2wsh"!==o)return{index:n,valid:!1,type:o,error:`Unexpected segwit type: ${o}`};if(null===s)return{index:n,valid:!1,type:o,error:"Missing script in P2WSH witness"};if(d=s,!(i.length>=2))return{index:n,valid:!1,type:o,error:"Missing pubkey in P2WSH witness"};f=i[1]}const l={txindex:n,txinput:t,pubkey:"p2wpkh"===o?f:void 0,script:"p2wsh"===o?d:void 0,sigflag:u},p=bd(e,l),h=function(e,t,n){const r=pn(e),o=pn(t),i=ln(n,"ecdsa");return Kt.verify(r,o,i)}(c,p,f);return{index:n,valid:h,type:o,error:h?void 0:"Invalid ECDSA signature"}}(e,t,n,i):1===a?function(e,t,n,r,o,i){const{type:s,params:a,script:c,cblock:u}=r;if(null==t.prevout)return{index:n,valid:!1,type:s,error:"Missing prevout for taproot verification"};const f=t.prevout;if(a.length<1)return{index:n,valid:!1,type:s,error:"Missing signature in witness"};const d=a[0],{signature:l,sigflag:p}=function(e){const t=k.hex(e);if(64===t.length)return{signature:e,sigflag:0};if(65===t.length){const e=t.at(-1)??0;if(0===e)throw new Error("0x00 is not a valid appended sigflag");return{signature:t.slice(0,64).hex,sigflag:e}}throw new Error(`Invalid Schnorr signature length: ${t.length}`)}(d),h=f.script_pk.slice(4);let m,g;if("p2tr"===s)m=h;else{if("p2ts"!==s)return{index:n,valid:!1,type:s,error:`Unexpected taproot type: ${s}`};{if(null===u||null===c)return{index:n,valid:!1,type:s,error:"Missing cblock or script in script-path spend"};const e=Od(c).hex;if(!Wd(h,e,u))return{index:n,valid:!1,type:s,error:"Control block verification failed"};m=a.length>=2&&64===a[1].length?a[1]:h,g=e}}const y={...i,txindex:n,txinput:t,sigflag:p,extension:g,script:"p2ts"===s?c??void 0:void 0},_=Ad(e,y),w=function(e,t,n){const r=pn(e),o=pn(t),i=ln(n,"bip340");return an.verify(r,o,i)}(l,_,m);return{index:n,valid:w,type:s,error:w?void 0:"Invalid Schnorr signature"}}(e,t,n,i,0,r):{index:n,valid:!1,type:s,error:`Unsupported witness version: ${a}`}}catch(e){return{index:n,valid:!1,error:e instanceof Error?e.message:String(e)}}}var Yd=Object.freeze({__proto__:null,sign_segwit_tx:function(e,t,n){Fd(e),Hd(n,s);return function(e,t){const n=pn(t),r=Kt.sign(n,e).toDERRawBytes();return k.bytes(r)}(e,bd(sd(t),n)).hex+Dd(n.sigflag??1)},sign_taproot_tx:function(e,t,n){Fd(e),Hd(n,a);return function(e,t){const n=pn(t);return pn(an.sign(n,e))}(e,Ad(sd(t),n)).hex+Dd(n.sigflag??0)},verify_tx:function(e,t={}){const{throws:n=!1}=t,r=sd(e),o=[];let i=!0;for(let e=0;e<r.vin.length;e++){const s=r.vin[e];if(null!==s.coinbase){o.push({index:e,valid:!0,type:"coinbase"});continue}const a=Gd(r,s,e,t);if(o.push(a),!a.valid&&(i=!1,n))throw new Error(`Input ${e} verification failed: ${a.error}`)}return{valid:i,inputs:o,error:i?void 0:"One or more inputs failed verification"}}}),Xd=Object.freeze({__proto__:null,create_taproot:function(e){If.parse(e);const{pubkey:t,version:n=Jd}=e,r=e.leaves??[],o=void 0!==e.target?k.bytes(e.target).hex:void 0;let i,s=[];if(r.length>0){const[e,t,n]=Kd(r,o);s=n,i=e}else i=o;const a=$d(t,i),c=dn(t,a,"ecdsa"),u=Md(c),f=ln(c,"bip340"),d=[k.num(n+u),k.bytes(t)];s.length>0&&d.push(...s);const l=k.join(d);return{int_key:k.bytes(t).hex,path:s,parity:u,taproot:i??null,cblock:l.hex,tapkey:f.hex,taptweak:a.hex}},encode_leaf_version:Pd,encode_tapbranch:Sd,encode_tapleaf:kd,encode_tapscript:Od,encode_taptweak:$d,get_merkle_root:function(e){return Kd(e)[0]},merkleize:Kd,parse_cblock:Vd,parse_cblock_parity:qd,parse_pubkey_parity:Md,parse_taproot_witness:function(e){const{cblock:t,params:n,script:r}=Ld(e);j.exists(t,"cblock is null"),j.exists(r,"script is null");const o=Vd(t);let i=Od(r,o.version).hex;for(const e of o.path)i=Sd(i,e).hex;const s=$d(o.int_key,i),a=dn(o.int_key,s,"bip340");return n.map(e=>k.bytes(e).hex),{cblock:o,params:n,script:r,tapkey:a.hex,tweak:s.hex}},verify_taproot:Wd});var Qd=Object.freeze({__proto__:null,assert_witness:function(e){j.ok(Array.isArray(e),"witness must be an array"),j.ok(e.every(e=>k.is_bytes(e)),"witness must be an array of strings or bytes")},get_witness_size:function(e){const t=e.map(e=>k.bytes(e)).reduce((e,t)=>e+t.length,0);return{total:t,vsize:Math.ceil(1+t/4)}},parse_witness:Ld});return e.ADDRESS=lo,e.CONST=l,e.META=di,e.SCHEMA=Hf,e.SCRIPT=pi,e.SIGHASH=Zd,e.SIGNER=Yd,e.TAPROOT=Xd,e.TX=yd,e.WITNESS=Qd,e}({});
|
|
1
|
+
var btc_dev=function(e){"use strict";const t={TXID:"00".repeat(32),VOUT:4294967295},n={LOCKTIME:0,SEQUENCE:4294967295,VERSION:2},r=[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],i={P2PKH:"p2pkh",P2SH:"p2sh",P2WPKH:"p2wpkh",P2WSH:"p2wsh",P2TR:"p2tr",OPRETURN:"opreturn"},o={[i.P2PKH]:/^76a914[0-9a-f]{40}88ac$/i,[i.P2SH]:/^a914[0-9a-f]{40}87$/i,[i.P2WPKH]:/^0014[0-9a-f]{40}$/i,[i.P2WSH]:/^0020[0-9a-f]{64}$/i,[i.P2TR]:/^5120[0-9a-f]{64}$/i,[i.OPRETURN]:/^6a[0-9a-f]{2,}$/i},s=[1,2,3,129,130,131],a=[0,...s],c=1e4,u=52e4;var f,d=Object.freeze({__proto__:null,COINBASE:t,DEFAULT:n,LOCK_SCRIPT_REGEX:o,LOCK_SCRIPT_TYPE:i,MAX_SCRIPT_SIZE:c,MAX_VARINT_SIZE:u,OP_1_OFFSET:80,SCRIPT_INT_KEY:"",SIGHASH_DEFAULT:1,SIGHASH_SEGWIT:s,SIGHASH_TAPROOT:a,SPEND_SCRIPT_TYPE:{P2PKH:"p2pkh",P2SH:"p2sh",P2WPKH:"p2wpkh",P2WSH:"p2wsh",P2TR:"p2tr",P2TS:"p2ts"},TAPLEAF_DEFAULT_VERSION:192,TAPLEAF_VERSIONS:r,TX_SIZE:{GLOBAL_BASE:8,GLOBAL_WIT:10,TXIN_BASE:40,TXOUT_BASE:8}});!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&&Number.isInteger(e)&&e>=0&&e<=255)))}}(f||(f={}));let l=class extends Error{constructor(e){super(e),this.name="ValidationError"}};class p extends l{constructor(e){super(e),this.name="HexValidationError"}}class h extends l{constructor(e){super(e),this.name="ByteRangeError"}}class m extends l{constructor(e){super(e),this.name="IntegerBoundsError"}}class g extends l{constructor(e){super(e),this.name="SizeError"}}var y;!function(e){e.within_size=function(e,t){if(e.length>t)throw new g(`Data is larger than array size: ${e.length} > ${t}`)},e.is_hex=function(e){if(null!==e.match(/[^a-fA-F0-9]/))throw new p(`Invalid characters in hex string: ${e}`);if(e.length%2!=0)throw new p(`Length of hex string is invalid: ${e.length}`)},e.is_bytes=function(e){if(!f.is_bytes(e))throw new h(`Bytes contains invalid elements: ${String(e)}`)},e.is_json=function(e){try{JSON.parse(e)}catch{throw new l("JSON string is invalid!")}},e.is_safe_int=function(e){if(e>Number.MAX_SAFE_INTEGER||e<Number.MIN_SAFE_INTEGER)throw new m("Number exceeds safe bounds!")}}(y||(y={}));const _=BigInt(0),w=BigInt(255),v=BigInt(256);function b(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 r="le"===n,i=new ArrayBuffer(t),o=new DataView(i);let s=r?0:t-1;for(;e>_;){const t=e&w,n=Number(t);r?o.setUint8(s++,n):o.setUint8(s--,n),e=(e-t)/v}return new Uint8Array(i)}function x(e,t){return"bigint"==typeof t?`${t}n`:t}function E(e,t){return"string"==typeof t&&/^[0-9]+n$/.test(t)?BigInt(t.slice(0,-1)):t}function O(e,t,n="be"){void 0===t&&(t=function(e){if(e<0)throw new TypeError("Number must be non-negative");if(e<=255)return 1;if(e<=65535)return 2;if(e<=4294967295)return 4;throw new TypeError("Numbers larger than 4 bytes must specify a fixed size!")}(e));const r="le"===n,i=new ArrayBuffer(t),o=new DataView(i);let s=r?0:t-1;for(;e>0;){const t=255&e;r?o.setUint8(s++,t):o.setUint8(s--,t),e=(e-t)/256}return new Uint8Array(i)}function k(e,t,n="be"){t=function(e,t){y.is_hex(e);const n=e.length/2;void 0===t&&(t=n);if(n>t)throw new TypeError(`Hex string is larger than array size: ${n} > ${t}`);return t}(e,t);const r="be"===n,i=new ArrayBuffer(t),o=new DataView(i);let s=r?0:t-1;for(let t=0;t<e.length;t+=2){const n=e.substring(t,t+2),i=parseInt(n,16);r?o.setUint8(s++,i):o.setUint8(s--,i)}return new Uint8Array(i)}function z(e,t,n){if(e instanceof ArrayBuffer)return new Uint8Array(e);if(e instanceof Uint8Array)return function(e,t,n="le"){void 0===t&&(t=e.length);y.within_size(e,t);const r=new Uint8Array(t).fill(0),i="be"===n?0:t-e.length;return r.set(e,i),r}(e,t,n);if("string"==typeof e)return y.is_hex(e),k(e,t,n);if("bigint"==typeof e)return b(e,t,n);if("number"==typeof e)return O(e,t,n);throw new TypeError("Input type not supported: "+typeof e)}const S=new TextEncoder,$=new TextDecoder;function P(e){return S.encode(e)}function A(e){return $.decode(e)}const I=1048576;class T extends Uint8Array{static{this.num=(e,t,n)=>new T(e,t,n)}static{this.big=(e,t,n)=>new T(e,t,n)}static{this.bin=(e,t,n)=>{const r=function(e){if(!/^[01]*$/.test(e))throw new TypeError("Binary string must contain only 0 and 1 characters");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 T(r,t,n)}}static{this.u8a=(e,t,n)=>new T(e,t,n)}static{this.str=(e,t,n)=>{const r=P(e);return new T(r,t,n)}}static{this.hex=(e,t,n)=>(y.is_hex(e),new T(e,t,n))}static{this.bytes=(e,t,n)=>(y.is_bytes(e),new T(e,t,n))}static{this.json=(e,t)=>{t=t??x;const n=P(JSON.stringify(e,t));return new T(n)}}static{this.chunk=(e,t,n)=>{const r=function(e,t,n){const r=e.length,i=n/t;if(n%t!==0)throw new TypeError(`Invalid parameters: ${n} % ${t} !== 0`);if(r!==n)throw new TypeError(`Invalid data stream: ${r} !== ${n}`);if(r%t!==0)throw new TypeError(`Invalid data stream: ${r} % ${t} !== 0`);const o=new Array(i);for(let n=0;n<i;n++){const r=n*t;o[n]=e.subarray(r,r+t)}return o}(z(e),t,n);return r.map(e=>new T(e))}}static{this.is_equal=(e,t)=>{const n=new T(e),r=new T(t);if(n.length!==r.length)return!1;for(let e=0;e<n.length;e++)if(n[e]!==r[e])return!1;return!0}}static{this.is_bytes=f.is_bytes}static{this.is_hex=f.is_hex}static random(e=32){const t=function(e=32){if(!Number.isInteger(e)||e<0)throw new TypeError("Length must be a non-negative integer");if(e>I)throw new RangeError(`Length exceeds maximum allowed: ${e} > 1048576`);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 T(t,e)}static now(){const e=Math.floor(Date.now()/1e3);return new T(e,4)}constructor(e,t,n){super(z(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 u8a(){return this.to_u8a()}to_big(e="be"){return function(e){let t=BigInt(0);for(let n=e.length-1;n>=0;n--)t=t*v+BigInt(e[n]);return BigInt(t)}("be"===e?this.u8a.reverse():this.u8a)}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.u8a:this.u8a.reverse())}to_json(e){void 0===e&&(e=E);const t=A(this);return JSON.parse(t,e)}to_num(e="be"){return function(e){let t=0;for(let n=e.length-1;n>=0;n--)t=256*t+e[n],y.is_safe_int(t);return t}("be"===e?this.u8a.reverse():this.u8a)}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 A(this)}to_u8a(){return new Uint8Array(this)}append(e){return T.join([this,new T(e)])}equals(e){const t=new T(e);if(this.length!==t.length)return!1;for(let e=0;e<this.length;e++)if(this[e]!==t[e])return!1;return!0}prepend(e){return T.join([new T(e),this])}prefix_varint(e){if(0===this.length)throw new Error("buffer is empty");const t=T.create_varint(this.length,e);return this.prepend(t)}reverse(){return super.reverse(),this}set(e,t){super.set(e,t)}slice(e,t){const n=new Uint8Array(this).slice(e,t);return new T(n)}subarray(e,t){const n=new Uint8Array(this).subarray(e,t);return new T(n)}toJSON(){return this.hex}toString(){return this.hex}static from(e){return new T(Uint8Array.from(e))}static of(...e){return new T(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 T(e)));return new T(t)}static sort(e,t){const n=e.map(e=>new T(e,t).hex);return n.sort(),n.map(e=>T.hex(e,t))}static create_varint(e,t){if(e<0)throw new Error(`Varint cannot be negative: ${e}`);if(e<253)return T.num(e,1);if(e<65536)return T.of(253,...T.num(e,2,t));if(e<4294967296)return T.of(254,...T.num(e,4,t));if(BigInt(e)<0x10000000000000000n)return T.of(255,...T.num(e,8,t));throw new Error(`Value is too large: ${e}`)}}class N{constructor(e){this.data=new T(e),this.size=this.data.length}peek(e){if(e>this.size)throw new Error(`Size greater than stream: ${e} > ${this.size}`);return new T(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}read_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}`)}}}class R extends Error{constructor(e,t){super(e),this.name="ValidationError",this.field=t}}class U extends Error{constructor(e,t){super(e),this.name="DecodingError",this.position=t}}class B extends Error{constructor(e){super(e),this.name="ConfigError"}}function j(e){const t=T.bytes(e).hex;for(const[e,n]of Object.entries(o))if(n.test(t))return e;return null}function Z(e){switch(T.bytes(e).at(0)){case 0:return 0;case 81:return 1;default:return null}}function C(e){const t=T.bytes(e).hex;return o.p2pkh.test(t)}function F(e){const t=T.bytes(e).hex;return o.p2sh.test(t)}function H(e){const t=T.bytes(e).hex;return o.p2wpkh.test(t)}function D(e){const t=T.bytes(e).hex;return o.p2wsh.test(t)}function L(e){const t=T.bytes(e).hex;return o.p2tr.test(t)}function V(e){return null==e||e instanceof Map||e instanceof Set||e instanceof Date||Array.isArray(e)||"object"!=typeof e?e:Object.keys(e).sort().filter(t=>void 0!==e[t]).reduce((t,n)=>(t[n]=e[n],t),{})}var q,M;
|
|
2
|
+
/*! noble-hashes - MIT License (c) 2022 Paul Miller (paulmillr.com) */
|
|
3
|
+
function K(e){return e instanceof Uint8Array||ArrayBuffer.isView(e)&&"Uint8Array"===e.constructor.name}function J(e,t=""){if(!Number.isSafeInteger(e)||e<0){throw new Error(`${t&&`"${t}" `}expected integer >= 0, got ${e}`)}}function G(e,t,n=""){const r=K(e),i=e?.length,o=void 0!==t;if(!r||o&&i!==t){throw new Error((n&&`"${n}" `)+"expected Uint8Array"+(o?` of length ${t}`:"")+", got "+(r?`length=${i}`:"type="+typeof e))}return e}function W(e){if("function"!=typeof e||"function"!=typeof e.create)throw new Error("Hash must wrapped by utils.createHasher");J(e.outputLen),J(e.blockLen)}function Y(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 X(...e){for(let t=0;t<e.length;t++)e[t].fill(0)}function Q(e){return new DataView(e.buffer,e.byteOffset,e.byteLength)}function ee(e,t){return e<<32-t|e>>>t}function te(e,t){return e<<t|e>>>32-t>>>0}!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)}function i(e){return!!n(e)&&(null===e.match(/[^a-fA-F0-9]/)&&e.length%2==0)}function o(e){return"function"==typeof e}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=V(e)),t(n)&&(n=V(n)),JSON.stringify(e)===JSON.stringify(n)},e.has_items=function(e){return Array.isArray(e)&&e.length>0},e.is_string=n,e.is_number=function(e){return"number"==typeof e&&Number.isFinite(e)},e.is_integer=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_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},e.is_null=function(e){return null===e},e.is_undefined=function(e){return void 0===e},e.is_array=function(e){return Array.isArray(e)},e.is_function=o,e.is_error=function(e){return e instanceof Error},e.is_promise=function(e){return e instanceof Promise||t(e)&&o(e.then)&&o(e.catch)}}(q||(q={})),function(e){e.ok=function(e,t){if(!1===e)throw new Error(t??"Assertion failed!")},e.exists=function(e,t){if(!q.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(!q.is_equal(e,t))throw new Error(n??`values are not equal: ${String(e)} !== ${String(t)}`)},e.is_object=function(e,t){if(!q.is_object(e))throw new Error(t??`value is not an object: ${String(e)}`)},e.is_deep_equal=function(e,t,n){if(!q.is_deep_equal(e,t))throw new Error(n??`values are not deep equal: ${String(e)} !== ${String(t)}`)},e.is_number=function(e){if(!q.is_number(e))throw new TypeError(`invalid number: ${String(e)}`)},e.is_integer=function(e){if(!q.is_integer(e))throw new TypeError(`invalid integer: ${String(e)}`)},e.is_bigint=function(e){if(!q.is_bigint(e))throw new TypeError(`invalid bigint: ${String(e)}`)},e.is_hex=function(e){if(!q.is_hex(e))throw new TypeError(`invalid hex: ${String(e)}`)},e.is_uchar=function(e){if(!q.is_uchar(e))throw new TypeError(`invalid unsignedchar: ${String(e)}`)},e.is_ushort=function(e){if(!q.is_ushort(e))throw new TypeError(`invalid unsigned short: ${String(e)}`)},e.is_uint=function(e){if(!q.is_uint(e))throw new TypeError(`invalid unsigned int: ${String(e)}`)},e.is_u8a=function(e){if(!q.is_u8a(e))throw new TypeError(`invalid Uint8Array: ${String(e)}`)},e.is_hash=function(e,t){if(!q.is_hash(e))throw new TypeError(t??`invalid hash: ${String(e)}`)},e.has_items=function(e,t){if(!q.has_items(e))throw new Error(t??"array does not contain any items")},e.is_base58=function(e){if(!q.is_base58(e))throw new Error("invalid base58 string")},e.is_base64=function(e){if(!q.is_base64(e))throw new Error("invalid base64 string")},e.is_b64url=function(e){if(!q.is_b64url(e))throw new Error("invalid base64url string")},e.is_bech32=function(e){if(!q.is_bech32(e))throw new Error("invalid bech32 string")}}(M||(M={}));const ne=(()=>"function"==typeof Uint8Array.from([]).toHex&&"function"==typeof Uint8Array.fromHex)(),re=Array.from({length:256},(e,t)=>t.toString(16).padStart(2,"0"));function ie(e){if(G(e),ne)return e.toHex();let t="";for(let n=0;n<e.length;n++)t+=re[e[n]];return t}const oe=48,se=57,ae=65,ce=70,ue=97,fe=102;function de(e){return e>=oe&&e<=se?e-oe:e>=ae&&e<=ce?e-(ae-10):e>=ue&&e<=fe?e-(ue-10):void 0}function le(e){if("string"!=typeof e)throw new Error("hex string expected, got "+typeof e);if(ne)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=de(e.charCodeAt(i)),o=de(e.charCodeAt(i+1));if(void 0===n||void 0===o){const t=e[i]+e[i+1];throw new Error('hex string expected, got non-hex character "'+t+'" at index '+i)}r[t]=16*n+o}return r}function pe(...e){let t=0;for(let n=0;n<e.length;n++){const r=e[n];G(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}function he(e,t={}){const n=(t,n)=>e(n).update(t).digest(),r=e(void 0);return n.outputLen=r.outputLen,n.blockLen=r.blockLen,n.create=t=>e(t),Object.assign(n,t),Object.freeze(n)}function me(e=32){const t="object"==typeof globalThis?globalThis.crypto:null;if("function"!=typeof t?.getRandomValues)throw new Error("crypto.getRandomValues must be defined");return t.getRandomValues(new Uint8Array(e))}const ge=e=>({oid:Uint8Array.from([6,9,96,134,72,1,101,3,4,2,e])});class ye{oHash;iHash;blockLen;outputLen;finished=!1;destroyed=!1;constructor(e,t){if(W(e),G(t,void 0,"key"),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 n=this.blockLen,r=new Uint8Array(n);r.set(t.length>n?e.create().update(t).digest():t);for(let e=0;e<r.length;e++)r[e]^=54;this.iHash.update(r),this.oHash=e.create();for(let e=0;e<r.length;e++)r[e]^=106;this.oHash.update(r),X(r)}update(e){return Y(this),this.iHash.update(e),this}digestInto(e){Y(this),G(e,this.outputLen,"output"),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||=Object.create(Object.getPrototypeOf(this),{});const{oHash:t,iHash:n,finished:r,destroyed:i,blockLen:o,outputLen:s}=this;return e.finished=r,e.destroyed=i,e.blockLen=o,e.outputLen=s,e.oHash=t._cloneInto(e.oHash),e.iHash=n._cloneInto(e.iHash),e}clone(){return this._cloneInto()}destroy(){this.destroyed=!0,this.oHash.destroy(),this.iHash.destroy()}}const _e=(e,t,n)=>new ye(e,t).update(n).digest();function we(e,t,n){return e&t^~e&n}function ve(e,t,n){return e&t^e&n^t&n}_e.create=(e,t)=>new ye(e,t);class be{blockLen;outputLen;padOffset;isLE;buffer;view;finished=!1;length=0;pos=0;destroyed=!1;constructor(e,t,n,r){this.blockLen=e,this.outputLen=t,this.padOffset=n,this.isLE=r,this.buffer=new Uint8Array(e),this.view=Q(this.buffer)}update(e){Y(this),G(e);const{view:t,buffer:n,blockLen:r}=this,i=e.length;for(let o=0;o<i;){const s=Math.min(r-this.pos,i-o);if(s===r){const t=Q(e);for(;r<=i-o;o+=r)this.process(t,o);continue}n.set(e.subarray(o,o+s),this.pos),this.pos+=s,o+=s,this.pos===r&&(this.process(t,0),this.pos=0)}return this.length+=e.length,this.roundClean(),this}digestInto(e){Y(this),function(e,t){G(e,void 0,"digestInto() output");const n=t.outputLen;if(e.length<n)throw new Error('"digestInto() output" expected to be of length >='+n)}(e,this),this.finished=!0;const{buffer:t,view:n,blockLen:r,isLE:i}=this;let{pos:o}=this;t[o++]=128,X(this.buffer.subarray(o)),this.padOffset>r-o&&(this.process(n,0),o=0);for(let e=o;e<r;e++)t[e]=0;n.setBigUint64(r-8,BigInt(8*this.length),i),this.process(n,0);const s=Q(e),a=this.outputLen;if(a%4)throw new Error("_sha2: outputLen must be aligned to 32bit");const c=a/4,u=this.get();if(c>u.length)throw new Error("_sha2: outputLen bigger than state");for(let e=0;e<c;e++)s.setUint32(4*e,u[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||=new this.constructor,e.set(...this.get());const{blockLen:t,buffer:n,length:r,finished:i,destroyed:o,pos:s}=this;return e.destroyed=o,e.finished=i,e.length=r,e.pos=s,r%t&&e.buffer.set(n),e}clone(){return this._cloneInto()}}const xe=Uint32Array.from([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]),Ee=Uint8Array.from([7,4,13,1,10,6,15,3,12,0,9,5,2,14,11,8]),Oe=(()=>Uint8Array.from(new Array(16).fill(0).map((e,t)=>t)))(),ke=(()=>Oe.map(e=>(9*e+5)%16))(),ze=(()=>{const e=[[Oe],[ke]];for(let t=0;t<4;t++)for(let n of e)n.push(n[t].map(e=>Ee[e]));return e})(),Se=(()=>ze[0])(),$e=(()=>ze[1])(),Pe=[[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)),Ae=Se.map((e,t)=>e.map(e=>Pe[t][e])),Ie=$e.map((e,t)=>e.map(e=>Pe[t][e])),Te=Uint32Array.from([0,1518500249,1859775393,2400959708,2840853838]),Ne=Uint32Array.from([1352829926,1548603684,1836072691,2053994217,0]);function Re(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 Ue=new Uint32Array(16);class Be extends be{h0=1732584193;h1=-271733879;h2=-1732584194;h3=271733878;h4=-1009589776;constructor(){super(64,20,8,!0)}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)Ue[n]=e.getUint32(t,!0);let n=0|this.h0,r=n,i=0|this.h1,o=i,s=0|this.h2,a=s,c=0|this.h3,u=c,f=0|this.h4,d=f;for(let e=0;e<5;e++){const t=4-e,l=Te[e],p=Ne[e],h=Se[e],m=$e[e],g=Ae[e],y=Ie[e];for(let t=0;t<16;t++){const r=te(n+Re(e,i,s,c)+Ue[h[t]]+l,g[t])+f|0;n=f,f=c,c=0|te(s,10),s=i,i=r}for(let e=0;e<16;e++){const n=te(r+Re(t,o,a,u)+Ue[m[e]]+p,y[e])+d|0;r=d,d=u,u=0|te(a,10),a=o,o=n}}this.set(this.h1+s+u|0,this.h2+c+d|0,this.h3+f+r|0,this.h4+n+o|0,this.h0+i+a|0)}roundClean(){X(Ue)}destroy(){this.destroyed=!0,X(this.buffer),this.set(0,0,0,0,0)}}const je=he(()=>new Be),Ze=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]),Ce=new Uint32Array(64);class Fe extends be{constructor(e){super(64,e,8,!1)}get(){const{A:e,B:t,C:n,D:r,E:i,F:o,G:s,H:a}=this;return[e,t,n,r,i,o,s,a]}set(e,t,n,r,i,o,s,a){this.A=0|e,this.B=0|t,this.C=0|n,this.D=0|r,this.E=0|i,this.F=0|o,this.G=0|s,this.H=0|a}process(e,t){for(let n=0;n<16;n++,t+=4)Ce[n]=e.getUint32(t,!1);for(let e=16;e<64;e++){const t=Ce[e-15],n=Ce[e-2],r=ee(t,7)^ee(t,18)^t>>>3,i=ee(n,17)^ee(n,19)^n>>>10;Ce[e]=i+Ce[e-7]+r+Ce[e-16]|0}let{A:n,B:r,C:i,D:o,E:s,F:a,G:c,H:u}=this;for(let e=0;e<64;e++){const t=u+(ee(s,6)^ee(s,11)^ee(s,25))+we(s,a,c)+Ze[e]+Ce[e]|0,f=(ee(n,2)^ee(n,13)^ee(n,22))+ve(n,r,i)|0;u=c,c=a,a=s,s=o+t|0,o=i,i=r,r=n,n=t+f|0}n=n+this.A|0,r=r+this.B|0,i=i+this.C|0,o=o+this.D|0,s=s+this.E|0,a=a+this.F|0,c=c+this.G|0,u=u+this.H|0,this.set(n,r,i,o,s,a,c,u)}roundClean(){X(Ce)}destroy(){this.set(0,0,0,0,0,0,0,0),X(this.buffer)}}class He extends Fe{A=0|xe[0];B=0|xe[1];C=0|xe[2];D=0|xe[3];E=0|xe[4];F=0|xe[5];G=0|xe[6];H=0|xe[7];constructor(){super(32)}}const De=he(()=>new He,ge(1));function Le(...e){const t=T.join(e),n=je(De(t));return new T(n)}function Ve(...e){const t=T.join(e),n=De(t);return new T(n)}function qe(...e){const t=T.join(e),n=De(De(t));return new T(n)}function Me(e,...t){const n=function(e){const t=Ve(T.str(e));return T.join([t,t])}(e);return Ve(T.join([n,...t]))}var Ke;!function(e){e.ok=function(e,t){if(!e)throw new Error(t??"Assertion failed!")},e.size=function(e,t,n){const r=T.bytes(e);if(r.length!==t)throw new Error(n??`invalid input size: ${r.length} !== ${t}`)},e.is_u8a=function(e){if(!(e instanceof Uint8Array))throw new TypeError(`invalid Uint8Array: ${String(e)}`)},e.is_base58=function(e){if("string"!=typeof e||!/^[123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz]+$/.test(e))throw new Error("invalid base58 string")},e.is_base64=function(e){if("string"!=typeof e||0===e.length||!/^[a-zA-Z0-9+/]+={0,2}$/.test(e))throw new Error("invalid base64 string")},e.is_b64url=function(e){if("string"!=typeof e||0===e.length||!/^[a-zA-Z0-9\-_]+={0,2}$/.test(e))throw new Error("invalid base64url string")},e.is_bech32=function(e){if("string"!=typeof e||!/^[a-z]+1[023456789acdefghjklmnpqrstuvwxyz]+$/.test(e))throw new Error("invalid bech32 string")}}(Ke||(Ke={}));
|
|
4
|
+
/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */
|
|
5
|
+
const Je=BigInt(0),Ge=BigInt(1);function We(e,t=""){if("boolean"!=typeof e){throw new Error((t&&`"${t}" `)+"expected boolean, got type="+typeof e)}return e}function Ye(e){if("bigint"==typeof e){if(!it(e))throw new Error("positive bigint expected, got "+e)}else J(e);return e}function Xe(e){const t=Ye(e).toString(16);return 1&t.length?"0"+t:t}function Qe(e){if("string"!=typeof e)throw new Error("hex string expected, got "+typeof e);return""===e?Je:BigInt("0x"+e)}function et(e){return Qe(ie(e))}function tt(e){return Qe(ie(function(e){return Uint8Array.from(e)}(G(e)).reverse()))}function nt(e,t){J(t);const n=le((e=Ye(e)).toString(16).padStart(2*t,"0"));if(n.length!==t)throw new Error("number too large");return n}function rt(e,t){return nt(e,t).reverse()}const it=e=>"bigint"==typeof e&&Je<=e;function ot(e,t,n,r){if(!function(e,t,n){return it(e)&&it(t)&&it(n)&&t<=e&&e<n}(t,n,r))throw new Error("expected valid "+e+": "+n+" <= n < "+r+", got "+t)}const st=e=>(Ge<<BigInt(e))-Ge;function at(e,t={},n={}){if(!e||"object"!=typeof e)throw new Error("expected valid options object");const r=(t,n)=>Object.entries(t).forEach(([t,r])=>function(t,n,r){const i=e[t];if(r&&void 0===i)return;const o=typeof i;if(o!==n||null===i)throw new Error(`param "${t}" is invalid: expected ${n}, got ${o}`)}(t,r,n));r(t,!1),r(n,!0)}function ct(e){const t=new WeakMap;return(n,...r)=>{const i=t.get(n);if(void 0!==i)return i;const o=e(n,...r);return t.set(n,o),o}}
|
|
6
|
+
/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */const ut=BigInt(0),ft=BigInt(1),dt=BigInt(2),lt=BigInt(3),pt=BigInt(4),ht=BigInt(5),mt=BigInt(7),gt=BigInt(8),yt=BigInt(9),_t=BigInt(16);function wt(e,t){const n=e%t;return n>=ut?n:t+n}function vt(e,t,n){let r=e;for(;t-- >ut;)r*=r,r%=n;return r}function bt(e,t){if(e===ut)throw new Error("invert: expected non-zero number");if(t<=ut)throw new Error("invert: expected positive modulus, got "+t);let n=wt(e,t),r=t,i=ut,o=ft;for(;n!==ut;){const e=r%n,t=i-o*(r/n);r=n,n=e,i=o,o=t}if(r!==ft)throw new Error("invert: does not exist");return wt(i,t)}function xt(e,t,n){if(!e.eql(e.sqr(t),n))throw new Error("Cannot find square root")}function Et(e,t){const n=(e.ORDER+ft)/pt,r=e.pow(t,n);return xt(e,r,t),r}function Ot(e,t){const n=(e.ORDER-ht)/gt,r=e.mul(t,dt),i=e.pow(r,n),o=e.mul(t,i),s=e.mul(e.mul(o,dt),i),a=e.mul(o,e.sub(s,e.ONE));return xt(e,a,t),a}function kt(e){if(e<lt)throw new Error("sqrt is not defined for small field");let t=e-ft,n=0;for(;t%dt===ut;)t/=dt,n++;let r=dt;const i=It(e);for(;1===Pt(i,r);)if(r++>1e3)throw new Error("Cannot find square root: probably non-prime P");if(1===n)return Et;let o=i.pow(r,t);const s=(t+ft)/dt;return function(e,r){if(e.is0(r))return r;if(1!==Pt(e,r))throw new Error("Cannot find square root");let i=n,a=e.mul(e.ONE,o),c=e.pow(r,t),u=e.pow(r,s);for(;!e.eql(c,e.ONE);){if(e.is0(c))return e.ZERO;let t=1,n=e.sqr(c);for(;!e.eql(n,e.ONE);)if(t++,n=e.sqr(n),t===i)throw new Error("Cannot find square root");const r=ft<<BigInt(i-t-1),o=e.pow(a,r);i=t,a=e.sqr(o),c=e.mul(c,a),u=e.mul(u,o)}return u}}function zt(e){return e%pt===lt?Et:e%gt===ht?Ot:e%_t===yt?function(e){const t=It(e),n=kt(e),r=n(t,t.neg(t.ONE)),i=n(t,r),o=n(t,t.neg(r)),s=(e+mt)/_t;return(e,t)=>{let n=e.pow(t,s),a=e.mul(n,r);const c=e.mul(n,i),u=e.mul(n,o),f=e.eql(e.sqr(a),t),d=e.eql(e.sqr(c),t);n=e.cmov(n,a,f),a=e.cmov(u,c,d);const l=e.eql(e.sqr(a),t),p=e.cmov(n,a,l);return xt(e,p,t),p}}(e):kt(e)}const St=["create","isValid","is0","neg","inv","sqrt","sqr","eql","add","sub","mul","pow","div","addN","subN","mulN","sqrN"];function $t(e,t,n=!1){const r=new Array(t.length).fill(n?e.ZERO:void 0),i=t.reduce((t,n,i)=>e.is0(n)?t:(r[i]=t,e.mul(t,n)),e.ONE),o=e.inv(i);return t.reduceRight((t,n,i)=>e.is0(n)?t:(r[i]=e.mul(t,r[i]),e.mul(t,n)),o),r}function Pt(e,t){const n=(e.ORDER-ft)/dt,r=e.pow(t,n),i=e.eql(r,e.ONE),o=e.eql(r,e.ZERO),s=e.eql(r,e.neg(e.ONE));if(!i&&!o&&!s)throw new Error("invalid Legendre symbol result");return i?1:o?0:-1}class At{ORDER;BITS;BYTES;isLE;ZERO=ut;ONE=ft;_lengths;_sqrt;_mod;constructor(e,t={}){if(e<=ut)throw new Error("invalid field: expected ORDER > 0, got "+e);let n;this.isLE=!1,null!=t&&"object"==typeof t&&("number"==typeof t.BITS&&(n=t.BITS),"function"==typeof t.sqrt&&(this.sqrt=t.sqrt),"boolean"==typeof t.isLE&&(this.isLE=t.isLE),t.allowedLengths&&(this._lengths=t.allowedLengths?.slice()),"boolean"==typeof t.modFromBytes&&(this._mod=t.modFromBytes));const{nBitLength:r,nByteLength:i}=function(e,t){void 0!==t&&J(t);const n=void 0!==t?t:e.toString(2).length;return{nBitLength:n,nByteLength:Math.ceil(n/8)}}(e,n);if(i>2048)throw new Error("invalid field: expected ORDER of <= 2048 bytes");this.ORDER=e,this.BITS=r,this.BYTES=i,this._sqrt=void 0,Object.preventExtensions(this)}create(e){return wt(e,this.ORDER)}isValid(e){if("bigint"!=typeof e)throw new Error("invalid field element: expected bigint, got "+typeof e);return ut<=e&&e<this.ORDER}is0(e){return e===ut}isValidNot0(e){return!this.is0(e)&&this.isValid(e)}isOdd(e){return(e&ft)===ft}neg(e){return wt(-e,this.ORDER)}eql(e,t){return e===t}sqr(e){return wt(e*e,this.ORDER)}add(e,t){return wt(e+t,this.ORDER)}sub(e,t){return wt(e-t,this.ORDER)}mul(e,t){return wt(e*t,this.ORDER)}pow(e,t){return function(e,t,n){if(n<ut)throw new Error("invalid exponent, negatives unsupported");if(n===ut)return e.ONE;if(n===ft)return t;let r=e.ONE,i=t;for(;n>ut;)n&ft&&(r=e.mul(r,i)),i=e.sqr(i),n>>=ft;return r}(this,e,t)}div(e,t){return wt(e*bt(t,this.ORDER),this.ORDER)}sqrN(e){return e*e}addN(e,t){return e+t}subN(e,t){return e-t}mulN(e,t){return e*t}inv(e){return bt(e,this.ORDER)}sqrt(e){return this._sqrt||(this._sqrt=zt(this.ORDER)),this._sqrt(this,e)}toBytes(e){return this.isLE?rt(e,this.BYTES):nt(e,this.BYTES)}fromBytes(e,t=!1){G(e);const{_lengths:n,BYTES:r,isLE:i,ORDER:o,_mod:s}=this;if(n){if(!n.includes(e.length)||e.length>r)throw new Error("Field.fromBytes: expected "+n+" bytes, got "+e.length);const t=new Uint8Array(r);t.set(e,i?0:t.length-e.length),e=t}if(e.length!==r)throw new Error("Field.fromBytes: expected "+r+" bytes, got "+e.length);let a=i?tt(e):et(e);if(s&&(a=wt(a,o)),!t&&!this.isValid(a))throw new Error("invalid field element: outside of range 0..ORDER");return a}invertBatch(e){return $t(this,e)}cmov(e,t,n){return n?t:e}}function It(e,t={}){return new At(e,t)}function Tt(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 Nt(e){const t=Tt(e);return t+Math.ceil(t/2)}function Rt(e,t,n=!1){G(e);const r=e.length,i=Tt(t),o=Nt(t);if(r<16||r<o||r>1024)throw new Error("expected "+o+"-1024 bytes of input, got "+r);const s=wt(n?tt(e):et(e),t-ft)+ft;return n?rt(s,i):nt(s,i)}
|
|
7
|
+
/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */const Ut=BigInt(0),Bt=BigInt(1);function jt(e,t){const n=t.negate();return e?n:t}function Zt(e,t){const n=$t(e.Fp,t.map(e=>e.Z));return t.map((t,r)=>e.fromAffine(t.toAffine(n[r])))}function Ct(e,t){if(!Number.isSafeInteger(e)||e<=0||e>t)throw new Error("invalid window size, expected [1.."+t+"], got W="+e)}function Ft(e,t){Ct(e,t);const n=2**e;return{windows:Math.ceil(t/e)+1,windowSize:2**(e-1),mask:st(e),maxNumber:n,shiftBy:BigInt(e)}}function Ht(e,t,n){const{windowSize:r,mask:i,maxNumber:o,shiftBy:s}=n;let a=Number(e&i),c=e>>s;a>r&&(a-=o,c+=Bt);const u=t*r;return{nextN:c,offset:u+Math.abs(a)-1,isZero:0===a,isNeg:a<0,isNegF:t%2!=0,offsetF:u}}const Dt=new WeakMap,Lt=new WeakMap;function Vt(e){return Lt.get(e)||1}function qt(e){if(e!==Ut)throw new Error("invalid wNAF")}class Mt{BASE;ZERO;Fn;bits;constructor(e,t){this.BASE=e.BASE,this.ZERO=e.ZERO,this.Fn=e.Fn,this.bits=t}_unsafeLadder(e,t,n=this.ZERO){let r=e;for(;t>Ut;)t&Bt&&(n=n.add(r)),r=r.double(),t>>=Bt;return n}precomputeWindow(e,t){const{windows:n,windowSize:r}=Ft(t,this.bits),i=[];let o=e,s=o;for(let e=0;e<n;e++){s=o,i.push(s);for(let e=1;e<r;e++)s=s.add(o),i.push(s);o=s.double()}return i}wNAF(e,t,n){if(!this.Fn.isValid(n))throw new Error("invalid scalar");let r=this.ZERO,i=this.BASE;const o=Ft(e,this.bits);for(let e=0;e<o.windows;e++){const{nextN:s,offset:a,isZero:c,isNeg:u,isNegF:f,offsetF:d}=Ht(n,e,o);n=s,c?i=i.add(jt(f,t[d])):r=r.add(jt(u,t[a]))}return qt(n),{p:r,f:i}}wNAFUnsafe(e,t,n,r=this.ZERO){const i=Ft(e,this.bits);for(let e=0;e<i.windows&&n!==Ut;e++){const{nextN:o,offset:s,isZero:a,isNeg:c}=Ht(n,e,i);if(n=o,!a){const e=t[s];r=r.add(c?e.negate():e)}}return qt(n),r}getPrecomputes(e,t,n){let r=Dt.get(t);return r||(r=this.precomputeWindow(t,e),1!==e&&("function"==typeof n&&(r=n(r)),Dt.set(t,r))),r}cached(e,t,n){const r=Vt(e);return this.wNAF(r,this.getPrecomputes(r,e,n),t)}unsafe(e,t,n,r){const i=Vt(e);return 1===i?this._unsafeLadder(e,t,r):this.wNAFUnsafe(i,this.getPrecomputes(i,e,n),t,r)}createCache(e,t){Ct(t,this.bits),Lt.set(e,t),Dt.delete(e)}hasCache(e){return 1!==Vt(e)}}function Kt(e,t,n){if(t){if(t.ORDER!==e)throw new Error("Field.ORDER must match order: Fp == p, Fn == n");return function(e){at(e,St.reduce((e,t)=>(e[t]="function",e),{ORDER:"bigint",BYTES:"number",BITS:"number"}))}(t),t}return It(e,{isLE:n})}function Jt(e,t){return function(n){const r=e(n);return{secretKey:r,publicKey:t(r)}}}
|
|
8
|
+
/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */const Gt=(e,t)=>(e+(e>=0?t:-t)/rn)/t;function Wt(e,t,n){const[[r,i],[o,s]]=t,a=Gt(s*e,n),c=Gt(-i*e,n);let u=e-a*r-c*o,f=-a*i-c*s;const d=u<tn,l=f<tn;d&&(u=-u),l&&(f=-f);const p=st(Math.ceil(function(e){let t;for(t=0;e>Je;e>>=Ge,t+=1);return t}(n)/2))+nn;if(u<tn||u>=p||f<tn||f>=p)throw new Error("splitScalar (endomorphism): failed, k="+e);return{k1neg:d,k1:u,k2neg:l,k2:f}}function Yt(e){if(!["compact","recovered","der"].includes(e))throw new Error('Signature format must be "compact", "recovered", or "der"');return e}function Xt(e,t){const n={};for(let r of Object.keys(t))n[r]=void 0===e[r]?t[r]:e[r];return We(n.lowS,"lowS"),We(n.prehash,"prehash"),void 0!==n.format&&Yt(n.format),n}class Qt extends Error{constructor(e=""){super(e)}}const en={Err:Qt,_tlv:{encode:(e,t)=>{const{Err:n}=en;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=Xe(r);if(i.length/2&128)throw new n("tlv.encode: long form length too big");const o=r>127?Xe(i.length/2|128):"";return Xe(e)+o+i+t},decode(e,t){const{Err:n}=en;let r=0;if(e<0||e>256)throw new n("tlv.encode: wrong tag");if(t.length<2||t[r++]!==e)throw new n("tlv.decode: wrong tlv");const i=t[r++];let o=0;if(!!(128&i)){const e=127&i;if(!e)throw new n("tlv.decode(long): indefinite length not supported");if(e>4)throw new n("tlv.decode(long): byte length is too big");const s=t.subarray(r,r+e);if(s.length!==e)throw new n("tlv.decode: length bytes not complete");if(0===s[0])throw new n("tlv.decode(long): zero leftmost byte");for(const e of s)o=o<<8|e;if(r+=e,o<128)throw new n("tlv.decode(long): not minimal encoding")}else o=i;const s=t.subarray(r,r+o);if(s.length!==o)throw new n("tlv.decode: wrong value length");return{v:s,l:t.subarray(r+o)}}},_int:{encode(e){const{Err:t}=en;if(e<tn)throw new t("integer: negative integers are not allowed");let n=Xe(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}=en;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 et(e)}},toSig(e){const{Err:t,_int:n,_tlv:r}=en,i=G(e,void 0,"signature"),{v:o,l:s}=r.decode(48,i);if(s.length)throw new t("invalid signature: left bytes after parsing");const{v:a,l:c}=r.decode(2,o),{v:u,l:f}=r.decode(2,c);if(f.length)throw new t("invalid signature: left bytes after parsing");return{r:n.decode(a),s:n.decode(u)}},hexFromSig(e){const{_tlv:t,_int:n}=en,r=t.encode(2,n.encode(e.r))+t.encode(2,n.encode(e.s));return t.encode(48,r)}},tn=BigInt(0),nn=BigInt(1),rn=BigInt(2),on=BigInt(3),sn=BigInt(4);function an(e,t={}){const n=function(e,t,n={},r){if(void 0===r&&(r="edwards"===e),!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>Ut))throw new Error(`CURVE.${e} must be positive bigint`)}const i=Kt(t.p,n.Fp,r),o=Kt(t.n,n.Fn,r),s=["Gx","Gy","a","b"];for(const e of s)if(!i.isValid(t[e]))throw new Error(`CURVE.${e} must be valid field element of CURVE.Fp`);return{CURVE:t=Object.freeze(Object.assign({},t)),Fp:i,Fn:o}}("weierstrass",e,t),{Fp:r,Fn:i}=n;let o=n.CURVE;const{h:s,n:a}=o;at(t,{},{allowInfinityPoint:"boolean",clearCofactor:"function",isTorsionFree:"function",fromBytes:"function",toBytes:"function",endo:"object"});const{endo:c}=t;if(c&&(!r.is0(o.a)||"bigint"!=typeof c.beta||!Array.isArray(c.basises)))throw new Error('invalid endo: expected "beta": bigint and "basises": array');const u=un(r,i);function f(){if(!r.isOdd)throw new Error("compression is not supported: Field does not have .isOdd()")}const d=t.toBytes||function(e,t,n){const{x:i,y:o}=t.toAffine(),s=r.toBytes(i);if(We(n,"isCompressed"),n){f();return pe(cn(!r.isOdd(o)),s)}return pe(Uint8Array.of(4),s,r.toBytes(o))},l=t.fromBytes||function(e){G(e,void 0,"Point");const{publicKey:t,publicKeyUncompressed:n}=u,i=e.length,o=e[0],s=e.subarray(1);if(i!==t||2!==o&&3!==o){if(i===n&&4===o){const e=r.BYTES,t=r.fromBytes(s.subarray(0,e)),n=r.fromBytes(s.subarray(e,2*e));if(!h(t,n))throw new Error("bad point: is not on curve");return{x:t,y:n}}throw new Error(`bad point: got length ${i}, expected compressed=${t} or uncompressed=${n}`)}{const e=r.fromBytes(s);if(!r.isValid(e))throw new Error("bad point: is not on curve, wrong x");const t=p(e);let n;try{n=r.sqrt(t)}catch(e){const t=e instanceof Error?": "+e.message:"";throw new Error("bad point: is not on curve, sqrt error"+t)}f();return!(1&~o)!==r.isOdd(n)&&(n=r.neg(n)),{x:e,y:n}}};function p(e){const t=r.sqr(e),n=r.mul(t,e);return r.add(r.add(n,r.mul(e,o.a)),o.b)}function h(e,t){const n=r.sqr(t),i=p(e);return r.eql(n,i)}if(!h(o.Gx,o.Gy))throw new Error("bad curve params: generator point");const m=r.mul(r.pow(o.a,on),sn),g=r.mul(r.sqr(o.b),BigInt(27));if(r.is0(r.add(m,g)))throw new Error("bad curve params: a or b");function y(e,t,n=!1){if(!r.isValid(t)||n&&r.is0(t))throw new Error(`bad point coordinate ${e}`);return t}function _(e){if(!(e instanceof E))throw new Error("Weierstrass Point expected")}function w(e){if(!c||!c.basises)throw new Error("no endo");return Wt(e,c.basises,i.ORDER)}const v=ct((e,t)=>{const{X:n,Y:i,Z:o}=e;if(r.eql(o,r.ONE))return{x:n,y:i};const s=e.is0();null==t&&(t=s?r.ONE:r.inv(o));const a=r.mul(n,t),c=r.mul(i,t),u=r.mul(o,t);if(s)return{x:r.ZERO,y:r.ZERO};if(!r.eql(u,r.ONE))throw new Error("invZ was invalid");return{x:a,y:c}}),b=ct(e=>{if(e.is0()){if(t.allowInfinityPoint&&!r.is0(e.Y))return;throw new Error("bad point: ZERO")}const{x:n,y:i}=e.toAffine();if(!r.isValid(n)||!r.isValid(i))throw new Error("bad point: x or y not field elements");if(!h(n,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 x(e,t,n,i,o){return n=new E(r.mul(n.X,e),n.Y,n.Z),t=jt(i,t),n=jt(o,n),t.add(n)}class E{static BASE=new E(o.Gx,o.Gy,r.ONE);static ZERO=new E(r.ZERO,r.ONE,r.ZERO);static Fp=r;static Fn=i;X;Y;Z;constructor(e,t,n){this.X=y("x",e),this.Y=y("y",t,!0),this.Z=y("z",n),Object.freeze(this)}static CURVE(){return o}static fromAffine(e){const{x:t,y:n}=e||{};if(!e||!r.isValid(t)||!r.isValid(n))throw new Error("invalid affine point");if(e instanceof E)throw new Error("projective point not allowed");return r.is0(t)&&r.is0(n)?E.ZERO:new E(t,n,r.ONE)}static fromBytes(e){const t=E.fromAffine(l(G(e,void 0,"point")));return t.assertValidity(),t}static fromHex(e){return E.fromBytes(le(e))}get x(){return this.toAffine().x}get y(){return this.toAffine().y}precompute(e=8,t=!0){return k.createCache(this,e),t||this.multiply(on),this}assertValidity(){b(this)}hasEvenY(){const{y:e}=this.toAffine();if(!r.isOdd)throw new Error("Field doesn't support isOdd");return!r.isOdd(e)}equals(e){_(e);const{X:t,Y:n,Z:i}=this,{X:o,Y:s,Z:a}=e,c=r.eql(r.mul(t,a),r.mul(o,i)),u=r.eql(r.mul(n,a),r.mul(s,i));return c&&u}negate(){return new E(this.X,r.neg(this.Y),this.Z)}double(){const{a:e,b:t}=o,n=r.mul(t,on),{X:i,Y:s,Z:a}=this;let c=r.ZERO,u=r.ZERO,f=r.ZERO,d=r.mul(i,i),l=r.mul(s,s),p=r.mul(a,a),h=r.mul(i,s);return h=r.add(h,h),f=r.mul(i,a),f=r.add(f,f),c=r.mul(e,f),u=r.mul(n,p),u=r.add(c,u),c=r.sub(l,u),u=r.add(l,u),u=r.mul(c,u),c=r.mul(h,c),f=r.mul(n,f),p=r.mul(e,p),h=r.sub(d,p),h=r.mul(e,h),h=r.add(h,f),f=r.add(d,d),d=r.add(f,d),d=r.add(d,p),d=r.mul(d,h),u=r.add(u,d),p=r.mul(s,a),p=r.add(p,p),d=r.mul(p,h),c=r.sub(c,d),f=r.mul(p,l),f=r.add(f,f),f=r.add(f,f),new E(c,u,f)}add(e){_(e);const{X:t,Y:n,Z:i}=this,{X:s,Y:a,Z:c}=e;let u=r.ZERO,f=r.ZERO,d=r.ZERO;const l=o.a,p=r.mul(o.b,on);let h=r.mul(t,s),m=r.mul(n,a),g=r.mul(i,c),y=r.add(t,n),w=r.add(s,a);y=r.mul(y,w),w=r.add(h,m),y=r.sub(y,w),w=r.add(t,i);let v=r.add(s,c);return w=r.mul(w,v),v=r.add(h,g),w=r.sub(w,v),v=r.add(n,i),u=r.add(a,c),v=r.mul(v,u),u=r.add(m,g),v=r.sub(v,u),d=r.mul(l,w),u=r.mul(p,g),d=r.add(u,d),u=r.sub(m,d),d=r.add(m,d),f=r.mul(u,d),m=r.add(h,h),m=r.add(m,h),g=r.mul(l,g),w=r.mul(p,w),m=r.add(m,g),g=r.sub(h,g),g=r.mul(l,g),w=r.add(w,g),h=r.mul(m,w),f=r.add(f,h),h=r.mul(v,w),u=r.mul(y,u),u=r.sub(u,h),h=r.mul(y,m),d=r.mul(v,d),d=r.add(d,h),new E(u,f,d)}subtract(e){return this.add(e.negate())}is0(){return this.equals(E.ZERO)}multiply(e){const{endo:n}=t;if(!i.isValidNot0(e))throw new Error("invalid scalar: out of range");let r,o;const s=e=>k.cached(this,e,e=>Zt(E,e));if(n){const{k1neg:t,k1:i,k2neg:a,k2:c}=w(e),{p:u,f:f}=s(i),{p:d,f:l}=s(c);o=f.add(l),r=x(n.beta,u,d,t,a)}else{const{p:t,f:n}=s(e);r=t,o=n}return Zt(E,[r,o])[0]}multiplyUnsafe(e){const{endo:n}=t,r=this;if(!i.isValid(e))throw new Error("invalid scalar: out of range");if(e===tn||r.is0())return E.ZERO;if(e===nn)return r;if(k.hasCache(this))return this.multiply(e);if(n){const{k1neg:t,k1:i,k2neg:o,k2:s}=w(e),{p1:a,p2:c}=function(e,t,n,r){let i=t,o=e.ZERO,s=e.ZERO;for(;n>Ut||r>Ut;)n&Bt&&(o=o.add(i)),r&Bt&&(s=s.add(i)),i=i.double(),n>>=Bt,r>>=Bt;return{p1:o,p2:s}}(E,r,i,s);return x(n.beta,a,c,t,o)}return k.unsafe(r,e)}toAffine(e){return v(this,e)}isTorsionFree(){const{isTorsionFree:e}=t;return s===nn||(e?e(E,this):k.unsafe(this,a).is0())}clearCofactor(){const{clearCofactor:e}=t;return s===nn?this:e?e(E,this):this.multiplyUnsafe(s)}isSmallOrder(){return this.multiplyUnsafe(s).is0()}toBytes(e=!0){return We(e,"isCompressed"),this.assertValidity(),d(E,this,e)}toHex(e=!0){return ie(this.toBytes(e))}toString(){return`<Point ${this.is0()?"ZERO":this.toHex()}>`}}const O=i.BITS,k=new Mt(E,t.endo?Math.ceil(O/2):O);return E.BASE.precompute(8),E}function cn(e){return Uint8Array.of(e?2:3)}function un(e,t){return{secretKey:t.BYTES,publicKey:1+e.BYTES,publicKeyUncompressed:1+2*e.BYTES,publicKeyHasPrefix:!0,signature:2*t.BYTES}}function fn(e,t,n={}){W(t),at(n,{},{hmac:"function",lowS:"boolean",randomBytes:"function",bits2int:"function",bits2int_modN:"function"});const r=(n=Object.assign({},n)).randomBytes||me,i=n.hmac||((e,n)=>_e(t,e,n)),{Fp:o,Fn:s}=e,{ORDER:a,BITS:c}=s,{keygen:u,getPublicKey:f,getSharedSecret:d,utils:l,lengths:p}=function(e,t={}){const{Fn:n}=e,r=t.randomBytes||me,i=Object.assign(un(e.Fp,n),{seed:Nt(n.ORDER)});function o(e=r(i.seed)){return Rt(G(e,i.seed,"seed"),n.ORDER)}function s(t,r=!0){return e.BASE.multiply(n.fromBytes(t)).toBytes(r)}function a(e){const{secretKey:t,publicKey:r,publicKeyUncompressed:o}=i;if(!K(e))return;if("_lengths"in n&&n._lengths||t===r)return;const s=G(e,void 0,"key").length;return s===r||s===o}const c={isValidSecretKey:function(e){try{const t=n.fromBytes(e);return n.isValidNot0(t)}catch(e){return!1}},isValidPublicKey:function(t,n){const{publicKey:r,publicKeyUncompressed:o}=i;try{const i=t.length;return!(!0===n&&i!==r||!1===n&&i!==o||!e.fromBytes(t))}catch(e){return!1}},randomSecretKey:o},u=Jt(o,s);return Object.freeze({getPublicKey:s,getSharedSecret:function(t,r,i=!0){if(!0===a(t))throw new Error("first arg must be private key");if(!1===a(r))throw new Error("second arg must be public key");const o=n.fromBytes(t);return e.fromBytes(r).multiply(o).toBytes(i)},keygen:u,Point:e,utils:c,lengths:i})}(e,n),h={prehash:!0,lowS:"boolean"!=typeof n.lowS||n.lowS,format:"compact",extraEntropy:!1},m=a*rn<o.ORDER;function g(e){return e>a>>nn}function y(e,t){if(!s.isValidNot0(t))throw new Error(`invalid signature ${e}: out of range 1..Point.Fn.ORDER`);return t}function _(){if(m)throw new Error('"recovered" sig type is not supported for cofactor >2 curves')}function w(e,t){Yt(t);const n=p.signature;return G(e,"compact"===t?n:"recovered"===t?n+1:void 0)}class v{r;s;recovery;constructor(e,t,n){if(this.r=y("r",e),this.s=y("s",t),null!=n){if(_(),![0,1,2,3].includes(n))throw new Error("invalid recovery id");this.recovery=n}Object.freeze(this)}static fromBytes(e,t=h.format){let n;if(w(e,t),"der"===t){const{r:t,s:n}=en.toSig(G(e));return new v(t,n)}"recovered"===t&&(n=e[0],t="compact",e=e.subarray(1));const r=p.signature/2,i=e.subarray(0,r),o=e.subarray(r,2*r);return new v(s.fromBytes(i),s.fromBytes(o),n)}static fromHex(e,t){return this.fromBytes(le(e),t)}assertRecovery(){const{recovery:e}=this;if(null==e)throw new Error("invalid recovery id: must be present");return e}addRecoveryBit(e){return new v(this.r,this.s,e)}recoverPublicKey(t){const{r:n,s:r}=this,i=this.assertRecovery(),c=2===i||3===i?n+a:n;if(!o.isValid(c))throw new Error("invalid recovery id: sig.r+curve.n != R.x");const u=o.toBytes(c),f=e.fromBytes(pe(cn(!(1&i)),u)),d=s.inv(c),l=x(G(t,void 0,"msgHash")),p=s.create(-l*d),h=s.create(r*d),m=e.BASE.multiplyUnsafe(p).add(f.multiplyUnsafe(h));if(m.is0())throw new Error("invalid recovery: point at infinify");return m.assertValidity(),m}hasHighS(){return g(this.s)}toBytes(e=h.format){if(Yt(e),"der"===e)return le(en.hexFromSig(this));const{r:t,s:n}=this,r=s.toBytes(t),i=s.toBytes(n);return"recovered"===e?(_(),pe(Uint8Array.of(this.assertRecovery()),r,i)):pe(r,i)}toHex(e){return ie(this.toBytes(e))}}const b=n.bits2int||function(e){if(e.length>8192)throw new Error("input is too large");const t=et(e),n=8*e.length-c;return n>0?t>>BigInt(n):t},x=n.bits2int_modN||function(e){return s.create(b(e))},E=st(c);function O(e){return ot("num < 2^"+c,e,tn,E),s.toBytes(e)}function k(e,n){return G(e,void 0,"message"),n?G(t(e),void 0,"prehashed message"):e}return Object.freeze({keygen:u,getPublicKey:f,getSharedSecret:d,utils:l,lengths:p,Point:e,sign:function(n,o,a={}){const{seed:c,k2sig:u}=function(t,n,i){const{lowS:o,prehash:a,extraEntropy:c}=Xt(i,h);t=k(t,a);const u=x(t),f=s.fromBytes(n);if(!s.isValidNot0(f))throw new Error("invalid private key");const d=[O(f),O(u)];if(null!=c&&!1!==c){const e=!0===c?r(p.secretKey):c;d.push(G(e,void 0,"extraEntropy"))}const l=pe(...d),y=u;return{seed:l,k2sig:function(t){const n=b(t);if(!s.isValidNot0(n))return;const r=s.inv(n),i=e.BASE.multiply(n).toAffine(),a=s.create(i.x);if(a===tn)return;const c=s.create(r*s.create(y+a*f));if(c===tn)return;let u=(i.x===a?0:2)|Number(i.y&nn),d=c;return o&&g(c)&&(d=s.neg(c),u^=1),new v(a,d,m?void 0:u)}}}(n,o,a);return function(e,t,n){if(J(e,"hashLen"),J(t,"qByteLen"),"function"!=typeof n)throw new Error("hmacFn must be a function");const r=e=>new Uint8Array(e),i=Uint8Array.of(),o=Uint8Array.of(0),s=Uint8Array.of(1);let a=r(e),c=r(e),u=0;const f=()=>{a.fill(1),c.fill(0),u=0},d=(...e)=>n(c,pe(a,...e)),l=(e=i)=>{c=d(o,e),a=d(),0!==e.length&&(c=d(s,e),a=d())},p=()=>{if(u++>=1e3)throw new Error("drbg: tried max amount of iterations");let e=0;const n=[];for(;e<t;){a=d();const t=a.slice();n.push(t),e+=a.length}return pe(...n)};return(e,t)=>{let n;for(f(),l(e);!(n=t(p()));)l();return f(),n}}(t.outputLen,s.BYTES,i)(c,u).toBytes(a.format)},verify:function(t,n,r,i={}){const{lowS:o,prehash:a,format:c}=Xt(i,h);if(r=G(r,void 0,"publicKey"),n=k(n,a),!K(t)){throw new Error("verify expects Uint8Array signature"+(t instanceof v?", use sig.toBytes()":""))}w(t,c);try{const i=v.fromBytes(t,c),a=e.fromBytes(r);if(o&&i.hasHighS())return!1;const{r:u,s:f}=i,d=x(n),l=s.inv(f),p=s.create(d*l),h=s.create(u*l),m=e.BASE.multiplyUnsafe(p).add(a.multiplyUnsafe(h));if(m.is0())return!1;return s.create(m.x)===u}catch(e){return!1}},recoverPublicKey:function(e,t,n={}){const{prehash:r}=Xt(n,h);return t=k(t,r),v.fromBytes(e,"recovered").recoverPublicKey(t).toBytes()},Signature:v,hash:t})}
|
|
9
|
+
/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */const dn={p:BigInt("0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f"),n:BigInt("0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141"),h:BigInt(1),a:BigInt(0),b:BigInt(7),Gx:BigInt("0x79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798"),Gy:BigInt("0x483ada7726a3c4655da4fbfc0e1108a8fd17b448a68554199c47d08ffb10d4b8")},ln={beta:BigInt("0x7ae96a2b657c07106e64479eac3434e99cf0497512f58995c1396c28719501ee"),basises:[[BigInt("0x3086d221a7d46bcde86c90e49284eb15"),-BigInt("0xe4437ed6010e88286f547fa90abfe4c3")],[BigInt("0x114ca50f7a8e2f3f657c1108d9d44cfd8"),BigInt("0x3086d221a7d46bcde86c90e49284eb15")]]},pn=BigInt(0),hn=BigInt(2);const mn=It(dn.p,{sqrt:function(e){const t=dn.p,n=BigInt(3),r=BigInt(6),i=BigInt(11),o=BigInt(22),s=BigInt(23),a=BigInt(44),c=BigInt(88),u=e*e*e%t,f=u*u*e%t,d=vt(f,n,t)*f%t,l=vt(d,n,t)*f%t,p=vt(l,hn,t)*u%t,h=vt(p,i,t)*p%t,m=vt(h,o,t)*h%t,g=vt(m,a,t)*m%t,y=vt(g,c,t)*g%t,_=vt(y,a,t)*m%t,w=vt(_,n,t)*f%t,v=vt(w,s,t)*h%t,b=vt(v,r,t)*u%t,x=vt(b,hn,t);if(!mn.eql(mn.sqr(x),e))throw new Error("Cannot find square root");return x}}),gn=an(dn,{Fp:mn,endo:ln}),yn=fn(gn,De),_n={};function wn(e,...t){let n=_n[e];if(void 0===n){const t=De((r=e,Uint8Array.from(r,(e,t)=>{const n=e.charCodeAt(0);if(1!==e.length||n>127)throw new Error(`string contains non-ASCII character "${r[t]}" with code ${n} at position ${t}`);return n})));n=pe(t,t),_n[e]=n}var r;return De(pe(n,...t))}const vn=e=>e.toBytes(!0).slice(1),bn=e=>e%hn===pn;function xn(e){const{Fn:t,BASE:n}=gn,r=t.fromBytes(e),i=n.multiply(r);return{scalar:bn(i.y)?r:t.neg(r),bytes:vn(i)}}function En(e){const t=mn;if(!t.isValidNot0(e))throw new Error("invalid x: Fail if x ≥ p");const n=t.create(e*e),r=t.create(n*e+BigInt(7));let i=t.sqrt(r);bn(i)||(i=t.neg(i));const o=gn.fromAffine({x:e,y:i});return o.assertValidity(),o}const On=et;function kn(...e){return gn.Fn.create(On(wn("BIP0340/challenge",...e)))}function zn(e){return xn(e).bytes}function Sn(e,t,n=me(32)){const{Fn:r}=gn,i=G(e,void 0,"message"),{bytes:o,scalar:s}=xn(t),a=G(n,32,"auxRand"),c=r.toBytes(s^On(wn("BIP0340/aux",a))),u=wn("BIP0340/nonce",c,o,i),{bytes:f,scalar:d}=xn(u),l=kn(f,o,i),p=new Uint8Array(64);if(p.set(f,0),p.set(r.toBytes(r.create(d+l*s)),32),!$n(p,i,o))throw new Error("sign: Invalid signature produced");return p}function $n(e,t,n){const{Fp:r,Fn:i,BASE:o}=gn,s=G(e,64,"signature"),a=G(t,void 0,"message"),c=G(n,32,"publicKey");try{const e=En(On(c)),t=On(s.subarray(0,32));if(!r.isValidNot0(t))return!1;const n=On(s.subarray(32,64));if(!i.isValidNot0(n))return!1;const u=kn(i.toBytes(t),vn(e),a),f=o.multiplyUnsafe(n).add(e.multiplyUnsafe(i.neg(u))),{x:d,y:l}=f.toAffine();return!(f.is0()||!bn(l)||d!==t)}catch(e){return!1}}const Pn=(()=>{const e=(e=me(48))=>Rt(e,dn.n);return{keygen:Jt(e,zn),getPublicKey:zn,sign:Sn,verify:$n,Point:gn,utils:{randomSecretKey:e,taggedHash:wn,lift_x:En,pointToBytes:vn},lengths:{secretKey:32,publicKey:32,publicKeyHasPrefix:!1,signature:64,seed:48}}})(),An=BigInt(0),In=BigInt(2);It(yn.Point.Fn.ORDER,{isLE:!0});const Tn=yn.Point.BASE;function Nn(e,t,n,r=!1){const i=Un(t).big,o=function(e){try{const t=Rn(e,"ecdsa");return yn.Point.fromHex(t.hex)}catch{throw new Error(`invalid pubkey: ${e}`)}}(e),s=Tn.multiply(i);let a=o.add(s);r&&a.y%In!==An&&(a=a.negate());return Rn(a.toHex(!0),n)}function Rn(e,t){try{const n=Un(e);if(33===n.length&&"bip340"===t)return n.slice(1);if(32===n.length&&"ecdsa"===t){const e=T.num(2,1);return T.join([e,n])}return n}catch{throw new Error(`invalid pubkey: ${String(e)}`)}}function Un(e){if(e instanceof Uint8Array)return T.bytes(e);if("string"==typeof e){if(e.length>0&&e.length%2==0&&/^[0-9a-fA-F]+$/.test(e))return T.hex(e);throw new Error(`invalid hex string: ${e}`)}throw new Error(`invalid bytes: ${String(e)}`)}
|
|
10
|
+
/*! scure-base - MIT License (c) 2022 Paul Miller (paulmillr.com) */function Bn(e){return e instanceof Uint8Array||ArrayBuffer.isView(e)&&"Uint8Array"===e.constructor.name}function jn(e,t){return!!Array.isArray(t)&&(0===t.length||(e?t.every(e=>"string"==typeof e):t.every(e=>Number.isSafeInteger(e))))}function Zn(e){if("function"!=typeof e)throw new Error("function expected");return!0}function Cn(e,t){if("string"!=typeof t)throw new Error(`${e}: string expected`);return!0}function Fn(e){if(!Number.isSafeInteger(e))throw new Error(`invalid integer: ${e}`)}function Hn(e){if(!Array.isArray(e))throw new Error("array expected")}function Dn(e,t){if(!jn(!0,t))throw new Error(`${e}: array of strings expected`)}function Ln(e,t){if(!jn(!1,t))throw new Error(`${e}: array of numbers expected`)}function Vn(...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 qn(e){const t="string"==typeof e?e.split(""):e,n=t.length;Dn("alphabet",t);const r=new Map(t.map((e,t)=>[e,t]));return{encode:r=>(Hn(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=>(Hn(t),t.map(t=>{Cn("alphabet.decode",t);const n=r.get(t);if(void 0===n)throw new Error(`Unknown letter: "${t}". Allowed: ${e}`);return n}))}}function Mn(e=""){return Cn("join",e),{encode:t=>(Dn("join.decode",t),t.join(e)),decode:t=>(Cn("join.decode",t),t.split(e))}}function Kn(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(Hn(e),!e.length)return[];let r=0;const i=[],o=Array.from(e,e=>{if(Fn(e),e<0||e>=t)throw new Error(`invalid integer: ${e}`);return e}),s=o.length;for(;;){let e=0,a=!0;for(let i=r;i<s;i++){const s=o[i],c=t*e,u=c+s;if(!Number.isSafeInteger(u)||c/t!==e||u-s!==c)throw new Error("convertRadix: carry overflow");const f=u/n;e=u%n;const d=Math.floor(f);if(o[i]=d,!Number.isSafeInteger(d)||d*n+e!==u)throw new Error("convertRadix: carry overflow");a&&(d?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()}const Jn=(e,t)=>0===t?e:Jn(t,e%t),Gn=(e,t)=>e+(t-Jn(e,t)),Wn=(()=>{let e=[];for(let t=0;t<40;t++)e.push(2**t);return e})();function Yn(e,t,n,r){if(Hn(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(Gn(t,n)>32)throw new Error(`convertRadix2: carry overflow from=${t} to=${n} carryBits=${Gn(t,n)}`);let i=0,o=0;const s=Wn[t],a=Wn[n]-1,c=[];for(const r of e){if(Fn(r),r>=s)throw new Error(`convertRadix2: invalid data word=${r} from=${t}`);if(i=i<<t|r,o+t>32)throw new Error(`convertRadix2: carry overflow pos=${o} from=${t}`);for(o+=t;o>=n;o-=n)c.push((i>>o-n&a)>>>0);const e=Wn[o];if(void 0===e)throw new Error("invalid carry");i&=e-1}if(i=i<<n-o&a,!r&&o>=t)throw new Error("Excess padding");if(!r&&i>0)throw new Error(`Non-zero padding: ${i}`);return r&&o>0&&c.push(i>>>0),c}function Xn(e,t=!1){if(Fn(e),e<=0||e>32)throw new Error("radix2: bits should be in (0..32]");if(Gn(8,e)>32||Gn(e,8)>32)throw new Error("radix2: carry overflow");return{encode:n=>{if(!Bn(n))throw new Error("radix2.encode input should be Uint8Array");return Yn(Array.from(n),8,e,!t)},decode:n=>(Ln("radix2.decode",n),Uint8Array.from(Yn(n,e,8,t)))}}function Qn(e){return Zn(e),function(...t){try{return e.apply(null,t)}catch(e){}}}const er=(()=>"function"==typeof Uint8Array.from([]).toBase64&&"function"==typeof Uint8Array.fromBase64)()?{encode:e=>(function(e){if(!Bn(e))throw new Error("Uint8Array expected")}(e),e.toBase64()),decode:e=>(e=>{if(Cn("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)}:Vn(Xn(6),qn("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"),function(e,t="="){return Fn(e),Cn("padding",t),{encode(n){for(Dn("padding.encode",n);n.length*e%8;)n.push(t);return n},decode(n){Dn("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),Mn("")),tr=Vn(Xn(6),qn("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_"),Mn("")),nr=(rr="123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz",Vn(function(e){return Fn(e),{encode:t=>{if(!Bn(t))throw new Error("radix.encode input should be Uint8Array");return Kn(Array.from(t),256,e)},decode:t=>(Ln("radix.decode",t),Uint8Array.from(Kn(t,e,256)))}}(58),qn(rr),Mn("")));var rr;const ir=e=>{return Vn((n=t=>e(e(t)),Fn(t=4),Zn(n),{encode(e){if(!Bn(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(!Bn(e))throw new Error("checksum.decode: input should be Uint8Array");const r=e.slice(0,-t),i=e.slice(-t),o=n(r).slice(0,t);for(let e=0;e<t;e++)if(o[e]!==i[e])throw new Error("Invalid checksum");return r}}),nr);var t,n},or=Vn(qn("qpzry9x8gf2tvdw0s3jn54khce6mua7l"),Mn("")),sr=[996825010,642813549,513874426,1027748829,705979059];function ar(e){const t=e>>25;let n=(33554431&e)<<5;for(let e=0;e<sr.length;e++)1==(t>>e&1)&&(n^=sr[e]);return n}function cr(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=ar(i)^n>>5}i=ar(i);for(let t=0;t<r;t++)i=ar(i)^31&e.charCodeAt(t);for(let e of t)i=ar(i)^e;for(let e=0;e<6;e++)i=ar(i);return i^=n,or.encode(Yn([i%Wn[30]],30,5,!1))}function ur(e){const t="bech32"===e?1:734539939,n=Xn(5),r=n.decode,i=n.encode,o=Qn(r);function s(e,n,r=90){Cn("bech32.encode prefix",e),Bn(n)&&(n=Array.from(n)),Ln("bech32.encode",n);const i=e.length;if(0===i)throw new TypeError(`Invalid prefix length ${i}`);const o=i+7+n.length;if(!1!==r&&o>r)throw new TypeError(`Length ${o} exceeds limit ${r}`);const s=e.toLowerCase(),a=cr(s,n,t);return`${s}1${or.encode(n)}${a}`}function a(e,n=90){Cn("bech32.decode input",e);const r=e.length;if(r<8||!1!==n&&r>n)throw new TypeError(`invalid string length: ${r} (${e}). Expected (8..${n})`);const i=e.toLowerCase();if(e!==i&&e!==e.toUpperCase())throw new Error("String must be lowercase or uppercase");const o=i.lastIndexOf("1");if(0===o||-1===o)throw new Error('Letter "1" must be present between prefix and data only');const s=i.slice(0,o),a=i.slice(o+1);if(a.length<6)throw new Error("Data must be at least 6 characters long");const c=or.decode(a).slice(0,-6),u=cr(s,c,t);if(!a.endsWith(u))throw new Error(`Invalid checksum in ${e}: expected "${u}"`);return{prefix:s,words:c}}return{encode:s,decode:a,encodeFromBytes:function(e,t){return s(e,i(t))},decodeToBytes:function(e){const{prefix:t,words:n}=a(e,!1);return{prefix:t,words:n,bytes:r(n)}},decodeUnsafe:Qn(a),fromWords:r,fromWordsUnsafe:o,toWords:i}}const fr=ur("bech32"),dr=ur("bech32m");var lr,pr,hr,mr,gr;function yr(e){if("string"!=typeof e||0===e.length)throw new Error(`invalid prefix: ${String(e)}`)}function _r(e){if(!Array.isArray(e)||!e.every(e=>"number"==typeof e))throw new Error(`invalid words: ${String(e)}`)}!function(e){e.encode=e=>(Ke.is_u8a(e),ir(De).encode(e)),e.decode=e=>(Ke.is_base58(e),ir(De).decode(e))}(lr||(lr={})),function(e){e.encode=e=>(Ke.is_u8a(e),er.encode(e)),e.decode=e=>(Ke.is_base64(e),er.decode(e))}(pr||(pr={})),function(e){e.encode=e=>(Ke.is_u8a(e),tr.encode(e)),e.decode=e=>(Ke.is_b64url(e),tr.decode(e))}(hr||(hr={})),function(e){e.to_words=fr.toWords,e.to_bytes=fr.fromWords,e.encode=(e,t,n=!1)=>(yr(e),_r(t),fr.encode(e,t,n)),e.decode=(e,t=!1)=>(Ke.is_bech32(e),fr.decode(e,t))}(mr||(mr={})),function(e){e.to_words=dr.toWords,e.to_bytes=dr.fromWords,e.encode=(e,t,n=!1)=>(yr(e),_r(t),dr.encode(e,t,n)),e.decode=(e,t=!1)=>(Ke.is_bech32(e),dr.decode(e,t))}(gr||(gr={}));const wr={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}$/},vr=0,br=1;function xr(e){const t=function(e){for(const[t,n]of Object.entries(wr))if(n.test(e))return t;return null}(e);if(null===t)throw new R(`unrecognized address format: ${e}`,"address");if("base58"===t)return function(e){const t=lr.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}=mr.decode(e),[r,...i]=n;M.ok(r===vr,"bech32 version mismatch");return{data:mr.to_bytes(i),format:"bech32",prefix:t,version:r}}(e);if("bech32m"===t)return function(e){const{prefix:t,words:n}=gr.decode(e),[r,...i]=n;M.ok(r===br,"bech32m version mismatch");return{data:gr.to_bytes(i),format:"bech32m",prefix:t,version:r}}(e);throw new R("unable to find a matching address configuration","address")}function Er(e){if("base58"===e.format)return function(e){M.ok("base58"===e.format,"encoding mismatch"),M.exists(e.version,"must specify a version");const t=T.join([e.version,e.data]);return lr.encode(t)}(e);if("bech32"===e.format)return function(e){M.ok("bech32"===e.format,"encoding mismatch"),M.exists(e.prefix,"prefix is required");const t=T.bytes(e.data),n=mr.to_words(t);return mr.encode(e.prefix,[vr,...n])}(e);if("bech32m"===e.format)return function(e){M.ok("bech32m"===e.format,"encoding mismatch"),M.exists(e.prefix,"prefix is required");const t=T.bytes(e.data),n=gr.to_words(t);return gr.encode(e.prefix,[br,...n])}(e);throw new R(`unrecognized encoding format: ${e.format}`,"format")}function Or(e,t){switch(t){case"p2pkh":return function(e){return{hex:`76a914${e}88ac`,asm:["OP_DUP","OP_HASH160",e,"OP_EQUALVERIFY","OP_CHECKSIG"]}}(e);case"p2sh":return function(e){return{hex:`a914${e}87`,asm:["OP_HASH160",e,"OP_EQUAL"]}}(e);case"p2wpkh":return function(e){return{hex:`0014${e}`,asm:["OP_0",e]}}(e);case"p2wsh":return function(e){return{hex:`0020${e}`,asm:["OP_0",e]}}(e);case"p2tr":return function(e){return{hex:`5120${e}`,asm:["OP_1",e]}}(e);default:throw new Error(`unrecognized script type: ${t}`)}}const kr=[["1","p2pkh","main",20,"base58",0],["3","p2sh","main",20,"base58",5],["m","p2pkh","testnet",20,"base58",111],["n","p2pkh","testnet",20,"base58",111],["2","p2sh","testnet",20,"base58",196],["m","p2pkh","regtest",20,"base58",111],["n","p2pkh","regtest",20,"base58",111],["2","p2sh","regtest",20,"base58",196],["bc","p2wpkh","main",20,"bech32",0],["tb","p2wpkh","testnet",20,"bech32",0],["bcrt","p2wpkh","regtest",20,"bech32",0],["bc","p2wsh","main",32,"bech32",0],["tb","p2wsh","testnet",32,"bech32",0],["bcrt","p2wsh","regtest",32,"bech32",0],["bc","p2tr","main",32,"bech32m",1],["tb","p2tr","testnet",32,"bech32m",1],["bcrt","p2tr","regtest",32,"bech32m",1]];function zr(e,t){for(const[n,r,i,o,s,a]of kr)if(r===t&&i===e)return{type:r,prefix:n,network:i,size:o,format:s,version:a};return null}function Sr(e){const t=xr(e);for(const[n,r,i,o,s,a]of kr){if(s!==t.format)continue;if(o!==t.data.length)continue;if(a!==t.version)continue;if(t.prefix){if(n!==t.prefix)continue}else if(!e.startsWith(n))continue;const c=T.bytes(t.data).hex;return{data:c,script:Or(c,r),type:r,prefix:n,network:i,size:o,format:s,version:a}}throw new B(`unrecognized address configuration: format=${t.format}, size=${t.data.length}, version=${t.version}. Supported formats: base58 (p2pkh, p2sh), bech32 (p2wpkh, p2wsh), bech32m (p2tr)`)}const $r=i.P2PKH;var Pr;function Ar(e,t="main"){return Nr(Ir(e),t)}function Ir(e){const t=T.bytes(e);M.ok(33===t.length,"invalid pubkey size");return Tr(Le(t))}function Tr(e){return T.join(["76a914",e,"88ac"])}function Nr(e,t="main"){const n=Ur(e),r=zr(t,$r);return M.exists(r,`unrecognized address config: ${$r} on ${t}`),M.ok(n.length===r.size,`invalid payload size: ${n.length} !== ${r.size}`),Er({data:n,format:"base58",version:r.version})}function Rr(e){const t=Sr(e);return M.ok("p2pkh"===t.type,`address type mismatch: ${t.type} !== ${$r}`),t}function Ur(e){const t=T.bytes(e);return M.ok(C(e),"invalid p2pkh script"),t.slice(3,23)}!function(e){e.create_address=Ar,e.create_script=Ir,e.encode_address=Nr,e.encode_script=Tr,e.decode_address=Rr,e.decode_script=Ur}(Pr||(Pr={}));const Br=i.P2SH;var jr;function Zr(e,t="main"){return Hr(Fr(Le(T.bytes(e))),t)}function Cr(e){return Fr(Le(T.bytes(e)))}function Fr(e){return T.join(["a914",e,"87"])}function Hr(e,t="main"){const n=Lr(e),r=zr(t,Br);return M.exists(r,`unrecognized address config: ${Br} on ${t}`),M.ok(n.length===r.size,`invalid payload size: ${n.length} !== ${r.size}`),Er({data:n,format:"base58",version:r.version})}function Dr(e){const t=Sr(e);return M.ok("p2sh"===t.type,`address type mismatch: ${t.type} !== ${Br}`),t}function Lr(e){M.ok(F(e),"invalid p2sh script");return T.bytes(e).slice(2,22)}!function(e){e.create_address=Zr,e.create_script=Cr,e.encode_address=Hr,e.encode_script=Fr,e.decode_address=Dr,e.decode_script=Lr}(jr||(jr={}));const Vr=i.P2TR;var qr;function Mr(e,t="main"){return Gr(Kr(e),t)}function Kr(e){const t=T.bytes(e);return M.ok(32===t.length,"invalid pubkey size"),Jr(t)}function Jr(e){return T.join(["5120",e])}function Gr(e,t="main"){const n=Yr(e),r=zr(t,Vr);return M.exists(r,`unrecognized address config: ${Vr} on ${t}`),M.ok(n.length===r.size,`invalid payload size: ${n.length} !== ${r.size}`),Er({data:n,format:"bech32m",prefix:r.prefix})}function Wr(e){const t=Sr(e);return M.ok("p2tr"===t.type,`address type mismatch: ${t.type} !== ${Vr}`),t}function Yr(e){M.ok(L(e),"invalid p2tr script");return T.bytes(e).slice(2,34)}!function(e){e.create_address=Mr,e.create_script=Kr,e.encode_address=Gr,e.encode_script=Jr,e.decode_address=Wr,e.decode_script=Yr}(qr||(qr={}));const Xr=i.P2WPKH;var Qr;function ei(e,t="main"){return ri(ti(e),t)}function ti(e){const t=T.bytes(e);M.ok(33===t.length,"invalid pubkey size");return ni(Le(t))}function ni(e){return T.join(["0014",e])}function ri(e,t="main"){const n=oi(e),r=zr(t,Xr);return M.exists(r,`unrecognized address config: ${Xr} on ${t}`),M.ok(n.length===r.size,`invalid payload size: ${n.length} !== ${r.size}`),Er({data:n,format:"bech32",prefix:r.prefix})}function ii(e){const t=Sr(e);return M.ok("p2wpkh"===t.type,`address type mismatch: ${t.type} !== ${Xr}`),t}function oi(e){M.ok(H(e),"invalid p2wpkh script");return T.bytes(e).slice(2,22)}!function(e){e.create_address=ei,e.create_script=ti,e.encode_address=ri,e.encode_script=ni,e.decode_address=ii,e.decode_script=oi}(Qr||(Qr={}));const si=i.P2WSH;var ai;function ci(e,t="main"){return di(ui(e),t)}function ui(e){return fi(Ve(T.bytes(e)))}function fi(e){return T.join(["0020",e])}function di(e,t="main"){const n=pi(e),r=zr(t,si);return M.exists(r,`unrecognized address config: ${si} on ${t}`),M.ok(n.length===r.size,`invalid payload size: ${n.length} !== ${r.size}`),Er({data:n,format:"bech32",prefix:r.prefix})}function li(e){const t=Sr(e);return M.ok("p2wsh"===t.type,`address type mismatch: ${t.type} !== ${si}`),t}function pi(e){M.ok(D(e),"invalid p2wsh script");return T.bytes(e).slice(2,34)}!function(e){e.create_address=ci,e.create_script=ui,e.encode_address=di,e.encode_script=fi,e.decode_address=li,e.decode_script=pi}(ai||(ai={}));var hi=Object.freeze({__proto__:null,get P2PKH(){return Pr},get P2SH(){return jr},get P2TR(){return qr},get P2WPKH(){return Qr},get P2WSH(){return ai},get_address:function(e,t="main"){const n=j(T.bytes(e));if(null===n)throw new B("Unknown or unsupported locking script type");switch(n){case i.P2PKH:return Pr.encode_address(e,t);case i.P2SH:return jr.encode_address(e,t);case i.P2WPKH:return Qr.encode_address(e,t);case i.P2WSH:return ai.encode_address(e,t);case i.P2TR:return qr.encode_address(e,t);default:throw new B(`unknown script type: ${n}`)}},parse_address:function(e){return Sr(e)}});const mi=5e8;var gi,yi;function _i(e){switch(e.type){case"timelock":return M.ok(e.stamp>=mi,"Invalid timestamp"),e.stamp;case"heightlock":return M.ok(e.height>0,"height must be greater than 0"),M.ok(e.height<mi,"invalid block height"),e.height;default:throw new B("Invalid locktime type: expected 'timelock' or 'heightlock'")}}function wi(e){return Number.isNaN(e)||e<=0?null:e<mi?{type:"heightlock",height:e}:{type:"timelock",stamp:e}}function vi(e,t=0){return`${e}i${t}`}function bi(e){Ei(e);const[t,n]=e.split("i");return{txid:t,order:parseInt(n,10)}}function xi(e){return null!==e.match(/^[a-f0-9]{64}i\d+$/)}function Ei(e){if(!xi(e))throw new R(`invalid inscription id: "${e}". Expected format: <64-char-txid>i<index> (e.g., "abc123...i0")`)}function Oi(e,t){return`${e}:${t}`}function ki(e){Si(e);const[t,n]=e.split(":");return{block_height:parseInt(t,10),block_index:parseInt(n,10)}}function zi(e){return null!==e.match(/^\d+:\d+$/)}function Si(e){if(!zi(e))throw new R(`invalid rune id: "${e}". Expected format: <block_height>:<block_index> (e.g., "840000:1")`)}function $i(e,t){return`${e}:${t}`}function Pi(e){Ii(e);const[t,n]=e.split(":");return{txid:t,vout:parseInt(n,10)}}function Ai(e){return null!==e.match(/^[a-f0-9]{64}:[0-9]+$/)}function Ii(e){if(!Ai(e))throw new R(`invalid outpoint: "${e}". Expected format: <64-char-txid>:<vout> (e.g., "abc123...:0")`)}!function(e){e.encode=_i,e.decode=wi}(gi||(gi={})),function(e){e.outpoint={encode:$i,decode:Pi,verify:Ai,assert:Ii},e.record_id={encode:vi,decode:bi,verify:xi,assert:Ei},e.rune_id={encode:Oi,decode:ki,verify:zi,assert:Si}}(yi||(yi={}));const Ti={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 Ni(e){if(e>186&&e<255)return`OP_SUCCESS${String(e)}`;for(const[t,n]of Object.entries(Ti))if(n===e)return t;throw new R(`opcode not found for value: ${e} (0x${e.toString(16)}). Valid range is 0x00-0xba`)}function Ri(e){for(const[t,n]of Object.entries(Ti))if(t===e)return Number(n);throw new R(`opcode not found: "${e}". Valid opcodes start with "OP_" (e.g., OP_DUP, OP_CHECKSIG)`)}function Ui(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 R(`invalid word value: ${e}. Expected 0-254`)}}function Bi(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}}function ji(e){const t=new N(e),n=[],r=t.size;let i,o,s,a=0;for(;a<r;)switch(i=t.read(1).num,o=Ui(i),a++,o){case"varint":try{n.push(t.read(i).hex)}catch{throw new U(`Malformed script: varint push at position ${a-1} requires ${i} bytes but stream exhausted`,a-1)}a+=i;break;case"pushdata1":try{s=t.read(1).reverse().num}catch{throw new U(`Malformed script: PUSHDATA1 at position ${a-1} missing size byte`,a-1)}try{n.push(t.read(s).hex)}catch{throw new U(`Malformed script: PUSHDATA1 at position ${a-1} requires ${s} bytes but stream exhausted`,a-1)}a+=s+1;break;case"pushdata2":try{s=t.read(2).reverse().num}catch{throw new U(`Malformed script: PUSHDATA2 at position ${a-1} missing size bytes`,a-1)}try{n.push(t.read(s).hex)}catch{throw new U(`Malformed script: PUSHDATA2 at position ${a-1} requires ${s} bytes but stream exhausted`,a-1)}a+=s+2;break;case"pushdata4":try{s=t.read(4).reverse().num}catch{throw new U(`Malformed script: PUSHDATA4 at position ${a-1} missing size bytes`,a-1)}try{n.push(t.read(s).hex)}catch{throw new U(`Malformed script: PUSHDATA4 at position ${a-1} requires ${s} bytes but stream exhausted`,a-1)}a+=s+4;break;case"opcode":if(!Bi(i))throw new U(`Invalid OPCODE: ${i}`,a-1);n.push(Ni(i));break;default:throw new U(`Word type undefined: ${i}`,a-1)}return n}function Zi(e){try{return ji(e).length>0}catch{return!1}}const Ci=520;function Fi(e,t=!1){if(0===e.length)return T.num(0,1);const n=[];for(const t of e)n.push(Hi(t));const r=T.join(n);if(r.length>c)throw new R(`script size ${r.length} exceeds consensus limit of 10000 bytes`);return t?r.prepend(T.create_varint(r.length,"le")):r}function Hi(e){let t;if("string"==typeof e){if(e.startsWith("OP_")){const t=Ri(e);return T.num(t,1)}t=T.is_hex(e)?T.hex(e):T.str(e)}else if("number"==typeof e)t=T.num(e);else{if(!(e instanceof Uint8Array))throw new R(`invalid script word type: ${typeof e}. Expected string, number, or Uint8Array`);t=new T(e)}if(1===t.length&&t[0]<=16)0!==t[0]&&(t[0]+=80);else if(t.length>Ci){let e;e=Di(t),e=e.map(e=>Li(e)),t=T.join(e)}else t=Li(t);return t}function Di(e){const t=[],n=new N(e);for(;n.size>Ci;)t.push(n.read(Ci));return t.push(n.read(n.size)),t}function Li(e){const t=Vi(e.length);return T.join([t,e])}function Vi(e){const t=T.num(76,1),n=T.num(77,1);switch(!0){case e<=75:return T.num(e);case e>75&&e<256:return T.join([t,T.num(e,1,"le")]);case e>=256&&e<=Ci:return T.join([n,T.num(e,2,"le")]);default:throw new R(`invalid script word size: ${e}. Maximum allowed is 520 bytes`)}}const qi=BigInt(0),Mi=BigInt(1),Ki=BigInt(26);var Ji;function Gi(e){const t=function(e){const t=ji(e),n=t.indexOf("OP_0");M.ok(-1!==n,"inscription envelope not found");const r=[];for(let e=n;e<t.length;e++){M.ok(e+2<t.length,"incomplete envelope: missing OP_IF or magic bytes"),M.ok("OP_IF"===t[e+1],"OP_IF missing from envelope"),M.ok("6f7264"===t[e+2],"magic bytes missing from envelope");const n=t.indexOf("OP_ENDIF",e);M.ok(-1!==n,"inscription envelope missing OP_ENDIF statement");const i=t.slice(e+3,n);r.push(i),e=n}return r}(e);return t.map(Xi)}function Wi(e){return T.join(e.map(Yi))}function Yi(e){const t=["OP_0","OP_IF","6f7264"];if("string"==typeof e.delegate){const n=to(e.delegate);t.push("OP_11",n)}if("string"==typeof e.ref&&t.push("OP_WITHIN",e.ref),"string"==typeof e.parent){const n=to(e.parent);t.push("OP_3",n)}if("number"==typeof e.opcode){const n=ro(e.opcode);t.push("OP_NOP",n)}if("number"==typeof e.pointer){const n=ro(e.pointer);t.push("OP_2",n)}if("string"==typeof e.rune){const n=function(e){const t=e.toUpperCase();let n=qi;for(const e of t){if(!(e>="A"&&e<="Z"))throw new R(`invalid character in rune label: '${e}' (only A-Z allowed)`,"label");n=n*Ki+BigInt(e.charCodeAt(0)-("A".charCodeAt(0)-1))}return n-=Mi,T.big(n).reverse().hex}(e.rune);t.push("OP_13",n)}if("string"==typeof e.mimetype){const n=function(e){return T.str(e).hex}(e.mimetype);t.push("OP_1",n)}if("string"==typeof e.content){const n=function(e){const t=T.is_hex(e)?T.hex(e):T.str(e),n=new N(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"),Fi(t)}function Xi(e){const t={};for(let n=0;n<e.length;n++)switch(e[n]){case"OP_1":t.mimetype=oo(e[n+1]),n+=1;break;case"OP_2":t.pointer=io(e[n+1]),n+=1;break;case"OP_3":t.parent=no(e[n+1]),n+=1;break;case"OP_11":t.delegate=no(e[n+1]),n+=1;break;case"OP_13":t.rune=ao(e[n+1]),n+=1;break;case"OP_WITHIN":t.ref=Qi(e[n+1]),n+=1;break;case"OP_NOP":t.opcode=io(e[n+1]),n+=1;break;case"OP_0":return t.content=so(e.slice(n+1)),t}return t}function Qi(e){return T.bytes(e).hex}function eo(e){if("string"==typeof e&&e.startsWith("OP_")){if("OP_0"===e)return T.num(0).hex;const t=e.match(/^OP_(\d+)$/);if(t){const e=parseInt(t[1],10);if(e>=1&&e<=16)return T.num(e).hex}}return e}function to(e){M.ok(e.includes("i"),"identifier must include an index");const t=e.split("i"),n=T.hex(t[0]),r=Number(t[1]),i=n.reverse().hex;return 0!==r?i+T.num(r).hex:i}function no(e){const t=T.bytes(e);if(32===t.length)return`${t.reverse().hex}i0`;const n=t.at(-1)??0;return`${t.slice(0,-1).reverse().hex}i${String(n)}`}function ro(e){return T.num(e).reverse().hex}function io(e){return T.bytes(eo(e)).reverse().num}function oo(e){return T.bytes(e).str}function so(e,t="hex"){const n=T.join(e);return"hex"===t?n.hex:n.str}function ao(e){const t=eo(e);let n=T.bytes(t).reverse().big;n+=Mi;let r="";for(;n>qi;){const e=n%Ki;if(e===qi)r=`Z${r}`,n=n/Ki-Mi;else{const t=Number(e)+"A".charCodeAt(0)-1;r=String.fromCharCode(t)+r,n/=Ki}}return r}!function(e){e.encode=Wi,e.decode=Gi}(Ji||(Ji={}));const co=4194304,uo=65535,fo=65535;var lo;function po(e){if("height"===e.mode){return(function(e){if(void 0===e||!Number.isInteger(e)||e<0||e>fo)throw new R(`heightlock value must be an integer between 0 and 65535, got: ${e}`);return e}(e.height)&uo)>>>0}if("stamp"===e.mode){const t=function(e){if(void 0===e||!Number.isInteger(e))throw new R(`timestamp must be an integer, got: ${e}`);const t=Math.floor(e/512);if(!Number.isInteger(t)||t<0||t>fo)throw new R("timelock value must be an integer between 0 and 65535 (in 512-second increments)");return t}(e.stamp);return(co|t&uo)>>>0}throw new R(`invalid timelock mode: "${e.mode}". Valid modes are "height" or "stamp"`)}function ho(e){const t=function(e){const t="string"==typeof e?parseInt(e,16):e;if(!Number.isInteger(t)||t<0||t>4294967295)throw new R(`invalid sequence value: ${t}. Must be an integer between 0 and 0xffffffff`);return t}(e);if(2147483648&t)return null;const n=t&uo;if(t&co){const e=512*n;if(e>4294967295)throw new R(`decoded timestamp ${e} exceeds 32-bit limit (max: 4294967295)`);return{mode:"stamp",stamp:e}}if(n>fo)throw new R(`decoded height ${n} exceeds maximum (65535)`);return{mode:"height",height:n}}!function(e){e.encode=po,e.decode=ho}(lo||(lo={}));var mo=Object.freeze({__proto__:null,get InscriptionUtil(){return Ji},get LocktimeField(){return gi},get RefPointer(){return yi},get SequenceField(){return lo},decode_inscription:Gi,decode_locktime:wi,decode_sequence:ho,encode_inscription:Wi,encode_locktime:_i,encode_sequence:po});function go(e){return T.bytes(e).prefix_varint("le").hex}var yo=Object.freeze({__proto__:null,OPCODE_MAP:Ti,decode_script:ji,encode_script:Fi,encode_script_word:Hi,get_asm_code:Ri,get_lock_script_info:function(e){return{type:j(e),version:Z(e)}},get_lock_script_type:j,get_lock_script_version:Z,get_op_code:Ni,get_op_type:Ui,get_size_varint:Vi,is_opreturn_script:function(e){const t=T.bytes(e).hex;return o.opreturn.test(t)},is_p2pkh_script:C,is_p2sh_script:F,is_p2tr_script:L,is_p2wpkh_script:H,is_p2wsh_script:D,is_return_script:function(e){return 106===T.bytes(e).at(0)},is_valid_op:Bi,is_valid_script:Zi,parse_script:function(e){const t=T.bytes(e);return{asm:ji(t),hex:t.hex}},parse_script_pubkeys:function(e){return[...("string"==typeof e?e:T.bytes(e).hex).matchAll(/20([0-9a-f]{64})(ac|ad|ba)/gi)].map(e=>e[1])},prefix_script_size:go,prefix_word_size:Li,split_script_word:Di});const _o=4e6,wo=1e5;function vo(e,t=!0){M.ok("string"==typeof e||e instanceof Uint8Array,"txdata must be hex or bytes");const n="string"==typeof e?e.length/2:e.length;if(n>_o)throw new U(`Transaction size ${n} exceeds maximum 4000000 bytes`);const r=new N(e),i=function(e){return e.read(4).reverse().to_num()}(r);let o=function(e){const[t,n]=[...e.peek(2)];if(0===t){if(e.read(2),1===n)return!0;throw new U(`Invalid witness flag: ${n}`,1)}return!1}(r);o=!!t&&o;const s=function(e){const t=[],n=e.read_varint();if(n>wo)throw new U(`Input count ${n} exceeds maximum 100000`);for(let r=0;r<n;r++){const n=bo(e);t.push(n)}return t}(r),a=function(e){const t=[],n=e.read_varint();if(n>wo)throw new U(`Output count ${n} exceeds maximum 100000`);for(let r=0;r<n;r++)try{t.push(xo(e))}catch(e){const t=e instanceof Error?e.message:String(e);throw new U(`Failed to decode output at index ${r}: ${t}`)}return t}(r);if(o)for(const e of s)e.witness=Eo(r);const c=function(e){return e.read(4).reverse().to_num()}(r);return{version:i,vin:s,vout:a,locktime:c}}function bo(e){const n=e.read(32).reverse().hex,r=e.read(4).reverse().num,i=Oo(e),o=e.read(4).reverse().num,s=[];return n===t.TXID&&r===t.VOUT?{coinbase:i,prevout:null,script_sig:null,sequence:o,txid:n,vout:r,witness:s}:{coinbase:null,prevout:null,script_sig:i,sequence:o,txid:n,vout:r,witness:s}}function xo(e){const t=e.read(8).reverse().big,n=Oo(e);return M.exists(n,"failed to decode script_pk"),{value:t,script_pk:n}}function Eo(e){const t=[],n=e.read_varint();if(n>wo)throw new U(`Witness element count ${n} exceeds maximum 100000`);for(let r=0;r<n;r++){const n=Oo(e);if(null===n)throw new U(`Failed to decode witness element at index ${r}`);t.push(n)}return t}function Oo(e){const t=e.read_varint("le");if(t>u)throw new U(`Payload size ${t} exceeds maximum 520000`);return t>0?e.read(t).hex:null}function ko(e,t,n){function r(n,r){if(n._zod||Object.defineProperty(n,"_zod",{value:{def:r,constr:s,traits:new Set},enumerable:!1}),n._zod.traits.has(e))return;n._zod.traits.add(e),t(n,r);const i=s.prototype,o=Object.keys(i);for(let e=0;e<o.length;e++){const t=o[e];t in n||(n[t]=i[t].bind(n))}}const i=n?.Parent??Object;class o extends i{}function s(e){var t;const i=n?.Parent?new o:this;r(i,e),(t=i._zod).deferred??(t.deferred=[]);for(const e of i._zod.deferred)e();return i}return Object.defineProperty(o,"name",{value:e}),Object.defineProperty(s,"init",{value:r}),Object.defineProperty(s,Symbol.hasInstance,{value:t=>!!(n?.Parent&&t instanceof n.Parent)||t?._zod?.traits?.has(e)}),Object.defineProperty(s,"name",{value:e}),s}class zo extends Error{constructor(){super("Encountered Promise during synchronous parse. Use .parseAsync() instead.")}}class So extends Error{constructor(e){super(`Encountered unidirectional transform during encode: ${e}`),this.name="ZodEncodeError"}}const $o={};function Po(e){return $o}function Ao(e){const t=Object.values(e).filter(e=>"number"==typeof e);return Object.entries(e).filter(([e,n])=>-1===t.indexOf(+e)).map(([e,t])=>t)}function Io(e,t){return"bigint"==typeof t?t.toString():t}function To(e){return{get value(){{const t=e();return Object.defineProperty(this,"value",{value:t}),t}}}}function No(e){return null==e}function Ro(e){const t=e.startsWith("^")?1:0,n=e.endsWith("$")?e.length-1:e.length;return e.slice(t,n)}const Uo=Symbol("evaluating");function Bo(e,t,n){let r;Object.defineProperty(e,t,{get(){if(r!==Uo)return void 0===r&&(r=Uo,r=n()),r},set(n){Object.defineProperty(e,t,{value:n})},configurable:!0})}function jo(e,t,n){Object.defineProperty(e,t,{value:n,writable:!0,enumerable:!0,configurable:!0})}function Zo(...e){const t={};for(const n of e){const e=Object.getOwnPropertyDescriptors(n);Object.assign(t,e)}return Object.defineProperties({},t)}function Co(e){return JSON.stringify(e)}const Fo="captureStackTrace"in Error?Error.captureStackTrace:(...e)=>{};function Ho(e){return"object"==typeof e&&null!==e&&!Array.isArray(e)}const Do=To(()=>{if("undefined"!=typeof navigator&&navigator?.userAgent?.includes("Cloudflare"))return!1;try{return new Function(""),!0}catch(e){return!1}});function Lo(e){if(!1===Ho(e))return!1;const t=e.constructor;if(void 0===t)return!0;if("function"!=typeof t)return!0;const n=t.prototype;return!1!==Ho(n)&&!1!==Object.prototype.hasOwnProperty.call(n,"isPrototypeOf")}function Vo(e){return Lo(e)?{...e}:Array.isArray(e)?[...e]:e}const qo=new Set(["string","number","symbol"]);function Mo(e){return e.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}function Ko(e,t,n){const r=new e._zod.constr(t??e._zod.def);return t&&!n?.parent||(r._zod.parent=e),r}function Jo(e){const t=e;if(!t)return{};if("string"==typeof t)return{error:()=>t};if(void 0!==t?.message){if(void 0!==t?.error)throw new Error("Cannot specify both `message` and `error` params");t.error=t.message}return delete t.message,"string"==typeof t.error?{...t,error:()=>t.error}:t}const Go={safeint:[Number.MIN_SAFE_INTEGER,Number.MAX_SAFE_INTEGER],int32:[-2147483648,2147483647],uint32:[0,4294967295],float32:[-34028234663852886e22,34028234663852886e22],float64:[-Number.MAX_VALUE,Number.MAX_VALUE]};function Wo(e,t=0){if(!0===e.aborted)return!0;for(let n=t;n<e.issues.length;n++)if(!0!==e.issues[n]?.continue)return!0;return!1}function Yo(e,t){return t.map(t=>{var n;return(n=t).path??(n.path=[]),t.path.unshift(e),t})}function Xo(e){return"string"==typeof e?e:e?.message}function Qo(e,t,n){const r={...e,path:e.path??[]};if(!e.message){const i=Xo(e.inst?._zod.def?.error?.(e))??Xo(t?.error?.(e))??Xo(n.customError?.(e))??Xo(n.localeError?.(e))??"Invalid input";r.message=i}return delete r.inst,delete r.continue,t?.reportInput||delete r.input,r}function es(e){return Array.isArray(e)?"array":"string"==typeof e?"string":"unknown"}function ts(...e){const[t,n,r]=e;return"string"==typeof t?{message:t,code:"custom",input:n,inst:r}:{...t}}const ns=(e,t)=>{e.name="$ZodError",Object.defineProperty(e,"_zod",{value:e._zod,enumerable:!1}),Object.defineProperty(e,"issues",{value:t,enumerable:!1}),e.message=JSON.stringify(t,Io,2),Object.defineProperty(e,"toString",{value:()=>e.message,enumerable:!1})},rs=ko("$ZodError",ns),is=ko("$ZodError",ns,{Parent:Error});const os=e=>(t,n,r,i)=>{const o=r?Object.assign(r,{async:!1}):{async:!1},s=t._zod.run({value:n,issues:[]},o);if(s instanceof Promise)throw new zo;if(s.issues.length){const t=new(i?.Err??e)(s.issues.map(e=>Qo(e,o,Po())));throw Fo(t,i?.callee),t}return s.value},ss=e=>async(t,n,r,i)=>{const o=r?Object.assign(r,{async:!0}):{async:!0};let s=t._zod.run({value:n,issues:[]},o);if(s instanceof Promise&&(s=await s),s.issues.length){const t=new(i?.Err??e)(s.issues.map(e=>Qo(e,o,Po())));throw Fo(t,i?.callee),t}return s.value},as=e=>(t,n,r)=>{const i=r?{...r,async:!1}:{async:!1},o=t._zod.run({value:n,issues:[]},i);if(o instanceof Promise)throw new zo;return o.issues.length?{success:!1,error:new(e??rs)(o.issues.map(e=>Qo(e,i,Po())))}:{success:!0,data:o.value}},cs=as(is),us=e=>async(t,n,r)=>{const i=r?Object.assign(r,{async:!0}):{async:!0};let o=t._zod.run({value:n,issues:[]},i);return o instanceof Promise&&(o=await o),o.issues.length?{success:!1,error:new e(o.issues.map(e=>Qo(e,i,Po())))}:{success:!0,data:o.value}},fs=us(is),ds=e=>(t,n,r)=>{const i=r?Object.assign(r,{direction:"backward"}):{direction:"backward"};return os(e)(t,n,i)},ls=e=>(t,n,r)=>os(e)(t,n,r),ps=e=>async(t,n,r)=>{const i=r?Object.assign(r,{direction:"backward"}):{direction:"backward"};return ss(e)(t,n,i)},hs=e=>async(t,n,r)=>ss(e)(t,n,r),ms=e=>(t,n,r)=>{const i=r?Object.assign(r,{direction:"backward"}):{direction:"backward"};return as(e)(t,n,i)},gs=e=>(t,n,r)=>as(e)(t,n,r),ys=e=>async(t,n,r)=>{const i=r?Object.assign(r,{direction:"backward"}):{direction:"backward"};return us(e)(t,n,i)},_s=e=>async(t,n,r)=>us(e)(t,n,r),ws=/^[cC][^\s-]{8,}$/,vs=/^[0-9a-z]+$/,bs=/^[0-9A-HJKMNP-TV-Za-hjkmnp-tv-z]{26}$/,xs=/^[0-9a-vA-V]{20}$/,Es=/^[A-Za-z0-9]{27}$/,Os=/^[a-zA-Z0-9_-]{21}$/,ks=/^P(?:(\d+W)|(?!.*W)(?=\d|T\d)(\d+Y)?(\d+M)?(\d+D)?(T(?=\d)(\d+H)?(\d+M)?(\d+([.,]\d+)?S)?)?)$/,zs=/^([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12})$/,Ss=e=>e?new RegExp(`^([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-${e}[0-9a-fA-F]{3}-[89abAB][0-9a-fA-F]{3}-[0-9a-fA-F]{12})$`):/^([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[1-8][0-9a-fA-F]{3}-[89abAB][0-9a-fA-F]{3}-[0-9a-fA-F]{12}|00000000-0000-0000-0000-000000000000|ffffffff-ffff-ffff-ffff-ffffffffffff)$/,$s=/^(?!\.)(?!.*\.\.)([A-Za-z0-9_'+\-\.]*)[A-Za-z0-9_+-]@([A-Za-z0-9][A-Za-z0-9\-]*\.)+[A-Za-z]{2,}$/;const Ps=/^(?:(?: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])$/,As=/^(([0-9a-fA-F]{1,4}:){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}|:))$/,Is=/^((25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\.){3}(25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\/([0-9]|[1-2][0-9]|3[0-2])$/,Ts=/^(([0-9a-fA-F]{1,4}:){7}[0-9a-fA-F]{1,4}|::|([0-9a-fA-F]{1,4})?::([0-9a-fA-F]{1,4}:?){0,6})\/(12[0-8]|1[01][0-9]|[1-9]?[0-9])$/,Ns=/^$|^(?:[0-9a-zA-Z+/]{4})*(?:(?:[0-9a-zA-Z+/]{2}==)|(?:[0-9a-zA-Z+/]{3}=))?$/,Rs=/^[A-Za-z0-9_-]*$/,Us=/^\+[1-9]\d{6,14}$/,Bs="(?:(?:\\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])))",js=new RegExp(`^${Bs}$`);function Zs(e){const t="(?:[01]\\d|2[0-3]):[0-5]\\d";return"number"==typeof e.precision?-1===e.precision?`${t}`:0===e.precision?`${t}:[0-5]\\d`:`${t}:[0-5]\\d\\.\\d{${e.precision}}`:`${t}(?::[0-5]\\d(?:\\.\\d+)?)?`}const Cs=/^-?\d+n?$/,Fs=/^-?\d+$/,Hs=/^-?\d+(?:\.\d+)?$/,Ds=/^(?:true|false)$/i,Ls=/^null$/i,Vs=/^[^A-Z]*$/,qs=/^[^a-z]*$/,Ms=ko("$ZodCheck",(e,t)=>{var n;e._zod??(e._zod={}),e._zod.def=t,(n=e._zod).onattach??(n.onattach=[])}),Ks={number:"number",bigint:"bigint",object:"date"},Js=ko("$ZodCheckLessThan",(e,t)=>{Ms.init(e,t);const n=Ks[typeof t.value];e._zod.onattach.push(e=>{const n=e._zod.bag,r=(t.inclusive?n.maximum:n.exclusiveMaximum)??Number.POSITIVE_INFINITY;t.value<r&&(t.inclusive?n.maximum=t.value:n.exclusiveMaximum=t.value)}),e._zod.check=r=>{(t.inclusive?r.value<=t.value:r.value<t.value)||r.issues.push({origin:n,code:"too_big",maximum:"object"==typeof t.value?t.value.getTime():t.value,input:r.value,inclusive:t.inclusive,inst:e,continue:!t.abort})}}),Gs=ko("$ZodCheckGreaterThan",(e,t)=>{Ms.init(e,t);const n=Ks[typeof t.value];e._zod.onattach.push(e=>{const n=e._zod.bag,r=(t.inclusive?n.minimum:n.exclusiveMinimum)??Number.NEGATIVE_INFINITY;t.value>r&&(t.inclusive?n.minimum=t.value:n.exclusiveMinimum=t.value)}),e._zod.check=r=>{(t.inclusive?r.value>=t.value:r.value>t.value)||r.issues.push({origin:n,code:"too_small",minimum:"object"==typeof t.value?t.value.getTime():t.value,input:r.value,inclusive:t.inclusive,inst:e,continue:!t.abort})}}),Ws=ko("$ZodCheckMultipleOf",(e,t)=>{Ms.init(e,t),e._zod.onattach.push(e=>{var n;(n=e._zod.bag).multipleOf??(n.multipleOf=t.value)}),e._zod.check=n=>{if(typeof n.value!=typeof t.value)throw new Error("Cannot mix number and bigint in multiple_of check.");("bigint"==typeof n.value?n.value%t.value===BigInt(0):0===function(e,t){const n=(e.toString().split(".")[1]||"").length,r=t.toString();let i=(r.split(".")[1]||"").length;if(0===i&&/\d?e-\d?/.test(r)){const e=r.match(/\d?e-(\d?)/);e?.[1]&&(i=Number.parseInt(e[1]))}const o=n>i?n:i;return Number.parseInt(e.toFixed(o).replace(".",""))%Number.parseInt(t.toFixed(o).replace(".",""))/10**o}(n.value,t.value))||n.issues.push({origin:typeof n.value,code:"not_multiple_of",divisor:t.value,input:n.value,inst:e,continue:!t.abort})}}),Ys=ko("$ZodCheckNumberFormat",(e,t)=>{Ms.init(e,t),t.format=t.format||"float64";const n=t.format?.includes("int"),r=n?"int":"number",[i,o]=Go[t.format];e._zod.onattach.push(e=>{const r=e._zod.bag;r.format=t.format,r.minimum=i,r.maximum=o,n&&(r.pattern=Fs)}),e._zod.check=s=>{const a=s.value;if(n){if(!Number.isInteger(a))return void s.issues.push({expected:r,format:t.format,code:"invalid_type",continue:!1,input:a,inst:e});if(!Number.isSafeInteger(a))return void(a>0?s.issues.push({input:a,code:"too_big",maximum:Number.MAX_SAFE_INTEGER,note:"Integers must be within the safe integer range.",inst:e,origin:r,inclusive:!0,continue:!t.abort}):s.issues.push({input:a,code:"too_small",minimum:Number.MIN_SAFE_INTEGER,note:"Integers must be within the safe integer range.",inst:e,origin:r,inclusive:!0,continue:!t.abort}))}a<i&&s.issues.push({origin:"number",input:a,code:"too_small",minimum:i,inclusive:!0,inst:e,continue:!t.abort}),a>o&&s.issues.push({origin:"number",input:a,code:"too_big",maximum:o,inclusive:!0,inst:e,continue:!t.abort})}}),Xs=ko("$ZodCheckMaxLength",(e,t)=>{var n;Ms.init(e,t),(n=e._zod.def).when??(n.when=e=>{const t=e.value;return!No(t)&&void 0!==t.length}),e._zod.onattach.push(e=>{const n=e._zod.bag.maximum??Number.POSITIVE_INFINITY;t.maximum<n&&(e._zod.bag.maximum=t.maximum)}),e._zod.check=n=>{const r=n.value;if(r.length<=t.maximum)return;const i=es(r);n.issues.push({origin:i,code:"too_big",maximum:t.maximum,inclusive:!0,input:r,inst:e,continue:!t.abort})}}),Qs=ko("$ZodCheckMinLength",(e,t)=>{var n;Ms.init(e,t),(n=e._zod.def).when??(n.when=e=>{const t=e.value;return!No(t)&&void 0!==t.length}),e._zod.onattach.push(e=>{const n=e._zod.bag.minimum??Number.NEGATIVE_INFINITY;t.minimum>n&&(e._zod.bag.minimum=t.minimum)}),e._zod.check=n=>{const r=n.value;if(r.length>=t.minimum)return;const i=es(r);n.issues.push({origin:i,code:"too_small",minimum:t.minimum,inclusive:!0,input:r,inst:e,continue:!t.abort})}}),ea=ko("$ZodCheckLengthEquals",(e,t)=>{var n;Ms.init(e,t),(n=e._zod.def).when??(n.when=e=>{const t=e.value;return!No(t)&&void 0!==t.length}),e._zod.onattach.push(e=>{const n=e._zod.bag;n.minimum=t.length,n.maximum=t.length,n.length=t.length}),e._zod.check=n=>{const r=n.value,i=r.length;if(i===t.length)return;const o=es(r),s=i>t.length;n.issues.push({origin:o,...s?{code:"too_big",maximum:t.length}:{code:"too_small",minimum:t.length},inclusive:!0,exact:!0,input:n.value,inst:e,continue:!t.abort})}}),ta=ko("$ZodCheckStringFormat",(e,t)=>{var n,r;Ms.init(e,t),e._zod.onattach.push(e=>{const n=e._zod.bag;n.format=t.format,t.pattern&&(n.patterns??(n.patterns=new Set),n.patterns.add(t.pattern))}),t.pattern?(n=e._zod).check??(n.check=n=>{t.pattern.lastIndex=0,t.pattern.test(n.value)||n.issues.push({origin:"string",code:"invalid_format",format:t.format,input:n.value,...t.pattern?{pattern:t.pattern.toString()}:{},inst:e,continue:!t.abort})}):(r=e._zod).check??(r.check=()=>{})}),na=ko("$ZodCheckRegex",(e,t)=>{ta.init(e,t),e._zod.check=n=>{t.pattern.lastIndex=0,t.pattern.test(n.value)||n.issues.push({origin:"string",code:"invalid_format",format:"regex",input:n.value,pattern:t.pattern.toString(),inst:e,continue:!t.abort})}}),ra=ko("$ZodCheckLowerCase",(e,t)=>{t.pattern??(t.pattern=Vs),ta.init(e,t)}),ia=ko("$ZodCheckUpperCase",(e,t)=>{t.pattern??(t.pattern=qs),ta.init(e,t)}),oa=ko("$ZodCheckIncludes",(e,t)=>{Ms.init(e,t);const n=Mo(t.includes),r=new RegExp("number"==typeof t.position?`^.{${t.position}}${n}`:n);t.pattern=r,e._zod.onattach.push(e=>{const t=e._zod.bag;t.patterns??(t.patterns=new Set),t.patterns.add(r)}),e._zod.check=n=>{n.value.includes(t.includes,t.position)||n.issues.push({origin:"string",code:"invalid_format",format:"includes",includes:t.includes,input:n.value,inst:e,continue:!t.abort})}}),sa=ko("$ZodCheckStartsWith",(e,t)=>{Ms.init(e,t);const n=new RegExp(`^${Mo(t.prefix)}.*`);t.pattern??(t.pattern=n),e._zod.onattach.push(e=>{const t=e._zod.bag;t.patterns??(t.patterns=new Set),t.patterns.add(n)}),e._zod.check=n=>{n.value.startsWith(t.prefix)||n.issues.push({origin:"string",code:"invalid_format",format:"starts_with",prefix:t.prefix,input:n.value,inst:e,continue:!t.abort})}}),aa=ko("$ZodCheckEndsWith",(e,t)=>{Ms.init(e,t);const n=new RegExp(`.*${Mo(t.suffix)}$`);t.pattern??(t.pattern=n),e._zod.onattach.push(e=>{const t=e._zod.bag;t.patterns??(t.patterns=new Set),t.patterns.add(n)}),e._zod.check=n=>{n.value.endsWith(t.suffix)||n.issues.push({origin:"string",code:"invalid_format",format:"ends_with",suffix:t.suffix,input:n.value,inst:e,continue:!t.abort})}}),ca=ko("$ZodCheckOverwrite",(e,t)=>{Ms.init(e,t),e._zod.check=e=>{e.value=t.tx(e.value)}});class ua{constructor(e=[]){this.content=[],this.indent=0,this&&(this.args=e)}indented(e){this.indent+=1,e(this),this.indent-=1}write(e){if("function"==typeof e)return e(this,{execution:"sync"}),void e(this,{execution:"async"});const t=e.split("\n").filter(e=>e),n=Math.min(...t.map(e=>e.length-e.trimStart().length)),r=t.map(e=>e.slice(n)).map(e=>" ".repeat(2*this.indent)+e);for(const e of r)this.content.push(e)}compile(){const e=Function,t=this?.args;return new e(...t,[...(this?.content??[""]).map(e=>` ${e}`)].join("\n"))}}const fa={major:4,minor:3,patch:6},da=ko("$ZodType",(e,t)=>{var n;e??(e={}),e._zod.def=t,e._zod.bag=e._zod.bag||{},e._zod.version=fa;const r=[...e._zod.def.checks??[]];e._zod.traits.has("$ZodCheck")&&r.unshift(e);for(const t of r)for(const n of t._zod.onattach)n(e);if(0===r.length)(n=e._zod).deferred??(n.deferred=[]),e._zod.deferred?.push(()=>{e._zod.run=e._zod.parse});else{const t=(e,t,n)=>{let r,i=Wo(e);for(const o of t){if(o._zod.def.when){if(!o._zod.def.when(e))continue}else if(i)continue;const t=e.issues.length,s=o._zod.check(e);if(s instanceof Promise&&!1===n?.async)throw new zo;if(r||s instanceof Promise)r=(r??Promise.resolve()).then(async()=>{await s;e.issues.length!==t&&(i||(i=Wo(e,t)))});else{if(e.issues.length===t)continue;i||(i=Wo(e,t))}}return r?r.then(()=>e):e},n=(n,i,o)=>{if(Wo(n))return n.aborted=!0,n;const s=t(i,r,o);if(s instanceof Promise){if(!1===o.async)throw new zo;return s.then(t=>e._zod.parse(t,o))}return e._zod.parse(s,o)};e._zod.run=(i,o)=>{if(o.skipChecks)return e._zod.parse(i,o);if("backward"===o.direction){const t=e._zod.parse({value:i.value,issues:[]},{...o,skipChecks:!0});return t instanceof Promise?t.then(e=>n(e,i,o)):n(t,i,o)}const s=e._zod.parse(i,o);if(s instanceof Promise){if(!1===o.async)throw new zo;return s.then(e=>t(e,r,o))}return t(s,r,o)}}Bo(e,"~standard",()=>({validate:t=>{try{const n=cs(e,t);return n.success?{value:n.data}:{issues:n.error?.issues}}catch(n){return fs(e,t).then(e=>e.success?{value:e.data}:{issues:e.error?.issues})}},vendor:"zod",version:1}))}),la=ko("$ZodString",(e,t)=>{var n;da.init(e,t),e._zod.pattern=[...e?._zod.bag?.patterns??[]].pop()??(n=e._zod.bag,new RegExp(`^${n?`[\\s\\S]{${n?.minimum??0},${n?.maximum??""}}`:"[\\s\\S]*"}$`)),e._zod.parse=(n,r)=>{if(t.coerce)try{n.value=String(n.value)}catch(r){}return"string"==typeof n.value||n.issues.push({expected:"string",code:"invalid_type",input:n.value,inst:e}),n}}),pa=ko("$ZodStringFormat",(e,t)=>{ta.init(e,t),la.init(e,t)}),ha=ko("$ZodGUID",(e,t)=>{t.pattern??(t.pattern=zs),pa.init(e,t)}),ma=ko("$ZodUUID",(e,t)=>{if(t.version){const e={v1:1,v2:2,v3:3,v4:4,v5:5,v6:6,v7:7,v8:8}[t.version];if(void 0===e)throw new Error(`Invalid UUID version: "${t.version}"`);t.pattern??(t.pattern=Ss(e))}else t.pattern??(t.pattern=Ss());pa.init(e,t)}),ga=ko("$ZodEmail",(e,t)=>{t.pattern??(t.pattern=$s),pa.init(e,t)}),ya=ko("$ZodURL",(e,t)=>{pa.init(e,t),e._zod.check=n=>{try{const r=n.value.trim(),i=new URL(r);return t.hostname&&(t.hostname.lastIndex=0,t.hostname.test(i.hostname)||n.issues.push({code:"invalid_format",format:"url",note:"Invalid hostname",pattern:t.hostname.source,input:n.value,inst:e,continue:!t.abort})),t.protocol&&(t.protocol.lastIndex=0,t.protocol.test(i.protocol.endsWith(":")?i.protocol.slice(0,-1):i.protocol)||n.issues.push({code:"invalid_format",format:"url",note:"Invalid protocol",pattern:t.protocol.source,input:n.value,inst:e,continue:!t.abort})),void(t.normalize?n.value=i.href:n.value=r)}catch(r){n.issues.push({code:"invalid_format",format:"url",input:n.value,inst:e,continue:!t.abort})}}}),_a=ko("$ZodEmoji",(e,t)=>{t.pattern??(t.pattern=new RegExp("^(\\p{Extended_Pictographic}|\\p{Emoji_Component})+$","u")),pa.init(e,t)}),wa=ko("$ZodNanoID",(e,t)=>{t.pattern??(t.pattern=Os),pa.init(e,t)}),va=ko("$ZodCUID",(e,t)=>{t.pattern??(t.pattern=ws),pa.init(e,t)}),ba=ko("$ZodCUID2",(e,t)=>{t.pattern??(t.pattern=vs),pa.init(e,t)}),xa=ko("$ZodULID",(e,t)=>{t.pattern??(t.pattern=bs),pa.init(e,t)}),Ea=ko("$ZodXID",(e,t)=>{t.pattern??(t.pattern=xs),pa.init(e,t)}),Oa=ko("$ZodKSUID",(e,t)=>{t.pattern??(t.pattern=Es),pa.init(e,t)}),ka=ko("$ZodISODateTime",(e,t)=>{t.pattern??(t.pattern=function(e){const t=Zs({precision:e.precision}),n=["Z"];e.local&&n.push(""),e.offset&&n.push("([+-](?:[01]\\d|2[0-3]):[0-5]\\d)");const r=`${t}(?:${n.join("|")})`;return new RegExp(`^${Bs}T(?:${r})$`)}(t)),pa.init(e,t)}),za=ko("$ZodISODate",(e,t)=>{t.pattern??(t.pattern=js),pa.init(e,t)}),Sa=ko("$ZodISOTime",(e,t)=>{t.pattern??(t.pattern=new RegExp(`^${Zs(t)}$`)),pa.init(e,t)}),$a=ko("$ZodISODuration",(e,t)=>{t.pattern??(t.pattern=ks),pa.init(e,t)}),Pa=ko("$ZodIPv4",(e,t)=>{t.pattern??(t.pattern=Ps),pa.init(e,t),e._zod.bag.format="ipv4"}),Aa=ko("$ZodIPv6",(e,t)=>{t.pattern??(t.pattern=As),pa.init(e,t),e._zod.bag.format="ipv6",e._zod.check=n=>{try{new URL(`http://[${n.value}]`)}catch{n.issues.push({code:"invalid_format",format:"ipv6",input:n.value,inst:e,continue:!t.abort})}}}),Ia=ko("$ZodCIDRv4",(e,t)=>{t.pattern??(t.pattern=Is),pa.init(e,t)}),Ta=ko("$ZodCIDRv6",(e,t)=>{t.pattern??(t.pattern=Ts),pa.init(e,t),e._zod.check=n=>{const r=n.value.split("/");try{if(2!==r.length)throw new Error;const[e,t]=r;if(!t)throw new Error;const n=Number(t);if(`${n}`!==t)throw new Error;if(n<0||n>128)throw new Error;new URL(`http://[${e}]`)}catch{n.issues.push({code:"invalid_format",format:"cidrv6",input:n.value,inst:e,continue:!t.abort})}}});function Na(e){if(""===e)return!0;if(e.length%4!=0)return!1;try{return atob(e),!0}catch{return!1}}const Ra=ko("$ZodBase64",(e,t)=>{t.pattern??(t.pattern=Ns),pa.init(e,t),e._zod.bag.contentEncoding="base64",e._zod.check=n=>{Na(n.value)||n.issues.push({code:"invalid_format",format:"base64",input:n.value,inst:e,continue:!t.abort})}});const Ua=ko("$ZodBase64URL",(e,t)=>{t.pattern??(t.pattern=Rs),pa.init(e,t),e._zod.bag.contentEncoding="base64url",e._zod.check=n=>{(function(e){if(!Rs.test(e))return!1;const t=e.replace(/[-_]/g,e=>"-"===e?"+":"/");return Na(t.padEnd(4*Math.ceil(t.length/4),"="))})(n.value)||n.issues.push({code:"invalid_format",format:"base64url",input:n.value,inst:e,continue:!t.abort})}}),Ba=ko("$ZodE164",(e,t)=>{t.pattern??(t.pattern=Us),pa.init(e,t)});const ja=ko("$ZodJWT",(e,t)=>{pa.init(e,t),e._zod.check=n=>{(function(e,t=null){try{const n=e.split(".");if(3!==n.length)return!1;const[r]=n;if(!r)return!1;const i=JSON.parse(atob(r));return!("typ"in i&&"JWT"!==i?.typ||!i.alg||t&&(!("alg"in i)||i.alg!==t))}catch{return!1}})(n.value,t.alg)||n.issues.push({code:"invalid_format",format:"jwt",input:n.value,inst:e,continue:!t.abort})}}),Za=ko("$ZodNumber",(e,t)=>{da.init(e,t),e._zod.pattern=e._zod.bag.pattern??Hs,e._zod.parse=(n,r)=>{if(t.coerce)try{n.value=Number(n.value)}catch(e){}const i=n.value;if("number"==typeof i&&!Number.isNaN(i)&&Number.isFinite(i))return n;const o="number"==typeof i?Number.isNaN(i)?"NaN":Number.isFinite(i)?void 0:"Infinity":void 0;return n.issues.push({expected:"number",code:"invalid_type",input:i,inst:e,...o?{received:o}:{}}),n}}),Ca=ko("$ZodNumberFormat",(e,t)=>{Ys.init(e,t),Za.init(e,t)}),Fa=ko("$ZodBoolean",(e,t)=>{da.init(e,t),e._zod.pattern=Ds,e._zod.parse=(n,r)=>{if(t.coerce)try{n.value=Boolean(n.value)}catch(e){}const i=n.value;return"boolean"==typeof i||n.issues.push({expected:"boolean",code:"invalid_type",input:i,inst:e}),n}}),Ha=ko("$ZodBigInt",(e,t)=>{da.init(e,t),e._zod.pattern=Cs,e._zod.parse=(n,r)=>{if(t.coerce)try{n.value=BigInt(n.value)}catch(e){}return"bigint"==typeof n.value||n.issues.push({expected:"bigint",code:"invalid_type",input:n.value,inst:e}),n}}),Da=ko("$ZodNull",(e,t)=>{da.init(e,t),e._zod.pattern=Ls,e._zod.values=new Set([null]),e._zod.parse=(t,n)=>{const r=t.value;return null===r||t.issues.push({expected:"null",code:"invalid_type",input:r,inst:e}),t}}),La=ko("$ZodUnknown",(e,t)=>{da.init(e,t),e._zod.parse=e=>e}),Va=ko("$ZodNever",(e,t)=>{da.init(e,t),e._zod.parse=(t,n)=>(t.issues.push({expected:"never",code:"invalid_type",input:t.value,inst:e}),t)});function qa(e,t,n){e.issues.length&&t.issues.push(...Yo(n,e.issues)),t.value[n]=e.value}const Ma=ko("$ZodArray",(e,t)=>{da.init(e,t),e._zod.parse=(n,r)=>{const i=n.value;if(!Array.isArray(i))return n.issues.push({expected:"array",code:"invalid_type",input:i,inst:e}),n;n.value=Array(i.length);const o=[];for(let e=0;e<i.length;e++){const s=i[e],a=t.element._zod.run({value:s,issues:[]},r);a instanceof Promise?o.push(a.then(t=>qa(t,n,e))):qa(a,n,e)}return o.length?Promise.all(o).then(()=>n):n}});function Ka(e,t,n,r,i){if(e.issues.length){if(i&&!(n in r))return;t.issues.push(...Yo(n,e.issues))}void 0===e.value?n in r&&(t.value[n]=void 0):t.value[n]=e.value}function Ja(e){const t=Object.keys(e.shape);for(const n of t)if(!e.shape?.[n]?._zod?.traits?.has("$ZodType"))throw new Error(`Invalid element at key "${n}": expected a Zod schema`);const n=(r=e.shape,Object.keys(r).filter(e=>"optional"===r[e]._zod.optin&&"optional"===r[e]._zod.optout));var r;return{...e,keys:t,keySet:new Set(t),numKeys:t.length,optionalKeys:new Set(n)}}function Ga(e,t,n,r,i,o){const s=[],a=i.keySet,c=i.catchall._zod,u=c.def.type,f="optional"===c.optout;for(const i in t){if(a.has(i))continue;if("never"===u){s.push(i);continue}const o=c.run({value:t[i],issues:[]},r);o instanceof Promise?e.push(o.then(e=>Ka(e,n,i,t,f))):Ka(o,n,i,t,f)}return s.length&&n.issues.push({code:"unrecognized_keys",keys:s,input:t,inst:o}),e.length?Promise.all(e).then(()=>n):n}const Wa=ko("$ZodObject",(e,t)=>{da.init(e,t);const n=Object.getOwnPropertyDescriptor(t,"shape");if(!n?.get){const e=t.shape;Object.defineProperty(t,"shape",{get:()=>{const n={...e};return Object.defineProperty(t,"shape",{value:n}),n}})}const r=To(()=>Ja(t));Bo(e._zod,"propValues",()=>{const e=t.shape,n={};for(const t in e){const r=e[t]._zod;if(r.values){n[t]??(n[t]=new Set);for(const e of r.values)n[t].add(e)}}return n});const i=Ho,o=t.catchall;let s;e._zod.parse=(t,n)=>{s??(s=r.value);const a=t.value;if(!i(a))return t.issues.push({expected:"object",code:"invalid_type",input:a,inst:e}),t;t.value={};const c=[],u=s.shape;for(const e of s.keys){const r=u[e],i="optional"===r._zod.optout,o=r._zod.run({value:a[e],issues:[]},n);o instanceof Promise?c.push(o.then(n=>Ka(n,t,e,a,i))):Ka(o,t,e,a,i)}return o?Ga(c,a,t,n,r.value,e):c.length?Promise.all(c).then(()=>t):t}}),Ya=ko("$ZodObjectJIT",(e,t)=>{Wa.init(e,t);const n=e._zod.parse,r=To(()=>Ja(t));let i;const o=Ho,s=!$o.jitless,a=s&&Do.value,c=t.catchall;let u;e._zod.parse=(f,d)=>{u??(u=r.value);const l=f.value;return o(l)?s&&a&&!1===d?.async&&!0!==d.jitless?(i||(i=(e=>{const t=new ua(["shape","payload","ctx"]),n=r.value,i=e=>{const t=Co(e);return`shape[${t}]._zod.run({ value: input[${t}], issues: [] }, ctx)`};t.write("const input = payload.value;");const o=Object.create(null);let s=0;for(const e of n.keys)o[e]="key_"+s++;t.write("const newResult = {};");for(const r of n.keys){const n=o[r],s=Co(r),a=e[r],c="optional"===a?._zod?.optout;t.write(`const ${n} = ${i(r)};`),c?t.write(`\n if (${n}.issues.length) {\n if (${s} in input) {\n payload.issues = payload.issues.concat(${n}.issues.map(iss => ({\n ...iss,\n path: iss.path ? [${s}, ...iss.path] : [${s}]\n })));\n }\n }\n \n if (${n}.value === undefined) {\n if (${s} in input) {\n newResult[${s}] = undefined;\n }\n } else {\n newResult[${s}] = ${n}.value;\n }\n \n `):t.write(`\n if (${n}.issues.length) {\n payload.issues = payload.issues.concat(${n}.issues.map(iss => ({\n ...iss,\n path: iss.path ? [${s}, ...iss.path] : [${s}]\n })));\n }\n \n if (${n}.value === undefined) {\n if (${s} in input) {\n newResult[${s}] = undefined;\n }\n } else {\n newResult[${s}] = ${n}.value;\n }\n \n `)}t.write("payload.value = newResult;"),t.write("return payload;");const a=t.compile();return(t,n)=>a(e,t,n)})(t.shape)),f=i(f,d),c?Ga([],l,f,d,u,e):f):n(f,d):(f.issues.push({expected:"object",code:"invalid_type",input:l,inst:e}),f)}});function Xa(e,t,n,r){for(const n of e)if(0===n.issues.length)return t.value=n.value,t;const i=e.filter(e=>!Wo(e));return 1===i.length?(t.value=i[0].value,i[0]):(t.issues.push({code:"invalid_union",input:t.value,inst:n,errors:e.map(e=>e.issues.map(e=>Qo(e,r,Po())))}),t)}const Qa=ko("$ZodUnion",(e,t)=>{da.init(e,t),Bo(e._zod,"optin",()=>t.options.some(e=>"optional"===e._zod.optin)?"optional":void 0),Bo(e._zod,"optout",()=>t.options.some(e=>"optional"===e._zod.optout)?"optional":void 0),Bo(e._zod,"values",()=>{if(t.options.every(e=>e._zod.values))return new Set(t.options.flatMap(e=>Array.from(e._zod.values)))}),Bo(e._zod,"pattern",()=>{if(t.options.every(e=>e._zod.pattern)){const e=t.options.map(e=>e._zod.pattern);return new RegExp(`^(${e.map(e=>Ro(e.source)).join("|")})$`)}});const n=1===t.options.length,r=t.options[0]._zod.run;e._zod.parse=(i,o)=>{if(n)return r(i,o);let s=!1;const a=[];for(const e of t.options){const t=e._zod.run({value:i.value,issues:[]},o);if(t instanceof Promise)a.push(t),s=!0;else{if(0===t.issues.length)return t;a.push(t)}}return s?Promise.all(a).then(t=>Xa(t,i,e,o)):Xa(a,i,e,o)}}),ec=ko("$ZodIntersection",(e,t)=>{da.init(e,t),e._zod.parse=(e,n)=>{const r=e.value,i=t.left._zod.run({value:r,issues:[]},n),o=t.right._zod.run({value:r,issues:[]},n);return i instanceof Promise||o instanceof Promise?Promise.all([i,o]).then(([t,n])=>nc(e,t,n)):nc(e,i,o)}});function tc(e,t){if(e===t)return{valid:!0,data:e};if(e instanceof Date&&t instanceof Date&&+e===+t)return{valid:!0,data:e};if(Lo(e)&&Lo(t)){const n=Object.keys(t),r=Object.keys(e).filter(e=>-1!==n.indexOf(e)),i={...e,...t};for(const n of r){const r=tc(e[n],t[n]);if(!r.valid)return{valid:!1,mergeErrorPath:[n,...r.mergeErrorPath]};i[n]=r.data}return{valid:!0,data:i}}if(Array.isArray(e)&&Array.isArray(t)){if(e.length!==t.length)return{valid:!1,mergeErrorPath:[]};const n=[];for(let r=0;r<e.length;r++){const i=tc(e[r],t[r]);if(!i.valid)return{valid:!1,mergeErrorPath:[r,...i.mergeErrorPath]};n.push(i.data)}return{valid:!0,data:n}}return{valid:!1,mergeErrorPath:[]}}function nc(e,t,n){const r=new Map;let i;for(const n of t.issues)if("unrecognized_keys"===n.code){i??(i=n);for(const e of n.keys)r.has(e)||r.set(e,{}),r.get(e).l=!0}else e.issues.push(n);for(const t of n.issues)if("unrecognized_keys"===t.code)for(const e of t.keys)r.has(e)||r.set(e,{}),r.get(e).r=!0;else e.issues.push(t);const o=[...r].filter(([,e])=>e.l&&e.r).map(([e])=>e);if(o.length&&i&&e.issues.push({...i,keys:o}),Wo(e))return e;const s=tc(t.value,n.value);if(!s.valid)throw new Error(`Unmergable intersection. Error path: ${JSON.stringify(s.mergeErrorPath)}`);return e.value=s.data,e}const rc=ko("$ZodRecord",(e,t)=>{da.init(e,t),e._zod.parse=(n,r)=>{const i=n.value;if(!Lo(i))return n.issues.push({expected:"record",code:"invalid_type",input:i,inst:e}),n;const o=[],s=t.keyType._zod.values;if(s){n.value={};const a=new Set;for(const e of s)if("string"==typeof e||"number"==typeof e||"symbol"==typeof e){a.add("number"==typeof e?e.toString():e);const s=t.valueType._zod.run({value:i[e],issues:[]},r);s instanceof Promise?o.push(s.then(t=>{t.issues.length&&n.issues.push(...Yo(e,t.issues)),n.value[e]=t.value})):(s.issues.length&&n.issues.push(...Yo(e,s.issues)),n.value[e]=s.value)}let c;for(const e in i)a.has(e)||(c=c??[],c.push(e));c&&c.length>0&&n.issues.push({code:"unrecognized_keys",input:i,inst:e,keys:c})}else{n.value={};for(const s of Reflect.ownKeys(i)){if("__proto__"===s)continue;let a=t.keyType._zod.run({value:s,issues:[]},r);if(a instanceof Promise)throw new Error("Async schemas not supported in object keys currently");if("string"==typeof s&&Hs.test(s)&&a.issues.length){const e=t.keyType._zod.run({value:Number(s),issues:[]},r);if(e instanceof Promise)throw new Error("Async schemas not supported in object keys currently");0===e.issues.length&&(a=e)}if(a.issues.length){"loose"===t.mode?n.value[s]=i[s]:n.issues.push({code:"invalid_key",origin:"record",issues:a.issues.map(e=>Qo(e,r,Po())),input:s,path:[s],inst:e});continue}const c=t.valueType._zod.run({value:i[s],issues:[]},r);c instanceof Promise?o.push(c.then(e=>{e.issues.length&&n.issues.push(...Yo(s,e.issues)),n.value[a.value]=e.value})):(c.issues.length&&n.issues.push(...Yo(s,c.issues)),n.value[a.value]=c.value)}}return o.length?Promise.all(o).then(()=>n):n}}),ic=ko("$ZodEnum",(e,t)=>{da.init(e,t);const n=Ao(t.entries),r=new Set(n);e._zod.values=r,e._zod.pattern=new RegExp(`^(${n.filter(e=>qo.has(typeof e)).map(e=>"string"==typeof e?Mo(e):e.toString()).join("|")})$`),e._zod.parse=(t,i)=>{const o=t.value;return r.has(o)||t.issues.push({code:"invalid_value",values:n,input:o,inst:e}),t}}),oc=ko("$ZodTransform",(e,t)=>{da.init(e,t),e._zod.parse=(n,r)=>{if("backward"===r.direction)throw new So(e.constructor.name);const i=t.transform(n.value,n);if(r.async){return(i instanceof Promise?i:Promise.resolve(i)).then(e=>(n.value=e,n))}if(i instanceof Promise)throw new zo;return n.value=i,n}});function sc(e,t){return e.issues.length&&void 0===t?{issues:[],value:void 0}:e}const ac=ko("$ZodOptional",(e,t)=>{da.init(e,t),e._zod.optin="optional",e._zod.optout="optional",Bo(e._zod,"values",()=>t.innerType._zod.values?new Set([...t.innerType._zod.values,void 0]):void 0),Bo(e._zod,"pattern",()=>{const e=t.innerType._zod.pattern;return e?new RegExp(`^(${Ro(e.source)})?$`):void 0}),e._zod.parse=(e,n)=>{if("optional"===t.innerType._zod.optin){const r=t.innerType._zod.run(e,n);return r instanceof Promise?r.then(t=>sc(t,e.value)):sc(r,e.value)}return void 0===e.value?e:t.innerType._zod.run(e,n)}}),cc=ko("$ZodExactOptional",(e,t)=>{ac.init(e,t),Bo(e._zod,"values",()=>t.innerType._zod.values),Bo(e._zod,"pattern",()=>t.innerType._zod.pattern),e._zod.parse=(e,n)=>t.innerType._zod.run(e,n)}),uc=ko("$ZodNullable",(e,t)=>{da.init(e,t),Bo(e._zod,"optin",()=>t.innerType._zod.optin),Bo(e._zod,"optout",()=>t.innerType._zod.optout),Bo(e._zod,"pattern",()=>{const e=t.innerType._zod.pattern;return e?new RegExp(`^(${Ro(e.source)}|null)$`):void 0}),Bo(e._zod,"values",()=>t.innerType._zod.values?new Set([...t.innerType._zod.values,null]):void 0),e._zod.parse=(e,n)=>null===e.value?e:t.innerType._zod.run(e,n)}),fc=ko("$ZodDefault",(e,t)=>{da.init(e,t),e._zod.optin="optional",Bo(e._zod,"values",()=>t.innerType._zod.values),e._zod.parse=(e,n)=>{if("backward"===n.direction)return t.innerType._zod.run(e,n);if(void 0===e.value)return e.value=t.defaultValue,e;const r=t.innerType._zod.run(e,n);return r instanceof Promise?r.then(e=>dc(e,t)):dc(r,t)}});function dc(e,t){return void 0===e.value&&(e.value=t.defaultValue),e}const lc=ko("$ZodPrefault",(e,t)=>{da.init(e,t),e._zod.optin="optional",Bo(e._zod,"values",()=>t.innerType._zod.values),e._zod.parse=(e,n)=>("backward"===n.direction||void 0===e.value&&(e.value=t.defaultValue),t.innerType._zod.run(e,n))}),pc=ko("$ZodNonOptional",(e,t)=>{da.init(e,t),Bo(e._zod,"values",()=>{const e=t.innerType._zod.values;return e?new Set([...e].filter(e=>void 0!==e)):void 0}),e._zod.parse=(n,r)=>{const i=t.innerType._zod.run(n,r);return i instanceof Promise?i.then(t=>hc(t,e)):hc(i,e)}});function hc(e,t){return e.issues.length||void 0!==e.value||e.issues.push({code:"invalid_type",expected:"nonoptional",input:e.value,inst:t}),e}const mc=ko("$ZodCatch",(e,t)=>{da.init(e,t),Bo(e._zod,"optin",()=>t.innerType._zod.optin),Bo(e._zod,"optout",()=>t.innerType._zod.optout),Bo(e._zod,"values",()=>t.innerType._zod.values),e._zod.parse=(e,n)=>{if("backward"===n.direction)return t.innerType._zod.run(e,n);const r=t.innerType._zod.run(e,n);return r instanceof Promise?r.then(r=>(e.value=r.value,r.issues.length&&(e.value=t.catchValue({...e,error:{issues:r.issues.map(e=>Qo(e,n,Po()))},input:e.value}),e.issues=[]),e)):(e.value=r.value,r.issues.length&&(e.value=t.catchValue({...e,error:{issues:r.issues.map(e=>Qo(e,n,Po()))},input:e.value}),e.issues=[]),e)}}),gc=ko("$ZodPipe",(e,t)=>{da.init(e,t),Bo(e._zod,"values",()=>t.in._zod.values),Bo(e._zod,"optin",()=>t.in._zod.optin),Bo(e._zod,"optout",()=>t.out._zod.optout),Bo(e._zod,"propValues",()=>t.in._zod.propValues),e._zod.parse=(e,n)=>{if("backward"===n.direction){const r=t.out._zod.run(e,n);return r instanceof Promise?r.then(e=>yc(e,t.in,n)):yc(r,t.in,n)}const r=t.in._zod.run(e,n);return r instanceof Promise?r.then(e=>yc(e,t.out,n)):yc(r,t.out,n)}});function yc(e,t,n){return e.issues.length?(e.aborted=!0,e):t._zod.run({value:e.value,issues:e.issues},n)}const _c=ko("$ZodReadonly",(e,t)=>{da.init(e,t),Bo(e._zod,"propValues",()=>t.innerType._zod.propValues),Bo(e._zod,"values",()=>t.innerType._zod.values),Bo(e._zod,"optin",()=>t.innerType?._zod?.optin),Bo(e._zod,"optout",()=>t.innerType?._zod?.optout),e._zod.parse=(e,n)=>{if("backward"===n.direction)return t.innerType._zod.run(e,n);const r=t.innerType._zod.run(e,n);return r instanceof Promise?r.then(wc):wc(r)}});function wc(e){return e.value=Object.freeze(e.value),e}const vc=ko("$ZodLazy",(e,t)=>{da.init(e,t),Bo(e._zod,"innerType",()=>t.getter()),Bo(e._zod,"pattern",()=>e._zod.innerType?._zod?.pattern),Bo(e._zod,"propValues",()=>e._zod.innerType?._zod?.propValues),Bo(e._zod,"optin",()=>e._zod.innerType?._zod?.optin??void 0),Bo(e._zod,"optout",()=>e._zod.innerType?._zod?.optout??void 0),e._zod.parse=(t,n)=>e._zod.innerType._zod.run(t,n)}),bc=ko("$ZodCustom",(e,t)=>{Ms.init(e,t),da.init(e,t),e._zod.parse=(e,t)=>e,e._zod.check=n=>{const r=n.value,i=t.fn(r);if(i instanceof Promise)return i.then(t=>xc(t,n,r,e));xc(i,n,r,e)}});function xc(e,t,n,r){if(!e){const e={code:"custom",input:n,inst:r,path:[...r._zod.def.path??[]],continue:!r._zod.def.abort};r._zod.def.params&&(e.params=r._zod.def.params),t.issues.push(ts(e))}}var Ec;class Oc{constructor(){this._map=new WeakMap,this._idmap=new Map}add(e,...t){const n=t[0];return this._map.set(e,n),n&&"object"==typeof n&&"id"in n&&this._idmap.set(n.id,e),this}clear(){return this._map=new WeakMap,this._idmap=new Map,this}remove(e){const t=this._map.get(e);return t&&"object"==typeof t&&"id"in t&&this._idmap.delete(t.id),this._map.delete(e),this}get(e){const t=e._zod.parent;if(t){const n={...this.get(t)??{}};delete n.id;const r={...n,...this._map.get(e)};return Object.keys(r).length?r:void 0}return this._map.get(e)}has(e){return this._map.has(e)}}(Ec=globalThis).__zod_globalRegistry??(Ec.__zod_globalRegistry=new Oc);const kc=globalThis.__zod_globalRegistry;function zc(e,t){return new e({type:"string",format:"guid",check:"string_format",abort:!1,...Jo(t)})}function Sc(e,t){return new Js({check:"less_than",...Jo(t),value:e,inclusive:!1})}function $c(e,t){return new Js({check:"less_than",...Jo(t),value:e,inclusive:!0})}function Pc(e,t){return new Gs({check:"greater_than",...Jo(t),value:e,inclusive:!1})}function Ac(e,t){return new Gs({check:"greater_than",...Jo(t),value:e,inclusive:!0})}function Ic(e,t){return new Ws({check:"multiple_of",...Jo(t),value:e})}function Tc(e,t){return new Xs({check:"max_length",...Jo(t),maximum:e})}function Nc(e,t){return new Qs({check:"min_length",...Jo(t),minimum:e})}function Rc(e,t){return new ea({check:"length_equals",...Jo(t),length:e})}function Uc(e){return new ca({check:"overwrite",tx:e})}function Bc(e){const t=function(e,t){const n=new Ms({check:"custom",...Jo(t)});return n._zod.check=e,n}(n=>(n.addIssue=e=>{if("string"==typeof e)n.issues.push(ts(e,n.value,t._zod.def));else{const r=e;r.fatal&&(r.continue=!1),r.code??(r.code="custom"),r.input??(r.input=n.value),r.inst??(r.inst=t),r.continue??(r.continue=!t._zod.def.abort),n.issues.push(ts(r))}},e(n.value,n)));return t}function jc(e){let t=e?.target??"draft-2020-12";return"draft-4"===t&&(t="draft-04"),"draft-7"===t&&(t="draft-07"),{processors:e.processors??{},metadataRegistry:e?.metadata??kc,target:t,unrepresentable:e?.unrepresentable??"throw",override:e?.override??(()=>{}),io:e?.io??"output",counter:0,seen:new Map,cycles:e?.cycles??"ref",reused:e?.reused??"inline",external:e?.external??void 0}}function Zc(e,t,n={path:[],schemaPath:[]}){var r;const i=e._zod.def,o=t.seen.get(e);if(o){o.count++;return n.schemaPath.includes(e)&&(o.cycle=n.path),o.schema}const s={schema:{},count:1,cycle:void 0,path:n.path};t.seen.set(e,s);const a=e._zod.toJSONSchema?.();if(a)s.schema=a;else{const r={...n,schemaPath:[...n.schemaPath,e],path:n.path};if(e._zod.processJSONSchema)e._zod.processJSONSchema(t,s.schema,r);else{const n=s.schema,o=t.processors[i.type];if(!o)throw new Error(`[toJSONSchema]: Non-representable type encountered: ${i.type}`);o(e,t,n,r)}const o=e._zod.parent;o&&(s.ref||(s.ref=o),Zc(o,t,r),t.seen.get(o).isParent=!0)}const c=t.metadataRegistry.get(e);c&&Object.assign(s.schema,c),"input"===t.io&&Hc(e)&&(delete s.schema.examples,delete s.schema.default),"input"===t.io&&s.schema._prefault&&((r=s.schema).default??(r.default=s.schema._prefault)),delete s.schema._prefault;return t.seen.get(e).schema}function Cc(e,t){const n=e.seen.get(t);if(!n)throw new Error("Unprocessed schema. This is a bug in Zod.");const r=new Map;for(const t of e.seen.entries()){const n=e.metadataRegistry.get(t[0])?.id;if(n){const e=r.get(n);if(e&&e!==t[0])throw new Error(`Duplicate schema id "${n}" detected during JSON Schema conversion. Two different schemas cannot share the same id when converted together.`);r.set(n,t[0])}}const i=t=>{if(t[1].schema.$ref)return;const r=t[1],{ref:i,defId:o}=(t=>{const r="draft-2020-12"===e.target?"$defs":"definitions";if(e.external){const n=e.external.registry.get(t[0])?.id,i=e.external.uri??(e=>e);if(n)return{ref:i(n)};const o=t[1].defId??t[1].schema.id??"schema"+e.counter++;return t[1].defId=o,{defId:o,ref:`${i("__shared")}#/${r}/${o}`}}if(t[1]===n)return{ref:"#"};const i=`#/${r}/`,o=t[1].schema.id??"__schema"+e.counter++;return{defId:o,ref:i+o}})(t);r.def={...r.schema},o&&(r.defId=o);const s=r.schema;for(const e in s)delete s[e];s.$ref=i};if("throw"===e.cycles)for(const t of e.seen.entries()){const e=t[1];if(e.cycle)throw new Error(`Cycle detected: #/${e.cycle?.join("/")}/<root>\n\nSet the \`cycles\` parameter to \`"ref"\` to resolve cyclical schemas with defs.`)}for(const n of e.seen.entries()){const r=n[1];if(t===n[0]){i(n);continue}if(e.external){const r=e.external.registry.get(n[0])?.id;if(t!==n[0]&&r){i(n);continue}}const o=e.metadataRegistry.get(n[0])?.id;o?i(n):(r.cycle||r.count>1&&"ref"===e.reused)&&i(n)}}function Fc(e,t){const n=e.seen.get(t);if(!n)throw new Error("Unprocessed schema. This is a bug in Zod.");const r=t=>{const n=e.seen.get(t);if(null===n.ref)return;const i=n.def??n.schema,o={...i},s=n.ref;if(n.ref=null,s){r(s);const n=e.seen.get(s),a=n.schema;!a.$ref||"draft-07"!==e.target&&"draft-04"!==e.target&&"openapi-3.0"!==e.target?Object.assign(i,a):(i.allOf=i.allOf??[],i.allOf.push(a)),Object.assign(i,o);if(t._zod.parent===s)for(const e in i)"$ref"!==e&&"allOf"!==e&&(e in o||delete i[e]);if(a.$ref&&n.def)for(const e in i)"$ref"!==e&&"allOf"!==e&&e in n.def&&JSON.stringify(i[e])===JSON.stringify(n.def[e])&&delete i[e]}const a=t._zod.parent;if(a&&a!==s){r(a);const t=e.seen.get(a);if(t?.schema.$ref&&(i.$ref=t.schema.$ref,t.def))for(const e in i)"$ref"!==e&&"allOf"!==e&&e in t.def&&JSON.stringify(i[e])===JSON.stringify(t.def[e])&&delete i[e]}e.override({zodSchema:t,jsonSchema:i,path:n.path??[]})};for(const t of[...e.seen.entries()].reverse())r(t[0]);const i={};if("draft-2020-12"===e.target?i.$schema="https://json-schema.org/draft/2020-12/schema":"draft-07"===e.target?i.$schema="http://json-schema.org/draft-07/schema#":"draft-04"===e.target&&(i.$schema="http://json-schema.org/draft-04/schema#"),e.external?.uri){const n=e.external.registry.get(t)?.id;if(!n)throw new Error("Schema is missing an `id` property");i.$id=e.external.uri(n)}Object.assign(i,n.def??n.schema);const o=e.external?.defs??{};for(const t of e.seen.entries()){const e=t[1];e.def&&e.defId&&(o[e.defId]=e.def)}e.external||Object.keys(o).length>0&&("draft-2020-12"===e.target?i.$defs=o:i.definitions=o);try{const n=JSON.parse(JSON.stringify(i));return Object.defineProperty(n,"~standard",{value:{...t["~standard"],jsonSchema:{input:Dc(t,"input",e.processors),output:Dc(t,"output",e.processors)}},enumerable:!1,writable:!1}),n}catch(e){throw new Error("Error converting schema to JSON.")}}function Hc(e,t){const n=t??{seen:new Set};if(n.seen.has(e))return!1;n.seen.add(e);const r=e._zod.def;if("transform"===r.type)return!0;if("array"===r.type)return Hc(r.element,n);if("set"===r.type)return Hc(r.valueType,n);if("lazy"===r.type)return Hc(r.getter(),n);if("promise"===r.type||"optional"===r.type||"nonoptional"===r.type||"nullable"===r.type||"readonly"===r.type||"default"===r.type||"prefault"===r.type)return Hc(r.innerType,n);if("intersection"===r.type)return Hc(r.left,n)||Hc(r.right,n);if("record"===r.type||"map"===r.type)return Hc(r.keyType,n)||Hc(r.valueType,n);if("pipe"===r.type)return Hc(r.in,n)||Hc(r.out,n);if("object"===r.type){for(const e in r.shape)if(Hc(r.shape[e],n))return!0;return!1}if("union"===r.type){for(const e of r.options)if(Hc(e,n))return!0;return!1}if("tuple"===r.type){for(const e of r.items)if(Hc(e,n))return!0;return!(!r.rest||!Hc(r.rest,n))}return!1}const Dc=(e,t,n={})=>r=>{const{libraryOptions:i,target:o}=r??{},s=jc({...i??{},target:o,io:t,processors:n});return Zc(e,s),Cc(s,e),Fc(s,e)},Lc={guid:"uuid",url:"uri",datetime:"date-time",json_string:"json-string",regex:""},Vc=(e,t,n,r)=>{const i=e._zod.def;Zc(i.innerType,t,r);t.seen.get(e).ref=i.innerType},qc=ko("ZodISODateTime",(e,t)=>{ka.init(e,t),gu.init(e,t)});function Mc(e){return function(e,t){return new e({type:"string",format:"datetime",check:"string_format",offset:!1,local:!1,precision:null,...Jo(t)})}(qc,e)}const Kc=ko("ZodISODate",(e,t)=>{za.init(e,t),gu.init(e,t)});function Jc(e){return function(e,t){return new e({type:"string",format:"date",check:"string_format",...Jo(t)})}(Kc,e)}const Gc=ko("ZodISOTime",(e,t)=>{Sa.init(e,t),gu.init(e,t)});function Wc(e){return function(e,t){return new e({type:"string",format:"time",check:"string_format",precision:null,...Jo(t)})}(Gc,e)}const Yc=ko("ZodISODuration",(e,t)=>{$a.init(e,t),gu.init(e,t)});function Xc(e){return function(e,t){return new e({type:"string",format:"duration",check:"string_format",...Jo(t)})}(Yc,e)}const Qc=ko("ZodError",(e,t)=>{rs.init(e,t),e.name="ZodError",Object.defineProperties(e,{format:{value:t=>function(e,t=e=>e.message){const n={_errors:[]},r=e=>{for(const i of e.issues)if("invalid_union"===i.code&&i.errors.length)i.errors.map(e=>r({issues:e}));else if("invalid_key"===i.code)r({issues:i.issues});else if("invalid_element"===i.code)r({issues:i.issues});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(e),n}(e,t)},flatten:{value:t=>function(e,t=e=>e.message){const n={},r=[];for(const i of e.issues)i.path.length>0?(n[i.path[0]]=n[i.path[0]]||[],n[i.path[0]].push(t(i))):r.push(t(i));return{formErrors:r,fieldErrors:n}}(e,t)},addIssue:{value:t=>{e.issues.push(t),e.message=JSON.stringify(e.issues,Io,2)}},addIssues:{value:t=>{e.issues.push(...t),e.message=JSON.stringify(e.issues,Io,2)}},isEmpty:{get:()=>0===e.issues.length}})},{Parent:Error}),eu=os(Qc),tu=ss(Qc),nu=as(Qc),ru=us(Qc),iu=ds(Qc),ou=ls(Qc),su=ps(Qc),au=hs(Qc),cu=ms(Qc),uu=gs(Qc),fu=ys(Qc),du=_s(Qc),lu=ko("ZodType",(e,t)=>(da.init(e,t),Object.assign(e["~standard"],{jsonSchema:{input:Dc(e,"input"),output:Dc(e,"output")}}),e.toJSONSchema=((e,t={})=>n=>{const r=jc({...n,processors:t});return Zc(e,r),Cc(r,e),Fc(r,e)})(e,{}),e.def=t,e.type=t.type,Object.defineProperty(e,"_def",{value:t}),e.check=(...n)=>e.clone(Zo(t,{checks:[...t.checks??[],...n.map(e=>"function"==typeof e?{_zod:{check:e,def:{check:"custom"},onattach:[]}}:e)]}),{parent:!0}),e.with=e.check,e.clone=(t,n)=>Ko(e,t,n),e.brand=()=>e,e.register=(t,n)=>(t.add(e,n),e),e.parse=(t,n)=>eu(e,t,n,{callee:e.parse}),e.safeParse=(t,n)=>nu(e,t,n),e.parseAsync=async(t,n)=>tu(e,t,n,{callee:e.parseAsync}),e.safeParseAsync=async(t,n)=>ru(e,t,n),e.spa=e.safeParseAsync,e.encode=(t,n)=>iu(e,t,n),e.decode=(t,n)=>ou(e,t,n),e.encodeAsync=async(t,n)=>su(e,t,n),e.decodeAsync=async(t,n)=>au(e,t,n),e.safeEncode=(t,n)=>cu(e,t,n),e.safeDecode=(t,n)=>uu(e,t,n),e.safeEncodeAsync=async(t,n)=>fu(e,t,n),e.safeDecodeAsync=async(t,n)=>du(e,t,n),e.refine=(t,n)=>e.check(function(e,t={}){return function(e,t,n){return new e({type:"custom",check:"custom",fn:t,...Jo(n)})}(_f,e,t)}(t,n)),e.superRefine=t=>e.check(Bc(t)),e.overwrite=t=>e.check(Uc(t)),e.optional=()=>sf(e),e.exactOptional=()=>new af({type:"optional",innerType:e}),e.nullable=()=>uf(e),e.nullish=()=>sf(uf(e)),e.nonoptional=t=>function(e,t){return new lf({type:"nonoptional",innerType:e,...Jo(t)})}(e,t),e.array=()=>Ju(e),e.or=t=>Xu([e,t]),e.and=t=>new Qu({type:"intersection",left:e,right:t}),e.transform=t=>mf(e,new rf({type:"transform",transform:t})),e.default=t=>{return n=t,new ff({type:"default",innerType:e,get defaultValue(){return"function"==typeof n?n():Vo(n)}});var n},e.prefault=t=>{return n=t,new df({type:"prefault",innerType:e,get defaultValue(){return"function"==typeof n?n():Vo(n)}});var n},e.catch=t=>{return new pf({type:"catch",innerType:e,catchValue:"function"==typeof(n=t)?n:()=>n});var n},e.pipe=t=>mf(e,t),e.readonly=()=>new gf({type:"readonly",innerType:e}),e.describe=t=>{const n=e.clone();return kc.add(n,{description:t}),n},Object.defineProperty(e,"description",{get:()=>kc.get(e)?.description,configurable:!0}),e.meta=(...t)=>{if(0===t.length)return kc.get(e);const n=e.clone();return kc.add(n,t[0]),n},e.isOptional=()=>e.safeParse(void 0).success,e.isNullable=()=>e.safeParse(null).success,e.apply=t=>t(e),e)),pu=ko("_ZodString",(e,t)=>{la.init(e,t),lu.init(e,t),e._zod.processJSONSchema=(t,n,r)=>((e,t,n)=>{const r=n;r.type="string";const{minimum:i,maximum:o,format:s,patterns:a,contentEncoding:c}=e._zod.bag;if("number"==typeof i&&(r.minLength=i),"number"==typeof o&&(r.maxLength=o),s&&(r.format=Lc[s]??s,""===r.format&&delete r.format,"time"===s&&delete r.format),c&&(r.contentEncoding=c),a&&a.size>0){const e=[...a];1===e.length?r.pattern=e[0].source:e.length>1&&(r.allOf=[...e.map(e=>({..."draft-07"===t.target||"draft-04"===t.target||"openapi-3.0"===t.target?{type:"string"}:{},pattern:e.source}))])}})(e,t,n);const n=e._zod.bag;e.format=n.format??null,e.minLength=n.minimum??null,e.maxLength=n.maximum??null,e.regex=(...t)=>e.check(function(e,t){return new na({check:"string_format",format:"regex",...Jo(t),pattern:e})}(...t)),e.includes=(...t)=>e.check(function(e,t){return new oa({check:"string_format",format:"includes",...Jo(t),includes:e})}(...t)),e.startsWith=(...t)=>e.check(function(e,t){return new sa({check:"string_format",format:"starts_with",...Jo(t),prefix:e})}(...t)),e.endsWith=(...t)=>e.check(function(e,t){return new aa({check:"string_format",format:"ends_with",...Jo(t),suffix:e})}(...t)),e.min=(...t)=>e.check(Nc(...t)),e.max=(...t)=>e.check(Tc(...t)),e.length=(...t)=>e.check(Rc(...t)),e.nonempty=(...t)=>e.check(Nc(1,...t)),e.lowercase=t=>e.check(function(e){return new ra({check:"string_format",format:"lowercase",...Jo(e)})}(t)),e.uppercase=t=>e.check(function(e){return new ia({check:"string_format",format:"uppercase",...Jo(e)})}(t)),e.trim=()=>e.check(Uc(e=>e.trim())),e.normalize=(...t)=>e.check(function(e){return Uc(t=>t.normalize(e))}(...t)),e.toLowerCase=()=>e.check(Uc(e=>e.toLowerCase())),e.toUpperCase=()=>e.check(Uc(e=>e.toUpperCase())),e.slugify=()=>e.check(Uc(e=>function(e){return e.toLowerCase().trim().replace(/[^\w\s-]/g,"").replace(/[\s_-]+/g,"-").replace(/^-+|-+$/g,"")}(e)))}),hu=ko("ZodString",(e,t)=>{la.init(e,t),pu.init(e,t),e.email=t=>e.check(function(e,t){return new e({type:"string",format:"email",check:"string_format",abort:!1,...Jo(t)})}(yu,t)),e.url=t=>e.check(function(e,t){return new e({type:"string",format:"url",check:"string_format",abort:!1,...Jo(t)})}(vu,t)),e.jwt=t=>e.check(function(e,t){return new e({type:"string",format:"jwt",check:"string_format",abort:!1,...Jo(t)})}(Uu,t)),e.emoji=t=>e.check(function(e,t){return new e({type:"string",format:"emoji",check:"string_format",abort:!1,...Jo(t)})}(bu,t)),e.guid=t=>e.check(zc(_u,t)),e.uuid=t=>e.check(function(e,t){return new e({type:"string",format:"uuid",check:"string_format",abort:!1,...Jo(t)})}(wu,t)),e.uuidv4=t=>e.check(function(e,t){return new e({type:"string",format:"uuid",check:"string_format",abort:!1,version:"v4",...Jo(t)})}(wu,t)),e.uuidv6=t=>e.check(function(e,t){return new e({type:"string",format:"uuid",check:"string_format",abort:!1,version:"v6",...Jo(t)})}(wu,t)),e.uuidv7=t=>e.check(function(e,t){return new e({type:"string",format:"uuid",check:"string_format",abort:!1,version:"v7",...Jo(t)})}(wu,t)),e.nanoid=t=>e.check(function(e,t){return new e({type:"string",format:"nanoid",check:"string_format",abort:!1,...Jo(t)})}(xu,t)),e.guid=t=>e.check(zc(_u,t)),e.cuid=t=>e.check(function(e,t){return new e({type:"string",format:"cuid",check:"string_format",abort:!1,...Jo(t)})}(Eu,t)),e.cuid2=t=>e.check(function(e,t){return new e({type:"string",format:"cuid2",check:"string_format",abort:!1,...Jo(t)})}(Ou,t)),e.ulid=t=>e.check(function(e,t){return new e({type:"string",format:"ulid",check:"string_format",abort:!1,...Jo(t)})}(ku,t)),e.base64=t=>e.check(function(e,t){return new e({type:"string",format:"base64",check:"string_format",abort:!1,...Jo(t)})}(Tu,t)),e.base64url=t=>e.check(function(e,t){return new e({type:"string",format:"base64url",check:"string_format",abort:!1,...Jo(t)})}(Nu,t)),e.xid=t=>e.check(function(e,t){return new e({type:"string",format:"xid",check:"string_format",abort:!1,...Jo(t)})}(zu,t)),e.ksuid=t=>e.check(function(e,t){return new e({type:"string",format:"ksuid",check:"string_format",abort:!1,...Jo(t)})}(Su,t)),e.ipv4=t=>e.check(function(e,t){return new e({type:"string",format:"ipv4",check:"string_format",abort:!1,...Jo(t)})}($u,t)),e.ipv6=t=>e.check(function(e,t){return new e({type:"string",format:"ipv6",check:"string_format",abort:!1,...Jo(t)})}(Pu,t)),e.cidrv4=t=>e.check(function(e,t){return new e({type:"string",format:"cidrv4",check:"string_format",abort:!1,...Jo(t)})}(Au,t)),e.cidrv6=t=>e.check(function(e,t){return new e({type:"string",format:"cidrv6",check:"string_format",abort:!1,...Jo(t)})}(Iu,t)),e.e164=t=>e.check(function(e,t){return new e({type:"string",format:"e164",check:"string_format",abort:!1,...Jo(t)})}(Ru,t)),e.datetime=t=>e.check(Mc(t)),e.date=t=>e.check(Jc(t)),e.time=t=>e.check(Wc(t)),e.duration=t=>e.check(Xc(t))});function mu(e){return function(e,t){return new e({type:"string",...Jo(t)})}(hu,e)}const gu=ko("ZodStringFormat",(e,t)=>{pa.init(e,t),pu.init(e,t)}),yu=ko("ZodEmail",(e,t)=>{ga.init(e,t),gu.init(e,t)}),_u=ko("ZodGUID",(e,t)=>{ha.init(e,t),gu.init(e,t)}),wu=ko("ZodUUID",(e,t)=>{ma.init(e,t),gu.init(e,t)}),vu=ko("ZodURL",(e,t)=>{ya.init(e,t),gu.init(e,t)}),bu=ko("ZodEmoji",(e,t)=>{_a.init(e,t),gu.init(e,t)}),xu=ko("ZodNanoID",(e,t)=>{wa.init(e,t),gu.init(e,t)}),Eu=ko("ZodCUID",(e,t)=>{va.init(e,t),gu.init(e,t)}),Ou=ko("ZodCUID2",(e,t)=>{ba.init(e,t),gu.init(e,t)}),ku=ko("ZodULID",(e,t)=>{xa.init(e,t),gu.init(e,t)}),zu=ko("ZodXID",(e,t)=>{Ea.init(e,t),gu.init(e,t)}),Su=ko("ZodKSUID",(e,t)=>{Oa.init(e,t),gu.init(e,t)}),$u=ko("ZodIPv4",(e,t)=>{Pa.init(e,t),gu.init(e,t)}),Pu=ko("ZodIPv6",(e,t)=>{Aa.init(e,t),gu.init(e,t)}),Au=ko("ZodCIDRv4",(e,t)=>{Ia.init(e,t),gu.init(e,t)}),Iu=ko("ZodCIDRv6",(e,t)=>{Ta.init(e,t),gu.init(e,t)}),Tu=ko("ZodBase64",(e,t)=>{Ra.init(e,t),gu.init(e,t)}),Nu=ko("ZodBase64URL",(e,t)=>{Ua.init(e,t),gu.init(e,t)}),Ru=ko("ZodE164",(e,t)=>{Ba.init(e,t),gu.init(e,t)}),Uu=ko("ZodJWT",(e,t)=>{ja.init(e,t),gu.init(e,t)}),Bu=ko("ZodNumber",(e,t)=>{Za.init(e,t),lu.init(e,t),e._zod.processJSONSchema=(t,n,r)=>((e,t,n)=>{const r=n,{minimum:i,maximum:o,format:s,multipleOf:a,exclusiveMaximum:c,exclusiveMinimum:u}=e._zod.bag;"string"==typeof s&&s.includes("int")?r.type="integer":r.type="number","number"==typeof u&&("draft-04"===t.target||"openapi-3.0"===t.target?(r.minimum=u,r.exclusiveMinimum=!0):r.exclusiveMinimum=u),"number"==typeof i&&(r.minimum=i,"number"==typeof u&&"draft-04"!==t.target&&(u>=i?delete r.minimum:delete r.exclusiveMinimum)),"number"==typeof c&&("draft-04"===t.target||"openapi-3.0"===t.target?(r.maximum=c,r.exclusiveMaximum=!0):r.exclusiveMaximum=c),"number"==typeof o&&(r.maximum=o,"number"==typeof c&&"draft-04"!==t.target&&(c<=o?delete r.maximum:delete r.exclusiveMaximum)),"number"==typeof a&&(r.multipleOf=a)})(e,t,n),e.gt=(t,n)=>e.check(Pc(t,n)),e.gte=(t,n)=>e.check(Ac(t,n)),e.min=(t,n)=>e.check(Ac(t,n)),e.lt=(t,n)=>e.check(Sc(t,n)),e.lte=(t,n)=>e.check($c(t,n)),e.max=(t,n)=>e.check($c(t,n)),e.int=t=>e.check(Cu(t)),e.safe=t=>e.check(Cu(t)),e.positive=t=>e.check(Pc(0,t)),e.nonnegative=t=>e.check(Ac(0,t)),e.negative=t=>e.check(Sc(0,t)),e.nonpositive=t=>e.check($c(0,t)),e.multipleOf=(t,n)=>e.check(Ic(t,n)),e.step=(t,n)=>e.check(Ic(t,n)),e.finite=()=>e;const n=e._zod.bag;e.minValue=Math.max(n.minimum??Number.NEGATIVE_INFINITY,n.exclusiveMinimum??Number.NEGATIVE_INFINITY)??null,e.maxValue=Math.min(n.maximum??Number.POSITIVE_INFINITY,n.exclusiveMaximum??Number.POSITIVE_INFINITY)??null,e.isInt=(n.format??"").includes("int")||Number.isSafeInteger(n.multipleOf??.5),e.isFinite=!0,e.format=n.format??null});function ju(e){return function(e,t){return new e({type:"number",checks:[],...Jo(t)})}(Bu,e)}const Zu=ko("ZodNumberFormat",(e,t)=>{Ca.init(e,t),Bu.init(e,t)});function Cu(e){return function(e,t){return new e({type:"number",check:"number_format",abort:!1,format:"safeint",...Jo(t)})}(Zu,e)}const Fu=ko("ZodBoolean",(e,t)=>{Fa.init(e,t),lu.init(e,t),e._zod.processJSONSchema=(e,t,n)=>((e,t,n)=>{n.type="boolean"})(0,0,t)});const Hu=ko("ZodBigInt",(e,t)=>{Ha.init(e,t),lu.init(e,t),e._zod.processJSONSchema=(e,t,n)=>((e,t)=>{if("throw"===t.unrepresentable)throw new Error("BigInt cannot be represented in JSON Schema")})(0,e),e.gte=(t,n)=>e.check(Ac(t,n)),e.min=(t,n)=>e.check(Ac(t,n)),e.gt=(t,n)=>e.check(Pc(t,n)),e.gte=(t,n)=>e.check(Ac(t,n)),e.min=(t,n)=>e.check(Ac(t,n)),e.lt=(t,n)=>e.check(Sc(t,n)),e.lte=(t,n)=>e.check($c(t,n)),e.max=(t,n)=>e.check($c(t,n)),e.positive=t=>e.check(Pc(BigInt(0),t)),e.negative=t=>e.check(Sc(BigInt(0),t)),e.nonpositive=t=>e.check($c(BigInt(0),t)),e.nonnegative=t=>e.check(Ac(BigInt(0),t)),e.multipleOf=(t,n)=>e.check(Ic(t,n));const n=e._zod.bag;e.minValue=n.minimum??null,e.maxValue=n.maximum??null,e.format=n.format??null});const Du=ko("ZodNull",(e,t)=>{Da.init(e,t),lu.init(e,t),e._zod.processJSONSchema=(e,t,n)=>((e,t,n)=>{"openapi-3.0"===t.target?(n.type="string",n.nullable=!0,n.enum=[null]):n.type="null"})(0,e,t)});const Lu=ko("ZodUnknown",(e,t)=>{La.init(e,t),lu.init(e,t),e._zod.processJSONSchema=(e,t,n)=>{}});function Vu(){return new Lu({type:"unknown"})}const qu=ko("ZodNever",(e,t)=>{Va.init(e,t),lu.init(e,t),e._zod.processJSONSchema=(e,t,n)=>((e,t,n)=>{n.not={}})(0,0,t)});function Mu(e){return function(e,t){return new e({type:"never",...Jo(t)})}(qu,e)}const Ku=ko("ZodArray",(e,t)=>{Ma.init(e,t),lu.init(e,t),e._zod.processJSONSchema=(t,n,r)=>((e,t,n,r)=>{const i=n,o=e._zod.def,{minimum:s,maximum:a}=e._zod.bag;"number"==typeof s&&(i.minItems=s),"number"==typeof a&&(i.maxItems=a),i.type="array",i.items=Zc(o.element,t,{...r,path:[...r.path,"items"]})})(e,t,n,r),e.element=t.element,e.min=(t,n)=>e.check(Nc(t,n)),e.nonempty=t=>e.check(Nc(1,t)),e.max=(t,n)=>e.check(Tc(t,n)),e.length=(t,n)=>e.check(Rc(t,n)),e.unwrap=()=>e.element});function Ju(e,t){return function(e,t,n){return new e({type:"array",element:t,...Jo(n)})}(Ku,e,t)}const Gu=ko("ZodObject",(e,t)=>{Ya.init(e,t),lu.init(e,t),e._zod.processJSONSchema=(t,n,r)=>((e,t,n,r)=>{const i=n,o=e._zod.def;i.type="object",i.properties={};const s=o.shape;for(const e in s)i.properties[e]=Zc(s[e],t,{...r,path:[...r.path,"properties",e]});const a=new Set(Object.keys(s)),c=new Set([...a].filter(e=>{const n=o.shape[e]._zod;return"input"===t.io?void 0===n.optin:void 0===n.optout}));c.size>0&&(i.required=Array.from(c)),"never"===o.catchall?._zod.def.type?i.additionalProperties=!1:o.catchall?o.catchall&&(i.additionalProperties=Zc(o.catchall,t,{...r,path:[...r.path,"additionalProperties"]})):"output"===t.io&&(i.additionalProperties=!1)})(e,t,n,r),Bo(e,"shape",()=>t.shape),e.keyof=()=>function(e,t){const n=Array.isArray(e)?Object.fromEntries(e.map(e=>[e,e])):e;return new nf({type:"enum",entries:n,...Jo(t)})}(Object.keys(e._zod.def.shape)),e.catchall=t=>e.clone({...e._zod.def,catchall:t}),e.passthrough=()=>e.clone({...e._zod.def,catchall:Vu()}),e.loose=()=>e.clone({...e._zod.def,catchall:Vu()}),e.strict=()=>e.clone({...e._zod.def,catchall:Mu()}),e.strip=()=>e.clone({...e._zod.def,catchall:void 0}),e.extend=t=>function(e,t){if(!Lo(t))throw new Error("Invalid input to extend: expected a plain object");const n=e._zod.def.checks;if(n&&n.length>0){const n=e._zod.def.shape;for(const e in t)if(void 0!==Object.getOwnPropertyDescriptor(n,e))throw new Error("Cannot overwrite keys on object schemas containing refinements. Use `.safeExtend()` instead.")}const r=Zo(e._zod.def,{get shape(){const n={...e._zod.def.shape,...t};return jo(this,"shape",n),n}});return Ko(e,r)}(e,t),e.safeExtend=t=>function(e,t){if(!Lo(t))throw new Error("Invalid input to safeExtend: expected a plain object");const n=Zo(e._zod.def,{get shape(){const n={...e._zod.def.shape,...t};return jo(this,"shape",n),n}});return Ko(e,n)}(e,t),e.merge=t=>function(e,t){const n=Zo(e._zod.def,{get shape(){const n={...e._zod.def.shape,...t._zod.def.shape};return jo(this,"shape",n),n},get catchall(){return t._zod.def.catchall},checks:[]});return Ko(e,n)}(e,t),e.pick=t=>function(e,t){const n=e._zod.def,r=n.checks;if(r&&r.length>0)throw new Error(".pick() cannot be used on object schemas containing refinements");return Ko(e,Zo(e._zod.def,{get shape(){const e={};for(const r in t){if(!(r in n.shape))throw new Error(`Unrecognized key: "${r}"`);t[r]&&(e[r]=n.shape[r])}return jo(this,"shape",e),e},checks:[]}))}(e,t),e.omit=t=>function(e,t){const n=e._zod.def,r=n.checks;if(r&&r.length>0)throw new Error(".omit() cannot be used on object schemas containing refinements");const i=Zo(e._zod.def,{get shape(){const r={...e._zod.def.shape};for(const e in t){if(!(e in n.shape))throw new Error(`Unrecognized key: "${e}"`);t[e]&&delete r[e]}return jo(this,"shape",r),r},checks:[]});return Ko(e,i)}(e,t),e.partial=(...t)=>function(e,t,n){const r=t._zod.def.checks;if(r&&r.length>0)throw new Error(".partial() cannot be used on object schemas containing refinements");const i=Zo(t._zod.def,{get shape(){const r=t._zod.def.shape,i={...r};if(n)for(const t in n){if(!(t in r))throw new Error(`Unrecognized key: "${t}"`);n[t]&&(i[t]=e?new e({type:"optional",innerType:r[t]}):r[t])}else for(const t in r)i[t]=e?new e({type:"optional",innerType:r[t]}):r[t];return jo(this,"shape",i),i},checks:[]});return Ko(t,i)}(of,e,t[0]),e.required=(...t)=>function(e,t,n){const r=Zo(t._zod.def,{get shape(){const r=t._zod.def.shape,i={...r};if(n)for(const t in n){if(!(t in i))throw new Error(`Unrecognized key: "${t}"`);n[t]&&(i[t]=new e({type:"nonoptional",innerType:r[t]}))}else for(const t in r)i[t]=new e({type:"nonoptional",innerType:r[t]});return jo(this,"shape",i),i}});return Ko(t,r)}(lf,e,t[0])});function Wu(e,t){const n={type:"object",shape:e??{},...Jo(t)};return new Gu(n)}const Yu=ko("ZodUnion",(e,t)=>{Qa.init(e,t),lu.init(e,t),e._zod.processJSONSchema=(t,n,r)=>((e,t,n,r)=>{const i=e._zod.def,o=!1===i.inclusive,s=i.options.map((e,n)=>Zc(e,t,{...r,path:[...r.path,o?"oneOf":"anyOf",n]}));o?n.oneOf=s:n.anyOf=s})(e,t,n,r),e.options=t.options});function Xu(e,t){return new Yu({type:"union",options:e,...Jo(t)})}const Qu=ko("ZodIntersection",(e,t)=>{ec.init(e,t),lu.init(e,t),e._zod.processJSONSchema=(t,n,r)=>((e,t,n,r)=>{const i=e._zod.def,o=Zc(i.left,t,{...r,path:[...r.path,"allOf",0]}),s=Zc(i.right,t,{...r,path:[...r.path,"allOf",1]}),a=e=>"allOf"in e&&1===Object.keys(e).length,c=[...a(o)?o.allOf:[o],...a(s)?s.allOf:[s]];n.allOf=c})(e,t,n,r)});const ef=ko("ZodRecord",(e,t)=>{rc.init(e,t),lu.init(e,t),e._zod.processJSONSchema=(t,n,r)=>((e,t,n,r)=>{const i=n,o=e._zod.def;i.type="object";const s=o.keyType,a=s._zod.bag,c=a?.patterns;if("loose"===o.mode&&c&&c.size>0){const e=Zc(o.valueType,t,{...r,path:[...r.path,"patternProperties","*"]});i.patternProperties={};for(const t of c)i.patternProperties[t.source]=e}else"draft-07"!==t.target&&"draft-2020-12"!==t.target||(i.propertyNames=Zc(o.keyType,t,{...r,path:[...r.path,"propertyNames"]})),i.additionalProperties=Zc(o.valueType,t,{...r,path:[...r.path,"additionalProperties"]});const u=s._zod.values;if(u){const e=[...u].filter(e=>"string"==typeof e||"number"==typeof e);e.length>0&&(i.required=e)}})(e,t,n,r),e.keyType=t.keyType,e.valueType=t.valueType});function tf(e,t,n){return new ef({type:"record",keyType:e,valueType:t,...Jo(n)})}const nf=ko("ZodEnum",(e,t)=>{ic.init(e,t),lu.init(e,t),e._zod.processJSONSchema=(t,n,r)=>((e,t,n)=>{const r=Ao(e._zod.def.entries);r.every(e=>"number"==typeof e)&&(n.type="number"),r.every(e=>"string"==typeof e)&&(n.type="string"),n.enum=r})(e,0,n),e.enum=t.entries,e.options=Object.values(t.entries);const n=new Set(Object.keys(t.entries));e.extract=(e,r)=>{const i={};for(const r of e){if(!n.has(r))throw new Error(`Key ${r} not found in enum`);i[r]=t.entries[r]}return new nf({...t,checks:[],...Jo(r),entries:i})},e.exclude=(e,r)=>{const i={...t.entries};for(const t of e){if(!n.has(t))throw new Error(`Key ${t} not found in enum`);delete i[t]}return new nf({...t,checks:[],...Jo(r),entries:i})}});const rf=ko("ZodTransform",(e,t)=>{oc.init(e,t),lu.init(e,t),e._zod.processJSONSchema=(e,t,n)=>((e,t)=>{if("throw"===t.unrepresentable)throw new Error("Transforms cannot be represented in JSON Schema")})(0,e),e._zod.parse=(n,r)=>{if("backward"===r.direction)throw new So(e.constructor.name);n.addIssue=r=>{if("string"==typeof r)n.issues.push(ts(r,n.value,t));else{const t=r;t.fatal&&(t.continue=!1),t.code??(t.code="custom"),t.input??(t.input=n.value),t.inst??(t.inst=e),n.issues.push(ts(t))}};const i=t.transform(n.value,n);return i instanceof Promise?i.then(e=>(n.value=e,n)):(n.value=i,n)}});const of=ko("ZodOptional",(e,t)=>{ac.init(e,t),lu.init(e,t),e._zod.processJSONSchema=(t,n,r)=>Vc(e,t,0,r),e.unwrap=()=>e._zod.def.innerType});function sf(e){return new of({type:"optional",innerType:e})}const af=ko("ZodExactOptional",(e,t)=>{cc.init(e,t),lu.init(e,t),e._zod.processJSONSchema=(t,n,r)=>Vc(e,t,0,r),e.unwrap=()=>e._zod.def.innerType});const cf=ko("ZodNullable",(e,t)=>{uc.init(e,t),lu.init(e,t),e._zod.processJSONSchema=(t,n,r)=>((e,t,n,r)=>{const i=e._zod.def,o=Zc(i.innerType,t,r),s=t.seen.get(e);"openapi-3.0"===t.target?(s.ref=i.innerType,n.nullable=!0):n.anyOf=[o,{type:"null"}]})(e,t,n,r),e.unwrap=()=>e._zod.def.innerType});function uf(e){return new cf({type:"nullable",innerType:e})}const ff=ko("ZodDefault",(e,t)=>{fc.init(e,t),lu.init(e,t),e._zod.processJSONSchema=(t,n,r)=>((e,t,n,r)=>{const i=e._zod.def;Zc(i.innerType,t,r),t.seen.get(e).ref=i.innerType,n.default=JSON.parse(JSON.stringify(i.defaultValue))})(e,t,n,r),e.unwrap=()=>e._zod.def.innerType,e.removeDefault=e.unwrap});const df=ko("ZodPrefault",(e,t)=>{lc.init(e,t),lu.init(e,t),e._zod.processJSONSchema=(t,n,r)=>((e,t,n,r)=>{const i=e._zod.def;Zc(i.innerType,t,r),t.seen.get(e).ref=i.innerType,"input"===t.io&&(n._prefault=JSON.parse(JSON.stringify(i.defaultValue)))})(e,t,n,r),e.unwrap=()=>e._zod.def.innerType});const lf=ko("ZodNonOptional",(e,t)=>{pc.init(e,t),lu.init(e,t),e._zod.processJSONSchema=(t,n,r)=>((e,t,n,r)=>{const i=e._zod.def;Zc(i.innerType,t,r),t.seen.get(e).ref=i.innerType})(e,t,0,r),e.unwrap=()=>e._zod.def.innerType});const pf=ko("ZodCatch",(e,t)=>{mc.init(e,t),lu.init(e,t),e._zod.processJSONSchema=(t,n,r)=>((e,t,n,r)=>{const i=e._zod.def;let o;Zc(i.innerType,t,r),t.seen.get(e).ref=i.innerType;try{o=i.catchValue(void 0)}catch{throw new Error("Dynamic catch values are not supported in JSON Schema")}n.default=o})(e,t,n,r),e.unwrap=()=>e._zod.def.innerType,e.removeCatch=e.unwrap});const hf=ko("ZodPipe",(e,t)=>{gc.init(e,t),lu.init(e,t),e._zod.processJSONSchema=(t,n,r)=>((e,t,n,r)=>{const i=e._zod.def,o="input"===t.io?"transform"===i.in._zod.def.type?i.out:i.in:i.out;Zc(o,t,r),t.seen.get(e).ref=o})(e,t,0,r),e.in=t.in,e.out=t.out});function mf(e,t){return new hf({type:"pipe",in:e,out:t})}const gf=ko("ZodReadonly",(e,t)=>{_c.init(e,t),lu.init(e,t),e._zod.processJSONSchema=(t,n,r)=>((e,t,n,r)=>{const i=e._zod.def;Zc(i.innerType,t,r),t.seen.get(e).ref=i.innerType,n.readOnly=!0})(e,t,n,r),e.unwrap=()=>e._zod.def.innerType});const yf=ko("ZodLazy",(e,t)=>{vc.init(e,t),lu.init(e,t),e._zod.processJSONSchema=(t,n,r)=>((e,t,n,r)=>{const i=e._zod.innerType;Zc(i,t,r),t.seen.get(e).ref=i})(e,t,0,r),e.unwrap=()=>e._zod.def.getter()});const _f=ko("ZodCustom",(e,t)=>{bc.init(e,t),lu.init(e,t),e._zod.processJSONSchema=(e,t,n)=>((e,t)=>{if("throw"===t.unrepresentable)throw new Error("Custom types cannot be represented in JSON Schema")})(0,e)});const wf=ju().min(Number.MIN_SAFE_INTEGER).max(Number.MAX_SAFE_INTEGER).int(),vf=function(e,t={}){const n=new _f({type:"custom",check:"custom",fn:t=>t instanceof e,abort:!0,...Jo(t)});return n._zod.bag.Class=e,n._zod.check=t=>{t.value instanceof e||t.issues.push({code:"invalid_type",expected:e.name,input:t.value,inst:n,path:[...n._zod.def.path??[]]})},n}(Uint8Array),bf=mu();wf.min(5e8),wf.min(0).max(255),wf.min(0).max(65535);const xf=wf.min(0).max(4294967295);ju().refine(e=>String(e).includes(".")).refine(e=>{const t=String(e).split(".").at(1);return void 0!==t&&t.length<=2});const Ef=mu().regex(/^[0-9a-fA-F]*$/).refine(e=>e.length%2==0),Of=Xu([mu(),ju(),function(e,t){return new e({type:"boolean",...Jo(t)})}(Fu,kf),function(e){return function(e,t){return new e({type:"null",...Jo(t)})}(Du,e)}()]);var kf;const zf=new yf({type:"lazy",getter:()=>Xu([Of,Ju(zf),tf(bf,zf)])});vf.refine(e=>20===e.length);const Sf=vf.refine(e=>32===e.length),$f=vf.refine(e=>33===e.length),Pf=vf.refine(e=>64===e.length);Ef.refine(e=>40===e.length);const Af=Ef.refine(e=>64===e.length),If=Ef.refine(e=>66===e.length),Tf=Ef.refine(e=>128===e.length);Xu([Ef,vf]);const Nf=Xu([Af,Sf]);Xu([If,$f]),Xu([Tf,Pf]),mu().regex(/^[1-9A-HJ-NP-Za-km-z]+$/),mu().regex(/^[a-zA-Z0-9+/]+={0,2}$/),mu().regex(/^[a-zA-Z0-9\-_]+={0,2}$/),mu().regex(/^[a-z]+1[023456789acdefghjklmnpqrstuvwxyz]+$/);const Rf=Xu([Ju(Nf),Nf]),Uf=Wu({pubkey:Nf,leaves:Rf.array().optional(),target:Nf.optional(),version:xf.optional()});var Bf=Object.freeze({__proto__:null,config:Uf,taptree:Rf});const jf=function(e){return function(e,t){return new e({type:"bigint",...Jo(t)})}(Hu,e)}().min(0n).max(2100000000000000n),Zf=Wu({value:jf,script_pk:Ef}),Cf=Wu({coinbase:Ef.nullable(),txid:Af,vout:xf,prevout:Zf.nullable(),script_sig:Ef.nullable(),sequence:xf,witness:Ju(Ef)}),Ff=Wu({version:xf,vin:Ju(Cf),vout:Ju(Zf),locktime:xf}),Hf=Zf.extend({value:Xu([xf,jf])}),Df=Cf.extend({coinbase:Ef.nullable().optional(),prevout:Hf.nullable().optional(),script_sig:Ef.nullable().optional(),sequence:Xu([Ef,xf]).optional(),witness:Ju(Ef).optional()}),Lf=Wu({version:xf.optional(),vin:Ju(Df),vout:Ju(Hf),locktime:xf.optional()});var Vf=Object.freeze({__proto__:null,tx_data:Ff,tx_input:Cf,tx_output:Zf,tx_template:Lf,vin_template:Df,vout_template:Hf}),qf=Object.freeze({__proto__:null,taproot:Bf,tx:Vf});function Mf(e){const t=e.issues.map(e=>`${e.path.length>0?`${e.path.join(".")}: `:""}${e.message}`);return t.join("; ")}function Kf(e){const t=Lf.safeParse(e);if(!t.success)throw new R(`invalid transaction template: ${Mf(t.error)}`)}function Jf(e){const t=e.findIndex(e=>null===e.prevout||void 0===e.prevout);if(-1!==t)throw new R(`transaction input at index ${t} is missing prevout data. Prevout (previous output) is required for signing`)}function Gf(e){const t=Ff.safeParse(e);if(!t.success)throw new R(`invalid transaction data: ${Mf(t.error)}`)}function Wf(e){const t=Df.safeParse(e);if(!t.success)throw new R(`invalid input template: ${Mf(t.error)}`)}function Yf(e){const t=Hf.safeParse(e);if(!t.success)throw new R(`invalid output template: ${Mf(t.error)}`)}function Xf(e,t=!0){Gf(e);const{version:n,vin:r,vout:i,locktime:o}=e,s=[Qf(n)];if(t&&s.push(T.hex("0001")),s.push(rd(r)),s.push(sd(i)),t)for(const e of r)s.push(cd(e.witness));return s.push(ud(o)),T.join(s)}function Qf(e){return T.num(e,4).reverse()}function ed(e){return T.hex(e,32).reverse()}function td(e){return T.num(e,4).reverse()}function nd(e){return T.num(e,4).reverse()}function rd(e){const t=[T.create_varint(e.length,"le")];for(const n of e)t.push(id(n));return T.join(t)}function id(e){return null!==e.coinbase?T.join([ed(t.TXID),td(t.VOUT),fd(e.coinbase),nd(e.sequence)]):T.join([ed(e.txid),td(e.vout),fd(e.script_sig),nd(e.sequence)])}function od(e){return T.big(e,8).reverse()}function sd(e){const t=[T.create_varint(e.length,"le")];for(const n of e)t.push(ad(n));return T.join(t)}function ad(e){const{value:t,script_pk:n}=e;return T.join([od(t),fd(n)])}function cd(e){const t=[T.create_varint(e.length)];for(const n of e)t.push(fd(n));return T.join(t)}function ud(e){return T.num(e,4).reverse()}function fd(e){return null!==e?(M.is_hex(e),T.hex(e).prefix_varint("le")):T.hex("00")}function dd(e,t){let n;if("string"==typeof e||e instanceof Uint8Array?n=vo(e):(Kf(e),n=bd(e)),t){M.has_items(t,"prevouts must be a non-empty array");for(const[e,r]of n.vin.entries()){const n=t.at(e);M.exists(n,`prevout not found for input index: ${e}`),r.prevout=vd(n)}}return n}function ld(e,t=!0){return Xf(vo(e),t)}function pd(e){if(!q.exists(e))return n.SEQUENCE;if(q.is_hex(e))return T.hex(e,4).reverse().num;if(q.is_uint(e))return e;throw new Error(`invalid sequence value: ${String(e)}`)}function hd(e){if(q.is_uint(e))return BigInt(e);if("bigint"==typeof e)return e;throw new TypeError(`invalid output value: ${String(e)}`)}function md(e){return{script_pk:e.script_pk,value:hd(e.value)}}function gd(e){Wf(e),M.exists(e.coinbase,"coinbase is required");const n=t.TXID,r=t.VOUT,i=e.coinbase,o=e.witness??[];return{coinbase:i,prevout:null,script_sig:null,sequence:pd(e.sequence),witness:o,txid:n,vout:r}}function yd(e){Wf(e),M.is_empty(e.coinbase,"coinbase is not allowed"),M.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:pd(e.sequence),witness:i}}function _d(e){Wf(e),M.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:md(e.prevout),script_sig:r,sequence:pd(e.sequence),witness:i}}function wd(e){return e.coinbase?gd(e):e.prevout?_d(e):yd(e)}function vd(e){Yf(e);return{script_pk:e.script_pk,value:hd(e.value)}}function bd(e){Kf(e);const{vin:t=[],vout:r=[]}=e??{vin:[],vout:[]},i=e.locktime??n.LOCKTIME,o=e.version??n.VERSION;return{locktime:i,vin:t.map(e=>wd(e)),vout:r.map(e=>vd(e)),version:o}}var xd=Object.freeze({__proto__:null,assert_has_prevouts:Jf,assert_tx_data:Gf,assert_tx_input:function(e){const t=Cf.safeParse(e);if(!t.success)throw new R(`invalid transaction input: ${Mf(t.error)}`)},assert_tx_output:function(e){const t=Zf.safeParse(e);if(!t.success)throw new R(`invalid transaction output: ${Mf(t.error)}`)},assert_tx_spend_data:function(e){Gf(e),Jf(e.vin)},assert_tx_template:Kf,assert_vin_template:Wf,assert_vout_template:Yf,create_coinbase_input:gd,create_spend_input:_d,create_tx:bd,create_tx_input:wd,create_tx_output:vd,create_virtual_input:yd,decode_tx:vo,encode_script_data:fd,encode_tx:Xf,encode_tx_inputs:rd,encode_tx_locktime:ud,encode_tx_outputs:sd,encode_tx_version:Qf,encode_tx_vout:ad,encode_txin_sequence:nd,encode_txin_txid:ed,encode_txin_vout:td,encode_vin:id,encode_vin_witness:cd,encode_vout_value:od,get_prevouts:function(e){Kf(e);const t=e.vin.map(e=>e.prevout);return M.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+cd(t).length,0)},get_tx_value:function(e){const t=dd(e);Kf(t);const n=t.vin.reduce((e,t)=>e+(t.prevout?.value??0n),0n),r=t.vout.reduce((e,t)=>e+t.value,0n);return{fees:n>r?n-r:0n,vin:n,vout:r}},get_txhash:function(e){return"object"==typeof e&&(Kf(e),e=Xf(e,!0)),qe(e).reverse().hex},get_txid:function(e){let t;if(e instanceof Uint8Array)t=ld(e,!1);else if("object"==typeof e)Kf(e),t=Xf(e,!1);else{if("string"!=typeof e)throw new TypeError("invalid txdata type: "+typeof e);M.is_hex(e),t=ld(e,!1)}return qe(t).reverse().hex},get_txin_size:function(e){return id(e).length},get_txout_size:function(e){return ad(e).length},get_txsize:function(e){const t=dd(e),n=Xf(t,!1).length,r=Xf(t,!0).length,i=3*n+r;return{base:n,total:r,vsize:Math.ceil(i/4),weight:i}},get_vin_size:function(e){return rd(e).length},get_vout_size:function(e){return sd(e).length},get_vsize:function(e){const t=T.bytes(e).length;return Math.ceil(t/4)},normalize_prevout:md,normalize_sequence:pd,normalize_value:hd,parse_tx:dd,read_payload:Oo,serialize_tx:function(e){const t=dd(e),n=t.version,r=t.locktime,i=[],o=[];for(const e of t.vin)null!==e.prevout&&i.push({script_pk:e.prevout.script_pk,value:String(e.prevout.value)});for(const e of t.vout)o.push({script_pk:e.script_pk,value:String(e.value)});return{version:n,locktime:r,vin:i,vout:o}},transcode_tx:ld});function Ed(e){return M.exists(e.prevout,`Prevout data missing for input: ${String(e.txid)}`),e.prevout}function Od(e,t){let{txindex:n,txinput:r}=t??{};if(void 0!==n){if(n>=e.vin.length)throw new R(`input index ${n} out of bounds. Transaction has ${e.vin.length} inputs (indices 0-${e.vin.length-1})`);r=e.vin.at(n)}return M.ok(void 0!==r),r}function kd(e){if(void 0===e)return;if(e.length<2)return;const t=e.at(-1);if("string"==typeof t&&t.startsWith("50")){return Ve(T.hex(t).prefix_varint("be"))}}function zd(e,t={}){const{sigflag:n=1,txindex:r}=t,i=dd(e),o=!(128&~n),a=n%128;if(!s.includes(a))throw new R(`invalid sighash type: 0x${n.toString(16)}. Valid values: SIGHASH_ALL (0x01), SIGHASH_NONE (0x02), SIGHASH_SINGLE (0x03), or combined with ANYONECANPAY (0x81, 0x82, 0x83)`);const{version:c,vin:u,vout:f,locktime:d}=i,l=Od(i,t),{txid:p,vout:h,prevout:m,sequence:g}=l,{value:y}=m??{};if(void 0===y)throw new R("Prevout value is required for segwit sighash calculation","prevout.value");let{pubkey:_,script:w}=t;if(void 0===w&&void 0!==_){const e=Le(_).hex;w=`76a914${String(e)}88ac`}if(void 0===w)throw new R("Either pubkey or script must be provided for segwit sighash","pubkey/script");if(ji(w).includes("OP_CODESEPARATOR"))throw new R("OP_CODESEPARATOR is not supported in segwit scripts","script");const v=[Qf(c),Sd(u,o),$d(u,a,o),ed(p),td(h),go(w),od(y),nd(g),Pd(f,a,r),ud(d),T.num(n,4).reverse()];return qe(T.join(v))}function Sd(e,t){if(!0===t)return T.num(0,32);const n=[];for(const{txid:t,vout:r}of e)n.push(ed(t)),n.push(td(r));return qe(T.join(n))}function $d(e,t,n){if(n||1!==t)return T.num(0,32);const r=[];for(const{sequence:t}of e)r.push(nd(t));return qe(T.join(r))}function Pd(e,t,n){const r=[];if(1===t){for(const{value:t,script_pk:n}of e)r.push(od(t)),r.push(go(n));return qe(T.join(r))}if(3===t&&(M.ok(void 0!==n,"txindex required for SIGHASH_SINGLE"),M.ok(n>=0,"txindex must be non-negative"),n<e.length)){const{value:t,script_pk:i}=e[n];return r.push(od(t)),r.push(go(i)),qe(T.join(r))}return T.num(0,32)}function Ad(e,t=192){return Id(go(e),t)}function Id(e,t=192){return Me("TapLeaf",Nd(t),e)}function Td(e,t){return t<e&&([e,t]=[t,e]),Me("TapBranch",e,t)}function Nd(e=192){return 254&e}function Rd(e,t=new Uint8Array){return M.ok(32===T.bytes(e).length,"pubkey must be 32 bytes"),Me("TapTweak",e,t)}function Ud(e,t={}){return Me("TapSighash",Bd(e,t))}function Bd(e,t={}){const{script:n,txindex:r,sigflag:i=0,extflag:o=0,key_version:s=0,separator_pos:c=4294967295}=t,u=dd(e),{version:f,vin:d,vout:l,locktime:p}=u,h=Od(u,t),{txid:m,vout:g,sequence:y,witness:_=[]}=h;if(!a.includes(i))throw new R(`invalid taproot sighash type: 0x${i.toString(16)}. Valid values: SIGHASH_DEFAULT (0x00), SIGHASH_ALL (0x01), SIGHASH_NONE (0x02), SIGHASH_SINGLE (0x03), or combined with ANYONECANPAY (0x81, 0x82, 0x83)`);if(o<0||o>127)throw new R(`extension flag out of range: ${o}. Valid range is 0-127`);let{extension:w}=t;void 0!==n&&(w=Ad(n).hex);const v=!(128&~i),b=kd(_),x=2*(o+(void 0!==w?1:0))+(void 0!==b?1:0),E=[T.num(0,1),T.num(i,1),Qf(f),ud(p)];if(!v){const e=d.map(e=>Ed(e));E.push(jd(d),Cd(e),Fd(e),Zd(d))}if(((3&i)<2||(3&i)>3)&&E.push(Hd(l)),E.push(T.num(x,1)),v){const{value:e,script_pk:t}=Ed(h);E.push(ed(m),td(g),od(e),fd(t),nd(y))}else M.ok("number"==typeof r),E.push(T.num(r,4).reverse());return void 0!==b&&E.push(b),3&~i||(M.ok("number"==typeof r,"txindex required for SIGHASH_SINGLE"),M.ok(r>=0&&r<l.length,`txindex ${r} out of bounds for ${l.length} outputs`),E.push(Dd(l[r]))),void 0!==w&&E.push(T.bytes(w),T.num(s),T.num(c,4,"le")),T.join(E)}function jd(e){const t=[];for(const{txid:n,vout:r}of e)t.push(ed(n)),t.push(td(r));return Ve(T.join(t))}function Zd(e){return Ve(...e.map(e=>nd(e.sequence)))}function Cd(e){return Ve(...e.map(e=>od(e.value)))}function Fd(e){return Ve(...e.map(e=>fd(e.script_pk)))}function Hd(e){const t=[];for(const{value:n,script_pk:r}of e)t.push(od(n)),t.push(fd(r));return Ve(...t)}function Dd(e){return Ve(od(e.value),fd(e.script_pk))}var Ld=Object.freeze({__proto__:null,bip143_hash_outputs:Pd,bip143_hash_prevouts:Sd,bip143_hash_sequence:$d,bip341_hash_amounts:Cd,bip341_hash_outpoints:jd,bip341_hash_output:Dd,bip341_hash_outputs:Hd,bip341_hash_scripts:Fd,bip341_hash_sequence:Zd,get_annex_data:kd,get_prevout:Ed,get_taproot_tx_preimage:Bd,hash_segwit_tx:zd,hash_taproot_tx:Ud,parse_txinput:Od});const Vd=/^[0-9a-fA-F]{64}$/;function qd(e){if("string"!=typeof e)throw new R("Secret key must be a string","seckey");if(!Vd.test(e))throw new R("Invalid secret key format: expected 32-byte hex string (64 characters)","seckey")}function Md(e,t){const{sigflag:n,txindex:r}=e;if(void 0!==n){if("number"!=typeof n||!Number.isInteger(n))throw new B("sigflag must be an integer");const e=127&n,r=!(128&~n)?128|e:e;if(!t.includes(r)&&!t.includes(e))throw new B(`Invalid sigflag: ${n}`)}if(void 0!==r&&("number"!=typeof r||!Number.isInteger(r)||r<0))throw new R("txindex must be a non-negative integer","txindex")}function Kd(e){return 0!==e?T.num(e,1).hex:""}function Jd(e){const t=e.map(e=>T.bytes(e)),n=e.map(e=>T.bytes(e).hex),i=function(e){const t=e.at(-1);return e.length>1&&t instanceof Uint8Array&&80===t[0]?new T(t).hex:null}(t);null!==i&&t.pop();const o=function(e){const t=e.at(-1);return e.length>1&&t instanceof Uint8Array&&t.length>32&&r.includes(254&t[0])?new T(t).hex:null}(t);null!==o&&t.pop();const s=function(e,t){const n=e.at(0),r=e.at(1),i=e.at(-1);return null!==t&&void 0!==i?"p2ts":2===e.length&&void 0!==n&&void 0!==r&&n.length>=71&&n.length<=73&&33===r.length?"p2wpkh":1!==e.length||void 0===n||64!==n.length&&65!==n.length?e.length>1&&void 0!==i&&Zi(i)?"p2wsh":null:"p2tr"}(t,o),a=function(e){return null===e?null:e.startsWith("p2w")?0:e.startsWith("p2t")?1:null}(s),c=function(e,t){let n;switch(t){case"p2ts":case"p2wsh":n=e.at(-1)}return void 0!==n?new T(n).hex:null}(t,s);null!==c&&t.pop();return{annex:i,cblock:o,params:t.map(e=>e.hex),script:c,stack:n,type:s,version:a}}function Gd(e){const t=new N(e),n=t.read(1).num,r=t.read(32).hex,[i,o]=Wd(n),s=[];for(;t.size>=32;)s.push(t.read(32).hex);if(0!==t.size)throw new U(`control block has ${t.size} extra bytes. Expected: 33 + (32 * path_length) bytes`);return{int_key:r,path:s,parity:o,version:i}}function Wd(e){return e%2==0?[e,2]:[e-1,3]}function Yd(e){M.ok(33===T.bytes(e).length,"invalid pubkey size");const[t]=T.bytes(e);if(2===t)return 0;if(3===t)return 1;throw new R(`invalid pubkey parity prefix: 0x${t.toString(16)}. Expected 0x02 (even) or 0x03 (odd)`)}function Xd(e,t,n=[],r=0){if(r>128)throw new R(`Taproot tree depth ${r} exceeds maximum 128`,"depth");const i=[],o=[];if(e.length<1)throw new R("Taproot tree cannot be empty","taptree");for(let o=0;o<e.length;o++){const s=e[o];if(Array.isArray(s)){const[e,o,a]=Xd(s,t,[],r+1);t=o,i.push(e);for(const e of a)n.push(e)}else{const e=T.bytes(s).hex;i.push(e)}}if(1===i.length)return[i[0],t,n];i.sort(),i.length%2!=0&&i.push(i[i.length-1]);for(let e=0;e<i.length-1;e+=2){const r=Td(i[e],i[e+1]).hex;o.push(r),"string"==typeof t&&(t===i[e]?(n.push(i[e+1]),t=r):t===i[e+1]&&(n.push(i[e]),t=r))}return Xd(o,t,n,r+1)}const Qd=192;function el(e,t,n){M.ok(32===T.bytes(e).length,"tapkey must be 32 bytes");const{parity:r,path:i,int_key:o}=Gd(n),s=T.join([r,e]);let a=T.bytes(t).hex;for(const e of i)a=Td(a,e).hex;const c=Nn(o,Rd(o,a),"ecdsa");return s.hex===c.hex}function tl(e,t,n,r){try{const{witness:i=[]}=t;if(0===i.length)return{index:n,valid:!0,type:null};const o=Jd(i.map(e=>T.hex(e))),{type:s,version:a}=o;if(null===s||null===a)return{index:n,valid:!1,type:s,error:"Unknown witness type"};const c=t.prevout;return null==c?{index:n,valid:!1,type:s,error:"Missing prevout data"}:0===a?function(e,t,n,r){const{type:i,params:o,script:s}=r;if(o.length<1)return{index:n,valid:!1,type:i,error:"Missing signature in witness"};const a=o[0],{signature:c,sigflag:u}=function(e){const t=T.hex(e),n=t.at(-1)??1,r=t.slice(0,-1).hex;return{signature:r,sigflag:n}}(a);let f,d;if("p2wpkh"===i){if(o.length<2)return{index:n,valid:!1,type:i,error:"Missing pubkey in P2WPKH witness"};f=o[1];d=`76a914${Le(f).hex}88ac`}else{if("p2wsh"!==i)return{index:n,valid:!1,type:i,error:`Unexpected segwit type: ${i}`};if(null===s)return{index:n,valid:!1,type:i,error:"Missing script in P2WSH witness"};if(d=s,!(o.length>=2))return{index:n,valid:!1,type:i,error:"Missing pubkey in P2WSH witness"};f=o[1]}const l={txindex:n,txinput:t,pubkey:"p2wpkh"===i?f:void 0,script:"p2wsh"===i?d:void 0,sigflag:u},p=zd(e,l),h=function(e,t,n){const r=Un(e),i=Un(t),o=Rn(n,"ecdsa");return yn.verify(r,i,o,{format:"der",prehash:!1})}(c,p,f);return{index:n,valid:h,type:i,error:h?void 0:"Invalid ECDSA signature"}}(e,t,n,o):1===a?function(e,t,n,r,i){const{type:o,params:s,script:a,cblock:c}=r;if(null==t.prevout)return{index:n,valid:!1,type:o,error:"Missing prevout for taproot verification"};const u=t.prevout;if(s.length<1)return{index:n,valid:!1,type:o,error:"Missing signature in witness"};const f=s[0],{signature:d,sigflag:l}=function(e){const t=T.hex(e);if(64===t.length)return{signature:e,sigflag:0};if(65===t.length){const e=t.at(-1)??0;if(0===e)throw new R("0x00 is not a valid appended sigflag (use 64-byte signature for SIGHASH_DEFAULT)","sigflag");return{signature:t.slice(0,64).hex,sigflag:e}}throw new R(`Invalid Schnorr signature length: ${t.length} (expected 64 or 65 bytes)`,"signature")}(f),p=u.script_pk.slice(4);let h,m;if("p2tr"===o)h=p;else{if("p2ts"!==o)return{index:n,valid:!1,type:o,error:`Unexpected taproot type: ${o}`};{if(null===c||null===a)return{index:n,valid:!1,type:o,error:"Missing cblock or script in script-path spend"};const e=Ad(a).hex;if(!el(p,e,c))return{index:n,valid:!1,type:o,error:"Control block verification failed"};h=s.length>=2&&64===s[1].length?s[1]:p,m=e}}const g={...i,txindex:n,txinput:t,sigflag:l,extension:m,script:"p2ts"===o?a??void 0:void 0},y=Ud(e,g),_=function(e,t,n){const r=Un(e),i=Un(t),o=Rn(n,"bip340");return Pn.verify(r,i,o)}(d,y,h);return{index:n,valid:_,type:o,error:_?void 0:"Invalid Schnorr signature"}}(e,t,n,o,r):{index:n,valid:!1,type:s,error:`Unsupported witness version: ${a}`}}catch(e){return{index:n,valid:!1,error:e instanceof Error?e.message:String(e)}}}var nl=Object.freeze({__proto__:null,sign_segwit_tx:function(e,t,n){qd(e),Md(n,s);return function(e,t){const n=Un(t),r=Un(e),i=yn.sign(n,r,{format:"der",prehash:!1});return T.bytes(i)}(e,zd(dd(t),n)).hex+Kd(n.sigflag??1)},sign_taproot_tx:function(e,t,n){qd(e),Md(n,a);return function(e,t){const n=Un(t),r=Un(e),i=Pn.sign(n,r);return T.bytes(i)}(e,Ud(dd(t),n)).hex+Kd(n.sigflag??0)},verify_tx:function(e,t={}){const{throws:n=!1}=t,r=dd(e),i=[];let o=!0;for(let e=0;e<r.vin.length;e++){const s=r.vin[e];if(null!==s.coinbase){i.push({index:e,valid:!0,type:"coinbase"});continue}const a=tl(r,s,e,t);if(i.push(a),!a.valid&&(o=!1,n))throw new R(`Input ${e} verification failed: ${a.error}`,`vin[${e}]`)}return{valid:o,inputs:i,error:o?void 0:"One or more inputs failed verification"}}}),rl=Object.freeze({__proto__:null,create_taproot:function(e){Uf.parse(e);const{pubkey:t,version:n=Qd}=e,r=e.leaves??[],i=void 0!==e.target?T.bytes(e.target).hex:void 0;let o,s=[];if(r.length>0){const[e,t,n]=Xd(r,i);s=n,o=e}else o=i;const a=Rd(t,o),c=Nn(t,a,"ecdsa"),u=Yd(c),f=Rn(c,"bip340"),d=[T.num(n+u),T.bytes(t)];s.length>0&&d.push(...s);const l=T.join(d);return{int_key:T.bytes(t).hex,path:s,parity:u,taproot:o??null,cblock:l.hex,tapkey:f.hex,taptweak:a.hex}},encode_leaf_version:Nd,encode_tapbranch:Td,encode_tapleaf:Id,encode_tapscript:Ad,encode_taptweak:Rd,get_merkle_root:function(e){return Xd(e)[0]},merkleize:Xd,parse_cblock:Gd,parse_cblock_parity:Wd,parse_pubkey_parity:Yd,parse_taproot_witness:function(e){const{cblock:t,params:n,script:r}=Jd(e);M.exists(t,"cblock is null"),M.exists(r,"script is null");const i=Gd(t);let o=Ad(r,i.version).hex;for(const e of i.path)o=Td(o,e).hex;const s=Rd(i.int_key,o),a=Nn(i.int_key,s,"bip340");return{cblock:i,params:n.map(e=>T.bytes(e).hex),script:r,tapkey:a.hex,tweak:s.hex}},verify_taproot:el});var il=Object.freeze({__proto__:null,assert_witness:function(e){M.ok(Array.isArray(e),"witness must be an array"),M.ok(e.every(e=>T.is_bytes(e)),"witness must be an array of strings or bytes")},get_witness_size:function(e){const t=e.map(e=>T.bytes(e)).reduce((e,t)=>e+t.length,0);return{total:t,vsize:Math.ceil(1+t/4)}},parse_witness:Jd});return e.ADDRESS=hi,e.CONST=d,e.ConfigError=B,e.DecodingError=U,e.META=mo,e.SCHEMA=qf,e.SCRIPT=yo,e.SIGHASH=Ld,e.SIGNER=nl,e.TAPROOT=rl,e.TX=xd,e.ValidationError=R,e.WITNESS=il,e}({});
|
|
13
11
|
//# sourceMappingURL=script.js.map
|