From 54750a796d61b796f9ef2d271d790310ec1d1647 Mon Sep 17 00:00:00 2001 From: teahubxyz Date: Wed, 14 Oct 2026 23:21:33 -0700 Subject: [PATCH] lineage: Orgchain v1.6.1 (under Last act, a timed beat goes to whoever acted last) Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01H4upF5LVwmPDDqrhdUfnXh --- .../lineage/orgchain/assets/index-BAOGqIMM.js | 2063 +++++++++++++++++ .../lineage/orgchain/assets/index-DvE3oFvb.js | 2063 ----------------- ventures/lineage/orgchain/index.html | 2 +- 3 files changed, 2064 insertions(+), 2064 deletions(-) create mode 100644 ventures/lineage/orgchain/assets/index-BAOGqIMM.js delete mode 100644 ventures/lineage/orgchain/assets/index-DvE3oFvb.js diff --git a/ventures/lineage/orgchain/assets/index-BAOGqIMM.js b/ventures/lineage/orgchain/assets/index-BAOGqIMM.js new file mode 100644 index 0000000..11114eb --- /dev/null +++ b/ventures/lineage/orgchain/assets/index-BAOGqIMM.js @@ -0,0 +1,2063 @@ +(function(){const t=document.createElement("link").relList;if(t&&t.supports&&t.supports("modulepreload"))return;for(const s of document.querySelectorAll('link[rel="modulepreload"]'))r(s);new MutationObserver(s=>{for(const o of s)if(o.type==="childList")for(const i of o.addedNodes)i.tagName==="LINK"&&i.rel==="modulepreload"&&r(i)}).observe(document,{childList:!0,subtree:!0});function n(s){const o={};return s.integrity&&(o.integrity=s.integrity),s.referrerPolicy&&(o.referrerPolicy=s.referrerPolicy),s.crossOrigin==="use-credentials"?o.credentials="include":s.crossOrigin==="anonymous"?o.credentials="omit":o.credentials="same-origin",o}function r(s){if(s.ep)return;s.ep=!0;const o=n(s);fetch(s.href,o)}})();const Xa=5e9;function Wc(e,t,n){const r=[];for(const[s,o]of e){const i=o-s;if(t>=i){t-=i;continue}const a=Math.min(n,i-t);if(a&&r.push([s+t,s+t+a]),n-=a,t=0,!n)break}return r}function Yc(e,t){var n;return(n=Wc(e,t,1)[0])==null?void 0:n[0]}function xs(e,t){let n=0;for(const[r,s]of e){if(t>=r&&ti.ranges);let o=0;return e.vout.map(i=>{const a=Wc(s,o,Number(i.value));return o+=Number(i.value),a})}function ci(e){if(!Number.isSafeInteger(e)||e<0)throw new Error(`Wrong positive integer: ${e}`)}function Jd(e){if(typeof e!="boolean")throw new Error(`Expected boolean, not ${e}`)}function Jc(e,...t){if(!(e instanceof Uint8Array))throw new TypeError("Expected Uint8Array");if(t.length>0&&!t.includes(e.length))throw new TypeError(`Expected Uint8Array of length ${t}, not of length=${e.length}`)}function Qd(e){if(typeof e!="function"||typeof e.create!="function")throw new Error("Hash should be wrapped by utils.wrapConstructor");ci(e.outputLen),ci(e.blockLen)}function eh(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 th(e,t){Jc(e);const n=t.outputLen;if(e.lengthnew DataView(e.buffer,e.byteOffset,e.byteLength),ht=(e,t)=>e<<32-t|e>>>t,rh=new Uint8Array(new Uint32Array([287454020]).buffer)[0]===68;if(!rh)throw new Error("Non little-endian hardware is not supported");Array.from({length:256},(e,t)=>t.toString(16).padStart(2,"0"));function sh(e){if(typeof e!="string")throw new TypeError(`utf8ToBytes expected string, got ${typeof e}`);return new TextEncoder().encode(e)}function Qc(e){if(typeof e=="string"&&(e=sh(e)),!(e instanceof Uint8Array))throw new TypeError(`Expected input type is Uint8Array (got ${typeof e})`);return e}let oh=class{clone(){return this._cloneInto()}};function eu(e){const t=r=>e().update(Qc(r)).digest(),n=e();return t.outputLen=n.outputLen,t.blockLen=n.blockLen,t.create=()=>e(),t}function ih(e,t,n,r){if(typeof e.setBigUint64=="function")return e.setBigUint64(t,n,r);const s=BigInt(32),o=BigInt(4294967295),i=Number(n>>s&o),a=Number(n&o),c=r?4:0,u=r?0:4;e.setUint32(t+c,i,r),e.setUint32(t+u,a,r)}let ah=class extends oh{constructor(t,n,r,s){super(),this.blockLen=t,this.outputLen=n,this.padOffset=r,this.isLE=s,this.finished=!1,this.length=0,this.pos=0,this.destroyed=!1,this.buffer=new Uint8Array(t),this.view=Io(this.buffer)}update(t){To.exists(this);const{view:n,buffer:r,blockLen:s}=this;t=Qc(t);const o=t.length;for(let i=0;is-i&&(this.process(r,0),i=0);for(let f=i;fl.length)throw new Error("_sha2: outputLen bigger than state");for(let f=0;fe&t^~e&n,uh=(e,t,n)=>e&t^e&n^t&n,fh=new Uint32Array([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]),Ht=new Uint32Array([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]),jt=new Uint32Array(64);let tu=class extends ah{constructor(){super(64,32,8,!1),this.A=Ht[0]|0,this.B=Ht[1]|0,this.C=Ht[2]|0,this.D=Ht[3]|0,this.E=Ht[4]|0,this.F=Ht[5]|0,this.G=Ht[6]|0,this.H=Ht[7]|0}get(){const{A:t,B:n,C:r,D:s,E:o,F:i,G:a,H:c}=this;return[t,n,r,s,o,i,a,c]}set(t,n,r,s,o,i,a,c){this.A=t|0,this.B=n|0,this.C=r|0,this.D=s|0,this.E=o|0,this.F=i|0,this.G=a|0,this.H=c|0}process(t,n){for(let f=0;f<16;f++,n+=4)jt[f]=t.getUint32(n,!1);for(let f=16;f<64;f++){const d=jt[f-15],h=jt[f-2],m=ht(d,7)^ht(d,18)^d>>>3,y=ht(h,17)^ht(h,19)^h>>>10;jt[f]=y+jt[f-7]+m+jt[f-16]|0}let{A:r,B:s,C:o,D:i,E:a,F:c,G:u,H:l}=this;for(let f=0;f<64;f++){const d=ht(a,6)^ht(a,11)^ht(a,25),h=l+d+ch(a,c,u)+fh[f]+jt[f]|0,y=(ht(r,2)^ht(r,13)^ht(r,22))+uh(r,s,o)|0;l=u,u=c,c=a,a=i+h|0,i=o,o=s,s=r,r=h+y|0}r=r+this.A|0,s=s+this.B|0,o=o+this.C|0,i=i+this.D|0,a=a+this.E|0,c=c+this.F|0,u=u+this.G|0,l=l+this.H|0,this.set(r,s,o,i,a,c,u,l)}roundClean(){jt.fill(0)}destroy(){this.set(0,0,0,0,0,0,0,0),this.buffer.fill(0)}},lh=class extends tu{constructor(){super(),this.A=-1056596264,this.B=914150663,this.C=812702999,this.D=-150054599,this.E=-4191439,this.F=1750603025,this.G=1694076839,this.H=-1090891868,this.outputLen=28}};const ui=eu(()=>new tu);eu(()=>new lh);function dh(e,t){if(e.length>t)throw new TypeError(`Data is larger than array size: ${e.length} > ${t}`)}function hh(e){if(e.match(/[^a-fA-f0-9]/)!==null)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}`)}function ph(e){if(e>Number.MAX_SAFE_INTEGER)throw new TypeError("Number exceeds safe bounds!")}const{getRandomValues:gh}=crypto??globalThis.crypto??window.crypto;function mh(e=32){if(typeof gh=="function")return crypto.getRandomValues(new Uint8Array(e));throw new Error("Crypto module missing getRandomValues!")}function yh(e,t,n="be"){t===void 0&&(t=e.length),dh(e,t);const r=new Uint8Array(t).fill(0),s=n==="be"?0:t-e.length;return r.set(e,s),r}function nu(e){let t,n=0;const r=e.reduce((o,i)=>o+i.length,0),s=new Uint8Array(r);for(t=0;t0||(i.length^a)>0?"":"1";c in o||u>0;)l=o[c],l=l>0?l*256+u:u,u=l/s|0,o[c]=l%s,c++;for(;c-- >0;)i+=r[o[c]];return n&&i.length%4>0?i+"=".repeat(4-i.length%4):i}function vh(e,t){const n=ru(t),r=n.length,s=[],o=[];e=e.replace("=","");let i,a=0,c,u;for(i=0;i0||(o.length^i)>0||o.push(0);a in s||c>0;)u=s[a],u=u>0?u*r+c:c,c=u>>8,s[a]=u%256,a++}for(;a-- >0;)o.push(s[a]);return new Uint8Array(o)}function su(e){return ui(ui(e))}function Eh(e){const t=su(e);return nu([e,t.slice(0,4)])}function Sh(e){const t=e.slice(0,-4),n=e.slice(-4);if(su(t).slice(0,4).toString()!==n.toString())throw new Error("Invalid checksum!");return t}const Ja={encode:xh,decode:vh},ou={encode:e=>{const t=Eh(e);return Ja.encode(t,"base58")},decode:e=>{const t=Ja.decode(e,"base58");return Sh(t)}},iu="qpzry9x8gf2tvdw0s3jn54khce6mua7l",kh=[996825010,642813549,513874426,1027748829,705979059],$s=[{version:0,name:"bech32",const:1},{version:1,name:"bech32m",const:734539939}];function au(e){let t=1;for(let n=0;n>25;t=(t&33554431)<<5^e[n];for(let s=0;s<5;++s)(r>>s&1)!==0&&(t^=kh[s])}return t}function cu(e){const t=[];let n;for(n=0;n>5);for(t.push(0),n=0;n>5*(5-i)&31);return o}function uu(e,t,n,r=!0){const s=[];let o=0,i=0;const a=(1<>t>0)throw new Error("Failed to perform base conversion. Invalid value: "+String(u));for(o=(o<=n;)i-=n,s.push(o>>i&a)}if(r)i>0&&s.push(o<=t||(o<0)throw new Error("Failed to perform base conversion. Invalid Size!");return s}function Ah(e,t,n){const r=t.concat($h(e,t,n));let s=e+"1";for(let o=0;oo.version===t[0])??$s[0];if(!_h(r,t,s))throw new Error("Checksum verification failed!");return[r,t.slice(0,t.length-6)]}function Bh(e){let t,n,r=!1,s=!1;for(t=0;t126)return!1;n>=97&&n<=122&&(r=!0),n>=65&&n<=90&&(s=!0)}return!(r&&s)}function Th(e){const t=e.lastIndexOf("1");return!(t<1||t+7>e.length||e.length>90)}function Ih(e,t="bc",n=0){const r=[n,...uu([...e],8,5)],s=$s.find(i=>i.version===n)??$s[0],o=Ah(t,r,s);return lu(o),o}function lu(e){e=e.toLowerCase();const t=e.split("1",1)[0],[n,r]=fu(e),s=uu(r.slice(1),5,8,!1),o=s.length;switch(!0){case t!==n:throw new Error("Returned hrp string is invalid.");case(s===null||o<2||o>40):throw new Error("Decoded string is invalid or out of spec.");case r[0]>16:throw new Error("Returned version bit is out of range.");default:return Uint8Array.from(s)}}function Oh(e){e=e.toLowerCase();const[t,n]=fu(e);return n[0]}const du={encode:Ih,decode:lu,version:Oh},hu="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",pu="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",Ch=new TextEncoder;function gu(e,t=!1,n=!0){typeof e=="string"&&(e=Ch.encode(e));const r=t?pu:hu;let s="",o=0,i=0;for(let a=0;a=6;)o-=6,s+=r[i>>o&63];if(o>0)for(i<<=6-o,s+=r[i&63];o<6;)s+=n?"=":"",o+=2;return s}function mu(e,t=!1){const n=t||e.includes("-")||e.includes("_")?pu.split(""):hu.split("");e=e.replace(/=+$/,"");const r=e.split("");let s=0,o=0;const i=[];for(let a=0;a=8&&(s-=8,i.push(o>>>s&255))}return new Uint8Array(i)}const yu={encode:gu,decode:mu},bu={encode:e=>gu(e,!0,!1),decode:e=>mu(e,!0)},Ph=BigInt(0),Uh=BigInt(255),wu=BigInt(256);function Nh(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.")}function Lh(e,t,n="be"){t===void 0&&(t=Nh(e));const r=n==="le",s=new ArrayBuffer(t),o=new DataView(s);let i=r?0:t-1;for(;e>Ph;){const a=e&Uh,c=Number(a);r?o.setUint8(i++,c):o.setUint8(i--,c),e=(e-a)/wu}return new Uint8Array(s)}function Rh(e){let t=BigInt(0);for(let n=e.length-1;n>=0;n--)t=t*wu+BigInt(e[n]);return BigInt(t)}function Hh(e){const t=e.split("").map(Number);if(t.length%8!==0)throw new Error(`Binary array is invalid length: ${e.length}`);const n=new Uint8Array(t.length/8);for(let r=0,s=0;r255)throw new Error(`Invalid byte value: ${r}. Byte values must be between 0 and 255.`);for(let s=7;s>=0;s--,n++)t[n]=r>>s&1}return t.join("")}function Kh(e){if(e<=255)return 1;if(e<=65535)return 2;if(e<=4294967295)return 4;throw new TypeError("Numbers larger than 4 bytes must specify a fixed size!")}function Dh(e,t,n="be"){t===void 0&&(t=Kh(e));const r=n==="le",s=new ArrayBuffer(t),o=new DataView(s);let i=r?0:t-1;for(;e>0;){const a=e&255;r?o.setUint8(i++,e):o.setUint8(i--,e),e=(e-a)/256}return new Uint8Array(s)}function Zh(e){let t=0;for(let n=e.length-1;n>=0;n--)t=t*256+e[n],ph(t);return t}const Mh=new TextEncoder,Vh=new TextDecoder;function Mi(e){return Mh.encode(e)}function Oo(e){return Vh.decode(e)}function qh(e,t){hh(e);const n=e.length/2;if(t===void 0&&(t=n),n>t)throw new TypeError(`Hex string is larger than array size: ${n} > ${t}`);return t}function zh(e,t,n="le"){t=qh(e,t);const r=n==="le",s=new ArrayBuffer(t),o=new DataView(s);let i=r?0:t-1;for(let a=0;atypeof r=="bigint"?`${r}n`:r);return Mi(t)}function Wh(e,t,n){if(e instanceof ArrayBuffer)return new Uint8Array(e);if(e instanceof Uint8Array)return yh(e,t,n);if(typeof e=="string")return zh(e,t,n);if(typeof e=="bigint")return Lh(e,t,n);if(typeof e=="number")return Dh(e,t,n);if(typeof e=="boolean")return Uint8Array.of(e?1:0);throw TypeError("Unsupported format:"+typeof e)}var J;let E=(J=class extends Uint8Array{static random(t=32){const n=mh(t);return new J(n,t)}constructor(t,n,r){const s=Wh(t,n,r);super(s)}get arr(){return[...this]}get num(){return this.toNum()}get big(){return this.toBig()}get str(){return this.toStr()}get hex(){return this.toHex()}get raw(){return new Uint8Array(this)}get bin(){return this.toBin()}get b58chk(){return this.tob58chk()}get base64(){return this.toBase64()}get b64url(){return this.toB64url()}get digest(){return this.toHash()}get id(){return this.toHash().hex}get stream(){return new fr(this)}toNum(t="be"){const n=t==="be"?this.reverse():this;return Zh(n)}toBin(){return jh(this)}toBig(t="be"){const n=t==="be"?this.reverse():this;return Rh(n)}toHash(){const t=ui(this);return new J(t)}toJson(){const t=Oo(this);return JSON.parse(t)}toBech32(t,n=0){return du.encode(this,t,n)}toStr(){return Oo(this)}toHex(){return Fh(this)}toBytes(){return new Uint8Array(this)}tob58chk(){return ou.encode(this)}toBase64(){return yu.encode(this)}toB64url(){return bu.encode(this)}prepend(t){return J.join([J.bytes(t),this])}append(t){return J.join([this,J.bytes(t)])}slice(t,n){const r=new Uint8Array(this).slice(t,n);return new J(r)}subarray(t,n){const r=new Uint8Array(this).subarray(t,n);return new J(r)}reverse(){const t=new Uint8Array(this).reverse();return new J(t)}write(t,n){const r=J.bytes(t);this.set(r,n)}prefixSize(t){const n=J.varInt(this.length,t);return J.join([n,this])}static from(t){return new J(Uint8Array.from(t))}static of(...t){return new J(Uint8Array.of(...t))}static join(t){const n=t.map(s=>J.bytes(s)),r=nu(n);return new J(r)}static varInt(t,n){if(t<253)return J.num(t,1);if(t<65536)return J.of(253,...J.num(t,2,n));if(t<4294967296)return J.of(254,...J.num(t,4,n));if(BigInt(t)<0x10000000000000000n)return J.of(255,...J.num(t,8,n));throw new Error(`Value is too large: ${t}`)}},J.num=Yh,J.big=Jh,J.bin=Xh,J.raw=Qh,J.str=e0,J.hex=t0,J.bytes=n0,J.json=r0,J.base64=s0,J.b64url=o0,J.bech32=i0,J.b58chk=a0,J.encode=Mi,J.decode=Oo,J);function Yh(e,t,n){return new E(e,t,n)}function Xh(e,t,n){return new E(Hh(e),t,n)}function Jh(e,t,n){return new E(e,t,n)}function Qh(e,t,n){return new E(e,t,n)}function e0(e,t,n){return new E(Mi(e),t,n)}function t0(e,t,n){return new E(e,t,n)}function n0(e,t,n){return new E(e,t,n)}function r0(e){return new E(Gh(e))}function s0(e){return new E(yu.decode(e))}function o0(e){return new E(bu.decode(e))}function i0(e){return new E(du.decode(e))}function a0(e){return new E(ou.decode(e))}let fr=class{constructor(t){this.data=E.bytes(t),this.size=this.data.length}peek(t){if(t>this.size)throw new Error(`Size greater than stream: ${t} > ${this.size}`);return new E(this.data.slice(0,t))}read(t){t=t??this.readSize();const n=this.peek(t);return this.data=this.data.slice(t),this.size=this.data.length,n}readSize(t){const n=this.read(1).num;switch(!0){case(n>=0&&n<253):return n;case n===253:return this.read(2).toNum(t);case n===254:return this.read(4).toNum(t);case n===255:return this.read(8).toNum(t);default:throw new Error(`Varint is out of range: ${n}`)}}};function kt(e,t){const n=E.bytes(e);if(n.length!==t)throw new Error(`Invalid input size: ${n.hex} !== ${t}`)}function Ue(e,t){if(t)throw new Error(e);return!1}function vs(e,...t){const n=E.str(e).digest.raw,r=t.map(s=>E.bytes(s));return E.join([n,n,E.join(r)]).digest}const xu={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,OP_SUCCESS187:187,OP_SUCCESS188:188,OP_SUCCESS189:189,OP_SUCCESS190:190,OP_SUCCESS191:191,OP_SUCCESS192:192,OP_SUCCESS193:193,OP_SUCCESS194:194,OP_SUCCESS195:195,OP_SUCCESS196:196,OP_SUCCESS197:197,OP_SUCCESS198:198,OP_SUCCESS199:199,OP_SUCCESS200:200,OP_SUCCESS201:201,OP_SUCCESS202:202,OP_SUCCESS203:203,OP_SUCCESS204:204,OP_SUCCESS205:205,OP_SUCCESS206:206,OP_SUCCESS207:207,OP_SUCCESS208:208,OP_SUCCESS209:209,OP_SUCCESS210:210,OP_SUCCESS211:211,OP_SUCCESS212:212,OP_SUCCESS213:213,OP_SUCCESS214:214,OP_SUCCESS215:215,OP_SUCCESS216:216,OP_SUCCESS217:217,OP_SUCCESS218:218,OP_SUCCESS219:219,OP_SUCCESS220:220,OP_SUCCESS221:221,OP_SUCCESS222:222,OP_SUCCESS223:223,OP_SUCCESS224:224,OP_SUCCESS225:225,OP_SUCCESS226:226,OP_SUCCESS227:227,OP_SUCCESS228:228,OP_SUCCESS229:229,OP_SUCCESS230:230,OP_SUCCESS231:231,OP_SUCCESS232:232,OP_SUCCESS233:233,OP_SUCCESS234:234,OP_SUCCESS235:235,OP_SUCCESS236:236,OP_SUCCESS237:237,OP_SUCCESS238:238,OP_SUCCESS239:239,OP_SUCCESS240:240,OP_SUCCESS241:241,OP_SUCCESS242:242,OP_SUCCESS243:243,OP_SUCCESS244:244,OP_SUCCESS245:245,OP_SUCCESS246:246,OP_SUCCESS247:247,OP_SUCCESS248:248,OP_SUCCESS249:249,OP_SUCCESS250:250,OP_SUCCESS251:251,OP_SUCCESS252:252,OP_SUCCESS253:253,OP_SUCCESS254:254};function c0(e){if(e>186&&e<255)return"OP_SUCCESS"+String(e);for(const[t,n]of Object.entries(xu))if(n===e)return t;throw new Error("OPCODE not found:"+String(e))}function u0(e){for(const[t,n]of Object.entries(xu))if(t===e)return Number(n);throw new Error("OPCODE not found:"+e)}function f0(e){switch(!0){case e===0:return"opcode";case(e>=1&&e<=75):return"varint";case e===76:return"pushdata1";case e===77:return"pushdata2";case e===78:return"pushdata4";case e<=254:return"opcode";default:throw new Error(`Invalid word range: ${e}`)}}function l0(e){const r=[];switch(!0){case typeof e!="number":return!1;case e===0:return!0;case r.includes(e):return!1;case(750?E.join(t):new Uint8Array}function d0(e){let t=new Uint8Array;if(typeof e=="string"){if(e.startsWith("OP_"))return E.num(u0(e),1);Rt(e)?t=E.hex(e):t=E.str(e)}else t=E.bytes(e);if(t.length===1)return t[0]!==0&&t[0]<=16?(t[0]+=80,t):(t[0]>128&&t[0]<=255&&(t=new Uint8Array([t[0],0])),E.join([Qa(t.length),t]));if(t.length>As){const n=h0(t);return Eu(n)}else return E.join([Qa(t.length),t])}function Qa(e){const t=E.num(76,1),n=E.num(77,1);switch(!0){case e<=75:return E.num(e);case(e>75&&e<256):return E.join([t,E.num(e,1,"le")]);case(e>=256&&e<=As):return E.join([n,E.num(e,2,"le")]);default:throw new Error("Invalid word size:"+e.toString())}}function h0(e){const t=[],n=new fr(e);for(;n.size>As;)t.push(n.read(As));return t.push(n.read(n.size)),t}function Vi(e,t=!1){let n=E.bytes(e);if(t){const s=n.stream.readSize("le");if(n=n.slice(1),n.length!==s)throw new Error(`Varint does not match stream size: ${s} !== ${n.length}`)}return p0(n)}function p0(e){const t=new fr(e),n=[],r=t.size;let s,o,i,a=0;for(;a0&&!t.includes(e.length))throw new TypeError(`Expected Uint8Array of length ${t}, not of length=${e.length}`)}function x0(e){if(typeof e!="function"||typeof e.create!="function")throw new Error("Hash should be wrapped by utils.wrapConstructor");fi(e.outputLen),fi(e.blockLen)}function v0(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 E0(e,t){Su(e);const n=t.outputLen;if(e.lengthnew DataView(e.buffer,e.byteOffset,e.byteLength),pt=(e,t)=>e<<32-t|e>>>t,k0=new Uint8Array(new Uint32Array([287454020]).buffer)[0]===68;if(!k0)throw new Error("Non little-endian hardware is not supported");Array.from({length:256},(e,t)=>t.toString(16).padStart(2,"0"));function _0(e){if(typeof e!="string")throw new TypeError(`utf8ToBytes expected string, got ${typeof e}`);return new TextEncoder().encode(e)}function qi(e){if(typeof e=="string"&&(e=_0(e)),!(e instanceof Uint8Array))throw new TypeError(`Expected input type is Uint8Array (got ${typeof e})`);return e}function $0(...e){if(!e.every(r=>r instanceof Uint8Array))throw new Error("Uint8Array list expected");if(e.length===1)return e[0];const t=e.reduce((r,s)=>r+s.length,0),n=new Uint8Array(t);for(let r=0,s=0;re().update(qi(r)).digest(),n=e();return t.outputLen=n.outputLen,t.blockLen=n.blockLen,t.create=()=>e(),t}function A0(e=32){if(Co&&typeof Co.getRandomValues=="function")return Co.getRandomValues(new Uint8Array(e));throw new Error("crypto.getRandomValues must be defined")}function B0(e,t,n,r){if(typeof e.setBigUint64=="function")return e.setBigUint64(t,n,r);const s=BigInt(32),o=BigInt(4294967295),i=Number(n>>s&o),a=Number(n&o),c=r?4:0,u=r?0:4;e.setUint32(t+c,i,r),e.setUint32(t+u,a,r)}let T0=class extends ku{constructor(t,n,r,s){super(),this.blockLen=t,this.outputLen=n,this.padOffset=r,this.isLE=s,this.finished=!1,this.length=0,this.pos=0,this.destroyed=!1,this.buffer=new Uint8Array(t),this.view=Po(this.buffer)}update(t){xn.exists(this);const{view:n,buffer:r,blockLen:s}=this;t=qi(t);const o=t.length;for(let i=0;is-i&&(this.process(r,0),i=0);for(let f=i;fl.length)throw new Error("_sha2: outputLen bigger than state");for(let f=0;fe&t^~e&n,O0=(e,t,n)=>e&t^e&n^t&n,C0=new Uint32Array([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]),Kt=new Uint32Array([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]),Dt=new Uint32Array(64);let $u=class extends T0{constructor(){super(64,32,8,!1),this.A=Kt[0]|0,this.B=Kt[1]|0,this.C=Kt[2]|0,this.D=Kt[3]|0,this.E=Kt[4]|0,this.F=Kt[5]|0,this.G=Kt[6]|0,this.H=Kt[7]|0}get(){const{A:t,B:n,C:r,D:s,E:o,F:i,G:a,H:c}=this;return[t,n,r,s,o,i,a,c]}set(t,n,r,s,o,i,a,c){this.A=t|0,this.B=n|0,this.C=r|0,this.D=s|0,this.E=o|0,this.F=i|0,this.G=a|0,this.H=c|0}process(t,n){for(let f=0;f<16;f++,n+=4)Dt[f]=t.getUint32(n,!1);for(let f=16;f<64;f++){const d=Dt[f-15],h=Dt[f-2],m=pt(d,7)^pt(d,18)^d>>>3,y=pt(h,17)^pt(h,19)^h>>>10;Dt[f]=y+Dt[f-7]+m+Dt[f-16]|0}let{A:r,B:s,C:o,D:i,E:a,F:c,G:u,H:l}=this;for(let f=0;f<64;f++){const d=pt(a,6)^pt(a,11)^pt(a,25),h=l+d+I0(a,c,u)+C0[f]+Dt[f]|0,y=(pt(r,2)^pt(r,13)^pt(r,22))+O0(r,s,o)|0;l=u,u=c,c=a,a=i+h|0,i=o,o=s,s=r,r=h+y|0}r=r+this.A|0,s=s+this.B|0,o=o+this.C|0,i=i+this.D|0,a=a+this.E|0,c=c+this.F|0,u=u+this.G|0,l=l+this.H|0,this.set(r,s,o,i,a,c,u,l)}roundClean(){Dt.fill(0)}destroy(){this.set(0,0,0,0,0,0,0,0),this.buffer.fill(0)}},P0=class extends $u{constructor(){super(),this.A=-1056596264,this.B=914150663,this.C=812702999,this.D=-150054599,this.E=-4191439,this.F=1750603025,this.G=1694076839,this.H=-1090891868,this.outputLen=28}};const Au=_u(()=>new $u);_u(()=>new P0);/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */const U0=BigInt(0),zi=BigInt(1),N0=BigInt(2),io=e=>e instanceof Uint8Array,L0=Array.from({length:256},(e,t)=>t.toString(16).padStart(2,"0"));function Qn(e){if(!io(e))throw new Error("Uint8Array expected");let t="";for(let n=0;ner(e.toString(16).padStart(t*2,"0")),Tu=(e,t)=>Gn(e,t).reverse(),R0=e=>er(Bu(e));function et(e,t,n){let r;if(typeof t=="string")try{r=er(t)}catch(o){throw new Error(`${e} must be valid hex string, got "${t}". Cause: ${o}`)}else if(io(t))r=Uint8Array.from(t);else throw new Error(`${e} must be hex string or Uint8Array`);const s=r.length;if(typeof n=="number"&&s!==n)throw new Error(`${e} expected ${n} bytes, got ${s}`);return r}function ot(...e){const t=new Uint8Array(e.reduce((r,s)=>r+s.length,0));let n=0;return e.forEach(r=>{if(!io(r))throw new Error("Uint8Array expected");t.set(r,n),n+=r.length}),t}function H0(e,t){if(e.length!==t.length)return!1;for(let n=0;n0n;e>>=zi,t+=1);return t}const K0=(e,t)=>e>>BigInt(t)&1n,D0=(e,t,n)=>e|(n?zi:U0)<(N0<new Uint8Array(e),ec=e=>Uint8Array.from(e);function Iu(e,t,n){if(typeof e!="number"||e<2)throw new Error("hashLen must be a number");if(typeof t!="number"||t<2)throw new Error("qByteLen must be a number");if(typeof n!="function")throw new Error("hmacFn must be a function");let r=Uo(e),s=Uo(e),o=0;const i=()=>{r.fill(1),s.fill(0),o=0},a=(...f)=>n(s,r,...f),c=(f=Uo())=>{s=a(ec([0]),f),r=a(),f.length!==0&&(s=a(ec([1]),f),r=a())},u=()=>{if(o++>=1e3)throw new Error("drbg: tried 1000 values");let f=0;const d=[];for(;f{i(),c(f);let h;for(;!(h=d(u()));)c();return i(),h}}const Z0={bigint:e=>typeof e=="bigint",function:e=>typeof e=="function",boolean:e=>typeof e=="boolean",string:e=>typeof e=="string",isSafeInteger:e=>Number.isSafeInteger(e),array:e=>Array.isArray(e),field:(e,t)=>t.Fp.isValid(e),hash:e=>typeof e=="function"&&Number.isSafeInteger(e.outputLen)};function lr(e,t,n={}){const r=(s,o,i)=>{const a=Z0[o];if(typeof a!="function")throw new Error(`Invalid validator "${o}", expected function`);const c=e[s];if(!(i&&c===void 0)&&!a(c,e))throw new Error(`Invalid param ${String(s)}=${c} (${typeof c}), expected ${o}`)};for(const[s,o]of Object.entries(t))r(s,o,!1);for(const[s,o]of Object.entries(n))r(s,o,!0);return e}var M0=Object.freeze({__proto__:null,bitGet:K0,bitLen:j0,bitMask:Wi,bitSet:D0,bytesToHex:Qn,bytesToNumberBE:nn,bytesToNumberLE:Gi,concatBytes:ot,createHmacDrbg:Iu,ensureBytes:et,equalBytes:H0,hexToBytes:er,hexToNumber:Fi,numberToBytesBE:Gn,numberToBytesLE:Tu,numberToHexUnpadded:Bu,numberToVarBytesBE:R0,utf8ToBytes:ao,validateObject:lr});/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */const Te=BigInt(0),_e=BigInt(1),mn=BigInt(2),V0=BigInt(3),li=BigInt(4),tc=BigInt(5),nc=BigInt(8);BigInt(9);BigInt(16);function Ne(e,t){const n=e%t;return n>=Te?n:t+n}function q0(e,t,n){if(n<=Te||t 0");if(n===_e)return Te;let r=_e;for(;t>Te;)t&_e&&(r=r*e%n),e=e*e%n,t>>=_e;return r}function Qe(e,t,n){let r=e;for(;t-- >Te;)r*=r,r%=n;return r}function di(e,t){if(e===Te||t<=Te)throw new Error(`invert: expected positive integers, got n=${e} mod=${t}`);let n=Ne(e,t),r=t,s=Te,o=_e;for(;n!==Te;){const a=r/n,c=r%n,u=s-o*a;r=n,n=c,s=o,o=u}if(r!==_e)throw new Error("invert: does not exist");return Ne(s,t)}function z0(e){const t=(e-_e)/mn;let n,r,s;for(n=e-_e,r=0;n%mn===Te;n/=mn,r++);for(s=mn;s(r[s]="function",r),t);return lr(e,n)}function W0(e,t,n){if(n 0");if(n===Te)return e.ONE;if(n===_e)return t;let r=e.ONE,s=t;for(;n>Te;)n&_e&&(r=e.mul(r,s)),s=e.sqr(s),n>>=_e;return r}function Y0(e,t){const n=new Array(t.length),r=t.reduce((o,i,a)=>e.is0(i)?o:(n[a]=o,e.mul(o,i)),e.ONE),s=e.inv(r);return t.reduceRight((o,i,a)=>e.is0(i)?o:(n[a]=e.mul(o,n[a]),e.mul(o,i)),s),n}function Yi(e,t){const n=t!==void 0?t:e.toString(2).length,r=Math.ceil(n/8);return{nBitLength:n,nByteLength:r}}function Cu(e,t,n=!1,r={}){if(e<=Te)throw new Error(`Expected Fp ORDER > 0, got ${e}`);const{nBitLength:s,nByteLength:o}=Yi(e,t);if(o>2048)throw new Error("Field lengths over 2048 bytes are not supported");const i=F0(e),a=Object.freeze({ORDER:e,BITS:s,BYTES:o,MASK:Wi(s),ZERO:Te,ONE:_e,create:c=>Ne(c,e),isValid:c=>{if(typeof c!="bigint")throw new Error(`Invalid field element: expected bigint, got ${typeof c}`);return Te<=c&&cc===Te,isOdd:c=>(c&_e)===_e,neg:c=>Ne(-c,e),eql:(c,u)=>c===u,sqr:c=>Ne(c*c,e),add:(c,u)=>Ne(c+u,e),sub:(c,u)=>Ne(c-u,e),mul:(c,u)=>Ne(c*u,e),pow:(c,u)=>W0(a,c,u),div:(c,u)=>Ne(c*di(u,e),e),sqrN:c=>c*c,addN:(c,u)=>c+u,subN:(c,u)=>c-u,mulN:(c,u)=>c*u,inv:c=>di(c,e),sqrt:r.sqrt||(c=>i(a,c)),invertBatch:c=>Y0(a,c),cmov:(c,u,l)=>l?u:c,toBytes:c=>n?Tu(c,o):Gn(c,o),fromBytes:c=>{if(c.length!==o)throw new Error(`Fp.fromBytes: expected ${o}, got ${c.length}`);return n?Gi(c):nn(c)}});return Object.freeze(a)}function X0(e,t,n=!1){e=et("privateHash",e);const r=e.length,s=Yi(t).nByteLength+8;if(s<24||r1024)throw new Error(`hashToPrivateScalar: expected ${s}-1024 bytes of input, got ${r}`);const o=n?Gi(e):nn(e);return Ne(o,t-_e)+_e}/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */const J0=BigInt(0),No=BigInt(1);function Q0(e,t){const n=(s,o)=>{const i=o.negate();return s?i:o},r=s=>{const o=Math.ceil(t/s)+1,i=2**(s-1);return{windows:o,windowSize:i}};return{constTimeNegate:n,unsafeLadder(s,o){let i=e.ZERO,a=s;for(;o>J0;)o&No&&(i=i.add(a)),a=a.double(),o>>=No;return i},precomputeWindow(s,o){const{windows:i,windowSize:a}=r(o),c=[];let u=s,l=u;for(let f=0;f>=h,g>c&&(g-=d,i+=No);const p=y,w=y+Math.abs(g)-1,b=m%2!==0,T=g<0;g===0?l=l.add(n(b,o[p])):u=u.add(n(T,o[w]))}return{p:u,f:l}},wNAFCached(s,o,i,a){const c=s._WINDOW_SIZE||1;let u=o.get(s);return u||(u=this.precomputeWindow(s,c),c!==1&&o.set(s,a(u))),this.wNAF(c,u,i)}}}function Pu(e){return Ou(e.Fp),lr(e,{n:"bigint",h:"bigint",Gx:"field",Gy:"field"},{nBitLength:"isSafeInteger",nByteLength:"isSafeInteger"}),Object.freeze({...Yi(e.n,e.nBitLength),...e,p:e.Fp.ORDER})}/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */function ep(e){const t=Pu(e);lr(t,{a:"field",b:"field"},{allowedPrivateKeyLengths:"array",wrapPrivateKey:"boolean",isTorsionFree:"function",clearCofactor:"function",allowInfinityPoint:"boolean",fromBytes:"function",toBytes:"function"});const{endo:n,Fp:r,a:s}=t;if(n){if(!r.eql(s,r.ZERO))throw new Error("Endomorphism can only be defined for Koblitz curves that have a=0");if(typeof n!="object"||typeof n.beta!="bigint"||typeof n.splitScalar!="function")throw new Error("Expected endomorphism with beta: bigint and splitScalar: function")}return Object.freeze({...t})}const{bytesToNumberBE:tp,hexToBytes:np}=M0,vn={Err:class extends Error{constructor(t=""){super(t)}},_parseInt(e){const{Err:t}=vn;if(e.length<2||e[0]!==2)throw new t("Invalid signature integer tag");const n=e[1],r=e.subarray(2,n+2);if(!n||r.length!==n)throw new t("Invalid signature integer: wrong length");if(r[0]===0&&r[1]<=127)throw new t("Invalid signature integer: trailing length");return{d:tp(r),l:e.subarray(n+2)}},toSig(e){const{Err:t}=vn,n=typeof e=="string"?np(e):e;if(!(n instanceof Uint8Array))throw new Error("ui8a expected");let r=n.length;if(r<2||n[0]!=48)throw new t("Invalid signature tag");if(n[1]!==r-2)throw new t("Invalid signature: incorrect length");const{d:s,l:o}=vn._parseInt(n.subarray(2)),{d:i,l:a}=vn._parseInt(o);if(a.length)throw new t("Invalid signature: left bytes after parsing");return{r:s,s:i}},hexFromSig(e){const t=u=>Number.parseInt(u[0],16)>=8?"00"+u:u,n=u=>{const l=u.toString(16);return l.length&1?`0${l}`:l},r=t(n(e.s)),s=t(n(e.r)),o=r.length/2,i=s.length/2,a=n(o),c=n(i);return`30${n(i+o+4)}02${c}${s}02${a}${r}`}},it=BigInt(0),$e=BigInt(1),At=BigInt(2),Bs=BigInt(3),rc=BigInt(4);function rp(e){const t=ep(e),{Fp:n}=t,r=t.toBytes||((m,y,g)=>{const p=y.toAffine();return ot(Uint8Array.from([4]),n.toBytes(p.x),n.toBytes(p.y))}),s=t.fromBytes||(m=>{const y=m.subarray(1),g=n.fromBytes(y.subarray(0,n.BYTES)),p=n.fromBytes(y.subarray(n.BYTES,2*n.BYTES));return{x:g,y:p}});function o(m){const{a:y,b:g}=t,p=n.sqr(m),w=n.mul(p,m);return n.add(n.add(w,n.mul(m,y)),g)}function i(m){return typeof m=="bigint"&&itn.eql(b,n.ZERO);return w(g)&&w(p)?f.ZERO:new f(g,p,n.ONE)}get x(){return this.toAffine().x}get y(){return this.toAffine().y}static normalizeZ(y){const g=n.invertBatch(y.map(p=>p.pz));return y.map((p,w)=>p.toAffine(g[w])).map(f.fromAffine)}static fromHex(y){const g=f.fromAffine(s(et("pointHex",y)));return g.assertValidity(),g}static fromPrivateKey(y){return f.BASE.multiply(c(y))}_setWindowSize(y){this._WINDOW_SIZE=y,u.delete(this)}assertValidity(){if(this.is0()){if(t.allowInfinityPoint)return;throw new Error("bad point: ZERO")}const{x:y,y:g}=this.toAffine();if(!n.isValid(y)||!n.isValid(g))throw new Error("bad point: x or y not FE");const p=n.sqr(g),w=o(y);if(!n.eql(p,w))throw new Error("bad point: equation left != right");if(!this.isTorsionFree())throw new Error("bad point: not in prime-order subgroup")}hasEvenY(){const{y}=this.toAffine();if(n.isOdd)return!n.isOdd(y);throw new Error("Field doesn't support isOdd")}equals(y){l(y);const{px:g,py:p,pz:w}=this,{px:b,py:T,pz:A}=y,O=n.eql(n.mul(g,A),n.mul(b,w)),U=n.eql(n.mul(p,A),n.mul(T,w));return O&&U}negate(){return new f(this.px,n.neg(this.py),this.pz)}double(){const{a:y,b:g}=t,p=n.mul(g,Bs),{px:w,py:b,pz:T}=this;let A=n.ZERO,O=n.ZERO,U=n.ZERO,C=n.mul(w,w),_=n.mul(b,b),N=n.mul(T,T),H=n.mul(w,b);return H=n.add(H,H),U=n.mul(w,T),U=n.add(U,U),A=n.mul(y,U),O=n.mul(p,N),O=n.add(A,O),A=n.sub(_,O),O=n.add(_,O),O=n.mul(A,O),A=n.mul(H,A),U=n.mul(p,U),N=n.mul(y,N),H=n.sub(C,N),H=n.mul(y,H),H=n.add(H,U),U=n.add(C,C),C=n.add(U,C),C=n.add(C,N),C=n.mul(C,H),O=n.add(O,C),N=n.mul(b,T),N=n.add(N,N),C=n.mul(N,H),A=n.sub(A,C),U=n.mul(N,_),U=n.add(U,U),U=n.add(U,U),new f(A,O,U)}add(y){l(y);const{px:g,py:p,pz:w}=this,{px:b,py:T,pz:A}=y;let O=n.ZERO,U=n.ZERO,C=n.ZERO;const _=t.a,N=n.mul(t.b,Bs);let H=n.mul(g,b),K=n.mul(p,T),v=n.mul(w,A),S=n.add(g,p),x=n.add(b,T);S=n.mul(S,x),x=n.add(H,K),S=n.sub(S,x),x=n.add(g,w);let k=n.add(b,A);return x=n.mul(x,k),k=n.add(H,v),x=n.sub(x,k),k=n.add(p,w),O=n.add(T,A),k=n.mul(k,O),O=n.add(K,v),k=n.sub(k,O),C=n.mul(_,x),O=n.mul(N,v),C=n.add(O,C),O=n.sub(K,C),C=n.add(K,C),U=n.mul(O,C),K=n.add(H,H),K=n.add(K,H),v=n.mul(_,v),x=n.mul(N,x),K=n.add(K,v),v=n.sub(H,v),v=n.mul(_,v),x=n.add(x,v),H=n.mul(K,x),U=n.add(U,H),H=n.mul(k,x),O=n.mul(S,O),O=n.sub(O,H),H=n.mul(S,K),C=n.mul(k,C),C=n.add(C,H),new f(O,U,C)}subtract(y){return this.add(y.negate())}is0(){return this.equals(f.ZERO)}wNAF(y){return h.wNAFCached(this,u,y,g=>{const p=n.invertBatch(g.map(w=>w.pz));return g.map((w,b)=>w.toAffine(p[b])).map(f.fromAffine)})}multiplyUnsafe(y){const g=f.ZERO;if(y===it)return g;if(a(y),y===$e)return this;const{endo:p}=t;if(!p)return h.unsafeLadder(this,y);let{k1neg:w,k1:b,k2neg:T,k2:A}=p.splitScalar(y),O=g,U=g,C=this;for(;b>it||A>it;)b&$e&&(O=O.add(C)),A&$e&&(U=U.add(C)),C=C.double(),b>>=$e,A>>=$e;return w&&(O=O.negate()),T&&(U=U.negate()),U=new f(n.mul(U.px,p.beta),U.py,U.pz),O.add(U)}multiply(y){a(y);let g=y,p,w;const{endo:b}=t;if(b){const{k1neg:T,k1:A,k2neg:O,k2:U}=b.splitScalar(g);let{p:C,f:_}=this.wNAF(A),{p:N,f:H}=this.wNAF(U);C=h.constTimeNegate(T,C),N=h.constTimeNegate(O,N),N=new f(n.mul(N.px,b.beta),N.py,N.pz),p=C.add(N),w=_.add(H)}else{const{p:T,f:A}=this.wNAF(g);p=T,w=A}return f.normalizeZ([p,w])[0]}multiplyAndAddUnsafe(y,g,p){const w=f.BASE,b=(A,O)=>O===it||O===$e||!A.equals(w)?A.multiplyUnsafe(O):A.multiply(O),T=b(this,g).add(b(y,p));return T.is0()?void 0:T}toAffine(y){const{px:g,py:p,pz:w}=this,b=this.is0();y==null&&(y=b?n.ONE:n.inv(w));const T=n.mul(g,y),A=n.mul(p,y),O=n.mul(w,y);if(b)return{x:n.ZERO,y:n.ZERO};if(!n.eql(O,n.ONE))throw new Error("invZ was invalid");return{x:T,y:A}}isTorsionFree(){const{h:y,isTorsionFree:g}=t;if(y===$e)return!0;if(g)return g(f,this);throw new Error("isTorsionFree() has not been declared for the elliptic curve")}clearCofactor(){const{h:y,clearCofactor:g}=t;return y===$e?this:g?g(f,this):this.multiplyUnsafe(t.h)}toRawBytes(y=!0){return this.assertValidity(),r(f,this,y)}toHex(y=!0){return Qn(this.toRawBytes(y))}}f.BASE=new f(t.Gx,t.Gy,n.ONE),f.ZERO=new f(n.ZERO,n.ONE,n.ZERO);const d=t.nBitLength,h=Q0(f,t.endo?Math.ceil(d/2):d);return{CURVE:t,ProjectivePoint:f,normPrivateKeyToScalar:c,weierstrassEquation:o,isWithinCurveOrder:i}}function sp(e){const t=Pu(e);return lr(t,{hash:"hash",hmac:"function",randomBytes:"function"},{bits2int:"function",bits2int_modN:"function",lowS:"boolean"}),Object.freeze({lowS:!0,...t})}function op(e){const t=sp(e),{Fp:n,n:r}=t,s=n.BYTES+1,o=2*n.BYTES+1;function i(x){return itQn(Gn(x,t.nByteLength));function m(x){const k=r>>$e;return x>k}function y(x){return m(x)?a(-x):x}const g=(x,k,I)=>nn(x.slice(k,I));class p{constructor(k,I,L){this.r=k,this.s=I,this.recovery=L,this.assertValidity()}static fromCompact(k){const I=t.nByteLength;return k=et("compactSignature",k,I*2),new p(g(k,0,I),g(k,I,2*I))}static fromDER(k){const{r:I,s:L}=vn.toSig(et("DER",k));return new p(I,L)}assertValidity(){if(!d(this.r))throw new Error("r must be 0 < r < CURVE.n");if(!d(this.s))throw new Error("s must be 0 < s < CURVE.n")}addRecoveryBit(k){return new p(this.r,this.s,k)}recoverPublicKey(k){const{r:I,s:L,recovery:P}=this,j=U(et("msgHash",k));if(P==null||![0,1,2,3].includes(P))throw new Error("recovery id invalid");const D=P===2||P===3?I+t.n:I;if(D>=n.ORDER)throw new Error("recovery id 2 or 3 invalid");const q=(P&1)===0?"02":"03",ie=u.fromHex(q+h(D)),oe=c(D),X=a(-j*oe),ue=a(L*oe),fe=u.BASE.multiplyAndAddUnsafe(ie,X,ue);if(!fe)throw new Error("point at infinify");return fe.assertValidity(),fe}hasHighS(){return m(this.s)}normalizeS(){return this.hasHighS()?new p(this.r,a(-this.s),this.recovery):this}toDERRawBytes(){return er(this.toDERHex())}toDERHex(){return vn.hexFromSig({r:this.r,s:this.s})}toCompactRawBytes(){return er(this.toCompactHex())}toCompactHex(){return h(this.r)+h(this.s)}}const w={isValidPrivateKey(x){try{return l(x),!0}catch{return!1}},normPrivateKeyToScalar:l,randomPrivateKey:()=>{const x=t.randomBytes(n.BYTES+8),k=X0(x,r);return Gn(k,t.nByteLength)},precompute(x=8,k=u.BASE){return k._setWindowSize(x),k.multiply(BigInt(3)),k}};function b(x,k=!0){return u.fromPrivateKey(x).toRawBytes(k)}function T(x){const k=x instanceof Uint8Array,I=typeof x=="string",L=(k||I)&&x.length;return k?L===s||L===o:I?L===2*s||L===2*o:x instanceof u}function A(x,k,I=!0){if(T(x))throw new Error("first arg must be private key");if(!T(k))throw new Error("second arg must be public key");return u.fromHex(k).multiply(l(x)).toRawBytes(I)}const O=t.bits2int||function(x){const k=nn(x),I=x.length*8-t.nBitLength;return I>0?k>>BigInt(I):k},U=t.bits2int_modN||function(x){return a(O(x))},C=Wi(t.nBitLength);function _(x){if(typeof x!="bigint")throw new Error("bigint expected");if(!(it<=x&&xce in I))throw new Error("sign() legacy options not supported");const{hash:L,randomBytes:P}=t;let{lowS:j,prehash:D,extraEntropy:q}=I;j==null&&(j=!0),x=et("msgHash",x),D&&(x=et("prehashed msgHash",L(x)));const ie=U(x),oe=l(k),X=[_(oe),_(ie)];if(q!=null){const ce=q===!0?P(n.BYTES):q;X.push(et("extraEntropy",ce,n.BYTES))}const ue=ot(...X),fe=ie;function ke(ce){const me=O(ce);if(!d(me))return;const _t=c(me),Je=u.BASE.multiply(me).toAffine(),Ie=a(Je.x);if(Ie===it)return;const $t=a(_t*a(fe+Ie*oe));if($t===it)return;let wr=(Je.x===Ie?0:2)|Number(Je.y&$e),Ya=$t;return j&&m($t)&&(Ya=y($t),wr^=1),new p(Ie,Ya,wr)}return{seed:ue,k2sig:ke}}const H={lowS:t.lowS,prehash:!1},K={lowS:t.lowS,prehash:!1};function v(x,k,I=H){const{seed:L,k2sig:P}=N(x,k,I);return Iu(t.hash.outputLen,t.nByteLength,t.hmac)(L,P)}u.BASE._setWindowSize(8);function S(x,k,I,L=K){var Je;const P=x;if(k=et("msgHash",k),I=et("publicKey",I),"strict"in L)throw new Error("options.strict was renamed to lowS");const{lowS:j,prehash:D}=L;let q,ie;try{if(typeof P=="string"||P instanceof Uint8Array)try{q=p.fromDER(P)}catch(Ie){if(!(Ie instanceof vn.Err))throw Ie;q=p.fromCompact(P)}else if(typeof P=="object"&&typeof P.r=="bigint"&&typeof P.s=="bigint"){const{r:Ie,s:$t}=P;q=new p(Ie,$t)}else throw new Error("PARSE");ie=u.fromHex(I)}catch(Ie){if(Ie.message==="PARSE")throw new Error("signature must be Signature instance, Uint8Array or hex string");return!1}if(j&&q.hasHighS())return!1;D&&(k=t.hash(k));const{r:oe,s:X}=q,ue=U(k),fe=c(X),ke=a(ue*fe),ce=a(oe*fe),me=(Je=u.BASE.multiplyAndAddUnsafe(ie,ke,ce))==null?void 0:Je.toAffine();return me?a(me.x)===oe:!1}return{CURVE:t,getPublicKey:b,getSharedSecret:A,sign:v,verify:S,ProjectivePoint:u,Signature:p,utils:w}}function ip(e,t){const n=e.ORDER;let r=it;for(let d=n-$e;d%At===it;d/=At)r+=$e;const s=r,o=(n-$e)/At**s,i=(o-$e)/At,a=At**s-$e,c=At**(s-$e),u=e.pow(t,o),l=e.pow(t,(o+$e)/At);let f=(d,h)=>{let m=u,y=e.pow(h,a),g=e.sqr(y);g=e.mul(g,h);let p=e.mul(d,g);p=e.pow(p,i),p=e.mul(p,y),y=e.mul(p,h),g=e.mul(p,d);let w=e.mul(g,y);p=e.pow(w,c);let b=e.eql(p,e.ONE);y=e.mul(g,l),p=e.mul(w,m),g=e.cmov(y,g,b),w=e.cmov(p,w,b);for(let T=s;T>1;T--){let A=At**(T-At),O=e.pow(w,A);const U=e.eql(O,e.ONE);y=e.mul(g,m),m=e.mul(m,m),O=e.mul(w,m),g=e.cmov(y,g,U),w=e.cmov(O,w,U)}return{isValid:b,value:g}};if(e.ORDER%rc===Bs){const d=(e.ORDER-Bs)/rc,h=e.sqrt(e.neg(t));f=(m,y)=>{let g=e.sqr(y);const p=e.mul(m,y);g=e.mul(g,p);let w=e.pow(g,d);w=e.mul(w,p);const b=e.mul(w,h),T=e.mul(e.sqr(w),y),A=e.eql(T,m);let O=e.cmov(b,w,A);return{isValid:A,value:O}}}return f}function ap(e,t){if(Ou(e),!e.isValid(t.A)||!e.isValid(t.B)||!e.isValid(t.Z))throw new Error("mapToCurveSimpleSWU: invalid opts");const n=ip(e,t.Z);if(!e.isOdd)throw new Error("Fp.isOdd is not implemented!");return r=>{let s,o,i,a,c,u,l,f;s=e.sqr(r),s=e.mul(s,t.Z),o=e.sqr(s),o=e.add(o,s),i=e.add(o,e.ONE),i=e.mul(i,t.B),a=e.cmov(t.Z,e.neg(o),!e.eql(o,e.ZERO)),a=e.mul(a,t.A),o=e.sqr(i),u=e.sqr(a),c=e.mul(u,t.A),o=e.add(o,c),o=e.mul(o,i),u=e.mul(u,a),c=e.mul(u,t.B),o=e.add(o,c),l=e.mul(s,i);const{isValid:d,value:h}=n(o,u);f=e.mul(s,r),f=e.mul(f,h),l=e.cmov(l,i,d),f=e.cmov(f,h,d);const m=e.isOdd(r)===e.isOdd(f);return f=e.cmov(e.neg(f),f,m),l=e.div(l,a),{x:l,y:f}}}function cp(e){if(e instanceof Uint8Array)return e;if(typeof e=="string")return ao(e);throw new Error("DST must be Uint8Array or string")}const up=nn;function Qt(e,t){if(e<0||e>=1<<8*t)throw new Error(`bad I2OSP call: value=${e} length=${t}`);const n=Array.from({length:t}).fill(0);for(let r=t-1;r>=0;r--)n[r]=e&255,e>>>=8;return new Uint8Array(n)}function fp(e,t){const n=new Uint8Array(e.length);for(let r=0;r255&&(t=r(ot(ao("H2C-OVERSIZE-DST-"),t)));const{outputLen:s,blockLen:o}=r,i=Math.ceil(n/s);if(i>255)throw new Error("Invalid xmd length");const a=ot(t,Qt(t.length,1)),c=Qt(0,o),u=Qt(n,2),l=new Array(i),f=r(ot(c,e,u,Qt(0,1),a));l[0]=r(ot(f,Qt(1,1),a));for(let h=1;h<=i;h++){const m=[fp(f,l[h-1]),Qt(h+1,1),a];l[h]=r(ot(...m))}return ot(...l).slice(0,n)}function dp(e,t,n,r,s){if(Br(e),Br(t),Xi(n),t.length>255){const o=Math.ceil(2*r/8);t=s.create({dkLen:o}).update(ao("H2C-OVERSIZE-DST-")).update(t).digest()}if(n>65535||t.length>255)throw new Error("expand_message_xof: invalid lenInBytes");return s.create({dkLen:n}).update(e).update(Qt(n,2)).update(t).update(Qt(t.length,1)).digest()}function sc(e,t,n){lr(n,{DST:"string",p:"bigint",m:"isSafeInteger",k:"isSafeInteger",hash:"hash"});const{p:r,k:s,m:o,hash:i,expand:a,DST:c}=n;Br(e),Xi(t);const u=cp(c),l=r.toString(2).length,f=Math.ceil((l+s)/8),d=t*o*f;let h;if(a==="xmd")h=lp(e,u,d,i);else if(a==="xof")h=dp(e,u,d,s,i);else if(a===void 0)h=e;else throw new Error('expand must be "xmd", "xof" or undefined');const m=new Array(t);for(let y=0;yArray.from(r).reverse());return(r,s)=>{const[o,i,a,c]=n.map(u=>u.reduce((l,f)=>e.add(e.mul(l,r),f)));return r=e.div(o,i),s=e.mul(s,e.div(a,c)),{x:r,y:s}}}function pp(e,t,n){if(typeof t!="function")throw new Error("mapToCurve() must be defined");return{hashToCurve(r,s){const o=sc(r,2,{...n,DST:n.DST,...s}),i=e.fromAffine(t(o[0])),a=e.fromAffine(t(o[1])),c=i.add(a).clearCofactor();return c.assertValidity(),c},encodeToCurve(r,s){const o=sc(r,1,{...n,DST:n.encodeDST,...s}),i=e.fromAffine(t(o[0])).clearCofactor();return i.assertValidity(),i}}}let Uu=class extends ku{constructor(t,n){super(),this.finished=!1,this.destroyed=!1,xn.hash(t);const r=qi(n);if(this.iHash=t.create(),typeof this.iHash.update!="function")throw new TypeError("Expected instance of class which extends utils.Hash");this.blockLen=this.iHash.blockLen,this.outputLen=this.iHash.outputLen;const s=this.blockLen,o=new Uint8Array(s);o.set(r.length>s?t.create().update(r).digest():r);for(let i=0;inew Uu(e,t).update(n).digest();Nu.create=(e,t)=>new Uu(e,t);/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */function gp(e){return{hash:e,hmac:(t,...n)=>Nu(e,t,$0(...n)),randomBytes:A0}}function mp(e,t){const n=r=>op({...e,...gp(r)});return Object.freeze({...n(t),create:n})}/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */const Lu=BigInt("0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f"),oc=BigInt("0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141"),yp=BigInt(1),hi=BigInt(2),ic=(e,t)=>(e+t/hi)/t;function bp(e){const t=Lu,n=BigInt(3),r=BigInt(6),s=BigInt(11),o=BigInt(22),i=BigInt(23),a=BigInt(44),c=BigInt(88),u=e*e*e%t,l=u*u*e%t,f=Qe(l,n,t)*l%t,d=Qe(f,n,t)*l%t,h=Qe(d,hi,t)*u%t,m=Qe(h,s,t)*h%t,y=Qe(m,o,t)*m%t,g=Qe(y,a,t)*y%t,p=Qe(g,c,t)*g%t,w=Qe(p,a,t)*y%t,b=Qe(w,n,t)*l%t,T=Qe(b,i,t)*m%t,A=Qe(T,r,t)*u%t,O=Qe(A,hi,t);if(!on.eql(on.sqr(O),e))throw new Error("Cannot find square root");return O}const on=Cu(Lu,void 0,void 0,{sqrt:bp}),Nt=mp({a:BigInt(0),b:BigInt(7),Fp:on,n:oc,Gx:BigInt("55066263022277343669578718895168534326250603453777594175500187360389116729240"),Gy:BigInt("32670510020758816978083085130507043184471273380659243275938904335757337482424"),h:BigInt(1),lowS:!0,endo:{beta:BigInt("0x7ae96a2b657c07106e64479eac3434e99cf0497512f58995c1396c28719501ee"),splitScalar:e=>{const t=oc,n=BigInt("0x3086d221a7d46bcde86c90e49284eb15"),r=-yp*BigInt("0xe4437ed6010e88286f547fa90abfe4c3"),s=BigInt("0x114ca50f7a8e2f3f657c1108d9d44cfd8"),o=n,i=BigInt("0x100000000000000000000000000000000"),a=ic(o*e,t),c=ic(-r*e,t);let u=Ne(e-a*n-c*s,t),l=Ne(-a*r-c*o,t);const f=u>i,d=l>i;if(f&&(u=t-u),d&&(l=t-l),u>i||l>i)throw new Error("splitScalar: Endomorphism failed, k="+e);return{k1neg:f,k1:u,k2neg:d,k2:l}}}},Au);BigInt(0);Nt.ProjectivePoint;Nt.utils.randomPrivateKey;const wp=hp(on,[["0x8e38e38e38e38e38e38e38e38e38e38e38e38e38e38e38e38e38e38daaaaa8c7","0x7d3d4c80bc321d5b9f315cea7fd44c5d595d2fc0bf63b92dfff1044f17c6581","0x534c328d23f234e6e2a413deca25caece4506144037c40314ecbd0b53d9dd262","0x8e38e38e38e38e38e38e38e38e38e38e38e38e38e38e38e38e38e38daaaaa88c"],["0xd35771193d94918a9ca34ccbb7b640dd86cd409542f8487d9fe6b745781eb49b","0xedadc6f64383dc1df7c4b2d51b54225406d36b641f5e41bbc52a56612a8c6d14","0x0000000000000000000000000000000000000000000000000000000000000001"],["0x4bda12f684bda12f684bda12f684bda12f684bda12f684bda12f684b8e38e23c","0xc75e0c32d5cb7c0fa9d0a54b12a0a6d5647ab046d686da6fdffc90fc201d71a3","0x29a6194691f91a73715209ef6512e576722830a201be2018a765e85a9ecee931","0x2f684bda12f684bda12f684bda12f684bda12f684bda12f684bda12f38e38d84"],["0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffefffff93b","0x7a06534bb8bdb49fd5e9e6632722c2989467c1bfc8e8d978dfb425d2685c2573","0x6484aa716545ca2cf3a70c3fa8fe337e0a3d21162f0d6299a7bf8192bfd2a76f","0x0000000000000000000000000000000000000000000000000000000000000001"]].map(e=>e.map(t=>BigInt(t)))),xp=ap(on,{A:BigInt("0x3f8731abdd661adca08a5558f0f5d272e953d363cb6f0e5d405447c01a444533"),B:BigInt("1771"),Z:on.create(BigInt("-11"))});pp(Nt.ProjectivePoint,e=>{const{x:t,y:n}=xp(on.create(e[0]));return wp(t,n)},{DST:"secp256k1_XMD:SHA-256_SSWU_RO_",encodeDST:"secp256k1_XMD:SHA-256_SSWU_NU_",p:on.ORDER,m:1,k:128,expand:"xmd",hash:Au});function pi(e){if(!Number.isSafeInteger(e)||e<0)throw new Error(`Wrong positive integer: ${e}`)}function vp(e){if(typeof e!="boolean")throw new Error(`Expected boolean, not ${e}`)}function Ru(e,...t){if(!(e instanceof Uint8Array))throw new TypeError("Expected Uint8Array");if(t.length>0&&!t.includes(e.length))throw new TypeError(`Expected Uint8Array of length ${t}, not of length=${e.length}`)}function Ep(e){if(typeof e!="function"||typeof e.create!="function")throw new Error("Hash should be wrapped by utils.wrapConstructor");pi(e.outputLen),pi(e.blockLen)}function Sp(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 kp(e,t){Ru(e);const n=t.outputLen;if(e.lengthnew DataView(e.buffer,e.byteOffset,e.byteLength),gt=(e,t)=>e<<32-t|e>>>t,$p=new Uint8Array(new Uint32Array([287454020]).buffer)[0]===68;if(!$p)throw new Error("Non little-endian hardware is not supported");Array.from({length:256},(e,t)=>t.toString(16).padStart(2,"0"));function Ap(e){if(typeof e!="string")throw new TypeError(`utf8ToBytes expected string, got ${typeof e}`);return new TextEncoder().encode(e)}function Hu(e){if(typeof e=="string"&&(e=Ap(e)),!(e instanceof Uint8Array))throw new TypeError(`Expected input type is Uint8Array (got ${typeof e})`);return e}let Bp=class{clone(){return this._cloneInto()}};function ju(e){const t=r=>e().update(Hu(r)).digest(),n=e();return t.outputLen=n.outputLen,t.blockLen=n.blockLen,t.create=()=>e(),t}function Tp(e,t,n,r){if(typeof e.setBigUint64=="function")return e.setBigUint64(t,n,r);const s=BigInt(32),o=BigInt(4294967295),i=Number(n>>s&o),a=Number(n&o),c=r?4:0,u=r?0:4;e.setUint32(t+c,i,r),e.setUint32(t+u,a,r)}let Ip=class extends Bp{constructor(t,n,r,s){super(),this.blockLen=t,this.outputLen=n,this.padOffset=r,this.isLE=s,this.finished=!1,this.length=0,this.pos=0,this.destroyed=!1,this.buffer=new Uint8Array(t),this.view=Ro(this.buffer)}update(t){Lo.exists(this);const{view:n,buffer:r,blockLen:s}=this;t=Hu(t);const o=t.length;for(let i=0;is-i&&(this.process(r,0),i=0);for(let f=i;fl.length)throw new Error("_sha2: outputLen bigger than state");for(let f=0;fe&t^~e&n,Cp=(e,t,n)=>e&t^e&n^t&n,Pp=new Uint32Array([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]),Zt=new Uint32Array([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]),Mt=new Uint32Array(64);let Ku=class extends Ip{constructor(){super(64,32,8,!1),this.A=Zt[0]|0,this.B=Zt[1]|0,this.C=Zt[2]|0,this.D=Zt[3]|0,this.E=Zt[4]|0,this.F=Zt[5]|0,this.G=Zt[6]|0,this.H=Zt[7]|0}get(){const{A:t,B:n,C:r,D:s,E:o,F:i,G:a,H:c}=this;return[t,n,r,s,o,i,a,c]}set(t,n,r,s,o,i,a,c){this.A=t|0,this.B=n|0,this.C=r|0,this.D=s|0,this.E=o|0,this.F=i|0,this.G=a|0,this.H=c|0}process(t,n){for(let f=0;f<16;f++,n+=4)Mt[f]=t.getUint32(n,!1);for(let f=16;f<64;f++){const d=Mt[f-15],h=Mt[f-2],m=gt(d,7)^gt(d,18)^d>>>3,y=gt(h,17)^gt(h,19)^h>>>10;Mt[f]=y+Mt[f-7]+m+Mt[f-16]|0}let{A:r,B:s,C:o,D:i,E:a,F:c,G:u,H:l}=this;for(let f=0;f<64;f++){const d=gt(a,6)^gt(a,11)^gt(a,25),h=l+d+Op(a,c,u)+Pp[f]+Mt[f]|0,y=(gt(r,2)^gt(r,13)^gt(r,22))+Cp(r,s,o)|0;l=u,u=c,c=a,a=i+h|0,i=o,o=s,s=r,r=h+y|0}r=r+this.A|0,s=s+this.B|0,o=o+this.C|0,i=i+this.D|0,a=a+this.E|0,c=c+this.F|0,u=u+this.G|0,l=l+this.H|0,this.set(r,s,o,i,a,c,u,l)}roundClean(){Mt.fill(0)}destroy(){this.set(0,0,0,0,0,0,0,0),this.buffer.fill(0)}},Up=class extends Ku{constructor(){super(),this.A=-1056596264,this.B=914150663,this.C=812702999,this.D=-150054599,this.E=-4191439,this.F=1750603025,this.G=1694076839,this.H=-1090891868,this.outputLen=28}};const gi=ju(()=>new Ku);ju(()=>new Up);function Np(e,t){if(e.length>t)throw new TypeError(`Data is larger than array size: ${e.length} > ${t}`)}function Lp(e){if(e.match(/[^a-fA-f0-9]/)!==null)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}`)}function Rp(e){if(e>Number.MAX_SAFE_INTEGER)throw new TypeError("Number exceeds safe bounds!")}const{getRandomValues:Hp}=crypto??globalThis.crypto??window.crypto;function jp(e=32){if(typeof Hp=="function")return crypto.getRandomValues(new Uint8Array(e));throw new Error("Crypto module missing getRandomValues!")}function Kp(e,t,n="be"){t===void 0&&(t=e.length),Np(e,t);const r=new Uint8Array(t).fill(0),s=n==="be"?0:t-e.length;return r.set(e,s),r}function Du(e){let t,n=0;const r=e.reduce((o,i)=>o+i.length,0),s=new Uint8Array(r);for(t=0;t0||(i.length^a)>0?"":"1";c in o||u>0;)l=o[c],l=l>0?l*256+u:u,u=l/s|0,o[c]=l%s,c++;for(;c-- >0;)i+=r[o[c]];return n&&i.length%4>0?i+"=".repeat(4-i.length%4):i}function Vp(e,t){const n=Zu(t),r=n.length,s=[],o=[];e=e.replace("=","");let i,a=0,c,u;for(i=0;i0||(o.length^i)>0||o.push(0);a in s||c>0;)u=s[a],u=u>0?u*r+c:c,c=u>>8,s[a]=u%256,a++}for(;a-- >0;)o.push(s[a]);return new Uint8Array(o)}function Mu(e){return gi(gi(e))}function qp(e){const t=Mu(e);return Du([e,t.slice(0,4)])}function zp(e){const t=e.slice(0,-4),n=e.slice(-4);if(Mu(t).slice(0,4).toString()!==n.toString())throw new Error("Invalid checksum!");return t}const ac={encode:Mp,decode:Vp},Vu={encode:e=>{const t=qp(e);return ac.encode(t,"base58")},decode:e=>{const t=ac.decode(e,"base58");return zp(t)}},qu="qpzry9x8gf2tvdw0s3jn54khce6mua7l",Fp=[996825010,642813549,513874426,1027748829,705979059],Ts=[{version:0,name:"bech32",const:1},{version:1,name:"bech32m",const:734539939}];function zu(e){let t=1;for(let n=0;n>25;t=(t&33554431)<<5^e[n];for(let s=0;s<5;++s)(r>>s&1)!==0&&(t^=Fp[s])}return t}function Fu(e){const t=[];let n;for(n=0;n>5);for(t.push(0),n=0;n>5*(5-i)&31);return o}function Gu(e,t,n,r=!0){const s=[];let o=0,i=0;const a=(1<>t>0)throw new Error("Failed to perform base conversion. Invalid value: "+String(u));for(o=(o<=n;)i-=n,s.push(o>>i&a)}if(r)i>0&&s.push(o<=t||(o<0)throw new Error("Failed to perform base conversion. Invalid Size!");return s}function Yp(e,t,n){const r=t.concat(Wp(e,t,n));let s=e+"1";for(let o=0;oo.version===t[0])??Ts[0];if(!Gp(r,t,s))throw new Error("Checksum verification failed!");return[r,t.slice(0,t.length-6)]}function Xp(e){let t,n,r=!1,s=!1;for(t=0;t126)return!1;n>=97&&n<=122&&(r=!0),n>=65&&n<=90&&(s=!0)}return!(r&&s)}function Jp(e){const t=e.lastIndexOf("1");return!(t<1||t+7>e.length||e.length>90)}function Qp(e,t="bc",n=0){const r=[n,...Gu([...e],8,5)],s=Ts.find(i=>i.version===n)??Ts[0],o=Yp(t,r,s);return Yu(o),o}function Yu(e){e=e.toLowerCase();const t=e.split("1",1)[0],[n,r]=Wu(e),s=Gu(r.slice(1),5,8,!1),o=s.length;switch(!0){case t!==n:throw new Error("Returned hrp string is invalid.");case(s===null||o<2||o>40):throw new Error("Decoded string is invalid or out of spec.");case r[0]>16:throw new Error("Returned version bit is out of range.");default:return Uint8Array.from(s)}}function eg(e){e=e.toLowerCase();const[t,n]=Wu(e);return n[0]}const Xu={encode:Qp,decode:Yu,version:eg},Ju="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",Qu="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",tg=new TextEncoder;function ef(e,t=!1,n=!0){typeof e=="string"&&(e=tg.encode(e));const r=t?Qu:Ju;let s="",o=0,i=0;for(let a=0;a=6;)o-=6,s+=r[i>>o&63];if(o>0)for(i<<=6-o,s+=r[i&63];o<6;)s+=n?"=":"",o+=2;return s}function tf(e,t=!1){const n=t||e.includes("-")||e.includes("_")?Qu.split(""):Ju.split("");e=e.replace(/=+$/,"");const r=e.split("");let s=0,o=0;const i=[];for(let a=0;a=8&&(s-=8,i.push(o>>>s&255))}return new Uint8Array(i)}const nf={encode:ef,decode:tf},rf={encode:e=>ef(e,!0,!1),decode:e=>tf(e,!0)},ng=BigInt(0),rg=BigInt(255),sf=BigInt(256);function sg(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.")}function og(e,t,n="be"){t===void 0&&(t=sg(e));const r=n==="le",s=new ArrayBuffer(t),o=new DataView(s);let i=r?0:t-1;for(;e>ng;){const a=e&rg,c=Number(a);r?o.setUint8(i++,c):o.setUint8(i--,c),e=(e-a)/sf}return new Uint8Array(s)}function ig(e){let t=BigInt(0);for(let n=e.length-1;n>=0;n--)t=t*sf+BigInt(e[n]);return BigInt(t)}function ag(e){const t=e.split("").map(Number);if(t.length%8!==0)throw new Error(`Binary array is invalid length: ${e.length}`);const n=new Uint8Array(t.length/8);for(let r=0,s=0;r255)throw new Error(`Invalid byte value: ${r}. Byte values must be between 0 and 255.`);for(let s=7;s>=0;s--,n++)t[n]=r>>s&1}return t.join("")}function ug(e){if(e<=255)return 1;if(e<=65535)return 2;if(e<=4294967295)return 4;throw new TypeError("Numbers larger than 4 bytes must specify a fixed size!")}function fg(e,t,n="be"){t===void 0&&(t=ug(e));const r=n==="le",s=new ArrayBuffer(t),o=new DataView(s);let i=r?0:t-1;for(;e>0;){const a=e&255;r?o.setUint8(i++,e):o.setUint8(i--,e),e=(e-a)/256}return new Uint8Array(s)}function lg(e){let t=0;for(let n=e.length-1;n>=0;n--)t=t*256+e[n],Rp(t);return t}const dg=new TextEncoder,hg=new TextDecoder;function Ji(e){return dg.encode(e)}function Ho(e){return hg.decode(e)}function pg(e,t){Lp(e);const n=e.length/2;if(t===void 0&&(t=n),n>t)throw new TypeError(`Hex string is larger than array size: ${n} > ${t}`);return t}function gg(e,t,n="le"){t=pg(e,t);const r=n==="le",s=new ArrayBuffer(t),o=new DataView(s);let i=r?0:t-1;for(let a=0;atypeof r=="bigint"?`${r}n`:r);return Ji(t)}function bg(e,t,n){if(e instanceof ArrayBuffer)return new Uint8Array(e);if(e instanceof Uint8Array)return Kp(e,t,n);if(typeof e=="string")return gg(e,t,n);if(typeof e=="bigint")return og(e,t,n);if(typeof e=="number")return fg(e,t,n);if(typeof e=="boolean")return Uint8Array.of(e?1:0);throw TypeError("Unsupported format:"+typeof e)}const ne=class ne extends Uint8Array{static random(t=32){const n=jp(t);return new ne(n,t)}constructor(t,n,r){const s=bg(t,n,r);super(s)}get arr(){return[...this]}get num(){return this.toNum()}get big(){return this.toBig()}get str(){return this.toStr()}get hex(){return this.toHex()}get raw(){return new Uint8Array(this)}get bin(){return this.toBin()}get b58chk(){return this.tob58chk()}get base64(){return this.toBase64()}get b64url(){return this.toB64url()}get digest(){return this.toHash()}get id(){return this.toHash().hex}get stream(){return new Og(this)}toNum(t="be"){const n=t==="be"?this.reverse():this;return lg(n)}toBin(){return cg(this)}toBig(t="be"){const n=t==="be"?this.reverse():this;return ig(n)}toHash(){const t=gi(this);return new ne(t)}toJson(){const t=Ho(this);return JSON.parse(t)}toBech32(t,n=0){return Xu.encode(this,t,n)}toStr(){return Ho(this)}toHex(){return mg(this)}toBytes(){return new Uint8Array(this)}tob58chk(){return Vu.encode(this)}toBase64(){return nf.encode(this)}toB64url(){return rf.encode(this)}prepend(t){return ne.join([ne.bytes(t),this])}append(t){return ne.join([this,ne.bytes(t)])}slice(t,n){const r=new Uint8Array(this).slice(t,n);return new ne(r)}subarray(t,n){const r=new Uint8Array(this).subarray(t,n);return new ne(r)}reverse(){const t=new Uint8Array(this).reverse();return new ne(t)}write(t,n){const r=ne.bytes(t);this.set(r,n)}prefixSize(t){const n=ne.varInt(this.length,t);return ne.join([n,this])}static from(t){return new ne(Uint8Array.from(t))}static of(...t){return new ne(Uint8Array.of(...t))}static join(t){const n=t.map(s=>ne.bytes(s)),r=Du(n);return new ne(r)}static varInt(t,n){if(t<253)return ne.num(t,1);if(t<65536)return ne.of(253,...ne.num(t,2,n));if(t<4294967296)return ne.of(254,...ne.num(t,4,n));if(BigInt(t)<0x10000000000000000n)return ne.of(255,...ne.num(t,8,n));throw new Error(`Value is too large: ${t}`)}};ne.num=wg,ne.big=vg,ne.bin=xg,ne.raw=Eg,ne.str=Sg,ne.hex=kg,ne.bytes=_g,ne.json=$g,ne.base64=Ag,ne.b64url=Bg,ne.bech32=Tg,ne.b58chk=Ig,ne.encode=Ji,ne.decode=Ho;let W=ne;function wg(e,t,n){return new W(e,t,n)}function xg(e,t,n){return new W(ag(e),t,n)}function vg(e,t,n){return new W(e,t,n)}function Eg(e,t,n){return new W(e,t,n)}function Sg(e,t,n){return new W(Ji(e),t,n)}function kg(e,t,n){return new W(e,t,n)}function _g(e,t,n){return new W(e,t,n)}function $g(e){return new W(yg(e))}function Ag(e){return new W(nf.decode(e))}function Bg(e){return new W(rf.decode(e))}function Tg(e){return new W(Xu.decode(e))}function Ig(e){return new W(Vu.decode(e))}class Og{constructor(t){this.data=W.bytes(t),this.size=this.data.length}peek(t){if(t>this.size)throw new Error(`Size greater than stream: ${t} > ${this.size}`);return new W(this.data.slice(0,t))}read(t){t=t??this.readSize();const n=this.peek(t);return this.data=this.data.slice(t),this.size=this.data.length,n}readSize(t){const n=this.read(1).num;switch(!0){case(n>=0&&n<253):return n;case n===253:return this.read(2).toNum(t);case n===254:return this.read(4).toNum(t);case n===255:return this.read(8).toNum(t);default:throw new Error(`Varint is out of range: ${n}`)}}}const Is=Nt.CURVE,Qi=Is.n,Cg=Is.p,Pg={x:Is.Gx,y:Is.Gy},Ug=BigInt(0);BigInt(1);BigInt(2);BigInt(3);BigInt(4);const mi={N:Qi,P:Cg,G:Pg,_0n:Ug},xr=Cu(Qi,32,!0),of=e=>Ne(e,Qi);function ea(e,t=!1){if(t)throw new Error(e);return!1}function af(e){return W.random(e)}function Ng(e){const t=W.bytes(e).big;return W.big(of(t),32)}var Lg=Object.freeze({__proto__:null,fail:ea,mod_bytes:Ng,random:af});const{N:Rg,_0n:Hg}=mi;function jg(e,t,n){const r=W.bytes(e);return r.length!==t?ea(`Invalid byte size: ${r.hex} !== ${t}`,n):!0}function Kg(e,t){return typeof e=="bigint"&&Hgthis.big}lt(t){return new be(t).big0&&!t.includes(e.length))throw new Error(`Expected Uint8Array of length ${t}, not of length=${e.length}`)}function Vg(e){if(typeof e!="function"||typeof e.create!="function")throw new Error("Hash should be wrapped by utils.wrapConstructor");yi(e.outputLen),yi(e.blockLen)}function qg(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 zg(e,t){cf(e);const n=t.outputLen;if(e.lengthe instanceof Uint8Array,jo=e=>new DataView(e.buffer,e.byteOffset,e.byteLength),mt=(e,t)=>e<<32-t|e>>>t,Wg=new Uint8Array(new Uint32Array([287454020]).buffer)[0]===68;if(!Wg)throw new Error("Non little-endian hardware is not supported");Array.from({length:256},(e,t)=>t.toString(16).padStart(2,"0"));function Yg(e){if(typeof e!="string")throw new Error(`utf8ToBytes expected string, got ${typeof e}`);return new Uint8Array(new TextEncoder().encode(e))}function ta(e){if(typeof e=="string"&&(e=Yg(e)),!Gg(e))throw new Error(`expected Uint8Array, got ${typeof e}`);return e}let uf=class{clone(){return this._cloneInto()}};function Kn(e){const t=r=>e().update(ta(r)).digest(),n=e();return t.outputLen=n.outputLen,t.blockLen=n.blockLen,t.create=()=>e(),t}function Xg(e,t,n,r){if(typeof e.setBigUint64=="function")return e.setBigUint64(t,n,r);const s=BigInt(32),o=BigInt(4294967295),i=Number(n>>s&o),a=Number(n&o),c=r?4:0,u=r?0:4;e.setUint32(t+c,i,r),e.setUint32(t+u,a,r)}class na extends uf{constructor(t,n,r,s){super(),this.blockLen=t,this.outputLen=n,this.padOffset=r,this.isLE=s,this.finished=!1,this.length=0,this.pos=0,this.destroyed=!1,this.buffer=new Uint8Array(t),this.view=jo(this.buffer)}update(t){En.exists(this);const{view:n,buffer:r,blockLen:s}=this;t=ta(t);const o=t.length;for(let i=0;is-i&&(this.process(r,0),i=0);for(let f=i;fl.length)throw new Error("_sha2: outputLen bigger than state");for(let f=0;fe&t^~e&n,Qg=(e,t,n)=>e&t^e&n^t&n,em=new Uint32Array([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]),Vt=new Uint32Array([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]),qt=new Uint32Array(64);let ff=class extends na{constructor(){super(64,32,8,!1),this.A=Vt[0]|0,this.B=Vt[1]|0,this.C=Vt[2]|0,this.D=Vt[3]|0,this.E=Vt[4]|0,this.F=Vt[5]|0,this.G=Vt[6]|0,this.H=Vt[7]|0}get(){const{A:t,B:n,C:r,D:s,E:o,F:i,G:a,H:c}=this;return[t,n,r,s,o,i,a,c]}set(t,n,r,s,o,i,a,c){this.A=t|0,this.B=n|0,this.C=r|0,this.D=s|0,this.E=o|0,this.F=i|0,this.G=a|0,this.H=c|0}process(t,n){for(let f=0;f<16;f++,n+=4)qt[f]=t.getUint32(n,!1);for(let f=16;f<64;f++){const d=qt[f-15],h=qt[f-2],m=mt(d,7)^mt(d,18)^d>>>3,y=mt(h,17)^mt(h,19)^h>>>10;qt[f]=y+qt[f-7]+m+qt[f-16]|0}let{A:r,B:s,C:o,D:i,E:a,F:c,G:u,H:l}=this;for(let f=0;f<64;f++){const d=mt(a,6)^mt(a,11)^mt(a,25),h=l+d+Jg(a,c,u)+em[f]+qt[f]|0,y=(mt(r,2)^mt(r,13)^mt(r,22))+Qg(r,s,o)|0;l=u,u=c,c=a,a=i+h|0,i=o,o=s,s=r,r=h+y|0}r=r+this.A|0,s=s+this.B|0,o=o+this.C|0,i=i+this.D|0,a=a+this.E|0,c=c+this.F|0,u=u+this.G|0,l=l+this.H|0,this.set(r,s,o,i,a,c,u,l)}roundClean(){qt.fill(0)}destroy(){this.set(0,0,0,0,0,0,0,0),this.buffer.fill(0)}};class tm extends ff{constructor(){super(),this.A=-1056596264,this.B=914150663,this.C=812702999,this.D=-150054599,this.E=-4191439,this.F=1750603025,this.G=1694076839,this.H=-1090891868,this.outputLen=28}}const Os=Kn(()=>new ff);Kn(()=>new tm);const ss=BigInt(2**32-1),bi=BigInt(32);function lf(e,t=!1){return t?{h:Number(e&ss),l:Number(e>>bi&ss)}:{h:Number(e>>bi&ss)|0,l:Number(e&ss)|0}}function nm(e,t=!1){let n=new Uint32Array(e.length),r=new Uint32Array(e.length);for(let s=0;sBigInt(e>>>0)<>>0),sm=(e,t,n)=>e>>>n,om=(e,t,n)=>e<<32-n|t>>>n,im=(e,t,n)=>e>>>n|t<<32-n,am=(e,t,n)=>e<<32-n|t>>>n,cm=(e,t,n)=>e<<64-n|t>>>n-32,um=(e,t,n)=>e>>>n-32|t<<64-n,fm=(e,t)=>t,lm=(e,t)=>e,dm=(e,t,n)=>e<>>32-n,hm=(e,t,n)=>t<>>32-n,pm=(e,t,n)=>t<>>64-n,gm=(e,t,n)=>e<>>64-n;function mm(e,t,n,r){const s=(t>>>0)+(r>>>0);return{h:e+n+(s/2**32|0)|0,l:s|0}}const ym=(e,t,n)=>(e>>>0)+(t>>>0)+(n>>>0),bm=(e,t,n,r)=>t+n+r+(e/2**32|0)|0,wm=(e,t,n,r)=>(e>>>0)+(t>>>0)+(n>>>0)+(r>>>0),xm=(e,t,n,r,s)=>t+n+r+s+(e/2**32|0)|0,vm=(e,t,n,r,s)=>(e>>>0)+(t>>>0)+(n>>>0)+(r>>>0)+(s>>>0),Em=(e,t,n,r,s,o)=>t+n+r+s+o+(e/2**32|0)|0,Sm={fromBig:lf,split:nm,toBig:rm,shrSH:sm,shrSL:om,rotrSH:im,rotrSL:am,rotrBH:cm,rotrBL:um,rotr32H:fm,rotr32L:lm,rotlSH:dm,rotlSL:hm,rotlBH:pm,rotlBL:gm,add:mm,add3L:ym,add3H:bm,add4L:wm,add4H:xm,add5H:Em,add5L:vm};var te=Sm;const[km,_m]=te.split(["0x428a2f98d728ae22","0x7137449123ef65cd","0xb5c0fbcfec4d3b2f","0xe9b5dba58189dbbc","0x3956c25bf348b538","0x59f111f1b605d019","0x923f82a4af194f9b","0xab1c5ed5da6d8118","0xd807aa98a3030242","0x12835b0145706fbe","0x243185be4ee4b28c","0x550c7dc3d5ffb4e2","0x72be5d74f27b896f","0x80deb1fe3b1696b1","0x9bdc06a725c71235","0xc19bf174cf692694","0xe49b69c19ef14ad2","0xefbe4786384f25e3","0x0fc19dc68b8cd5b5","0x240ca1cc77ac9c65","0x2de92c6f592b0275","0x4a7484aa6ea6e483","0x5cb0a9dcbd41fbd4","0x76f988da831153b5","0x983e5152ee66dfab","0xa831c66d2db43210","0xb00327c898fb213f","0xbf597fc7beef0ee4","0xc6e00bf33da88fc2","0xd5a79147930aa725","0x06ca6351e003826f","0x142929670a0e6e70","0x27b70a8546d22ffc","0x2e1b21385c26c926","0x4d2c6dfc5ac42aed","0x53380d139d95b3df","0x650a73548baf63de","0x766a0abb3c77b2a8","0x81c2c92e47edaee6","0x92722c851482353b","0xa2bfe8a14cf10364","0xa81a664bbc423001","0xc24b8b70d0f89791","0xc76c51a30654be30","0xd192e819d6ef5218","0xd69906245565a910","0xf40e35855771202a","0x106aa07032bbd1b8","0x19a4c116b8d2d0c8","0x1e376c085141ab53","0x2748774cdf8eeb99","0x34b0bcb5e19b48a8","0x391c0cb3c5c95a63","0x4ed8aa4ae3418acb","0x5b9cca4f7763e373","0x682e6ff3d6b2b8a3","0x748f82ee5defb2fc","0x78a5636f43172f60","0x84c87814a1f0ab72","0x8cc702081a6439ec","0x90befffa23631e28","0xa4506cebde82bde9","0xbef9a3f7b2c67915","0xc67178f2e372532b","0xca273eceea26619c","0xd186b8c721c0c207","0xeada7dd6cde0eb1e","0xf57d4f7fee6ed178","0x06f067aa72176fba","0x0a637dc5a2c898a6","0x113f9804bef90dae","0x1b710b35131c471b","0x28db77f523047d84","0x32caab7b40c72493","0x3c9ebe0a15c9bebc","0x431d67c49c100d4c","0x4cc5d4becb3e42b6","0x597f299cfc657e2a","0x5fcb6fab3ad6faec","0x6c44198c4a475817"].map(e=>BigInt(e))),zt=new Uint32Array(80),Ft=new Uint32Array(80);let co=class extends na{constructor(){super(128,64,16,!1),this.Ah=1779033703,this.Al=-205731576,this.Bh=-1150833019,this.Bl=-2067093701,this.Ch=1013904242,this.Cl=-23791573,this.Dh=-1521486534,this.Dl=1595750129,this.Eh=1359893119,this.El=-1377402159,this.Fh=-1694144372,this.Fl=725511199,this.Gh=528734635,this.Gl=-79577749,this.Hh=1541459225,this.Hl=327033209}get(){const{Ah:t,Al:n,Bh:r,Bl:s,Ch:o,Cl:i,Dh:a,Dl:c,Eh:u,El:l,Fh:f,Fl:d,Gh:h,Gl:m,Hh:y,Hl:g}=this;return[t,n,r,s,o,i,a,c,u,l,f,d,h,m,y,g]}set(t,n,r,s,o,i,a,c,u,l,f,d,h,m,y,g){this.Ah=t|0,this.Al=n|0,this.Bh=r|0,this.Bl=s|0,this.Ch=o|0,this.Cl=i|0,this.Dh=a|0,this.Dl=c|0,this.Eh=u|0,this.El=l|0,this.Fh=f|0,this.Fl=d|0,this.Gh=h|0,this.Gl=m|0,this.Hh=y|0,this.Hl=g|0}process(t,n){for(let b=0;b<16;b++,n+=4)zt[b]=t.getUint32(n),Ft[b]=t.getUint32(n+=4);for(let b=16;b<80;b++){const T=zt[b-15]|0,A=Ft[b-15]|0,O=te.rotrSH(T,A,1)^te.rotrSH(T,A,8)^te.shrSH(T,A,7),U=te.rotrSL(T,A,1)^te.rotrSL(T,A,8)^te.shrSL(T,A,7),C=zt[b-2]|0,_=Ft[b-2]|0,N=te.rotrSH(C,_,19)^te.rotrBH(C,_,61)^te.shrSH(C,_,6),H=te.rotrSL(C,_,19)^te.rotrBL(C,_,61)^te.shrSL(C,_,6),K=te.add4L(U,H,Ft[b-7],Ft[b-16]),v=te.add4H(K,O,N,zt[b-7],zt[b-16]);zt[b]=v|0,Ft[b]=K|0}let{Ah:r,Al:s,Bh:o,Bl:i,Ch:a,Cl:c,Dh:u,Dl:l,Eh:f,El:d,Fh:h,Fl:m,Gh:y,Gl:g,Hh:p,Hl:w}=this;for(let b=0;b<80;b++){const T=te.rotrSH(f,d,14)^te.rotrSH(f,d,18)^te.rotrBH(f,d,41),A=te.rotrSL(f,d,14)^te.rotrSL(f,d,18)^te.rotrBL(f,d,41),O=f&h^~f&y,U=d&m^~d&g,C=te.add5L(w,A,U,_m[b],Ft[b]),_=te.add5H(C,p,T,O,km[b],zt[b]),N=C|0,H=te.rotrSH(r,s,28)^te.rotrBH(r,s,34)^te.rotrBH(r,s,39),K=te.rotrSL(r,s,28)^te.rotrBL(r,s,34)^te.rotrBL(r,s,39),v=r&o^r&a^o&a,S=s&i^s&c^i&c;p=y|0,w=g|0,y=h|0,g=m|0,h=f|0,m=d|0,{h:f,l:d}=te.add(u|0,l|0,_|0,N|0),u=a|0,l=c|0,a=o|0,c=i|0,o=r|0,i=s|0;const x=te.add3L(N,K,S);r=te.add3H(x,_,H,v),s=x|0}({h:r,l:s}=te.add(this.Ah|0,this.Al|0,r|0,s|0)),{h:o,l:i}=te.add(this.Bh|0,this.Bl|0,o|0,i|0),{h:a,l:c}=te.add(this.Ch|0,this.Cl|0,a|0,c|0),{h:u,l}=te.add(this.Dh|0,this.Dl|0,u|0,l|0),{h:f,l:d}=te.add(this.Eh|0,this.El|0,f|0,d|0),{h,l:m}=te.add(this.Fh|0,this.Fl|0,h|0,m|0),{h:y,l:g}=te.add(this.Gh|0,this.Gl|0,y|0,g|0),{h:p,l:w}=te.add(this.Hh|0,this.Hl|0,p|0,w|0),this.set(r,s,o,i,a,c,u,l,f,d,h,m,y,g,p,w)}roundClean(){zt.fill(0),Ft.fill(0)}destroy(){this.buffer.fill(0),this.set(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0)}};class $m extends co{constructor(){super(),this.Ah=-1942145080,this.Al=424955298,this.Bh=1944164710,this.Bl=-1982016298,this.Ch=502970286,this.Cl=855612546,this.Dh=1738396948,this.Dl=1479516111,this.Eh=258812777,this.El=2077511080,this.Fh=2011393907,this.Fl=79989058,this.Gh=1067287976,this.Gl=1780299464,this.Hh=286451373,this.Hl=-1848208735,this.outputLen=28}}class Am extends co{constructor(){super(),this.Ah=573645204,this.Al=-64227540,this.Bh=-1621794909,this.Bl=-934517566,this.Ch=596883563,this.Cl=1867755857,this.Dh=-1774684391,this.Dl=1497426621,this.Eh=-1775747358,this.El=-1467023389,this.Fh=-1101128155,this.Fl=1401305490,this.Gh=721525244,this.Gl=746961066,this.Hh=246885852,this.Hl=-2117784414,this.outputLen=32}}class Bm extends co{constructor(){super(),this.Ah=-876896931,this.Al=-1056596264,this.Bh=1654270250,this.Bl=914150663,this.Ch=-1856437926,this.Cl=812702999,this.Dh=355462360,this.Dl=-150054599,this.Eh=1731405415,this.El=-4191439,this.Fh=-1900787065,this.Fl=1750603025,this.Gh=-619958771,this.Gl=1694076839,this.Hh=1203062813,this.Hl=-1090891868,this.outputLen=48}}const Tm=Kn(()=>new co);Kn(()=>new $m);Kn(()=>new Am);Kn(()=>new Bm);const Im=new Uint8Array([7,4,13,1,10,6,15,3,12,0,9,5,2,14,11,8]),df=Uint8Array.from({length:16},(e,t)=>t),Om=df.map(e=>(9*e+5)%16);let ra=[df],sa=[Om];for(let e=0;e<4;e++)for(let t of[ra,sa])t.push(t[e].map(n=>Im[n]));const hf=[[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=>new Uint8Array(e)),Cm=ra.map((e,t)=>e.map(n=>hf[t][n])),Pm=sa.map((e,t)=>e.map(n=>hf[t][n])),Um=new Uint32Array([0,1518500249,1859775393,2400959708,2840853838]),Nm=new Uint32Array([1352829926,1548603684,1836072691,2053994217,0]),os=(e,t)=>e<>>32-t;function uc(e,t,n,r){return e===0?t^n^r:e===1?t&n|~t&r:e===2?(t|~n)^r:e===3?t&r|n&~r:t^(n|~r)}const is=new Uint32Array(16);let Lm=class extends na{constructor(){super(64,20,8,!0),this.h0=1732584193,this.h1=-271733879,this.h2=-1732584194,this.h3=271733878,this.h4=-1009589776}get(){const{h0:t,h1:n,h2:r,h3:s,h4:o}=this;return[t,n,r,s,o]}set(t,n,r,s,o){this.h0=t|0,this.h1=n|0,this.h2=r|0,this.h3=s|0,this.h4=o|0}process(t,n){for(let h=0;h<16;h++,n+=4)is[h]=t.getUint32(n,!0);let r=this.h0|0,s=r,o=this.h1|0,i=o,a=this.h2|0,c=a,u=this.h3|0,l=u,f=this.h4|0,d=f;for(let h=0;h<5;h++){const m=4-h,y=Um[h],g=Nm[h],p=ra[h],w=sa[h],b=Cm[h],T=Pm[h];for(let A=0;A<16;A++){const O=os(r+uc(h,o,a,u)+is[p[A]]+y,b[A])+f|0;r=f,f=u,u=os(a,10)|0,a=o,o=O}for(let A=0;A<16;A++){const O=os(s+uc(m,i,c,l)+is[w[A]]+g,T[A])+d|0;s=d,d=l,l=os(c,10)|0,c=i,i=O}}this.set(this.h1+a+l|0,this.h2+u+d|0,this.h3+f+s|0,this.h4+r+i|0,this.h0+o+c|0)}roundClean(){is.fill(0)}destroy(){this.destroyed=!0,this.buffer.fill(0),this.set(0,0,0,0,0)}};const Rm=Kn(()=>new Lm);let pf=class extends uf{constructor(t,n){super(),this.finished=!1,this.destroyed=!1,En.hash(t);const r=ta(n);if(this.iHash=t.create(),typeof this.iHash.update!="function")throw new Error("Expected instance of class which extends utils.Hash");this.blockLen=this.iHash.blockLen,this.outputLen=this.iHash.outputLen;const s=this.blockLen,o=new Uint8Array(s);o.set(r.length>s?t.create().update(r).digest():r);for(let i=0;inew pf(e,t).update(n).digest();gf.create=(e,t)=>new pf(e,t);function Hm(e){const t=W.bytes(e);return W.raw(Os(t))}function tr(e){const t=W.bytes(e);return W.raw(Os(Os(t)))}function oa(e){const t=W.bytes(e);return W.raw(Rm(Os(t)))}function jm(e,t){const n=W.bytes(e),r=W.bytes(t);return W.raw(gf(Tm,n,r))}function Km(e){const t=W.str(e).digest;return W.join([t,t])}function Dm(e=32){return ia(af(e))}function ia(e){return Ke.mod(e).buff}function mf(e,t=!1){const n=Ke.mod(e).point;return t?n.x:n.buff}function yf(e,t){const n=jn.from_x(t),r=Ke.mod(e);return n.mul(r).buff}function Zm(e,t,n="ecdh/code"){const r=Km(n),s=ia(e),o=mf(s),i=W.bytes(t),a=yf(s,i),c=[o.hex,i.hex];return c.sort(),jm(a,W.join([r,...c]))}function Mm(e){const t=W.bytes(e);switch(!0){case t.length===32:return!0;case(t.length===33&&t[0]===2):return!0;case(t.length===33&&t[0]===3):return!1;default:throw new TypeError(`Invalid public key: ${t.hex}`)}}function Vm(e){const t=W.bytes(e);switch(t.length){case 32:return t;case 33:return t.slice(1,33);default:throw new Error(`Invalid key length: ${t.length}`)}}var qm=Object.freeze({__proto__:null,genSecretKey:Dm,getPublicKey:mf,getSecretKey:ia,getSharedCode:Zm,getSharedKey:yf,is_even_pub:Mm,xonly_pub:Vm});W.random(32);const bf={secp:Nt},wi={...qm,...Lg};function uo(e){const t=E.bytes(e);return kt(t,33),oa(t)}function wf(e){const t=Se.fmt.toBytes(e,!1);return oa(t)}function xf(e){const t=Se.fmt.toBytes(e,!1);return Hm(t)}function vf(e,t="main"){const n=t==="main"?["1"]:["m","n"];for(const r of n)if(e.startsWith(r))return!0;return!1}function Ef(e,t="main"){const n=E.bytes(e),r=t==="main"?E.num(0):E.num(111);return kt(e,20),n.prepend(r).tob58chk()}function zm(e,t="main"){if(!vf(e,t))throw new TypeError("Invalid p2pkh address!");return E.b58chk(e).slice(1)}function Fm(e){const t=E.bytes(e);return kt(t,20),["OP_DUP","OP_HASH160",t.hex,"OP_EQUALVERIFY","OP_CHECKSIG"]}function Gm(e,t){const n=uo(e);return Ef(n,t)}const Sf={check:vf,encode:Ef,decode:zm,hash:uo,scriptPubKey:Fm,fromPubKey:Gm};function kf(e,t="main"){const n=t==="main"?["3"]:["2"];for(const r of n)if(e.startsWith(r))return!0;return!1}function _f(e,t="main"){const n=t==="main"?E.num(5):E.num(196),r=E.bytes(e);return kt(r,20),r.prepend(n).tob58chk()}function Wm(e,t="main"){if(!kf(e,t))throw new TypeError(`Invalid p2sh address for network ${t}:`+e);return E.b58chk(e).slice(1)}function Ym(e){return["OP_HASH160",E.bytes(e).hex,"OP_EQUAL"]}function Xm(e,t){const n=wf(e);return _f(n,t)}const $f={check:kf,encode:_f,decode:Wm,hash:wf,scriptPubKey:Ym,fromScript:Xm},aa={main:"bc",testnet:"tb",signet:"tb",regtest:"bcrt"},Jm=["bc1q","tb1q","bcrt1q"];function Af(e){for(const t of Jm)if(e.startsWith(t))return!0;return!1}function Bf(e,t="main"){const n=aa[t],r=E.bytes(e);return kt(r,20),r.toBech32(n,0)}function Qm(e){if(!Af(e))throw new TypeError("Invalid segwit address!");return E.bech32(e)}function ey(e){const t=E.bytes(e);return kt(t,20),["OP_0",t.hex]}function ty(e,t){const n=uo(e);return Bf(n,t)}const Tf={check:Af,encode:Bf,decode:Qm,hash:uo,scriptPubKey:ey,fromPubKey:ty},ny=["bc1q","tb1q","bcrt1q"];function If(e){for(const t of ny)if(e.startsWith(t))return!0;return!1}function Of(e,t="main"){const n=aa[t],r=E.bytes(e);return kt(r,32),r.toBech32(n,0)}function ry(e){if(!If(e))throw new TypeError("Invalid segwit address!");return E.bech32(e)}function sy(e){const t=E.bytes(e);return kt(t,32),["OP_0",t.hex]}function oy(e,t){const n=xf(e);return Of(n,t)}const Cf={check:If,encode:Of,decode:ry,hash:xf,scriptPubKey:sy,fromScript:oy};function In(e){const t=E.bytes(e);return t.length>32?t.slice(1,33):t}const iy=["bc1p","tb1p","bcrt1p"];function Pf(e){for(const t of iy)if(e.startsWith(t))return!0;return!1}function Uf(e,t="main"){const n=aa[t],r=E.bytes(e);return kt(r,32),r.toBech32(n,1)}function ay(e){if(!Pf(e))throw new TypeError("Invalid taproot address!");return E.bech32(e)}function cy(e){const t=E.bytes(e);return kt(t,32),["OP_1",t.hex]}function uy(e,t){const n=In(e);return Uf(n,t)}const Nf={check:Pf,encode:Uf,decode:ay,scriptPubKey:cy,fromPubKey:uy},fy={version:2,vin:[],vout:[],locktime:0},ly={scriptSig:[],sequence:4294967293,witness:[]},dy={value:0n,scriptPubKey:[]};function ca(e){const t={...fy,...e};return t.vin=t.vin.map(n=>({...ly,...n})),t.vout=t.vout.map(n=>({...dy,...n})),t}function nr(e,t){const{version:n,vin:r,vout:s,locktime:o}=ca(e),i=t!==!0&&hy(r),a=[ua(n)];i&&a.push(E.hex("0001")),a.push(py(r)),a.push(gy(s));for(const c of r)i&&a.push(yy(c.witness));return a.push(fa(o)),E.join(a)}function hy(e){for(const t of e){const{witness:n}=t;if(typeof n=="string"||n instanceof Uint8Array||Array.isArray(n)&&n.length>0)return!0}return!1}function ua(e){return E.num(e,4).reverse()}function qr(e){return E.hex(e,32).reverse()}function zr(e){return E.num(e,4).reverse()}function Fr(e){if(typeof e=="string")return E.hex(e,4).reverse();if(typeof e=="number")return E.num(e,4).reverse();throw new Error("Unrecognized format: "+String(e))}function py(e){const t=[E.varInt(e.length,"le")];for(const n of e){const{txid:r,vout:s,scriptSig:o,sequence:i}=n;t.push(qr(r)),t.push(zr(s)),t.push(Hn(o,!0)),t.push(Fr(i))}return E.join(t)}function an(e){if(typeof e=="number"){if(e%1!==0)throw new Error("Value must be an integer:"+String(e));return E.num(e,8).reverse()}return E.big(e,8).reverse()}function gy(e){const t=[E.varInt(e.length,"le")];for(const n of e)t.push(my(n));return E.join(t)}function my(e){const{value:t,scriptPubKey:n}=e,r=[];return r.push(an(t)),r.push(Hn(n,!0)),E.join(r)}function yy(e=[]){const t=[];if(Array.isArray(e)){const n=E.varInt(e.length);t.push(n);for(const r of e)t.push(by(r));return E.join(t)}else return E.bytes(e)}function by(e){return wy(e)?new E(0):Hn(e,!0)}function wy(e){if(Array.isArray(e))return e.length===0;if(typeof e=="string"&&e==="")return!0;const t=E.bytes(e);return t.length===1&&t[0]===0}function fa(e){if(typeof e=="string")return E.hex(e,4);if(typeof e=="number")return E.num(e,4).reverse();throw new Error("Unrecognized format: "+String(e))}function la(e){typeof e=="string"&&(e=E.hex(e).raw);const t=new fr(e),n=xy(t),r=vy(t),s=Ey(t),o=ky(t);if(r)for(const a of s)a.witness=$y(t);const i=Ay(t);return{version:n,vin:s,vout:o,locktime:i}}function xy(e){return e.read(4).reverse().toNum()}function vy(e){const[t,n]=[...e.peek(2)];if(t===0){if(e.read(2),n===1)return!0;throw new Error(`Invalid witness flag: ${n}`)}return!1}function Ey(e){const t=[],n=e.readSize("le");for(let r=0;r0?e.read(n).hex:null}function Rf(e,t){const n=Lf(e);return n!==null?n:[]}function Ay(e){return e.read(4).reverse().toNum()}function By(e){if(vu(e))return la(e);if(typeof e=="object"&&!(e instanceof Uint8Array))return nr(e),ca(e);throw new Error("Invalid format: "+typeof e)}function Ty(e){if(vu(e))return la(e),E.bytes(e);if(typeof e=="object")return nr(e);throw new Error("Invalid format: "+typeof e)}const da={toBytes:Ty,toJson:By},Iy=[["p2pkh",/^76a914(?\w{40})88ac$/],["p2sh",/^a914(?\w{40})87$/],["p2w-pkh",/^0014(?\w{40})$/],["p2w-sh",/^0020(?\w{64})$/],["p2tr",/^5120(?\w{64})$/]],Oy=[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];function Cy(e){let t=e.at(-1);return Rt(t)&&(t=E.hex(t)),e.length>1&&t instanceof Uint8Array&&t[0]===80?(e.pop(),E.raw(t)):null}function Py(e){let t=e.at(-1);return Rt(t)&&(t=E.hex(t)),e.length>1&&t instanceof Uint8Array&&t.length>32&&Oy.includes(t[0]&254)?(e.pop(),E.raw(t)):null}function Uy(e){if(e.length>1){const t=e.at(-1);try{const n=Se.fmt.toBytes(t);return e.pop(),n}catch{return null}}return null}function Ny(e){const t=[];for(const n of e)if(Rt(n)||n instanceof Uint8Array||typeof n=="number")t.push(E.bytes(n));else throw new Error("unrecognized value: "+String(n));return t}function Ly(e=[]){const t=[...e],n=Cy(t),r=Py(t),s=Uy(t),o=Ny(t);return{annex:n,cblock:r,script:s,params:o}}function Ry(e){const t=Se.fmt.toBytes(e,!1).hex;for(const[n,r]of Iy){const s=n,{groups:o}=r.exec(t)??{},{hash:i}=o??{};if(Rt(i))return{type:s,data:E.hex(i)}}return{type:"raw",data:E.hex(t)}}function Hy(e){const t=da.toJson(e),n=nr(t,!0);return tr(n).reverse().hex}function jy(e){const t=da.toJson(e),n=nr(t,!0).length,r=nr(t,!1).length,s=n*3+r,o=s%4>0?1:0,i=Math.floor(s/4)+o;return{size:r,bsize:n,vsize:i,weight:s}}const ae={create:ca,encode:nr,decode:la,fmt:da,util:{getTxSize:jy,getTxid:Hy,readScriptPubKey:Ry,readWitness:Ly}},Ky=[["1","p2pkh","main",20,"base58"],["3","p2sh","main",20,"base58"],["m","p2pkh","testnet",20,"base58"],["n","p2pkh","testnet",20,"base58"],["2","p2sh","testnet",20,"base58"],["bc1q","p2w-pkh","main",20,"bech32"],["tb1q","p2w-pkh","testnet",20,"bech32"],["bcrt1q","p2w-pkh","regtest",20,"bech32"],["bc1q","p2w-sh","main",32,"bech32"],["tb1q","p2w-sh","testnet",32,"bech32"],["bcrt1q","p2w-sh","regtest",32,"bech32"],["bc1p","p2tr","main",32,"bech32m"],["tb1p","p2tr","testnet",32,"bech32m"],["bcrt1p","p2tr","regtest",32,"bech32m"]];function Dy(e,t){switch(t){case"base58":return E.b58chk(e).slice(1);case"bech32":return E.bech32(e);case"bech32m":return E.bech32(e);default:throw new Error("Invalid address format: "+t)}}function Zy(e){for(const t of Ky){const[n,r,s,o,i]=t;if(e.startsWith(n)&&Dy(e,i).length===o)return t}throw new Error("Invalid address: "+e)}function Hf(e){switch(e){case"p2pkh":return Sf;case"p2sh":return $f;case"p2w-pkh":return Tf;case"p2w-sh":return Cf;case"p2tr":return Nf;default:throw new Error("Invalid address type: "+e)}}function jf(e){const[t,n,r]=Zy(e),s=Hf(n),o=s.decode(e,r),i=s.scriptPubKey(o);return{prefix:t,type:n,network:r,data:o,script:i}}function My(e,t){const{type:n,data:r}=ae.util.readScriptPubKey(e);return Hf(n).encode(r,t)}function Vy(e){const{script:t}=jf(e);return Se.fmt.toAsm(t,!1)}const Tr={p2pkh:Sf,p2sh:$f,p2wpkh:Tf,p2wsh:Cf,p2tr:Nf,decode:jf,fromScriptPubKey:My,toScriptPubKey:Vy},qy=[1,2,3];function ha(e,t,n={}){const{sigflag:r=1}=n,s=(r&128)===128,o=r%128;if(!qy.includes(o))throw new Error("Invalid hash type: "+String(r));const i=ae.fmt.toJson(e),{version:a,vin:c,vout:u,locktime:l}=i,{txid:f,vout:d,prevout:h,sequence:m}=c[t],{value:y}=h??{};if(y===void 0)throw new Error("Prevout value is empty!");let g=n.script;if(g===void 0&&n.pubkey!==void 0&&(g=`76a914${oa(n.pubkey).hex}88ac`),g===void 0)throw new Error("No pubkey / script has been set!");if(Se.fmt.toAsm(g).includes("OP_CODESEPARATOR"))throw new Error("This library does not currently support the use of OP_CODESEPARATOR in segwit scripts.");const p=[ua(a),zy(c,s),Fy(c,o,s),qr(f),zr(d),Se.encode(g,!0),an(y),Fr(m),Gy(u,t,o),fa(l),E.num(r,4).reverse()];return tr(E.join(p))}function zy(e,t){if(t===!0)return E.num(0,32);const n=[];for(const{txid:r,vout:s}of e)n.push(qr(r)),n.push(zr(s));return tr(E.join(n))}function Fy(e,t,n){if(n||t!==1)return E.num(0,32);const r=[];for(const{sequence:s}of e)r.push(Fr(s));return tr(E.join(r))}function Gy(e,t,n){const r=[];if(n===1){for(const{value:s,scriptPubKey:o}of e)r.push(an(s)),r.push(Se.encode(o,!0));return tr(E.join(r))}if(n===3&&t1&&c[1].length===33)u=E.bytes(c[1]);else return Ue("No pubkey provided!",s);const l=Se.fmt.toParam(c[0]),f=l.slice(0,-1),d=l.slice(-1)[0],h=ha(r,t,{...n,sigflag:d});return bf.secp.verify(f,h,u)?!0:Ue("Invalid signature!",s)}const Xy={hash:ha,sign:Wy,verify:Yy},Jy=[0,1,2,3,129,130,131];function pa(e,t,n={}){const{extension:r,sigflag:s=0,extflag:o=0,key_version:i=0,separator_pos:a=4294967295}=n,c=ae.fmt.toJson(e),{version:u,vin:l,vout:f,locktime:d}=c;if(t>=l.length)throw new Error("Index out of bounds: "+String(t));if(!Jy.includes(s))throw new Error("Invalid hash type: "+String(s));if(o<0||o>127)throw new Error("Extention flag out of range: "+String(o));const{txid:h,vout:m,sequence:y,witness:g=[]}=l[t],p=(s&128)===128,w=ob(g),b=w!==void 0?1:0,A=(o+(r!==void 0?1:0))*2+b,O=E.str("TapSighash").digest,U=[O,O,E.num(0,1),E.num(s,1),ua(u),fa(d)];if(!p){const C=l.map(_=>fc(_));U.push(Qy(l),tb(C),nb(C),eb(l))}if(((s&3)<2||(s&3)>3)&&U.push(rb(f)),U.push(E.num(A,1)),p){const{value:C,scriptPubKey:_}=fc(l[t]);U.push(qr(h),zr(m),an(C),Se.encode(_,!0),Fr(y))}else U.push(E.num(t,4).reverse());return w!==void 0&&U.push(w),(s&3)===3&&U.push(sb(f[t])),r!==void 0&&U.push(E.bytes(r),E.num(i),E.num(a,4,"le")),E.join(U).digest}function Qy(e){const t=[];for(const{txid:n,vout:r}of e)t.push(qr(n)),t.push(zr(r));return E.join(t).digest}function eb(e){const t=[];for(const{sequence:n}of e)t.push(Fr(n));return E.join(t).digest}function tb(e){const t=[];for(const{value:n}of e)t.push(an(n));return E.join(t).digest}function nb(e){const t=[];for(const{scriptPubKey:n}of e)t.push(Hn(n,!0));return E.join(t).digest}function rb(e){const t=[];for(const{value:n,scriptPubKey:r}of e)t.push(an(n)),t.push(Se.encode(r,!0));return E.join(t).digest}function sb(e){return E.join([an(e.value),Se.encode(e.scriptPubKey,!0)]).digest}function ob(e){if(e===void 0||e.length<2)return;let t=e.at(-1);if(typeof t=="string"&&(t=E.hex(t)),t instanceof Uint8Array&&t[0]===80)return E.raw(t).prefixSize("be").digest}function fc(e){if(e.prevout===void 0)throw new Error("Prevout data missing for input: "+String(e.txid));return e.prevout}const ib=0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2fn,ab=0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141n;function cb(e,t,n,r={}){const{sigflag:s=0}=r,o=pa(t,n,r),i=ub(e,o);return s===0?E.raw(i):E.join([i,s])}function ub(e,t,n=E.random(32)){const r=E.bytes(t),s=new Ke(e),o=s.point,i=o.hasEvenY?s.big:s.negated.big,a=vs("BIP0340/aux",E.bytes(n)),c=i^a.big,u=vs("BIP0340/nonce",c,o.x.raw,r),l=new Ke(u),f=l.point,d=f.hasEvenY?l.big:l.negated.big,h=new Ke(vs("BIP0340/challenge",f.x.raw,o.x.raw,r)),m=new Ke(d+h.big*i);return E.join([f.x.raw,m.raw])}function fb(e,t,n,r=!1){const s=jn.from_x(In(n)),o=E.bytes(t),i=E.bytes(e).stream;i.size<64&&Ue("Signature length is too small: "+String(i.size),r);const a=i.read(32);a.big>ib&&Ue("Signature r value greater than field size!",r);const c=i.read(32);c.big>ab&&Ue("Signature s value greater than curve order!",r);const u=new Ke(vs("BIP0340/challenge",a.raw,s.x.raw,o)),l=new Ke(c).point,f=s.mul(u.big),d=l.sub(f);return d.hasOddY&&Ue("Signature R value has odd Y coordinate!",r),d.x.big===0n&&Ue("Signature R value is infinite!",r),d.x.big===a.big}const lb=192;function fo(e){const t=E.str(e).digest;return E.join([t,t])}function ga(e,t=lb){return E.join([fo("TapLeaf"),pb(t),E.bytes(e)]).digest.hex}function db(e,t){return ga(Se.fmt.toBytes(e),t)}function ma(e,t){return t0){const[h,m,y]=Cs(r,i);c=y,a=Wn(e,h,n)}else i!==void 0?a=Wn(e,i,n):a=Wn(e,void 0,n);const u=n?wi.getPublicKey(a)[0]:a[0],f=[E.num(s+qf(u)),o];c.length>0&&c.forEach(h=>f.push(E.hex(h)));const d=E.join(f);if(i!==void 0&&!ya(a,i,d,t))throw new Error("Path checking failed! Unable to generate path.");return[In(a).hex,d.hex]}function ya(e,t,n,r={}){const{isPrivate:s=!1,throws:o=!1}=r,{parity:i,paths:a,intkey:c}=Vf(n),u=s?wi.getPublicKey(e,!0):In(e),l=E.join([i,u]);if(l.length!==33)return Ue("Invalid tapkey: "+l.hex,o);let f=E.bytes(t).hex;for(const h of a)f=ma(f,h);const d=Wn(c,f);return E.raw(d).hex===E.raw(l).hex}function Vf(e){const t=new fr(E.bytes(e)),n=t.read(1).num,r=t.read(32),[s,o]=n%2===0?[n,2]:[n-1,3],i=[];for(;t.size>=32;)i.push(t.read(32).hex);if(t.size!==0)throw new Error("Non-empty buffer on control block: "+String(t));return{intkey:r,paths:i,parity:o,version:s}}function qf(e=2){if(e===0||e===1)return e;if(e===2||e==="02")return 0;if(e===3||e==="03")return 1;throw new Error("Invalid parity bit: "+String(e))}function Eb(e,t,n={}){const r=ae.fmt.toJson(e),{throws:s=!1}=n,{prevout:o,witness:i=[]}=r.vin[t],a=ae.util.readWitness(i),{cblock:c,script:u,params:l}=a;let f;if(l.length<1)return Ue("Invalid witness data: "+String(i),s);const{scriptPubKey:d}=o??{};if(d===void 0)return Ue("Prevout scriptPubKey is empty!",s);const{type:h,data:m}=ae.util.readScriptPubKey(d);if(h!=="p2tr")return Ue("Prevout script is not a valid taproot output:"+m.hex,s);if(m.length!==32)return Ue("Invalid tapkey length: "+String(m.length),s);if(c!==null&&u!==null){const b=c[0]&254,T=ga(u,b);if(n.extension=T,!ya(m,T,c,{throws:s}))return Ue("cblock verification failed!",s)}n.pubkey!==void 0?f=E.bytes(n.pubkey):l.length>1&&l[1].length===32?f=E.bytes(l[1]):f=E.bytes(m);const y=Se.fmt.toParam(l[0]),g=new fr(y),p=g.read(64).raw;if(g.size===1&&(n.sigflag=g.read(1).num,n.sigflag===0))return Ue("0x00 is not a valid appended sigflag!",s);const w=pa(r,t,n);return fb(p,w,f,s)?!0:Ue("Invalid signature!",s)}const Sb={hash:pa,sign:cb,verify:Eb},lo={segwit:Xy,taproot:Sb},kb={getTag:fo,getLeaf:ga,getBranch:ma,getRoot:hb},_b={readCtrlBlock:Vf,readParityBit:qf},$b={getPubKey:gb,getSecKey:mb,getTweak:Kf,tweakSecKey:Df,tweakPubKey:Zf},Ps={getPubKey:vb,getSecKey:xb,encodeScript:db,checkPath:ya,tree:kb,tweak:$b,util:_b,SCRIPT_PUBKEY:bb};var le;(function(e){e.assertEqual=s=>s;function t(s){}e.assertIs=t;function n(s){throw new Error}e.assertNever=n,e.arrayToEnum=s=>{const o={};for(const i of s)o[i]=i;return o},e.getValidEnumValues=s=>{const o=e.objectKeys(s).filter(a=>typeof s[s[a]]!="number"),i={};for(const a of o)i[a]=s[a];return e.objectValues(i)},e.objectValues=s=>e.objectKeys(s).map(function(o){return s[o]}),e.objectKeys=typeof Object.keys=="function"?s=>Object.keys(s):s=>{const o=[];for(const i in s)Object.prototype.hasOwnProperty.call(s,i)&&o.push(i);return o},e.find=(s,o)=>{for(const i of s)if(o(i))return i},e.isInteger=typeof Number.isInteger=="function"?s=>Number.isInteger(s):s=>typeof s=="number"&&isFinite(s)&&Math.floor(s)===s;function r(s,o=" | "){return s.map(i=>typeof i=="string"?`'${i}'`:i).join(o)}e.joinValues=r,e.jsonStringifyReplacer=(s,o)=>typeof o=="bigint"?o.toString():o})(le||(le={}));var xi;(function(e){e.mergeShapes=(t,n)=>({...t,...n})})(xi||(xi={}));const Z=le.arrayToEnum(["string","nan","number","integer","float","boolean","date","bigint","symbol","function","undefined","null","array","object","unknown","promise","void","never","map","set"]),en=e=>{switch(typeof e){case"undefined":return Z.undefined;case"string":return Z.string;case"number":return isNaN(e)?Z.nan:Z.number;case"boolean":return Z.boolean;case"function":return Z.function;case"bigint":return Z.bigint;case"symbol":return Z.symbol;case"object":return Array.isArray(e)?Z.array:e===null?Z.null:e.then&&typeof e.then=="function"&&e.catch&&typeof e.catch=="function"?Z.promise:typeof Map<"u"&&e instanceof Map?Z.map:typeof Set<"u"&&e instanceof Set?Z.set:typeof Date<"u"&&e instanceof Date?Z.date:Z.object;default:return Z.unknown}},R=le.arrayToEnum(["invalid_type","invalid_literal","custom","invalid_union","invalid_union_discriminator","invalid_enum_value","unrecognized_keys","invalid_arguments","invalid_return_type","invalid_date","invalid_string","too_small","too_big","invalid_intersection_types","not_multiple_of","not_finite"]),Ab=e=>JSON.stringify(e,null,2).replace(/"([^"]+)":/g,"$1:");class ut extends Error{constructor(t){super(),this.issues=[],this.addIssue=r=>{this.issues=[...this.issues,r]},this.addIssues=(r=[])=>{this.issues=[...this.issues,...r]};const n=new.target.prototype;Object.setPrototypeOf?Object.setPrototypeOf(this,n):this.__proto__=n,this.name="ZodError",this.issues=t}get errors(){return this.issues}format(t){const n=t||function(o){return o.message},r={_errors:[]},s=o=>{for(const i of o.issues)if(i.code==="invalid_union")i.unionErrors.map(s);else if(i.code==="invalid_return_type")s(i.returnTypeError);else if(i.code==="invalid_arguments")s(i.argumentsError);else if(i.path.length===0)r._errors.push(n(i));else{let a=r,c=0;for(;cn.message){const n={},r=[];for(const s of this.issues)s.path.length>0?(n[s.path[0]]=n[s.path[0]]||[],n[s.path[0]].push(t(s))):r.push(t(s));return{formErrors:r,fieldErrors:n}}get formErrors(){return this.flatten()}}ut.create=e=>new ut(e);const Ir=(e,t)=>{let n;switch(e.code){case R.invalid_type:e.received===Z.undefined?n="Required":n=`Expected ${e.expected}, received ${e.received}`;break;case R.invalid_literal:n=`Invalid literal value, expected ${JSON.stringify(e.expected,le.jsonStringifyReplacer)}`;break;case R.unrecognized_keys:n=`Unrecognized key(s) in object: ${le.joinValues(e.keys,", ")}`;break;case R.invalid_union:n="Invalid input";break;case R.invalid_union_discriminator:n=`Invalid discriminator value. Expected ${le.joinValues(e.options)}`;break;case R.invalid_enum_value:n=`Invalid enum value. Expected ${le.joinValues(e.options)}, received '${e.received}'`;break;case R.invalid_arguments:n="Invalid function arguments";break;case R.invalid_return_type:n="Invalid function return type";break;case R.invalid_date:n="Invalid date";break;case R.invalid_string:typeof e.validation=="object"?"includes"in e.validation?(n=`Invalid input: must include "${e.validation.includes}"`,typeof e.validation.position=="number"&&(n=`${n} at one or more positions greater than or equal to ${e.validation.position}`)):"startsWith"in e.validation?n=`Invalid input: must start with "${e.validation.startsWith}"`:"endsWith"in e.validation?n=`Invalid input: must end with "${e.validation.endsWith}"`:le.assertNever(e.validation):e.validation!=="regex"?n=`Invalid ${e.validation}`:n="Invalid";break;case R.too_small:e.type==="array"?n=`Array must contain ${e.exact?"exactly":e.inclusive?"at least":"more than"} ${e.minimum} element(s)`:e.type==="string"?n=`String must contain ${e.exact?"exactly":e.inclusive?"at least":"over"} ${e.minimum} character(s)`:e.type==="number"?n=`Number must be ${e.exact?"exactly equal to ":e.inclusive?"greater than or equal to ":"greater than "}${e.minimum}`:e.type==="date"?n=`Date must be ${e.exact?"exactly equal to ":e.inclusive?"greater than or equal to ":"greater than "}${new Date(Number(e.minimum))}`:n="Invalid input";break;case R.too_big:e.type==="array"?n=`Array must contain ${e.exact?"exactly":e.inclusive?"at most":"less than"} ${e.maximum} element(s)`:e.type==="string"?n=`String must contain ${e.exact?"exactly":e.inclusive?"at most":"under"} ${e.maximum} character(s)`:e.type==="number"?n=`Number must be ${e.exact?"exactly":e.inclusive?"less than or equal to":"less than"} ${e.maximum}`:e.type==="bigint"?n=`BigInt must be ${e.exact?"exactly":e.inclusive?"less than or equal to":"less than"} ${e.maximum}`:e.type==="date"?n=`Date must be ${e.exact?"exactly":e.inclusive?"smaller than or equal to":"smaller than"} ${new Date(Number(e.maximum))}`:n="Invalid input";break;case R.custom:n="Invalid input";break;case R.invalid_intersection_types:n="Intersection results could not be merged";break;case R.not_multiple_of:n=`Number must be a multiple of ${e.multipleOf}`;break;case R.not_finite:n="Number must be finite";break;default:n=t.defaultError,le.assertNever(e)}return{message:n}};let zf=Ir;function Bb(e){zf=e}function Us(){return zf}const Ns=e=>{const{data:t,path:n,errorMaps:r,issueData:s}=e,o=[...n,...s.path||[]],i={...s,path:o};let a="";const c=r.filter(u=>!!u).slice().reverse();for(const u of c)a=u(i,{data:t,defaultError:a}).message;return{...s,path:o,message:s.message||a}},Tb=[];function M(e,t){const n=Ns({issueData:t,data:e.data,path:e.path,errorMaps:[e.common.contextualErrorMap,e.schemaErrorMap,Us(),Ir].filter(r=>!!r)});e.common.issues.push(n)}class je{constructor(){this.value="valid"}dirty(){this.value==="valid"&&(this.value="dirty")}abort(){this.value!=="aborted"&&(this.value="aborted")}static mergeArray(t,n){const r=[];for(const s of n){if(s.status==="aborted")return Y;s.status==="dirty"&&t.dirty(),r.push(s.value)}return{status:t.value,value:r}}static async mergeObjectAsync(t,n){const r=[];for(const s of n)r.push({key:await s.key,value:await s.value});return je.mergeObjectSync(t,r)}static mergeObjectSync(t,n){const r={};for(const s of n){const{key:o,value:i}=s;if(o.status==="aborted"||i.status==="aborted")return Y;o.status==="dirty"&&t.dirty(),i.status==="dirty"&&t.dirty(),(typeof i.value<"u"||s.alwaysSet)&&(r[o.value]=i.value)}return{status:t.value,value:r}}}const Y=Object.freeze({status:"aborted"}),Ff=e=>({status:"dirty",value:e}),Ve=e=>({status:"valid",value:e}),vi=e=>e.status==="aborted",Ei=e=>e.status==="dirty",Ls=e=>e.status==="valid",Rs=e=>typeof Promise<"u"&&e instanceof Promise;var F;(function(e){e.errToObj=t=>typeof t=="string"?{message:t}:t||{},e.toString=t=>typeof t=="string"?t:t==null?void 0:t.message})(F||(F={}));class vt{constructor(t,n,r,s){this._cachedPath=[],this.parent=t,this.data=n,this._path=r,this._key=s}get path(){return this._cachedPath.length||(this._key instanceof Array?this._cachedPath.push(...this._path,...this._key):this._cachedPath.push(...this._path,this._key)),this._cachedPath}}const lc=(e,t)=>{if(Ls(t))return{success:!0,data:t.value};if(!e.common.issues.length)throw new Error("Validation failed but no issues detected.");return{success:!1,get error(){if(this._error)return this._error;const n=new ut(e.common.issues);return this._error=n,this._error}}};function ee(e){if(!e)return{};const{errorMap:t,invalid_type_error:n,required_error:r,description:s}=e;if(t&&(n||r))throw new Error(`Can't use "invalid_type_error" or "required_error" in conjunction with custom error map.`);return t?{errorMap:t,description:s}:{errorMap:(i,a)=>i.code!=="invalid_type"?{message:a.defaultError}:typeof a.data>"u"?{message:r??a.defaultError}:{message:n??a.defaultError},description:s}}class re{constructor(t){this.spa=this.safeParseAsync,this._def=t,this.parse=this.parse.bind(this),this.safeParse=this.safeParse.bind(this),this.parseAsync=this.parseAsync.bind(this),this.safeParseAsync=this.safeParseAsync.bind(this),this.spa=this.spa.bind(this),this.refine=this.refine.bind(this),this.refinement=this.refinement.bind(this),this.superRefine=this.superRefine.bind(this),this.optional=this.optional.bind(this),this.nullable=this.nullable.bind(this),this.nullish=this.nullish.bind(this),this.array=this.array.bind(this),this.promise=this.promise.bind(this),this.or=this.or.bind(this),this.and=this.and.bind(this),this.transform=this.transform.bind(this),this.brand=this.brand.bind(this),this.default=this.default.bind(this),this.catch=this.catch.bind(this),this.describe=this.describe.bind(this),this.pipe=this.pipe.bind(this),this.isNullable=this.isNullable.bind(this),this.isOptional=this.isOptional.bind(this)}get description(){return this._def.description}_getType(t){return en(t.data)}_getOrReturnCtx(t,n){return n||{common:t.parent.common,data:t.data,parsedType:en(t.data),schemaErrorMap:this._def.errorMap,path:t.path,parent:t.parent}}_processInputParams(t){return{status:new je,ctx:{common:t.parent.common,data:t.data,parsedType:en(t.data),schemaErrorMap:this._def.errorMap,path:t.path,parent:t.parent}}}_parseSync(t){const n=this._parse(t);if(Rs(n))throw new Error("Synchronous parse encountered promise.");return n}_parseAsync(t){const n=this._parse(t);return Promise.resolve(n)}parse(t,n){const r=this.safeParse(t,n);if(r.success)return r.data;throw r.error}safeParse(t,n){var r;const s={common:{issues:[],async:(r=n==null?void 0:n.async)!==null&&r!==void 0?r:!1,contextualErrorMap:n==null?void 0:n.errorMap},path:(n==null?void 0:n.path)||[],schemaErrorMap:this._def.errorMap,parent:null,data:t,parsedType:en(t)},o=this._parseSync({data:t,path:s.path,parent:s});return lc(s,o)}async parseAsync(t,n){const r=await this.safeParseAsync(t,n);if(r.success)return r.data;throw r.error}async safeParseAsync(t,n){const r={common:{issues:[],contextualErrorMap:n==null?void 0:n.errorMap,async:!0},path:(n==null?void 0:n.path)||[],schemaErrorMap:this._def.errorMap,parent:null,data:t,parsedType:en(t)},s=this._parse({data:t,path:r.path,parent:r}),o=await(Rs(s)?s:Promise.resolve(s));return lc(r,o)}refine(t,n){const r=s=>typeof n=="string"||typeof n>"u"?{message:n}:typeof n=="function"?n(s):n;return this._refinement((s,o)=>{const i=t(s),a=()=>o.addIssue({code:R.custom,...r(s)});return typeof Promise<"u"&&i instanceof Promise?i.then(c=>c?!0:(a(),!1)):i?!0:(a(),!1)})}refinement(t,n){return this._refinement((r,s)=>t(r)?!0:(s.addIssue(typeof n=="function"?n(r,s):n),!1))}_refinement(t){return new lt({schema:this,typeName:G.ZodEffects,effect:{type:"refinement",refinement:t}})}superRefine(t){return this._refinement(t)}optional(){return Pt.create(this,this._def)}nullable(){return Pn.create(this,this._def)}nullish(){return this.nullable().optional()}array(){return ft.create(this,this._def)}promise(){return sr.create(this,this._def)}or(t){return Ur.create([this,t],this._def)}and(t){return Nr.create(this,t,this._def)}transform(t){return new lt({...ee(this._def),schema:this,typeName:G.ZodEffects,effect:{type:"transform",transform:t}})}default(t){const n=typeof t=="function"?t:()=>t;return new Kr({...ee(this._def),innerType:this,defaultValue:n,typeName:G.ZodDefault})}brand(){return new Wf({typeName:G.ZodBranded,type:this,...ee(this._def)})}catch(t){const n=typeof t=="function"?t:()=>t;return new Ds({...ee(this._def),innerType:this,catchValue:n,typeName:G.ZodCatch})}describe(t){const n=this.constructor;return new n({...this._def,description:t})}pipe(t){return Gr.create(this,t)}isOptional(){return this.safeParse(void 0).success}isNullable(){return this.safeParse(null).success}}const Ib=/^c[^\s-]{8,}$/i,Ob=/^[a-z][a-z0-9]*$/,Cb=/[0-9A-HJKMNP-TV-Z]{26}/,Pb=/^([a-f0-9]{8}-[a-f0-9]{4}-[1-5][a-f0-9]{3}-[a-f0-9]{4}-[a-f0-9]{12}|00000000-0000-0000-0000-000000000000)$/i,Ub=/^(([^<>()[\]\\.,;:\s@\"]+(\.[^<>()[\]\\.,;:\s@\"]+)*)|(\".+\"))@((\[(((25[0-5])|(2[0-4][0-9])|(1[0-9]{2})|([0-9]{1,2}))\.){3}((25[0-5])|(2[0-4][0-9])|(1[0-9]{2})|([0-9]{1,2}))\])|(\[IPv6:(([a-f0-9]{1,4}:){7}|::([a-f0-9]{1,4}:){0,6}|([a-f0-9]{1,4}:){1}:([a-f0-9]{1,4}:){0,5}|([a-f0-9]{1,4}:){2}:([a-f0-9]{1,4}:){0,4}|([a-f0-9]{1,4}:){3}:([a-f0-9]{1,4}:){0,3}|([a-f0-9]{1,4}:){4}:([a-f0-9]{1,4}:){0,2}|([a-f0-9]{1,4}:){5}:([a-f0-9]{1,4}:){0,1})([a-f0-9]{1,4}|(((25[0-5])|(2[0-4][0-9])|(1[0-9]{2})|([0-9]{1,2}))\.){3}((25[0-5])|(2[0-4][0-9])|(1[0-9]{2})|([0-9]{1,2})))\])|([A-Za-z0-9]([A-Za-z0-9-]*[A-Za-z0-9])*(\.[A-Za-z]{2,})+))$/,Nb=new RegExp("^(\\p{Extended_Pictographic}|\\p{Emoji_Component})+$","u"),Lb=/^(((25[0-5])|(2[0-4][0-9])|(1[0-9]{2})|([0-9]{1,2}))\.){3}((25[0-5])|(2[0-4][0-9])|(1[0-9]{2})|([0-9]{1,2}))$/,Rb=/^(([a-f0-9]{1,4}:){7}|::([a-f0-9]{1,4}:){0,6}|([a-f0-9]{1,4}:){1}:([a-f0-9]{1,4}:){0,5}|([a-f0-9]{1,4}:){2}:([a-f0-9]{1,4}:){0,4}|([a-f0-9]{1,4}:){3}:([a-f0-9]{1,4}:){0,3}|([a-f0-9]{1,4}:){4}:([a-f0-9]{1,4}:){0,2}|([a-f0-9]{1,4}:){5}:([a-f0-9]{1,4}:){0,1})([a-f0-9]{1,4}|(((25[0-5])|(2[0-4][0-9])|(1[0-9]{2})|([0-9]{1,2}))\.){3}((25[0-5])|(2[0-4][0-9])|(1[0-9]{2})|([0-9]{1,2})))$/,Hb=e=>e.precision?e.offset?new RegExp(`^\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}\\.\\d{${e.precision}}(([+-]\\d{2}(:?\\d{2})?)|Z)$`):new RegExp(`^\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}\\.\\d{${e.precision}}Z$`):e.precision===0?e.offset?new RegExp("^\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}(([+-]\\d{2}(:?\\d{2})?)|Z)$"):new RegExp("^\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}Z$"):e.offset?new RegExp("^\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}(\\.\\d+)?(([+-]\\d{2}(:?\\d{2})?)|Z)$"):new RegExp("^\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}(\\.\\d+)?Z$");function jb(e,t){return!!((t==="v4"||!t)&&Lb.test(e)||(t==="v6"||!t)&&Rb.test(e))}class at extends re{constructor(){super(...arguments),this._regex=(t,n,r)=>this.refinement(s=>t.test(s),{validation:n,code:R.invalid_string,...F.errToObj(r)}),this.nonempty=t=>this.min(1,F.errToObj(t)),this.trim=()=>new at({...this._def,checks:[...this._def.checks,{kind:"trim"}]}),this.toLowerCase=()=>new at({...this._def,checks:[...this._def.checks,{kind:"toLowerCase"}]}),this.toUpperCase=()=>new at({...this._def,checks:[...this._def.checks,{kind:"toUpperCase"}]})}_parse(t){if(this._def.coerce&&(t.data=String(t.data)),this._getType(t)!==Z.string){const o=this._getOrReturnCtx(t);return M(o,{code:R.invalid_type,expected:Z.string,received:o.parsedType}),Y}const r=new je;let s;for(const o of this._def.checks)if(o.kind==="min")t.data.lengtho.value&&(s=this._getOrReturnCtx(t,s),M(s,{code:R.too_big,maximum:o.value,type:"string",inclusive:!0,exact:!1,message:o.message}),r.dirty());else if(o.kind==="length"){const i=t.data.length>o.value,a=t.data.length"u"?null:t==null?void 0:t.precision,offset:(n=t==null?void 0:t.offset)!==null&&n!==void 0?n:!1,...F.errToObj(t==null?void 0:t.message)})}regex(t,n){return this._addCheck({kind:"regex",regex:t,...F.errToObj(n)})}includes(t,n){return this._addCheck({kind:"includes",value:t,position:n==null?void 0:n.position,...F.errToObj(n==null?void 0:n.message)})}startsWith(t,n){return this._addCheck({kind:"startsWith",value:t,...F.errToObj(n)})}endsWith(t,n){return this._addCheck({kind:"endsWith",value:t,...F.errToObj(n)})}min(t,n){return this._addCheck({kind:"min",value:t,...F.errToObj(n)})}max(t,n){return this._addCheck({kind:"max",value:t,...F.errToObj(n)})}length(t,n){return this._addCheck({kind:"length",value:t,...F.errToObj(n)})}get isDatetime(){return!!this._def.checks.find(t=>t.kind==="datetime")}get isEmail(){return!!this._def.checks.find(t=>t.kind==="email")}get isURL(){return!!this._def.checks.find(t=>t.kind==="url")}get isEmoji(){return!!this._def.checks.find(t=>t.kind==="emoji")}get isUUID(){return!!this._def.checks.find(t=>t.kind==="uuid")}get isCUID(){return!!this._def.checks.find(t=>t.kind==="cuid")}get isCUID2(){return!!this._def.checks.find(t=>t.kind==="cuid2")}get isULID(){return!!this._def.checks.find(t=>t.kind==="ulid")}get isIP(){return!!this._def.checks.find(t=>t.kind==="ip")}get minLength(){let t=null;for(const n of this._def.checks)n.kind==="min"&&(t===null||n.value>t)&&(t=n.value);return t}get maxLength(){let t=null;for(const n of this._def.checks)n.kind==="max"&&(t===null||n.value{var t;return new at({checks:[],typeName:G.ZodString,coerce:(t=e==null?void 0:e.coerce)!==null&&t!==void 0?t:!1,...ee(e)})};function Kb(e,t){const n=(e.toString().split(".")[1]||"").length,r=(t.toString().split(".")[1]||"").length,s=n>r?n:r,o=parseInt(e.toFixed(s).replace(".","")),i=parseInt(t.toFixed(s).replace(".",""));return o%i/Math.pow(10,s)}class cn extends re{constructor(){super(...arguments),this.min=this.gte,this.max=this.lte,this.step=this.multipleOf}_parse(t){if(this._def.coerce&&(t.data=Number(t.data)),this._getType(t)!==Z.number){const o=this._getOrReturnCtx(t);return M(o,{code:R.invalid_type,expected:Z.number,received:o.parsedType}),Y}let r;const s=new je;for(const o of this._def.checks)o.kind==="int"?le.isInteger(t.data)||(r=this._getOrReturnCtx(t,r),M(r,{code:R.invalid_type,expected:"integer",received:"float",message:o.message}),s.dirty()):o.kind==="min"?(o.inclusive?t.datao.value:t.data>=o.value)&&(r=this._getOrReturnCtx(t,r),M(r,{code:R.too_big,maximum:o.value,type:"number",inclusive:o.inclusive,exact:!1,message:o.message}),s.dirty()):o.kind==="multipleOf"?Kb(t.data,o.value)!==0&&(r=this._getOrReturnCtx(t,r),M(r,{code:R.not_multiple_of,multipleOf:o.value,message:o.message}),s.dirty()):o.kind==="finite"?Number.isFinite(t.data)||(r=this._getOrReturnCtx(t,r),M(r,{code:R.not_finite,message:o.message}),s.dirty()):le.assertNever(o);return{status:s.value,value:t.data}}gte(t,n){return this.setLimit("min",t,!0,F.toString(n))}gt(t,n){return this.setLimit("min",t,!1,F.toString(n))}lte(t,n){return this.setLimit("max",t,!0,F.toString(n))}lt(t,n){return this.setLimit("max",t,!1,F.toString(n))}setLimit(t,n,r,s){return new cn({...this._def,checks:[...this._def.checks,{kind:t,value:n,inclusive:r,message:F.toString(s)}]})}_addCheck(t){return new cn({...this._def,checks:[...this._def.checks,t]})}int(t){return this._addCheck({kind:"int",message:F.toString(t)})}positive(t){return this._addCheck({kind:"min",value:0,inclusive:!1,message:F.toString(t)})}negative(t){return this._addCheck({kind:"max",value:0,inclusive:!1,message:F.toString(t)})}nonpositive(t){return this._addCheck({kind:"max",value:0,inclusive:!0,message:F.toString(t)})}nonnegative(t){return this._addCheck({kind:"min",value:0,inclusive:!0,message:F.toString(t)})}multipleOf(t,n){return this._addCheck({kind:"multipleOf",value:t,message:F.toString(n)})}finite(t){return this._addCheck({kind:"finite",message:F.toString(t)})}safe(t){return this._addCheck({kind:"min",inclusive:!0,value:Number.MIN_SAFE_INTEGER,message:F.toString(t)})._addCheck({kind:"max",inclusive:!0,value:Number.MAX_SAFE_INTEGER,message:F.toString(t)})}get minValue(){let t=null;for(const n of this._def.checks)n.kind==="min"&&(t===null||n.value>t)&&(t=n.value);return t}get maxValue(){let t=null;for(const n of this._def.checks)n.kind==="max"&&(t===null||n.valuet.kind==="int"||t.kind==="multipleOf"&&le.isInteger(t.value))}get isFinite(){let t=null,n=null;for(const r of this._def.checks){if(r.kind==="finite"||r.kind==="int"||r.kind==="multipleOf")return!0;r.kind==="min"?(n===null||r.value>n)&&(n=r.value):r.kind==="max"&&(t===null||r.valuenew cn({checks:[],typeName:G.ZodNumber,coerce:(e==null?void 0:e.coerce)||!1,...ee(e)});class un extends re{constructor(){super(...arguments),this.min=this.gte,this.max=this.lte}_parse(t){if(this._def.coerce&&(t.data=BigInt(t.data)),this._getType(t)!==Z.bigint){const o=this._getOrReturnCtx(t);return M(o,{code:R.invalid_type,expected:Z.bigint,received:o.parsedType}),Y}let r;const s=new je;for(const o of this._def.checks)o.kind==="min"?(o.inclusive?t.datao.value:t.data>=o.value)&&(r=this._getOrReturnCtx(t,r),M(r,{code:R.too_big,type:"bigint",maximum:o.value,inclusive:o.inclusive,message:o.message}),s.dirty()):o.kind==="multipleOf"?t.data%o.value!==BigInt(0)&&(r=this._getOrReturnCtx(t,r),M(r,{code:R.not_multiple_of,multipleOf:o.value,message:o.message}),s.dirty()):le.assertNever(o);return{status:s.value,value:t.data}}gte(t,n){return this.setLimit("min",t,!0,F.toString(n))}gt(t,n){return this.setLimit("min",t,!1,F.toString(n))}lte(t,n){return this.setLimit("max",t,!0,F.toString(n))}lt(t,n){return this.setLimit("max",t,!1,F.toString(n))}setLimit(t,n,r,s){return new un({...this._def,checks:[...this._def.checks,{kind:t,value:n,inclusive:r,message:F.toString(s)}]})}_addCheck(t){return new un({...this._def,checks:[...this._def.checks,t]})}positive(t){return this._addCheck({kind:"min",value:BigInt(0),inclusive:!1,message:F.toString(t)})}negative(t){return this._addCheck({kind:"max",value:BigInt(0),inclusive:!1,message:F.toString(t)})}nonpositive(t){return this._addCheck({kind:"max",value:BigInt(0),inclusive:!0,message:F.toString(t)})}nonnegative(t){return this._addCheck({kind:"min",value:BigInt(0),inclusive:!0,message:F.toString(t)})}multipleOf(t,n){return this._addCheck({kind:"multipleOf",value:t,message:F.toString(n)})}get minValue(){let t=null;for(const n of this._def.checks)n.kind==="min"&&(t===null||n.value>t)&&(t=n.value);return t}get maxValue(){let t=null;for(const n of this._def.checks)n.kind==="max"&&(t===null||n.value{var t;return new un({checks:[],typeName:G.ZodBigInt,coerce:(t=e==null?void 0:e.coerce)!==null&&t!==void 0?t:!1,...ee(e)})};class Or extends re{_parse(t){if(this._def.coerce&&(t.data=!!t.data),this._getType(t)!==Z.boolean){const r=this._getOrReturnCtx(t);return M(r,{code:R.invalid_type,expected:Z.boolean,received:r.parsedType}),Y}return Ve(t.data)}}Or.create=e=>new Or({typeName:G.ZodBoolean,coerce:(e==null?void 0:e.coerce)||!1,...ee(e)});class On extends re{_parse(t){if(this._def.coerce&&(t.data=new Date(t.data)),this._getType(t)!==Z.date){const o=this._getOrReturnCtx(t);return M(o,{code:R.invalid_type,expected:Z.date,received:o.parsedType}),Y}if(isNaN(t.data.getTime())){const o=this._getOrReturnCtx(t);return M(o,{code:R.invalid_date}),Y}const r=new je;let s;for(const o of this._def.checks)o.kind==="min"?t.data.getTime()o.value&&(s=this._getOrReturnCtx(t,s),M(s,{code:R.too_big,message:o.message,inclusive:!0,exact:!1,maximum:o.value,type:"date"}),r.dirty()):le.assertNever(o);return{status:r.value,value:new Date(t.data.getTime())}}_addCheck(t){return new On({...this._def,checks:[...this._def.checks,t]})}min(t,n){return this._addCheck({kind:"min",value:t.getTime(),message:F.toString(n)})}max(t,n){return this._addCheck({kind:"max",value:t.getTime(),message:F.toString(n)})}get minDate(){let t=null;for(const n of this._def.checks)n.kind==="min"&&(t===null||n.value>t)&&(t=n.value);return t!=null?new Date(t):null}get maxDate(){let t=null;for(const n of this._def.checks)n.kind==="max"&&(t===null||n.valuenew On({checks:[],coerce:(e==null?void 0:e.coerce)||!1,typeName:G.ZodDate,...ee(e)});class Hs extends re{_parse(t){if(this._getType(t)!==Z.symbol){const r=this._getOrReturnCtx(t);return M(r,{code:R.invalid_type,expected:Z.symbol,received:r.parsedType}),Y}return Ve(t.data)}}Hs.create=e=>new Hs({typeName:G.ZodSymbol,...ee(e)});class Cr extends re{_parse(t){if(this._getType(t)!==Z.undefined){const r=this._getOrReturnCtx(t);return M(r,{code:R.invalid_type,expected:Z.undefined,received:r.parsedType}),Y}return Ve(t.data)}}Cr.create=e=>new Cr({typeName:G.ZodUndefined,...ee(e)});class Pr extends re{_parse(t){if(this._getType(t)!==Z.null){const r=this._getOrReturnCtx(t);return M(r,{code:R.invalid_type,expected:Z.null,received:r.parsedType}),Y}return Ve(t.data)}}Pr.create=e=>new Pr({typeName:G.ZodNull,...ee(e)});class rr extends re{constructor(){super(...arguments),this._any=!0}_parse(t){return Ve(t.data)}}rr.create=e=>new rr({typeName:G.ZodAny,...ee(e)});class Bn extends re{constructor(){super(...arguments),this._unknown=!0}_parse(t){return Ve(t.data)}}Bn.create=e=>new Bn({typeName:G.ZodUnknown,...ee(e)});class Lt extends re{_parse(t){const n=this._getOrReturnCtx(t);return M(n,{code:R.invalid_type,expected:Z.never,received:n.parsedType}),Y}}Lt.create=e=>new Lt({typeName:G.ZodNever,...ee(e)});class js extends re{_parse(t){if(this._getType(t)!==Z.undefined){const r=this._getOrReturnCtx(t);return M(r,{code:R.invalid_type,expected:Z.void,received:r.parsedType}),Y}return Ve(t.data)}}js.create=e=>new js({typeName:G.ZodVoid,...ee(e)});class ft extends re{_parse(t){const{ctx:n,status:r}=this._processInputParams(t),s=this._def;if(n.parsedType!==Z.array)return M(n,{code:R.invalid_type,expected:Z.array,received:n.parsedType}),Y;if(s.exactLength!==null){const i=n.data.length>s.exactLength.value,a=n.data.lengths.maxLength.value&&(M(n,{code:R.too_big,maximum:s.maxLength.value,type:"array",inclusive:!0,exact:!1,message:s.maxLength.message}),r.dirty()),n.common.async)return Promise.all([...n.data].map((i,a)=>s.type._parseAsync(new vt(n,i,n.path,a)))).then(i=>je.mergeArray(r,i));const o=[...n.data].map((i,a)=>s.type._parseSync(new vt(n,i,n.path,a)));return je.mergeArray(r,o)}get element(){return this._def.type}min(t,n){return new ft({...this._def,minLength:{value:t,message:F.toString(n)}})}max(t,n){return new ft({...this._def,maxLength:{value:t,message:F.toString(n)}})}length(t,n){return new ft({...this._def,exactLength:{value:t,message:F.toString(n)}})}nonempty(t){return this.min(1,t)}}ft.create=(e,t)=>new ft({type:e,minLength:null,maxLength:null,exactLength:null,typeName:G.ZodArray,...ee(t)});function Fn(e){if(e instanceof Ee){const t={};for(const n in e.shape){const r=e.shape[n];t[n]=Pt.create(Fn(r))}return new Ee({...e._def,shape:()=>t})}else return e instanceof ft?new ft({...e._def,type:Fn(e.element)}):e instanceof Pt?Pt.create(Fn(e.unwrap())):e instanceof Pn?Pn.create(Fn(e.unwrap())):e instanceof Et?Et.create(e.items.map(t=>Fn(t))):e}class Ee extends re{constructor(){super(...arguments),this._cached=null,this.nonstrict=this.passthrough,this.augment=this.extend}_getCached(){if(this._cached!==null)return this._cached;const t=this._def.shape(),n=le.objectKeys(t);return this._cached={shape:t,keys:n}}_parse(t){if(this._getType(t)!==Z.object){const u=this._getOrReturnCtx(t);return M(u,{code:R.invalid_type,expected:Z.object,received:u.parsedType}),Y}const{status:r,ctx:s}=this._processInputParams(t),{shape:o,keys:i}=this._getCached(),a=[];if(!(this._def.catchall instanceof Lt&&this._def.unknownKeys==="strip"))for(const u in s.data)i.includes(u)||a.push(u);const c=[];for(const u of i){const l=o[u],f=s.data[u];c.push({key:{status:"valid",value:u},value:l._parse(new vt(s,f,s.path,u)),alwaysSet:u in s.data})}if(this._def.catchall instanceof Lt){const u=this._def.unknownKeys;if(u==="passthrough")for(const l of a)c.push({key:{status:"valid",value:l},value:{status:"valid",value:s.data[l]}});else if(u==="strict")a.length>0&&(M(s,{code:R.unrecognized_keys,keys:a}),r.dirty());else if(u!=="strip")throw new Error("Internal ZodObject error: invalid unknownKeys value.")}else{const u=this._def.catchall;for(const l of a){const f=s.data[l];c.push({key:{status:"valid",value:l},value:u._parse(new vt(s,f,s.path,l)),alwaysSet:l in s.data})}}return s.common.async?Promise.resolve().then(async()=>{const u=[];for(const l of c){const f=await l.key;u.push({key:f,value:await l.value,alwaysSet:l.alwaysSet})}return u}).then(u=>je.mergeObjectSync(r,u)):je.mergeObjectSync(r,c)}get shape(){return this._def.shape()}strict(t){return new Ee({...this._def,unknownKeys:"strict",...t!==void 0?{errorMap:(n,r)=>{var s,o,i,a;const c=(i=(o=(s=this._def).errorMap)===null||o===void 0?void 0:o.call(s,n,r).message)!==null&&i!==void 0?i:r.defaultError;return n.code==="unrecognized_keys"?{message:(a=F.errToObj(t).message)!==null&&a!==void 0?a:c}:{message:c}}}:{}})}strip(){return new Ee({...this._def,unknownKeys:"strip"})}passthrough(){return new Ee({...this._def,unknownKeys:"passthrough"})}extend(t){return new Ee({...this._def,shape:()=>({...this._def.shape(),...t})})}merge(t){return new Ee({unknownKeys:t._def.unknownKeys,catchall:t._def.catchall,shape:()=>({...this._def.shape(),...t._def.shape()}),typeName:G.ZodObject})}setKey(t,n){return this.augment({[t]:n})}catchall(t){return new Ee({...this._def,catchall:t})}pick(t){const n={};return le.objectKeys(t).forEach(r=>{t[r]&&this.shape[r]&&(n[r]=this.shape[r])}),new Ee({...this._def,shape:()=>n})}omit(t){const n={};return le.objectKeys(this.shape).forEach(r=>{t[r]||(n[r]=this.shape[r])}),new Ee({...this._def,shape:()=>n})}deepPartial(){return Fn(this)}partial(t){const n={};return le.objectKeys(this.shape).forEach(r=>{const s=this.shape[r];t&&!t[r]?n[r]=s:n[r]=s.optional()}),new Ee({...this._def,shape:()=>n})}required(t){const n={};return le.objectKeys(this.shape).forEach(r=>{if(t&&!t[r])n[r]=this.shape[r];else{let o=this.shape[r];for(;o instanceof Pt;)o=o._def.innerType;n[r]=o}}),new Ee({...this._def,shape:()=>n})}keyof(){return Gf(le.objectKeys(this.shape))}}Ee.create=(e,t)=>new Ee({shape:()=>e,unknownKeys:"strip",catchall:Lt.create(),typeName:G.ZodObject,...ee(t)});Ee.strictCreate=(e,t)=>new Ee({shape:()=>e,unknownKeys:"strict",catchall:Lt.create(),typeName:G.ZodObject,...ee(t)});Ee.lazycreate=(e,t)=>new Ee({shape:e,unknownKeys:"strip",catchall:Lt.create(),typeName:G.ZodObject,...ee(t)});class Ur extends re{_parse(t){const{ctx:n}=this._processInputParams(t),r=this._def.options;function s(o){for(const a of o)if(a.result.status==="valid")return a.result;for(const a of o)if(a.result.status==="dirty")return n.common.issues.push(...a.ctx.common.issues),a.result;const i=o.map(a=>new ut(a.ctx.common.issues));return M(n,{code:R.invalid_union,unionErrors:i}),Y}if(n.common.async)return Promise.all(r.map(async o=>{const i={...n,common:{...n.common,issues:[]},parent:null};return{result:await o._parseAsync({data:n.data,path:n.path,parent:i}),ctx:i}})).then(s);{let o;const i=[];for(const c of r){const u={...n,common:{...n.common,issues:[]},parent:null},l=c._parseSync({data:n.data,path:n.path,parent:u});if(l.status==="valid")return l;l.status==="dirty"&&!o&&(o={result:l,ctx:u}),u.common.issues.length&&i.push(u.common.issues)}if(o)return n.common.issues.push(...o.ctx.common.issues),o.result;const a=i.map(c=>new ut(c));return M(n,{code:R.invalid_union,unionErrors:a}),Y}}get options(){return this._def.options}}Ur.create=(e,t)=>new Ur({options:e,typeName:G.ZodUnion,...ee(t)});const Es=e=>e instanceof Rr?Es(e.schema):e instanceof lt?Es(e.innerType()):e instanceof Hr?[e.value]:e instanceof fn?e.options:e instanceof jr?Object.keys(e.enum):e instanceof Kr?Es(e._def.innerType):e instanceof Cr?[void 0]:e instanceof Pr?[null]:null;class ho extends re{_parse(t){const{ctx:n}=this._processInputParams(t);if(n.parsedType!==Z.object)return M(n,{code:R.invalid_type,expected:Z.object,received:n.parsedType}),Y;const r=this.discriminator,s=n.data[r],o=this.optionsMap.get(s);return o?n.common.async?o._parseAsync({data:n.data,path:n.path,parent:n}):o._parseSync({data:n.data,path:n.path,parent:n}):(M(n,{code:R.invalid_union_discriminator,options:Array.from(this.optionsMap.keys()),path:[r]}),Y)}get discriminator(){return this._def.discriminator}get options(){return this._def.options}get optionsMap(){return this._def.optionsMap}static create(t,n,r){const s=new Map;for(const o of n){const i=Es(o.shape[t]);if(!i)throw new Error(`A discriminator value for key \`${t}\` could not be extracted from all schema options`);for(const a of i){if(s.has(a))throw new Error(`Discriminator property ${String(t)} has duplicate value ${String(a)}`);s.set(a,o)}}return new ho({typeName:G.ZodDiscriminatedUnion,discriminator:t,options:n,optionsMap:s,...ee(r)})}}function Si(e,t){const n=en(e),r=en(t);if(e===t)return{valid:!0,data:e};if(n===Z.object&&r===Z.object){const s=le.objectKeys(t),o=le.objectKeys(e).filter(a=>s.indexOf(a)!==-1),i={...e,...t};for(const a of o){const c=Si(e[a],t[a]);if(!c.valid)return{valid:!1};i[a]=c.data}return{valid:!0,data:i}}else if(n===Z.array&&r===Z.array){if(e.length!==t.length)return{valid:!1};const s=[];for(let o=0;o{if(vi(o)||vi(i))return Y;const a=Si(o.value,i.value);return a.valid?((Ei(o)||Ei(i))&&n.dirty(),{status:n.value,value:a.data}):(M(r,{code:R.invalid_intersection_types}),Y)};return r.common.async?Promise.all([this._def.left._parseAsync({data:r.data,path:r.path,parent:r}),this._def.right._parseAsync({data:r.data,path:r.path,parent:r})]).then(([o,i])=>s(o,i)):s(this._def.left._parseSync({data:r.data,path:r.path,parent:r}),this._def.right._parseSync({data:r.data,path:r.path,parent:r}))}}Nr.create=(e,t,n)=>new Nr({left:e,right:t,typeName:G.ZodIntersection,...ee(n)});class Et extends re{_parse(t){const{status:n,ctx:r}=this._processInputParams(t);if(r.parsedType!==Z.array)return M(r,{code:R.invalid_type,expected:Z.array,received:r.parsedType}),Y;if(r.data.lengththis._def.items.length&&(M(r,{code:R.too_big,maximum:this._def.items.length,inclusive:!0,exact:!1,type:"array"}),n.dirty());const o=[...r.data].map((i,a)=>{const c=this._def.items[a]||this._def.rest;return c?c._parse(new vt(r,i,r.path,a)):null}).filter(i=>!!i);return r.common.async?Promise.all(o).then(i=>je.mergeArray(n,i)):je.mergeArray(n,o)}get items(){return this._def.items}rest(t){return new Et({...this._def,rest:t})}}Et.create=(e,t)=>{if(!Array.isArray(e))throw new Error("You must pass an array of schemas to z.tuple([ ... ])");return new Et({items:e,typeName:G.ZodTuple,rest:null,...ee(t)})};class Lr extends re{get keySchema(){return this._def.keyType}get valueSchema(){return this._def.valueType}_parse(t){const{status:n,ctx:r}=this._processInputParams(t);if(r.parsedType!==Z.object)return M(r,{code:R.invalid_type,expected:Z.object,received:r.parsedType}),Y;const s=[],o=this._def.keyType,i=this._def.valueType;for(const a in r.data)s.push({key:o._parse(new vt(r,a,r.path,a)),value:i._parse(new vt(r,r.data[a],r.path,a))});return r.common.async?je.mergeObjectAsync(n,s):je.mergeObjectSync(n,s)}get element(){return this._def.valueType}static create(t,n,r){return n instanceof re?new Lr({keyType:t,valueType:n,typeName:G.ZodRecord,...ee(r)}):new Lr({keyType:at.create(),valueType:t,typeName:G.ZodRecord,...ee(n)})}}class Ks extends re{_parse(t){const{status:n,ctx:r}=this._processInputParams(t);if(r.parsedType!==Z.map)return M(r,{code:R.invalid_type,expected:Z.map,received:r.parsedType}),Y;const s=this._def.keyType,o=this._def.valueType,i=[...r.data.entries()].map(([a,c],u)=>({key:s._parse(new vt(r,a,r.path,[u,"key"])),value:o._parse(new vt(r,c,r.path,[u,"value"]))}));if(r.common.async){const a=new Map;return Promise.resolve().then(async()=>{for(const c of i){const u=await c.key,l=await c.value;if(u.status==="aborted"||l.status==="aborted")return Y;(u.status==="dirty"||l.status==="dirty")&&n.dirty(),a.set(u.value,l.value)}return{status:n.value,value:a}})}else{const a=new Map;for(const c of i){const u=c.key,l=c.value;if(u.status==="aborted"||l.status==="aborted")return Y;(u.status==="dirty"||l.status==="dirty")&&n.dirty(),a.set(u.value,l.value)}return{status:n.value,value:a}}}}Ks.create=(e,t,n)=>new Ks({valueType:t,keyType:e,typeName:G.ZodMap,...ee(n)});class Cn extends re{_parse(t){const{status:n,ctx:r}=this._processInputParams(t);if(r.parsedType!==Z.set)return M(r,{code:R.invalid_type,expected:Z.set,received:r.parsedType}),Y;const s=this._def;s.minSize!==null&&r.data.sizes.maxSize.value&&(M(r,{code:R.too_big,maximum:s.maxSize.value,type:"set",inclusive:!0,exact:!1,message:s.maxSize.message}),n.dirty());const o=this._def.valueType;function i(c){const u=new Set;for(const l of c){if(l.status==="aborted")return Y;l.status==="dirty"&&n.dirty(),u.add(l.value)}return{status:n.value,value:u}}const a=[...r.data.values()].map((c,u)=>o._parse(new vt(r,c,r.path,u)));return r.common.async?Promise.all(a).then(c=>i(c)):i(a)}min(t,n){return new Cn({...this._def,minSize:{value:t,message:F.toString(n)}})}max(t,n){return new Cn({...this._def,maxSize:{value:t,message:F.toString(n)}})}size(t,n){return this.min(t,n).max(t,n)}nonempty(t){return this.min(1,t)}}Cn.create=(e,t)=>new Cn({valueType:e,minSize:null,maxSize:null,typeName:G.ZodSet,...ee(t)});class Yn extends re{constructor(){super(...arguments),this.validate=this.implement}_parse(t){const{ctx:n}=this._processInputParams(t);if(n.parsedType!==Z.function)return M(n,{code:R.invalid_type,expected:Z.function,received:n.parsedType}),Y;function r(a,c){return Ns({data:a,path:n.path,errorMaps:[n.common.contextualErrorMap,n.schemaErrorMap,Us(),Ir].filter(u=>!!u),issueData:{code:R.invalid_arguments,argumentsError:c}})}function s(a,c){return Ns({data:a,path:n.path,errorMaps:[n.common.contextualErrorMap,n.schemaErrorMap,Us(),Ir].filter(u=>!!u),issueData:{code:R.invalid_return_type,returnTypeError:c}})}const o={errorMap:n.common.contextualErrorMap},i=n.data;return this._def.returns instanceof sr?Ve(async(...a)=>{const c=new ut([]),u=await this._def.args.parseAsync(a,o).catch(d=>{throw c.addIssue(r(a,d)),c}),l=await i(...u);return await this._def.returns._def.type.parseAsync(l,o).catch(d=>{throw c.addIssue(s(l,d)),c})}):Ve((...a)=>{const c=this._def.args.safeParse(a,o);if(!c.success)throw new ut([r(a,c.error)]);const u=i(...c.data),l=this._def.returns.safeParse(u,o);if(!l.success)throw new ut([s(u,l.error)]);return l.data})}parameters(){return this._def.args}returnType(){return this._def.returns}args(...t){return new Yn({...this._def,args:Et.create(t).rest(Bn.create())})}returns(t){return new Yn({...this._def,returns:t})}implement(t){return this.parse(t)}strictImplement(t){return this.parse(t)}static create(t,n,r){return new Yn({args:t||Et.create([]).rest(Bn.create()),returns:n||Bn.create(),typeName:G.ZodFunction,...ee(r)})}}class Rr extends re{get schema(){return this._def.getter()}_parse(t){const{ctx:n}=this._processInputParams(t);return this._def.getter()._parse({data:n.data,path:n.path,parent:n})}}Rr.create=(e,t)=>new Rr({getter:e,typeName:G.ZodLazy,...ee(t)});class Hr extends re{_parse(t){if(t.data!==this._def.value){const n=this._getOrReturnCtx(t);return M(n,{received:n.data,code:R.invalid_literal,expected:this._def.value}),Y}return{status:"valid",value:t.data}}get value(){return this._def.value}}Hr.create=(e,t)=>new Hr({value:e,typeName:G.ZodLiteral,...ee(t)});function Gf(e,t){return new fn({values:e,typeName:G.ZodEnum,...ee(t)})}class fn extends re{_parse(t){if(typeof t.data!="string"){const n=this._getOrReturnCtx(t),r=this._def.values;return M(n,{expected:le.joinValues(r),received:n.parsedType,code:R.invalid_type}),Y}if(this._def.values.indexOf(t.data)===-1){const n=this._getOrReturnCtx(t),r=this._def.values;return M(n,{received:n.data,code:R.invalid_enum_value,options:r}),Y}return Ve(t.data)}get options(){return this._def.values}get enum(){const t={};for(const n of this._def.values)t[n]=n;return t}get Values(){const t={};for(const n of this._def.values)t[n]=n;return t}get Enum(){const t={};for(const n of this._def.values)t[n]=n;return t}extract(t){return fn.create(t)}exclude(t){return fn.create(this.options.filter(n=>!t.includes(n)))}}fn.create=Gf;class jr extends re{_parse(t){const n=le.getValidEnumValues(this._def.values),r=this._getOrReturnCtx(t);if(r.parsedType!==Z.string&&r.parsedType!==Z.number){const s=le.objectValues(n);return M(r,{expected:le.joinValues(s),received:r.parsedType,code:R.invalid_type}),Y}if(n.indexOf(t.data)===-1){const s=le.objectValues(n);return M(r,{received:r.data,code:R.invalid_enum_value,options:s}),Y}return Ve(t.data)}get enum(){return this._def.values}}jr.create=(e,t)=>new jr({values:e,typeName:G.ZodNativeEnum,...ee(t)});class sr extends re{unwrap(){return this._def.type}_parse(t){const{ctx:n}=this._processInputParams(t);if(n.parsedType!==Z.promise&&n.common.async===!1)return M(n,{code:R.invalid_type,expected:Z.promise,received:n.parsedType}),Y;const r=n.parsedType===Z.promise?n.data:Promise.resolve(n.data);return Ve(r.then(s=>this._def.type.parseAsync(s,{path:n.path,errorMap:n.common.contextualErrorMap})))}}sr.create=(e,t)=>new sr({type:e,typeName:G.ZodPromise,...ee(t)});class lt extends re{innerType(){return this._def.schema}sourceType(){return this._def.schema._def.typeName===G.ZodEffects?this._def.schema.sourceType():this._def.schema}_parse(t){const{status:n,ctx:r}=this._processInputParams(t),s=this._def.effect||null;if(s.type==="preprocess"){const i=s.transform(r.data);return r.common.async?Promise.resolve(i).then(a=>this._def.schema._parseAsync({data:a,path:r.path,parent:r})):this._def.schema._parseSync({data:i,path:r.path,parent:r})}const o={addIssue:i=>{M(r,i),i.fatal?n.abort():n.dirty()},get path(){return r.path}};if(o.addIssue=o.addIssue.bind(o),s.type==="refinement"){const i=a=>{const c=s.refinement(a,o);if(r.common.async)return Promise.resolve(c);if(c instanceof Promise)throw new Error("Async refinement encountered during synchronous parse operation. Use .parseAsync instead.");return a};if(r.common.async===!1){const a=this._def.schema._parseSync({data:r.data,path:r.path,parent:r});return a.status==="aborted"?Y:(a.status==="dirty"&&n.dirty(),i(a.value),{status:n.value,value:a.value})}else return this._def.schema._parseAsync({data:r.data,path:r.path,parent:r}).then(a=>a.status==="aborted"?Y:(a.status==="dirty"&&n.dirty(),i(a.value).then(()=>({status:n.value,value:a.value}))))}if(s.type==="transform")if(r.common.async===!1){const i=this._def.schema._parseSync({data:r.data,path:r.path,parent:r});if(!Ls(i))return i;const a=s.transform(i.value,o);if(a instanceof Promise)throw new Error("Asynchronous transform encountered during synchronous parse operation. Use .parseAsync instead.");return{status:n.value,value:a}}else return this._def.schema._parseAsync({data:r.data,path:r.path,parent:r}).then(i=>Ls(i)?Promise.resolve(s.transform(i.value,o)).then(a=>({status:n.value,value:a})):i);le.assertNever(s)}}lt.create=(e,t,n)=>new lt({schema:e,typeName:G.ZodEffects,effect:t,...ee(n)});lt.createWithPreprocess=(e,t,n)=>new lt({schema:t,effect:{type:"preprocess",transform:e},typeName:G.ZodEffects,...ee(n)});class Pt extends re{_parse(t){return this._getType(t)===Z.undefined?Ve(void 0):this._def.innerType._parse(t)}unwrap(){return this._def.innerType}}Pt.create=(e,t)=>new Pt({innerType:e,typeName:G.ZodOptional,...ee(t)});class Pn extends re{_parse(t){return this._getType(t)===Z.null?Ve(null):this._def.innerType._parse(t)}unwrap(){return this._def.innerType}}Pn.create=(e,t)=>new Pn({innerType:e,typeName:G.ZodNullable,...ee(t)});class Kr extends re{_parse(t){const{ctx:n}=this._processInputParams(t);let r=n.data;return n.parsedType===Z.undefined&&(r=this._def.defaultValue()),this._def.innerType._parse({data:r,path:n.path,parent:n})}removeDefault(){return this._def.innerType}}Kr.create=(e,t)=>new Kr({innerType:e,typeName:G.ZodDefault,defaultValue:typeof t.default=="function"?t.default:()=>t.default,...ee(t)});class Ds extends re{_parse(t){const{ctx:n}=this._processInputParams(t),r={...n,common:{...n.common,issues:[]}},s=this._def.innerType._parse({data:r.data,path:r.path,parent:{...r}});return Rs(s)?s.then(o=>({status:"valid",value:o.status==="valid"?o.value:this._def.catchValue({get error(){return new ut(r.common.issues)},input:r.data})})):{status:"valid",value:s.status==="valid"?s.value:this._def.catchValue({get error(){return new ut(r.common.issues)},input:r.data})}}removeCatch(){return this._def.innerType}}Ds.create=(e,t)=>new Ds({innerType:e,typeName:G.ZodCatch,catchValue:typeof t.catch=="function"?t.catch:()=>t.catch,...ee(t)});class Zs extends re{_parse(t){if(this._getType(t)!==Z.nan){const r=this._getOrReturnCtx(t);return M(r,{code:R.invalid_type,expected:Z.nan,received:r.parsedType}),Y}return{status:"valid",value:t.data}}}Zs.create=e=>new Zs({typeName:G.ZodNaN,...ee(e)});const Db=Symbol("zod_brand");class Wf extends re{_parse(t){const{ctx:n}=this._processInputParams(t),r=n.data;return this._def.type._parse({data:r,path:n.path,parent:n})}unwrap(){return this._def.type}}class Gr extends re{_parse(t){const{status:n,ctx:r}=this._processInputParams(t);if(r.common.async)return(async()=>{const o=await this._def.in._parseAsync({data:r.data,path:r.path,parent:r});return o.status==="aborted"?Y:o.status==="dirty"?(n.dirty(),Ff(o.value)):this._def.out._parseAsync({data:o.value,path:r.path,parent:r})})();{const s=this._def.in._parseSync({data:r.data,path:r.path,parent:r});return s.status==="aborted"?Y:s.status==="dirty"?(n.dirty(),{status:"dirty",value:s.value}):this._def.out._parseSync({data:s.value,path:r.path,parent:r})}}static create(t,n){return new Gr({in:t,out:n,typeName:G.ZodPipeline})}}const Yf=(e,t={},n)=>e?rr.create().superRefine((r,s)=>{var o,i;if(!e(r)){const a=typeof t=="function"?t(r):typeof t=="string"?{message:t}:t,c=(i=(o=a.fatal)!==null&&o!==void 0?o:n)!==null&&i!==void 0?i:!0,u=typeof a=="string"?{message:a}:a;s.addIssue({code:"custom",...u,fatal:c})}}):rr.create(),Zb={object:Ee.lazycreate};var G;(function(e){e.ZodString="ZodString",e.ZodNumber="ZodNumber",e.ZodNaN="ZodNaN",e.ZodBigInt="ZodBigInt",e.ZodBoolean="ZodBoolean",e.ZodDate="ZodDate",e.ZodSymbol="ZodSymbol",e.ZodUndefined="ZodUndefined",e.ZodNull="ZodNull",e.ZodAny="ZodAny",e.ZodUnknown="ZodUnknown",e.ZodNever="ZodNever",e.ZodVoid="ZodVoid",e.ZodArray="ZodArray",e.ZodObject="ZodObject",e.ZodUnion="ZodUnion",e.ZodDiscriminatedUnion="ZodDiscriminatedUnion",e.ZodIntersection="ZodIntersection",e.ZodTuple="ZodTuple",e.ZodRecord="ZodRecord",e.ZodMap="ZodMap",e.ZodSet="ZodSet",e.ZodFunction="ZodFunction",e.ZodLazy="ZodLazy",e.ZodLiteral="ZodLiteral",e.ZodEnum="ZodEnum",e.ZodEffects="ZodEffects",e.ZodNativeEnum="ZodNativeEnum",e.ZodOptional="ZodOptional",e.ZodNullable="ZodNullable",e.ZodDefault="ZodDefault",e.ZodCatch="ZodCatch",e.ZodPromise="ZodPromise",e.ZodBranded="ZodBranded",e.ZodPipeline="ZodPipeline"})(G||(G={}));const Mb=(e,t={message:`Input not instance of ${e.name}`})=>Yf(n=>n instanceof e,t),Xf=at.create,Jf=cn.create,Vb=Zs.create,qb=un.create,Qf=Or.create,zb=On.create,Fb=Hs.create,Gb=Cr.create,Wb=Pr.create,Yb=rr.create,Xb=Bn.create,Jb=Lt.create,Qb=js.create,ew=ft.create,tw=Ee.create,nw=Ee.strictCreate,rw=Ur.create,sw=ho.create,ow=Nr.create,iw=Et.create,aw=Lr.create,cw=Ks.create,uw=Cn.create,fw=Yn.create,lw=Rr.create,dw=Hr.create,hw=fn.create,pw=jr.create,gw=sr.create,dc=lt.create,mw=Pt.create,yw=Pn.create,bw=lt.createWithPreprocess,ww=Gr.create,xw=()=>Xf().optional(),vw=()=>Jf().optional(),Ew=()=>Qf().optional(),Sw={string:(e=>at.create({...e,coerce:!0})),number:(e=>cn.create({...e,coerce:!0})),boolean:(e=>Or.create({...e,coerce:!0})),bigint:(e=>un.create({...e,coerce:!0})),date:(e=>On.create({...e,coerce:!0}))},kw=Y;var Me=Object.freeze({__proto__:null,defaultErrorMap:Ir,setErrorMap:Bb,getErrorMap:Us,makeIssue:Ns,EMPTY_PATH:Tb,addIssueToContext:M,ParseStatus:je,INVALID:Y,DIRTY:Ff,OK:Ve,isAborted:vi,isDirty:Ei,isValid:Ls,isAsync:Rs,get util(){return le},get objectUtil(){return xi},ZodParsedType:Z,getParsedType:en,ZodType:re,ZodString:at,ZodNumber:cn,ZodBigInt:un,ZodBoolean:Or,ZodDate:On,ZodSymbol:Hs,ZodUndefined:Cr,ZodNull:Pr,ZodAny:rr,ZodUnknown:Bn,ZodNever:Lt,ZodVoid:js,ZodArray:ft,ZodObject:Ee,ZodUnion:Ur,ZodDiscriminatedUnion:ho,ZodIntersection:Nr,ZodTuple:Et,ZodRecord:Lr,ZodMap:Ks,ZodSet:Cn,ZodFunction:Yn,ZodLazy:Rr,ZodLiteral:Hr,ZodEnum:fn,ZodNativeEnum:jr,ZodPromise:sr,ZodEffects:lt,ZodTransformer:lt,ZodOptional:Pt,ZodNullable:Pn,ZodDefault:Kr,ZodCatch:Ds,ZodNaN:Zs,BRAND:Db,ZodBranded:Wf,ZodPipeline:Gr,custom:Yf,Schema:re,ZodSchema:re,late:Zb,get ZodFirstPartyTypeKind(){return G},coerce:Sw,any:Yb,array:ew,bigint:qb,boolean:Qf,date:zb,discriminatedUnion:sw,effect:dc,enum:hw,function:fw,instanceof:Mb,intersection:ow,lazy:lw,literal:dw,map:cw,nan:Vb,nativeEnum:pw,never:Jb,null:Wb,nullable:yw,number:Jf,object:tw,oboolean:Ew,onumber:vw,optional:mw,ostring:xw,pipeline:ww,preprocess:bw,promise:gw,record:aw,set:uw,strictObject:nw,string:Xf,symbol:Fb,transformer:dc,tuple:iw,undefined:Gb,union:rw,unknown:Xb,void:Qb,NEVER:kw,ZodIssueCode:R,quotelessJson:Ab,ZodError:ut});const el=Me.string().regex(/^[a-fA-F0-9]$/),_w=Me.string().regex(/^[a-fA-F0-9]{64}$/),or=Me.number().min(0).max(4294967295),$w=Me.bigint(),tl=Me.instanceof(Uint8Array),Aw=Me.union([el,or,Me.string(),tl]).array(),ba=Me.union([Aw,el,tl]),Bw=Me.array(ba),nl=Me.object({value:Me.union([or,$w]),scriptPubKey:ba}),Tw=Me.object({txid:_w,vout:or,scriptSig:ba,sequence:or,prevout:nl.optional(),witness:Bw});Me.object({version:or,vin:Me.array(Tw),vout:Me.array(nl),locktime:or});const ki=2048,Iw=new TextEncoder;function rl(e){const t=[],n=(s,o)=>{if(o<24)t.push(s*32+o);else if(o<=255)t.push(s*32+24,o);else if(o<=65535)t.push(s*32+25,o>>>8,o&255);else if(o<=4294967295){const i=new Uint8Array(4);new DataView(i.buffer).setUint32(0,o),t.push(s*32+26,...i)}else{t.push(s*32+27);const i=new Uint8Array(8);new DataView(i.buffer).setBigUint64(0,BigInt(o)),t.push(...i)}},r=(s,o=0)=>{if(o>64)throw new Error("Metadata nesting exceeds 64 levels.");if(s===null)t.push(246);else if(typeof s=="boolean")t.push(s?245:244);else if(typeof s=="number"&&Number.isFinite(s))if(Number.isSafeInteger(s)&&!Object.is(s,-0))n(s>=0?0:1,s>=0?s:-1-s);else{const i=new Uint8Array(8);new DataView(i.buffer).setFloat64(0,s),t.push(251,...i)}else if(typeof s=="string"){const i=Iw.encode(s);n(3,i.length);for(const a of i)t.push(a)}else if(Array.isArray(s))n(4,s.length),s.forEach(i=>r(i,o+1));else if(typeof s=="object"&&Object.getPrototypeOf(s)===Object.prototype){const i=Object.entries(s);n(5,i.length);for(const[a,c]of i)r(a,o+1),r(c,o+1)}else throw new Error("Metadata must contain only JSON values.");if(t.length>ki)throw new Error(`Metadata must be at most ${ki} CBOR bytes.`)};return r(e),Uint8Array.from(t)}function Ow(e){if(e=new Uint8Array(e),!e.length||e.length>ki)throw new Error("Invalid CBOR metadata size.");let t=0;const n=o=>{if(t+o>e.length)throw new Error("Truncated CBOR metadata.");const i=e.slice(t,t+o);return t+=o,i},r=(o=0)=>{if(o>64)throw new Error("Metadata nesting exceeds 64 levels.");const i=n(1)[0],a=i>>5,c=i&31;if(a===7){if(c===20)return!1;if(c===21)return!0;if(c===22)return null;if(c===27){const l=new DataView(n(8).buffer).getFloat64(0);if(Number.isFinite(l))return l}throw new Error("Unsupported CBOR value.")}let u=c;if(c>=24&&c<=27){u=0;for(const l of n(2**(c-24)))u=u*256+l}else if(c>=28)throw new Error("Unsupported CBOR length.");if(!Number.isSafeInteger(u))throw new Error("CBOR integer exceeds JSON precision.");if(a===0)return u;if(a===1)return-1-u;if(a===3)return new TextDecoder("utf-8",{fatal:!0}).decode(n(u));if((a===4||a===5)&&u>e.length)throw new Error("Invalid CBOR collection length.");if(a===4)return Array.from({length:u},()=>r(o+1));if(a===5){const l={};for(let f=0;f({txid:e,vout:t,sequence:4294967295,prevout:{value:n,scriptPubKey:r}}),De=(e,t)=>({value:e,scriptPubKey:t}),hc=16*1024,bt=1e3,he=500,Ms="text/plain;charset=utf-8",Cw=["text/plain","application/json","text/html","image/svg+xml","image/png","image/jpeg","image/webp"],sl=new TextEncoder,kr=e=>Array.from(e,t=>t.toString(16).padStart(2,"0")).join(""),yn=e=>Uint8Array.from(e.match(/../g)??[],t=>parseInt(t,16)),Vs=e=>kr(sl.encode(e));function wa(e){const t=typeof e=="string"?{contentType:Ms,bytes:sl.encode(e)}:e;if(!t||![...Cw,Ms].includes(t.contentType))throw new Error("Unsupported MIME type.");if(!(t.bytes instanceof Uint8Array)||!t.bytes.length)throw new Error("Enter non-empty inscription bytes.");if(t.bytes.length>hc)throw new Error(`Body must be at most ${hc} bytes.`);return{contentType:t.contentType,bytes:new Uint8Array(t.bytes)}}function qs(e){const t=/^([0-9a-f]{64})i(0|[1-9][0-9]*)$/.exec(e);if(!t||Number(t[2])>4294967295)throw new Error("Invalid parent inscription id.");let n=Number(t[2]),r="";for(;n;)r+=(n%256).toString(16).padStart(2,"0"),n=Math.floor(n/256);return t[1].match(/../g).reverse().join("")+r}function pc(e){if(typeof e!="string"||!/^[0-9a-f]{64,72}$/.test(e)||e.length%2)throw new Error("Invalid parent tag.");const t=[...yn(e.slice(64))].reduce((r,s,o)=>r+s*256**o,0),n=`${e.slice(0,64).match(/../g).reverse().join("")}i${t}`;if(qs(n)!==e)throw new Error("Non-canonical parent tag.");return n}function ol(e,t,n=null,r=void 0,s={}){const{contentType:o,bytes:i}=wa(t),{delegate:a=null,pointer:c,metaprotocol:u=null}=s,l=u==null||u===""?null:new TextEncoder().encode(String(u));if(l&&l.length>520)throw new Error("Metaprotocol identifier must be 520 bytes or less.");const f=r===void 0?void 0:rl(r),d=[];for(let m=0;m{const y=m.length/2;return(y<=75?y.toString(16).padStart(2,"0"):y<=255?"4c"+y.toString(16).padStart(2,"0"):"4d"+(y%256).toString(16).padStart(2,"0")+Math.floor(y/256).toString(16).padStart(2,"0"))+m};return h(e)+"ac0063"+h(Vs("ord"))+h("01")+h(Vs(o))+(a?h("0b")+h(qs(a)):"")+(c===void 0?"":h("02")+h(il(c)))+(n?h("03")+h(qs(n)):"")+(f===void 0?"":Array.from({length:Math.ceil(f.length/520)},(m,y)=>h("05")+h(kr(f.slice(y*520,(y+1)*520)))).join(""))+(l?h("07")+h(kr(l)):"")+"00"+d.map(h).join("")+"68"}function xa(e){if(!Array.isArray(e)||e.length!==3)throw new Error("Unsupported script-path witness.");const t=Se.decode(e[1]);let n=7,r=null,s=null,o;t[n]==="0b"&&(s=pc(t[n+1]),n+=2),t[n]==="02"&&(o=Uw(t[n+1]==="OP_0"?"":t[n+1]),n+=2),t[n]==="03"&&(r=pc(t[n+1]),n+=2);const i=[];for(;t[n]==="05";){const m=t[n+1];if(typeof m!="string"||!/^(?:[0-9a-f]{2}){1,520}$/.test(m))throw new Error("Invalid metadata push.");i.push(m),n+=2}const a=i.length?Ow(yn(i.join(""))):void 0;let c=null;if(t[n]==="07"){const m=t[n+1];if(typeof m!="string"||!/^(?:[0-9a-f]{2}){1,520}$/.test(m))throw new Error("Invalid metaprotocol field.");c=new TextDecoder().decode(yn(m)),n+=2}if(t[n]!=="OP_0")throw new Error("Unsupported ord tag or missing body separator.");const u=t.slice(n+1,-1);if(!u.length||u.some(m=>typeof m!="string"||!/^(?:[0-9a-f]{2})+$/.test(m)))throw new Error("Invalid body envelope.");const l=new TextDecoder().decode(yn(t[6])),f=wa({contentType:l,bytes:yn(u.join(""))}),d=ol(t[0],f,r,a,{delegate:s,pointer:o,metaprotocol:c}),h=a===void 0&&!r&&l===Ms&&f.bytes.length<=280&&Se.encode([t[0],"OP_CHECKSIG","OP_0","OP_IF",Vs("ord"),"01",Vs(Ms),"OP_0",kr(f.bytes),"OP_ENDIF"],!1).hex;if(d!==e[1]&&h!==e[1])throw new Error("Unsupported ord envelope.");if(!/^[0-9a-f]{64}$/.test(t[0]))throw new Error("Invalid inscription signing key.");return{...f,parent:r,delegate:s,pointer:o,metaprotocol:c,metadata:a,metadataBytes:i.length?yn(i.join("")):void 0,text:new TextDecoder().decode(f.bytes),pubkey:t[0]}}class Pw{constructor(t,n){this.chain=t,this.wallet=n}prepare(t,n=null,r=void 0,s={}){const o=wa(t);if(r!==void 0&&rl(r),s.delegate&&qs(s.delegate),s.pointer!==void 0&&il(s.pointer),s.metaprotocol!==void 0&&s.metaprotocol!==null&&s.metaprotocol!==""&&new TextEncoder().encode(String(s.metaprotocol)).length>520)throw new Error("Metaprotocol identifier must be 520 bytes or less.");if(n&&s.reinscribe)throw new Error("Choose parent or reinscription, not both.");const i=this.chain.coins(this.wallet.script),a=n?i.find(l=>{var f;return(f=l.inscriptions)==null?void 0:f.some(d=>d.id===n)}):null;if(n&&!a)throw new Error("Parent must be an owned, unspent inscription.");const c=s.reinscribe?i.find(l=>{var f;return(f=l.inscriptions)==null?void 0:f.some(d=>d.id===s.reinscribe)}):null;if(s.reinscribe&&!c)throw new Error("Reinscription must spend an owned sat.");const u=i.find(l=>!l.inscription&&l.value>=bt+2*he+330);if(!u)throw new Error("Mine a block first to get spendable fake BTC.");return{...o,coin:u,parent:a,reinscribe:c,totalFee:he*2,postage:bt}}inscribe(t,n=null,r=void 0,s={}){const{coin:o,parent:i,reinscribe:a,...c}=this.prepare(t,n,r,s),u=i??a,l=a==null?void 0:a.inscriptions.find(T=>T.id===s.reinscribe),f=l?this.chain.satLocation(l.sat).offset:s.pointer??(i?i.value:void 0),d=ol(this.wallet.pubkey,c,n,r,{...s,pointer:f}),h=Ps.encodeScript(d),[m,y]=Ps.getPubKey(this.wallet.pubkey,{target:h}),g=ae.create({vin:[rn(o.txid,o.vout,o.value,o.scriptPubKey)],vout:[De(bt+he,["OP_1",m]),De(o.value-bt-2*he,this.wallet.script)]});g.vin[0].witness=[this.wallet.sign(g)];const p=ae.util.getTxid(g),w=ae.create({vin:[...u?[rn(u.txid,u.vout,u.value,u.scriptPubKey)]:[],rn(p,0,bt+he,["OP_1",m])],vout:[...u?[De(u.value,this.wallet.script)]:[],De(bt,this.wallet.script)]}),b=u?1:0;return w.vin[b].witness=[this.wallet.sign(w,h,b),Se.encode(d,!1).hex,y],u&&(w.vin[0].witness=[this.wallet.sign(w)]),this.chain.submitPackage([ae.encode(g).hex,ae.encode(w).hex]),`${ae.util.getTxid(w)}i0`}list(){return this.chain.coins(this.wallet.script).flatMap(t=>t.inscriptions??[])}}function il(e){let t;try{t=BigInt(e)}catch{throw new Error("Invalid pointer.")}if(t<0n||t>0xffffffffffffffffn||typeof e=="number"&&!Number.isSafeInteger(e))throw new Error("Invalid pointer.");let n="";for(;t;)n+=Number(t&255n).toString(16).padStart(2,"0"),t>>=8n;return n}function Uw(e){if(typeof e!="string"||!/^(?:[0-9a-f]{2}){0,8}$/.test(e))throw new Error("Invalid pointer tag.");return[...yn(e)].reduce((t,n,r)=>t+(BigInt(n)<{var p;const i=ae.decode(r),a=ae.util.getTxid(i),c=i.vin[0].txid==="0".repeat(64),u=c?[]:i.vin.map(w=>this.utxos.get(`${w.txid}:${w.vout}`)),l=Xc(i,u,s,c);i.vin.forEach(w=>this.utxos.delete(`${w.txid}:${w.vout}`)),i.vout.forEach((w,b)=>this.utxos.set(`${a}:${b}`,{txid:a,vout:b,value:Number(w.value),ranges:l[b]}));const f=(p=i.vin.find(w=>{var b;return((b=w.witness)==null?void 0:b.length)===3}))==null?void 0:p.witness;if(!f)return;const d=xa(f),h=BigInt(d.pointer??0),m=i.vout.reduce((w,b)=>w+Number(b.value),0),y=Yc(l.flat(),hw.sat===y).length,status:s===null?"pending":"confirmed",height:s,block:o,metadata:g??null,hasMetadata:g!==void 0,parent:d.parent,protocol:d.metaprotocol??(g&&!Array.isArray(g)&&typeof g=="object"&&Object.hasOwn(g,"protocol")&&typeof g.protocol=="string"?g.protocol:null)})};for(const r of t.blocks)for(const s of r.raws)n(s,r.height,r.hash);for(const r of t.mempool)n(r,null,null);for(const r of this.events){r.location=null;for(const s of this.utxos.values()){const o=xs(s.ranges,r.sat);if(o!==null){r.location={txid:s.txid,vout:s.vout,offset:o};break}}r.delegatedBy=this.events.filter(s=>s.delegate===r.id).map(s=>s.id),r.inscriptions=this.events.filter(s=>s.sat===r.sat).map(s=>s.id)}}forProtocol(t){return this.events.filter(n=>n.protocol===t)}get protocols(){return[...new Set(this.events.filter(t=>t.protocol!==null).map(t=>t.protocol))].sort()}get stats(){return{events:this.events.length,withMetadata:this.events.filter(t=>t.hasMetadata).length,confirmed:this.events.filter(t=>t.status==="confirmed").length,pending:this.events.filter(t=>t.status==="pending").length,protocols:this.protocols}}}const va="lineage/v0",Nw=["white","green","black"],gc="names are 1-40 lowercase letters, digits or hyphens (they become domains)",Lw=/^[a-z0-9](?:[a-z0-9-]{0,38}[a-z0-9])?$/,Ko=e=>typeof e=="string"&&Lw.test(e),Ss=(e,t)=>typeof e=="string"?e.trim().slice(0,t):"";function Ea(e){return String(e??"").toLowerCase().normalize("NFKD").replace(/[̀-ͯ]/g,"").replace(/[^a-z0-9]+/g,"-").replace(/^-+|-+$/g,"").slice(0,40).replace(/-+$/,"")}const Sa=e=>e.events.filter(t=>t.protocol===va);function Un(e,{upTo:t=1/0,pending:n=!1}={}){const r=new Map,s=[],o=[],i=a=>a.status==="active";for(const a of e){const c=a.status==="confirmed";if(c?a.height>t:!n)continue;const u=a.metadata&&typeof a.metadata=="object"&&!Array.isArray(a.metadata)?a.metadata:{},l={id:a.id,op:typeof u.op=="string"?u.op.slice(0,20):"?",beat:c?a.height:null,pending:!c,meta:u,parent:a.parent??null,ok:!0,why:"",node:null,root:null,also:[]},f=l.parent?r.get(l.parent):null,d=l.beat??"cued",h=g=>{l.ok=!1,l.why=g},m=g=>f?i(f)?"":`the ${g} is ${f.status}`:`the ${g} is not in this lineage`;let y="";switch(l.op){case"found":if(l.parent)h("a holding has no parent");else if(!Ko(u.name))h(gc);else if(s.some(g=>i(g)&&g.name===u.name))h(`an active holding is already named ${u.name}`);else{const g=mc(a,u.name,null,"holding");r.set(g.id,g),s.push(g),l.node=g.id}break;case"birth":{const g=u.kind==="agent"?"agent":"org";if(y=m("parent"))h(y);else if(f.kind==="agent")h("agents do not give birth");else if(!Ko(u.name))h(gc);else if(f.children.some(p=>i(r.get(p))&&r.get(p).name===u.name))h(`${f.name} already has an active ${u.name}`);else{const p=mc(a,u.name,f,g);p.index=f.children.filter(w=>r.get(w).kind===g).length,f.children.push(p.id),r.set(p.id,p),l.node=p.id}break}case"award":{const g=r.get(u.to);(y=m("issuer"))?h(y):f.kind==="agent"?h("agents do not award belts"):!g||g.root!==f.root||g.id===f.id?h("the recipient must be another node in this holding"):i(g)?!Ko(u.skill)||!Nw.includes(u.belt)?h("an award needs a skill name and a belt (white, green or black)"):(g.badges=g.badges.filter(p=>p.skill!==u.skill),g.badges.push({skill:u.skill,belt:u.belt,by:f.id,beat:d,id:a.id}),l.node=g.id):h(`the recipient is ${g.status}`);break}case"decide":(y=m("decider"))?h(y):Ss(u.title,140)?(f.decisions.push({title:Ss(u.title,140),why:Ss(u.why,400),beat:d,id:a.id}),l.node=f.id):h("a decision needs a title");break;case"graduate":{const g=r.get(u.of);(y=m("parent"))?h(y):!g||g.parent!==f.id?h("only its parent can graduate a child"):g.kind!=="org"?h("only orgs graduate"):i(g)?g.edge==="adopted"?h("already graduated"):(g.edge="adopted",g.graduated=d,l.node=g.id):h(`the child is ${g.status}`);break}case"close":if(!f)h(l.parent?"that node is not in this lineage":"a close spends the node it closes");else if(!i(f))h(`already ${f.status}`);else{const g=p=>{p.status="closed",p.closed=d;for(const w of p.children){const b=r.get(w);b.edge==="derived"&&i(b)&&(l.also.push(b.id),g(b))}};g(f),l.node=f.id}break;default:h("not a lineage/v0 op")}l.root=l.node?r.get(l.node).root:(f==null?void 0:f.root)??null,o.push(l)}return{nodes:r,roots:s,log:o}}function mc(e,t,n,r){return{id:e.id,name:t,kind:r,parent:(n==null?void 0:n.id)??null,root:n?n.root:e.id,edge:n?"derived":null,status:"active",index:null,born:e.status==="confirmed"?e.height:"cued",children:[],badges:[],decisions:[],graduated:null,closed:null}}function Rw(e,t){const n=[],r=e.nodes.get(t),s=(o,i,a)=>{n.push({type:"node",node:o,guide:i,path:o.parent?`${o.index}'`:"●"});const c=o.children.map(l=>e.nodes.get(l)),u=[["agents",c.filter(l=>l.kind==="agent")],["orgs",c.filter(l=>l.kind!=="agent")]].filter(([,l])=>l.length);u.forEach(([l,f],d)=>{const h=d===u.length-1,m=a+(h?" ":"│ ");n.push({type:"group",label:l,guide:a+(h?"└─ ":"├─ ")}),f.forEach((y,g)=>{const p=g===f.length-1;s(y,m+(p?"└─ ":"├─ "),m+(p?" ":"│ "))})})};return r&&s(r,"",""),n}function Hw(e,t){const n={orgs:0,agents:0,belts:0,decisions:0,closed:0};for(const r of e.nodes.values())r.root===t&&(r.id!==t&&(n[r.kind==="agent"?"agents":"orgs"]++,r.status==="closed"&&n.closed++),n.belts+=r.badges.length,n.decisions+=r.decisions.length);return n}function go(e,t){const n=[];for(let r=e.nodes.get(t);r;r=e.nodes.get(r.parent))n.unshift(r.name);return n.join(" / ")}function al(e,t){const n=e.meta,r=s=>{var o;return((o=t.nodes.get(s))==null?void 0:o.name)??(typeof s=="string"?`${s.slice(0,8)}…`:"?")};if(!e.ok)return`${e.op}: ${e.why}`;switch(e.op){case"found":return`found ${n.name}`;case"birth":return`birth ${n.name}${n.kind==="agent"?" (agent)":""} ← ${r(e.parent)}`;case"award":return`award ${n.skill} · ${n.belt} → ${r(n.to)}, from ${r(e.parent)}`;case"decide":return`decide “${Ss(n.title,140)}” · ${r(e.parent)}`;case"graduate":return`graduate ${r(n.of)} from ${r(e.parent)}`;case"close":return`close ${r(e.parent)}${e.also.length?` and ${e.also.length} derived`:""}`;default:return e.op}}const Mn=typeof globalThis=="object"&&"crypto"in globalThis?globalThis.crypto:void 0;/*! noble-hashes - MIT License (c) 2022 Paul Miller (paulmillr.com) */function Wr(e){return e instanceof Uint8Array||ArrayBuffer.isView(e)&&e.constructor.name==="Uint8Array"}function sn(e){if(!Number.isSafeInteger(e)||e<0)throw new Error("positive integer expected, got "+e)}function Le(e,...t){if(!Wr(e))throw new Error("Uint8Array expected");if(t.length>0&&!t.includes(e.length))throw new Error("Uint8Array expected of length "+t+", got length="+e.length)}function Yr(e){if(typeof e!="function"||typeof e.create!="function")throw new Error("Hash should be wrapped by utils.createHasher");sn(e.outputLen),sn(e.blockLen)}function zs(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 jw(e,t){Le(e);const n=t.outputLen;if(e.length>>t}function as(e,t){return e<>>32-t>>>0}const cl=typeof Uint8Array.from([]).toHex=="function"&&typeof Uint8Array.fromHex=="function",Kw=Array.from({length:256},(e,t)=>t.toString(16).padStart(2,"0"));function Re(e){if(Le(e),cl)return e.toHex();let t="";for(let n=0;n=Bt._0&&e<=Bt._9)return e-Bt._0;if(e>=Bt.A&&e<=Bt.F)return e-(Bt.A-10);if(e>=Bt.a&&e<=Bt.f)return e-(Bt.a-10)}function dt(e){if(typeof e!="string")throw new Error("hex string expected, got "+typeof e);if(cl)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 s=0,o=0;se().update(Dr(r)).digest(),n=e();return t.outputLen=n.outputLen,t.blockLen=n.blockLen,t.create=()=>e(),t}function Dn(e=32){if(Mn&&typeof Mn.getRandomValues=="function")return Mn.getRandomValues(new Uint8Array(e));if(Mn&&typeof Mn.randomBytes=="function")return Uint8Array.from(Mn.randomBytes(e));throw new Error("crypto.getRandomValues must be defined")}function Zw(e,t,n,r){if(typeof e.setBigUint64=="function")return e.setBigUint64(t,n,r);const s=BigInt(32),o=BigInt(4294967295),i=Number(n>>s&o),a=Number(n&o),c=r?4:0,u=r?0:4;e.setUint32(t+c,i,r),e.setUint32(t+u,a,r)}function Mw(e,t,n){return e&t^~e&n}function Vw(e,t,n){return e&t^e&n^t&n}class _a extends ul{constructor(t,n,r,s){super(),this.finished=!1,this.length=0,this.pos=0,this.destroyed=!1,this.blockLen=t,this.outputLen=n,this.padOffset=r,this.isLE=s,this.buffer=new Uint8Array(t),this.view=Tn(this.buffer)}update(t){zs(this),t=Dr(t),Le(t);const{view:n,buffer:r,blockLen:s}=this,o=t.length;for(let i=0;is-i&&(this.process(r,0),i=0);for(let f=i;fl.length)throw new Error("_sha2: outputLen bigger than state");for(let f=0;f>wc&cs)}:{h:Number(e>>wc&cs)|0,l:Number(e&cs)|0}}function zw(e,t=!1){const n=e.length;let r=new Uint32Array(n),s=new Uint32Array(n);for(let o=0;oe>>>n,vc=(e,t,n)=>e<<32-n|t>>>n,Vn=(e,t,n)=>e>>>n|t<<32-n,qn=(e,t,n)=>e<<32-n|t>>>n,us=(e,t,n)=>e<<64-n|t>>>n-32,fs=(e,t,n)=>e>>>n-32|t<<64-n;function Tt(e,t,n,r){const s=(t>>>0)+(r>>>0);return{h:e+n+(s/2**32|0)|0,l:s|0}}const Fw=(e,t,n)=>(e>>>0)+(t>>>0)+(n>>>0),Gw=(e,t,n,r)=>t+n+r+(e/2**32|0)|0,Ww=(e,t,n,r)=>(e>>>0)+(t>>>0)+(n>>>0)+(r>>>0),Yw=(e,t,n,r,s)=>t+n+r+s+(e/2**32|0)|0,Xw=(e,t,n,r,s)=>(e>>>0)+(t>>>0)+(n>>>0)+(r>>>0)+(s>>>0),Jw=(e,t,n,r,s,o)=>t+n+r+s+o+(e/2**32|0)|0,Qw=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]),Wt=new Uint32Array(64);class e1 extends _a{constructor(t=32){super(64,t,8,!1),this.A=Gt[0]|0,this.B=Gt[1]|0,this.C=Gt[2]|0,this.D=Gt[3]|0,this.E=Gt[4]|0,this.F=Gt[5]|0,this.G=Gt[6]|0,this.H=Gt[7]|0}get(){const{A:t,B:n,C:r,D:s,E:o,F:i,G:a,H:c}=this;return[t,n,r,s,o,i,a,c]}set(t,n,r,s,o,i,a,c){this.A=t|0,this.B=n|0,this.C=r|0,this.D=s|0,this.E=o|0,this.F=i|0,this.G=a|0,this.H=c|0}process(t,n){for(let f=0;f<16;f++,n+=4)Wt[f]=t.getUint32(n,!1);for(let f=16;f<64;f++){const d=Wt[f-15],h=Wt[f-2],m=yt(d,7)^yt(d,18)^d>>>3,y=yt(h,17)^yt(h,19)^h>>>10;Wt[f]=y+Wt[f-7]+m+Wt[f-16]|0}let{A:r,B:s,C:o,D:i,E:a,F:c,G:u,H:l}=this;for(let f=0;f<64;f++){const d=yt(a,6)^yt(a,11)^yt(a,25),h=l+d+Mw(a,c,u)+Qw[f]+Wt[f]|0,y=(yt(r,2)^yt(r,13)^yt(r,22))+Vw(r,s,o)|0;l=u,u=c,c=a,a=i+h|0,i=o,o=s,s=r,r=h+y|0}r=r+this.A|0,s=s+this.B|0,o=o+this.C|0,i=i+this.D|0,a=a+this.E|0,c=c+this.F|0,u=u+this.G|0,l=l+this.H|0,this.set(r,s,o,i,a,c,u,l)}roundClean(){St(Wt)}destroy(){this.set(0,0,0,0,0,0,0,0),St(this.buffer)}}const fl=zw(["0x428a2f98d728ae22","0x7137449123ef65cd","0xb5c0fbcfec4d3b2f","0xe9b5dba58189dbbc","0x3956c25bf348b538","0x59f111f1b605d019","0x923f82a4af194f9b","0xab1c5ed5da6d8118","0xd807aa98a3030242","0x12835b0145706fbe","0x243185be4ee4b28c","0x550c7dc3d5ffb4e2","0x72be5d74f27b896f","0x80deb1fe3b1696b1","0x9bdc06a725c71235","0xc19bf174cf692694","0xe49b69c19ef14ad2","0xefbe4786384f25e3","0x0fc19dc68b8cd5b5","0x240ca1cc77ac9c65","0x2de92c6f592b0275","0x4a7484aa6ea6e483","0x5cb0a9dcbd41fbd4","0x76f988da831153b5","0x983e5152ee66dfab","0xa831c66d2db43210","0xb00327c898fb213f","0xbf597fc7beef0ee4","0xc6e00bf33da88fc2","0xd5a79147930aa725","0x06ca6351e003826f","0x142929670a0e6e70","0x27b70a8546d22ffc","0x2e1b21385c26c926","0x4d2c6dfc5ac42aed","0x53380d139d95b3df","0x650a73548baf63de","0x766a0abb3c77b2a8","0x81c2c92e47edaee6","0x92722c851482353b","0xa2bfe8a14cf10364","0xa81a664bbc423001","0xc24b8b70d0f89791","0xc76c51a30654be30","0xd192e819d6ef5218","0xd69906245565a910","0xf40e35855771202a","0x106aa07032bbd1b8","0x19a4c116b8d2d0c8","0x1e376c085141ab53","0x2748774cdf8eeb99","0x34b0bcb5e19b48a8","0x391c0cb3c5c95a63","0x4ed8aa4ae3418acb","0x5b9cca4f7763e373","0x682e6ff3d6b2b8a3","0x748f82ee5defb2fc","0x78a5636f43172f60","0x84c87814a1f0ab72","0x8cc702081a6439ec","0x90befffa23631e28","0xa4506cebde82bde9","0xbef9a3f7b2c67915","0xc67178f2e372532b","0xca273eceea26619c","0xd186b8c721c0c207","0xeada7dd6cde0eb1e","0xf57d4f7fee6ed178","0x06f067aa72176fba","0x0a637dc5a2c898a6","0x113f9804bef90dae","0x1b710b35131c471b","0x28db77f523047d84","0x32caab7b40c72493","0x3c9ebe0a15c9bebc","0x431d67c49c100d4c","0x4cc5d4becb3e42b6","0x597f299cfc657e2a","0x5fcb6fab3ad6faec","0x6c44198c4a475817"].map(e=>BigInt(e))),t1=fl[0],n1=fl[1],Yt=new Uint32Array(80),Xt=new Uint32Array(80);class r1 extends _a{constructor(t=64){super(128,t,16,!1),this.Ah=Pe[0]|0,this.Al=Pe[1]|0,this.Bh=Pe[2]|0,this.Bl=Pe[3]|0,this.Ch=Pe[4]|0,this.Cl=Pe[5]|0,this.Dh=Pe[6]|0,this.Dl=Pe[7]|0,this.Eh=Pe[8]|0,this.El=Pe[9]|0,this.Fh=Pe[10]|0,this.Fl=Pe[11]|0,this.Gh=Pe[12]|0,this.Gl=Pe[13]|0,this.Hh=Pe[14]|0,this.Hl=Pe[15]|0}get(){const{Ah:t,Al:n,Bh:r,Bl:s,Ch:o,Cl:i,Dh:a,Dl:c,Eh:u,El:l,Fh:f,Fl:d,Gh:h,Gl:m,Hh:y,Hl:g}=this;return[t,n,r,s,o,i,a,c,u,l,f,d,h,m,y,g]}set(t,n,r,s,o,i,a,c,u,l,f,d,h,m,y,g){this.Ah=t|0,this.Al=n|0,this.Bh=r|0,this.Bl=s|0,this.Ch=o|0,this.Cl=i|0,this.Dh=a|0,this.Dl=c|0,this.Eh=u|0,this.El=l|0,this.Fh=f|0,this.Fl=d|0,this.Gh=h|0,this.Gl=m|0,this.Hh=y|0,this.Hl=g|0}process(t,n){for(let b=0;b<16;b++,n+=4)Yt[b]=t.getUint32(n),Xt[b]=t.getUint32(n+=4);for(let b=16;b<80;b++){const T=Yt[b-15]|0,A=Xt[b-15]|0,O=Vn(T,A,1)^Vn(T,A,8)^xc(T,A,7),U=qn(T,A,1)^qn(T,A,8)^vc(T,A,7),C=Yt[b-2]|0,_=Xt[b-2]|0,N=Vn(C,_,19)^us(C,_,61)^xc(C,_,6),H=qn(C,_,19)^fs(C,_,61)^vc(C,_,6),K=Ww(U,H,Xt[b-7],Xt[b-16]),v=Yw(K,O,N,Yt[b-7],Yt[b-16]);Yt[b]=v|0,Xt[b]=K|0}let{Ah:r,Al:s,Bh:o,Bl:i,Ch:a,Cl:c,Dh:u,Dl:l,Eh:f,El:d,Fh:h,Fl:m,Gh:y,Gl:g,Hh:p,Hl:w}=this;for(let b=0;b<80;b++){const T=Vn(f,d,14)^Vn(f,d,18)^us(f,d,41),A=qn(f,d,14)^qn(f,d,18)^fs(f,d,41),O=f&h^~f&y,U=d&m^~d&g,C=Xw(w,A,U,n1[b],Xt[b]),_=Jw(C,p,T,O,t1[b],Yt[b]),N=C|0,H=Vn(r,s,28)^us(r,s,34)^us(r,s,39),K=qn(r,s,28)^fs(r,s,34)^fs(r,s,39),v=r&o^r&a^o&a,S=s&i^s&c^i&c;p=y|0,w=g|0,y=h|0,g=m|0,h=f|0,m=d|0,{h:f,l:d}=Tt(u|0,l|0,_|0,N|0),u=a|0,l=c|0,a=o|0,c=i|0,o=r|0,i=s|0;const x=Fw(N,K,S);r=Gw(x,_,H,v),s=x|0}({h:r,l:s}=Tt(this.Ah|0,this.Al|0,r|0,s|0)),{h:o,l:i}=Tt(this.Bh|0,this.Bl|0,o|0,i|0),{h:a,l:c}=Tt(this.Ch|0,this.Cl|0,a|0,c|0),{h:u,l}=Tt(this.Dh|0,this.Dl|0,u|0,l|0),{h:f,l:d}=Tt(this.Eh|0,this.El|0,f|0,d|0),{h,l:m}=Tt(this.Fh|0,this.Fl|0,h|0,m|0),{h:y,l:g}=Tt(this.Gh|0,this.Gl|0,y|0,g|0),{h:p,l:w}=Tt(this.Hh|0,this.Hl|0,p|0,w|0),this.set(r,s,o,i,a,c,u,l,f,d,h,m,y,g,p,w)}roundClean(){St(Yt,Xt)}destroy(){St(this.buffer),this.set(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0)}}const rt=ka(()=>new e1),Zr=ka(()=>new r1),s1=Uint8Array.from([7,4,13,1,10,6,15,3,12,0,9,5,2,14,11,8]),ll=Uint8Array.from(new Array(16).fill(0).map((e,t)=>t)),o1=ll.map(e=>(9*e+5)%16),dl=(()=>{const n=[[ll],[o1]];for(let r=0;r<4;r++)for(let s of n)s.push(s[r].map(o=>s1[o]));return n})(),hl=dl[0],pl=dl[1],gl=[[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)),i1=hl.map((e,t)=>e.map(n=>gl[t][n])),a1=pl.map((e,t)=>e.map(n=>gl[t][n])),c1=Uint32Array.from([0,1518500249,1859775393,2400959708,2840853838]),u1=Uint32Array.from([1352829926,1548603684,1836072691,2053994217,0]);function Ec(e,t,n,r){return e===0?t^n^r:e===1?t&n|~t&r:e===2?(t|~n)^r:e===3?t&r|n&~r:t^(n|~r)}const ls=new Uint32Array(16);class f1 extends _a{constructor(){super(64,20,8,!0),this.h0=1732584193,this.h1=-271733879,this.h2=-1732584194,this.h3=271733878,this.h4=-1009589776}get(){const{h0:t,h1:n,h2:r,h3:s,h4:o}=this;return[t,n,r,s,o]}set(t,n,r,s,o){this.h0=t|0,this.h1=n|0,this.h2=r|0,this.h3=s|0,this.h4=o|0}process(t,n){for(let h=0;h<16;h++,n+=4)ls[h]=t.getUint32(n,!0);let r=this.h0|0,s=r,o=this.h1|0,i=o,a=this.h2|0,c=a,u=this.h3|0,l=u,f=this.h4|0,d=f;for(let h=0;h<5;h++){const m=4-h,y=c1[h],g=u1[h],p=hl[h],w=pl[h],b=i1[h],T=a1[h];for(let A=0;A<16;A++){const O=as(r+Ec(h,o,a,u)+ls[p[A]]+y,b[A])+f|0;r=f,f=u,u=as(a,10)|0,a=o,o=O}for(let A=0;A<16;A++){const O=as(s+Ec(m,i,c,l)+ls[w[A]]+g,T[A])+d|0;s=d,d=l,l=as(c,10)|0,c=i,i=O}}this.set(this.h1+a+l|0,this.h2+u+d|0,this.h3+f+s|0,this.h4+r+i|0,this.h0+o+c|0)}roundClean(){St(ls)}destroy(){this.destroyed=!0,St(this.buffer),this.set(0,0,0,0,0)}}const ml=ka(()=>new f1);class yl extends ul{constructor(t,n){super(),this.finished=!1,this.destroyed=!1,Yr(t);const r=Dr(n);if(this.iHash=t.create(),typeof this.iHash.update!="function")throw new Error("Expected instance of class which extends utils.Hash");this.blockLen=this.iHash.blockLen,this.outputLen=this.iHash.outputLen;const s=this.blockLen,o=new Uint8Array(s);o.set(r.length>s?t.create().update(r).digest():r);for(let i=0;inew yl(e,t).update(n).digest();ln.create=(e,t)=>new yl(e,t);/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */const $a=BigInt(0),_i=BigInt(1);function Nn(e,t=""){if(typeof e!="boolean"){const n=t&&`"${t}"`;throw new Error(n+"expected boolean, got type="+typeof e)}return e}function ct(e,t,n=""){const r=Wr(e),s=e==null?void 0:e.length,o=t!==void 0;if(!r||o&&s!==t){const i=n&&`"${n}" `,a=o?` of length ${t}`:"",c=r?`length=${s}`:`type=${typeof e}`;throw new Error(i+"expected Uint8Array"+a+", got "+c)}return e}function ds(e){const t=e.toString(16);return t.length&1?"0"+t:t}function bl(e){if(typeof e!="string")throw new Error("hex string expected, got "+typeof e);return e===""?$a:BigInt("0x"+e)}function dr(e){return bl(Re(e))}function Ln(e){return Le(e),bl(Re(Uint8Array.from(e).reverse()))}function mo(e,t){return dt(e.toString(16).padStart(t*2,"0"))}function Aa(e,t){return mo(e,t).reverse()}function pe(e,t,n){let r;if(typeof t=="string")try{r=dt(t)}catch(o){throw new Error(e+" must be hex string or Uint8Array, cause: "+o)}else if(Wr(t))r=Uint8Array.from(t);else throw new Error(e+" must be hex string or Uint8Array");const s=r.length;if(typeof n=="number"&&s!==n)throw new Error(e+" of length "+n+" expected, got "+s);return r}function Sc(e){return Uint8Array.from(e)}const Do=e=>typeof e=="bigint"&&$a<=e;function $i(e,t,n){return Do(e)&&Do(t)&&Do(n)&&t<=e&&e$a;e>>=_i,t+=1);return t}const Xr=e=>(_i<new Uint8Array(h),s=h=>Uint8Array.of(h);let o=r(e),i=r(e),a=0;const c=()=>{o.fill(1),i.fill(0),a=0},u=(...h)=>n(i,o,...h),l=(h=r(0))=>{i=u(s(0),h),o=u(),h.length!==0&&(i=u(s(1),h),o=u())},f=()=>{if(a++>=1e3)throw new Error("drbg: tried 1000 values");let h=0;const m=[];for(;h{c(),l(h);let y;for(;!(y=m(f()));)l();return c(),y}}function hr(e,t,n={}){if(!e||typeof e!="object")throw new Error("expected valid options object");function r(s,o,i){const a=e[s];if(i&&a===void 0)return;const c=typeof a;if(c!==o||a===null)throw new Error(`param "${s}" is invalid: expected ${o}, got ${c}`)}Object.entries(t).forEach(([s,o])=>r(s,o,!1)),Object.entries(n).forEach(([s,o])=>r(s,o,!0))}function Fs(e){const t=new WeakMap;return(n,...r)=>{const s=t.get(n);if(s!==void 0)return s;const o=e(n,...r);return t.set(n,o),o}}/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */const Fe=BigInt(0),Oe=BigInt(1),Sn=BigInt(2),xl=BigInt(3),vl=BigInt(4),El=BigInt(5),d1=BigInt(7),Sl=BigInt(8),h1=BigInt(9),kl=BigInt(16);function we(e,t){const n=e%t;return n>=Fe?n:t+n}function ve(e,t,n){let r=e;for(;t-- >Fe;)r*=r,r%=n;return r}function kc(e,t){if(e===Fe)throw new Error("invert: expected non-zero number");if(t<=Fe)throw new Error("invert: expected positive modulus, got "+t);let n=we(e,t),r=t,s=Fe,o=Oe;for(;n!==Fe;){const a=r/n,c=r%n,u=s-o*a;r=n,n=c,s=o,o=u}if(r!==Oe)throw new Error("invert: does not exist");return we(s,t)}function Ba(e,t,n){if(!e.eql(e.sqr(t),n))throw new Error("Cannot find square root")}function _l(e,t){const n=(e.ORDER+Oe)/vl,r=e.pow(t,n);return Ba(e,r,t),r}function p1(e,t){const n=(e.ORDER-El)/Sl,r=e.mul(t,Sn),s=e.pow(r,n),o=e.mul(t,s),i=e.mul(e.mul(o,Sn),s),a=e.mul(o,e.sub(i,e.ONE));return Ba(e,a,t),a}function g1(e){const t=Zn(e),n=$l(e),r=n(t,t.neg(t.ONE)),s=n(t,r),o=n(t,t.neg(r)),i=(e+d1)/kl;return(a,c)=>{let u=a.pow(c,i),l=a.mul(u,r);const f=a.mul(u,s),d=a.mul(u,o),h=a.eql(a.sqr(l),c),m=a.eql(a.sqr(f),c);u=a.cmov(u,l,h),l=a.cmov(d,f,m);const y=a.eql(a.sqr(l),c),g=a.cmov(u,l,y);return Ba(a,g,c),g}}function $l(e){if(e1e3)throw new Error("Cannot find square root: probably non-prime P");if(n===1)return _l;let o=s.pow(r,t);const i=(t+Oe)/Sn;return function(c,u){if(c.is0(u))return u;if(_c(c,u)!==1)throw new Error("Cannot find square root");let l=n,f=c.mul(c.ONE,o),d=c.pow(u,t),h=c.pow(u,i);for(;!c.eql(d,c.ONE);){if(c.is0(d))return c.ZERO;let m=1,y=c.sqr(d);for(;!c.eql(y,c.ONE);)if(m++,y=c.sqr(y),m===l)throw new Error("Cannot find square root");const g=Oe<(we(e,t)&Oe)===Oe,b1=["create","isValid","is0","neg","inv","sqrt","sqr","eql","add","sub","mul","pow","div","addN","subN","mulN","sqrN"];function w1(e){const t={ORDER:"bigint",MASK:"bigint",BYTES:"number",BITS:"number"},n=b1.reduce((r,s)=>(r[s]="function",r),t);return hr(e,n),e}function x1(e,t,n){if(nFe;)n&Oe&&(r=e.mul(r,s)),s=e.sqr(s),n>>=Oe;return r}function Al(e,t,n=!1){const r=new Array(t.length).fill(n?e.ZERO:void 0),s=t.reduce((i,a,c)=>e.is0(a)?i:(r[c]=i,e.mul(i,a)),e.ONE),o=e.inv(s);return t.reduceRight((i,a,c)=>e.is0(a)?i:(r[c]=e.mul(i,r[c]),e.mul(i,a)),o),r}function _c(e,t){const n=(e.ORDER-Oe)/Sn,r=e.pow(t,n),s=e.eql(r,e.ONE),o=e.eql(r,e.ZERO),i=e.eql(r,e.neg(e.ONE));if(!s&&!o&&!i)throw new Error("invalid Legendre symbol result");return s?1:o?0:-1}function Bl(e,t){t!==void 0&&sn(t);const n=t!==void 0?t:e.toString(2).length,r=Math.ceil(n/8);return{nBitLength:n,nByteLength:r}}function Zn(e,t,n=!1,r={}){if(e<=Fe)throw new Error("invalid field: expected ORDER > 0, got "+e);let s,o,i=!1,a;if(typeof t=="object"&&t!=null){if(r.sqrt||n)throw new Error("cannot specify opts in two arguments");const d=t;d.BITS&&(s=d.BITS),d.sqrt&&(o=d.sqrt),typeof d.isLE=="boolean"&&(n=d.isLE),typeof d.modFromBytes=="boolean"&&(i=d.modFromBytes),a=d.allowedLengths}else typeof t=="number"&&(s=t),r.sqrt&&(o=r.sqrt);const{nBitLength:c,nByteLength:u}=Bl(e,s);if(u>2048)throw new Error("invalid field: expected ORDER of <= 2048 bytes");let l;const f=Object.freeze({ORDER:e,isLE:n,BITS:c,BYTES:u,MASK:Xr(c),ZERO:Fe,ONE:Oe,allowedLengths:a,create:d=>we(d,e),isValid:d=>{if(typeof d!="bigint")throw new Error("invalid field element: expected bigint, got "+typeof d);return Fe<=d&&dd===Fe,isValidNot0:d=>!f.is0(d)&&f.isValid(d),isOdd:d=>(d&Oe)===Oe,neg:d=>we(-d,e),eql:(d,h)=>d===h,sqr:d=>we(d*d,e),add:(d,h)=>we(d+h,e),sub:(d,h)=>we(d-h,e),mul:(d,h)=>we(d*h,e),pow:(d,h)=>x1(f,d,h),div:(d,h)=>we(d*kc(h,e),e),sqrN:d=>d*d,addN:(d,h)=>d+h,subN:(d,h)=>d-h,mulN:(d,h)=>d*h,inv:d=>kc(d,e),sqrt:o||(d=>(l||(l=m1(e)),l(f,d))),toBytes:d=>n?Aa(d,u):mo(d,u),fromBytes:(d,h=!0)=>{if(a){if(!a.includes(d.length)||d.length>u)throw new Error("Field.fromBytes: expected "+a+" bytes, got "+d.length);const y=new Uint8Array(u);y.set(d,n?0:y.length-d.length),d=y}if(d.length!==u)throw new Error("Field.fromBytes: expected "+u+" bytes, got "+d.length);let m=n?Ln(d):dr(d);if(i&&(m=we(m,e)),!h&&!f.isValid(m))throw new Error("invalid field element: outside of range 0..ORDER");return m},invertBatch:d=>Al(f,d),cmov:(d,h,m)=>m?h:d});return Object.freeze(f)}function Tl(e){if(typeof e!="bigint")throw new Error("field order must be bigint");const t=e.toString(2).length;return Math.ceil(t/8)}function Il(e){const t=Tl(e);return t+Math.ceil(t/2)}function Ol(e,t,n=!1){const r=e.length,s=Tl(t),o=Il(t);if(r<16||r1024)throw new Error("expected "+o+"-1024 bytes of input, got "+r);const i=n?Ln(e):dr(e),a=we(i,t-Oe)+Oe;return n?Aa(a,s):mo(a,s)}/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */const ir=BigInt(0),kn=BigInt(1);function Gs(e,t){const n=t.negate();return e?n:t}function _n(e,t){const n=Al(e.Fp,t.map(r=>r.Z));return t.map((r,s)=>e.fromAffine(r.toAffine(n[s])))}function Cl(e,t){if(!Number.isSafeInteger(e)||e<=0||e>t)throw new Error("invalid window size, expected [1.."+t+"], got W="+e)}function Zo(e,t){Cl(e,t);const n=Math.ceil(t/e)+1,r=2**(e-1),s=2**e,o=Xr(e),i=BigInt(e);return{windows:n,windowSize:r,mask:o,maxNumber:s,shiftBy:i}}function $c(e,t,n){const{windowSize:r,mask:s,maxNumber:o,shiftBy:i}=n;let a=Number(e&s),c=e>>i;a>r&&(a-=o,c+=kn);const u=t*r,l=u+Math.abs(a)-1,f=a===0,d=a<0,h=t%2!==0;return{nextN:c,offset:l,isZero:f,isNeg:d,isNegF:h,offsetF:u}}function v1(e,t){if(!Array.isArray(e))throw new Error("array expected");e.forEach((n,r)=>{if(!(n instanceof t))throw new Error("invalid point at index "+r)})}function E1(e,t){if(!Array.isArray(e))throw new Error("array of scalars expected");e.forEach((n,r)=>{if(!t.isValid(n))throw new Error("invalid scalar at index "+r)})}const Mo=new WeakMap,Pl=new WeakMap;function Vo(e){return Pl.get(e)||1}function Ac(e){if(e!==ir)throw new Error("invalid wNAF")}class Ul{constructor(t,n){this.BASE=t.BASE,this.ZERO=t.ZERO,this.Fn=t.Fn,this.bits=n}_unsafeLadder(t,n,r=this.ZERO){let s=t;for(;n>ir;)n&kn&&(r=r.add(s)),s=s.double(),n>>=kn;return r}precomputeWindow(t,n){const{windows:r,windowSize:s}=Zo(n,this.bits),o=[];let i=t,a=i;for(let c=0;cir||r>ir;)n&kn&&(o=o.add(s)),r&kn&&(i=i.add(s)),s=s.double(),n>>=kn,r>>=kn;return{p1:o,p2:i}}function Nl(e,t,n,r){v1(n,e),E1(r,t);const s=n.length,o=r.length;if(s!==o)throw new Error("arrays of points and scalars must have equal length");const i=e.ZERO,a=wl(BigInt(s));let c=1;a>12?c=a-3:a>4?c=a-2:a>0&&(c=2);const u=Xr(c),l=new Array(Number(u)+1).fill(i),f=Math.floor((t.BITS-1)/c)*c;let d=i;for(let h=f;h>=0;h-=c){l.fill(i);for(let y=0;y>BigInt(h)&u);l[p]=l[p].add(n[y])}let m=i;for(let y=l.length-1,g=i;y>0;y--)g=g.add(l[y]),m=m.add(g);if(d=d.add(m),h!==0)for(let y=0;yir))throw new Error(`CURVE.${c} must be positive bigint`)}const s=Bc(t.p,n.Fp,r),o=Bc(t.n,n.Fn,r),a=["Gx","Gy","a",e==="weierstrass"?"b":"d"];for(const c of a)if(!s.isValid(t[c]))throw new Error(`CURVE.${c} must be valid field element of CURVE.Fp`);return t=Object.freeze(Object.assign({},t)),{CURVE:t,Fp:s,Fn:o}}/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */const Tc=(e,t)=>(e+(e>=0?t:-t)/Rl)/t;function k1(e,t,n){const[[r,s],[o,i]]=t,a=Tc(i*e,n),c=Tc(-s*e,n);let u=e-a*r-c*o,l=-a*s-c*i;const f=u=h||l=h)throw new Error("splitScalar (endomorphism): failed, k="+e);return{k1neg:f,k1:u,k2neg:d,k2:l}}function Ai(e){if(!["compact","recovered","der"].includes(e))throw new Error('Signature format must be "compact", "recovered", or "der"');return e}function qo(e,t){const n={};for(let r of Object.keys(t))n[r]=e[r]===void 0?t[r]:e[r];return Nn(n.lowS,"lowS"),Nn(n.prehash,"prehash"),n.format!==void 0&&Ai(n.format),n}class _1 extends Error{constructor(t=""){super(t)}}const It={Err:_1,_tlv:{encode:(e,t)=>{const{Err:n}=It;if(e<0||e>256)throw new n("tlv.encode: wrong tag");if(t.length&1)throw new n("tlv.encode: unpadded data");const r=t.length/2,s=ds(r);if(s.length/2&128)throw new n("tlv.encode: long form length too big");const o=r>127?ds(s.length/2|128):"";return ds(e)+o+s+t},decode(e,t){const{Err:n}=It;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 s=t[r++],o=!!(s&128);let i=0;if(!o)i=s;else{const c=s&127;if(!c)throw new n("tlv.decode(long): indefinite length not supported");if(c>4)throw new n("tlv.decode(long): byte length is too big");const u=t.subarray(r,r+c);if(u.length!==c)throw new n("tlv.decode: length bytes not complete");if(u[0]===0)throw new n("tlv.decode(long): zero leftmost byte");for(const l of u)i=i<<8|l;if(r+=c,i<128)throw new n("tlv.decode(long): not minimal encoding")}const a=t.subarray(r,r+i);if(a.length!==i)throw new n("tlv.decode: wrong value length");return{v:a,l:t.subarray(r+i)}}},_int:{encode(e){const{Err:t}=It;if(e{const{X:S,Y:x,Z:k}=K;if(r.eql(k,r.ONE))return{x:S,y:x};const I=K.is0();v==null&&(v=I?r.ONE:r.inv(k));const L=r.mul(S,v),P=r.mul(x,v),j=r.mul(k,v);if(I)return{x:r.ZERO,y:r.ZERO};if(!r.eql(j,r.ONE))throw new Error("invZ was invalid");return{x:L,y:P}}),U=Fs(K=>{if(K.is0()){if(t.allowInfinityPoint&&!r.is0(K.Y))return;throw new Error("bad point: ZERO")}const{x:v,y:S}=K.toAffine();if(!r.isValid(v)||!r.isValid(S))throw new Error("bad point: x or y not field elements");if(!g(v,S))throw new Error("bad point: equation left != right");if(!K.isTorsionFree())throw new Error("bad point: not in prime-order subgroup");return!0});function C(K,v,S,x,k){return S=new _(r.mul(S.X,K),S.Y,S.Z),v=Gs(x,v),S=Gs(k,S),v.add(S)}class _{constructor(v,S,x){this.X=b("x",v),this.Y=b("y",S,!0),this.Z=b("z",x),Object.freeze(this)}static CURVE(){return o}static fromAffine(v){const{x:S,y:x}=v||{};if(!v||!r.isValid(S)||!r.isValid(x))throw new Error("invalid affine point");if(v instanceof _)throw new Error("projective point not allowed");return r.is0(S)&&r.is0(x)?_.ZERO:new _(S,x,r.ONE)}static fromBytes(v){const S=_.fromAffine(m(ct(v,void 0,"point")));return S.assertValidity(),S}static fromHex(v){return _.fromBytes(pe("pointHex",v))}get x(){return this.toAffine().x}get y(){return this.toAffine().y}precompute(v=8,S=!0){return H.createCache(this,v),S||this.multiply(hs),this}assertValidity(){U(this)}hasEvenY(){const{y:v}=this.toAffine();if(!r.isOdd)throw new Error("Field doesn't support isOdd");return!r.isOdd(v)}equals(v){T(v);const{X:S,Y:x,Z:k}=this,{X:I,Y:L,Z:P}=v,j=r.eql(r.mul(S,P),r.mul(I,k)),D=r.eql(r.mul(x,P),r.mul(L,k));return j&&D}negate(){return new _(this.X,r.neg(this.Y),this.Z)}double(){const{a:v,b:S}=o,x=r.mul(S,hs),{X:k,Y:I,Z:L}=this;let P=r.ZERO,j=r.ZERO,D=r.ZERO,q=r.mul(k,k),ie=r.mul(I,I),oe=r.mul(L,L),X=r.mul(k,I);return X=r.add(X,X),D=r.mul(k,L),D=r.add(D,D),P=r.mul(v,D),j=r.mul(x,oe),j=r.add(P,j),P=r.sub(ie,j),j=r.add(ie,j),j=r.mul(P,j),P=r.mul(X,P),D=r.mul(x,D),oe=r.mul(v,oe),X=r.sub(q,oe),X=r.mul(v,X),X=r.add(X,D),D=r.add(q,q),q=r.add(D,q),q=r.add(q,oe),q=r.mul(q,X),j=r.add(j,q),oe=r.mul(I,L),oe=r.add(oe,oe),q=r.mul(oe,X),P=r.sub(P,q),D=r.mul(oe,ie),D=r.add(D,D),D=r.add(D,D),new _(P,j,D)}add(v){T(v);const{X:S,Y:x,Z:k}=this,{X:I,Y:L,Z:P}=v;let j=r.ZERO,D=r.ZERO,q=r.ZERO;const ie=o.a,oe=r.mul(o.b,hs);let X=r.mul(S,I),ue=r.mul(x,L),fe=r.mul(k,P),ke=r.add(S,x),ce=r.add(I,L);ke=r.mul(ke,ce),ce=r.add(X,ue),ke=r.sub(ke,ce),ce=r.add(S,k);let me=r.add(I,P);return ce=r.mul(ce,me),me=r.add(X,fe),ce=r.sub(ce,me),me=r.add(x,k),j=r.add(L,P),me=r.mul(me,j),j=r.add(ue,fe),me=r.sub(me,j),q=r.mul(ie,ce),j=r.mul(oe,fe),q=r.add(j,q),j=r.sub(ue,q),q=r.add(ue,q),D=r.mul(j,q),ue=r.add(X,X),ue=r.add(ue,X),fe=r.mul(ie,fe),ce=r.mul(oe,ce),ue=r.add(ue,fe),fe=r.sub(X,fe),fe=r.mul(ie,fe),ce=r.add(ce,fe),X=r.mul(ue,ce),D=r.add(D,X),X=r.mul(me,ce),j=r.mul(ke,j),j=r.sub(j,X),X=r.mul(ke,ue),q=r.mul(me,q),q=r.add(q,X),new _(j,D,q)}subtract(v){return this.add(v.negate())}is0(){return this.equals(_.ZERO)}multiply(v){const{endo:S}=t;if(!s.isValidNot0(v))throw new Error("invalid scalar: out of range");let x,k;const I=L=>H.cached(this,L,P=>_n(_,P));if(S){const{k1neg:L,k1:P,k2neg:j,k2:D}=A(v),{p:q,f:ie}=I(P),{p:oe,f:X}=I(D);k=ie.add(X),x=C(S.beta,q,oe,L,j)}else{const{p:L,f:P}=I(v);x=L,k=P}return _n(_,[x,k])[0]}multiplyUnsafe(v){const{endo:S}=t,x=this;if(!s.isValid(v))throw new Error("invalid scalar: out of range");if(v===Ot||x.is0())return _.ZERO;if(v===Xn)return x;if(H.hasCache(this))return this.multiply(v);if(S){const{k1neg:k,k1:I,k2neg:L,k2:P}=A(v),{p1:j,p2:D}=S1(_,x,I,P);return C(S.beta,j,D,k,L)}else return H.unsafe(x,v)}multiplyAndAddUnsafe(v,S,x){const k=this.multiplyUnsafe(S).add(v.multiplyUnsafe(x));return k.is0()?void 0:k}toAffine(v){return O(this,v)}isTorsionFree(){const{isTorsionFree:v}=t;return i===Xn?!0:v?v(_,this):H.unsafe(this,a).is0()}clearCofactor(){const{clearCofactor:v}=t;return i===Xn?this:v?v(_,this):this.multiplyUnsafe(i)}isSmallOrder(){return this.multiplyUnsafe(i).is0()}toBytes(v=!0){return Nn(v,"isCompressed"),this.assertValidity(),h(_,this,v)}toHex(v=!0){return Re(this.toBytes(v))}toString(){return``}get px(){return this.X}get py(){return this.X}get pz(){return this.Z}toRawBytes(v=!0){return this.toBytes(v)}_setWindowSize(v){this.precompute(v)}static normalizeZ(v){return _n(_,v)}static msm(v,S){return Nl(_,s,v,S)}static fromPrivateKey(v){return _.BASE.multiply($n(s,v))}}_.BASE=new _(o.Gx,o.Gy,r.ONE),_.ZERO=new _(r.ZERO,r.ONE,r.ZERO),_.Fp=r,_.Fn=s;const N=s.BITS,H=new Ul(_,t.endo?Math.ceil(N/2):N);return _.BASE.precompute(8),_}function Hl(e){return Uint8Array.of(e?2:3)}function jl(e,t){return{secretKey:t.BYTES,publicKey:1+e.BYTES,publicKeyUncompressed:1+2*e.BYTES,publicKeyHasPrefix:!0,signature:2*t.BYTES}}function B1(e,t={}){const{Fn:n}=e,r=t.randomBytes||Dn,s=Object.assign(jl(e.Fp,n),{seed:Il(n.ORDER)});function o(h){try{return!!$n(n,h)}catch{return!1}}function i(h,m){const{publicKey:y,publicKeyUncompressed:g}=s;try{const p=h.length;return m===!0&&p!==y||m===!1&&p!==g?!1:!!e.fromBytes(h)}catch{return!1}}function a(h=r(s.seed)){return Ol(ct(h,s.seed,"seed"),n.ORDER)}function c(h,m=!0){return e.BASE.multiply($n(n,h)).toBytes(m)}function u(h){const m=a(h);return{secretKey:m,publicKey:c(m)}}function l(h){if(typeof h=="bigint")return!1;if(h instanceof e)return!0;const{secretKey:m,publicKey:y,publicKeyUncompressed:g}=s;if(n.allowedLengths||m===y)return;const p=pe("key",h).length;return p===y||p===g}function f(h,m,y=!0){if(l(h)===!0)throw new Error("first arg must be private key");if(l(m)===!1)throw new Error("second arg must be public key");const g=$n(n,h);return e.fromHex(m).multiply(g).toBytes(y)}return Object.freeze({getPublicKey:c,getSharedSecret:f,keygen:u,Point:e,utils:{isValidSecretKey:o,isValidPublicKey:i,randomSecretKey:a,isValidPrivateKey:o,randomPrivateKey:a,normPrivateKeyToScalar:h=>$n(n,h),precompute(h=8,m=e.BASE){return m.precompute(h,!1)}},lengths:s})}function T1(e,t,n={}){Yr(t),hr(n,{},{hmac:"function",lowS:"boolean",randomBytes:"function",bits2int:"function",bits2int_modN:"function"});const r=n.randomBytes||Dn,s=n.hmac||((S,...x)=>ln(t,S,xe(...x))),{Fp:o,Fn:i}=e,{ORDER:a,BITS:c}=i,{keygen:u,getPublicKey:l,getSharedSecret:f,utils:d,lengths:h}=B1(e,n),m={prehash:!1,lowS:typeof n.lowS=="boolean"?n.lowS:!1,format:void 0,extraEntropy:!1},y="compact";function g(S){const x=a>>Xn;return S>x}function p(S,x){if(!i.isValidNot0(x))throw new Error(`invalid signature ${S}: out of range 1..Point.Fn.ORDER`);return x}function w(S,x){Ai(x);const k=h.signature,I=x==="compact"?k:x==="recovered"?k+1:void 0;return ct(S,I,`${x} signature`)}class b{constructor(x,k,I){this.r=p("r",x),this.s=p("s",k),I!=null&&(this.recovery=I),Object.freeze(this)}static fromBytes(x,k=y){w(x,k);let I;if(k==="der"){const{r:D,s:q}=It.toSig(ct(x));return new b(D,q)}k==="recovered"&&(I=x[0],k="compact",x=x.subarray(1));const L=i.BYTES,P=x.subarray(0,L),j=x.subarray(L,L*2);return new b(i.fromBytes(P),i.fromBytes(j),I)}static fromHex(x,k){return this.fromBytes(dt(x),k)}addRecoveryBit(x){return new b(this.r,this.s,x)}recoverPublicKey(x){const k=o.ORDER,{r:I,s:L,recovery:P}=this;if(P==null||![0,1,2,3].includes(P))throw new Error("recovery id invalid");if(a*Rl1)throw new Error("recovery id is ambiguous for h>1 curve");const D=P===2||P===3?I+a:I;if(!o.isValid(D))throw new Error("recovery id 2 or 3 invalid");const q=o.toBytes(D),ie=e.fromBytes(xe(Hl((P&1)===0),q)),oe=i.inv(D),X=A(pe("msgHash",x)),ue=i.create(-X*oe),fe=i.create(L*oe),ke=e.BASE.multiplyUnsafe(ue).add(ie.multiplyUnsafe(fe));if(ke.is0())throw new Error("point at infinify");return ke.assertValidity(),ke}hasHighS(){return g(this.s)}toBytes(x=y){if(Ai(x),x==="der")return dt(It.hexFromSig(this));const k=i.toBytes(this.r),I=i.toBytes(this.s);if(x==="recovered"){if(this.recovery==null)throw new Error("recovery bit must be present");return xe(Uint8Array.of(this.recovery),k,I)}return xe(k,I)}toHex(x){return Re(this.toBytes(x))}assertValidity(){}static fromCompact(x){return b.fromBytes(pe("sig",x),"compact")}static fromDER(x){return b.fromBytes(pe("sig",x),"der")}normalizeS(){return this.hasHighS()?new b(this.r,i.neg(this.s),this.recovery):this}toDERRawBytes(){return this.toBytes("der")}toDERHex(){return Re(this.toBytes("der"))}toCompactRawBytes(){return this.toBytes("compact")}toCompactHex(){return Re(this.toBytes("compact"))}}const T=n.bits2int||function(x){if(x.length>8192)throw new Error("input is too large");const k=dr(x),I=x.length*8-c;return I>0?k>>BigInt(I):k},A=n.bits2int_modN||function(x){return i.create(T(x))},O=Xr(c);function U(S){return Mr("num < 2^"+c,S,Ot,O),i.toBytes(S)}function C(S,x){return ct(S,void 0,"message"),x?ct(t(S),void 0,"prehashed message"):S}function _(S,x,k){if(["recovered","canonical"].some(ue=>ue in k))throw new Error("sign() legacy options not supported");const{lowS:I,prehash:L,extraEntropy:P}=qo(k,m);S=C(S,L);const j=A(S),D=$n(i,x),q=[U(D),U(j)];if(P!=null&&P!==!1){const ue=P===!0?r(h.secretKey):P;q.push(pe("extraEntropy",ue))}const ie=xe(...q),oe=j;function X(ue){const fe=T(ue);if(!i.isValidNot0(fe))return;const ke=i.inv(fe),ce=e.BASE.multiply(fe).toAffine(),me=i.create(ce.x);if(me===Ot)return;const _t=i.create(ke*i.create(oe+me*D));if(_t===Ot)return;let Je=(ce.x===me?0:2)|Number(ce.y&Xn),Ie=_t;return I&&g(_t)&&(Ie=i.neg(_t),Je^=1),new b(me,Ie,Je)}return{seed:ie,k2sig:X}}function N(S,x,k={}){S=pe("message",S);const{seed:I,k2sig:L}=_(S,x,k);return l1(t.outputLen,i.BYTES,s)(I,L)}function H(S){let x;const k=typeof S=="string"||Wr(S),I=!k&&S!==null&&typeof S=="object"&&typeof S.r=="bigint"&&typeof S.s=="bigint";if(!k&&!I)throw new Error("invalid signature, expected Uint8Array, hex string or Signature instance");if(I)x=new b(S.r,S.s);else if(k){try{x=b.fromBytes(pe("sig",S),"der")}catch(L){if(!(L instanceof It.Err))throw L}if(!x)try{x=b.fromBytes(pe("sig",S),"compact")}catch{return!1}}return x||!1}function K(S,x,k,I={}){const{lowS:L,prehash:P,format:j}=qo(I,m);if(k=pe("publicKey",k),x=C(pe("message",x),P),"strict"in I)throw new Error("options.strict was renamed to lowS");const D=j===void 0?H(S):b.fromBytes(pe("sig",S),j);if(D===!1)return!1;try{const q=e.fromBytes(k);if(L&&D.hasHighS())return!1;const{r:ie,s:oe}=D,X=A(x),ue=i.inv(oe),fe=i.create(X*ue),ke=i.create(ie*ue),ce=e.BASE.multiplyUnsafe(fe).add(q.multiplyUnsafe(ke));return ce.is0()?!1:i.create(ce.x)===ie}catch{return!1}}function v(S,x,k={}){const{prehash:I}=qo(k,m);return x=C(x,I),b.fromBytes(S,"recovered").recoverPublicKey(x).toBytes()}return Object.freeze({keygen:u,getPublicKey:l,getSharedSecret:f,utils:d,lengths:h,Point:e,sign:N,verify:K,recoverPublicKey:v,Signature:b,hash:t})}function I1(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(i=>Math.ceil(i/2)))):void 0;const s=Zn(t.n,{BITS:e.nBitLength,allowedLengths:r,modFromBytes:e.wrapPrivateKey}),o={Fp:n,Fn:s,allowInfinityPoint:e.allowInfinityPoint,endo:e.endo,isTorsionFree:e.isTorsionFree,clearCofactor:e.clearCofactor,fromBytes:e.fromBytes,toBytes:e.toBytes};return{CURVE:t,curveOpts:o}}function O1(e){const{CURVE:t,curveOpts:n}=I1(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 C1(e,t){const n=t.Point;return Object.assign({},t,{ProjectivePoint:n,CURVE:Object.assign({},e,Bl(n.Fn.ORDER,n.Fn.BITS))})}function P1(e){const{CURVE:t,curveOpts:n,hash:r,ecdsaOpts:s}=O1(e),o=A1(t,n),i=T1(o,r,s);return C1(e,i)}/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */function U1(e,t){const n=r=>P1({...e,hash:r});return{...n(t),create:n}}/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */const ar={p:BigInt("0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f"),n:BigInt("0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141"),h:BigInt(1),a:BigInt(0),b:BigInt(7),Gx:BigInt("0x79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798"),Gy:BigInt("0x483ada7726a3c4655da4fbfc0e1108a8fd17b448a68554199c47d08ffb10d4b8")},N1={beta:BigInt("0x7ae96a2b657c07106e64479eac3434e99cf0497512f58995c1396c28719501ee"),basises:[[BigInt("0x3086d221a7d46bcde86c90e49284eb15"),-BigInt("0xe4437ed6010e88286f547fa90abfe4c3")],[BigInt("0x114ca50f7a8e2f3f657c1108d9d44cfd8"),BigInt("0x3086d221a7d46bcde86c90e49284eb15")]]},L1=BigInt(0),Ic=BigInt(1),Bi=BigInt(2);function R1(e){const t=ar.p,n=BigInt(3),r=BigInt(6),s=BigInt(11),o=BigInt(22),i=BigInt(23),a=BigInt(44),c=BigInt(88),u=e*e*e%t,l=u*u*e%t,f=ve(l,n,t)*l%t,d=ve(f,n,t)*l%t,h=ve(d,Bi,t)*u%t,m=ve(h,s,t)*h%t,y=ve(m,o,t)*m%t,g=ve(y,a,t)*y%t,p=ve(g,c,t)*g%t,w=ve(p,a,t)*y%t,b=ve(w,n,t)*l%t,T=ve(b,i,t)*m%t,A=ve(T,r,t)*u%t,O=ve(A,Bi,t);if(!Ws.eql(Ws.sqr(O),e))throw new Error("Cannot find square root");return O}const Ws=Zn(ar.p,{sqrt:R1}),ze=U1({...ar,Fp:Ws,lowS:!0,endo:N1},rt),Oc={};function Ys(e,...t){let n=Oc[e];if(n===void 0){const r=rt(Ye(e));n=xe(r,r),Oc[e]=n}return rt(xe(n,...t))}const Ta=e=>e.toBytes(!0).slice(1),pr=ze.Point,Ia=e=>e%Bi===L1;function Ti(e){const{Fn:t,BASE:n}=pr,r=$n(t,e),s=n.multiply(r);return{scalar:Ia(s.y)?r:t.neg(r),bytes:Ta(s)}}function Kl(e){const t=Ws;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 s=t.sqrt(r);Ia(s)||(s=t.neg(s));const o=pr.fromAffine({x:e,y:s});return o.assertValidity(),o}const _r=dr;function Dl(...e){return pr.Fn.create(_r(Ys("BIP0340/challenge",...e)))}function Cc(e){return Ti(e).bytes}function H1(e,t,n=Dn(32)){const{Fn:r}=pr,s=pe("message",e),{bytes:o,scalar:i}=Ti(t),a=pe("auxRand",n,32),c=r.toBytes(i^_r(Ys("BIP0340/aux",a))),u=Ys("BIP0340/nonce",c,o,s),{bytes:l,scalar:f}=Ti(u),d=Dl(l,o,s),h=new Uint8Array(64);if(h.set(l,0),h.set(r.toBytes(r.create(f+d*i)),32),!Zl(h,s,o))throw new Error("sign: Invalid signature produced");return h}function Zl(e,t,n){const{Fn:r,BASE:s}=pr,o=pe("signature",e,64),i=pe("message",t),a=pe("publicKey",n,32);try{const c=Kl(_r(a)),u=_r(o.subarray(0,32));if(!$i(u,Ic,ar.p))return!1;const l=_r(o.subarray(32,64));if(!$i(l,Ic,ar.n))return!1;const f=Dl(r.toBytes(u),Ta(c),i),d=s.multiplyUnsafe(l).add(c.multiplyUnsafe(r.neg(f))),{x:h,y:m}=d.toAffine();return!(d.is0()||!Ia(m)||h!==u)}catch{return!1}}const Ml=(()=>{const n=(s=Dn(48))=>Ol(s,ar.n);ze.utils.randomSecretKey;function r(s){const o=n(s);return{secretKey:o,publicKey:Cc(o)}}return{keygen:r,getPublicKey:Cc,sign:H1,verify:Zl,Point:pr,utils:{randomSecretKey:n,randomPrivateKey:n,taggedHash:Ys,lift_x:Kl,pointToBytes:Ta,numberToBytesBE:mo,bytesToNumberBE:dr,mod:we},lengths:{secretKey:32,publicKey:32,publicKeyHasPrefix:!1,signature:64,seed:48}}})(),Xs=Re,j1=dt,tn="super-testnet-local-v0";class dn{constructor(t){if(!/^[0-9a-f]{64}$/.test(t)||!ze.utils.isValidPrivateKey(t))throw new Error("Invalid test wallet key. Load a Super Testnet v0 backup.");this.kind="test-wallet",this.secret=t,this.pubkey=Xs(Ml.getPublicKey(t)),this.address=Tr.p2tr.fromPubKey(this.pubkey,"regtest"),this.script=["OP_1",this.pubkey]}static create(){return new dn(Xs(ze.utils.randomPrivateKey()))}static load(t){if((t==null?void 0:t.network)!==tn||(t==null?void 0:t.version)!==1||(t==null?void 0:t.kind)!=="test-wallet")throw new Error("Only Super Testnet v0 test-wallet backups are accepted.");return new dn(t.secret)}backup(){return{kind:"test-wallet",version:1,network:tn,secret:this.secret}}sign(t,n,r=0){return lo.taproot.sign(this.secret,t,r,n?{extension:n}:{}).hex}}const zo=50*1e8,ps="0".repeat(64),Pc=e=>Xs(rt(new TextEncoder().encode(JSON.stringify(e)))),gs=(e,t)=>`${e}:${t}`,qe=e=>Se.encode(e,!1).hex,de=(e,t)=>{if(!e)throw new Error(t)},K1=/^5120[0-9a-f]{64}$/,Fo=/^0014[0-9a-f]{40}$/,Vl=64,D1=e=>Xs(ml(rt(j1(e))));function Z1(e,t){const[n,r]=e.vin[t].witness;return ze.verify(n.slice(0,-2),lo.segwit.hash(e,t,{pubkey:r,sigflag:1}),r,{lowS:!0,format:"der"})}class yo{constructor(t){if(this.blocks=[],this.mempool=[],this.utxos=new Map,this.transactions=new Map,t){de(t.network===tn&&t.version===1,"Unsupported local chain version/network."),de(Array.isArray(t.blocks)&&Array.isArray(t.mempool),"Invalid chain snapshot.");for(const n of t.blocks)this.acceptBlock(structuredClone(n));this.submitPackage(t.mempool)}}snapshot(){return{network:tn,version:1,blocks:structuredClone(this.blocks),mempool:[...this.mempool]}}coins(t){return[...this.utxos.values()].filter(n=>qe(n.scriptPubKey)===qe(t))}satLocation(t){for(const n of this.utxos.values()){const r=xs(n.ranges,t);if(r!==null)return{txid:n.txid,vout:n.vout,offset:r}}return null}balance(t){return this.coins(t).reduce((n,r)=>n+r.value,0)}apply(t,n,r=!1){var h,m,y;de(typeof t=="string"&&t.length<4e4&&/^(?:[a-f0-9]{2})+$/.test(t),"Invalid raw transaction.");const s=ae.decode(t),o=ae.util.getTxid(s);de(!this.transactions.has(o),"Duplicate transaction."),de(s.version===2&&s.locktime===0,"Unsupported transaction version or locktime."),de((s.vin.length===1||!r&&s.vin.length===2)&&s.vout.length>=1&&s.vout.length<=(r?Vl:2),"Unsupported transaction shape.");let i=0;for(const g of s.vout){const p=Number(g.value);de(Number.isSafeInteger(p)&&p>=330&&p<=zo,"Invalid output amount.");const w=qe(g.scriptPubKey);de(K1.test(w)||Fo.test(w),"Only Taproot and P2WPKH outputs are supported."),i+=p}let a,c=[];const u=s.vin.findIndex(g=>{var p;return((p=g.witness)==null?void 0:p.length)===3}),l=s.vin[u<0?0:u];if(r)de(l.txid===ps&&l.vout===4294967295&&i===zo,"Invalid local coinbase."),de(qe(l.scriptSig)===Se.encode([new TextEncoder().encode(`${tn}:${n}`)],!1).hex,"Wrong coinbase height."),de(!((h=l.witness)!=null&&h.length),"Unexpected coinbase witness.");else{c=s.vin.map(p=>this.utxos.get(gs(p.txid,p.vout))),de(c.every(Boolean),"Input is missing or already spent."),de(new Set(s.vin.map(p=>gs(p.txid,p.vout))).size===s.vin.length,"Duplicate input."),s.vin.forEach((p,w)=>{var T,A,O;de(p.sequence==="ffffffff"&&qe(p.scriptSig)==="","Unsupported input flags."),p.prevout={value:c[w].value,scriptPubKey:c[w].scriptPubKey};const b=qe(c[w].scriptPubKey);if(Fo.test(b)){const[U,C]=p.witness??[];de(w!==u&&((T=p.witness)==null?void 0:T.length)===2,"Unsupported witness."),de(/^30[0-9a-f]{12,140}01$/.test(U)&&/^0[23][0-9a-f]{64}$/.test(C)&&D1(C)===b.slice(4),"P2WPKH spends need a SIGHASH_ALL signature by the key they pay.");return}de(((A=p.witness)==null?void 0:A.length)===1||w===u&&((O=p.witness)==null?void 0:O.length)===3,"Unsupported witness."),de(/^[0-9a-f]{128}$/.test(p.witness[0]),"Only default 64-byte Schnorr signatures are accepted.")}),de(c.reduce((p,w)=>p+w.value,0)-i===he,"v0 requires a fixed 500 sat fee per transaction.");let g={};if(l.witness.length===3){const p=xa(l.witness),w=u;if(de(Number(s.vout[w].value)===bt,"Invalid reveal postage."),de(qe(s.vout[w].scriptPubKey)===`5120${p.pubkey}`,"Reveal must return to its signing wallet."),p.parent){const b=u===0?1:0,T=c[b];de((m=T==null?void 0:T.inscriptions)==null?void 0:m.some(A=>A.id===p.parent),"Referenced parent inscription must actually be spent."),de(s.vout.length===2&&Number(s.vout[b].value)===T.value&&qe(T.scriptPubKey)===`5120${p.pubkey}`&&qe(s.vout[b].scriptPubKey)===qe(T.scriptPubKey),"Parent must be owned and preserved in the same wallet.")}else s.vin.length===2&&(de(u===1&&((y=c[0].inscriptions)==null?void 0:y.length)&&p.pointer!==void 0,"Reinscription spend requires correct tag and owned sat."),de(Number(s.vout[0].value)===c[0].value&&qe(s.vout[0].scriptPubKey)===qe(c[0].scriptPubKey)&&qe(c[0].scriptPubKey)===`5120${p.pubkey}`,"Reinscription sat must be returned to owner."));g={pubkey:p.pubkey},a={id:`${o}i0`,txid:o,commitTxid:l.txid,text:p.text,bytes:Array.from(p.bytes),contentType:p.contentType,parent:p.parent,delegate:p.delegate,pointer:p.pointer,metaprotocol:p.metaprotocol,metadata:p.metadata,height:n,value:bt}}s.vin.forEach((p,w)=>{let b=!1;try{b=Fo.test(qe(c[w].scriptPubKey))?Z1(s,w):lo.taproot.verify(s,w,w===u?g:{})}catch{}de(b,"Invalid signature or Taproot commitment.")})}const f=Xc(s,c,n,r),d=c.flatMap(g=>g.inscriptions??[]);if(a){const g=BigInt(a.pointer??0),p=g{var b;return((b=w.inscription)==null?void 0:b.sat)===a.sat}).length,d.push(a)}return de(d.every(g=>f.some(p=>xs(p,g.sat)!==null)),"Local lab protects inscription sats from fee loss."),r||s.vin.forEach(g=>this.utxos.delete(gs(g.txid,g.vout))),s.vout.forEach((g,p)=>{const w=d.filter(b=>xs(f[p],b.sat)!==null);this.utxos.set(gs(o,p),{txid:o,vout:p,value:Number(g.value),scriptPubKey:g.scriptPubKey,height:n,ranges:f[p],inscriptions:w,...w.length?{inscription:w[0]}:{}})}),this.transactions.set(o,{txid:o,raw:t,height:n,coinbase:r,tx:s,...a?{inscription:a}:{}}),o}submitPackage(t){de(Array.isArray(t)&&this.mempool.length+t.length<=1e3,"Invalid package or mempool full; mine a block first.");const n=new Map(this.utxos),r=new Map(this.transactions);try{t.forEach(s=>this.apply(s,null))}catch(s){throw this.utxos=n,this.transactions=r,s}this.mempool.push(...t)}acceptBlock(t){var i;de(t.height===this.blocks.length+1&&t.previous===(((i=this.blocks.at(-1))==null?void 0:i.hash)??ps),"Invalid block ancestry."),de(Number.isSafeInteger(t.time)&&t.time>0&&Array.isArray(t.raws)&&t.raws.length>0&&t.raws.length<=1001,"Invalid block.");const{hash:n,...r}=t;de(Pc(r)===n,"Invalid local block hash.");const s=new Map(this.utxos),o=new Map(this.transactions);try{t.raws.forEach((a,c)=>this.apply(a,t.height,c===0))}catch(a){throw this.utxos=s,this.transactions=o,a}this.blocks.push(t)}mine(t){return this.mineTo([De(zo,t)])}mineTo(t){var a;const n=new yo({...this.snapshot(),mempool:[]}),r=this.blocks.length+1,s=ae.create({vin:[{txid:ps,vout:4294967295,scriptSig:[new TextEncoder().encode(`${tn}:${r}`)]}],vout:t}),o={height:r,previous:((a=this.blocks.at(-1))==null?void 0:a.hash)??ps,time:Date.now(),raws:[ae.encode(s).hex,...this.mempool]},i={...o,hash:Pc(o)};return n.acceptBlock(i),Object.assign(this,n),i}}/*! scure-base - MIT License (c) 2022 Paul Miller (paulmillr.com) */function cr(e){return e instanceof Uint8Array||ArrayBuffer.isView(e)&&e.constructor.name==="Uint8Array"}function M1(e,...t){if(!cr(e))throw new Error("Uint8Array expected");if(t.length>0&&!t.includes(e.length))throw new Error("Uint8Array expected of length "+t+", got length="+e.length)}function ql(e,t){return Array.isArray(t)?t.length===0?!0:e?t.every(n=>typeof n=="string"):t.every(n=>Number.isSafeInteger(n)):!1}function zl(e){if(typeof e!="function")throw new Error("function expected");return!0}function Rn(e,t){if(typeof t!="string")throw new Error(`${e}: string expected`);return!0}function gr(e){if(!Number.isSafeInteger(e))throw new Error(`invalid integer: ${e}`)}function Js(e){if(!Array.isArray(e))throw new Error("array expected")}function Qs(e,t){if(!ql(!0,t))throw new Error(`${e}: array of strings expected`)}function Oa(e,t){if(!ql(!1,t))throw new Error(`${e}: array of numbers expected`)}function Jr(...e){const t=o=>o,n=(o,i)=>a=>o(i(a)),r=e.map(o=>o.encode).reduceRight(n,t),s=e.map(o=>o.decode).reduce(n,t);return{encode:r,decode:s}}function bo(e){const t=typeof e=="string"?e.split(""):e,n=t.length;Qs("alphabet",t);const r=new Map(t.map((s,o)=>[s,o]));return{encode:s=>(Js(s),s.map(o=>{if(!Number.isSafeInteger(o)||o<0||o>=n)throw new Error(`alphabet.encode: digit index outside alphabet "${o}". Allowed: ${e}`);return t[o]})),decode:s=>(Js(s),s.map(o=>{Rn("alphabet.decode",o);const i=r.get(o);if(i===void 0)throw new Error(`Unknown letter: "${o}". Allowed: ${e}`);return i}))}}function wo(e=""){return Rn("join",e),{encode:t=>(Qs("join.decode",t),t.join(e)),decode:t=>(Rn("join.decode",t),t.split(e))}}function Fl(e,t="="){return gr(e),Rn("padding",t),{encode(n){for(Qs("padding.encode",n);n.length*e%8;)n.push(t);return n},decode(n){Qs("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)}}}function Ii(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(Js(e),!e.length)return[];let r=0;const s=[],o=Array.from(e,a=>{if(gr(a),a<0||a>=t)throw new Error(`invalid integer: ${a}`);return a}),i=o.length;for(;;){let a=0,c=!0;for(let u=r;ut===0?e:Gl(t,e%t),eo=(e,t)=>e+(t-Gl(e,t)),ks=(()=>{let e=[];for(let t=0;t<40;t++)e.push(2**t);return e})();function to(e,t,n,r){if(Js(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(eo(t,n)>32)throw new Error(`convertRadix2: carry overflow from=${t} to=${n} carryBits=${eo(t,n)}`);let s=0,o=0;const i=ks[t],a=ks[n]-1,c=[];for(const u of e){if(gr(u),u>=i)throw new Error(`convertRadix2: invalid data word=${u} from=${t}`);if(s=s<32)throw new Error(`convertRadix2: carry overflow pos=${o} from=${t}`);for(o+=t;o>=n;o-=n)c.push((s>>o-n&a)>>>0);const l=ks[o];if(l===void 0)throw new Error("invalid carry");s&=l-1}if(s=s<=t)throw new Error("Excess padding");if(!r&&s>0)throw new Error(`Non-zero padding: ${s}`);return r&&o>0&&c.push(s>>>0),c}function Wl(e){gr(e);const t=2**8;return{encode:n=>{if(!cr(n))throw new Error("radix.encode input should be Uint8Array");return Ii(Array.from(n),t,e)},decode:n=>(Oa("radix.decode",n),Uint8Array.from(Ii(n,e,t)))}}function Ca(e,t=!1){if(gr(e),e<=0||e>32)throw new Error("radix2: bits should be in (0..32]");if(eo(8,e)>32||eo(e,8)>32)throw new Error("radix2: carry overflow");return{encode:n=>{if(!cr(n))throw new Error("radix2.encode input should be Uint8Array");return to(Array.from(n),8,e,!t)},decode:n=>(Oa("radix2.decode",n),Uint8Array.from(to(n,e,8,t)))}}function Uc(e){return zl(e),function(...t){try{return e.apply(null,t)}catch{}}}function Yl(e,t){return gr(e),zl(t),{encode(n){if(!cr(n))throw new Error("checksum.encode: input should be Uint8Array");const r=t(n).slice(0,e),s=new Uint8Array(n.length+e);return s.set(n),s.set(r,n.length),s},decode(n){if(!cr(n))throw new Error("checksum.decode: input should be Uint8Array");const r=n.slice(0,-e),s=n.slice(-e),o=t(r).slice(0,e);for(let i=0;i{Rn("base64",e);const n=/^[A-Za-z0-9=+/]+$/,r="base64";if(e.length>0&&!n.test(e))throw new Error("invalid base64");return Uint8Array.fromBase64(e,{alphabet:r,lastChunkHandling:"strict"})},wt=V1?{encode(e){return M1(e),e.toBase64()},decode(e){return q1(e)}}:Jr(Ca(6),bo("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"),Fl(6),wo("")),z1=e=>Jr(Wl(58),bo(e),wo("")),F1=z1("123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"),Xl=e=>Jr(Yl(4,t=>e(e(t))),F1),Oi=Jr(bo("qpzry9x8gf2tvdw0s3jn54khce6mua7l"),wo("")),Nc=[996825010,642813549,513874426,1027748829,705979059];function vr(e){const t=e>>25;let n=(e&33554431)<<5;for(let r=0;r>r&1)===1&&(n^=Nc[r]);return n}function Lc(e,t,n=1){const r=e.length;let s=1;for(let o=0;o126)throw new Error(`Invalid prefix (${e})`);s=vr(s)^i>>5}s=vr(s);for(let o=0;oh)throw new TypeError(`Length ${y} exceeds limit ${h}`);const g=f.toLowerCase(),p=Lc(g,d,t);return`${g}1${Oi.encode(d)}${p}`}function a(f,d=90){Rn("bech32.decode input",f);const h=f.length;if(h<8||d!==!1&&h>d)throw new TypeError(`invalid string length: ${h} (${f}). Expected (8..${d})`);const m=f.toLowerCase();if(f!==m&&f!==f.toUpperCase())throw new Error("String must be lowercase or uppercase");const y=m.lastIndexOf("1");if(y===0||y===-1)throw new Error('Letter "1" must be present between prefix and data only');const g=m.slice(0,y),p=m.slice(y+1);if(p.length<6)throw new Error("Data must be at least 6 characters long");const w=Oi.decode(p).slice(0,-6),b=Lc(g,w,t);if(!p.endsWith(b))throw new Error(`Invalid checksum in ${f}: expected "${b}"`);return{prefix:g,words:w}}const c=Uc(a);function u(f){const{prefix:d,words:h}=a(f,!1);return{prefix:d,words:h,bytes:r(h)}}function l(f,d){return i(f,s(d))}return{encode:i,decode:a,encodeFromBytes:l,decodeToBytes:u,decodeUnsafe:c,fromWords:r,fromWordsUnsafe:o,toWords:s}}const no=G1("bech32");/*! scure-bip32 - MIT License (c) 2022 Patricio Palladino, Paul Miller (paulmillr.com) */const ys=ze.ProjectivePoint,Go=Xl(rt);function Rc(e){Le(e);const t=e.length===0?"0":Re(e);return BigInt("0x"+t)}function W1(e){if(typeof e!="bigint")throw new Error("bigint expected");return dt(e.toString(16).padStart(64,"0"))}const Y1=Ye("Bitcoin seed"),Wo={private:76066276,public:76067358},Yo=2147483648,X1=e=>ml(rt(e)),J1=e=>Tn(e).getUint32(0,!1),bs=e=>{if(!Number.isSafeInteger(e)||e<0||e>2**32-1)throw new Error("invalid number, should be from 0 to 2**32-1, got "+e);const t=new Uint8Array(4);return Tn(t).setUint32(0,e,!1),t};class bn{get fingerprint(){if(!this.pubHash)throw new Error("No publicKey set!");return J1(this.pubHash)}get identifier(){return this.pubHash}get pubKeyHash(){return this.pubHash}get privateKey(){return this.privKeyBytes||null}get publicKey(){return this.pubKey||null}get privateExtendedKey(){const t=this.privateKey;if(!t)throw new Error("No private key");return Go.encode(this.serialize(this.versions.private,xe(new Uint8Array([0]),t)))}get publicExtendedKey(){if(!this.pubKey)throw new Error("No public key");return Go.encode(this.serialize(this.versions.public,this.pubKey))}static fromMasterSeed(t,n=Wo){if(Le(t),8*t.length<128||8*t.length>512)throw new Error("HDKey: seed length must be between 128 and 512 bits; 256 bits is advised, got "+t.length);const r=ln(Zr,Y1,t);return new bn({versions:n,chainCode:r.slice(32),privateKey:r.slice(0,32)})}static fromExtendedKey(t,n=Wo){const r=Go.decode(t),s=Tn(r),o=s.getUint32(0,!1),i={versions:n,depth:r[4],parentFingerprint:s.getUint32(5,!1),index:s.getUint32(9,!1),chainCode:r.slice(13,45)},a=r.slice(45),c=a[0]===0;if(o!==n[c?"private":"public"])throw new Error("Version mismatch");return c?new bn({...i,privateKey:a.slice(1)}):new bn({...i,publicKey:a})}static fromJSON(t){return bn.fromExtendedKey(t.xpriv)}constructor(t){if(this.depth=0,this.index=0,this.chainCode=null,this.parentFingerprint=0,!t||typeof t!="object")throw new Error("HDKey.constructor must not be called directly");if(this.versions=t.versions||Wo,this.depth=t.depth||0,this.chainCode=t.chainCode||null,this.index=t.index||0,this.parentFingerprint=t.parentFingerprint||0,!this.depth&&(this.parentFingerprint||this.index))throw new Error("HDKey: zero depth with non-zero index/parent fingerprint");if(t.publicKey&&t.privateKey)throw new Error("HDKey: publicKey and privateKey at same time.");if(t.privateKey){if(!ze.utils.isValidPrivateKey(t.privateKey))throw new Error("Invalid private key");this.privKey=typeof t.privateKey=="bigint"?t.privateKey:Rc(t.privateKey),this.privKeyBytes=W1(this.privKey),this.pubKey=ze.getPublicKey(t.privateKey,!0)}else if(t.publicKey)this.pubKey=ys.fromHex(t.publicKey).toRawBytes(!0);else throw new Error("HDKey: no public or private key provided");this.pubHash=X1(this.pubKey)}derive(t){if(!/^[mM]'?/.test(t))throw new Error('Path must start with "m" or "M"');if(/^[mM]'?$/.test(t))return this;const n=t.replace(/^[mM]'?\//,"").split("/");let r=this;for(const s of n){const o=/^(\d+)('?)$/.exec(s),i=o&&o[1];if(!o||o.length!==3||typeof i!="string")throw new Error("invalid child index: "+s);let a=+i;if(!Number.isSafeInteger(a)||a>=Yo)throw new Error("Invalid index");o[2]==="'"&&(a+=Yo),r=r.deriveChild(a)}return r}deriveChild(t){if(!this.pubKey||!this.chainCode)throw new Error("No publicKey or chainCode set");let n=bs(t);if(t>=Yo){const a=this.privateKey;if(!a)throw new Error("Could not derive hardened child key");n=xe(new Uint8Array([0]),a,n)}else n=xe(this.pubKey,n);const r=ln(Zr,this.chainCode,n),s=Rc(r.slice(0,32)),o=r.slice(32);if(!ze.utils.isValidPrivateKey(s))throw new Error("Tweak bigger than curve order");const i={versions:this.versions,chainCode:o,depth:this.depth+1,parentFingerprint:this.fingerprint,index:t};try{if(this.privateKey){const a=we(this.privKey+s,ze.CURVE.n);if(!ze.utils.isValidPrivateKey(a))throw new Error("The tweak was out of range or the resulted private key is invalid");i.privateKey=a}else{const a=ys.fromHex(this.pubKey).add(ys.fromPrivateKey(s));if(a.equals(ys.ZERO))throw new Error("The tweak was equal to negative P, which made the result key invalid");i.publicKey=a.toRawBytes(!0)}return new bn(i)}catch{return this.deriveChild(t+1)}}sign(t){if(!this.privateKey)throw new Error("No privateKey set!");return Le(t,32),ze.sign(t,this.privKey).toCompactRawBytes()}verify(t,n){if(Le(t,32),Le(n,64),!this.publicKey)throw new Error("No publicKey set!");let r;try{r=ze.Signature.fromCompact(n)}catch{return!1}return ze.verify(r,t,this.publicKey)}wipePrivateData(){return this.privKey=void 0,this.privKeyBytes&&(this.privKeyBytes.fill(0),this.privKeyBytes=void 0),this}toJSON(){return{xpriv:this.privateExtendedKey,xpub:this.publicExtendedKey}}serialize(t,n){if(!this.chainCode)throw new Error("No chainCode set");return Le(n,33),xe(bs(t),new Uint8Array([this.depth]),bs(this.parentFingerprint),bs(this.index),this.chainCode,n)}}function Q1(e,t,n,r){Yr(e);const s=Dw({dkLen:32,asyncTick:10},r),{c:o,dkLen:i,asyncTick:a}=s;if(sn(o),sn(i),sn(a),o<1)throw new Error("iterations (c) should be >= 1");const c=bc(t),u=bc(n),l=new Uint8Array(i),f=ln.create(e,c),d=f._cloneInto().update(u);return{c:o,dkLen:i,asyncTick:a,DK:l,PRF:f,PRFSalt:d}}function ex(e,t,n,r,s){return e.destroy(),t.destroy(),r&&r.destroy(),St(s),n}function tx(e,t,n,r){const{c:s,dkLen:o,DK:i,PRF:a,PRFSalt:c}=Q1(e,t,n,r);let u;const l=new Uint8Array(4),f=Tn(l),d=new Uint8Array(a.outputLen);for(let h=1,m=0;me[0]==="あいこくしん";function Jl(e){if(typeof e!="string")throw new TypeError("invalid mnemonic type: "+typeof e);return e.normalize("NFKD")}function Ql(e){const t=Jl(e),n=t.split(" ");if(![12,15,18,21,24].includes(n.length))throw new Error("Invalid mnemonic");return{nfkd:t,words:n}}function ed(e){Le(e,16,20,24,28,32)}function rx(e,t=128){if(sn(t),t%32!==0||t>256)throw new TypeError("Invalid entropy");return nd(Dn(t/8),e)}const sx=e=>{const t=8-e.length/4;return new Uint8Array([rt(e)[0]>>t<{if(typeof t!="string")throw new Error("wordlist: non-string element: "+t)}),ms.chain(ms.checksum(1,sx),ms.radix2(11,!0),ms.alphabet(e))}function ox(e,t){const{words:n}=Ql(e),r=td(t).decode(n);return ed(r),r}function nd(e,t){return ed(e),td(t).encode(e).join(nx(t)?" ":" ")}function ix(e,t){try{ox(e,t)}catch{return!1}return!0}const ax=e=>Jl("mnemonic"+e);function cx(e,t=""){return tx(Zr,Ql(e).nfkd,ax(t),{c:2048,dkLen:64})}const Pa=`abandon +ability +able +about +above +absent +absorb +abstract +absurd +abuse +access +accident +account +accuse +achieve +acid +acoustic +acquire +across +act +action +actor +actress +actual +adapt +add +addict +address +adjust +admit +adult +advance +advice +aerobic +affair +afford +afraid +again +age +agent +agree +ahead +aim +air +airport +aisle +alarm +album +alcohol +alert +alien +all +alley +allow +almost +alone +alpha +already +also +alter +always +amateur +amazing +among +amount +amused +analyst +anchor +ancient +anger +angle +angry +animal +ankle +announce +annual +another +answer +antenna +antique +anxiety +any +apart +apology +appear +apple +approve +april +arch +arctic +area +arena +argue +arm +armed +armor +army +around +arrange +arrest +arrive +arrow +art +artefact +artist +artwork +ask +aspect +assault +asset +assist +assume +asthma +athlete +atom +attack +attend +attitude +attract +auction +audit +august +aunt +author +auto +autumn +average +avocado +avoid +awake +aware +away +awesome +awful +awkward +axis +baby +bachelor +bacon +badge +bag +balance +balcony +ball +bamboo +banana +banner +bar +barely +bargain +barrel +base +basic +basket +battle +beach +bean +beauty +because +become +beef +before +begin +behave +behind +believe +below +belt +bench +benefit +best +betray +better +between +beyond +bicycle +bid +bike +bind +biology +bird +birth +bitter +black +blade +blame +blanket +blast +bleak +bless +blind +blood +blossom +blouse +blue +blur +blush +board +boat +body +boil +bomb +bone +bonus +book +boost +border +boring +borrow +boss +bottom +bounce +box +boy +bracket +brain +brand +brass +brave +bread +breeze +brick +bridge +brief +bright +bring +brisk +broccoli +broken +bronze +broom +brother +brown +brush +bubble +buddy +budget +buffalo +build +bulb +bulk +bullet +bundle +bunker +burden +burger +burst +bus +business +busy +butter +buyer +buzz +cabbage +cabin +cable +cactus +cage +cake +call +calm +camera +camp +can +canal +cancel +candy +cannon +canoe +canvas +canyon +capable +capital +captain +car +carbon +card +cargo +carpet +carry +cart +case +cash +casino +castle +casual +cat +catalog +catch +category +cattle +caught +cause +caution +cave +ceiling +celery +cement +census +century +cereal +certain +chair +chalk +champion +change +chaos +chapter +charge +chase +chat +cheap +check +cheese +chef +cherry +chest +chicken +chief +child +chimney +choice +choose +chronic +chuckle +chunk +churn +cigar +cinnamon +circle +citizen +city +civil +claim +clap +clarify +claw +clay +clean +clerk +clever +click +client +cliff +climb +clinic +clip +clock +clog +close +cloth +cloud +clown +club +clump +cluster +clutch +coach +coast +coconut +code +coffee +coil +coin +collect +color +column +combine +come +comfort +comic +common +company +concert +conduct +confirm +congress +connect +consider +control +convince +cook +cool +copper +copy +coral +core +corn +correct +cost +cotton +couch +country +couple +course +cousin +cover +coyote +crack +cradle +craft +cram +crane +crash +crater +crawl +crazy +cream +credit +creek +crew +cricket +crime +crisp +critic +crop +cross +crouch +crowd +crucial +cruel +cruise +crumble +crunch +crush +cry +crystal +cube +culture +cup +cupboard +curious +current +curtain +curve +cushion +custom +cute +cycle +dad +damage +damp +dance +danger +daring +dash +daughter +dawn +day +deal +debate +debris +decade +december +decide +decline +decorate +decrease +deer +defense +define +defy +degree +delay +deliver +demand +demise +denial +dentist +deny +depart +depend +deposit +depth +deputy +derive +describe +desert +design +desk +despair +destroy +detail +detect +develop +device +devote +diagram +dial +diamond +diary +dice +diesel +diet +differ +digital +dignity +dilemma +dinner +dinosaur +direct +dirt +disagree +discover +disease +dish +dismiss +disorder +display +distance +divert +divide +divorce +dizzy +doctor +document +dog +doll +dolphin +domain +donate +donkey +donor +door +dose +double +dove +draft +dragon +drama +drastic +draw +dream +dress +drift +drill +drink +drip +drive +drop +drum +dry +duck +dumb +dune +during +dust +dutch +duty +dwarf +dynamic +eager +eagle +early +earn +earth +easily +east +easy +echo +ecology +economy +edge +edit +educate +effort +egg +eight +either +elbow +elder +electric +elegant +element +elephant +elevator +elite +else +embark +embody +embrace +emerge +emotion +employ +empower +empty +enable +enact +end +endless +endorse +enemy +energy +enforce +engage +engine +enhance +enjoy +enlist +enough +enrich +enroll +ensure +enter +entire +entry +envelope +episode +equal +equip +era +erase +erode +erosion +error +erupt +escape +essay +essence +estate +eternal +ethics +evidence +evil +evoke +evolve +exact +example +excess +exchange +excite +exclude +excuse +execute +exercise +exhaust +exhibit +exile +exist +exit +exotic +expand +expect +expire +explain +expose +express +extend +extra +eye +eyebrow +fabric +face +faculty +fade +faint +faith +fall +false +fame +family +famous +fan +fancy +fantasy +farm +fashion +fat +fatal +father +fatigue +fault +favorite +feature +february +federal +fee +feed +feel +female +fence +festival +fetch +fever +few +fiber +fiction +field +figure +file +film +filter +final +find +fine +finger +finish +fire +firm +first +fiscal +fish +fit +fitness +fix +flag +flame +flash +flat +flavor +flee +flight +flip +float +flock +floor +flower +fluid +flush +fly +foam +focus +fog +foil +fold +follow +food +foot +force +forest +forget +fork +fortune +forum +forward +fossil +foster +found +fox +fragile +frame +frequent +fresh +friend +fringe +frog +front +frost +frown +frozen +fruit +fuel +fun +funny +furnace +fury +future +gadget +gain +galaxy +gallery +game +gap +garage +garbage +garden +garlic +garment +gas +gasp +gate +gather +gauge +gaze +general +genius +genre +gentle +genuine +gesture +ghost +giant +gift +giggle +ginger +giraffe +girl +give +glad +glance +glare +glass +glide +glimpse +globe +gloom +glory +glove +glow +glue +goat +goddess +gold +good +goose +gorilla +gospel +gossip +govern +gown +grab +grace +grain +grant +grape +grass +gravity +great +green +grid +grief +grit +grocery +group +grow +grunt +guard +guess +guide +guilt +guitar +gun +gym +habit +hair +half +hammer +hamster +hand +happy +harbor +hard +harsh +harvest +hat +have +hawk +hazard +head +health +heart +heavy +hedgehog +height +hello +helmet +help +hen +hero +hidden +high +hill +hint +hip +hire +history +hobby +hockey +hold +hole +holiday +hollow +home +honey +hood +hope +horn +horror +horse +hospital +host +hotel +hour +hover +hub +huge +human +humble +humor +hundred +hungry +hunt +hurdle +hurry +hurt +husband +hybrid +ice +icon +idea +identify +idle +ignore +ill +illegal +illness +image +imitate +immense +immune +impact +impose +improve +impulse +inch +include +income +increase +index +indicate +indoor +industry +infant +inflict +inform +inhale +inherit +initial +inject +injury +inmate +inner +innocent +input +inquiry +insane +insect +inside +inspire +install +intact +interest +into +invest +invite +involve +iron +island +isolate +issue +item +ivory +jacket +jaguar +jar +jazz +jealous +jeans +jelly +jewel +job +join +joke +journey +joy +judge +juice +jump +jungle +junior +junk +just +kangaroo +keen +keep +ketchup +key +kick +kid +kidney +kind +kingdom +kiss +kit +kitchen +kite +kitten +kiwi +knee +knife +knock +know +lab +label +labor +ladder +lady +lake +lamp +language +laptop +large +later +latin +laugh +laundry +lava +law +lawn +lawsuit +layer +lazy +leader +leaf +learn +leave +lecture +left +leg +legal +legend +leisure +lemon +lend +length +lens +leopard +lesson +letter +level +liar +liberty +library +license +life +lift +light +like +limb +limit +link +lion +liquid +list +little +live +lizard +load +loan +lobster +local +lock +logic +lonely +long +loop +lottery +loud +lounge +love +loyal +lucky +luggage +lumber +lunar +lunch +luxury +lyrics +machine +mad +magic +magnet +maid +mail +main +major +make +mammal +man +manage +mandate +mango +mansion +manual +maple +marble +march +margin +marine +market +marriage +mask +mass +master +match +material +math +matrix +matter +maximum +maze +meadow +mean +measure +meat +mechanic +medal +media +melody +melt +member +memory +mention +menu +mercy +merge +merit +merry +mesh +message +metal +method +middle +midnight +milk +million +mimic +mind +minimum +minor +minute +miracle +mirror +misery +miss +mistake +mix +mixed +mixture +mobile +model +modify +mom +moment +monitor +monkey +monster +month +moon +moral +more +morning +mosquito +mother +motion +motor +mountain +mouse +move +movie +much +muffin +mule +multiply +muscle +museum +mushroom +music +must +mutual +myself +mystery +myth +naive +name +napkin +narrow +nasty +nation +nature +near +neck +need +negative +neglect +neither +nephew +nerve +nest +net +network +neutral +never +news +next +nice +night +noble +noise +nominee +noodle +normal +north +nose +notable +note +nothing +notice +novel +now +nuclear +number +nurse +nut +oak +obey +object +oblige +obscure +observe +obtain +obvious +occur +ocean +october +odor +off +offer +office +often +oil +okay +old +olive +olympic +omit +once +one +onion +online +only +open +opera +opinion +oppose +option +orange +orbit +orchard +order +ordinary +organ +orient +original +orphan +ostrich +other +outdoor +outer +output +outside +oval +oven +over +own +owner +oxygen +oyster +ozone +pact +paddle +page +pair +palace +palm +panda +panel +panic +panther +paper +parade +parent +park +parrot +party +pass +patch +path +patient +patrol +pattern +pause +pave +payment +peace +peanut +pear +peasant +pelican +pen +penalty +pencil +people +pepper +perfect +permit +person +pet +phone +photo +phrase +physical +piano +picnic +picture +piece +pig +pigeon +pill +pilot +pink +pioneer +pipe +pistol +pitch +pizza +place +planet +plastic +plate +play +please +pledge +pluck +plug +plunge +poem +poet +point +polar +pole +police +pond +pony +pool +popular +portion +position +possible +post +potato +pottery +poverty +powder +power +practice +praise +predict +prefer +prepare +present +pretty +prevent +price +pride +primary +print +priority +prison +private +prize +problem +process +produce +profit +program +project +promote +proof +property +prosper +protect +proud +provide +public +pudding +pull +pulp +pulse +pumpkin +punch +pupil +puppy +purchase +purity +purpose +purse +push +put +puzzle +pyramid +quality +quantum +quarter +question +quick +quit +quiz +quote +rabbit +raccoon +race +rack +radar +radio +rail +rain +raise +rally +ramp +ranch +random +range +rapid +rare +rate +rather +raven +raw +razor +ready +real +reason +rebel +rebuild +recall +receive +recipe +record +recycle +reduce +reflect +reform +refuse +region +regret +regular +reject +relax +release +relief +rely +remain +remember +remind +remove +render +renew +rent +reopen +repair +repeat +replace +report +require +rescue +resemble +resist +resource +response +result +retire +retreat +return +reunion +reveal +review +reward +rhythm +rib +ribbon +rice +rich +ride +ridge +rifle +right +rigid +ring +riot +ripple +risk +ritual +rival +river +road +roast +robot +robust +rocket +romance +roof +rookie +room +rose +rotate +rough +round +route +royal +rubber +rude +rug +rule +run +runway +rural +sad +saddle +sadness +safe +sail +salad +salmon +salon +salt +salute +same +sample +sand +satisfy +satoshi +sauce +sausage +save +say +scale +scan +scare +scatter +scene +scheme +school +science +scissors +scorpion +scout +scrap +screen +script +scrub +sea +search +season +seat +second +secret +section +security +seed +seek +segment +select +sell +seminar +senior +sense +sentence +series +service +session +settle +setup +seven +shadow +shaft +shallow +share +shed +shell +sheriff +shield +shift +shine +ship +shiver +shock +shoe +shoot +shop +short +shoulder +shove +shrimp +shrug +shuffle +shy +sibling +sick +side +siege +sight +sign +silent +silk +silly +silver +similar +simple +since +sing +siren +sister +situate +six +size +skate +sketch +ski +skill +skin +skirt +skull +slab +slam +sleep +slender +slice +slide +slight +slim +slogan +slot +slow +slush +small +smart +smile +smoke +smooth +snack +snake +snap +sniff +snow +soap +soccer +social +sock +soda +soft +solar +soldier +solid +solution +solve +someone +song +soon +sorry +sort +soul +sound +soup +source +south +space +spare +spatial +spawn +speak +special +speed +spell +spend +sphere +spice +spider +spike +spin +spirit +split +spoil +sponsor +spoon +sport +spot +spray +spread +spring +spy +square +squeeze +squirrel +stable +stadium +staff +stage +stairs +stamp +stand +start +state +stay +steak +steel +stem +step +stereo +stick +still +sting +stock +stomach +stone +stool +story +stove +strategy +street +strike +strong +struggle +student +stuff +stumble +style +subject +submit +subway +success +such +sudden +suffer +sugar +suggest +suit +summer +sun +sunny +sunset +super +supply +supreme +sure +surface +surge +surprise +surround +survey +suspect +sustain +swallow +swamp +swap +swarm +swear +sweet +swift +swim +swing +switch +sword +symbol +symptom +syrup +system +table +tackle +tag +tail +talent +talk +tank +tape +target +task +taste +tattoo +taxi +teach +team +tell +ten +tenant +tennis +tent +term +test +text +thank +that +theme +then +theory +there +they +thing +this +thought +three +thrive +throw +thumb +thunder +ticket +tide +tiger +tilt +timber +time +tiny +tip +tired +tissue +title +toast +tobacco +today +toddler +toe +together +toilet +token +tomato +tomorrow +tone +tongue +tonight +tool +tooth +top +topic +topple +torch +tornado +tortoise +toss +total +tourist +toward +tower +town +toy +track +trade +traffic +tragic +train +transfer +trap +trash +travel +tray +treat +tree +trend +trial +tribe +trick +trigger +trim +trip +trophy +trouble +truck +true +truly +trumpet +trust +truth +try +tube +tuition +tumble +tuna +tunnel +turkey +turn +turtle +twelve +twenty +twice +twin +twist +two +type +typical +ugly +umbrella +unable +unaware +uncle +uncover +under +undo +unfair +unfold +unhappy +uniform +unique +unit +universe +unknown +unlock +until +unusual +unveil +update +upgrade +uphold +upon +upper +upset +urban +urge +usage +use +used +useful +useless +usual +utility +vacant +vacuum +vague +valid +valley +valve +van +vanish +vapor +various +vast +vault +vehicle +velvet +vendor +venture +venue +verb +verify +version +very +vessel +veteran +viable +vibrant +vicious +victory +video +view +village +vintage +violin +virtual +virus +visa +visit +visual +vital +vivid +vocal +voice +void +volcano +volume +vote +voyage +wage +wagon +wait +walk +wall +walnut +want +warfare +warm +warrior +wash +wasp +waste +water +wave +way +wealth +weapon +wear +weasel +weather +web +wedding +weekend +weird +welcome +west +wet +whale +what +wheat +wheel +when +where +whip +whisper +wide +width +wife +wild +will +win +window +wine +wing +wink +winner +winter +wire +wisdom +wise +wish +witness +wolf +woman +wonder +wood +wool +word +work +world +worry +worth +wrap +wreck +wrestle +wrist +write +wrong +yard +year +yellow +you +young +youth +zebra +zero +zone +zoo`.split(` +`),tt={orgSeed:e=>`m/83696968'/39'/0'/24'/${e}'`,wallet:(e,t=1)=>`m/86'/${t}'/${e}'/0/0`,segwit:(e,t=1)=>`m/84'/${t}'/${e}'/0/0`,nostr:e=>`m/44'/1237'/${e}'/0/0`},ux=2**31-1,Xo=new Map,Jo=new Map,Hc=()=>rx(Pa,256);function rd(e,t=0){if(typeof e!="string"||!ix(e,Pa)||t&&e.split(" ").length!==t)throw new Error("Invalid lab mnemonic.");return e}function mr(e,t){if(!Number.isSafeInteger(e)||e<0||e>ux)throw new Error(`Invalid ${t}.`);return e}const Qo=new Map;function Ua(e){return Qo.has(e)||Qo.set(e,cx(rd(e))),Qo.get(e)}function yr(e){return Xo.has(e)||Xo.set(e,bn.fromMasterSeed(Ua(e))),Xo.get(e)}function fx(e,t){const n=e.derive(t).privateKey;if(!n)throw new Error("BIP-85 path produced no private key.");return ln(Zr,Ye("bip-entropy-from-k"),n)}function lx(e,t){const n=`${e}|${mr(t,"child index")}`;return Jo.has(n)||Jo.set(n,nd(fx(yr(e),tt.orgSeed(t)).slice(0,32),Pa)),Jo.get(n)}function Ci(e,t=0,n=1){return Re(yr(e).derive(tt.wallet(mr(t,"account"),n)).privateKey)}function sd(e,t=0,n=1){return Re(yr(e).derive(tt.segwit(mr(t,"account"),n)).privateKey)}function od(e,t=0,n=1){return Re(yr(e).derive(tt.segwit(mr(t,"account"),n)).publicKey)}function Na(e,t=0){return Re(yr(e).derive(tt.nostr(mr(t,"account"))).privateKey)}function dx(e,t=0){const n=Ml.getPublicKey(yr(e).derive(tt.nostr(mr(t,"account"))).privateKey);return{pubkey:Re(n),npub:no.encode("npub",no.toWords(n))}}const id="lineage-claim",Pi=330,ro=e=>Se.encode(e,!1).hex,jc=e=>({txid:e.txid,vout:e.vout,value:e.value,script:ro(e.scriptPubKey)}),ei=/^[0-9a-f]{64}$/,hx=/^5120[0-9a-f]{64}$/;function La(e,t){var n;for(const r of e.utxos.values())if((n=r.inscriptions)!=null&&n.some(s=>s.id===t))return r;return null}function ad(e){return ae.create({vin:[rn(e.holder.txid,e.holder.vout,e.holder.value,e.holder.script),rn(e.payer.txid,e.payer.vout,e.payer.value,e.payer.script)],vout:[De(e.holder.value,["OP_1",e.to]),De(e.payer.value-he,["OP_1",e.to])]})}function px(e,t,n,r=Date.now()){if((n==null?void 0:n.kind)!=="test-wallet")throw new Error("Claims are signed by local test wallets.");const s=La(e,t);if(!s)throw new Error("That inscription is not in an unspent output.");if(ro(s.scriptPubKey)===ro(n.script))throw new Error("The recipient already holds that inscription.");const o=e.coins(n.script).find(c=>{var u;return!((u=c.inscriptions)!=null&&u.length)&&c.value>=he+Pi});if(!o)throw new Error("The recipient needs a plain coin for the 500-sat fee. Mine a block to it first.");const i={kind:id,version:1,inscription:t,carried:s.inscriptions.map(c=>c.id),holder:jc(s),payer:jc(o),to:n.pubkey,at:r},a=ad(i);return i.txid=ae.util.getTxid(a),i.sig=n.sign(a,void 0,1),i}function gx(e,t,n){const r=yx(t);if((n==null?void 0:n.kind)!=="test-wallet")throw new Error("Countersigning needs a local test wallet.");if(ro(n.script)!==r.holder.script)throw new Error("Only the current holder can countersign.");if(mx(e,r)!=="open")throw new Error("This claim is stale: an input it spends was already spent.");const s=ad(r);return s.vin[1].witness=[r.sig],s.vin[0].witness=[n.sign(s,void 0,0)],e.submitPackage([ae.encode(s).hex]),ae.util.getTxid(s)}function mx(e,t){return e.utxos.has(`${t.holder.txid}:${t.holder.vout}`)&&e.utxos.has(`${t.payer.txid}:${t.payer.vout}`)?"open":"stale"}function yx(e){const t=n=>n&&ei.test(n.txid)&&Number.isSafeInteger(n.vout)&&n.vout>=0&&Number.isSafeInteger(n.value)&&n.value>=Pi&&hx.test(n.script);if((e==null?void 0:e.kind)!==id||e.version!==1||!/^[0-9a-f]{64}i\d+$/.test(e.inscription)||!Array.isArray(e.carried)||!t(e.holder)||!t(e.payer)||e.payer.value255*s)throw new Error("Length should be <= 255*HashLen");const o=Math.ceil(r/s);n===void 0&&(n=Kc);const i=new Uint8Array(o*s),a=ln.create(e,t),c=a._cloneInto(),u=new Uint8Array(a.outputLen);for(let l=0;lwx(e,bx(e,t,n),r,s);/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */const Jt=BigInt(0),Be=BigInt(1),ni=BigInt(2),vx=BigInt(8);function Ex(e,t,n,r){const s=e.sqr(n),o=e.sqr(r),i=e.add(e.mul(t.a,s),o),a=e.add(e.ONE,e.mul(t.d,e.mul(s,o)));return e.eql(i,a)}function Sx(e,t={}){const n=Ll("edwards",e,t,t.FpFnLE),{Fp:r,Fn:s}=n;let o=n.CURVE;const{h:i}=o;hr(t,{},{uvRatio:"function"});const a=ni<r.create(g),u=t.uvRatio||((g,p)=>{try{return{isValid:!0,value:r.sqrt(r.div(g,p))}}catch{return{isValid:!1,value:Jt}}});if(!Ex(r,o,o.Gx,o.Gy))throw new Error("bad curve params: generator point");function l(g,p,w=!1){const b=w?Be:Jt;return Mr("coordinate "+g,p,b,a),p}function f(g){if(!(g instanceof m))throw new Error("ExtendedPoint expected")}const d=Fs((g,p)=>{const{X:w,Y:b,Z:T}=g,A=g.is0();p==null&&(p=A?vx:r.inv(T));const O=c(w*p),U=c(b*p),C=r.mul(T,p);if(A)return{x:Jt,y:Be};if(C!==Be)throw new Error("invZ was invalid");return{x:O,y:U}}),h=Fs(g=>{const{a:p,d:w}=o;if(g.is0())throw new Error("bad point: ZERO");const{X:b,Y:T,Z:A,T:O}=g,U=c(b*b),C=c(T*T),_=c(A*A),N=c(_*_),H=c(U*p),K=c(_*c(H+C)),v=c(N+c(w*c(U*C)));if(K!==v)throw new Error("bad point: equation left != right (1)");const S=c(b*T),x=c(A*O);if(S!==x)throw new Error("bad point: equation left != right (2)");return!0});class m{constructor(p,w,b,T){this.X=l("x",p),this.Y=l("y",w),this.Z=l("z",b,!0),this.T=l("t",T),Object.freeze(this)}static CURVE(){return o}static fromAffine(p){if(p instanceof m)throw new Error("extended point not allowed");const{x:w,y:b}=p||{};return l("x",w),l("y",b),new m(w,b,Be,c(w*b))}static fromBytes(p,w=!1){const b=r.BYTES,{a:T,d:A}=o;p=Sc(ct(p,b,"point")),Nn(w,"zip215");const O=Sc(p),U=p[b-1];O[b-1]=U&-129;const C=Ln(O),_=w?a:r.ORDER;Mr("point.y",C,Jt,_);const N=c(C*C),H=c(N-Be),K=c(A*N-T);let{isValid:v,value:S}=u(H,K);if(!v)throw new Error("bad point: invalid y coordinate");const x=(S&Be)===Be,k=(U&128)!==0;if(!w&&S===Jt&&k)throw new Error("bad point: x=0 and x_0=1");return k!==x&&(S=c(-S)),m.fromAffine({x:S,y:C})}static fromHex(p,w=!1){return m.fromBytes(pe("point",p),w)}get x(){return this.toAffine().x}get y(){return this.toAffine().y}precompute(p=8,w=!0){return y.createCache(this,p),w||this.multiply(ni),this}assertValidity(){h(this)}equals(p){f(p);const{X:w,Y:b,Z:T}=this,{X:A,Y:O,Z:U}=p,C=c(w*U),_=c(A*T),N=c(b*U),H=c(O*T);return C===_&&N===H}is0(){return this.equals(m.ZERO)}negate(){return new m(c(-this.X),this.Y,this.Z,c(-this.T))}double(){const{a:p}=o,{X:w,Y:b,Z:T}=this,A=c(w*w),O=c(b*b),U=c(ni*c(T*T)),C=c(p*A),_=w+b,N=c(c(_*_)-A-O),H=C+O,K=H-U,v=C-O,S=c(N*K),x=c(H*v),k=c(N*v),I=c(K*H);return new m(S,x,I,k)}add(p){f(p);const{a:w,d:b}=o,{X:T,Y:A,Z:O,T:U}=this,{X:C,Y:_,Z:N,T:H}=p,K=c(T*C),v=c(A*_),S=c(U*b*H),x=c(O*N),k=c((T+A)*(C+_)-K-v),I=x-S,L=x+S,P=c(v-w*K),j=c(k*I),D=c(L*P),q=c(k*P),ie=c(I*L);return new m(j,D,ie,q)}subtract(p){return this.add(p.negate())}multiply(p){if(!s.isValidNot0(p))throw new Error("invalid scalar: expected 1 <= sc < curve.n");const{p:w,f:b}=y.cached(this,p,T=>_n(m,T));return _n(m,[w,b])[0]}multiplyUnsafe(p,w=m.ZERO){if(!s.isValid(p))throw new Error("invalid scalar: expected 0 <= sc < curve.n");return p===Jt?m.ZERO:this.is0()||p===Be?this:y.unsafe(this,p,b=>_n(m,b),w)}isSmallOrder(){return this.multiplyUnsafe(i).is0()}isTorsionFree(){return y.unsafe(this,o.n).is0()}toAffine(p){return d(this,p)}clearCofactor(){return i===Be?this:this.multiplyUnsafe(i)}toBytes(){const{x:p,y:w}=this.toAffine(),b=r.toBytes(w);return b[b.length-1]|=p&Be?128:0,b}toHex(){return Re(this.toBytes())}toString(){return``}get ex(){return this.X}get ey(){return this.Y}get ez(){return this.Z}get et(){return this.T}static normalizeZ(p){return _n(m,p)}static msm(p,w){return Nl(m,s,p,w)}_setWindowSize(p){this.precompute(p)}toRawBytes(){return this.toBytes()}}m.BASE=new m(o.Gx,o.Gy,Be,c(o.Gx*o.Gy)),m.ZERO=new m(Jt,Be,Be,Jt),m.Fp=r,m.Fn=s;const y=new Ul(m,s.BITS);return m.BASE.precompute(8),m}function kx(e,t,n={}){if(typeof t!="function")throw new Error('"hash" function param is required');hr(n,{},{adjustScalarBytes:"function",randomBytes:"function",domain:"function",prehash:"function",mapToCurve:"function"});const{prehash:r}=n,{BASE:s,Fp:o,Fn:i}=e,a=n.randomBytes||Dn,c=n.adjustScalarBytes||(_=>_),u=n.domain||((_,N,H)=>{if(Nn(H,"phflag"),N.length||H)throw new Error("Contexts/pre-hash are not supported");return _});function l(_){return i.create(Ln(_))}function f(_){const N=b.secretKey;_=pe("private key",_,N);const H=pe("hashed private key",t(_),2*N),K=c(H.slice(0,N)),v=H.slice(N,2*N),S=l(K);return{head:K,prefix:v,scalar:S}}function d(_){const{head:N,prefix:H,scalar:K}=f(_),v=s.multiply(K),S=v.toBytes();return{head:N,prefix:H,scalar:K,point:v,pointBytes:S}}function h(_){return d(_).pointBytes}function m(_=Uint8Array.of(),...N){const H=xe(...N);return l(t(u(H,pe("context",_),!!r)))}function y(_,N,H={}){_=pe("message",_),r&&(_=r(_));const{prefix:K,scalar:v,pointBytes:S}=d(N),x=m(H.context,K,_),k=s.multiply(x).toBytes(),I=m(H.context,k,S,_),L=i.create(x+I*v);if(!i.isValid(L))throw new Error("sign failed: invalid s");const P=xe(k,i.toBytes(L));return ct(P,b.signature,"result")}const g={zip215:!0};function p(_,N,H,K=g){const{context:v,zip215:S}=K,x=b.signature;_=pe("signature",_,x),N=pe("message",N),H=pe("publicKey",H,b.publicKey),S!==void 0&&Nn(S,"zip215"),r&&(N=r(N));const k=x/2,I=_.subarray(0,k),L=Ln(_.subarray(k,x));let P,j,D;try{P=e.fromBytes(H,S),j=e.fromBytes(I,S),D=s.multiplyUnsafe(L)}catch{return!1}if(!S&&P.isSmallOrder())return!1;const q=m(v,j.toBytes(),P.toBytes(),N);return j.add(P.multiplyUnsafe(q)).subtract(D).clearCofactor().is0()}const w=o.BYTES,b={secretKey:w,publicKey:w,signature:2*w,seed:w};function T(_=a(b.seed)){return ct(_,b.seed,"seed")}function A(_){const N=C.randomSecretKey(_);return{secretKey:N,publicKey:h(N)}}function O(_){return Wr(_)&&_.length===i.BYTES}function U(_,N){try{return!!e.fromBytes(_,N)}catch{return!1}}const C={getExtendedPublicKey:d,randomSecretKey:T,isValidSecretKey:O,isValidPublicKey:U,toMontgomery(_){const{y:N}=e.fromBytes(_),H=b.publicKey,K=H===32;if(!K&&H!==57)throw new Error("only defined for 25519 and 448");const v=K?o.div(Be+N,Be-N):o.div(N-Be,N+Be);return o.toBytes(v)},toMontgomerySecret(_){const N=b.secretKey;ct(_,N);const H=t(_.subarray(0,N));return c(H).subarray(0,N)},randomPrivateKey:T,precompute(_=8,N=e.BASE){return N.precompute(_,!1)}};return Object.freeze({keygen:A,getPublicKey:h,sign:y,verify:p,utils:C,Point:e,lengths:b})}function _x(e){const t={a:e.a,d:e.d,p:e.Fp.ORDER,n:e.n,h:e.h,Gx:e.Gx,Gy:e.Gy},n=e.Fp,r=Zn(t.n,e.nBitLength,!0),s={Fp:n,Fn:r,uvRatio:e.uvRatio},o={randomBytes:e.randomBytes,adjustScalarBytes:e.adjustScalarBytes,domain:e.domain,prehash:e.prehash,mapToCurve:e.mapToCurve};return{CURVE:t,curveOpts:s,hash:e.hash,eddsaOpts:o}}function $x(e,t){const n=t.Point;return Object.assign({},t,{ExtendedPoint:n,CURVE:e,nBitLength:n.Fn.BITS,nByteLength:n.Fn.BYTES})}function Ax(e){const{CURVE:t,curveOpts:n,hash:r,eddsaOpts:s}=_x(e),o=Sx(t,n),i=kx(o,r,s);return $x(e,i)}/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */const Er=BigInt(0),zn=BigInt(1),ws=BigInt(2);function Bx(e){return hr(e,{adjustScalarBytes:"function",powPminus2:"function"}),Object.freeze({...e})}function Tx(e){const t=Bx(e),{P:n,type:r,adjustScalarBytes:s,powPminus2:o,randomBytes:i}=t,a=r==="x25519";if(!a&&r!=="x448")throw new Error("invalid type");const c=i||Dn,u=a?255:448,l=a?32:56,f=BigInt(a?9:5),d=BigInt(a?121665:39081),h=a?ws**BigInt(254):ws**BigInt(447),m=a?BigInt(8)*ws**BigInt(251)-zn:BigInt(4)*ws**BigInt(445)-zn,y=h+m+zn,g=v=>we(v,n),p=w(f);function w(v){return Aa(g(v),l)}function b(v){const S=pe("u coordinate",v,l);return a&&(S[31]&=127),g(Ln(S))}function T(v){return Ln(s(pe("scalar",v,l)))}function A(v,S){const x=C(b(S),T(v));if(x===Er)throw new Error("invalid private or public key received");return w(x)}function O(v){return A(v,p)}function U(v,S,x){const k=g(v*(S-x));return S=g(S-k),x=g(x+k),{x_2:S,x_3:x}}function C(v,S){Mr("u",v,Er,n),Mr("scalar",S,h,y);const x=S,k=v;let I=zn,L=Er,P=v,j=zn,D=Er;for(let ie=BigInt(u-1);ie>=Er;ie--){const oe=x>>ie&zn;D^=oe,{x_2:I,x_3:P}=U(D,I,P),{x_2:L,x_3:j}=U(D,L,j),D=oe;const X=I+L,ue=g(X*X),fe=I-L,ke=g(fe*fe),ce=ue-ke,me=P+j,_t=P-j,Je=g(_t*X),Ie=g(me*fe),$t=Je+Ie,wr=Je-Ie;P=g($t*$t),j=g(k*g(wr*wr)),I=g(ue*ke),L=g(ce*(ue+g(d*ce)))}({x_2:I,x_3:P}=U(D,I,P)),{x_2:L,x_3:j}=U(D,L,j);const q=o(L);return g(I*q)}const _={secretKey:l,publicKey:l,seed:l},N=(v=c(l))=>(Le(v,_.seed),v);function H(v){const S=N(v);return{secretKey:S,publicKey:O(S)}}return{keygen:H,getSharedSecret:(v,S)=>A(v,S),getPublicKey:v=>O(v),scalarMult:A,scalarMultBase:O,utils:{randomSecretKey:N,randomPrivateKey:N},GuBytes:p.slice(),lengths:_}}/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */const Ix=BigInt(1),Dc=BigInt(2),Ox=BigInt(3),Cx=BigInt(5),Px=BigInt(8),Ra=BigInt("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffed"),cd={p:Ra,n:BigInt("0x1000000000000000000000000000000014def9dea2f79cd65812631a5cf5d3ed"),h:Px,a:BigInt("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffec"),d:BigInt("0x52036cee2b6ffe738cc740797779e89800700a4d4141d8ab75eb4dca135978a3"),Gx:BigInt("0x216936d3cd6e53fec0a4e231fdd6dc5c692cc7609525a7b2c9562d608f25d51a"),Gy:BigInt("0x6666666666666666666666666666666666666666666666666666666666666658")};function ud(e){const t=BigInt(10),n=BigInt(20),r=BigInt(40),s=BigInt(80),o=Ra,a=e*e%o*e%o,c=ve(a,Dc,o)*a%o,u=ve(c,Ix,o)*e%o,l=ve(u,Cx,o)*u%o,f=ve(l,t,o)*l%o,d=ve(f,n,o)*f%o,h=ve(d,r,o)*d%o,m=ve(h,s,o)*h%o,y=ve(m,s,o)*h%o,g=ve(y,t,o)*l%o;return{pow_p_5_8:ve(g,Dc,o)*e%o,b2:a}}function fd(e){return e[0]&=248,e[31]&=127,e[31]|=64,e}const Zc=BigInt("19681161376707505956807079304988542015446066515923890162744021073123829784752");function Ux(e,t){const n=Ra,r=we(t*t*t,n),s=we(r*r*t,n),o=ud(e*s).pow_p_5_8;let i=we(e*r*o,n);const a=we(t*i*i,n),c=i,u=we(i*Zc,n),l=a===e,f=a===we(-e,n),d=a===we(-e*Zc,n);return l&&(i=c),(f||d)&&(i=u),y1(i,n)&&(i=we(-i,n)),{isValid:l||f,value:i}}const ld=Zn(cd.p,{isLE:!0}),Nx={...cd,Fp:ld,hash:Zr,adjustScalarBytes:fd,uvRatio:Ux},xo=Ax(Nx),dd=(()=>{const e=ld.ORDER;return Tx({P:e,type:"x25519",powPminus2:t=>{const{pow_p_5_8:n,b2:r}=ud(t);return we(ve(n,Ox,e)*r,e)},adjustScalarBytes:fd})})(),Lx=Ye("lineage/v0"),xt=(e,t)=>xx(rt,e,Lx,Ye(t),32),vo=e=>{const t=Uint8Array.from(e);return t[0]&=248,t[31]&=127,t[31]|=64,t},hd=e=>{const t=new Uint8Array(4);return new DataView(t.buffer).setUint32(0,e),t},st=e=>xe(hd(e.length),e),Ha=e=>xe(st(Ye("ssh-ed25519")),st(e)),Ui=(e,t)=>`ssh-ed25519 ${wt.encode(Ha(e))}${t?` ${t}`:""}`,Ni=e=>`SHA256:${wt.encode(rt(Ha(e))).replace(/=+$/,"")}`;function Rx(e){const t=dt(e),n=r=>xo.getPublicKey(xt(t,r));return{ssh:n("ssh"),git:n("git"),dkim:n("dkim"),wg:dd.getPublicKey(vo(xt(t,"wg")))}}function Hx(e){const t=n=>xo.getPublicKey(xt(e,n));return{"ssh-ca":t("node/ssh-ca"),mtls:t("node/mtls"),noise:dd.getPublicKey(vo(xt(e,"node/noise")))}}function jx(e,t,n,r){return[["ssh",Ni(e.ssh),Ui(e.ssh,t)],["git",Ni(e.git),`${t} namespaces="git" ${Ui(e.git,t)}`],["dkim",`${n}._domainkey.${r}`,`${n}._domainkey.${r}. IN TXT "v=DKIM1; k=ed25519; p=${wt.encode(e.dkim)}"`],["wg",wt.encode(e.wg),`[Peer] +# ${t} +PublicKey = ${wt.encode(e.wg)}`]]}function Kx(e,t){return[["ssh-ca",Ni(e["ssh-ca"]),Ui(e["ssh-ca"],`lineage-ca@${t}`)],["mtls",wt.encode(e.mtls),null],["noise",`mkey:${Re(e.noise)}`,null]]}const Dx=dt("302e020100300506032b657004220420");function pd(e,t,n){const r=rt(e).slice(0,4);let s=xe(r,r,st(Ye("ssh-ed25519")),st(t),st(xe(e,t)),st(Ye(n)));s=xe(s,new Uint8Array((8-s.length%8)%8).map((i,a)=>a+1));const o=xe(Ye("openssh-key-v1\0"),st(Ye("none")),st(Ye("none")),st(new Uint8Array(0)),hd(1),st(Ha(t)),st(s));return`-----BEGIN OPENSSH PRIVATE KEY----- +${wt.encode(o).match(/.{1,70}/g).join(` +`)} +-----END OPENSSH PRIVATE KEY----- +`}const Zx=(e,t)=>`-----BEGIN ${e}----- +${wt.encode(t).match(/.{1,64}/g).join(` +`)} +-----END ${e}----- +`;function Mx(e,t){const n=dt(e),r=s=>{const o=xt(n,s);return pd(o,xo.getPublicKey(o),t)};return[["ssh","OpenSSH private key",r("ssh")],["git","OpenSSH private key",r("git")],["dkim","Ed25519 private key (base64)",wt.encode(xt(n,"dkim"))],["wg","Interface entry",`[Interface] +PrivateKey = ${wt.encode(vo(xt(n,"wg")))}`]]}function Vx(e,t){const n=xt(e,"node/ssh-ca");return[["ssh-ca","OpenSSH private key",pd(n,xo.getPublicKey(n),`lineage-ca@${t}`)],["mtls","Private key (PKCS#8 PEM)",Zx("PRIVATE KEY",xe(Dx,xt(e,"node/mtls")))],["noise","noise_private.key",`privkey:${Re(vo(xt(e,"node/noise")))}`]]}const qx=["bip86","tapkey","wallet"],ja=()=>({scheme:"bip86",roots:{},adopted:{}}),zx=e=>Ps.getPubKey(e)[0];function gd(e,t,n){return e.scheme==="wallet"?Ci(t,n):Ps.getSecKey(e.scheme==="tapkey"?Na(t,n):Ci(t,n))[0]}const md=(e,t)=>e.scheme==="tapkey"?tt.nostr(t):tt.wallet(t),Fx=(e,t)=>new dn(gd(e,t,0)),Xe=e=>Se.encode(e,!1).hex;function hn(e,t,n){if(!n)return null;const r=i=>i?{mnemonic:i,account:0,origin:`${n.name} root`,steps:[]}:null;if(n.kind==="holding")return r(e.roots[n.id]);const s=t.nodes.get(n.parent);if(n.kind==="agent"){const i=hn(e,t,s);return i&&{...i,account:n.index+1}}if(n.edge==="adopted")return r(e.adopted[n.id]);const o=hn(e,t,s);return o&&{mnemonic:lx(o.mnemonic,n.index),account:0,origin:o.origin,steps:[...o.steps,`${n.index}'`]}}const ri=new Map;function He(e,t,n){const r=hn(e,t,n);if(!r)return null;const s=`${e.scheme}|${r.mnemonic}|${r.account}`;if(!ri.has(s)){const{npub:u,pubkey:l}=dx(r.mnemonic,r.account);ri.set(s,{wallet:new dn(gd(e,r.mnemonic,r.account)),npub:u,pubkey:l})}const{wallet:o,npub:i,pubkey:a}=ri.get(s),c=[r.origin,...r.steps].join(" › ");return{wallet:o,npub:i,pubkey:a,scheme:e.scheme,account:r.account,from:c,path:`${c} · ${md(e,r.account)}`}}function Gx(e,t,n){const r=hn(e,t,n);if(!r)return null;const s=He(e,t,n),o=od(r.mnemonic,r.account);return{taproot:{address:s.wallet.address,path:md(e,r.account)},segwit:{address:Tr.p2wpkh.fromPubKey(o,"regtest"),path:tt.segwit(r.account)},tapkey:{address:Tr.p2tr.fromPubKey(zx(s.pubkey),"regtest"),path:tt.nostr(r.account)},npub:{address:s.npub,path:tt.nostr(r.account)}}}function Ka(e,t,n){const r=La(e.chain,n);if(!r)return null;const s=Xe(r.scriptPubKey),o=t.nodes.get(n),i=He(e.keys,t,o),a=o&&He(e.keys,t,t.nodes.get(o.parent));return i&&Xe(i.wallet.script)===s?{wallet:i.wallet,who:"own"}:e.wallet&&Xe(e.wallet.script)===s?{wallet:e.wallet,who:"lab"}:a&&Xe(a.wallet.script)===s?{wallet:a.wallet,who:"parent"}:{wallet:null,who:"other",script:s}}function Eo(e,t){const n=e.nodes.get(t),r=[n];for(const s of n.children){const o=e.nodes.get(s);o.status==="active"&&o.edge==="derived"&&r.push(...Eo(e,s))}return r}function Li(e,t){const n=[];for(let r=t;r;r=e.nodes.get(r.parent))n.push(r.name);return n.join(".")}function Wx(e,t,n){const r=hn(e,t,n);if(!r)return null;if(n.kind!=="agent")return Kx(Hx(Ua(r.mnemonic)),Li(t,n));const s=Li(t,t.nodes.get(n.parent));return jx(Rx(Na(r.mnemonic,r.account)),`${n.name}@${s}`,n.name,s)}const Yx=Xl(rt),Sr=(e,t=239)=>Yx.encode(xe(Uint8Array.of(t),dt(e),Uint8Array.of(1))),Xx=e=>no.encode("nsec",no.toWords(dt(e))),Jx="0123456789()[],'/*abcdefgh@:$%{}IJKLMNOPQRSTUVWXYZ&+-.;<=>?!^_|~ijklmnopqrstuvwxyzABCDEFGH`#\"\\ ",Qx=[0xf5dee51989n,0xa9fdca3312n,0x1bab10e32dn,0x3706b1677an,0x644d626ffdn];function si(e){const t=(i,a)=>{const c=i>>35n;return i=(i&0x7ffffffffn)<<5n^BigInt(a),Qx.forEach((u,l)=>{c>>BigInt(l)&1n&&(i^=u)}),i};let n=1n,r=0,s=0;for(const i of e){const a=Jx.indexOf(i);if(a<0)throw new Error("Invalid descriptor character.");n=t(n,a&31),r=r*3+(a>>5),++s===3&&(n=t(n,r),r=0,s=0)}s&&(n=t(n,r));for(let i=0;i<8;i++)n=t(n,0);n^=1n;let o="";for(let i=0;i<8;i++)o+="qpzry9x8gf2tvdw0s3jn54khce6mua7l"[Number(n>>BigInt(5*(7-i))&31n)];return`${e}#${o}`}function e2(e,t,n){const r=hn(e,t,n);if(!r)return null;const s=Na(r.mnemonic,r.account),o=Ci(r.mnemonic,r.account),i={bip86:`tr(${Sr(o)})`,tapkey:`tr(${Sr(s)})`,wallet:`rawtr(${Sr(o)})`}[e.scheme],a=n.kind==="agent",c=Li(t,a?t.nodes.get(n.parent):n);return{seed:a?null:{from:[r.origin,...r.steps].join(" › "),mnemonic:r.mnemonic},account:[["nsec","NIP-06",Xx(s)],["taproot","descriptor",si(i)],["segwit","descriptor",si(`wpkh(${Sr(sd(r.mnemonic,r.account))})`)],["tapkey","descriptor",si(`tr(${Sr(s)})`)]],leaves:a?Mx(s,`${n.name}@${c}`):Vx(Ua(r.mnemonic),c)}}const So="orgchain:lab:v1",t2=["each",10,30,60,"manual"];function Qr(e={tempo:"each",nextAt:null}){const{tempo:t,nextAt:n}=e??{},r=typeof t=="number";if(!t2.includes(t)||!(n===null||r&&Number.isSafeInteger(n)&&n>0))throw new Error("Invalid clock.");return{tempo:t,nextAt:n}}function yd(e){const t=ja();for(const n of["roots","adopted"])for(const[r,s]of Object.entries((e==null?void 0:e[n])??{})){if(!/^[0-9a-f]{64}i0$/.test(r))throw new Error("Invalid lab keys.");t[n][r]=rd(s,24)}if(t.scheme=(e==null?void 0:e.scheme)??(Object.keys(t.roots).length?"wallet":"bip86"),!qx.includes(t.scheme))throw new Error("Invalid lab keys.");return t}const n2=["split","last"];function es(e){const t=(e==null?void 0:e.rule)??"split",n={};if(!n2.includes(t))throw new Error("Invalid mining rule.");for(const[r,s]of Object.entries((e==null?void 0:e.rigs)??{})){if(!/^[0-9a-f]{64}i0$/.test(r)||!Number.isSafeInteger(s)||s<0||s>9)throw new Error("Invalid hashrate.");s!==1&&(n[r]=s)}return{rule:t,rigs:n}}const ts=()=>({wallet:null,chain:new yo,clock:Qr(),keys:ja(),mining:es()});function bd(e){if(!e)return ts();const t=JSON.parse(e);if((t==null?void 0:t.kind)!=="orgchain-lab"||t.network!==tn||t.version!==1)throw new Error("That is not an Orgchain v1 lab.");return{wallet:t.wallet?dn.load(t.wallet):null,chain:new yo(t.chain),clock:Qr(t.clock),keys:yd(t.keys),mining:es(t.mining)}}const wd=e=>{var t;return JSON.stringify({kind:"orgchain-lab",network:tn,version:1,wallet:((t=e.wallet)==null?void 0:t.backup())??null,chain:e.chain.snapshot(),clock:Qr(e.clock),keys:yd(e.keys),mining:es(e.mining)})};function r2(e,t,n){var r;e.mining=es({...e.mining,rigs:{...(r=e.mining)==null?void 0:r.rigs,[t]:n}})}function s2(e,t){e.mining=es({...e.mining,rule:t})}const Da=()=>bd(localStorage.getItem(So));function o2(e){try{localStorage.setItem(So,wd(e))}catch{throw new Error("Browser storage is full or unavailable, so nothing was saved. Save a backup, then reset.")}}async function i2(e,{locks:t=(s=>(s=globalThis.navigator)==null?void 0:s.locks)(),read:n=Da,save:r=o2}={}){if(!t)throw new Error("Orgchain needs Web Locks: open it over HTTPS or on localhost.");return t.request(So,async()=>{const o=n(),i=await e(o);return i!==!1&&r(o),{lab:o,result:i}})}function pn(e,t=null){e.wallet||(e.wallet=dn.create());const n=t!=null&&t.length?e.chain.mineTo(t.map(r=>De(r.value,r.script))):e.chain.mine(e.wallet.script);return e.clock=Qr({tempo:e.clock.tempo,nextAt:null}),n}function ko(e,t=Date.now()){const{tempo:n,nextAt:r}=e.clock;typeof n=="number"&&e.chain.mempool.length&&r===null&&(e.clock={tempo:n,nextAt:t+n*1e3})}function a2(e,t,n=Date.now(),r=null){e.clock=Qr({tempo:t,nextAt:null}),t==="each"&&e.chain.mempool.length?pn(e,r):ko(e,n)}function c2(e,t=Date.now(),n=null){const{tempo:r,nextAt:s}=e.clock;return typeof r!="number"||!e.chain.mempool.length?!1:s===null?(ko(e,t),!0):t(e/_o).toFixed(8).replace(/\.?0+$/,""),ye=e=>`${xd(e)} tBTC`;function Za(e){if(e<1e6)return ye(e);const t=Math.round(e/1e6)*1e6;return`${t===e?"":"≈"}${ye(t)}`}function u2(e){const t=/^\s*(\d{0,7})(?:\.(\d{0,8}))?\s*$/.exec(String(e??""));return!t||!(t[1]||t[2])?null:Number(t[1]||0)*_o+Number((t[2]??"").padEnd(8,"0"))}class f2{constructor(t,n,r){this.secret=t,this.pubkey=n,this.path=r,this.address=Tr.p2wpkh.fromPubKey(n,"regtest"),this.script=Tr.toScriptPubKey(this.address)}sign(t,n){return[lo.segwit.sign(this.secret,t,n,{pubkey:this.pubkey}).hex,this.pubkey]}}const oi=new Map;function Ce(e,t,n){const r=hn(e,t,n);if(!r)return null;const s=`${r.mnemonic}|${r.account}`;return oi.has(s)||oi.set(s,new f2(sd(r.mnemonic,r.account),od(r.mnemonic,r.account),tt.segwit(r.account))),oi.get(s)}function l2(e,t,n){var s;const r=n?t.nodes.get(n):null;return(r==null?void 0:r.kind)==="holding"&&r.status==="active"?((s=Ce(e,t,r))==null?void 0:s.script)??null:null}const Jn=(e,t)=>{var n,r;return((r=(n=e.mining)==null?void 0:n.rigs)==null?void 0:r[t])??1};function Ma(e,t){return t.roots.filter(n=>n.status==="active"&&Jn(e,n.id)>0&&Ce(e.keys,t,n)).slice(0,Vl)}function vd(e,t,n){var i;if(((i=e.mining)==null?void 0:i.rule)==="last"){const a=l2(e.keys,t,n);return a?[{script:a,value:Ct}]:null}const r=Ma(e,t),s=r.reduce((a,c)=>a+Jn(e,c.id),0);let o=Ct;return r.length?r.map((a,c)=>{const u=c===r.length-1?o:Math.floor(Ct*Jn(e,a.id)/s);return o-=u,{script:Ce(e.keys,t,a).script,value:u}}):null}function Ed(e,t){const n=t+he,r=a=>a===n||a-n>=nt&&a-n<=Ct,s=[...e].sort((a,c)=>a.value-c.value),o=s.find(a=>r(a.value));if(o)return[o];let i=null;for(let a=0;ar.value).sort((r,s)=>s-r),n=[];if(t.length&&n.push(t[0]-he),t.length>1){const r=t[0]+t[1]-he;n.push(r<=Ct?r:r-Ct>=nt?Ct:r-nt)}return Math.max(0,...n.filter(r=>r>=nt&&r<=Ct))}function d2(e,t,n){const r=t.reduce((c,u)=>c+u.value,0),s=n+he,o=Va(t);if(rc.value),...t.flatMap((c,u)=>t.slice(u+1).map(l=>c.value+l.value))],a=Math.min(...i.filter(c=>c>=s));return Number.isFinite(a)&&a-s!!Ed(e,t),h2=(e,t,n)=>Sd(e.chain.coins(t.script),n);function kd(e,t,n,r,s="This node"){const o=e.chain.coins(t.script),i=Ed(o,r);if(!i)throw new Error(d2(s,o,r));const a=i.reduce((l,f)=>l+f.value,0)-r-he,c=ae.create({vin:i.map(l=>rn(l.txid,l.vout,l.value,l.scriptPubKey)),vout:[De(r,n),...a?[De(a,t.script)]:[]]});i.forEach((l,f)=>{c.vin[f].witness=t.sign(c,f)});const u=ae.encode(c).hex;return e.chain.submitPackage([u]),ae.util.getTxid(u)}function _d(e,t,n,r,s){const o=t.nodes.get(n),i=t.nodes.get(r);if(!o||!i)throw new Error("Pick who sends and who receives.");if(o.id===i.id)throw new Error(`${o.name} cannot send to itself.`);for(const u of[o,i])if(u.status!=="active")throw new Error(`${u.name} is ${u.status}.`);const a=Ce(e.keys,t,o),c=Ce(e.keys,t,i);if(!a||!c)throw new Error("A holding that predates lab keys has no SegWit addresses.");if(!Number.isSafeInteger(s)||sCt)throw new Error("Send at most 50 test BTC at a time: no output on this chain is bigger than one block reward.");return kd(e,a,c.script,s,o.name)}function p2(e,t,n){if(!t||!n||Xe(t.script)===Xe(n.script))return 0;let r=0;for(const s of e.chain.coins(t.script)){if(s.value-he[t,...t.log.flatMap((n,r)=>n.ok&&n.op==="graduate"?[Un(e.slice(0,r),{pending:!0})]:[])];function Ad(e,t){const n=new Map;for(const r of e)for(const s of r.nodes.values()){const o=t(r,s);o&&!n.has(o)&&n.set(o,s.id)}return n}const g2=(e,t,n)=>Ad($d(t,n),(r,s)=>{const o=Ce(e,r,s);return o&&Xe(o.script)}),ii=new Map,m2=(e,t,n)=>Ad($d(t,n),(r,s)=>{const o=hn(e,r,s),i=o&&`${e.scheme}|${o.mnemonic}|${o.account}`;return i&&!ii.has(i)&&ii.set(i,Xe(He(e,r,s).wallet.script)),i?ii.get(i):null}),Bd=(e,t)=>e.coins(t.script).filter(n=>{var r;return!((r=n.inscriptions)!=null&&r.length)}).reduce((n,r)=>n+r.value,0);function y2(e,t,n=new Map){var i;const r=[],s=a=>t.get(Xe(a))??null,o=a=>a.reduce((c,u)=>c+u.value,0);for(const{txid:a,tx:c,height:u,coinbase:l}of e.transactions.values()){const f=c.vout.map(w=>({script:Xe(w.scriptPubKey),node:s(w.scriptPubKey),value:Number(w.value)}));if(l){f.forEach((w,b)=>{w.node&&r.push({kind:"mine",key:`${a}:${b}`,txid:a,beat:u,from:null,to:w.node,amount:w.value,fee:0,change:0})});continue}const d=c.vin.map(w=>{var T;const b=(T=e.transactions.get(w.txid))==null?void 0:T.tx.vout[w.vout];return b?{node:s(b.scriptPubKey),value:Number(b.value)}:null}),h=(i=d[0])==null?void 0:i.node;if(!h||!d.every(w=>(w==null?void 0:w.node)===h))continue;const m=f.filter(w=>w.node!==h),y=f.filter(w=>w.node===h),g=o(d)-o(f),p={key:a,txid:a,beat:u,from:h,fee:g};m.length&&m.every(w=>n.get(w.script)===h)?r.push({...p,kind:"gas",to:h,amount:o(m),change:o(y)}):m.length?r.push({...p,kind:"pay",to:m[0].node,amount:m[0].value,change:o(y)}):r.push({...p,kind:"move",to:h,amount:o(y),change:0})}return r}function Ri(e,t,n=1/0){const r=new Map;for(const{txid:o,tx:i,height:a,coinbase:c}of e.transactions.values())if(!(a===null?n!==1/0:a>n)){if(!c)for(const u of i.vin)r.delete(`${u.txid}:${u.vout}`);i.vout.forEach((u,l)=>{const f=t.get(Xe(u.scriptPubKey));f&&r.set(`${o}:${l}`,{node:f,value:Number(u.value)})})}const s=new Map;for(const{node:o,value:i}of r.values())s.set(o,(s.get(o)??0)+i);return s}const Mc={found:["name"],birth:["name","kind"],award:["to","skill","belt"],decide:["title","why"],graduate:["of"],close:[]},b2={found:e=>`found ${e.name}`,birth:e=>`birth ${e.name}`,award:e=>`award ${e.skill} ${e.belt}`,decide:e=>`decide ${e.title}`,graduate:()=>"graduate",close:()=>"close"};function w2(e,t={}){if(!Object.hasOwn(Mc,e))throw new Error("Unknown verb.");const n={op:e};for(const r of Mc[e]){const s=t[r];typeof s=="string"&&s.trim()&&(n[r]=s.trim())}return n}const Ut=e=>Un(Sa(new po(e.chain)),{pending:!0});function Td(e,t,n,r){const s=w2(t,r),o=Sa(new po(e.chain)),i={id:"check",status:"pending",height:null,metadata:s,parent:n??null,protocol:va},{ok:a,why:c}=Un([...o,i],{pending:!0}).log.at(-1);if(!a)throw new Error(`${c[0].toUpperCase()}${c.slice(1)}.`);return s}const Hi=bt+2*he+330,Id=1e5,qa=1e4,za=(e,t=0)=>bt+2*he+(e==="birth"?1:e==="graduate"?Math.max(0,t-1):0)*he+330,x2=(e,t=0)=>za(e,t)-330,ur=(e,t,n)=>e.chain.coins(t.script).find(r=>{var s;return!((s=r.inscriptions)!=null&&s.length)&&r.value>=n}),ji=e=>rn(e.txid,e.vout,e.value,e.scriptPubKey),Od=(e,t)=>(t.forEach((n,r)=>{e.vin[r].witness=[n.sign(e,void 0,r)]}),ae.encode(e).hex);function Cd(e){e.keys??(e.keys=ja()),e.wallet||(e.wallet=dn.create()),ur(e,e.wallet,Id+he+330)||pn(e)}function Pd(e,t,n=Hi,r=Id){if(t===e.wallet||ur(e,t,n))return;const s=ur(e,e.wallet,r+he+330),o=ae.create({vin:[ji(s)],vout:[De(r,t.script),De(s.value-r-he,e.wallet.script)]});e.chain.submitPackage([Od(o,[e.wallet])])}function Vc(e,t,n,r,s){if(r===e.wallet||ur(e,r,s))return;const o=n&&Ce(e.keys,t,n);if(!o)return Pd(e,r,s);kd(e,o,r.script,Math.max(qa,s),n.name)}function v2(e,t,n,r,s){if(r===e.wallet||ur(e,r,s))return!0;const o=n&&Ce(e.keys,t,n);return!o||h2(e,o,Math.max(qa,s))}function Ud(e,t,n,r,s={}){var l;const o=r?t.nodes.get(r):null,i=o&&((l=Ka(e,t,r))==null?void 0:l.wallet);if(n==="found"||!i)return"";const a=n==="graduate"?t.nodes.get(s.of):null,c=a&&He(e.keys,t,a)?Eo(t,a.id).length:0;if(!v2(e,t,o,i,za(n,c))){const f=t.nodes.get(o.parent);return f?`${o.name} has no test BTC for gas. ${f.name} can send some`:`${o.name} has no test BTC for gas. It earns some each beat it mines`}const u=c?Ce(e.keys,t,a):null;return u&&!Sd(e.chain.coins(u.script).filter(f=>f.value-he>=nt).map(f=>({value:f.value-he})),qa)?`${a.name} needs test BTC of its own to claim its new root. Send it some first`:""}function qc(e,t,n,r,s=n){const o=La(e.chain,t),i=ur(e,s,he+330),a=ae.create({vin:[ji(o),ji(i)],vout:[De(o.value,r.script),De(i.value-he,s.script)]});e.chain.submitPackage([Od(a,[n,s])])}function zc(e,t,n,r,s){return new Pw(e.chain,t).inscribe(b2[n](s),r??null,s,{metaprotocol:va})}const Nd=(e,t)=>{var r;const n=Ut(e);return vd(e,n,((r=n.nodes.get(t))==null?void 0:r.root)??null)},$o=(e,t)=>vd(e,Ut(e),t);function Fa(e){var r,s;const t=Ut(e),n=new Map;for(const o of t.nodes.values()){const i=Ce(e.keys,t,o);i&&n.set(Xe(i.script),o.root)}for(const o of[...e.chain.mempool].reverse()){const i=e.chain.transactions.get(ae.util.getTxid(o));if(i!=null&&i.inscription){const l=(r=t.log.find(f=>f.id===i.inscription.id))==null?void 0:r.root;if(l)return l;continue}const a=i==null?void 0:i.tx.vin[0],c=a&&((s=e.chain.transactions.get(a.txid))==null?void 0:s.tx.vout[a.vout]),u=c&&n.get(Xe(c.scriptPubKey));if(u)return u}return null}function Fc(e,t,n){var s;const r=Ka(e,t,n);if(!(r!=null&&r.wallet))throw new Error(`No key in this lab holds ${((s=t.nodes.get(n))==null?void 0:s.name)??"that node"}'s inscription.`);return r.wallet}function Ld(e,t,n,r){if(t==="found"){const l=Hc(),f=Fx(e.keys,l);Pd(e,f,Hi,Hi);const d=zc(e,f,t,null,r);return e.keys.roots[d]=l,d}const s=Ut(e),o=Fc(e,s,n),i=s.nodes.get(n),a=t==="graduate"?s.nodes.get(r.of):null,c=a&&He(e.keys,s,a)?Eo(s,a.id).map(l=>[l.id,Fc(e,s,l.id)]):[];Vc(e,s,i,o,za(t,c.length));const u=zc(e,o,t,n,r);if(t==="birth"){const l=Ut(e),f=He(e.keys,l,l.nodes.get(u));f&&qc(e,u,o,f.wallet)}if(c.length){e.keys.adopted[a.id]=Hc();const l=Ut(e);for(const[f,d]of c){const h=He(e.keys,l,l.nodes.get(f)).wallet;if(p2(e,Ce(e.keys,s,s.nodes.get(f)),Ce(e.keys,l,l.nodes.get(f))),f!==a.id){qc(e,f,d,h,o);continue}Vc(e,l,l.nodes.get(f),h,he+330),gx(e.chain,px(e.chain,f,h),d)}}return u}function E2(e,t,n,r,s=Date.now()){const o=Td(e,t,n,r),i=Ud(e,Ut(e),t,n??null,o);if(i)throw new Error(`${i}.`);Cd(e);const a=Ld(e,t,n??null,o);return e.clock.tempo==="each"?pn(e,Nd(e,n??a)):ko(e,s),a}function S2(e,t,n,r,s=Date.now()){const o=_d(e,Ut(e),t,n,r);return e.clock.tempo==="each"?pn(e,Nd(e,t)):ko(e,s),o}const Ki="yolopreneur",k2=[[["found",null,{name:"yolopreneur"}]],[["birth","yolopreneur",{name:"well-known",kind:"org"}],["birth","yolopreneur",{name:"time",kind:"org"}]],[["send","yolopreneur",{to:"time",amount:40}],["send","yolopreneur",{to:"well-known",amount:10}],["birth","well-known",{name:"mailr",kind:"org"}],["birth","well-known",{name:"lineage",kind:"org"}],["birth","time",{name:"luna",kind:"agent"}],["birth","time",{name:"sol",kind:"agent"}],["birth","time",{name:"astra",kind:"agent"}]],[["send","well-known",{to:"lineage",amount:2}],["birth","time",{name:"docscope",kind:"org"}],["birth","time",{name:"dollhouse",kind:"org"}],["birth","time",{name:"doodleloop",kind:"org"}],["birth","time",{name:"hearthframe",kind:"org"}]],[["send","time",{to:"sol",amount:1}],["send","time",{to:"luna",amount:.5}],["award","time",{to:"sol",skill:"launch",belt:"green"}],["award","time",{to:"luna",skill:"post",belt:"white"}],["decide","yolopreneur",{title:"Every venture gets a page",why:".yolopreneur.lol, served from one pages branch."}]],[["graduate","well-known",{of:"lineage"}],["decide","lineage",{title:"Lineage gets its own org",why:"Its own repo on Teahub now, lineage.llc later: adopted, not derived."}]]];function _2(e){Cd(e),e.chain.mempool.length&&pn(e);const t={};for(const n of k2){for(const[r,s,o]of n){if(r==="send"){_d(e,Ut(e),t[s],t[o.to],o.amount*_o);continue}const i=Object.fromEntries(Object.entries(o).map(([u,l])=>[u,u==="to"||u==="of"?t[l]:l])),a=s?t[s]:null,c=Ld(e,r,a,Td(e,r,a,i));(r==="found"||r==="birth")&&(t[o.name]=c)}pn(e,$o(e,t[Ki]))}return t[Ki]}const V=e=>document.getElementById(e);function $(e,t={},...n){const r=document.createElement(e);for(const[s,o]of Object.entries(t))o==null||o===!1||(s==="class"?r.className=o:s==="text"?r.textContent=o:s.startsWith("on")?r.addEventListener(s.slice(2),o):r.setAttribute(s,o===!0?"":String(o)));for(const s of n.flat(1/0))s!=null&&s!==!1&&s!==""&&r.append(s instanceof Node?s:String(s));return r}const $r=(e,t)=>`${e} ${t}${e===1?"":"s"}`,An=e=>e==="cued"?"cued":`beat ${e}`,$2=e=>new Date(e).toLocaleTimeString([],{hour:"2-digit",minute:"2-digit",second:"2-digit"}),Gc=e=>JSON.stringify(e,(t,n)=>typeof n=="bigint"?String(n):n,2),B={holding:null,node:null,event:null,tx:null,beat:null,verb:"birth",busy:!1,replay:null,closing:null,reveal:null};let z=ts(),so=new po(z.chain),wn=[],Q=Un([]),Ge=Q,Ze={owner:new Map,ledger:[],now:new Map,view:new Map};const We=()=>z.chain.blocks.length,Di=()=>wn.filter(e=>e.status==="pending").length,Zi=()=>Ze.ledger.filter(e=>e.beat===null&&e.kind==="pay").length,A2=()=>Di()+Zi(),_s=e=>Ze.view.get(e)??0,Rd=e=>Ze.now.get(e)??0,se=(e,t=Q)=>e?t.nodes.get(e)??null:null,Hd=e=>Object.assign(B,{event:null,tx:null,closing:null,reveal:null},e),ns=e=>{Hd(e),Ao()};function Ae(e,t=!1){const n=V("say");n.textContent=e,n.classList.toggle("bad",t)}function jd(){try{z=Da()}catch(e){z=ts(),Ae(`This browser's saved lab could not be read (${e.message}) Load a backup, or reset to start over.`,!0)}Ga()}function Ga(){var t;so=new po(z.chain),wn=Sa(so),Q=Un(wn,{pending:!0}),B.beat!==null&&B.beat>=We()&&(B.beat=null),se(B.holding)||(B.holding=((t=Q.roots.at(-1))==null?void 0:t.id)??null),(!se(B.node)||se(B.node).root!==B.holding)&&(B.node=B.holding),B.event&&!Q.log.some(n=>n.id===B.event)&&(B.event=null),Ge=B.beat===null?Q:Un(wn,{upTo:B.beat});const e=g2(z.keys,wn,Q);Ze={owner:e,ledger:y2(z.chain,e,m2(z.keys,wn,Q)),now:Ri(z.chain,e)},Ze.view=B.beat===null?Ze.now:Ri(z.chain,e,B.beat),B.tx&&!Ze.ledger.some(n=>n.key===B.tx)&&(B.tx=null),Ao()}function oo(e){B.beat=e>=We()?null:Math.max(0,e),Ge=B.beat===null?Q:Un(wn,{upTo:B.beat}),Ze.view=B.beat===null?Ze.now:Ri(z.chain,Ze.owner,B.beat),Ao()}async function gn(e,t){if(B.busy)return!1;B.busy=!0,document.body.classList.add("busy");try{return z=(await i2(e,t)).lab,!0}catch(n){return Ae((n==null?void 0:n.message)||String(n),!0),!1}finally{B.busy=!1,document.body.classList.remove("busy"),Ga()}}async function br(e,t,n,r){let s=null;if(!await gn(i=>{s=E2(i,e,t,n)}))return!1;const o=so.events.find(i=>i.id===s);return Ae(r(s,(o==null?void 0:o.status)==="confirmed"?`at beat ${o.height}`:"cued for the next beat")),Ao(),!0}async function Kd(e){const t=Di(),n=Zi(),r=We();if(!await gn(e)||We()===r)return;const s=[[t-Di(),"cued act"],[n-Zi(),"cued send"]].filter(([i])=>i>0).map(([i,a])=>$r(i,a)),o=B2(Ze.ledger.filter(i=>i.kind==="mine"&&i.beat===We()));Ae(`Beat ${We()}: ${s.length?`${s.join(" and ")} landed, and ${o}`:o}.`)}function B2(e){if(!e.length)return"the lab wallet earned 50 tBTC";const t=e.map(r=>{var s;return((s=se(r.to))==null?void 0:s.name)??"?"}),n=e.map(r=>Za(r.amount));return e.length===1?`${t[0]} earned ${ye(e[0].amount)}`:n.every(r=>r===n[0])?`${t.slice(0,-1).join(", ")} and ${t.at(-1)} earned ${n[0]} each`:e.map((r,s)=>`${t[s]}${s?"":" earned"} ${n[s]}`).join(", ")}function T2(){var t;if(((t=z.mining)==null?void 0:t.rule)==="last")return"the holding that acts";const e=Ma(z,Q);return e.length?e.length===1?e[0].name:`${e.length} holdings, split by hashrate`:"the lab wallet"}function Ao(){Dd(),O2(),C2(),Bo(),Fd(),Wa()}function Dd(){const e=A2(),{tempo:t}=z.clock;for(const r of document.querySelectorAll("[data-tempo]"))r.setAttribute("aria-pressed",String(String(t)===r.dataset.tempo));V("clock-beat").textContent=String(We()),V("clock-cued").textContent=e?`${e} cued · ${I2()}`:"nothing cued";const n=T2();V("clock-pays").textContent=`beats pay ${n}`,V("beat-now").title=`Beat now: ${e?"land what is cued, and ":""}pay ${n} 50 test BTC`}function I2(){const{tempo:e,nextAt:t}=z.clock;return e==="manual"?"waiting for Beat now":typeof e=="number"&&t?`next beat in ${Math.max(0,Math.ceil((t-Date.now())/1e3))}s`:"landing on the next beat"}function O2(){var r,s;const e=((r=z.mining)==null?void 0:r.rule)!=="last",t=e?Ma(z,Q):[],n=t.reduce((o,i)=>o+Jn(z,i.id),0);V("holdings-list").replaceChildren(...Q.roots.map(o=>{const i=Hw(Q,o.id),a=o.id===B.holding,c=o.status==="active",u=t.some(d=>d.id===o.id)?Jn(z,o.id)/n:0,l=[...Q.nodes.values()].reduce((d,h)=>d+(h.root===o.id?Rd(h.id):0),0),f=[An(o.born),$r(i.orgs,"org"),$r(i.agents,"agent"),$r(i.belts,"belt"),l>0&&Za(l),e&&c&&(u?`${Math.round(u*100)}% of each beat`:"not mining"),!c&&"closed"].filter(Boolean);return $("li",{},$("button",{type:"button",class:`hold${a?" on":""}${c?"":" gone"}`,"aria-pressed":String(a),onclick:()=>ns({holding:o.id,node:o.id})},$("span",{class:"hn",text:o.name})," ",$("span",{class:"hm",text:f.join(" · ")})),e&&c&&Ce(z.keys,Q,o)&&N2(o,Jn(z,o.id)))}));for(const o of document.querySelectorAll("[data-rule]"))o.setAttribute("aria-pressed",String((((s=z.mining)==null?void 0:s.rule)??"split")===o.dataset.rule));V("mining-note").textContent=e?"Every active holding mines: each beat's 50 tBTC splits by hashrate, set on each holding (0 sits out).":"The holding behind the latest act or send takes the whole beat; with nothing cued, Beat now pays the one you're working in. At a timed tempo it's a race for the next beat.",V("holdings-empty").hidden=Q.roots.length>0,V("holdings-sub").textContent=Q.roots.length?String(Q.roots.length):"",V("sample").disabled=Q.roots.some(o=>o.name===Ki&&o.status==="active")}function C2(){var r;const e=V("tree-rows"),t=se(B.holding);if(V("tree-sub").textContent=t?`${t.name} · ${B.beat===null?"now":`beat ${B.beat} of ${We()}`}`:"",!t)return e.replaceChildren($("p",{class:"wait",text:"No holding yet. Found one, or load the yolopreneur sample."}));if(!Ge.nodes.has(t.id))return e.replaceChildren($("p",{class:"wait",text:`${t.name} is founded at ${An(t.born)}. Move the slider forward.`}));const n=e.contains(document.activeElement)?document.activeElement.dataset.id:null;e.replaceChildren(...Rw(Ge,t.id).map(s=>s.type==="group"?$("div",{class:"row grp"},$("span",{class:"g","aria-hidden":"true",text:s.guide}),$("span",{class:"gl",text:s.label})):P2(s))),n&&((r=e.querySelector(`[data-id="${n}"]`))==null||r.focus())}function P2({node:e,guide:t,path:n}){const r=e.id===B.node,s=["row",r&&"on",e.status==="closed"&&"gone",e.born==="cued"&&"cue"].filter(Boolean).join(" ");return $("div",{class:s},$("button",{type:"button",class:"sel","data-id":e.id,"aria-pressed":String(r),onclick:()=>ns({node:e.id})},$("span",{class:"g","aria-hidden":"true",text:t}),$("span",{class:"p",text:`${n} `}),$("span",{class:"l",text:e.name})," ",$("span",{class:"v"},U2(e))))}function U2(e){return[e.kind==="agent"&&$("span",{class:"mk",text:"agent"}),e.edge==="adopted"&&$("span",{class:"mk ok",text:"graduated"}),e.status==="closed"&&$("span",{class:"mk bad",text:"closed"}),e.born==="cued"&&$("span",{class:"mk",text:"cued"}),...e.badges.map(Zd),_s(e.id)>0&&$("span",{class:"mk sats",title:`${ye(_s(e.id))} at its SegWit address`,text:Za(_s(e.id))})].filter(Boolean).flatMap((n,r)=>r?[" ",n]:[n])}const Zd=e=>$("span",{class:`belt ${e.belt}`,title:`${e.skill}: ${e.belt} belt`},e.skill,$("span",{class:"sr",text:` (${e.belt} belt)`})),Md=(e,t)=>{for(let n=se(e.parent);n;n=se(n.parent))if(n.id===t.id)return!0;return!1},Vd=e=>[...Q.nodes.values()].filter(t=>t.root===e.root&&t.id!==e.id&&t.status==="active").map(t=>[t,(Md(t,e)?0:2)+(t.kind==="agent"?0:1)]).sort((t,n)=>t[1]-n[1]).map(([t])=>t),qd=e=>e.children.reduce((t,n)=>{const r=se(n);return r&&r.edge==="derived"&&r.status==="active"?t+1+qd(r):t},0);function N2(e,t){const n=async r=>{await gn(s=>r2(s,e.id,r))&&Ae(r?`${e.name} mines at hashrate ${r}.`:`${e.name} sits out of mining.`)};return $("span",{class:"rig"},$("span",{class:"rl",text:"hashrate"}),$("span",{class:"rn"},$("button",{type:"button",class:"rb","aria-label":`Lower ${e.name}'s hashrate`,disabled:t<=0,onclick:()=>n(t-1)},"−"),$("b",{text:String(t)}),$("button",{type:"button",class:"rb","aria-label":`Raise ${e.name}'s hashrate`,disabled:t>=9,onclick:()=>n(t+1)},"+")))}const zd=e=>[...Q.nodes.values()].filter(t=>t.id!==e.id&&t.status==="active").map(t=>[t,(t.root===e.root?0:4)+(Md(t,e)?0:2)+(t.kind==="agent"?0:1)]).sort((t,n)=>t[1]-n[1]).map(([t])=>t);function L2(e){const t=Ce(z.keys,Q,e),n=se(e.parent);return t?Va(z.chain.coins(t.script))Ud(z,Q,s,o,i);return{birth:n||(e.kind==="agent"?"Agents do not give birth":r("birth")),award:n||(e.kind==="agent"?"Agents do not award belts":Vd(e).length?r("award"):"There is nobody else in this holding to award yet"),decide:n||r("decide"),send:n||L2(e),graduate:n||(t?e.kind!=="org"?"Only orgs graduate":e.edge==="adopted"?`${e.name} has already graduated`:t.status!=="active"?`${t.name} is closed`:r("graduate",t.id,{of:e.id}):"A holding has no parent to graduate from"),close:n||r("close")}}function Bo(){const e=se(B.node),t=B.beat!==null;if(V("act-none").hidden=!!e,V("act-past").hidden=!e||!t,V("act-on").hidden=!e||t,V("act-sub").textContent=(e==null?void 0:e.name)??"",V("past-beat").textContent=String(B.beat??""),!e||t)return;const n=R2(e),r=se(e.parent);for(const f of document.querySelectorAll("[data-verb]"))f.setAttribute("aria-pressed",String(f.dataset.verb===B.verb)),f.classList.toggle("off",!!n[f.dataset.verb]);for(const f of document.querySelectorAll("form[data-form]"))f.hidden=f.dataset.form!==B.verb||!!n[B.verb];V("act-why").textContent=n[B.verb]?`${n[B.verb]}.`:"";for(const f of document.querySelectorAll("#act-on [data-name]"))f.textContent=e.name;for(const f of document.querySelectorAll("#act-on [data-parent]"))f.textContent=(r==null?void 0:r.name)??"";const s=f=>f.map(d=>`${d.value}=${d.textContent}`).join("|");for(const[f,d]of[[V("award-to"),Vd(e)],[V("send-to"),zd(e)]]){const h=f.value,m=d.map(y=>$("option",{value:y.id,text:`${go(Q,y.id)}${y.kind==="agent"?" (agent)":""}`}));s(m)!==s([...f.options])&&(f.replaceChildren(...m),m.some(y=>y.value===h)&&(f.value=h))}V("send-has").textContent=ye(Rd(e.id)),V("graduate-go").textContent=`Graduate ${e.name}`;const o=B.verb==="graduate"?r:e,i=o&&He(z.keys,Q,o),a=i&&(B.verb==="send"?`${i.from} · ${Ce(z.keys,Q,o).path}`:i.path);V("act-key").textContent=!o||n[B.verb]?"":i?`Signs as ${o.name}: ${a}`:"Signs with the lab wallet: this holding predates lab keys.";const c=B.verb==="graduate"&&He(z.keys,Q,e)?Eo(Q,e.id).length:0;V("act-gas").textContent=!o||n[B.verb]||!i?"":B.verb==="send"?`Fee: ${he} sats, from ${e.name}'s balance.`:`Gas: ${x2(B.verb,c).toLocaleString("en-US")} sats from ${o.name}'s tank (${ye(Bd(z.chain,i.wallet))}), which tops up from its balance.${c?` ${e.name} pays ${he} more, from its own money, to claim its new root.`:""}`;const u=qd(e),l=B.closing===e.id;V("close-note").textContent=u?`Closing ${e.name} spends it for the last time, and its ${$r(u,"derived descendant")} close with it. Graduated children hold their own roots and stay open.`:`Closing ${e.name} spends its inscription for the last time. Nothing can act through it afterwards.`,V("close-go").textContent=l?`Yes, close ${e.name}`:`Close ${e.name}`,V("close-keep").hidden=!l}function Fd(){const e=V("inspect-body"),t=B.event?Q.log.find(o=>o.id===B.event):null;if(t)return V("inspect-sub").textContent="event",e.replaceChildren(...F2(t));const n=B.tx?Ze.ledger.find(o=>o.key===B.tx):null;if(n)return V("inspect-sub").textContent="money",e.replaceChildren(...G2(n));const r=se(B.node);if(V("inspect-sub").textContent=(r==null?void 0:r.kind)??"",!r)return e.replaceChildren($("p",{class:"note pad",text:"Select a node in the tree, or an event in the timeline."}));const s=se(B.node,Ge);if(!s)return e.replaceChildren($("p",{class:"note pad",text:`${r.name} is not born yet at beat ${B.beat}.`}));e.replaceChildren(...H2(s))}const Vr=([e,t,n])=>$("div",{class:"f"},$("dt",{text:e}),$("dd",{},t,n&&$("span",{class:"fn",text:n})));function H2(e){const t=se(e.parent,Ge),n=[["Born",e.born==="cued"?"cued for the next beat":`beat ${e.born}`],t&&["Parent",`${t.name} · ${e.kind} ${e.index}'`],t&&["Edge",e.edge==="adopted"?`adopted at ${An(e.graduated)}: it holds its own root`:`derived: ${t.name} holds its seed`],e.closed!==null&&["Closed",An(e.closed)],["Children",e.children.length?e.children.map(r=>{var s;return(s=se(r,Ge))==null?void 0:s.name}).join(", "):"none yet"],Ce(z.keys,Ge,e)&&["Balance",ye(_s(e.id)),`Test BTC at its SegWit address${B.beat===null?"":`, as of beat ${B.beat}`}.`],B.beat===null&&He(z.keys,Q,e)&&["Gas tank",ye(Bd(z.chain,He(z.keys,Q,e).wallet)),"Plain coins at its Taproot key. Its acts burn their fees from here, and the tank tops up from its balance, 0.0001 tBTC at a time."],["Inscription",e.id]].filter(Boolean);return[$("div",{class:"ih"},$("p",{class:"eyebrow",text:go(Ge,e.id)}),$("h3",{class:"it",text:e.name}),$("div",{class:"chips"},$("span",{class:"chip",text:e.kind}),$("span",{class:`chip ${e.status==="active"?"ok":"bad"}`,text:e.status}),e.edge==="adopted"&&$("span",{class:"chip ok",text:"graduated"}),e.born==="cued"&&$("span",{class:"chip",text:"cued"}))),$("div",{class:"ib"},$("dl",{class:"fl"},n.map(Vr)),e.badges.length>0&&$("div",{},$("p",{class:"lab",text:"Belts"}),$("ul",{class:"list"},e.badges.map(r=>{var s;return $("li",{},Zd(r),$("span",{class:"when",text:` from ${((s=se(r.by))==null?void 0:s.name)??"?"}, ${An(r.beat)}`}))}))),e.decisions.length>0&&$("div",{},$("p",{class:"lab",text:"Decisions"}),$("ul",{class:"list"},e.decisions.map(r=>$("li",{},$("b",{text:r.title}),r.why&&` · ${r.why}`,$("span",{class:"when",text:` (${An(r.beat)})`}))))),j2(e),M2(e))]}function j2(e){const t=Ze.ledger.filter(n=>(n.to===e.id||n.from===e.id)&&(B.beat===null||n.beat!==null&&n.beat<=B.beat)).slice(-6).reverse();return t.length>0&&$("div",{},$("p",{class:"lab",text:"Money"}),$("ul",{class:"list"},t.map(n=>$("li",{},$("b",{text:K2(n,e.id)}),$("span",{class:"when",text:` (${An(n.beat??"cued")})`})))))}function K2(e,t){const n=r=>{var s;return((s=se(r))==null?void 0:s.name)??"?"};return e.kind==="mine"?`+${ye(e.amount)}, a beat's reward`:e.kind==="move"?`${ye(e.amount)} moved to its new key, after a ${e.fee}-sat fee`:e.kind==="gas"?`−${ye(e.amount)} into its gas tank, and a ${e.fee}-sat fee`:e.to===t?`+${ye(e.amount)} from ${n(e.from)}`:`−${ye(e.amount)} to ${n(e.to)}, and a ${e.fee}-sat fee`}function Gd(e){const t=n=>{const r=se(n);return r?r.root===B.holding?r.name:go(Q,n):"?"};return e.kind==="mine"?`${ye(e.amount)} → ${t(e.to)}`:e.kind==="move"?`${ye(e.amount)} → ${t(e.to)}'s new key`:e.kind==="gas"?`${ye(e.amount)} → ${t(e.to)}'s gas tank`:`${ye(e.amount)} ${t(e.from)} → ${t(e.to)}`}const D2={own:"its own key",lab:"the lab wallet",parent:"its parent's key (its handoff is cued)",other:"a key outside this lab"},Z2={ssh:"shell access, certified by the CA",git:"commit signing",dkim:"mail signing",wg:"WireGuard peer key","ssh-ca":"SSH certificate authority",mtls:"TLS identity between nodes",noise:"Headscale noise key"};function M2(e){const t=He(z.keys,Ge,e),n=Ka(z,Q,e.id),r=["Held now by",n?D2[n.who]:"nobody: its inscription has been spent"];if(!t)return $("div",{class:"keys"},$("p",{class:"lab",text:"Keys"}),$("dl",{class:"fl"},[["Signs with","the lab wallet: this holding predates lab keys, so it has no addresses, leaves or secrets of its own"],r].map(Vr)));const s=e.kind==="agent",o=Gx(z.keys,Ge,e),i=Wx(z.keys,Ge,e),a=i.map(([,,d])=>d).filter(Boolean),c="Reset the lab for standard BIP-86 keys.",u=s?"Holds this seat's inscription, and inscriptions sent to it land here.":"Holds this org's inscription and signs its acts. Inscriptions sent to it land here.",l={bip86:`BIP-86 at ${o.taproot.path}. ${u}`,tapkey:`Its npub's key with the BIP-86 tweak, the way v1.2 keyed this lab. ${u} ${c}`,wallet:`An untweaked key at ${o.taproot.path}, the way v1.1 keyed this lab. ${u} ${c}`}[t.scheme],f=[["Taproot",o.taproot.address,l],["SegWit",o.segwit.address,`BIP-84 at ${o.segwit.path}. Its money: ${e.kind==="holding"?"the beats it earns land here, and ":""}sends come and go here.`],["Tapkey",o.tapkey.address,"Its npub as a Taproot address (its nostr key with the BIP-86 tweak), so the npub alone finds it. Nostr secrets get pasted into clients, so treat it as an inbox."],["npub",o.npub.address,`NIP-06 at ${o.npub.path}. Its nostr name; the leaves below hang off it.`],["From",`${t.from} · account ${t.account}`],r];return $("div",{class:"keys"},$("p",{class:"lab",text:"Keys"}),$("dl",{class:"fl"},f.map(Vr)),$("p",{class:"lab"},"Leaves",$("span",{text:` · HKDF-SHA256 from its ${s?"nostr secret":"seed"}`})),$("ul",{class:"list leaves"},i.map(([d,h])=>$("li",{},$("b",{text:d}),$("span",{class:"when",text:` ${Z2[d]}`}),$("code",{text:h})))),Ar(s?"Public lines to paste":"CA key for TrustedUserCAKeys",a.join(` + +`)),q2(e,t))}function Ar(e,t,n=t){const r=$("pre",{text:n}),s=$("button",{type:"button",class:"cp","aria-label":`Copy ${e}`,onclick:()=>V2(t,s,r)},"Copy");return $("div",{class:"code"},$("div",{class:"code-h cph"},$("span",{text:e}),s),r)}async function V2(e,t,n){const r=s=>{t.textContent=s,setTimeout(()=>{t.textContent="Copy"},1400)};try{await navigator.clipboard.writeText(e),r("Copied")}catch{getSelection().selectAllChildren(n),r("Selected")}}function q2(e,t){var a;const n=B.reveal===e.id,r=n&&e2(z.keys,Ge,e),s=se(e.parent,Ge),o=()=>{var c;B.reveal=n?null:e.id,Fd(),(c=V("reveal"))==null||c.focus()},i=(a=r==null?void 0:r.seed)==null?void 0:a.mnemonic.split(" ");return $("div",{class:"secret"},$("div",{class:"hz"},$("span",{class:"hz-l",text:"Secret · stays in this tab"}),$("button",{type:"button",class:"btn sm",id:"reveal","aria-expanded":String(n),onclick:o},n?"Hide":"Reveal")),r&&$("div",{class:"sb"},r.seed?Ar(`Seed · ${r.seed.from}`,r.seed.mnemonic,i.map((c,u)=>`${String(u+1).padStart(2,"0")} ${c}`).reduce((c,u,l)=>(l%3?c[c.length-1].push(u):c.push([u]),c),[]).map(c=>c.join(" ")).join(` +`)):$("p",{class:"note",text:`A seat has no seed of its own: these are account ${t.account} of ${(s==null?void 0:s.name)??"its org"}'s seed.`}),r.account.map(([c,u,l])=>Ar(`${c} · ${u}`,l)),r.leaves.map(([c,u,l])=>Ar(`${c} · ${u}`,l))))}function z2(e){var i,a,c;const t=(a=(i=z.chain.transactions.get(e.id.slice(0,-2)))==null?void 0:i.tx.vin.find(u=>{var l;return((l=u.witness)==null?void 0:l.length)===3}))==null?void 0:a.witness;if(!t)return"?";const n=xa(t).pubkey,r=se(e.parent),s=e.op==="found"?se(e.node):null,o=[[s&&He(z.keys,Q,s),`${s==null?void 0:s.name}'s root`],[r&&He(z.keys,Q,r),`${r==null?void 0:r.name}'s key`],[(r==null?void 0:r.edge)==="adopted"&&He(z.keys,Q,{...r,edge:"derived"}),`${r==null?void 0:r.name}'s derived key, from before it graduated`]];for(const[u,l]of o)if(u&&u.wallet.pubkey===n)return l;return((c=z.wallet)==null?void 0:c.pubkey)===n?"the lab wallet":`a key outside this lab (${n.slice(0,12)}…)`}function F2(e){var o,i,a;const t=so.events.find(c=>c.id===e.id),n=(i=(o=z.chain.transactions.get(e.id.slice(0,-2)))==null?void 0:o.inscription)==null?void 0:i.text,r=[["When",e.pending?"cued for the next beat":`beat ${e.beat}`],["Authorized by",e.parent?`${((a=se(e.parent))==null?void 0:a.name)??"an unknown inscription"}, whose inscription this event spent`:"nothing: a founding has no parent"],["Signed by",z2(e)],["Inscription",e.id],n&&["Body",n],(t==null?void 0:t.block)&&["Block",t.block]].filter(Boolean),s=t&&{id:t.id,status:t.status,height:t.height,block:t.block,parent:t.parent??null,metaprotocol:t.metaprotocol??null,contentType:t.contentType,sat:t.sat,location:t.location};return[$("div",{class:"ih"},$("p",{class:"eyebrow",text:`${e.op} · ${e.pending?"cued":`beat ${e.beat}`}`}),$("h3",{class:"it",text:al(e,Q)}),$("div",{class:"chips"},$("span",{class:"chip",text:(t==null?void 0:t.protocol)??"?"}),$("span",{class:`chip ${e.ok?"ok":"bad"}`,text:e.ok?"applied":"rejected"})),!e.ok&&$("p",{class:"idesc",text:"The reducer rejected this event. It stays on the chain, but it does not change the tree."})),$("div",{class:"ib"},$("dl",{class:"fl"},r.map(Vr)),$("div",{class:"code"},$("p",{class:"code-h",text:"Metadata · CBOR, tag 5"}),$("pre",{text:Gc(e.meta)})),s&&$("div",{class:"code"},$("p",{class:"code-h",text:"Raw index entry"}),$("pre",{text:Gc(s)})))]}function G2(e){const t=s=>{var o;return((o=se(s))==null?void 0:o.name)??"a key outside this lab"},n=z.chain.transactions.get(e.txid),r=[["When",e.beat===null?"cued for the next beat":`beat ${e.beat}`],["From",e.kind==="mine"?"its share of the beat's block reward (the coinbase)":`${t(e.from)}'s SegWit address${e.kind==="move"?", from before it graduated":""}`],["To",e.kind==="gas"?`${t(e.to)}'s gas tank, at its Taproot key`:`${t(e.to)}'s ${e.kind==="move"?"new ":""}SegWit address`],["Amount",ye(e.amount)],e.kind!=="mine"&&["Fee",`${e.fee} sats, retired: this toy chain pays no fees to miners`],e.change>0&&["Change",`${ye(e.change)} back to ${t(e.from)}`],["Signed by",e.kind==="mine"?"nobody: a coinbase spends nothing":`${t(e.from)}'s SegWit key (BIP-143, SIGHASH_ALL)`],["Transaction",e.txid]].filter(Boolean);return[$("div",{class:"ih"},$("p",{class:"eyebrow",text:`${e.kind} · ${e.beat===null?"cued":`beat ${e.beat}`}`}),$("h3",{class:"it",text:Gd(e)}),$("div",{class:"chips"},$("span",{class:"chip",text:"test BTC"}),$("span",{class:`chip${e.beat===null?"":" ok"}`,text:e.beat===null?"cued":"confirmed"}))),$("div",{class:"ib"},$("dl",{class:"fl"},r.map(Vr)),n&&Ar("Raw transaction",n.raw))]}function Wa(){const e=We(),t=V("beat"),n=se(B.holding);t.max=String(e),t.value=String(B.beat??e),t.disabled=e===0,V("beat-label").textContent=B.beat===null?`Now · beat ${e}`:`Beat ${B.beat} of ${e}`,V("replay").textContent=B.replay?"Stop":"Replay",V("replay").disabled=!n||e===0,V("to-now").disabled=B.beat===null,V("timeline-sub").textContent=(n==null?void 0:n.name)??"";const r=new Map,s=new Map([...z.chain.transactions.keys()].map((a,c)=>[a,c])),o=(a,c)=>r.set(a,[...r.get(a)??[],c]);for(const a of Q.log)a.root&&a.root===B.holding&&o(a.pending?"cued":a.beat,{e:a,at:s.get(a.id.slice(0,-2))??0});for(const a of Ze.ledger)[a.to,a.from].some(c=>{var u;return c&&((u=se(c))==null?void 0:u.root)===B.holding})&&o(a.beat??"cued",{m:a,at:s.get(a.txid)??0});const i=[...r.keys()].sort((a,c)=>a==="cued"?-1:c==="cued"?1:c-a);if(!i.length)return V("timeline-list").replaceChildren($("li",{class:"wait",text:n?"Nothing yet.":"Found a holding to start its timeline."}));V("timeline-list").replaceChildren(...i.map(a=>{const c=a==="cued"?null:z.chain.blocks[a-1],u=B.beat!==null&&(a==="cued"||a>B.beat),l=B.beat!==null&&a===B.beat;return $("li",{class:`beat${u?" later":""}${l?" now":""}`},$("p",{class:"bh"},$("span",{class:"bn",text:a==="cued"?"Cued":`Beat ${a}`}),$("span",{class:"bt",text:c?$2(c.time):z.clock.tempo==="manual"?"waiting for Beat now":"landing on the next beat"})),$("ol",{class:"evs"},r.get(a).sort((f,d)=>f.at-d.at).map(({e:f,m:d})=>d?Y2(d):W2(f))))}))}function W2(e){const[t,...n]=al(e,Q).split(" ");return $("li",{},$("button",{type:"button",class:`ev${e.ok?"":" bad"}${e.id===B.event?" on":""}`,"aria-pressed":String(e.id===B.event),onclick:()=>ns({event:e.id,node:e.node??B.node})},$("span",{class:"op",text:e.ok?t:`✕ ${t.replace(/:$/,"")}`})," ",$("span",{class:"es",text:n.join(" ")})))}const Y2=e=>$("li",{},$("button",{type:"button",class:`ev money${e.kind==="gas"?" gas":""}${e.key===B.tx?" on":""}`,"aria-pressed":String(e.key===B.tx),onclick:()=>{var t;return ns({tx:e.key,node:((t=se(e.to))==null?void 0:t.root)===B.holding?e.to:B.node})}},$("span",{class:"op",text:e.kind})," ",$("span",{class:"es",text:Gd(e)})));V("f-found").addEventListener("submit",async e=>{e.preventDefault();const t=e.currentTarget,n=Ea(t.elements.name.value);if(!n)return Ae("Name the holding: lowercase letters, digits and hyphens.",!0);await br("found",null,{name:n},(r,s)=>(Hd({holding:r,node:r}),`${n} is founded, ${s}.`))&&t.reset()});V("sample").addEventListener("click",async()=>{let e=null;Ae("Rehearsing the yolopreneur tree over six beats…"),await gn(t=>{e=_2(t)})&&(ns({holding:e,node:e}),Ae("Loaded the yolopreneur sample: six beats of history. Press Replay to watch it grow."))});V("f-birth").addEventListener("submit",async e=>{e.preventDefault();const t=e.currentTarget,n=se(B.node),r=Ea(t.elements.name.value),s=t.elements.kind.value;if(!r)return Ae("Name the child: lowercase letters, digits and hyphens.",!0);await br("birth",n.id,{name:r,kind:s},(o,i)=>`${r} is born to ${n.name}, ${i}.`)&&(t.elements.name.value="")});V("f-award").addEventListener("submit",async e=>{e.preventDefault();const t=e.currentTarget,n=se(B.node),r=t.elements.to.value,s=Ea(t.elements.skill.value),o=t.elements.belt.value;if(!s)return Ae("Name the skill, for example launch.",!0);await br("award",n.id,{to:r,skill:s,belt:o},(i,a)=>{var c;return`${(c=se(r))==null?void 0:c.name} holds a ${o} belt in ${s}, ${a}.`})&&(t.elements.skill.value="")});V("f-decide").addEventListener("submit",async e=>{e.preventDefault();const t=e.currentTarget,n=se(B.node),r=t.elements.title.value.trim(),s=t.elements.why.value.trim();if(!r)return Ae("A decision needs a title.",!0);await br("decide",n.id,{title:r,why:s},(o,i)=>`${n.name} decided “${r}”, ${i}.`)&&t.reset()});V("f-send").addEventListener("submit",async e=>{var a;e.preventDefault();const t=e.currentTarget,n=se(B.node),r=t.elements.to.value,s=u2(t.elements.amount.value);if(s===null)return Ae("Write an amount in test BTC, for example 1.5 (at most eight decimals).",!0);let o=null;if(!await gn(c=>{o=S2(c,n.id,r,s)}))return;const i=Ze.ledger.find(c=>c.txid===o);Ae(`${n.name} sent ${ye(s)} to ${((a=se(r))==null?void 0:a.root)===n.root?se(r).name:go(Q,r)}, ${i!=null&&i.beat?`at beat ${i.beat}`:"cued for the next beat"}.`),t.elements.amount.value=""});V("send-max").addEventListener("click",()=>{const e=se(B.node),t=e&&Ce(z.keys,Q,e);t&&(V("send-amount").value=xd(Va(z.chain.coins(t.script))))});V("f-graduate").addEventListener("submit",async e=>{e.preventDefault();const t=se(B.node),n=se(t.parent);await br("graduate",n.id,{of:t.id},(r,s)=>`${t.name} graduates from ${n.name}, ${s}. Its edge is adopted now.`)});V("f-close").addEventListener("submit",async e=>{e.preventDefault();const t=se(B.node);if(B.closing!==t.id)return B.closing=t.id,Bo(),V("close-go").focus();B.closing=null,await br("close",t.id,{},(n,r)=>`${t.name} is closed, ${r}.`)});V("close-keep").addEventListener("click",()=>{B.closing=null,Bo(),V("close-go").focus()});for(const e of document.querySelectorAll("[data-verb]"))e.addEventListener("click",()=>{B.verb=e.dataset.verb,B.closing=null,Bo()});for(const e of document.querySelectorAll("[data-rule]"))e.addEventListener("click",async()=>{const t=e.dataset.rule;await gn(n=>s2(n,t))&&Ae(t==="split"?"Each beat splits across the holdings that mine, by hashrate.":"Each beat goes whole to the holding that acts.")});for(const e of document.querySelectorAll("[data-tempo]"))e.addEventListener("click",async()=>{const t=e.dataset.tempo,n=/^\d+$/.test(t)?Number(t):t;await gn(r=>a2(r,n,Date.now(),$o(r,Fa(r)??B.holding)))&&Ae(t==="each"?"Each act is its own beat.":t==="manual"?"Acts are cued until you press Beat now.":`Acts are cued and land together on the next beat, at most ${t} seconds after the first.`)});V("beat-now").addEventListener("click",()=>Kd(e=>{pn(e,$o(e,Fa(e)??B.holding))}));setInterval(()=>{Dd();const{tempo:e,nextAt:t}=z.clock;B.busy||document.hidden||typeof e!="number"||!z.chain.mempool.length||t&&Date.now()c2(n,Date.now(),$o(n,Fa(n)??B.holding)))},1e3);addEventListener("storage",e=>{(e.key===So||e.key===null)&&jd()});function rs(){B.replay&&(clearInterval(B.replay),B.replay=null,Wa())}function X2(){const e=se(B.holding);if(!(!e||!We())){if(oo(typeof e.born=="number"?e.born:We()),B.beat===null)return Ae("Nothing to replay yet: this holding has one beat of history.");B.replay=setInterval(()=>{(B.beat===null||B.beat+1>=We())&&rs(),oo(B.beat===null?We():B.beat+1)},800),Wa()}}V("beat").addEventListener("input",e=>{rs(),oo(Number(e.target.value))});V("replay").addEventListener("click",()=>B.replay?rs():X2());for(const e of["to-now","past-now"])V(e).addEventListener("click",()=>{rs(),oo(We())});const ai=["system","light","dark"],Wd=()=>{V("theme").textContent=`Theme: ${document.documentElement.dataset.theme??"system"}`};V("theme").addEventListener("click",()=>{const e=ai[(ai.indexOf(document.documentElement.dataset.theme??"system")+1)%ai.length];e==="system"?delete document.documentElement.dataset.theme:document.documentElement.dataset.theme=e;try{e==="system"?localStorage.removeItem("orgchain-theme"):localStorage.setItem("orgchain-theme",e)}catch{}Wd()});function Yd(e,t,n){const r=V("confirm");r.replaceChildren($("span",{text:e}),$("button",{type:"button",class:"btn sm danger",text:t,onclick:()=>{r.hidden=!0,n()}}),$("button",{type:"button",class:"btn sm",text:"Cancel",onclick:()=>{r.hidden=!0}})),r.hidden=!1,r.querySelector("button").focus()}const J2={read:()=>{try{return Da()}catch{return ts()}}};async function Xd(e,t){rs(),await gn(n=>{Object.assign(n,e())},J2)&&(Object.assign(B,{holding:null,node:null,event:null,tx:null,beat:null,closing:null}),Ga(),Ae(t))}V("save").addEventListener("click",()=>{const e=$("a",{href:URL.createObjectURL(new Blob([wd(z)],{type:"application/json"})),download:`orgchain-lab-${new Date().toISOString().slice(0,10)}.json`});document.body.append(e),e.click(),e.remove(),setTimeout(()=>URL.revokeObjectURL(e.href),5e3),Ae("Saved a backup of this lab, test wallet included. Load it in any browser to carry on.")});V("load").addEventListener("click",()=>V("load-file").click());V("load-file").addEventListener("change",async e=>{var r;const t=(r=e.target.files)==null?void 0:r[0];if(e.target.value="",!t)return;let n;try{n=bd(await t.text())}catch(s){return Ae(`${t.name} is not an Orgchain lab: ${s.message}`,!0)}Yd(`Replace this browser's lab with ${t.name}?`,"Replace",()=>Xd(()=>n,`Loaded ${t.name}.`))});V("reset").addEventListener("click",()=>Yd("Erase this browser's lab: every holding, the chain and the test wallet?","Erase",()=>Xd(ts,"Erased. This is a fresh lab.")));Wd();jd(); diff --git a/ventures/lineage/orgchain/assets/index-DvE3oFvb.js b/ventures/lineage/orgchain/assets/index-DvE3oFvb.js deleted file mode 100644 index e80eec5..0000000 --- a/ventures/lineage/orgchain/assets/index-DvE3oFvb.js +++ /dev/null @@ -1,2063 +0,0 @@ -(function(){const t=document.createElement("link").relList;if(t&&t.supports&&t.supports("modulepreload"))return;for(const s of document.querySelectorAll('link[rel="modulepreload"]'))r(s);new MutationObserver(s=>{for(const o of s)if(o.type==="childList")for(const i of o.addedNodes)i.tagName==="LINK"&&i.rel==="modulepreload"&&r(i)}).observe(document,{childList:!0,subtree:!0});function n(s){const o={};return s.integrity&&(o.integrity=s.integrity),s.referrerPolicy&&(o.referrerPolicy=s.referrerPolicy),s.crossOrigin==="use-credentials"?o.credentials="include":s.crossOrigin==="anonymous"?o.credentials="omit":o.credentials="same-origin",o}function r(s){if(s.ep)return;s.ep=!0;const o=n(s);fetch(s.href,o)}})();const Ya=5e9;function Gc(e,t,n){const r=[];for(const[s,o]of e){const i=o-s;if(t>=i){t-=i;continue}const a=Math.min(n,i-t);if(a&&r.push([s+t,s+t+a]),n-=a,t=0,!n)break}return r}function Wc(e,t){var n;return(n=Gc(e,t,1)[0])==null?void 0:n[0]}function xs(e,t){let n=0;for(const[r,s]of e){if(t>=r&&ti.ranges);let o=0;return e.vout.map(i=>{const a=Gc(s,o,Number(i.value));return o+=Number(i.value),a})}function ci(e){if(!Number.isSafeInteger(e)||e<0)throw new Error(`Wrong positive integer: ${e}`)}function Xd(e){if(typeof e!="boolean")throw new Error(`Expected boolean, not ${e}`)}function Xc(e,...t){if(!(e instanceof Uint8Array))throw new TypeError("Expected Uint8Array");if(t.length>0&&!t.includes(e.length))throw new TypeError(`Expected Uint8Array of length ${t}, not of length=${e.length}`)}function Jd(e){if(typeof e!="function"||typeof e.create!="function")throw new Error("Hash should be wrapped by utils.wrapConstructor");ci(e.outputLen),ci(e.blockLen)}function Qd(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 eh(e,t){Xc(e);const n=t.outputLen;if(e.lengthnew DataView(e.buffer,e.byteOffset,e.byteLength),ht=(e,t)=>e<<32-t|e>>>t,nh=new Uint8Array(new Uint32Array([287454020]).buffer)[0]===68;if(!nh)throw new Error("Non little-endian hardware is not supported");Array.from({length:256},(e,t)=>t.toString(16).padStart(2,"0"));function rh(e){if(typeof e!="string")throw new TypeError(`utf8ToBytes expected string, got ${typeof e}`);return new TextEncoder().encode(e)}function Jc(e){if(typeof e=="string"&&(e=rh(e)),!(e instanceof Uint8Array))throw new TypeError(`Expected input type is Uint8Array (got ${typeof e})`);return e}let sh=class{clone(){return this._cloneInto()}};function Qc(e){const t=r=>e().update(Jc(r)).digest(),n=e();return t.outputLen=n.outputLen,t.blockLen=n.blockLen,t.create=()=>e(),t}function oh(e,t,n,r){if(typeof e.setBigUint64=="function")return e.setBigUint64(t,n,r);const s=BigInt(32),o=BigInt(4294967295),i=Number(n>>s&o),a=Number(n&o),c=r?4:0,u=r?0:4;e.setUint32(t+c,i,r),e.setUint32(t+u,a,r)}let ih=class extends sh{constructor(t,n,r,s){super(),this.blockLen=t,this.outputLen=n,this.padOffset=r,this.isLE=s,this.finished=!1,this.length=0,this.pos=0,this.destroyed=!1,this.buffer=new Uint8Array(t),this.view=Io(this.buffer)}update(t){To.exists(this);const{view:n,buffer:r,blockLen:s}=this;t=Jc(t);const o=t.length;for(let i=0;is-i&&(this.process(r,0),i=0);for(let l=i;lf.length)throw new Error("_sha2: outputLen bigger than state");for(let l=0;le&t^~e&n,ch=(e,t,n)=>e&t^e&n^t&n,uh=new Uint32Array([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]),Rt=new Uint32Array([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]),Ht=new Uint32Array(64);let eu=class extends ih{constructor(){super(64,32,8,!1),this.A=Rt[0]|0,this.B=Rt[1]|0,this.C=Rt[2]|0,this.D=Rt[3]|0,this.E=Rt[4]|0,this.F=Rt[5]|0,this.G=Rt[6]|0,this.H=Rt[7]|0}get(){const{A:t,B:n,C:r,D:s,E:o,F:i,G:a,H:c}=this;return[t,n,r,s,o,i,a,c]}set(t,n,r,s,o,i,a,c){this.A=t|0,this.B=n|0,this.C=r|0,this.D=s|0,this.E=o|0,this.F=i|0,this.G=a|0,this.H=c|0}process(t,n){for(let l=0;l<16;l++,n+=4)Ht[l]=t.getUint32(n,!1);for(let l=16;l<64;l++){const d=Ht[l-15],h=Ht[l-2],m=ht(d,7)^ht(d,18)^d>>>3,y=ht(h,17)^ht(h,19)^h>>>10;Ht[l]=y+Ht[l-7]+m+Ht[l-16]|0}let{A:r,B:s,C:o,D:i,E:a,F:c,G:u,H:f}=this;for(let l=0;l<64;l++){const d=ht(a,6)^ht(a,11)^ht(a,25),h=f+d+ah(a,c,u)+uh[l]+Ht[l]|0,y=(ht(r,2)^ht(r,13)^ht(r,22))+ch(r,s,o)|0;f=u,u=c,c=a,a=i+h|0,i=o,o=s,s=r,r=h+y|0}r=r+this.A|0,s=s+this.B|0,o=o+this.C|0,i=i+this.D|0,a=a+this.E|0,c=c+this.F|0,u=u+this.G|0,f=f+this.H|0,this.set(r,s,o,i,a,c,u,f)}roundClean(){Ht.fill(0)}destroy(){this.set(0,0,0,0,0,0,0,0),this.buffer.fill(0)}},lh=class extends eu{constructor(){super(),this.A=-1056596264,this.B=914150663,this.C=812702999,this.D=-150054599,this.E=-4191439,this.F=1750603025,this.G=1694076839,this.H=-1090891868,this.outputLen=28}};const ui=Qc(()=>new eu);Qc(()=>new lh);function fh(e,t){if(e.length>t)throw new TypeError(`Data is larger than array size: ${e.length} > ${t}`)}function dh(e){if(e.match(/[^a-fA-f0-9]/)!==null)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}`)}function hh(e){if(e>Number.MAX_SAFE_INTEGER)throw new TypeError("Number exceeds safe bounds!")}const{getRandomValues:ph}=crypto??globalThis.crypto??window.crypto;function gh(e=32){if(typeof ph=="function")return crypto.getRandomValues(new Uint8Array(e));throw new Error("Crypto module missing getRandomValues!")}function mh(e,t,n="be"){t===void 0&&(t=e.length),fh(e,t);const r=new Uint8Array(t).fill(0),s=n==="be"?0:t-e.length;return r.set(e,s),r}function tu(e){let t,n=0;const r=e.reduce((o,i)=>o+i.length,0),s=new Uint8Array(r);for(t=0;t0||(i.length^a)>0?"":"1";c in o||u>0;)f=o[c],f=f>0?f*256+u:u,u=f/s|0,o[c]=f%s,c++;for(;c-- >0;)i+=r[o[c]];return n&&i.length%4>0?i+"=".repeat(4-i.length%4):i}function xh(e,t){const n=nu(t),r=n.length,s=[],o=[];e=e.replace("=","");let i,a=0,c,u;for(i=0;i0||(o.length^i)>0||o.push(0);a in s||c>0;)u=s[a],u=u>0?u*r+c:c,c=u>>8,s[a]=u%256,a++}for(;a-- >0;)o.push(s[a]);return new Uint8Array(o)}function ru(e){return ui(ui(e))}function vh(e){const t=ru(e);return tu([e,t.slice(0,4)])}function Eh(e){const t=e.slice(0,-4),n=e.slice(-4);if(ru(t).slice(0,4).toString()!==n.toString())throw new Error("Invalid checksum!");return t}const Xa={encode:wh,decode:xh},su={encode:e=>{const t=vh(e);return Xa.encode(t,"base58")},decode:e=>{const t=Xa.decode(e,"base58");return Eh(t)}},ou="qpzry9x8gf2tvdw0s3jn54khce6mua7l",Sh=[996825010,642813549,513874426,1027748829,705979059],$s=[{version:0,name:"bech32",const:1},{version:1,name:"bech32m",const:734539939}];function iu(e){let t=1;for(let n=0;n>25;t=(t&33554431)<<5^e[n];for(let s=0;s<5;++s)(r>>s&1)!==0&&(t^=Sh[s])}return t}function au(e){const t=[];let n;for(n=0;n>5);for(t.push(0),n=0;n>5*(5-i)&31);return o}function cu(e,t,n,r=!0){const s=[];let o=0,i=0;const a=(1<>t>0)throw new Error("Failed to perform base conversion. Invalid value: "+String(u));for(o=(o<=n;)i-=n,s.push(o>>i&a)}if(r)i>0&&s.push(o<=t||(o<0)throw new Error("Failed to perform base conversion. Invalid Size!");return s}function $h(e,t,n){const r=t.concat(_h(e,t,n));let s=e+"1";for(let o=0;oo.version===t[0])??$s[0];if(!kh(r,t,s))throw new Error("Checksum verification failed!");return[r,t.slice(0,t.length-6)]}function Ah(e){let t,n,r=!1,s=!1;for(t=0;t126)return!1;n>=97&&n<=122&&(r=!0),n>=65&&n<=90&&(s=!0)}return!(r&&s)}function Bh(e){const t=e.lastIndexOf("1");return!(t<1||t+7>e.length||e.length>90)}function Th(e,t="bc",n=0){const r=[n,...cu([...e],8,5)],s=$s.find(i=>i.version===n)??$s[0],o=$h(t,r,s);return lu(o),o}function lu(e){e=e.toLowerCase();const t=e.split("1",1)[0],[n,r]=uu(e),s=cu(r.slice(1),5,8,!1),o=s.length;switch(!0){case t!==n:throw new Error("Returned hrp string is invalid.");case(s===null||o<2||o>40):throw new Error("Decoded string is invalid or out of spec.");case r[0]>16:throw new Error("Returned version bit is out of range.");default:return Uint8Array.from(s)}}function Ih(e){e=e.toLowerCase();const[t,n]=uu(e);return n[0]}const fu={encode:Th,decode:lu,version:Ih},du="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",hu="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",Oh=new TextEncoder;function pu(e,t=!1,n=!0){typeof e=="string"&&(e=Oh.encode(e));const r=t?hu:du;let s="",o=0,i=0;for(let a=0;a=6;)o-=6,s+=r[i>>o&63];if(o>0)for(i<<=6-o,s+=r[i&63];o<6;)s+=n?"=":"",o+=2;return s}function gu(e,t=!1){const n=t||e.includes("-")||e.includes("_")?hu.split(""):du.split("");e=e.replace(/=+$/,"");const r=e.split("");let s=0,o=0;const i=[];for(let a=0;a=8&&(s-=8,i.push(o>>>s&255))}return new Uint8Array(i)}const mu={encode:pu,decode:gu},yu={encode:e=>pu(e,!0,!1),decode:e=>gu(e,!0)},Ch=BigInt(0),Ph=BigInt(255),bu=BigInt(256);function Uh(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.")}function Nh(e,t,n="be"){t===void 0&&(t=Uh(e));const r=n==="le",s=new ArrayBuffer(t),o=new DataView(s);let i=r?0:t-1;for(;e>Ch;){const a=e&Ph,c=Number(a);r?o.setUint8(i++,c):o.setUint8(i--,c),e=(e-a)/bu}return new Uint8Array(s)}function Lh(e){let t=BigInt(0);for(let n=e.length-1;n>=0;n--)t=t*bu+BigInt(e[n]);return BigInt(t)}function Rh(e){const t=e.split("").map(Number);if(t.length%8!==0)throw new Error(`Binary array is invalid length: ${e.length}`);const n=new Uint8Array(t.length/8);for(let r=0,s=0;r255)throw new Error(`Invalid byte value: ${r}. Byte values must be between 0 and 255.`);for(let s=7;s>=0;s--,n++)t[n]=r>>s&1}return t.join("")}function jh(e){if(e<=255)return 1;if(e<=65535)return 2;if(e<=4294967295)return 4;throw new TypeError("Numbers larger than 4 bytes must specify a fixed size!")}function Kh(e,t,n="be"){t===void 0&&(t=jh(e));const r=n==="le",s=new ArrayBuffer(t),o=new DataView(s);let i=r?0:t-1;for(;e>0;){const a=e&255;r?o.setUint8(i++,e):o.setUint8(i--,e),e=(e-a)/256}return new Uint8Array(s)}function Dh(e){let t=0;for(let n=e.length-1;n>=0;n--)t=t*256+e[n],hh(t);return t}const Zh=new TextEncoder,Mh=new TextDecoder;function Mi(e){return Zh.encode(e)}function Oo(e){return Mh.decode(e)}function Vh(e,t){dh(e);const n=e.length/2;if(t===void 0&&(t=n),n>t)throw new TypeError(`Hex string is larger than array size: ${n} > ${t}`);return t}function qh(e,t,n="le"){t=Vh(e,t);const r=n==="le",s=new ArrayBuffer(t),o=new DataView(s);let i=r?0:t-1;for(let a=0;atypeof r=="bigint"?`${r}n`:r);return Mi(t)}function Gh(e,t,n){if(e instanceof ArrayBuffer)return new Uint8Array(e);if(e instanceof Uint8Array)return mh(e,t,n);if(typeof e=="string")return qh(e,t,n);if(typeof e=="bigint")return Nh(e,t,n);if(typeof e=="number")return Kh(e,t,n);if(typeof e=="boolean")return Uint8Array.of(e?1:0);throw TypeError("Unsupported format:"+typeof e)}var J;let E=(J=class extends Uint8Array{static random(t=32){const n=gh(t);return new J(n,t)}constructor(t,n,r){const s=Gh(t,n,r);super(s)}get arr(){return[...this]}get num(){return this.toNum()}get big(){return this.toBig()}get str(){return this.toStr()}get hex(){return this.toHex()}get raw(){return new Uint8Array(this)}get bin(){return this.toBin()}get b58chk(){return this.tob58chk()}get base64(){return this.toBase64()}get b64url(){return this.toB64url()}get digest(){return this.toHash()}get id(){return this.toHash().hex}get stream(){return new lr(this)}toNum(t="be"){const n=t==="be"?this.reverse():this;return Dh(n)}toBin(){return Hh(this)}toBig(t="be"){const n=t==="be"?this.reverse():this;return Lh(n)}toHash(){const t=ui(this);return new J(t)}toJson(){const t=Oo(this);return JSON.parse(t)}toBech32(t,n=0){return fu.encode(this,t,n)}toStr(){return Oo(this)}toHex(){return zh(this)}toBytes(){return new Uint8Array(this)}tob58chk(){return su.encode(this)}toBase64(){return mu.encode(this)}toB64url(){return yu.encode(this)}prepend(t){return J.join([J.bytes(t),this])}append(t){return J.join([this,J.bytes(t)])}slice(t,n){const r=new Uint8Array(this).slice(t,n);return new J(r)}subarray(t,n){const r=new Uint8Array(this).subarray(t,n);return new J(r)}reverse(){const t=new Uint8Array(this).reverse();return new J(t)}write(t,n){const r=J.bytes(t);this.set(r,n)}prefixSize(t){const n=J.varInt(this.length,t);return J.join([n,this])}static from(t){return new J(Uint8Array.from(t))}static of(...t){return new J(Uint8Array.of(...t))}static join(t){const n=t.map(s=>J.bytes(s)),r=tu(n);return new J(r)}static varInt(t,n){if(t<253)return J.num(t,1);if(t<65536)return J.of(253,...J.num(t,2,n));if(t<4294967296)return J.of(254,...J.num(t,4,n));if(BigInt(t)<0x10000000000000000n)return J.of(255,...J.num(t,8,n));throw new Error(`Value is too large: ${t}`)}},J.num=Wh,J.big=Xh,J.bin=Yh,J.raw=Jh,J.str=Qh,J.hex=e0,J.bytes=t0,J.json=n0,J.base64=r0,J.b64url=s0,J.bech32=o0,J.b58chk=i0,J.encode=Mi,J.decode=Oo,J);function Wh(e,t,n){return new E(e,t,n)}function Yh(e,t,n){return new E(Rh(e),t,n)}function Xh(e,t,n){return new E(e,t,n)}function Jh(e,t,n){return new E(e,t,n)}function Qh(e,t,n){return new E(Mi(e),t,n)}function e0(e,t,n){return new E(e,t,n)}function t0(e,t,n){return new E(e,t,n)}function n0(e){return new E(Fh(e))}function r0(e){return new E(mu.decode(e))}function s0(e){return new E(yu.decode(e))}function o0(e){return new E(fu.decode(e))}function i0(e){return new E(su.decode(e))}let lr=class{constructor(t){this.data=E.bytes(t),this.size=this.data.length}peek(t){if(t>this.size)throw new Error(`Size greater than stream: ${t} > ${this.size}`);return new E(this.data.slice(0,t))}read(t){t=t??this.readSize();const n=this.peek(t);return this.data=this.data.slice(t),this.size=this.data.length,n}readSize(t){const n=this.read(1).num;switch(!0){case(n>=0&&n<253):return n;case n===253:return this.read(2).toNum(t);case n===254:return this.read(4).toNum(t);case n===255:return this.read(8).toNum(t);default:throw new Error(`Varint is out of range: ${n}`)}}};function kt(e,t){const n=E.bytes(e);if(n.length!==t)throw new Error(`Invalid input size: ${n.hex} !== ${t}`)}function Pe(e,t){if(t)throw new Error(e);return!1}function vs(e,...t){const n=E.str(e).digest.raw,r=t.map(s=>E.bytes(s));return E.join([n,n,E.join(r)]).digest}const wu={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,OP_SUCCESS187:187,OP_SUCCESS188:188,OP_SUCCESS189:189,OP_SUCCESS190:190,OP_SUCCESS191:191,OP_SUCCESS192:192,OP_SUCCESS193:193,OP_SUCCESS194:194,OP_SUCCESS195:195,OP_SUCCESS196:196,OP_SUCCESS197:197,OP_SUCCESS198:198,OP_SUCCESS199:199,OP_SUCCESS200:200,OP_SUCCESS201:201,OP_SUCCESS202:202,OP_SUCCESS203:203,OP_SUCCESS204:204,OP_SUCCESS205:205,OP_SUCCESS206:206,OP_SUCCESS207:207,OP_SUCCESS208:208,OP_SUCCESS209:209,OP_SUCCESS210:210,OP_SUCCESS211:211,OP_SUCCESS212:212,OP_SUCCESS213:213,OP_SUCCESS214:214,OP_SUCCESS215:215,OP_SUCCESS216:216,OP_SUCCESS217:217,OP_SUCCESS218:218,OP_SUCCESS219:219,OP_SUCCESS220:220,OP_SUCCESS221:221,OP_SUCCESS222:222,OP_SUCCESS223:223,OP_SUCCESS224:224,OP_SUCCESS225:225,OP_SUCCESS226:226,OP_SUCCESS227:227,OP_SUCCESS228:228,OP_SUCCESS229:229,OP_SUCCESS230:230,OP_SUCCESS231:231,OP_SUCCESS232:232,OP_SUCCESS233:233,OP_SUCCESS234:234,OP_SUCCESS235:235,OP_SUCCESS236:236,OP_SUCCESS237:237,OP_SUCCESS238:238,OP_SUCCESS239:239,OP_SUCCESS240:240,OP_SUCCESS241:241,OP_SUCCESS242:242,OP_SUCCESS243:243,OP_SUCCESS244:244,OP_SUCCESS245:245,OP_SUCCESS246:246,OP_SUCCESS247:247,OP_SUCCESS248:248,OP_SUCCESS249:249,OP_SUCCESS250:250,OP_SUCCESS251:251,OP_SUCCESS252:252,OP_SUCCESS253:253,OP_SUCCESS254:254};function a0(e){if(e>186&&e<255)return"OP_SUCCESS"+String(e);for(const[t,n]of Object.entries(wu))if(n===e)return t;throw new Error("OPCODE not found:"+String(e))}function c0(e){for(const[t,n]of Object.entries(wu))if(t===e)return Number(n);throw new Error("OPCODE not found:"+e)}function u0(e){switch(!0){case e===0:return"opcode";case(e>=1&&e<=75):return"varint";case e===76:return"pushdata1";case e===77:return"pushdata2";case e===78:return"pushdata4";case e<=254:return"opcode";default:throw new Error(`Invalid word range: ${e}`)}}function l0(e){const r=[];switch(!0){case typeof e!="number":return!1;case e===0:return!0;case r.includes(e):return!1;case(750?E.join(t):new Uint8Array}function f0(e){let t=new Uint8Array;if(typeof e=="string"){if(e.startsWith("OP_"))return E.num(c0(e),1);Lt(e)?t=E.hex(e):t=E.str(e)}else t=E.bytes(e);if(t.length===1)return t[0]!==0&&t[0]<=16?(t[0]+=80,t):(t[0]>128&&t[0]<=255&&(t=new Uint8Array([t[0],0])),E.join([Ja(t.length),t]));if(t.length>As){const n=d0(t);return vu(n)}else return E.join([Ja(t.length),t])}function Ja(e){const t=E.num(76,1),n=E.num(77,1);switch(!0){case e<=75:return E.num(e);case(e>75&&e<256):return E.join([t,E.num(e,1,"le")]);case(e>=256&&e<=As):return E.join([n,E.num(e,2,"le")]);default:throw new Error("Invalid word size:"+e.toString())}}function d0(e){const t=[],n=new lr(e);for(;n.size>As;)t.push(n.read(As));return t.push(n.read(n.size)),t}function Vi(e,t=!1){let n=E.bytes(e);if(t){const s=n.stream.readSize("le");if(n=n.slice(1),n.length!==s)throw new Error(`Varint does not match stream size: ${s} !== ${n.length}`)}return h0(n)}function h0(e){const t=new lr(e),n=[],r=t.size;let s,o,i,a=0;for(;a0&&!t.includes(e.length))throw new TypeError(`Expected Uint8Array of length ${t}, not of length=${e.length}`)}function w0(e){if(typeof e!="function"||typeof e.create!="function")throw new Error("Hash should be wrapped by utils.wrapConstructor");li(e.outputLen),li(e.blockLen)}function x0(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 v0(e,t){Eu(e);const n=t.outputLen;if(e.lengthnew DataView(e.buffer,e.byteOffset,e.byteLength),pt=(e,t)=>e<<32-t|e>>>t,S0=new Uint8Array(new Uint32Array([287454020]).buffer)[0]===68;if(!S0)throw new Error("Non little-endian hardware is not supported");Array.from({length:256},(e,t)=>t.toString(16).padStart(2,"0"));function k0(e){if(typeof e!="string")throw new TypeError(`utf8ToBytes expected string, got ${typeof e}`);return new TextEncoder().encode(e)}function qi(e){if(typeof e=="string"&&(e=k0(e)),!(e instanceof Uint8Array))throw new TypeError(`Expected input type is Uint8Array (got ${typeof e})`);return e}function _0(...e){if(!e.every(r=>r instanceof Uint8Array))throw new Error("Uint8Array list expected");if(e.length===1)return e[0];const t=e.reduce((r,s)=>r+s.length,0),n=new Uint8Array(t);for(let r=0,s=0;re().update(qi(r)).digest(),n=e();return t.outputLen=n.outputLen,t.blockLen=n.blockLen,t.create=()=>e(),t}function $0(e=32){if(Co&&typeof Co.getRandomValues=="function")return Co.getRandomValues(new Uint8Array(e));throw new Error("crypto.getRandomValues must be defined")}function A0(e,t,n,r){if(typeof e.setBigUint64=="function")return e.setBigUint64(t,n,r);const s=BigInt(32),o=BigInt(4294967295),i=Number(n>>s&o),a=Number(n&o),c=r?4:0,u=r?0:4;e.setUint32(t+c,i,r),e.setUint32(t+u,a,r)}let B0=class extends Su{constructor(t,n,r,s){super(),this.blockLen=t,this.outputLen=n,this.padOffset=r,this.isLE=s,this.finished=!1,this.length=0,this.pos=0,this.destroyed=!1,this.buffer=new Uint8Array(t),this.view=Po(this.buffer)}update(t){xn.exists(this);const{view:n,buffer:r,blockLen:s}=this;t=qi(t);const o=t.length;for(let i=0;is-i&&(this.process(r,0),i=0);for(let l=i;lf.length)throw new Error("_sha2: outputLen bigger than state");for(let l=0;le&t^~e&n,I0=(e,t,n)=>e&t^e&n^t&n,O0=new Uint32Array([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]),jt=new Uint32Array([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]),Kt=new Uint32Array(64);let _u=class extends B0{constructor(){super(64,32,8,!1),this.A=jt[0]|0,this.B=jt[1]|0,this.C=jt[2]|0,this.D=jt[3]|0,this.E=jt[4]|0,this.F=jt[5]|0,this.G=jt[6]|0,this.H=jt[7]|0}get(){const{A:t,B:n,C:r,D:s,E:o,F:i,G:a,H:c}=this;return[t,n,r,s,o,i,a,c]}set(t,n,r,s,o,i,a,c){this.A=t|0,this.B=n|0,this.C=r|0,this.D=s|0,this.E=o|0,this.F=i|0,this.G=a|0,this.H=c|0}process(t,n){for(let l=0;l<16;l++,n+=4)Kt[l]=t.getUint32(n,!1);for(let l=16;l<64;l++){const d=Kt[l-15],h=Kt[l-2],m=pt(d,7)^pt(d,18)^d>>>3,y=pt(h,17)^pt(h,19)^h>>>10;Kt[l]=y+Kt[l-7]+m+Kt[l-16]|0}let{A:r,B:s,C:o,D:i,E:a,F:c,G:u,H:f}=this;for(let l=0;l<64;l++){const d=pt(a,6)^pt(a,11)^pt(a,25),h=f+d+T0(a,c,u)+O0[l]+Kt[l]|0,y=(pt(r,2)^pt(r,13)^pt(r,22))+I0(r,s,o)|0;f=u,u=c,c=a,a=i+h|0,i=o,o=s,s=r,r=h+y|0}r=r+this.A|0,s=s+this.B|0,o=o+this.C|0,i=i+this.D|0,a=a+this.E|0,c=c+this.F|0,u=u+this.G|0,f=f+this.H|0,this.set(r,s,o,i,a,c,u,f)}roundClean(){Kt.fill(0)}destroy(){this.set(0,0,0,0,0,0,0,0),this.buffer.fill(0)}},C0=class extends _u{constructor(){super(),this.A=-1056596264,this.B=914150663,this.C=812702999,this.D=-150054599,this.E=-4191439,this.F=1750603025,this.G=1694076839,this.H=-1090891868,this.outputLen=28}};const $u=ku(()=>new _u);ku(()=>new C0);/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */const P0=BigInt(0),zi=BigInt(1),U0=BigInt(2),io=e=>e instanceof Uint8Array,N0=Array.from({length:256},(e,t)=>t.toString(16).padStart(2,"0"));function Qn(e){if(!io(e))throw new Error("Uint8Array expected");let t="";for(let n=0;ner(e.toString(16).padStart(t*2,"0")),Bu=(e,t)=>Gn(e,t).reverse(),L0=e=>er(Au(e));function Qe(e,t,n){let r;if(typeof t=="string")try{r=er(t)}catch(o){throw new Error(`${e} must be valid hex string, got "${t}". Cause: ${o}`)}else if(io(t))r=Uint8Array.from(t);else throw new Error(`${e} must be hex string or Uint8Array`);const s=r.length;if(typeof n=="number"&&s!==n)throw new Error(`${e} expected ${n} bytes, got ${s}`);return r}function st(...e){const t=new Uint8Array(e.reduce((r,s)=>r+s.length,0));let n=0;return e.forEach(r=>{if(!io(r))throw new Error("Uint8Array expected");t.set(r,n),n+=r.length}),t}function R0(e,t){if(e.length!==t.length)return!1;for(let n=0;n0n;e>>=zi,t+=1);return t}const j0=(e,t)=>e>>BigInt(t)&1n,K0=(e,t,n)=>e|(n?zi:P0)<(U0<new Uint8Array(e),Qa=e=>Uint8Array.from(e);function Tu(e,t,n){if(typeof e!="number"||e<2)throw new Error("hashLen must be a number");if(typeof t!="number"||t<2)throw new Error("qByteLen must be a number");if(typeof n!="function")throw new Error("hmacFn must be a function");let r=Uo(e),s=Uo(e),o=0;const i=()=>{r.fill(1),s.fill(0),o=0},a=(...l)=>n(s,r,...l),c=(l=Uo())=>{s=a(Qa([0]),l),r=a(),l.length!==0&&(s=a(Qa([1]),l),r=a())},u=()=>{if(o++>=1e3)throw new Error("drbg: tried 1000 values");let l=0;const d=[];for(;l{i(),c(l);let h;for(;!(h=d(u()));)c();return i(),h}}const D0={bigint:e=>typeof e=="bigint",function:e=>typeof e=="function",boolean:e=>typeof e=="boolean",string:e=>typeof e=="string",isSafeInteger:e=>Number.isSafeInteger(e),array:e=>Array.isArray(e),field:(e,t)=>t.Fp.isValid(e),hash:e=>typeof e=="function"&&Number.isSafeInteger(e.outputLen)};function fr(e,t,n={}){const r=(s,o,i)=>{const a=D0[o];if(typeof a!="function")throw new Error(`Invalid validator "${o}", expected function`);const c=e[s];if(!(i&&c===void 0)&&!a(c,e))throw new Error(`Invalid param ${String(s)}=${c} (${typeof c}), expected ${o}`)};for(const[s,o]of Object.entries(t))r(s,o,!1);for(const[s,o]of Object.entries(n))r(s,o,!0);return e}var Z0=Object.freeze({__proto__:null,bitGet:j0,bitLen:H0,bitMask:Wi,bitSet:K0,bytesToHex:Qn,bytesToNumberBE:tn,bytesToNumberLE:Gi,concatBytes:st,createHmacDrbg:Tu,ensureBytes:Qe,equalBytes:R0,hexToBytes:er,hexToNumber:Fi,numberToBytesBE:Gn,numberToBytesLE:Bu,numberToHexUnpadded:Au,numberToVarBytesBE:L0,utf8ToBytes:ao,validateObject:fr});/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */const Te=BigInt(0),_e=BigInt(1),mn=BigInt(2),M0=BigInt(3),fi=BigInt(4),ec=BigInt(5),tc=BigInt(8);BigInt(9);BigInt(16);function Ue(e,t){const n=e%t;return n>=Te?n:t+n}function V0(e,t,n){if(n<=Te||t 0");if(n===_e)return Te;let r=_e;for(;t>Te;)t&_e&&(r=r*e%n),e=e*e%n,t>>=_e;return r}function Je(e,t,n){let r=e;for(;t-- >Te;)r*=r,r%=n;return r}function di(e,t){if(e===Te||t<=Te)throw new Error(`invert: expected positive integers, got n=${e} mod=${t}`);let n=Ue(e,t),r=t,s=Te,o=_e;for(;n!==Te;){const a=r/n,c=r%n,u=s-o*a;r=n,n=c,s=o,o=u}if(r!==_e)throw new Error("invert: does not exist");return Ue(s,t)}function q0(e){const t=(e-_e)/mn;let n,r,s;for(n=e-_e,r=0;n%mn===Te;n/=mn,r++);for(s=mn;s(r[s]="function",r),t);return fr(e,n)}function G0(e,t,n){if(n 0");if(n===Te)return e.ONE;if(n===_e)return t;let r=e.ONE,s=t;for(;n>Te;)n&_e&&(r=e.mul(r,s)),s=e.sqr(s),n>>=_e;return r}function W0(e,t){const n=new Array(t.length),r=t.reduce((o,i,a)=>e.is0(i)?o:(n[a]=o,e.mul(o,i)),e.ONE),s=e.inv(r);return t.reduceRight((o,i,a)=>e.is0(i)?o:(n[a]=e.mul(o,n[a]),e.mul(o,i)),s),n}function Yi(e,t){const n=t!==void 0?t:e.toString(2).length,r=Math.ceil(n/8);return{nBitLength:n,nByteLength:r}}function Ou(e,t,n=!1,r={}){if(e<=Te)throw new Error(`Expected Fp ORDER > 0, got ${e}`);const{nBitLength:s,nByteLength:o}=Yi(e,t);if(o>2048)throw new Error("Field lengths over 2048 bytes are not supported");const i=z0(e),a=Object.freeze({ORDER:e,BITS:s,BYTES:o,MASK:Wi(s),ZERO:Te,ONE:_e,create:c=>Ue(c,e),isValid:c=>{if(typeof c!="bigint")throw new Error(`Invalid field element: expected bigint, got ${typeof c}`);return Te<=c&&cc===Te,isOdd:c=>(c&_e)===_e,neg:c=>Ue(-c,e),eql:(c,u)=>c===u,sqr:c=>Ue(c*c,e),add:(c,u)=>Ue(c+u,e),sub:(c,u)=>Ue(c-u,e),mul:(c,u)=>Ue(c*u,e),pow:(c,u)=>G0(a,c,u),div:(c,u)=>Ue(c*di(u,e),e),sqrN:c=>c*c,addN:(c,u)=>c+u,subN:(c,u)=>c-u,mulN:(c,u)=>c*u,inv:c=>di(c,e),sqrt:r.sqrt||(c=>i(a,c)),invertBatch:c=>W0(a,c),cmov:(c,u,f)=>f?u:c,toBytes:c=>n?Bu(c,o):Gn(c,o),fromBytes:c=>{if(c.length!==o)throw new Error(`Fp.fromBytes: expected ${o}, got ${c.length}`);return n?Gi(c):tn(c)}});return Object.freeze(a)}function Y0(e,t,n=!1){e=Qe("privateHash",e);const r=e.length,s=Yi(t).nByteLength+8;if(s<24||r1024)throw new Error(`hashToPrivateScalar: expected ${s}-1024 bytes of input, got ${r}`);const o=n?Gi(e):tn(e);return Ue(o,t-_e)+_e}/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */const X0=BigInt(0),No=BigInt(1);function J0(e,t){const n=(s,o)=>{const i=o.negate();return s?i:o},r=s=>{const o=Math.ceil(t/s)+1,i=2**(s-1);return{windows:o,windowSize:i}};return{constTimeNegate:n,unsafeLadder(s,o){let i=e.ZERO,a=s;for(;o>X0;)o&No&&(i=i.add(a)),a=a.double(),o>>=No;return i},precomputeWindow(s,o){const{windows:i,windowSize:a}=r(o),c=[];let u=s,f=u;for(let l=0;l>=h,g>c&&(g-=d,i+=No);const p=y,w=y+Math.abs(g)-1,b=m%2!==0,T=g<0;g===0?f=f.add(n(b,o[p])):u=u.add(n(T,o[w]))}return{p:u,f}},wNAFCached(s,o,i,a){const c=s._WINDOW_SIZE||1;let u=o.get(s);return u||(u=this.precomputeWindow(s,c),c!==1&&o.set(s,a(u))),this.wNAF(c,u,i)}}}function Cu(e){return Iu(e.Fp),fr(e,{n:"bigint",h:"bigint",Gx:"field",Gy:"field"},{nBitLength:"isSafeInteger",nByteLength:"isSafeInteger"}),Object.freeze({...Yi(e.n,e.nBitLength),...e,p:e.Fp.ORDER})}/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */function Q0(e){const t=Cu(e);fr(t,{a:"field",b:"field"},{allowedPrivateKeyLengths:"array",wrapPrivateKey:"boolean",isTorsionFree:"function",clearCofactor:"function",allowInfinityPoint:"boolean",fromBytes:"function",toBytes:"function"});const{endo:n,Fp:r,a:s}=t;if(n){if(!r.eql(s,r.ZERO))throw new Error("Endomorphism can only be defined for Koblitz curves that have a=0");if(typeof n!="object"||typeof n.beta!="bigint"||typeof n.splitScalar!="function")throw new Error("Expected endomorphism with beta: bigint and splitScalar: function")}return Object.freeze({...t})}const{bytesToNumberBE:ep,hexToBytes:tp}=Z0,vn={Err:class extends Error{constructor(t=""){super(t)}},_parseInt(e){const{Err:t}=vn;if(e.length<2||e[0]!==2)throw new t("Invalid signature integer tag");const n=e[1],r=e.subarray(2,n+2);if(!n||r.length!==n)throw new t("Invalid signature integer: wrong length");if(r[0]===0&&r[1]<=127)throw new t("Invalid signature integer: trailing length");return{d:ep(r),l:e.subarray(n+2)}},toSig(e){const{Err:t}=vn,n=typeof e=="string"?tp(e):e;if(!(n instanceof Uint8Array))throw new Error("ui8a expected");let r=n.length;if(r<2||n[0]!=48)throw new t("Invalid signature tag");if(n[1]!==r-2)throw new t("Invalid signature: incorrect length");const{d:s,l:o}=vn._parseInt(n.subarray(2)),{d:i,l:a}=vn._parseInt(o);if(a.length)throw new t("Invalid signature: left bytes after parsing");return{r:s,s:i}},hexFromSig(e){const t=u=>Number.parseInt(u[0],16)>=8?"00"+u:u,n=u=>{const f=u.toString(16);return f.length&1?`0${f}`:f},r=t(n(e.s)),s=t(n(e.r)),o=r.length/2,i=s.length/2,a=n(o),c=n(i);return`30${n(i+o+4)}02${c}${s}02${a}${r}`}},ot=BigInt(0),$e=BigInt(1),At=BigInt(2),Bs=BigInt(3),nc=BigInt(4);function np(e){const t=Q0(e),{Fp:n}=t,r=t.toBytes||((m,y,g)=>{const p=y.toAffine();return st(Uint8Array.from([4]),n.toBytes(p.x),n.toBytes(p.y))}),s=t.fromBytes||(m=>{const y=m.subarray(1),g=n.fromBytes(y.subarray(0,n.BYTES)),p=n.fromBytes(y.subarray(n.BYTES,2*n.BYTES));return{x:g,y:p}});function o(m){const{a:y,b:g}=t,p=n.sqr(m),w=n.mul(p,m);return n.add(n.add(w,n.mul(m,y)),g)}function i(m){return typeof m=="bigint"&&otn.eql(b,n.ZERO);return w(g)&&w(p)?l.ZERO:new l(g,p,n.ONE)}get x(){return this.toAffine().x}get y(){return this.toAffine().y}static normalizeZ(y){const g=n.invertBatch(y.map(p=>p.pz));return y.map((p,w)=>p.toAffine(g[w])).map(l.fromAffine)}static fromHex(y){const g=l.fromAffine(s(Qe("pointHex",y)));return g.assertValidity(),g}static fromPrivateKey(y){return l.BASE.multiply(c(y))}_setWindowSize(y){this._WINDOW_SIZE=y,u.delete(this)}assertValidity(){if(this.is0()){if(t.allowInfinityPoint)return;throw new Error("bad point: ZERO")}const{x:y,y:g}=this.toAffine();if(!n.isValid(y)||!n.isValid(g))throw new Error("bad point: x or y not FE");const p=n.sqr(g),w=o(y);if(!n.eql(p,w))throw new Error("bad point: equation left != right");if(!this.isTorsionFree())throw new Error("bad point: not in prime-order subgroup")}hasEvenY(){const{y}=this.toAffine();if(n.isOdd)return!n.isOdd(y);throw new Error("Field doesn't support isOdd")}equals(y){f(y);const{px:g,py:p,pz:w}=this,{px:b,py:T,pz:A}=y,O=n.eql(n.mul(g,A),n.mul(b,w)),U=n.eql(n.mul(p,A),n.mul(T,w));return O&&U}negate(){return new l(this.px,n.neg(this.py),this.pz)}double(){const{a:y,b:g}=t,p=n.mul(g,Bs),{px:w,py:b,pz:T}=this;let A=n.ZERO,O=n.ZERO,U=n.ZERO,C=n.mul(w,w),_=n.mul(b,b),N=n.mul(T,T),H=n.mul(w,b);return H=n.add(H,H),U=n.mul(w,T),U=n.add(U,U),A=n.mul(y,U),O=n.mul(p,N),O=n.add(A,O),A=n.sub(_,O),O=n.add(_,O),O=n.mul(A,O),A=n.mul(H,A),U=n.mul(p,U),N=n.mul(y,N),H=n.sub(C,N),H=n.mul(y,H),H=n.add(H,U),U=n.add(C,C),C=n.add(U,C),C=n.add(C,N),C=n.mul(C,H),O=n.add(O,C),N=n.mul(b,T),N=n.add(N,N),C=n.mul(N,H),A=n.sub(A,C),U=n.mul(N,_),U=n.add(U,U),U=n.add(U,U),new l(A,O,U)}add(y){f(y);const{px:g,py:p,pz:w}=this,{px:b,py:T,pz:A}=y;let O=n.ZERO,U=n.ZERO,C=n.ZERO;const _=t.a,N=n.mul(t.b,Bs);let H=n.mul(g,b),K=n.mul(p,T),v=n.mul(w,A),S=n.add(g,p),x=n.add(b,T);S=n.mul(S,x),x=n.add(H,K),S=n.sub(S,x),x=n.add(g,w);let k=n.add(b,A);return x=n.mul(x,k),k=n.add(H,v),x=n.sub(x,k),k=n.add(p,w),O=n.add(T,A),k=n.mul(k,O),O=n.add(K,v),k=n.sub(k,O),C=n.mul(_,x),O=n.mul(N,v),C=n.add(O,C),O=n.sub(K,C),C=n.add(K,C),U=n.mul(O,C),K=n.add(H,H),K=n.add(K,H),v=n.mul(_,v),x=n.mul(N,x),K=n.add(K,v),v=n.sub(H,v),v=n.mul(_,v),x=n.add(x,v),H=n.mul(K,x),U=n.add(U,H),H=n.mul(k,x),O=n.mul(S,O),O=n.sub(O,H),H=n.mul(S,K),C=n.mul(k,C),C=n.add(C,H),new l(O,U,C)}subtract(y){return this.add(y.negate())}is0(){return this.equals(l.ZERO)}wNAF(y){return h.wNAFCached(this,u,y,g=>{const p=n.invertBatch(g.map(w=>w.pz));return g.map((w,b)=>w.toAffine(p[b])).map(l.fromAffine)})}multiplyUnsafe(y){const g=l.ZERO;if(y===ot)return g;if(a(y),y===$e)return this;const{endo:p}=t;if(!p)return h.unsafeLadder(this,y);let{k1neg:w,k1:b,k2neg:T,k2:A}=p.splitScalar(y),O=g,U=g,C=this;for(;b>ot||A>ot;)b&$e&&(O=O.add(C)),A&$e&&(U=U.add(C)),C=C.double(),b>>=$e,A>>=$e;return w&&(O=O.negate()),T&&(U=U.negate()),U=new l(n.mul(U.px,p.beta),U.py,U.pz),O.add(U)}multiply(y){a(y);let g=y,p,w;const{endo:b}=t;if(b){const{k1neg:T,k1:A,k2neg:O,k2:U}=b.splitScalar(g);let{p:C,f:_}=this.wNAF(A),{p:N,f:H}=this.wNAF(U);C=h.constTimeNegate(T,C),N=h.constTimeNegate(O,N),N=new l(n.mul(N.px,b.beta),N.py,N.pz),p=C.add(N),w=_.add(H)}else{const{p:T,f:A}=this.wNAF(g);p=T,w=A}return l.normalizeZ([p,w])[0]}multiplyAndAddUnsafe(y,g,p){const w=l.BASE,b=(A,O)=>O===ot||O===$e||!A.equals(w)?A.multiplyUnsafe(O):A.multiply(O),T=b(this,g).add(b(y,p));return T.is0()?void 0:T}toAffine(y){const{px:g,py:p,pz:w}=this,b=this.is0();y==null&&(y=b?n.ONE:n.inv(w));const T=n.mul(g,y),A=n.mul(p,y),O=n.mul(w,y);if(b)return{x:n.ZERO,y:n.ZERO};if(!n.eql(O,n.ONE))throw new Error("invZ was invalid");return{x:T,y:A}}isTorsionFree(){const{h:y,isTorsionFree:g}=t;if(y===$e)return!0;if(g)return g(l,this);throw new Error("isTorsionFree() has not been declared for the elliptic curve")}clearCofactor(){const{h:y,clearCofactor:g}=t;return y===$e?this:g?g(l,this):this.multiplyUnsafe(t.h)}toRawBytes(y=!0){return this.assertValidity(),r(l,this,y)}toHex(y=!0){return Qn(this.toRawBytes(y))}}l.BASE=new l(t.Gx,t.Gy,n.ONE),l.ZERO=new l(n.ZERO,n.ONE,n.ZERO);const d=t.nBitLength,h=J0(l,t.endo?Math.ceil(d/2):d);return{CURVE:t,ProjectivePoint:l,normPrivateKeyToScalar:c,weierstrassEquation:o,isWithinCurveOrder:i}}function rp(e){const t=Cu(e);return fr(t,{hash:"hash",hmac:"function",randomBytes:"function"},{bits2int:"function",bits2int_modN:"function",lowS:"boolean"}),Object.freeze({lowS:!0,...t})}function sp(e){const t=rp(e),{Fp:n,n:r}=t,s=n.BYTES+1,o=2*n.BYTES+1;function i(x){return otQn(Gn(x,t.nByteLength));function m(x){const k=r>>$e;return x>k}function y(x){return m(x)?a(-x):x}const g=(x,k,I)=>tn(x.slice(k,I));class p{constructor(k,I,L){this.r=k,this.s=I,this.recovery=L,this.assertValidity()}static fromCompact(k){const I=t.nByteLength;return k=Qe("compactSignature",k,I*2),new p(g(k,0,I),g(k,I,2*I))}static fromDER(k){const{r:I,s:L}=vn.toSig(Qe("DER",k));return new p(I,L)}assertValidity(){if(!d(this.r))throw new Error("r must be 0 < r < CURVE.n");if(!d(this.s))throw new Error("s must be 0 < s < CURVE.n")}addRecoveryBit(k){return new p(this.r,this.s,k)}recoverPublicKey(k){const{r:I,s:L,recovery:P}=this,j=U(Qe("msgHash",k));if(P==null||![0,1,2,3].includes(P))throw new Error("recovery id invalid");const D=P===2||P===3?I+t.n:I;if(D>=n.ORDER)throw new Error("recovery id 2 or 3 invalid");const q=(P&1)===0?"02":"03",ie=u.fromHex(q+h(D)),oe=c(D),X=a(-j*oe),ue=a(L*oe),le=u.BASE.multiplyAndAddUnsafe(ie,X,ue);if(!le)throw new Error("point at infinify");return le.assertValidity(),le}hasHighS(){return m(this.s)}normalizeS(){return this.hasHighS()?new p(this.r,a(-this.s),this.recovery):this}toDERRawBytes(){return er(this.toDERHex())}toDERHex(){return vn.hexFromSig({r:this.r,s:this.s})}toCompactRawBytes(){return er(this.toCompactHex())}toCompactHex(){return h(this.r)+h(this.s)}}const w={isValidPrivateKey(x){try{return f(x),!0}catch{return!1}},normPrivateKeyToScalar:f,randomPrivateKey:()=>{const x=t.randomBytes(n.BYTES+8),k=Y0(x,r);return Gn(k,t.nByteLength)},precompute(x=8,k=u.BASE){return k._setWindowSize(x),k.multiply(BigInt(3)),k}};function b(x,k=!0){return u.fromPrivateKey(x).toRawBytes(k)}function T(x){const k=x instanceof Uint8Array,I=typeof x=="string",L=(k||I)&&x.length;return k?L===s||L===o:I?L===2*s||L===2*o:x instanceof u}function A(x,k,I=!0){if(T(x))throw new Error("first arg must be private key");if(!T(k))throw new Error("second arg must be public key");return u.fromHex(k).multiply(f(x)).toRawBytes(I)}const O=t.bits2int||function(x){const k=tn(x),I=x.length*8-t.nBitLength;return I>0?k>>BigInt(I):k},U=t.bits2int_modN||function(x){return a(O(x))},C=Wi(t.nBitLength);function _(x){if(typeof x!="bigint")throw new Error("bigint expected");if(!(ot<=x&&xae in I))throw new Error("sign() legacy options not supported");const{hash:L,randomBytes:P}=t;let{lowS:j,prehash:D,extraEntropy:q}=I;j==null&&(j=!0),x=Qe("msgHash",x),D&&(x=Qe("prehashed msgHash",L(x)));const ie=U(x),oe=f(k),X=[_(oe),_(ie)];if(q!=null){const ae=q===!0?P(n.BYTES):q;X.push(Qe("extraEntropy",ae,n.BYTES))}const ue=st(...X),le=ie;function ke(ae){const me=O(ae);if(!d(me))return;const _t=c(me),Xe=u.BASE.multiply(me).toAffine(),Ie=a(Xe.x);if(Ie===ot)return;const $t=a(_t*a(le+Ie*oe));if($t===ot)return;let wr=(Xe.x===Ie?0:2)|Number(Xe.y&$e),Wa=$t;return j&&m($t)&&(Wa=y($t),wr^=1),new p(Ie,Wa,wr)}return{seed:ue,k2sig:ke}}const H={lowS:t.lowS,prehash:!1},K={lowS:t.lowS,prehash:!1};function v(x,k,I=H){const{seed:L,k2sig:P}=N(x,k,I);return Tu(t.hash.outputLen,t.nByteLength,t.hmac)(L,P)}u.BASE._setWindowSize(8);function S(x,k,I,L=K){var Xe;const P=x;if(k=Qe("msgHash",k),I=Qe("publicKey",I),"strict"in L)throw new Error("options.strict was renamed to lowS");const{lowS:j,prehash:D}=L;let q,ie;try{if(typeof P=="string"||P instanceof Uint8Array)try{q=p.fromDER(P)}catch(Ie){if(!(Ie instanceof vn.Err))throw Ie;q=p.fromCompact(P)}else if(typeof P=="object"&&typeof P.r=="bigint"&&typeof P.s=="bigint"){const{r:Ie,s:$t}=P;q=new p(Ie,$t)}else throw new Error("PARSE");ie=u.fromHex(I)}catch(Ie){if(Ie.message==="PARSE")throw new Error("signature must be Signature instance, Uint8Array or hex string");return!1}if(j&&q.hasHighS())return!1;D&&(k=t.hash(k));const{r:oe,s:X}=q,ue=U(k),le=c(X),ke=a(ue*le),ae=a(oe*le),me=(Xe=u.BASE.multiplyAndAddUnsafe(ie,ke,ae))==null?void 0:Xe.toAffine();return me?a(me.x)===oe:!1}return{CURVE:t,getPublicKey:b,getSharedSecret:A,sign:v,verify:S,ProjectivePoint:u,Signature:p,utils:w}}function op(e,t){const n=e.ORDER;let r=ot;for(let d=n-$e;d%At===ot;d/=At)r+=$e;const s=r,o=(n-$e)/At**s,i=(o-$e)/At,a=At**s-$e,c=At**(s-$e),u=e.pow(t,o),f=e.pow(t,(o+$e)/At);let l=(d,h)=>{let m=u,y=e.pow(h,a),g=e.sqr(y);g=e.mul(g,h);let p=e.mul(d,g);p=e.pow(p,i),p=e.mul(p,y),y=e.mul(p,h),g=e.mul(p,d);let w=e.mul(g,y);p=e.pow(w,c);let b=e.eql(p,e.ONE);y=e.mul(g,f),p=e.mul(w,m),g=e.cmov(y,g,b),w=e.cmov(p,w,b);for(let T=s;T>1;T--){let A=At**(T-At),O=e.pow(w,A);const U=e.eql(O,e.ONE);y=e.mul(g,m),m=e.mul(m,m),O=e.mul(w,m),g=e.cmov(y,g,U),w=e.cmov(O,w,U)}return{isValid:b,value:g}};if(e.ORDER%nc===Bs){const d=(e.ORDER-Bs)/nc,h=e.sqrt(e.neg(t));l=(m,y)=>{let g=e.sqr(y);const p=e.mul(m,y);g=e.mul(g,p);let w=e.pow(g,d);w=e.mul(w,p);const b=e.mul(w,h),T=e.mul(e.sqr(w),y),A=e.eql(T,m);let O=e.cmov(b,w,A);return{isValid:A,value:O}}}return l}function ip(e,t){if(Iu(e),!e.isValid(t.A)||!e.isValid(t.B)||!e.isValid(t.Z))throw new Error("mapToCurveSimpleSWU: invalid opts");const n=op(e,t.Z);if(!e.isOdd)throw new Error("Fp.isOdd is not implemented!");return r=>{let s,o,i,a,c,u,f,l;s=e.sqr(r),s=e.mul(s,t.Z),o=e.sqr(s),o=e.add(o,s),i=e.add(o,e.ONE),i=e.mul(i,t.B),a=e.cmov(t.Z,e.neg(o),!e.eql(o,e.ZERO)),a=e.mul(a,t.A),o=e.sqr(i),u=e.sqr(a),c=e.mul(u,t.A),o=e.add(o,c),o=e.mul(o,i),u=e.mul(u,a),c=e.mul(u,t.B),o=e.add(o,c),f=e.mul(s,i);const{isValid:d,value:h}=n(o,u);l=e.mul(s,r),l=e.mul(l,h),f=e.cmov(f,i,d),l=e.cmov(l,h,d);const m=e.isOdd(r)===e.isOdd(l);return l=e.cmov(e.neg(l),l,m),f=e.div(f,a),{x:f,y:l}}}function ap(e){if(e instanceof Uint8Array)return e;if(typeof e=="string")return ao(e);throw new Error("DST must be Uint8Array or string")}const cp=tn;function Jt(e,t){if(e<0||e>=1<<8*t)throw new Error(`bad I2OSP call: value=${e} length=${t}`);const n=Array.from({length:t}).fill(0);for(let r=t-1;r>=0;r--)n[r]=e&255,e>>>=8;return new Uint8Array(n)}function up(e,t){const n=new Uint8Array(e.length);for(let r=0;r255&&(t=r(st(ao("H2C-OVERSIZE-DST-"),t)));const{outputLen:s,blockLen:o}=r,i=Math.ceil(n/s);if(i>255)throw new Error("Invalid xmd length");const a=st(t,Jt(t.length,1)),c=Jt(0,o),u=Jt(n,2),f=new Array(i),l=r(st(c,e,u,Jt(0,1),a));f[0]=r(st(l,Jt(1,1),a));for(let h=1;h<=i;h++){const m=[up(l,f[h-1]),Jt(h+1,1),a];f[h]=r(st(...m))}return st(...f).slice(0,n)}function fp(e,t,n,r,s){if(Br(e),Br(t),Xi(n),t.length>255){const o=Math.ceil(2*r/8);t=s.create({dkLen:o}).update(ao("H2C-OVERSIZE-DST-")).update(t).digest()}if(n>65535||t.length>255)throw new Error("expand_message_xof: invalid lenInBytes");return s.create({dkLen:n}).update(e).update(Jt(n,2)).update(t).update(Jt(t.length,1)).digest()}function rc(e,t,n){fr(n,{DST:"string",p:"bigint",m:"isSafeInteger",k:"isSafeInteger",hash:"hash"});const{p:r,k:s,m:o,hash:i,expand:a,DST:c}=n;Br(e),Xi(t);const u=ap(c),f=r.toString(2).length,l=Math.ceil((f+s)/8),d=t*o*l;let h;if(a==="xmd")h=lp(e,u,d,i);else if(a==="xof")h=fp(e,u,d,s,i);else if(a===void 0)h=e;else throw new Error('expand must be "xmd", "xof" or undefined');const m=new Array(t);for(let y=0;yArray.from(r).reverse());return(r,s)=>{const[o,i,a,c]=n.map(u=>u.reduce((f,l)=>e.add(e.mul(f,r),l)));return r=e.div(o,i),s=e.mul(s,e.div(a,c)),{x:r,y:s}}}function hp(e,t,n){if(typeof t!="function")throw new Error("mapToCurve() must be defined");return{hashToCurve(r,s){const o=rc(r,2,{...n,DST:n.DST,...s}),i=e.fromAffine(t(o[0])),a=e.fromAffine(t(o[1])),c=i.add(a).clearCofactor();return c.assertValidity(),c},encodeToCurve(r,s){const o=rc(r,1,{...n,DST:n.encodeDST,...s}),i=e.fromAffine(t(o[0])).clearCofactor();return i.assertValidity(),i}}}let Pu=class extends Su{constructor(t,n){super(),this.finished=!1,this.destroyed=!1,xn.hash(t);const r=qi(n);if(this.iHash=t.create(),typeof this.iHash.update!="function")throw new TypeError("Expected instance of class which extends utils.Hash");this.blockLen=this.iHash.blockLen,this.outputLen=this.iHash.outputLen;const s=this.blockLen,o=new Uint8Array(s);o.set(r.length>s?t.create().update(r).digest():r);for(let i=0;inew Pu(e,t).update(n).digest();Uu.create=(e,t)=>new Pu(e,t);/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */function pp(e){return{hash:e,hmac:(t,...n)=>Uu(e,t,_0(...n)),randomBytes:$0}}function gp(e,t){const n=r=>sp({...e,...pp(r)});return Object.freeze({...n(t),create:n})}/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */const Nu=BigInt("0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f"),sc=BigInt("0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141"),mp=BigInt(1),hi=BigInt(2),oc=(e,t)=>(e+t/hi)/t;function yp(e){const t=Nu,n=BigInt(3),r=BigInt(6),s=BigInt(11),o=BigInt(22),i=BigInt(23),a=BigInt(44),c=BigInt(88),u=e*e*e%t,f=u*u*e%t,l=Je(f,n,t)*f%t,d=Je(l,n,t)*f%t,h=Je(d,hi,t)*u%t,m=Je(h,s,t)*h%t,y=Je(m,o,t)*m%t,g=Je(y,a,t)*y%t,p=Je(g,c,t)*g%t,w=Je(p,a,t)*y%t,b=Je(w,n,t)*f%t,T=Je(b,i,t)*m%t,A=Je(T,r,t)*u%t,O=Je(A,hi,t);if(!on.eql(on.sqr(O),e))throw new Error("Cannot find square root");return O}const on=Ou(Nu,void 0,void 0,{sqrt:yp}),Ut=gp({a:BigInt(0),b:BigInt(7),Fp:on,n:sc,Gx:BigInt("55066263022277343669578718895168534326250603453777594175500187360389116729240"),Gy:BigInt("32670510020758816978083085130507043184471273380659243275938904335757337482424"),h:BigInt(1),lowS:!0,endo:{beta:BigInt("0x7ae96a2b657c07106e64479eac3434e99cf0497512f58995c1396c28719501ee"),splitScalar:e=>{const t=sc,n=BigInt("0x3086d221a7d46bcde86c90e49284eb15"),r=-mp*BigInt("0xe4437ed6010e88286f547fa90abfe4c3"),s=BigInt("0x114ca50f7a8e2f3f657c1108d9d44cfd8"),o=n,i=BigInt("0x100000000000000000000000000000000"),a=oc(o*e,t),c=oc(-r*e,t);let u=Ue(e-a*n-c*s,t),f=Ue(-a*r-c*o,t);const l=u>i,d=f>i;if(l&&(u=t-u),d&&(f=t-f),u>i||f>i)throw new Error("splitScalar: Endomorphism failed, k="+e);return{k1neg:l,k1:u,k2neg:d,k2:f}}}},$u);BigInt(0);Ut.ProjectivePoint;Ut.utils.randomPrivateKey;const bp=dp(on,[["0x8e38e38e38e38e38e38e38e38e38e38e38e38e38e38e38e38e38e38daaaaa8c7","0x7d3d4c80bc321d5b9f315cea7fd44c5d595d2fc0bf63b92dfff1044f17c6581","0x534c328d23f234e6e2a413deca25caece4506144037c40314ecbd0b53d9dd262","0x8e38e38e38e38e38e38e38e38e38e38e38e38e38e38e38e38e38e38daaaaa88c"],["0xd35771193d94918a9ca34ccbb7b640dd86cd409542f8487d9fe6b745781eb49b","0xedadc6f64383dc1df7c4b2d51b54225406d36b641f5e41bbc52a56612a8c6d14","0x0000000000000000000000000000000000000000000000000000000000000001"],["0x4bda12f684bda12f684bda12f684bda12f684bda12f684bda12f684b8e38e23c","0xc75e0c32d5cb7c0fa9d0a54b12a0a6d5647ab046d686da6fdffc90fc201d71a3","0x29a6194691f91a73715209ef6512e576722830a201be2018a765e85a9ecee931","0x2f684bda12f684bda12f684bda12f684bda12f684bda12f684bda12f38e38d84"],["0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffefffff93b","0x7a06534bb8bdb49fd5e9e6632722c2989467c1bfc8e8d978dfb425d2685c2573","0x6484aa716545ca2cf3a70c3fa8fe337e0a3d21162f0d6299a7bf8192bfd2a76f","0x0000000000000000000000000000000000000000000000000000000000000001"]].map(e=>e.map(t=>BigInt(t)))),wp=ip(on,{A:BigInt("0x3f8731abdd661adca08a5558f0f5d272e953d363cb6f0e5d405447c01a444533"),B:BigInt("1771"),Z:on.create(BigInt("-11"))});hp(Ut.ProjectivePoint,e=>{const{x:t,y:n}=wp(on.create(e[0]));return bp(t,n)},{DST:"secp256k1_XMD:SHA-256_SSWU_RO_",encodeDST:"secp256k1_XMD:SHA-256_SSWU_NU_",p:on.ORDER,m:1,k:128,expand:"xmd",hash:$u});function pi(e){if(!Number.isSafeInteger(e)||e<0)throw new Error(`Wrong positive integer: ${e}`)}function xp(e){if(typeof e!="boolean")throw new Error(`Expected boolean, not ${e}`)}function Lu(e,...t){if(!(e instanceof Uint8Array))throw new TypeError("Expected Uint8Array");if(t.length>0&&!t.includes(e.length))throw new TypeError(`Expected Uint8Array of length ${t}, not of length=${e.length}`)}function vp(e){if(typeof e!="function"||typeof e.create!="function")throw new Error("Hash should be wrapped by utils.wrapConstructor");pi(e.outputLen),pi(e.blockLen)}function Ep(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 Sp(e,t){Lu(e);const n=t.outputLen;if(e.lengthnew DataView(e.buffer,e.byteOffset,e.byteLength),gt=(e,t)=>e<<32-t|e>>>t,_p=new Uint8Array(new Uint32Array([287454020]).buffer)[0]===68;if(!_p)throw new Error("Non little-endian hardware is not supported");Array.from({length:256},(e,t)=>t.toString(16).padStart(2,"0"));function $p(e){if(typeof e!="string")throw new TypeError(`utf8ToBytes expected string, got ${typeof e}`);return new TextEncoder().encode(e)}function Ru(e){if(typeof e=="string"&&(e=$p(e)),!(e instanceof Uint8Array))throw new TypeError(`Expected input type is Uint8Array (got ${typeof e})`);return e}let Ap=class{clone(){return this._cloneInto()}};function Hu(e){const t=r=>e().update(Ru(r)).digest(),n=e();return t.outputLen=n.outputLen,t.blockLen=n.blockLen,t.create=()=>e(),t}function Bp(e,t,n,r){if(typeof e.setBigUint64=="function")return e.setBigUint64(t,n,r);const s=BigInt(32),o=BigInt(4294967295),i=Number(n>>s&o),a=Number(n&o),c=r?4:0,u=r?0:4;e.setUint32(t+c,i,r),e.setUint32(t+u,a,r)}let Tp=class extends Ap{constructor(t,n,r,s){super(),this.blockLen=t,this.outputLen=n,this.padOffset=r,this.isLE=s,this.finished=!1,this.length=0,this.pos=0,this.destroyed=!1,this.buffer=new Uint8Array(t),this.view=Ro(this.buffer)}update(t){Lo.exists(this);const{view:n,buffer:r,blockLen:s}=this;t=Ru(t);const o=t.length;for(let i=0;is-i&&(this.process(r,0),i=0);for(let l=i;lf.length)throw new Error("_sha2: outputLen bigger than state");for(let l=0;le&t^~e&n,Op=(e,t,n)=>e&t^e&n^t&n,Cp=new Uint32Array([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]),Dt=new Uint32Array([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]),Zt=new Uint32Array(64);let ju=class extends Tp{constructor(){super(64,32,8,!1),this.A=Dt[0]|0,this.B=Dt[1]|0,this.C=Dt[2]|0,this.D=Dt[3]|0,this.E=Dt[4]|0,this.F=Dt[5]|0,this.G=Dt[6]|0,this.H=Dt[7]|0}get(){const{A:t,B:n,C:r,D:s,E:o,F:i,G:a,H:c}=this;return[t,n,r,s,o,i,a,c]}set(t,n,r,s,o,i,a,c){this.A=t|0,this.B=n|0,this.C=r|0,this.D=s|0,this.E=o|0,this.F=i|0,this.G=a|0,this.H=c|0}process(t,n){for(let l=0;l<16;l++,n+=4)Zt[l]=t.getUint32(n,!1);for(let l=16;l<64;l++){const d=Zt[l-15],h=Zt[l-2],m=gt(d,7)^gt(d,18)^d>>>3,y=gt(h,17)^gt(h,19)^h>>>10;Zt[l]=y+Zt[l-7]+m+Zt[l-16]|0}let{A:r,B:s,C:o,D:i,E:a,F:c,G:u,H:f}=this;for(let l=0;l<64;l++){const d=gt(a,6)^gt(a,11)^gt(a,25),h=f+d+Ip(a,c,u)+Cp[l]+Zt[l]|0,y=(gt(r,2)^gt(r,13)^gt(r,22))+Op(r,s,o)|0;f=u,u=c,c=a,a=i+h|0,i=o,o=s,s=r,r=h+y|0}r=r+this.A|0,s=s+this.B|0,o=o+this.C|0,i=i+this.D|0,a=a+this.E|0,c=c+this.F|0,u=u+this.G|0,f=f+this.H|0,this.set(r,s,o,i,a,c,u,f)}roundClean(){Zt.fill(0)}destroy(){this.set(0,0,0,0,0,0,0,0),this.buffer.fill(0)}},Pp=class extends ju{constructor(){super(),this.A=-1056596264,this.B=914150663,this.C=812702999,this.D=-150054599,this.E=-4191439,this.F=1750603025,this.G=1694076839,this.H=-1090891868,this.outputLen=28}};const gi=Hu(()=>new ju);Hu(()=>new Pp);function Up(e,t){if(e.length>t)throw new TypeError(`Data is larger than array size: ${e.length} > ${t}`)}function Np(e){if(e.match(/[^a-fA-f0-9]/)!==null)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}`)}function Lp(e){if(e>Number.MAX_SAFE_INTEGER)throw new TypeError("Number exceeds safe bounds!")}const{getRandomValues:Rp}=crypto??globalThis.crypto??window.crypto;function Hp(e=32){if(typeof Rp=="function")return crypto.getRandomValues(new Uint8Array(e));throw new Error("Crypto module missing getRandomValues!")}function jp(e,t,n="be"){t===void 0&&(t=e.length),Up(e,t);const r=new Uint8Array(t).fill(0),s=n==="be"?0:t-e.length;return r.set(e,s),r}function Ku(e){let t,n=0;const r=e.reduce((o,i)=>o+i.length,0),s=new Uint8Array(r);for(t=0;t0||(i.length^a)>0?"":"1";c in o||u>0;)f=o[c],f=f>0?f*256+u:u,u=f/s|0,o[c]=f%s,c++;for(;c-- >0;)i+=r[o[c]];return n&&i.length%4>0?i+"=".repeat(4-i.length%4):i}function Mp(e,t){const n=Du(t),r=n.length,s=[],o=[];e=e.replace("=","");let i,a=0,c,u;for(i=0;i0||(o.length^i)>0||o.push(0);a in s||c>0;)u=s[a],u=u>0?u*r+c:c,c=u>>8,s[a]=u%256,a++}for(;a-- >0;)o.push(s[a]);return new Uint8Array(o)}function Zu(e){return gi(gi(e))}function Vp(e){const t=Zu(e);return Ku([e,t.slice(0,4)])}function qp(e){const t=e.slice(0,-4),n=e.slice(-4);if(Zu(t).slice(0,4).toString()!==n.toString())throw new Error("Invalid checksum!");return t}const ic={encode:Zp,decode:Mp},Mu={encode:e=>{const t=Vp(e);return ic.encode(t,"base58")},decode:e=>{const t=ic.decode(e,"base58");return qp(t)}},Vu="qpzry9x8gf2tvdw0s3jn54khce6mua7l",zp=[996825010,642813549,513874426,1027748829,705979059],Ts=[{version:0,name:"bech32",const:1},{version:1,name:"bech32m",const:734539939}];function qu(e){let t=1;for(let n=0;n>25;t=(t&33554431)<<5^e[n];for(let s=0;s<5;++s)(r>>s&1)!==0&&(t^=zp[s])}return t}function zu(e){const t=[];let n;for(n=0;n>5);for(t.push(0),n=0;n>5*(5-i)&31);return o}function Fu(e,t,n,r=!0){const s=[];let o=0,i=0;const a=(1<>t>0)throw new Error("Failed to perform base conversion. Invalid value: "+String(u));for(o=(o<=n;)i-=n,s.push(o>>i&a)}if(r)i>0&&s.push(o<=t||(o<0)throw new Error("Failed to perform base conversion. Invalid Size!");return s}function Wp(e,t,n){const r=t.concat(Gp(e,t,n));let s=e+"1";for(let o=0;oo.version===t[0])??Ts[0];if(!Fp(r,t,s))throw new Error("Checksum verification failed!");return[r,t.slice(0,t.length-6)]}function Yp(e){let t,n,r=!1,s=!1;for(t=0;t126)return!1;n>=97&&n<=122&&(r=!0),n>=65&&n<=90&&(s=!0)}return!(r&&s)}function Xp(e){const t=e.lastIndexOf("1");return!(t<1||t+7>e.length||e.length>90)}function Jp(e,t="bc",n=0){const r=[n,...Fu([...e],8,5)],s=Ts.find(i=>i.version===n)??Ts[0],o=Wp(t,r,s);return Wu(o),o}function Wu(e){e=e.toLowerCase();const t=e.split("1",1)[0],[n,r]=Gu(e),s=Fu(r.slice(1),5,8,!1),o=s.length;switch(!0){case t!==n:throw new Error("Returned hrp string is invalid.");case(s===null||o<2||o>40):throw new Error("Decoded string is invalid or out of spec.");case r[0]>16:throw new Error("Returned version bit is out of range.");default:return Uint8Array.from(s)}}function Qp(e){e=e.toLowerCase();const[t,n]=Gu(e);return n[0]}const Yu={encode:Jp,decode:Wu,version:Qp},Xu="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",Ju="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",eg=new TextEncoder;function Qu(e,t=!1,n=!0){typeof e=="string"&&(e=eg.encode(e));const r=t?Ju:Xu;let s="",o=0,i=0;for(let a=0;a=6;)o-=6,s+=r[i>>o&63];if(o>0)for(i<<=6-o,s+=r[i&63];o<6;)s+=n?"=":"",o+=2;return s}function el(e,t=!1){const n=t||e.includes("-")||e.includes("_")?Ju.split(""):Xu.split("");e=e.replace(/=+$/,"");const r=e.split("");let s=0,o=0;const i=[];for(let a=0;a=8&&(s-=8,i.push(o>>>s&255))}return new Uint8Array(i)}const tl={encode:Qu,decode:el},nl={encode:e=>Qu(e,!0,!1),decode:e=>el(e,!0)},tg=BigInt(0),ng=BigInt(255),rl=BigInt(256);function rg(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.")}function sg(e,t,n="be"){t===void 0&&(t=rg(e));const r=n==="le",s=new ArrayBuffer(t),o=new DataView(s);let i=r?0:t-1;for(;e>tg;){const a=e&ng,c=Number(a);r?o.setUint8(i++,c):o.setUint8(i--,c),e=(e-a)/rl}return new Uint8Array(s)}function og(e){let t=BigInt(0);for(let n=e.length-1;n>=0;n--)t=t*rl+BigInt(e[n]);return BigInt(t)}function ig(e){const t=e.split("").map(Number);if(t.length%8!==0)throw new Error(`Binary array is invalid length: ${e.length}`);const n=new Uint8Array(t.length/8);for(let r=0,s=0;r255)throw new Error(`Invalid byte value: ${r}. Byte values must be between 0 and 255.`);for(let s=7;s>=0;s--,n++)t[n]=r>>s&1}return t.join("")}function cg(e){if(e<=255)return 1;if(e<=65535)return 2;if(e<=4294967295)return 4;throw new TypeError("Numbers larger than 4 bytes must specify a fixed size!")}function ug(e,t,n="be"){t===void 0&&(t=cg(e));const r=n==="le",s=new ArrayBuffer(t),o=new DataView(s);let i=r?0:t-1;for(;e>0;){const a=e&255;r?o.setUint8(i++,e):o.setUint8(i--,e),e=(e-a)/256}return new Uint8Array(s)}function lg(e){let t=0;for(let n=e.length-1;n>=0;n--)t=t*256+e[n],Lp(t);return t}const fg=new TextEncoder,dg=new TextDecoder;function Ji(e){return fg.encode(e)}function Ho(e){return dg.decode(e)}function hg(e,t){Np(e);const n=e.length/2;if(t===void 0&&(t=n),n>t)throw new TypeError(`Hex string is larger than array size: ${n} > ${t}`);return t}function pg(e,t,n="le"){t=hg(e,t);const r=n==="le",s=new ArrayBuffer(t),o=new DataView(s);let i=r?0:t-1;for(let a=0;atypeof r=="bigint"?`${r}n`:r);return Ji(t)}function yg(e,t,n){if(e instanceof ArrayBuffer)return new Uint8Array(e);if(e instanceof Uint8Array)return jp(e,t,n);if(typeof e=="string")return pg(e,t,n);if(typeof e=="bigint")return sg(e,t,n);if(typeof e=="number")return ug(e,t,n);if(typeof e=="boolean")return Uint8Array.of(e?1:0);throw TypeError("Unsupported format:"+typeof e)}const ne=class ne extends Uint8Array{static random(t=32){const n=Hp(t);return new ne(n,t)}constructor(t,n,r){const s=yg(t,n,r);super(s)}get arr(){return[...this]}get num(){return this.toNum()}get big(){return this.toBig()}get str(){return this.toStr()}get hex(){return this.toHex()}get raw(){return new Uint8Array(this)}get bin(){return this.toBin()}get b58chk(){return this.tob58chk()}get base64(){return this.toBase64()}get b64url(){return this.toB64url()}get digest(){return this.toHash()}get id(){return this.toHash().hex}get stream(){return new Ig(this)}toNum(t="be"){const n=t==="be"?this.reverse():this;return lg(n)}toBin(){return ag(this)}toBig(t="be"){const n=t==="be"?this.reverse():this;return og(n)}toHash(){const t=gi(this);return new ne(t)}toJson(){const t=Ho(this);return JSON.parse(t)}toBech32(t,n=0){return Yu.encode(this,t,n)}toStr(){return Ho(this)}toHex(){return gg(this)}toBytes(){return new Uint8Array(this)}tob58chk(){return Mu.encode(this)}toBase64(){return tl.encode(this)}toB64url(){return nl.encode(this)}prepend(t){return ne.join([ne.bytes(t),this])}append(t){return ne.join([this,ne.bytes(t)])}slice(t,n){const r=new Uint8Array(this).slice(t,n);return new ne(r)}subarray(t,n){const r=new Uint8Array(this).subarray(t,n);return new ne(r)}reverse(){const t=new Uint8Array(this).reverse();return new ne(t)}write(t,n){const r=ne.bytes(t);this.set(r,n)}prefixSize(t){const n=ne.varInt(this.length,t);return ne.join([n,this])}static from(t){return new ne(Uint8Array.from(t))}static of(...t){return new ne(Uint8Array.of(...t))}static join(t){const n=t.map(s=>ne.bytes(s)),r=Ku(n);return new ne(r)}static varInt(t,n){if(t<253)return ne.num(t,1);if(t<65536)return ne.of(253,...ne.num(t,2,n));if(t<4294967296)return ne.of(254,...ne.num(t,4,n));if(BigInt(t)<0x10000000000000000n)return ne.of(255,...ne.num(t,8,n));throw new Error(`Value is too large: ${t}`)}};ne.num=bg,ne.big=xg,ne.bin=wg,ne.raw=vg,ne.str=Eg,ne.hex=Sg,ne.bytes=kg,ne.json=_g,ne.base64=$g,ne.b64url=Ag,ne.bech32=Bg,ne.b58chk=Tg,ne.encode=Ji,ne.decode=Ho;let W=ne;function bg(e,t,n){return new W(e,t,n)}function wg(e,t,n){return new W(ig(e),t,n)}function xg(e,t,n){return new W(e,t,n)}function vg(e,t,n){return new W(e,t,n)}function Eg(e,t,n){return new W(Ji(e),t,n)}function Sg(e,t,n){return new W(e,t,n)}function kg(e,t,n){return new W(e,t,n)}function _g(e){return new W(mg(e))}function $g(e){return new W(tl.decode(e))}function Ag(e){return new W(nl.decode(e))}function Bg(e){return new W(Yu.decode(e))}function Tg(e){return new W(Mu.decode(e))}class Ig{constructor(t){this.data=W.bytes(t),this.size=this.data.length}peek(t){if(t>this.size)throw new Error(`Size greater than stream: ${t} > ${this.size}`);return new W(this.data.slice(0,t))}read(t){t=t??this.readSize();const n=this.peek(t);return this.data=this.data.slice(t),this.size=this.data.length,n}readSize(t){const n=this.read(1).num;switch(!0){case(n>=0&&n<253):return n;case n===253:return this.read(2).toNum(t);case n===254:return this.read(4).toNum(t);case n===255:return this.read(8).toNum(t);default:throw new Error(`Varint is out of range: ${n}`)}}}const Is=Ut.CURVE,Qi=Is.n,Og=Is.p,Cg={x:Is.Gx,y:Is.Gy},Pg=BigInt(0);BigInt(1);BigInt(2);BigInt(3);BigInt(4);const mi={N:Qi,P:Og,G:Cg,_0n:Pg},xr=Ou(Qi,32,!0),sl=e=>Ue(e,Qi);function ea(e,t=!1){if(t)throw new Error(e);return!1}function ol(e){return W.random(e)}function Ug(e){const t=W.bytes(e).big;return W.big(sl(t),32)}var Ng=Object.freeze({__proto__:null,fail:ea,mod_bytes:Ug,random:ol});const{N:Lg,_0n:Rg}=mi;function Hg(e,t,n){const r=W.bytes(e);return r.length!==t?ea(`Invalid byte size: ${r.hex} !== ${t}`,n):!0}function jg(e,t){return typeof e=="bigint"&&Rgthis.big}lt(t){return new be(t).big0&&!t.includes(e.length))throw new Error(`Expected Uint8Array of length ${t}, not of length=${e.length}`)}function Mg(e){if(typeof e!="function"||typeof e.create!="function")throw new Error("Hash should be wrapped by utils.wrapConstructor");yi(e.outputLen),yi(e.blockLen)}function Vg(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 qg(e,t){il(e);const n=t.outputLen;if(e.lengthe instanceof Uint8Array,jo=e=>new DataView(e.buffer,e.byteOffset,e.byteLength),mt=(e,t)=>e<<32-t|e>>>t,Gg=new Uint8Array(new Uint32Array([287454020]).buffer)[0]===68;if(!Gg)throw new Error("Non little-endian hardware is not supported");Array.from({length:256},(e,t)=>t.toString(16).padStart(2,"0"));function Wg(e){if(typeof e!="string")throw new Error(`utf8ToBytes expected string, got ${typeof e}`);return new Uint8Array(new TextEncoder().encode(e))}function ta(e){if(typeof e=="string"&&(e=Wg(e)),!Fg(e))throw new Error(`expected Uint8Array, got ${typeof e}`);return e}let al=class{clone(){return this._cloneInto()}};function Kn(e){const t=r=>e().update(ta(r)).digest(),n=e();return t.outputLen=n.outputLen,t.blockLen=n.blockLen,t.create=()=>e(),t}function Yg(e,t,n,r){if(typeof e.setBigUint64=="function")return e.setBigUint64(t,n,r);const s=BigInt(32),o=BigInt(4294967295),i=Number(n>>s&o),a=Number(n&o),c=r?4:0,u=r?0:4;e.setUint32(t+c,i,r),e.setUint32(t+u,a,r)}class na extends al{constructor(t,n,r,s){super(),this.blockLen=t,this.outputLen=n,this.padOffset=r,this.isLE=s,this.finished=!1,this.length=0,this.pos=0,this.destroyed=!1,this.buffer=new Uint8Array(t),this.view=jo(this.buffer)}update(t){En.exists(this);const{view:n,buffer:r,blockLen:s}=this;t=ta(t);const o=t.length;for(let i=0;is-i&&(this.process(r,0),i=0);for(let l=i;lf.length)throw new Error("_sha2: outputLen bigger than state");for(let l=0;le&t^~e&n,Jg=(e,t,n)=>e&t^e&n^t&n,Qg=new Uint32Array([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]),Mt=new Uint32Array([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]),Vt=new Uint32Array(64);let cl=class extends na{constructor(){super(64,32,8,!1),this.A=Mt[0]|0,this.B=Mt[1]|0,this.C=Mt[2]|0,this.D=Mt[3]|0,this.E=Mt[4]|0,this.F=Mt[5]|0,this.G=Mt[6]|0,this.H=Mt[7]|0}get(){const{A:t,B:n,C:r,D:s,E:o,F:i,G:a,H:c}=this;return[t,n,r,s,o,i,a,c]}set(t,n,r,s,o,i,a,c){this.A=t|0,this.B=n|0,this.C=r|0,this.D=s|0,this.E=o|0,this.F=i|0,this.G=a|0,this.H=c|0}process(t,n){for(let l=0;l<16;l++,n+=4)Vt[l]=t.getUint32(n,!1);for(let l=16;l<64;l++){const d=Vt[l-15],h=Vt[l-2],m=mt(d,7)^mt(d,18)^d>>>3,y=mt(h,17)^mt(h,19)^h>>>10;Vt[l]=y+Vt[l-7]+m+Vt[l-16]|0}let{A:r,B:s,C:o,D:i,E:a,F:c,G:u,H:f}=this;for(let l=0;l<64;l++){const d=mt(a,6)^mt(a,11)^mt(a,25),h=f+d+Xg(a,c,u)+Qg[l]+Vt[l]|0,y=(mt(r,2)^mt(r,13)^mt(r,22))+Jg(r,s,o)|0;f=u,u=c,c=a,a=i+h|0,i=o,o=s,s=r,r=h+y|0}r=r+this.A|0,s=s+this.B|0,o=o+this.C|0,i=i+this.D|0,a=a+this.E|0,c=c+this.F|0,u=u+this.G|0,f=f+this.H|0,this.set(r,s,o,i,a,c,u,f)}roundClean(){Vt.fill(0)}destroy(){this.set(0,0,0,0,0,0,0,0),this.buffer.fill(0)}};class em extends cl{constructor(){super(),this.A=-1056596264,this.B=914150663,this.C=812702999,this.D=-150054599,this.E=-4191439,this.F=1750603025,this.G=1694076839,this.H=-1090891868,this.outputLen=28}}const Os=Kn(()=>new cl);Kn(()=>new em);const ss=BigInt(2**32-1),bi=BigInt(32);function ul(e,t=!1){return t?{h:Number(e&ss),l:Number(e>>bi&ss)}:{h:Number(e>>bi&ss)|0,l:Number(e&ss)|0}}function tm(e,t=!1){let n=new Uint32Array(e.length),r=new Uint32Array(e.length);for(let s=0;sBigInt(e>>>0)<>>0),rm=(e,t,n)=>e>>>n,sm=(e,t,n)=>e<<32-n|t>>>n,om=(e,t,n)=>e>>>n|t<<32-n,im=(e,t,n)=>e<<32-n|t>>>n,am=(e,t,n)=>e<<64-n|t>>>n-32,cm=(e,t,n)=>e>>>n-32|t<<64-n,um=(e,t)=>t,lm=(e,t)=>e,fm=(e,t,n)=>e<>>32-n,dm=(e,t,n)=>t<>>32-n,hm=(e,t,n)=>t<>>64-n,pm=(e,t,n)=>e<>>64-n;function gm(e,t,n,r){const s=(t>>>0)+(r>>>0);return{h:e+n+(s/2**32|0)|0,l:s|0}}const mm=(e,t,n)=>(e>>>0)+(t>>>0)+(n>>>0),ym=(e,t,n,r)=>t+n+r+(e/2**32|0)|0,bm=(e,t,n,r)=>(e>>>0)+(t>>>0)+(n>>>0)+(r>>>0),wm=(e,t,n,r,s)=>t+n+r+s+(e/2**32|0)|0,xm=(e,t,n,r,s)=>(e>>>0)+(t>>>0)+(n>>>0)+(r>>>0)+(s>>>0),vm=(e,t,n,r,s,o)=>t+n+r+s+o+(e/2**32|0)|0,Em={fromBig:ul,split:tm,toBig:nm,shrSH:rm,shrSL:sm,rotrSH:om,rotrSL:im,rotrBH:am,rotrBL:cm,rotr32H:um,rotr32L:lm,rotlSH:fm,rotlSL:dm,rotlBH:hm,rotlBL:pm,add:gm,add3L:mm,add3H:ym,add4L:bm,add4H:wm,add5H:vm,add5L:xm};var te=Em;const[Sm,km]=te.split(["0x428a2f98d728ae22","0x7137449123ef65cd","0xb5c0fbcfec4d3b2f","0xe9b5dba58189dbbc","0x3956c25bf348b538","0x59f111f1b605d019","0x923f82a4af194f9b","0xab1c5ed5da6d8118","0xd807aa98a3030242","0x12835b0145706fbe","0x243185be4ee4b28c","0x550c7dc3d5ffb4e2","0x72be5d74f27b896f","0x80deb1fe3b1696b1","0x9bdc06a725c71235","0xc19bf174cf692694","0xe49b69c19ef14ad2","0xefbe4786384f25e3","0x0fc19dc68b8cd5b5","0x240ca1cc77ac9c65","0x2de92c6f592b0275","0x4a7484aa6ea6e483","0x5cb0a9dcbd41fbd4","0x76f988da831153b5","0x983e5152ee66dfab","0xa831c66d2db43210","0xb00327c898fb213f","0xbf597fc7beef0ee4","0xc6e00bf33da88fc2","0xd5a79147930aa725","0x06ca6351e003826f","0x142929670a0e6e70","0x27b70a8546d22ffc","0x2e1b21385c26c926","0x4d2c6dfc5ac42aed","0x53380d139d95b3df","0x650a73548baf63de","0x766a0abb3c77b2a8","0x81c2c92e47edaee6","0x92722c851482353b","0xa2bfe8a14cf10364","0xa81a664bbc423001","0xc24b8b70d0f89791","0xc76c51a30654be30","0xd192e819d6ef5218","0xd69906245565a910","0xf40e35855771202a","0x106aa07032bbd1b8","0x19a4c116b8d2d0c8","0x1e376c085141ab53","0x2748774cdf8eeb99","0x34b0bcb5e19b48a8","0x391c0cb3c5c95a63","0x4ed8aa4ae3418acb","0x5b9cca4f7763e373","0x682e6ff3d6b2b8a3","0x748f82ee5defb2fc","0x78a5636f43172f60","0x84c87814a1f0ab72","0x8cc702081a6439ec","0x90befffa23631e28","0xa4506cebde82bde9","0xbef9a3f7b2c67915","0xc67178f2e372532b","0xca273eceea26619c","0xd186b8c721c0c207","0xeada7dd6cde0eb1e","0xf57d4f7fee6ed178","0x06f067aa72176fba","0x0a637dc5a2c898a6","0x113f9804bef90dae","0x1b710b35131c471b","0x28db77f523047d84","0x32caab7b40c72493","0x3c9ebe0a15c9bebc","0x431d67c49c100d4c","0x4cc5d4becb3e42b6","0x597f299cfc657e2a","0x5fcb6fab3ad6faec","0x6c44198c4a475817"].map(e=>BigInt(e))),qt=new Uint32Array(80),zt=new Uint32Array(80);let co=class extends na{constructor(){super(128,64,16,!1),this.Ah=1779033703,this.Al=-205731576,this.Bh=-1150833019,this.Bl=-2067093701,this.Ch=1013904242,this.Cl=-23791573,this.Dh=-1521486534,this.Dl=1595750129,this.Eh=1359893119,this.El=-1377402159,this.Fh=-1694144372,this.Fl=725511199,this.Gh=528734635,this.Gl=-79577749,this.Hh=1541459225,this.Hl=327033209}get(){const{Ah:t,Al:n,Bh:r,Bl:s,Ch:o,Cl:i,Dh:a,Dl:c,Eh:u,El:f,Fh:l,Fl:d,Gh:h,Gl:m,Hh:y,Hl:g}=this;return[t,n,r,s,o,i,a,c,u,f,l,d,h,m,y,g]}set(t,n,r,s,o,i,a,c,u,f,l,d,h,m,y,g){this.Ah=t|0,this.Al=n|0,this.Bh=r|0,this.Bl=s|0,this.Ch=o|0,this.Cl=i|0,this.Dh=a|0,this.Dl=c|0,this.Eh=u|0,this.El=f|0,this.Fh=l|0,this.Fl=d|0,this.Gh=h|0,this.Gl=m|0,this.Hh=y|0,this.Hl=g|0}process(t,n){for(let b=0;b<16;b++,n+=4)qt[b]=t.getUint32(n),zt[b]=t.getUint32(n+=4);for(let b=16;b<80;b++){const T=qt[b-15]|0,A=zt[b-15]|0,O=te.rotrSH(T,A,1)^te.rotrSH(T,A,8)^te.shrSH(T,A,7),U=te.rotrSL(T,A,1)^te.rotrSL(T,A,8)^te.shrSL(T,A,7),C=qt[b-2]|0,_=zt[b-2]|0,N=te.rotrSH(C,_,19)^te.rotrBH(C,_,61)^te.shrSH(C,_,6),H=te.rotrSL(C,_,19)^te.rotrBL(C,_,61)^te.shrSL(C,_,6),K=te.add4L(U,H,zt[b-7],zt[b-16]),v=te.add4H(K,O,N,qt[b-7],qt[b-16]);qt[b]=v|0,zt[b]=K|0}let{Ah:r,Al:s,Bh:o,Bl:i,Ch:a,Cl:c,Dh:u,Dl:f,Eh:l,El:d,Fh:h,Fl:m,Gh:y,Gl:g,Hh:p,Hl:w}=this;for(let b=0;b<80;b++){const T=te.rotrSH(l,d,14)^te.rotrSH(l,d,18)^te.rotrBH(l,d,41),A=te.rotrSL(l,d,14)^te.rotrSL(l,d,18)^te.rotrBL(l,d,41),O=l&h^~l&y,U=d&m^~d&g,C=te.add5L(w,A,U,km[b],zt[b]),_=te.add5H(C,p,T,O,Sm[b],qt[b]),N=C|0,H=te.rotrSH(r,s,28)^te.rotrBH(r,s,34)^te.rotrBH(r,s,39),K=te.rotrSL(r,s,28)^te.rotrBL(r,s,34)^te.rotrBL(r,s,39),v=r&o^r&a^o&a,S=s&i^s&c^i&c;p=y|0,w=g|0,y=h|0,g=m|0,h=l|0,m=d|0,{h:l,l:d}=te.add(u|0,f|0,_|0,N|0),u=a|0,f=c|0,a=o|0,c=i|0,o=r|0,i=s|0;const x=te.add3L(N,K,S);r=te.add3H(x,_,H,v),s=x|0}({h:r,l:s}=te.add(this.Ah|0,this.Al|0,r|0,s|0)),{h:o,l:i}=te.add(this.Bh|0,this.Bl|0,o|0,i|0),{h:a,l:c}=te.add(this.Ch|0,this.Cl|0,a|0,c|0),{h:u,l:f}=te.add(this.Dh|0,this.Dl|0,u|0,f|0),{h:l,l:d}=te.add(this.Eh|0,this.El|0,l|0,d|0),{h,l:m}=te.add(this.Fh|0,this.Fl|0,h|0,m|0),{h:y,l:g}=te.add(this.Gh|0,this.Gl|0,y|0,g|0),{h:p,l:w}=te.add(this.Hh|0,this.Hl|0,p|0,w|0),this.set(r,s,o,i,a,c,u,f,l,d,h,m,y,g,p,w)}roundClean(){qt.fill(0),zt.fill(0)}destroy(){this.buffer.fill(0),this.set(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0)}};class _m extends co{constructor(){super(),this.Ah=-1942145080,this.Al=424955298,this.Bh=1944164710,this.Bl=-1982016298,this.Ch=502970286,this.Cl=855612546,this.Dh=1738396948,this.Dl=1479516111,this.Eh=258812777,this.El=2077511080,this.Fh=2011393907,this.Fl=79989058,this.Gh=1067287976,this.Gl=1780299464,this.Hh=286451373,this.Hl=-1848208735,this.outputLen=28}}class $m extends co{constructor(){super(),this.Ah=573645204,this.Al=-64227540,this.Bh=-1621794909,this.Bl=-934517566,this.Ch=596883563,this.Cl=1867755857,this.Dh=-1774684391,this.Dl=1497426621,this.Eh=-1775747358,this.El=-1467023389,this.Fh=-1101128155,this.Fl=1401305490,this.Gh=721525244,this.Gl=746961066,this.Hh=246885852,this.Hl=-2117784414,this.outputLen=32}}class Am extends co{constructor(){super(),this.Ah=-876896931,this.Al=-1056596264,this.Bh=1654270250,this.Bl=914150663,this.Ch=-1856437926,this.Cl=812702999,this.Dh=355462360,this.Dl=-150054599,this.Eh=1731405415,this.El=-4191439,this.Fh=-1900787065,this.Fl=1750603025,this.Gh=-619958771,this.Gl=1694076839,this.Hh=1203062813,this.Hl=-1090891868,this.outputLen=48}}const Bm=Kn(()=>new co);Kn(()=>new _m);Kn(()=>new $m);Kn(()=>new Am);const Tm=new Uint8Array([7,4,13,1,10,6,15,3,12,0,9,5,2,14,11,8]),ll=Uint8Array.from({length:16},(e,t)=>t),Im=ll.map(e=>(9*e+5)%16);let ra=[ll],sa=[Im];for(let e=0;e<4;e++)for(let t of[ra,sa])t.push(t[e].map(n=>Tm[n]));const fl=[[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=>new Uint8Array(e)),Om=ra.map((e,t)=>e.map(n=>fl[t][n])),Cm=sa.map((e,t)=>e.map(n=>fl[t][n])),Pm=new Uint32Array([0,1518500249,1859775393,2400959708,2840853838]),Um=new Uint32Array([1352829926,1548603684,1836072691,2053994217,0]),os=(e,t)=>e<>>32-t;function cc(e,t,n,r){return e===0?t^n^r:e===1?t&n|~t&r:e===2?(t|~n)^r:e===3?t&r|n&~r:t^(n|~r)}const is=new Uint32Array(16);let Nm=class extends na{constructor(){super(64,20,8,!0),this.h0=1732584193,this.h1=-271733879,this.h2=-1732584194,this.h3=271733878,this.h4=-1009589776}get(){const{h0:t,h1:n,h2:r,h3:s,h4:o}=this;return[t,n,r,s,o]}set(t,n,r,s,o){this.h0=t|0,this.h1=n|0,this.h2=r|0,this.h3=s|0,this.h4=o|0}process(t,n){for(let h=0;h<16;h++,n+=4)is[h]=t.getUint32(n,!0);let r=this.h0|0,s=r,o=this.h1|0,i=o,a=this.h2|0,c=a,u=this.h3|0,f=u,l=this.h4|0,d=l;for(let h=0;h<5;h++){const m=4-h,y=Pm[h],g=Um[h],p=ra[h],w=sa[h],b=Om[h],T=Cm[h];for(let A=0;A<16;A++){const O=os(r+cc(h,o,a,u)+is[p[A]]+y,b[A])+l|0;r=l,l=u,u=os(a,10)|0,a=o,o=O}for(let A=0;A<16;A++){const O=os(s+cc(m,i,c,f)+is[w[A]]+g,T[A])+d|0;s=d,d=f,f=os(c,10)|0,c=i,i=O}}this.set(this.h1+a+f|0,this.h2+u+d|0,this.h3+l+s|0,this.h4+r+i|0,this.h0+o+c|0)}roundClean(){is.fill(0)}destroy(){this.destroyed=!0,this.buffer.fill(0),this.set(0,0,0,0,0)}};const Lm=Kn(()=>new Nm);let dl=class extends al{constructor(t,n){super(),this.finished=!1,this.destroyed=!1,En.hash(t);const r=ta(n);if(this.iHash=t.create(),typeof this.iHash.update!="function")throw new Error("Expected instance of class which extends utils.Hash");this.blockLen=this.iHash.blockLen,this.outputLen=this.iHash.outputLen;const s=this.blockLen,o=new Uint8Array(s);o.set(r.length>s?t.create().update(r).digest():r);for(let i=0;inew dl(e,t).update(n).digest();hl.create=(e,t)=>new dl(e,t);function Rm(e){const t=W.bytes(e);return W.raw(Os(t))}function tr(e){const t=W.bytes(e);return W.raw(Os(Os(t)))}function oa(e){const t=W.bytes(e);return W.raw(Lm(Os(t)))}function Hm(e,t){const n=W.bytes(e),r=W.bytes(t);return W.raw(hl(Bm,n,r))}function jm(e){const t=W.str(e).digest;return W.join([t,t])}function Km(e=32){return ia(ol(e))}function ia(e){return Ke.mod(e).buff}function pl(e,t=!1){const n=Ke.mod(e).point;return t?n.x:n.buff}function gl(e,t){const n=jn.from_x(t),r=Ke.mod(e);return n.mul(r).buff}function Dm(e,t,n="ecdh/code"){const r=jm(n),s=ia(e),o=pl(s),i=W.bytes(t),a=gl(s,i),c=[o.hex,i.hex];return c.sort(),Hm(a,W.join([r,...c]))}function Zm(e){const t=W.bytes(e);switch(!0){case t.length===32:return!0;case(t.length===33&&t[0]===2):return!0;case(t.length===33&&t[0]===3):return!1;default:throw new TypeError(`Invalid public key: ${t.hex}`)}}function Mm(e){const t=W.bytes(e);switch(t.length){case 32:return t;case 33:return t.slice(1,33);default:throw new Error(`Invalid key length: ${t.length}`)}}var Vm=Object.freeze({__proto__:null,genSecretKey:Km,getPublicKey:pl,getSecretKey:ia,getSharedCode:Dm,getSharedKey:gl,is_even_pub:Zm,xonly_pub:Mm});W.random(32);const ml={secp:Ut},wi={...Vm,...Ng};function uo(e){const t=E.bytes(e);return kt(t,33),oa(t)}function yl(e){const t=Se.fmt.toBytes(e,!1);return oa(t)}function bl(e){const t=Se.fmt.toBytes(e,!1);return Rm(t)}function wl(e,t="main"){const n=t==="main"?["1"]:["m","n"];for(const r of n)if(e.startsWith(r))return!0;return!1}function xl(e,t="main"){const n=E.bytes(e),r=t==="main"?E.num(0):E.num(111);return kt(e,20),n.prepend(r).tob58chk()}function qm(e,t="main"){if(!wl(e,t))throw new TypeError("Invalid p2pkh address!");return E.b58chk(e).slice(1)}function zm(e){const t=E.bytes(e);return kt(t,20),["OP_DUP","OP_HASH160",t.hex,"OP_EQUALVERIFY","OP_CHECKSIG"]}function Fm(e,t){const n=uo(e);return xl(n,t)}const vl={check:wl,encode:xl,decode:qm,hash:uo,scriptPubKey:zm,fromPubKey:Fm};function El(e,t="main"){const n=t==="main"?["3"]:["2"];for(const r of n)if(e.startsWith(r))return!0;return!1}function Sl(e,t="main"){const n=t==="main"?E.num(5):E.num(196),r=E.bytes(e);return kt(r,20),r.prepend(n).tob58chk()}function Gm(e,t="main"){if(!El(e,t))throw new TypeError(`Invalid p2sh address for network ${t}:`+e);return E.b58chk(e).slice(1)}function Wm(e){return["OP_HASH160",E.bytes(e).hex,"OP_EQUAL"]}function Ym(e,t){const n=yl(e);return Sl(n,t)}const kl={check:El,encode:Sl,decode:Gm,hash:yl,scriptPubKey:Wm,fromScript:Ym},aa={main:"bc",testnet:"tb",signet:"tb",regtest:"bcrt"},Xm=["bc1q","tb1q","bcrt1q"];function _l(e){for(const t of Xm)if(e.startsWith(t))return!0;return!1}function $l(e,t="main"){const n=aa[t],r=E.bytes(e);return kt(r,20),r.toBech32(n,0)}function Jm(e){if(!_l(e))throw new TypeError("Invalid segwit address!");return E.bech32(e)}function Qm(e){const t=E.bytes(e);return kt(t,20),["OP_0",t.hex]}function ey(e,t){const n=uo(e);return $l(n,t)}const Al={check:_l,encode:$l,decode:Jm,hash:uo,scriptPubKey:Qm,fromPubKey:ey},ty=["bc1q","tb1q","bcrt1q"];function Bl(e){for(const t of ty)if(e.startsWith(t))return!0;return!1}function Tl(e,t="main"){const n=aa[t],r=E.bytes(e);return kt(r,32),r.toBech32(n,0)}function ny(e){if(!Bl(e))throw new TypeError("Invalid segwit address!");return E.bech32(e)}function ry(e){const t=E.bytes(e);return kt(t,32),["OP_0",t.hex]}function sy(e,t){const n=bl(e);return Tl(n,t)}const Il={check:Bl,encode:Tl,decode:ny,hash:bl,scriptPubKey:ry,fromScript:sy};function In(e){const t=E.bytes(e);return t.length>32?t.slice(1,33):t}const oy=["bc1p","tb1p","bcrt1p"];function Ol(e){for(const t of oy)if(e.startsWith(t))return!0;return!1}function Cl(e,t="main"){const n=aa[t],r=E.bytes(e);return kt(r,32),r.toBech32(n,1)}function iy(e){if(!Ol(e))throw new TypeError("Invalid taproot address!");return E.bech32(e)}function ay(e){const t=E.bytes(e);return kt(t,32),["OP_1",t.hex]}function cy(e,t){const n=In(e);return Cl(n,t)}const Pl={check:Ol,encode:Cl,decode:iy,scriptPubKey:ay,fromPubKey:cy},uy={version:2,vin:[],vout:[],locktime:0},ly={scriptSig:[],sequence:4294967293,witness:[]},fy={value:0n,scriptPubKey:[]};function ca(e){const t={...uy,...e};return t.vin=t.vin.map(n=>({...ly,...n})),t.vout=t.vout.map(n=>({...fy,...n})),t}function nr(e,t){const{version:n,vin:r,vout:s,locktime:o}=ca(e),i=t!==!0&&dy(r),a=[ua(n)];i&&a.push(E.hex("0001")),a.push(hy(r)),a.push(py(s));for(const c of r)i&&a.push(my(c.witness));return a.push(la(o)),E.join(a)}function dy(e){for(const t of e){const{witness:n}=t;if(typeof n=="string"||n instanceof Uint8Array||Array.isArray(n)&&n.length>0)return!0}return!1}function ua(e){return E.num(e,4).reverse()}function qr(e){return E.hex(e,32).reverse()}function zr(e){return E.num(e,4).reverse()}function Fr(e){if(typeof e=="string")return E.hex(e,4).reverse();if(typeof e=="number")return E.num(e,4).reverse();throw new Error("Unrecognized format: "+String(e))}function hy(e){const t=[E.varInt(e.length,"le")];for(const n of e){const{txid:r,vout:s,scriptSig:o,sequence:i}=n;t.push(qr(r)),t.push(zr(s)),t.push(Hn(o,!0)),t.push(Fr(i))}return E.join(t)}function an(e){if(typeof e=="number"){if(e%1!==0)throw new Error("Value must be an integer:"+String(e));return E.num(e,8).reverse()}return E.big(e,8).reverse()}function py(e){const t=[E.varInt(e.length,"le")];for(const n of e)t.push(gy(n));return E.join(t)}function gy(e){const{value:t,scriptPubKey:n}=e,r=[];return r.push(an(t)),r.push(Hn(n,!0)),E.join(r)}function my(e=[]){const t=[];if(Array.isArray(e)){const n=E.varInt(e.length);t.push(n);for(const r of e)t.push(yy(r));return E.join(t)}else return E.bytes(e)}function yy(e){return by(e)?new E(0):Hn(e,!0)}function by(e){if(Array.isArray(e))return e.length===0;if(typeof e=="string"&&e==="")return!0;const t=E.bytes(e);return t.length===1&&t[0]===0}function la(e){if(typeof e=="string")return E.hex(e,4);if(typeof e=="number")return E.num(e,4).reverse();throw new Error("Unrecognized format: "+String(e))}function fa(e){typeof e=="string"&&(e=E.hex(e).raw);const t=new lr(e),n=wy(t),r=xy(t),s=vy(t),o=Sy(t);if(r)for(const a of s)a.witness=_y(t);const i=$y(t);return{version:n,vin:s,vout:o,locktime:i}}function wy(e){return e.read(4).reverse().toNum()}function xy(e){const[t,n]=[...e.peek(2)];if(t===0){if(e.read(2),n===1)return!0;throw new Error(`Invalid witness flag: ${n}`)}return!1}function vy(e){const t=[],n=e.readSize("le");for(let r=0;r0?e.read(n).hex:null}function Nl(e,t){const n=Ul(e);return n!==null?n:[]}function $y(e){return e.read(4).reverse().toNum()}function Ay(e){if(xu(e))return fa(e);if(typeof e=="object"&&!(e instanceof Uint8Array))return nr(e),ca(e);throw new Error("Invalid format: "+typeof e)}function By(e){if(xu(e))return fa(e),E.bytes(e);if(typeof e=="object")return nr(e);throw new Error("Invalid format: "+typeof e)}const da={toBytes:By,toJson:Ay},Ty=[["p2pkh",/^76a914(?\w{40})88ac$/],["p2sh",/^a914(?\w{40})87$/],["p2w-pkh",/^0014(?\w{40})$/],["p2w-sh",/^0020(?\w{64})$/],["p2tr",/^5120(?\w{64})$/]],Iy=[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];function Oy(e){let t=e.at(-1);return Lt(t)&&(t=E.hex(t)),e.length>1&&t instanceof Uint8Array&&t[0]===80?(e.pop(),E.raw(t)):null}function Cy(e){let t=e.at(-1);return Lt(t)&&(t=E.hex(t)),e.length>1&&t instanceof Uint8Array&&t.length>32&&Iy.includes(t[0]&254)?(e.pop(),E.raw(t)):null}function Py(e){if(e.length>1){const t=e.at(-1);try{const n=Se.fmt.toBytes(t);return e.pop(),n}catch{return null}}return null}function Uy(e){const t=[];for(const n of e)if(Lt(n)||n instanceof Uint8Array||typeof n=="number")t.push(E.bytes(n));else throw new Error("unrecognized value: "+String(n));return t}function Ny(e=[]){const t=[...e],n=Oy(t),r=Cy(t),s=Py(t),o=Uy(t);return{annex:n,cblock:r,script:s,params:o}}function Ly(e){const t=Se.fmt.toBytes(e,!1).hex;for(const[n,r]of Ty){const s=n,{groups:o}=r.exec(t)??{},{hash:i}=o??{};if(Lt(i))return{type:s,data:E.hex(i)}}return{type:"raw",data:E.hex(t)}}function Ry(e){const t=da.toJson(e),n=nr(t,!0);return tr(n).reverse().hex}function Hy(e){const t=da.toJson(e),n=nr(t,!0).length,r=nr(t,!1).length,s=n*3+r,o=s%4>0?1:0,i=Math.floor(s/4)+o;return{size:r,bsize:n,vsize:i,weight:s}}const ce={create:ca,encode:nr,decode:fa,fmt:da,util:{getTxSize:Hy,getTxid:Ry,readScriptPubKey:Ly,readWitness:Ny}},jy=[["1","p2pkh","main",20,"base58"],["3","p2sh","main",20,"base58"],["m","p2pkh","testnet",20,"base58"],["n","p2pkh","testnet",20,"base58"],["2","p2sh","testnet",20,"base58"],["bc1q","p2w-pkh","main",20,"bech32"],["tb1q","p2w-pkh","testnet",20,"bech32"],["bcrt1q","p2w-pkh","regtest",20,"bech32"],["bc1q","p2w-sh","main",32,"bech32"],["tb1q","p2w-sh","testnet",32,"bech32"],["bcrt1q","p2w-sh","regtest",32,"bech32"],["bc1p","p2tr","main",32,"bech32m"],["tb1p","p2tr","testnet",32,"bech32m"],["bcrt1p","p2tr","regtest",32,"bech32m"]];function Ky(e,t){switch(t){case"base58":return E.b58chk(e).slice(1);case"bech32":return E.bech32(e);case"bech32m":return E.bech32(e);default:throw new Error("Invalid address format: "+t)}}function Dy(e){for(const t of jy){const[n,r,s,o,i]=t;if(e.startsWith(n)&&Ky(e,i).length===o)return t}throw new Error("Invalid address: "+e)}function Ll(e){switch(e){case"p2pkh":return vl;case"p2sh":return kl;case"p2w-pkh":return Al;case"p2w-sh":return Il;case"p2tr":return Pl;default:throw new Error("Invalid address type: "+e)}}function Rl(e){const[t,n,r]=Dy(e),s=Ll(n),o=s.decode(e,r),i=s.scriptPubKey(o);return{prefix:t,type:n,network:r,data:o,script:i}}function Zy(e,t){const{type:n,data:r}=ce.util.readScriptPubKey(e);return Ll(n).encode(r,t)}function My(e){const{script:t}=Rl(e);return Se.fmt.toAsm(t,!1)}const Tr={p2pkh:vl,p2sh:kl,p2wpkh:Al,p2wsh:Il,p2tr:Pl,decode:Rl,fromScriptPubKey:Zy,toScriptPubKey:My},Vy=[1,2,3];function ha(e,t,n={}){const{sigflag:r=1}=n,s=(r&128)===128,o=r%128;if(!Vy.includes(o))throw new Error("Invalid hash type: "+String(r));const i=ce.fmt.toJson(e),{version:a,vin:c,vout:u,locktime:f}=i,{txid:l,vout:d,prevout:h,sequence:m}=c[t],{value:y}=h??{};if(y===void 0)throw new Error("Prevout value is empty!");let g=n.script;if(g===void 0&&n.pubkey!==void 0&&(g=`76a914${oa(n.pubkey).hex}88ac`),g===void 0)throw new Error("No pubkey / script has been set!");if(Se.fmt.toAsm(g).includes("OP_CODESEPARATOR"))throw new Error("This library does not currently support the use of OP_CODESEPARATOR in segwit scripts.");const p=[ua(a),qy(c,s),zy(c,o,s),qr(l),zr(d),Se.encode(g,!0),an(y),Fr(m),Fy(u,t,o),la(f),E.num(r,4).reverse()];return tr(E.join(p))}function qy(e,t){if(t===!0)return E.num(0,32);const n=[];for(const{txid:r,vout:s}of e)n.push(qr(r)),n.push(zr(s));return tr(E.join(n))}function zy(e,t,n){if(n||t!==1)return E.num(0,32);const r=[];for(const{sequence:s}of e)r.push(Fr(s));return tr(E.join(r))}function Fy(e,t,n){const r=[];if(n===1){for(const{value:s,scriptPubKey:o}of e)r.push(an(s)),r.push(Se.encode(o,!0));return tr(E.join(r))}if(n===3&&t1&&c[1].length===33)u=E.bytes(c[1]);else return Pe("No pubkey provided!",s);const f=Se.fmt.toParam(c[0]),l=f.slice(0,-1),d=f.slice(-1)[0],h=ha(r,t,{...n,sigflag:d});return ml.secp.verify(l,h,u)?!0:Pe("Invalid signature!",s)}const Yy={hash:ha,sign:Gy,verify:Wy},Xy=[0,1,2,3,129,130,131];function pa(e,t,n={}){const{extension:r,sigflag:s=0,extflag:o=0,key_version:i=0,separator_pos:a=4294967295}=n,c=ce.fmt.toJson(e),{version:u,vin:f,vout:l,locktime:d}=c;if(t>=f.length)throw new Error("Index out of bounds: "+String(t));if(!Xy.includes(s))throw new Error("Invalid hash type: "+String(s));if(o<0||o>127)throw new Error("Extention flag out of range: "+String(o));const{txid:h,vout:m,sequence:y,witness:g=[]}=f[t],p=(s&128)===128,w=sb(g),b=w!==void 0?1:0,A=(o+(r!==void 0?1:0))*2+b,O=E.str("TapSighash").digest,U=[O,O,E.num(0,1),E.num(s,1),ua(u),la(d)];if(!p){const C=f.map(_=>uc(_));U.push(Jy(f),eb(C),tb(C),Qy(f))}if(((s&3)<2||(s&3)>3)&&U.push(nb(l)),U.push(E.num(A,1)),p){const{value:C,scriptPubKey:_}=uc(f[t]);U.push(qr(h),zr(m),an(C),Se.encode(_,!0),Fr(y))}else U.push(E.num(t,4).reverse());return w!==void 0&&U.push(w),(s&3)===3&&U.push(rb(l[t])),r!==void 0&&U.push(E.bytes(r),E.num(i),E.num(a,4,"le")),E.join(U).digest}function Jy(e){const t=[];for(const{txid:n,vout:r}of e)t.push(qr(n)),t.push(zr(r));return E.join(t).digest}function Qy(e){const t=[];for(const{sequence:n}of e)t.push(Fr(n));return E.join(t).digest}function eb(e){const t=[];for(const{value:n}of e)t.push(an(n));return E.join(t).digest}function tb(e){const t=[];for(const{scriptPubKey:n}of e)t.push(Hn(n,!0));return E.join(t).digest}function nb(e){const t=[];for(const{value:n,scriptPubKey:r}of e)t.push(an(n)),t.push(Se.encode(r,!0));return E.join(t).digest}function rb(e){return E.join([an(e.value),Se.encode(e.scriptPubKey,!0)]).digest}function sb(e){if(e===void 0||e.length<2)return;let t=e.at(-1);if(typeof t=="string"&&(t=E.hex(t)),t instanceof Uint8Array&&t[0]===80)return E.raw(t).prefixSize("be").digest}function uc(e){if(e.prevout===void 0)throw new Error("Prevout data missing for input: "+String(e.txid));return e.prevout}const ob=0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2fn,ib=0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141n;function ab(e,t,n,r={}){const{sigflag:s=0}=r,o=pa(t,n,r),i=cb(e,o);return s===0?E.raw(i):E.join([i,s])}function cb(e,t,n=E.random(32)){const r=E.bytes(t),s=new Ke(e),o=s.point,i=o.hasEvenY?s.big:s.negated.big,a=vs("BIP0340/aux",E.bytes(n)),c=i^a.big,u=vs("BIP0340/nonce",c,o.x.raw,r),f=new Ke(u),l=f.point,d=l.hasEvenY?f.big:f.negated.big,h=new Ke(vs("BIP0340/challenge",l.x.raw,o.x.raw,r)),m=new Ke(d+h.big*i);return E.join([l.x.raw,m.raw])}function ub(e,t,n,r=!1){const s=jn.from_x(In(n)),o=E.bytes(t),i=E.bytes(e).stream;i.size<64&&Pe("Signature length is too small: "+String(i.size),r);const a=i.read(32);a.big>ob&&Pe("Signature r value greater than field size!",r);const c=i.read(32);c.big>ib&&Pe("Signature s value greater than curve order!",r);const u=new Ke(vs("BIP0340/challenge",a.raw,s.x.raw,o)),f=new Ke(c).point,l=s.mul(u.big),d=f.sub(l);return d.hasOddY&&Pe("Signature R value has odd Y coordinate!",r),d.x.big===0n&&Pe("Signature R value is infinite!",r),d.x.big===a.big}const lb=192;function lo(e){const t=E.str(e).digest;return E.join([t,t])}function ga(e,t=lb){return E.join([lo("TapLeaf"),hb(t),E.bytes(e)]).digest.hex}function fb(e,t){return ga(Se.fmt.toBytes(e),t)}function ma(e,t){return t0){const[h,m,y]=Cs(r,i);c=y,a=Wn(e,h,n)}else i!==void 0?a=Wn(e,i,n):a=Wn(e,void 0,n);const u=n?wi.getPublicKey(a)[0]:a[0],l=[E.num(s+Ml(u)),o];c.length>0&&c.forEach(h=>l.push(E.hex(h)));const d=E.join(l);if(i!==void 0&&!ya(a,i,d,t))throw new Error("Path checking failed! Unable to generate path.");return[In(a).hex,d.hex]}function ya(e,t,n,r={}){const{isPrivate:s=!1,throws:o=!1}=r,{parity:i,paths:a,intkey:c}=Zl(n),u=s?wi.getPublicKey(e,!0):In(e),f=E.join([i,u]);if(f.length!==33)return Pe("Invalid tapkey: "+f.hex,o);let l=E.bytes(t).hex;for(const h of a)l=ma(l,h);const d=Wn(c,l);return E.raw(d).hex===E.raw(f).hex}function Zl(e){const t=new lr(E.bytes(e)),n=t.read(1).num,r=t.read(32),[s,o]=n%2===0?[n,2]:[n-1,3],i=[];for(;t.size>=32;)i.push(t.read(32).hex);if(t.size!==0)throw new Error("Non-empty buffer on control block: "+String(t));return{intkey:r,paths:i,parity:o,version:s}}function Ml(e=2){if(e===0||e===1)return e;if(e===2||e==="02")return 0;if(e===3||e==="03")return 1;throw new Error("Invalid parity bit: "+String(e))}function vb(e,t,n={}){const r=ce.fmt.toJson(e),{throws:s=!1}=n,{prevout:o,witness:i=[]}=r.vin[t],a=ce.util.readWitness(i),{cblock:c,script:u,params:f}=a;let l;if(f.length<1)return Pe("Invalid witness data: "+String(i),s);const{scriptPubKey:d}=o??{};if(d===void 0)return Pe("Prevout scriptPubKey is empty!",s);const{type:h,data:m}=ce.util.readScriptPubKey(d);if(h!=="p2tr")return Pe("Prevout script is not a valid taproot output:"+m.hex,s);if(m.length!==32)return Pe("Invalid tapkey length: "+String(m.length),s);if(c!==null&&u!==null){const b=c[0]&254,T=ga(u,b);if(n.extension=T,!ya(m,T,c,{throws:s}))return Pe("cblock verification failed!",s)}n.pubkey!==void 0?l=E.bytes(n.pubkey):f.length>1&&f[1].length===32?l=E.bytes(f[1]):l=E.bytes(m);const y=Se.fmt.toParam(f[0]),g=new lr(y),p=g.read(64).raw;if(g.size===1&&(n.sigflag=g.read(1).num,n.sigflag===0))return Pe("0x00 is not a valid appended sigflag!",s);const w=pa(r,t,n);return ub(p,w,l,s)?!0:Pe("Invalid signature!",s)}const Eb={hash:pa,sign:ab,verify:vb},fo={segwit:Yy,taproot:Eb},Sb={getTag:lo,getLeaf:ga,getBranch:ma,getRoot:db},kb={readCtrlBlock:Zl,readParityBit:Ml},_b={getPubKey:pb,getSecKey:gb,getTweak:Hl,tweakSecKey:jl,tweakPubKey:Kl},Ps={getPubKey:xb,getSecKey:wb,encodeScript:fb,checkPath:ya,tree:Sb,tweak:_b,util:kb,SCRIPT_PUBKEY:yb};var fe;(function(e){e.assertEqual=s=>s;function t(s){}e.assertIs=t;function n(s){throw new Error}e.assertNever=n,e.arrayToEnum=s=>{const o={};for(const i of s)o[i]=i;return o},e.getValidEnumValues=s=>{const o=e.objectKeys(s).filter(a=>typeof s[s[a]]!="number"),i={};for(const a of o)i[a]=s[a];return e.objectValues(i)},e.objectValues=s=>e.objectKeys(s).map(function(o){return s[o]}),e.objectKeys=typeof Object.keys=="function"?s=>Object.keys(s):s=>{const o=[];for(const i in s)Object.prototype.hasOwnProperty.call(s,i)&&o.push(i);return o},e.find=(s,o)=>{for(const i of s)if(o(i))return i},e.isInteger=typeof Number.isInteger=="function"?s=>Number.isInteger(s):s=>typeof s=="number"&&isFinite(s)&&Math.floor(s)===s;function r(s,o=" | "){return s.map(i=>typeof i=="string"?`'${i}'`:i).join(o)}e.joinValues=r,e.jsonStringifyReplacer=(s,o)=>typeof o=="bigint"?o.toString():o})(fe||(fe={}));var xi;(function(e){e.mergeShapes=(t,n)=>({...t,...n})})(xi||(xi={}));const Z=fe.arrayToEnum(["string","nan","number","integer","float","boolean","date","bigint","symbol","function","undefined","null","array","object","unknown","promise","void","never","map","set"]),Qt=e=>{switch(typeof e){case"undefined":return Z.undefined;case"string":return Z.string;case"number":return isNaN(e)?Z.nan:Z.number;case"boolean":return Z.boolean;case"function":return Z.function;case"bigint":return Z.bigint;case"symbol":return Z.symbol;case"object":return Array.isArray(e)?Z.array:e===null?Z.null:e.then&&typeof e.then=="function"&&e.catch&&typeof e.catch=="function"?Z.promise:typeof Map<"u"&&e instanceof Map?Z.map:typeof Set<"u"&&e instanceof Set?Z.set:typeof Date<"u"&&e instanceof Date?Z.date:Z.object;default:return Z.unknown}},R=fe.arrayToEnum(["invalid_type","invalid_literal","custom","invalid_union","invalid_union_discriminator","invalid_enum_value","unrecognized_keys","invalid_arguments","invalid_return_type","invalid_date","invalid_string","too_small","too_big","invalid_intersection_types","not_multiple_of","not_finite"]),$b=e=>JSON.stringify(e,null,2).replace(/"([^"]+)":/g,"$1:");class ut extends Error{constructor(t){super(),this.issues=[],this.addIssue=r=>{this.issues=[...this.issues,r]},this.addIssues=(r=[])=>{this.issues=[...this.issues,...r]};const n=new.target.prototype;Object.setPrototypeOf?Object.setPrototypeOf(this,n):this.__proto__=n,this.name="ZodError",this.issues=t}get errors(){return this.issues}format(t){const n=t||function(o){return o.message},r={_errors:[]},s=o=>{for(const i of o.issues)if(i.code==="invalid_union")i.unionErrors.map(s);else if(i.code==="invalid_return_type")s(i.returnTypeError);else if(i.code==="invalid_arguments")s(i.argumentsError);else if(i.path.length===0)r._errors.push(n(i));else{let a=r,c=0;for(;cn.message){const n={},r=[];for(const s of this.issues)s.path.length>0?(n[s.path[0]]=n[s.path[0]]||[],n[s.path[0]].push(t(s))):r.push(t(s));return{formErrors:r,fieldErrors:n}}get formErrors(){return this.flatten()}}ut.create=e=>new ut(e);const Ir=(e,t)=>{let n;switch(e.code){case R.invalid_type:e.received===Z.undefined?n="Required":n=`Expected ${e.expected}, received ${e.received}`;break;case R.invalid_literal:n=`Invalid literal value, expected ${JSON.stringify(e.expected,fe.jsonStringifyReplacer)}`;break;case R.unrecognized_keys:n=`Unrecognized key(s) in object: ${fe.joinValues(e.keys,", ")}`;break;case R.invalid_union:n="Invalid input";break;case R.invalid_union_discriminator:n=`Invalid discriminator value. Expected ${fe.joinValues(e.options)}`;break;case R.invalid_enum_value:n=`Invalid enum value. Expected ${fe.joinValues(e.options)}, received '${e.received}'`;break;case R.invalid_arguments:n="Invalid function arguments";break;case R.invalid_return_type:n="Invalid function return type";break;case R.invalid_date:n="Invalid date";break;case R.invalid_string:typeof e.validation=="object"?"includes"in e.validation?(n=`Invalid input: must include "${e.validation.includes}"`,typeof e.validation.position=="number"&&(n=`${n} at one or more positions greater than or equal to ${e.validation.position}`)):"startsWith"in e.validation?n=`Invalid input: must start with "${e.validation.startsWith}"`:"endsWith"in e.validation?n=`Invalid input: must end with "${e.validation.endsWith}"`:fe.assertNever(e.validation):e.validation!=="regex"?n=`Invalid ${e.validation}`:n="Invalid";break;case R.too_small:e.type==="array"?n=`Array must contain ${e.exact?"exactly":e.inclusive?"at least":"more than"} ${e.minimum} element(s)`:e.type==="string"?n=`String must contain ${e.exact?"exactly":e.inclusive?"at least":"over"} ${e.minimum} character(s)`:e.type==="number"?n=`Number must be ${e.exact?"exactly equal to ":e.inclusive?"greater than or equal to ":"greater than "}${e.minimum}`:e.type==="date"?n=`Date must be ${e.exact?"exactly equal to ":e.inclusive?"greater than or equal to ":"greater than "}${new Date(Number(e.minimum))}`:n="Invalid input";break;case R.too_big:e.type==="array"?n=`Array must contain ${e.exact?"exactly":e.inclusive?"at most":"less than"} ${e.maximum} element(s)`:e.type==="string"?n=`String must contain ${e.exact?"exactly":e.inclusive?"at most":"under"} ${e.maximum} character(s)`:e.type==="number"?n=`Number must be ${e.exact?"exactly":e.inclusive?"less than or equal to":"less than"} ${e.maximum}`:e.type==="bigint"?n=`BigInt must be ${e.exact?"exactly":e.inclusive?"less than or equal to":"less than"} ${e.maximum}`:e.type==="date"?n=`Date must be ${e.exact?"exactly":e.inclusive?"smaller than or equal to":"smaller than"} ${new Date(Number(e.maximum))}`:n="Invalid input";break;case R.custom:n="Invalid input";break;case R.invalid_intersection_types:n="Intersection results could not be merged";break;case R.not_multiple_of:n=`Number must be a multiple of ${e.multipleOf}`;break;case R.not_finite:n="Number must be finite";break;default:n=t.defaultError,fe.assertNever(e)}return{message:n}};let Vl=Ir;function Ab(e){Vl=e}function Us(){return Vl}const Ns=e=>{const{data:t,path:n,errorMaps:r,issueData:s}=e,o=[...n,...s.path||[]],i={...s,path:o};let a="";const c=r.filter(u=>!!u).slice().reverse();for(const u of c)a=u(i,{data:t,defaultError:a}).message;return{...s,path:o,message:s.message||a}},Bb=[];function M(e,t){const n=Ns({issueData:t,data:e.data,path:e.path,errorMaps:[e.common.contextualErrorMap,e.schemaErrorMap,Us(),Ir].filter(r=>!!r)});e.common.issues.push(n)}class He{constructor(){this.value="valid"}dirty(){this.value==="valid"&&(this.value="dirty")}abort(){this.value!=="aborted"&&(this.value="aborted")}static mergeArray(t,n){const r=[];for(const s of n){if(s.status==="aborted")return Y;s.status==="dirty"&&t.dirty(),r.push(s.value)}return{status:t.value,value:r}}static async mergeObjectAsync(t,n){const r=[];for(const s of n)r.push({key:await s.key,value:await s.value});return He.mergeObjectSync(t,r)}static mergeObjectSync(t,n){const r={};for(const s of n){const{key:o,value:i}=s;if(o.status==="aborted"||i.status==="aborted")return Y;o.status==="dirty"&&t.dirty(),i.status==="dirty"&&t.dirty(),(typeof i.value<"u"||s.alwaysSet)&&(r[o.value]=i.value)}return{status:t.value,value:r}}}const Y=Object.freeze({status:"aborted"}),ql=e=>({status:"dirty",value:e}),Ve=e=>({status:"valid",value:e}),vi=e=>e.status==="aborted",Ei=e=>e.status==="dirty",Ls=e=>e.status==="valid",Rs=e=>typeof Promise<"u"&&e instanceof Promise;var F;(function(e){e.errToObj=t=>typeof t=="string"?{message:t}:t||{},e.toString=t=>typeof t=="string"?t:t==null?void 0:t.message})(F||(F={}));class vt{constructor(t,n,r,s){this._cachedPath=[],this.parent=t,this.data=n,this._path=r,this._key=s}get path(){return this._cachedPath.length||(this._key instanceof Array?this._cachedPath.push(...this._path,...this._key):this._cachedPath.push(...this._path,this._key)),this._cachedPath}}const lc=(e,t)=>{if(Ls(t))return{success:!0,data:t.value};if(!e.common.issues.length)throw new Error("Validation failed but no issues detected.");return{success:!1,get error(){if(this._error)return this._error;const n=new ut(e.common.issues);return this._error=n,this._error}}};function ee(e){if(!e)return{};const{errorMap:t,invalid_type_error:n,required_error:r,description:s}=e;if(t&&(n||r))throw new Error(`Can't use "invalid_type_error" or "required_error" in conjunction with custom error map.`);return t?{errorMap:t,description:s}:{errorMap:(i,a)=>i.code!=="invalid_type"?{message:a.defaultError}:typeof a.data>"u"?{message:r??a.defaultError}:{message:n??a.defaultError},description:s}}class re{constructor(t){this.spa=this.safeParseAsync,this._def=t,this.parse=this.parse.bind(this),this.safeParse=this.safeParse.bind(this),this.parseAsync=this.parseAsync.bind(this),this.safeParseAsync=this.safeParseAsync.bind(this),this.spa=this.spa.bind(this),this.refine=this.refine.bind(this),this.refinement=this.refinement.bind(this),this.superRefine=this.superRefine.bind(this),this.optional=this.optional.bind(this),this.nullable=this.nullable.bind(this),this.nullish=this.nullish.bind(this),this.array=this.array.bind(this),this.promise=this.promise.bind(this),this.or=this.or.bind(this),this.and=this.and.bind(this),this.transform=this.transform.bind(this),this.brand=this.brand.bind(this),this.default=this.default.bind(this),this.catch=this.catch.bind(this),this.describe=this.describe.bind(this),this.pipe=this.pipe.bind(this),this.isNullable=this.isNullable.bind(this),this.isOptional=this.isOptional.bind(this)}get description(){return this._def.description}_getType(t){return Qt(t.data)}_getOrReturnCtx(t,n){return n||{common:t.parent.common,data:t.data,parsedType:Qt(t.data),schemaErrorMap:this._def.errorMap,path:t.path,parent:t.parent}}_processInputParams(t){return{status:new He,ctx:{common:t.parent.common,data:t.data,parsedType:Qt(t.data),schemaErrorMap:this._def.errorMap,path:t.path,parent:t.parent}}}_parseSync(t){const n=this._parse(t);if(Rs(n))throw new Error("Synchronous parse encountered promise.");return n}_parseAsync(t){const n=this._parse(t);return Promise.resolve(n)}parse(t,n){const r=this.safeParse(t,n);if(r.success)return r.data;throw r.error}safeParse(t,n){var r;const s={common:{issues:[],async:(r=n==null?void 0:n.async)!==null&&r!==void 0?r:!1,contextualErrorMap:n==null?void 0:n.errorMap},path:(n==null?void 0:n.path)||[],schemaErrorMap:this._def.errorMap,parent:null,data:t,parsedType:Qt(t)},o=this._parseSync({data:t,path:s.path,parent:s});return lc(s,o)}async parseAsync(t,n){const r=await this.safeParseAsync(t,n);if(r.success)return r.data;throw r.error}async safeParseAsync(t,n){const r={common:{issues:[],contextualErrorMap:n==null?void 0:n.errorMap,async:!0},path:(n==null?void 0:n.path)||[],schemaErrorMap:this._def.errorMap,parent:null,data:t,parsedType:Qt(t)},s=this._parse({data:t,path:r.path,parent:r}),o=await(Rs(s)?s:Promise.resolve(s));return lc(r,o)}refine(t,n){const r=s=>typeof n=="string"||typeof n>"u"?{message:n}:typeof n=="function"?n(s):n;return this._refinement((s,o)=>{const i=t(s),a=()=>o.addIssue({code:R.custom,...r(s)});return typeof Promise<"u"&&i instanceof Promise?i.then(c=>c?!0:(a(),!1)):i?!0:(a(),!1)})}refinement(t,n){return this._refinement((r,s)=>t(r)?!0:(s.addIssue(typeof n=="function"?n(r,s):n),!1))}_refinement(t){return new ft({schema:this,typeName:G.ZodEffects,effect:{type:"refinement",refinement:t}})}superRefine(t){return this._refinement(t)}optional(){return Pt.create(this,this._def)}nullable(){return Pn.create(this,this._def)}nullish(){return this.nullable().optional()}array(){return lt.create(this,this._def)}promise(){return sr.create(this,this._def)}or(t){return Ur.create([this,t],this._def)}and(t){return Nr.create(this,t,this._def)}transform(t){return new ft({...ee(this._def),schema:this,typeName:G.ZodEffects,effect:{type:"transform",transform:t}})}default(t){const n=typeof t=="function"?t:()=>t;return new Kr({...ee(this._def),innerType:this,defaultValue:n,typeName:G.ZodDefault})}brand(){return new Fl({typeName:G.ZodBranded,type:this,...ee(this._def)})}catch(t){const n=typeof t=="function"?t:()=>t;return new Ds({...ee(this._def),innerType:this,catchValue:n,typeName:G.ZodCatch})}describe(t){const n=this.constructor;return new n({...this._def,description:t})}pipe(t){return Gr.create(this,t)}isOptional(){return this.safeParse(void 0).success}isNullable(){return this.safeParse(null).success}}const Tb=/^c[^\s-]{8,}$/i,Ib=/^[a-z][a-z0-9]*$/,Ob=/[0-9A-HJKMNP-TV-Z]{26}/,Cb=/^([a-f0-9]{8}-[a-f0-9]{4}-[1-5][a-f0-9]{3}-[a-f0-9]{4}-[a-f0-9]{12}|00000000-0000-0000-0000-000000000000)$/i,Pb=/^(([^<>()[\]\\.,;:\s@\"]+(\.[^<>()[\]\\.,;:\s@\"]+)*)|(\".+\"))@((\[(((25[0-5])|(2[0-4][0-9])|(1[0-9]{2})|([0-9]{1,2}))\.){3}((25[0-5])|(2[0-4][0-9])|(1[0-9]{2})|([0-9]{1,2}))\])|(\[IPv6:(([a-f0-9]{1,4}:){7}|::([a-f0-9]{1,4}:){0,6}|([a-f0-9]{1,4}:){1}:([a-f0-9]{1,4}:){0,5}|([a-f0-9]{1,4}:){2}:([a-f0-9]{1,4}:){0,4}|([a-f0-9]{1,4}:){3}:([a-f0-9]{1,4}:){0,3}|([a-f0-9]{1,4}:){4}:([a-f0-9]{1,4}:){0,2}|([a-f0-9]{1,4}:){5}:([a-f0-9]{1,4}:){0,1})([a-f0-9]{1,4}|(((25[0-5])|(2[0-4][0-9])|(1[0-9]{2})|([0-9]{1,2}))\.){3}((25[0-5])|(2[0-4][0-9])|(1[0-9]{2})|([0-9]{1,2})))\])|([A-Za-z0-9]([A-Za-z0-9-]*[A-Za-z0-9])*(\.[A-Za-z]{2,})+))$/,Ub=new RegExp("^(\\p{Extended_Pictographic}|\\p{Emoji_Component})+$","u"),Nb=/^(((25[0-5])|(2[0-4][0-9])|(1[0-9]{2})|([0-9]{1,2}))\.){3}((25[0-5])|(2[0-4][0-9])|(1[0-9]{2})|([0-9]{1,2}))$/,Lb=/^(([a-f0-9]{1,4}:){7}|::([a-f0-9]{1,4}:){0,6}|([a-f0-9]{1,4}:){1}:([a-f0-9]{1,4}:){0,5}|([a-f0-9]{1,4}:){2}:([a-f0-9]{1,4}:){0,4}|([a-f0-9]{1,4}:){3}:([a-f0-9]{1,4}:){0,3}|([a-f0-9]{1,4}:){4}:([a-f0-9]{1,4}:){0,2}|([a-f0-9]{1,4}:){5}:([a-f0-9]{1,4}:){0,1})([a-f0-9]{1,4}|(((25[0-5])|(2[0-4][0-9])|(1[0-9]{2})|([0-9]{1,2}))\.){3}((25[0-5])|(2[0-4][0-9])|(1[0-9]{2})|([0-9]{1,2})))$/,Rb=e=>e.precision?e.offset?new RegExp(`^\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}\\.\\d{${e.precision}}(([+-]\\d{2}(:?\\d{2})?)|Z)$`):new RegExp(`^\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}\\.\\d{${e.precision}}Z$`):e.precision===0?e.offset?new RegExp("^\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}(([+-]\\d{2}(:?\\d{2})?)|Z)$"):new RegExp("^\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}Z$"):e.offset?new RegExp("^\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}(\\.\\d+)?(([+-]\\d{2}(:?\\d{2})?)|Z)$"):new RegExp("^\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}(\\.\\d+)?Z$");function Hb(e,t){return!!((t==="v4"||!t)&&Nb.test(e)||(t==="v6"||!t)&&Lb.test(e))}class it extends re{constructor(){super(...arguments),this._regex=(t,n,r)=>this.refinement(s=>t.test(s),{validation:n,code:R.invalid_string,...F.errToObj(r)}),this.nonempty=t=>this.min(1,F.errToObj(t)),this.trim=()=>new it({...this._def,checks:[...this._def.checks,{kind:"trim"}]}),this.toLowerCase=()=>new it({...this._def,checks:[...this._def.checks,{kind:"toLowerCase"}]}),this.toUpperCase=()=>new it({...this._def,checks:[...this._def.checks,{kind:"toUpperCase"}]})}_parse(t){if(this._def.coerce&&(t.data=String(t.data)),this._getType(t)!==Z.string){const o=this._getOrReturnCtx(t);return M(o,{code:R.invalid_type,expected:Z.string,received:o.parsedType}),Y}const r=new He;let s;for(const o of this._def.checks)if(o.kind==="min")t.data.lengtho.value&&(s=this._getOrReturnCtx(t,s),M(s,{code:R.too_big,maximum:o.value,type:"string",inclusive:!0,exact:!1,message:o.message}),r.dirty());else if(o.kind==="length"){const i=t.data.length>o.value,a=t.data.length"u"?null:t==null?void 0:t.precision,offset:(n=t==null?void 0:t.offset)!==null&&n!==void 0?n:!1,...F.errToObj(t==null?void 0:t.message)})}regex(t,n){return this._addCheck({kind:"regex",regex:t,...F.errToObj(n)})}includes(t,n){return this._addCheck({kind:"includes",value:t,position:n==null?void 0:n.position,...F.errToObj(n==null?void 0:n.message)})}startsWith(t,n){return this._addCheck({kind:"startsWith",value:t,...F.errToObj(n)})}endsWith(t,n){return this._addCheck({kind:"endsWith",value:t,...F.errToObj(n)})}min(t,n){return this._addCheck({kind:"min",value:t,...F.errToObj(n)})}max(t,n){return this._addCheck({kind:"max",value:t,...F.errToObj(n)})}length(t,n){return this._addCheck({kind:"length",value:t,...F.errToObj(n)})}get isDatetime(){return!!this._def.checks.find(t=>t.kind==="datetime")}get isEmail(){return!!this._def.checks.find(t=>t.kind==="email")}get isURL(){return!!this._def.checks.find(t=>t.kind==="url")}get isEmoji(){return!!this._def.checks.find(t=>t.kind==="emoji")}get isUUID(){return!!this._def.checks.find(t=>t.kind==="uuid")}get isCUID(){return!!this._def.checks.find(t=>t.kind==="cuid")}get isCUID2(){return!!this._def.checks.find(t=>t.kind==="cuid2")}get isULID(){return!!this._def.checks.find(t=>t.kind==="ulid")}get isIP(){return!!this._def.checks.find(t=>t.kind==="ip")}get minLength(){let t=null;for(const n of this._def.checks)n.kind==="min"&&(t===null||n.value>t)&&(t=n.value);return t}get maxLength(){let t=null;for(const n of this._def.checks)n.kind==="max"&&(t===null||n.value{var t;return new it({checks:[],typeName:G.ZodString,coerce:(t=e==null?void 0:e.coerce)!==null&&t!==void 0?t:!1,...ee(e)})};function jb(e,t){const n=(e.toString().split(".")[1]||"").length,r=(t.toString().split(".")[1]||"").length,s=n>r?n:r,o=parseInt(e.toFixed(s).replace(".","")),i=parseInt(t.toFixed(s).replace(".",""));return o%i/Math.pow(10,s)}class cn extends re{constructor(){super(...arguments),this.min=this.gte,this.max=this.lte,this.step=this.multipleOf}_parse(t){if(this._def.coerce&&(t.data=Number(t.data)),this._getType(t)!==Z.number){const o=this._getOrReturnCtx(t);return M(o,{code:R.invalid_type,expected:Z.number,received:o.parsedType}),Y}let r;const s=new He;for(const o of this._def.checks)o.kind==="int"?fe.isInteger(t.data)||(r=this._getOrReturnCtx(t,r),M(r,{code:R.invalid_type,expected:"integer",received:"float",message:o.message}),s.dirty()):o.kind==="min"?(o.inclusive?t.datao.value:t.data>=o.value)&&(r=this._getOrReturnCtx(t,r),M(r,{code:R.too_big,maximum:o.value,type:"number",inclusive:o.inclusive,exact:!1,message:o.message}),s.dirty()):o.kind==="multipleOf"?jb(t.data,o.value)!==0&&(r=this._getOrReturnCtx(t,r),M(r,{code:R.not_multiple_of,multipleOf:o.value,message:o.message}),s.dirty()):o.kind==="finite"?Number.isFinite(t.data)||(r=this._getOrReturnCtx(t,r),M(r,{code:R.not_finite,message:o.message}),s.dirty()):fe.assertNever(o);return{status:s.value,value:t.data}}gte(t,n){return this.setLimit("min",t,!0,F.toString(n))}gt(t,n){return this.setLimit("min",t,!1,F.toString(n))}lte(t,n){return this.setLimit("max",t,!0,F.toString(n))}lt(t,n){return this.setLimit("max",t,!1,F.toString(n))}setLimit(t,n,r,s){return new cn({...this._def,checks:[...this._def.checks,{kind:t,value:n,inclusive:r,message:F.toString(s)}]})}_addCheck(t){return new cn({...this._def,checks:[...this._def.checks,t]})}int(t){return this._addCheck({kind:"int",message:F.toString(t)})}positive(t){return this._addCheck({kind:"min",value:0,inclusive:!1,message:F.toString(t)})}negative(t){return this._addCheck({kind:"max",value:0,inclusive:!1,message:F.toString(t)})}nonpositive(t){return this._addCheck({kind:"max",value:0,inclusive:!0,message:F.toString(t)})}nonnegative(t){return this._addCheck({kind:"min",value:0,inclusive:!0,message:F.toString(t)})}multipleOf(t,n){return this._addCheck({kind:"multipleOf",value:t,message:F.toString(n)})}finite(t){return this._addCheck({kind:"finite",message:F.toString(t)})}safe(t){return this._addCheck({kind:"min",inclusive:!0,value:Number.MIN_SAFE_INTEGER,message:F.toString(t)})._addCheck({kind:"max",inclusive:!0,value:Number.MAX_SAFE_INTEGER,message:F.toString(t)})}get minValue(){let t=null;for(const n of this._def.checks)n.kind==="min"&&(t===null||n.value>t)&&(t=n.value);return t}get maxValue(){let t=null;for(const n of this._def.checks)n.kind==="max"&&(t===null||n.valuet.kind==="int"||t.kind==="multipleOf"&&fe.isInteger(t.value))}get isFinite(){let t=null,n=null;for(const r of this._def.checks){if(r.kind==="finite"||r.kind==="int"||r.kind==="multipleOf")return!0;r.kind==="min"?(n===null||r.value>n)&&(n=r.value):r.kind==="max"&&(t===null||r.valuenew cn({checks:[],typeName:G.ZodNumber,coerce:(e==null?void 0:e.coerce)||!1,...ee(e)});class un extends re{constructor(){super(...arguments),this.min=this.gte,this.max=this.lte}_parse(t){if(this._def.coerce&&(t.data=BigInt(t.data)),this._getType(t)!==Z.bigint){const o=this._getOrReturnCtx(t);return M(o,{code:R.invalid_type,expected:Z.bigint,received:o.parsedType}),Y}let r;const s=new He;for(const o of this._def.checks)o.kind==="min"?(o.inclusive?t.datao.value:t.data>=o.value)&&(r=this._getOrReturnCtx(t,r),M(r,{code:R.too_big,type:"bigint",maximum:o.value,inclusive:o.inclusive,message:o.message}),s.dirty()):o.kind==="multipleOf"?t.data%o.value!==BigInt(0)&&(r=this._getOrReturnCtx(t,r),M(r,{code:R.not_multiple_of,multipleOf:o.value,message:o.message}),s.dirty()):fe.assertNever(o);return{status:s.value,value:t.data}}gte(t,n){return this.setLimit("min",t,!0,F.toString(n))}gt(t,n){return this.setLimit("min",t,!1,F.toString(n))}lte(t,n){return this.setLimit("max",t,!0,F.toString(n))}lt(t,n){return this.setLimit("max",t,!1,F.toString(n))}setLimit(t,n,r,s){return new un({...this._def,checks:[...this._def.checks,{kind:t,value:n,inclusive:r,message:F.toString(s)}]})}_addCheck(t){return new un({...this._def,checks:[...this._def.checks,t]})}positive(t){return this._addCheck({kind:"min",value:BigInt(0),inclusive:!1,message:F.toString(t)})}negative(t){return this._addCheck({kind:"max",value:BigInt(0),inclusive:!1,message:F.toString(t)})}nonpositive(t){return this._addCheck({kind:"max",value:BigInt(0),inclusive:!0,message:F.toString(t)})}nonnegative(t){return this._addCheck({kind:"min",value:BigInt(0),inclusive:!0,message:F.toString(t)})}multipleOf(t,n){return this._addCheck({kind:"multipleOf",value:t,message:F.toString(n)})}get minValue(){let t=null;for(const n of this._def.checks)n.kind==="min"&&(t===null||n.value>t)&&(t=n.value);return t}get maxValue(){let t=null;for(const n of this._def.checks)n.kind==="max"&&(t===null||n.value{var t;return new un({checks:[],typeName:G.ZodBigInt,coerce:(t=e==null?void 0:e.coerce)!==null&&t!==void 0?t:!1,...ee(e)})};class Or extends re{_parse(t){if(this._def.coerce&&(t.data=!!t.data),this._getType(t)!==Z.boolean){const r=this._getOrReturnCtx(t);return M(r,{code:R.invalid_type,expected:Z.boolean,received:r.parsedType}),Y}return Ve(t.data)}}Or.create=e=>new Or({typeName:G.ZodBoolean,coerce:(e==null?void 0:e.coerce)||!1,...ee(e)});class On extends re{_parse(t){if(this._def.coerce&&(t.data=new Date(t.data)),this._getType(t)!==Z.date){const o=this._getOrReturnCtx(t);return M(o,{code:R.invalid_type,expected:Z.date,received:o.parsedType}),Y}if(isNaN(t.data.getTime())){const o=this._getOrReturnCtx(t);return M(o,{code:R.invalid_date}),Y}const r=new He;let s;for(const o of this._def.checks)o.kind==="min"?t.data.getTime()o.value&&(s=this._getOrReturnCtx(t,s),M(s,{code:R.too_big,message:o.message,inclusive:!0,exact:!1,maximum:o.value,type:"date"}),r.dirty()):fe.assertNever(o);return{status:r.value,value:new Date(t.data.getTime())}}_addCheck(t){return new On({...this._def,checks:[...this._def.checks,t]})}min(t,n){return this._addCheck({kind:"min",value:t.getTime(),message:F.toString(n)})}max(t,n){return this._addCheck({kind:"max",value:t.getTime(),message:F.toString(n)})}get minDate(){let t=null;for(const n of this._def.checks)n.kind==="min"&&(t===null||n.value>t)&&(t=n.value);return t!=null?new Date(t):null}get maxDate(){let t=null;for(const n of this._def.checks)n.kind==="max"&&(t===null||n.valuenew On({checks:[],coerce:(e==null?void 0:e.coerce)||!1,typeName:G.ZodDate,...ee(e)});class Hs extends re{_parse(t){if(this._getType(t)!==Z.symbol){const r=this._getOrReturnCtx(t);return M(r,{code:R.invalid_type,expected:Z.symbol,received:r.parsedType}),Y}return Ve(t.data)}}Hs.create=e=>new Hs({typeName:G.ZodSymbol,...ee(e)});class Cr extends re{_parse(t){if(this._getType(t)!==Z.undefined){const r=this._getOrReturnCtx(t);return M(r,{code:R.invalid_type,expected:Z.undefined,received:r.parsedType}),Y}return Ve(t.data)}}Cr.create=e=>new Cr({typeName:G.ZodUndefined,...ee(e)});class Pr extends re{_parse(t){if(this._getType(t)!==Z.null){const r=this._getOrReturnCtx(t);return M(r,{code:R.invalid_type,expected:Z.null,received:r.parsedType}),Y}return Ve(t.data)}}Pr.create=e=>new Pr({typeName:G.ZodNull,...ee(e)});class rr extends re{constructor(){super(...arguments),this._any=!0}_parse(t){return Ve(t.data)}}rr.create=e=>new rr({typeName:G.ZodAny,...ee(e)});class Bn extends re{constructor(){super(...arguments),this._unknown=!0}_parse(t){return Ve(t.data)}}Bn.create=e=>new Bn({typeName:G.ZodUnknown,...ee(e)});class Nt extends re{_parse(t){const n=this._getOrReturnCtx(t);return M(n,{code:R.invalid_type,expected:Z.never,received:n.parsedType}),Y}}Nt.create=e=>new Nt({typeName:G.ZodNever,...ee(e)});class js extends re{_parse(t){if(this._getType(t)!==Z.undefined){const r=this._getOrReturnCtx(t);return M(r,{code:R.invalid_type,expected:Z.void,received:r.parsedType}),Y}return Ve(t.data)}}js.create=e=>new js({typeName:G.ZodVoid,...ee(e)});class lt extends re{_parse(t){const{ctx:n,status:r}=this._processInputParams(t),s=this._def;if(n.parsedType!==Z.array)return M(n,{code:R.invalid_type,expected:Z.array,received:n.parsedType}),Y;if(s.exactLength!==null){const i=n.data.length>s.exactLength.value,a=n.data.lengths.maxLength.value&&(M(n,{code:R.too_big,maximum:s.maxLength.value,type:"array",inclusive:!0,exact:!1,message:s.maxLength.message}),r.dirty()),n.common.async)return Promise.all([...n.data].map((i,a)=>s.type._parseAsync(new vt(n,i,n.path,a)))).then(i=>He.mergeArray(r,i));const o=[...n.data].map((i,a)=>s.type._parseSync(new vt(n,i,n.path,a)));return He.mergeArray(r,o)}get element(){return this._def.type}min(t,n){return new lt({...this._def,minLength:{value:t,message:F.toString(n)}})}max(t,n){return new lt({...this._def,maxLength:{value:t,message:F.toString(n)}})}length(t,n){return new lt({...this._def,exactLength:{value:t,message:F.toString(n)}})}nonempty(t){return this.min(1,t)}}lt.create=(e,t)=>new lt({type:e,minLength:null,maxLength:null,exactLength:null,typeName:G.ZodArray,...ee(t)});function Fn(e){if(e instanceof Ee){const t={};for(const n in e.shape){const r=e.shape[n];t[n]=Pt.create(Fn(r))}return new Ee({...e._def,shape:()=>t})}else return e instanceof lt?new lt({...e._def,type:Fn(e.element)}):e instanceof Pt?Pt.create(Fn(e.unwrap())):e instanceof Pn?Pn.create(Fn(e.unwrap())):e instanceof Et?Et.create(e.items.map(t=>Fn(t))):e}class Ee extends re{constructor(){super(...arguments),this._cached=null,this.nonstrict=this.passthrough,this.augment=this.extend}_getCached(){if(this._cached!==null)return this._cached;const t=this._def.shape(),n=fe.objectKeys(t);return this._cached={shape:t,keys:n}}_parse(t){if(this._getType(t)!==Z.object){const u=this._getOrReturnCtx(t);return M(u,{code:R.invalid_type,expected:Z.object,received:u.parsedType}),Y}const{status:r,ctx:s}=this._processInputParams(t),{shape:o,keys:i}=this._getCached(),a=[];if(!(this._def.catchall instanceof Nt&&this._def.unknownKeys==="strip"))for(const u in s.data)i.includes(u)||a.push(u);const c=[];for(const u of i){const f=o[u],l=s.data[u];c.push({key:{status:"valid",value:u},value:f._parse(new vt(s,l,s.path,u)),alwaysSet:u in s.data})}if(this._def.catchall instanceof Nt){const u=this._def.unknownKeys;if(u==="passthrough")for(const f of a)c.push({key:{status:"valid",value:f},value:{status:"valid",value:s.data[f]}});else if(u==="strict")a.length>0&&(M(s,{code:R.unrecognized_keys,keys:a}),r.dirty());else if(u!=="strip")throw new Error("Internal ZodObject error: invalid unknownKeys value.")}else{const u=this._def.catchall;for(const f of a){const l=s.data[f];c.push({key:{status:"valid",value:f},value:u._parse(new vt(s,l,s.path,f)),alwaysSet:f in s.data})}}return s.common.async?Promise.resolve().then(async()=>{const u=[];for(const f of c){const l=await f.key;u.push({key:l,value:await f.value,alwaysSet:f.alwaysSet})}return u}).then(u=>He.mergeObjectSync(r,u)):He.mergeObjectSync(r,c)}get shape(){return this._def.shape()}strict(t){return new Ee({...this._def,unknownKeys:"strict",...t!==void 0?{errorMap:(n,r)=>{var s,o,i,a;const c=(i=(o=(s=this._def).errorMap)===null||o===void 0?void 0:o.call(s,n,r).message)!==null&&i!==void 0?i:r.defaultError;return n.code==="unrecognized_keys"?{message:(a=F.errToObj(t).message)!==null&&a!==void 0?a:c}:{message:c}}}:{}})}strip(){return new Ee({...this._def,unknownKeys:"strip"})}passthrough(){return new Ee({...this._def,unknownKeys:"passthrough"})}extend(t){return new Ee({...this._def,shape:()=>({...this._def.shape(),...t})})}merge(t){return new Ee({unknownKeys:t._def.unknownKeys,catchall:t._def.catchall,shape:()=>({...this._def.shape(),...t._def.shape()}),typeName:G.ZodObject})}setKey(t,n){return this.augment({[t]:n})}catchall(t){return new Ee({...this._def,catchall:t})}pick(t){const n={};return fe.objectKeys(t).forEach(r=>{t[r]&&this.shape[r]&&(n[r]=this.shape[r])}),new Ee({...this._def,shape:()=>n})}omit(t){const n={};return fe.objectKeys(this.shape).forEach(r=>{t[r]||(n[r]=this.shape[r])}),new Ee({...this._def,shape:()=>n})}deepPartial(){return Fn(this)}partial(t){const n={};return fe.objectKeys(this.shape).forEach(r=>{const s=this.shape[r];t&&!t[r]?n[r]=s:n[r]=s.optional()}),new Ee({...this._def,shape:()=>n})}required(t){const n={};return fe.objectKeys(this.shape).forEach(r=>{if(t&&!t[r])n[r]=this.shape[r];else{let o=this.shape[r];for(;o instanceof Pt;)o=o._def.innerType;n[r]=o}}),new Ee({...this._def,shape:()=>n})}keyof(){return zl(fe.objectKeys(this.shape))}}Ee.create=(e,t)=>new Ee({shape:()=>e,unknownKeys:"strip",catchall:Nt.create(),typeName:G.ZodObject,...ee(t)});Ee.strictCreate=(e,t)=>new Ee({shape:()=>e,unknownKeys:"strict",catchall:Nt.create(),typeName:G.ZodObject,...ee(t)});Ee.lazycreate=(e,t)=>new Ee({shape:e,unknownKeys:"strip",catchall:Nt.create(),typeName:G.ZodObject,...ee(t)});class Ur extends re{_parse(t){const{ctx:n}=this._processInputParams(t),r=this._def.options;function s(o){for(const a of o)if(a.result.status==="valid")return a.result;for(const a of o)if(a.result.status==="dirty")return n.common.issues.push(...a.ctx.common.issues),a.result;const i=o.map(a=>new ut(a.ctx.common.issues));return M(n,{code:R.invalid_union,unionErrors:i}),Y}if(n.common.async)return Promise.all(r.map(async o=>{const i={...n,common:{...n.common,issues:[]},parent:null};return{result:await o._parseAsync({data:n.data,path:n.path,parent:i}),ctx:i}})).then(s);{let o;const i=[];for(const c of r){const u={...n,common:{...n.common,issues:[]},parent:null},f=c._parseSync({data:n.data,path:n.path,parent:u});if(f.status==="valid")return f;f.status==="dirty"&&!o&&(o={result:f,ctx:u}),u.common.issues.length&&i.push(u.common.issues)}if(o)return n.common.issues.push(...o.ctx.common.issues),o.result;const a=i.map(c=>new ut(c));return M(n,{code:R.invalid_union,unionErrors:a}),Y}}get options(){return this._def.options}}Ur.create=(e,t)=>new Ur({options:e,typeName:G.ZodUnion,...ee(t)});const Es=e=>e instanceof Rr?Es(e.schema):e instanceof ft?Es(e.innerType()):e instanceof Hr?[e.value]:e instanceof ln?e.options:e instanceof jr?Object.keys(e.enum):e instanceof Kr?Es(e._def.innerType):e instanceof Cr?[void 0]:e instanceof Pr?[null]:null;class ho extends re{_parse(t){const{ctx:n}=this._processInputParams(t);if(n.parsedType!==Z.object)return M(n,{code:R.invalid_type,expected:Z.object,received:n.parsedType}),Y;const r=this.discriminator,s=n.data[r],o=this.optionsMap.get(s);return o?n.common.async?o._parseAsync({data:n.data,path:n.path,parent:n}):o._parseSync({data:n.data,path:n.path,parent:n}):(M(n,{code:R.invalid_union_discriminator,options:Array.from(this.optionsMap.keys()),path:[r]}),Y)}get discriminator(){return this._def.discriminator}get options(){return this._def.options}get optionsMap(){return this._def.optionsMap}static create(t,n,r){const s=new Map;for(const o of n){const i=Es(o.shape[t]);if(!i)throw new Error(`A discriminator value for key \`${t}\` could not be extracted from all schema options`);for(const a of i){if(s.has(a))throw new Error(`Discriminator property ${String(t)} has duplicate value ${String(a)}`);s.set(a,o)}}return new ho({typeName:G.ZodDiscriminatedUnion,discriminator:t,options:n,optionsMap:s,...ee(r)})}}function Si(e,t){const n=Qt(e),r=Qt(t);if(e===t)return{valid:!0,data:e};if(n===Z.object&&r===Z.object){const s=fe.objectKeys(t),o=fe.objectKeys(e).filter(a=>s.indexOf(a)!==-1),i={...e,...t};for(const a of o){const c=Si(e[a],t[a]);if(!c.valid)return{valid:!1};i[a]=c.data}return{valid:!0,data:i}}else if(n===Z.array&&r===Z.array){if(e.length!==t.length)return{valid:!1};const s=[];for(let o=0;o{if(vi(o)||vi(i))return Y;const a=Si(o.value,i.value);return a.valid?((Ei(o)||Ei(i))&&n.dirty(),{status:n.value,value:a.data}):(M(r,{code:R.invalid_intersection_types}),Y)};return r.common.async?Promise.all([this._def.left._parseAsync({data:r.data,path:r.path,parent:r}),this._def.right._parseAsync({data:r.data,path:r.path,parent:r})]).then(([o,i])=>s(o,i)):s(this._def.left._parseSync({data:r.data,path:r.path,parent:r}),this._def.right._parseSync({data:r.data,path:r.path,parent:r}))}}Nr.create=(e,t,n)=>new Nr({left:e,right:t,typeName:G.ZodIntersection,...ee(n)});class Et extends re{_parse(t){const{status:n,ctx:r}=this._processInputParams(t);if(r.parsedType!==Z.array)return M(r,{code:R.invalid_type,expected:Z.array,received:r.parsedType}),Y;if(r.data.lengththis._def.items.length&&(M(r,{code:R.too_big,maximum:this._def.items.length,inclusive:!0,exact:!1,type:"array"}),n.dirty());const o=[...r.data].map((i,a)=>{const c=this._def.items[a]||this._def.rest;return c?c._parse(new vt(r,i,r.path,a)):null}).filter(i=>!!i);return r.common.async?Promise.all(o).then(i=>He.mergeArray(n,i)):He.mergeArray(n,o)}get items(){return this._def.items}rest(t){return new Et({...this._def,rest:t})}}Et.create=(e,t)=>{if(!Array.isArray(e))throw new Error("You must pass an array of schemas to z.tuple([ ... ])");return new Et({items:e,typeName:G.ZodTuple,rest:null,...ee(t)})};class Lr extends re{get keySchema(){return this._def.keyType}get valueSchema(){return this._def.valueType}_parse(t){const{status:n,ctx:r}=this._processInputParams(t);if(r.parsedType!==Z.object)return M(r,{code:R.invalid_type,expected:Z.object,received:r.parsedType}),Y;const s=[],o=this._def.keyType,i=this._def.valueType;for(const a in r.data)s.push({key:o._parse(new vt(r,a,r.path,a)),value:i._parse(new vt(r,r.data[a],r.path,a))});return r.common.async?He.mergeObjectAsync(n,s):He.mergeObjectSync(n,s)}get element(){return this._def.valueType}static create(t,n,r){return n instanceof re?new Lr({keyType:t,valueType:n,typeName:G.ZodRecord,...ee(r)}):new Lr({keyType:it.create(),valueType:t,typeName:G.ZodRecord,...ee(n)})}}class Ks extends re{_parse(t){const{status:n,ctx:r}=this._processInputParams(t);if(r.parsedType!==Z.map)return M(r,{code:R.invalid_type,expected:Z.map,received:r.parsedType}),Y;const s=this._def.keyType,o=this._def.valueType,i=[...r.data.entries()].map(([a,c],u)=>({key:s._parse(new vt(r,a,r.path,[u,"key"])),value:o._parse(new vt(r,c,r.path,[u,"value"]))}));if(r.common.async){const a=new Map;return Promise.resolve().then(async()=>{for(const c of i){const u=await c.key,f=await c.value;if(u.status==="aborted"||f.status==="aborted")return Y;(u.status==="dirty"||f.status==="dirty")&&n.dirty(),a.set(u.value,f.value)}return{status:n.value,value:a}})}else{const a=new Map;for(const c of i){const u=c.key,f=c.value;if(u.status==="aborted"||f.status==="aborted")return Y;(u.status==="dirty"||f.status==="dirty")&&n.dirty(),a.set(u.value,f.value)}return{status:n.value,value:a}}}}Ks.create=(e,t,n)=>new Ks({valueType:t,keyType:e,typeName:G.ZodMap,...ee(n)});class Cn extends re{_parse(t){const{status:n,ctx:r}=this._processInputParams(t);if(r.parsedType!==Z.set)return M(r,{code:R.invalid_type,expected:Z.set,received:r.parsedType}),Y;const s=this._def;s.minSize!==null&&r.data.sizes.maxSize.value&&(M(r,{code:R.too_big,maximum:s.maxSize.value,type:"set",inclusive:!0,exact:!1,message:s.maxSize.message}),n.dirty());const o=this._def.valueType;function i(c){const u=new Set;for(const f of c){if(f.status==="aborted")return Y;f.status==="dirty"&&n.dirty(),u.add(f.value)}return{status:n.value,value:u}}const a=[...r.data.values()].map((c,u)=>o._parse(new vt(r,c,r.path,u)));return r.common.async?Promise.all(a).then(c=>i(c)):i(a)}min(t,n){return new Cn({...this._def,minSize:{value:t,message:F.toString(n)}})}max(t,n){return new Cn({...this._def,maxSize:{value:t,message:F.toString(n)}})}size(t,n){return this.min(t,n).max(t,n)}nonempty(t){return this.min(1,t)}}Cn.create=(e,t)=>new Cn({valueType:e,minSize:null,maxSize:null,typeName:G.ZodSet,...ee(t)});class Yn extends re{constructor(){super(...arguments),this.validate=this.implement}_parse(t){const{ctx:n}=this._processInputParams(t);if(n.parsedType!==Z.function)return M(n,{code:R.invalid_type,expected:Z.function,received:n.parsedType}),Y;function r(a,c){return Ns({data:a,path:n.path,errorMaps:[n.common.contextualErrorMap,n.schemaErrorMap,Us(),Ir].filter(u=>!!u),issueData:{code:R.invalid_arguments,argumentsError:c}})}function s(a,c){return Ns({data:a,path:n.path,errorMaps:[n.common.contextualErrorMap,n.schemaErrorMap,Us(),Ir].filter(u=>!!u),issueData:{code:R.invalid_return_type,returnTypeError:c}})}const o={errorMap:n.common.contextualErrorMap},i=n.data;return this._def.returns instanceof sr?Ve(async(...a)=>{const c=new ut([]),u=await this._def.args.parseAsync(a,o).catch(d=>{throw c.addIssue(r(a,d)),c}),f=await i(...u);return await this._def.returns._def.type.parseAsync(f,o).catch(d=>{throw c.addIssue(s(f,d)),c})}):Ve((...a)=>{const c=this._def.args.safeParse(a,o);if(!c.success)throw new ut([r(a,c.error)]);const u=i(...c.data),f=this._def.returns.safeParse(u,o);if(!f.success)throw new ut([s(u,f.error)]);return f.data})}parameters(){return this._def.args}returnType(){return this._def.returns}args(...t){return new Yn({...this._def,args:Et.create(t).rest(Bn.create())})}returns(t){return new Yn({...this._def,returns:t})}implement(t){return this.parse(t)}strictImplement(t){return this.parse(t)}static create(t,n,r){return new Yn({args:t||Et.create([]).rest(Bn.create()),returns:n||Bn.create(),typeName:G.ZodFunction,...ee(r)})}}class Rr extends re{get schema(){return this._def.getter()}_parse(t){const{ctx:n}=this._processInputParams(t);return this._def.getter()._parse({data:n.data,path:n.path,parent:n})}}Rr.create=(e,t)=>new Rr({getter:e,typeName:G.ZodLazy,...ee(t)});class Hr extends re{_parse(t){if(t.data!==this._def.value){const n=this._getOrReturnCtx(t);return M(n,{received:n.data,code:R.invalid_literal,expected:this._def.value}),Y}return{status:"valid",value:t.data}}get value(){return this._def.value}}Hr.create=(e,t)=>new Hr({value:e,typeName:G.ZodLiteral,...ee(t)});function zl(e,t){return new ln({values:e,typeName:G.ZodEnum,...ee(t)})}class ln extends re{_parse(t){if(typeof t.data!="string"){const n=this._getOrReturnCtx(t),r=this._def.values;return M(n,{expected:fe.joinValues(r),received:n.parsedType,code:R.invalid_type}),Y}if(this._def.values.indexOf(t.data)===-1){const n=this._getOrReturnCtx(t),r=this._def.values;return M(n,{received:n.data,code:R.invalid_enum_value,options:r}),Y}return Ve(t.data)}get options(){return this._def.values}get enum(){const t={};for(const n of this._def.values)t[n]=n;return t}get Values(){const t={};for(const n of this._def.values)t[n]=n;return t}get Enum(){const t={};for(const n of this._def.values)t[n]=n;return t}extract(t){return ln.create(t)}exclude(t){return ln.create(this.options.filter(n=>!t.includes(n)))}}ln.create=zl;class jr extends re{_parse(t){const n=fe.getValidEnumValues(this._def.values),r=this._getOrReturnCtx(t);if(r.parsedType!==Z.string&&r.parsedType!==Z.number){const s=fe.objectValues(n);return M(r,{expected:fe.joinValues(s),received:r.parsedType,code:R.invalid_type}),Y}if(n.indexOf(t.data)===-1){const s=fe.objectValues(n);return M(r,{received:r.data,code:R.invalid_enum_value,options:s}),Y}return Ve(t.data)}get enum(){return this._def.values}}jr.create=(e,t)=>new jr({values:e,typeName:G.ZodNativeEnum,...ee(t)});class sr extends re{unwrap(){return this._def.type}_parse(t){const{ctx:n}=this._processInputParams(t);if(n.parsedType!==Z.promise&&n.common.async===!1)return M(n,{code:R.invalid_type,expected:Z.promise,received:n.parsedType}),Y;const r=n.parsedType===Z.promise?n.data:Promise.resolve(n.data);return Ve(r.then(s=>this._def.type.parseAsync(s,{path:n.path,errorMap:n.common.contextualErrorMap})))}}sr.create=(e,t)=>new sr({type:e,typeName:G.ZodPromise,...ee(t)});class ft extends re{innerType(){return this._def.schema}sourceType(){return this._def.schema._def.typeName===G.ZodEffects?this._def.schema.sourceType():this._def.schema}_parse(t){const{status:n,ctx:r}=this._processInputParams(t),s=this._def.effect||null;if(s.type==="preprocess"){const i=s.transform(r.data);return r.common.async?Promise.resolve(i).then(a=>this._def.schema._parseAsync({data:a,path:r.path,parent:r})):this._def.schema._parseSync({data:i,path:r.path,parent:r})}const o={addIssue:i=>{M(r,i),i.fatal?n.abort():n.dirty()},get path(){return r.path}};if(o.addIssue=o.addIssue.bind(o),s.type==="refinement"){const i=a=>{const c=s.refinement(a,o);if(r.common.async)return Promise.resolve(c);if(c instanceof Promise)throw new Error("Async refinement encountered during synchronous parse operation. Use .parseAsync instead.");return a};if(r.common.async===!1){const a=this._def.schema._parseSync({data:r.data,path:r.path,parent:r});return a.status==="aborted"?Y:(a.status==="dirty"&&n.dirty(),i(a.value),{status:n.value,value:a.value})}else return this._def.schema._parseAsync({data:r.data,path:r.path,parent:r}).then(a=>a.status==="aborted"?Y:(a.status==="dirty"&&n.dirty(),i(a.value).then(()=>({status:n.value,value:a.value}))))}if(s.type==="transform")if(r.common.async===!1){const i=this._def.schema._parseSync({data:r.data,path:r.path,parent:r});if(!Ls(i))return i;const a=s.transform(i.value,o);if(a instanceof Promise)throw new Error("Asynchronous transform encountered during synchronous parse operation. Use .parseAsync instead.");return{status:n.value,value:a}}else return this._def.schema._parseAsync({data:r.data,path:r.path,parent:r}).then(i=>Ls(i)?Promise.resolve(s.transform(i.value,o)).then(a=>({status:n.value,value:a})):i);fe.assertNever(s)}}ft.create=(e,t,n)=>new ft({schema:e,typeName:G.ZodEffects,effect:t,...ee(n)});ft.createWithPreprocess=(e,t,n)=>new ft({schema:t,effect:{type:"preprocess",transform:e},typeName:G.ZodEffects,...ee(n)});class Pt extends re{_parse(t){return this._getType(t)===Z.undefined?Ve(void 0):this._def.innerType._parse(t)}unwrap(){return this._def.innerType}}Pt.create=(e,t)=>new Pt({innerType:e,typeName:G.ZodOptional,...ee(t)});class Pn extends re{_parse(t){return this._getType(t)===Z.null?Ve(null):this._def.innerType._parse(t)}unwrap(){return this._def.innerType}}Pn.create=(e,t)=>new Pn({innerType:e,typeName:G.ZodNullable,...ee(t)});class Kr extends re{_parse(t){const{ctx:n}=this._processInputParams(t);let r=n.data;return n.parsedType===Z.undefined&&(r=this._def.defaultValue()),this._def.innerType._parse({data:r,path:n.path,parent:n})}removeDefault(){return this._def.innerType}}Kr.create=(e,t)=>new Kr({innerType:e,typeName:G.ZodDefault,defaultValue:typeof t.default=="function"?t.default:()=>t.default,...ee(t)});class Ds extends re{_parse(t){const{ctx:n}=this._processInputParams(t),r={...n,common:{...n.common,issues:[]}},s=this._def.innerType._parse({data:r.data,path:r.path,parent:{...r}});return Rs(s)?s.then(o=>({status:"valid",value:o.status==="valid"?o.value:this._def.catchValue({get error(){return new ut(r.common.issues)},input:r.data})})):{status:"valid",value:s.status==="valid"?s.value:this._def.catchValue({get error(){return new ut(r.common.issues)},input:r.data})}}removeCatch(){return this._def.innerType}}Ds.create=(e,t)=>new Ds({innerType:e,typeName:G.ZodCatch,catchValue:typeof t.catch=="function"?t.catch:()=>t.catch,...ee(t)});class Zs extends re{_parse(t){if(this._getType(t)!==Z.nan){const r=this._getOrReturnCtx(t);return M(r,{code:R.invalid_type,expected:Z.nan,received:r.parsedType}),Y}return{status:"valid",value:t.data}}}Zs.create=e=>new Zs({typeName:G.ZodNaN,...ee(e)});const Kb=Symbol("zod_brand");class Fl extends re{_parse(t){const{ctx:n}=this._processInputParams(t),r=n.data;return this._def.type._parse({data:r,path:n.path,parent:n})}unwrap(){return this._def.type}}class Gr extends re{_parse(t){const{status:n,ctx:r}=this._processInputParams(t);if(r.common.async)return(async()=>{const o=await this._def.in._parseAsync({data:r.data,path:r.path,parent:r});return o.status==="aborted"?Y:o.status==="dirty"?(n.dirty(),ql(o.value)):this._def.out._parseAsync({data:o.value,path:r.path,parent:r})})();{const s=this._def.in._parseSync({data:r.data,path:r.path,parent:r});return s.status==="aborted"?Y:s.status==="dirty"?(n.dirty(),{status:"dirty",value:s.value}):this._def.out._parseSync({data:s.value,path:r.path,parent:r})}}static create(t,n){return new Gr({in:t,out:n,typeName:G.ZodPipeline})}}const Gl=(e,t={},n)=>e?rr.create().superRefine((r,s)=>{var o,i;if(!e(r)){const a=typeof t=="function"?t(r):typeof t=="string"?{message:t}:t,c=(i=(o=a.fatal)!==null&&o!==void 0?o:n)!==null&&i!==void 0?i:!0,u=typeof a=="string"?{message:a}:a;s.addIssue({code:"custom",...u,fatal:c})}}):rr.create(),Db={object:Ee.lazycreate};var G;(function(e){e.ZodString="ZodString",e.ZodNumber="ZodNumber",e.ZodNaN="ZodNaN",e.ZodBigInt="ZodBigInt",e.ZodBoolean="ZodBoolean",e.ZodDate="ZodDate",e.ZodSymbol="ZodSymbol",e.ZodUndefined="ZodUndefined",e.ZodNull="ZodNull",e.ZodAny="ZodAny",e.ZodUnknown="ZodUnknown",e.ZodNever="ZodNever",e.ZodVoid="ZodVoid",e.ZodArray="ZodArray",e.ZodObject="ZodObject",e.ZodUnion="ZodUnion",e.ZodDiscriminatedUnion="ZodDiscriminatedUnion",e.ZodIntersection="ZodIntersection",e.ZodTuple="ZodTuple",e.ZodRecord="ZodRecord",e.ZodMap="ZodMap",e.ZodSet="ZodSet",e.ZodFunction="ZodFunction",e.ZodLazy="ZodLazy",e.ZodLiteral="ZodLiteral",e.ZodEnum="ZodEnum",e.ZodEffects="ZodEffects",e.ZodNativeEnum="ZodNativeEnum",e.ZodOptional="ZodOptional",e.ZodNullable="ZodNullable",e.ZodDefault="ZodDefault",e.ZodCatch="ZodCatch",e.ZodPromise="ZodPromise",e.ZodBranded="ZodBranded",e.ZodPipeline="ZodPipeline"})(G||(G={}));const Zb=(e,t={message:`Input not instance of ${e.name}`})=>Gl(n=>n instanceof e,t),Wl=it.create,Yl=cn.create,Mb=Zs.create,Vb=un.create,Xl=Or.create,qb=On.create,zb=Hs.create,Fb=Cr.create,Gb=Pr.create,Wb=rr.create,Yb=Bn.create,Xb=Nt.create,Jb=js.create,Qb=lt.create,ew=Ee.create,tw=Ee.strictCreate,nw=Ur.create,rw=ho.create,sw=Nr.create,ow=Et.create,iw=Lr.create,aw=Ks.create,cw=Cn.create,uw=Yn.create,lw=Rr.create,fw=Hr.create,dw=ln.create,hw=jr.create,pw=sr.create,fc=ft.create,gw=Pt.create,mw=Pn.create,yw=ft.createWithPreprocess,bw=Gr.create,ww=()=>Wl().optional(),xw=()=>Yl().optional(),vw=()=>Xl().optional(),Ew={string:(e=>it.create({...e,coerce:!0})),number:(e=>cn.create({...e,coerce:!0})),boolean:(e=>Or.create({...e,coerce:!0})),bigint:(e=>un.create({...e,coerce:!0})),date:(e=>On.create({...e,coerce:!0}))},Sw=Y;var Me=Object.freeze({__proto__:null,defaultErrorMap:Ir,setErrorMap:Ab,getErrorMap:Us,makeIssue:Ns,EMPTY_PATH:Bb,addIssueToContext:M,ParseStatus:He,INVALID:Y,DIRTY:ql,OK:Ve,isAborted:vi,isDirty:Ei,isValid:Ls,isAsync:Rs,get util(){return fe},get objectUtil(){return xi},ZodParsedType:Z,getParsedType:Qt,ZodType:re,ZodString:it,ZodNumber:cn,ZodBigInt:un,ZodBoolean:Or,ZodDate:On,ZodSymbol:Hs,ZodUndefined:Cr,ZodNull:Pr,ZodAny:rr,ZodUnknown:Bn,ZodNever:Nt,ZodVoid:js,ZodArray:lt,ZodObject:Ee,ZodUnion:Ur,ZodDiscriminatedUnion:ho,ZodIntersection:Nr,ZodTuple:Et,ZodRecord:Lr,ZodMap:Ks,ZodSet:Cn,ZodFunction:Yn,ZodLazy:Rr,ZodLiteral:Hr,ZodEnum:ln,ZodNativeEnum:jr,ZodPromise:sr,ZodEffects:ft,ZodTransformer:ft,ZodOptional:Pt,ZodNullable:Pn,ZodDefault:Kr,ZodCatch:Ds,ZodNaN:Zs,BRAND:Kb,ZodBranded:Fl,ZodPipeline:Gr,custom:Gl,Schema:re,ZodSchema:re,late:Db,get ZodFirstPartyTypeKind(){return G},coerce:Ew,any:Wb,array:Qb,bigint:Vb,boolean:Xl,date:qb,discriminatedUnion:rw,effect:fc,enum:dw,function:uw,instanceof:Zb,intersection:sw,lazy:lw,literal:fw,map:aw,nan:Mb,nativeEnum:hw,never:Xb,null:Gb,nullable:mw,number:Yl,object:ew,oboolean:vw,onumber:xw,optional:gw,ostring:ww,pipeline:bw,preprocess:yw,promise:pw,record:iw,set:cw,strictObject:tw,string:Wl,symbol:zb,transformer:fc,tuple:ow,undefined:Fb,union:nw,unknown:Yb,void:Jb,NEVER:Sw,ZodIssueCode:R,quotelessJson:$b,ZodError:ut});const Jl=Me.string().regex(/^[a-fA-F0-9]$/),kw=Me.string().regex(/^[a-fA-F0-9]{64}$/),or=Me.number().min(0).max(4294967295),_w=Me.bigint(),Ql=Me.instanceof(Uint8Array),$w=Me.union([Jl,or,Me.string(),Ql]).array(),ba=Me.union([$w,Jl,Ql]),Aw=Me.array(ba),ef=Me.object({value:Me.union([or,_w]),scriptPubKey:ba}),Bw=Me.object({txid:kw,vout:or,scriptSig:ba,sequence:or,prevout:ef.optional(),witness:Aw});Me.object({version:or,vin:Me.array(Bw),vout:Me.array(ef),locktime:or});const ki=2048,Tw=new TextEncoder;function tf(e){const t=[],n=(s,o)=>{if(o<24)t.push(s*32+o);else if(o<=255)t.push(s*32+24,o);else if(o<=65535)t.push(s*32+25,o>>>8,o&255);else if(o<=4294967295){const i=new Uint8Array(4);new DataView(i.buffer).setUint32(0,o),t.push(s*32+26,...i)}else{t.push(s*32+27);const i=new Uint8Array(8);new DataView(i.buffer).setBigUint64(0,BigInt(o)),t.push(...i)}},r=(s,o=0)=>{if(o>64)throw new Error("Metadata nesting exceeds 64 levels.");if(s===null)t.push(246);else if(typeof s=="boolean")t.push(s?245:244);else if(typeof s=="number"&&Number.isFinite(s))if(Number.isSafeInteger(s)&&!Object.is(s,-0))n(s>=0?0:1,s>=0?s:-1-s);else{const i=new Uint8Array(8);new DataView(i.buffer).setFloat64(0,s),t.push(251,...i)}else if(typeof s=="string"){const i=Tw.encode(s);n(3,i.length);for(const a of i)t.push(a)}else if(Array.isArray(s))n(4,s.length),s.forEach(i=>r(i,o+1));else if(typeof s=="object"&&Object.getPrototypeOf(s)===Object.prototype){const i=Object.entries(s);n(5,i.length);for(const[a,c]of i)r(a,o+1),r(c,o+1)}else throw new Error("Metadata must contain only JSON values.");if(t.length>ki)throw new Error(`Metadata must be at most ${ki} CBOR bytes.`)};return r(e),Uint8Array.from(t)}function Iw(e){if(e=new Uint8Array(e),!e.length||e.length>ki)throw new Error("Invalid CBOR metadata size.");let t=0;const n=o=>{if(t+o>e.length)throw new Error("Truncated CBOR metadata.");const i=e.slice(t,t+o);return t+=o,i},r=(o=0)=>{if(o>64)throw new Error("Metadata nesting exceeds 64 levels.");const i=n(1)[0],a=i>>5,c=i&31;if(a===7){if(c===20)return!1;if(c===21)return!0;if(c===22)return null;if(c===27){const f=new DataView(n(8).buffer).getFloat64(0);if(Number.isFinite(f))return f}throw new Error("Unsupported CBOR value.")}let u=c;if(c>=24&&c<=27){u=0;for(const f of n(2**(c-24)))u=u*256+f}else if(c>=28)throw new Error("Unsupported CBOR length.");if(!Number.isSafeInteger(u))throw new Error("CBOR integer exceeds JSON precision.");if(a===0)return u;if(a===1)return-1-u;if(a===3)return new TextDecoder("utf-8",{fatal:!0}).decode(n(u));if((a===4||a===5)&&u>e.length)throw new Error("Invalid CBOR collection length.");if(a===4)return Array.from({length:u},()=>r(o+1));if(a===5){const f={};for(let l=0;l({txid:e,vout:t,sequence:4294967295,prevout:{value:n,scriptPubKey:r}}),De=(e,t)=>({value:e,scriptPubKey:t}),dc=16*1024,bt=1e3,he=500,Ms="text/plain;charset=utf-8",Ow=["text/plain","application/json","text/html","image/svg+xml","image/png","image/jpeg","image/webp"],nf=new TextEncoder,kr=e=>Array.from(e,t=>t.toString(16).padStart(2,"0")).join(""),yn=e=>Uint8Array.from(e.match(/../g)??[],t=>parseInt(t,16)),Vs=e=>kr(nf.encode(e));function wa(e){const t=typeof e=="string"?{contentType:Ms,bytes:nf.encode(e)}:e;if(!t||![...Ow,Ms].includes(t.contentType))throw new Error("Unsupported MIME type.");if(!(t.bytes instanceof Uint8Array)||!t.bytes.length)throw new Error("Enter non-empty inscription bytes.");if(t.bytes.length>dc)throw new Error(`Body must be at most ${dc} bytes.`);return{contentType:t.contentType,bytes:new Uint8Array(t.bytes)}}function qs(e){const t=/^([0-9a-f]{64})i(0|[1-9][0-9]*)$/.exec(e);if(!t||Number(t[2])>4294967295)throw new Error("Invalid parent inscription id.");let n=Number(t[2]),r="";for(;n;)r+=(n%256).toString(16).padStart(2,"0"),n=Math.floor(n/256);return t[1].match(/../g).reverse().join("")+r}function hc(e){if(typeof e!="string"||!/^[0-9a-f]{64,72}$/.test(e)||e.length%2)throw new Error("Invalid parent tag.");const t=[...yn(e.slice(64))].reduce((r,s,o)=>r+s*256**o,0),n=`${e.slice(0,64).match(/../g).reverse().join("")}i${t}`;if(qs(n)!==e)throw new Error("Non-canonical parent tag.");return n}function rf(e,t,n=null,r=void 0,s={}){const{contentType:o,bytes:i}=wa(t),{delegate:a=null,pointer:c,metaprotocol:u=null}=s,f=u==null||u===""?null:new TextEncoder().encode(String(u));if(f&&f.length>520)throw new Error("Metaprotocol identifier must be 520 bytes or less.");const l=r===void 0?void 0:tf(r),d=[];for(let m=0;m{const y=m.length/2;return(y<=75?y.toString(16).padStart(2,"0"):y<=255?"4c"+y.toString(16).padStart(2,"0"):"4d"+(y%256).toString(16).padStart(2,"0")+Math.floor(y/256).toString(16).padStart(2,"0"))+m};return h(e)+"ac0063"+h(Vs("ord"))+h("01")+h(Vs(o))+(a?h("0b")+h(qs(a)):"")+(c===void 0?"":h("02")+h(sf(c)))+(n?h("03")+h(qs(n)):"")+(l===void 0?"":Array.from({length:Math.ceil(l.length/520)},(m,y)=>h("05")+h(kr(l.slice(y*520,(y+1)*520)))).join(""))+(f?h("07")+h(kr(f)):"")+"00"+d.map(h).join("")+"68"}function xa(e){if(!Array.isArray(e)||e.length!==3)throw new Error("Unsupported script-path witness.");const t=Se.decode(e[1]);let n=7,r=null,s=null,o;t[n]==="0b"&&(s=hc(t[n+1]),n+=2),t[n]==="02"&&(o=Pw(t[n+1]==="OP_0"?"":t[n+1]),n+=2),t[n]==="03"&&(r=hc(t[n+1]),n+=2);const i=[];for(;t[n]==="05";){const m=t[n+1];if(typeof m!="string"||!/^(?:[0-9a-f]{2}){1,520}$/.test(m))throw new Error("Invalid metadata push.");i.push(m),n+=2}const a=i.length?Iw(yn(i.join(""))):void 0;let c=null;if(t[n]==="07"){const m=t[n+1];if(typeof m!="string"||!/^(?:[0-9a-f]{2}){1,520}$/.test(m))throw new Error("Invalid metaprotocol field.");c=new TextDecoder().decode(yn(m)),n+=2}if(t[n]!=="OP_0")throw new Error("Unsupported ord tag or missing body separator.");const u=t.slice(n+1,-1);if(!u.length||u.some(m=>typeof m!="string"||!/^(?:[0-9a-f]{2})+$/.test(m)))throw new Error("Invalid body envelope.");const f=new TextDecoder().decode(yn(t[6])),l=wa({contentType:f,bytes:yn(u.join(""))}),d=rf(t[0],l,r,a,{delegate:s,pointer:o,metaprotocol:c}),h=a===void 0&&!r&&f===Ms&&l.bytes.length<=280&&Se.encode([t[0],"OP_CHECKSIG","OP_0","OP_IF",Vs("ord"),"01",Vs(Ms),"OP_0",kr(l.bytes),"OP_ENDIF"],!1).hex;if(d!==e[1]&&h!==e[1])throw new Error("Unsupported ord envelope.");if(!/^[0-9a-f]{64}$/.test(t[0]))throw new Error("Invalid inscription signing key.");return{...l,parent:r,delegate:s,pointer:o,metaprotocol:c,metadata:a,metadataBytes:i.length?yn(i.join("")):void 0,text:new TextDecoder().decode(l.bytes),pubkey:t[0]}}class Cw{constructor(t,n){this.chain=t,this.wallet=n}prepare(t,n=null,r=void 0,s={}){const o=wa(t);if(r!==void 0&&tf(r),s.delegate&&qs(s.delegate),s.pointer!==void 0&&sf(s.pointer),s.metaprotocol!==void 0&&s.metaprotocol!==null&&s.metaprotocol!==""&&new TextEncoder().encode(String(s.metaprotocol)).length>520)throw new Error("Metaprotocol identifier must be 520 bytes or less.");if(n&&s.reinscribe)throw new Error("Choose parent or reinscription, not both.");const i=this.chain.coins(this.wallet.script),a=n?i.find(f=>{var l;return(l=f.inscriptions)==null?void 0:l.some(d=>d.id===n)}):null;if(n&&!a)throw new Error("Parent must be an owned, unspent inscription.");const c=s.reinscribe?i.find(f=>{var l;return(l=f.inscriptions)==null?void 0:l.some(d=>d.id===s.reinscribe)}):null;if(s.reinscribe&&!c)throw new Error("Reinscription must spend an owned sat.");const u=i.find(f=>!f.inscription&&f.value>=bt+2*he+330);if(!u)throw new Error("Mine a block first to get spendable fake BTC.");return{...o,coin:u,parent:a,reinscribe:c,totalFee:he*2,postage:bt}}inscribe(t,n=null,r=void 0,s={}){const{coin:o,parent:i,reinscribe:a,...c}=this.prepare(t,n,r,s),u=i??a,f=a==null?void 0:a.inscriptions.find(T=>T.id===s.reinscribe),l=f?this.chain.satLocation(f.sat).offset:s.pointer??(i?i.value:void 0),d=rf(this.wallet.pubkey,c,n,r,{...s,pointer:l}),h=Ps.encodeScript(d),[m,y]=Ps.getPubKey(this.wallet.pubkey,{target:h}),g=ce.create({vin:[nn(o.txid,o.vout,o.value,o.scriptPubKey)],vout:[De(bt+he,["OP_1",m]),De(o.value-bt-2*he,this.wallet.script)]});g.vin[0].witness=[this.wallet.sign(g)];const p=ce.util.getTxid(g),w=ce.create({vin:[...u?[nn(u.txid,u.vout,u.value,u.scriptPubKey)]:[],nn(p,0,bt+he,["OP_1",m])],vout:[...u?[De(u.value,this.wallet.script)]:[],De(bt,this.wallet.script)]}),b=u?1:0;return w.vin[b].witness=[this.wallet.sign(w,h,b),Se.encode(d,!1).hex,y],u&&(w.vin[0].witness=[this.wallet.sign(w)]),this.chain.submitPackage([ce.encode(g).hex,ce.encode(w).hex]),`${ce.util.getTxid(w)}i0`}list(){return this.chain.coins(this.wallet.script).flatMap(t=>t.inscriptions??[])}}function sf(e){let t;try{t=BigInt(e)}catch{throw new Error("Invalid pointer.")}if(t<0n||t>0xffffffffffffffffn||typeof e=="number"&&!Number.isSafeInteger(e))throw new Error("Invalid pointer.");let n="";for(;t;)n+=Number(t&255n).toString(16).padStart(2,"0"),t>>=8n;return n}function Pw(e){if(typeof e!="string"||!/^(?:[0-9a-f]{2}){0,8}$/.test(e))throw new Error("Invalid pointer tag.");return[...yn(e)].reduce((t,n,r)=>t+(BigInt(n)<{var p;const i=ce.decode(r),a=ce.util.getTxid(i),c=i.vin[0].txid==="0".repeat(64),u=c?[]:i.vin.map(w=>this.utxos.get(`${w.txid}:${w.vout}`)),f=Yc(i,u,s,c);i.vin.forEach(w=>this.utxos.delete(`${w.txid}:${w.vout}`)),i.vout.forEach((w,b)=>this.utxos.set(`${a}:${b}`,{txid:a,vout:b,value:Number(w.value),ranges:f[b]}));const l=(p=i.vin.find(w=>{var b;return((b=w.witness)==null?void 0:b.length)===3}))==null?void 0:p.witness;if(!l)return;const d=xa(l),h=BigInt(d.pointer??0),m=i.vout.reduce((w,b)=>w+Number(b.value),0),y=Wc(f.flat(),hw.sat===y).length,status:s===null?"pending":"confirmed",height:s,block:o,metadata:g??null,hasMetadata:g!==void 0,parent:d.parent,protocol:d.metaprotocol??(g&&!Array.isArray(g)&&typeof g=="object"&&Object.hasOwn(g,"protocol")&&typeof g.protocol=="string"?g.protocol:null)})};for(const r of t.blocks)for(const s of r.raws)n(s,r.height,r.hash);for(const r of t.mempool)n(r,null,null);for(const r of this.events){r.location=null;for(const s of this.utxos.values()){const o=xs(s.ranges,r.sat);if(o!==null){r.location={txid:s.txid,vout:s.vout,offset:o};break}}r.delegatedBy=this.events.filter(s=>s.delegate===r.id).map(s=>s.id),r.inscriptions=this.events.filter(s=>s.sat===r.sat).map(s=>s.id)}}forProtocol(t){return this.events.filter(n=>n.protocol===t)}get protocols(){return[...new Set(this.events.filter(t=>t.protocol!==null).map(t=>t.protocol))].sort()}get stats(){return{events:this.events.length,withMetadata:this.events.filter(t=>t.hasMetadata).length,confirmed:this.events.filter(t=>t.status==="confirmed").length,pending:this.events.filter(t=>t.status==="pending").length,protocols:this.protocols}}}const va="lineage/v0",Uw=["white","green","black"],pc="names are 1-40 lowercase letters, digits or hyphens (they become domains)",Nw=/^[a-z0-9](?:[a-z0-9-]{0,38}[a-z0-9])?$/,Ko=e=>typeof e=="string"&&Nw.test(e),Ss=(e,t)=>typeof e=="string"?e.trim().slice(0,t):"";function Ea(e){return String(e??"").toLowerCase().normalize("NFKD").replace(/[̀-ͯ]/g,"").replace(/[^a-z0-9]+/g,"-").replace(/^-+|-+$/g,"").slice(0,40).replace(/-+$/,"")}const Sa=e=>e.events.filter(t=>t.protocol===va);function Un(e,{upTo:t=1/0,pending:n=!1}={}){const r=new Map,s=[],o=[],i=a=>a.status==="active";for(const a of e){const c=a.status==="confirmed";if(c?a.height>t:!n)continue;const u=a.metadata&&typeof a.metadata=="object"&&!Array.isArray(a.metadata)?a.metadata:{},f={id:a.id,op:typeof u.op=="string"?u.op.slice(0,20):"?",beat:c?a.height:null,pending:!c,meta:u,parent:a.parent??null,ok:!0,why:"",node:null,root:null,also:[]},l=f.parent?r.get(f.parent):null,d=f.beat??"cued",h=g=>{f.ok=!1,f.why=g},m=g=>l?i(l)?"":`the ${g} is ${l.status}`:`the ${g} is not in this lineage`;let y="";switch(f.op){case"found":if(f.parent)h("a holding has no parent");else if(!Ko(u.name))h(pc);else if(s.some(g=>i(g)&&g.name===u.name))h(`an active holding is already named ${u.name}`);else{const g=gc(a,u.name,null,"holding");r.set(g.id,g),s.push(g),f.node=g.id}break;case"birth":{const g=u.kind==="agent"?"agent":"org";if(y=m("parent"))h(y);else if(l.kind==="agent")h("agents do not give birth");else if(!Ko(u.name))h(pc);else if(l.children.some(p=>i(r.get(p))&&r.get(p).name===u.name))h(`${l.name} already has an active ${u.name}`);else{const p=gc(a,u.name,l,g);p.index=l.children.filter(w=>r.get(w).kind===g).length,l.children.push(p.id),r.set(p.id,p),f.node=p.id}break}case"award":{const g=r.get(u.to);(y=m("issuer"))?h(y):l.kind==="agent"?h("agents do not award belts"):!g||g.root!==l.root||g.id===l.id?h("the recipient must be another node in this holding"):i(g)?!Ko(u.skill)||!Uw.includes(u.belt)?h("an award needs a skill name and a belt (white, green or black)"):(g.badges=g.badges.filter(p=>p.skill!==u.skill),g.badges.push({skill:u.skill,belt:u.belt,by:l.id,beat:d,id:a.id}),f.node=g.id):h(`the recipient is ${g.status}`);break}case"decide":(y=m("decider"))?h(y):Ss(u.title,140)?(l.decisions.push({title:Ss(u.title,140),why:Ss(u.why,400),beat:d,id:a.id}),f.node=l.id):h("a decision needs a title");break;case"graduate":{const g=r.get(u.of);(y=m("parent"))?h(y):!g||g.parent!==l.id?h("only its parent can graduate a child"):g.kind!=="org"?h("only orgs graduate"):i(g)?g.edge==="adopted"?h("already graduated"):(g.edge="adopted",g.graduated=d,f.node=g.id):h(`the child is ${g.status}`);break}case"close":if(!l)h(f.parent?"that node is not in this lineage":"a close spends the node it closes");else if(!i(l))h(`already ${l.status}`);else{const g=p=>{p.status="closed",p.closed=d;for(const w of p.children){const b=r.get(w);b.edge==="derived"&&i(b)&&(f.also.push(b.id),g(b))}};g(l),f.node=l.id}break;default:h("not a lineage/v0 op")}f.root=f.node?r.get(f.node).root:(l==null?void 0:l.root)??null,o.push(f)}return{nodes:r,roots:s,log:o}}function gc(e,t,n,r){return{id:e.id,name:t,kind:r,parent:(n==null?void 0:n.id)??null,root:n?n.root:e.id,edge:n?"derived":null,status:"active",index:null,born:e.status==="confirmed"?e.height:"cued",children:[],badges:[],decisions:[],graduated:null,closed:null}}function Lw(e,t){const n=[],r=e.nodes.get(t),s=(o,i,a)=>{n.push({type:"node",node:o,guide:i,path:o.parent?`${o.index}'`:"●"});const c=o.children.map(f=>e.nodes.get(f)),u=[["agents",c.filter(f=>f.kind==="agent")],["orgs",c.filter(f=>f.kind!=="agent")]].filter(([,f])=>f.length);u.forEach(([f,l],d)=>{const h=d===u.length-1,m=a+(h?" ":"│ ");n.push({type:"group",label:f,guide:a+(h?"└─ ":"├─ ")}),l.forEach((y,g)=>{const p=g===l.length-1;s(y,m+(p?"└─ ":"├─ "),m+(p?" ":"│ "))})})};return r&&s(r,"",""),n}function Rw(e,t){const n={orgs:0,agents:0,belts:0,decisions:0,closed:0};for(const r of e.nodes.values())r.root===t&&(r.id!==t&&(n[r.kind==="agent"?"agents":"orgs"]++,r.status==="closed"&&n.closed++),n.belts+=r.badges.length,n.decisions+=r.decisions.length);return n}function go(e,t){const n=[];for(let r=e.nodes.get(t);r;r=e.nodes.get(r.parent))n.unshift(r.name);return n.join(" / ")}function of(e,t){const n=e.meta,r=s=>{var o;return((o=t.nodes.get(s))==null?void 0:o.name)??(typeof s=="string"?`${s.slice(0,8)}…`:"?")};if(!e.ok)return`${e.op}: ${e.why}`;switch(e.op){case"found":return`found ${n.name}`;case"birth":return`birth ${n.name}${n.kind==="agent"?" (agent)":""} ← ${r(e.parent)}`;case"award":return`award ${n.skill} · ${n.belt} → ${r(n.to)}, from ${r(e.parent)}`;case"decide":return`decide “${Ss(n.title,140)}” · ${r(e.parent)}`;case"graduate":return`graduate ${r(n.of)} from ${r(e.parent)}`;case"close":return`close ${r(e.parent)}${e.also.length?` and ${e.also.length} derived`:""}`;default:return e.op}}const Mn=typeof globalThis=="object"&&"crypto"in globalThis?globalThis.crypto:void 0;/*! noble-hashes - MIT License (c) 2022 Paul Miller (paulmillr.com) */function Wr(e){return e instanceof Uint8Array||ArrayBuffer.isView(e)&&e.constructor.name==="Uint8Array"}function rn(e){if(!Number.isSafeInteger(e)||e<0)throw new Error("positive integer expected, got "+e)}function Ne(e,...t){if(!Wr(e))throw new Error("Uint8Array expected");if(t.length>0&&!t.includes(e.length))throw new Error("Uint8Array expected of length "+t+", got length="+e.length)}function Yr(e){if(typeof e!="function"||typeof e.create!="function")throw new Error("Hash should be wrapped by utils.createHasher");rn(e.outputLen),rn(e.blockLen)}function zs(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 Hw(e,t){Ne(e);const n=t.outputLen;if(e.length>>t}function as(e,t){return e<>>32-t>>>0}const af=typeof Uint8Array.from([]).toHex=="function"&&typeof Uint8Array.fromHex=="function",jw=Array.from({length:256},(e,t)=>t.toString(16).padStart(2,"0"));function Le(e){if(Ne(e),af)return e.toHex();let t="";for(let n=0;n=Bt._0&&e<=Bt._9)return e-Bt._0;if(e>=Bt.A&&e<=Bt.F)return e-(Bt.A-10);if(e>=Bt.a&&e<=Bt.f)return e-(Bt.a-10)}function dt(e){if(typeof e!="string")throw new Error("hex string expected, got "+typeof e);if(af)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 s=0,o=0;se().update(Dr(r)).digest(),n=e();return t.outputLen=n.outputLen,t.blockLen=n.blockLen,t.create=()=>e(),t}function Dn(e=32){if(Mn&&typeof Mn.getRandomValues=="function")return Mn.getRandomValues(new Uint8Array(e));if(Mn&&typeof Mn.randomBytes=="function")return Uint8Array.from(Mn.randomBytes(e));throw new Error("crypto.getRandomValues must be defined")}function Dw(e,t,n,r){if(typeof e.setBigUint64=="function")return e.setBigUint64(t,n,r);const s=BigInt(32),o=BigInt(4294967295),i=Number(n>>s&o),a=Number(n&o),c=r?4:0,u=r?0:4;e.setUint32(t+c,i,r),e.setUint32(t+u,a,r)}function Zw(e,t,n){return e&t^~e&n}function Mw(e,t,n){return e&t^e&n^t&n}class _a extends cf{constructor(t,n,r,s){super(),this.finished=!1,this.length=0,this.pos=0,this.destroyed=!1,this.blockLen=t,this.outputLen=n,this.padOffset=r,this.isLE=s,this.buffer=new Uint8Array(t),this.view=Tn(this.buffer)}update(t){zs(this),t=Dr(t),Ne(t);const{view:n,buffer:r,blockLen:s}=this,o=t.length;for(let i=0;is-i&&(this.process(r,0),i=0);for(let l=i;lf.length)throw new Error("_sha2: outputLen bigger than state");for(let l=0;l>bc&cs)}:{h:Number(e>>bc&cs)|0,l:Number(e&cs)|0}}function qw(e,t=!1){const n=e.length;let r=new Uint32Array(n),s=new Uint32Array(n);for(let o=0;oe>>>n,xc=(e,t,n)=>e<<32-n|t>>>n,Vn=(e,t,n)=>e>>>n|t<<32-n,qn=(e,t,n)=>e<<32-n|t>>>n,us=(e,t,n)=>e<<64-n|t>>>n-32,ls=(e,t,n)=>e>>>n-32|t<<64-n;function Tt(e,t,n,r){const s=(t>>>0)+(r>>>0);return{h:e+n+(s/2**32|0)|0,l:s|0}}const zw=(e,t,n)=>(e>>>0)+(t>>>0)+(n>>>0),Fw=(e,t,n,r)=>t+n+r+(e/2**32|0)|0,Gw=(e,t,n,r)=>(e>>>0)+(t>>>0)+(n>>>0)+(r>>>0),Ww=(e,t,n,r,s)=>t+n+r+s+(e/2**32|0)|0,Yw=(e,t,n,r,s)=>(e>>>0)+(t>>>0)+(n>>>0)+(r>>>0)+(s>>>0),Xw=(e,t,n,r,s,o)=>t+n+r+s+o+(e/2**32|0)|0,Jw=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]),Gt=new Uint32Array(64);class Qw extends _a{constructor(t=32){super(64,t,8,!1),this.A=Ft[0]|0,this.B=Ft[1]|0,this.C=Ft[2]|0,this.D=Ft[3]|0,this.E=Ft[4]|0,this.F=Ft[5]|0,this.G=Ft[6]|0,this.H=Ft[7]|0}get(){const{A:t,B:n,C:r,D:s,E:o,F:i,G:a,H:c}=this;return[t,n,r,s,o,i,a,c]}set(t,n,r,s,o,i,a,c){this.A=t|0,this.B=n|0,this.C=r|0,this.D=s|0,this.E=o|0,this.F=i|0,this.G=a|0,this.H=c|0}process(t,n){for(let l=0;l<16;l++,n+=4)Gt[l]=t.getUint32(n,!1);for(let l=16;l<64;l++){const d=Gt[l-15],h=Gt[l-2],m=yt(d,7)^yt(d,18)^d>>>3,y=yt(h,17)^yt(h,19)^h>>>10;Gt[l]=y+Gt[l-7]+m+Gt[l-16]|0}let{A:r,B:s,C:o,D:i,E:a,F:c,G:u,H:f}=this;for(let l=0;l<64;l++){const d=yt(a,6)^yt(a,11)^yt(a,25),h=f+d+Zw(a,c,u)+Jw[l]+Gt[l]|0,y=(yt(r,2)^yt(r,13)^yt(r,22))+Mw(r,s,o)|0;f=u,u=c,c=a,a=i+h|0,i=o,o=s,s=r,r=h+y|0}r=r+this.A|0,s=s+this.B|0,o=o+this.C|0,i=i+this.D|0,a=a+this.E|0,c=c+this.F|0,u=u+this.G|0,f=f+this.H|0,this.set(r,s,o,i,a,c,u,f)}roundClean(){St(Gt)}destroy(){this.set(0,0,0,0,0,0,0,0),St(this.buffer)}}const uf=qw(["0x428a2f98d728ae22","0x7137449123ef65cd","0xb5c0fbcfec4d3b2f","0xe9b5dba58189dbbc","0x3956c25bf348b538","0x59f111f1b605d019","0x923f82a4af194f9b","0xab1c5ed5da6d8118","0xd807aa98a3030242","0x12835b0145706fbe","0x243185be4ee4b28c","0x550c7dc3d5ffb4e2","0x72be5d74f27b896f","0x80deb1fe3b1696b1","0x9bdc06a725c71235","0xc19bf174cf692694","0xe49b69c19ef14ad2","0xefbe4786384f25e3","0x0fc19dc68b8cd5b5","0x240ca1cc77ac9c65","0x2de92c6f592b0275","0x4a7484aa6ea6e483","0x5cb0a9dcbd41fbd4","0x76f988da831153b5","0x983e5152ee66dfab","0xa831c66d2db43210","0xb00327c898fb213f","0xbf597fc7beef0ee4","0xc6e00bf33da88fc2","0xd5a79147930aa725","0x06ca6351e003826f","0x142929670a0e6e70","0x27b70a8546d22ffc","0x2e1b21385c26c926","0x4d2c6dfc5ac42aed","0x53380d139d95b3df","0x650a73548baf63de","0x766a0abb3c77b2a8","0x81c2c92e47edaee6","0x92722c851482353b","0xa2bfe8a14cf10364","0xa81a664bbc423001","0xc24b8b70d0f89791","0xc76c51a30654be30","0xd192e819d6ef5218","0xd69906245565a910","0xf40e35855771202a","0x106aa07032bbd1b8","0x19a4c116b8d2d0c8","0x1e376c085141ab53","0x2748774cdf8eeb99","0x34b0bcb5e19b48a8","0x391c0cb3c5c95a63","0x4ed8aa4ae3418acb","0x5b9cca4f7763e373","0x682e6ff3d6b2b8a3","0x748f82ee5defb2fc","0x78a5636f43172f60","0x84c87814a1f0ab72","0x8cc702081a6439ec","0x90befffa23631e28","0xa4506cebde82bde9","0xbef9a3f7b2c67915","0xc67178f2e372532b","0xca273eceea26619c","0xd186b8c721c0c207","0xeada7dd6cde0eb1e","0xf57d4f7fee6ed178","0x06f067aa72176fba","0x0a637dc5a2c898a6","0x113f9804bef90dae","0x1b710b35131c471b","0x28db77f523047d84","0x32caab7b40c72493","0x3c9ebe0a15c9bebc","0x431d67c49c100d4c","0x4cc5d4becb3e42b6","0x597f299cfc657e2a","0x5fcb6fab3ad6faec","0x6c44198c4a475817"].map(e=>BigInt(e))),e1=uf[0],t1=uf[1],Wt=new Uint32Array(80),Yt=new Uint32Array(80);class n1 extends _a{constructor(t=64){super(128,t,16,!1),this.Ah=Ce[0]|0,this.Al=Ce[1]|0,this.Bh=Ce[2]|0,this.Bl=Ce[3]|0,this.Ch=Ce[4]|0,this.Cl=Ce[5]|0,this.Dh=Ce[6]|0,this.Dl=Ce[7]|0,this.Eh=Ce[8]|0,this.El=Ce[9]|0,this.Fh=Ce[10]|0,this.Fl=Ce[11]|0,this.Gh=Ce[12]|0,this.Gl=Ce[13]|0,this.Hh=Ce[14]|0,this.Hl=Ce[15]|0}get(){const{Ah:t,Al:n,Bh:r,Bl:s,Ch:o,Cl:i,Dh:a,Dl:c,Eh:u,El:f,Fh:l,Fl:d,Gh:h,Gl:m,Hh:y,Hl:g}=this;return[t,n,r,s,o,i,a,c,u,f,l,d,h,m,y,g]}set(t,n,r,s,o,i,a,c,u,f,l,d,h,m,y,g){this.Ah=t|0,this.Al=n|0,this.Bh=r|0,this.Bl=s|0,this.Ch=o|0,this.Cl=i|0,this.Dh=a|0,this.Dl=c|0,this.Eh=u|0,this.El=f|0,this.Fh=l|0,this.Fl=d|0,this.Gh=h|0,this.Gl=m|0,this.Hh=y|0,this.Hl=g|0}process(t,n){for(let b=0;b<16;b++,n+=4)Wt[b]=t.getUint32(n),Yt[b]=t.getUint32(n+=4);for(let b=16;b<80;b++){const T=Wt[b-15]|0,A=Yt[b-15]|0,O=Vn(T,A,1)^Vn(T,A,8)^wc(T,A,7),U=qn(T,A,1)^qn(T,A,8)^xc(T,A,7),C=Wt[b-2]|0,_=Yt[b-2]|0,N=Vn(C,_,19)^us(C,_,61)^wc(C,_,6),H=qn(C,_,19)^ls(C,_,61)^xc(C,_,6),K=Gw(U,H,Yt[b-7],Yt[b-16]),v=Ww(K,O,N,Wt[b-7],Wt[b-16]);Wt[b]=v|0,Yt[b]=K|0}let{Ah:r,Al:s,Bh:o,Bl:i,Ch:a,Cl:c,Dh:u,Dl:f,Eh:l,El:d,Fh:h,Fl:m,Gh:y,Gl:g,Hh:p,Hl:w}=this;for(let b=0;b<80;b++){const T=Vn(l,d,14)^Vn(l,d,18)^us(l,d,41),A=qn(l,d,14)^qn(l,d,18)^ls(l,d,41),O=l&h^~l&y,U=d&m^~d&g,C=Yw(w,A,U,t1[b],Yt[b]),_=Xw(C,p,T,O,e1[b],Wt[b]),N=C|0,H=Vn(r,s,28)^us(r,s,34)^us(r,s,39),K=qn(r,s,28)^ls(r,s,34)^ls(r,s,39),v=r&o^r&a^o&a,S=s&i^s&c^i&c;p=y|0,w=g|0,y=h|0,g=m|0,h=l|0,m=d|0,{h:l,l:d}=Tt(u|0,f|0,_|0,N|0),u=a|0,f=c|0,a=o|0,c=i|0,o=r|0,i=s|0;const x=zw(N,K,S);r=Fw(x,_,H,v),s=x|0}({h:r,l:s}=Tt(this.Ah|0,this.Al|0,r|0,s|0)),{h:o,l:i}=Tt(this.Bh|0,this.Bl|0,o|0,i|0),{h:a,l:c}=Tt(this.Ch|0,this.Cl|0,a|0,c|0),{h:u,l:f}=Tt(this.Dh|0,this.Dl|0,u|0,f|0),{h:l,l:d}=Tt(this.Eh|0,this.El|0,l|0,d|0),{h,l:m}=Tt(this.Fh|0,this.Fl|0,h|0,m|0),{h:y,l:g}=Tt(this.Gh|0,this.Gl|0,y|0,g|0),{h:p,l:w}=Tt(this.Hh|0,this.Hl|0,p|0,w|0),this.set(r,s,o,i,a,c,u,f,l,d,h,m,y,g,p,w)}roundClean(){St(Wt,Yt)}destroy(){St(this.buffer),this.set(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0)}}const nt=ka(()=>new Qw),Zr=ka(()=>new n1),r1=Uint8Array.from([7,4,13,1,10,6,15,3,12,0,9,5,2,14,11,8]),lf=Uint8Array.from(new Array(16).fill(0).map((e,t)=>t)),s1=lf.map(e=>(9*e+5)%16),ff=(()=>{const n=[[lf],[s1]];for(let r=0;r<4;r++)for(let s of n)s.push(s[r].map(o=>r1[o]));return n})(),df=ff[0],hf=ff[1],pf=[[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)),o1=df.map((e,t)=>e.map(n=>pf[t][n])),i1=hf.map((e,t)=>e.map(n=>pf[t][n])),a1=Uint32Array.from([0,1518500249,1859775393,2400959708,2840853838]),c1=Uint32Array.from([1352829926,1548603684,1836072691,2053994217,0]);function vc(e,t,n,r){return e===0?t^n^r:e===1?t&n|~t&r:e===2?(t|~n)^r:e===3?t&r|n&~r:t^(n|~r)}const fs=new Uint32Array(16);class u1 extends _a{constructor(){super(64,20,8,!0),this.h0=1732584193,this.h1=-271733879,this.h2=-1732584194,this.h3=271733878,this.h4=-1009589776}get(){const{h0:t,h1:n,h2:r,h3:s,h4:o}=this;return[t,n,r,s,o]}set(t,n,r,s,o){this.h0=t|0,this.h1=n|0,this.h2=r|0,this.h3=s|0,this.h4=o|0}process(t,n){for(let h=0;h<16;h++,n+=4)fs[h]=t.getUint32(n,!0);let r=this.h0|0,s=r,o=this.h1|0,i=o,a=this.h2|0,c=a,u=this.h3|0,f=u,l=this.h4|0,d=l;for(let h=0;h<5;h++){const m=4-h,y=a1[h],g=c1[h],p=df[h],w=hf[h],b=o1[h],T=i1[h];for(let A=0;A<16;A++){const O=as(r+vc(h,o,a,u)+fs[p[A]]+y,b[A])+l|0;r=l,l=u,u=as(a,10)|0,a=o,o=O}for(let A=0;A<16;A++){const O=as(s+vc(m,i,c,f)+fs[w[A]]+g,T[A])+d|0;s=d,d=f,f=as(c,10)|0,c=i,i=O}}this.set(this.h1+a+f|0,this.h2+u+d|0,this.h3+l+s|0,this.h4+r+i|0,this.h0+o+c|0)}roundClean(){St(fs)}destroy(){this.destroyed=!0,St(this.buffer),this.set(0,0,0,0,0)}}const gf=ka(()=>new u1);class mf extends cf{constructor(t,n){super(),this.finished=!1,this.destroyed=!1,Yr(t);const r=Dr(n);if(this.iHash=t.create(),typeof this.iHash.update!="function")throw new Error("Expected instance of class which extends utils.Hash");this.blockLen=this.iHash.blockLen,this.outputLen=this.iHash.outputLen;const s=this.blockLen,o=new Uint8Array(s);o.set(r.length>s?t.create().update(r).digest():r);for(let i=0;inew mf(e,t).update(n).digest();fn.create=(e,t)=>new mf(e,t);/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */const $a=BigInt(0),_i=BigInt(1);function Nn(e,t=""){if(typeof e!="boolean"){const n=t&&`"${t}"`;throw new Error(n+"expected boolean, got type="+typeof e)}return e}function at(e,t,n=""){const r=Wr(e),s=e==null?void 0:e.length,o=t!==void 0;if(!r||o&&s!==t){const i=n&&`"${n}" `,a=o?` of length ${t}`:"",c=r?`length=${s}`:`type=${typeof e}`;throw new Error(i+"expected Uint8Array"+a+", got "+c)}return e}function ds(e){const t=e.toString(16);return t.length&1?"0"+t:t}function yf(e){if(typeof e!="string")throw new Error("hex string expected, got "+typeof e);return e===""?$a:BigInt("0x"+e)}function dr(e){return yf(Le(e))}function Ln(e){return Ne(e),yf(Le(Uint8Array.from(e).reverse()))}function mo(e,t){return dt(e.toString(16).padStart(t*2,"0"))}function Aa(e,t){return mo(e,t).reverse()}function pe(e,t,n){let r;if(typeof t=="string")try{r=dt(t)}catch(o){throw new Error(e+" must be hex string or Uint8Array, cause: "+o)}else if(Wr(t))r=Uint8Array.from(t);else throw new Error(e+" must be hex string or Uint8Array");const s=r.length;if(typeof n=="number"&&s!==n)throw new Error(e+" of length "+n+" expected, got "+s);return r}function Ec(e){return Uint8Array.from(e)}const Do=e=>typeof e=="bigint"&&$a<=e;function $i(e,t,n){return Do(e)&&Do(t)&&Do(n)&&t<=e&&e$a;e>>=_i,t+=1);return t}const Xr=e=>(_i<new Uint8Array(h),s=h=>Uint8Array.of(h);let o=r(e),i=r(e),a=0;const c=()=>{o.fill(1),i.fill(0),a=0},u=(...h)=>n(i,o,...h),f=(h=r(0))=>{i=u(s(0),h),o=u(),h.length!==0&&(i=u(s(1),h),o=u())},l=()=>{if(a++>=1e3)throw new Error("drbg: tried 1000 values");let h=0;const m=[];for(;h{c(),f(h);let y;for(;!(y=m(l()));)f();return c(),y}}function hr(e,t,n={}){if(!e||typeof e!="object")throw new Error("expected valid options object");function r(s,o,i){const a=e[s];if(i&&a===void 0)return;const c=typeof a;if(c!==o||a===null)throw new Error(`param "${s}" is invalid: expected ${o}, got ${c}`)}Object.entries(t).forEach(([s,o])=>r(s,o,!1)),Object.entries(n).forEach(([s,o])=>r(s,o,!0))}function Fs(e){const t=new WeakMap;return(n,...r)=>{const s=t.get(n);if(s!==void 0)return s;const o=e(n,...r);return t.set(n,o),o}}/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */const Fe=BigInt(0),Oe=BigInt(1),Sn=BigInt(2),wf=BigInt(3),xf=BigInt(4),vf=BigInt(5),f1=BigInt(7),Ef=BigInt(8),d1=BigInt(9),Sf=BigInt(16);function we(e,t){const n=e%t;return n>=Fe?n:t+n}function ve(e,t,n){let r=e;for(;t-- >Fe;)r*=r,r%=n;return r}function Sc(e,t){if(e===Fe)throw new Error("invert: expected non-zero number");if(t<=Fe)throw new Error("invert: expected positive modulus, got "+t);let n=we(e,t),r=t,s=Fe,o=Oe;for(;n!==Fe;){const a=r/n,c=r%n,u=s-o*a;r=n,n=c,s=o,o=u}if(r!==Oe)throw new Error("invert: does not exist");return we(s,t)}function Ba(e,t,n){if(!e.eql(e.sqr(t),n))throw new Error("Cannot find square root")}function kf(e,t){const n=(e.ORDER+Oe)/xf,r=e.pow(t,n);return Ba(e,r,t),r}function h1(e,t){const n=(e.ORDER-vf)/Ef,r=e.mul(t,Sn),s=e.pow(r,n),o=e.mul(t,s),i=e.mul(e.mul(o,Sn),s),a=e.mul(o,e.sub(i,e.ONE));return Ba(e,a,t),a}function p1(e){const t=Zn(e),n=_f(e),r=n(t,t.neg(t.ONE)),s=n(t,r),o=n(t,t.neg(r)),i=(e+f1)/Sf;return(a,c)=>{let u=a.pow(c,i),f=a.mul(u,r);const l=a.mul(u,s),d=a.mul(u,o),h=a.eql(a.sqr(f),c),m=a.eql(a.sqr(l),c);u=a.cmov(u,f,h),f=a.cmov(d,l,m);const y=a.eql(a.sqr(f),c),g=a.cmov(u,f,y);return Ba(a,g,c),g}}function _f(e){if(e1e3)throw new Error("Cannot find square root: probably non-prime P");if(n===1)return kf;let o=s.pow(r,t);const i=(t+Oe)/Sn;return function(c,u){if(c.is0(u))return u;if(kc(c,u)!==1)throw new Error("Cannot find square root");let f=n,l=c.mul(c.ONE,o),d=c.pow(u,t),h=c.pow(u,i);for(;!c.eql(d,c.ONE);){if(c.is0(d))return c.ZERO;let m=1,y=c.sqr(d);for(;!c.eql(y,c.ONE);)if(m++,y=c.sqr(y),m===f)throw new Error("Cannot find square root");const g=Oe<(we(e,t)&Oe)===Oe,y1=["create","isValid","is0","neg","inv","sqrt","sqr","eql","add","sub","mul","pow","div","addN","subN","mulN","sqrN"];function b1(e){const t={ORDER:"bigint",MASK:"bigint",BYTES:"number",BITS:"number"},n=y1.reduce((r,s)=>(r[s]="function",r),t);return hr(e,n),e}function w1(e,t,n){if(nFe;)n&Oe&&(r=e.mul(r,s)),s=e.sqr(s),n>>=Oe;return r}function $f(e,t,n=!1){const r=new Array(t.length).fill(n?e.ZERO:void 0),s=t.reduce((i,a,c)=>e.is0(a)?i:(r[c]=i,e.mul(i,a)),e.ONE),o=e.inv(s);return t.reduceRight((i,a,c)=>e.is0(a)?i:(r[c]=e.mul(i,r[c]),e.mul(i,a)),o),r}function kc(e,t){const n=(e.ORDER-Oe)/Sn,r=e.pow(t,n),s=e.eql(r,e.ONE),o=e.eql(r,e.ZERO),i=e.eql(r,e.neg(e.ONE));if(!s&&!o&&!i)throw new Error("invalid Legendre symbol result");return s?1:o?0:-1}function Af(e,t){t!==void 0&&rn(t);const n=t!==void 0?t:e.toString(2).length,r=Math.ceil(n/8);return{nBitLength:n,nByteLength:r}}function Zn(e,t,n=!1,r={}){if(e<=Fe)throw new Error("invalid field: expected ORDER > 0, got "+e);let s,o,i=!1,a;if(typeof t=="object"&&t!=null){if(r.sqrt||n)throw new Error("cannot specify opts in two arguments");const d=t;d.BITS&&(s=d.BITS),d.sqrt&&(o=d.sqrt),typeof d.isLE=="boolean"&&(n=d.isLE),typeof d.modFromBytes=="boolean"&&(i=d.modFromBytes),a=d.allowedLengths}else typeof t=="number"&&(s=t),r.sqrt&&(o=r.sqrt);const{nBitLength:c,nByteLength:u}=Af(e,s);if(u>2048)throw new Error("invalid field: expected ORDER of <= 2048 bytes");let f;const l=Object.freeze({ORDER:e,isLE:n,BITS:c,BYTES:u,MASK:Xr(c),ZERO:Fe,ONE:Oe,allowedLengths:a,create:d=>we(d,e),isValid:d=>{if(typeof d!="bigint")throw new Error("invalid field element: expected bigint, got "+typeof d);return Fe<=d&&dd===Fe,isValidNot0:d=>!l.is0(d)&&l.isValid(d),isOdd:d=>(d&Oe)===Oe,neg:d=>we(-d,e),eql:(d,h)=>d===h,sqr:d=>we(d*d,e),add:(d,h)=>we(d+h,e),sub:(d,h)=>we(d-h,e),mul:(d,h)=>we(d*h,e),pow:(d,h)=>w1(l,d,h),div:(d,h)=>we(d*Sc(h,e),e),sqrN:d=>d*d,addN:(d,h)=>d+h,subN:(d,h)=>d-h,mulN:(d,h)=>d*h,inv:d=>Sc(d,e),sqrt:o||(d=>(f||(f=g1(e)),f(l,d))),toBytes:d=>n?Aa(d,u):mo(d,u),fromBytes:(d,h=!0)=>{if(a){if(!a.includes(d.length)||d.length>u)throw new Error("Field.fromBytes: expected "+a+" bytes, got "+d.length);const y=new Uint8Array(u);y.set(d,n?0:y.length-d.length),d=y}if(d.length!==u)throw new Error("Field.fromBytes: expected "+u+" bytes, got "+d.length);let m=n?Ln(d):dr(d);if(i&&(m=we(m,e)),!h&&!l.isValid(m))throw new Error("invalid field element: outside of range 0..ORDER");return m},invertBatch:d=>$f(l,d),cmov:(d,h,m)=>m?h:d});return Object.freeze(l)}function Bf(e){if(typeof e!="bigint")throw new Error("field order must be bigint");const t=e.toString(2).length;return Math.ceil(t/8)}function Tf(e){const t=Bf(e);return t+Math.ceil(t/2)}function If(e,t,n=!1){const r=e.length,s=Bf(t),o=Tf(t);if(r<16||r1024)throw new Error("expected "+o+"-1024 bytes of input, got "+r);const i=n?Ln(e):dr(e),a=we(i,t-Oe)+Oe;return n?Aa(a,s):mo(a,s)}/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */const ir=BigInt(0),kn=BigInt(1);function Gs(e,t){const n=t.negate();return e?n:t}function _n(e,t){const n=$f(e.Fp,t.map(r=>r.Z));return t.map((r,s)=>e.fromAffine(r.toAffine(n[s])))}function Of(e,t){if(!Number.isSafeInteger(e)||e<=0||e>t)throw new Error("invalid window size, expected [1.."+t+"], got W="+e)}function Zo(e,t){Of(e,t);const n=Math.ceil(t/e)+1,r=2**(e-1),s=2**e,o=Xr(e),i=BigInt(e);return{windows:n,windowSize:r,mask:o,maxNumber:s,shiftBy:i}}function _c(e,t,n){const{windowSize:r,mask:s,maxNumber:o,shiftBy:i}=n;let a=Number(e&s),c=e>>i;a>r&&(a-=o,c+=kn);const u=t*r,f=u+Math.abs(a)-1,l=a===0,d=a<0,h=t%2!==0;return{nextN:c,offset:f,isZero:l,isNeg:d,isNegF:h,offsetF:u}}function x1(e,t){if(!Array.isArray(e))throw new Error("array expected");e.forEach((n,r)=>{if(!(n instanceof t))throw new Error("invalid point at index "+r)})}function v1(e,t){if(!Array.isArray(e))throw new Error("array of scalars expected");e.forEach((n,r)=>{if(!t.isValid(n))throw new Error("invalid scalar at index "+r)})}const Mo=new WeakMap,Cf=new WeakMap;function Vo(e){return Cf.get(e)||1}function $c(e){if(e!==ir)throw new Error("invalid wNAF")}class Pf{constructor(t,n){this.BASE=t.BASE,this.ZERO=t.ZERO,this.Fn=t.Fn,this.bits=n}_unsafeLadder(t,n,r=this.ZERO){let s=t;for(;n>ir;)n&kn&&(r=r.add(s)),s=s.double(),n>>=kn;return r}precomputeWindow(t,n){const{windows:r,windowSize:s}=Zo(n,this.bits),o=[];let i=t,a=i;for(let c=0;cir||r>ir;)n&kn&&(o=o.add(s)),r&kn&&(i=i.add(s)),s=s.double(),n>>=kn,r>>=kn;return{p1:o,p2:i}}function Uf(e,t,n,r){x1(n,e),v1(r,t);const s=n.length,o=r.length;if(s!==o)throw new Error("arrays of points and scalars must have equal length");const i=e.ZERO,a=bf(BigInt(s));let c=1;a>12?c=a-3:a>4?c=a-2:a>0&&(c=2);const u=Xr(c),f=new Array(Number(u)+1).fill(i),l=Math.floor((t.BITS-1)/c)*c;let d=i;for(let h=l;h>=0;h-=c){f.fill(i);for(let y=0;y>BigInt(h)&u);f[p]=f[p].add(n[y])}let m=i;for(let y=f.length-1,g=i;y>0;y--)g=g.add(f[y]),m=m.add(g);if(d=d.add(m),h!==0)for(let y=0;yir))throw new Error(`CURVE.${c} must be positive bigint`)}const s=Ac(t.p,n.Fp,r),o=Ac(t.n,n.Fn,r),a=["Gx","Gy","a",e==="weierstrass"?"b":"d"];for(const c of a)if(!s.isValid(t[c]))throw new Error(`CURVE.${c} must be valid field element of CURVE.Fp`);return t=Object.freeze(Object.assign({},t)),{CURVE:t,Fp:s,Fn:o}}/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */const Bc=(e,t)=>(e+(e>=0?t:-t)/Lf)/t;function S1(e,t,n){const[[r,s],[o,i]]=t,a=Bc(i*e,n),c=Bc(-s*e,n);let u=e-a*r-c*o,f=-a*s-c*i;const l=u=h||f=h)throw new Error("splitScalar (endomorphism): failed, k="+e);return{k1neg:l,k1:u,k2neg:d,k2:f}}function Ai(e){if(!["compact","recovered","der"].includes(e))throw new Error('Signature format must be "compact", "recovered", or "der"');return e}function qo(e,t){const n={};for(let r of Object.keys(t))n[r]=e[r]===void 0?t[r]:e[r];return Nn(n.lowS,"lowS"),Nn(n.prehash,"prehash"),n.format!==void 0&&Ai(n.format),n}class k1 extends Error{constructor(t=""){super(t)}}const It={Err:k1,_tlv:{encode:(e,t)=>{const{Err:n}=It;if(e<0||e>256)throw new n("tlv.encode: wrong tag");if(t.length&1)throw new n("tlv.encode: unpadded data");const r=t.length/2,s=ds(r);if(s.length/2&128)throw new n("tlv.encode: long form length too big");const o=r>127?ds(s.length/2|128):"";return ds(e)+o+s+t},decode(e,t){const{Err:n}=It;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 s=t[r++],o=!!(s&128);let i=0;if(!o)i=s;else{const c=s&127;if(!c)throw new n("tlv.decode(long): indefinite length not supported");if(c>4)throw new n("tlv.decode(long): byte length is too big");const u=t.subarray(r,r+c);if(u.length!==c)throw new n("tlv.decode: length bytes not complete");if(u[0]===0)throw new n("tlv.decode(long): zero leftmost byte");for(const f of u)i=i<<8|f;if(r+=c,i<128)throw new n("tlv.decode(long): not minimal encoding")}const a=t.subarray(r,r+i);if(a.length!==i)throw new n("tlv.decode: wrong value length");return{v:a,l:t.subarray(r+i)}}},_int:{encode(e){const{Err:t}=It;if(e{const{X:S,Y:x,Z:k}=K;if(r.eql(k,r.ONE))return{x:S,y:x};const I=K.is0();v==null&&(v=I?r.ONE:r.inv(k));const L=r.mul(S,v),P=r.mul(x,v),j=r.mul(k,v);if(I)return{x:r.ZERO,y:r.ZERO};if(!r.eql(j,r.ONE))throw new Error("invZ was invalid");return{x:L,y:P}}),U=Fs(K=>{if(K.is0()){if(t.allowInfinityPoint&&!r.is0(K.Y))return;throw new Error("bad point: ZERO")}const{x:v,y:S}=K.toAffine();if(!r.isValid(v)||!r.isValid(S))throw new Error("bad point: x or y not field elements");if(!g(v,S))throw new Error("bad point: equation left != right");if(!K.isTorsionFree())throw new Error("bad point: not in prime-order subgroup");return!0});function C(K,v,S,x,k){return S=new _(r.mul(S.X,K),S.Y,S.Z),v=Gs(x,v),S=Gs(k,S),v.add(S)}class _{constructor(v,S,x){this.X=b("x",v),this.Y=b("y",S,!0),this.Z=b("z",x),Object.freeze(this)}static CURVE(){return o}static fromAffine(v){const{x:S,y:x}=v||{};if(!v||!r.isValid(S)||!r.isValid(x))throw new Error("invalid affine point");if(v instanceof _)throw new Error("projective point not allowed");return r.is0(S)&&r.is0(x)?_.ZERO:new _(S,x,r.ONE)}static fromBytes(v){const S=_.fromAffine(m(at(v,void 0,"point")));return S.assertValidity(),S}static fromHex(v){return _.fromBytes(pe("pointHex",v))}get x(){return this.toAffine().x}get y(){return this.toAffine().y}precompute(v=8,S=!0){return H.createCache(this,v),S||this.multiply(hs),this}assertValidity(){U(this)}hasEvenY(){const{y:v}=this.toAffine();if(!r.isOdd)throw new Error("Field doesn't support isOdd");return!r.isOdd(v)}equals(v){T(v);const{X:S,Y:x,Z:k}=this,{X:I,Y:L,Z:P}=v,j=r.eql(r.mul(S,P),r.mul(I,k)),D=r.eql(r.mul(x,P),r.mul(L,k));return j&&D}negate(){return new _(this.X,r.neg(this.Y),this.Z)}double(){const{a:v,b:S}=o,x=r.mul(S,hs),{X:k,Y:I,Z:L}=this;let P=r.ZERO,j=r.ZERO,D=r.ZERO,q=r.mul(k,k),ie=r.mul(I,I),oe=r.mul(L,L),X=r.mul(k,I);return X=r.add(X,X),D=r.mul(k,L),D=r.add(D,D),P=r.mul(v,D),j=r.mul(x,oe),j=r.add(P,j),P=r.sub(ie,j),j=r.add(ie,j),j=r.mul(P,j),P=r.mul(X,P),D=r.mul(x,D),oe=r.mul(v,oe),X=r.sub(q,oe),X=r.mul(v,X),X=r.add(X,D),D=r.add(q,q),q=r.add(D,q),q=r.add(q,oe),q=r.mul(q,X),j=r.add(j,q),oe=r.mul(I,L),oe=r.add(oe,oe),q=r.mul(oe,X),P=r.sub(P,q),D=r.mul(oe,ie),D=r.add(D,D),D=r.add(D,D),new _(P,j,D)}add(v){T(v);const{X:S,Y:x,Z:k}=this,{X:I,Y:L,Z:P}=v;let j=r.ZERO,D=r.ZERO,q=r.ZERO;const ie=o.a,oe=r.mul(o.b,hs);let X=r.mul(S,I),ue=r.mul(x,L),le=r.mul(k,P),ke=r.add(S,x),ae=r.add(I,L);ke=r.mul(ke,ae),ae=r.add(X,ue),ke=r.sub(ke,ae),ae=r.add(S,k);let me=r.add(I,P);return ae=r.mul(ae,me),me=r.add(X,le),ae=r.sub(ae,me),me=r.add(x,k),j=r.add(L,P),me=r.mul(me,j),j=r.add(ue,le),me=r.sub(me,j),q=r.mul(ie,ae),j=r.mul(oe,le),q=r.add(j,q),j=r.sub(ue,q),q=r.add(ue,q),D=r.mul(j,q),ue=r.add(X,X),ue=r.add(ue,X),le=r.mul(ie,le),ae=r.mul(oe,ae),ue=r.add(ue,le),le=r.sub(X,le),le=r.mul(ie,le),ae=r.add(ae,le),X=r.mul(ue,ae),D=r.add(D,X),X=r.mul(me,ae),j=r.mul(ke,j),j=r.sub(j,X),X=r.mul(ke,ue),q=r.mul(me,q),q=r.add(q,X),new _(j,D,q)}subtract(v){return this.add(v.negate())}is0(){return this.equals(_.ZERO)}multiply(v){const{endo:S}=t;if(!s.isValidNot0(v))throw new Error("invalid scalar: out of range");let x,k;const I=L=>H.cached(this,L,P=>_n(_,P));if(S){const{k1neg:L,k1:P,k2neg:j,k2:D}=A(v),{p:q,f:ie}=I(P),{p:oe,f:X}=I(D);k=ie.add(X),x=C(S.beta,q,oe,L,j)}else{const{p:L,f:P}=I(v);x=L,k=P}return _n(_,[x,k])[0]}multiplyUnsafe(v){const{endo:S}=t,x=this;if(!s.isValid(v))throw new Error("invalid scalar: out of range");if(v===Ot||x.is0())return _.ZERO;if(v===Xn)return x;if(H.hasCache(this))return this.multiply(v);if(S){const{k1neg:k,k1:I,k2neg:L,k2:P}=A(v),{p1:j,p2:D}=E1(_,x,I,P);return C(S.beta,j,D,k,L)}else return H.unsafe(x,v)}multiplyAndAddUnsafe(v,S,x){const k=this.multiplyUnsafe(S).add(v.multiplyUnsafe(x));return k.is0()?void 0:k}toAffine(v){return O(this,v)}isTorsionFree(){const{isTorsionFree:v}=t;return i===Xn?!0:v?v(_,this):H.unsafe(this,a).is0()}clearCofactor(){const{clearCofactor:v}=t;return i===Xn?this:v?v(_,this):this.multiplyUnsafe(i)}isSmallOrder(){return this.multiplyUnsafe(i).is0()}toBytes(v=!0){return Nn(v,"isCompressed"),this.assertValidity(),h(_,this,v)}toHex(v=!0){return Le(this.toBytes(v))}toString(){return``}get px(){return this.X}get py(){return this.X}get pz(){return this.Z}toRawBytes(v=!0){return this.toBytes(v)}_setWindowSize(v){this.precompute(v)}static normalizeZ(v){return _n(_,v)}static msm(v,S){return Uf(_,s,v,S)}static fromPrivateKey(v){return _.BASE.multiply($n(s,v))}}_.BASE=new _(o.Gx,o.Gy,r.ONE),_.ZERO=new _(r.ZERO,r.ONE,r.ZERO),_.Fp=r,_.Fn=s;const N=s.BITS,H=new Pf(_,t.endo?Math.ceil(N/2):N);return _.BASE.precompute(8),_}function Rf(e){return Uint8Array.of(e?2:3)}function Hf(e,t){return{secretKey:t.BYTES,publicKey:1+e.BYTES,publicKeyUncompressed:1+2*e.BYTES,publicKeyHasPrefix:!0,signature:2*t.BYTES}}function A1(e,t={}){const{Fn:n}=e,r=t.randomBytes||Dn,s=Object.assign(Hf(e.Fp,n),{seed:Tf(n.ORDER)});function o(h){try{return!!$n(n,h)}catch{return!1}}function i(h,m){const{publicKey:y,publicKeyUncompressed:g}=s;try{const p=h.length;return m===!0&&p!==y||m===!1&&p!==g?!1:!!e.fromBytes(h)}catch{return!1}}function a(h=r(s.seed)){return If(at(h,s.seed,"seed"),n.ORDER)}function c(h,m=!0){return e.BASE.multiply($n(n,h)).toBytes(m)}function u(h){const m=a(h);return{secretKey:m,publicKey:c(m)}}function f(h){if(typeof h=="bigint")return!1;if(h instanceof e)return!0;const{secretKey:m,publicKey:y,publicKeyUncompressed:g}=s;if(n.allowedLengths||m===y)return;const p=pe("key",h).length;return p===y||p===g}function l(h,m,y=!0){if(f(h)===!0)throw new Error("first arg must be private key");if(f(m)===!1)throw new Error("second arg must be public key");const g=$n(n,h);return e.fromHex(m).multiply(g).toBytes(y)}return Object.freeze({getPublicKey:c,getSharedSecret:l,keygen:u,Point:e,utils:{isValidSecretKey:o,isValidPublicKey:i,randomSecretKey:a,isValidPrivateKey:o,randomPrivateKey:a,normPrivateKeyToScalar:h=>$n(n,h),precompute(h=8,m=e.BASE){return m.precompute(h,!1)}},lengths:s})}function B1(e,t,n={}){Yr(t),hr(n,{},{hmac:"function",lowS:"boolean",randomBytes:"function",bits2int:"function",bits2int_modN:"function"});const r=n.randomBytes||Dn,s=n.hmac||((S,...x)=>fn(t,S,xe(...x))),{Fp:o,Fn:i}=e,{ORDER:a,BITS:c}=i,{keygen:u,getPublicKey:f,getSharedSecret:l,utils:d,lengths:h}=A1(e,n),m={prehash:!1,lowS:typeof n.lowS=="boolean"?n.lowS:!1,format:void 0,extraEntropy:!1},y="compact";function g(S){const x=a>>Xn;return S>x}function p(S,x){if(!i.isValidNot0(x))throw new Error(`invalid signature ${S}: out of range 1..Point.Fn.ORDER`);return x}function w(S,x){Ai(x);const k=h.signature,I=x==="compact"?k:x==="recovered"?k+1:void 0;return at(S,I,`${x} signature`)}class b{constructor(x,k,I){this.r=p("r",x),this.s=p("s",k),I!=null&&(this.recovery=I),Object.freeze(this)}static fromBytes(x,k=y){w(x,k);let I;if(k==="der"){const{r:D,s:q}=It.toSig(at(x));return new b(D,q)}k==="recovered"&&(I=x[0],k="compact",x=x.subarray(1));const L=i.BYTES,P=x.subarray(0,L),j=x.subarray(L,L*2);return new b(i.fromBytes(P),i.fromBytes(j),I)}static fromHex(x,k){return this.fromBytes(dt(x),k)}addRecoveryBit(x){return new b(this.r,this.s,x)}recoverPublicKey(x){const k=o.ORDER,{r:I,s:L,recovery:P}=this;if(P==null||![0,1,2,3].includes(P))throw new Error("recovery id invalid");if(a*Lf1)throw new Error("recovery id is ambiguous for h>1 curve");const D=P===2||P===3?I+a:I;if(!o.isValid(D))throw new Error("recovery id 2 or 3 invalid");const q=o.toBytes(D),ie=e.fromBytes(xe(Rf((P&1)===0),q)),oe=i.inv(D),X=A(pe("msgHash",x)),ue=i.create(-X*oe),le=i.create(L*oe),ke=e.BASE.multiplyUnsafe(ue).add(ie.multiplyUnsafe(le));if(ke.is0())throw new Error("point at infinify");return ke.assertValidity(),ke}hasHighS(){return g(this.s)}toBytes(x=y){if(Ai(x),x==="der")return dt(It.hexFromSig(this));const k=i.toBytes(this.r),I=i.toBytes(this.s);if(x==="recovered"){if(this.recovery==null)throw new Error("recovery bit must be present");return xe(Uint8Array.of(this.recovery),k,I)}return xe(k,I)}toHex(x){return Le(this.toBytes(x))}assertValidity(){}static fromCompact(x){return b.fromBytes(pe("sig",x),"compact")}static fromDER(x){return b.fromBytes(pe("sig",x),"der")}normalizeS(){return this.hasHighS()?new b(this.r,i.neg(this.s),this.recovery):this}toDERRawBytes(){return this.toBytes("der")}toDERHex(){return Le(this.toBytes("der"))}toCompactRawBytes(){return this.toBytes("compact")}toCompactHex(){return Le(this.toBytes("compact"))}}const T=n.bits2int||function(x){if(x.length>8192)throw new Error("input is too large");const k=dr(x),I=x.length*8-c;return I>0?k>>BigInt(I):k},A=n.bits2int_modN||function(x){return i.create(T(x))},O=Xr(c);function U(S){return Mr("num < 2^"+c,S,Ot,O),i.toBytes(S)}function C(S,x){return at(S,void 0,"message"),x?at(t(S),void 0,"prehashed message"):S}function _(S,x,k){if(["recovered","canonical"].some(ue=>ue in k))throw new Error("sign() legacy options not supported");const{lowS:I,prehash:L,extraEntropy:P}=qo(k,m);S=C(S,L);const j=A(S),D=$n(i,x),q=[U(D),U(j)];if(P!=null&&P!==!1){const ue=P===!0?r(h.secretKey):P;q.push(pe("extraEntropy",ue))}const ie=xe(...q),oe=j;function X(ue){const le=T(ue);if(!i.isValidNot0(le))return;const ke=i.inv(le),ae=e.BASE.multiply(le).toAffine(),me=i.create(ae.x);if(me===Ot)return;const _t=i.create(ke*i.create(oe+me*D));if(_t===Ot)return;let Xe=(ae.x===me?0:2)|Number(ae.y&Xn),Ie=_t;return I&&g(_t)&&(Ie=i.neg(_t),Xe^=1),new b(me,Ie,Xe)}return{seed:ie,k2sig:X}}function N(S,x,k={}){S=pe("message",S);const{seed:I,k2sig:L}=_(S,x,k);return l1(t.outputLen,i.BYTES,s)(I,L)}function H(S){let x;const k=typeof S=="string"||Wr(S),I=!k&&S!==null&&typeof S=="object"&&typeof S.r=="bigint"&&typeof S.s=="bigint";if(!k&&!I)throw new Error("invalid signature, expected Uint8Array, hex string or Signature instance");if(I)x=new b(S.r,S.s);else if(k){try{x=b.fromBytes(pe("sig",S),"der")}catch(L){if(!(L instanceof It.Err))throw L}if(!x)try{x=b.fromBytes(pe("sig",S),"compact")}catch{return!1}}return x||!1}function K(S,x,k,I={}){const{lowS:L,prehash:P,format:j}=qo(I,m);if(k=pe("publicKey",k),x=C(pe("message",x),P),"strict"in I)throw new Error("options.strict was renamed to lowS");const D=j===void 0?H(S):b.fromBytes(pe("sig",S),j);if(D===!1)return!1;try{const q=e.fromBytes(k);if(L&&D.hasHighS())return!1;const{r:ie,s:oe}=D,X=A(x),ue=i.inv(oe),le=i.create(X*ue),ke=i.create(ie*ue),ae=e.BASE.multiplyUnsafe(le).add(q.multiplyUnsafe(ke));return ae.is0()?!1:i.create(ae.x)===ie}catch{return!1}}function v(S,x,k={}){const{prehash:I}=qo(k,m);return x=C(x,I),b.fromBytes(S,"recovered").recoverPublicKey(x).toBytes()}return Object.freeze({keygen:u,getPublicKey:f,getSharedSecret:l,utils:d,lengths:h,Point:e,sign:N,verify:K,recoverPublicKey:v,Signature:b,hash:t})}function T1(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(i=>Math.ceil(i/2)))):void 0;const s=Zn(t.n,{BITS:e.nBitLength,allowedLengths:r,modFromBytes:e.wrapPrivateKey}),o={Fp:n,Fn:s,allowInfinityPoint:e.allowInfinityPoint,endo:e.endo,isTorsionFree:e.isTorsionFree,clearCofactor:e.clearCofactor,fromBytes:e.fromBytes,toBytes:e.toBytes};return{CURVE:t,curveOpts:o}}function I1(e){const{CURVE:t,curveOpts:n}=T1(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 O1(e,t){const n=t.Point;return Object.assign({},t,{ProjectivePoint:n,CURVE:Object.assign({},e,Af(n.Fn.ORDER,n.Fn.BITS))})}function C1(e){const{CURVE:t,curveOpts:n,hash:r,ecdsaOpts:s}=I1(e),o=$1(t,n),i=B1(o,r,s);return O1(e,i)}/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */function P1(e,t){const n=r=>C1({...e,hash:r});return{...n(t),create:n}}/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */const ar={p:BigInt("0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f"),n:BigInt("0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141"),h:BigInt(1),a:BigInt(0),b:BigInt(7),Gx:BigInt("0x79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798"),Gy:BigInt("0x483ada7726a3c4655da4fbfc0e1108a8fd17b448a68554199c47d08ffb10d4b8")},U1={beta:BigInt("0x7ae96a2b657c07106e64479eac3434e99cf0497512f58995c1396c28719501ee"),basises:[[BigInt("0x3086d221a7d46bcde86c90e49284eb15"),-BigInt("0xe4437ed6010e88286f547fa90abfe4c3")],[BigInt("0x114ca50f7a8e2f3f657c1108d9d44cfd8"),BigInt("0x3086d221a7d46bcde86c90e49284eb15")]]},N1=BigInt(0),Tc=BigInt(1),Bi=BigInt(2);function L1(e){const t=ar.p,n=BigInt(3),r=BigInt(6),s=BigInt(11),o=BigInt(22),i=BigInt(23),a=BigInt(44),c=BigInt(88),u=e*e*e%t,f=u*u*e%t,l=ve(f,n,t)*f%t,d=ve(l,n,t)*f%t,h=ve(d,Bi,t)*u%t,m=ve(h,s,t)*h%t,y=ve(m,o,t)*m%t,g=ve(y,a,t)*y%t,p=ve(g,c,t)*g%t,w=ve(p,a,t)*y%t,b=ve(w,n,t)*f%t,T=ve(b,i,t)*m%t,A=ve(T,r,t)*u%t,O=ve(A,Bi,t);if(!Ws.eql(Ws.sqr(O),e))throw new Error("Cannot find square root");return O}const Ws=Zn(ar.p,{sqrt:L1}),ze=P1({...ar,Fp:Ws,lowS:!0,endo:U1},nt),Ic={};function Ys(e,...t){let n=Ic[e];if(n===void 0){const r=nt(Ye(e));n=xe(r,r),Ic[e]=n}return nt(xe(n,...t))}const Ta=e=>e.toBytes(!0).slice(1),pr=ze.Point,Ia=e=>e%Bi===N1;function Ti(e){const{Fn:t,BASE:n}=pr,r=$n(t,e),s=n.multiply(r);return{scalar:Ia(s.y)?r:t.neg(r),bytes:Ta(s)}}function jf(e){const t=Ws;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 s=t.sqrt(r);Ia(s)||(s=t.neg(s));const o=pr.fromAffine({x:e,y:s});return o.assertValidity(),o}const _r=dr;function Kf(...e){return pr.Fn.create(_r(Ys("BIP0340/challenge",...e)))}function Oc(e){return Ti(e).bytes}function R1(e,t,n=Dn(32)){const{Fn:r}=pr,s=pe("message",e),{bytes:o,scalar:i}=Ti(t),a=pe("auxRand",n,32),c=r.toBytes(i^_r(Ys("BIP0340/aux",a))),u=Ys("BIP0340/nonce",c,o,s),{bytes:f,scalar:l}=Ti(u),d=Kf(f,o,s),h=new Uint8Array(64);if(h.set(f,0),h.set(r.toBytes(r.create(l+d*i)),32),!Df(h,s,o))throw new Error("sign: Invalid signature produced");return h}function Df(e,t,n){const{Fn:r,BASE:s}=pr,o=pe("signature",e,64),i=pe("message",t),a=pe("publicKey",n,32);try{const c=jf(_r(a)),u=_r(o.subarray(0,32));if(!$i(u,Tc,ar.p))return!1;const f=_r(o.subarray(32,64));if(!$i(f,Tc,ar.n))return!1;const l=Kf(r.toBytes(u),Ta(c),i),d=s.multiplyUnsafe(f).add(c.multiplyUnsafe(r.neg(l))),{x:h,y:m}=d.toAffine();return!(d.is0()||!Ia(m)||h!==u)}catch{return!1}}const Zf=(()=>{const n=(s=Dn(48))=>If(s,ar.n);ze.utils.randomSecretKey;function r(s){const o=n(s);return{secretKey:o,publicKey:Oc(o)}}return{keygen:r,getPublicKey:Oc,sign:R1,verify:Df,Point:pr,utils:{randomSecretKey:n,randomPrivateKey:n,taggedHash:Ys,lift_x:jf,pointToBytes:Ta,numberToBytesBE:mo,bytesToNumberBE:dr,mod:we},lengths:{secretKey:32,publicKey:32,publicKeyHasPrefix:!1,signature:64,seed:48}}})(),Xs=Le,H1=dt,en="super-testnet-local-v0";class dn{constructor(t){if(!/^[0-9a-f]{64}$/.test(t)||!ze.utils.isValidPrivateKey(t))throw new Error("Invalid test wallet key. Load a Super Testnet v0 backup.");this.kind="test-wallet",this.secret=t,this.pubkey=Xs(Zf.getPublicKey(t)),this.address=Tr.p2tr.fromPubKey(this.pubkey,"regtest"),this.script=["OP_1",this.pubkey]}static create(){return new dn(Xs(ze.utils.randomPrivateKey()))}static load(t){if((t==null?void 0:t.network)!==en||(t==null?void 0:t.version)!==1||(t==null?void 0:t.kind)!=="test-wallet")throw new Error("Only Super Testnet v0 test-wallet backups are accepted.");return new dn(t.secret)}backup(){return{kind:"test-wallet",version:1,network:en,secret:this.secret}}sign(t,n,r=0){return fo.taproot.sign(this.secret,t,r,n?{extension:n}:{}).hex}}const zo=50*1e8,ps="0".repeat(64),Cc=e=>Xs(nt(new TextEncoder().encode(JSON.stringify(e)))),gs=(e,t)=>`${e}:${t}`,qe=e=>Se.encode(e,!1).hex,de=(e,t)=>{if(!e)throw new Error(t)},j1=/^5120[0-9a-f]{64}$/,Fo=/^0014[0-9a-f]{40}$/,Mf=64,K1=e=>Xs(gf(nt(H1(e))));function D1(e,t){const[n,r]=e.vin[t].witness;return ze.verify(n.slice(0,-2),fo.segwit.hash(e,t,{pubkey:r,sigflag:1}),r,{lowS:!0,format:"der"})}class yo{constructor(t){if(this.blocks=[],this.mempool=[],this.utxos=new Map,this.transactions=new Map,t){de(t.network===en&&t.version===1,"Unsupported local chain version/network."),de(Array.isArray(t.blocks)&&Array.isArray(t.mempool),"Invalid chain snapshot.");for(const n of t.blocks)this.acceptBlock(structuredClone(n));this.submitPackage(t.mempool)}}snapshot(){return{network:en,version:1,blocks:structuredClone(this.blocks),mempool:[...this.mempool]}}coins(t){return[...this.utxos.values()].filter(n=>qe(n.scriptPubKey)===qe(t))}satLocation(t){for(const n of this.utxos.values()){const r=xs(n.ranges,t);if(r!==null)return{txid:n.txid,vout:n.vout,offset:r}}return null}balance(t){return this.coins(t).reduce((n,r)=>n+r.value,0)}apply(t,n,r=!1){var h,m,y;de(typeof t=="string"&&t.length<4e4&&/^(?:[a-f0-9]{2})+$/.test(t),"Invalid raw transaction.");const s=ce.decode(t),o=ce.util.getTxid(s);de(!this.transactions.has(o),"Duplicate transaction."),de(s.version===2&&s.locktime===0,"Unsupported transaction version or locktime."),de((s.vin.length===1||!r&&s.vin.length===2)&&s.vout.length>=1&&s.vout.length<=(r?Mf:2),"Unsupported transaction shape.");let i=0;for(const g of s.vout){const p=Number(g.value);de(Number.isSafeInteger(p)&&p>=330&&p<=zo,"Invalid output amount.");const w=qe(g.scriptPubKey);de(j1.test(w)||Fo.test(w),"Only Taproot and P2WPKH outputs are supported."),i+=p}let a,c=[];const u=s.vin.findIndex(g=>{var p;return((p=g.witness)==null?void 0:p.length)===3}),f=s.vin[u<0?0:u];if(r)de(f.txid===ps&&f.vout===4294967295&&i===zo,"Invalid local coinbase."),de(qe(f.scriptSig)===Se.encode([new TextEncoder().encode(`${en}:${n}`)],!1).hex,"Wrong coinbase height."),de(!((h=f.witness)!=null&&h.length),"Unexpected coinbase witness.");else{c=s.vin.map(p=>this.utxos.get(gs(p.txid,p.vout))),de(c.every(Boolean),"Input is missing or already spent."),de(new Set(s.vin.map(p=>gs(p.txid,p.vout))).size===s.vin.length,"Duplicate input."),s.vin.forEach((p,w)=>{var T,A,O;de(p.sequence==="ffffffff"&&qe(p.scriptSig)==="","Unsupported input flags."),p.prevout={value:c[w].value,scriptPubKey:c[w].scriptPubKey};const b=qe(c[w].scriptPubKey);if(Fo.test(b)){const[U,C]=p.witness??[];de(w!==u&&((T=p.witness)==null?void 0:T.length)===2,"Unsupported witness."),de(/^30[0-9a-f]{12,140}01$/.test(U)&&/^0[23][0-9a-f]{64}$/.test(C)&&K1(C)===b.slice(4),"P2WPKH spends need a SIGHASH_ALL signature by the key they pay.");return}de(((A=p.witness)==null?void 0:A.length)===1||w===u&&((O=p.witness)==null?void 0:O.length)===3,"Unsupported witness."),de(/^[0-9a-f]{128}$/.test(p.witness[0]),"Only default 64-byte Schnorr signatures are accepted.")}),de(c.reduce((p,w)=>p+w.value,0)-i===he,"v0 requires a fixed 500 sat fee per transaction.");let g={};if(f.witness.length===3){const p=xa(f.witness),w=u;if(de(Number(s.vout[w].value)===bt,"Invalid reveal postage."),de(qe(s.vout[w].scriptPubKey)===`5120${p.pubkey}`,"Reveal must return to its signing wallet."),p.parent){const b=u===0?1:0,T=c[b];de((m=T==null?void 0:T.inscriptions)==null?void 0:m.some(A=>A.id===p.parent),"Referenced parent inscription must actually be spent."),de(s.vout.length===2&&Number(s.vout[b].value)===T.value&&qe(T.scriptPubKey)===`5120${p.pubkey}`&&qe(s.vout[b].scriptPubKey)===qe(T.scriptPubKey),"Parent must be owned and preserved in the same wallet.")}else s.vin.length===2&&(de(u===1&&((y=c[0].inscriptions)==null?void 0:y.length)&&p.pointer!==void 0,"Reinscription spend requires correct tag and owned sat."),de(Number(s.vout[0].value)===c[0].value&&qe(s.vout[0].scriptPubKey)===qe(c[0].scriptPubKey)&&qe(c[0].scriptPubKey)===`5120${p.pubkey}`,"Reinscription sat must be returned to owner."));g={pubkey:p.pubkey},a={id:`${o}i0`,txid:o,commitTxid:f.txid,text:p.text,bytes:Array.from(p.bytes),contentType:p.contentType,parent:p.parent,delegate:p.delegate,pointer:p.pointer,metaprotocol:p.metaprotocol,metadata:p.metadata,height:n,value:bt}}s.vin.forEach((p,w)=>{let b=!1;try{b=Fo.test(qe(c[w].scriptPubKey))?D1(s,w):fo.taproot.verify(s,w,w===u?g:{})}catch{}de(b,"Invalid signature or Taproot commitment.")})}const l=Yc(s,c,n,r),d=c.flatMap(g=>g.inscriptions??[]);if(a){const g=BigInt(a.pointer??0),p=g{var b;return((b=w.inscription)==null?void 0:b.sat)===a.sat}).length,d.push(a)}return de(d.every(g=>l.some(p=>xs(p,g.sat)!==null)),"Local lab protects inscription sats from fee loss."),r||s.vin.forEach(g=>this.utxos.delete(gs(g.txid,g.vout))),s.vout.forEach((g,p)=>{const w=d.filter(b=>xs(l[p],b.sat)!==null);this.utxos.set(gs(o,p),{txid:o,vout:p,value:Number(g.value),scriptPubKey:g.scriptPubKey,height:n,ranges:l[p],inscriptions:w,...w.length?{inscription:w[0]}:{}})}),this.transactions.set(o,{txid:o,raw:t,height:n,coinbase:r,tx:s,...a?{inscription:a}:{}}),o}submitPackage(t){de(Array.isArray(t)&&this.mempool.length+t.length<=1e3,"Invalid package or mempool full; mine a block first.");const n=new Map(this.utxos),r=new Map(this.transactions);try{t.forEach(s=>this.apply(s,null))}catch(s){throw this.utxos=n,this.transactions=r,s}this.mempool.push(...t)}acceptBlock(t){var i;de(t.height===this.blocks.length+1&&t.previous===(((i=this.blocks.at(-1))==null?void 0:i.hash)??ps),"Invalid block ancestry."),de(Number.isSafeInteger(t.time)&&t.time>0&&Array.isArray(t.raws)&&t.raws.length>0&&t.raws.length<=1001,"Invalid block.");const{hash:n,...r}=t;de(Cc(r)===n,"Invalid local block hash.");const s=new Map(this.utxos),o=new Map(this.transactions);try{t.raws.forEach((a,c)=>this.apply(a,t.height,c===0))}catch(a){throw this.utxos=s,this.transactions=o,a}this.blocks.push(t)}mine(t){return this.mineTo([De(zo,t)])}mineTo(t){var a;const n=new yo({...this.snapshot(),mempool:[]}),r=this.blocks.length+1,s=ce.create({vin:[{txid:ps,vout:4294967295,scriptSig:[new TextEncoder().encode(`${en}:${r}`)]}],vout:t}),o={height:r,previous:((a=this.blocks.at(-1))==null?void 0:a.hash)??ps,time:Date.now(),raws:[ce.encode(s).hex,...this.mempool]},i={...o,hash:Cc(o)};return n.acceptBlock(i),Object.assign(this,n),i}}/*! scure-base - MIT License (c) 2022 Paul Miller (paulmillr.com) */function cr(e){return e instanceof Uint8Array||ArrayBuffer.isView(e)&&e.constructor.name==="Uint8Array"}function Z1(e,...t){if(!cr(e))throw new Error("Uint8Array expected");if(t.length>0&&!t.includes(e.length))throw new Error("Uint8Array expected of length "+t+", got length="+e.length)}function Vf(e,t){return Array.isArray(t)?t.length===0?!0:e?t.every(n=>typeof n=="string"):t.every(n=>Number.isSafeInteger(n)):!1}function qf(e){if(typeof e!="function")throw new Error("function expected");return!0}function Rn(e,t){if(typeof t!="string")throw new Error(`${e}: string expected`);return!0}function gr(e){if(!Number.isSafeInteger(e))throw new Error(`invalid integer: ${e}`)}function Js(e){if(!Array.isArray(e))throw new Error("array expected")}function Qs(e,t){if(!Vf(!0,t))throw new Error(`${e}: array of strings expected`)}function Oa(e,t){if(!Vf(!1,t))throw new Error(`${e}: array of numbers expected`)}function Jr(...e){const t=o=>o,n=(o,i)=>a=>o(i(a)),r=e.map(o=>o.encode).reduceRight(n,t),s=e.map(o=>o.decode).reduce(n,t);return{encode:r,decode:s}}function bo(e){const t=typeof e=="string"?e.split(""):e,n=t.length;Qs("alphabet",t);const r=new Map(t.map((s,o)=>[s,o]));return{encode:s=>(Js(s),s.map(o=>{if(!Number.isSafeInteger(o)||o<0||o>=n)throw new Error(`alphabet.encode: digit index outside alphabet "${o}". Allowed: ${e}`);return t[o]})),decode:s=>(Js(s),s.map(o=>{Rn("alphabet.decode",o);const i=r.get(o);if(i===void 0)throw new Error(`Unknown letter: "${o}". Allowed: ${e}`);return i}))}}function wo(e=""){return Rn("join",e),{encode:t=>(Qs("join.decode",t),t.join(e)),decode:t=>(Rn("join.decode",t),t.split(e))}}function zf(e,t="="){return gr(e),Rn("padding",t),{encode(n){for(Qs("padding.encode",n);n.length*e%8;)n.push(t);return n},decode(n){Qs("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)}}}function Ii(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(Js(e),!e.length)return[];let r=0;const s=[],o=Array.from(e,a=>{if(gr(a),a<0||a>=t)throw new Error(`invalid integer: ${a}`);return a}),i=o.length;for(;;){let a=0,c=!0;for(let u=r;ut===0?e:Ff(t,e%t),eo=(e,t)=>e+(t-Ff(e,t)),ks=(()=>{let e=[];for(let t=0;t<40;t++)e.push(2**t);return e})();function to(e,t,n,r){if(Js(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(eo(t,n)>32)throw new Error(`convertRadix2: carry overflow from=${t} to=${n} carryBits=${eo(t,n)}`);let s=0,o=0;const i=ks[t],a=ks[n]-1,c=[];for(const u of e){if(gr(u),u>=i)throw new Error(`convertRadix2: invalid data word=${u} from=${t}`);if(s=s<32)throw new Error(`convertRadix2: carry overflow pos=${o} from=${t}`);for(o+=t;o>=n;o-=n)c.push((s>>o-n&a)>>>0);const f=ks[o];if(f===void 0)throw new Error("invalid carry");s&=f-1}if(s=s<=t)throw new Error("Excess padding");if(!r&&s>0)throw new Error(`Non-zero padding: ${s}`);return r&&o>0&&c.push(s>>>0),c}function Gf(e){gr(e);const t=2**8;return{encode:n=>{if(!cr(n))throw new Error("radix.encode input should be Uint8Array");return Ii(Array.from(n),t,e)},decode:n=>(Oa("radix.decode",n),Uint8Array.from(Ii(n,e,t)))}}function Ca(e,t=!1){if(gr(e),e<=0||e>32)throw new Error("radix2: bits should be in (0..32]");if(eo(8,e)>32||eo(e,8)>32)throw new Error("radix2: carry overflow");return{encode:n=>{if(!cr(n))throw new Error("radix2.encode input should be Uint8Array");return to(Array.from(n),8,e,!t)},decode:n=>(Oa("radix2.decode",n),Uint8Array.from(to(n,e,8,t)))}}function Pc(e){return qf(e),function(...t){try{return e.apply(null,t)}catch{}}}function Wf(e,t){return gr(e),qf(t),{encode(n){if(!cr(n))throw new Error("checksum.encode: input should be Uint8Array");const r=t(n).slice(0,e),s=new Uint8Array(n.length+e);return s.set(n),s.set(r,n.length),s},decode(n){if(!cr(n))throw new Error("checksum.decode: input should be Uint8Array");const r=n.slice(0,-e),s=n.slice(-e),o=t(r).slice(0,e);for(let i=0;i{Rn("base64",e);const n=/^[A-Za-z0-9=+/]+$/,r="base64";if(e.length>0&&!n.test(e))throw new Error("invalid base64");return Uint8Array.fromBase64(e,{alphabet:r,lastChunkHandling:"strict"})},wt=M1?{encode(e){return Z1(e),e.toBase64()},decode(e){return V1(e)}}:Jr(Ca(6),bo("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"),zf(6),wo("")),q1=e=>Jr(Gf(58),bo(e),wo("")),z1=q1("123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"),Yf=e=>Jr(Wf(4,t=>e(e(t))),z1),Oi=Jr(bo("qpzry9x8gf2tvdw0s3jn54khce6mua7l"),wo("")),Uc=[996825010,642813549,513874426,1027748829,705979059];function vr(e){const t=e>>25;let n=(e&33554431)<<5;for(let r=0;r>r&1)===1&&(n^=Uc[r]);return n}function Nc(e,t,n=1){const r=e.length;let s=1;for(let o=0;o126)throw new Error(`Invalid prefix (${e})`);s=vr(s)^i>>5}s=vr(s);for(let o=0;oh)throw new TypeError(`Length ${y} exceeds limit ${h}`);const g=l.toLowerCase(),p=Nc(g,d,t);return`${g}1${Oi.encode(d)}${p}`}function a(l,d=90){Rn("bech32.decode input",l);const h=l.length;if(h<8||d!==!1&&h>d)throw new TypeError(`invalid string length: ${h} (${l}). Expected (8..${d})`);const m=l.toLowerCase();if(l!==m&&l!==l.toUpperCase())throw new Error("String must be lowercase or uppercase");const y=m.lastIndexOf("1");if(y===0||y===-1)throw new Error('Letter "1" must be present between prefix and data only');const g=m.slice(0,y),p=m.slice(y+1);if(p.length<6)throw new Error("Data must be at least 6 characters long");const w=Oi.decode(p).slice(0,-6),b=Nc(g,w,t);if(!p.endsWith(b))throw new Error(`Invalid checksum in ${l}: expected "${b}"`);return{prefix:g,words:w}}const c=Pc(a);function u(l){const{prefix:d,words:h}=a(l,!1);return{prefix:d,words:h,bytes:r(h)}}function f(l,d){return i(l,s(d))}return{encode:i,decode:a,encodeFromBytes:f,decodeToBytes:u,decodeUnsafe:c,fromWords:r,fromWordsUnsafe:o,toWords:s}}const no=F1("bech32");/*! scure-bip32 - MIT License (c) 2022 Patricio Palladino, Paul Miller (paulmillr.com) */const ys=ze.ProjectivePoint,Go=Yf(nt);function Lc(e){Ne(e);const t=e.length===0?"0":Le(e);return BigInt("0x"+t)}function G1(e){if(typeof e!="bigint")throw new Error("bigint expected");return dt(e.toString(16).padStart(64,"0"))}const W1=Ye("Bitcoin seed"),Wo={private:76066276,public:76067358},Yo=2147483648,Y1=e=>gf(nt(e)),X1=e=>Tn(e).getUint32(0,!1),bs=e=>{if(!Number.isSafeInteger(e)||e<0||e>2**32-1)throw new Error("invalid number, should be from 0 to 2**32-1, got "+e);const t=new Uint8Array(4);return Tn(t).setUint32(0,e,!1),t};class bn{get fingerprint(){if(!this.pubHash)throw new Error("No publicKey set!");return X1(this.pubHash)}get identifier(){return this.pubHash}get pubKeyHash(){return this.pubHash}get privateKey(){return this.privKeyBytes||null}get publicKey(){return this.pubKey||null}get privateExtendedKey(){const t=this.privateKey;if(!t)throw new Error("No private key");return Go.encode(this.serialize(this.versions.private,xe(new Uint8Array([0]),t)))}get publicExtendedKey(){if(!this.pubKey)throw new Error("No public key");return Go.encode(this.serialize(this.versions.public,this.pubKey))}static fromMasterSeed(t,n=Wo){if(Ne(t),8*t.length<128||8*t.length>512)throw new Error("HDKey: seed length must be between 128 and 512 bits; 256 bits is advised, got "+t.length);const r=fn(Zr,W1,t);return new bn({versions:n,chainCode:r.slice(32),privateKey:r.slice(0,32)})}static fromExtendedKey(t,n=Wo){const r=Go.decode(t),s=Tn(r),o=s.getUint32(0,!1),i={versions:n,depth:r[4],parentFingerprint:s.getUint32(5,!1),index:s.getUint32(9,!1),chainCode:r.slice(13,45)},a=r.slice(45),c=a[0]===0;if(o!==n[c?"private":"public"])throw new Error("Version mismatch");return c?new bn({...i,privateKey:a.slice(1)}):new bn({...i,publicKey:a})}static fromJSON(t){return bn.fromExtendedKey(t.xpriv)}constructor(t){if(this.depth=0,this.index=0,this.chainCode=null,this.parentFingerprint=0,!t||typeof t!="object")throw new Error("HDKey.constructor must not be called directly");if(this.versions=t.versions||Wo,this.depth=t.depth||0,this.chainCode=t.chainCode||null,this.index=t.index||0,this.parentFingerprint=t.parentFingerprint||0,!this.depth&&(this.parentFingerprint||this.index))throw new Error("HDKey: zero depth with non-zero index/parent fingerprint");if(t.publicKey&&t.privateKey)throw new Error("HDKey: publicKey and privateKey at same time.");if(t.privateKey){if(!ze.utils.isValidPrivateKey(t.privateKey))throw new Error("Invalid private key");this.privKey=typeof t.privateKey=="bigint"?t.privateKey:Lc(t.privateKey),this.privKeyBytes=G1(this.privKey),this.pubKey=ze.getPublicKey(t.privateKey,!0)}else if(t.publicKey)this.pubKey=ys.fromHex(t.publicKey).toRawBytes(!0);else throw new Error("HDKey: no public or private key provided");this.pubHash=Y1(this.pubKey)}derive(t){if(!/^[mM]'?/.test(t))throw new Error('Path must start with "m" or "M"');if(/^[mM]'?$/.test(t))return this;const n=t.replace(/^[mM]'?\//,"").split("/");let r=this;for(const s of n){const o=/^(\d+)('?)$/.exec(s),i=o&&o[1];if(!o||o.length!==3||typeof i!="string")throw new Error("invalid child index: "+s);let a=+i;if(!Number.isSafeInteger(a)||a>=Yo)throw new Error("Invalid index");o[2]==="'"&&(a+=Yo),r=r.deriveChild(a)}return r}deriveChild(t){if(!this.pubKey||!this.chainCode)throw new Error("No publicKey or chainCode set");let n=bs(t);if(t>=Yo){const a=this.privateKey;if(!a)throw new Error("Could not derive hardened child key");n=xe(new Uint8Array([0]),a,n)}else n=xe(this.pubKey,n);const r=fn(Zr,this.chainCode,n),s=Lc(r.slice(0,32)),o=r.slice(32);if(!ze.utils.isValidPrivateKey(s))throw new Error("Tweak bigger than curve order");const i={versions:this.versions,chainCode:o,depth:this.depth+1,parentFingerprint:this.fingerprint,index:t};try{if(this.privateKey){const a=we(this.privKey+s,ze.CURVE.n);if(!ze.utils.isValidPrivateKey(a))throw new Error("The tweak was out of range or the resulted private key is invalid");i.privateKey=a}else{const a=ys.fromHex(this.pubKey).add(ys.fromPrivateKey(s));if(a.equals(ys.ZERO))throw new Error("The tweak was equal to negative P, which made the result key invalid");i.publicKey=a.toRawBytes(!0)}return new bn(i)}catch{return this.deriveChild(t+1)}}sign(t){if(!this.privateKey)throw new Error("No privateKey set!");return Ne(t,32),ze.sign(t,this.privKey).toCompactRawBytes()}verify(t,n){if(Ne(t,32),Ne(n,64),!this.publicKey)throw new Error("No publicKey set!");let r;try{r=ze.Signature.fromCompact(n)}catch{return!1}return ze.verify(r,t,this.publicKey)}wipePrivateData(){return this.privKey=void 0,this.privKeyBytes&&(this.privKeyBytes.fill(0),this.privKeyBytes=void 0),this}toJSON(){return{xpriv:this.privateExtendedKey,xpub:this.publicExtendedKey}}serialize(t,n){if(!this.chainCode)throw new Error("No chainCode set");return Ne(n,33),xe(bs(t),new Uint8Array([this.depth]),bs(this.parentFingerprint),bs(this.index),this.chainCode,n)}}function J1(e,t,n,r){Yr(e);const s=Kw({dkLen:32,asyncTick:10},r),{c:o,dkLen:i,asyncTick:a}=s;if(rn(o),rn(i),rn(a),o<1)throw new Error("iterations (c) should be >= 1");const c=yc(t),u=yc(n),f=new Uint8Array(i),l=fn.create(e,c),d=l._cloneInto().update(u);return{c:o,dkLen:i,asyncTick:a,DK:f,PRF:l,PRFSalt:d}}function Q1(e,t,n,r,s){return e.destroy(),t.destroy(),r&&r.destroy(),St(s),n}function ex(e,t,n,r){const{c:s,dkLen:o,DK:i,PRF:a,PRFSalt:c}=J1(e,t,n,r);let u;const f=new Uint8Array(4),l=Tn(f),d=new Uint8Array(a.outputLen);for(let h=1,m=0;me[0]==="あいこくしん";function Xf(e){if(typeof e!="string")throw new TypeError("invalid mnemonic type: "+typeof e);return e.normalize("NFKD")}function Jf(e){const t=Xf(e),n=t.split(" ");if(![12,15,18,21,24].includes(n.length))throw new Error("Invalid mnemonic");return{nfkd:t,words:n}}function Qf(e){Ne(e,16,20,24,28,32)}function nx(e,t=128){if(rn(t),t%32!==0||t>256)throw new TypeError("Invalid entropy");return td(Dn(t/8),e)}const rx=e=>{const t=8-e.length/4;return new Uint8Array([nt(e)[0]>>t<{if(typeof t!="string")throw new Error("wordlist: non-string element: "+t)}),ms.chain(ms.checksum(1,rx),ms.radix2(11,!0),ms.alphabet(e))}function sx(e,t){const{words:n}=Jf(e),r=ed(t).decode(n);return Qf(r),r}function td(e,t){return Qf(e),ed(t).encode(e).join(tx(t)?" ":" ")}function ox(e,t){try{sx(e,t)}catch{return!1}return!0}const ix=e=>Xf("mnemonic"+e);function ax(e,t=""){return ex(Zr,Jf(e).nfkd,ix(t),{c:2048,dkLen:64})}const Pa=`abandon -ability -able -about -above -absent -absorb -abstract -absurd -abuse -access -accident -account -accuse -achieve -acid -acoustic -acquire -across -act -action -actor -actress -actual -adapt -add -addict -address -adjust -admit -adult -advance -advice -aerobic -affair -afford -afraid -again -age -agent -agree -ahead -aim -air -airport -aisle -alarm -album -alcohol -alert -alien -all -alley -allow -almost -alone -alpha -already -also -alter -always -amateur -amazing -among -amount -amused -analyst -anchor -ancient -anger -angle -angry -animal -ankle -announce -annual -another -answer -antenna -antique -anxiety -any -apart -apology -appear -apple -approve -april -arch -arctic -area -arena -argue -arm -armed -armor -army -around -arrange -arrest -arrive -arrow -art -artefact -artist -artwork -ask -aspect -assault -asset -assist -assume -asthma -athlete -atom -attack -attend -attitude -attract -auction -audit -august -aunt -author -auto -autumn -average -avocado -avoid -awake -aware -away -awesome -awful -awkward -axis -baby -bachelor -bacon -badge -bag -balance -balcony -ball -bamboo -banana -banner -bar -barely -bargain -barrel -base -basic -basket -battle -beach -bean -beauty -because -become -beef -before -begin -behave -behind -believe -below -belt -bench -benefit -best -betray -better -between -beyond -bicycle -bid -bike -bind -biology -bird -birth -bitter -black -blade -blame -blanket -blast -bleak -bless -blind -blood -blossom -blouse -blue -blur -blush -board -boat -body -boil -bomb -bone -bonus -book -boost -border -boring -borrow -boss -bottom -bounce -box -boy -bracket -brain -brand -brass -brave -bread -breeze -brick -bridge -brief -bright -bring -brisk -broccoli -broken -bronze -broom -brother -brown -brush -bubble -buddy -budget -buffalo -build -bulb -bulk -bullet -bundle -bunker -burden -burger -burst -bus -business -busy -butter -buyer -buzz -cabbage -cabin -cable -cactus -cage -cake -call -calm -camera -camp -can -canal -cancel -candy -cannon -canoe -canvas -canyon -capable -capital -captain -car -carbon -card -cargo -carpet -carry -cart -case -cash -casino -castle -casual -cat -catalog -catch -category -cattle -caught -cause -caution -cave -ceiling -celery -cement -census -century -cereal -certain -chair -chalk -champion -change -chaos -chapter -charge -chase -chat -cheap -check -cheese -chef -cherry -chest -chicken -chief -child -chimney -choice -choose -chronic -chuckle -chunk -churn -cigar -cinnamon -circle -citizen -city -civil -claim -clap -clarify -claw -clay -clean -clerk -clever -click -client -cliff -climb -clinic -clip -clock -clog -close -cloth -cloud -clown -club -clump -cluster -clutch -coach -coast -coconut -code -coffee -coil -coin -collect -color -column -combine -come -comfort -comic -common -company -concert -conduct -confirm -congress -connect -consider -control -convince -cook -cool -copper -copy -coral -core -corn -correct -cost -cotton -couch -country -couple -course -cousin -cover -coyote -crack -cradle -craft -cram -crane -crash -crater -crawl -crazy -cream -credit -creek -crew -cricket -crime -crisp -critic -crop -cross -crouch -crowd -crucial -cruel -cruise -crumble -crunch -crush -cry -crystal -cube -culture -cup -cupboard -curious -current -curtain -curve -cushion -custom -cute -cycle -dad -damage -damp -dance -danger -daring -dash -daughter -dawn -day -deal -debate -debris -decade -december -decide -decline -decorate -decrease -deer -defense -define -defy -degree -delay -deliver -demand -demise -denial -dentist -deny -depart -depend -deposit -depth -deputy -derive -describe -desert -design -desk -despair -destroy -detail -detect -develop -device -devote -diagram -dial -diamond -diary -dice -diesel -diet -differ -digital -dignity -dilemma -dinner -dinosaur -direct -dirt -disagree -discover -disease -dish -dismiss -disorder -display -distance -divert -divide -divorce -dizzy -doctor -document -dog -doll -dolphin -domain -donate -donkey -donor -door -dose -double -dove -draft -dragon -drama -drastic -draw -dream -dress -drift -drill -drink -drip -drive -drop -drum -dry -duck -dumb -dune -during -dust -dutch -duty -dwarf -dynamic -eager -eagle -early -earn -earth -easily -east -easy -echo -ecology -economy -edge -edit -educate -effort -egg -eight -either -elbow -elder -electric -elegant -element -elephant -elevator -elite -else -embark -embody -embrace -emerge -emotion -employ -empower -empty -enable -enact -end -endless -endorse -enemy -energy -enforce -engage -engine -enhance -enjoy -enlist -enough -enrich -enroll -ensure -enter -entire -entry -envelope -episode -equal -equip -era -erase -erode -erosion -error -erupt -escape -essay -essence -estate -eternal -ethics -evidence -evil -evoke -evolve -exact -example -excess -exchange -excite -exclude -excuse -execute -exercise -exhaust -exhibit -exile -exist -exit -exotic -expand -expect -expire -explain -expose -express -extend -extra -eye -eyebrow -fabric -face -faculty -fade -faint -faith -fall -false -fame -family -famous -fan -fancy -fantasy -farm -fashion -fat -fatal -father -fatigue -fault -favorite -feature -february -federal -fee -feed -feel -female -fence -festival -fetch -fever -few -fiber -fiction -field -figure -file -film -filter -final -find -fine -finger -finish -fire -firm -first -fiscal -fish -fit -fitness -fix -flag -flame -flash -flat -flavor -flee -flight -flip -float -flock -floor -flower -fluid -flush -fly -foam -focus -fog -foil -fold -follow -food -foot -force -forest -forget -fork -fortune -forum -forward -fossil -foster -found -fox -fragile -frame -frequent -fresh -friend -fringe -frog -front -frost -frown -frozen -fruit -fuel -fun -funny -furnace -fury -future -gadget -gain -galaxy -gallery -game -gap -garage -garbage -garden -garlic -garment -gas -gasp -gate -gather -gauge -gaze -general -genius -genre -gentle -genuine -gesture -ghost -giant -gift -giggle -ginger -giraffe -girl -give -glad -glance -glare -glass -glide -glimpse -globe -gloom -glory -glove -glow -glue -goat -goddess -gold -good -goose -gorilla -gospel -gossip -govern -gown -grab -grace -grain -grant -grape -grass -gravity -great -green -grid -grief -grit -grocery -group -grow -grunt -guard -guess -guide -guilt -guitar -gun -gym -habit -hair -half -hammer -hamster -hand -happy -harbor -hard -harsh -harvest -hat -have -hawk -hazard -head -health -heart -heavy -hedgehog -height -hello -helmet -help -hen -hero -hidden -high -hill -hint -hip -hire -history -hobby -hockey -hold -hole -holiday -hollow -home -honey -hood -hope -horn -horror -horse -hospital -host -hotel -hour -hover -hub -huge -human -humble -humor -hundred -hungry -hunt -hurdle -hurry -hurt -husband -hybrid -ice -icon -idea -identify -idle -ignore -ill -illegal -illness -image -imitate -immense -immune -impact -impose -improve -impulse -inch -include -income -increase -index -indicate -indoor -industry -infant -inflict -inform -inhale -inherit -initial -inject -injury -inmate -inner -innocent -input -inquiry -insane -insect -inside -inspire -install -intact -interest -into -invest -invite -involve -iron -island -isolate -issue -item -ivory -jacket -jaguar -jar -jazz -jealous -jeans -jelly -jewel -job -join -joke -journey -joy -judge -juice -jump -jungle -junior -junk -just -kangaroo -keen -keep -ketchup -key -kick -kid -kidney -kind -kingdom -kiss -kit -kitchen -kite -kitten -kiwi -knee -knife -knock -know -lab -label -labor -ladder -lady -lake -lamp -language -laptop -large -later -latin -laugh -laundry -lava -law -lawn -lawsuit -layer -lazy -leader -leaf -learn -leave -lecture -left -leg -legal -legend -leisure -lemon -lend -length -lens -leopard -lesson -letter -level -liar -liberty -library -license -life -lift -light -like -limb -limit -link -lion -liquid -list -little -live -lizard -load -loan -lobster -local -lock -logic -lonely -long -loop -lottery -loud -lounge -love -loyal -lucky -luggage -lumber -lunar -lunch -luxury -lyrics -machine -mad -magic -magnet -maid -mail -main -major -make -mammal -man -manage -mandate -mango -mansion -manual -maple -marble -march -margin -marine -market -marriage -mask -mass -master -match -material -math -matrix -matter -maximum -maze -meadow -mean -measure -meat -mechanic -medal -media -melody -melt -member -memory -mention -menu -mercy -merge -merit -merry -mesh -message -metal -method -middle -midnight -milk -million -mimic -mind -minimum -minor -minute -miracle -mirror -misery -miss -mistake -mix -mixed -mixture -mobile -model -modify -mom -moment -monitor -monkey -monster -month -moon -moral -more -morning -mosquito -mother -motion -motor -mountain -mouse -move -movie -much -muffin -mule -multiply -muscle -museum -mushroom -music -must -mutual -myself -mystery -myth -naive -name -napkin -narrow -nasty -nation -nature -near -neck -need -negative -neglect -neither -nephew -nerve -nest -net -network -neutral -never -news -next -nice -night -noble -noise -nominee -noodle -normal -north -nose -notable -note -nothing -notice -novel -now -nuclear -number -nurse -nut -oak -obey -object -oblige -obscure -observe -obtain -obvious -occur -ocean -october -odor -off -offer -office -often -oil -okay -old -olive -olympic -omit -once -one -onion -online -only -open -opera -opinion -oppose -option -orange -orbit -orchard -order -ordinary -organ -orient -original -orphan -ostrich -other -outdoor -outer -output -outside -oval -oven -over -own -owner -oxygen -oyster -ozone -pact -paddle -page -pair -palace -palm -panda -panel -panic -panther -paper -parade -parent -park -parrot -party -pass -patch -path -patient -patrol -pattern -pause -pave -payment -peace -peanut -pear -peasant -pelican -pen -penalty -pencil -people -pepper -perfect -permit -person -pet -phone -photo -phrase -physical -piano -picnic -picture -piece -pig -pigeon -pill -pilot -pink -pioneer -pipe -pistol -pitch -pizza -place -planet -plastic -plate -play -please -pledge -pluck -plug -plunge -poem -poet -point -polar -pole -police -pond -pony -pool -popular -portion -position -possible -post -potato -pottery -poverty -powder -power -practice -praise -predict -prefer -prepare -present -pretty -prevent -price -pride -primary -print -priority -prison -private -prize -problem -process -produce -profit -program -project -promote -proof -property -prosper -protect -proud -provide -public -pudding -pull -pulp -pulse -pumpkin -punch -pupil -puppy -purchase -purity -purpose -purse -push -put -puzzle -pyramid -quality -quantum -quarter -question -quick -quit -quiz -quote -rabbit -raccoon -race -rack -radar -radio -rail -rain -raise -rally -ramp -ranch -random -range -rapid -rare -rate -rather -raven -raw -razor -ready -real -reason -rebel -rebuild -recall -receive -recipe -record -recycle -reduce -reflect -reform -refuse -region -regret -regular -reject -relax -release -relief -rely -remain -remember -remind -remove -render -renew -rent -reopen -repair -repeat -replace -report -require -rescue -resemble -resist -resource -response -result -retire -retreat -return -reunion -reveal -review -reward -rhythm -rib -ribbon -rice -rich -ride -ridge -rifle -right -rigid -ring -riot -ripple -risk -ritual -rival -river -road -roast -robot -robust -rocket -romance -roof -rookie -room -rose -rotate -rough -round -route -royal -rubber -rude -rug -rule -run -runway -rural -sad -saddle -sadness -safe -sail -salad -salmon -salon -salt -salute -same -sample -sand -satisfy -satoshi -sauce -sausage -save -say -scale -scan -scare -scatter -scene -scheme -school -science -scissors -scorpion -scout -scrap -screen -script -scrub -sea -search -season -seat -second -secret -section -security -seed -seek -segment -select -sell -seminar -senior -sense -sentence -series -service -session -settle -setup -seven -shadow -shaft -shallow -share -shed -shell -sheriff -shield -shift -shine -ship -shiver -shock -shoe -shoot -shop -short -shoulder -shove -shrimp -shrug -shuffle -shy -sibling -sick -side -siege -sight -sign -silent -silk -silly -silver -similar -simple -since -sing -siren -sister -situate -six -size -skate -sketch -ski -skill -skin -skirt -skull -slab -slam -sleep -slender -slice -slide -slight -slim -slogan -slot -slow -slush -small -smart -smile -smoke -smooth -snack -snake -snap -sniff -snow -soap -soccer -social -sock -soda -soft -solar -soldier -solid -solution -solve -someone -song -soon -sorry -sort -soul -sound -soup -source -south -space -spare -spatial -spawn -speak -special -speed -spell -spend -sphere -spice -spider -spike -spin -spirit -split -spoil -sponsor -spoon -sport -spot -spray -spread -spring -spy -square -squeeze -squirrel -stable -stadium -staff -stage -stairs -stamp -stand -start -state -stay -steak -steel -stem -step -stereo -stick -still -sting -stock -stomach -stone -stool -story -stove -strategy -street -strike -strong -struggle -student -stuff -stumble -style -subject -submit -subway -success -such -sudden -suffer -sugar -suggest -suit -summer -sun -sunny -sunset -super -supply -supreme -sure -surface -surge -surprise -surround -survey -suspect -sustain -swallow -swamp -swap -swarm -swear -sweet -swift -swim -swing -switch -sword -symbol -symptom -syrup -system -table -tackle -tag -tail -talent -talk -tank -tape -target -task -taste -tattoo -taxi -teach -team -tell -ten -tenant -tennis -tent -term -test -text -thank -that -theme -then -theory -there -they -thing -this -thought -three -thrive -throw -thumb -thunder -ticket -tide -tiger -tilt -timber -time -tiny -tip -tired -tissue -title -toast -tobacco -today -toddler -toe -together -toilet -token -tomato -tomorrow -tone -tongue -tonight -tool -tooth -top -topic -topple -torch -tornado -tortoise -toss -total -tourist -toward -tower -town -toy -track -trade -traffic -tragic -train -transfer -trap -trash -travel -tray -treat -tree -trend -trial -tribe -trick -trigger -trim -trip -trophy -trouble -truck -true -truly -trumpet -trust -truth -try -tube -tuition -tumble -tuna -tunnel -turkey -turn -turtle -twelve -twenty -twice -twin -twist -two -type -typical -ugly -umbrella -unable -unaware -uncle -uncover -under -undo -unfair -unfold -unhappy -uniform -unique -unit -universe -unknown -unlock -until -unusual -unveil -update -upgrade -uphold -upon -upper -upset -urban -urge -usage -use -used -useful -useless -usual -utility -vacant -vacuum -vague -valid -valley -valve -van -vanish -vapor -various -vast -vault -vehicle -velvet -vendor -venture -venue -verb -verify -version -very -vessel -veteran -viable -vibrant -vicious -victory -video -view -village -vintage -violin -virtual -virus -visa -visit -visual -vital -vivid -vocal -voice -void -volcano -volume -vote -voyage -wage -wagon -wait -walk -wall -walnut -want -warfare -warm -warrior -wash -wasp -waste -water -wave -way -wealth -weapon -wear -weasel -weather -web -wedding -weekend -weird -welcome -west -wet -whale -what -wheat -wheel -when -where -whip -whisper -wide -width -wife -wild -will -win -window -wine -wing -wink -winner -winter -wire -wisdom -wise -wish -witness -wolf -woman -wonder -wood -wool -word -work -world -worry -worth -wrap -wreck -wrestle -wrist -write -wrong -yard -year -yellow -you -young -youth -zebra -zero -zone -zoo`.split(` -`),et={orgSeed:e=>`m/83696968'/39'/0'/24'/${e}'`,wallet:(e,t=1)=>`m/86'/${t}'/${e}'/0/0`,segwit:(e,t=1)=>`m/84'/${t}'/${e}'/0/0`,nostr:e=>`m/44'/1237'/${e}'/0/0`},cx=2**31-1,Xo=new Map,Jo=new Map,Rc=()=>nx(Pa,256);function nd(e,t=0){if(typeof e!="string"||!ox(e,Pa)||t&&e.split(" ").length!==t)throw new Error("Invalid lab mnemonic.");return e}function mr(e,t){if(!Number.isSafeInteger(e)||e<0||e>cx)throw new Error(`Invalid ${t}.`);return e}const Qo=new Map;function Ua(e){return Qo.has(e)||Qo.set(e,ax(nd(e))),Qo.get(e)}function yr(e){return Xo.has(e)||Xo.set(e,bn.fromMasterSeed(Ua(e))),Xo.get(e)}function ux(e,t){const n=e.derive(t).privateKey;if(!n)throw new Error("BIP-85 path produced no private key.");return fn(Zr,Ye("bip-entropy-from-k"),n)}function lx(e,t){const n=`${e}|${mr(t,"child index")}`;return Jo.has(n)||Jo.set(n,td(ux(yr(e),et.orgSeed(t)).slice(0,32),Pa)),Jo.get(n)}function Ci(e,t=0,n=1){return Le(yr(e).derive(et.wallet(mr(t,"account"),n)).privateKey)}function rd(e,t=0,n=1){return Le(yr(e).derive(et.segwit(mr(t,"account"),n)).privateKey)}function sd(e,t=0,n=1){return Le(yr(e).derive(et.segwit(mr(t,"account"),n)).publicKey)}function Na(e,t=0){return Le(yr(e).derive(et.nostr(mr(t,"account"))).privateKey)}function fx(e,t=0){const n=Zf.getPublicKey(yr(e).derive(et.nostr(mr(t,"account"))).privateKey);return{pubkey:Le(n),npub:no.encode("npub",no.toWords(n))}}const od="lineage-claim",Pi=330,ro=e=>Se.encode(e,!1).hex,Hc=e=>({txid:e.txid,vout:e.vout,value:e.value,script:ro(e.scriptPubKey)}),ei=/^[0-9a-f]{64}$/,dx=/^5120[0-9a-f]{64}$/;function La(e,t){var n;for(const r of e.utxos.values())if((n=r.inscriptions)!=null&&n.some(s=>s.id===t))return r;return null}function id(e){return ce.create({vin:[nn(e.holder.txid,e.holder.vout,e.holder.value,e.holder.script),nn(e.payer.txid,e.payer.vout,e.payer.value,e.payer.script)],vout:[De(e.holder.value,["OP_1",e.to]),De(e.payer.value-he,["OP_1",e.to])]})}function hx(e,t,n,r=Date.now()){if((n==null?void 0:n.kind)!=="test-wallet")throw new Error("Claims are signed by local test wallets.");const s=La(e,t);if(!s)throw new Error("That inscription is not in an unspent output.");if(ro(s.scriptPubKey)===ro(n.script))throw new Error("The recipient already holds that inscription.");const o=e.coins(n.script).find(c=>{var u;return!((u=c.inscriptions)!=null&&u.length)&&c.value>=he+Pi});if(!o)throw new Error("The recipient needs a plain coin for the 500-sat fee. Mine a block to it first.");const i={kind:od,version:1,inscription:t,carried:s.inscriptions.map(c=>c.id),holder:Hc(s),payer:Hc(o),to:n.pubkey,at:r},a=id(i);return i.txid=ce.util.getTxid(a),i.sig=n.sign(a,void 0,1),i}function px(e,t,n){const r=mx(t);if((n==null?void 0:n.kind)!=="test-wallet")throw new Error("Countersigning needs a local test wallet.");if(ro(n.script)!==r.holder.script)throw new Error("Only the current holder can countersign.");if(gx(e,r)!=="open")throw new Error("This claim is stale: an input it spends was already spent.");const s=id(r);return s.vin[1].witness=[r.sig],s.vin[0].witness=[n.sign(s,void 0,0)],e.submitPackage([ce.encode(s).hex]),ce.util.getTxid(s)}function gx(e,t){return e.utxos.has(`${t.holder.txid}:${t.holder.vout}`)&&e.utxos.has(`${t.payer.txid}:${t.payer.vout}`)?"open":"stale"}function mx(e){const t=n=>n&&ei.test(n.txid)&&Number.isSafeInteger(n.vout)&&n.vout>=0&&Number.isSafeInteger(n.value)&&n.value>=Pi&&dx.test(n.script);if((e==null?void 0:e.kind)!==od||e.version!==1||!/^[0-9a-f]{64}i\d+$/.test(e.inscription)||!Array.isArray(e.carried)||!t(e.holder)||!t(e.payer)||e.payer.value255*s)throw new Error("Length should be <= 255*HashLen");const o=Math.ceil(r/s);n===void 0&&(n=jc);const i=new Uint8Array(o*s),a=fn.create(e,t),c=a._cloneInto(),u=new Uint8Array(a.outputLen);for(let f=0;fbx(e,yx(e,t,n),r,s);/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */const Xt=BigInt(0),Be=BigInt(1),ni=BigInt(2),xx=BigInt(8);function vx(e,t,n,r){const s=e.sqr(n),o=e.sqr(r),i=e.add(e.mul(t.a,s),o),a=e.add(e.ONE,e.mul(t.d,e.mul(s,o)));return e.eql(i,a)}function Ex(e,t={}){const n=Nf("edwards",e,t,t.FpFnLE),{Fp:r,Fn:s}=n;let o=n.CURVE;const{h:i}=o;hr(t,{},{uvRatio:"function"});const a=ni<r.create(g),u=t.uvRatio||((g,p)=>{try{return{isValid:!0,value:r.sqrt(r.div(g,p))}}catch{return{isValid:!1,value:Xt}}});if(!vx(r,o,o.Gx,o.Gy))throw new Error("bad curve params: generator point");function f(g,p,w=!1){const b=w?Be:Xt;return Mr("coordinate "+g,p,b,a),p}function l(g){if(!(g instanceof m))throw new Error("ExtendedPoint expected")}const d=Fs((g,p)=>{const{X:w,Y:b,Z:T}=g,A=g.is0();p==null&&(p=A?xx:r.inv(T));const O=c(w*p),U=c(b*p),C=r.mul(T,p);if(A)return{x:Xt,y:Be};if(C!==Be)throw new Error("invZ was invalid");return{x:O,y:U}}),h=Fs(g=>{const{a:p,d:w}=o;if(g.is0())throw new Error("bad point: ZERO");const{X:b,Y:T,Z:A,T:O}=g,U=c(b*b),C=c(T*T),_=c(A*A),N=c(_*_),H=c(U*p),K=c(_*c(H+C)),v=c(N+c(w*c(U*C)));if(K!==v)throw new Error("bad point: equation left != right (1)");const S=c(b*T),x=c(A*O);if(S!==x)throw new Error("bad point: equation left != right (2)");return!0});class m{constructor(p,w,b,T){this.X=f("x",p),this.Y=f("y",w),this.Z=f("z",b,!0),this.T=f("t",T),Object.freeze(this)}static CURVE(){return o}static fromAffine(p){if(p instanceof m)throw new Error("extended point not allowed");const{x:w,y:b}=p||{};return f("x",w),f("y",b),new m(w,b,Be,c(w*b))}static fromBytes(p,w=!1){const b=r.BYTES,{a:T,d:A}=o;p=Ec(at(p,b,"point")),Nn(w,"zip215");const O=Ec(p),U=p[b-1];O[b-1]=U&-129;const C=Ln(O),_=w?a:r.ORDER;Mr("point.y",C,Xt,_);const N=c(C*C),H=c(N-Be),K=c(A*N-T);let{isValid:v,value:S}=u(H,K);if(!v)throw new Error("bad point: invalid y coordinate");const x=(S&Be)===Be,k=(U&128)!==0;if(!w&&S===Xt&&k)throw new Error("bad point: x=0 and x_0=1");return k!==x&&(S=c(-S)),m.fromAffine({x:S,y:C})}static fromHex(p,w=!1){return m.fromBytes(pe("point",p),w)}get x(){return this.toAffine().x}get y(){return this.toAffine().y}precompute(p=8,w=!0){return y.createCache(this,p),w||this.multiply(ni),this}assertValidity(){h(this)}equals(p){l(p);const{X:w,Y:b,Z:T}=this,{X:A,Y:O,Z:U}=p,C=c(w*U),_=c(A*T),N=c(b*U),H=c(O*T);return C===_&&N===H}is0(){return this.equals(m.ZERO)}negate(){return new m(c(-this.X),this.Y,this.Z,c(-this.T))}double(){const{a:p}=o,{X:w,Y:b,Z:T}=this,A=c(w*w),O=c(b*b),U=c(ni*c(T*T)),C=c(p*A),_=w+b,N=c(c(_*_)-A-O),H=C+O,K=H-U,v=C-O,S=c(N*K),x=c(H*v),k=c(N*v),I=c(K*H);return new m(S,x,I,k)}add(p){l(p);const{a:w,d:b}=o,{X:T,Y:A,Z:O,T:U}=this,{X:C,Y:_,Z:N,T:H}=p,K=c(T*C),v=c(A*_),S=c(U*b*H),x=c(O*N),k=c((T+A)*(C+_)-K-v),I=x-S,L=x+S,P=c(v-w*K),j=c(k*I),D=c(L*P),q=c(k*P),ie=c(I*L);return new m(j,D,ie,q)}subtract(p){return this.add(p.negate())}multiply(p){if(!s.isValidNot0(p))throw new Error("invalid scalar: expected 1 <= sc < curve.n");const{p:w,f:b}=y.cached(this,p,T=>_n(m,T));return _n(m,[w,b])[0]}multiplyUnsafe(p,w=m.ZERO){if(!s.isValid(p))throw new Error("invalid scalar: expected 0 <= sc < curve.n");return p===Xt?m.ZERO:this.is0()||p===Be?this:y.unsafe(this,p,b=>_n(m,b),w)}isSmallOrder(){return this.multiplyUnsafe(i).is0()}isTorsionFree(){return y.unsafe(this,o.n).is0()}toAffine(p){return d(this,p)}clearCofactor(){return i===Be?this:this.multiplyUnsafe(i)}toBytes(){const{x:p,y:w}=this.toAffine(),b=r.toBytes(w);return b[b.length-1]|=p&Be?128:0,b}toHex(){return Le(this.toBytes())}toString(){return``}get ex(){return this.X}get ey(){return this.Y}get ez(){return this.Z}get et(){return this.T}static normalizeZ(p){return _n(m,p)}static msm(p,w){return Uf(m,s,p,w)}_setWindowSize(p){this.precompute(p)}toRawBytes(){return this.toBytes()}}m.BASE=new m(o.Gx,o.Gy,Be,c(o.Gx*o.Gy)),m.ZERO=new m(Xt,Be,Be,Xt),m.Fp=r,m.Fn=s;const y=new Pf(m,s.BITS);return m.BASE.precompute(8),m}function Sx(e,t,n={}){if(typeof t!="function")throw new Error('"hash" function param is required');hr(n,{},{adjustScalarBytes:"function",randomBytes:"function",domain:"function",prehash:"function",mapToCurve:"function"});const{prehash:r}=n,{BASE:s,Fp:o,Fn:i}=e,a=n.randomBytes||Dn,c=n.adjustScalarBytes||(_=>_),u=n.domain||((_,N,H)=>{if(Nn(H,"phflag"),N.length||H)throw new Error("Contexts/pre-hash are not supported");return _});function f(_){return i.create(Ln(_))}function l(_){const N=b.secretKey;_=pe("private key",_,N);const H=pe("hashed private key",t(_),2*N),K=c(H.slice(0,N)),v=H.slice(N,2*N),S=f(K);return{head:K,prefix:v,scalar:S}}function d(_){const{head:N,prefix:H,scalar:K}=l(_),v=s.multiply(K),S=v.toBytes();return{head:N,prefix:H,scalar:K,point:v,pointBytes:S}}function h(_){return d(_).pointBytes}function m(_=Uint8Array.of(),...N){const H=xe(...N);return f(t(u(H,pe("context",_),!!r)))}function y(_,N,H={}){_=pe("message",_),r&&(_=r(_));const{prefix:K,scalar:v,pointBytes:S}=d(N),x=m(H.context,K,_),k=s.multiply(x).toBytes(),I=m(H.context,k,S,_),L=i.create(x+I*v);if(!i.isValid(L))throw new Error("sign failed: invalid s");const P=xe(k,i.toBytes(L));return at(P,b.signature,"result")}const g={zip215:!0};function p(_,N,H,K=g){const{context:v,zip215:S}=K,x=b.signature;_=pe("signature",_,x),N=pe("message",N),H=pe("publicKey",H,b.publicKey),S!==void 0&&Nn(S,"zip215"),r&&(N=r(N));const k=x/2,I=_.subarray(0,k),L=Ln(_.subarray(k,x));let P,j,D;try{P=e.fromBytes(H,S),j=e.fromBytes(I,S),D=s.multiplyUnsafe(L)}catch{return!1}if(!S&&P.isSmallOrder())return!1;const q=m(v,j.toBytes(),P.toBytes(),N);return j.add(P.multiplyUnsafe(q)).subtract(D).clearCofactor().is0()}const w=o.BYTES,b={secretKey:w,publicKey:w,signature:2*w,seed:w};function T(_=a(b.seed)){return at(_,b.seed,"seed")}function A(_){const N=C.randomSecretKey(_);return{secretKey:N,publicKey:h(N)}}function O(_){return Wr(_)&&_.length===i.BYTES}function U(_,N){try{return!!e.fromBytes(_,N)}catch{return!1}}const C={getExtendedPublicKey:d,randomSecretKey:T,isValidSecretKey:O,isValidPublicKey:U,toMontgomery(_){const{y:N}=e.fromBytes(_),H=b.publicKey,K=H===32;if(!K&&H!==57)throw new Error("only defined for 25519 and 448");const v=K?o.div(Be+N,Be-N):o.div(N-Be,N+Be);return o.toBytes(v)},toMontgomerySecret(_){const N=b.secretKey;at(_,N);const H=t(_.subarray(0,N));return c(H).subarray(0,N)},randomPrivateKey:T,precompute(_=8,N=e.BASE){return N.precompute(_,!1)}};return Object.freeze({keygen:A,getPublicKey:h,sign:y,verify:p,utils:C,Point:e,lengths:b})}function kx(e){const t={a:e.a,d:e.d,p:e.Fp.ORDER,n:e.n,h:e.h,Gx:e.Gx,Gy:e.Gy},n=e.Fp,r=Zn(t.n,e.nBitLength,!0),s={Fp:n,Fn:r,uvRatio:e.uvRatio},o={randomBytes:e.randomBytes,adjustScalarBytes:e.adjustScalarBytes,domain:e.domain,prehash:e.prehash,mapToCurve:e.mapToCurve};return{CURVE:t,curveOpts:s,hash:e.hash,eddsaOpts:o}}function _x(e,t){const n=t.Point;return Object.assign({},t,{ExtendedPoint:n,CURVE:e,nBitLength:n.Fn.BITS,nByteLength:n.Fn.BYTES})}function $x(e){const{CURVE:t,curveOpts:n,hash:r,eddsaOpts:s}=kx(e),o=Ex(t,n),i=Sx(o,r,s);return _x(e,i)}/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */const Er=BigInt(0),zn=BigInt(1),ws=BigInt(2);function Ax(e){return hr(e,{adjustScalarBytes:"function",powPminus2:"function"}),Object.freeze({...e})}function Bx(e){const t=Ax(e),{P:n,type:r,adjustScalarBytes:s,powPminus2:o,randomBytes:i}=t,a=r==="x25519";if(!a&&r!=="x448")throw new Error("invalid type");const c=i||Dn,u=a?255:448,f=a?32:56,l=BigInt(a?9:5),d=BigInt(a?121665:39081),h=a?ws**BigInt(254):ws**BigInt(447),m=a?BigInt(8)*ws**BigInt(251)-zn:BigInt(4)*ws**BigInt(445)-zn,y=h+m+zn,g=v=>we(v,n),p=w(l);function w(v){return Aa(g(v),f)}function b(v){const S=pe("u coordinate",v,f);return a&&(S[31]&=127),g(Ln(S))}function T(v){return Ln(s(pe("scalar",v,f)))}function A(v,S){const x=C(b(S),T(v));if(x===Er)throw new Error("invalid private or public key received");return w(x)}function O(v){return A(v,p)}function U(v,S,x){const k=g(v*(S-x));return S=g(S-k),x=g(x+k),{x_2:S,x_3:x}}function C(v,S){Mr("u",v,Er,n),Mr("scalar",S,h,y);const x=S,k=v;let I=zn,L=Er,P=v,j=zn,D=Er;for(let ie=BigInt(u-1);ie>=Er;ie--){const oe=x>>ie&zn;D^=oe,{x_2:I,x_3:P}=U(D,I,P),{x_2:L,x_3:j}=U(D,L,j),D=oe;const X=I+L,ue=g(X*X),le=I-L,ke=g(le*le),ae=ue-ke,me=P+j,_t=P-j,Xe=g(_t*X),Ie=g(me*le),$t=Xe+Ie,wr=Xe-Ie;P=g($t*$t),j=g(k*g(wr*wr)),I=g(ue*ke),L=g(ae*(ue+g(d*ae)))}({x_2:I,x_3:P}=U(D,I,P)),{x_2:L,x_3:j}=U(D,L,j);const q=o(L);return g(I*q)}const _={secretKey:f,publicKey:f,seed:f},N=(v=c(f))=>(Ne(v,_.seed),v);function H(v){const S=N(v);return{secretKey:S,publicKey:O(S)}}return{keygen:H,getSharedSecret:(v,S)=>A(v,S),getPublicKey:v=>O(v),scalarMult:A,scalarMultBase:O,utils:{randomSecretKey:N,randomPrivateKey:N},GuBytes:p.slice(),lengths:_}}/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */const Tx=BigInt(1),Kc=BigInt(2),Ix=BigInt(3),Ox=BigInt(5),Cx=BigInt(8),Ra=BigInt("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffed"),ad={p:Ra,n:BigInt("0x1000000000000000000000000000000014def9dea2f79cd65812631a5cf5d3ed"),h:Cx,a:BigInt("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffec"),d:BigInt("0x52036cee2b6ffe738cc740797779e89800700a4d4141d8ab75eb4dca135978a3"),Gx:BigInt("0x216936d3cd6e53fec0a4e231fdd6dc5c692cc7609525a7b2c9562d608f25d51a"),Gy:BigInt("0x6666666666666666666666666666666666666666666666666666666666666658")};function cd(e){const t=BigInt(10),n=BigInt(20),r=BigInt(40),s=BigInt(80),o=Ra,a=e*e%o*e%o,c=ve(a,Kc,o)*a%o,u=ve(c,Tx,o)*e%o,f=ve(u,Ox,o)*u%o,l=ve(f,t,o)*f%o,d=ve(l,n,o)*l%o,h=ve(d,r,o)*d%o,m=ve(h,s,o)*h%o,y=ve(m,s,o)*h%o,g=ve(y,t,o)*f%o;return{pow_p_5_8:ve(g,Kc,o)*e%o,b2:a}}function ud(e){return e[0]&=248,e[31]&=127,e[31]|=64,e}const Dc=BigInt("19681161376707505956807079304988542015446066515923890162744021073123829784752");function Px(e,t){const n=Ra,r=we(t*t*t,n),s=we(r*r*t,n),o=cd(e*s).pow_p_5_8;let i=we(e*r*o,n);const a=we(t*i*i,n),c=i,u=we(i*Dc,n),f=a===e,l=a===we(-e,n),d=a===we(-e*Dc,n);return f&&(i=c),(l||d)&&(i=u),m1(i,n)&&(i=we(-i,n)),{isValid:f||l,value:i}}const ld=Zn(ad.p,{isLE:!0}),Ux={...ad,Fp:ld,hash:Zr,adjustScalarBytes:ud,uvRatio:Px},xo=$x(Ux),fd=(()=>{const e=ld.ORDER;return Bx({P:e,type:"x25519",powPminus2:t=>{const{pow_p_5_8:n,b2:r}=cd(t);return we(ve(n,Ix,e)*r,e)},adjustScalarBytes:ud})})(),Nx=Ye("lineage/v0"),xt=(e,t)=>wx(nt,e,Nx,Ye(t),32),vo=e=>{const t=Uint8Array.from(e);return t[0]&=248,t[31]&=127,t[31]|=64,t},dd=e=>{const t=new Uint8Array(4);return new DataView(t.buffer).setUint32(0,e),t},rt=e=>xe(dd(e.length),e),Ha=e=>xe(rt(Ye("ssh-ed25519")),rt(e)),Ui=(e,t)=>`ssh-ed25519 ${wt.encode(Ha(e))}${t?` ${t}`:""}`,Ni=e=>`SHA256:${wt.encode(nt(Ha(e))).replace(/=+$/,"")}`;function Lx(e){const t=dt(e),n=r=>xo.getPublicKey(xt(t,r));return{ssh:n("ssh"),git:n("git"),dkim:n("dkim"),wg:fd.getPublicKey(vo(xt(t,"wg")))}}function Rx(e){const t=n=>xo.getPublicKey(xt(e,n));return{"ssh-ca":t("node/ssh-ca"),mtls:t("node/mtls"),noise:fd.getPublicKey(vo(xt(e,"node/noise")))}}function Hx(e,t,n,r){return[["ssh",Ni(e.ssh),Ui(e.ssh,t)],["git",Ni(e.git),`${t} namespaces="git" ${Ui(e.git,t)}`],["dkim",`${n}._domainkey.${r}`,`${n}._domainkey.${r}. IN TXT "v=DKIM1; k=ed25519; p=${wt.encode(e.dkim)}"`],["wg",wt.encode(e.wg),`[Peer] -# ${t} -PublicKey = ${wt.encode(e.wg)}`]]}function jx(e,t){return[["ssh-ca",Ni(e["ssh-ca"]),Ui(e["ssh-ca"],`lineage-ca@${t}`)],["mtls",wt.encode(e.mtls),null],["noise",`mkey:${Le(e.noise)}`,null]]}const Kx=dt("302e020100300506032b657004220420");function hd(e,t,n){const r=nt(e).slice(0,4);let s=xe(r,r,rt(Ye("ssh-ed25519")),rt(t),rt(xe(e,t)),rt(Ye(n)));s=xe(s,new Uint8Array((8-s.length%8)%8).map((i,a)=>a+1));const o=xe(Ye("openssh-key-v1\0"),rt(Ye("none")),rt(Ye("none")),rt(new Uint8Array(0)),dd(1),rt(Ha(t)),rt(s));return`-----BEGIN OPENSSH PRIVATE KEY----- -${wt.encode(o).match(/.{1,70}/g).join(` -`)} ------END OPENSSH PRIVATE KEY----- -`}const Dx=(e,t)=>`-----BEGIN ${e}----- -${wt.encode(t).match(/.{1,64}/g).join(` -`)} ------END ${e}----- -`;function Zx(e,t){const n=dt(e),r=s=>{const o=xt(n,s);return hd(o,xo.getPublicKey(o),t)};return[["ssh","OpenSSH private key",r("ssh")],["git","OpenSSH private key",r("git")],["dkim","Ed25519 private key (base64)",wt.encode(xt(n,"dkim"))],["wg","Interface entry",`[Interface] -PrivateKey = ${wt.encode(vo(xt(n,"wg")))}`]]}function Mx(e,t){const n=xt(e,"node/ssh-ca");return[["ssh-ca","OpenSSH private key",hd(n,xo.getPublicKey(n),`lineage-ca@${t}`)],["mtls","Private key (PKCS#8 PEM)",Dx("PRIVATE KEY",xe(Kx,xt(e,"node/mtls")))],["noise","noise_private.key",`privkey:${Le(vo(xt(e,"node/noise")))}`]]}const Vx=["bip86","tapkey","wallet"],ja=()=>({scheme:"bip86",roots:{},adopted:{}}),qx=e=>Ps.getPubKey(e)[0];function pd(e,t,n){return e.scheme==="wallet"?Ci(t,n):Ps.getSecKey(e.scheme==="tapkey"?Na(t,n):Ci(t,n))[0]}const gd=(e,t)=>e.scheme==="tapkey"?et.nostr(t):et.wallet(t),zx=(e,t)=>new dn(pd(e,t,0)),ct=e=>Se.encode(e,!1).hex;function hn(e,t,n){if(!n)return null;const r=i=>i?{mnemonic:i,account:0,origin:`${n.name} root`,steps:[]}:null;if(n.kind==="holding")return r(e.roots[n.id]);const s=t.nodes.get(n.parent);if(n.kind==="agent"){const i=hn(e,t,s);return i&&{...i,account:n.index+1}}if(n.edge==="adopted")return r(e.adopted[n.id]);const o=hn(e,t,s);return o&&{mnemonic:lx(o.mnemonic,n.index),account:0,origin:o.origin,steps:[...o.steps,`${n.index}'`]}}const ri=new Map;function Re(e,t,n){const r=hn(e,t,n);if(!r)return null;const s=`${e.scheme}|${r.mnemonic}|${r.account}`;if(!ri.has(s)){const{npub:u,pubkey:f}=fx(r.mnemonic,r.account);ri.set(s,{wallet:new dn(pd(e,r.mnemonic,r.account)),npub:u,pubkey:f})}const{wallet:o,npub:i,pubkey:a}=ri.get(s),c=[r.origin,...r.steps].join(" › ");return{wallet:o,npub:i,pubkey:a,scheme:e.scheme,account:r.account,from:c,path:`${c} · ${gd(e,r.account)}`}}function Fx(e,t,n){const r=hn(e,t,n);if(!r)return null;const s=Re(e,t,n),o=sd(r.mnemonic,r.account);return{taproot:{address:s.wallet.address,path:gd(e,r.account)},segwit:{address:Tr.p2wpkh.fromPubKey(o,"regtest"),path:et.segwit(r.account)},tapkey:{address:Tr.p2tr.fromPubKey(qx(s.pubkey),"regtest"),path:et.nostr(r.account)},npub:{address:s.npub,path:et.nostr(r.account)}}}function Ka(e,t,n){const r=La(e.chain,n);if(!r)return null;const s=ct(r.scriptPubKey),o=t.nodes.get(n),i=Re(e.keys,t,o),a=o&&Re(e.keys,t,t.nodes.get(o.parent));return i&&ct(i.wallet.script)===s?{wallet:i.wallet,who:"own"}:e.wallet&&ct(e.wallet.script)===s?{wallet:e.wallet,who:"lab"}:a&&ct(a.wallet.script)===s?{wallet:a.wallet,who:"parent"}:{wallet:null,who:"other",script:s}}function Eo(e,t){const n=e.nodes.get(t),r=[n];for(const s of n.children){const o=e.nodes.get(s);o.status==="active"&&o.edge==="derived"&&r.push(...Eo(e,s))}return r}function Li(e,t){const n=[];for(let r=t;r;r=e.nodes.get(r.parent))n.push(r.name);return n.join(".")}function Gx(e,t,n){const r=hn(e,t,n);if(!r)return null;if(n.kind!=="agent")return jx(Rx(Ua(r.mnemonic)),Li(t,n));const s=Li(t,t.nodes.get(n.parent));return Hx(Lx(Na(r.mnemonic,r.account)),`${n.name}@${s}`,n.name,s)}const Wx=Yf(nt),Sr=(e,t=239)=>Wx.encode(xe(Uint8Array.of(t),dt(e),Uint8Array.of(1))),Yx=e=>no.encode("nsec",no.toWords(dt(e))),Xx="0123456789()[],'/*abcdefgh@:$%{}IJKLMNOPQRSTUVWXYZ&+-.;<=>?!^_|~ijklmnopqrstuvwxyzABCDEFGH`#\"\\ ",Jx=[0xf5dee51989n,0xa9fdca3312n,0x1bab10e32dn,0x3706b1677an,0x644d626ffdn];function si(e){const t=(i,a)=>{const c=i>>35n;return i=(i&0x7ffffffffn)<<5n^BigInt(a),Jx.forEach((u,f)=>{c>>BigInt(f)&1n&&(i^=u)}),i};let n=1n,r=0,s=0;for(const i of e){const a=Xx.indexOf(i);if(a<0)throw new Error("Invalid descriptor character.");n=t(n,a&31),r=r*3+(a>>5),++s===3&&(n=t(n,r),r=0,s=0)}s&&(n=t(n,r));for(let i=0;i<8;i++)n=t(n,0);n^=1n;let o="";for(let i=0;i<8;i++)o+="qpzry9x8gf2tvdw0s3jn54khce6mua7l"[Number(n>>BigInt(5*(7-i))&31n)];return`${e}#${o}`}function Qx(e,t,n){const r=hn(e,t,n);if(!r)return null;const s=Na(r.mnemonic,r.account),o=Ci(r.mnemonic,r.account),i={bip86:`tr(${Sr(o)})`,tapkey:`tr(${Sr(s)})`,wallet:`rawtr(${Sr(o)})`}[e.scheme],a=n.kind==="agent",c=Li(t,a?t.nodes.get(n.parent):n);return{seed:a?null:{from:[r.origin,...r.steps].join(" › "),mnemonic:r.mnemonic},account:[["nsec","NIP-06",Yx(s)],["taproot","descriptor",si(i)],["segwit","descriptor",si(`wpkh(${Sr(rd(r.mnemonic,r.account))})`)],["tapkey","descriptor",si(`tr(${Sr(s)})`)]],leaves:a?Zx(s,`${n.name}@${c}`):Mx(Ua(r.mnemonic),c)}}const So="orgchain:lab:v1",e2=["each",10,30,60,"manual"];function Qr(e={tempo:"each",nextAt:null}){const{tempo:t,nextAt:n}=e??{},r=typeof t=="number";if(!e2.includes(t)||!(n===null||r&&Number.isSafeInteger(n)&&n>0))throw new Error("Invalid clock.");return{tempo:t,nextAt:n}}function md(e){const t=ja();for(const n of["roots","adopted"])for(const[r,s]of Object.entries((e==null?void 0:e[n])??{})){if(!/^[0-9a-f]{64}i0$/.test(r))throw new Error("Invalid lab keys.");t[n][r]=nd(s,24)}if(t.scheme=(e==null?void 0:e.scheme)??(Object.keys(t.roots).length?"wallet":"bip86"),!Vx.includes(t.scheme))throw new Error("Invalid lab keys.");return t}const t2=["split","last"];function es(e){const t=(e==null?void 0:e.rule)??"split",n={};if(!t2.includes(t))throw new Error("Invalid mining rule.");for(const[r,s]of Object.entries((e==null?void 0:e.rigs)??{})){if(!/^[0-9a-f]{64}i0$/.test(r)||!Number.isSafeInteger(s)||s<0||s>9)throw new Error("Invalid hashrate.");s!==1&&(n[r]=s)}return{rule:t,rigs:n}}const ts=()=>({wallet:null,chain:new yo,clock:Qr(),keys:ja(),mining:es()});function yd(e){if(!e)return ts();const t=JSON.parse(e);if((t==null?void 0:t.kind)!=="orgchain-lab"||t.network!==en||t.version!==1)throw new Error("That is not an Orgchain v1 lab.");return{wallet:t.wallet?dn.load(t.wallet):null,chain:new yo(t.chain),clock:Qr(t.clock),keys:md(t.keys),mining:es(t.mining)}}const bd=e=>{var t;return JSON.stringify({kind:"orgchain-lab",network:en,version:1,wallet:((t=e.wallet)==null?void 0:t.backup())??null,chain:e.chain.snapshot(),clock:Qr(e.clock),keys:md(e.keys),mining:es(e.mining)})};function n2(e,t,n){var r;e.mining=es({...e.mining,rigs:{...(r=e.mining)==null?void 0:r.rigs,[t]:n}})}function r2(e,t){e.mining=es({...e.mining,rule:t})}const Da=()=>yd(localStorage.getItem(So));function s2(e){try{localStorage.setItem(So,bd(e))}catch{throw new Error("Browser storage is full or unavailable, so nothing was saved. Save a backup, then reset.")}}async function o2(e,{locks:t=(s=>(s=globalThis.navigator)==null?void 0:s.locks)(),read:n=Da,save:r=s2}={}){if(!t)throw new Error("Orgchain needs Web Locks: open it over HTTPS or on localhost.");return t.request(So,async()=>{const o=n(),i=await e(o);return i!==!1&&r(o),{lab:o,result:i}})}function pn(e,t=null){e.wallet||(e.wallet=dn.create());const n=t!=null&&t.length?e.chain.mineTo(t.map(r=>De(r.value,r.script))):e.chain.mine(e.wallet.script);return e.clock=Qr({tempo:e.clock.tempo,nextAt:null}),n}function ko(e,t=Date.now()){const{tempo:n,nextAt:r}=e.clock;typeof n=="number"&&e.chain.mempool.length&&r===null&&(e.clock={tempo:n,nextAt:t+n*1e3})}function i2(e,t,n=Date.now(),r=null){e.clock=Qr({tempo:t,nextAt:null}),t==="each"&&e.chain.mempool.length?pn(e,r):ko(e,n)}function a2(e,t=Date.now(),n=null){const{tempo:r,nextAt:s}=e.clock;return typeof r!="number"||!e.chain.mempool.length?!1:s===null?(ko(e,t),!0):t(e/_o).toFixed(8).replace(/\.?0+$/,""),ye=e=>`${wd(e)} tBTC`;function Za(e){if(e<1e6)return ye(e);const t=Math.round(e/1e6)*1e6;return`${t===e?"":"≈"}${ye(t)}`}function c2(e){const t=/^\s*(\d{0,7})(?:\.(\d{0,8}))?\s*$/.exec(String(e??""));return!t||!(t[1]||t[2])?null:Number(t[1]||0)*_o+Number((t[2]??"").padEnd(8,"0"))}class u2{constructor(t,n,r){this.secret=t,this.pubkey=n,this.path=r,this.address=Tr.p2wpkh.fromPubKey(n,"regtest"),this.script=Tr.toScriptPubKey(this.address)}sign(t,n){return[fo.segwit.sign(this.secret,t,n,{pubkey:this.pubkey}).hex,this.pubkey]}}const oi=new Map;function je(e,t,n){const r=hn(e,t,n);if(!r)return null;const s=`${r.mnemonic}|${r.account}`;return oi.has(s)||oi.set(s,new u2(rd(r.mnemonic,r.account),sd(r.mnemonic,r.account),et.segwit(r.account))),oi.get(s)}function l2(e,t,n){var s;const r=n?t.nodes.get(n):null;return(r==null?void 0:r.kind)==="holding"&&r.status==="active"?((s=je(e,t,r))==null?void 0:s.script)??null:null}const Jn=(e,t)=>{var n,r;return((r=(n=e.mining)==null?void 0:n.rigs)==null?void 0:r[t])??1};function Ma(e,t){return t.roots.filter(n=>n.status==="active"&&Jn(e,n.id)>0&&je(e.keys,t,n)).slice(0,Mf)}function xd(e,t,n){var i;if(((i=e.mining)==null?void 0:i.rule)==="last"){const a=l2(e.keys,t,n);return a?[{script:a,value:Ct}]:null}const r=Ma(e,t),s=r.reduce((a,c)=>a+Jn(e,c.id),0);let o=Ct;return r.length?r.map((a,c)=>{const u=c===r.length-1?o:Math.floor(Ct*Jn(e,a.id)/s);return o-=u,{script:je(e.keys,t,a).script,value:u}}):null}function vd(e,t){const n=t+he,r=a=>a===n||a-n>=tt&&a-n<=Ct,s=[...e].sort((a,c)=>a.value-c.value),o=s.find(a=>r(a.value));if(o)return[o];let i=null;for(let a=0;ar.value).sort((r,s)=>s-r),n=[];if(t.length&&n.push(t[0]-he),t.length>1){const r=t[0]+t[1]-he;n.push(r<=Ct?r:r-Ct>=tt?Ct:r-tt)}return Math.max(0,...n.filter(r=>r>=tt&&r<=Ct))}function f2(e,t,n){const r=t.reduce((c,u)=>c+u.value,0),s=n+he,o=Va(t);if(rc.value),...t.flatMap((c,u)=>t.slice(u+1).map(f=>c.value+f.value))],a=Math.min(...i.filter(c=>c>=s));return Number.isFinite(a)&&a-s!!vd(e,t),d2=(e,t,n)=>Ed(e.chain.coins(t.script),n);function Sd(e,t,n,r,s="This node"){const o=e.chain.coins(t.script),i=vd(o,r);if(!i)throw new Error(f2(s,o,r));const a=i.reduce((f,l)=>f+l.value,0)-r-he,c=ce.create({vin:i.map(f=>nn(f.txid,f.vout,f.value,f.scriptPubKey)),vout:[De(r,n),...a?[De(a,t.script)]:[]]});i.forEach((f,l)=>{c.vin[l].witness=t.sign(c,l)});const u=ce.encode(c).hex;return e.chain.submitPackage([u]),ce.util.getTxid(u)}function kd(e,t,n,r,s){const o=t.nodes.get(n),i=t.nodes.get(r);if(!o||!i)throw new Error("Pick who sends and who receives.");if(o.id===i.id)throw new Error(`${o.name} cannot send to itself.`);for(const u of[o,i])if(u.status!=="active")throw new Error(`${u.name} is ${u.status}.`);const a=je(e.keys,t,o),c=je(e.keys,t,i);if(!a||!c)throw new Error("A holding that predates lab keys has no SegWit addresses.");if(!Number.isSafeInteger(s)||sCt)throw new Error("Send at most 50 test BTC at a time: no output on this chain is bigger than one block reward.");return Sd(e,a,c.script,s,o.name)}function h2(e,t,n){if(!t||!n||ct(t.script)===ct(n.script))return 0;let r=0;for(const s of e.chain.coins(t.script)){if(s.value-he[t,...t.log.flatMap((n,r)=>n.ok&&n.op==="graduate"?[Un(e.slice(0,r),{pending:!0})]:[])];function $d(e,t){const n=new Map;for(const r of e)for(const s of r.nodes.values()){const o=t(r,s);o&&!n.has(o)&&n.set(o,s.id)}return n}const p2=(e,t,n)=>$d(_d(t,n),(r,s)=>{const o=je(e,r,s);return o&&ct(o.script)}),ii=new Map,g2=(e,t,n)=>$d(_d(t,n),(r,s)=>{const o=hn(e,r,s),i=o&&`${e.scheme}|${o.mnemonic}|${o.account}`;return i&&!ii.has(i)&&ii.set(i,ct(Re(e,r,s).wallet.script)),i?ii.get(i):null}),Ad=(e,t)=>e.coins(t.script).filter(n=>{var r;return!((r=n.inscriptions)!=null&&r.length)}).reduce((n,r)=>n+r.value,0);function m2(e,t,n=new Map){var i;const r=[],s=a=>t.get(ct(a))??null,o=a=>a.reduce((c,u)=>c+u.value,0);for(const{txid:a,tx:c,height:u,coinbase:f}of e.transactions.values()){const l=c.vout.map(w=>({script:ct(w.scriptPubKey),node:s(w.scriptPubKey),value:Number(w.value)}));if(f){l.forEach((w,b)=>{w.node&&r.push({kind:"mine",key:`${a}:${b}`,txid:a,beat:u,from:null,to:w.node,amount:w.value,fee:0,change:0})});continue}const d=c.vin.map(w=>{var T;const b=(T=e.transactions.get(w.txid))==null?void 0:T.tx.vout[w.vout];return b?{node:s(b.scriptPubKey),value:Number(b.value)}:null}),h=(i=d[0])==null?void 0:i.node;if(!h||!d.every(w=>(w==null?void 0:w.node)===h))continue;const m=l.filter(w=>w.node!==h),y=l.filter(w=>w.node===h),g=o(d)-o(l),p={key:a,txid:a,beat:u,from:h,fee:g};m.length&&m.every(w=>n.get(w.script)===h)?r.push({...p,kind:"gas",to:h,amount:o(m),change:o(y)}):m.length?r.push({...p,kind:"pay",to:m[0].node,amount:m[0].value,change:o(y)}):r.push({...p,kind:"move",to:h,amount:o(y),change:0})}return r}function Ri(e,t,n=1/0){const r=new Map;for(const{txid:o,tx:i,height:a,coinbase:c}of e.transactions.values())if(!(a===null?n!==1/0:a>n)){if(!c)for(const u of i.vin)r.delete(`${u.txid}:${u.vout}`);i.vout.forEach((u,f)=>{const l=t.get(ct(u.scriptPubKey));l&&r.set(`${o}:${f}`,{node:l,value:Number(u.value)})})}const s=new Map;for(const{node:o,value:i}of r.values())s.set(o,(s.get(o)??0)+i);return s}const Zc={found:["name"],birth:["name","kind"],award:["to","skill","belt"],decide:["title","why"],graduate:["of"],close:[]},y2={found:e=>`found ${e.name}`,birth:e=>`birth ${e.name}`,award:e=>`award ${e.skill} ${e.belt}`,decide:e=>`decide ${e.title}`,graduate:()=>"graduate",close:()=>"close"};function b2(e,t={}){if(!Object.hasOwn(Zc,e))throw new Error("Unknown verb.");const n={op:e};for(const r of Zc[e]){const s=t[r];typeof s=="string"&&s.trim()&&(n[r]=s.trim())}return n}const sn=e=>Un(Sa(new po(e.chain)),{pending:!0});function Bd(e,t,n,r){const s=b2(t,r),o=Sa(new po(e.chain)),i={id:"check",status:"pending",height:null,metadata:s,parent:n??null,protocol:va},{ok:a,why:c}=Un([...o,i],{pending:!0}).log.at(-1);if(!a)throw new Error(`${c[0].toUpperCase()}${c.slice(1)}.`);return s}const Hi=bt+2*he+330,Td=1e5,qa=1e4,za=(e,t=0)=>bt+2*he+(e==="birth"?1:e==="graduate"?Math.max(0,t-1):0)*he+330,w2=(e,t=0)=>za(e,t)-330,ur=(e,t,n)=>e.chain.coins(t.script).find(r=>{var s;return!((s=r.inscriptions)!=null&&s.length)&&r.value>=n}),ji=e=>nn(e.txid,e.vout,e.value,e.scriptPubKey),Id=(e,t)=>(t.forEach((n,r)=>{e.vin[r].witness=[n.sign(e,void 0,r)]}),ce.encode(e).hex);function Od(e){e.keys??(e.keys=ja()),e.wallet||(e.wallet=dn.create()),ur(e,e.wallet,Td+he+330)||pn(e)}function Cd(e,t,n=Hi,r=Td){if(t===e.wallet||ur(e,t,n))return;const s=ur(e,e.wallet,r+he+330),o=ce.create({vin:[ji(s)],vout:[De(r,t.script),De(s.value-r-he,e.wallet.script)]});e.chain.submitPackage([Id(o,[e.wallet])])}function Mc(e,t,n,r,s){if(r===e.wallet||ur(e,r,s))return;const o=n&&je(e.keys,t,n);if(!o)return Cd(e,r,s);Sd(e,o,r.script,Math.max(qa,s),n.name)}function x2(e,t,n,r,s){if(r===e.wallet||ur(e,r,s))return!0;const o=n&&je(e.keys,t,n);return!o||d2(e,o,Math.max(qa,s))}function Pd(e,t,n,r,s={}){var f;const o=r?t.nodes.get(r):null,i=o&&((f=Ka(e,t,r))==null?void 0:f.wallet);if(n==="found"||!i)return"";const a=n==="graduate"?t.nodes.get(s.of):null,c=a&&Re(e.keys,t,a)?Eo(t,a.id).length:0;if(!x2(e,t,o,i,za(n,c))){const l=t.nodes.get(o.parent);return l?`${o.name} has no test BTC for gas. ${l.name} can send some`:`${o.name} has no test BTC for gas. It earns some each beat it mines`}const u=c?je(e.keys,t,a):null;return u&&!Ed(e.chain.coins(u.script).filter(l=>l.value-he>=tt).map(l=>({value:l.value-he})),qa)?`${a.name} needs test BTC of its own to claim its new root. Send it some first`:""}function Vc(e,t,n,r,s=n){const o=La(e.chain,t),i=ur(e,s,he+330),a=ce.create({vin:[ji(o),ji(i)],vout:[De(o.value,r.script),De(i.value-he,s.script)]});e.chain.submitPackage([Id(a,[n,s])])}function qc(e,t,n,r,s){return new Cw(e.chain,t).inscribe(y2[n](s),r??null,s,{metaprotocol:va})}const Ud=(e,t)=>{var r;const n=sn(e);return xd(e,n,((r=n.nodes.get(t))==null?void 0:r.root)??null)},$o=(e,t)=>xd(e,sn(e),t);function zc(e,t,n){var s;const r=Ka(e,t,n);if(!(r!=null&&r.wallet))throw new Error(`No key in this lab holds ${((s=t.nodes.get(n))==null?void 0:s.name)??"that node"}'s inscription.`);return r.wallet}function Nd(e,t,n,r){if(t==="found"){const f=Rc(),l=zx(e.keys,f);Cd(e,l,Hi,Hi);const d=qc(e,l,t,null,r);return e.keys.roots[d]=f,d}const s=sn(e),o=zc(e,s,n),i=s.nodes.get(n),a=t==="graduate"?s.nodes.get(r.of):null,c=a&&Re(e.keys,s,a)?Eo(s,a.id).map(f=>[f.id,zc(e,s,f.id)]):[];Mc(e,s,i,o,za(t,c.length));const u=qc(e,o,t,n,r);if(t==="birth"){const f=sn(e),l=Re(e.keys,f,f.nodes.get(u));l&&Vc(e,u,o,l.wallet)}if(c.length){e.keys.adopted[a.id]=Rc();const f=sn(e);for(const[l,d]of c){const h=Re(e.keys,f,f.nodes.get(l)).wallet;if(h2(e,je(e.keys,s,s.nodes.get(l)),je(e.keys,f,f.nodes.get(l))),l!==a.id){Vc(e,l,d,h,o);continue}Mc(e,f,f.nodes.get(l),h,he+330),px(e.chain,hx(e.chain,l,h),d)}}return u}function v2(e,t,n,r,s=Date.now()){const o=Bd(e,t,n,r),i=Pd(e,sn(e),t,n??null,o);if(i)throw new Error(`${i}.`);Od(e);const a=Nd(e,t,n??null,o);return e.clock.tempo==="each"?pn(e,Ud(e,n??a)):ko(e,s),a}function E2(e,t,n,r,s=Date.now()){const o=kd(e,sn(e),t,n,r);return e.clock.tempo==="each"?pn(e,Ud(e,t)):ko(e,s),o}const Ki="yolopreneur",S2=[[["found",null,{name:"yolopreneur"}]],[["birth","yolopreneur",{name:"well-known",kind:"org"}],["birth","yolopreneur",{name:"time",kind:"org"}]],[["send","yolopreneur",{to:"time",amount:40}],["send","yolopreneur",{to:"well-known",amount:10}],["birth","well-known",{name:"mailr",kind:"org"}],["birth","well-known",{name:"lineage",kind:"org"}],["birth","time",{name:"luna",kind:"agent"}],["birth","time",{name:"sol",kind:"agent"}],["birth","time",{name:"astra",kind:"agent"}]],[["send","well-known",{to:"lineage",amount:2}],["birth","time",{name:"docscope",kind:"org"}],["birth","time",{name:"dollhouse",kind:"org"}],["birth","time",{name:"doodleloop",kind:"org"}],["birth","time",{name:"hearthframe",kind:"org"}]],[["send","time",{to:"sol",amount:1}],["send","time",{to:"luna",amount:.5}],["award","time",{to:"sol",skill:"launch",belt:"green"}],["award","time",{to:"luna",skill:"post",belt:"white"}],["decide","yolopreneur",{title:"Every venture gets a page",why:".yolopreneur.lol, served from one pages branch."}]],[["graduate","well-known",{of:"lineage"}],["decide","lineage",{title:"Lineage gets its own org",why:"Its own repo on Teahub now, lineage.llc later: adopted, not derived."}]]];function k2(e){Od(e),e.chain.mempool.length&&pn(e);const t={};for(const n of S2){for(const[r,s,o]of n){if(r==="send"){kd(e,sn(e),t[s],t[o.to],o.amount*_o);continue}const i=Object.fromEntries(Object.entries(o).map(([u,f])=>[u,u==="to"||u==="of"?t[f]:f])),a=s?t[s]:null,c=Nd(e,r,a,Bd(e,r,a,i));(r==="found"||r==="birth")&&(t[o.name]=c)}pn(e,$o(e,t[Ki]))}return t[Ki]}const V=e=>document.getElementById(e);function $(e,t={},...n){const r=document.createElement(e);for(const[s,o]of Object.entries(t))o==null||o===!1||(s==="class"?r.className=o:s==="text"?r.textContent=o:s.startsWith("on")?r.addEventListener(s.slice(2),o):r.setAttribute(s,o===!0?"":String(o)));for(const s of n.flat(1/0))s!=null&&s!==!1&&s!==""&&r.append(s instanceof Node?s:String(s));return r}const $r=(e,t)=>`${e} ${t}${e===1?"":"s"}`,An=e=>e==="cued"?"cued":`beat ${e}`,_2=e=>new Date(e).toLocaleTimeString([],{hour:"2-digit",minute:"2-digit",second:"2-digit"}),Fc=e=>JSON.stringify(e,(t,n)=>typeof n=="bigint"?String(n):n,2),B={holding:null,node:null,event:null,tx:null,beat:null,verb:"birth",busy:!1,replay:null,closing:null,reveal:null};let z=ts(),so=new po(z.chain),wn=[],Q=Un([]),Ge=Q,Ze={owner:new Map,ledger:[],now:new Map,view:new Map};const We=()=>z.chain.blocks.length,Di=()=>wn.filter(e=>e.status==="pending").length,Zi=()=>Ze.ledger.filter(e=>e.beat===null&&e.kind==="pay").length,$2=()=>Di()+Zi(),_s=e=>Ze.view.get(e)??0,Ld=e=>Ze.now.get(e)??0,se=(e,t=Q)=>e?t.nodes.get(e)??null:null,Rd=e=>Object.assign(B,{event:null,tx:null,closing:null,reveal:null},e),ns=e=>{Rd(e),Ao()};function Ae(e,t=!1){const n=V("say");n.textContent=e,n.classList.toggle("bad",t)}function Hd(){try{z=Da()}catch(e){z=ts(),Ae(`This browser's saved lab could not be read (${e.message}) Load a backup, or reset to start over.`,!0)}Fa()}function Fa(){var t;so=new po(z.chain),wn=Sa(so),Q=Un(wn,{pending:!0}),B.beat!==null&&B.beat>=We()&&(B.beat=null),se(B.holding)||(B.holding=((t=Q.roots.at(-1))==null?void 0:t.id)??null),(!se(B.node)||se(B.node).root!==B.holding)&&(B.node=B.holding),B.event&&!Q.log.some(n=>n.id===B.event)&&(B.event=null),Ge=B.beat===null?Q:Un(wn,{upTo:B.beat});const e=p2(z.keys,wn,Q);Ze={owner:e,ledger:m2(z.chain,e,g2(z.keys,wn,Q)),now:Ri(z.chain,e)},Ze.view=B.beat===null?Ze.now:Ri(z.chain,e,B.beat),B.tx&&!Ze.ledger.some(n=>n.key===B.tx)&&(B.tx=null),Ao()}function oo(e){B.beat=e>=We()?null:Math.max(0,e),Ge=B.beat===null?Q:Un(wn,{upTo:B.beat}),Ze.view=B.beat===null?Ze.now:Ri(z.chain,Ze.owner,B.beat),Ao()}async function gn(e,t){if(B.busy)return!1;B.busy=!0,document.body.classList.add("busy");try{return z=(await o2(e,t)).lab,!0}catch(n){return Ae((n==null?void 0:n.message)||String(n),!0),!1}finally{B.busy=!1,document.body.classList.remove("busy"),Fa()}}async function br(e,t,n,r){let s=null;if(!await gn(i=>{s=v2(i,e,t,n)}))return!1;const o=so.events.find(i=>i.id===s);return Ae(r(s,(o==null?void 0:o.status)==="confirmed"?`at beat ${o.height}`:"cued for the next beat")),Ao(),!0}async function jd(e){const t=Di(),n=Zi(),r=We();if(!await gn(e)||We()===r)return;const s=[[t-Di(),"cued act"],[n-Zi(),"cued send"]].filter(([i])=>i>0).map(([i,a])=>$r(i,a)),o=A2(Ze.ledger.filter(i=>i.kind==="mine"&&i.beat===We()));Ae(`Beat ${We()}: ${s.length?`${s.join(" and ")} landed, and ${o}`:o}.`)}function A2(e){if(!e.length)return"the lab wallet earned 50 tBTC";const t=e.map(r=>{var s;return((s=se(r.to))==null?void 0:s.name)??"?"}),n=e.map(r=>Za(r.amount));return e.length===1?`${t[0]} earned ${ye(e[0].amount)}`:n.every(r=>r===n[0])?`${t.slice(0,-1).join(", ")} and ${t.at(-1)} earned ${n[0]} each`:e.map((r,s)=>`${t[s]}${s?"":" earned"} ${n[s]}`).join(", ")}function B2(){var t;if(((t=z.mining)==null?void 0:t.rule)==="last")return"the holding that acts";const e=Ma(z,Q);return e.length?e.length===1?e[0].name:`${e.length} holdings, split by hashrate`:"the lab wallet"}function Ao(){Kd(),I2(),O2(),Bo(),zd(),Ga()}function Kd(){const e=$2(),{tempo:t}=z.clock;for(const r of document.querySelectorAll("[data-tempo]"))r.setAttribute("aria-pressed",String(String(t)===r.dataset.tempo));V("clock-beat").textContent=String(We()),V("clock-cued").textContent=e?`${e} cued · ${T2()}`:"nothing cued";const n=B2();V("clock-pays").textContent=`beats pay ${n}`,V("beat-now").title=`Beat now: ${e?"land what is cued, and ":""}pay ${n} 50 test BTC`}function T2(){const{tempo:e,nextAt:t}=z.clock;return e==="manual"?"waiting for Beat now":typeof e=="number"&&t?`next beat in ${Math.max(0,Math.ceil((t-Date.now())/1e3))}s`:"landing on the next beat"}function I2(){var r,s;const e=((r=z.mining)==null?void 0:r.rule)!=="last",t=e?Ma(z,Q):[],n=t.reduce((o,i)=>o+Jn(z,i.id),0);V("holdings-list").replaceChildren(...Q.roots.map(o=>{const i=Rw(Q,o.id),a=o.id===B.holding,c=o.status==="active",u=t.some(d=>d.id===o.id)?Jn(z,o.id)/n:0,f=[...Q.nodes.values()].reduce((d,h)=>d+(h.root===o.id?Ld(h.id):0),0),l=[An(o.born),$r(i.orgs,"org"),$r(i.agents,"agent"),$r(i.belts,"belt"),f>0&&Za(f),e&&c&&(u?`${Math.round(u*100)}% of each beat`:"not mining"),!c&&"closed"].filter(Boolean);return $("li",{},$("button",{type:"button",class:`hold${a?" on":""}${c?"":" gone"}`,"aria-pressed":String(a),onclick:()=>ns({holding:o.id,node:o.id})},$("span",{class:"hn",text:o.name})," ",$("span",{class:"hm",text:l.join(" · ")})),e&&c&&je(z.keys,Q,o)&&U2(o,Jn(z,o.id)))}));for(const o of document.querySelectorAll("[data-rule]"))o.setAttribute("aria-pressed",String((((s=z.mining)==null?void 0:s.rule)??"split")===o.dataset.rule));V("mining-note").textContent=e?"Every active holding mines: each beat's 50 tBTC splits by hashrate, set on each holding (0 sits out).":"The holding that acts takes the whole beat, and Beat now pays the one you're working in. Every act costs gas, so it's a race.",V("holdings-empty").hidden=Q.roots.length>0,V("holdings-sub").textContent=Q.roots.length?String(Q.roots.length):"",V("sample").disabled=Q.roots.some(o=>o.name===Ki&&o.status==="active")}function O2(){var r;const e=V("tree-rows"),t=se(B.holding);if(V("tree-sub").textContent=t?`${t.name} · ${B.beat===null?"now":`beat ${B.beat} of ${We()}`}`:"",!t)return e.replaceChildren($("p",{class:"wait",text:"No holding yet. Found one, or load the yolopreneur sample."}));if(!Ge.nodes.has(t.id))return e.replaceChildren($("p",{class:"wait",text:`${t.name} is founded at ${An(t.born)}. Move the slider forward.`}));const n=e.contains(document.activeElement)?document.activeElement.dataset.id:null;e.replaceChildren(...Lw(Ge,t.id).map(s=>s.type==="group"?$("div",{class:"row grp"},$("span",{class:"g","aria-hidden":"true",text:s.guide}),$("span",{class:"gl",text:s.label})):C2(s))),n&&((r=e.querySelector(`[data-id="${n}"]`))==null||r.focus())}function C2({node:e,guide:t,path:n}){const r=e.id===B.node,s=["row",r&&"on",e.status==="closed"&&"gone",e.born==="cued"&&"cue"].filter(Boolean).join(" ");return $("div",{class:s},$("button",{type:"button",class:"sel","data-id":e.id,"aria-pressed":String(r),onclick:()=>ns({node:e.id})},$("span",{class:"g","aria-hidden":"true",text:t}),$("span",{class:"p",text:`${n} `}),$("span",{class:"l",text:e.name})," ",$("span",{class:"v"},P2(e))))}function P2(e){return[e.kind==="agent"&&$("span",{class:"mk",text:"agent"}),e.edge==="adopted"&&$("span",{class:"mk ok",text:"graduated"}),e.status==="closed"&&$("span",{class:"mk bad",text:"closed"}),e.born==="cued"&&$("span",{class:"mk",text:"cued"}),...e.badges.map(Dd),_s(e.id)>0&&$("span",{class:"mk sats",title:`${ye(_s(e.id))} at its SegWit address`,text:Za(_s(e.id))})].filter(Boolean).flatMap((n,r)=>r?[" ",n]:[n])}const Dd=e=>$("span",{class:`belt ${e.belt}`,title:`${e.skill}: ${e.belt} belt`},e.skill,$("span",{class:"sr",text:` (${e.belt} belt)`})),Zd=(e,t)=>{for(let n=se(e.parent);n;n=se(n.parent))if(n.id===t.id)return!0;return!1},Md=e=>[...Q.nodes.values()].filter(t=>t.root===e.root&&t.id!==e.id&&t.status==="active").map(t=>[t,(Zd(t,e)?0:2)+(t.kind==="agent"?0:1)]).sort((t,n)=>t[1]-n[1]).map(([t])=>t),Vd=e=>e.children.reduce((t,n)=>{const r=se(n);return r&&r.edge==="derived"&&r.status==="active"?t+1+Vd(r):t},0);function U2(e,t){const n=async r=>{await gn(s=>n2(s,e.id,r))&&Ae(r?`${e.name} mines at hashrate ${r}.`:`${e.name} sits out of mining.`)};return $("span",{class:"rig"},$("span",{class:"rl",text:"hashrate"}),$("span",{class:"rn"},$("button",{type:"button",class:"rb","aria-label":`Lower ${e.name}'s hashrate`,disabled:t<=0,onclick:()=>n(t-1)},"−"),$("b",{text:String(t)}),$("button",{type:"button",class:"rb","aria-label":`Raise ${e.name}'s hashrate`,disabled:t>=9,onclick:()=>n(t+1)},"+")))}const qd=e=>[...Q.nodes.values()].filter(t=>t.id!==e.id&&t.status==="active").map(t=>[t,(t.root===e.root?0:4)+(Zd(t,e)?0:2)+(t.kind==="agent"?0:1)]).sort((t,n)=>t[1]-n[1]).map(([t])=>t);function N2(e){const t=je(z.keys,Q,e),n=se(e.parent);return t?Va(z.chain.coins(t.script))Pd(z,Q,s,o,i);return{birth:n||(e.kind==="agent"?"Agents do not give birth":r("birth")),award:n||(e.kind==="agent"?"Agents do not award belts":Md(e).length?r("award"):"There is nobody else in this holding to award yet"),decide:n||r("decide"),send:n||N2(e),graduate:n||(t?e.kind!=="org"?"Only orgs graduate":e.edge==="adopted"?`${e.name} has already graduated`:t.status!=="active"?`${t.name} is closed`:r("graduate",t.id,{of:e.id}):"A holding has no parent to graduate from"),close:n||r("close")}}function Bo(){const e=se(B.node),t=B.beat!==null;if(V("act-none").hidden=!!e,V("act-past").hidden=!e||!t,V("act-on").hidden=!e||t,V("act-sub").textContent=(e==null?void 0:e.name)??"",V("past-beat").textContent=String(B.beat??""),!e||t)return;const n=L2(e),r=se(e.parent);for(const l of document.querySelectorAll("[data-verb]"))l.setAttribute("aria-pressed",String(l.dataset.verb===B.verb)),l.classList.toggle("off",!!n[l.dataset.verb]);for(const l of document.querySelectorAll("form[data-form]"))l.hidden=l.dataset.form!==B.verb||!!n[B.verb];V("act-why").textContent=n[B.verb]?`${n[B.verb]}.`:"";for(const l of document.querySelectorAll("#act-on [data-name]"))l.textContent=e.name;for(const l of document.querySelectorAll("#act-on [data-parent]"))l.textContent=(r==null?void 0:r.name)??"";const s=l=>l.map(d=>`${d.value}=${d.textContent}`).join("|");for(const[l,d]of[[V("award-to"),Md(e)],[V("send-to"),qd(e)]]){const h=l.value,m=d.map(y=>$("option",{value:y.id,text:`${go(Q,y.id)}${y.kind==="agent"?" (agent)":""}`}));s(m)!==s([...l.options])&&(l.replaceChildren(...m),m.some(y=>y.value===h)&&(l.value=h))}V("send-has").textContent=ye(Ld(e.id)),V("graduate-go").textContent=`Graduate ${e.name}`;const o=B.verb==="graduate"?r:e,i=o&&Re(z.keys,Q,o),a=i&&(B.verb==="send"?`${i.from} · ${je(z.keys,Q,o).path}`:i.path);V("act-key").textContent=!o||n[B.verb]?"":i?`Signs as ${o.name}: ${a}`:"Signs with the lab wallet: this holding predates lab keys.";const c=B.verb==="graduate"&&Re(z.keys,Q,e)?Eo(Q,e.id).length:0;V("act-gas").textContent=!o||n[B.verb]||!i?"":B.verb==="send"?`Fee: ${he} sats, from ${e.name}'s balance.`:`Gas: ${w2(B.verb,c).toLocaleString("en-US")} sats from ${o.name}'s tank (${ye(Ad(z.chain,i.wallet))}), which tops up from its balance.${c?` ${e.name} pays ${he} more, from its own money, to claim its new root.`:""}`;const u=Vd(e),f=B.closing===e.id;V("close-note").textContent=u?`Closing ${e.name} spends it for the last time, and its ${$r(u,"derived descendant")} close with it. Graduated children hold their own roots and stay open.`:`Closing ${e.name} spends its inscription for the last time. Nothing can act through it afterwards.`,V("close-go").textContent=f?`Yes, close ${e.name}`:`Close ${e.name}`,V("close-keep").hidden=!f}function zd(){const e=V("inspect-body"),t=B.event?Q.log.find(o=>o.id===B.event):null;if(t)return V("inspect-sub").textContent="event",e.replaceChildren(...z2(t));const n=B.tx?Ze.ledger.find(o=>o.key===B.tx):null;if(n)return V("inspect-sub").textContent="money",e.replaceChildren(...F2(n));const r=se(B.node);if(V("inspect-sub").textContent=(r==null?void 0:r.kind)??"",!r)return e.replaceChildren($("p",{class:"note pad",text:"Select a node in the tree, or an event in the timeline."}));const s=se(B.node,Ge);if(!s)return e.replaceChildren($("p",{class:"note pad",text:`${r.name} is not born yet at beat ${B.beat}.`}));e.replaceChildren(...R2(s))}const Vr=([e,t,n])=>$("div",{class:"f"},$("dt",{text:e}),$("dd",{},t,n&&$("span",{class:"fn",text:n})));function R2(e){const t=se(e.parent,Ge),n=[["Born",e.born==="cued"?"cued for the next beat":`beat ${e.born}`],t&&["Parent",`${t.name} · ${e.kind} ${e.index}'`],t&&["Edge",e.edge==="adopted"?`adopted at ${An(e.graduated)}: it holds its own root`:`derived: ${t.name} holds its seed`],e.closed!==null&&["Closed",An(e.closed)],["Children",e.children.length?e.children.map(r=>{var s;return(s=se(r,Ge))==null?void 0:s.name}).join(", "):"none yet"],je(z.keys,Ge,e)&&["Balance",ye(_s(e.id)),`Test BTC at its SegWit address${B.beat===null?"":`, as of beat ${B.beat}`}.`],B.beat===null&&Re(z.keys,Q,e)&&["Gas tank",ye(Ad(z.chain,Re(z.keys,Q,e).wallet)),"Plain coins at its Taproot key. Its acts burn their fees from here, and the tank tops up from its balance, 0.0001 tBTC at a time."],["Inscription",e.id]].filter(Boolean);return[$("div",{class:"ih"},$("p",{class:"eyebrow",text:go(Ge,e.id)}),$("h3",{class:"it",text:e.name}),$("div",{class:"chips"},$("span",{class:"chip",text:e.kind}),$("span",{class:`chip ${e.status==="active"?"ok":"bad"}`,text:e.status}),e.edge==="adopted"&&$("span",{class:"chip ok",text:"graduated"}),e.born==="cued"&&$("span",{class:"chip",text:"cued"}))),$("div",{class:"ib"},$("dl",{class:"fl"},n.map(Vr)),e.badges.length>0&&$("div",{},$("p",{class:"lab",text:"Belts"}),$("ul",{class:"list"},e.badges.map(r=>{var s;return $("li",{},Dd(r),$("span",{class:"when",text:` from ${((s=se(r.by))==null?void 0:s.name)??"?"}, ${An(r.beat)}`}))}))),e.decisions.length>0&&$("div",{},$("p",{class:"lab",text:"Decisions"}),$("ul",{class:"list"},e.decisions.map(r=>$("li",{},$("b",{text:r.title}),r.why&&` · ${r.why}`,$("span",{class:"when",text:` (${An(r.beat)})`}))))),H2(e),Z2(e))]}function H2(e){const t=Ze.ledger.filter(n=>(n.to===e.id||n.from===e.id)&&(B.beat===null||n.beat!==null&&n.beat<=B.beat)).slice(-6).reverse();return t.length>0&&$("div",{},$("p",{class:"lab",text:"Money"}),$("ul",{class:"list"},t.map(n=>$("li",{},$("b",{text:j2(n,e.id)}),$("span",{class:"when",text:` (${An(n.beat??"cued")})`})))))}function j2(e,t){const n=r=>{var s;return((s=se(r))==null?void 0:s.name)??"?"};return e.kind==="mine"?`+${ye(e.amount)}, a beat's reward`:e.kind==="move"?`${ye(e.amount)} moved to its new key, after a ${e.fee}-sat fee`:e.kind==="gas"?`−${ye(e.amount)} into its gas tank, and a ${e.fee}-sat fee`:e.to===t?`+${ye(e.amount)} from ${n(e.from)}`:`−${ye(e.amount)} to ${n(e.to)}, and a ${e.fee}-sat fee`}function Fd(e){const t=n=>{const r=se(n);return r?r.root===B.holding?r.name:go(Q,n):"?"};return e.kind==="mine"?`${ye(e.amount)} → ${t(e.to)}`:e.kind==="move"?`${ye(e.amount)} → ${t(e.to)}'s new key`:e.kind==="gas"?`${ye(e.amount)} → ${t(e.to)}'s gas tank`:`${ye(e.amount)} ${t(e.from)} → ${t(e.to)}`}const K2={own:"its own key",lab:"the lab wallet",parent:"its parent's key (its handoff is cued)",other:"a key outside this lab"},D2={ssh:"shell access, certified by the CA",git:"commit signing",dkim:"mail signing",wg:"WireGuard peer key","ssh-ca":"SSH certificate authority",mtls:"TLS identity between nodes",noise:"Headscale noise key"};function Z2(e){const t=Re(z.keys,Ge,e),n=Ka(z,Q,e.id),r=["Held now by",n?K2[n.who]:"nobody: its inscription has been spent"];if(!t)return $("div",{class:"keys"},$("p",{class:"lab",text:"Keys"}),$("dl",{class:"fl"},[["Signs with","the lab wallet: this holding predates lab keys, so it has no addresses, leaves or secrets of its own"],r].map(Vr)));const s=e.kind==="agent",o=Fx(z.keys,Ge,e),i=Gx(z.keys,Ge,e),a=i.map(([,,d])=>d).filter(Boolean),c="Reset the lab for standard BIP-86 keys.",u=s?"Holds this seat's inscription, and inscriptions sent to it land here.":"Holds this org's inscription and signs its acts. Inscriptions sent to it land here.",f={bip86:`BIP-86 at ${o.taproot.path}. ${u}`,tapkey:`Its npub's key with the BIP-86 tweak, the way v1.2 keyed this lab. ${u} ${c}`,wallet:`An untweaked key at ${o.taproot.path}, the way v1.1 keyed this lab. ${u} ${c}`}[t.scheme],l=[["Taproot",o.taproot.address,f],["SegWit",o.segwit.address,`BIP-84 at ${o.segwit.path}. Its money: ${e.kind==="holding"?"the beats it earns land here, and ":""}sends come and go here.`],["Tapkey",o.tapkey.address,"Its npub as a Taproot address (its nostr key with the BIP-86 tweak), so the npub alone finds it. Nostr secrets get pasted into clients, so treat it as an inbox."],["npub",o.npub.address,`NIP-06 at ${o.npub.path}. Its nostr name; the leaves below hang off it.`],["From",`${t.from} · account ${t.account}`],r];return $("div",{class:"keys"},$("p",{class:"lab",text:"Keys"}),$("dl",{class:"fl"},l.map(Vr)),$("p",{class:"lab"},"Leaves",$("span",{text:` · HKDF-SHA256 from its ${s?"nostr secret":"seed"}`})),$("ul",{class:"list leaves"},i.map(([d,h])=>$("li",{},$("b",{text:d}),$("span",{class:"when",text:` ${D2[d]}`}),$("code",{text:h})))),Ar(s?"Public lines to paste":"CA key for TrustedUserCAKeys",a.join(` - -`)),V2(e,t))}function Ar(e,t,n=t){const r=$("pre",{text:n}),s=$("button",{type:"button",class:"cp","aria-label":`Copy ${e}`,onclick:()=>M2(t,s,r)},"Copy");return $("div",{class:"code"},$("div",{class:"code-h cph"},$("span",{text:e}),s),r)}async function M2(e,t,n){const r=s=>{t.textContent=s,setTimeout(()=>{t.textContent="Copy"},1400)};try{await navigator.clipboard.writeText(e),r("Copied")}catch{getSelection().selectAllChildren(n),r("Selected")}}function V2(e,t){var a;const n=B.reveal===e.id,r=n&&Qx(z.keys,Ge,e),s=se(e.parent,Ge),o=()=>{var c;B.reveal=n?null:e.id,zd(),(c=V("reveal"))==null||c.focus()},i=(a=r==null?void 0:r.seed)==null?void 0:a.mnemonic.split(" ");return $("div",{class:"secret"},$("div",{class:"hz"},$("span",{class:"hz-l",text:"Secret · stays in this tab"}),$("button",{type:"button",class:"btn sm",id:"reveal","aria-expanded":String(n),onclick:o},n?"Hide":"Reveal")),r&&$("div",{class:"sb"},r.seed?Ar(`Seed · ${r.seed.from}`,r.seed.mnemonic,i.map((c,u)=>`${String(u+1).padStart(2,"0")} ${c}`).reduce((c,u,f)=>(f%3?c[c.length-1].push(u):c.push([u]),c),[]).map(c=>c.join(" ")).join(` -`)):$("p",{class:"note",text:`A seat has no seed of its own: these are account ${t.account} of ${(s==null?void 0:s.name)??"its org"}'s seed.`}),r.account.map(([c,u,f])=>Ar(`${c} · ${u}`,f)),r.leaves.map(([c,u,f])=>Ar(`${c} · ${u}`,f))))}function q2(e){var i,a,c;const t=(a=(i=z.chain.transactions.get(e.id.slice(0,-2)))==null?void 0:i.tx.vin.find(u=>{var f;return((f=u.witness)==null?void 0:f.length)===3}))==null?void 0:a.witness;if(!t)return"?";const n=xa(t).pubkey,r=se(e.parent),s=e.op==="found"?se(e.node):null,o=[[s&&Re(z.keys,Q,s),`${s==null?void 0:s.name}'s root`],[r&&Re(z.keys,Q,r),`${r==null?void 0:r.name}'s key`],[(r==null?void 0:r.edge)==="adopted"&&Re(z.keys,Q,{...r,edge:"derived"}),`${r==null?void 0:r.name}'s derived key, from before it graduated`]];for(const[u,f]of o)if(u&&u.wallet.pubkey===n)return f;return((c=z.wallet)==null?void 0:c.pubkey)===n?"the lab wallet":`a key outside this lab (${n.slice(0,12)}…)`}function z2(e){var o,i,a;const t=so.events.find(c=>c.id===e.id),n=(i=(o=z.chain.transactions.get(e.id.slice(0,-2)))==null?void 0:o.inscription)==null?void 0:i.text,r=[["When",e.pending?"cued for the next beat":`beat ${e.beat}`],["Authorized by",e.parent?`${((a=se(e.parent))==null?void 0:a.name)??"an unknown inscription"}, whose inscription this event spent`:"nothing: a founding has no parent"],["Signed by",q2(e)],["Inscription",e.id],n&&["Body",n],(t==null?void 0:t.block)&&["Block",t.block]].filter(Boolean),s=t&&{id:t.id,status:t.status,height:t.height,block:t.block,parent:t.parent??null,metaprotocol:t.metaprotocol??null,contentType:t.contentType,sat:t.sat,location:t.location};return[$("div",{class:"ih"},$("p",{class:"eyebrow",text:`${e.op} · ${e.pending?"cued":`beat ${e.beat}`}`}),$("h3",{class:"it",text:of(e,Q)}),$("div",{class:"chips"},$("span",{class:"chip",text:(t==null?void 0:t.protocol)??"?"}),$("span",{class:`chip ${e.ok?"ok":"bad"}`,text:e.ok?"applied":"rejected"})),!e.ok&&$("p",{class:"idesc",text:"The reducer rejected this event. It stays on the chain, but it does not change the tree."})),$("div",{class:"ib"},$("dl",{class:"fl"},r.map(Vr)),$("div",{class:"code"},$("p",{class:"code-h",text:"Metadata · CBOR, tag 5"}),$("pre",{text:Fc(e.meta)})),s&&$("div",{class:"code"},$("p",{class:"code-h",text:"Raw index entry"}),$("pre",{text:Fc(s)})))]}function F2(e){const t=s=>{var o;return((o=se(s))==null?void 0:o.name)??"a key outside this lab"},n=z.chain.transactions.get(e.txid),r=[["When",e.beat===null?"cued for the next beat":`beat ${e.beat}`],["From",e.kind==="mine"?"its share of the beat's block reward (the coinbase)":`${t(e.from)}'s SegWit address${e.kind==="move"?", from before it graduated":""}`],["To",e.kind==="gas"?`${t(e.to)}'s gas tank, at its Taproot key`:`${t(e.to)}'s ${e.kind==="move"?"new ":""}SegWit address`],["Amount",ye(e.amount)],e.kind!=="mine"&&["Fee",`${e.fee} sats, retired: this toy chain pays no fees to miners`],e.change>0&&["Change",`${ye(e.change)} back to ${t(e.from)}`],["Signed by",e.kind==="mine"?"nobody: a coinbase spends nothing":`${t(e.from)}'s SegWit key (BIP-143, SIGHASH_ALL)`],["Transaction",e.txid]].filter(Boolean);return[$("div",{class:"ih"},$("p",{class:"eyebrow",text:`${e.kind} · ${e.beat===null?"cued":`beat ${e.beat}`}`}),$("h3",{class:"it",text:Fd(e)}),$("div",{class:"chips"},$("span",{class:"chip",text:"test BTC"}),$("span",{class:`chip${e.beat===null?"":" ok"}`,text:e.beat===null?"cued":"confirmed"}))),$("div",{class:"ib"},$("dl",{class:"fl"},r.map(Vr)),n&&Ar("Raw transaction",n.raw))]}function Ga(){const e=We(),t=V("beat"),n=se(B.holding);t.max=String(e),t.value=String(B.beat??e),t.disabled=e===0,V("beat-label").textContent=B.beat===null?`Now · beat ${e}`:`Beat ${B.beat} of ${e}`,V("replay").textContent=B.replay?"Stop":"Replay",V("replay").disabled=!n||e===0,V("to-now").disabled=B.beat===null,V("timeline-sub").textContent=(n==null?void 0:n.name)??"";const r=new Map,s=new Map([...z.chain.transactions.keys()].map((a,c)=>[a,c])),o=(a,c)=>r.set(a,[...r.get(a)??[],c]);for(const a of Q.log)a.root&&a.root===B.holding&&o(a.pending?"cued":a.beat,{e:a,at:s.get(a.id.slice(0,-2))??0});for(const a of Ze.ledger)[a.to,a.from].some(c=>{var u;return c&&((u=se(c))==null?void 0:u.root)===B.holding})&&o(a.beat??"cued",{m:a,at:s.get(a.txid)??0});const i=[...r.keys()].sort((a,c)=>a==="cued"?-1:c==="cued"?1:c-a);if(!i.length)return V("timeline-list").replaceChildren($("li",{class:"wait",text:n?"Nothing yet.":"Found a holding to start its timeline."}));V("timeline-list").replaceChildren(...i.map(a=>{const c=a==="cued"?null:z.chain.blocks[a-1],u=B.beat!==null&&(a==="cued"||a>B.beat),f=B.beat!==null&&a===B.beat;return $("li",{class:`beat${u?" later":""}${f?" now":""}`},$("p",{class:"bh"},$("span",{class:"bn",text:a==="cued"?"Cued":`Beat ${a}`}),$("span",{class:"bt",text:c?_2(c.time):z.clock.tempo==="manual"?"waiting for Beat now":"landing on the next beat"})),$("ol",{class:"evs"},r.get(a).sort((l,d)=>l.at-d.at).map(({e:l,m:d})=>d?W2(d):G2(l))))}))}function G2(e){const[t,...n]=of(e,Q).split(" ");return $("li",{},$("button",{type:"button",class:`ev${e.ok?"":" bad"}${e.id===B.event?" on":""}`,"aria-pressed":String(e.id===B.event),onclick:()=>ns({event:e.id,node:e.node??B.node})},$("span",{class:"op",text:e.ok?t:`✕ ${t.replace(/:$/,"")}`})," ",$("span",{class:"es",text:n.join(" ")})))}const W2=e=>$("li",{},$("button",{type:"button",class:`ev money${e.kind==="gas"?" gas":""}${e.key===B.tx?" on":""}`,"aria-pressed":String(e.key===B.tx),onclick:()=>{var t;return ns({tx:e.key,node:((t=se(e.to))==null?void 0:t.root)===B.holding?e.to:B.node})}},$("span",{class:"op",text:e.kind})," ",$("span",{class:"es",text:Fd(e)})));V("f-found").addEventListener("submit",async e=>{e.preventDefault();const t=e.currentTarget,n=Ea(t.elements.name.value);if(!n)return Ae("Name the holding: lowercase letters, digits and hyphens.",!0);await br("found",null,{name:n},(r,s)=>(Rd({holding:r,node:r}),`${n} is founded, ${s}.`))&&t.reset()});V("sample").addEventListener("click",async()=>{let e=null;Ae("Rehearsing the yolopreneur tree over six beats…"),await gn(t=>{e=k2(t)})&&(ns({holding:e,node:e}),Ae("Loaded the yolopreneur sample: six beats of history. Press Replay to watch it grow."))});V("f-birth").addEventListener("submit",async e=>{e.preventDefault();const t=e.currentTarget,n=se(B.node),r=Ea(t.elements.name.value),s=t.elements.kind.value;if(!r)return Ae("Name the child: lowercase letters, digits and hyphens.",!0);await br("birth",n.id,{name:r,kind:s},(o,i)=>`${r} is born to ${n.name}, ${i}.`)&&(t.elements.name.value="")});V("f-award").addEventListener("submit",async e=>{e.preventDefault();const t=e.currentTarget,n=se(B.node),r=t.elements.to.value,s=Ea(t.elements.skill.value),o=t.elements.belt.value;if(!s)return Ae("Name the skill, for example launch.",!0);await br("award",n.id,{to:r,skill:s,belt:o},(i,a)=>{var c;return`${(c=se(r))==null?void 0:c.name} holds a ${o} belt in ${s}, ${a}.`})&&(t.elements.skill.value="")});V("f-decide").addEventListener("submit",async e=>{e.preventDefault();const t=e.currentTarget,n=se(B.node),r=t.elements.title.value.trim(),s=t.elements.why.value.trim();if(!r)return Ae("A decision needs a title.",!0);await br("decide",n.id,{title:r,why:s},(o,i)=>`${n.name} decided “${r}”, ${i}.`)&&t.reset()});V("f-send").addEventListener("submit",async e=>{var a;e.preventDefault();const t=e.currentTarget,n=se(B.node),r=t.elements.to.value,s=c2(t.elements.amount.value);if(s===null)return Ae("Write an amount in test BTC, for example 1.5 (at most eight decimals).",!0);let o=null;if(!await gn(c=>{o=E2(c,n.id,r,s)}))return;const i=Ze.ledger.find(c=>c.txid===o);Ae(`${n.name} sent ${ye(s)} to ${((a=se(r))==null?void 0:a.root)===n.root?se(r).name:go(Q,r)}, ${i!=null&&i.beat?`at beat ${i.beat}`:"cued for the next beat"}.`),t.elements.amount.value=""});V("send-max").addEventListener("click",()=>{const e=se(B.node),t=e&&je(z.keys,Q,e);t&&(V("send-amount").value=wd(Va(z.chain.coins(t.script))))});V("f-graduate").addEventListener("submit",async e=>{e.preventDefault();const t=se(B.node),n=se(t.parent);await br("graduate",n.id,{of:t.id},(r,s)=>`${t.name} graduates from ${n.name}, ${s}. Its edge is adopted now.`)});V("f-close").addEventListener("submit",async e=>{e.preventDefault();const t=se(B.node);if(B.closing!==t.id)return B.closing=t.id,Bo(),V("close-go").focus();B.closing=null,await br("close",t.id,{},(n,r)=>`${t.name} is closed, ${r}.`)});V("close-keep").addEventListener("click",()=>{B.closing=null,Bo(),V("close-go").focus()});for(const e of document.querySelectorAll("[data-verb]"))e.addEventListener("click",()=>{B.verb=e.dataset.verb,B.closing=null,Bo()});for(const e of document.querySelectorAll("[data-rule]"))e.addEventListener("click",async()=>{const t=e.dataset.rule;await gn(n=>r2(n,t))&&Ae(t==="split"?"Each beat splits across the holdings that mine, by hashrate.":"Each beat goes whole to the holding that acts.")});for(const e of document.querySelectorAll("[data-tempo]"))e.addEventListener("click",async()=>{const t=e.dataset.tempo,n=/^\d+$/.test(t)?Number(t):t;await gn(r=>i2(r,n,Date.now(),$o(r,B.holding)))&&Ae(t==="each"?"Each act is its own beat.":t==="manual"?"Acts are cued until you press Beat now.":`Acts are cued and land together on the next beat, at most ${t} seconds after the first.`)});V("beat-now").addEventListener("click",()=>jd(e=>{pn(e,$o(e,B.holding))}));setInterval(()=>{Kd();const{tempo:e,nextAt:t}=z.clock;B.busy||document.hidden||typeof e!="number"||!z.chain.mempool.length||t&&Date.now()a2(n,Date.now(),$o(n,B.holding)))},1e3);addEventListener("storage",e=>{(e.key===So||e.key===null)&&Hd()});function rs(){B.replay&&(clearInterval(B.replay),B.replay=null,Ga())}function Y2(){const e=se(B.holding);if(!(!e||!We())){if(oo(typeof e.born=="number"?e.born:We()),B.beat===null)return Ae("Nothing to replay yet: this holding has one beat of history.");B.replay=setInterval(()=>{(B.beat===null||B.beat+1>=We())&&rs(),oo(B.beat===null?We():B.beat+1)},800),Ga()}}V("beat").addEventListener("input",e=>{rs(),oo(Number(e.target.value))});V("replay").addEventListener("click",()=>B.replay?rs():Y2());for(const e of["to-now","past-now"])V(e).addEventListener("click",()=>{rs(),oo(We())});const ai=["system","light","dark"],Gd=()=>{V("theme").textContent=`Theme: ${document.documentElement.dataset.theme??"system"}`};V("theme").addEventListener("click",()=>{const e=ai[(ai.indexOf(document.documentElement.dataset.theme??"system")+1)%ai.length];e==="system"?delete document.documentElement.dataset.theme:document.documentElement.dataset.theme=e;try{e==="system"?localStorage.removeItem("orgchain-theme"):localStorage.setItem("orgchain-theme",e)}catch{}Gd()});function Wd(e,t,n){const r=V("confirm");r.replaceChildren($("span",{text:e}),$("button",{type:"button",class:"btn sm danger",text:t,onclick:()=>{r.hidden=!0,n()}}),$("button",{type:"button",class:"btn sm",text:"Cancel",onclick:()=>{r.hidden=!0}})),r.hidden=!1,r.querySelector("button").focus()}const X2={read:()=>{try{return Da()}catch{return ts()}}};async function Yd(e,t){rs(),await gn(n=>{Object.assign(n,e())},X2)&&(Object.assign(B,{holding:null,node:null,event:null,tx:null,beat:null,closing:null}),Fa(),Ae(t))}V("save").addEventListener("click",()=>{const e=$("a",{href:URL.createObjectURL(new Blob([bd(z)],{type:"application/json"})),download:`orgchain-lab-${new Date().toISOString().slice(0,10)}.json`});document.body.append(e),e.click(),e.remove(),setTimeout(()=>URL.revokeObjectURL(e.href),5e3),Ae("Saved a backup of this lab, test wallet included. Load it in any browser to carry on.")});V("load").addEventListener("click",()=>V("load-file").click());V("load-file").addEventListener("change",async e=>{var r;const t=(r=e.target.files)==null?void 0:r[0];if(e.target.value="",!t)return;let n;try{n=yd(await t.text())}catch(s){return Ae(`${t.name} is not an Orgchain lab: ${s.message}`,!0)}Wd(`Replace this browser's lab with ${t.name}?`,"Replace",()=>Yd(()=>n,`Loaded ${t.name}.`))});V("reset").addEventListener("click",()=>Wd("Erase this browser's lab: every holding, the chain and the test wallet?","Erase",()=>Yd(ts,"Erased. This is a fresh lab.")));Gd();Hd(); diff --git a/ventures/lineage/orgchain/index.html b/ventures/lineage/orgchain/index.html index ea0dac0..eab19cb 100644 --- a/ventures/lineage/orgchain/index.html +++ b/ventures/lineage/orgchain/index.html @@ -8,7 +8,7 @@ - +