From ada3979db2d1e713ad3ac6d21e04d272116be16f Mon Sep 17 00:00:00 2001 From: teahubxyz Date: Thu, 15 Oct 2026 12:15:57 -0700 Subject: [PATCH] lineage: Orgchain v1.11 (charters, a ladder of legal forms; agents graduate) Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01H4upF5LVwmPDDqrhdUfnXh --- .../lineage/orgchain/assets/index-CcoNSRTp.js | 2065 ----------------- .../lineage/orgchain/assets/index-DXb8Kdrd.js | 2065 +++++++++++++++++ ...{index-C1PA9bil.css => index-DwOZaPY4.css} | 2 +- ventures/lineage/orgchain/index.html | 30 +- 4 files changed, 2090 insertions(+), 2072 deletions(-) delete mode 100644 ventures/lineage/orgchain/assets/index-CcoNSRTp.js create mode 100644 ventures/lineage/orgchain/assets/index-DXb8Kdrd.js rename ventures/lineage/orgchain/assets/{index-C1PA9bil.css => index-DwOZaPY4.css} (96%) diff --git a/ventures/lineage/orgchain/assets/index-CcoNSRTp.js b/ventures/lineage/orgchain/assets/index-CcoNSRTp.js deleted file mode 100644 index 45061ee..0000000 --- a/ventures/lineage/orgchain/assets/index-CcoNSRTp.js +++ /dev/null @@ -1,2065 +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 Js=5e9,Vc=2**52,ef=(e,t)=>[[Vc+e*Js,Vc+e*Js+t]];function tf(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 nf(e,t){var n;return(n=tf(e,t,1)[0])==null?void 0:n[0]}function zs(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=tf(s,o,Number(i.value));return o+=Number(i.value),a})}function Ri(e){if(!Number.isSafeInteger(e)||e<0)throw new Error(`Wrong positive integer: ${e}`)}function k0(e){if(typeof e!="boolean")throw new Error(`Expected boolean, not ${e}`)}function sf(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 S0(e){if(typeof e!="function"||typeof e.create!="function")throw new Error("Hash should be wrapped by utils.wrapConstructor");Ri(e.outputLen),Ri(e.blockLen)}function $0(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 _0(e,t){sf(e);const n=t.outputLen;if(e.lengthnew DataView(e.buffer,e.byteOffset,e.byteLength),Et=(e,t)=>e<<32-t|e>>>t,B0=new Uint8Array(new Uint32Array([287454020]).buffer)[0]===68;if(!B0)throw new Error("Non little-endian hardware is not supported");Array.from({length:256},(e,t)=>t.toString(16).padStart(2,"0"));function T0(e){if(typeof e!="string")throw new TypeError(`utf8ToBytes expected string, got ${typeof e}`);return new TextEncoder().encode(e)}function of(e){if(typeof e=="string"&&(e=T0(e)),!(e instanceof Uint8Array))throw new TypeError(`Expected input type is Uint8Array (got ${typeof e})`);return e}let I0=class{clone(){return this._cloneInto()}};function af(e){const t=r=>e().update(of(r)).digest(),n=e();return t.outputLen=n.outputLen,t.blockLen=n.blockLen,t.create=()=>e(),t}function O0(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 C0=class extends I0{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=ri(this.buffer)}update(t){ni.exists(this);const{view:n,buffer:r,blockLen:s}=this;t=of(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,U0=(e,t,n)=>e&t^e&n^t&n,N0=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]),Wt=new Uint32Array([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]),Gt=new Uint32Array(64);let cf=class extends C0{constructor(){super(64,32,8,!1),this.A=Wt[0]|0,this.B=Wt[1]|0,this.C=Wt[2]|0,this.D=Wt[3]|0,this.E=Wt[4]|0,this.F=Wt[5]|0,this.G=Wt[6]|0,this.H=Wt[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)Gt[f]=t.getUint32(n,!1);for(let f=16;f<64;f++){const d=Gt[f-15],h=Gt[f-2],p=Et(d,7)^Et(d,18)^d>>>3,g=Et(h,17)^Et(h,19)^h>>>10;Gt[f]=g+Gt[f-7]+p+Gt[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=Et(a,6)^Et(a,11)^Et(a,25),h=l+d+P0(a,c,u)+N0[f]+Gt[f]|0,g=(Et(r,2)^Et(r,13)^Et(r,22))+U0(r,s,o)|0;l=u,u=c,c=a,a=i+h|0,i=o,o=s,s=r,r=h+g|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(){Gt.fill(0)}destroy(){this.set(0,0,0,0,0,0,0,0),this.buffer.fill(0)}},L0=class extends cf{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 Hi=af(()=>new cf);af(()=>new L0);function R0(e,t){if(e.length>t)throw new TypeError(`Data is larger than array size: ${e.length} > ${t}`)}function H0(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 j0(e){if(e>Number.MAX_SAFE_INTEGER)throw new TypeError("Number exceeds safe bounds!")}const{getRandomValues:K0}=crypto??globalThis.crypto??window.crypto;function D0(e=32){if(typeof K0=="function")return crypto.getRandomValues(new Uint8Array(e));throw new Error("Crypto module missing getRandomValues!")}function M0(e,t,n="be"){t===void 0&&(t=e.length),R0(e,t);const r=new Uint8Array(t).fill(0),s=n==="be"?0:t-e.length;return r.set(e,s),r}function uf(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 z0(e,t){const n=ff(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 lf(e){return Hi(Hi(e))}function F0(e){const t=lf(e);return uf([e,t.slice(0,4)])}function W0(e){const t=e.slice(0,-4),n=e.slice(-4);if(lf(t).slice(0,4).toString()!==n.toString())throw new Error("Invalid checksum!");return t}const qc={encode:q0,decode:z0},df={encode:e=>{const t=F0(e);return qc.encode(t,"base58")},decode:e=>{const t=qc.decode(e,"base58");return W0(t)}},hf="qpzry9x8gf2tvdw0s3jn54khce6mua7l",G0=[996825010,642813549,513874426,1027748829,705979059],Qs=[{version:0,name:"bech32",const:1},{version:1,name:"bech32m",const:734539939}];function pf(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^=G0[s])}return t}function gf(e){const t=[];let n;for(n=0;n>5);for(t.push(0),n=0;n>5*(5-i)&31);return o}function mf(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 J0(e,t,n){const r=t.concat(X0(e,t,n));let s=e+"1";for(let o=0;oo.version===t[0])??Qs[0];if(!Y0(r,t,s))throw new Error("Checksum verification failed!");return[r,t.slice(0,t.length-6)]}function Q0(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 ep(e){const t=e.lastIndexOf("1");return!(t<1||t+7>e.length||e.length>90)}function tp(e,t="bc",n=0){const r=[n,...mf([...e],8,5)],s=Qs.find(i=>i.version===n)??Qs[0],o=J0(t,r,s);return bf(o),o}function bf(e){e=e.toLowerCase();const t=e.split("1",1)[0],[n,r]=yf(e),s=mf(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 np(e){e=e.toLowerCase();const[t,n]=yf(e);return n[0]}const wf={encode:tp,decode:bf,version:np},xf="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",vf="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",rp=new TextEncoder;function Ef(e,t=!1,n=!0){typeof e=="string"&&(e=rp.encode(e));const r=t?vf:xf;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 kf(e,t=!1){const n=t||e.includes("-")||e.includes("_")?vf.split(""):xf.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 Sf={encode:Ef,decode:kf},$f={encode:e=>Ef(e,!0,!1),decode:e=>kf(e,!0)},sp=BigInt(0),op=BigInt(255),_f=BigInt(256);function ip(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 ap(e,t,n="be"){t===void 0&&(t=ip(e));const r=n==="le",s=new ArrayBuffer(t),o=new DataView(s);let i=r?0:t-1;for(;e>sp;){const a=e&op,c=Number(a);r?o.setUint8(i++,c):o.setUint8(i--,c),e=(e-a)/_f}return new Uint8Array(s)}function cp(e){let t=BigInt(0);for(let n=e.length-1;n>=0;n--)t=t*_f+BigInt(e[n]);return BigInt(t)}function up(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 lp(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 dp(e,t,n="be"){t===void 0&&(t=lp(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 hp(e){let t=0;for(let n=e.length-1;n>=0;n--)t=t*256+e[n],j0(t);return t}const pp=new TextEncoder,gp=new TextDecoder;function Ea(e){return pp.encode(e)}function si(e){return gp.decode(e)}function mp(e,t){H0(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 yp(e,t,n="le"){t=mp(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 Ea(t)}function xp(e,t,n){if(e instanceof ArrayBuffer)return new Uint8Array(e);if(e instanceof Uint8Array)return M0(e,t,n);if(typeof e=="string")return yp(e,t,n);if(typeof e=="bigint")return ap(e,t,n);if(typeof e=="number")return dp(e,t,n);if(typeof e=="boolean")return Uint8Array.of(e?1:0);throw TypeError("Unsupported format:"+typeof e)}var ee;let S=(ee=class extends Uint8Array{static random(t=32){const n=D0(t);return new ee(n,t)}constructor(t,n,r){const s=xp(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 Ir(this)}toNum(t="be"){const n=t==="be"?this.reverse():this;return hp(n)}toBin(){return fp(this)}toBig(t="be"){const n=t==="be"?this.reverse():this;return cp(n)}toHash(){const t=Hi(this);return new ee(t)}toJson(){const t=si(this);return JSON.parse(t)}toBech32(t,n=0){return wf.encode(this,t,n)}toStr(){return si(this)}toHex(){return bp(this)}toBytes(){return new Uint8Array(this)}tob58chk(){return df.encode(this)}toBase64(){return Sf.encode(this)}toB64url(){return $f.encode(this)}prepend(t){return ee.join([ee.bytes(t),this])}append(t){return ee.join([this,ee.bytes(t)])}slice(t,n){const r=new Uint8Array(this).slice(t,n);return new ee(r)}subarray(t,n){const r=new Uint8Array(this).subarray(t,n);return new ee(r)}reverse(){const t=new Uint8Array(this).reverse();return new ee(t)}write(t,n){const r=ee.bytes(t);this.set(r,n)}prefixSize(t){const n=ee.varInt(this.length,t);return ee.join([n,this])}static from(t){return new ee(Uint8Array.from(t))}static of(...t){return new ee(Uint8Array.of(...t))}static join(t){const n=t.map(s=>ee.bytes(s)),r=uf(n);return new ee(r)}static varInt(t,n){if(t<253)return ee.num(t,1);if(t<65536)return ee.of(253,...ee.num(t,2,n));if(t<4294967296)return ee.of(254,...ee.num(t,4,n));if(BigInt(t)<0x10000000000000000n)return ee.of(255,...ee.num(t,8,n));throw new Error(`Value is too large: ${t}`)}},ee.num=vp,ee.big=kp,ee.bin=Ep,ee.raw=Sp,ee.str=$p,ee.hex=_p,ee.bytes=Ap,ee.json=Bp,ee.base64=Tp,ee.b64url=Ip,ee.bech32=Op,ee.b58chk=Cp,ee.encode=Ea,ee.decode=si,ee);function vp(e,t,n){return new S(e,t,n)}function Ep(e,t,n){return new S(up(e),t,n)}function kp(e,t,n){return new S(e,t,n)}function Sp(e,t,n){return new S(e,t,n)}function $p(e,t,n){return new S(Ea(e),t,n)}function _p(e,t,n){return new S(e,t,n)}function Ap(e,t,n){return new S(e,t,n)}function Bp(e){return new S(wp(e))}function Tp(e){return new S(Sf.decode(e))}function Ip(e){return new S($f.decode(e))}function Op(e){return new S(wf.decode(e))}function Cp(e){return new S(df.decode(e))}let Ir=class{constructor(t){this.data=S.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 S(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 Ut(e,t){const n=S.bytes(e);if(n.length!==t)throw new Error(`Invalid input size: ${n.hex} !== ${t}`)}function Ve(e,t){if(t)throw new Error(e);return!1}function Fs(e,...t){const n=S.str(e).digest.raw,r=t.map(s=>S.bytes(s));return S.join([n,n,S.join(r)]).digest}const Af={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 Pp(e){if(e>186&&e<255)return"OP_SUCCESS"+String(e);for(const[t,n]of Object.entries(Af))if(n===e)return t;throw new Error("OPCODE not found:"+String(e))}function Up(e){for(const[t,n]of Object.entries(Af))if(t===e)return Number(n);throw new Error("OPCODE not found:"+e)}function Np(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 Lp(e){const r=[];switch(!0){case typeof e!="number":return!1;case e===0:return!0;case r.includes(e):return!1;case(750?S.join(t):new Uint8Array}function Rp(e){let t=new Uint8Array;if(typeof e=="string"){if(e.startsWith("OP_"))return S.num(Up(e),1);Ft(e)?t=S.hex(e):t=S.str(e)}else t=S.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])),S.join([zc(t.length),t]));if(t.length>eo){const n=Hp(t);return Tf(n)}else return S.join([zc(t.length),t])}function zc(e){const t=S.num(76,1),n=S.num(77,1);switch(!0){case e<=75:return S.num(e);case(e>75&&e<256):return S.join([t,S.num(e,1,"le")]);case(e>=256&&e<=eo):return S.join([n,S.num(e,2,"le")]);default:throw new Error("Invalid word size:"+e.toString())}}function Hp(e){const t=[],n=new Ir(e);for(;n.size>eo;)t.push(n.read(eo));return t.push(n.read(n.size)),t}function ka(e,t=!1){let n=S.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 jp(n)}function jp(e){const t=new Ir(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 qp(e){if(typeof e!="function"||typeof e.create!="function")throw new Error("Hash should be wrapped by utils.wrapConstructor");ji(e.outputLen),ji(e.blockLen)}function zp(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 Fp(e,t){If(e);const n=t.outputLen;if(e.lengthnew DataView(e.buffer,e.byteOffset,e.byteLength),kt=(e,t)=>e<<32-t|e>>>t,Gp=new Uint8Array(new Uint32Array([287454020]).buffer)[0]===68;if(!Gp)throw new Error("Non little-endian hardware is not supported");Array.from({length:256},(e,t)=>t.toString(16).padStart(2,"0"));function Yp(e){if(typeof e!="string")throw new TypeError(`utf8ToBytes expected string, got ${typeof e}`);return new TextEncoder().encode(e)}function Sa(e){if(typeof e=="string"&&(e=Yp(e)),!(e instanceof Uint8Array))throw new TypeError(`Expected input type is Uint8Array (got ${typeof e})`);return e}function Xp(...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(Sa(r)).digest(),n=e();return t.outputLen=n.outputLen,t.blockLen=n.blockLen,t.create=()=>e(),t}function Jp(e=32){if(oi&&typeof oi.getRandomValues=="function")return oi.getRandomValues(new Uint8Array(e));throw new Error("crypto.getRandomValues must be defined")}function Qp(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 eg=class extends Of{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=ii(this.buffer)}update(t){Pn.exists(this);const{view:n,buffer:r,blockLen:s}=this;t=Sa(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,ng=(e,t,n)=>e&t^e&n^t&n,rg=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]),Yt=new Uint32Array([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]),Xt=new Uint32Array(64);let Pf=class extends eg{constructor(){super(64,32,8,!1),this.A=Yt[0]|0,this.B=Yt[1]|0,this.C=Yt[2]|0,this.D=Yt[3]|0,this.E=Yt[4]|0,this.F=Yt[5]|0,this.G=Yt[6]|0,this.H=Yt[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)Xt[f]=t.getUint32(n,!1);for(let f=16;f<64;f++){const d=Xt[f-15],h=Xt[f-2],p=kt(d,7)^kt(d,18)^d>>>3,g=kt(h,17)^kt(h,19)^h>>>10;Xt[f]=g+Xt[f-7]+p+Xt[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=kt(a,6)^kt(a,11)^kt(a,25),h=l+d+tg(a,c,u)+rg[f]+Xt[f]|0,g=(kt(r,2)^kt(r,13)^kt(r,22))+ng(r,s,o)|0;l=u,u=c,c=a,a=i+h|0,i=o,o=s,s=r,r=h+g|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(){Xt.fill(0)}destroy(){this.set(0,0,0,0,0,0,0,0),this.buffer.fill(0)}},sg=class extends Pf{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 Uf=Cf(()=>new Pf);Cf(()=>new sg);/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */const og=BigInt(0),$a=BigInt(1),ig=BigInt(2),Co=e=>e instanceof Uint8Array,ag=Array.from({length:256},(e,t)=>t.toString(16).padStart(2,"0"));function pr(e){if(!Co(e))throw new Error("Uint8Array expected");let t="";for(let n=0;ngr(e.toString(16).padStart(t*2,"0")),Lf=(e,t)=>cr(e,t).reverse(),cg=e=>gr(Nf(e));function ot(e,t,n){let r;if(typeof t=="string")try{r=gr(t)}catch(o){throw new Error(`${e} must be valid hex string, got "${t}". Cause: ${o}`)}else if(Co(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 dt(...e){const t=new Uint8Array(e.reduce((r,s)=>r+s.length,0));let n=0;return e.forEach(r=>{if(!Co(r))throw new Error("Uint8Array expected");t.set(r,n),n+=r.length}),t}function ug(e,t){if(e.length!==t.length)return!1;for(let n=0;n0n;e>>=$a,t+=1);return t}const lg=(e,t)=>e>>BigInt(t)&1n,dg=(e,t,n)=>e|(n?$a:og)<(ig<new Uint8Array(e),Fc=e=>Uint8Array.from(e);function Rf(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=ai(e),s=ai(e),o=0;const i=()=>{r.fill(1),s.fill(0),o=0},a=(...f)=>n(s,r,...f),c=(f=ai())=>{s=a(Fc([0]),f),r=a(),f.length!==0&&(s=a(Fc([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 hg={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 Or(e,t,n={}){const r=(s,o,i)=>{const a=hg[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 pg=Object.freeze({__proto__:null,bitGet:lg,bitLen:fg,bitMask:Ba,bitSet:dg,bytesToHex:pr,bytesToNumberBE:mn,bytesToNumberLE:Aa,concatBytes:dt,createHmacDrbg:Rf,ensureBytes:ot,equalBytes:ug,hexToBytes:gr,hexToNumber:_a,numberToBytesBE:cr,numberToBytesLE:Lf,numberToHexUnpadded:Nf,numberToVarBytesBE:cg,utf8ToBytes:Po,validateObject:Or});/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */const He=BigInt(0),Ie=BigInt(1),In=BigInt(2),gg=BigInt(3),Ki=BigInt(4),Wc=BigInt(5),Gc=BigInt(8);BigInt(9);BigInt(16);function qe(e,t){const n=e%t;return n>=He?n:t+n}function mg(e,t,n){if(n<=He||t 0");if(n===Ie)return He;let r=Ie;for(;t>He;)t&Ie&&(r=r*e%n),e=e*e%n,t>>=Ie;return r}function st(e,t,n){let r=e;for(;t-- >He;)r*=r,r%=n;return r}function Di(e,t){if(e===He||t<=He)throw new Error(`invert: expected positive integers, got n=${e} mod=${t}`);let n=qe(e,t),r=t,s=He,o=Ie;for(;n!==He;){const a=r/n,c=r%n,u=s-o*a;r=n,n=c,s=o,o=u}if(r!==Ie)throw new Error("invert: does not exist");return qe(s,t)}function yg(e){const t=(e-Ie)/In;let n,r,s;for(n=e-Ie,r=0;n%In===He;n/=In,r++);for(s=In;s(r[s]="function",r),t);return Or(e,n)}function xg(e,t,n){if(n 0");if(n===He)return e.ONE;if(n===Ie)return t;let r=e.ONE,s=t;for(;n>He;)n&Ie&&(r=e.mul(r,s)),s=e.sqr(s),n>>=Ie;return r}function vg(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 Ta(e,t){const n=t!==void 0?t:e.toString(2).length,r=Math.ceil(n/8);return{nBitLength:n,nByteLength:r}}function jf(e,t,n=!1,r={}){if(e<=He)throw new Error(`Expected Fp ORDER > 0, got ${e}`);const{nBitLength:s,nByteLength:o}=Ta(e,t);if(o>2048)throw new Error("Field lengths over 2048 bytes are not supported");const i=bg(e),a=Object.freeze({ORDER:e,BITS:s,BYTES:o,MASK:Ba(s),ZERO:He,ONE:Ie,create:c=>qe(c,e),isValid:c=>{if(typeof c!="bigint")throw new Error(`Invalid field element: expected bigint, got ${typeof c}`);return He<=c&&cc===He,isOdd:c=>(c&Ie)===Ie,neg:c=>qe(-c,e),eql:(c,u)=>c===u,sqr:c=>qe(c*c,e),add:(c,u)=>qe(c+u,e),sub:(c,u)=>qe(c-u,e),mul:(c,u)=>qe(c*u,e),pow:(c,u)=>xg(a,c,u),div:(c,u)=>qe(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=>vg(a,c),cmov:(c,u,l)=>l?u:c,toBytes:c=>n?Lf(c,o):cr(c,o),fromBytes:c=>{if(c.length!==o)throw new Error(`Fp.fromBytes: expected ${o}, got ${c.length}`);return n?Aa(c):mn(c)}});return Object.freeze(a)}function Eg(e,t,n=!1){e=ot("privateHash",e);const r=e.length,s=Ta(t).nByteLength+8;if(s<24||r1024)throw new Error(`hashToPrivateScalar: expected ${s}-1024 bytes of input, got ${r}`);const o=n?Aa(e):mn(e);return qe(o,t-Ie)+Ie}/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */const kg=BigInt(0),ci=BigInt(1);function Sg(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>kg;)o&ci&&(i=i.add(a)),a=a.double(),o>>=ci;return i},precomputeWindow(s,o){const{windows:i,windowSize:a}=r(o),c=[];let u=s,l=u;for(let f=0;f>=h,b>c&&(b-=d,i+=ci);const m=g,E=g+Math.abs(b)-1,y=p%2!==0,v=b<0;b===0?l=l.add(n(y,o[m])):u=u.add(n(v,o[E]))}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 Kf(e){return Hf(e.Fp),Or(e,{n:"bigint",h:"bigint",Gx:"field",Gy:"field"},{nBitLength:"isSafeInteger",nByteLength:"isSafeInteger"}),Object.freeze({...Ta(e.n,e.nBitLength),...e,p:e.Fp.ORDER})}/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */function $g(e){const t=Kf(e);Or(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:_g,hexToBytes:Ag}=pg,Un={Err:class extends Error{constructor(t=""){super(t)}},_parseInt(e){const{Err:t}=Un;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:_g(r),l:e.subarray(n+2)}},toSig(e){const{Err:t}=Un,n=typeof e=="string"?Ag(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}=Un._parseInt(n.subarray(2)),{d:i,l:a}=Un._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}`}},ht=BigInt(0),Pe=BigInt(1),Rt=BigInt(2),to=BigInt(3),Yc=BigInt(4);function Bg(e){const t=$g(e),{Fp:n}=t,r=t.toBytes||((p,g,b)=>{const m=g.toAffine();return dt(Uint8Array.from([4]),n.toBytes(m.x),n.toBytes(m.y))}),s=t.fromBytes||(p=>{const g=p.subarray(1),b=n.fromBytes(g.subarray(0,n.BYTES)),m=n.fromBytes(g.subarray(n.BYTES,2*n.BYTES));return{x:b,y:m}});function o(p){const{a:g,b}=t,m=n.sqr(p),E=n.mul(m,p);return n.add(n.add(E,n.mul(p,g)),b)}function i(p){return typeof p=="bigint"&&htn.eql(y,n.ZERO);return E(b)&&E(m)?f.ZERO:new f(b,m,n.ONE)}get x(){return this.toAffine().x}get y(){return this.toAffine().y}static normalizeZ(g){const b=n.invertBatch(g.map(m=>m.pz));return g.map((m,E)=>m.toAffine(b[E])).map(f.fromAffine)}static fromHex(g){const b=f.fromAffine(s(ot("pointHex",g)));return b.assertValidity(),b}static fromPrivateKey(g){return f.BASE.multiply(c(g))}_setWindowSize(g){this._WINDOW_SIZE=g,u.delete(this)}assertValidity(){if(this.is0()){if(t.allowInfinityPoint)return;throw new Error("bad point: ZERO")}const{x:g,y:b}=this.toAffine();if(!n.isValid(g)||!n.isValid(b))throw new Error("bad point: x or y not FE");const m=n.sqr(b),E=o(g);if(!n.eql(m,E))throw new Error("bad point: equation left != right");if(!this.isTorsionFree())throw new Error("bad point: not in prime-order subgroup")}hasEvenY(){const{y:g}=this.toAffine();if(n.isOdd)return!n.isOdd(g);throw new Error("Field doesn't support isOdd")}equals(g){l(g);const{px:b,py:m,pz:E}=this,{px:y,py:v,pz:x}=g,B=n.eql(n.mul(b,x),n.mul(y,E)),O=n.eql(n.mul(m,x),n.mul(v,E));return B&&O}negate(){return new f(this.px,n.neg(this.py),this.pz)}double(){const{a:g,b}=t,m=n.mul(b,to),{px:E,py:y,pz:v}=this;let x=n.ZERO,B=n.ZERO,O=n.ZERO,C=n.mul(E,E),T=n.mul(y,y),U=n.mul(v,v),H=n.mul(E,y);return H=n.add(H,H),O=n.mul(E,v),O=n.add(O,O),x=n.mul(g,O),B=n.mul(m,U),B=n.add(x,B),x=n.sub(T,B),B=n.add(T,B),B=n.mul(x,B),x=n.mul(H,x),O=n.mul(m,O),U=n.mul(g,U),H=n.sub(C,U),H=n.mul(g,H),H=n.add(H,O),O=n.add(C,C),C=n.add(O,C),C=n.add(C,U),C=n.mul(C,H),B=n.add(B,C),U=n.mul(y,v),U=n.add(U,U),C=n.mul(U,H),x=n.sub(x,C),O=n.mul(U,T),O=n.add(O,O),O=n.add(O,O),new f(x,B,O)}add(g){l(g);const{px:b,py:m,pz:E}=this,{px:y,py:v,pz:x}=g;let B=n.ZERO,O=n.ZERO,C=n.ZERO;const T=t.a,U=n.mul(t.b,to);let H=n.mul(b,y),K=n.mul(m,v),k=n.mul(E,x),$=n.add(b,m),w=n.add(y,v);$=n.mul($,w),w=n.add(H,K),$=n.sub($,w),w=n.add(b,E);let _=n.add(y,x);return w=n.mul(w,_),_=n.add(H,k),w=n.sub(w,_),_=n.add(m,E),B=n.add(v,x),_=n.mul(_,B),B=n.add(K,k),_=n.sub(_,B),C=n.mul(T,w),B=n.mul(U,k),C=n.add(B,C),B=n.sub(K,C),C=n.add(K,C),O=n.mul(B,C),K=n.add(H,H),K=n.add(K,H),k=n.mul(T,k),w=n.mul(U,w),K=n.add(K,k),k=n.sub(H,k),k=n.mul(T,k),w=n.add(w,k),H=n.mul(K,w),O=n.add(O,H),H=n.mul(_,w),B=n.mul($,B),B=n.sub(B,H),H=n.mul($,K),C=n.mul(_,C),C=n.add(C,H),new f(B,O,C)}subtract(g){return this.add(g.negate())}is0(){return this.equals(f.ZERO)}wNAF(g){return h.wNAFCached(this,u,g,b=>{const m=n.invertBatch(b.map(E=>E.pz));return b.map((E,y)=>E.toAffine(m[y])).map(f.fromAffine)})}multiplyUnsafe(g){const b=f.ZERO;if(g===ht)return b;if(a(g),g===Pe)return this;const{endo:m}=t;if(!m)return h.unsafeLadder(this,g);let{k1neg:E,k1:y,k2neg:v,k2:x}=m.splitScalar(g),B=b,O=b,C=this;for(;y>ht||x>ht;)y&Pe&&(B=B.add(C)),x&Pe&&(O=O.add(C)),C=C.double(),y>>=Pe,x>>=Pe;return E&&(B=B.negate()),v&&(O=O.negate()),O=new f(n.mul(O.px,m.beta),O.py,O.pz),B.add(O)}multiply(g){a(g);let b=g,m,E;const{endo:y}=t;if(y){const{k1neg:v,k1:x,k2neg:B,k2:O}=y.splitScalar(b);let{p:C,f:T}=this.wNAF(x),{p:U,f:H}=this.wNAF(O);C=h.constTimeNegate(v,C),U=h.constTimeNegate(B,U),U=new f(n.mul(U.px,y.beta),U.py,U.pz),m=C.add(U),E=T.add(H)}else{const{p:v,f:x}=this.wNAF(b);m=v,E=x}return f.normalizeZ([m,E])[0]}multiplyAndAddUnsafe(g,b,m){const E=f.BASE,y=(x,B)=>B===ht||B===Pe||!x.equals(E)?x.multiplyUnsafe(B):x.multiply(B),v=y(this,b).add(y(g,m));return v.is0()?void 0:v}toAffine(g){const{px:b,py:m,pz:E}=this,y=this.is0();g==null&&(g=y?n.ONE:n.inv(E));const v=n.mul(b,g),x=n.mul(m,g),B=n.mul(E,g);if(y)return{x:n.ZERO,y:n.ZERO};if(!n.eql(B,n.ONE))throw new Error("invZ was invalid");return{x:v,y:x}}isTorsionFree(){const{h:g,isTorsionFree:b}=t;if(g===Pe)return!0;if(b)return b(f,this);throw new Error("isTorsionFree() has not been declared for the elliptic curve")}clearCofactor(){const{h:g,clearCofactor:b}=t;return g===Pe?this:b?b(f,this):this.multiplyUnsafe(t.h)}toRawBytes(g=!0){return this.assertValidity(),r(f,this,g)}toHex(g=!0){return pr(this.toRawBytes(g))}}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=Sg(f,t.endo?Math.ceil(d/2):d);return{CURVE:t,ProjectivePoint:f,normPrivateKeyToScalar:c,weierstrassEquation:o,isWithinCurveOrder:i}}function Tg(e){const t=Kf(e);return Or(t,{hash:"hash",hmac:"function",randomBytes:"function"},{bits2int:"function",bits2int_modN:"function",lowS:"boolean"}),Object.freeze({lowS:!0,...t})}function Ig(e){const t=Tg(e),{Fp:n,n:r}=t,s=n.BYTES+1,o=2*n.BYTES+1;function i(w){return htpr(cr(w,t.nByteLength));function p(w){const _=r>>Pe;return w>_}function g(w){return p(w)?a(-w):w}const b=(w,_,P)=>mn(w.slice(_,P));class m{constructor(_,P,L){this.r=_,this.s=P,this.recovery=L,this.assertValidity()}static fromCompact(_){const P=t.nByteLength;return _=ot("compactSignature",_,P*2),new m(b(_,0,P),b(_,P,2*P))}static fromDER(_){const{r:P,s:L}=Un.toSig(ot("DER",_));return new m(P,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(_){return new m(this.r,this.s,_)}recoverPublicKey(_){const{r:P,s:L,recovery:N}=this,j=O(ot("msgHash",_));if(N==null||![0,1,2,3].includes(N))throw new Error("recovery id invalid");const M=N===2||N===3?P+t.n:P;if(M>=n.ORDER)throw new Error("recovery id 2 or 3 invalid");const F=(N&1)===0?"02":"03",ue=u.fromHex(F+h(M)),oe=c(M),Q=a(-j*oe),he=a(L*oe),pe=u.BASE.multiplyAndAddUnsafe(ue,Q,he);if(!pe)throw new Error("point at infinify");return pe.assertValidity(),pe}hasHighS(){return p(this.s)}normalizeS(){return this.hasHighS()?new m(this.r,a(-this.s),this.recovery):this}toDERRawBytes(){return gr(this.toDERHex())}toDERHex(){return Un.hexFromSig({r:this.r,s:this.s})}toCompactRawBytes(){return gr(this.toCompactHex())}toCompactHex(){return h(this.r)+h(this.s)}}const E={isValidPrivateKey(w){try{return l(w),!0}catch{return!1}},normPrivateKeyToScalar:l,randomPrivateKey:()=>{const w=t.randomBytes(n.BYTES+8),_=Eg(w,r);return cr(_,t.nByteLength)},precompute(w=8,_=u.BASE){return _._setWindowSize(w),_.multiply(BigInt(3)),_}};function y(w,_=!0){return u.fromPrivateKey(w).toRawBytes(_)}function v(w){const _=w instanceof Uint8Array,P=typeof w=="string",L=(_||P)&&w.length;return _?L===s||L===o:P?L===2*s||L===2*o:w instanceof u}function x(w,_,P=!0){if(v(w))throw new Error("first arg must be private key");if(!v(_))throw new Error("second arg must be public key");return u.fromHex(_).multiply(l(w)).toRawBytes(P)}const B=t.bits2int||function(w){const _=mn(w),P=w.length*8-t.nBitLength;return P>0?_>>BigInt(P):_},O=t.bits2int_modN||function(w){return a(B(w))},C=Ba(t.nBitLength);function T(w){if(typeof w!="bigint")throw new Error("bigint expected");if(!(ht<=w&&wfe in P))throw new Error("sign() legacy options not supported");const{hash:L,randomBytes:N}=t;let{lowS:j,prehash:M,extraEntropy:F}=P;j==null&&(j=!0),w=ot("msgHash",w),M&&(w=ot("prehashed msgHash",L(w)));const ue=O(w),oe=l(_),Q=[T(oe),T(ue)];if(F!=null){const fe=F===!0?N(n.BYTES):F;Q.push(ot("extraEntropy",fe,n.BYTES))}const he=dt(...Q),pe=ue;function Te(fe){const we=B(fe);if(!d(we))return;const Nt=c(we),rt=u.BASE.multiply(we).toAffine(),Ke=a(rt.x);if(Ke===ht)return;const Lt=a(Nt*a(pe+Ke*oe));if(Lt===ht)return;let Rr=(rt.x===Ke?0:2)|Number(rt.y&Pe),Zc=Lt;return j&&p(Lt)&&(Zc=g(Lt),Rr^=1),new m(Ke,Zc,Rr)}return{seed:he,k2sig:Te}}const H={lowS:t.lowS,prehash:!1},K={lowS:t.lowS,prehash:!1};function k(w,_,P=H){const{seed:L,k2sig:N}=U(w,_,P);return Rf(t.hash.outputLen,t.nByteLength,t.hmac)(L,N)}u.BASE._setWindowSize(8);function $(w,_,P,L=K){var rt;const N=w;if(_=ot("msgHash",_),P=ot("publicKey",P),"strict"in L)throw new Error("options.strict was renamed to lowS");const{lowS:j,prehash:M}=L;let F,ue;try{if(typeof N=="string"||N instanceof Uint8Array)try{F=m.fromDER(N)}catch(Ke){if(!(Ke instanceof Un.Err))throw Ke;F=m.fromCompact(N)}else if(typeof N=="object"&&typeof N.r=="bigint"&&typeof N.s=="bigint"){const{r:Ke,s:Lt}=N;F=new m(Ke,Lt)}else throw new Error("PARSE");ue=u.fromHex(P)}catch(Ke){if(Ke.message==="PARSE")throw new Error("signature must be Signature instance, Uint8Array or hex string");return!1}if(j&&F.hasHighS())return!1;M&&(_=t.hash(_));const{r:oe,s:Q}=F,he=O(_),pe=c(Q),Te=a(he*pe),fe=a(oe*pe),we=(rt=u.BASE.multiplyAndAddUnsafe(ue,Te,fe))==null?void 0:rt.toAffine();return we?a(we.x)===oe:!1}return{CURVE:t,getPublicKey:y,getSharedSecret:x,sign:k,verify:$,ProjectivePoint:u,Signature:m,utils:E}}function Og(e,t){const n=e.ORDER;let r=ht;for(let d=n-Pe;d%Rt===ht;d/=Rt)r+=Pe;const s=r,o=(n-Pe)/Rt**s,i=(o-Pe)/Rt,a=Rt**s-Pe,c=Rt**(s-Pe),u=e.pow(t,o),l=e.pow(t,(o+Pe)/Rt);let f=(d,h)=>{let p=u,g=e.pow(h,a),b=e.sqr(g);b=e.mul(b,h);let m=e.mul(d,b);m=e.pow(m,i),m=e.mul(m,g),g=e.mul(m,h),b=e.mul(m,d);let E=e.mul(b,g);m=e.pow(E,c);let y=e.eql(m,e.ONE);g=e.mul(b,l),m=e.mul(E,p),b=e.cmov(g,b,y),E=e.cmov(m,E,y);for(let v=s;v>1;v--){let x=Rt**(v-Rt),B=e.pow(E,x);const O=e.eql(B,e.ONE);g=e.mul(b,p),p=e.mul(p,p),B=e.mul(E,p),b=e.cmov(g,b,O),E=e.cmov(B,E,O)}return{isValid:y,value:b}};if(e.ORDER%Yc===to){const d=(e.ORDER-to)/Yc,h=e.sqrt(e.neg(t));f=(p,g)=>{let b=e.sqr(g);const m=e.mul(p,g);b=e.mul(b,m);let E=e.pow(b,d);E=e.mul(E,m);const y=e.mul(E,h),v=e.mul(e.sqr(E),g),x=e.eql(v,p);let B=e.cmov(y,E,x);return{isValid:x,value:B}}}return f}function Cg(e,t){if(Hf(e),!e.isValid(t.A)||!e.isValid(t.B)||!e.isValid(t.Z))throw new Error("mapToCurveSimpleSWU: invalid opts");const n=Og(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 p=e.isOdd(r)===e.isOdd(f);return f=e.cmov(e.neg(f),f,p),l=e.div(l,a),{x:l,y:f}}}function Pg(e){if(e instanceof Uint8Array)return e;if(typeof e=="string")return Po(e);throw new Error("DST must be Uint8Array or string")}const Ug=mn;function fn(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 Ng(e,t){const n=new Uint8Array(e.length);for(let r=0;r255&&(t=r(dt(Po("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=dt(t,fn(t.length,1)),c=fn(0,o),u=fn(n,2),l=new Array(i),f=r(dt(c,e,u,fn(0,1),a));l[0]=r(dt(f,fn(1,1),a));for(let h=1;h<=i;h++){const p=[Ng(f,l[h-1]),fn(h+1,1),a];l[h]=r(dt(...p))}return dt(...l).slice(0,n)}function Rg(e,t,n,r,s){if(Gr(e),Gr(t),Ia(n),t.length>255){const o=Math.ceil(2*r/8);t=s.create({dkLen:o}).update(Po("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(fn(n,2)).update(t).update(fn(t.length,1)).digest()}function Xc(e,t,n){Or(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;Gr(e),Ia(t);const u=Pg(c),l=r.toString(2).length,f=Math.ceil((l+s)/8),d=t*o*f;let h;if(a==="xmd")h=Lg(e,u,d,i);else if(a==="xof")h=Rg(e,u,d,s,i);else if(a===void 0)h=e;else throw new Error('expand must be "xmd", "xof" or undefined');const p=new Array(t);for(let g=0;gArray.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 jg(e,t,n){if(typeof t!="function")throw new Error("mapToCurve() must be defined");return{hashToCurve(r,s){const o=Xc(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=Xc(r,1,{...n,DST:n.encodeDST,...s}),i=e.fromAffine(t(o[0])).clearCofactor();return i.assertValidity(),i}}}let Df=class extends Of{constructor(t,n){super(),this.finished=!1,this.destroyed=!1,Pn.hash(t);const r=Sa(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 Df(e,t).update(n).digest();Mf.create=(e,t)=>new Df(e,t);/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */function Kg(e){return{hash:e,hmac:(t,...n)=>Mf(e,t,Xp(...n)),randomBytes:Jp}}function Dg(e,t){const n=r=>Ig({...e,...Kg(r)});return Object.freeze({...n(t),create:n})}/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */const Zf=BigInt("0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f"),Jc=BigInt("0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141"),Mg=BigInt(1),Mi=BigInt(2),Qc=(e,t)=>(e+t/Mi)/t;function Zg(e){const t=Zf,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=st(l,n,t)*l%t,d=st(f,n,t)*l%t,h=st(d,Mi,t)*u%t,p=st(h,s,t)*h%t,g=st(p,o,t)*p%t,b=st(g,a,t)*g%t,m=st(b,c,t)*b%t,E=st(m,a,t)*g%t,y=st(E,n,t)*l%t,v=st(y,i,t)*p%t,x=st(v,r,t)*u%t,B=st(x,Mi,t);if(!yn.eql(yn.sqr(B),e))throw new Error("Cannot find square root");return B}const yn=jf(Zf,void 0,void 0,{sqrt:Zg}),Vt=Dg({a:BigInt(0),b:BigInt(7),Fp:yn,n:Jc,Gx:BigInt("55066263022277343669578718895168534326250603453777594175500187360389116729240"),Gy:BigInt("32670510020758816978083085130507043184471273380659243275938904335757337482424"),h:BigInt(1),lowS:!0,endo:{beta:BigInt("0x7ae96a2b657c07106e64479eac3434e99cf0497512f58995c1396c28719501ee"),splitScalar:e=>{const t=Jc,n=BigInt("0x3086d221a7d46bcde86c90e49284eb15"),r=-Mg*BigInt("0xe4437ed6010e88286f547fa90abfe4c3"),s=BigInt("0x114ca50f7a8e2f3f657c1108d9d44cfd8"),o=n,i=BigInt("0x100000000000000000000000000000000"),a=Qc(o*e,t),c=Qc(-r*e,t);let u=qe(e-a*n-c*s,t),l=qe(-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}}}},Uf);BigInt(0);Vt.ProjectivePoint;Vt.utils.randomPrivateKey;const Vg=Hg(yn,[["0x8e38e38e38e38e38e38e38e38e38e38e38e38e38e38e38e38e38e38daaaaa8c7","0x7d3d4c80bc321d5b9f315cea7fd44c5d595d2fc0bf63b92dfff1044f17c6581","0x534c328d23f234e6e2a413deca25caece4506144037c40314ecbd0b53d9dd262","0x8e38e38e38e38e38e38e38e38e38e38e38e38e38e38e38e38e38e38daaaaa88c"],["0xd35771193d94918a9ca34ccbb7b640dd86cd409542f8487d9fe6b745781eb49b","0xedadc6f64383dc1df7c4b2d51b54225406d36b641f5e41bbc52a56612a8c6d14","0x0000000000000000000000000000000000000000000000000000000000000001"],["0x4bda12f684bda12f684bda12f684bda12f684bda12f684bda12f684b8e38e23c","0xc75e0c32d5cb7c0fa9d0a54b12a0a6d5647ab046d686da6fdffc90fc201d71a3","0x29a6194691f91a73715209ef6512e576722830a201be2018a765e85a9ecee931","0x2f684bda12f684bda12f684bda12f684bda12f684bda12f684bda12f38e38d84"],["0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffefffff93b","0x7a06534bb8bdb49fd5e9e6632722c2989467c1bfc8e8d978dfb425d2685c2573","0x6484aa716545ca2cf3a70c3fa8fe337e0a3d21162f0d6299a7bf8192bfd2a76f","0x0000000000000000000000000000000000000000000000000000000000000001"]].map(e=>e.map(t=>BigInt(t)))),qg=Cg(yn,{A:BigInt("0x3f8731abdd661adca08a5558f0f5d272e953d363cb6f0e5d405447c01a444533"),B:BigInt("1771"),Z:yn.create(BigInt("-11"))});jg(Vt.ProjectivePoint,e=>{const{x:t,y:n}=qg(yn.create(e[0]));return Vg(t,n)},{DST:"secp256k1_XMD:SHA-256_SSWU_RO_",encodeDST:"secp256k1_XMD:SHA-256_SSWU_NU_",p:yn.ORDER,m:1,k:128,expand:"xmd",hash:Uf});function Zi(e){if(!Number.isSafeInteger(e)||e<0)throw new Error(`Wrong positive integer: ${e}`)}function zg(e){if(typeof e!="boolean")throw new Error(`Expected boolean, not ${e}`)}function Vf(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 Fg(e){if(typeof e!="function"||typeof e.create!="function")throw new Error("Hash should be wrapped by utils.wrapConstructor");Zi(e.outputLen),Zi(e.blockLen)}function Wg(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 Gg(e,t){Vf(e);const n=t.outputLen;if(e.lengthnew DataView(e.buffer,e.byteOffset,e.byteLength),St=(e,t)=>e<<32-t|e>>>t,Xg=new Uint8Array(new Uint32Array([287454020]).buffer)[0]===68;if(!Xg)throw new Error("Non little-endian hardware is not supported");Array.from({length:256},(e,t)=>t.toString(16).padStart(2,"0"));function Jg(e){if(typeof e!="string")throw new TypeError(`utf8ToBytes expected string, got ${typeof e}`);return new TextEncoder().encode(e)}function qf(e){if(typeof e=="string"&&(e=Jg(e)),!(e instanceof Uint8Array))throw new TypeError(`Expected input type is Uint8Array (got ${typeof e})`);return e}let Qg=class{clone(){return this._cloneInto()}};function zf(e){const t=r=>e().update(qf(r)).digest(),n=e();return t.outputLen=n.outputLen,t.blockLen=n.blockLen,t.create=()=>e(),t}function em(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 tm=class extends Qg{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=fi(this.buffer)}update(t){ui.exists(this);const{view:n,buffer:r,blockLen:s}=this;t=qf(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,rm=(e,t,n)=>e&t^e&n^t&n,sm=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]),Qt=new Uint32Array(64);let Ff=class extends tm{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 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],p=St(d,7)^St(d,18)^d>>>3,g=St(h,17)^St(h,19)^h>>>10;Qt[f]=g+Qt[f-7]+p+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=St(a,6)^St(a,11)^St(a,25),h=l+d+nm(a,c,u)+sm[f]+Qt[f]|0,g=(St(r,2)^St(r,13)^St(r,22))+rm(r,s,o)|0;l=u,u=c,c=a,a=i+h|0,i=o,o=s,s=r,r=h+g|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)}},om=class 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 Vi=zf(()=>new Ff);zf(()=>new om);function im(e,t){if(e.length>t)throw new TypeError(`Data is larger than array size: ${e.length} > ${t}`)}function am(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 cm(e){if(e>Number.MAX_SAFE_INTEGER)throw new TypeError("Number exceeds safe bounds!")}const{getRandomValues:um}=crypto??globalThis.crypto??window.crypto;function fm(e=32){if(typeof um=="function")return crypto.getRandomValues(new Uint8Array(e));throw new Error("Crypto module missing getRandomValues!")}function lm(e,t,n="be"){t===void 0&&(t=e.length),im(e,t);const r=new Uint8Array(t).fill(0),s=n==="be"?0:t-e.length;return r.set(e,s),r}function Wf(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 gm(e,t){const n=Gf(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 Yf(e){return Vi(Vi(e))}function mm(e){const t=Yf(e);return Wf([e,t.slice(0,4)])}function ym(e){const t=e.slice(0,-4),n=e.slice(-4);if(Yf(t).slice(0,4).toString()!==n.toString())throw new Error("Invalid checksum!");return t}const eu={encode:pm,decode:gm},Xf={encode:e=>{const t=mm(e);return eu.encode(t,"base58")},decode:e=>{const t=eu.decode(e,"base58");return ym(t)}},Jf="qpzry9x8gf2tvdw0s3jn54khce6mua7l",bm=[996825010,642813549,513874426,1027748829,705979059],no=[{version:0,name:"bech32",const:1},{version:1,name:"bech32m",const:734539939}];function Qf(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^=bm[s])}return t}function el(e){const t=[];let n;for(n=0;n>5);for(t.push(0),n=0;n>5*(5-i)&31);return o}function tl(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 vm(e,t,n){const r=t.concat(xm(e,t,n));let s=e+"1";for(let o=0;oo.version===t[0])??no[0];if(!wm(r,t,s))throw new Error("Checksum verification failed!");return[r,t.slice(0,t.length-6)]}function Em(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 km(e){const t=e.lastIndexOf("1");return!(t<1||t+7>e.length||e.length>90)}function Sm(e,t="bc",n=0){const r=[n,...tl([...e],8,5)],s=no.find(i=>i.version===n)??no[0],o=vm(t,r,s);return rl(o),o}function rl(e){e=e.toLowerCase();const t=e.split("1",1)[0],[n,r]=nl(e),s=tl(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 $m(e){e=e.toLowerCase();const[t,n]=nl(e);return n[0]}const sl={encode:Sm,decode:rl,version:$m},ol="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",il="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",_m=new TextEncoder;function al(e,t=!1,n=!0){typeof e=="string"&&(e=_m.encode(e));const r=t?il:ol;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 cl(e,t=!1){const n=t||e.includes("-")||e.includes("_")?il.split(""):ol.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 ul={encode:al,decode:cl},fl={encode:e=>al(e,!0,!1),decode:e=>cl(e,!0)},Am=BigInt(0),Bm=BigInt(255),ll=BigInt(256);function Tm(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 Im(e,t,n="be"){t===void 0&&(t=Tm(e));const r=n==="le",s=new ArrayBuffer(t),o=new DataView(s);let i=r?0:t-1;for(;e>Am;){const a=e&Bm,c=Number(a);r?o.setUint8(i++,c):o.setUint8(i--,c),e=(e-a)/ll}return new Uint8Array(s)}function Om(e){let t=BigInt(0);for(let n=e.length-1;n>=0;n--)t=t*ll+BigInt(e[n]);return BigInt(t)}function Cm(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 Um(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 Nm(e,t,n="be"){t===void 0&&(t=Um(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 Lm(e){let t=0;for(let n=e.length-1;n>=0;n--)t=t*256+e[n],cm(t);return t}const Rm=new TextEncoder,Hm=new TextDecoder;function Oa(e){return Rm.encode(e)}function li(e){return Hm.decode(e)}function jm(e,t){am(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 Km(e,t,n="le"){t=jm(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 Oa(t)}function Zm(e,t,n){if(e instanceof ArrayBuffer)return new Uint8Array(e);if(e instanceof Uint8Array)return lm(e,t,n);if(typeof e=="string")return Km(e,t,n);if(typeof e=="bigint")return Im(e,t,n);if(typeof e=="number")return Nm(e,t,n);if(typeof e=="boolean")return Uint8Array.of(e?1:0);throw TypeError("Unsupported format:"+typeof e)}const re=class re extends Uint8Array{static random(t=32){const n=fm(t);return new re(n,t)}constructor(t,n,r){const s=Zm(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 ny(this)}toNum(t="be"){const n=t==="be"?this.reverse():this;return Lm(n)}toBin(){return Pm(this)}toBig(t="be"){const n=t==="be"?this.reverse():this;return Om(n)}toHash(){const t=Vi(this);return new re(t)}toJson(){const t=li(this);return JSON.parse(t)}toBech32(t,n=0){return sl.encode(this,t,n)}toStr(){return li(this)}toHex(){return Dm(this)}toBytes(){return new Uint8Array(this)}tob58chk(){return Xf.encode(this)}toBase64(){return ul.encode(this)}toB64url(){return fl.encode(this)}prepend(t){return re.join([re.bytes(t),this])}append(t){return re.join([this,re.bytes(t)])}slice(t,n){const r=new Uint8Array(this).slice(t,n);return new re(r)}subarray(t,n){const r=new Uint8Array(this).subarray(t,n);return new re(r)}reverse(){const t=new Uint8Array(this).reverse();return new re(t)}write(t,n){const r=re.bytes(t);this.set(r,n)}prefixSize(t){const n=re.varInt(this.length,t);return re.join([n,this])}static from(t){return new re(Uint8Array.from(t))}static of(...t){return new re(Uint8Array.of(...t))}static join(t){const n=t.map(s=>re.bytes(s)),r=Wf(n);return new re(r)}static varInt(t,n){if(t<253)return re.num(t,1);if(t<65536)return re.of(253,...re.num(t,2,n));if(t<4294967296)return re.of(254,...re.num(t,4,n));if(BigInt(t)<0x10000000000000000n)return re.of(255,...re.num(t,8,n));throw new Error(`Value is too large: ${t}`)}};re.num=Vm,re.big=zm,re.bin=qm,re.raw=Fm,re.str=Wm,re.hex=Gm,re.bytes=Ym,re.json=Xm,re.base64=Jm,re.b64url=Qm,re.bech32=ey,re.b58chk=ty,re.encode=Oa,re.decode=li;let Y=re;function Vm(e,t,n){return new Y(e,t,n)}function qm(e,t,n){return new Y(Cm(e),t,n)}function zm(e,t,n){return new Y(e,t,n)}function Fm(e,t,n){return new Y(e,t,n)}function Wm(e,t,n){return new Y(Oa(e),t,n)}function Gm(e,t,n){return new Y(e,t,n)}function Ym(e,t,n){return new Y(e,t,n)}function Xm(e){return new Y(Mm(e))}function Jm(e){return new Y(ul.decode(e))}function Qm(e){return new Y(fl.decode(e))}function ey(e){return new Y(sl.decode(e))}function ty(e){return new Y(Xf.decode(e))}class ny{constructor(t){this.data=Y.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 Y(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 ro=Vt.CURVE,Ca=ro.n,ry=ro.p,sy={x:ro.Gx,y:ro.Gy},oy=BigInt(0);BigInt(1);BigInt(2);BigInt(3);BigInt(4);const qi={N:Ca,P:ry,G:sy,_0n:oy},Hr=jf(Ca,32,!0),dl=e=>qe(e,Ca);function Pa(e,t=!1){if(t)throw new Error(e);return!1}function hl(e){return Y.random(e)}function iy(e){const t=Y.bytes(e).big;return Y.big(dl(t),32)}var ay=Object.freeze({__proto__:null,fail:Pa,mod_bytes:iy,random:hl});const{N:cy,_0n:uy}=qi;function fy(e,t,n){const r=Y.bytes(e);return r.length!==t?Pa(`Invalid byte size: ${r.hex} !== ${t}`,n):!0}function ly(e,t){return typeof e=="bigint"&&uythis.big}lt(t){return new ve(t).big0&&!t.includes(e.length))throw new Error(`Expected Uint8Array of length ${t}, not of length=${e.length}`)}function gy(e){if(typeof e!="function"||typeof e.create!="function")throw new Error("Hash should be wrapped by utils.wrapConstructor");zi(e.outputLen),zi(e.blockLen)}function my(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 yy(e,t){pl(e);const n=t.outputLen;if(e.lengthe instanceof Uint8Array,di=e=>new DataView(e.buffer,e.byteOffset,e.byteLength),$t=(e,t)=>e<<32-t|e>>>t,xy=new Uint8Array(new Uint32Array([287454020]).buffer)[0]===68;if(!xy)throw new Error("Non little-endian hardware is not supported");Array.from({length:256},(e,t)=>t.toString(16).padStart(2,"0"));function vy(e){if(typeof e!="string")throw new Error(`utf8ToBytes expected string, got ${typeof e}`);return new Uint8Array(new TextEncoder().encode(e))}function Ua(e){if(typeof e=="string"&&(e=vy(e)),!wy(e))throw new Error(`expected Uint8Array, got ${typeof e}`);return e}let gl=class{clone(){return this._cloneInto()}};function Jn(e){const t=r=>e().update(Ua(r)).digest(),n=e();return t.outputLen=n.outputLen,t.blockLen=n.blockLen,t.create=()=>e(),t}function Ey(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 gl{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=di(this.buffer)}update(t){Nn.exists(this);const{view:n,buffer:r,blockLen:s}=this;t=Ua(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,Sy=(e,t,n)=>e&t^e&n^t&n,$y=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]),en=new Uint32Array([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]),tn=new Uint32Array(64);let ml=class extends Na{constructor(){super(64,32,8,!1),this.A=en[0]|0,this.B=en[1]|0,this.C=en[2]|0,this.D=en[3]|0,this.E=en[4]|0,this.F=en[5]|0,this.G=en[6]|0,this.H=en[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)tn[f]=t.getUint32(n,!1);for(let f=16;f<64;f++){const d=tn[f-15],h=tn[f-2],p=$t(d,7)^$t(d,18)^d>>>3,g=$t(h,17)^$t(h,19)^h>>>10;tn[f]=g+tn[f-7]+p+tn[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=$t(a,6)^$t(a,11)^$t(a,25),h=l+d+ky(a,c,u)+$y[f]+tn[f]|0,g=($t(r,2)^$t(r,13)^$t(r,22))+Sy(r,s,o)|0;l=u,u=c,c=a,a=i+h|0,i=o,o=s,s=r,r=h+g|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(){tn.fill(0)}destroy(){this.set(0,0,0,0,0,0,0,0),this.buffer.fill(0)}};class _y extends ml{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 so=Jn(()=>new ml);Jn(()=>new _y);const Bs=BigInt(2**32-1),Fi=BigInt(32);function yl(e,t=!1){return t?{h:Number(e&Bs),l:Number(e>>Fi&Bs)}:{h:Number(e>>Fi&Bs)|0,l:Number(e&Bs)|0}}function Ay(e,t=!1){let n=new Uint32Array(e.length),r=new Uint32Array(e.length);for(let s=0;sBigInt(e>>>0)<>>0),Ty=(e,t,n)=>e>>>n,Iy=(e,t,n)=>e<<32-n|t>>>n,Oy=(e,t,n)=>e>>>n|t<<32-n,Cy=(e,t,n)=>e<<32-n|t>>>n,Py=(e,t,n)=>e<<64-n|t>>>n-32,Uy=(e,t,n)=>e>>>n-32|t<<64-n,Ny=(e,t)=>t,Ly=(e,t)=>e,Ry=(e,t,n)=>e<>>32-n,Hy=(e,t,n)=>t<>>32-n,jy=(e,t,n)=>t<>>64-n,Ky=(e,t,n)=>e<>>64-n;function Dy(e,t,n,r){const s=(t>>>0)+(r>>>0);return{h:e+n+(s/2**32|0)|0,l:s|0}}const My=(e,t,n)=>(e>>>0)+(t>>>0)+(n>>>0),Zy=(e,t,n,r)=>t+n+r+(e/2**32|0)|0,Vy=(e,t,n,r)=>(e>>>0)+(t>>>0)+(n>>>0)+(r>>>0),qy=(e,t,n,r,s)=>t+n+r+s+(e/2**32|0)|0,zy=(e,t,n,r,s)=>(e>>>0)+(t>>>0)+(n>>>0)+(r>>>0)+(s>>>0),Fy=(e,t,n,r,s,o)=>t+n+r+s+o+(e/2**32|0)|0,Wy={fromBig:yl,split:Ay,toBig:By,shrSH:Ty,shrSL:Iy,rotrSH:Oy,rotrSL:Cy,rotrBH:Py,rotrBL:Uy,rotr32H:Ny,rotr32L:Ly,rotlSH:Ry,rotlSL:Hy,rotlBH:jy,rotlBL:Ky,add:Dy,add3L:My,add3H:Zy,add4L:Vy,add4H:qy,add5H:Fy,add5L:zy};var ne=Wy;const[Gy,Yy]=ne.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))),nn=new Uint32Array(80),rn=new Uint32Array(80);let Uo=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:p,Hh:g,Hl:b}=this;return[t,n,r,s,o,i,a,c,u,l,f,d,h,p,g,b]}set(t,n,r,s,o,i,a,c,u,l,f,d,h,p,g,b){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=p|0,this.Hh=g|0,this.Hl=b|0}process(t,n){for(let y=0;y<16;y++,n+=4)nn[y]=t.getUint32(n),rn[y]=t.getUint32(n+=4);for(let y=16;y<80;y++){const v=nn[y-15]|0,x=rn[y-15]|0,B=ne.rotrSH(v,x,1)^ne.rotrSH(v,x,8)^ne.shrSH(v,x,7),O=ne.rotrSL(v,x,1)^ne.rotrSL(v,x,8)^ne.shrSL(v,x,7),C=nn[y-2]|0,T=rn[y-2]|0,U=ne.rotrSH(C,T,19)^ne.rotrBH(C,T,61)^ne.shrSH(C,T,6),H=ne.rotrSL(C,T,19)^ne.rotrBL(C,T,61)^ne.shrSL(C,T,6),K=ne.add4L(O,H,rn[y-7],rn[y-16]),k=ne.add4H(K,B,U,nn[y-7],nn[y-16]);nn[y]=k|0,rn[y]=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:p,Gh:g,Gl:b,Hh:m,Hl:E}=this;for(let y=0;y<80;y++){const v=ne.rotrSH(f,d,14)^ne.rotrSH(f,d,18)^ne.rotrBH(f,d,41),x=ne.rotrSL(f,d,14)^ne.rotrSL(f,d,18)^ne.rotrBL(f,d,41),B=f&h^~f&g,O=d&p^~d&b,C=ne.add5L(E,x,O,Yy[y],rn[y]),T=ne.add5H(C,m,v,B,Gy[y],nn[y]),U=C|0,H=ne.rotrSH(r,s,28)^ne.rotrBH(r,s,34)^ne.rotrBH(r,s,39),K=ne.rotrSL(r,s,28)^ne.rotrBL(r,s,34)^ne.rotrBL(r,s,39),k=r&o^r&a^o&a,$=s&i^s&c^i&c;m=g|0,E=b|0,g=h|0,b=p|0,h=f|0,p=d|0,{h:f,l:d}=ne.add(u|0,l|0,T|0,U|0),u=a|0,l=c|0,a=o|0,c=i|0,o=r|0,i=s|0;const w=ne.add3L(U,K,$);r=ne.add3H(w,T,H,k),s=w|0}({h:r,l:s}=ne.add(this.Ah|0,this.Al|0,r|0,s|0)),{h:o,l:i}=ne.add(this.Bh|0,this.Bl|0,o|0,i|0),{h:a,l:c}=ne.add(this.Ch|0,this.Cl|0,a|0,c|0),{h:u,l}=ne.add(this.Dh|0,this.Dl|0,u|0,l|0),{h:f,l:d}=ne.add(this.Eh|0,this.El|0,f|0,d|0),{h,l:p}=ne.add(this.Fh|0,this.Fl|0,h|0,p|0),{h:g,l:b}=ne.add(this.Gh|0,this.Gl|0,g|0,b|0),{h:m,l:E}=ne.add(this.Hh|0,this.Hl|0,m|0,E|0),this.set(r,s,o,i,a,c,u,l,f,d,h,p,g,b,m,E)}roundClean(){nn.fill(0),rn.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 Xy extends Uo{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 Jy extends Uo{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 Qy extends Uo{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 eb=Jn(()=>new Uo);Jn(()=>new Xy);Jn(()=>new Jy);Jn(()=>new Qy);const tb=new Uint8Array([7,4,13,1,10,6,15,3,12,0,9,5,2,14,11,8]),bl=Uint8Array.from({length:16},(e,t)=>t),nb=bl.map(e=>(9*e+5)%16);let La=[bl],Ra=[nb];for(let e=0;e<4;e++)for(let t of[La,Ra])t.push(t[e].map(n=>tb[n]));const wl=[[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)),rb=La.map((e,t)=>e.map(n=>wl[t][n])),sb=Ra.map((e,t)=>e.map(n=>wl[t][n])),ob=new Uint32Array([0,1518500249,1859775393,2400959708,2840853838]),ib=new Uint32Array([1352829926,1548603684,1836072691,2053994217,0]),Ts=(e,t)=>e<>>32-t;function nu(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 ab=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 p=4-h,g=ob[h],b=ib[h],m=La[h],E=Ra[h],y=rb[h],v=sb[h];for(let x=0;x<16;x++){const B=Ts(r+nu(h,o,a,u)+Is[m[x]]+g,y[x])+f|0;r=f,f=u,u=Ts(a,10)|0,a=o,o=B}for(let x=0;x<16;x++){const B=Ts(s+nu(p,i,c,l)+Is[E[x]]+b,v[x])+d|0;s=d,d=l,l=Ts(c,10)|0,c=i,i=B}}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 cb=Jn(()=>new ab);let xl=class extends gl{constructor(t,n){super(),this.finished=!1,this.destroyed=!1,Nn.hash(t);const r=Ua(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 xl(e,t).update(n).digest();vl.create=(e,t)=>new xl(e,t);function ub(e){const t=Y.bytes(e);return Y.raw(so(t))}function mr(e){const t=Y.bytes(e);return Y.raw(so(so(t)))}function Ha(e){const t=Y.bytes(e);return Y.raw(cb(so(t)))}function fb(e,t){const n=Y.bytes(e),r=Y.bytes(t);return Y.raw(vl(eb,n,r))}function lb(e){const t=Y.str(e).digest;return Y.join([t,t])}function db(e=32){return ja(hl(e))}function ja(e){return Ge.mod(e).buff}function El(e,t=!1){const n=Ge.mod(e).point;return t?n.x:n.buff}function kl(e,t){const n=Xn.from_x(t),r=Ge.mod(e);return n.mul(r).buff}function hb(e,t,n="ecdh/code"){const r=lb(n),s=ja(e),o=El(s),i=Y.bytes(t),a=kl(s,i),c=[o.hex,i.hex];return c.sort(),fb(a,Y.join([r,...c]))}function pb(e){const t=Y.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 gb(e){const t=Y.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 mb=Object.freeze({__proto__:null,genSecretKey:db,getPublicKey:El,getSecretKey:ja,getSharedCode:hb,getSharedKey:kl,is_even_pub:pb,xonly_pub:gb});Y.random(32);const Sl={secp:Vt},Wi={...mb,...ay};function No(e){const t=S.bytes(e);return Ut(t,33),Ha(t)}function $l(e){const t=Be.fmt.toBytes(e,!1);return Ha(t)}function _l(e){const t=Be.fmt.toBytes(e,!1);return ub(t)}function Al(e,t="main"){const n=t==="main"?["1"]:["m","n"];for(const r of n)if(e.startsWith(r))return!0;return!1}function Bl(e,t="main"){const n=S.bytes(e),r=t==="main"?S.num(0):S.num(111);return Ut(e,20),n.prepend(r).tob58chk()}function yb(e,t="main"){if(!Al(e,t))throw new TypeError("Invalid p2pkh address!");return S.b58chk(e).slice(1)}function bb(e){const t=S.bytes(e);return Ut(t,20),["OP_DUP","OP_HASH160",t.hex,"OP_EQUALVERIFY","OP_CHECKSIG"]}function wb(e,t){const n=No(e);return Bl(n,t)}const Tl={check:Al,encode:Bl,decode:yb,hash:No,scriptPubKey:bb,fromPubKey:wb};function Il(e,t="main"){const n=t==="main"?["3"]:["2"];for(const r of n)if(e.startsWith(r))return!0;return!1}function Ol(e,t="main"){const n=t==="main"?S.num(5):S.num(196),r=S.bytes(e);return Ut(r,20),r.prepend(n).tob58chk()}function xb(e,t="main"){if(!Il(e,t))throw new TypeError(`Invalid p2sh address for network ${t}:`+e);return S.b58chk(e).slice(1)}function vb(e){return["OP_HASH160",S.bytes(e).hex,"OP_EQUAL"]}function Eb(e,t){const n=$l(e);return Ol(n,t)}const Cl={check:Il,encode:Ol,decode:xb,hash:$l,scriptPubKey:vb,fromScript:Eb},Ka={main:"bc",testnet:"tb",signet:"tb",regtest:"bcrt"},kb=["bc1q","tb1q","bcrt1q"];function Pl(e){for(const t of kb)if(e.startsWith(t))return!0;return!1}function Ul(e,t="main"){const n=Ka[t],r=S.bytes(e);return Ut(r,20),r.toBech32(n,0)}function Sb(e){if(!Pl(e))throw new TypeError("Invalid segwit address!");return S.bech32(e)}function $b(e){const t=S.bytes(e);return Ut(t,20),["OP_0",t.hex]}function _b(e,t){const n=No(e);return Ul(n,t)}const Nl={check:Pl,encode:Ul,decode:Sb,hash:No,scriptPubKey:$b,fromPubKey:_b},Ab=["bc1q","tb1q","bcrt1q"];function Ll(e){for(const t of Ab)if(e.startsWith(t))return!0;return!1}function Rl(e,t="main"){const n=Ka[t],r=S.bytes(e);return Ut(r,32),r.toBech32(n,0)}function Bb(e){if(!Ll(e))throw new TypeError("Invalid segwit address!");return S.bech32(e)}function Tb(e){const t=S.bytes(e);return Ut(t,32),["OP_0",t.hex]}function Ib(e,t){const n=_l(e);return Rl(n,t)}const Hl={check:Ll,encode:Rl,decode:Bb,hash:_l,scriptPubKey:Tb,fromScript:Ib};function Mn(e){const t=S.bytes(e);return t.length>32?t.slice(1,33):t}const Ob=["bc1p","tb1p","bcrt1p"];function jl(e){for(const t of Ob)if(e.startsWith(t))return!0;return!1}function Kl(e,t="main"){const n=Ka[t],r=S.bytes(e);return Ut(r,32),r.toBech32(n,1)}function Cb(e){if(!jl(e))throw new TypeError("Invalid taproot address!");return S.bech32(e)}function Pb(e){const t=S.bytes(e);return Ut(t,32),["OP_1",t.hex]}function Ub(e,t){const n=Mn(e);return Kl(n,t)}const Dl={check:jl,encode:Kl,decode:Cb,scriptPubKey:Pb,fromPubKey:Ub},Nb={version:2,vin:[],vout:[],locktime:0},Lb={scriptSig:[],sequence:4294967293,witness:[]},Rb={value:0n,scriptPubKey:[]};function Da(e){const t={...Nb,...e};return t.vin=t.vin.map(n=>({...Lb,...n})),t.vout=t.vout.map(n=>({...Rb,...n})),t}function yr(e,t){const{version:n,vin:r,vout:s,locktime:o}=Da(e),i=t!==!0&&Hb(r),a=[Ma(n)];i&&a.push(S.hex("0001")),a.push(jb(r)),a.push(Kb(s));for(const c of r)i&&a.push(Mb(c.witness));return a.push(Za(o)),S.join(a)}function Hb(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 Ma(e){return S.num(e,4).reverse()}function ps(e){return S.hex(e,32).reverse()}function gs(e){return S.num(e,4).reverse()}function ms(e){if(typeof e=="string")return S.hex(e,4).reverse();if(typeof e=="number")return S.num(e,4).reverse();throw new Error("Unrecognized format: "+String(e))}function jb(e){const t=[S.varInt(e.length,"le")];for(const n of e){const{txid:r,vout:s,scriptSig:o,sequence:i}=n;t.push(ps(r)),t.push(gs(s)),t.push(Yn(o,!0)),t.push(ms(i))}return S.join(t)}function bn(e){if(typeof e=="number"){if(e%1!==0)throw new Error("Value must be an integer:"+String(e));return S.num(e,8).reverse()}return S.big(e,8).reverse()}function Kb(e){const t=[S.varInt(e.length,"le")];for(const n of e)t.push(Db(n));return S.join(t)}function Db(e){const{value:t,scriptPubKey:n}=e,r=[];return r.push(bn(t)),r.push(Yn(n,!0)),S.join(r)}function Mb(e=[]){const t=[];if(Array.isArray(e)){const n=S.varInt(e.length);t.push(n);for(const r of e)t.push(Zb(r));return S.join(t)}else return S.bytes(e)}function Zb(e){return Vb(e)?new S(0):Yn(e,!0)}function Vb(e){if(Array.isArray(e))return e.length===0;if(typeof e=="string"&&e==="")return!0;const t=S.bytes(e);return t.length===1&&t[0]===0}function Za(e){if(typeof e=="string")return S.hex(e,4);if(typeof e=="number")return S.num(e,4).reverse();throw new Error("Unrecognized format: "+String(e))}function Va(e){typeof e=="string"&&(e=S.hex(e).raw);const t=new Ir(e),n=qb(t),r=zb(t),s=Fb(t),o=Gb(t);if(r)for(const a of s)a.witness=Xb(t);const i=Jb(t);return{version:n,vin:s,vout:o,locktime:i}}function qb(e){return e.read(4).reverse().toNum()}function zb(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 Fb(e){const t=[],n=e.readSize("le");for(let r=0;r0?e.read(n).hex:null}function Zl(e,t){const n=Ml(e);return n!==null?n:[]}function Jb(e){return e.read(4).reverse().toNum()}function Qb(e){if(Bf(e))return Va(e);if(typeof e=="object"&&!(e instanceof Uint8Array))return yr(e),Da(e);throw new Error("Invalid format: "+typeof e)}function ew(e){if(Bf(e))return Va(e),S.bytes(e);if(typeof e=="object")return yr(e);throw new Error("Invalid format: "+typeof e)}const qa={toBytes:ew,toJson:Qb},tw=[["p2pkh",/^76a914(?\w{40})88ac$/],["p2sh",/^a914(?\w{40})87$/],["p2w-pkh",/^0014(?\w{40})$/],["p2w-sh",/^0020(?\w{64})$/],["p2tr",/^5120(?\w{64})$/]],nw=[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 rw(e){let t=e.at(-1);return Ft(t)&&(t=S.hex(t)),e.length>1&&t instanceof Uint8Array&&t[0]===80?(e.pop(),S.raw(t)):null}function sw(e){let t=e.at(-1);return Ft(t)&&(t=S.hex(t)),e.length>1&&t instanceof Uint8Array&&t.length>32&&nw.includes(t[0]&254)?(e.pop(),S.raw(t)):null}function ow(e){if(e.length>1){const t=e.at(-1);try{const n=Be.fmt.toBytes(t);return e.pop(),n}catch{return null}}return null}function iw(e){const t=[];for(const n of e)if(Ft(n)||n instanceof Uint8Array||typeof n=="number")t.push(S.bytes(n));else throw new Error("unrecognized value: "+String(n));return t}function aw(e=[]){const t=[...e],n=rw(t),r=sw(t),s=ow(t),o=iw(t);return{annex:n,cblock:r,script:s,params:o}}function cw(e){const t=Be.fmt.toBytes(e,!1).hex;for(const[n,r]of tw){const s=n,{groups:o}=r.exec(t)??{},{hash:i}=o??{};if(Ft(i))return{type:s,data:S.hex(i)}}return{type:"raw",data:S.hex(t)}}function uw(e){const t=qa.toJson(e),n=yr(t,!0);return mr(n).reverse().hex}function fw(e){const t=qa.toJson(e),n=yr(t,!0).length,r=yr(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 ie={create:Da,encode:yr,decode:Va,fmt:qa,util:{getTxSize:fw,getTxid:uw,readScriptPubKey:cw,readWitness:aw}},lw=[["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 dw(e,t){switch(t){case"base58":return S.b58chk(e).slice(1);case"bech32":return S.bech32(e);case"bech32m":return S.bech32(e);default:throw new Error("Invalid address format: "+t)}}function hw(e){for(const t of lw){const[n,r,s,o,i]=t;if(e.startsWith(n)&&dw(e,i).length===o)return t}throw new Error("Invalid address: "+e)}function Vl(e){switch(e){case"p2pkh":return Tl;case"p2sh":return Cl;case"p2w-pkh":return Nl;case"p2w-sh":return Hl;case"p2tr":return Dl;default:throw new Error("Invalid address type: "+e)}}function ql(e){const[t,n,r]=hw(e),s=Vl(n),o=s.decode(e,r),i=s.scriptPubKey(o);return{prefix:t,type:n,network:r,data:o,script:i}}function pw(e,t){const{type:n,data:r}=ie.util.readScriptPubKey(e);return Vl(n).encode(r,t)}function gw(e){const{script:t}=ql(e);return Be.fmt.toAsm(t,!1)}const Yr={p2pkh:Tl,p2sh:Cl,p2wpkh:Nl,p2wsh:Hl,p2tr:Dl,decode:ql,fromScriptPubKey:pw,toScriptPubKey:gw},mw=[1,2,3];function za(e,t,n={}){const{sigflag:r=1}=n,s=(r&128)===128,o=r%128;if(!mw.includes(o))throw new Error("Invalid hash type: "+String(r));const i=ie.fmt.toJson(e),{version:a,vin:c,vout:u,locktime:l}=i,{txid:f,vout:d,prevout:h,sequence:p}=c[t],{value:g}=h??{};if(g===void 0)throw new Error("Prevout value is empty!");let b=n.script;if(b===void 0&&n.pubkey!==void 0&&(b=`76a914${Ha(n.pubkey).hex}88ac`),b===void 0)throw new Error("No pubkey / script has been set!");if(Be.fmt.toAsm(b).includes("OP_CODESEPARATOR"))throw new Error("This library does not currently support the use of OP_CODESEPARATOR in segwit scripts.");const m=[Ma(a),yw(c,s),bw(c,o,s),ps(f),gs(d),Be.encode(b,!0),bn(g),ms(p),ww(u,t,o),Za(l),S.num(r,4).reverse()];return mr(S.join(m))}function yw(e,t){if(t===!0)return S.num(0,32);const n=[];for(const{txid:r,vout:s}of e)n.push(ps(r)),n.push(gs(s));return mr(S.join(n))}function bw(e,t,n){if(n||t!==1)return S.num(0,32);const r=[];for(const{sequence:s}of e)r.push(ms(s));return mr(S.join(r))}function ww(e,t,n){const r=[];if(n===1){for(const{value:s,scriptPubKey:o}of e)r.push(bn(s)),r.push(Be.encode(o,!0));return mr(S.join(r))}if(n===3&&t1&&c[1].length===33)u=S.bytes(c[1]);else return Ve("No pubkey provided!",s);const l=Be.fmt.toParam(c[0]),f=l.slice(0,-1),d=l.slice(-1)[0],h=za(r,t,{...n,sigflag:d});return Sl.secp.verify(f,h,u)?!0:Ve("Invalid signature!",s)}const Ew={hash:za,sign:xw,verify:vw},kw=[0,1,2,3,129,130,131];function Fa(e,t,n={}){const{extension:r,sigflag:s=0,extflag:o=0,key_version:i=0,separator_pos:a=4294967295}=n,c=ie.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(!kw.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:p,sequence:g,witness:b=[]}=l[t],m=(s&128)===128,E=Iw(b),y=E!==void 0?1:0,x=(o+(r!==void 0?1:0))*2+y,B=S.str("TapSighash").digest,O=[B,B,S.num(0,1),S.num(s,1),Ma(u),Za(d)];if(!m){const C=l.map(T=>ru(T));O.push(Sw(l),_w(C),Aw(C),$w(l))}if(((s&3)<2||(s&3)>3)&&O.push(Bw(f)),O.push(S.num(x,1)),m){const{value:C,scriptPubKey:T}=ru(l[t]);O.push(ps(h),gs(p),bn(C),Be.encode(T,!0),ms(g))}else O.push(S.num(t,4).reverse());return E!==void 0&&O.push(E),(s&3)===3&&O.push(Tw(f[t])),r!==void 0&&O.push(S.bytes(r),S.num(i),S.num(a,4,"le")),S.join(O).digest}function Sw(e){const t=[];for(const{txid:n,vout:r}of e)t.push(ps(n)),t.push(gs(r));return S.join(t).digest}function $w(e){const t=[];for(const{sequence:n}of e)t.push(ms(n));return S.join(t).digest}function _w(e){const t=[];for(const{value:n}of e)t.push(bn(n));return S.join(t).digest}function Aw(e){const t=[];for(const{scriptPubKey:n}of e)t.push(Yn(n,!0));return S.join(t).digest}function Bw(e){const t=[];for(const{value:n,scriptPubKey:r}of e)t.push(bn(n)),t.push(Be.encode(r,!0));return S.join(t).digest}function Tw(e){return S.join([bn(e.value),Be.encode(e.scriptPubKey,!0)]).digest}function Iw(e){if(e===void 0||e.length<2)return;let t=e.at(-1);if(typeof t=="string"&&(t=S.hex(t)),t instanceof Uint8Array&&t[0]===80)return S.raw(t).prefixSize("be").digest}function ru(e){if(e.prevout===void 0)throw new Error("Prevout data missing for input: "+String(e.txid));return e.prevout}const Ow=0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2fn,Cw=0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141n;function Pw(e,t,n,r={}){const{sigflag:s=0}=r,o=Fa(t,n,r),i=Uw(e,o);return s===0?S.raw(i):S.join([i,s])}function Uw(e,t,n=S.random(32)){const r=S.bytes(t),s=new Ge(e),o=s.point,i=o.hasEvenY?s.big:s.negated.big,a=Fs("BIP0340/aux",S.bytes(n)),c=i^a.big,u=Fs("BIP0340/nonce",c,o.x.raw,r),l=new Ge(u),f=l.point,d=f.hasEvenY?l.big:l.negated.big,h=new Ge(Fs("BIP0340/challenge",f.x.raw,o.x.raw,r)),p=new Ge(d+h.big*i);return S.join([f.x.raw,p.raw])}function Nw(e,t,n,r=!1){const s=Xn.from_x(Mn(n)),o=S.bytes(t),i=S.bytes(e).stream;i.size<64&&Ve("Signature length is too small: "+String(i.size),r);const a=i.read(32);a.big>Ow&&Ve("Signature r value greater than field size!",r);const c=i.read(32);c.big>Cw&&Ve("Signature s value greater than curve order!",r);const u=new Ge(Fs("BIP0340/challenge",a.raw,s.x.raw,o)),l=new Ge(c).point,f=s.mul(u.big),d=l.sub(f);return d.hasOddY&&Ve("Signature R value has odd Y coordinate!",r),d.x.big===0n&&Ve("Signature R value is infinite!",r),d.x.big===a.big}const Lw=192;function Lo(e){const t=S.str(e).digest;return S.join([t,t])}function Wa(e,t=Lw){return S.join([Lo("TapLeaf"),jw(t),S.bytes(e)]).digest.hex}function Rw(e,t){return Wa(Be.fmt.toBytes(e),t)}function Ga(e,t){return t0){const[h,p,g]=oo(r,i);c=g,a=ur(e,h,n)}else i!==void 0?a=ur(e,i,n):a=ur(e,void 0,n);const u=n?Wi.getPublicKey(a)[0]:a[0],f=[S.num(s+Xl(u)),o];c.length>0&&c.forEach(h=>f.push(S.hex(h)));const d=S.join(f);if(i!==void 0&&!Ya(a,i,d,t))throw new Error("Path checking failed! Unable to generate path.");return[Mn(a).hex,d.hex]}function Ya(e,t,n,r={}){const{isPrivate:s=!1,throws:o=!1}=r,{parity:i,paths:a,intkey:c}=Yl(n),u=s?Wi.getPublicKey(e,!0):Mn(e),l=S.join([i,u]);if(l.length!==33)return Ve("Invalid tapkey: "+l.hex,o);let f=S.bytes(t).hex;for(const h of a)f=Ga(f,h);const d=ur(c,f);return S.raw(d).hex===S.raw(l).hex}function Yl(e){const t=new Ir(S.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 Xl(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 Fw(e,t,n={}){const r=ie.fmt.toJson(e),{throws:s=!1}=n,{prevout:o,witness:i=[]}=r.vin[t],a=ie.util.readWitness(i),{cblock:c,script:u,params:l}=a;let f;if(l.length<1)return Ve("Invalid witness data: "+String(i),s);const{scriptPubKey:d}=o??{};if(d===void 0)return Ve("Prevout scriptPubKey is empty!",s);const{type:h,data:p}=ie.util.readScriptPubKey(d);if(h!=="p2tr")return Ve("Prevout script is not a valid taproot output:"+p.hex,s);if(p.length!==32)return Ve("Invalid tapkey length: "+String(p.length),s);if(c!==null&&u!==null){const y=c[0]&254,v=Wa(u,y);if(n.extension=v,!Ya(p,v,c,{throws:s}))return Ve("cblock verification failed!",s)}n.pubkey!==void 0?f=S.bytes(n.pubkey):l.length>1&&l[1].length===32?f=S.bytes(l[1]):f=S.bytes(p);const g=Be.fmt.toParam(l[0]),b=new Ir(g),m=b.read(64).raw;if(b.size===1&&(n.sigflag=b.read(1).num,n.sigflag===0))return Ve("0x00 is not a valid appended sigflag!",s);const E=Fa(r,t,n);return Nw(m,E,f,s)?!0:Ve("Invalid signature!",s)}const Ww={hash:Fa,sign:Pw,verify:Fw},br={segwit:Ew,taproot:Ww},Gw={getTag:Lo,getLeaf:Wa,getBranch:Ga,getRoot:Hw},Yw={readCtrlBlock:Yl,readParityBit:Xl},Xw={getPubKey:Kw,getSecKey:Dw,getTweak:zl,tweakSecKey:Fl,tweakPubKey:Wl},Ro={getPubKey:zw,getSecKey:qw,encodeScript:Rw,checkPath:Ya,tree:Gw,tweak:Xw,util:Yw,SCRIPT_PUBKEY:Zw};var ge;(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})(ge||(ge={}));var Gi;(function(e){e.mergeShapes=(t,n)=>({...t,...n})})(Gi||(Gi={}));const Z=ge.arrayToEnum(["string","nan","number","integer","float","boolean","date","bigint","symbol","function","undefined","null","array","object","unknown","promise","void","never","map","set"]),dn=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=ge.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"]),Jw=e=>JSON.stringify(e,null,2).replace(/"([^"]+)":/g,"$1:");class mt 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()}}mt.create=e=>new mt(e);const Xr=(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,ge.jsonStringifyReplacer)}`;break;case R.unrecognized_keys:n=`Unrecognized key(s) in object: ${ge.joinValues(e.keys,", ")}`;break;case R.invalid_union:n="Invalid input";break;case R.invalid_union_discriminator:n=`Invalid discriminator value. Expected ${ge.joinValues(e.options)}`;break;case R.invalid_enum_value:n=`Invalid enum value. Expected ${ge.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}"`:ge.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,ge.assertNever(e)}return{message:n}};let Jl=Xr;function Qw(e){Jl=e}function io(){return Jl}const ao=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}},e1=[];function V(e,t){const n=ao({issueData:t,data:e.data,path:e.path,errorMaps:[e.common.contextualErrorMap,e.schemaErrorMap,io(),Xr].filter(r=>!!r)});e.common.issues.push(n)}class Fe{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 J;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 Fe.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 J;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 J=Object.freeze({status:"aborted"}),Ql=e=>({status:"dirty",value:e}),Je=e=>({status:"valid",value:e}),Yi=e=>e.status==="aborted",Xi=e=>e.status==="dirty",co=e=>e.status==="valid",uo=e=>typeof Promise<"u"&&e instanceof Promise;var W;(function(e){e.errToObj=t=>typeof t=="string"?{message:t}:t||{},e.toString=t=>typeof t=="string"?t:t==null?void 0:t.message})(W||(W={}));class Ct{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 su=(e,t)=>{if(co(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 mt(e.common.issues);return this._error=n,this._error}}};function te(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 se{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 dn(t.data)}_getOrReturnCtx(t,n){return n||{common:t.parent.common,data:t.data,parsedType:dn(t.data),schemaErrorMap:this._def.errorMap,path:t.path,parent:t.parent}}_processInputParams(t){return{status:new Fe,ctx:{common:t.parent.common,data:t.data,parsedType:dn(t.data),schemaErrorMap:this._def.errorMap,path:t.path,parent:t.parent}}}_parseSync(t){const n=this._parse(t);if(uo(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:dn(t)},o=this._parseSync({data:t,path:s.path,parent:s});return su(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:dn(t)},s=this._parse({data:t,path:r.path,parent:r}),o=await(uo(s)?s:Promise.resolve(s));return su(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 wt({schema:this,typeName:G.ZodEffects,effect:{type:"refinement",refinement:t}})}superRefine(t){return this._refinement(t)}optional(){return Mt.create(this,this._def)}nullable(){return qn.create(this,this._def)}nullish(){return this.nullable().optional()}array(){return yt.create(this,this._def)}promise(){return xr.create(this,this._def)}or(t){return ts.create([this,t],this._def)}and(t){return ns.create(this,t,this._def)}transform(t){return new wt({...te(this._def),schema:this,typeName:G.ZodEffects,effect:{type:"transform",transform:t}})}default(t){const n=typeof t=="function"?t:()=>t;return new as({...te(this._def),innerType:this,defaultValue:n,typeName:G.ZodDefault})}brand(){return new td({typeName:G.ZodBranded,type:this,...te(this._def)})}catch(t){const n=typeof t=="function"?t:()=>t;return new po({...te(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 ys.create(this,t)}isOptional(){return this.safeParse(void 0).success}isNullable(){return this.safeParse(null).success}}const t1=/^c[^\s-]{8,}$/i,n1=/^[a-z][a-z0-9]*$/,r1=/[0-9A-HJKMNP-TV-Z]{26}/,s1=/^([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,o1=/^(([^<>()[\]\\.,;:\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,})+))$/,i1=new RegExp("^(\\p{Extended_Pictographic}|\\p{Emoji_Component})+$","u"),a1=/^(((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}))$/,c1=/^(([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})))$/,u1=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 f1(e,t){return!!((t==="v4"||!t)&&a1.test(e)||(t==="v6"||!t)&&c1.test(e))}class pt extends se{constructor(){super(...arguments),this._regex=(t,n,r)=>this.refinement(s=>t.test(s),{validation:n,code:R.invalid_string,...W.errToObj(r)}),this.nonempty=t=>this.min(1,W.errToObj(t)),this.trim=()=>new pt({...this._def,checks:[...this._def.checks,{kind:"trim"}]}),this.toLowerCase=()=>new pt({...this._def,checks:[...this._def.checks,{kind:"toLowerCase"}]}),this.toUpperCase=()=>new pt({...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 V(o,{code:R.invalid_type,expected:Z.string,received:o.parsedType}),J}const r=new Fe;let s;for(const o of this._def.checks)if(o.kind==="min")t.data.lengtho.value&&(s=this._getOrReturnCtx(t,s),V(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,...W.errToObj(t==null?void 0:t.message)})}regex(t,n){return this._addCheck({kind:"regex",regex:t,...W.errToObj(n)})}includes(t,n){return this._addCheck({kind:"includes",value:t,position:n==null?void 0:n.position,...W.errToObj(n==null?void 0:n.message)})}startsWith(t,n){return this._addCheck({kind:"startsWith",value:t,...W.errToObj(n)})}endsWith(t,n){return this._addCheck({kind:"endsWith",value:t,...W.errToObj(n)})}min(t,n){return this._addCheck({kind:"min",value:t,...W.errToObj(n)})}max(t,n){return this._addCheck({kind:"max",value:t,...W.errToObj(n)})}length(t,n){return this._addCheck({kind:"length",value:t,...W.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 pt({checks:[],typeName:G.ZodString,coerce:(t=e==null?void 0:e.coerce)!==null&&t!==void 0?t:!1,...te(e)})};function l1(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 wn extends se{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 V(o,{code:R.invalid_type,expected:Z.number,received:o.parsedType}),J}let r;const s=new Fe;for(const o of this._def.checks)o.kind==="int"?ge.isInteger(t.data)||(r=this._getOrReturnCtx(t,r),V(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),V(r,{code:R.too_big,maximum:o.value,type:"number",inclusive:o.inclusive,exact:!1,message:o.message}),s.dirty()):o.kind==="multipleOf"?l1(t.data,o.value)!==0&&(r=this._getOrReturnCtx(t,r),V(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),V(r,{code:R.not_finite,message:o.message}),s.dirty()):ge.assertNever(o);return{status:s.value,value:t.data}}gte(t,n){return this.setLimit("min",t,!0,W.toString(n))}gt(t,n){return this.setLimit("min",t,!1,W.toString(n))}lte(t,n){return this.setLimit("max",t,!0,W.toString(n))}lt(t,n){return this.setLimit("max",t,!1,W.toString(n))}setLimit(t,n,r,s){return new wn({...this._def,checks:[...this._def.checks,{kind:t,value:n,inclusive:r,message:W.toString(s)}]})}_addCheck(t){return new wn({...this._def,checks:[...this._def.checks,t]})}int(t){return this._addCheck({kind:"int",message:W.toString(t)})}positive(t){return this._addCheck({kind:"min",value:0,inclusive:!1,message:W.toString(t)})}negative(t){return this._addCheck({kind:"max",value:0,inclusive:!1,message:W.toString(t)})}nonpositive(t){return this._addCheck({kind:"max",value:0,inclusive:!0,message:W.toString(t)})}nonnegative(t){return this._addCheck({kind:"min",value:0,inclusive:!0,message:W.toString(t)})}multipleOf(t,n){return this._addCheck({kind:"multipleOf",value:t,message:W.toString(n)})}finite(t){return this._addCheck({kind:"finite",message:W.toString(t)})}safe(t){return this._addCheck({kind:"min",inclusive:!0,value:Number.MIN_SAFE_INTEGER,message:W.toString(t)})._addCheck({kind:"max",inclusive:!0,value:Number.MAX_SAFE_INTEGER,message:W.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"&&ge.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 wn({checks:[],typeName:G.ZodNumber,coerce:(e==null?void 0:e.coerce)||!1,...te(e)});class xn extends se{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 V(o,{code:R.invalid_type,expected:Z.bigint,received:o.parsedType}),J}let r;const s=new Fe;for(const o of this._def.checks)o.kind==="min"?(o.inclusive?t.datao.value:t.data>=o.value)&&(r=this._getOrReturnCtx(t,r),V(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),V(r,{code:R.not_multiple_of,multipleOf:o.value,message:o.message}),s.dirty()):ge.assertNever(o);return{status:s.value,value:t.data}}gte(t,n){return this.setLimit("min",t,!0,W.toString(n))}gt(t,n){return this.setLimit("min",t,!1,W.toString(n))}lte(t,n){return this.setLimit("max",t,!0,W.toString(n))}lt(t,n){return this.setLimit("max",t,!1,W.toString(n))}setLimit(t,n,r,s){return new xn({...this._def,checks:[...this._def.checks,{kind:t,value:n,inclusive:r,message:W.toString(s)}]})}_addCheck(t){return new xn({...this._def,checks:[...this._def.checks,t]})}positive(t){return this._addCheck({kind:"min",value:BigInt(0),inclusive:!1,message:W.toString(t)})}negative(t){return this._addCheck({kind:"max",value:BigInt(0),inclusive:!1,message:W.toString(t)})}nonpositive(t){return this._addCheck({kind:"max",value:BigInt(0),inclusive:!0,message:W.toString(t)})}nonnegative(t){return this._addCheck({kind:"min",value:BigInt(0),inclusive:!0,message:W.toString(t)})}multipleOf(t,n){return this._addCheck({kind:"multipleOf",value:t,message:W.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 xn({checks:[],typeName:G.ZodBigInt,coerce:(t=e==null?void 0:e.coerce)!==null&&t!==void 0?t:!1,...te(e)})};class Jr extends se{_parse(t){if(this._def.coerce&&(t.data=!!t.data),this._getType(t)!==Z.boolean){const r=this._getOrReturnCtx(t);return V(r,{code:R.invalid_type,expected:Z.boolean,received:r.parsedType}),J}return Je(t.data)}}Jr.create=e=>new Jr({typeName:G.ZodBoolean,coerce:(e==null?void 0:e.coerce)||!1,...te(e)});class Zn extends se{_parse(t){if(this._def.coerce&&(t.data=new Date(t.data)),this._getType(t)!==Z.date){const o=this._getOrReturnCtx(t);return V(o,{code:R.invalid_type,expected:Z.date,received:o.parsedType}),J}if(isNaN(t.data.getTime())){const o=this._getOrReturnCtx(t);return V(o,{code:R.invalid_date}),J}const r=new Fe;let s;for(const o of this._def.checks)o.kind==="min"?t.data.getTime()o.value&&(s=this._getOrReturnCtx(t,s),V(s,{code:R.too_big,message:o.message,inclusive:!0,exact:!1,maximum:o.value,type:"date"}),r.dirty()):ge.assertNever(o);return{status:r.value,value:new Date(t.data.getTime())}}_addCheck(t){return new Zn({...this._def,checks:[...this._def.checks,t]})}min(t,n){return this._addCheck({kind:"min",value:t.getTime(),message:W.toString(n)})}max(t,n){return this._addCheck({kind:"max",value:t.getTime(),message:W.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 Zn({checks:[],coerce:(e==null?void 0:e.coerce)||!1,typeName:G.ZodDate,...te(e)});class fo extends se{_parse(t){if(this._getType(t)!==Z.symbol){const r=this._getOrReturnCtx(t);return V(r,{code:R.invalid_type,expected:Z.symbol,received:r.parsedType}),J}return Je(t.data)}}fo.create=e=>new fo({typeName:G.ZodSymbol,...te(e)});class Qr extends se{_parse(t){if(this._getType(t)!==Z.undefined){const r=this._getOrReturnCtx(t);return V(r,{code:R.invalid_type,expected:Z.undefined,received:r.parsedType}),J}return Je(t.data)}}Qr.create=e=>new Qr({typeName:G.ZodUndefined,...te(e)});class es extends se{_parse(t){if(this._getType(t)!==Z.null){const r=this._getOrReturnCtx(t);return V(r,{code:R.invalid_type,expected:Z.null,received:r.parsedType}),J}return Je(t.data)}}es.create=e=>new es({typeName:G.ZodNull,...te(e)});class wr extends se{constructor(){super(...arguments),this._any=!0}_parse(t){return Je(t.data)}}wr.create=e=>new wr({typeName:G.ZodAny,...te(e)});class Kn extends se{constructor(){super(...arguments),this._unknown=!0}_parse(t){return Je(t.data)}}Kn.create=e=>new Kn({typeName:G.ZodUnknown,...te(e)});class qt extends se{_parse(t){const n=this._getOrReturnCtx(t);return V(n,{code:R.invalid_type,expected:Z.never,received:n.parsedType}),J}}qt.create=e=>new qt({typeName:G.ZodNever,...te(e)});class lo extends se{_parse(t){if(this._getType(t)!==Z.undefined){const r=this._getOrReturnCtx(t);return V(r,{code:R.invalid_type,expected:Z.void,received:r.parsedType}),J}return Je(t.data)}}lo.create=e=>new lo({typeName:G.ZodVoid,...te(e)});class yt extends se{_parse(t){const{ctx:n,status:r}=this._processInputParams(t),s=this._def;if(n.parsedType!==Z.array)return V(n,{code:R.invalid_type,expected:Z.array,received:n.parsedType}),J;if(s.exactLength!==null){const i=n.data.length>s.exactLength.value,a=n.data.lengths.maxLength.value&&(V(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 Ct(n,i,n.path,a)))).then(i=>Fe.mergeArray(r,i));const o=[...n.data].map((i,a)=>s.type._parseSync(new Ct(n,i,n.path,a)));return Fe.mergeArray(r,o)}get element(){return this._def.type}min(t,n){return new yt({...this._def,minLength:{value:t,message:W.toString(n)}})}max(t,n){return new yt({...this._def,maxLength:{value:t,message:W.toString(n)}})}length(t,n){return new yt({...this._def,exactLength:{value:t,message:W.toString(n)}})}nonempty(t){return this.min(1,t)}}yt.create=(e,t)=>new yt({type:e,minLength:null,maxLength:null,exactLength:null,typeName:G.ZodArray,...te(t)});function ar(e){if(e instanceof Ae){const t={};for(const n in e.shape){const r=e.shape[n];t[n]=Mt.create(ar(r))}return new Ae({...e._def,shape:()=>t})}else return e instanceof yt?new yt({...e._def,type:ar(e.element)}):e instanceof Mt?Mt.create(ar(e.unwrap())):e instanceof qn?qn.create(ar(e.unwrap())):e instanceof Pt?Pt.create(e.items.map(t=>ar(t))):e}class Ae extends se{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=ge.objectKeys(t);return this._cached={shape:t,keys:n}}_parse(t){if(this._getType(t)!==Z.object){const u=this._getOrReturnCtx(t);return V(u,{code:R.invalid_type,expected:Z.object,received:u.parsedType}),J}const{status:r,ctx:s}=this._processInputParams(t),{shape:o,keys:i}=this._getCached(),a=[];if(!(this._def.catchall instanceof qt&&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 Ct(s,f,s.path,u)),alwaysSet:u in s.data})}if(this._def.catchall instanceof qt){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&&(V(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 Ct(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=>Fe.mergeObjectSync(r,u)):Fe.mergeObjectSync(r,c)}get shape(){return this._def.shape()}strict(t){return new Ae({...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=W.errToObj(t).message)!==null&&a!==void 0?a:c}:{message:c}}}:{}})}strip(){return new Ae({...this._def,unknownKeys:"strip"})}passthrough(){return new Ae({...this._def,unknownKeys:"passthrough"})}extend(t){return new Ae({...this._def,shape:()=>({...this._def.shape(),...t})})}merge(t){return new Ae({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 Ae({...this._def,catchall:t})}pick(t){const n={};return ge.objectKeys(t).forEach(r=>{t[r]&&this.shape[r]&&(n[r]=this.shape[r])}),new Ae({...this._def,shape:()=>n})}omit(t){const n={};return ge.objectKeys(this.shape).forEach(r=>{t[r]||(n[r]=this.shape[r])}),new Ae({...this._def,shape:()=>n})}deepPartial(){return ar(this)}partial(t){const n={};return ge.objectKeys(this.shape).forEach(r=>{const s=this.shape[r];t&&!t[r]?n[r]=s:n[r]=s.optional()}),new Ae({...this._def,shape:()=>n})}required(t){const n={};return ge.objectKeys(this.shape).forEach(r=>{if(t&&!t[r])n[r]=this.shape[r];else{let o=this.shape[r];for(;o instanceof Mt;)o=o._def.innerType;n[r]=o}}),new Ae({...this._def,shape:()=>n})}keyof(){return ed(ge.objectKeys(this.shape))}}Ae.create=(e,t)=>new Ae({shape:()=>e,unknownKeys:"strip",catchall:qt.create(),typeName:G.ZodObject,...te(t)});Ae.strictCreate=(e,t)=>new Ae({shape:()=>e,unknownKeys:"strict",catchall:qt.create(),typeName:G.ZodObject,...te(t)});Ae.lazycreate=(e,t)=>new Ae({shape:e,unknownKeys:"strip",catchall:qt.create(),typeName:G.ZodObject,...te(t)});class ts extends se{_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 mt(a.ctx.common.issues));return V(n,{code:R.invalid_union,unionErrors:i}),J}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 mt(c));return V(n,{code:R.invalid_union,unionErrors:a}),J}}get options(){return this._def.options}}ts.create=(e,t)=>new ts({options:e,typeName:G.ZodUnion,...te(t)});const Ws=e=>e instanceof ss?Ws(e.schema):e instanceof wt?Ws(e.innerType()):e instanceof os?[e.value]:e instanceof vn?e.options:e instanceof is?Object.keys(e.enum):e instanceof as?Ws(e._def.innerType):e instanceof Qr?[void 0]:e instanceof es?[null]:null;class Ho extends se{_parse(t){const{ctx:n}=this._processInputParams(t);if(n.parsedType!==Z.object)return V(n,{code:R.invalid_type,expected:Z.object,received:n.parsedType}),J;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}):(V(n,{code:R.invalid_union_discriminator,options:Array.from(this.optionsMap.keys()),path:[r]}),J)}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=Ws(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,...te(r)})}}function Ji(e,t){const n=dn(e),r=dn(t);if(e===t)return{valid:!0,data:e};if(n===Z.object&&r===Z.object){const s=ge.objectKeys(t),o=ge.objectKeys(e).filter(a=>s.indexOf(a)!==-1),i={...e,...t};for(const a of o){const c=Ji(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(Yi(o)||Yi(i))return J;const a=Ji(o.value,i.value);return a.valid?((Xi(o)||Xi(i))&&n.dirty(),{status:n.value,value:a.data}):(V(r,{code:R.invalid_intersection_types}),J)};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}))}}ns.create=(e,t,n)=>new ns({left:e,right:t,typeName:G.ZodIntersection,...te(n)});class Pt extends se{_parse(t){const{status:n,ctx:r}=this._processInputParams(t);if(r.parsedType!==Z.array)return V(r,{code:R.invalid_type,expected:Z.array,received:r.parsedType}),J;if(r.data.lengththis._def.items.length&&(V(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 Ct(r,i,r.path,a)):null}).filter(i=>!!i);return r.common.async?Promise.all(o).then(i=>Fe.mergeArray(n,i)):Fe.mergeArray(n,o)}get items(){return this._def.items}rest(t){return new Pt({...this._def,rest:t})}}Pt.create=(e,t)=>{if(!Array.isArray(e))throw new Error("You must pass an array of schemas to z.tuple([ ... ])");return new Pt({items:e,typeName:G.ZodTuple,rest:null,...te(t)})};class rs extends se{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 V(r,{code:R.invalid_type,expected:Z.object,received:r.parsedType}),J;const s=[],o=this._def.keyType,i=this._def.valueType;for(const a in r.data)s.push({key:o._parse(new Ct(r,a,r.path,a)),value:i._parse(new Ct(r,r.data[a],r.path,a))});return r.common.async?Fe.mergeObjectAsync(n,s):Fe.mergeObjectSync(n,s)}get element(){return this._def.valueType}static create(t,n,r){return n instanceof se?new rs({keyType:t,valueType:n,typeName:G.ZodRecord,...te(r)}):new rs({keyType:pt.create(),valueType:t,typeName:G.ZodRecord,...te(n)})}}class ho extends se{_parse(t){const{status:n,ctx:r}=this._processInputParams(t);if(r.parsedType!==Z.map)return V(r,{code:R.invalid_type,expected:Z.map,received:r.parsedType}),J;const s=this._def.keyType,o=this._def.valueType,i=[...r.data.entries()].map(([a,c],u)=>({key:s._parse(new Ct(r,a,r.path,[u,"key"])),value:o._parse(new Ct(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 J;(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 J;(u.status==="dirty"||l.status==="dirty")&&n.dirty(),a.set(u.value,l.value)}return{status:n.value,value:a}}}}ho.create=(e,t,n)=>new ho({valueType:t,keyType:e,typeName:G.ZodMap,...te(n)});class Vn extends se{_parse(t){const{status:n,ctx:r}=this._processInputParams(t);if(r.parsedType!==Z.set)return V(r,{code:R.invalid_type,expected:Z.set,received:r.parsedType}),J;const s=this._def;s.minSize!==null&&r.data.sizes.maxSize.value&&(V(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 J;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 Ct(r,c,r.path,u)));return r.common.async?Promise.all(a).then(c=>i(c)):i(a)}min(t,n){return new Vn({...this._def,minSize:{value:t,message:W.toString(n)}})}max(t,n){return new Vn({...this._def,maxSize:{value:t,message:W.toString(n)}})}size(t,n){return this.min(t,n).max(t,n)}nonempty(t){return this.min(1,t)}}Vn.create=(e,t)=>new Vn({valueType:e,minSize:null,maxSize:null,typeName:G.ZodSet,...te(t)});class fr extends se{constructor(){super(...arguments),this.validate=this.implement}_parse(t){const{ctx:n}=this._processInputParams(t);if(n.parsedType!==Z.function)return V(n,{code:R.invalid_type,expected:Z.function,received:n.parsedType}),J;function r(a,c){return ao({data:a,path:n.path,errorMaps:[n.common.contextualErrorMap,n.schemaErrorMap,io(),Xr].filter(u=>!!u),issueData:{code:R.invalid_arguments,argumentsError:c}})}function s(a,c){return ao({data:a,path:n.path,errorMaps:[n.common.contextualErrorMap,n.schemaErrorMap,io(),Xr].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 xr?Je(async(...a)=>{const c=new mt([]),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})}):Je((...a)=>{const c=this._def.args.safeParse(a,o);if(!c.success)throw new mt([r(a,c.error)]);const u=i(...c.data),l=this._def.returns.safeParse(u,o);if(!l.success)throw new mt([s(u,l.error)]);return l.data})}parameters(){return this._def.args}returnType(){return this._def.returns}args(...t){return new fr({...this._def,args:Pt.create(t).rest(Kn.create())})}returns(t){return new fr({...this._def,returns:t})}implement(t){return this.parse(t)}strictImplement(t){return this.parse(t)}static create(t,n,r){return new fr({args:t||Pt.create([]).rest(Kn.create()),returns:n||Kn.create(),typeName:G.ZodFunction,...te(r)})}}class ss extends se{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})}}ss.create=(e,t)=>new ss({getter:e,typeName:G.ZodLazy,...te(t)});class os extends se{_parse(t){if(t.data!==this._def.value){const n=this._getOrReturnCtx(t);return V(n,{received:n.data,code:R.invalid_literal,expected:this._def.value}),J}return{status:"valid",value:t.data}}get value(){return this._def.value}}os.create=(e,t)=>new os({value:e,typeName:G.ZodLiteral,...te(t)});function ed(e,t){return new vn({values:e,typeName:G.ZodEnum,...te(t)})}class vn extends se{_parse(t){if(typeof t.data!="string"){const n=this._getOrReturnCtx(t),r=this._def.values;return V(n,{expected:ge.joinValues(r),received:n.parsedType,code:R.invalid_type}),J}if(this._def.values.indexOf(t.data)===-1){const n=this._getOrReturnCtx(t),r=this._def.values;return V(n,{received:n.data,code:R.invalid_enum_value,options:r}),J}return Je(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 vn.create(t)}exclude(t){return vn.create(this.options.filter(n=>!t.includes(n)))}}vn.create=ed;class is extends se{_parse(t){const n=ge.getValidEnumValues(this._def.values),r=this._getOrReturnCtx(t);if(r.parsedType!==Z.string&&r.parsedType!==Z.number){const s=ge.objectValues(n);return V(r,{expected:ge.joinValues(s),received:r.parsedType,code:R.invalid_type}),J}if(n.indexOf(t.data)===-1){const s=ge.objectValues(n);return V(r,{received:r.data,code:R.invalid_enum_value,options:s}),J}return Je(t.data)}get enum(){return this._def.values}}is.create=(e,t)=>new is({values:e,typeName:G.ZodNativeEnum,...te(t)});class xr extends se{unwrap(){return this._def.type}_parse(t){const{ctx:n}=this._processInputParams(t);if(n.parsedType!==Z.promise&&n.common.async===!1)return V(n,{code:R.invalid_type,expected:Z.promise,received:n.parsedType}),J;const r=n.parsedType===Z.promise?n.data:Promise.resolve(n.data);return Je(r.then(s=>this._def.type.parseAsync(s,{path:n.path,errorMap:n.common.contextualErrorMap})))}}xr.create=(e,t)=>new xr({type:e,typeName:G.ZodPromise,...te(t)});class wt extends se{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=>{V(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"?J:(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"?J:(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(!co(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=>co(i)?Promise.resolve(s.transform(i.value,o)).then(a=>({status:n.value,value:a})):i);ge.assertNever(s)}}wt.create=(e,t,n)=>new wt({schema:e,typeName:G.ZodEffects,effect:t,...te(n)});wt.createWithPreprocess=(e,t,n)=>new wt({schema:t,effect:{type:"preprocess",transform:e},typeName:G.ZodEffects,...te(n)});class Mt extends se{_parse(t){return this._getType(t)===Z.undefined?Je(void 0):this._def.innerType._parse(t)}unwrap(){return this._def.innerType}}Mt.create=(e,t)=>new Mt({innerType:e,typeName:G.ZodOptional,...te(t)});class qn extends se{_parse(t){return this._getType(t)===Z.null?Je(null):this._def.innerType._parse(t)}unwrap(){return this._def.innerType}}qn.create=(e,t)=>new qn({innerType:e,typeName:G.ZodNullable,...te(t)});class as extends se{_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}}as.create=(e,t)=>new as({innerType:e,typeName:G.ZodDefault,defaultValue:typeof t.default=="function"?t.default:()=>t.default,...te(t)});class po extends se{_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 uo(s)?s.then(o=>({status:"valid",value:o.status==="valid"?o.value:this._def.catchValue({get error(){return new mt(r.common.issues)},input:r.data})})):{status:"valid",value:s.status==="valid"?s.value:this._def.catchValue({get error(){return new mt(r.common.issues)},input:r.data})}}removeCatch(){return this._def.innerType}}po.create=(e,t)=>new po({innerType:e,typeName:G.ZodCatch,catchValue:typeof t.catch=="function"?t.catch:()=>t.catch,...te(t)});class go extends se{_parse(t){if(this._getType(t)!==Z.nan){const r=this._getOrReturnCtx(t);return V(r,{code:R.invalid_type,expected:Z.nan,received:r.parsedType}),J}return{status:"valid",value:t.data}}}go.create=e=>new go({typeName:G.ZodNaN,...te(e)});const d1=Symbol("zod_brand");class td extends se{_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 ys extends se{_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"?J: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"?J: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 ys({in:t,out:n,typeName:G.ZodPipeline})}}const nd=(e,t={},n)=>e?wr.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})}}):wr.create(),h1={object:Ae.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 p1=(e,t={message:`Input not instance of ${e.name}`})=>nd(n=>n instanceof e,t),rd=pt.create,sd=wn.create,g1=go.create,m1=xn.create,od=Jr.create,y1=Zn.create,b1=fo.create,w1=Qr.create,x1=es.create,v1=wr.create,E1=Kn.create,k1=qt.create,S1=lo.create,$1=yt.create,_1=Ae.create,A1=Ae.strictCreate,B1=ts.create,T1=Ho.create,I1=ns.create,O1=Pt.create,C1=rs.create,P1=ho.create,U1=Vn.create,N1=fr.create,L1=ss.create,R1=os.create,H1=vn.create,j1=is.create,K1=xr.create,ou=wt.create,D1=Mt.create,M1=qn.create,Z1=wt.createWithPreprocess,V1=ys.create,q1=()=>rd().optional(),z1=()=>sd().optional(),F1=()=>od().optional(),W1={string:(e=>pt.create({...e,coerce:!0})),number:(e=>wn.create({...e,coerce:!0})),boolean:(e=>Jr.create({...e,coerce:!0})),bigint:(e=>xn.create({...e,coerce:!0})),date:(e=>Zn.create({...e,coerce:!0}))},G1=J;var Xe=Object.freeze({__proto__:null,defaultErrorMap:Xr,setErrorMap:Qw,getErrorMap:io,makeIssue:ao,EMPTY_PATH:e1,addIssueToContext:V,ParseStatus:Fe,INVALID:J,DIRTY:Ql,OK:Je,isAborted:Yi,isDirty:Xi,isValid:co,isAsync:uo,get util(){return ge},get objectUtil(){return Gi},ZodParsedType:Z,getParsedType:dn,ZodType:se,ZodString:pt,ZodNumber:wn,ZodBigInt:xn,ZodBoolean:Jr,ZodDate:Zn,ZodSymbol:fo,ZodUndefined:Qr,ZodNull:es,ZodAny:wr,ZodUnknown:Kn,ZodNever:qt,ZodVoid:lo,ZodArray:yt,ZodObject:Ae,ZodUnion:ts,ZodDiscriminatedUnion:Ho,ZodIntersection:ns,ZodTuple:Pt,ZodRecord:rs,ZodMap:ho,ZodSet:Vn,ZodFunction:fr,ZodLazy:ss,ZodLiteral:os,ZodEnum:vn,ZodNativeEnum:is,ZodPromise:xr,ZodEffects:wt,ZodTransformer:wt,ZodOptional:Mt,ZodNullable:qn,ZodDefault:as,ZodCatch:po,ZodNaN:go,BRAND:d1,ZodBranded:td,ZodPipeline:ys,custom:nd,Schema:se,ZodSchema:se,late:h1,get ZodFirstPartyTypeKind(){return G},coerce:W1,any:v1,array:$1,bigint:m1,boolean:od,date:y1,discriminatedUnion:T1,effect:ou,enum:H1,function:N1,instanceof:p1,intersection:I1,lazy:L1,literal:R1,map:P1,nan:g1,nativeEnum:j1,never:k1,null:x1,nullable:M1,number:sd,object:_1,oboolean:F1,onumber:z1,optional:D1,ostring:q1,pipeline:V1,preprocess:Z1,promise:K1,record:C1,set:U1,strictObject:A1,string:rd,symbol:b1,transformer:ou,tuple:O1,undefined:w1,union:B1,unknown:E1,void:S1,NEVER:G1,ZodIssueCode:R,quotelessJson:Jw,ZodError:mt});const id=Xe.string().regex(/^[a-fA-F0-9]$/),Y1=Xe.string().regex(/^[a-fA-F0-9]{64}$/),vr=Xe.number().min(0).max(4294967295),X1=Xe.bigint(),ad=Xe.instanceof(Uint8Array),J1=Xe.union([id,vr,Xe.string(),ad]).array(),Xa=Xe.union([J1,id,ad]),Q1=Xe.array(Xa),cd=Xe.object({value:Xe.union([vr,X1]),scriptPubKey:Xa}),ex=Xe.object({txid:Y1,vout:vr,scriptSig:Xa,sequence:vr,prevout:cd.optional(),witness:Q1});Xe.object({version:vr,vin:Xe.array(ex),vout:Xe.array(cd),locktime:vr});const Qi=2048,tx=new TextEncoder;function ud(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=tx.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>Qi)throw new Error(`Metadata must be at most ${Qi} CBOR bytes.`)};return r(e),Uint8Array.from(t)}function nx(e){if(e=new Uint8Array(e),!e.length||e.length>Qi)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}}),je=(e,t)=>({value:e,scriptPubKey:t}),iu=16*1024,At=1e3,de=500,mo="text/plain;charset=utf-8",rx=["text/plain","application/json","text/html","image/svg+xml","image/png","image/jpeg","image/webp"],fd=new TextEncoder,zr=e=>Array.from(e,t=>t.toString(16).padStart(2,"0")).join(""),On=e=>Uint8Array.from(e.match(/../g)??[],t=>parseInt(t,16)),yo=e=>zr(fd.encode(e));function Ja(e){const t=typeof e=="string"?{contentType:mo,bytes:fd.encode(e)}:e;if(!t||![...rx,mo].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>iu)throw new Error(`Body must be at most ${iu} bytes.`);return{contentType:t.contentType,bytes:new Uint8Array(t.bytes)}}function bo(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 au(e){if(typeof e!="string"||!/^[0-9a-f]{64,72}$/.test(e)||e.length%2)throw new Error("Invalid parent tag.");const t=[...On(e.slice(64))].reduce((r,s,o)=>r+s*256**o,0),n=`${e.slice(0,64).match(/../g).reverse().join("")}i${t}`;if(bo(n)!==e)throw new Error("Non-canonical parent tag.");return n}function ld(e,t,n=null,r=void 0,s={}){const{contentType:o,bytes:i}=Ja(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:ud(r),d=[];for(let p=0;p{const g=p.length/2;return(g<=75?g.toString(16).padStart(2,"0"):g<=255?"4c"+g.toString(16).padStart(2,"0"):"4d"+(g%256).toString(16).padStart(2,"0")+Math.floor(g/256).toString(16).padStart(2,"0"))+p};return h(e)+"ac0063"+h(yo("ord"))+h("01")+h(yo(o))+(a?h("0b")+h(bo(a)):"")+(c===void 0?"":h("02")+h(dd(c)))+(n?h("03")+h(bo(n)):"")+(f===void 0?"":Array.from({length:Math.ceil(f.length/520)},(p,g)=>h("05")+h(zr(f.slice(g*520,(g+1)*520)))).join(""))+(l?h("07")+h(zr(l)):"")+"00"+d.map(h).join("")+"68"}const sx=e=>Ro.tree.getLeaf(Be.encode(e,!0));function Qa(e){if(!Array.isArray(e)||e.length!==3)throw new Error("Unsupported script-path witness.");const t=Be.decode(e[1]);let n=7,r=null,s=null,o;t[n]==="0b"&&(s=au(t[n+1]),n+=2),t[n]==="02"&&(o=ix(t[n+1]==="OP_0"?"":t[n+1]),n+=2),t[n]==="03"&&(r=au(t[n+1]),n+=2);const i=[];for(;t[n]==="05";){const p=t[n+1];if(typeof p!="string"||!/^(?:[0-9a-f]{2}){1,520}$/.test(p))throw new Error("Invalid metadata push.");i.push(p),n+=2}const a=i.length?nx(On(i.join(""))):void 0;let c=null;if(t[n]==="07"){const p=t[n+1];if(typeof p!="string"||!/^(?:[0-9a-f]{2}){1,520}$/.test(p))throw new Error("Invalid metaprotocol field.");c=new TextDecoder().decode(On(p)),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(p=>typeof p!="string"||!/^(?:[0-9a-f]{2})+$/.test(p)))throw new Error("Invalid body envelope.");const l=new TextDecoder().decode(On(t[6])),f=Ja({contentType:l,bytes:On(u.join(""))}),d=ld(t[0],f,r,a,{delegate:s,pointer:o,metaprotocol:c}),h=a===void 0&&!r&&l===mo&&f.bytes.length<=280&&Be.encode([t[0],"OP_CHECKSIG","OP_0","OP_IF",yo("ord"),"01",yo(mo),"OP_0",zr(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?On(i.join("")):void 0,text:new TextDecoder().decode(f.bytes),pubkey:t[0]}}class ox{constructor(t,n){this.chain=t,this.wallet=n}prepare(t,n=null,r=void 0,s={}){const o=Ja(t);if(r!==void 0&&ud(r),s.delegate&&bo(s.delegate),s.pointer!==void 0&&dd(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>=At+2*de+330);if(!u)throw new Error("Mine a block first to get spendable fake BTC.");return{...o,coin:u,parent:a,reinscribe:c,totalFee:de*2,postage:At}}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(v=>v.id===s.reinscribe),f=l?this.chain.satLocation(l.sat).offset:s.pointer??(i?i.value:void 0),d=ld(this.wallet.pubkey,c,n,r,{...s,pointer:f}),h=sx(d),[p,g]=Ro.getPubKey(this.wallet.pubkey,{target:h}),b=ie.create({vin:[Zt(o.txid,o.vout,o.value,o.scriptPubKey)],vout:[je(At+de,["OP_1",p]),je(o.value-At-2*de,this.wallet.script)]});b.vin[0].witness=[this.wallet.sign(b)];const m=ie.util.getTxid(b),E=ie.create({vin:[...u?[Zt(u.txid,u.vout,u.value,u.scriptPubKey)]:[],Zt(m,0,At+de,["OP_1",p])],vout:[...u?[je(u.value,this.wallet.script)]:[],je(At,this.wallet.script)]}),y=u?1:0;return E.vin[y].witness=[this.wallet.sign(E,h,y),Be.encode(d,!1).hex,g],u&&(E.vin[0].witness=[this.wallet.sign(E)]),this.chain.submitPackage([ie.encode(b).hex,ie.encode(E).hex]),`${ie.util.getTxid(E)}i0`}list(){return this.chain.coins(this.wallet.script).flatMap(t=>t.inscriptions??[])}}function dd(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 ix(e){if(typeof e!="string"||!/^(?:[0-9a-f]{2}){0,8}$/.test(e))throw new Error("Invalid pointer tag.");return[...On(e)].reduce((t,n,r)=>t+(BigInt(n)<this.utxos.set(`${r.txid}:${r.vout}`,{txid:r.txid,vout:r.vout,value:r.value,ranges:ef(s,r.value)}));const n=(r,s,o)=>{var m;const i=ie.decode(r),a=ie.util.getTxid(i),c=i.vin[0].txid==="0".repeat(64),u=c?[]:i.vin.map(E=>this.utxos.get(`${E.txid}:${E.vout}`)),l=rf(i,u,s,c);i.vin.forEach(E=>this.utxos.delete(`${E.txid}:${E.vout}`)),i.vout.forEach((E,y)=>this.utxos.set(`${a}:${y}`,{txid:a,vout:y,value:Number(E.value),ranges:l[y]}));const f=(m=i.vin.find(E=>{var y;return((y=E.witness)==null?void 0:y.length)===3}))==null?void 0:m.witness;if(!f)return;const d=Qa(f),h=BigInt(d.pointer??0),p=i.vout.reduce((E,y)=>E+Number(y.value),0),g=nf(l.flat(),hE.sat===g).length,status:s===null?"pending":"confirmed",height:s,block:o,metadata:b??null,hasMetadata:b!==void 0,parent:d.parent,protocol:d.metaprotocol??(b&&!Array.isArray(b)&&typeof b=="object"&&Object.hasOwn(b,"protocol")&&typeof b.protocol=="string"?b.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=zs(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 nr=typeof globalThis=="object"&&"crypto"in globalThis?globalThis.crypto:void 0;/*! noble-hashes - MIT License (c) 2022 Paul Miller (paulmillr.com) */function ws(e){return e instanceof Uint8Array||ArrayBuffer.isView(e)&&e.constructor.name==="Uint8Array"}function It(e){if(!Number.isSafeInteger(e)||e<0)throw new Error("positive integer expected, got "+e)}function Re(e,...t){if(!ws(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 xs(e){if(typeof e!="function"||typeof e.create!="function")throw new Error("Hash should be wrapped by utils.createHasher");It(e.outputLen),It(e.blockLen)}function Er(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 hd(e,t){Re(e);const n=t.outputLen;if(e.length>>t}function Os(e,t){return e<>>32-t>>>0}const cx=new Uint8Array(new Uint32Array([287454020]).buffer)[0]===68;function ux(e){return e<<24&4278190080|e<<8&16711680|e>>>8&65280|e>>>24&255}function fx(e){for(let t=0;te:fx,pd=typeof Uint8Array.from([]).toHex=="function"&&typeof Uint8Array.fromHex=="function",lx=Array.from({length:256},(e,t)=>t.toString(16).padStart(2,"0"));function Se(e){if(Re(e),pd)return e.toHex();let t="";for(let n=0;n=Ht._0&&e<=Ht._9)return e-Ht._0;if(e>=Ht.A&&e<=Ht.F)return e-(Ht.A-10);if(e>=Ht.a&&e<=Ht.f)return e-(Ht.a-10)}function ut(e){if(typeof e!="string")throw new Error("hex string expected, got "+typeof e);if(pd)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(kr(r)).digest(),n=e();return t.outputLen=n.outputLen,t.blockLen=n.blockLen,t.create=()=>e(),t}function Qn(e=32){if(nr&&typeof nr.getRandomValues=="function")return nr.getRandomValues(new Uint8Array(e));if(nr&&typeof nr.randomBytes=="function")return Uint8Array.from(nr.randomBytes(e));throw new Error("crypto.getRandomValues must be defined")}function hx(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 px(e,t,n){return e&t^~e&n}function gx(e,t,n){return e&t^e&n^t&n}class tc extends ec{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=Dn(this.buffer)}update(t){Er(this),t=kr(t),Re(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>lu&Cs)}:{h:Number(e>>lu&Cs)|0,l:Number(e&Cs)|0}}function gd(e,t=!1){const n=e.length;let r=new Uint32Array(n),s=new Uint32Array(n);for(let o=0;oe>>>n,hu=(e,t,n)=>e<<32-n|t>>>n,rr=(e,t,n)=>e>>>n|t<<32-n,sr=(e,t,n)=>e<<32-n|t>>>n,Ps=(e,t,n)=>e<<64-n|t>>>n-32,Us=(e,t,n)=>e>>>n-32|t<<64-n,yx=(e,t,n)=>e<>>32-n,bx=(e,t,n)=>t<>>32-n,wx=(e,t,n)=>t<>>64-n,xx=(e,t,n)=>e<>>64-n;function jt(e,t,n,r){const s=(t>>>0)+(r>>>0);return{h:e+n+(s/2**32|0)|0,l:s|0}}const vx=(e,t,n)=>(e>>>0)+(t>>>0)+(n>>>0),Ex=(e,t,n,r)=>t+n+r+(e/2**32|0)|0,kx=(e,t,n,r)=>(e>>>0)+(t>>>0)+(n>>>0)+(r>>>0),Sx=(e,t,n,r,s)=>t+n+r+s+(e/2**32|0)|0,$x=(e,t,n,r,s)=>(e>>>0)+(t>>>0)+(n>>>0)+(r>>>0)+(s>>>0),_x=(e,t,n,r,s,o)=>t+n+r+s+o+(e/2**32|0)|0,Ax=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]),on=new Uint32Array(64);class Bx extends tc{constructor(t=32){super(64,t,8,!1),this.A=sn[0]|0,this.B=sn[1]|0,this.C=sn[2]|0,this.D=sn[3]|0,this.E=sn[4]|0,this.F=sn[5]|0,this.G=sn[6]|0,this.H=sn[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)on[f]=t.getUint32(n,!1);for(let f=16;f<64;f++){const d=on[f-15],h=on[f-2],p=_t(d,7)^_t(d,18)^d>>>3,g=_t(h,17)^_t(h,19)^h>>>10;on[f]=g+on[f-7]+p+on[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=_t(a,6)^_t(a,11)^_t(a,25),h=l+d+px(a,c,u)+Ax[f]+on[f]|0,g=(_t(r,2)^_t(r,13)^_t(r,22))+gx(r,s,o)|0;l=u,u=c,c=a,a=i+h|0,i=o,o=s,s=r,r=h+g|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(){ct(on)}destroy(){this.set(0,0,0,0,0,0,0,0),ct(this.buffer)}}const md=gd(["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))),Tx=md[0],Ix=md[1],an=new Uint32Array(80),cn=new Uint32Array(80);class Ox extends tc{constructor(t=64){super(128,t,16,!1),this.Ah=Ze[0]|0,this.Al=Ze[1]|0,this.Bh=Ze[2]|0,this.Bl=Ze[3]|0,this.Ch=Ze[4]|0,this.Cl=Ze[5]|0,this.Dh=Ze[6]|0,this.Dl=Ze[7]|0,this.Eh=Ze[8]|0,this.El=Ze[9]|0,this.Fh=Ze[10]|0,this.Fl=Ze[11]|0,this.Gh=Ze[12]|0,this.Gl=Ze[13]|0,this.Hh=Ze[14]|0,this.Hl=Ze[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:p,Hh:g,Hl:b}=this;return[t,n,r,s,o,i,a,c,u,l,f,d,h,p,g,b]}set(t,n,r,s,o,i,a,c,u,l,f,d,h,p,g,b){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=p|0,this.Hh=g|0,this.Hl=b|0}process(t,n){for(let y=0;y<16;y++,n+=4)an[y]=t.getUint32(n),cn[y]=t.getUint32(n+=4);for(let y=16;y<80;y++){const v=an[y-15]|0,x=cn[y-15]|0,B=rr(v,x,1)^rr(v,x,8)^du(v,x,7),O=sr(v,x,1)^sr(v,x,8)^hu(v,x,7),C=an[y-2]|0,T=cn[y-2]|0,U=rr(C,T,19)^Ps(C,T,61)^du(C,T,6),H=sr(C,T,19)^Us(C,T,61)^hu(C,T,6),K=kx(O,H,cn[y-7],cn[y-16]),k=Sx(K,B,U,an[y-7],an[y-16]);an[y]=k|0,cn[y]=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:p,Gh:g,Gl:b,Hh:m,Hl:E}=this;for(let y=0;y<80;y++){const v=rr(f,d,14)^rr(f,d,18)^Ps(f,d,41),x=sr(f,d,14)^sr(f,d,18)^Us(f,d,41),B=f&h^~f&g,O=d&p^~d&b,C=$x(E,x,O,Ix[y],cn[y]),T=_x(C,m,v,B,Tx[y],an[y]),U=C|0,H=rr(r,s,28)^Ps(r,s,34)^Ps(r,s,39),K=sr(r,s,28)^Us(r,s,34)^Us(r,s,39),k=r&o^r&a^o&a,$=s&i^s&c^i&c;m=g|0,E=b|0,g=h|0,b=p|0,h=f|0,p=d|0,{h:f,l:d}=jt(u|0,l|0,T|0,U|0),u=a|0,l=c|0,a=o|0,c=i|0,o=r|0,i=s|0;const w=vx(U,K,$);r=Ex(w,T,H,k),s=w|0}({h:r,l:s}=jt(this.Ah|0,this.Al|0,r|0,s|0)),{h:o,l:i}=jt(this.Bh|0,this.Bl|0,o|0,i|0),{h:a,l:c}=jt(this.Ch|0,this.Cl|0,a|0,c|0),{h:u,l}=jt(this.Dh|0,this.Dl|0,u|0,l|0),{h:f,l:d}=jt(this.Eh|0,this.El|0,f|0,d|0),{h,l:p}=jt(this.Fh|0,this.Fl|0,h|0,p|0),{h:g,l:b}=jt(this.Gh|0,this.Gl|0,g|0,b|0),{h:m,l:E}=jt(this.Hh|0,this.Hl|0,m|0,E|0),this.set(r,s,o,i,a,c,u,l,f,d,h,p,g,b,m,E)}roundClean(){ct(an,cn)}destroy(){ct(this.buffer),this.set(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0)}}const xe=jo(()=>new Bx),cs=jo(()=>new Ox);class yd extends ec{constructor(t,n){super(),this.finished=!1,this.destroyed=!1,xs(t);const r=kr(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 yd(e,t).update(n).digest();En.create=(e,t)=>new yd(e,t);/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */const nc=BigInt(0),ea=BigInt(1);function zn(e,t=""){if(typeof e!="boolean"){const n=t&&`"${t}"`;throw new Error(n+"expected boolean, got type="+typeof e)}return e}function gt(e,t,n=""){const r=ws(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 Ns(e){const t=e.toString(16);return t.length&1?"0"+t:t}function bd(e){if(typeof e!="string")throw new Error("hex string expected, got "+typeof e);return e===""?nc:BigInt("0x"+e)}function er(e){return bd(Se(e))}function Fn(e){return Re(e),bd(Se(Uint8Array.from(e).reverse()))}function Ko(e,t){return ut(e.toString(16).padStart(t*2,"0"))}function rc(e,t){return Ko(e,t).reverse()}function me(e,t,n){let r;if(typeof t=="string")try{r=ut(t)}catch(o){throw new Error(e+" must be hex string or Uint8Array, cause: "+o)}else if(ws(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 pu(e){return Uint8Array.from(e)}const hi=e=>typeof e=="bigint"&&nc<=e;function ta(e,t,n){return hi(e)&&hi(t)&&hi(n)&&t<=e&&enc;e>>=ea,t+=1);return t}const vs=e=>(ea<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 p=[];for(;h{c(),l(h);let g;for(;!(g=p(f()));)l();return c(),g}}function Cr(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 wo(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 et=BigInt(0),Me=BigInt(1),Ln=BigInt(2),xd=BigInt(3),vd=BigInt(4),Ed=BigInt(5),Px=BigInt(7),kd=BigInt(8),Ux=BigInt(9),Sd=BigInt(16);function Ee(e,t){const n=e%t;return n>=et?n:t+n}function _e(e,t,n){let r=e;for(;t-- >et;)r*=r,r%=n;return r}function gu(e,t){if(e===et)throw new Error("invert: expected non-zero number");if(t<=et)throw new Error("invert: expected positive modulus, got "+t);let n=Ee(e,t),r=t,s=et,o=Me;for(;n!==et;){const a=r/n,c=r%n,u=s-o*a;r=n,n=c,s=o,o=u}if(r!==Me)throw new Error("invert: does not exist");return Ee(s,t)}function sc(e,t,n){if(!e.eql(e.sqr(t),n))throw new Error("Cannot find square root")}function $d(e,t){const n=(e.ORDER+Me)/vd,r=e.pow(t,n);return sc(e,r,t),r}function Nx(e,t){const n=(e.ORDER-Ed)/kd,r=e.mul(t,Ln),s=e.pow(r,n),o=e.mul(t,s),i=e.mul(e.mul(o,Ln),s),a=e.mul(o,e.sub(i,e.ONE));return sc(e,a,t),a}function Lx(e){const t=tr(e),n=_d(e),r=n(t,t.neg(t.ONE)),s=n(t,r),o=n(t,t.neg(r)),i=(e+Px)/Sd;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),p=a.eql(a.sqr(f),c);u=a.cmov(u,l,h),l=a.cmov(d,f,p);const g=a.eql(a.sqr(l),c),b=a.cmov(u,l,g);return sc(a,b,c),b}}function _d(e){if(e1e3)throw new Error("Cannot find square root: probably non-prime P");if(n===1)return $d;let o=s.pow(r,t);const i=(t+Me)/Ln;return function(c,u){if(c.is0(u))return u;if(mu(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 p=1,g=c.sqr(d);for(;!c.eql(g,c.ONE);)if(p++,g=c.sqr(g),p===l)throw new Error("Cannot find square root");const b=Me<(Ee(e,t)&Me)===Me,jx=["create","isValid","is0","neg","inv","sqrt","sqr","eql","add","sub","mul","pow","div","addN","subN","mulN","sqrN"];function Kx(e){const t={ORDER:"bigint",MASK:"bigint",BYTES:"number",BITS:"number"},n=jx.reduce((r,s)=>(r[s]="function",r),t);return Cr(e,n),e}function Dx(e,t,n){if(net;)n&Me&&(r=e.mul(r,s)),s=e.sqr(s),n>>=Me;return r}function Ad(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 mu(e,t){const n=(e.ORDER-Me)/Ln,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 Bd(e,t){t!==void 0&&It(t);const n=t!==void 0?t:e.toString(2).length,r=Math.ceil(n/8);return{nBitLength:n,nByteLength:r}}function tr(e,t,n=!1,r={}){if(e<=et)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}=Bd(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:vs(c),ZERO:et,ONE:Me,allowedLengths:a,create:d=>Ee(d,e),isValid:d=>{if(typeof d!="bigint")throw new Error("invalid field element: expected bigint, got "+typeof d);return et<=d&&dd===et,isValidNot0:d=>!f.is0(d)&&f.isValid(d),isOdd:d=>(d&Me)===Me,neg:d=>Ee(-d,e),eql:(d,h)=>d===h,sqr:d=>Ee(d*d,e),add:(d,h)=>Ee(d+h,e),sub:(d,h)=>Ee(d-h,e),mul:(d,h)=>Ee(d*h,e),pow:(d,h)=>Dx(f,d,h),div:(d,h)=>Ee(d*gu(h,e),e),sqrN:d=>d*d,addN:(d,h)=>d+h,subN:(d,h)=>d-h,mulN:(d,h)=>d*h,inv:d=>gu(d,e),sqrt:o||(d=>(l||(l=Rx(e)),l(f,d))),toBytes:d=>n?rc(d,u):Ko(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 g=new Uint8Array(u);g.set(d,n?0:g.length-d.length),d=g}if(d.length!==u)throw new Error("Field.fromBytes: expected "+u+" bytes, got "+d.length);let p=n?Fn(d):er(d);if(i&&(p=Ee(p,e)),!h&&!f.isValid(p))throw new Error("invalid field element: outside of range 0..ORDER");return p},invertBatch:d=>Ad(f,d),cmov:(d,h,p)=>p?h:d});return Object.freeze(f)}function Td(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 Id(e){const t=Td(e);return t+Math.ceil(t/2)}function Od(e,t,n=!1){const r=e.length,s=Td(t),o=Id(t);if(r<16||r1024)throw new Error("expected "+o+"-1024 bytes of input, got "+r);const i=n?Fn(e):er(e),a=Ee(i,t-Me)+Me;return n?rc(a,s):Ko(a,s)}/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */const Sr=BigInt(0),Rn=BigInt(1);function xo(e,t){const n=t.negate();return e?n:t}function Hn(e,t){const n=Ad(e.Fp,t.map(r=>r.Z));return t.map((r,s)=>e.fromAffine(r.toAffine(n[s])))}function Cd(e,t){if(!Number.isSafeInteger(e)||e<=0||e>t)throw new Error("invalid window size, expected [1.."+t+"], got W="+e)}function pi(e,t){Cd(e,t);const n=Math.ceil(t/e)+1,r=2**(e-1),s=2**e,o=vs(e),i=BigInt(e);return{windows:n,windowSize:r,mask:o,maxNumber:s,shiftBy:i}}function yu(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+=Rn);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 Mx(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 Zx(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 gi=new WeakMap,Pd=new WeakMap;function mi(e){return Pd.get(e)||1}function bu(e){if(e!==Sr)throw new Error("invalid wNAF")}class Ud{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>Sr;)n&Rn&&(r=r.add(s)),s=s.double(),n>>=Rn;return r}precomputeWindow(t,n){const{windows:r,windowSize:s}=pi(n,this.bits),o=[];let i=t,a=i;for(let c=0;cSr||r>Sr;)n&Rn&&(o=o.add(s)),r&Rn&&(i=i.add(s)),s=s.double(),n>>=Rn,r>>=Rn;return{p1:o,p2:i}}function Nd(e,t,n,r){Mx(n,e),Zx(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=wd(BigInt(s));let c=1;a>12?c=a-3:a>4?c=a-2:a>0&&(c=2);const u=vs(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 g=0;g>BigInt(h)&u);l[m]=l[m].add(n[g])}let p=i;for(let g=l.length-1,b=i;g>0;g--)b=b.add(l[g]),p=p.add(b);if(d=d.add(p),h!==0)for(let g=0;gSr))throw new Error(`CURVE.${c} must be positive bigint`)}const s=wu(t.p,n.Fp,r),o=wu(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 xu=(e,t)=>(e+(e>=0?t:-t)/Rd)/t;function qx(e,t,n){const[[r,s],[o,i]]=t,a=xu(i*e,n),c=xu(-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 na(e){if(!["compact","recovered","der"].includes(e))throw new Error('Signature format must be "compact", "recovered", or "der"');return e}function yi(e,t){const n={};for(let r of Object.keys(t))n[r]=e[r]===void 0?t[r]:e[r];return zn(n.lowS,"lowS"),zn(n.prehash,"prehash"),n.format!==void 0&&na(n.format),n}class zx extends Error{constructor(t=""){super(t)}}const Kt={Err:zx,_tlv:{encode:(e,t)=>{const{Err:n}=Kt;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=Ns(r);if(s.length/2&128)throw new n("tlv.encode: long form length too big");const o=r>127?Ns(s.length/2|128):"";return Ns(e)+o+s+t},decode(e,t){const{Err:n}=Kt;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}=Kt;if(e{const{X:$,Y:w,Z:_}=K;if(r.eql(_,r.ONE))return{x:$,y:w};const P=K.is0();k==null&&(k=P?r.ONE:r.inv(_));const L=r.mul($,k),N=r.mul(w,k),j=r.mul(_,k);if(P)return{x:r.ZERO,y:r.ZERO};if(!r.eql(j,r.ONE))throw new Error("invZ was invalid");return{x:L,y:N}}),O=wo(K=>{if(K.is0()){if(t.allowInfinityPoint&&!r.is0(K.Y))return;throw new Error("bad point: ZERO")}const{x:k,y:$}=K.toAffine();if(!r.isValid(k)||!r.isValid($))throw new Error("bad point: x or y not field elements");if(!b(k,$))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,k,$,w,_){return $=new T(r.mul($.X,K),$.Y,$.Z),k=xo(w,k),$=xo(_,$),k.add($)}class T{constructor(k,$,w){this.X=y("x",k),this.Y=y("y",$,!0),this.Z=y("z",w),Object.freeze(this)}static CURVE(){return o}static fromAffine(k){const{x:$,y:w}=k||{};if(!k||!r.isValid($)||!r.isValid(w))throw new Error("invalid affine point");if(k instanceof T)throw new Error("projective point not allowed");return r.is0($)&&r.is0(w)?T.ZERO:new T($,w,r.ONE)}static fromBytes(k){const $=T.fromAffine(p(gt(k,void 0,"point")));return $.assertValidity(),$}static fromHex(k){return T.fromBytes(me("pointHex",k))}get x(){return this.toAffine().x}get y(){return this.toAffine().y}precompute(k=8,$=!0){return H.createCache(this,k),$||this.multiply(Ls),this}assertValidity(){O(this)}hasEvenY(){const{y:k}=this.toAffine();if(!r.isOdd)throw new Error("Field doesn't support isOdd");return!r.isOdd(k)}equals(k){v(k);const{X:$,Y:w,Z:_}=this,{X:P,Y:L,Z:N}=k,j=r.eql(r.mul($,N),r.mul(P,_)),M=r.eql(r.mul(w,N),r.mul(L,_));return j&&M}negate(){return new T(this.X,r.neg(this.Y),this.Z)}double(){const{a:k,b:$}=o,w=r.mul($,Ls),{X:_,Y:P,Z:L}=this;let N=r.ZERO,j=r.ZERO,M=r.ZERO,F=r.mul(_,_),ue=r.mul(P,P),oe=r.mul(L,L),Q=r.mul(_,P);return Q=r.add(Q,Q),M=r.mul(_,L),M=r.add(M,M),N=r.mul(k,M),j=r.mul(w,oe),j=r.add(N,j),N=r.sub(ue,j),j=r.add(ue,j),j=r.mul(N,j),N=r.mul(Q,N),M=r.mul(w,M),oe=r.mul(k,oe),Q=r.sub(F,oe),Q=r.mul(k,Q),Q=r.add(Q,M),M=r.add(F,F),F=r.add(M,F),F=r.add(F,oe),F=r.mul(F,Q),j=r.add(j,F),oe=r.mul(P,L),oe=r.add(oe,oe),F=r.mul(oe,Q),N=r.sub(N,F),M=r.mul(oe,ue),M=r.add(M,M),M=r.add(M,M),new T(N,j,M)}add(k){v(k);const{X:$,Y:w,Z:_}=this,{X:P,Y:L,Z:N}=k;let j=r.ZERO,M=r.ZERO,F=r.ZERO;const ue=o.a,oe=r.mul(o.b,Ls);let Q=r.mul($,P),he=r.mul(w,L),pe=r.mul(_,N),Te=r.add($,w),fe=r.add(P,L);Te=r.mul(Te,fe),fe=r.add(Q,he),Te=r.sub(Te,fe),fe=r.add($,_);let we=r.add(P,N);return fe=r.mul(fe,we),we=r.add(Q,pe),fe=r.sub(fe,we),we=r.add(w,_),j=r.add(L,N),we=r.mul(we,j),j=r.add(he,pe),we=r.sub(we,j),F=r.mul(ue,fe),j=r.mul(oe,pe),F=r.add(j,F),j=r.sub(he,F),F=r.add(he,F),M=r.mul(j,F),he=r.add(Q,Q),he=r.add(he,Q),pe=r.mul(ue,pe),fe=r.mul(oe,fe),he=r.add(he,pe),pe=r.sub(Q,pe),pe=r.mul(ue,pe),fe=r.add(fe,pe),Q=r.mul(he,fe),M=r.add(M,Q),Q=r.mul(we,fe),j=r.mul(Te,j),j=r.sub(j,Q),Q=r.mul(Te,he),F=r.mul(we,F),F=r.add(F,Q),new T(j,M,F)}subtract(k){return this.add(k.negate())}is0(){return this.equals(T.ZERO)}multiply(k){const{endo:$}=t;if(!s.isValidNot0(k))throw new Error("invalid scalar: out of range");let w,_;const P=L=>H.cached(this,L,N=>Hn(T,N));if($){const{k1neg:L,k1:N,k2neg:j,k2:M}=x(k),{p:F,f:ue}=P(N),{p:oe,f:Q}=P(M);_=ue.add(Q),w=C($.beta,F,oe,L,j)}else{const{p:L,f:N}=P(k);w=L,_=N}return Hn(T,[w,_])[0]}multiplyUnsafe(k){const{endo:$}=t,w=this;if(!s.isValid(k))throw new Error("invalid scalar: out of range");if(k===Dt||w.is0())return T.ZERO;if(k===lr)return w;if(H.hasCache(this))return this.multiply(k);if($){const{k1neg:_,k1:P,k2neg:L,k2:N}=x(k),{p1:j,p2:M}=Vx(T,w,P,N);return C($.beta,j,M,_,L)}else return H.unsafe(w,k)}multiplyAndAddUnsafe(k,$,w){const _=this.multiplyUnsafe($).add(k.multiplyUnsafe(w));return _.is0()?void 0:_}toAffine(k){return B(this,k)}isTorsionFree(){const{isTorsionFree:k}=t;return i===lr?!0:k?k(T,this):H.unsafe(this,a).is0()}clearCofactor(){const{clearCofactor:k}=t;return i===lr?this:k?k(T,this):this.multiplyUnsafe(i)}isSmallOrder(){return this.multiplyUnsafe(i).is0()}toBytes(k=!0){return zn(k,"isCompressed"),this.assertValidity(),h(T,this,k)}toHex(k=!0){return Se(this.toBytes(k))}toString(){return``}get px(){return this.X}get py(){return this.X}get pz(){return this.Z}toRawBytes(k=!0){return this.toBytes(k)}_setWindowSize(k){this.precompute(k)}static normalizeZ(k){return Hn(T,k)}static msm(k,$){return Nd(T,s,k,$)}static fromPrivateKey(k){return T.BASE.multiply(jn(s,k))}}T.BASE=new T(o.Gx,o.Gy,r.ONE),T.ZERO=new T(r.ZERO,r.ONE,r.ZERO),T.Fp=r,T.Fn=s;const U=s.BITS,H=new Ud(T,t.endo?Math.ceil(U/2):U);return T.BASE.precompute(8),T}function Hd(e){return Uint8Array.of(e?2:3)}function jd(e,t){return{secretKey:t.BYTES,publicKey:1+e.BYTES,publicKeyUncompressed:1+2*e.BYTES,publicKeyHasPrefix:!0,signature:2*t.BYTES}}function Gx(e,t={}){const{Fn:n}=e,r=t.randomBytes||Qn,s=Object.assign(jd(e.Fp,n),{seed:Id(n.ORDER)});function o(h){try{return!!jn(n,h)}catch{return!1}}function i(h,p){const{publicKey:g,publicKeyUncompressed:b}=s;try{const m=h.length;return p===!0&&m!==g||p===!1&&m!==b?!1:!!e.fromBytes(h)}catch{return!1}}function a(h=r(s.seed)){return Od(gt(h,s.seed,"seed"),n.ORDER)}function c(h,p=!0){return e.BASE.multiply(jn(n,h)).toBytes(p)}function u(h){const p=a(h);return{secretKey:p,publicKey:c(p)}}function l(h){if(typeof h=="bigint")return!1;if(h instanceof e)return!0;const{secretKey:p,publicKey:g,publicKeyUncompressed:b}=s;if(n.allowedLengths||p===g)return;const m=me("key",h).length;return m===g||m===b}function f(h,p,g=!0){if(l(h)===!0)throw new Error("first arg must be private key");if(l(p)===!1)throw new Error("second arg must be public key");const b=jn(n,h);return e.fromHex(p).multiply(b).toBytes(g)}return Object.freeze({getPublicKey:c,getSharedSecret:f,keygen:u,Point:e,utils:{isValidSecretKey:o,isValidPublicKey:i,randomSecretKey:a,isValidPrivateKey:o,randomPrivateKey:a,normPrivateKeyToScalar:h=>jn(n,h),precompute(h=8,p=e.BASE){return p.precompute(h,!1)}},lengths:s})}function Yx(e,t,n={}){xs(t),Cr(n,{},{hmac:"function",lowS:"boolean",randomBytes:"function",bits2int:"function",bits2int_modN:"function"});const r=n.randomBytes||Qn,s=n.hmac||(($,...w)=>En(t,$,ae(...w))),{Fp:o,Fn:i}=e,{ORDER:a,BITS:c}=i,{keygen:u,getPublicKey:l,getSharedSecret:f,utils:d,lengths:h}=Gx(e,n),p={prehash:!1,lowS:typeof n.lowS=="boolean"?n.lowS:!1,format:void 0,extraEntropy:!1},g="compact";function b($){const w=a>>lr;return $>w}function m($,w){if(!i.isValidNot0(w))throw new Error(`invalid signature ${$}: out of range 1..Point.Fn.ORDER`);return w}function E($,w){na(w);const _=h.signature,P=w==="compact"?_:w==="recovered"?_+1:void 0;return gt($,P,`${w} signature`)}class y{constructor(w,_,P){this.r=m("r",w),this.s=m("s",_),P!=null&&(this.recovery=P),Object.freeze(this)}static fromBytes(w,_=g){E(w,_);let P;if(_==="der"){const{r:M,s:F}=Kt.toSig(gt(w));return new y(M,F)}_==="recovered"&&(P=w[0],_="compact",w=w.subarray(1));const L=i.BYTES,N=w.subarray(0,L),j=w.subarray(L,L*2);return new y(i.fromBytes(N),i.fromBytes(j),P)}static fromHex(w,_){return this.fromBytes(ut(w),_)}addRecoveryBit(w){return new y(this.r,this.s,w)}recoverPublicKey(w){const _=o.ORDER,{r:P,s:L,recovery:N}=this;if(N==null||![0,1,2,3].includes(N))throw new Error("recovery id invalid");if(a*Rd<_&&N>1)throw new Error("recovery id is ambiguous for h>1 curve");const M=N===2||N===3?P+a:P;if(!o.isValid(M))throw new Error("recovery id 2 or 3 invalid");const F=o.toBytes(M),ue=e.fromBytes(ae(Hd((N&1)===0),F)),oe=i.inv(M),Q=x(me("msgHash",w)),he=i.create(-Q*oe),pe=i.create(L*oe),Te=e.BASE.multiplyUnsafe(he).add(ue.multiplyUnsafe(pe));if(Te.is0())throw new Error("point at infinify");return Te.assertValidity(),Te}hasHighS(){return b(this.s)}toBytes(w=g){if(na(w),w==="der")return ut(Kt.hexFromSig(this));const _=i.toBytes(this.r),P=i.toBytes(this.s);if(w==="recovered"){if(this.recovery==null)throw new Error("recovery bit must be present");return ae(Uint8Array.of(this.recovery),_,P)}return ae(_,P)}toHex(w){return Se(this.toBytes(w))}assertValidity(){}static fromCompact(w){return y.fromBytes(me("sig",w),"compact")}static fromDER(w){return y.fromBytes(me("sig",w),"der")}normalizeS(){return this.hasHighS()?new y(this.r,i.neg(this.s),this.recovery):this}toDERRawBytes(){return this.toBytes("der")}toDERHex(){return Se(this.toBytes("der"))}toCompactRawBytes(){return this.toBytes("compact")}toCompactHex(){return Se(this.toBytes("compact"))}}const v=n.bits2int||function(w){if(w.length>8192)throw new Error("input is too large");const _=er(w),P=w.length*8-c;return P>0?_>>BigInt(P):_},x=n.bits2int_modN||function(w){return i.create(v(w))},B=vs(c);function O($){return us("num < 2^"+c,$,Dt,B),i.toBytes($)}function C($,w){return gt($,void 0,"message"),w?gt(t($),void 0,"prehashed message"):$}function T($,w,_){if(["recovered","canonical"].some(he=>he in _))throw new Error("sign() legacy options not supported");const{lowS:P,prehash:L,extraEntropy:N}=yi(_,p);$=C($,L);const j=x($),M=jn(i,w),F=[O(M),O(j)];if(N!=null&&N!==!1){const he=N===!0?r(h.secretKey):N;F.push(me("extraEntropy",he))}const ue=ae(...F),oe=j;function Q(he){const pe=v(he);if(!i.isValidNot0(pe))return;const Te=i.inv(pe),fe=e.BASE.multiply(pe).toAffine(),we=i.create(fe.x);if(we===Dt)return;const Nt=i.create(Te*i.create(oe+we*M));if(Nt===Dt)return;let rt=(fe.x===we?0:2)|Number(fe.y&lr),Ke=Nt;return P&&b(Nt)&&(Ke=i.neg(Nt),rt^=1),new y(we,Ke,rt)}return{seed:ue,k2sig:Q}}function U($,w,_={}){$=me("message",$);const{seed:P,k2sig:L}=T($,w,_);return Cx(t.outputLen,i.BYTES,s)(P,L)}function H($){let w;const _=typeof $=="string"||ws($),P=!_&&$!==null&&typeof $=="object"&&typeof $.r=="bigint"&&typeof $.s=="bigint";if(!_&&!P)throw new Error("invalid signature, expected Uint8Array, hex string or Signature instance");if(P)w=new y($.r,$.s);else if(_){try{w=y.fromBytes(me("sig",$),"der")}catch(L){if(!(L instanceof Kt.Err))throw L}if(!w)try{w=y.fromBytes(me("sig",$),"compact")}catch{return!1}}return w||!1}function K($,w,_,P={}){const{lowS:L,prehash:N,format:j}=yi(P,p);if(_=me("publicKey",_),w=C(me("message",w),N),"strict"in P)throw new Error("options.strict was renamed to lowS");const M=j===void 0?H($):y.fromBytes(me("sig",$),j);if(M===!1)return!1;try{const F=e.fromBytes(_);if(L&&M.hasHighS())return!1;const{r:ue,s:oe}=M,Q=x(w),he=i.inv(oe),pe=i.create(Q*he),Te=i.create(ue*he),fe=e.BASE.multiplyUnsafe(pe).add(F.multiplyUnsafe(Te));return fe.is0()?!1:i.create(fe.x)===ue}catch{return!1}}function k($,w,_={}){const{prehash:P}=yi(_,p);return w=C(w,P),y.fromBytes($,"recovered").recoverPublicKey(w).toBytes()}return Object.freeze({keygen:u,getPublicKey:l,getSharedSecret:f,utils:d,lengths:h,Point:e,sign:U,verify:K,recoverPublicKey:k,Signature:y,hash:t})}function Xx(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=tr(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 Jx(e){const{CURVE:t,curveOpts:n}=Xx(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 Qx(e,t){const n=t.Point;return Object.assign({},t,{ProjectivePoint:n,CURVE:Object.assign({},e,Bd(n.Fn.ORDER,n.Fn.BITS))})}function e2(e){const{CURVE:t,curveOpts:n,hash:r,ecdsaOpts:s}=Jx(e),o=Wx(t,n),i=Yx(o,r,s);return Qx(e,i)}/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */function t2(e,t){const n=r=>e2({...e,hash:r});return{...n(t),create:n}}/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */const $r={p:BigInt("0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f"),n:BigInt("0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141"),h:BigInt(1),a:BigInt(0),b:BigInt(7),Gx:BigInt("0x79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798"),Gy:BigInt("0x483ada7726a3c4655da4fbfc0e1108a8fd17b448a68554199c47d08ffb10d4b8")},n2={beta:BigInt("0x7ae96a2b657c07106e64479eac3434e99cf0497512f58995c1396c28719501ee"),basises:[[BigInt("0x3086d221a7d46bcde86c90e49284eb15"),-BigInt("0xe4437ed6010e88286f547fa90abfe4c3")],[BigInt("0x114ca50f7a8e2f3f657c1108d9d44cfd8"),BigInt("0x3086d221a7d46bcde86c90e49284eb15")]]},r2=BigInt(0),vu=BigInt(1),ra=BigInt(2);function s2(e){const t=$r.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=_e(l,n,t)*l%t,d=_e(f,n,t)*l%t,h=_e(d,ra,t)*u%t,p=_e(h,s,t)*h%t,g=_e(p,o,t)*p%t,b=_e(g,a,t)*g%t,m=_e(b,c,t)*b%t,E=_e(m,a,t)*g%t,y=_e(E,n,t)*l%t,v=_e(y,i,t)*p%t,x=_e(v,r,t)*u%t,B=_e(x,ra,t);if(!vo.eql(vo.sqr(B),e))throw new Error("Cannot find square root");return B}const vo=tr($r.p,{sqrt:s2}),ke=t2({...$r,Fp:vo,lowS:!0,endo:n2},xe),Eu={};function Eo(e,...t){let n=Eu[e];if(n===void 0){const r=xe(Ue(e));n=ae(r,r),Eu[e]=n}return xe(ae(n,...t))}const oc=e=>e.toBytes(!0).slice(1),Pr=ke.Point,ic=e=>e%ra===r2;function sa(e){const{Fn:t,BASE:n}=Pr,r=jn(t,e),s=n.multiply(r);return{scalar:ic(s.y)?r:t.neg(r),bytes:oc(s)}}function Kd(e){const t=vo;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);ic(s)||(s=t.neg(s));const o=Pr.fromAffine({x:e,y:s});return o.assertValidity(),o}const Fr=er;function Dd(...e){return Pr.Fn.create(Fr(Eo("BIP0340/challenge",...e)))}function ku(e){return sa(e).bytes}function o2(e,t,n=Qn(32)){const{Fn:r}=Pr,s=me("message",e),{bytes:o,scalar:i}=sa(t),a=me("auxRand",n,32),c=r.toBytes(i^Fr(Eo("BIP0340/aux",a))),u=Eo("BIP0340/nonce",c,o,s),{bytes:l,scalar:f}=sa(u),d=Dd(l,o,s),h=new Uint8Array(64);if(h.set(l,0),h.set(r.toBytes(r.create(f+d*i)),32),!Md(h,s,o))throw new Error("sign: Invalid signature produced");return h}function Md(e,t,n){const{Fn:r,BASE:s}=Pr,o=me("signature",e,64),i=me("message",t),a=me("publicKey",n,32);try{const c=Kd(Fr(a)),u=Fr(o.subarray(0,32));if(!ta(u,vu,$r.p))return!1;const l=Fr(o.subarray(32,64));if(!ta(l,vu,$r.n))return!1;const f=Dd(r.toBytes(u),oc(c),i),d=s.multiplyUnsafe(l).add(c.multiplyUnsafe(r.neg(f))),{x:h,y:p}=d.toAffine();return!(d.is0()||!ic(p)||h!==u)}catch{return!1}}const kn=(()=>{const n=(s=Qn(48))=>Od(s,$r.n);ke.utils.randomSecretKey;function r(s){const o=n(s);return{secretKey:o,publicKey:ku(o)}}return{keygen:r,getPublicKey:ku,sign:o2,verify:Md,Point:Pr,utils:{randomSecretKey:n,randomPrivateKey:n,taggedHash:Eo,lift_x:Kd,pointToBytes:oc,numberToBytesBE:Ko,bytesToNumberBE:er,mod:Ee},lengths:{secretKey:32,publicKey:32,publicKeyHasPrefix:!1,signature:64,seed:48}}})(),i2=BigInt(0),jr=BigInt(1),a2=BigInt(2),c2=BigInt(7),u2=BigInt(256),f2=BigInt(113),Zd=[],Vd=[],qd=[];for(let e=0,t=jr,n=1,r=0;e<24;e++){[n,r]=[r,(2*n+3*r)%5],Zd.push(2*(5*r+n)),Vd.push((e+1)*(e+2)/2%64);let s=i2;for(let o=0;o<7;o++)t=(t<>c2)*f2)%u2,t&a2&&(s^=jr<<(jr<n>32?wx(e,t,n):yx(e,t,n),$u=(e,t,n)=>n>32?xx(e,t,n):bx(e,t,n);function h2(e,t=24){const n=new Uint32Array(10);for(let r=24-t;r<24;r++){for(let i=0;i<10;i++)n[i]=e[i]^e[i+10]^e[i+20]^e[i+30]^e[i+40];for(let i=0;i<10;i+=2){const a=(i+8)%10,c=(i+2)%10,u=n[c],l=n[c+1],f=Su(u,l,1)^n[a],d=$u(u,l,1)^n[a+1];for(let h=0;h<50;h+=10)e[i+h]^=f,e[i+h+1]^=d}let s=e[2],o=e[3];for(let i=0;i<24;i++){const a=Vd[i],c=Su(s,o,a),u=$u(s,o,a),l=Zd[i];s=e[l],o=e[l+1],e[l]=c,e[l+1]=u}for(let i=0;i<50;i+=10){for(let a=0;a<10;a++)n[a]=e[i+a];for(let a=0;a<10;a++)e[i+a]^=~n[(a+2)%10]&n[(a+4)%10]}e[0]^=l2[r],e[1]^=d2[r]}ct(n)}class ac extends ec{constructor(t,n,r,s=!1,o=24){if(super(),this.pos=0,this.posOut=0,this.finished=!1,this.destroyed=!1,this.enableXOF=!1,this.blockLen=t,this.suffix=n,this.outputLen=r,this.enableXOF=s,this.rounds=o,It(r),!(0=r&&this.keccak();const i=Math.min(r-this.posOut,o-s);t.set(n.subarray(this.posOut,this.posOut+i),s),this.posOut+=i,s+=i}return t}xofInto(t){if(!this.enableXOF)throw new Error("XOF is not possible for this instance");return this.writeInto(t)}xof(t){return It(t),this.xofInto(new Uint8Array(t))}digestInto(t){if(hd(t,this),this.finished)throw new Error("digest() was already called");return this.writeInto(t),this.destroy(),t}digest(){return this.digestInto(new Uint8Array(this.outputLen))}destroy(){this.destroyed=!0,ct(this.state)}_cloneInto(t){const{blockLen:n,suffix:r,outputLen:s,rounds:o,enableXOF:i}=this;return t||(t=new ac(n,r,s,i,o)),t.state32.set(this.state32),t.pos=this.pos,t.posOut=this.posOut,t.finished=this.finished,t.rounds=o,t.suffix=r,t.outputLen=s,t.enableXOF=i,t.destroyed=this.destroyed,t}}const p2=(e,t,n)=>jo(()=>new ac(t,e,n)),cc=p2(1,136,256/8),g2=Uint8Array.from([7,4,13,1,10,6,15,3,12,0,9,5,2,14,11,8]),Fd=Uint8Array.from(new Array(16).fill(0).map((e,t)=>t)),m2=Fd.map(e=>(9*e+5)%16),Wd=(()=>{const n=[[Fd],[m2]];for(let r=0;r<4;r++)for(let s of n)s.push(s[r].map(o=>g2[o]));return n})(),Gd=Wd[0],Yd=Wd[1],Xd=[[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)),y2=Gd.map((e,t)=>e.map(n=>Xd[t][n])),b2=Yd.map((e,t)=>e.map(n=>Xd[t][n])),w2=Uint32Array.from([0,1518500249,1859775393,2400959708,2840853838]),x2=Uint32Array.from([1352829926,1548603684,1836072691,2053994217,0]);function _u(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 Rs=new Uint32Array(16);class v2 extends tc{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)Rs[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 p=4-h,g=w2[h],b=x2[h],m=Gd[h],E=Yd[h],y=y2[h],v=b2[h];for(let x=0;x<16;x++){const B=Os(r+_u(h,o,a,u)+Rs[m[x]]+g,y[x])+f|0;r=f,f=u,u=Os(a,10)|0,a=o,o=B}for(let x=0;x<16;x++){const B=Os(s+_u(p,i,c,l)+Rs[E[x]]+b,v[x])+d|0;s=d,d=l,l=Os(c,10)|0,c=i,i=B}}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(){ct(Rs)}destroy(){this.destroyed=!0,ct(this.buffer),this.set(0,0,0,0,0)}}const uc=jo(()=>new v2);/*! scure-base - MIT License (c) 2022 Paul Miller (paulmillr.com) */function _r(e){return e instanceof Uint8Array||ArrayBuffer.isView(e)&&e.constructor.name==="Uint8Array"}function E2(e,...t){if(!_r(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 Jd(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 Qd(e){if(typeof e!="function")throw new Error("function expected");return!0}function Wn(e,t){if(typeof t!="string")throw new Error(`${e}: string expected`);return!0}function Ur(e){if(!Number.isSafeInteger(e))throw new Error(`invalid integer: ${e}`)}function ko(e){if(!Array.isArray(e))throw new Error("array expected")}function So(e,t){if(!Jd(!0,t))throw new Error(`${e}: array of strings expected`)}function fc(e,t){if(!Jd(!1,t))throw new Error(`${e}: array of numbers expected`)}function Es(...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 Do(e){const t=typeof e=="string"?e.split(""):e,n=t.length;So("alphabet",t);const r=new Map(t.map((s,o)=>[s,o]));return{encode:s=>(ko(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=>(ko(s),s.map(o=>{Wn("alphabet.decode",o);const i=r.get(o);if(i===void 0)throw new Error(`Unknown letter: "${o}". Allowed: ${e}`);return i}))}}function Mo(e=""){return Wn("join",e),{encode:t=>(So("join.decode",t),t.join(e)),decode:t=>(Wn("join.decode",t),t.split(e))}}function eh(e,t="="){return Ur(e),Wn("padding",t),{encode(n){for(So("padding.encode",n);n.length*e%8;)n.push(t);return n},decode(n){So("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 oa(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(ko(e),!e.length)return[];let r=0;const s=[],o=Array.from(e,a=>{if(Ur(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:th(t,e%t),$o=(e,t)=>e+(t-th(e,t)),Gs=(()=>{let e=[];for(let t=0;t<40;t++)e.push(2**t);return e})();function _o(e,t,n,r){if(ko(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($o(t,n)>32)throw new Error(`convertRadix2: carry overflow from=${t} to=${n} carryBits=${$o(t,n)}`);let s=0,o=0;const i=Gs[t],a=Gs[n]-1,c=[];for(const u of e){if(Ur(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=Gs[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 nh(e){Ur(e);const t=2**8;return{encode:n=>{if(!_r(n))throw new Error("radix.encode input should be Uint8Array");return oa(Array.from(n),t,e)},decode:n=>(fc("radix.decode",n),Uint8Array.from(oa(n,e,t)))}}function lc(e,t=!1){if(Ur(e),e<=0||e>32)throw new Error("radix2: bits should be in (0..32]");if($o(8,e)>32||$o(e,8)>32)throw new Error("radix2: carry overflow");return{encode:n=>{if(!_r(n))throw new Error("radix2.encode input should be Uint8Array");return _o(Array.from(n),8,e,!t)},decode:n=>(fc("radix2.decode",n),Uint8Array.from(_o(n,e,8,t)))}}function Au(e){return Qd(e),function(...t){try{return e.apply(null,t)}catch{}}}function rh(e,t){return Ur(e),Qd(t),{encode(n){if(!_r(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(!_r(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{Wn("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"})},it=k2?{encode(e){return E2(e),e.toBase64()},decode(e){return S2(e)}}:Es(lc(6),Do("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"),eh(6),Mo("")),$2=e=>Es(nh(58),Do(e),Mo("")),_2=$2("123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"),sh=e=>Es(rh(4,t=>e(e(t))),_2),ia=Es(Do("qpzry9x8gf2tvdw0s3jn54khce6mua7l"),Mo("")),Bu=[996825010,642813549,513874426,1027748829,705979059];function Kr(e){const t=e>>25;let n=(e&33554431)<<5;for(let r=0;r>r&1)===1&&(n^=Bu[r]);return n}function Tu(e,t,n=1){const r=e.length;let s=1;for(let o=0;o126)throw new Error(`Invalid prefix (${e})`);s=Kr(s)^i>>5}s=Kr(s);for(let o=0;oh)throw new TypeError(`Length ${g} exceeds limit ${h}`);const b=f.toLowerCase(),m=Tu(b,d,t);return`${b}1${ia.encode(d)}${m}`}function a(f,d=90){Wn("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 p=f.toLowerCase();if(f!==p&&f!==f.toUpperCase())throw new Error("String must be lowercase or uppercase");const g=p.lastIndexOf("1");if(g===0||g===-1)throw new Error('Letter "1" must be present between prefix and data only');const b=p.slice(0,g),m=p.slice(g+1);if(m.length<6)throw new Error("Data must be at least 6 characters long");const E=ia.decode(m).slice(0,-6),y=Tu(b,E,t);if(!m.endsWith(y))throw new Error(`Invalid checksum in ${f}: expected "${y}"`);return{prefix:b,words:E}}const c=Au(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 Gn=oh("bech32"),A2=oh("bech32m");/*! scure-bip32 - MIT License (c) 2022 Patricio Palladino, Paul Miller (paulmillr.com) */const js=ke.ProjectivePoint,bi=sh(xe);function Iu(e){Re(e);const t=e.length===0?"0":Se(e);return BigInt("0x"+t)}function B2(e){if(typeof e!="bigint")throw new Error("bigint expected");return ut(e.toString(16).padStart(64,"0"))}const T2=Ue("Bitcoin seed"),wi={private:76066276,public:76067358},xi=2147483648,I2=e=>uc(xe(e)),O2=e=>Dn(e).getUint32(0,!1),Ks=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 Dn(t).setUint32(0,e,!1),t};class Cn{get fingerprint(){if(!this.pubHash)throw new Error("No publicKey set!");return O2(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 bi.encode(this.serialize(this.versions.private,ae(new Uint8Array([0]),t)))}get publicExtendedKey(){if(!this.pubKey)throw new Error("No public key");return bi.encode(this.serialize(this.versions.public,this.pubKey))}static fromMasterSeed(t,n=wi){if(Re(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=En(cs,T2,t);return new Cn({versions:n,chainCode:r.slice(32),privateKey:r.slice(0,32)})}static fromExtendedKey(t,n=wi){const r=bi.decode(t),s=Dn(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 Cn({...i,privateKey:a.slice(1)}):new Cn({...i,publicKey:a})}static fromJSON(t){return Cn.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||wi,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(!ke.utils.isValidPrivateKey(t.privateKey))throw new Error("Invalid private key");this.privKey=typeof t.privateKey=="bigint"?t.privateKey:Iu(t.privateKey),this.privKeyBytes=B2(this.privKey),this.pubKey=ke.getPublicKey(t.privateKey,!0)}else if(t.publicKey)this.pubKey=js.fromHex(t.publicKey).toRawBytes(!0);else throw new Error("HDKey: no public or private key provided");this.pubHash=I2(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>=xi)throw new Error("Invalid index");o[2]==="'"&&(a+=xi),r=r.deriveChild(a)}return r}deriveChild(t){if(!this.pubKey||!this.chainCode)throw new Error("No publicKey or chainCode set");let n=Ks(t);if(t>=xi){const a=this.privateKey;if(!a)throw new Error("Could not derive hardened child key");n=ae(new Uint8Array([0]),a,n)}else n=ae(this.pubKey,n);const r=En(cs,this.chainCode,n),s=Iu(r.slice(0,32)),o=r.slice(32);if(!ke.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=Ee(this.privKey+s,ke.CURVE.n);if(!ke.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=js.fromHex(this.pubKey).add(js.fromPrivateKey(s));if(a.equals(js.ZERO))throw new Error("The tweak was equal to negative P, which made the result key invalid");i.publicKey=a.toRawBytes(!0)}return new Cn(i)}catch{return this.deriveChild(t+1)}}sign(t){if(!this.privateKey)throw new Error("No privateKey set!");return Re(t,32),ke.sign(t,this.privKey).toCompactRawBytes()}verify(t,n){if(Re(t,32),Re(n,64),!this.publicKey)throw new Error("No publicKey set!");let r;try{r=ke.Signature.fromCompact(n)}catch{return!1}return ke.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 Re(n,33),ae(Ks(t),new Uint8Array([this.depth]),Ks(this.parentFingerprint),Ks(this.index),this.chainCode,n)}}function C2(e,t,n,r){xs(e);const s=dx({dkLen:32,asyncTick:10},r),{c:o,dkLen:i,asyncTick:a}=s;if(It(o),It(i),It(a),o<1)throw new Error("iterations (c) should be >= 1");const c=fu(t),u=fu(n),l=new Uint8Array(i),f=En.create(e,c),d=f._cloneInto().update(u);return{c:o,dkLen:i,asyncTick:a,DK:l,PRF:f,PRFSalt:d}}function P2(e,t,n,r,s){return e.destroy(),t.destroy(),r&&r.destroy(),ct(s),n}function U2(e,t,n,r){const{c:s,dkLen:o,DK:i,PRF:a,PRFSalt:c}=C2(e,t,n,r);let u;const l=new Uint8Array(4),f=Dn(l),d=new Uint8Array(a.outputLen);for(let h=1,p=0;pe[0]==="あいこくしん";function ih(e){if(typeof e!="string")throw new TypeError("invalid mnemonic type: "+typeof e);return e.normalize("NFKD")}function ah(e){const t=ih(e),n=t.split(" ");if(![12,15,18,21,24].includes(n.length))throw new Error("Invalid mnemonic");return{nfkd:t,words:n}}function ch(e){Re(e,16,20,24,28,32)}function L2(e,t=128){if(It(t),t%32!==0||t>256)throw new TypeError("Invalid entropy");return fh(Qn(t/8),e)}const R2=e=>{const t=8-e.length/4;return new Uint8Array([xe(e)[0]>>t<{if(typeof t!="string")throw new Error("wordlist: non-string element: "+t)}),Hs.chain(Hs.checksum(1,R2),Hs.radix2(11,!0),Hs.alphabet(e))}function H2(e,t){const{words:n}=ah(e),r=uh(t).decode(n);return ch(r),r}function fh(e,t){return ch(e),uh(t).encode(e).join(N2(t)?" ":" ")}function j2(e,t){try{H2(e,t)}catch{return!1}return!0}const K2=e=>ih("mnemonic"+e);function D2(e,t=""){return U2(cs,ah(e).nfkd,K2(t),{c:2048,dkLen:64})}const dc=`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(` -`),Ye={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`,ethereum:e=>`m/44'/60'/${e}'/0/0`},M2=2**31-1,vi=new Map,Ei=new Map,Ou=()=>L2(dc,256);function lh(e,t=0){if(typeof e!="string"||!j2(e,dc)||t&&e.split(" ").length!==t)throw new Error("Invalid lab mnemonic.");return e}function An(e,t){if(!Number.isSafeInteger(e)||e<0||e>M2)throw new Error(`Invalid ${t}.`);return e}const ki=new Map;function hc(e){return ki.has(e)||ki.set(e,D2(lh(e))),ki.get(e)}function Bn(e){return vi.has(e)||vi.set(e,Cn.fromMasterSeed(hc(e))),vi.get(e)}function Z2(e,t){const n=e.derive(t).privateKey;if(!n)throw new Error("BIP-85 path produced no private key.");return En(cs,Ue("bip-entropy-from-k"),n)}function V2(e,t){const n=`${e}|${An(t,"child index")}`;return Ei.has(n)||Ei.set(n,fh(Z2(Bn(e),Ye.orgSeed(t)).slice(0,32),dc)),Ei.get(n)}function aa(e,t=0,n=1){return Se(Bn(e).derive(Ye.wallet(An(t,"account"),n)).privateKey)}function pc(e,t=0,n=1){return Se(Bn(e).derive(Ye.segwit(An(t,"account"),n)).privateKey)}function dh(e,t=0,n=1){return Se(Bn(e).derive(Ye.segwit(An(t,"account"),n)).publicKey)}function Zo(e,t=0){return Se(Bn(e).derive(Ye.nostr(An(t,"account"))).privateKey)}function hh(e){const t=e.toLowerCase(),n=Se(cc(Ue(t)));return`0x${[...t].map((r,s)=>parseInt(n[s],16)>=8?r.toUpperCase():r).join("")}`}const ph=e=>hh(Se(cc(ke.ProjectivePoint.fromHex(e).toRawBytes(!1).slice(1)).slice(-20)));function gh(e,t=0){return Se(Bn(e).derive(Ye.ethereum(An(t,"account"))).privateKey)}const Si=new Map;function q2(e,t=0){const n=`${e}|${t}`;return Si.has(n)||Si.set(n,ph(Bn(e).derive(Ye.ethereum(An(t,"account"))).publicKey)),Si.get(n)}function z2(e,t=0){const n=kn.getPublicKey(Bn(e).derive(Ye.nostr(An(t,"account"))).privateKey);return{pubkey:Se(n),npub:Gn.encode("npub",Gn.toWords(n))}}const xt=["taproot","segwit","nostr","ethereum"],Vo=(e,t)=>["lineage/v0 keyring",`node: ${e}`,...xt.map(n=>`${n}: ${t[n]}`)].join(` -`),F2=["bc","tb","bcrt"],mh=new Uint8Array(32),Qe=e=>{const t=new Uint8Array(4);return new DataView(t.buffer).setUint32(0,e,!0),t},fs=e=>ae(e.length<253?Uint8Array.of(e.length):Uint8Array.of(253,e.length&255,e.length>>8),e),Vr=e=>xe(xe(e)),yh=(e,...t)=>{const n=xe(Ue(e));return xe(ae(n,n,...t))},W2=(e,t)=>e.length===t.length&&e.every((n,r)=>n===t[r]);function ls(e){if(typeof e!="string"||e!==e.toLowerCase())return null;for(const[t,n]of[[Gn,0],[A2,1]])try{const{prefix:r,words:s}=t.decode(e,90);if(s[0]===n&&F2.includes(r))return{network:r,version:n,program:Uint8Array.from(t.fromWords(s.slice(1)))}}catch{}return null}const gc=e=>(e==null?void 0:e.version)===1&&e.program.length===32,mc=e=>(e==null?void 0:e.version)===0&&e.program.length===20,bh=({version:e,program:t})=>ae(Uint8Array.of(e?80+e:0,t.length),t),G2=e=>yh("BIP0322-signed-message",Ue(e)),Ao=new Uint8Array(8),Cu=ae(Ao,fs(Uint8Array.of(106)));function Y2(e,t){const n=bh(e),r=ae(Uint8Array.of(0,32),G2(t));return Vr(ae(Qe(0),Uint8Array.of(1),new Uint8Array(32),Qe(4294967295),fs(r),Qe(0),Uint8Array.of(1),Ao,fs(n),Qe(0)))}function Bo(e,t,n=0){const r=bh(e),s=ae(Y2(e,t),Qe(0));if(e.version===0){const o=ae(Uint8Array.of(25,118,169,20),e.program,Uint8Array.of(136,172));return Vr(ae(Qe(0),Vr(s),Vr(Qe(0)),s,o,Ao,Qe(0),Vr(Cu),Qe(0),Qe(1)))}return yh("TapSighash",Uint8Array.of(0,n),Qe(0),Qe(0),xe(s),xe(Ao),xe(fs(r)),xe(Qe(0)),xe(Cu),Uint8Array.of(0),Qe(0))}const Pu=e=>it.encode(ae(Uint8Array.of(e.length),...e.map(fs)));function X2(e){try{const t=it.decode(e);let n=0;const r=()=>{if(n>=t.length)throw new Error("short");const o=t[n++];if(o<253)return o;if(o>253||n+2>t.length)throw new Error("size");return n+=2,t[n-2]|t[n-1]<<8},s=Array.from({length:r()},()=>{const o=r();if(n+o>t.length)throw new Error("short");return n+=o,t.slice(n-o,n)});return n===t.length?s:null}catch{return null}}function Uu(e,t,n){const r=ls(e);if(gc(r))return Pu([kn.sign(Bo(r,t),n,mh)]);if(!mc(r))throw new Error("BIP-322 here signs for Taproot and P2WPKH addresses only.");const s=ke.sign(Bo(r,t),n).toDERRawBytes();return Pu([ae(s,Uint8Array.of(1)),ke.getPublicKey(n,!0)])}function Nu(e,t,n){const r=ls(e),s=typeof n=="string"?X2(n):null;if(!r||!s)return!1;try{if(gc(r)){const[o]=s;return s.length!==1||!(o.length===64||o.length===65&&o[64]===1)?!1:kn.verify(o.slice(0,64),Bo(r,t,o.length===65?1:0),r.program)}if(mc(r)){const[o,i]=s;return s.length!==2||i.length!==33||o.at(-1)!==1||!W2(uc(xe(i)),r.program)?!1:ke.verify(ke.Signature.fromDER(o.slice(0,-1)),Bo(r,t),i)}}catch{}return!1}const wh=e=>{const t=Ue(e);return cc(ae(Ue(`Ethereum Signed Message: -${t.length}`),t))},xh=e=>typeof e=="string"&&/^0x[0-9a-fA-F]{40}$/.test(e)&&hh(e.slice(2))===e;function J2(e,t){const n=ke.sign(wh(e),t);return`0x${Se(n.toCompactRawBytes())}${(27+n.recovery).toString(16)}`}function Q2(e,t,n){if(!xh(e)||typeof n!="string"||!/^0x[0-9a-f]{130}$/.test(n))return!1;try{const r=ut(n.slice(2)),s=r[64]-27;if(s!==0&&s!==1)return!1;const o=ke.Signature.fromCompact(r.slice(0,64)).addRecoveryBit(s).recoverPublicKey(wh(t));return ph(o.toRawBytes(!1))===e}catch{return!1}}const vh=(e,t)=>xe(Ue(JSON.stringify([0,e,0,1,[],t])));function yc(e){try{const{prefix:t,words:n}=Gn.decode(e,90),r=Gn.fromWords(n);return t==="npub"&&r.length===32&&e===e.toLowerCase()?Se(Uint8Array.from(r)):null}catch{return null}}const ev=(e,t)=>Se(kn.sign(vh(Se(kn.getPublicKey(t)),e),t,mh));function tv(e,t,n){const r=yc(e);try{return!!r&&typeof n=="string"&&/^[0-9a-f]{128}$/.test(n)&&kn.verify(n,vh(r,t),r)}catch{return!1}}const nv={taproot:Uu,segwit:Uu,nostr:(e,t,n)=>ev(t,n),ethereum:(e,t,n)=>J2(t,n)},rv={taproot:Nu,segwit:Nu,nostr:tv,ethereum:Q2};function Eh(e){const t=ls(e.taproot),n=ls(e.segwit);return gc(t)?mc(n)?t.network!==n.network?"its Taproot and SegWit addresses must be on one network":yc(e.nostr)?xh(e.ethereum)?"":"ethereum must be an EIP-55 address":"nostr must be an npub":"segwit must be a P2WPKH address":"taproot must be a Taproot address"}function sv(e,t,n){const r=Eh(t);if(r)throw new Error(`${r[0].toUpperCase()}${r.slice(1)}.`);const s=Vo(e,t);return{...Object.fromEntries(xt.map(o=>[o,t[o]])),proof:Object.fromEntries(xt.map(o=>[o,nv[o](t[o],s,n[o])]))}}const Dr=new Map;function ov(e,t){const n=t.proof&&typeof t.proof=="object"&&!Array.isArray(t.proof)?t.proof:{},r=JSON.stringify([e,...xt.map(s=>[t[s]??null,n[s]??null])]);if(!Dr.has(r)){Dr.size>=1e3&&Dr.clear();let s=Eh(t);if(!s){const o=Vo(e,t),i=xt.find(a=>!rv[a](t[a],o,n[a]));i&&(s=`the ${i} key did not sign this keyring`)}Dr.set(r,s)}return Dr.get(r)}const Lu=e=>xt.map(t=>`${t}:${t==="nostr"?yc(e[t]):t==="ethereum"?e[t].toLowerCase():Se(ls(e[t]).program)}`),bc="lineage/v0",iv=["white","green","black"],$i="names are 1-40 lowercase letters, digits or hyphens (they become domains)",av=/^[a-z0-9](?:[a-z0-9-]{0,38}[a-z0-9])?$/,Ds=e=>typeof e=="string"&&av.test(e),qr=(e,t)=>typeof e=="string"?e.trim().slice(0,t):"";function qo(e){return String(e??"").toLowerCase().normalize("NFKD").replace(/[̀-ͯ]/g,"").replace(/[^a-z0-9]+/g,"-").replace(/^-+|-+$/g,"").slice(0,40).replace(/-+$/,"")}const zo=e=>e.events.filter(t=>t.protocol===bc);function Sn(e,{upTo:t=1/0,pending:n=!1}={}){const r=new Map,s=[],o=[],i=new Map,a=new Map,c=f=>f.status==="active",u=f=>{if(f.keyring&&!f.keyring.retired)for(const d of Lu(f.keyring.keys))a.delete(d)},l=(f,d,h,p)=>{f.keyring&&!f.keyring.retired&&(u(f),f.keyring.retired={cause:d,by:h,beat:p})};for(const f of e){const d=f.status==="confirmed";if(d?f.height>t:!n)continue;const h=f.metadata&&typeof f.metadata=="object"&&!Array.isArray(f.metadata)?f.metadata:{},p={id:f.id,op:typeof h.op=="string"?h.op.slice(0,20):"?",beat:d?f.height:null,pending:!d,meta:h,parent:f.parent??null,ok:!0,why:"",node:null,root:null,also:[]},g=p.parent?r.get(p.parent):null,b=p.beat??"cued",m=x=>{p.ok=!1,p.why=x},E=x=>g?c(g)?"":`the ${x} is ${g.status}`:`the ${x} is not in this lineage`;let y="";switch(p.op){case"found":if(p.parent)m("a holding has no parent");else if(!Ds(h.name))m($i);else if(s.some(x=>c(x)&&x.name===h.name))m(`an active holding is already named ${h.name}`);else{const x=Ru(f,h.name,null,"holding");r.set(x.id,x),s.push(x),p.node=x.id}break;case"birth":{const x=h.kind==="agent"?"agent":"org";if(y=E("parent"))m(y);else if(g.kind==="agent")m("agents do not give birth");else if(!Ds(h.name))m($i);else if(g.children.some(B=>c(r.get(B))&&r.get(B).name===h.name))m(`${g.name} already has an active ${h.name}`);else{const B=Ru(f,h.name,g,x);B.index=g.children.filter(O=>r.get(O).kind===x).length,g.children.push(B.id),r.set(B.id,B),p.node=B.id}break}case"award":{const x=r.get(h.to);(y=E("issuer"))?m(y):g.kind==="agent"?m("agents do not award belts"):!x||x.id===g.id?m("the recipient must be another node in this lineage"):c(x)?!Ds(h.skill)||!iv.includes(h.belt)?m("an award needs a skill name and a belt (white, green or black)"):(x.badges=x.badges.filter(B=>B.skill!==h.skill),x.badges.push({skill:h.skill,belt:h.belt,by:g.id,beat:b,id:f.id}),p.node=x.id):m(`the recipient is ${x.status}`);break}case"decide":(y=E("decider"))?m(y):qr(h.title,140)?(g.decisions.push({title:qr(h.title,140),why:qr(h.why,400),beat:b,id:f.id}),p.node=g.id):m("a decision needs a title");break;case"make":(y=E("maker"))?m(y):Ds(h.name)?g.made.some(x=>i.get(x).name===h.name)?m(`there is already a ${h.name} by ${g.name}`):(i.set(f.id,{id:f.id,name:h.name,note:qr(h.note,280),maker:g.id,beat:b}),g.made.push(f.id),p.node=g.id):m($i);break;case"graduate":{const x=r.get(h.of);if(y=E("parent"))m(y);else if(!x||x.parent!==g.id)m("only its parent can graduate a child");else if(x.kind!=="org")m("only orgs graduate");else if(!c(x))m(`the child is ${x.status}`);else if(x.edge==="adopted")m("already graduated");else{const B=x.root,O=T=>{T.root=x.id;for(const U of T.children)r.get(U).root===B&&O(r.get(U))};x.edge="adopted",x.graduated=b,p.node=x.id,O(x),s.push(x);const C=T=>{l(T,"graduate",x.id,b);for(const U of T.children)r.get(U).edge==="derived"&&C(r.get(U))};C(x)}break}case"close":if(!g)m(p.parent?"that node is not in this lineage":"a close spends the node it closes");else if(!c(g))m(`already ${g.status}`);else{const x=B=>{B.status="closed",B.closed=b,l(B,"close",g.id,b);for(const O of B.children){const C=r.get(O);C.edge==="derived"&&c(C)&&(p.also.push(C.id),x(C))}};x(g),p.node=g.id}break;case"keyring":{if(y=E("node"))m(y);else if(y=ov(g.id,h))m(y);else{const x=Object.fromEntries(xt.map(C=>[C,h[C]])),B=Lu(x),O=B.findIndex(C=>a.has(C)&&a.get(C)!==g.id);if(O>=0)m(`its ${xt[O]} key is already bound to ${r.get(a.get(B[O])).name}`);else{u(g),g.keyring={id:f.id,beat:b,keys:x,retired:null};for(const C of B)a.set(C,g.id);p.node=g.id}}break}default:m("not a lineage/v0 op")}const v=p.node?r.get(p.node).root:null;p.root=(g==null?void 0:g.root)??v,p.roots=[...new Set([p.root,v].filter(Boolean))],o.push(p)}return{nodes:r,roots:s,log:o,items:i,bound:a}}function Ru(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:[],made:[],keyring:null,graduated:null,closed:null}}function cv(e,t){const n=[],r=e.nodes.get(t),s=(o,i,a)=>{const c=o.root!==t;if(n.push({type:"node",node:o,guide:i,path:o.id===t?"●":`${o.index}'`,away:c}),c)return;const u=o.children.map(f=>e.nodes.get(f)),l=[["agents",u.filter(f=>f.kind==="agent")],["orgs",u.filter(f=>f.kind!=="agent")]].filter(([,f])=>f.length);l.forEach(([f,d],h)=>{const p=h===l.length-1,g=a+(p?" ":"│ ");n.push({type:"group",label:f,guide:a+(p?"└─ ":"├─ ")}),d.forEach((b,m)=>{const E=m===d.length-1;s(b,g+(E?"└─ ":"├─ "),g+(E?" ":"│ "))})})};return r&&s(r,"",""),n}function uv(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 Ar(e,t){const n=[];for(let r=e.nodes.get(t);r;r=r.id===r.root?null:e.nodes.get(r.parent))n.unshift(r.name);return n.join(" / ")}function kh(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 “${qr(n.title,140)}” · ${r(e.parent)}`;case"make":return`make ${n.name} · ${r(e.parent)}`;case"keyring":return`keyring · ${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 hn=Se,fv=ae,ca=ut,lv=er,pn="super-testnet-local-v0";class $n{constructor(t){if(!/^[0-9a-f]{64}$/.test(t)||!ke.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=hn(kn.getPublicKey(t)),this.address=Yr.p2tr.fromPubKey(this.pubkey,"regtest"),this.script=["OP_1",this.pubkey]}static create(){return new $n(hn(ke.utils.randomPrivateKey()))}static load(t){if((t==null?void 0:t.network)!==pn||(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 $n(t.secret)}backup(){return{kind:"test-wallet",version:1,network:pn,secret:this.secret}}sign(t,n,r=0){return br.taproot.sign(this.secret,t,r,n?{extension:n}:{}).hex}}const Ms=50*1e8,Zs="0".repeat(64),Hu=e=>hn(xe(new TextEncoder().encode(JSON.stringify(e)))),or=(e,t)=>`${e}:${t}`,We=e=>Be.encode(e,!1).hex,le=(e,t)=>{if(!e)throw new Error(t)},ju=/^5120[0-9a-f]{64}$/,Vs=/^0014[0-9a-f]{40}$/,Sh=64,bt=8,dv=e=>hn(uc(xe(ca(e))));function hv(e,t){const[n,r]=e.vin[t].witness;return ke.verify(n.slice(0,-2),br.segwit.hash(e,t,{pubkey:r,sigflag:1}),r,{lowS:!0,format:"der"})}const _i=(e,...t)=>{const n=xe(new TextEncoder().encode(e));return xe(fv(n,n,...t))},pv=e=>e<253?Uint8Array.of(e):Uint8Array.of(253,e&255,e>>8);function gv(e,t){const[n,r,s]=e.vin[t].witness,o=ca(s),i=ca(r);if(o.length<33||(o.length-33)%32||i.length>65535||!/^20[0-9a-f]{64}ac/.test(r))return!1;const a=_i("TapLeaf",Uint8Array.of(o[0]&254),pv(i.length),i);let c=a;for(let f=33;f=ke.CURVE.n)return!1;const l=ke.ProjectivePoint.fromHex(`02${hn(o.slice(1,33))}`).add(ke.ProjectivePoint.BASE.multiply(u)).toAffine();return`5120${l.x.toString(16).padStart(64,"0")}`!==We(e.vin[t].prevout.scriptPubKey)||Number(l.y&1n)!==(o[0]&1)?!1:kn.verify(n,br.taproot.hash(e,t,{extension:hn(a)}),r.slice(2,66))}class Fo{constructor(t){if(this.blocks=[],this.mempool=[],this.utxos=new Map,this.transactions=new Map,this.imports=[],t){le(t.network===pn&&t.version===1,"Unsupported local chain version/network."),le(Array.isArray(t.blocks)&&Array.isArray(t.mempool)&&Array.isArray(t.imports??[]),"Invalid chain snapshot.");for(const n of t.imports??[])this.importCoin(n);for(const n of t.blocks)this.acceptBlock(structuredClone(n));this.submitPackage(t.mempool)}}snapshot(){return{network:pn,version:1,blocks:structuredClone(this.blocks),mempool:[...this.mempool],...this.imports.length?{imports:structuredClone(this.imports)}:{}}}importCoin({txid:t,vout:n,value:r,script:s}){le(/^[0-9a-f]{64}$/.test(t)&&Number.isSafeInteger(n)&&n>=0&&Number.isSafeInteger(r)&&r>=330&&r<=Ms&&(ju.test(s)||Vs.test(s)),"Invalid imported coin."),le(!this.utxos.has(or(t,n))&&!this.transactions.has(t)&&!this.imported(t,n),"That coin is already in this chain."),this.utxos.set(or(t,n),{txid:t,vout:n,value:r,scriptPubKey:s,height:0,ranges:ef(this.imports.length,r),inscriptions:[]}),this.imports.push({txid:t,vout:n,value:r,script:s})}imported(t,n){const r=this.imports.find(s=>s.txid===t&&s.vout===n);return r?{value:r.value,scriptPubKey:r.script}:null}coins(t){return[...this.utxos.values()].filter(n=>We(n.scriptPubKey)===We(t))}satLocation(t){for(const n of this.utxos.values()){const r=zs(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 b,m,E;le(typeof t=="string"&&t.length<4e4&&/^(?:[a-f0-9]{2})+$/.test(t),"Invalid raw transaction.");const s=ie.decode(t),o=ie.util.getTxid(s);le(!this.transactions.has(o),"Duplicate transaction."),le(s.version===2&&s.locktime===0,"Unsupported transaction version or locktime.");const i=!r&&s.vin.some(y=>{var v;return((v=y.witness)==null?void 0:v.length)===3}),a=r?1:i?2:bt,c=r?Sh:i?2:bt;le(s.vin.length>=1&&s.vin.length<=a&&s.vout.length>=1&&s.vout.length<=c,"Unsupported transaction shape.");let u=0;for(const y of s.vout){const v=Number(y.value);le(Number.isSafeInteger(v)&&v>=330&&v<=Ms,"Invalid output amount.");const x=We(y.scriptPubKey);le(ju.test(x)||Vs.test(x),"Only Taproot and P2WPKH outputs are supported."),u+=v}let l,f=[];const d=s.vin.findIndex(y=>{var v;return((v=y.witness)==null?void 0:v.length)===3}),h=s.vin[d<0?0:d];if(r)le(h.txid===Zs&&h.vout===4294967295&&u===Ms,"Invalid local coinbase."),le(We(h.scriptSig)===Be.encode([new TextEncoder().encode(`${pn}:${n}`)],!1).hex,"Wrong coinbase height."),le(!((b=h.witness)!=null&&b.length),"Unexpected coinbase witness.");else{f=s.vin.map(v=>this.utxos.get(or(v.txid,v.vout))),le(f.every(Boolean),"Input is missing or already spent."),le(new Set(s.vin.map(v=>or(v.txid,v.vout))).size===s.vin.length,"Duplicate input."),s.vin.forEach((v,x)=>{var O,C,T;le(v.sequence==="ffffffff"&&We(v.scriptSig)==="","Unsupported input flags."),v.prevout={value:f[x].value,scriptPubKey:f[x].scriptPubKey};const B=We(f[x].scriptPubKey);if(Vs.test(B)){const[U,H]=v.witness??[];le(x!==d&&((O=v.witness)==null?void 0:O.length)===2,"Unsupported witness."),le(/^30[0-9a-f]{12,140}01$/.test(U)&&/^0[23][0-9a-f]{64}$/.test(H)&&dv(H)===B.slice(4),"P2WPKH spends need a SIGHASH_ALL signature by the key they pay.");return}le(((C=v.witness)==null?void 0:C.length)===1||x===d&&((T=v.witness)==null?void 0:T.length)===3,"Unsupported witness."),le(/^[0-9a-f]{128}$/.test(v.witness[0])||!i&&/^[0-9a-f]{128}83$/.test(v.witness[0]),"Only default 64-byte Schnorr signatures, or SIGHASH_SINGLE|ANYONECANPAY outside reveals, are accepted.")}),le(f.reduce((v,x)=>v+x.value,0)-u===de,"v0 requires a fixed 500 sat fee per transaction.");let y={};if(h.witness.length===3){const v=Qa(h.witness),x=d;if(le(Number(s.vout[x].value)===At,"Invalid reveal postage."),le(We(s.vout[x].scriptPubKey)===`5120${v.pubkey}`,"Reveal must return to its signing wallet."),v.parent){const B=d===0?1:0,O=f[B];le((m=O==null?void 0:O.inscriptions)==null?void 0:m.some(C=>C.id===v.parent),"Referenced parent inscription must actually be spent."),le(s.vout.length===2&&Number(s.vout[B].value)===O.value&&We(O.scriptPubKey)===`5120${v.pubkey}`&&We(s.vout[B].scriptPubKey)===We(O.scriptPubKey),"Parent must be owned and preserved in the same wallet.")}else s.vin.length===2&&(le(d===1&&((E=f[0].inscriptions)==null?void 0:E.length)&&v.pointer!==void 0,"Reinscription spend requires correct tag and owned sat."),le(Number(s.vout[0].value)===f[0].value&&We(s.vout[0].scriptPubKey)===We(f[0].scriptPubKey)&&We(f[0].scriptPubKey)===`5120${v.pubkey}`,"Reinscription sat must be returned to owner."));y={pubkey:v.pubkey},l={id:`${o}i0`,txid:o,commitTxid:h.txid,text:v.text,bytes:Array.from(v.bytes),contentType:v.contentType,parent:v.parent,delegate:v.delegate,pointer:v.pointer,metaprotocol:v.metaprotocol,metadata:v.metadata,height:n,value:At}}s.vin.forEach((v,x)=>{let B=!1;try{B=Vs.test(We(f[x].scriptPubKey))?hv(s,x):x===d?gv(s,x)||br.taproot.verify(s,x,y):br.taproot.verify(s,x,{})}catch{}le(B,"Invalid signature or Taproot commitment.")})}const p=rf(s,f,n,r),g=f.flatMap(y=>y.inscriptions??[]);if(l){const y=BigInt(l.pointer??0),v=y{var B;return((B=x.inscription)==null?void 0:B.sat)===l.sat}).length,g.push(l)}return le(g.every(y=>p.some(v=>zs(v,y.sat)!==null)),"Local lab protects inscription sats from fee loss."),r||s.vin.forEach(y=>this.utxos.delete(or(y.txid,y.vout))),s.vout.forEach((y,v)=>{const x=g.filter(B=>zs(p[v],B.sat)!==null);this.utxos.set(or(o,v),{txid:o,vout:v,value:Number(y.value),scriptPubKey:y.scriptPubKey,height:n,ranges:p[v],inscriptions:x,...x.length?{inscription:x[0]}:{}})}),this.transactions.set(o,{txid:o,raw:t,height:n,coinbase:r,tx:s,...l?{inscription:l}:{}}),o}submitPackage(t){le(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;le(t.height===this.blocks.length+1&&t.previous===(((i=this.blocks.at(-1))==null?void 0:i.hash)??Zs),"Invalid block ancestry."),le(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;le(Hu(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([je(Ms,t)])}mineTo(t){var a;const n=new Fo({...this.snapshot(),mempool:[]}),r=this.blocks.length+1,s=ie.create({vin:[{txid:Zs,vout:4294967295,scriptSig:[new TextEncoder().encode(`${pn}:${r}`)]}],vout:t}),o={height:r,previous:((a=this.blocks.at(-1))==null?void 0:a.hash)??Zs,time:Date.now(),raws:[ie.encode(s).hex,...this.mempool]},i={...o,hash:Hu(o)};return n.acceptBlock(i),Object.assign(this,n),i}}const $h="lineage-claim",ua=330,To=e=>Be.encode(e,!1).hex,Ku=e=>({txid:e.txid,vout:e.vout,value:e.value,script:To(e.scriptPubKey)}),Ai=/^[0-9a-f]{64}$/,mv=/^5120[0-9a-f]{64}$/;function Wo(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 _h(e){return ie.create({vin:[Zt(e.holder.txid,e.holder.vout,e.holder.value,e.holder.script),Zt(e.payer.txid,e.payer.vout,e.payer.value,e.payer.script)],vout:[je(e.holder.value,["OP_1",e.to]),je(e.payer.value-de,["OP_1",e.to])]})}function yv(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=Wo(e,t);if(!s)throw new Error("That inscription is not in an unspent output.");if(To(s.scriptPubKey)===To(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>=de+ua});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:$h,version:1,inscription:t,carried:s.inscriptions.map(c=>c.id),holder:Ku(s),payer:Ku(o),to:n.pubkey,at:r},a=_h(i);return i.txid=ie.util.getTxid(a),i.sig=n.sign(a,void 0,1),i}function bv(e,t,n){const r=xv(t);if((n==null?void 0:n.kind)!=="test-wallet")throw new Error("Countersigning needs a local test wallet.");if(To(n.script)!==r.holder.script)throw new Error("Only the current holder can countersign.");if(wv(e,r)!=="open")throw new Error("This claim is stale: an input it spends was already spent.");const s=_h(r);return s.vin[1].witness=[r.sig],s.vin[0].witness=[n.sign(s,void 0,0)],e.submitPackage([ie.encode(s).hex]),ie.util.getTxid(s)}function wv(e,t){return e.utxos.has(`${t.holder.txid}:${t.holder.vout}`)&&e.utxos.has(`${t.payer.txid}:${t.payer.vout}`)?"open":"stale"}function xv(e){const t=n=>n&&Ai.test(n.txid)&&Number.isSafeInteger(n.vout)&&n.vout>=0&&Number.isSafeInteger(n.value)&&n.value>=ua&&mv.test(n.script);if((e==null?void 0:e.kind)!==$h||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=Du);const i=new Uint8Array(o*s),a=En.create(e,t),c=a._cloneInto(),u=new Uint8Array(a.outputLen);for(let l=0;lEv(e,vv(e,t,n),r,s);/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */const un=BigInt(0),Le=BigInt(1),Ti=BigInt(2),Sv=BigInt(8);function $v(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 _v(e,t={}){const n=Ld("edwards",e,t,t.FpFnLE),{Fp:r,Fn:s}=n;let o=n.CURVE;const{h:i}=o;Cr(t,{},{uvRatio:"function"});const a=Ti<r.create(b),u=t.uvRatio||((b,m)=>{try{return{isValid:!0,value:r.sqrt(r.div(b,m))}}catch{return{isValid:!1,value:un}}});if(!$v(r,o,o.Gx,o.Gy))throw new Error("bad curve params: generator point");function l(b,m,E=!1){const y=E?Le:un;return us("coordinate "+b,m,y,a),m}function f(b){if(!(b instanceof p))throw new Error("ExtendedPoint expected")}const d=wo((b,m)=>{const{X:E,Y:y,Z:v}=b,x=b.is0();m==null&&(m=x?Sv:r.inv(v));const B=c(E*m),O=c(y*m),C=r.mul(v,m);if(x)return{x:un,y:Le};if(C!==Le)throw new Error("invZ was invalid");return{x:B,y:O}}),h=wo(b=>{const{a:m,d:E}=o;if(b.is0())throw new Error("bad point: ZERO");const{X:y,Y:v,Z:x,T:B}=b,O=c(y*y),C=c(v*v),T=c(x*x),U=c(T*T),H=c(O*m),K=c(T*c(H+C)),k=c(U+c(E*c(O*C)));if(K!==k)throw new Error("bad point: equation left != right (1)");const $=c(y*v),w=c(x*B);if($!==w)throw new Error("bad point: equation left != right (2)");return!0});class p{constructor(m,E,y,v){this.X=l("x",m),this.Y=l("y",E),this.Z=l("z",y,!0),this.T=l("t",v),Object.freeze(this)}static CURVE(){return o}static fromAffine(m){if(m instanceof p)throw new Error("extended point not allowed");const{x:E,y}=m||{};return l("x",E),l("y",y),new p(E,y,Le,c(E*y))}static fromBytes(m,E=!1){const y=r.BYTES,{a:v,d:x}=o;m=pu(gt(m,y,"point")),zn(E,"zip215");const B=pu(m),O=m[y-1];B[y-1]=O&-129;const C=Fn(B),T=E?a:r.ORDER;us("point.y",C,un,T);const U=c(C*C),H=c(U-Le),K=c(x*U-v);let{isValid:k,value:$}=u(H,K);if(!k)throw new Error("bad point: invalid y coordinate");const w=($&Le)===Le,_=(O&128)!==0;if(!E&&$===un&&_)throw new Error("bad point: x=0 and x_0=1");return _!==w&&($=c(-$)),p.fromAffine({x:$,y:C})}static fromHex(m,E=!1){return p.fromBytes(me("point",m),E)}get x(){return this.toAffine().x}get y(){return this.toAffine().y}precompute(m=8,E=!0){return g.createCache(this,m),E||this.multiply(Ti),this}assertValidity(){h(this)}equals(m){f(m);const{X:E,Y:y,Z:v}=this,{X:x,Y:B,Z:O}=m,C=c(E*O),T=c(x*v),U=c(y*O),H=c(B*v);return C===T&&U===H}is0(){return this.equals(p.ZERO)}negate(){return new p(c(-this.X),this.Y,this.Z,c(-this.T))}double(){const{a:m}=o,{X:E,Y:y,Z:v}=this,x=c(E*E),B=c(y*y),O=c(Ti*c(v*v)),C=c(m*x),T=E+y,U=c(c(T*T)-x-B),H=C+B,K=H-O,k=C-B,$=c(U*K),w=c(H*k),_=c(U*k),P=c(K*H);return new p($,w,P,_)}add(m){f(m);const{a:E,d:y}=o,{X:v,Y:x,Z:B,T:O}=this,{X:C,Y:T,Z:U,T:H}=m,K=c(v*C),k=c(x*T),$=c(O*y*H),w=c(B*U),_=c((v+x)*(C+T)-K-k),P=w-$,L=w+$,N=c(k-E*K),j=c(_*P),M=c(L*N),F=c(_*N),ue=c(P*L);return new p(j,M,ue,F)}subtract(m){return this.add(m.negate())}multiply(m){if(!s.isValidNot0(m))throw new Error("invalid scalar: expected 1 <= sc < curve.n");const{p:E,f:y}=g.cached(this,m,v=>Hn(p,v));return Hn(p,[E,y])[0]}multiplyUnsafe(m,E=p.ZERO){if(!s.isValid(m))throw new Error("invalid scalar: expected 0 <= sc < curve.n");return m===un?p.ZERO:this.is0()||m===Le?this:g.unsafe(this,m,y=>Hn(p,y),E)}isSmallOrder(){return this.multiplyUnsafe(i).is0()}isTorsionFree(){return g.unsafe(this,o.n).is0()}toAffine(m){return d(this,m)}clearCofactor(){return i===Le?this:this.multiplyUnsafe(i)}toBytes(){const{x:m,y:E}=this.toAffine(),y=r.toBytes(E);return y[y.length-1]|=m&Le?128:0,y}toHex(){return Se(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(m){return Hn(p,m)}static msm(m,E){return Nd(p,s,m,E)}_setWindowSize(m){this.precompute(m)}toRawBytes(){return this.toBytes()}}p.BASE=new p(o.Gx,o.Gy,Le,c(o.Gx*o.Gy)),p.ZERO=new p(un,Le,Le,un),p.Fp=r,p.Fn=s;const g=new Ud(p,s.BITS);return p.BASE.precompute(8),p}function Av(e,t,n={}){if(typeof t!="function")throw new Error('"hash" function param is required');Cr(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||Qn,c=n.adjustScalarBytes||(T=>T),u=n.domain||((T,U,H)=>{if(zn(H,"phflag"),U.length||H)throw new Error("Contexts/pre-hash are not supported");return T});function l(T){return i.create(Fn(T))}function f(T){const U=y.secretKey;T=me("private key",T,U);const H=me("hashed private key",t(T),2*U),K=c(H.slice(0,U)),k=H.slice(U,2*U),$=l(K);return{head:K,prefix:k,scalar:$}}function d(T){const{head:U,prefix:H,scalar:K}=f(T),k=s.multiply(K),$=k.toBytes();return{head:U,prefix:H,scalar:K,point:k,pointBytes:$}}function h(T){return d(T).pointBytes}function p(T=Uint8Array.of(),...U){const H=ae(...U);return l(t(u(H,me("context",T),!!r)))}function g(T,U,H={}){T=me("message",T),r&&(T=r(T));const{prefix:K,scalar:k,pointBytes:$}=d(U),w=p(H.context,K,T),_=s.multiply(w).toBytes(),P=p(H.context,_,$,T),L=i.create(w+P*k);if(!i.isValid(L))throw new Error("sign failed: invalid s");const N=ae(_,i.toBytes(L));return gt(N,y.signature,"result")}const b={zip215:!0};function m(T,U,H,K=b){const{context:k,zip215:$}=K,w=y.signature;T=me("signature",T,w),U=me("message",U),H=me("publicKey",H,y.publicKey),$!==void 0&&zn($,"zip215"),r&&(U=r(U));const _=w/2,P=T.subarray(0,_),L=Fn(T.subarray(_,w));let N,j,M;try{N=e.fromBytes(H,$),j=e.fromBytes(P,$),M=s.multiplyUnsafe(L)}catch{return!1}if(!$&&N.isSmallOrder())return!1;const F=p(k,j.toBytes(),N.toBytes(),U);return j.add(N.multiplyUnsafe(F)).subtract(M).clearCofactor().is0()}const E=o.BYTES,y={secretKey:E,publicKey:E,signature:2*E,seed:E};function v(T=a(y.seed)){return gt(T,y.seed,"seed")}function x(T){const U=C.randomSecretKey(T);return{secretKey:U,publicKey:h(U)}}function B(T){return ws(T)&&T.length===i.BYTES}function O(T,U){try{return!!e.fromBytes(T,U)}catch{return!1}}const C={getExtendedPublicKey:d,randomSecretKey:v,isValidSecretKey:B,isValidPublicKey:O,toMontgomery(T){const{y:U}=e.fromBytes(T),H=y.publicKey,K=H===32;if(!K&&H!==57)throw new Error("only defined for 25519 and 448");const k=K?o.div(Le+U,Le-U):o.div(U-Le,U+Le);return o.toBytes(k)},toMontgomerySecret(T){const U=y.secretKey;gt(T,U);const H=t(T.subarray(0,U));return c(H).subarray(0,U)},randomPrivateKey:v,precompute(T=8,U=e.BASE){return U.precompute(T,!1)}};return Object.freeze({keygen:x,getPublicKey:h,sign:g,verify:m,utils:C,Point:e,lengths:y})}function Bv(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=tr(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 Tv(e,t){const n=t.Point;return Object.assign({},t,{ExtendedPoint:n,CURVE:e,nBitLength:n.Fn.BITS,nByteLength:n.Fn.BYTES})}function Iv(e){const{CURVE:t,curveOpts:n,hash:r,eddsaOpts:s}=Bv(e),o=_v(t,n),i=Av(o,r,s);return Tv(e,i)}/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */const Mr=BigInt(0),ir=BigInt(1),qs=BigInt(2);function Ov(e){return Cr(e,{adjustScalarBytes:"function",powPminus2:"function"}),Object.freeze({...e})}function Cv(e){const t=Ov(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||Qn,u=a?255:448,l=a?32:56,f=BigInt(a?9:5),d=BigInt(a?121665:39081),h=a?qs**BigInt(254):qs**BigInt(447),p=a?BigInt(8)*qs**BigInt(251)-ir:BigInt(4)*qs**BigInt(445)-ir,g=h+p+ir,b=k=>Ee(k,n),m=E(f);function E(k){return rc(b(k),l)}function y(k){const $=me("u coordinate",k,l);return a&&($[31]&=127),b(Fn($))}function v(k){return Fn(s(me("scalar",k,l)))}function x(k,$){const w=C(y($),v(k));if(w===Mr)throw new Error("invalid private or public key received");return E(w)}function B(k){return x(k,m)}function O(k,$,w){const _=b(k*($-w));return $=b($-_),w=b(w+_),{x_2:$,x_3:w}}function C(k,$){us("u",k,Mr,n),us("scalar",$,h,g);const w=$,_=k;let P=ir,L=Mr,N=k,j=ir,M=Mr;for(let ue=BigInt(u-1);ue>=Mr;ue--){const oe=w>>ue&ir;M^=oe,{x_2:P,x_3:N}=O(M,P,N),{x_2:L,x_3:j}=O(M,L,j),M=oe;const Q=P+L,he=b(Q*Q),pe=P-L,Te=b(pe*pe),fe=he-Te,we=N+j,Nt=N-j,rt=b(Nt*Q),Ke=b(we*pe),Lt=rt+Ke,Rr=rt-Ke;N=b(Lt*Lt),j=b(_*b(Rr*Rr)),P=b(he*Te),L=b(fe*(he+b(d*fe)))}({x_2:P,x_3:N}=O(M,P,N)),{x_2:L,x_3:j}=O(M,L,j);const F=o(L);return b(P*F)}const T={secretKey:l,publicKey:l,seed:l},U=(k=c(l))=>(Re(k,T.seed),k);function H(k){const $=U(k);return{secretKey:$,publicKey:B($)}}return{keygen:H,getSharedSecret:(k,$)=>x(k,$),getPublicKey:k=>B(k),scalarMult:x,scalarMultBase:B,utils:{randomSecretKey:U,randomPrivateKey:U},GuBytes:m.slice(),lengths:T}}/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */const Pv=BigInt(1),Mu=BigInt(2),Uv=BigInt(3),Nv=BigInt(5),Lv=BigInt(8),wc=BigInt("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffed"),Ah={p:wc,n:BigInt("0x1000000000000000000000000000000014def9dea2f79cd65812631a5cf5d3ed"),h:Lv,a:BigInt("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffec"),d:BigInt("0x52036cee2b6ffe738cc740797779e89800700a4d4141d8ab75eb4dca135978a3"),Gx:BigInt("0x216936d3cd6e53fec0a4e231fdd6dc5c692cc7609525a7b2c9562d608f25d51a"),Gy:BigInt("0x6666666666666666666666666666666666666666666666666666666666666658")};function Bh(e){const t=BigInt(10),n=BigInt(20),r=BigInt(40),s=BigInt(80),o=wc,a=e*e%o*e%o,c=_e(a,Mu,o)*a%o,u=_e(c,Pv,o)*e%o,l=_e(u,Nv,o)*u%o,f=_e(l,t,o)*l%o,d=_e(f,n,o)*f%o,h=_e(d,r,o)*d%o,p=_e(h,s,o)*h%o,g=_e(p,s,o)*h%o,b=_e(g,t,o)*l%o;return{pow_p_5_8:_e(b,Mu,o)*e%o,b2:a}}function Th(e){return e[0]&=248,e[31]&=127,e[31]|=64,e}const Zu=BigInt("19681161376707505956807079304988542015446066515923890162744021073123829784752");function Rv(e,t){const n=wc,r=Ee(t*t*t,n),s=Ee(r*r*t,n),o=Bh(e*s).pow_p_5_8;let i=Ee(e*r*o,n);const a=Ee(t*i*i,n),c=i,u=Ee(i*Zu,n),l=a===e,f=a===Ee(-e,n),d=a===Ee(-e*Zu,n);return l&&(i=c),(f||d)&&(i=u),Hx(i,n)&&(i=Ee(-i,n)),{isValid:l||f,value:i}}const Ih=tr(Ah.p,{isLE:!0}),Hv={...Ah,Fp:Ih,hash:cs,adjustScalarBytes:Th,uvRatio:Rv},Go=Iv(Hv),Oh=(()=>{const e=Ih.ORDER;return Cv({P:e,type:"x25519",powPminus2:t=>{const{pow_p_5_8:n,b2:r}=Bh(t);return Ee(_e(n,Uv,e)*r,e)},adjustScalarBytes:Th})})(),jv=Ue("lineage/v0"),Ot=(e,t)=>kv(xe,e,jv,Ue(t),32),Yo=e=>{const t=Uint8Array.from(e);return t[0]&=248,t[31]&=127,t[31]|=64,t},Ch=e=>{const t=new Uint8Array(4);return new DataView(t.buffer).setUint32(0,e),t},lt=e=>ae(Ch(e.length),e),xc=e=>ae(lt(Ue("ssh-ed25519")),lt(e)),fa=(e,t)=>`ssh-ed25519 ${it.encode(xc(e))}${t?` ${t}`:""}`,la=e=>`SHA256:${it.encode(xe(xc(e))).replace(/=+$/,"")}`;function Kv(e){const t=ut(e),n=r=>Go.getPublicKey(Ot(t,r));return{ssh:n("ssh"),git:n("git"),dkim:n("dkim"),wg:Oh.getPublicKey(Yo(Ot(t,"wg")))}}function Dv(e){const t=n=>Go.getPublicKey(Ot(e,n));return{"ssh-ca":t("node/ssh-ca"),mtls:t("node/mtls"),noise:Oh.getPublicKey(Yo(Ot(e,"node/noise")))}}function Mv(e,t,n,r){return[["ssh",la(e.ssh),fa(e.ssh,t)],["git",la(e.git),`${t} namespaces="git" ${fa(e.git,t)}`],["dkim",`${n}._domainkey.${r}`,`${n}._domainkey.${r}. IN TXT "v=DKIM1; k=ed25519; p=${it.encode(e.dkim)}"`],["wg",it.encode(e.wg),`[Peer] -# ${t} -PublicKey = ${it.encode(e.wg)}`]]}function Zv(e,t){return[["ssh-ca",la(e["ssh-ca"]),fa(e["ssh-ca"],`lineage-ca@${t}`)],["mtls",it.encode(e.mtls),null],["noise",`mkey:${Se(e.noise)}`,null]]}const Vv=ut("302e020100300506032b657004220420");function Ph(e,t,n){const r=xe(e).slice(0,4);let s=ae(r,r,lt(Ue("ssh-ed25519")),lt(t),lt(ae(e,t)),lt(Ue(n)));s=ae(s,new Uint8Array((8-s.length%8)%8).map((i,a)=>a+1));const o=ae(Ue("openssh-key-v1\0"),lt(Ue("none")),lt(Ue("none")),lt(new Uint8Array(0)),Ch(1),lt(xc(t)),lt(s));return`-----BEGIN OPENSSH PRIVATE KEY----- -${it.encode(o).match(/.{1,70}/g).join(` -`)} ------END OPENSSH PRIVATE KEY----- -`}const qv=(e,t)=>`-----BEGIN ${e}----- -${it.encode(t).match(/.{1,64}/g).join(` -`)} ------END ${e}----- -`;function zv(e,t){const n=ut(e),r=s=>{const o=Ot(n,s);return Ph(o,Go.getPublicKey(o),t)};return[["ssh","OpenSSH private key",r("ssh")],["git","OpenSSH private key",r("git")],["dkim","Ed25519 private key (base64)",it.encode(Ot(n,"dkim"))],["wg","Interface entry",`[Interface] -PrivateKey = ${it.encode(Yo(Ot(n,"wg")))}`]]}function Fv(e,t){const n=Ot(e,"node/ssh-ca");return[["ssh-ca","OpenSSH private key",Ph(n,Go.getPublicKey(n),`lineage-ca@${t}`)],["mtls","Private key (PKCS#8 PEM)",qv("PRIVATE KEY",ae(Vv,Ot(e,"node/mtls")))],["noise","noise_private.key",`privkey:${Se(Yo(Ot(e,"node/noise")))}`]]}const Wv=["bip86","tapkey","wallet"],vc=()=>({scheme:"bip86",roots:{},adopted:{}}),Gv=e=>Ro.getPubKey(e)[0];function Uh(e,t,n){return e.scheme==="wallet"?aa(t,n):Ro.getSecKey(e.scheme==="tapkey"?Zo(t,n):aa(t,n))[0]}const Nh=(e,t)=>e.scheme==="tapkey"?Ye.nostr(t):Ye.wallet(t),Yv=(e,t)=>new $n(Uh(e,t,0)),Ce=e=>Be.encode(e,!1).hex;function zt(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=zt(e,t,s);return i&&{...i,account:n.index+1}}if(n.edge==="adopted")return r(e.adopted[n.id]);const o=zt(e,t,s);return o&&{mnemonic:V2(o.mnemonic,n.index),account:0,origin:o.origin,steps:[...o.steps,`${n.index}'`]}}const Ii=new Map;function Oe(e,t,n){const r=zt(e,t,n);if(!r)return null;const s=`${e.scheme}|${r.mnemonic}|${r.account}`;if(!Ii.has(s)){const{npub:u,pubkey:l}=z2(r.mnemonic,r.account);Ii.set(s,{wallet:new $n(Uh(e,r.mnemonic,r.account)),npub:u,pubkey:l})}const{wallet:o,npub:i,pubkey:a}=Ii.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} · ${Nh(e,r.account)}`}}function Ec(e,t,n){const r=zt(e,t,n);if(!r)return null;const s=Oe(e,t,n),o=dh(r.mnemonic,r.account);return{taproot:{address:s.wallet.address,path:Nh(e,r.account)},segwit:{address:Yr.p2wpkh.fromPubKey(o,"regtest"),path:Ye.segwit(r.account)},tapkey:{address:Yr.p2tr.fromPubKey(Gv(s.pubkey),"regtest"),path:Ye.nostr(r.account)},npub:{address:s.npub,path:Ye.nostr(r.account)},ethereum:{address:q2(r.mnemonic,r.account),path:Ye.ethereum(r.account)}}}function Xv(e,t,n){const r=zt(e,t,n);if(!r)return null;const s=Oe(e,t,n),o=Ec(e,t,n),{mnemonic:i,account:a}=r;return{keys:{taproot:o.taproot.address,segwit:o.segwit.address,nostr:o.npub.address,ethereum:o.ethereum.address},secrets:{taproot:s.wallet.secret,segwit:pc(i,a),nostr:Zo(i,a),ethereum:gh(i,a)}}}function kc(e,t,n){const r=Wo(e.chain,n);if(!r)return null;const s=Ce(r.scriptPubKey),o=t.nodes.get(n),i=Oe(e.keys,t,o),a=o&&Oe(e.keys,t,t.nodes.get(o.parent));return i&&Ce(i.wallet.script)===s?{wallet:i.wallet,who:"own"}:e.wallet&&Ce(e.wallet.script)===s?{wallet:e.wallet,who:"lab"}:a&&Ce(a.wallet.script)===s?{wallet:a.wallet,who:"parent"}:{wallet:null,who:"other",script:s}}function ks(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(...ks(e,s))}return r}function da(e,t){const n=[];for(let r=t;r;r=e.nodes.get(r.parent))n.push(r.name);return n.join(".")}function Jv(e,t,n){const r=zt(e,t,n);if(!r)return null;if(n.kind!=="agent")return Zv(Dv(hc(r.mnemonic)),da(t,n));const s=da(t,t.nodes.get(n.parent));return Mv(Kv(Zo(r.mnemonic,r.account)),`${n.name}@${s}`,n.name,s)}const Qv=sh(xe),Zr=(e,t=239)=>Qv.encode(ae(Uint8Array.of(t),ut(e),Uint8Array.of(1))),eE=e=>Gn.encode("nsec",Gn.toWords(ut(e))),tE="0123456789()[],'/*abcdefgh@:$%{}IJKLMNOPQRSTUVWXYZ&+-.;<=>?!^_|~ijklmnopqrstuvwxyzABCDEFGH`#\"\\ ",nE=[0xf5dee51989n,0xa9fdca3312n,0x1bab10e32dn,0x3706b1677an,0x644d626ffdn];function Oi(e){const t=(i,a)=>{const c=i>>35n;return i=(i&0x7ffffffffn)<<5n^BigInt(a),nE.forEach((u,l)=>{c>>BigInt(l)&1n&&(i^=u)}),i};let n=1n,r=0,s=0;for(const i of e){const a=tE.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 rE(e,t,n){const r=zt(e,t,n);if(!r)return null;const s=Zo(r.mnemonic,r.account),o=aa(r.mnemonic,r.account),i={bip86:`tr(${Zr(o)})`,tapkey:`tr(${Zr(s)})`,wallet:`rawtr(${Zr(o)})`}[e.scheme],a=n.kind==="agent",c=da(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",eE(s)],["taproot","descriptor",Oi(i)],["segwit","descriptor",Oi(`wpkh(${Zr(pc(r.mnemonic,r.account))})`)],["tapkey","descriptor",Oi(`tr(${Zr(s)})`)],["ethereum","private key",`0x${gh(r.mnemonic,r.account)}`]],leaves:a?zv(s,`${n.name}@${c}`):Fv(hc(r.mnemonic),c)}}const ds=1e8,nt=50*ds,Ne=330,Lh=e=>(e/ds).toFixed(8).replace(/\.?0+$/,""),ce=e=>`${Lh(e)} tBTC`;function Sc(e){if(e<1e6)return ce(e);const t=Math.round(e/1e6)*1e6;return`${t===e?"":"≈"}${ce(t)}`}function $c(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)*ds+Number((t[2]??"").padEnd(8,"0"))}class Rh{constructor(t,n,r){this.secret=t,this.pubkey=n,this.path=r,this.address=Yr.p2wpkh.fromPubKey(n,"regtest"),this.script=Yr.toScriptPubKey(this.address)}sign(t,n){return[br.segwit.sign(this.secret,t,n,{pubkey:this.pubkey}).hex,this.pubkey]}}const Ci=new Map;function $e(e,t,n){const r=zt(e,t,n);if(!r)return null;const s=`${r.mnemonic}|${r.account}`;return Ci.has(s)||Ci.set(s,new Rh(pc(r.mnemonic,r.account),dh(r.mnemonic,r.account),Ye.segwit(r.account))),Ci.get(s)}function sE(e,t,n){var s;const r=n?t.nodes.get(n):null;return r&&r.root===r.id&&r.status==="active"?((s=$e(e,t,r))==null?void 0:s.script)??null:null}const dr=(e,t)=>{var n,r;return((r=(n=e.mining)==null?void 0:n.rigs)==null?void 0:r[t])??1};function _c(e,t){var n;return((n=e.mining)==null?void 0:n.rule)==="none"?[]:t.roots.filter(r=>r.status==="active"&&dr(e,r.id)>0&&$e(e.keys,t,r)).slice(0,Sh)}function Hh(e,t,n){var i,a;if(((i=e.mining)==null?void 0:i.rule)==="none")return null;if(((a=e.mining)==null?void 0:a.rule)==="last"){const c=sE(e.keys,t,n);return c?[{script:c,value:nt}]:null}const r=_c(e,t),s=r.reduce((c,u)=>c+dr(e,u.id),0);let o=nt;return r.length?r.map((c,u)=>{const l=u===r.length-1?o:Math.floor(nt*dr(e,c.id)/s);return o-=l,{script:$e(e.keys,t,c).script,value:l}}):null}function hs(e,t,n=bt){const r=t+de,s=u=>u===r||u-r>=Ne&&u-r<=nt,o=[...e].sort((u,l)=>u.value-l.value),i=o.find(u=>s(u.value));if(i||n<2)return i?[i]:null;let a=null;for(let u=0;ue.reduce((t,n)=>t+n.value,0);function Bc(e,t=bt){let n=0,r=-de;for(const s of e.map(o=>o.value).sort((o,i)=>i-o).slice(0,t)){r+=s;const o=r<=nt?r:r-nt>=Ne?nt:r-Ne;o>=Ne&&r-o<=nt&&(n=Math.max(n,o))}return n}function jh(e,t,n,r=bt,s="send"){const o=Ac(t),i=n+de,a=Bc(t,r),c=`${s[0].toUpperCase()}${s.slice(1)}`;if(od.value).sort((d,h)=>h-d),l=u.slice(0,r).map((d,h)=>u.slice(0,h+1).reduce((p,g)=>p+g,0)),f=Math.min(...[...u,...u.flatMap((d,h)=>u.slice(h+1).map(p=>d+p)),...l].filter(d=>d>=i));return Number.isFinite(f)&&f-inew Set((e.offers??[]).flatMap(t=>t.payers.map(n=>`${n.txid}:${n.vout}`))),Dh=(e,t)=>e.chain.coins(t.script).filter(n=>{var r;return!((r=n.inscriptions)!=null&&r.length)}),Mh=(e,t,n=bt)=>!!hs(e,t,n),Zh=(e,t,n)=>Mh(Dh(e,t),n);function Tc(e,t,n,r,s="This node",o="send"){const i=Dh(e,t),a=Kh(e),c=hs(i.filter(d=>!a.has(`${d.txid}:${d.vout}`)),r)??hs(i,r);if(!c)throw new Error(jh(s,i,r,bt,o));const u=Ac(c)-r-de,l=ie.create({vin:c.map(d=>Zt(d.txid,d.vout,d.value,d.scriptPubKey)),vout:[je(r,n),...u?[je(u,t.script)]:[]]});c.forEach((d,h)=>{l.vin[h].witness=t instanceof Rh?t.sign(l,h):[t.sign(l,void 0,h)]});const f=ie.encode(l).hex;return e.chain.submitPackage([f]),ie.util.getTxid(f)}function Vh(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=$e(e.keys,t,o),c=$e(e.keys,t,i);if(!a||!c)throw new Error("A holding that predates lab keys has no SegWit addresses.");if(!Number.isSafeInteger(s)||snt)throw new Error("Send at most 50 test BTC at a time: no output on this chain is bigger than one block reward.");return Tc(e,a,c.script,s,o.name)}function oE(e,t,n){if(!t||!n||Ce(t.script)===Ce(n.script))return 0;let r=0;for(const s of e.chain.coins(t.script)){if(s.value-de[t,...t.log.flatMap((n,r)=>n.ok&&n.op==="graduate"?[Sn(e.slice(0,r),{pending:!0})]:[])];function qh(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 iE=(e,t,n)=>qh(Ic(t,n),(r,s)=>{const o=$e(e,r,s);return o&&Ce(o.script)}),Pi=new Map,aE=(e,t,n)=>qh(Ic(t,n),(r,s)=>{const o=zt(e,r,s),i=o&&`${e.scheme}|${o.mnemonic}|${o.account}`;return i&&!Pi.has(i)&&Pi.set(i,Ce(Oe(e,r,s).wallet.script)),i?Pi.get(i):null}),Oc=(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 cE(e,t,n,r){for(const s of Ic(t,n))for(const o of s.nodes.values()){const i=Oe(e,s,o);if(i&&Ce(i.wallet.script)===r)return{node:o.id,wallet:i.wallet}}return null}function uE(e,t,n=new Map,r=new Map){var a;const s=[],o=c=>t.get(Ce(c))??null,i=c=>c.reduce((u,l)=>u+l.value,0);for(const{txid:c,tx:u,height:l,coinbase:f}of e.transactions.values()){const d=u.vout.map(v=>({script:Ce(v.scriptPubKey),node:o(v.scriptPubKey),value:Number(v.value)}));if(f){d.forEach((v,x)=>{v.node&&s.push({kind:"mine",key:`${c}:${x}`,txid:c,beat:l,from:null,to:v.node,amount:v.value,fee:0,change:0})});continue}const h=u.vin.map(v=>{var B,O;const x=((B=e.transactions.get(v.txid))==null?void 0:B.tx.vout[v.vout])??((O=e.imported)==null?void 0:O.call(e,v.txid,v.vout));return x?{node:o(x.scriptPubKey),value:Number(x.value)}:null}),p=r.get(c);if(p&&h.length>1&&h[0]&&h.slice(1).every(v=>(v==null?void 0:v.node)===p.buyer)){s.push({kind:"deal",key:c,txid:c,beat:l,from:p.buyer,to:p.seller,amount:p.price,item:p.item,fee:i(h)-i(d),change:i(d.filter(v=>v.node===p.buyer))});continue}if(h.every(v=>v&&!v.node)){const v=d.filter(x=>x.node);v.length&&s.push({kind:"fund",key:c,txid:c,beat:l,from:null,to:v[0].node,amount:v[0].value,fee:i(h)-i(d),change:i(d.filter(x=>!x.node))});continue}const g=(a=h[0])==null?void 0:a.node;if(!g||!h.every(v=>(v==null?void 0:v.node)===g))continue;const b=d.filter(v=>v.node!==g),m=d.filter(v=>v.node===g),E=i(h)-i(d),y={key:c,txid:c,beat:l,from:g,fee:E};b.length&&b.every(v=>n.get(v.script)===g)?s.push({...y,kind:"gas",to:g,amount:i(b),change:i(m)}):b.length?s.push({...y,kind:"pay",to:b[0].node,amount:b[0].value,change:i(m)}):s.push({...y,kind:"move",to:g,amount:i(m),change:0})}return s}function ha(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(Ce(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 pa="lineage-offer",Vu=/^[0-9a-f]{64}$/,Ui=/^[0-9a-f]{64}i0$/,qu=/^5120[0-9a-f]{64}$/,Ni=/^0014[0-9a-f]{40}$/,zu=e=>({txid:e.txid,vout:e.vout,value:e.value,script:Ce(e.scriptPubKey)}),Fu=(e,t)=>!e.utxos.has(`${t.txid}:${t.vout}`),zh=e=>{const t=zo(new bs(e.chain));return{events:t,state:Sn(t,{pending:!0})}};function Fh(e){return ie.create({vin:[e.holder,...e.payers].map(t=>Zt(t.txid,t.vout,t.value,t.script)),vout:[je(e.holder.value,e.to),...e.price?[je(e.price,e.pay)]:[],...e.change?[je(e.change,e.back)]:[]]})}function Cc(e,t,n,r){const s=Wo(e.chain,r),o=s&&cE(e.keys,t,n,Ce(s.scriptPubKey));return o?{coin:s,node:n.nodes.get(o.node),wallet:o.wallet}:null}function Wh(e,t,n,r,s=Date.now()){const{events:o,state:i}=zh(e),a=i.items.get(t),c=i.nodes.get(n);if(!a)throw new Error("Pick an item to make an offer on.");if(!c)throw new Error("Pick who makes the offer.");if(!Number.isSafeInteger(r)||r<0||r>0&&rnt)throw new Error("Offer at most 50 test BTC: no output on this chain is bigger than one block reward.");const u=Cc(e,o,i,t),l=u==null?void 0:u.node;if(!l)throw new Error(`No node in this lab holds ${a.name}.`);if(l.id===c.id)throw new Error(`${c.name} already holds ${a.name}.`);for(const y of[c,l])if(y.status!=="active")throw new Error(`${y.name} is ${y.status}.`);const f=$e(e.keys,i,c),d=$e(e.keys,i,l),h=Oe(e.keys,i,c);if(!f||!d||!h)throw new Error("A holding that predates lab keys cannot trade.");if((e.offers??[]).some(y=>y.item===t&&y.buyer===c.id&&ga(e,i,y)==="open"))throw new Error(`${c.name} already has an open offer on ${a.name}. Withdraw it first.`);const p=e.chain.coins(f.script),g=Kh(e),b=hs(p.filter(y=>!g.has(`${y.txid}:${y.vout}`)),r,bt-1)??hs(p,r,bt-1);if(!b)throw new Error(jh(c.name,p,r,bt-1,"offer"));const m={kind:pa,version:1,item:t,buyer:c.id,seller:l.id,price:r,holder:zu(u.coin),payers:b.map(zu),to:Ce(h.wallet.script),pay:Ce(d.script),back:Ce(f.script),change:b.reduce((y,v)=>y+v.value,0)-r-de,at:s},E=Fh(m);return m.txid=ie.util.getTxid(E),m.witnesses=b.map((y,v)=>f.sign(E,v+1)),(e.offers??(e.offers=[])).push(m),m}function Pc(e,t,n){var c,u;const r=l=>{var f;return((f=t.nodes.get(l))==null?void 0:f.name)??"a node"},s=((c=t.items.get(n.item))==null?void 0:c.name)??"the item";if(Fu(e.chain,n.holder))return`${s} has moved since`;if(n.payers.some(l=>Fu(e.chain,l)))return`${r(n.buyer)} has spent a coin the offer promised`;for(const l of[n.buyer,n.seller]){const f=t.nodes.get(l);if((f==null?void 0:f.status)!=="active")return`${r(l)} is ${(f==null?void 0:f.status)??"gone"}`}const o=t.nodes.get(n.buyer),i=t.nodes.get(n.seller),a=l=>l?Ce(l.script):"";return a((u=Oe(e.keys,t,o))==null?void 0:u.wallet)!==n.to||a($e(e.keys,t,o))!==n.back?`${o.name} has new keys since`:n.price&&a($e(e.keys,t,i))!==n.pay?`${i.name} has new keys since`:""}const ga=(e,t,n)=>e.chain.transactions.has(n.txid)?"done":Pc(e,t,n)?"stale":"open";function fE(e,t){const n=(e.offers??[]).find(c=>c.txid===t);if(!n)throw new Error("That offer is gone.");if(e.chain.transactions.has(n.txid))throw new Error("That offer was already accepted.");const{events:r,state:s}=zh(e),o=Pc(e,s,n);if(o)throw new Error(`This offer is stale: ${o}.`);const i=Cc(e,r,s,n.item);if((i==null?void 0:i.node.id)!==n.seller)throw new Error("Only the holder can accept.");const a=Fh(n);return n.witnesses.forEach((c,u)=>{a.vin[u+1].witness=c}),a.vin[0].witness=[i.wallet.sign(a,void 0,0)],e.chain.submitPackage([ie.encode(a).hex]),n}function lE(e,t){const n=(e.offers??[]).find(r=>r.txid===t);if(!n)throw new Error("That offer is gone.");if(e.chain.transactions.has(n.txid))throw new Error("That offer was accepted: it is on the chain now.");return e.offers=e.offers.filter(r=>r!==n),n}function dE(e){const t=(r,s)=>r&&Vu.test(r.txid)&&Number.isSafeInteger(r.vout)&&r.vout>=0&&Number.isSafeInteger(r.value)&&r.value>=Ne&&r.value<=nt&&s.test(r.script),n=r=>Number.isSafeInteger(r)&&(r===0||r>=Ne&&r<=nt);if((e==null?void 0:e.kind)!==pa||e.version!==1||!Ui.test(e.item)||!Ui.test(e.buyer)||!Ui.test(e.seller)||e.buyer===e.seller||!n(e.price)||!n(e.change)||!t(e.holder,qu)||!Array.isArray(e.payers)||!e.payers.length||e.payers.length>bt-1||!e.payers.every(r=>t(r,Ni))||!qu.test(e.to)||!Ni.test(e.pay)||!Ni.test(e.back)||!Vu.test(e.txid)||!Array.isArray(e.witnesses)||e.witnesses.length!==e.payers.length||!e.witnesses.every(r=>Array.isArray(r)&&r.length===2&&/^30[0-9a-f]{12,140}01$/.test(r[0])&&/^0[23][0-9a-f]{64}$/.test(r[1]))||!Number.isSafeInteger(e.at))throw new Error("Invalid offer.");return{kind:pa,version:1,item:e.item,buyer:e.buyer,seller:e.seller,price:e.price,holder:{...e.holder},payers:e.payers.map(r=>({...r})),to:e.to,pay:e.pay,back:e.back,change:e.change,at:e.at,txid:e.txid,witnesses:e.witnesses.map(r=>[...r])}}const Xo="orgchain:lab:v1",hE=["each",10,30,60,"manual"];function Ss(e={tempo:"each",nextAt:null}){const{tempo:t,nextAt:n}=e??{},r=typeof t=="number";if(!hE.includes(t)||!(n===null||r&&Number.isSafeInteger(n)&&n>0))throw new Error("Invalid clock.");return{tempo:t,nextAt:n}}function Gh(e){const t=vc();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]=lh(s,24)}if(t.scheme=(e==null?void 0:e.scheme)??(Object.keys(t.roots).length?"wallet":"bip86"),!Wv.includes(t.scheme))throw new Error("Invalid lab keys.");return t}const pE=["split","last","none"];function $s(e){const t=(e==null?void 0:e.rule)??"split",n={};if(!pE.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}}function Yh(e=[]){if(!Array.isArray(e)||e.length>1e3)throw new Error("Invalid offers.");const t=e.map(dE);if(new Set(t.map(n=>n.txid)).size!==t.length)throw new Error("Invalid offers.");return t}const _s=()=>({wallet:null,chain:new Fo,clock:Ss(),keys:vc(),mining:$s(),offers:[]});function Xh(e){if(!e)return _s();const t=JSON.parse(e);if((t==null?void 0:t.kind)!=="orgchain-lab"||t.network!==pn||t.version!==1)throw new Error("That is not an Orgchain v1 lab.");return{wallet:t.wallet?$n.load(t.wallet):null,chain:new Fo(t.chain),clock:Ss(t.clock),keys:Gh(t.keys),mining:$s(t.mining),offers:Yh(t.offers)}}const Jh=e=>{var t;return JSON.stringify({kind:"orgchain-lab",network:pn,version:1,wallet:((t=e.wallet)==null?void 0:t.backup())??null,chain:e.chain.snapshot(),clock:Ss(e.clock),keys:Gh(e.keys),mining:$s(e.mining),offers:Yh(e.offers)})};function gE(e,t,n){var r;e.mining=$s({...e.mining,rigs:{...(r=e.mining)==null?void 0:r.rigs,[t]:n}})}function mE(e,t){e.mining=$s({...e.mining,rule:t})}const Uc=()=>Xh(localStorage.getItem(Xo));function yE(e){try{localStorage.setItem(Xo,Jh(e))}catch{throw new Error("Browser storage is full or unavailable, so nothing was saved. Save a backup, then reset.")}}async function bE(e,{locks:t=(s=>(s=globalThis.navigator)==null?void 0:s.locks)(),read:n=Uc,save:r=yE}={}){if(!t)throw new Error("Orgchain needs Web Locks: open it over HTTPS or on localhost.");return t.request(Xo,async()=>{const o=n(),i=await e(o);return i!==!1&&r(o),{lab:o,result:i}})}function vt(e,t=null){e.wallet||(e.wallet=$n.create());const n=t!=null&&t.length?e.chain.mineTo(t.map(r=>je(r.value,r.script))):e.chain.mine(e.wallet.script);return e.clock=Ss({tempo:e.clock.tempo,nextAt:null}),n}function Nr(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 wE(e,t,n=Date.now(),r=null){e.clock=Ss({tempo:t,nextAt:null}),t==="each"&&e.chain.mempool.length?vt(e,r):Nr(e,n)}function xE(e,t=Date.now(),n=null){const{tempo:r,nextAt:s}=e.clock;return typeof r!="number"||!e.chain.mempool.length?!1:s===null?(Nr(e,t),!0):t`found ${e.name}`,birth:e=>`birth ${e.name}`,award:e=>`award ${e.skill} ${e.belt}`,decide:e=>`decide ${e.title}`,make:e=>`make ${e.name}`,keyring:(e,t)=>Vo(t,e),graduate:()=>"graduate",close:()=>"close"};function EE(e,t={}){if(!Object.hasOwn(Wu,e))throw new Error("Unknown verb.");const n={op:e};for(const s of Wu[e]){const o=t[s];typeof o=="string"&&o.trim()&&(n[s]=o.trim())}const r=e==="keyring"&&t.proof&&typeof t.proof=="object"?t.proof:null;return r&&(n.proof=Object.fromEntries(xt.filter(s=>typeof r[s]=="string").map(s=>[s,r[s]]))),n}function Qh(e,t){const n=at(e),r=n.nodes.get(t),s=r&&Xv(e.keys,n,r);if(!s)throw new Error(`${(r==null?void 0:r.name)??"That node"} predates lab keys, so it has no keys to list.`);return sv(t,s.keys,s.secrets)}function Nc(e,t,n,r={}){if(t==="keyring"){for(let s=e.nodes.get(n);s;s=s.edge==="derived"?e.nodes.get(s.parent):null)if(s.graduated==="cued")return`${s.name}'s graduation is cued, and it changes ${s.id===n?"its":`${e.nodes.get(n).name}'s`} keys. Publish the keyring once it lands`}if(t==="graduate"&&e.nodes.has(r.of)){const s=new Set(ks(e,r.of).map(i=>i.id)),o=e.log.find(i=>i.pending&&i.ok&&i.op==="keyring"&&s.has(i.node));if(o)return`${e.nodes.get(o.node).name}'s keyring is cued. Graduate ${e.nodes.get(r.of).name} once it lands, so the graduation retires it`}return""}const at=e=>Sn(zo(new bs(e.chain)),{pending:!0});function e0(e,t,n,r){const s=EE(t,r),o=zo(new bs(e.chain)),i={id:"check",status:"pending",height:null,metadata:s,parent:n??null,protocol:bc},{ok:a,why:c}=Sn([...o,i],{pending:!0}).log.at(-1);if(!a)throw new Error(`${c[0].toUpperCase()}${c.slice(1)}.`);return s}const ma=At+2*de+330,t0=1e5,Lc=1e4,Rc=(e,t=0)=>At+2*de+(e==="birth"?1:e==="graduate"?Math.max(0,t-1):0)*de+330,kE=(e,t=0)=>Rc(e,t)-330,Br=(e,t,n)=>e.chain.coins(t.script).find(r=>{var s;return!((s=r.inscriptions)!=null&&s.length)&&r.value>=n}),ya=e=>Zt(e.txid,e.vout,e.value,e.scriptPubKey),n0=(e,t)=>(t.forEach((n,r)=>{e.vin[r].witness=[n.sign(e,void 0,r)]}),ie.encode(e).hex);function Hc(e){e.keys??(e.keys=vc()),e.wallet||(e.wallet=$n.create()),Br(e,e.wallet,t0+de+330)||vt(e)}function r0(e,t,n=ma,r=t0){if(t===e.wallet||Br(e,t,n))return;const s=Br(e,e.wallet,r+de+330),o=ie.create({vin:[ya(s)],vout:[je(r,t.script),je(s.value-r-de,e.wallet.script)]});e.chain.submitPackage([n0(o,[e.wallet])])}function Gu(e,t,n,r,s){if(r===e.wallet||Br(e,r,s))return;const o=n&&$e(e.keys,t,n);if(!o)return r0(e,r,s);Tc(e,o,r.script,Math.max(Lc,s),n.name)}function SE(e,t,n,r,s){if(r===e.wallet||Br(e,r,s))return!0;const o=n&&$e(e.keys,t,n);return!o||Zh(e,o,Math.max(Lc,s))}function s0(e,t,n,r,s={}){var l,f;const o=r?t.nodes.get(r):null,i=o&&((l=kc(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&&Oe(e.keys,t,a)?ks(t,a.id).length:0;if(!SE(e,t,o,i,Rc(n,c))){const d=t.nodes.get(o.parent);return`${o.name} has no test BTC for gas. ${d?`${d.name} can send some`:((f=e.mining)==null?void 0:f.rule)==="none"?"Fund it from the lab wallet":"It earns some each beat it mines"}`}const u=c?$e(e.keys,t,a):null;return u&&!Mh(e.chain.coins(u.script).filter(d=>d.value-de>=Ne).map(d=>({value:d.value-de})),Lc)?`${a.name} needs test BTC of its own to claim its new root. Send it some first`:""}function Yu(e,t,n,r,s=n){const o=Wo(e.chain,t),i=Br(e,s,de+330),a=ie.create({vin:[ya(o),ya(i)],vout:[je(o.value,r.script),je(i.value-de,s.script)]});e.chain.submitPackage([n0(a,[n,s])])}function Xu(e,t,n,r,s){return new ox(e.chain,t).inscribe(vE[n](s,r),r??null,s,{metaprotocol:bc})}const Jo=(e,t)=>{var r;const n=at(e);return Hh(e,n,((r=n.nodes.get(t))==null?void 0:r.root)??null)},Qo=(e,t)=>Hh(e,at(e),t);function jc(e){var r,s,o;const t=at(e),n=new Map;for(const i of t.nodes.values())for(const a of[$e(e.keys,t,i),(r=Oe(e.keys,t,i))==null?void 0:r.wallet])a&&n.set(Ce(a.script),i.root);for(const i of[...e.chain.mempool].reverse()){const a=e.chain.transactions.get(ie.util.getTxid(i));if(a!=null&&a.inscription){const c=(s=t.log.find(u=>u.id===a.inscription.id))==null?void 0:s.root;if(c)return c;continue}for(const c of(a==null?void 0:a.tx.vin)??[]){const u=((o=e.chain.transactions.get(c.txid))==null?void 0:o.tx.vout[c.vout])??e.chain.imported(c.txid,c.vout),l=u&&n.get(Ce(u.scriptPubKey));if(l)return l}}return null}function Ju(e,t,n){var s;const r=kc(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 o0(e,t,n,r){if(t==="found"){const l=Ou(),f=Yv(e.keys,l);r0(e,f,ma,ma);const d=Xu(e,f,t,null,r);return e.keys.roots[d]=l,d}const s=at(e),o=Ju(e,s,n),i=s.nodes.get(n),a=t==="graduate"?s.nodes.get(r.of):null,c=a&&Oe(e.keys,s,a)?ks(s,a.id).map(l=>[l.id,Ju(e,s,l.id)]):[];Gu(e,s,i,o,Rc(t,c.length));const u=Xu(e,o,t,n,r);if(t==="birth"){const l=at(e),f=Oe(e.keys,l,l.nodes.get(u));f&&Yu(e,u,o,f.wallet)}if(c.length){e.keys.adopted[a.id]=Ou();const l=at(e);for(const[f,d]of c){const h=Oe(e.keys,l,l.nodes.get(f)).wallet;if(oE(e,$e(e.keys,s,s.nodes.get(f)),$e(e.keys,l,l.nodes.get(f))),f!==a.id){Yu(e,f,d,h,o);continue}Gu(e,l,l.nodes.get(f),h,de+330),bv(e.chain,yv(e.chain,f,h),d)}}return u}function $E(e,t,n,r,s=Date.now()){const o=Nc(at(e),t,n??null,r??{});if(o)throw new Error(`${o}.`);const i=e0(e,t,n,t==="keyring"?Qh(e,n):r),a=s0(e,at(e),t,n??null,i);if(a)throw new Error(`${a}.`);Hc(e);const c=o0(e,t,n??null,i);return e.clock.tempo==="each"?vt(e,Jo(e,n??c)):Nr(e,s),c}function _E(e,t,n,r,s=Date.now()){const o=Vh(e,at(e),t,n,r);return e.clock.tempo==="each"?vt(e,Jo(e,t)):Nr(e,s),o}const AE=(e,t,n,r,s=Date.now())=>Wh(e,t,n,r,s);function BE(e,t,n=Date.now()){const r=fE(e,t);return e.clock.tempo==="each"?vt(e,Jo(e,r.seller)):Nr(e,n),r}const TE=(e,t)=>lE(e,t);function IE(e,t,n,r=Date.now()){const s=at(e),o=s.nodes.get(t);if(!o||o.root!==o.id)throw new Error("Pick a holding to fund.");if(o.status!=="active")throw new Error(`${o.name} is closed.`);const i=$e(e.keys,s,o);if(!i)throw new Error("A holding that predates lab keys has no SegWit address to fund.");if(!Number.isSafeInteger(n)||nnt)throw new Error("Fund at most 50 test BTC at a time: no output on this chain is bigger than one block reward.");Hc(e),Zh(e,e.wallet,n)||vt(e);const a=Tc(e,e.wallet,i.script,n,"The lab wallet","fund");return e.clock.tempo==="each"?vt(e,Jo(e,t)):Nr(e,r),a}const ba="yolopreneur",OE=[[["found",null,{name:"yolopreneur"}]],[["birth","yolopreneur",{name:"well-known",kind:"org"}],["birth","yolopreneur",{name:"time",kind:"org"}],["keyring","yolopreneur",{}]],[["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."}],["make","sol",{name:"launch-kit",note:"The page, the post and the checklist every venture launches with."}],["keyring","sol",{}],["keyring","lineage",{}]],[["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."}],["offer","lineage",{item:"launch-kit",price:.1}]]];function CE(e){Hc(e),e.chain.mempool.length&&vt(e);const t={},n={};for(const r of OE){for(const[s,o,i]of r){if(s==="send"){Vh(e,at(e),t[o],t[i.to],i.amount*ds);continue}if(s==="offer"){Wh(e,n[i.item],t[o],i.price*ds);continue}const a=s==="keyring"?Qh(e,t[o]):Object.fromEntries(Object.entries(i).map(([l,f])=>[l,l==="to"||l==="of"?t[f]:f])),c=o?t[o]:null,u=o0(e,s,c,e0(e,s,c,a));(s==="found"||s==="birth")&&(t[i.name]=u),s==="make"&&(n[i.name]=u)}vt(e,Qo(e,t[ba]))}return t[ba]}const D=e=>document.getElementById(e);function A(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 Wr=(e,t)=>`${e} ${t}${e===1?"":"s"}`,Tt=e=>e==="cued"?"cued":`beat ${e}`,PE=e=>new Date(e).toLocaleTimeString([],{hour:"2-digit",minute:"2-digit",second:"2-digit"}),Qu=e=>JSON.stringify(e,(t,n)=>typeof n=="bigint"?String(n):n,2),I={holding:null,node:null,event:null,tx:null,beat:null,verb:"birth",busy:!1,replay:null,closing:null,reveal:null};let q=_s(),Io=new bs(q.chain),ln=[],z=Sn([]),ze=z,De={owner:new Map,ledger:[],now:new Map,view:new Map},gn=new Map;const tt=()=>q.chain.blocks.length,wa=()=>ln.filter(e=>e.status==="pending").length,xa=e=>De.ledger.filter(t=>t.beat===null&&t.kind===e).length,Ys=[["pay","cued send"],["deal","cued deal"],["fund","cued deposit"]],UE=()=>wa()+Ys.reduce((e,[t])=>e+xa(t),0),_n=e=>{var t;return((t=z.items.get(e))==null?void 0:t.name)??"an item"},va=()=>q.offers??[],Xs=e=>De.view.get(e)??0,i0=e=>De.now.get(e)??0,X=(e,t=z)=>e?t.nodes.get(e)??null:null,NE=e=>{var t;return!!e&&(e.root===I.holding||((t=X(e.parent))==null?void 0:t.root)===I.holding)},Kc=e=>Object.assign(I,{event:null,tx:null,closing:null,reveal:null},e),Lr=e=>{Kc(e),ei()};function be(e,t=!1){const n=D("say");n.textContent=e,n.classList.toggle("bad",t)}function a0(){try{q=Uc()}catch(e){q=_s(),be(`This browser's saved lab could not be read (${e.message}) Load a backup, or reset to start over.`,!0)}Dc()}function Dc(){var n;Io=new bs(q.chain),ln=zo(Io),z=Sn(ln,{pending:!0}),I.beat!==null&&I.beat>=tt()&&(I.beat=null),X(I.holding)||(I.holding=((n=z.roots.filter(r=>r.kind==="holding").at(-1)??z.roots.at(-1))==null?void 0:n.id)??null),NE(X(I.node))||(I.node=I.holding),I.event&&!z.log.some(r=>r.id===I.event)&&(I.event=null),ze=I.beat===null?z:Sn(ln,{upTo:I.beat});const e=iE(q.keys,ln,z),t=new Map(va().map(r=>[r.txid,r]));De={owner:e,ledger:uE(q.chain,e,aE(q.keys,ln,z),t),now:ha(q.chain,e)},gn=new Map([...z.items.keys()].map(r=>{var s;return[r,((s=Cc(q,ln,z,r))==null?void 0:s.node.id)??null]})),De.view=I.beat===null?De.now:ha(q.chain,e,I.beat),I.tx&&!De.ledger.some(r=>r.key===I.tx)&&(I.tx=null),ei()}function Oo(e){I.beat=e>=tt()?null:Math.max(0,e),ze=I.beat===null?z:Sn(ln,{upTo:I.beat}),De.view=I.beat===null?De.now:ha(q.chain,De.owner,I.beat),ei()}async function ft(e,t){if(I.busy)return!1;I.busy=!0,document.body.classList.add("busy");try{return q=(await bE(e,t)).lab,!0}catch(n){return be((n==null?void 0:n.message)||String(n),!0),!1}finally{I.busy=!1,document.body.classList.remove("busy"),Dc()}}async function Tn(e,t,n,r){let s=null;if(!await ft(i=>{s=$E(i,e,t,n)}))return!1;const o=Io.events.find(i=>i.id===s);return be(r(s,(o==null?void 0:o.status)==="confirmed"?`at beat ${o.height}`:"cued for the next beat")),ei(),!0}async function c0(e){const t=[wa(),...Ys.map(([a])=>xa(a))],n=tt();if(!await ft(e)||tt()===n)return;const r=[wa(),...Ys.map(([a])=>xa(a))],s=["cued act",...Ys.map(([,a])=>a)],o=t.map((a,c)=>[a-r[c],s[c]]).filter(([a])=>a>0).map(([a,c])=>Wr(a,c)),i=LE(De.ledger.filter(a=>a.kind==="mine"&&a.beat===tt()));be(`Beat ${tt()}: ${o.length?`${o.join(" and ")} landed, and ${i}`:i}.`)}function LE(e){if(!e.length)return"the lab wallet earned 50 tBTC";const t=e.map(r=>{var s;return((s=X(r.to))==null?void 0:s.name)??"?"}),n=e.map(r=>Sc(r.amount));return e.length===1?`${t[0]} earned ${ce(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 RE(){var t;if(((t=q.mining)==null?void 0:t.rule)==="last")return"the holding that acts";const e=_c(q,z);return e.length?e.length===1?e[0].name:`${e.length} holdings, split by hashrate`:"the lab wallet"}function ei(){u0(),KE(),DE(),ti(),b0(),Mc()}function u0(){const e=UE(),{tempo:t}=q.clock;for(const r of document.querySelectorAll("[data-tempo]"))r.setAttribute("aria-pressed",String(String(t)===r.dataset.tempo));D("clock-beat").textContent=String(tt()),D("clock-cued").textContent=e?`${e} cued · ${HE()}`:"nothing cued";const n=RE();D("clock-pays").textContent=`beats pay ${n}`,D("beat-now").title=`Beat now: ${e?"land what is cued, and ":""}pay ${n} 50 test BTC`}function HE(){const{tempo:e,nextAt:t}=q.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"}const jE={split:"Every active holding mines: each beat's 50 tBTC splits by hashrate, set on each holding (0 sits out).",last:"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.",none:"Mainnet has no mining to join: beats pay the lab wallet, standing in for the world's miners. Fund a holding from it, the way you'd fund a seed from a wallet you already have."};function KE(){var a,c;const e=((a=q.mining)==null?void 0:a.rule)??"split",t=e==="split",n=t?_c(q,z):[],r=n.reduce((u,l)=>u+dr(q,l.id),0);D("holdings-list").replaceChildren(...z.roots.map(u=>{var m;const l=uv(z,u.id),f=u.id===I.holding,d=u.status==="active",h=n.some(E=>E.id===u.id)?dr(q,u.id)/r:0,p=[...z.nodes.values()].reduce((E,y)=>E+(y.root===u.id?i0(y.id):0),0),b=[u.graduated!==null&&`from ${((m=X(u.parent))==null?void 0:m.name)??"?"}${u.graduated==="cued"?", cued":` at beat ${u.graduated}`}`||Tt(u.born),Wr(l.orgs,"org"),Wr(l.agents,"agent"),Wr(l.belts,"belt"),p>0&&Sc(p),t&&d&&(h?`${Math.round(h*100)}% of each beat`:"not mining"),!d&&"closed"].filter(Boolean);return A("li",{},A("button",{type:"button",class:`hold${f?" on":""}${d?"":" gone"}`,"aria-pressed":String(f),onclick:()=>Lr({holding:u.id,node:u.id})},A("span",{class:"hn",text:u.name})," ",A("span",{class:"hm",text:b.join(" · ")})),t&&d&&$e(q.keys,z,u)&&VE(u,dr(q,u.id)))}));for(const u of document.querySelectorAll("[data-rule]"))u.setAttribute("aria-pressed",String(e===u.dataset.rule));D("mining-note").textContent=jE[e];const s=z.roots.filter(u=>u.status==="active"&&$e(q.keys,z,u)),o=D("fund-to"),i=o.value;D("f-fund").hidden=e!=="none"||!s.length||I.beat!==null,o.replaceChildren(...s.map(u=>A("option",{value:u.id,text:u.name}))),o.value=s.some(u=>u.id===i)?i:s.some(u=>u.id===I.holding)?I.holding:((c=s[0])==null?void 0:c.id)??"",D("fund-has").textContent=ce(q.wallet?Oc(q.chain,q.wallet):0),D("holdings-empty").hidden=z.roots.length>0,D("holdings-sub").textContent=z.roots.length?String(z.roots.length):"",D("sample").disabled=z.roots.some(u=>u.name===ba&&u.status==="active")}function DE(){var r;const e=D("tree-rows"),t=X(I.holding);if(D("tree-sub").textContent=t?`${t.name} · ${I.beat===null?"now":`beat ${I.beat} of ${tt()}`}`:"",!t)return e.replaceChildren(A("p",{class:"wait",text:"No holding yet. Found one, or load the yolopreneur sample."}));if(!ze.nodes.has(t.id))return e.replaceChildren(A("p",{class:"wait",text:`${t.name} is founded at ${Tt(t.born)}. Move the slider forward.`}));const n=e.contains(document.activeElement)?document.activeElement.dataset.id:null;e.replaceChildren(...cv(ze,t.id).map(s=>s.type==="group"?A("div",{class:"row grp"},A("span",{class:"g","aria-hidden":"true",text:s.guide}),A("span",{class:"gl",text:s.label})):ME(s))),n&&((r=e.querySelector(`[data-id="${n}"]`))==null||r.focus())}function ME({node:e,guide:t,path:n,away:r}){const s=e.id===I.node,o=["row",s&&"on",e.status==="closed"&&"gone",e.born==="cued"&&"cue"].filter(Boolean).join(" ");return A("div",{class:o},A("button",{type:"button",class:"sel","data-id":e.id,"aria-pressed":String(s),onclick:()=>Lr({node:e.id}),title:r?`${e.name} graduated into a holding of its own`:null},A("span",{class:"g","aria-hidden":"true",text:t}),A("span",{class:"p",text:`${n} `}),A("span",{class:"l",text:e.name})," ",A("span",{class:"v"},ZE(e))))}function ZE(e){return[e.kind==="agent"&&A("span",{class:"mk",text:"agent"}),e.edge==="adopted"&&A("span",{class:"mk ok",text:"graduated"}),e.status==="closed"&&A("span",{class:"mk bad",text:"closed"}),e.born==="cued"&&A("span",{class:"mk",text:"cued"}),...e.badges.map(f0),Xs(e.id)>0&&A("span",{class:"mk sats",title:`${ce(Xs(e.id))} at its SegWit address`,text:Sc(Xs(e.id))})].filter(Boolean).flatMap((n,r)=>r?[" ",n]:[n])}const f0=e=>A("span",{class:`belt ${e.belt}`,title:`${e.skill}: ${e.belt} belt`},e.skill,A("span",{class:"sr",text:` (${e.belt} belt)`})),l0=(e,t)=>{for(let n=X(e.parent);n;n=X(n.parent))if(n.id===t.id)return!0;return!1},d0=e=>[...z.nodes.values()].filter(t=>t.id!==e.id&&t.status==="active").map(t=>[t,(t.root===e.root?0:4)+(l0(t,e)?0:2)+(t.kind==="agent"?0:1)]).sort((t,n)=>t[1]-n[1]).map(([t])=>t),h0=e=>e.children.reduce((t,n)=>{const r=X(n);return r&&r.edge==="derived"&&r.status==="active"?t+1+h0(r):t},0);function VE(e,t){const n=async r=>{await ft(s=>gE(s,e.id,r))&&be(r?`${e.name} mines at hashrate ${r}.`:`${e.name} sits out of mining.`)};return A("span",{class:"rig"},A("span",{class:"rl",text:"hashrate"}),A("span",{class:"rn"},A("button",{type:"button",class:"rb","aria-label":`Lower ${e.name}'s hashrate`,disabled:t<=0,onclick:()=>n(t-1)},"−"),A("b",{text:String(t)}),A("button",{type:"button",class:"rb","aria-label":`Raise ${e.name}'s hashrate`,disabled:t>=9,onclick:()=>n(t+1)},"+")))}const p0=e=>[...z.nodes.values()].filter(t=>t.id!==e.id&&t.status==="active").map(t=>[t,(t.root===e.root?0:4)+(l0(t,e)?0:2)+(t.kind==="agent"?0:1)]).sort((t,n)=>t[1]-n[1]).map(([t])=>t);function qE(e){const t=$e(q.keys,z,e);return t?Bc(q.chain.coins(t.script))[...z.items.values()].map(t=>[t,X(gn.get(t.id))]).filter(([,t])=>t&&t.id!==e.id&&t.status==="active").sort((t,n)=>(t[1].root===e.root?0:1)-(n[1].root===e.root?0:1)).map(([t])=>t);function zE(e){const t=$e(q.keys,z,e);return t?m0(e).length?q.chain.coins(t.script).some(n=>n.value>=de+Ne||n.value===de)?"":g0(e,"to pay with"):"Nobody else holds an item yet. Items come from Make":"This holding predates lab keys, so it has no SegWit address to pay from"}function y0(e,t=z){const n=Ec(q.keys,t,e);return n&&{taproot:n.taproot.address,segwit:n.segwit.address,nostr:n.npub.address,ethereum:n.ethereum.address}}function FE(e){const t=y0(e),n=e.keyring;if(!t)return"This holding predates lab keys, so it has no keys to list";const r=Nc(z,"keyring",e.id);return r||(!n||n.retired||xt.some(s=>n.keys[s]!==t[s])?"":n.beat==="cued"?`${e.name}'s keyring is cued for the next beat`:`${e.name}'s keyring already lists these keys, since beat ${n.beat}`)}function WE(e){const t=X(e.parent),n=e.status==="closed"?`${e.name} is closed`:"",r=(s,o=e.id,i={})=>s0(q,z,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":d0(e).length?r("award"):"There is nobody else to award yet"),decide:n||r("decide"),make:n||r("make"),keyring:n||FE(e)||r("keyring"),send:n||qE(e),offer:n||zE(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`:Nc(z,"graduate",t.id,{of:e.id})||r("graduate",t.id,{of:e.id}):"A holding has no parent to graduate from"),close:n||r("close")}}function ti(){const e=X(I.node),t=I.beat!==null;if(D("act-none").hidden=!!e,D("act-past").hidden=!e||!t,D("act-on").hidden=!e||t,D("act-sub").textContent=(e==null?void 0:e.name)??"",D("past-beat").textContent=String(I.beat??""),!e||t)return;const n=WE(e),r=X(e.parent);for(const p of document.querySelectorAll("[data-verb]"))p.setAttribute("aria-pressed",String(p.dataset.verb===I.verb)),p.classList.toggle("off",!!n[p.dataset.verb]);for(const p of document.querySelectorAll("form[data-form]"))p.hidden=p.dataset.form!==I.verb||!!n[I.verb];D("act-why").textContent=n[I.verb]?`${n[I.verb]}.`:"";for(const p of document.querySelectorAll("#act-on [data-name]"))p.textContent=e.name;for(const p of document.querySelectorAll("#act-on [data-parent]"))p.textContent=(r==null?void 0:r.name)??"";const s=p=>p.map(g=>`${g.value}=${g.textContent}`).join("|"),o=[[D("award-to"),d0(e).map(p=>[p.id,`${Ar(z,p.id)}${p.kind==="agent"?" (agent)":""}`])],[D("send-to"),p0(e).map(p=>[p.id,`${Ar(z,p.id)}${p.kind==="agent"?" (agent)":""}`])],[D("offer-item"),m0(e).map(p=>[p.id,`${p.name} · held by ${Bt(gn.get(p.id))}`])]];for(const[p,g]of o){const b=p.value,m=g.map(([E,y])=>A("option",{value:E,text:y}));s(m)!==s([...p.options])&&(p.replaceChildren(...m),m.some(E=>E.value===b)&&(p.value=b))}for(const p of["send-has","offer-has"])D(p).textContent=ce(i0(e.id));D("graduate-go").textContent=`Graduate ${e.name}`;const i=I.verb==="keyring"&&!n.keyring&&y0(e);i&&D("keyring-keys").replaceChildren(...[["Taproot",i.taproot],["SegWit",i.segwit],["nostr",i.nostr],["Ethereum",i.ethereum]].map(Tr));const a=I.verb==="graduate"?r:e,c=a&&Oe(q.keys,z,a),u=I.verb==="send"||I.verb==="offer",l=c&&(u?`${c.from} · ${$e(q.keys,z,a).path}`:c.path);D("act-key").textContent=!a||n[I.verb]?"":c?`Signs as ${a.name}: ${l}`:"Signs with the lab wallet: this holding predates lab keys.";const f=I.verb==="graduate"&&Oe(q.keys,z,e)?ks(z,e.id).length:0;D("act-gas").textContent=!a||n[I.verb]||!c?"":I.verb==="send"?`Fee: ${de} sats, from ${e.name}'s balance.`:I.verb==="offer"?`Fee: ${de} sats, from ${e.name}'s balance, paid only if the holder accepts.`:`Gas: ${kE(I.verb,f).toLocaleString("en-US")} sats from ${a.name}'s tank (${ce(Oc(q.chain,c.wallet))}), which tops up from its balance.${f?` ${e.name} pays ${de} more, from its own money, to claim its new root.`:""}`;const d=h0(e),h=I.closing===e.id;D("close-note").textContent=d?`Closing ${e.name} spends it for the last time, and its ${Wr(d,"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.`,D("close-go").textContent=h?`Yes, close ${e.name}`:`Close ${e.name}`,D("close-keep").hidden=!h}function b0(){const e=D("inspect-body"),t=I.event?z.log.find(o=>o.id===I.event):null;if(t)return D("inspect-sub").textContent="event",e.replaceChildren(...uk(t));const n=I.tx?De.ledger.find(o=>o.key===I.tx):null;if(n)return D("inspect-sub").textContent="money",e.replaceChildren(...fk(n));const r=X(I.node);if(D("inspect-sub").textContent=(r==null?void 0:r.kind)??"",!r)return e.replaceChildren(A("p",{class:"note pad",text:"Select a node in the tree, or an event in the timeline."}));const s=X(I.node,ze);if(!s)return e.replaceChildren(A("p",{class:"note pad",text:`${r.name} is not born yet at beat ${I.beat}.`}));e.replaceChildren(...GE(s))}const Tr=([e,t,n])=>A("div",{class:"f"},A("dt",{text:e}),A("dd",{},t,n&&A("span",{class:"fn",text:n})));function GE(e){const t=X(e.parent,ze),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 ${Tt(e.graduated)}: it holds its own root`:`derived: ${t.name} holds its seed`],t&&e.root===e.id&&["Holding",A("span",{},"its own, since it graduated",e.id!==I.holding&&A("button",{type:"button",class:"btn sm open",onclick:()=>{Lr({holding:e.id,node:e.id}),QE()}},`Open ${e.name}`))],e.closed!==null&&["Closed",Tt(e.closed)],["Children",e.children.length?e.children.map(r=>{var s;return(s=X(r,ze))==null?void 0:s.name}).join(", "):"none yet"],$e(q.keys,ze,e)&&["Balance",ce(Xs(e.id)),`Test BTC at its SegWit address${I.beat===null?"":`, as of beat ${I.beat}`}.`],I.beat===null&&Oe(q.keys,z,e)&&["Gas tank",ce(Oc(q.chain,Oe(q.keys,z,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[A("div",{class:"ih"},A("p",{class:"eyebrow",text:Ar(ze,e.id)}),A("h3",{class:"it",text:e.name}),A("div",{class:"chips"},A("span",{class:"chip",text:e.kind}),A("span",{class:`chip ${e.status==="active"?"ok":"bad"}`,text:e.status}),e.edge==="adopted"&&A("span",{class:"chip ok",text:"graduated"}),e.born==="cued"&&A("span",{class:"chip",text:"cued"}))),A("div",{class:"ib"},A("dl",{class:"fl"},n.map(Tr)),e.badges.length>0&&A("div",{},A("p",{class:"lab",text:"Belts"}),A("ul",{class:"list"},e.badges.map(r=>{var s;return A("li",{},f0(r),A("span",{class:"when",text:` from ${((s=X(r.by))==null?void 0:s.name)??"?"}, ${Tt(r.beat)}`}))}))),e.decisions.length>0&&A("div",{},A("p",{class:"lab",text:"Decisions"}),A("ul",{class:"list"},e.decisions.map(r=>A("li",{},A("b",{text:r.title}),r.why&&` · ${r.why}`,A("span",{class:"when",text:` (${Tt(r.beat)})`}))))),YE(e),ek(e),sk(e))]}function YE(e){const t=(a,c)=>c.length>0&&A("div",{},A("p",{class:"lab",text:a}),A("ul",{class:"list items"},c)),n=(a,c)=>A("li",{},A("b",{text:a.name}),a.note&&` · ${a.note}`,A("span",{class:"when",text:` (${c})`}));if(I.beat!==null)return t("Made",e.made.map(a=>ze.items.get(a)).filter(Boolean).map(a=>n(a,Tt(a.beat))));const r=a=>`made${a.maker===e.id?"":` by ${Bt(a.maker)}`}${a.beat==="cued"?", cued":` at beat ${a.beat}`}`,s=[...z.items.values()].filter(a=>gn.get(a.id)===e.id).map(a=>{const c=n(a,r(a)),u=va().filter(l=>l.item===a.id&&l.seller===e.id&&ga(q,z,l)==="open");return u.length&&c.append(A("ul",{class:"bids"},u.map(l=>A("li",{},A("span",{text:`${Bt(l.buyer)} offers ${l.price?ce(l.price):"nothing, a free claim"}`}),e.status==="active"&&A("button",{type:"button",class:"btn sm","aria-label":`Accept ${Bt(l.buyer)}'s offer for ${a.name}`,onclick:()=>XE(l)},"Accept"))))),c}),o=e.made.map(a=>z.items.get(a)).filter(a=>a&&gn.get(a.id)!==e.id).map(a=>n(a,gn.get(a.id)?`now held by ${Bt(gn.get(a.id))}`:"held outside this lab")),i=va().filter(a=>a.buyer===e.id&&ga(q,z,a)!=="done").map(a=>{const c=Pc(q,z,a);return A("li",{},A("b",{text:a.price?ce(a.price):"nothing"}),` for ${_n(a.item)}`,A("span",{class:"when",text:c?` (stale: ${c})`:` (open until ${Bt(a.seller)} accepts)`}),A("button",{type:"button",class:"btn sm","aria-label":`Withdraw the offer for ${_n(a.item)}`,onclick:()=>JE(a)},"Withdraw"))});return[t("Items",s),t("Made, held elsewhere",o),t("Offers made",i)]}const Bt=e=>{const t=X(e);return t?t.root===I.holding?t.name:Ar(z,e):"?"};async function XE(e){const t=_n(e.item),n=Bt(e.buyer),r=Bt(e.seller);if(!await ft(o=>{BE(o,e.txid)}))return;const s=De.ledger.find(o=>o.txid===e.txid);be(`${r} accepted: ${t} goes to ${n}${e.price?` for ${ce(e.price)}`:", free"}, ${s!=null&&s.beat?`at beat ${s.beat}`:"cued for the next beat"}.`)}async function JE(e){const t=_n(e.item),n=Bt(e.buyer);await ft(r=>{TE(r,e.txid)})&&be(`${n} withdrew its offer for ${t}.`)}function QE(){const e=document.querySelector(".tree-blk").getBoundingClientRect().top+scrollY-document.querySelector(".clock").offsetHeight-12;e(n.to===e.id||n.from===e.id)&&(I.beat===null||n.beat!==null&&n.beat<=I.beat)).slice(-6).reverse();return t.length>0&&A("div",{},A("p",{class:"lab",text:"Money"}),A("ul",{class:"list"},t.map(n=>A("li",{},A("b",{text:tk(n,e.id)}),A("span",{class:"when",text:` (${Tt(n.beat??"cued")})`})))))}function tk(e,t){const n=r=>{var s;return((s=X(r))==null?void 0:s.name)??"?"};if(e.kind==="mine")return`+${ce(e.amount)}, a beat's reward`;if(e.kind==="move")return`${ce(e.amount)} moved to its new key, after a ${e.fee}-sat fee`;if(e.kind==="gas")return`−${ce(e.amount)} into its gas tank, and a ${e.fee}-sat fee`;if(e.kind==="fund")return`+${ce(e.amount)} from the lab wallet`;if(e.kind==="deal"){const r=_n(e.item);return e.to===t?e.amount?`+${ce(e.amount)} from ${n(e.from)} for ${r}`:`${r} to ${n(e.from)}, free`:e.amount?`−${ce(e.amount)} to ${n(e.to)} for ${r}, and a ${e.fee}-sat fee`:`${r} from ${n(e.to)}, free but for a ${e.fee}-sat fee`}return e.to===t?`+${ce(e.amount)} from ${n(e.from)}`:`−${ce(e.amount)} to ${n(e.to)}, and a ${e.fee}-sat fee`}function w0(e){const t=n=>{const r=X(n);return r?r.root===I.holding?r.name:Ar(z,n):"?"};return e.kind==="mine"?`${ce(e.amount)} → ${t(e.to)}`:e.kind==="move"?`${ce(e.amount)} → ${t(e.to)}'s new key`:e.kind==="gas"?`${ce(e.amount)} → ${t(e.to)}'s gas tank`:e.kind==="fund"?`${ce(e.amount)} lab wallet → ${t(e.to)}`:e.kind==="deal"?`${_n(e.item)} ${t(e.to)} → ${t(e.from)}, ${e.amount?`for ${ce(e.amount)}`:"free"}`:`${ce(e.amount)} ${t(e.from)} → ${t(e.to)}`}const nk={own:"its own key",lab:"the lab wallet",parent:"its parent's key (its handoff is cued)",other:"a key outside this lab"},rk={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 sk(e){const t=Oe(q.keys,ze,e),n=kc(q,z,e.id),r=["Held now by",n?nk[n.who]:"nobody: its inscription has been spent"];if(!t)return A("div",{class:"keys"},A("p",{class:"lab",text:"Keys"}),A("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(Tr)));const s=e.kind==="agent",o=Ec(q.keys,ze,e),i=Jv(q.keys,ze,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.`],["Ethereum",o.ethereum.address,s?`BIP-44 at ${o.ethereum.path}: account ${t.account} of its org's seed, the way Ledger Live numbers Ethereum accounts.`:`BIP-44 at ${o.ethereum.path}. Its legal-control key, the one that holds the entity NFT, as on the lineage key tree page.`],["From",`${t.from} · account ${t.account}`],r,ok(e)];return A("div",{class:"keys"},A("p",{class:"lab",text:"Keys"}),A("dl",{class:"fl"},f.map(Tr)),e.keyring&&hr(`${e.keyring.retired?"Retired keyring":"Keyring"} · what each key signed`,Vo(e.id,e.keyring.keys)),A("p",{class:"lab"},"Leaves",A("span",{text:` · HKDF-SHA256 from its ${s?"nostr secret":"seed"}`})),A("ul",{class:"list leaves"},i.map(([d,h])=>A("li",{},A("b",{text:d}),A("span",{class:"when",text:` ${rk[d]}`}),A("code",{text:h})))),hr(s?"Public lines to paste":"CA key for TrustedUserCAKeys",a.join(` - -`)),ak(e,t))}function ok(e){var r;const t=e.keyring,n=(t==null?void 0:t.retired)&&(t.retired.by===e.id?"It":((r=X(t.retired.by,ze))==null?void 0:r.name)??"Its parent");return t?t.retired?["Keyring",`retired at ${Tt(t.retired.beat)}`,t.retired.cause==="close"?`${n} closed, which freed the keys it listed.`:n==="It"?"It graduated, so its keys changed with its new root. Keyring publishes a new one.":`${n} graduated, so ${e.name}'s keys changed with ${n}'s new root. Keyring publishes a new one.`]:["Keyring",`published at ${Tt(t.beat)}`,"Each key signed it: Taproot and SegWit by BIP-322, the npub as a nostr event, Ethereum by EIP-191."]:["Keyring","none yet","Keyring publishes one: an inscription that lists these keys, each key signing it."]}function hr(e,t,n=t){const r=A("pre",{text:n}),s=A("button",{type:"button",class:"cp","aria-label":`Copy ${e}`,onclick:()=>ik(t,s,r)},"Copy");return A("div",{class:"code"},A("div",{class:"code-h cph"},A("span",{text:e}),s),r)}async function ik(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 ak(e,t){var a;const n=I.reveal===e.id,r=n&&rE(q.keys,ze,e),s=X(e.parent,ze),o=()=>{var c;I.reveal=n?null:e.id,b0(),(c=D("reveal"))==null||c.focus()},i=(a=r==null?void 0:r.seed)==null?void 0:a.mnemonic.split(" ");return A("div",{class:"secret"},A("div",{class:"hz"},A("span",{class:"hz-l",text:"Secret · stays in this tab"}),A("button",{type:"button",class:"btn sm",id:"reveal","aria-expanded":String(n),onclick:o},n?"Hide":"Reveal")),r&&A("div",{class:"sb"},r.seed?hr(`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(` -`)):A("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])=>hr(`${c} · ${u}`,l)),r.leaves.map(([c,u,l])=>hr(`${c} · ${u}`,l))))}function ck(e){var i,a,c;const t=(a=(i=q.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=Qa(t).pubkey,r=X(e.parent),s=e.op==="found"?X(e.node):null,o=[[s&&Oe(q.keys,z,s),`${s==null?void 0:s.name}'s root`],[r&&Oe(q.keys,z,r),`${r==null?void 0:r.name}'s key`],[(r==null?void 0:r.edge)==="adopted"&&Oe(q.keys,z,{...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=q.wallet)==null?void 0:c.pubkey)===n?"the lab wallet":`a key outside this lab (${n.slice(0,12)}…)`}function uk(e){var o,i,a;const t=Io.events.find(c=>c.id===e.id),n=(i=(o=q.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=X(e.parent))==null?void 0:a.name)??"an unknown inscription"}, whose inscription this event spent`:"nothing: a founding has no parent"],["Signed by",ck(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[A("div",{class:"ih"},A("p",{class:"eyebrow",text:`${e.op} · ${e.pending?"cued":`beat ${e.beat}`}`}),A("h3",{class:"it",text:kh(e,z)}),A("div",{class:"chips"},A("span",{class:"chip",text:(t==null?void 0:t.protocol)??"?"}),A("span",{class:`chip ${e.ok?"ok":"bad"}`,text:e.ok?"applied":"rejected"})),!e.ok&&A("p",{class:"idesc",text:"The reducer rejected this event. It stays on the chain, but it does not change the tree."})),A("div",{class:"ib"},A("dl",{class:"fl"},r.map(Tr)),A("div",{class:"code"},A("p",{class:"code-h",text:"Metadata · CBOR, tag 5"}),A("pre",{text:Qu(e.meta)})),s&&A("div",{class:"code"},A("p",{class:"code-h",text:"Raw index entry"}),A("pre",{text:Qu(s)})))]}function fk(e){const t=i=>{var a;return((a=X(i))==null?void 0:a.name)??"a key outside this lab"},n=q.chain.transactions.get(e.txid),r=e.kind==="deal",s=e.kind==="fund",o=[["When",e.beat===null?"cued for the next beat":`beat ${e.beat}`],r&&["Item",`${_n(e.item)}, an inscription: from ${t(e.to)}'s Taproot key to ${t(e.from)}'s`],["From",e.kind==="mine"?"its share of the beat's block reward (the coinbase)":s?"the lab wallet, standing in for a wallet you already have":`${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`:r&&!e.amount?"nobody: a free claim pays no price":`${t(e.to)}'s ${e.kind==="move"?"new ":""}SegWit address`],[r?"Price":"Amount",r&&!e.amount?"nothing":ce(e.amount)],e.kind!=="mine"&&["Fee",`${e.fee} sats, retired: this toy chain pays no fees to miners`],e.change>0&&["Change",`${ce(e.change)} back to ${s?"the lab wallet":t(e.from)}`],["Signed by",e.kind==="mine"?"nobody: a coinbase spends nothing":s?"the lab wallet's Taproot key":r?`${t(e.from)}'s SegWit key (SIGHASH_ALL) when it made the offer, then ${t(e.to)}'s Taproot key when it accepted`:`${t(e.from)}'s SegWit key (BIP-143, SIGHASH_ALL)`],["Transaction",e.txid]].filter(Boolean);return[A("div",{class:"ih"},A("p",{class:"eyebrow",text:`${e.kind} · ${e.beat===null?"cued":`beat ${e.beat}`}`}),A("h3",{class:"it",text:w0(e)}),A("div",{class:"chips"},A("span",{class:"chip",text:"test BTC"}),A("span",{class:`chip${e.beat===null?"":" ok"}`,text:e.beat===null?"cued":"confirmed"}))),A("div",{class:"ib"},A("dl",{class:"fl"},o.map(Tr)),n&&hr("Raw transaction",n.raw))]}function Mc(){const e=tt(),t=D("beat"),n=X(I.holding);t.max=String(e),t.value=String(I.beat??e),t.disabled=e===0,D("beat-label").textContent=I.beat===null?`Now · beat ${e}`:`Beat ${I.beat} of ${e}`,D("replay").textContent=I.replay?"Stop":"Replay",D("replay").disabled=!n||e===0,D("to-now").disabled=I.beat===null,D("timeline-sub").textContent=(n==null?void 0:n.name)??"";const r=new Map,s=new Map([...q.chain.transactions.keys()].map((a,c)=>[a,c])),o=(a,c)=>r.set(a,[...r.get(a)??[],c]);for(const a of z.log)a.roots.includes(I.holding)&&o(a.pending?"cued":a.beat,{e:a,at:s.get(a.id.slice(0,-2))??0});for(const a of De.ledger)[a.to,a.from].some(c=>{var u;return c&&((u=X(c))==null?void 0:u.root)===I.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 D("timeline-list").replaceChildren(A("li",{class:"wait",text:n?"Nothing yet.":"Found a holding to start its timeline."}));D("timeline-list").replaceChildren(...i.map(a=>{const c=a==="cued"?null:q.chain.blocks[a-1],u=I.beat!==null&&(a==="cued"||a>I.beat),l=I.beat!==null&&a===I.beat;return A("li",{class:`beat${u?" later":""}${l?" now":""}`},A("p",{class:"bh"},A("span",{class:"bn",text:a==="cued"?"Cued":`Beat ${a}`}),A("span",{class:"bt",text:c?PE(c.time):q.clock.tempo==="manual"?"waiting for Beat now":"landing on the next beat"})),A("ol",{class:"evs"},r.get(a).sort((f,d)=>f.at-d.at).map(({e:f,m:d})=>d?dk(d):lk(f))))}))}function lk(e){const[t,...n]=kh(e,z).split(" ");return A("li",{},A("button",{type:"button",class:`ev${e.ok?"":" bad"}${e.id===I.event?" on":""}`,"aria-pressed":String(e.id===I.event),onclick:()=>Lr({event:e.id,node:e.node??I.node})},A("span",{class:"op",text:e.ok?t:`✕ ${t.replace(/:$/,"")}`})," ",A("span",{class:"es",text:n.join(" ")})))}const dk=e=>A("li",{},A("button",{type:"button",class:`ev money${e.kind==="gas"?" gas":""}${e.kind==="deal"?" deal":""}${e.key===I.tx?" on":""}`,"aria-pressed":String(e.key===I.tx),onclick:()=>{var t;return Lr({tx:e.key,node:((t=X(e.to))==null?void 0:t.root)===I.holding?e.to:I.node})}},A("span",{class:"op",text:e.kind})," ",A("span",{class:"es",text:w0(e)})));D("f-found").addEventListener("submit",async e=>{e.preventDefault();const t=e.currentTarget,n=qo(t.elements.name.value);if(!n)return be("Name the holding: lowercase letters, digits and hyphens.",!0);await Tn("found",null,{name:n},(r,s)=>(Kc({holding:r,node:r}),`${n} is founded, ${s}.`))&&t.reset()});D("sample").addEventListener("click",async()=>{let e=null;be("Rehearsing the yolopreneur tree over six beats…"),await ft(t=>{e=CE(t)})&&(Lr({holding:e,node:e}),be("Loaded the yolopreneur sample: six beats of history, ending on lineage's open offer for sol's launch-kit. Press Replay to watch it grow."))});D("f-birth").addEventListener("submit",async e=>{e.preventDefault();const t=e.currentTarget,n=X(I.node),r=qo(t.elements.name.value),s=t.elements.kind.value;if(!r)return be("Name the child: lowercase letters, digits and hyphens.",!0);await Tn("birth",n.id,{name:r,kind:s},(o,i)=>`${r} is born to ${n.name}, ${i}.`)&&(t.elements.name.value="")});D("f-award").addEventListener("submit",async e=>{e.preventDefault();const t=e.currentTarget,n=X(I.node),r=t.elements.to.value,s=qo(t.elements.skill.value),o=t.elements.belt.value;if(!s)return be("Name the skill, for example launch.",!0);await Tn("award",n.id,{to:r,skill:s,belt:o},(i,a)=>{var c;return`${(c=X(r))==null?void 0:c.name} holds a ${o} belt in ${s}, ${a}.`})&&(t.elements.skill.value="")});D("f-decide").addEventListener("submit",async e=>{e.preventDefault();const t=e.currentTarget,n=X(I.node),r=t.elements.title.value.trim(),s=t.elements.why.value.trim();if(!r)return be("A decision needs a title.",!0);await Tn("decide",n.id,{title:r,why:s},(o,i)=>`${n.name} decided “${r}”, ${i}.`)&&t.reset()});D("f-send").addEventListener("submit",async e=>{var a;e.preventDefault();const t=e.currentTarget,n=X(I.node),r=t.elements.to.value,s=$c(t.elements.amount.value);if(s===null)return be("Write an amount in test BTC, for example 1.5 (at most eight decimals).",!0);let o=null;if(!await ft(c=>{o=_E(c,n.id,r,s)}))return;const i=De.ledger.find(c=>c.txid===o);be(`${n.name} sent ${ce(s)} to ${((a=X(r))==null?void 0:a.root)===n.root?X(r).name:Ar(z,r)}, ${i!=null&&i.beat?`at beat ${i.beat}`:"cued for the next beat"}.`),t.elements.amount.value=""});D("f-make").addEventListener("submit",async e=>{e.preventDefault();const t=e.currentTarget,n=X(I.node),r=qo(t.elements.name.value),s=t.elements.note.value.trim();if(!r)return be("Name the item: lowercase letters, digits and hyphens.",!0);await Tn("make",n.id,{name:r,note:s},(o,i)=>`${n.name} made ${r}, ${i}.`)&&t.reset()});D("f-keyring").addEventListener("submit",async e=>{e.preventDefault();const t=X(I.node);await Tn("keyring",t.id,{},(n,r)=>`${t.name} published its keyring, ${r}: four keys, each signing the same statement.`)});D("f-offer").addEventListener("submit",async e=>{e.preventDefault();const t=e.currentTarget,n=X(I.node),r=D("offer-item").value,s=$c(t.elements.price.value);if(s===null)return be("Write a price in test BTC, for example 0.1, or 0 for a free claim.",!0);const o=Bt(gn.get(r)),i=_n(r);await ft(a=>{AE(a,r,n.id,s)})&&(be(`${n.name} offers ${s?ce(s):"nothing"} for ${i}. The offer stands until ${o} accepts it.`),t.elements.price.value="")});D("send-max").addEventListener("click",()=>{const e=X(I.node),t=e&&$e(q.keys,z,e);t&&(D("send-amount").value=Lh(Bc(q.chain.coins(t.script))))});D("f-graduate").addEventListener("submit",async e=>{e.preventDefault();const t=X(I.node),n=X(t.parent);await Tn("graduate",n.id,{of:t.id},(r,s)=>(Kc({node:t.id}),`${t.name} graduates from ${n.name}, ${s}. It's a holding of its own now.`))});D("f-close").addEventListener("submit",async e=>{e.preventDefault();const t=X(I.node);if(I.closing!==t.id)return I.closing=t.id,ti(),D("close-go").focus();I.closing=null,await Tn("close",t.id,{},(n,r)=>`${t.name} is closed, ${r}.`)});D("close-keep").addEventListener("click",()=>{I.closing=null,ti(),D("close-go").focus()});for(const e of document.querySelectorAll("[data-verb]"))e.addEventListener("click",()=>{I.verb=e.dataset.verb,I.closing=null,ti()});for(const e of document.querySelectorAll("[data-rule]"))e.addEventListener("click",async()=>{const t=e.dataset.rule;await ft(n=>mE(n,t))&&be({split:"Each beat splits across the holdings that mine, by hashrate.",last:"Each beat goes whole to the holding that acts.",none:"Mainnet: no holding mines. Beats pay the lab wallet, and you fund holdings from it."}[t])});D("f-fund").addEventListener("submit",async e=>{var i;e.preventDefault();const t=e.currentTarget,n=t.elements.to.value,r=$c(t.elements.amount.value);if(r===null)return be("Write an amount in test BTC, for example 5 (at most eight decimals).",!0);let s=null;if(!await ft(a=>{s=IE(a,n,r)}))return;const o=De.ledger.find(a=>a.txid===s);be(`The lab wallet funded ${(i=X(n))==null?void 0:i.name} with ${ce(r)}, ${o!=null&&o.beat?`at beat ${o.beat}`:"cued for the next beat"}.`),t.elements.amount.value=""});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 ft(r=>wE(r,n,Date.now(),Qo(r,jc(r)??I.holding)))&&be(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.`)});D("beat-now").addEventListener("click",()=>c0(e=>{vt(e,Qo(e,jc(e)??I.holding))}));setInterval(()=>{u0();const{tempo:e,nextAt:t}=q.clock;I.busy||document.hidden||typeof e!="number"||!q.chain.mempool.length||t&&Date.now()xE(n,Date.now(),Qo(n,jc(n)??I.holding)))},1e3);addEventListener("storage",e=>{(e.key===Xo||e.key===null)&&a0()});function As(){I.replay&&(clearInterval(I.replay),I.replay=null,Mc())}function hk(){const e=X(I.holding);if(!(!e||!tt())){if(Oo(typeof e.born=="number"?e.born:tt()),I.beat===null)return be("Nothing to replay yet: this holding has one beat of history.");I.replay=setInterval(()=>{(I.beat===null||I.beat+1>=tt())&&As(),Oo(I.beat===null?tt():I.beat+1)},800),Mc()}}D("beat").addEventListener("input",e=>{As(),Oo(Number(e.target.value))});D("replay").addEventListener("click",()=>I.replay?As():hk());for(const e of["to-now","past-now"])D(e).addEventListener("click",()=>{As(),Oo(tt())});const Li=["system","light","dark"],x0=()=>{D("theme").textContent=`Theme: ${document.documentElement.dataset.theme??"system"}`};D("theme").addEventListener("click",()=>{const e=Li[(Li.indexOf(document.documentElement.dataset.theme??"system")+1)%Li.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{}x0()});function v0(e,t,n){const r=D("confirm");r.replaceChildren(A("span",{text:e}),A("button",{type:"button",class:"btn sm danger",text:t,onclick:()=>{r.hidden=!0,n()}}),A("button",{type:"button",class:"btn sm",text:"Cancel",onclick:()=>{r.hidden=!0}})),r.hidden=!1,r.querySelector("button").focus()}const pk={read:()=>{try{return Uc()}catch{return _s()}}};async function E0(e,t){As(),await ft(n=>{Object.assign(n,e())},pk)&&(Object.assign(I,{holding:null,node:null,event:null,tx:null,beat:null,closing:null}),Dc(),be(t))}D("save").addEventListener("click",()=>{const e=A("a",{href:URL.createObjectURL(new Blob([Jh(q)],{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),be("Saved a backup of this lab, test wallet included. Load it in any browser to carry on.")});D("load").addEventListener("click",()=>D("load-file").click());D("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=Xh(await t.text())}catch(s){return be(`${t.name} is not an Orgchain lab: ${s.message}`,!0)}v0(`Replace this browser's lab with ${t.name}?`,"Replace",()=>E0(()=>n,`Loaded ${t.name}.`))});D("reset").addEventListener("click",()=>v0("Erase this browser's lab: every holding, the chain and the test wallet?","Erase",()=>E0(_s,"Erased. This is a fresh lab.")));x0();a0(); diff --git a/ventures/lineage/orgchain/assets/index-DXb8Kdrd.js b/ventures/lineage/orgchain/assets/index-DXb8Kdrd.js new file mode 100644 index 0000000..1cf9eb1 --- /dev/null +++ b/ventures/lineage/orgchain/assets/index-DXb8Kdrd.js @@ -0,0 +1,2065 @@ +(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 ro=5e9,Yc=2**52,uf=(e,t)=>[[Yc+e*ro,Yc+e*ro+t]];function ff(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 lf(e,t){var n;return(n=ff(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=ff(s,o,Number(i.value));return o+=Number(i.value),a})}function Di(e){if(!Number.isSafeInteger(e)||e<0)throw new Error(`Wrong positive integer: ${e}`)}function O0(e){if(typeof e!="boolean")throw new Error(`Expected boolean, not ${e}`)}function hf(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 C0(e){if(typeof e!="function"||typeof e.create!="function")throw new Error("Hash should be wrapped by utils.wrapConstructor");Di(e.outputLen),Di(e.blockLen)}function P0(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 U0(e,t){hf(e);const n=t.outputLen;if(e.lengthnew DataView(e.buffer,e.byteOffset,e.byteLength),kt=(e,t)=>e<<32-t|e>>>t,L0=new Uint8Array(new Uint32Array([287454020]).buffer)[0]===68;if(!L0)throw new Error("Non little-endian hardware is not supported");Array.from({length:256},(e,t)=>t.toString(16).padStart(2,"0"));function R0(e){if(typeof e!="string")throw new TypeError(`utf8ToBytes expected string, got ${typeof e}`);return new TextEncoder().encode(e)}function pf(e){if(typeof e=="string"&&(e=R0(e)),!(e instanceof Uint8Array))throw new TypeError(`Expected input type is Uint8Array (got ${typeof e})`);return e}let H0=class{clone(){return this._cloneInto()}};function gf(e){const t=r=>e().update(pf(r)).digest(),n=e();return t.outputLen=n.outputLen,t.blockLen=n.blockLen,t.create=()=>e(),t}function j0(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 K0=class extends H0{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=ci(this.buffer)}update(t){ai.exists(this);const{view:n,buffer:r,blockLen:s}=this;t=pf(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,M0=(e,t,n)=>e&t^e&n^t&n,Z0=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]),Gt=new Uint32Array([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]),Yt=new Uint32Array(64);let mf=class extends K0{constructor(){super(64,32,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 l=0;l<16;l++,n+=4)Yt[l]=t.getUint32(n,!1);for(let l=16;l<64;l++){const d=Yt[l-15],p=Yt[l-2],h=kt(d,7)^kt(d,18)^d>>>3,g=kt(p,17)^kt(p,19)^p>>>10;Yt[l]=g+Yt[l-7]+h+Yt[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=kt(a,6)^kt(a,11)^kt(a,25),p=f+d+D0(a,c,u)+Z0[l]+Yt[l]|0,g=(kt(r,2)^kt(r,13)^kt(r,22))+M0(r,s,o)|0;f=u,u=c,c=a,a=i+p|0,i=o,o=s,s=r,r=p+g|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(){Yt.fill(0)}destroy(){this.set(0,0,0,0,0,0,0,0),this.buffer.fill(0)}},V0=class extends mf{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 Mi=gf(()=>new mf);gf(()=>new V0);function q0(e,t){if(e.length>t)throw new TypeError(`Data is larger than array size: ${e.length} > ${t}`)}function z0(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 F0(e){if(e>Number.MAX_SAFE_INTEGER)throw new TypeError("Number exceeds safe bounds!")}const{getRandomValues:W0}=crypto??globalThis.crypto??window.crypto;function G0(e=32){if(typeof W0=="function")return crypto.getRandomValues(new Uint8Array(e));throw new Error("Crypto module missing getRandomValues!")}function Y0(e,t,n="be"){t===void 0&&(t=e.length),q0(e,t);const r=new Uint8Array(t).fill(0),s=n==="be"?0:t-e.length;return r.set(e,s),r}function yf(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 ep(e,t){const n=bf(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 wf(e){return Mi(Mi(e))}function tp(e){const t=wf(e);return yf([e,t.slice(0,4)])}function np(e){const t=e.slice(0,-4),n=e.slice(-4);if(wf(t).slice(0,4).toString()!==n.toString())throw new Error("Invalid checksum!");return t}const Xc={encode:Q0,decode:ep},xf={encode:e=>{const t=tp(e);return Xc.encode(t,"base58")},decode:e=>{const t=Xc.decode(e,"base58");return np(t)}},vf="qpzry9x8gf2tvdw0s3jn54khce6mua7l",rp=[996825010,642813549,513874426,1027748829,705979059],so=[{version:0,name:"bech32",const:1},{version:1,name:"bech32m",const:734539939}];function Ef(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^=rp[s])}return t}function kf(e){const t=[];let n;for(n=0;n>5);for(t.push(0),n=0;n>5*(5-i)&31);return o}function Sf(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 ip(e,t,n){const r=t.concat(op(e,t,n));let s=e+"1";for(let o=0;oo.version===t[0])??so[0];if(!sp(r,t,s))throw new Error("Checksum verification failed!");return[r,t.slice(0,t.length-6)]}function ap(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 cp(e){const t=e.lastIndexOf("1");return!(t<1||t+7>e.length||e.length>90)}function up(e,t="bc",n=0){const r=[n,...Sf([...e],8,5)],s=so.find(i=>i.version===n)??so[0],o=ip(t,r,s);return _f(o),o}function _f(e){e=e.toLowerCase();const t=e.split("1",1)[0],[n,r]=$f(e),s=Sf(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 fp(e){e=e.toLowerCase();const[t,n]=$f(e);return n[0]}const Af={encode:up,decode:_f,version:fp},Bf="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",Tf="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",lp=new TextEncoder;function If(e,t=!1,n=!0){typeof e=="string"&&(e=lp.encode(e));const r=t?Tf:Bf;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 Of(e,t=!1){const n=t||e.includes("-")||e.includes("_")?Tf.split(""):Bf.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 Cf={encode:If,decode:Of},Pf={encode:e=>If(e,!0,!1),decode:e=>Of(e,!0)},dp=BigInt(0),hp=BigInt(255),Uf=BigInt(256);function pp(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 gp(e,t,n="be"){t===void 0&&(t=pp(e));const r=n==="le",s=new ArrayBuffer(t),o=new DataView(s);let i=r?0:t-1;for(;e>dp;){const a=e&hp,c=Number(a);r?o.setUint8(i++,c):o.setUint8(i--,c),e=(e-a)/Uf}return new Uint8Array(s)}function mp(e){let t=BigInt(0);for(let n=e.length-1;n>=0;n--)t=t*Uf+BigInt(e[n]);return BigInt(t)}function yp(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 wp(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 xp(e,t,n="be"){t===void 0&&(t=wp(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 vp(e){let t=0;for(let n=e.length-1;n>=0;n--)t=t*256+e[n],F0(t);return t}const Ep=new TextEncoder,kp=new TextDecoder;function _a(e){return Ep.encode(e)}function ui(e){return kp.decode(e)}function Sp(e,t){z0(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 $p(e,t,n="le"){t=Sp(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 _a(t)}function Bp(e,t,n){if(e instanceof ArrayBuffer)return new Uint8Array(e);if(e instanceof Uint8Array)return Y0(e,t,n);if(typeof e=="string")return $p(e,t,n);if(typeof e=="bigint")return gp(e,t,n);if(typeof e=="number")return xp(e,t,n);if(typeof e=="boolean")return Uint8Array.of(e?1:0);throw TypeError("Unsupported format:"+typeof e)}var ee;let S=(ee=class extends Uint8Array{static random(t=32){const n=G0(t);return new ee(n,t)}constructor(t,n,r){const s=Bp(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 Cr(this)}toNum(t="be"){const n=t==="be"?this.reverse():this;return vp(n)}toBin(){return bp(this)}toBig(t="be"){const n=t==="be"?this.reverse():this;return mp(n)}toHash(){const t=Mi(this);return new ee(t)}toJson(){const t=ui(this);return JSON.parse(t)}toBech32(t,n=0){return Af.encode(this,t,n)}toStr(){return ui(this)}toHex(){return _p(this)}toBytes(){return new Uint8Array(this)}tob58chk(){return xf.encode(this)}toBase64(){return Cf.encode(this)}toB64url(){return Pf.encode(this)}prepend(t){return ee.join([ee.bytes(t),this])}append(t){return ee.join([this,ee.bytes(t)])}slice(t,n){const r=new Uint8Array(this).slice(t,n);return new ee(r)}subarray(t,n){const r=new Uint8Array(this).subarray(t,n);return new ee(r)}reverse(){const t=new Uint8Array(this).reverse();return new ee(t)}write(t,n){const r=ee.bytes(t);this.set(r,n)}prefixSize(t){const n=ee.varInt(this.length,t);return ee.join([n,this])}static from(t){return new ee(Uint8Array.from(t))}static of(...t){return new ee(Uint8Array.of(...t))}static join(t){const n=t.map(s=>ee.bytes(s)),r=yf(n);return new ee(r)}static varInt(t,n){if(t<253)return ee.num(t,1);if(t<65536)return ee.of(253,...ee.num(t,2,n));if(t<4294967296)return ee.of(254,...ee.num(t,4,n));if(BigInt(t)<0x10000000000000000n)return ee.of(255,...ee.num(t,8,n));throw new Error(`Value is too large: ${t}`)}},ee.num=Tp,ee.big=Op,ee.bin=Ip,ee.raw=Cp,ee.str=Pp,ee.hex=Up,ee.bytes=Np,ee.json=Lp,ee.base64=Rp,ee.b64url=Hp,ee.bech32=jp,ee.b58chk=Kp,ee.encode=_a,ee.decode=ui,ee);function Tp(e,t,n){return new S(e,t,n)}function Ip(e,t,n){return new S(yp(e),t,n)}function Op(e,t,n){return new S(e,t,n)}function Cp(e,t,n){return new S(e,t,n)}function Pp(e,t,n){return new S(_a(e),t,n)}function Up(e,t,n){return new S(e,t,n)}function Np(e,t,n){return new S(e,t,n)}function Lp(e){return new S(Ap(e))}function Rp(e){return new S(Cf.decode(e))}function Hp(e){return new S(Pf.decode(e))}function jp(e){return new S(Af.decode(e))}function Kp(e){return new S(xf.decode(e))}let Cr=class{constructor(t){this.data=S.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 S(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 Nt(e,t){const n=S.bytes(e);if(n.length!==t)throw new Error(`Invalid input size: ${n.hex} !== ${t}`)}function qe(e,t){if(t)throw new Error(e);return!1}function Js(e,...t){const n=S.str(e).digest.raw,r=t.map(s=>S.bytes(s));return S.join([n,n,S.join(r)]).digest}const Nf={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 Dp(e){if(e>186&&e<255)return"OP_SUCCESS"+String(e);for(const[t,n]of Object.entries(Nf))if(n===e)return t;throw new Error("OPCODE not found:"+String(e))}function Mp(e){for(const[t,n]of Object.entries(Nf))if(t===e)return Number(n);throw new Error("OPCODE not found:"+e)}function Zp(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 Vp(e){const r=[];switch(!0){case typeof e!="number":return!1;case e===0:return!0;case r.includes(e):return!1;case(750?S.join(t):new Uint8Array}function qp(e){let t=new Uint8Array;if(typeof e=="string"){if(e.startsWith("OP_"))return S.num(Mp(e),1);Wt(e)?t=S.hex(e):t=S.str(e)}else t=S.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])),S.join([Jc(t.length),t]));if(t.length>oo){const n=zp(t);return Rf(n)}else return S.join([Jc(t.length),t])}function Jc(e){const t=S.num(76,1),n=S.num(77,1);switch(!0){case e<=75:return S.num(e);case(e>75&&e<256):return S.join([t,S.num(e,1,"le")]);case(e>=256&&e<=oo):return S.join([n,S.num(e,2,"le")]);default:throw new Error("Invalid word size:"+e.toString())}}function zp(e){const t=[],n=new Cr(e);for(;n.size>oo;)t.push(n.read(oo));return t.push(n.read(n.size)),t}function Aa(e,t=!1){let n=S.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 Fp(n)}function Fp(e){const t=new Cr(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 Qp(e){if(typeof e!="function"||typeof e.create!="function")throw new Error("Hash should be wrapped by utils.wrapConstructor");Zi(e.outputLen),Zi(e.blockLen)}function eg(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 tg(e,t){Hf(e);const n=t.outputLen;if(e.lengthnew DataView(e.buffer,e.byteOffset,e.byteLength),St=(e,t)=>e<<32-t|e>>>t,rg=new Uint8Array(new Uint32Array([287454020]).buffer)[0]===68;if(!rg)throw new Error("Non little-endian hardware is not supported");Array.from({length:256},(e,t)=>t.toString(16).padStart(2,"0"));function sg(e){if(typeof e!="string")throw new TypeError(`utf8ToBytes expected string, got ${typeof e}`);return new TextEncoder().encode(e)}function Ba(e){if(typeof e=="string"&&(e=sg(e)),!(e instanceof Uint8Array))throw new TypeError(`Expected input type is Uint8Array (got ${typeof e})`);return e}function og(...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(Ba(r)).digest(),n=e();return t.outputLen=n.outputLen,t.blockLen=n.blockLen,t.create=()=>e(),t}function ig(e=32){if(fi&&typeof fi.getRandomValues=="function")return fi.getRandomValues(new Uint8Array(e));throw new Error("crypto.getRandomValues must be defined")}function ag(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 cg=class extends jf{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=li(this.buffer)}update(t){Un.exists(this);const{view:n,buffer:r,blockLen:s}=this;t=Ba(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,fg=(e,t,n)=>e&t^e&n^t&n,lg=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]),Xt=new Uint32Array([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]),Jt=new Uint32Array(64);let Df=class extends cg{constructor(){super(64,32,8,!1),this.A=Xt[0]|0,this.B=Xt[1]|0,this.C=Xt[2]|0,this.D=Xt[3]|0,this.E=Xt[4]|0,this.F=Xt[5]|0,this.G=Xt[6]|0,this.H=Xt[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)Jt[l]=t.getUint32(n,!1);for(let l=16;l<64;l++){const d=Jt[l-15],p=Jt[l-2],h=St(d,7)^St(d,18)^d>>>3,g=St(p,17)^St(p,19)^p>>>10;Jt[l]=g+Jt[l-7]+h+Jt[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=St(a,6)^St(a,11)^St(a,25),p=f+d+ug(a,c,u)+lg[l]+Jt[l]|0,g=(St(r,2)^St(r,13)^St(r,22))+fg(r,s,o)|0;f=u,u=c,c=a,a=i+p|0,i=o,o=s,s=r,r=p+g|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(){Jt.fill(0)}destroy(){this.set(0,0,0,0,0,0,0,0),this.buffer.fill(0)}},dg=class extends Df{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 Mf=Kf(()=>new Df);Kf(()=>new dg);/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */const hg=BigInt(0),Ta=BigInt(1),pg=BigInt(2),Ho=e=>e instanceof Uint8Array,gg=Array.from({length:256},(e,t)=>t.toString(16).padStart(2,"0"));function mr(e){if(!Ho(e))throw new Error("Uint8Array expected");let t="";for(let n=0;nyr(e.toString(16).padStart(t*2,"0")),Vf=(e,t)=>fr(e,t).reverse(),mg=e=>yr(Zf(e));function ot(e,t,n){let r;if(typeof t=="string")try{r=yr(t)}catch(o){throw new Error(`${e} must be valid hex string, got "${t}". Cause: ${o}`)}else if(Ho(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 dt(...e){const t=new Uint8Array(e.reduce((r,s)=>r+s.length,0));let n=0;return e.forEach(r=>{if(!Ho(r))throw new Error("Uint8Array expected");t.set(r,n),n+=r.length}),t}function yg(e,t){if(e.length!==t.length)return!1;for(let n=0;n0n;e>>=Ta,t+=1);return t}const wg=(e,t)=>e>>BigInt(t)&1n,xg=(e,t,n)=>e|(n?Ta:hg)<(pg<new Uint8Array(e),Qc=e=>Uint8Array.from(e);function qf(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=di(e),s=di(e),o=0;const i=()=>{r.fill(1),s.fill(0),o=0},a=(...l)=>n(s,r,...l),c=(l=di())=>{s=a(Qc([0]),l),r=a(),l.length!==0&&(s=a(Qc([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 p;for(;!(p=d(u()));)c();return i(),p}}const vg={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 Pr(e,t,n={}){const r=(s,o,i)=>{const a=vg[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 Eg=Object.freeze({__proto__:null,bitGet:wg,bitLen:bg,bitMask:Ca,bitSet:xg,bytesToHex:mr,bytesToNumberBE:yn,bytesToNumberLE:Oa,concatBytes:dt,createHmacDrbg:qf,ensureBytes:ot,equalBytes:yg,hexToBytes:yr,hexToNumber:Ia,numberToBytesBE:fr,numberToBytesLE:Vf,numberToHexUnpadded:Zf,numberToVarBytesBE:mg,utf8ToBytes:jo,validateObject:Pr});/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */const je=BigInt(0),Oe=BigInt(1),On=BigInt(2),kg=BigInt(3),Vi=BigInt(4),eu=BigInt(5),tu=BigInt(8);BigInt(9);BigInt(16);function ze(e,t){const n=e%t;return n>=je?n:t+n}function Sg(e,t,n){if(n<=je||t 0");if(n===Oe)return je;let r=Oe;for(;t>je;)t&Oe&&(r=r*e%n),e=e*e%n,t>>=Oe;return r}function st(e,t,n){let r=e;for(;t-- >je;)r*=r,r%=n;return r}function qi(e,t){if(e===je||t<=je)throw new Error(`invert: expected positive integers, got n=${e} mod=${t}`);let n=ze(e,t),r=t,s=je,o=Oe;for(;n!==je;){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 ze(s,t)}function $g(e){const t=(e-Oe)/On;let n,r,s;for(n=e-Oe,r=0;n%On===je;n/=On,r++);for(s=On;s(r[s]="function",r),t);return Pr(e,n)}function Bg(e,t,n){if(n 0");if(n===je)return e.ONE;if(n===Oe)return t;let r=e.ONE,s=t;for(;n>je;)n&Oe&&(r=e.mul(r,s)),s=e.sqr(s),n>>=Oe;return r}function Tg(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 Pa(e,t){const n=t!==void 0?t:e.toString(2).length,r=Math.ceil(n/8);return{nBitLength:n,nByteLength:r}}function Ff(e,t,n=!1,r={}){if(e<=je)throw new Error(`Expected Fp ORDER > 0, got ${e}`);const{nBitLength:s,nByteLength:o}=Pa(e,t);if(o>2048)throw new Error("Field lengths over 2048 bytes are not supported");const i=_g(e),a=Object.freeze({ORDER:e,BITS:s,BYTES:o,MASK:Ca(s),ZERO:je,ONE:Oe,create:c=>ze(c,e),isValid:c=>{if(typeof c!="bigint")throw new Error(`Invalid field element: expected bigint, got ${typeof c}`);return je<=c&&cc===je,isOdd:c=>(c&Oe)===Oe,neg:c=>ze(-c,e),eql:(c,u)=>c===u,sqr:c=>ze(c*c,e),add:(c,u)=>ze(c+u,e),sub:(c,u)=>ze(c-u,e),mul:(c,u)=>ze(c*u,e),pow:(c,u)=>Bg(a,c,u),div:(c,u)=>ze(c*qi(u,e),e),sqrN:c=>c*c,addN:(c,u)=>c+u,subN:(c,u)=>c-u,mulN:(c,u)=>c*u,inv:c=>qi(c,e),sqrt:r.sqrt||(c=>i(a,c)),invertBatch:c=>Tg(a,c),cmov:(c,u,f)=>f?u:c,toBytes:c=>n?Vf(c,o):fr(c,o),fromBytes:c=>{if(c.length!==o)throw new Error(`Fp.fromBytes: expected ${o}, got ${c.length}`);return n?Oa(c):yn(c)}});return Object.freeze(a)}function Ig(e,t,n=!1){e=ot("privateHash",e);const r=e.length,s=Pa(t).nByteLength+8;if(s<24||r1024)throw new Error(`hashToPrivateScalar: expected ${s}-1024 bytes of input, got ${r}`);const o=n?Oa(e):yn(e);return ze(o,t-Oe)+Oe}/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */const Og=BigInt(0),hi=BigInt(1);function Cg(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>Og;)o&hi&&(i=i.add(a)),a=a.double(),o>>=hi;return i},precomputeWindow(s,o){const{windows:i,windowSize:a}=r(o),c=[];let u=s,f=u;for(let l=0;l>=p,m>c&&(m-=d,i+=hi);const b=g,w=g+Math.abs(m)-1,y=h%2!==0,x=m<0;m===0?f=f.add(n(y,o[b])):u=u.add(n(x,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 Wf(e){return zf(e.Fp),Pr(e,{n:"bigint",h:"bigint",Gx:"field",Gy:"field"},{nBitLength:"isSafeInteger",nByteLength:"isSafeInteger"}),Object.freeze({...Pa(e.n,e.nBitLength),...e,p:e.Fp.ORDER})}/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */function Pg(e){const t=Wf(e);Pr(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:Ug,hexToBytes:Ng}=Eg,Nn={Err:class extends Error{constructor(t=""){super(t)}},_parseInt(e){const{Err:t}=Nn;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:Ug(r),l:e.subarray(n+2)}},toSig(e){const{Err:t}=Nn,n=typeof e=="string"?Ng(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}=Nn._parseInt(n.subarray(2)),{d:i,l:a}=Nn._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}`}},ht=BigInt(0),Ue=BigInt(1),Ht=BigInt(2),io=BigInt(3),nu=BigInt(4);function Lg(e){const t=Pg(e),{Fp:n}=t,r=t.toBytes||((h,g,m)=>{const b=g.toAffine();return dt(Uint8Array.from([4]),n.toBytes(b.x),n.toBytes(b.y))}),s=t.fromBytes||(h=>{const g=h.subarray(1),m=n.fromBytes(g.subarray(0,n.BYTES)),b=n.fromBytes(g.subarray(n.BYTES,2*n.BYTES));return{x:m,y:b}});function o(h){const{a:g,b:m}=t,b=n.sqr(h),w=n.mul(b,h);return n.add(n.add(w,n.mul(h,g)),m)}function i(h){return typeof h=="bigint"&&htn.eql(y,n.ZERO);return w(m)&&w(b)?l.ZERO:new l(m,b,n.ONE)}get x(){return this.toAffine().x}get y(){return this.toAffine().y}static normalizeZ(g){const m=n.invertBatch(g.map(b=>b.pz));return g.map((b,w)=>b.toAffine(m[w])).map(l.fromAffine)}static fromHex(g){const m=l.fromAffine(s(ot("pointHex",g)));return m.assertValidity(),m}static fromPrivateKey(g){return l.BASE.multiply(c(g))}_setWindowSize(g){this._WINDOW_SIZE=g,u.delete(this)}assertValidity(){if(this.is0()){if(t.allowInfinityPoint)return;throw new Error("bad point: ZERO")}const{x:g,y:m}=this.toAffine();if(!n.isValid(g)||!n.isValid(m))throw new Error("bad point: x or y not FE");const b=n.sqr(m),w=o(g);if(!n.eql(b,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:g}=this.toAffine();if(n.isOdd)return!n.isOdd(g);throw new Error("Field doesn't support isOdd")}equals(g){f(g);const{px:m,py:b,pz:w}=this,{px:y,py:x,pz:$}=g,E=n.eql(n.mul(m,$),n.mul(y,w)),I=n.eql(n.mul(b,$),n.mul(x,w));return E&&I}negate(){return new l(this.px,n.neg(this.py),this.pz)}double(){const{a:g,b:m}=t,b=n.mul(m,io),{px:w,py:y,pz:x}=this;let $=n.ZERO,E=n.ZERO,I=n.ZERO,P=n.mul(w,w),B=n.mul(y,y),U=n.mul(x,x),L=n.mul(w,y);return L=n.add(L,L),I=n.mul(w,x),I=n.add(I,I),$=n.mul(g,I),E=n.mul(b,U),E=n.add($,E),$=n.sub(B,E),E=n.add(B,E),E=n.mul($,E),$=n.mul(L,$),I=n.mul(b,I),U=n.mul(g,U),L=n.sub(P,U),L=n.mul(g,L),L=n.add(L,I),I=n.add(P,P),P=n.add(I,P),P=n.add(P,U),P=n.mul(P,L),E=n.add(E,P),U=n.mul(y,x),U=n.add(U,U),P=n.mul(U,L),$=n.sub($,P),I=n.mul(U,B),I=n.add(I,I),I=n.add(I,I),new l($,E,I)}add(g){f(g);const{px:m,py:b,pz:w}=this,{px:y,py:x,pz:$}=g;let E=n.ZERO,I=n.ZERO,P=n.ZERO;const B=t.a,U=n.mul(t.b,io);let L=n.mul(m,y),D=n.mul(b,x),k=n.mul(w,$),_=n.add(m,b),v=n.add(y,x);_=n.mul(_,v),v=n.add(L,D),_=n.sub(_,v),v=n.add(m,w);let A=n.add(y,$);return v=n.mul(v,A),A=n.add(L,k),v=n.sub(v,A),A=n.add(b,w),E=n.add(x,$),A=n.mul(A,E),E=n.add(D,k),A=n.sub(A,E),P=n.mul(B,v),E=n.mul(U,k),P=n.add(E,P),E=n.sub(D,P),P=n.add(D,P),I=n.mul(E,P),D=n.add(L,L),D=n.add(D,L),k=n.mul(B,k),v=n.mul(U,v),D=n.add(D,k),k=n.sub(L,k),k=n.mul(B,k),v=n.add(v,k),L=n.mul(D,v),I=n.add(I,L),L=n.mul(A,v),E=n.mul(_,E),E=n.sub(E,L),L=n.mul(_,D),P=n.mul(A,P),P=n.add(P,L),new l(E,I,P)}subtract(g){return this.add(g.negate())}is0(){return this.equals(l.ZERO)}wNAF(g){return p.wNAFCached(this,u,g,m=>{const b=n.invertBatch(m.map(w=>w.pz));return m.map((w,y)=>w.toAffine(b[y])).map(l.fromAffine)})}multiplyUnsafe(g){const m=l.ZERO;if(g===ht)return m;if(a(g),g===Ue)return this;const{endo:b}=t;if(!b)return p.unsafeLadder(this,g);let{k1neg:w,k1:y,k2neg:x,k2:$}=b.splitScalar(g),E=m,I=m,P=this;for(;y>ht||$>ht;)y&Ue&&(E=E.add(P)),$&Ue&&(I=I.add(P)),P=P.double(),y>>=Ue,$>>=Ue;return w&&(E=E.negate()),x&&(I=I.negate()),I=new l(n.mul(I.px,b.beta),I.py,I.pz),E.add(I)}multiply(g){a(g);let m=g,b,w;const{endo:y}=t;if(y){const{k1neg:x,k1:$,k2neg:E,k2:I}=y.splitScalar(m);let{p:P,f:B}=this.wNAF($),{p:U,f:L}=this.wNAF(I);P=p.constTimeNegate(x,P),U=p.constTimeNegate(E,U),U=new l(n.mul(U.px,y.beta),U.py,U.pz),b=P.add(U),w=B.add(L)}else{const{p:x,f:$}=this.wNAF(m);b=x,w=$}return l.normalizeZ([b,w])[0]}multiplyAndAddUnsafe(g,m,b){const w=l.BASE,y=($,E)=>E===ht||E===Ue||!$.equals(w)?$.multiplyUnsafe(E):$.multiply(E),x=y(this,m).add(y(g,b));return x.is0()?void 0:x}toAffine(g){const{px:m,py:b,pz:w}=this,y=this.is0();g==null&&(g=y?n.ONE:n.inv(w));const x=n.mul(m,g),$=n.mul(b,g),E=n.mul(w,g);if(y)return{x:n.ZERO,y:n.ZERO};if(!n.eql(E,n.ONE))throw new Error("invZ was invalid");return{x,y:$}}isTorsionFree(){const{h:g,isTorsionFree:m}=t;if(g===Ue)return!0;if(m)return m(l,this);throw new Error("isTorsionFree() has not been declared for the elliptic curve")}clearCofactor(){const{h:g,clearCofactor:m}=t;return g===Ue?this:m?m(l,this):this.multiplyUnsafe(t.h)}toRawBytes(g=!0){return this.assertValidity(),r(l,this,g)}toHex(g=!0){return mr(this.toRawBytes(g))}}l.BASE=new l(t.Gx,t.Gy,n.ONE),l.ZERO=new l(n.ZERO,n.ONE,n.ZERO);const d=t.nBitLength,p=Cg(l,t.endo?Math.ceil(d/2):d);return{CURVE:t,ProjectivePoint:l,normPrivateKeyToScalar:c,weierstrassEquation:o,isWithinCurveOrder:i}}function Rg(e){const t=Wf(e);return Pr(t,{hash:"hash",hmac:"function",randomBytes:"function"},{bits2int:"function",bits2int_modN:"function",lowS:"boolean"}),Object.freeze({lowS:!0,...t})}function Hg(e){const t=Rg(e),{Fp:n,n:r}=t,s=n.BYTES+1,o=2*n.BYTES+1;function i(v){return htmr(fr(v,t.nByteLength));function h(v){const A=r>>Ue;return v>A}function g(v){return h(v)?a(-v):v}const m=(v,A,C)=>yn(v.slice(A,C));class b{constructor(A,C,R){this.r=A,this.s=C,this.recovery=R,this.assertValidity()}static fromCompact(A){const C=t.nByteLength;return A=ot("compactSignature",A,C*2),new b(m(A,0,C),m(A,C,2*C))}static fromDER(A){const{r:C,s:R}=Nn.toSig(ot("DER",A));return new b(C,R)}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(A){return new b(this.r,this.s,A)}recoverPublicKey(A){const{r:C,s:R,recovery:N}=this,j=I(ot("msgHash",A));if(N==null||![0,1,2,3].includes(N))throw new Error("recovery id invalid");const M=N===2||N===3?C+t.n:C;if(M>=n.ORDER)throw new Error("recovery id 2 or 3 invalid");const F=(N&1)===0?"02":"03",ue=u.fromHex(F+p(M)),oe=c(M),Q=a(-j*oe),he=a(R*oe),pe=u.BASE.multiplyAndAddUnsafe(ue,Q,he);if(!pe)throw new Error("point at infinify");return pe.assertValidity(),pe}hasHighS(){return h(this.s)}normalizeS(){return this.hasHighS()?new b(this.r,a(-this.s),this.recovery):this}toDERRawBytes(){return yr(this.toDERHex())}toDERHex(){return Nn.hexFromSig({r:this.r,s:this.s})}toCompactRawBytes(){return yr(this.toCompactHex())}toCompactHex(){return p(this.r)+p(this.s)}}const w={isValidPrivateKey(v){try{return f(v),!0}catch{return!1}},normPrivateKeyToScalar:f,randomPrivateKey:()=>{const v=t.randomBytes(n.BYTES+8),A=Ig(v,r);return fr(A,t.nByteLength)},precompute(v=8,A=u.BASE){return A._setWindowSize(v),A.multiply(BigInt(3)),A}};function y(v,A=!0){return u.fromPrivateKey(v).toRawBytes(A)}function x(v){const A=v instanceof Uint8Array,C=typeof v=="string",R=(A||C)&&v.length;return A?R===s||R===o:C?R===2*s||R===2*o:v instanceof u}function $(v,A,C=!0){if(x(v))throw new Error("first arg must be private key");if(!x(A))throw new Error("second arg must be public key");return u.fromHex(A).multiply(f(v)).toRawBytes(C)}const E=t.bits2int||function(v){const A=yn(v),C=v.length*8-t.nBitLength;return C>0?A>>BigInt(C):A},I=t.bits2int_modN||function(v){return a(E(v))},P=Ca(t.nBitLength);function B(v){if(typeof v!="bigint")throw new Error("bigint expected");if(!(ht<=v&&vfe in C))throw new Error("sign() legacy options not supported");const{hash:R,randomBytes:N}=t;let{lowS:j,prehash:M,extraEntropy:F}=C;j==null&&(j=!0),v=ot("msgHash",v),M&&(v=ot("prehashed msgHash",R(v)));const ue=I(v),oe=f(A),Q=[B(oe),B(ue)];if(F!=null){const fe=F===!0?N(n.BYTES):F;Q.push(ot("extraEntropy",fe,n.BYTES))}const he=dt(...Q),pe=ue;function Ie(fe){const we=E(fe);if(!d(we))return;const Lt=c(we),rt=u.BASE.multiply(we).toAffine(),De=a(rt.x);if(De===ht)return;const Rt=a(Lt*a(pe+De*oe));if(Rt===ht)return;let jr=(rt.x===De?0:2)|Number(rt.y&Ue),Gc=Rt;return j&&h(Rt)&&(Gc=g(Rt),jr^=1),new b(De,Gc,jr)}return{seed:he,k2sig:Ie}}const L={lowS:t.lowS,prehash:!1},D={lowS:t.lowS,prehash:!1};function k(v,A,C=L){const{seed:R,k2sig:N}=U(v,A,C);return qf(t.hash.outputLen,t.nByteLength,t.hmac)(R,N)}u.BASE._setWindowSize(8);function _(v,A,C,R=D){var rt;const N=v;if(A=ot("msgHash",A),C=ot("publicKey",C),"strict"in R)throw new Error("options.strict was renamed to lowS");const{lowS:j,prehash:M}=R;let F,ue;try{if(typeof N=="string"||N instanceof Uint8Array)try{F=b.fromDER(N)}catch(De){if(!(De instanceof Nn.Err))throw De;F=b.fromCompact(N)}else if(typeof N=="object"&&typeof N.r=="bigint"&&typeof N.s=="bigint"){const{r:De,s:Rt}=N;F=new b(De,Rt)}else throw new Error("PARSE");ue=u.fromHex(C)}catch(De){if(De.message==="PARSE")throw new Error("signature must be Signature instance, Uint8Array or hex string");return!1}if(j&&F.hasHighS())return!1;M&&(A=t.hash(A));const{r:oe,s:Q}=F,he=I(A),pe=c(Q),Ie=a(he*pe),fe=a(oe*pe),we=(rt=u.BASE.multiplyAndAddUnsafe(ue,Ie,fe))==null?void 0:rt.toAffine();return we?a(we.x)===oe:!1}return{CURVE:t,getPublicKey:y,getSharedSecret:$,sign:k,verify:_,ProjectivePoint:u,Signature:b,utils:w}}function jg(e,t){const n=e.ORDER;let r=ht;for(let d=n-Ue;d%Ht===ht;d/=Ht)r+=Ue;const s=r,o=(n-Ue)/Ht**s,i=(o-Ue)/Ht,a=Ht**s-Ue,c=Ht**(s-Ue),u=e.pow(t,o),f=e.pow(t,(o+Ue)/Ht);let l=(d,p)=>{let h=u,g=e.pow(p,a),m=e.sqr(g);m=e.mul(m,p);let b=e.mul(d,m);b=e.pow(b,i),b=e.mul(b,g),g=e.mul(b,p),m=e.mul(b,d);let w=e.mul(m,g);b=e.pow(w,c);let y=e.eql(b,e.ONE);g=e.mul(m,f),b=e.mul(w,h),m=e.cmov(g,m,y),w=e.cmov(b,w,y);for(let x=s;x>1;x--){let $=Ht**(x-Ht),E=e.pow(w,$);const I=e.eql(E,e.ONE);g=e.mul(m,h),h=e.mul(h,h),E=e.mul(w,h),m=e.cmov(g,m,I),w=e.cmov(E,w,I)}return{isValid:y,value:m}};if(e.ORDER%nu===io){const d=(e.ORDER-io)/nu,p=e.sqrt(e.neg(t));l=(h,g)=>{let m=e.sqr(g);const b=e.mul(h,g);m=e.mul(m,b);let w=e.pow(m,d);w=e.mul(w,b);const y=e.mul(w,p),x=e.mul(e.sqr(w),g),$=e.eql(x,h);let E=e.cmov(y,w,$);return{isValid:$,value:E}}}return l}function Kg(e,t){if(zf(e),!e.isValid(t.A)||!e.isValid(t.B)||!e.isValid(t.Z))throw new Error("mapToCurveSimpleSWU: invalid opts");const n=jg(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:p}=n(o,u);l=e.mul(s,r),l=e.mul(l,p),f=e.cmov(f,i,d),l=e.cmov(l,p,d);const h=e.isOdd(r)===e.isOdd(l);return l=e.cmov(e.neg(l),l,h),f=e.div(f,a),{x:f,y:l}}}function Dg(e){if(e instanceof Uint8Array)return e;if(typeof e=="string")return jo(e);throw new Error("DST must be Uint8Array or string")}const Mg=yn;function ln(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 Zg(e,t){const n=new Uint8Array(e.length);for(let r=0;r255&&(t=r(dt(jo("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=dt(t,ln(t.length,1)),c=ln(0,o),u=ln(n,2),f=new Array(i),l=r(dt(c,e,u,ln(0,1),a));f[0]=r(dt(l,ln(1,1),a));for(let p=1;p<=i;p++){const h=[Zg(l,f[p-1]),ln(p+1,1),a];f[p]=r(dt(...h))}return dt(...f).slice(0,n)}function qg(e,t,n,r,s){if(Jr(e),Jr(t),Ua(n),t.length>255){const o=Math.ceil(2*r/8);t=s.create({dkLen:o}).update(jo("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(ln(n,2)).update(t).update(ln(t.length,1)).digest()}function ru(e,t,n){Pr(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;Jr(e),Ua(t);const u=Dg(c),f=r.toString(2).length,l=Math.ceil((f+s)/8),d=t*o*l;let p;if(a==="xmd")p=Vg(e,u,d,i);else if(a==="xof")p=qg(e,u,d,s,i);else if(a===void 0)p=e;else throw new Error('expand must be "xmd", "xof" or undefined');const h=new Array(t);for(let g=0;gArray.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 Fg(e,t,n){if(typeof t!="function")throw new Error("mapToCurve() must be defined");return{hashToCurve(r,s){const o=ru(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=ru(r,1,{...n,DST:n.encodeDST,...s}),i=e.fromAffine(t(o[0])).clearCofactor();return i.assertValidity(),i}}}let Gf=class extends jf{constructor(t,n){super(),this.finished=!1,this.destroyed=!1,Un.hash(t);const r=Ba(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 Gf(e,t).update(n).digest();Yf.create=(e,t)=>new Gf(e,t);/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */function Wg(e){return{hash:e,hmac:(t,...n)=>Yf(e,t,og(...n)),randomBytes:ig}}function Gg(e,t){const n=r=>Hg({...e,...Wg(r)});return Object.freeze({...n(t),create:n})}/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */const Xf=BigInt("0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f"),su=BigInt("0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141"),Yg=BigInt(1),zi=BigInt(2),ou=(e,t)=>(e+t/zi)/t;function Xg(e){const t=Xf,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=st(f,n,t)*f%t,d=st(l,n,t)*f%t,p=st(d,zi,t)*u%t,h=st(p,s,t)*p%t,g=st(h,o,t)*h%t,m=st(g,a,t)*g%t,b=st(m,c,t)*m%t,w=st(b,a,t)*g%t,y=st(w,n,t)*f%t,x=st(y,i,t)*h%t,$=st(x,r,t)*u%t,E=st($,zi,t);if(!wn.eql(wn.sqr(E),e))throw new Error("Cannot find square root");return E}const wn=Ff(Xf,void 0,void 0,{sqrt:Xg}),qt=Gg({a:BigInt(0),b:BigInt(7),Fp:wn,n:su,Gx:BigInt("55066263022277343669578718895168534326250603453777594175500187360389116729240"),Gy:BigInt("32670510020758816978083085130507043184471273380659243275938904335757337482424"),h:BigInt(1),lowS:!0,endo:{beta:BigInt("0x7ae96a2b657c07106e64479eac3434e99cf0497512f58995c1396c28719501ee"),splitScalar:e=>{const t=su,n=BigInt("0x3086d221a7d46bcde86c90e49284eb15"),r=-Yg*BigInt("0xe4437ed6010e88286f547fa90abfe4c3"),s=BigInt("0x114ca50f7a8e2f3f657c1108d9d44cfd8"),o=n,i=BigInt("0x100000000000000000000000000000000"),a=ou(o*e,t),c=ou(-r*e,t);let u=ze(e-a*n-c*s,t),f=ze(-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}}}},Mf);BigInt(0);qt.ProjectivePoint;qt.utils.randomPrivateKey;const Jg=zg(wn,[["0x8e38e38e38e38e38e38e38e38e38e38e38e38e38e38e38e38e38e38daaaaa8c7","0x7d3d4c80bc321d5b9f315cea7fd44c5d595d2fc0bf63b92dfff1044f17c6581","0x534c328d23f234e6e2a413deca25caece4506144037c40314ecbd0b53d9dd262","0x8e38e38e38e38e38e38e38e38e38e38e38e38e38e38e38e38e38e38daaaaa88c"],["0xd35771193d94918a9ca34ccbb7b640dd86cd409542f8487d9fe6b745781eb49b","0xedadc6f64383dc1df7c4b2d51b54225406d36b641f5e41bbc52a56612a8c6d14","0x0000000000000000000000000000000000000000000000000000000000000001"],["0x4bda12f684bda12f684bda12f684bda12f684bda12f684bda12f684b8e38e23c","0xc75e0c32d5cb7c0fa9d0a54b12a0a6d5647ab046d686da6fdffc90fc201d71a3","0x29a6194691f91a73715209ef6512e576722830a201be2018a765e85a9ecee931","0x2f684bda12f684bda12f684bda12f684bda12f684bda12f684bda12f38e38d84"],["0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffefffff93b","0x7a06534bb8bdb49fd5e9e6632722c2989467c1bfc8e8d978dfb425d2685c2573","0x6484aa716545ca2cf3a70c3fa8fe337e0a3d21162f0d6299a7bf8192bfd2a76f","0x0000000000000000000000000000000000000000000000000000000000000001"]].map(e=>e.map(t=>BigInt(t)))),Qg=Kg(wn,{A:BigInt("0x3f8731abdd661adca08a5558f0f5d272e953d363cb6f0e5d405447c01a444533"),B:BigInt("1771"),Z:wn.create(BigInt("-11"))});Fg(qt.ProjectivePoint,e=>{const{x:t,y:n}=Qg(wn.create(e[0]));return Jg(t,n)},{DST:"secp256k1_XMD:SHA-256_SSWU_RO_",encodeDST:"secp256k1_XMD:SHA-256_SSWU_NU_",p:wn.ORDER,m:1,k:128,expand:"xmd",hash:Mf});function Fi(e){if(!Number.isSafeInteger(e)||e<0)throw new Error(`Wrong positive integer: ${e}`)}function em(e){if(typeof e!="boolean")throw new Error(`Expected boolean, not ${e}`)}function Jf(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 tm(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 nm(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 rm(e,t){Jf(e);const n=t.outputLen;if(e.lengthnew DataView(e.buffer,e.byteOffset,e.byteLength),$t=(e,t)=>e<<32-t|e>>>t,om=new Uint8Array(new Uint32Array([287454020]).buffer)[0]===68;if(!om)throw new Error("Non little-endian hardware is not supported");Array.from({length:256},(e,t)=>t.toString(16).padStart(2,"0"));function im(e){if(typeof e!="string")throw new TypeError(`utf8ToBytes expected string, got ${typeof e}`);return new TextEncoder().encode(e)}function Qf(e){if(typeof e=="string"&&(e=im(e)),!(e instanceof Uint8Array))throw new TypeError(`Expected input type is Uint8Array (got ${typeof e})`);return e}let am=class{clone(){return this._cloneInto()}};function el(e){const t=r=>e().update(Qf(r)).digest(),n=e();return t.outputLen=n.outputLen,t.blockLen=n.blockLen,t.create=()=>e(),t}function cm(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 um=class extends am{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=gi(this.buffer)}update(t){pi.exists(this);const{view:n,buffer:r,blockLen:s}=this;t=Qf(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,lm=(e,t,n)=>e&t^e&n^t&n,dm=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]),Qt=new Uint32Array([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]),en=new Uint32Array(64);let tl=class extends um{constructor(){super(64,32,8,!1),this.A=Qt[0]|0,this.B=Qt[1]|0,this.C=Qt[2]|0,this.D=Qt[3]|0,this.E=Qt[4]|0,this.F=Qt[5]|0,this.G=Qt[6]|0,this.H=Qt[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)en[l]=t.getUint32(n,!1);for(let l=16;l<64;l++){const d=en[l-15],p=en[l-2],h=$t(d,7)^$t(d,18)^d>>>3,g=$t(p,17)^$t(p,19)^p>>>10;en[l]=g+en[l-7]+h+en[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=$t(a,6)^$t(a,11)^$t(a,25),p=f+d+fm(a,c,u)+dm[l]+en[l]|0,g=($t(r,2)^$t(r,13)^$t(r,22))+lm(r,s,o)|0;f=u,u=c,c=a,a=i+p|0,i=o,o=s,s=r,r=p+g|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(){en.fill(0)}destroy(){this.set(0,0,0,0,0,0,0,0),this.buffer.fill(0)}},hm=class extends tl{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 Wi=el(()=>new tl);el(()=>new hm);function pm(e,t){if(e.length>t)throw new TypeError(`Data is larger than array size: ${e.length} > ${t}`)}function gm(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 mm(e){if(e>Number.MAX_SAFE_INTEGER)throw new TypeError("Number exceeds safe bounds!")}const{getRandomValues:ym}=crypto??globalThis.crypto??window.crypto;function bm(e=32){if(typeof ym=="function")return crypto.getRandomValues(new Uint8Array(e));throw new Error("Crypto module missing getRandomValues!")}function wm(e,t,n="be"){t===void 0&&(t=e.length),pm(e,t);const r=new Uint8Array(t).fill(0),s=n==="be"?0:t-e.length;return r.set(e,s),r}function nl(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 km(e,t){const n=rl(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 sl(e){return Wi(Wi(e))}function Sm(e){const t=sl(e);return nl([e,t.slice(0,4)])}function $m(e){const t=e.slice(0,-4),n=e.slice(-4);if(sl(t).slice(0,4).toString()!==n.toString())throw new Error("Invalid checksum!");return t}const iu={encode:Em,decode:km},ol={encode:e=>{const t=Sm(e);return iu.encode(t,"base58")},decode:e=>{const t=iu.decode(e,"base58");return $m(t)}},il="qpzry9x8gf2tvdw0s3jn54khce6mua7l",_m=[996825010,642813549,513874426,1027748829,705979059],ao=[{version:0,name:"bech32",const:1},{version:1,name:"bech32m",const:734539939}];function al(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^=_m[s])}return t}function cl(e){const t=[];let n;for(n=0;n>5);for(t.push(0),n=0;n>5*(5-i)&31);return o}function ul(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 Tm(e,t,n){const r=t.concat(Bm(e,t,n));let s=e+"1";for(let o=0;oo.version===t[0])??ao[0];if(!Am(r,t,s))throw new Error("Checksum verification failed!");return[r,t.slice(0,t.length-6)]}function Im(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 Om(e){const t=e.lastIndexOf("1");return!(t<1||t+7>e.length||e.length>90)}function Cm(e,t="bc",n=0){const r=[n,...ul([...e],8,5)],s=ao.find(i=>i.version===n)??ao[0],o=Tm(t,r,s);return ll(o),o}function ll(e){e=e.toLowerCase();const t=e.split("1",1)[0],[n,r]=fl(e),s=ul(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 Pm(e){e=e.toLowerCase();const[t,n]=fl(e);return n[0]}const dl={encode:Cm,decode:ll,version:Pm},hl="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",pl="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",Um=new TextEncoder;function gl(e,t=!1,n=!0){typeof e=="string"&&(e=Um.encode(e));const r=t?pl:hl;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 ml(e,t=!1){const n=t||e.includes("-")||e.includes("_")?pl.split(""):hl.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 yl={encode:gl,decode:ml},bl={encode:e=>gl(e,!0,!1),decode:e=>ml(e,!0)},Nm=BigInt(0),Lm=BigInt(255),wl=BigInt(256);function Rm(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 Hm(e,t,n="be"){t===void 0&&(t=Rm(e));const r=n==="le",s=new ArrayBuffer(t),o=new DataView(s);let i=r?0:t-1;for(;e>Nm;){const a=e&Lm,c=Number(a);r?o.setUint8(i++,c):o.setUint8(i--,c),e=(e-a)/wl}return new Uint8Array(s)}function jm(e){let t=BigInt(0);for(let n=e.length-1;n>=0;n--)t=t*wl+BigInt(e[n]);return BigInt(t)}function Km(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 Mm(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 Zm(e,t,n="be"){t===void 0&&(t=Mm(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 Vm(e){let t=0;for(let n=e.length-1;n>=0;n--)t=t*256+e[n],mm(t);return t}const qm=new TextEncoder,zm=new TextDecoder;function Na(e){return qm.encode(e)}function mi(e){return zm.decode(e)}function Fm(e,t){gm(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 Wm(e,t,n="le"){t=Fm(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 Na(t)}function Xm(e,t,n){if(e instanceof ArrayBuffer)return new Uint8Array(e);if(e instanceof Uint8Array)return wm(e,t,n);if(typeof e=="string")return Wm(e,t,n);if(typeof e=="bigint")return Hm(e,t,n);if(typeof e=="number")return Zm(e,t,n);if(typeof e=="boolean")return Uint8Array.of(e?1:0);throw TypeError("Unsupported format:"+typeof e)}const re=class re extends Uint8Array{static random(t=32){const n=bm(t);return new re(n,t)}constructor(t,n,r){const s=Xm(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 fy(this)}toNum(t="be"){const n=t==="be"?this.reverse():this;return Vm(n)}toBin(){return Dm(this)}toBig(t="be"){const n=t==="be"?this.reverse():this;return jm(n)}toHash(){const t=Wi(this);return new re(t)}toJson(){const t=mi(this);return JSON.parse(t)}toBech32(t,n=0){return dl.encode(this,t,n)}toStr(){return mi(this)}toHex(){return Gm(this)}toBytes(){return new Uint8Array(this)}tob58chk(){return ol.encode(this)}toBase64(){return yl.encode(this)}toB64url(){return bl.encode(this)}prepend(t){return re.join([re.bytes(t),this])}append(t){return re.join([this,re.bytes(t)])}slice(t,n){const r=new Uint8Array(this).slice(t,n);return new re(r)}subarray(t,n){const r=new Uint8Array(this).subarray(t,n);return new re(r)}reverse(){const t=new Uint8Array(this).reverse();return new re(t)}write(t,n){const r=re.bytes(t);this.set(r,n)}prefixSize(t){const n=re.varInt(this.length,t);return re.join([n,this])}static from(t){return new re(Uint8Array.from(t))}static of(...t){return new re(Uint8Array.of(...t))}static join(t){const n=t.map(s=>re.bytes(s)),r=nl(n);return new re(r)}static varInt(t,n){if(t<253)return re.num(t,1);if(t<65536)return re.of(253,...re.num(t,2,n));if(t<4294967296)return re.of(254,...re.num(t,4,n));if(BigInt(t)<0x10000000000000000n)return re.of(255,...re.num(t,8,n));throw new Error(`Value is too large: ${t}`)}};re.num=Jm,re.big=ey,re.bin=Qm,re.raw=ty,re.str=ny,re.hex=ry,re.bytes=sy,re.json=oy,re.base64=iy,re.b64url=ay,re.bech32=cy,re.b58chk=uy,re.encode=Na,re.decode=mi;let X=re;function Jm(e,t,n){return new X(e,t,n)}function Qm(e,t,n){return new X(Km(e),t,n)}function ey(e,t,n){return new X(e,t,n)}function ty(e,t,n){return new X(e,t,n)}function ny(e,t,n){return new X(Na(e),t,n)}function ry(e,t,n){return new X(e,t,n)}function sy(e,t,n){return new X(e,t,n)}function oy(e){return new X(Ym(e))}function iy(e){return new X(yl.decode(e))}function ay(e){return new X(bl.decode(e))}function cy(e){return new X(dl.decode(e))}function uy(e){return new X(ol.decode(e))}class fy{constructor(t){this.data=X.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 X(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 co=qt.CURVE,La=co.n,ly=co.p,dy={x:co.Gx,y:co.Gy},hy=BigInt(0);BigInt(1);BigInt(2);BigInt(3);BigInt(4);const Gi={N:La,P:ly,G:dy,_0n:hy},Kr=Ff(La,32,!0),xl=e=>ze(e,La);function Ra(e,t=!1){if(t)throw new Error(e);return!1}function vl(e){return X.random(e)}function py(e){const t=X.bytes(e).big;return X.big(xl(t),32)}var gy=Object.freeze({__proto__:null,fail:Ra,mod_bytes:py,random:vl});const{N:my,_0n:yy}=Gi;function by(e,t,n){const r=X.bytes(e);return r.length!==t?Ra(`Invalid byte size: ${r.hex} !== ${t}`,n):!0}function wy(e,t){return typeof e=="bigint"&&yythis.big}lt(t){return new ve(t).big0&&!t.includes(e.length))throw new Error(`Expected Uint8Array of length ${t}, not of length=${e.length}`)}function ky(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 Sy(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 $y(e,t){El(e);const n=t.outputLen;if(e.lengthe instanceof Uint8Array,yi=e=>new DataView(e.buffer,e.byteOffset,e.byteLength),_t=(e,t)=>e<<32-t|e>>>t,By=new Uint8Array(new Uint32Array([287454020]).buffer)[0]===68;if(!By)throw new Error("Non little-endian hardware is not supported");Array.from({length:256},(e,t)=>t.toString(16).padStart(2,"0"));function Ty(e){if(typeof e!="string")throw new Error(`utf8ToBytes expected string, got ${typeof e}`);return new Uint8Array(new TextEncoder().encode(e))}function Ha(e){if(typeof e=="string"&&(e=Ty(e)),!Ay(e))throw new Error(`expected Uint8Array, got ${typeof e}`);return e}let kl=class{clone(){return this._cloneInto()}};function Qn(e){const t=r=>e().update(Ha(r)).digest(),n=e();return t.outputLen=n.outputLen,t.blockLen=n.blockLen,t.create=()=>e(),t}function Iy(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 ja extends kl{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=yi(this.buffer)}update(t){Ln.exists(this);const{view:n,buffer:r,blockLen:s}=this;t=Ha(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,Cy=(e,t,n)=>e&t^e&n^t&n,Py=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]),tn=new Uint32Array([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]),nn=new Uint32Array(64);let Sl=class extends ja{constructor(){super(64,32,8,!1),this.A=tn[0]|0,this.B=tn[1]|0,this.C=tn[2]|0,this.D=tn[3]|0,this.E=tn[4]|0,this.F=tn[5]|0,this.G=tn[6]|0,this.H=tn[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)nn[l]=t.getUint32(n,!1);for(let l=16;l<64;l++){const d=nn[l-15],p=nn[l-2],h=_t(d,7)^_t(d,18)^d>>>3,g=_t(p,17)^_t(p,19)^p>>>10;nn[l]=g+nn[l-7]+h+nn[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=_t(a,6)^_t(a,11)^_t(a,25),p=f+d+Oy(a,c,u)+Py[l]+nn[l]|0,g=(_t(r,2)^_t(r,13)^_t(r,22))+Cy(r,s,o)|0;f=u,u=c,c=a,a=i+p|0,i=o,o=s,s=r,r=p+g|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(){nn.fill(0)}destroy(){this.set(0,0,0,0,0,0,0,0),this.buffer.fill(0)}};class Uy extends Sl{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 uo=Qn(()=>new Sl);Qn(()=>new Uy);const Ps=BigInt(2**32-1),Xi=BigInt(32);function $l(e,t=!1){return t?{h:Number(e&Ps),l:Number(e>>Xi&Ps)}:{h:Number(e>>Xi&Ps)|0,l:Number(e&Ps)|0}}function Ny(e,t=!1){let n=new Uint32Array(e.length),r=new Uint32Array(e.length);for(let s=0;sBigInt(e>>>0)<>>0),Ry=(e,t,n)=>e>>>n,Hy=(e,t,n)=>e<<32-n|t>>>n,jy=(e,t,n)=>e>>>n|t<<32-n,Ky=(e,t,n)=>e<<32-n|t>>>n,Dy=(e,t,n)=>e<<64-n|t>>>n-32,My=(e,t,n)=>e>>>n-32|t<<64-n,Zy=(e,t)=>t,Vy=(e,t)=>e,qy=(e,t,n)=>e<>>32-n,zy=(e,t,n)=>t<>>32-n,Fy=(e,t,n)=>t<>>64-n,Wy=(e,t,n)=>e<>>64-n;function Gy(e,t,n,r){const s=(t>>>0)+(r>>>0);return{h:e+n+(s/2**32|0)|0,l:s|0}}const Yy=(e,t,n)=>(e>>>0)+(t>>>0)+(n>>>0),Xy=(e,t,n,r)=>t+n+r+(e/2**32|0)|0,Jy=(e,t,n,r)=>(e>>>0)+(t>>>0)+(n>>>0)+(r>>>0),Qy=(e,t,n,r,s)=>t+n+r+s+(e/2**32|0)|0,eb=(e,t,n,r,s)=>(e>>>0)+(t>>>0)+(n>>>0)+(r>>>0)+(s>>>0),tb=(e,t,n,r,s,o)=>t+n+r+s+o+(e/2**32|0)|0,nb={fromBig:$l,split:Ny,toBig:Ly,shrSH:Ry,shrSL:Hy,rotrSH:jy,rotrSL:Ky,rotrBH:Dy,rotrBL:My,rotr32H:Zy,rotr32L:Vy,rotlSH:qy,rotlSL:zy,rotlBH:Fy,rotlBL:Wy,add:Gy,add3L:Yy,add3H:Xy,add4L:Jy,add4H:Qy,add5H:tb,add5L:eb};var ne=nb;const[rb,sb]=ne.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))),rn=new Uint32Array(80),sn=new Uint32Array(80);let Ko=class extends ja{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:p,Gl:h,Hh:g,Hl:m}=this;return[t,n,r,s,o,i,a,c,u,f,l,d,p,h,g,m]}set(t,n,r,s,o,i,a,c,u,f,l,d,p,h,g,m){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=p|0,this.Gl=h|0,this.Hh=g|0,this.Hl=m|0}process(t,n){for(let y=0;y<16;y++,n+=4)rn[y]=t.getUint32(n),sn[y]=t.getUint32(n+=4);for(let y=16;y<80;y++){const x=rn[y-15]|0,$=sn[y-15]|0,E=ne.rotrSH(x,$,1)^ne.rotrSH(x,$,8)^ne.shrSH(x,$,7),I=ne.rotrSL(x,$,1)^ne.rotrSL(x,$,8)^ne.shrSL(x,$,7),P=rn[y-2]|0,B=sn[y-2]|0,U=ne.rotrSH(P,B,19)^ne.rotrBH(P,B,61)^ne.shrSH(P,B,6),L=ne.rotrSL(P,B,19)^ne.rotrBL(P,B,61)^ne.shrSL(P,B,6),D=ne.add4L(I,L,sn[y-7],sn[y-16]),k=ne.add4H(D,E,U,rn[y-7],rn[y-16]);rn[y]=k|0,sn[y]=D|0}let{Ah:r,Al:s,Bh:o,Bl:i,Ch:a,Cl:c,Dh:u,Dl:f,Eh:l,El:d,Fh:p,Fl:h,Gh:g,Gl:m,Hh:b,Hl:w}=this;for(let y=0;y<80;y++){const x=ne.rotrSH(l,d,14)^ne.rotrSH(l,d,18)^ne.rotrBH(l,d,41),$=ne.rotrSL(l,d,14)^ne.rotrSL(l,d,18)^ne.rotrBL(l,d,41),E=l&p^~l&g,I=d&h^~d&m,P=ne.add5L(w,$,I,sb[y],sn[y]),B=ne.add5H(P,b,x,E,rb[y],rn[y]),U=P|0,L=ne.rotrSH(r,s,28)^ne.rotrBH(r,s,34)^ne.rotrBH(r,s,39),D=ne.rotrSL(r,s,28)^ne.rotrBL(r,s,34)^ne.rotrBL(r,s,39),k=r&o^r&a^o&a,_=s&i^s&c^i&c;b=g|0,w=m|0,g=p|0,m=h|0,p=l|0,h=d|0,{h:l,l:d}=ne.add(u|0,f|0,B|0,U|0),u=a|0,f=c|0,a=o|0,c=i|0,o=r|0,i=s|0;const v=ne.add3L(U,D,_);r=ne.add3H(v,B,L,k),s=v|0}({h:r,l:s}=ne.add(this.Ah|0,this.Al|0,r|0,s|0)),{h:o,l:i}=ne.add(this.Bh|0,this.Bl|0,o|0,i|0),{h:a,l:c}=ne.add(this.Ch|0,this.Cl|0,a|0,c|0),{h:u,l:f}=ne.add(this.Dh|0,this.Dl|0,u|0,f|0),{h:l,l:d}=ne.add(this.Eh|0,this.El|0,l|0,d|0),{h:p,l:h}=ne.add(this.Fh|0,this.Fl|0,p|0,h|0),{h:g,l:m}=ne.add(this.Gh|0,this.Gl|0,g|0,m|0),{h:b,l:w}=ne.add(this.Hh|0,this.Hl|0,b|0,w|0),this.set(r,s,o,i,a,c,u,f,l,d,p,h,g,m,b,w)}roundClean(){rn.fill(0),sn.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 ob extends Ko{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 ib extends Ko{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 ab extends Ko{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 cb=Qn(()=>new Ko);Qn(()=>new ob);Qn(()=>new ib);Qn(()=>new ab);const ub=new Uint8Array([7,4,13,1,10,6,15,3,12,0,9,5,2,14,11,8]),_l=Uint8Array.from({length:16},(e,t)=>t),fb=_l.map(e=>(9*e+5)%16);let Ka=[_l],Da=[fb];for(let e=0;e<4;e++)for(let t of[Ka,Da])t.push(t[e].map(n=>ub[n]));const Al=[[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)),lb=Ka.map((e,t)=>e.map(n=>Al[t][n])),db=Da.map((e,t)=>e.map(n=>Al[t][n])),hb=new Uint32Array([0,1518500249,1859775393,2400959708,2840853838]),pb=new Uint32Array([1352829926,1548603684,1836072691,2053994217,0]),Us=(e,t)=>e<>>32-t;function cu(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 Ns=new Uint32Array(16);let gb=class extends ja{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 p=0;p<16;p++,n+=4)Ns[p]=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 p=0;p<5;p++){const h=4-p,g=hb[p],m=pb[p],b=Ka[p],w=Da[p],y=lb[p],x=db[p];for(let $=0;$<16;$++){const E=Us(r+cu(p,o,a,u)+Ns[b[$]]+g,y[$])+l|0;r=l,l=u,u=Us(a,10)|0,a=o,o=E}for(let $=0;$<16;$++){const E=Us(s+cu(h,i,c,f)+Ns[w[$]]+m,x[$])+d|0;s=d,d=f,f=Us(c,10)|0,c=i,i=E}}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(){Ns.fill(0)}destroy(){this.destroyed=!0,this.buffer.fill(0),this.set(0,0,0,0,0)}};const mb=Qn(()=>new gb);let Bl=class extends kl{constructor(t,n){super(),this.finished=!1,this.destroyed=!1,Ln.hash(t);const r=Ha(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 Bl(e,t).update(n).digest();Tl.create=(e,t)=>new Bl(e,t);function yb(e){const t=X.bytes(e);return X.raw(uo(t))}function br(e){const t=X.bytes(e);return X.raw(uo(uo(t)))}function Ma(e){const t=X.bytes(e);return X.raw(mb(uo(t)))}function bb(e,t){const n=X.bytes(e),r=X.bytes(t);return X.raw(Tl(cb,n,r))}function wb(e){const t=X.str(e).digest;return X.join([t,t])}function xb(e=32){return Za(vl(e))}function Za(e){return Ge.mod(e).buff}function Il(e,t=!1){const n=Ge.mod(e).point;return t?n.x:n.buff}function Ol(e,t){const n=Jn.from_x(t),r=Ge.mod(e);return n.mul(r).buff}function vb(e,t,n="ecdh/code"){const r=wb(n),s=Za(e),o=Il(s),i=X.bytes(t),a=Ol(s,i),c=[o.hex,i.hex];return c.sort(),bb(a,X.join([r,...c]))}function Eb(e){const t=X.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 kb(e){const t=X.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 Sb=Object.freeze({__proto__:null,genSecretKey:xb,getPublicKey:Il,getSecretKey:Za,getSharedCode:vb,getSharedKey:Ol,is_even_pub:Eb,xonly_pub:kb});X.random(32);const Cl={secp:qt},Ji={...Sb,...gy};function Do(e){const t=S.bytes(e);return Nt(t,33),Ma(t)}function Pl(e){const t=Be.fmt.toBytes(e,!1);return Ma(t)}function Ul(e){const t=Be.fmt.toBytes(e,!1);return yb(t)}function Nl(e,t="main"){const n=t==="main"?["1"]:["m","n"];for(const r of n)if(e.startsWith(r))return!0;return!1}function Ll(e,t="main"){const n=S.bytes(e),r=t==="main"?S.num(0):S.num(111);return Nt(e,20),n.prepend(r).tob58chk()}function $b(e,t="main"){if(!Nl(e,t))throw new TypeError("Invalid p2pkh address!");return S.b58chk(e).slice(1)}function _b(e){const t=S.bytes(e);return Nt(t,20),["OP_DUP","OP_HASH160",t.hex,"OP_EQUALVERIFY","OP_CHECKSIG"]}function Ab(e,t){const n=Do(e);return Ll(n,t)}const Rl={check:Nl,encode:Ll,decode:$b,hash:Do,scriptPubKey:_b,fromPubKey:Ab};function Hl(e,t="main"){const n=t==="main"?["3"]:["2"];for(const r of n)if(e.startsWith(r))return!0;return!1}function jl(e,t="main"){const n=t==="main"?S.num(5):S.num(196),r=S.bytes(e);return Nt(r,20),r.prepend(n).tob58chk()}function Bb(e,t="main"){if(!Hl(e,t))throw new TypeError(`Invalid p2sh address for network ${t}:`+e);return S.b58chk(e).slice(1)}function Tb(e){return["OP_HASH160",S.bytes(e).hex,"OP_EQUAL"]}function Ib(e,t){const n=Pl(e);return jl(n,t)}const Kl={check:Hl,encode:jl,decode:Bb,hash:Pl,scriptPubKey:Tb,fromScript:Ib},Va={main:"bc",testnet:"tb",signet:"tb",regtest:"bcrt"},Ob=["bc1q","tb1q","bcrt1q"];function Dl(e){for(const t of Ob)if(e.startsWith(t))return!0;return!1}function Ml(e,t="main"){const n=Va[t],r=S.bytes(e);return Nt(r,20),r.toBech32(n,0)}function Cb(e){if(!Dl(e))throw new TypeError("Invalid segwit address!");return S.bech32(e)}function Pb(e){const t=S.bytes(e);return Nt(t,20),["OP_0",t.hex]}function Ub(e,t){const n=Do(e);return Ml(n,t)}const Zl={check:Dl,encode:Ml,decode:Cb,hash:Do,scriptPubKey:Pb,fromPubKey:Ub},Nb=["bc1q","tb1q","bcrt1q"];function Vl(e){for(const t of Nb)if(e.startsWith(t))return!0;return!1}function ql(e,t="main"){const n=Va[t],r=S.bytes(e);return Nt(r,32),r.toBech32(n,0)}function Lb(e){if(!Vl(e))throw new TypeError("Invalid segwit address!");return S.bech32(e)}function Rb(e){const t=S.bytes(e);return Nt(t,32),["OP_0",t.hex]}function Hb(e,t){const n=Ul(e);return ql(n,t)}const zl={check:Vl,encode:ql,decode:Lb,hash:Ul,scriptPubKey:Rb,fromScript:Hb};function Zn(e){const t=S.bytes(e);return t.length>32?t.slice(1,33):t}const jb=["bc1p","tb1p","bcrt1p"];function Fl(e){for(const t of jb)if(e.startsWith(t))return!0;return!1}function Wl(e,t="main"){const n=Va[t],r=S.bytes(e);return Nt(r,32),r.toBech32(n,1)}function Kb(e){if(!Fl(e))throw new TypeError("Invalid taproot address!");return S.bech32(e)}function Db(e){const t=S.bytes(e);return Nt(t,32),["OP_1",t.hex]}function Mb(e,t){const n=Zn(e);return Wl(n,t)}const Gl={check:Fl,encode:Wl,decode:Kb,scriptPubKey:Db,fromPubKey:Mb},Zb={version:2,vin:[],vout:[],locktime:0},Vb={scriptSig:[],sequence:4294967293,witness:[]},qb={value:0n,scriptPubKey:[]};function qa(e){const t={...Zb,...e};return t.vin=t.vin.map(n=>({...Vb,...n})),t.vout=t.vout.map(n=>({...qb,...n})),t}function wr(e,t){const{version:n,vin:r,vout:s,locktime:o}=qa(e),i=t!==!0&&zb(r),a=[za(n)];i&&a.push(S.hex("0001")),a.push(Fb(r)),a.push(Wb(s));for(const c of r)i&&a.push(Yb(c.witness));return a.push(Fa(o)),S.join(a)}function zb(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 za(e){return S.num(e,4).reverse()}function ys(e){return S.hex(e,32).reverse()}function bs(e){return S.num(e,4).reverse()}function ws(e){if(typeof e=="string")return S.hex(e,4).reverse();if(typeof e=="number")return S.num(e,4).reverse();throw new Error("Unrecognized format: "+String(e))}function Fb(e){const t=[S.varInt(e.length,"le")];for(const n of e){const{txid:r,vout:s,scriptSig:o,sequence:i}=n;t.push(ys(r)),t.push(bs(s)),t.push(Xn(o,!0)),t.push(ws(i))}return S.join(t)}function xn(e){if(typeof e=="number"){if(e%1!==0)throw new Error("Value must be an integer:"+String(e));return S.num(e,8).reverse()}return S.big(e,8).reverse()}function Wb(e){const t=[S.varInt(e.length,"le")];for(const n of e)t.push(Gb(n));return S.join(t)}function Gb(e){const{value:t,scriptPubKey:n}=e,r=[];return r.push(xn(t)),r.push(Xn(n,!0)),S.join(r)}function Yb(e=[]){const t=[];if(Array.isArray(e)){const n=S.varInt(e.length);t.push(n);for(const r of e)t.push(Xb(r));return S.join(t)}else return S.bytes(e)}function Xb(e){return Jb(e)?new S(0):Xn(e,!0)}function Jb(e){if(Array.isArray(e))return e.length===0;if(typeof e=="string"&&e==="")return!0;const t=S.bytes(e);return t.length===1&&t[0]===0}function Fa(e){if(typeof e=="string")return S.hex(e,4);if(typeof e=="number")return S.num(e,4).reverse();throw new Error("Unrecognized format: "+String(e))}function Wa(e){typeof e=="string"&&(e=S.hex(e).raw);const t=new Cr(e),n=Qb(t),r=ew(t),s=tw(t),o=rw(t);if(r)for(const a of s)a.witness=ow(t);const i=iw(t);return{version:n,vin:s,vout:o,locktime:i}}function Qb(e){return e.read(4).reverse().toNum()}function ew(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 tw(e){const t=[],n=e.readSize("le");for(let r=0;r0?e.read(n).hex:null}function Xl(e,t){const n=Yl(e);return n!==null?n:[]}function iw(e){return e.read(4).reverse().toNum()}function aw(e){if(Lf(e))return Wa(e);if(typeof e=="object"&&!(e instanceof Uint8Array))return wr(e),qa(e);throw new Error("Invalid format: "+typeof e)}function cw(e){if(Lf(e))return Wa(e),S.bytes(e);if(typeof e=="object")return wr(e);throw new Error("Invalid format: "+typeof e)}const Ga={toBytes:cw,toJson:aw},uw=[["p2pkh",/^76a914(?\w{40})88ac$/],["p2sh",/^a914(?\w{40})87$/],["p2w-pkh",/^0014(?\w{40})$/],["p2w-sh",/^0020(?\w{64})$/],["p2tr",/^5120(?\w{64})$/]],fw=[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 lw(e){let t=e.at(-1);return Wt(t)&&(t=S.hex(t)),e.length>1&&t instanceof Uint8Array&&t[0]===80?(e.pop(),S.raw(t)):null}function dw(e){let t=e.at(-1);return Wt(t)&&(t=S.hex(t)),e.length>1&&t instanceof Uint8Array&&t.length>32&&fw.includes(t[0]&254)?(e.pop(),S.raw(t)):null}function hw(e){if(e.length>1){const t=e.at(-1);try{const n=Be.fmt.toBytes(t);return e.pop(),n}catch{return null}}return null}function pw(e){const t=[];for(const n of e)if(Wt(n)||n instanceof Uint8Array||typeof n=="number")t.push(S.bytes(n));else throw new Error("unrecognized value: "+String(n));return t}function gw(e=[]){const t=[...e],n=lw(t),r=dw(t),s=hw(t),o=pw(t);return{annex:n,cblock:r,script:s,params:o}}function mw(e){const t=Be.fmt.toBytes(e,!1).hex;for(const[n,r]of uw){const s=n,{groups:o}=r.exec(t)??{},{hash:i}=o??{};if(Wt(i))return{type:s,data:S.hex(i)}}return{type:"raw",data:S.hex(t)}}function yw(e){const t=Ga.toJson(e),n=wr(t,!0);return br(n).reverse().hex}function bw(e){const t=Ga.toJson(e),n=wr(t,!0).length,r=wr(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 ie={create:qa,encode:wr,decode:Wa,fmt:Ga,util:{getTxSize:bw,getTxid:yw,readScriptPubKey:mw,readWitness:gw}},ww=[["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 xw(e,t){switch(t){case"base58":return S.b58chk(e).slice(1);case"bech32":return S.bech32(e);case"bech32m":return S.bech32(e);default:throw new Error("Invalid address format: "+t)}}function vw(e){for(const t of ww){const[n,r,s,o,i]=t;if(e.startsWith(n)&&xw(e,i).length===o)return t}throw new Error("Invalid address: "+e)}function Jl(e){switch(e){case"p2pkh":return Rl;case"p2sh":return Kl;case"p2w-pkh":return Zl;case"p2w-sh":return zl;case"p2tr":return Gl;default:throw new Error("Invalid address type: "+e)}}function Ql(e){const[t,n,r]=vw(e),s=Jl(n),o=s.decode(e,r),i=s.scriptPubKey(o);return{prefix:t,type:n,network:r,data:o,script:i}}function Ew(e,t){const{type:n,data:r}=ie.util.readScriptPubKey(e);return Jl(n).encode(r,t)}function kw(e){const{script:t}=Ql(e);return Be.fmt.toAsm(t,!1)}const Qr={p2pkh:Rl,p2sh:Kl,p2wpkh:Zl,p2wsh:zl,p2tr:Gl,decode:Ql,fromScriptPubKey:Ew,toScriptPubKey:kw},Sw=[1,2,3];function Ya(e,t,n={}){const{sigflag:r=1}=n,s=(r&128)===128,o=r%128;if(!Sw.includes(o))throw new Error("Invalid hash type: "+String(r));const i=ie.fmt.toJson(e),{version:a,vin:c,vout:u,locktime:f}=i,{txid:l,vout:d,prevout:p,sequence:h}=c[t],{value:g}=p??{};if(g===void 0)throw new Error("Prevout value is empty!");let m=n.script;if(m===void 0&&n.pubkey!==void 0&&(m=`76a914${Ma(n.pubkey).hex}88ac`),m===void 0)throw new Error("No pubkey / script has been set!");if(Be.fmt.toAsm(m).includes("OP_CODESEPARATOR"))throw new Error("This library does not currently support the use of OP_CODESEPARATOR in segwit scripts.");const b=[za(a),$w(c,s),_w(c,o,s),ys(l),bs(d),Be.encode(m,!0),xn(g),ws(h),Aw(u,t,o),Fa(f),S.num(r,4).reverse()];return br(S.join(b))}function $w(e,t){if(t===!0)return S.num(0,32);const n=[];for(const{txid:r,vout:s}of e)n.push(ys(r)),n.push(bs(s));return br(S.join(n))}function _w(e,t,n){if(n||t!==1)return S.num(0,32);const r=[];for(const{sequence:s}of e)r.push(ws(s));return br(S.join(r))}function Aw(e,t,n){const r=[];if(n===1){for(const{value:s,scriptPubKey:o}of e)r.push(xn(s)),r.push(Be.encode(o,!0));return br(S.join(r))}if(n===3&&t1&&c[1].length===33)u=S.bytes(c[1]);else return qe("No pubkey provided!",s);const f=Be.fmt.toParam(c[0]),l=f.slice(0,-1),d=f.slice(-1)[0],p=Ya(r,t,{...n,sigflag:d});return Cl.secp.verify(l,p,u)?!0:qe("Invalid signature!",s)}const Iw={hash:Ya,sign:Bw,verify:Tw},Ow=[0,1,2,3,129,130,131];function Xa(e,t,n={}){const{extension:r,sigflag:s=0,extflag:o=0,key_version:i=0,separator_pos:a=4294967295}=n,c=ie.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(!Ow.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:p,vout:h,sequence:g,witness:m=[]}=f[t],b=(s&128)===128,w=Hw(m),y=w!==void 0?1:0,$=(o+(r!==void 0?1:0))*2+y,E=S.str("TapSighash").digest,I=[E,E,S.num(0,1),S.num(s,1),za(u),Fa(d)];if(!b){const P=f.map(B=>uu(B));I.push(Cw(f),Uw(P),Nw(P),Pw(f))}if(((s&3)<2||(s&3)>3)&&I.push(Lw(l)),I.push(S.num($,1)),b){const{value:P,scriptPubKey:B}=uu(f[t]);I.push(ys(p),bs(h),xn(P),Be.encode(B,!0),ws(g))}else I.push(S.num(t,4).reverse());return w!==void 0&&I.push(w),(s&3)===3&&I.push(Rw(l[t])),r!==void 0&&I.push(S.bytes(r),S.num(i),S.num(a,4,"le")),S.join(I).digest}function Cw(e){const t=[];for(const{txid:n,vout:r}of e)t.push(ys(n)),t.push(bs(r));return S.join(t).digest}function Pw(e){const t=[];for(const{sequence:n}of e)t.push(ws(n));return S.join(t).digest}function Uw(e){const t=[];for(const{value:n}of e)t.push(xn(n));return S.join(t).digest}function Nw(e){const t=[];for(const{scriptPubKey:n}of e)t.push(Xn(n,!0));return S.join(t).digest}function Lw(e){const t=[];for(const{value:n,scriptPubKey:r}of e)t.push(xn(n)),t.push(Be.encode(r,!0));return S.join(t).digest}function Rw(e){return S.join([xn(e.value),Be.encode(e.scriptPubKey,!0)]).digest}function Hw(e){if(e===void 0||e.length<2)return;let t=e.at(-1);if(typeof t=="string"&&(t=S.hex(t)),t instanceof Uint8Array&&t[0]===80)return S.raw(t).prefixSize("be").digest}function uu(e){if(e.prevout===void 0)throw new Error("Prevout data missing for input: "+String(e.txid));return e.prevout}const jw=0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2fn,Kw=0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141n;function Dw(e,t,n,r={}){const{sigflag:s=0}=r,o=Xa(t,n,r),i=Mw(e,o);return s===0?S.raw(i):S.join([i,s])}function Mw(e,t,n=S.random(32)){const r=S.bytes(t),s=new Ge(e),o=s.point,i=o.hasEvenY?s.big:s.negated.big,a=Js("BIP0340/aux",S.bytes(n)),c=i^a.big,u=Js("BIP0340/nonce",c,o.x.raw,r),f=new Ge(u),l=f.point,d=l.hasEvenY?f.big:f.negated.big,p=new Ge(Js("BIP0340/challenge",l.x.raw,o.x.raw,r)),h=new Ge(d+p.big*i);return S.join([l.x.raw,h.raw])}function Zw(e,t,n,r=!1){const s=Jn.from_x(Zn(n)),o=S.bytes(t),i=S.bytes(e).stream;i.size<64&&qe("Signature length is too small: "+String(i.size),r);const a=i.read(32);a.big>jw&&qe("Signature r value greater than field size!",r);const c=i.read(32);c.big>Kw&&qe("Signature s value greater than curve order!",r);const u=new Ge(Js("BIP0340/challenge",a.raw,s.x.raw,o)),f=new Ge(c).point,l=s.mul(u.big),d=f.sub(l);return d.hasOddY&&qe("Signature R value has odd Y coordinate!",r),d.x.big===0n&&qe("Signature R value is infinite!",r),d.x.big===a.big}const Vw=192;function Mo(e){const t=S.str(e).digest;return S.join([t,t])}function Ja(e,t=Vw){return S.join([Mo("TapLeaf"),Fw(t),S.bytes(e)]).digest.hex}function qw(e,t){return Ja(Be.fmt.toBytes(e),t)}function Qa(e,t){return t0){const[p,h,g]=fo(r,i);c=g,a=lr(e,p,n)}else i!==void 0?a=lr(e,i,n):a=lr(e,void 0,n);const u=n?Ji.getPublicKey(a)[0]:a[0],l=[S.num(s+od(u)),o];c.length>0&&c.forEach(p=>l.push(S.hex(p)));const d=S.join(l);if(i!==void 0&&!ec(a,i,d,t))throw new Error("Path checking failed! Unable to generate path.");return[Zn(a).hex,d.hex]}function ec(e,t,n,r={}){const{isPrivate:s=!1,throws:o=!1}=r,{parity:i,paths:a,intkey:c}=sd(n),u=s?Ji.getPublicKey(e,!0):Zn(e),f=S.join([i,u]);if(f.length!==33)return qe("Invalid tapkey: "+f.hex,o);let l=S.bytes(t).hex;for(const p of a)l=Qa(l,p);const d=lr(c,l);return S.raw(d).hex===S.raw(f).hex}function sd(e){const t=new Cr(S.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 od(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 t1(e,t,n={}){const r=ie.fmt.toJson(e),{throws:s=!1}=n,{prevout:o,witness:i=[]}=r.vin[t],a=ie.util.readWitness(i),{cblock:c,script:u,params:f}=a;let l;if(f.length<1)return qe("Invalid witness data: "+String(i),s);const{scriptPubKey:d}=o??{};if(d===void 0)return qe("Prevout scriptPubKey is empty!",s);const{type:p,data:h}=ie.util.readScriptPubKey(d);if(p!=="p2tr")return qe("Prevout script is not a valid taproot output:"+h.hex,s);if(h.length!==32)return qe("Invalid tapkey length: "+String(h.length),s);if(c!==null&&u!==null){const y=c[0]&254,x=Ja(u,y);if(n.extension=x,!ec(h,x,c,{throws:s}))return qe("cblock verification failed!",s)}n.pubkey!==void 0?l=S.bytes(n.pubkey):f.length>1&&f[1].length===32?l=S.bytes(f[1]):l=S.bytes(h);const g=Be.fmt.toParam(f[0]),m=new Cr(g),b=m.read(64).raw;if(m.size===1&&(n.sigflag=m.read(1).num,n.sigflag===0))return qe("0x00 is not a valid appended sigflag!",s);const w=Xa(r,t,n);return Zw(b,w,l,s)?!0:qe("Invalid signature!",s)}const n1={hash:Xa,sign:Dw,verify:t1},xr={segwit:Iw,taproot:n1},r1={getTag:Mo,getLeaf:Ja,getBranch:Qa,getRoot:zw},s1={readCtrlBlock:sd,readParityBit:od},o1={getPubKey:Ww,getSecKey:Gw,getTweak:ed,tweakSecKey:td,tweakPubKey:nd},Zo={getPubKey:e1,getSecKey:Qw,encodeScript:qw,checkPath:ec,tree:r1,tweak:o1,util:s1,SCRIPT_PUBKEY:Xw};var ge;(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})(ge||(ge={}));var Qi;(function(e){e.mergeShapes=(t,n)=>({...t,...n})})(Qi||(Qi={}));const Z=ge.arrayToEnum(["string","nan","number","integer","float","boolean","date","bigint","symbol","function","undefined","null","array","object","unknown","promise","void","never","map","set"]),hn=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}},H=ge.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"]),i1=e=>JSON.stringify(e,null,2).replace(/"([^"]+)":/g,"$1:");class yt 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()}}yt.create=e=>new yt(e);const es=(e,t)=>{let n;switch(e.code){case H.invalid_type:e.received===Z.undefined?n="Required":n=`Expected ${e.expected}, received ${e.received}`;break;case H.invalid_literal:n=`Invalid literal value, expected ${JSON.stringify(e.expected,ge.jsonStringifyReplacer)}`;break;case H.unrecognized_keys:n=`Unrecognized key(s) in object: ${ge.joinValues(e.keys,", ")}`;break;case H.invalid_union:n="Invalid input";break;case H.invalid_union_discriminator:n=`Invalid discriminator value. Expected ${ge.joinValues(e.options)}`;break;case H.invalid_enum_value:n=`Invalid enum value. Expected ${ge.joinValues(e.options)}, received '${e.received}'`;break;case H.invalid_arguments:n="Invalid function arguments";break;case H.invalid_return_type:n="Invalid function return type";break;case H.invalid_date:n="Invalid date";break;case H.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}"`:ge.assertNever(e.validation):e.validation!=="regex"?n=`Invalid ${e.validation}`:n="Invalid";break;case H.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 H.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 H.custom:n="Invalid input";break;case H.invalid_intersection_types:n="Intersection results could not be merged";break;case H.not_multiple_of:n=`Number must be a multiple of ${e.multipleOf}`;break;case H.not_finite:n="Number must be finite";break;default:n=t.defaultError,ge.assertNever(e)}return{message:n}};let id=es;function a1(e){id=e}function lo(){return id}const ho=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}},c1=[];function V(e,t){const n=ho({issueData:t,data:e.data,path:e.path,errorMaps:[e.common.contextualErrorMap,e.schemaErrorMap,lo(),es].filter(r=>!!r)});e.common.issues.push(n)}class Fe{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 J;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 Fe.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 J;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 J=Object.freeze({status:"aborted"}),ad=e=>({status:"dirty",value:e}),Je=e=>({status:"valid",value:e}),ea=e=>e.status==="aborted",ta=e=>e.status==="dirty",po=e=>e.status==="valid",go=e=>typeof Promise<"u"&&e instanceof Promise;var W;(function(e){e.errToObj=t=>typeof t=="string"?{message:t}:t||{},e.toString=t=>typeof t=="string"?t:t==null?void 0:t.message})(W||(W={}));class Ct{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 fu=(e,t)=>{if(po(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 yt(e.common.issues);return this._error=n,this._error}}};function te(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 se{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 hn(t.data)}_getOrReturnCtx(t,n){return n||{common:t.parent.common,data:t.data,parsedType:hn(t.data),schemaErrorMap:this._def.errorMap,path:t.path,parent:t.parent}}_processInputParams(t){return{status:new Fe,ctx:{common:t.parent.common,data:t.data,parsedType:hn(t.data),schemaErrorMap:this._def.errorMap,path:t.path,parent:t.parent}}}_parseSync(t){const n=this._parse(t);if(go(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:hn(t)},o=this._parseSync({data:t,path:s.path,parent:s});return fu(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:hn(t)},s=this._parse({data:t,path:r.path,parent:r}),o=await(go(s)?s:Promise.resolve(s));return fu(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:H.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 xt({schema:this,typeName:Y.ZodEffects,effect:{type:"refinement",refinement:t}})}superRefine(t){return this._refinement(t)}optional(){return Zt.create(this,this._def)}nullable(){return zn.create(this,this._def)}nullish(){return this.nullable().optional()}array(){return bt.create(this,this._def)}promise(){return Er.create(this,this._def)}or(t){return ss.create([this,t],this._def)}and(t){return os.create(this,t,this._def)}transform(t){return new xt({...te(this._def),schema:this,typeName:Y.ZodEffects,effect:{type:"transform",transform:t}})}default(t){const n=typeof t=="function"?t:()=>t;return new fs({...te(this._def),innerType:this,defaultValue:n,typeName:Y.ZodDefault})}brand(){return new ud({typeName:Y.ZodBranded,type:this,...te(this._def)})}catch(t){const n=typeof t=="function"?t:()=>t;return new wo({...te(this._def),innerType:this,catchValue:n,typeName:Y.ZodCatch})}describe(t){const n=this.constructor;return new n({...this._def,description:t})}pipe(t){return xs.create(this,t)}isOptional(){return this.safeParse(void 0).success}isNullable(){return this.safeParse(null).success}}const u1=/^c[^\s-]{8,}$/i,f1=/^[a-z][a-z0-9]*$/,l1=/[0-9A-HJKMNP-TV-Z]{26}/,d1=/^([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,h1=/^(([^<>()[\]\\.,;:\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,})+))$/,p1=new RegExp("^(\\p{Extended_Pictographic}|\\p{Emoji_Component})+$","u"),g1=/^(((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}))$/,m1=/^(([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})))$/,y1=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 b1(e,t){return!!((t==="v4"||!t)&&g1.test(e)||(t==="v6"||!t)&&m1.test(e))}class pt extends se{constructor(){super(...arguments),this._regex=(t,n,r)=>this.refinement(s=>t.test(s),{validation:n,code:H.invalid_string,...W.errToObj(r)}),this.nonempty=t=>this.min(1,W.errToObj(t)),this.trim=()=>new pt({...this._def,checks:[...this._def.checks,{kind:"trim"}]}),this.toLowerCase=()=>new pt({...this._def,checks:[...this._def.checks,{kind:"toLowerCase"}]}),this.toUpperCase=()=>new pt({...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 V(o,{code:H.invalid_type,expected:Z.string,received:o.parsedType}),J}const r=new Fe;let s;for(const o of this._def.checks)if(o.kind==="min")t.data.lengtho.value&&(s=this._getOrReturnCtx(t,s),V(s,{code:H.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,...W.errToObj(t==null?void 0:t.message)})}regex(t,n){return this._addCheck({kind:"regex",regex:t,...W.errToObj(n)})}includes(t,n){return this._addCheck({kind:"includes",value:t,position:n==null?void 0:n.position,...W.errToObj(n==null?void 0:n.message)})}startsWith(t,n){return this._addCheck({kind:"startsWith",value:t,...W.errToObj(n)})}endsWith(t,n){return this._addCheck({kind:"endsWith",value:t,...W.errToObj(n)})}min(t,n){return this._addCheck({kind:"min",value:t,...W.errToObj(n)})}max(t,n){return this._addCheck({kind:"max",value:t,...W.errToObj(n)})}length(t,n){return this._addCheck({kind:"length",value:t,...W.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 pt({checks:[],typeName:Y.ZodString,coerce:(t=e==null?void 0:e.coerce)!==null&&t!==void 0?t:!1,...te(e)})};function w1(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 vn extends se{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 V(o,{code:H.invalid_type,expected:Z.number,received:o.parsedType}),J}let r;const s=new Fe;for(const o of this._def.checks)o.kind==="int"?ge.isInteger(t.data)||(r=this._getOrReturnCtx(t,r),V(r,{code:H.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),V(r,{code:H.too_big,maximum:o.value,type:"number",inclusive:o.inclusive,exact:!1,message:o.message}),s.dirty()):o.kind==="multipleOf"?w1(t.data,o.value)!==0&&(r=this._getOrReturnCtx(t,r),V(r,{code:H.not_multiple_of,multipleOf:o.value,message:o.message}),s.dirty()):o.kind==="finite"?Number.isFinite(t.data)||(r=this._getOrReturnCtx(t,r),V(r,{code:H.not_finite,message:o.message}),s.dirty()):ge.assertNever(o);return{status:s.value,value:t.data}}gte(t,n){return this.setLimit("min",t,!0,W.toString(n))}gt(t,n){return this.setLimit("min",t,!1,W.toString(n))}lte(t,n){return this.setLimit("max",t,!0,W.toString(n))}lt(t,n){return this.setLimit("max",t,!1,W.toString(n))}setLimit(t,n,r,s){return new vn({...this._def,checks:[...this._def.checks,{kind:t,value:n,inclusive:r,message:W.toString(s)}]})}_addCheck(t){return new vn({...this._def,checks:[...this._def.checks,t]})}int(t){return this._addCheck({kind:"int",message:W.toString(t)})}positive(t){return this._addCheck({kind:"min",value:0,inclusive:!1,message:W.toString(t)})}negative(t){return this._addCheck({kind:"max",value:0,inclusive:!1,message:W.toString(t)})}nonpositive(t){return this._addCheck({kind:"max",value:0,inclusive:!0,message:W.toString(t)})}nonnegative(t){return this._addCheck({kind:"min",value:0,inclusive:!0,message:W.toString(t)})}multipleOf(t,n){return this._addCheck({kind:"multipleOf",value:t,message:W.toString(n)})}finite(t){return this._addCheck({kind:"finite",message:W.toString(t)})}safe(t){return this._addCheck({kind:"min",inclusive:!0,value:Number.MIN_SAFE_INTEGER,message:W.toString(t)})._addCheck({kind:"max",inclusive:!0,value:Number.MAX_SAFE_INTEGER,message:W.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"&&ge.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 vn({checks:[],typeName:Y.ZodNumber,coerce:(e==null?void 0:e.coerce)||!1,...te(e)});class En extends se{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 V(o,{code:H.invalid_type,expected:Z.bigint,received:o.parsedType}),J}let r;const s=new Fe;for(const o of this._def.checks)o.kind==="min"?(o.inclusive?t.datao.value:t.data>=o.value)&&(r=this._getOrReturnCtx(t,r),V(r,{code:H.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),V(r,{code:H.not_multiple_of,multipleOf:o.value,message:o.message}),s.dirty()):ge.assertNever(o);return{status:s.value,value:t.data}}gte(t,n){return this.setLimit("min",t,!0,W.toString(n))}gt(t,n){return this.setLimit("min",t,!1,W.toString(n))}lte(t,n){return this.setLimit("max",t,!0,W.toString(n))}lt(t,n){return this.setLimit("max",t,!1,W.toString(n))}setLimit(t,n,r,s){return new En({...this._def,checks:[...this._def.checks,{kind:t,value:n,inclusive:r,message:W.toString(s)}]})}_addCheck(t){return new En({...this._def,checks:[...this._def.checks,t]})}positive(t){return this._addCheck({kind:"min",value:BigInt(0),inclusive:!1,message:W.toString(t)})}negative(t){return this._addCheck({kind:"max",value:BigInt(0),inclusive:!1,message:W.toString(t)})}nonpositive(t){return this._addCheck({kind:"max",value:BigInt(0),inclusive:!0,message:W.toString(t)})}nonnegative(t){return this._addCheck({kind:"min",value:BigInt(0),inclusive:!0,message:W.toString(t)})}multipleOf(t,n){return this._addCheck({kind:"multipleOf",value:t,message:W.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 En({checks:[],typeName:Y.ZodBigInt,coerce:(t=e==null?void 0:e.coerce)!==null&&t!==void 0?t:!1,...te(e)})};class ts extends se{_parse(t){if(this._def.coerce&&(t.data=!!t.data),this._getType(t)!==Z.boolean){const r=this._getOrReturnCtx(t);return V(r,{code:H.invalid_type,expected:Z.boolean,received:r.parsedType}),J}return Je(t.data)}}ts.create=e=>new ts({typeName:Y.ZodBoolean,coerce:(e==null?void 0:e.coerce)||!1,...te(e)});class Vn extends se{_parse(t){if(this._def.coerce&&(t.data=new Date(t.data)),this._getType(t)!==Z.date){const o=this._getOrReturnCtx(t);return V(o,{code:H.invalid_type,expected:Z.date,received:o.parsedType}),J}if(isNaN(t.data.getTime())){const o=this._getOrReturnCtx(t);return V(o,{code:H.invalid_date}),J}const r=new Fe;let s;for(const o of this._def.checks)o.kind==="min"?t.data.getTime()o.value&&(s=this._getOrReturnCtx(t,s),V(s,{code:H.too_big,message:o.message,inclusive:!0,exact:!1,maximum:o.value,type:"date"}),r.dirty()):ge.assertNever(o);return{status:r.value,value:new Date(t.data.getTime())}}_addCheck(t){return new Vn({...this._def,checks:[...this._def.checks,t]})}min(t,n){return this._addCheck({kind:"min",value:t.getTime(),message:W.toString(n)})}max(t,n){return this._addCheck({kind:"max",value:t.getTime(),message:W.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 Vn({checks:[],coerce:(e==null?void 0:e.coerce)||!1,typeName:Y.ZodDate,...te(e)});class mo extends se{_parse(t){if(this._getType(t)!==Z.symbol){const r=this._getOrReturnCtx(t);return V(r,{code:H.invalid_type,expected:Z.symbol,received:r.parsedType}),J}return Je(t.data)}}mo.create=e=>new mo({typeName:Y.ZodSymbol,...te(e)});class ns extends se{_parse(t){if(this._getType(t)!==Z.undefined){const r=this._getOrReturnCtx(t);return V(r,{code:H.invalid_type,expected:Z.undefined,received:r.parsedType}),J}return Je(t.data)}}ns.create=e=>new ns({typeName:Y.ZodUndefined,...te(e)});class rs extends se{_parse(t){if(this._getType(t)!==Z.null){const r=this._getOrReturnCtx(t);return V(r,{code:H.invalid_type,expected:Z.null,received:r.parsedType}),J}return Je(t.data)}}rs.create=e=>new rs({typeName:Y.ZodNull,...te(e)});class vr extends se{constructor(){super(...arguments),this._any=!0}_parse(t){return Je(t.data)}}vr.create=e=>new vr({typeName:Y.ZodAny,...te(e)});class Dn extends se{constructor(){super(...arguments),this._unknown=!0}_parse(t){return Je(t.data)}}Dn.create=e=>new Dn({typeName:Y.ZodUnknown,...te(e)});class zt extends se{_parse(t){const n=this._getOrReturnCtx(t);return V(n,{code:H.invalid_type,expected:Z.never,received:n.parsedType}),J}}zt.create=e=>new zt({typeName:Y.ZodNever,...te(e)});class yo extends se{_parse(t){if(this._getType(t)!==Z.undefined){const r=this._getOrReturnCtx(t);return V(r,{code:H.invalid_type,expected:Z.void,received:r.parsedType}),J}return Je(t.data)}}yo.create=e=>new yo({typeName:Y.ZodVoid,...te(e)});class bt extends se{_parse(t){const{ctx:n,status:r}=this._processInputParams(t),s=this._def;if(n.parsedType!==Z.array)return V(n,{code:H.invalid_type,expected:Z.array,received:n.parsedType}),J;if(s.exactLength!==null){const i=n.data.length>s.exactLength.value,a=n.data.lengths.maxLength.value&&(V(n,{code:H.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 Ct(n,i,n.path,a)))).then(i=>Fe.mergeArray(r,i));const o=[...n.data].map((i,a)=>s.type._parseSync(new Ct(n,i,n.path,a)));return Fe.mergeArray(r,o)}get element(){return this._def.type}min(t,n){return new bt({...this._def,minLength:{value:t,message:W.toString(n)}})}max(t,n){return new bt({...this._def,maxLength:{value:t,message:W.toString(n)}})}length(t,n){return new bt({...this._def,exactLength:{value:t,message:W.toString(n)}})}nonempty(t){return this.min(1,t)}}bt.create=(e,t)=>new bt({type:e,minLength:null,maxLength:null,exactLength:null,typeName:Y.ZodArray,...te(t)});function cr(e){if(e instanceof Ae){const t={};for(const n in e.shape){const r=e.shape[n];t[n]=Zt.create(cr(r))}return new Ae({...e._def,shape:()=>t})}else return e instanceof bt?new bt({...e._def,type:cr(e.element)}):e instanceof Zt?Zt.create(cr(e.unwrap())):e instanceof zn?zn.create(cr(e.unwrap())):e instanceof Pt?Pt.create(e.items.map(t=>cr(t))):e}class Ae extends se{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=ge.objectKeys(t);return this._cached={shape:t,keys:n}}_parse(t){if(this._getType(t)!==Z.object){const u=this._getOrReturnCtx(t);return V(u,{code:H.invalid_type,expected:Z.object,received:u.parsedType}),J}const{status:r,ctx:s}=this._processInputParams(t),{shape:o,keys:i}=this._getCached(),a=[];if(!(this._def.catchall instanceof zt&&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 Ct(s,l,s.path,u)),alwaysSet:u in s.data})}if(this._def.catchall instanceof zt){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&&(V(s,{code:H.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 Ct(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=>Fe.mergeObjectSync(r,u)):Fe.mergeObjectSync(r,c)}get shape(){return this._def.shape()}strict(t){return new Ae({...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=W.errToObj(t).message)!==null&&a!==void 0?a:c}:{message:c}}}:{}})}strip(){return new Ae({...this._def,unknownKeys:"strip"})}passthrough(){return new Ae({...this._def,unknownKeys:"passthrough"})}extend(t){return new Ae({...this._def,shape:()=>({...this._def.shape(),...t})})}merge(t){return new Ae({unknownKeys:t._def.unknownKeys,catchall:t._def.catchall,shape:()=>({...this._def.shape(),...t._def.shape()}),typeName:Y.ZodObject})}setKey(t,n){return this.augment({[t]:n})}catchall(t){return new Ae({...this._def,catchall:t})}pick(t){const n={};return ge.objectKeys(t).forEach(r=>{t[r]&&this.shape[r]&&(n[r]=this.shape[r])}),new Ae({...this._def,shape:()=>n})}omit(t){const n={};return ge.objectKeys(this.shape).forEach(r=>{t[r]||(n[r]=this.shape[r])}),new Ae({...this._def,shape:()=>n})}deepPartial(){return cr(this)}partial(t){const n={};return ge.objectKeys(this.shape).forEach(r=>{const s=this.shape[r];t&&!t[r]?n[r]=s:n[r]=s.optional()}),new Ae({...this._def,shape:()=>n})}required(t){const n={};return ge.objectKeys(this.shape).forEach(r=>{if(t&&!t[r])n[r]=this.shape[r];else{let o=this.shape[r];for(;o instanceof Zt;)o=o._def.innerType;n[r]=o}}),new Ae({...this._def,shape:()=>n})}keyof(){return cd(ge.objectKeys(this.shape))}}Ae.create=(e,t)=>new Ae({shape:()=>e,unknownKeys:"strip",catchall:zt.create(),typeName:Y.ZodObject,...te(t)});Ae.strictCreate=(e,t)=>new Ae({shape:()=>e,unknownKeys:"strict",catchall:zt.create(),typeName:Y.ZodObject,...te(t)});Ae.lazycreate=(e,t)=>new Ae({shape:e,unknownKeys:"strip",catchall:zt.create(),typeName:Y.ZodObject,...te(t)});class ss extends se{_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 yt(a.ctx.common.issues));return V(n,{code:H.invalid_union,unionErrors:i}),J}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 yt(c));return V(n,{code:H.invalid_union,unionErrors:a}),J}}get options(){return this._def.options}}ss.create=(e,t)=>new ss({options:e,typeName:Y.ZodUnion,...te(t)});const Qs=e=>e instanceof as?Qs(e.schema):e instanceof xt?Qs(e.innerType()):e instanceof cs?[e.value]:e instanceof kn?e.options:e instanceof us?Object.keys(e.enum):e instanceof fs?Qs(e._def.innerType):e instanceof ns?[void 0]:e instanceof rs?[null]:null;class Vo extends se{_parse(t){const{ctx:n}=this._processInputParams(t);if(n.parsedType!==Z.object)return V(n,{code:H.invalid_type,expected:Z.object,received:n.parsedType}),J;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}):(V(n,{code:H.invalid_union_discriminator,options:Array.from(this.optionsMap.keys()),path:[r]}),J)}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=Qs(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 Vo({typeName:Y.ZodDiscriminatedUnion,discriminator:t,options:n,optionsMap:s,...te(r)})}}function na(e,t){const n=hn(e),r=hn(t);if(e===t)return{valid:!0,data:e};if(n===Z.object&&r===Z.object){const s=ge.objectKeys(t),o=ge.objectKeys(e).filter(a=>s.indexOf(a)!==-1),i={...e,...t};for(const a of o){const c=na(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(ea(o)||ea(i))return J;const a=na(o.value,i.value);return a.valid?((ta(o)||ta(i))&&n.dirty(),{status:n.value,value:a.data}):(V(r,{code:H.invalid_intersection_types}),J)};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}))}}os.create=(e,t,n)=>new os({left:e,right:t,typeName:Y.ZodIntersection,...te(n)});class Pt extends se{_parse(t){const{status:n,ctx:r}=this._processInputParams(t);if(r.parsedType!==Z.array)return V(r,{code:H.invalid_type,expected:Z.array,received:r.parsedType}),J;if(r.data.lengththis._def.items.length&&(V(r,{code:H.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 Ct(r,i,r.path,a)):null}).filter(i=>!!i);return r.common.async?Promise.all(o).then(i=>Fe.mergeArray(n,i)):Fe.mergeArray(n,o)}get items(){return this._def.items}rest(t){return new Pt({...this._def,rest:t})}}Pt.create=(e,t)=>{if(!Array.isArray(e))throw new Error("You must pass an array of schemas to z.tuple([ ... ])");return new Pt({items:e,typeName:Y.ZodTuple,rest:null,...te(t)})};class is extends se{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 V(r,{code:H.invalid_type,expected:Z.object,received:r.parsedType}),J;const s=[],o=this._def.keyType,i=this._def.valueType;for(const a in r.data)s.push({key:o._parse(new Ct(r,a,r.path,a)),value:i._parse(new Ct(r,r.data[a],r.path,a))});return r.common.async?Fe.mergeObjectAsync(n,s):Fe.mergeObjectSync(n,s)}get element(){return this._def.valueType}static create(t,n,r){return n instanceof se?new is({keyType:t,valueType:n,typeName:Y.ZodRecord,...te(r)}):new is({keyType:pt.create(),valueType:t,typeName:Y.ZodRecord,...te(n)})}}class bo extends se{_parse(t){const{status:n,ctx:r}=this._processInputParams(t);if(r.parsedType!==Z.map)return V(r,{code:H.invalid_type,expected:Z.map,received:r.parsedType}),J;const s=this._def.keyType,o=this._def.valueType,i=[...r.data.entries()].map(([a,c],u)=>({key:s._parse(new Ct(r,a,r.path,[u,"key"])),value:o._parse(new Ct(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 J;(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 J;(u.status==="dirty"||f.status==="dirty")&&n.dirty(),a.set(u.value,f.value)}return{status:n.value,value:a}}}}bo.create=(e,t,n)=>new bo({valueType:t,keyType:e,typeName:Y.ZodMap,...te(n)});class qn extends se{_parse(t){const{status:n,ctx:r}=this._processInputParams(t);if(r.parsedType!==Z.set)return V(r,{code:H.invalid_type,expected:Z.set,received:r.parsedType}),J;const s=this._def;s.minSize!==null&&r.data.sizes.maxSize.value&&(V(r,{code:H.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 J;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 Ct(r,c,r.path,u)));return r.common.async?Promise.all(a).then(c=>i(c)):i(a)}min(t,n){return new qn({...this._def,minSize:{value:t,message:W.toString(n)}})}max(t,n){return new qn({...this._def,maxSize:{value:t,message:W.toString(n)}})}size(t,n){return this.min(t,n).max(t,n)}nonempty(t){return this.min(1,t)}}qn.create=(e,t)=>new qn({valueType:e,minSize:null,maxSize:null,typeName:Y.ZodSet,...te(t)});class dr extends se{constructor(){super(...arguments),this.validate=this.implement}_parse(t){const{ctx:n}=this._processInputParams(t);if(n.parsedType!==Z.function)return V(n,{code:H.invalid_type,expected:Z.function,received:n.parsedType}),J;function r(a,c){return ho({data:a,path:n.path,errorMaps:[n.common.contextualErrorMap,n.schemaErrorMap,lo(),es].filter(u=>!!u),issueData:{code:H.invalid_arguments,argumentsError:c}})}function s(a,c){return ho({data:a,path:n.path,errorMaps:[n.common.contextualErrorMap,n.schemaErrorMap,lo(),es].filter(u=>!!u),issueData:{code:H.invalid_return_type,returnTypeError:c}})}const o={errorMap:n.common.contextualErrorMap},i=n.data;return this._def.returns instanceof Er?Je(async(...a)=>{const c=new yt([]),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})}):Je((...a)=>{const c=this._def.args.safeParse(a,o);if(!c.success)throw new yt([r(a,c.error)]);const u=i(...c.data),f=this._def.returns.safeParse(u,o);if(!f.success)throw new yt([s(u,f.error)]);return f.data})}parameters(){return this._def.args}returnType(){return this._def.returns}args(...t){return new dr({...this._def,args:Pt.create(t).rest(Dn.create())})}returns(t){return new dr({...this._def,returns:t})}implement(t){return this.parse(t)}strictImplement(t){return this.parse(t)}static create(t,n,r){return new dr({args:t||Pt.create([]).rest(Dn.create()),returns:n||Dn.create(),typeName:Y.ZodFunction,...te(r)})}}class as extends se{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})}}as.create=(e,t)=>new as({getter:e,typeName:Y.ZodLazy,...te(t)});class cs extends se{_parse(t){if(t.data!==this._def.value){const n=this._getOrReturnCtx(t);return V(n,{received:n.data,code:H.invalid_literal,expected:this._def.value}),J}return{status:"valid",value:t.data}}get value(){return this._def.value}}cs.create=(e,t)=>new cs({value:e,typeName:Y.ZodLiteral,...te(t)});function cd(e,t){return new kn({values:e,typeName:Y.ZodEnum,...te(t)})}class kn extends se{_parse(t){if(typeof t.data!="string"){const n=this._getOrReturnCtx(t),r=this._def.values;return V(n,{expected:ge.joinValues(r),received:n.parsedType,code:H.invalid_type}),J}if(this._def.values.indexOf(t.data)===-1){const n=this._getOrReturnCtx(t),r=this._def.values;return V(n,{received:n.data,code:H.invalid_enum_value,options:r}),J}return Je(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 kn.create(t)}exclude(t){return kn.create(this.options.filter(n=>!t.includes(n)))}}kn.create=cd;class us extends se{_parse(t){const n=ge.getValidEnumValues(this._def.values),r=this._getOrReturnCtx(t);if(r.parsedType!==Z.string&&r.parsedType!==Z.number){const s=ge.objectValues(n);return V(r,{expected:ge.joinValues(s),received:r.parsedType,code:H.invalid_type}),J}if(n.indexOf(t.data)===-1){const s=ge.objectValues(n);return V(r,{received:r.data,code:H.invalid_enum_value,options:s}),J}return Je(t.data)}get enum(){return this._def.values}}us.create=(e,t)=>new us({values:e,typeName:Y.ZodNativeEnum,...te(t)});class Er extends se{unwrap(){return this._def.type}_parse(t){const{ctx:n}=this._processInputParams(t);if(n.parsedType!==Z.promise&&n.common.async===!1)return V(n,{code:H.invalid_type,expected:Z.promise,received:n.parsedType}),J;const r=n.parsedType===Z.promise?n.data:Promise.resolve(n.data);return Je(r.then(s=>this._def.type.parseAsync(s,{path:n.path,errorMap:n.common.contextualErrorMap})))}}Er.create=(e,t)=>new Er({type:e,typeName:Y.ZodPromise,...te(t)});class xt extends se{innerType(){return this._def.schema}sourceType(){return this._def.schema._def.typeName===Y.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=>{V(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"?J:(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"?J:(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(!po(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=>po(i)?Promise.resolve(s.transform(i.value,o)).then(a=>({status:n.value,value:a})):i);ge.assertNever(s)}}xt.create=(e,t,n)=>new xt({schema:e,typeName:Y.ZodEffects,effect:t,...te(n)});xt.createWithPreprocess=(e,t,n)=>new xt({schema:t,effect:{type:"preprocess",transform:e},typeName:Y.ZodEffects,...te(n)});class Zt extends se{_parse(t){return this._getType(t)===Z.undefined?Je(void 0):this._def.innerType._parse(t)}unwrap(){return this._def.innerType}}Zt.create=(e,t)=>new Zt({innerType:e,typeName:Y.ZodOptional,...te(t)});class zn extends se{_parse(t){return this._getType(t)===Z.null?Je(null):this._def.innerType._parse(t)}unwrap(){return this._def.innerType}}zn.create=(e,t)=>new zn({innerType:e,typeName:Y.ZodNullable,...te(t)});class fs extends se{_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}}fs.create=(e,t)=>new fs({innerType:e,typeName:Y.ZodDefault,defaultValue:typeof t.default=="function"?t.default:()=>t.default,...te(t)});class wo extends se{_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 go(s)?s.then(o=>({status:"valid",value:o.status==="valid"?o.value:this._def.catchValue({get error(){return new yt(r.common.issues)},input:r.data})})):{status:"valid",value:s.status==="valid"?s.value:this._def.catchValue({get error(){return new yt(r.common.issues)},input:r.data})}}removeCatch(){return this._def.innerType}}wo.create=(e,t)=>new wo({innerType:e,typeName:Y.ZodCatch,catchValue:typeof t.catch=="function"?t.catch:()=>t.catch,...te(t)});class xo extends se{_parse(t){if(this._getType(t)!==Z.nan){const r=this._getOrReturnCtx(t);return V(r,{code:H.invalid_type,expected:Z.nan,received:r.parsedType}),J}return{status:"valid",value:t.data}}}xo.create=e=>new xo({typeName:Y.ZodNaN,...te(e)});const x1=Symbol("zod_brand");class ud extends se{_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 xs extends se{_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"?J:o.status==="dirty"?(n.dirty(),ad(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"?J: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 xs({in:t,out:n,typeName:Y.ZodPipeline})}}const fd=(e,t={},n)=>e?vr.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})}}):vr.create(),v1={object:Ae.lazycreate};var Y;(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"})(Y||(Y={}));const E1=(e,t={message:`Input not instance of ${e.name}`})=>fd(n=>n instanceof e,t),ld=pt.create,dd=vn.create,k1=xo.create,S1=En.create,hd=ts.create,$1=Vn.create,_1=mo.create,A1=ns.create,B1=rs.create,T1=vr.create,I1=Dn.create,O1=zt.create,C1=yo.create,P1=bt.create,U1=Ae.create,N1=Ae.strictCreate,L1=ss.create,R1=Vo.create,H1=os.create,j1=Pt.create,K1=is.create,D1=bo.create,M1=qn.create,Z1=dr.create,V1=as.create,q1=cs.create,z1=kn.create,F1=us.create,W1=Er.create,lu=xt.create,G1=Zt.create,Y1=zn.create,X1=xt.createWithPreprocess,J1=xs.create,Q1=()=>ld().optional(),ex=()=>dd().optional(),tx=()=>hd().optional(),nx={string:(e=>pt.create({...e,coerce:!0})),number:(e=>vn.create({...e,coerce:!0})),boolean:(e=>ts.create({...e,coerce:!0})),bigint:(e=>En.create({...e,coerce:!0})),date:(e=>Vn.create({...e,coerce:!0}))},rx=J;var Xe=Object.freeze({__proto__:null,defaultErrorMap:es,setErrorMap:a1,getErrorMap:lo,makeIssue:ho,EMPTY_PATH:c1,addIssueToContext:V,ParseStatus:Fe,INVALID:J,DIRTY:ad,OK:Je,isAborted:ea,isDirty:ta,isValid:po,isAsync:go,get util(){return ge},get objectUtil(){return Qi},ZodParsedType:Z,getParsedType:hn,ZodType:se,ZodString:pt,ZodNumber:vn,ZodBigInt:En,ZodBoolean:ts,ZodDate:Vn,ZodSymbol:mo,ZodUndefined:ns,ZodNull:rs,ZodAny:vr,ZodUnknown:Dn,ZodNever:zt,ZodVoid:yo,ZodArray:bt,ZodObject:Ae,ZodUnion:ss,ZodDiscriminatedUnion:Vo,ZodIntersection:os,ZodTuple:Pt,ZodRecord:is,ZodMap:bo,ZodSet:qn,ZodFunction:dr,ZodLazy:as,ZodLiteral:cs,ZodEnum:kn,ZodNativeEnum:us,ZodPromise:Er,ZodEffects:xt,ZodTransformer:xt,ZodOptional:Zt,ZodNullable:zn,ZodDefault:fs,ZodCatch:wo,ZodNaN:xo,BRAND:x1,ZodBranded:ud,ZodPipeline:xs,custom:fd,Schema:se,ZodSchema:se,late:v1,get ZodFirstPartyTypeKind(){return Y},coerce:nx,any:T1,array:P1,bigint:S1,boolean:hd,date:$1,discriminatedUnion:R1,effect:lu,enum:z1,function:Z1,instanceof:E1,intersection:H1,lazy:V1,literal:q1,map:D1,nan:k1,nativeEnum:F1,never:O1,null:B1,nullable:Y1,number:dd,object:U1,oboolean:tx,onumber:ex,optional:G1,ostring:Q1,pipeline:J1,preprocess:X1,promise:W1,record:K1,set:M1,strictObject:N1,string:ld,symbol:_1,transformer:lu,tuple:j1,undefined:A1,union:L1,unknown:I1,void:C1,NEVER:rx,ZodIssueCode:H,quotelessJson:i1,ZodError:yt});const pd=Xe.string().regex(/^[a-fA-F0-9]$/),sx=Xe.string().regex(/^[a-fA-F0-9]{64}$/),kr=Xe.number().min(0).max(4294967295),ox=Xe.bigint(),gd=Xe.instanceof(Uint8Array),ix=Xe.union([pd,kr,Xe.string(),gd]).array(),tc=Xe.union([ix,pd,gd]),ax=Xe.array(tc),md=Xe.object({value:Xe.union([kr,ox]),scriptPubKey:tc}),cx=Xe.object({txid:sx,vout:kr,scriptSig:tc,sequence:kr,prevout:md.optional(),witness:ax});Xe.object({version:kr,vin:Xe.array(cx),vout:Xe.array(md),locktime:kr});const ra=2048,ux=new TextEncoder;function yd(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=ux.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>ra)throw new Error(`Metadata must be at most ${ra} CBOR bytes.`)};return r(e),Uint8Array.from(t)}function fx(e){if(e=new Uint8Array(e),!e.length||e.length>ra)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}}),Ke=(e,t)=>({value:e,scriptPubKey:t}),du=16*1024,Bt=1e3,de=500,vo="text/plain;charset=utf-8",lx=["text/plain","application/json","text/html","image/svg+xml","image/png","image/jpeg","image/webp"],bd=new TextEncoder,Wr=e=>Array.from(e,t=>t.toString(16).padStart(2,"0")).join(""),Cn=e=>Uint8Array.from(e.match(/../g)??[],t=>parseInt(t,16)),Eo=e=>Wr(bd.encode(e));function nc(e){const t=typeof e=="string"?{contentType:vo,bytes:bd.encode(e)}:e;if(!t||![...lx,vo].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>du)throw new Error(`Body must be at most ${du} bytes.`);return{contentType:t.contentType,bytes:new Uint8Array(t.bytes)}}function ko(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 hu(e){if(typeof e!="string"||!/^[0-9a-f]{64,72}$/.test(e)||e.length%2)throw new Error("Invalid parent tag.");const t=[...Cn(e.slice(64))].reduce((r,s,o)=>r+s*256**o,0),n=`${e.slice(0,64).match(/../g).reverse().join("")}i${t}`;if(ko(n)!==e)throw new Error("Non-canonical parent tag.");return n}function wd(e,t,n=null,r=void 0,s={}){const{contentType:o,bytes:i}=nc(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:yd(r),d=[];for(let h=0;h{const g=h.length/2;return(g<=75?g.toString(16).padStart(2,"0"):g<=255?"4c"+g.toString(16).padStart(2,"0"):"4d"+(g%256).toString(16).padStart(2,"0")+Math.floor(g/256).toString(16).padStart(2,"0"))+h};return p(e)+"ac0063"+p(Eo("ord"))+p("01")+p(Eo(o))+(a?p("0b")+p(ko(a)):"")+(c===void 0?"":p("02")+p(xd(c)))+(n?p("03")+p(ko(n)):"")+(l===void 0?"":Array.from({length:Math.ceil(l.length/520)},(h,g)=>p("05")+p(Wr(l.slice(g*520,(g+1)*520)))).join(""))+(f?p("07")+p(Wr(f)):"")+"00"+d.map(p).join("")+"68"}const dx=e=>Zo.tree.getLeaf(Be.encode(e,!0));function rc(e){if(!Array.isArray(e)||e.length!==3)throw new Error("Unsupported script-path witness.");const t=Be.decode(e[1]);let n=7,r=null,s=null,o;t[n]==="0b"&&(s=hu(t[n+1]),n+=2),t[n]==="02"&&(o=px(t[n+1]==="OP_0"?"":t[n+1]),n+=2),t[n]==="03"&&(r=hu(t[n+1]),n+=2);const i=[];for(;t[n]==="05";){const h=t[n+1];if(typeof h!="string"||!/^(?:[0-9a-f]{2}){1,520}$/.test(h))throw new Error("Invalid metadata push.");i.push(h),n+=2}const a=i.length?fx(Cn(i.join(""))):void 0;let c=null;if(t[n]==="07"){const h=t[n+1];if(typeof h!="string"||!/^(?:[0-9a-f]{2}){1,520}$/.test(h))throw new Error("Invalid metaprotocol field.");c=new TextDecoder().decode(Cn(h)),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(h=>typeof h!="string"||!/^(?:[0-9a-f]{2})+$/.test(h)))throw new Error("Invalid body envelope.");const f=new TextDecoder().decode(Cn(t[6])),l=nc({contentType:f,bytes:Cn(u.join(""))}),d=wd(t[0],l,r,a,{delegate:s,pointer:o,metaprotocol:c}),p=a===void 0&&!r&&f===vo&&l.bytes.length<=280&&Be.encode([t[0],"OP_CHECKSIG","OP_0","OP_IF",Eo("ord"),"01",Eo(vo),"OP_0",Wr(l.bytes),"OP_ENDIF"],!1).hex;if(d!==e[1]&&p!==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?Cn(i.join("")):void 0,text:new TextDecoder().decode(l.bytes),pubkey:t[0]}}class hx{constructor(t,n){this.chain=t,this.wallet=n}prepare(t,n=null,r=void 0,s={}){const o=nc(t);if(r!==void 0&&yd(r),s.delegate&&ko(s.delegate),s.pointer!==void 0&&xd(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*de+330);if(!u)throw new Error("Mine a block first to get spendable fake BTC.");return{...o,coin:u,parent:a,reinscribe:c,totalFee:de*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(x=>x.id===s.reinscribe),l=f?this.chain.satLocation(f.sat).offset:s.pointer??(i?i.value:void 0),d=wd(this.wallet.pubkey,c,n,r,{...s,pointer:l}),p=dx(d),[h,g]=Zo.getPubKey(this.wallet.pubkey,{target:p}),m=ie.create({vin:[Vt(o.txid,o.vout,o.value,o.scriptPubKey)],vout:[Ke(Bt+de,["OP_1",h]),Ke(o.value-Bt-2*de,this.wallet.script)]});m.vin[0].witness=[this.wallet.sign(m)];const b=ie.util.getTxid(m),w=ie.create({vin:[...u?[Vt(u.txid,u.vout,u.value,u.scriptPubKey)]:[],Vt(b,0,Bt+de,["OP_1",h])],vout:[...u?[Ke(u.value,this.wallet.script)]:[],Ke(Bt,this.wallet.script)]}),y=u?1:0;return w.vin[y].witness=[this.wallet.sign(w,p,y),Be.encode(d,!1).hex,g],u&&(w.vin[0].witness=[this.wallet.sign(w)]),this.chain.submitPackage([ie.encode(m).hex,ie.encode(w).hex]),`${ie.util.getTxid(w)}i0`}list(){return this.chain.coins(this.wallet.script).flatMap(t=>t.inscriptions??[])}}function xd(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 px(e){if(typeof e!="string"||!/^(?:[0-9a-f]{2}){0,8}$/.test(e))throw new Error("Invalid pointer tag.");return[...Cn(e)].reduce((t,n,r)=>t+(BigInt(n)<this.utxos.set(`${r.txid}:${r.vout}`,{txid:r.txid,vout:r.vout,value:r.value,ranges:uf(s,r.value)}));const n=(r,s,o)=>{var b;const i=ie.decode(r),a=ie.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=df(i,u,s,c);i.vin.forEach(w=>this.utxos.delete(`${w.txid}:${w.vout}`)),i.vout.forEach((w,y)=>this.utxos.set(`${a}:${y}`,{txid:a,vout:y,value:Number(w.value),ranges:f[y]}));const l=(b=i.vin.find(w=>{var y;return((y=w.witness)==null?void 0:y.length)===3}))==null?void 0:b.witness;if(!l)return;const d=rc(l),p=BigInt(d.pointer??0),h=i.vout.reduce((w,y)=>w+Number(y.value),0),g=lf(f.flat(),pw.sat===g).length,status:s===null?"pending":"confirmed",height:s,block:o,metadata:m??null,hasMetadata:m!==void 0,parent:d.parent,protocol:d.metaprotocol??(m&&!Array.isArray(m)&&typeof m=="object"&&Object.hasOwn(m,"protocol")&&typeof m.protocol=="string"?m.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 rr=typeof globalThis=="object"&&"crypto"in globalThis?globalThis.crypto:void 0;/*! noble-hashes - MIT License (c) 2022 Paul Miller (paulmillr.com) */function Es(e){return e instanceof Uint8Array||ArrayBuffer.isView(e)&&e.constructor.name==="Uint8Array"}function It(e){if(!Number.isSafeInteger(e)||e<0)throw new Error("positive integer expected, got "+e)}function He(e,...t){if(!Es(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 ks(e){if(typeof e!="function"||typeof e.create!="function")throw new Error("Hash should be wrapped by utils.createHasher");It(e.outputLen),It(e.blockLen)}function Sr(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 vd(e,t){He(e);const n=t.outputLen;if(e.length>>t}function Ls(e,t){return e<>>32-t>>>0}const mx=new Uint8Array(new Uint32Array([287454020]).buffer)[0]===68;function yx(e){return e<<24&4278190080|e<<8&16711680|e>>>8&65280|e>>>24&255}function bx(e){for(let t=0;te:bx,Ed=typeof Uint8Array.from([]).toHex=="function"&&typeof Uint8Array.fromHex=="function",wx=Array.from({length:256},(e,t)=>t.toString(16).padStart(2,"0"));function Se(e){if(He(e),Ed)return e.toHex();let t="";for(let n=0;n=jt._0&&e<=jt._9)return e-jt._0;if(e>=jt.A&&e<=jt.F)return e-(jt.A-10);if(e>=jt.a&&e<=jt.f)return e-(jt.a-10)}function ut(e){if(typeof e!="string")throw new Error("hex string expected, got "+typeof e);if(Ed)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($r(r)).digest(),n=e();return t.outputLen=n.outputLen,t.blockLen=n.blockLen,t.create=()=>e(),t}function er(e=32){if(rr&&typeof rr.getRandomValues=="function")return rr.getRandomValues(new Uint8Array(e));if(rr&&typeof rr.randomBytes=="function")return Uint8Array.from(rr.randomBytes(e));throw new Error("crypto.getRandomValues must be defined")}function vx(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 Ex(e,t,n){return e&t^~e&n}function kx(e,t,n){return e&t^e&n^t&n}class oc extends sc{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=Mn(this.buffer)}update(t){Sr(this),t=$r(t),He(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>yu&Rs)}:{h:Number(e>>yu&Rs)|0,l:Number(e&Rs)|0}}function kd(e,t=!1){const n=e.length;let r=new Uint32Array(n),s=new Uint32Array(n);for(let o=0;oe>>>n,wu=(e,t,n)=>e<<32-n|t>>>n,sr=(e,t,n)=>e>>>n|t<<32-n,or=(e,t,n)=>e<<32-n|t>>>n,Hs=(e,t,n)=>e<<64-n|t>>>n-32,js=(e,t,n)=>e>>>n-32|t<<64-n,$x=(e,t,n)=>e<>>32-n,_x=(e,t,n)=>t<>>32-n,Ax=(e,t,n)=>t<>>64-n,Bx=(e,t,n)=>e<>>64-n;function Kt(e,t,n,r){const s=(t>>>0)+(r>>>0);return{h:e+n+(s/2**32|0)|0,l:s|0}}const Tx=(e,t,n)=>(e>>>0)+(t>>>0)+(n>>>0),Ix=(e,t,n,r)=>t+n+r+(e/2**32|0)|0,Ox=(e,t,n,r)=>(e>>>0)+(t>>>0)+(n>>>0)+(r>>>0),Cx=(e,t,n,r,s)=>t+n+r+s+(e/2**32|0)|0,Px=(e,t,n,r,s)=>(e>>>0)+(t>>>0)+(n>>>0)+(r>>>0)+(s>>>0),Ux=(e,t,n,r,s,o)=>t+n+r+s+o+(e/2**32|0)|0,Nx=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]),an=new Uint32Array(64);class Lx extends oc{constructor(t=32){super(64,t,8,!1),this.A=on[0]|0,this.B=on[1]|0,this.C=on[2]|0,this.D=on[3]|0,this.E=on[4]|0,this.F=on[5]|0,this.G=on[6]|0,this.H=on[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)an[l]=t.getUint32(n,!1);for(let l=16;l<64;l++){const d=an[l-15],p=an[l-2],h=At(d,7)^At(d,18)^d>>>3,g=At(p,17)^At(p,19)^p>>>10;an[l]=g+an[l-7]+h+an[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=At(a,6)^At(a,11)^At(a,25),p=f+d+Ex(a,c,u)+Nx[l]+an[l]|0,g=(At(r,2)^At(r,13)^At(r,22))+kx(r,s,o)|0;f=u,u=c,c=a,a=i+p|0,i=o,o=s,s=r,r=p+g|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(){ct(an)}destroy(){this.set(0,0,0,0,0,0,0,0),ct(this.buffer)}}const Sd=kd(["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))),Rx=Sd[0],Hx=Sd[1],cn=new Uint32Array(80),un=new Uint32Array(80);class jx extends oc{constructor(t=64){super(128,t,16,!1),this.Ah=Ve[0]|0,this.Al=Ve[1]|0,this.Bh=Ve[2]|0,this.Bl=Ve[3]|0,this.Ch=Ve[4]|0,this.Cl=Ve[5]|0,this.Dh=Ve[6]|0,this.Dl=Ve[7]|0,this.Eh=Ve[8]|0,this.El=Ve[9]|0,this.Fh=Ve[10]|0,this.Fl=Ve[11]|0,this.Gh=Ve[12]|0,this.Gl=Ve[13]|0,this.Hh=Ve[14]|0,this.Hl=Ve[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:p,Gl:h,Hh:g,Hl:m}=this;return[t,n,r,s,o,i,a,c,u,f,l,d,p,h,g,m]}set(t,n,r,s,o,i,a,c,u,f,l,d,p,h,g,m){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=p|0,this.Gl=h|0,this.Hh=g|0,this.Hl=m|0}process(t,n){for(let y=0;y<16;y++,n+=4)cn[y]=t.getUint32(n),un[y]=t.getUint32(n+=4);for(let y=16;y<80;y++){const x=cn[y-15]|0,$=un[y-15]|0,E=sr(x,$,1)^sr(x,$,8)^bu(x,$,7),I=or(x,$,1)^or(x,$,8)^wu(x,$,7),P=cn[y-2]|0,B=un[y-2]|0,U=sr(P,B,19)^Hs(P,B,61)^bu(P,B,6),L=or(P,B,19)^js(P,B,61)^wu(P,B,6),D=Ox(I,L,un[y-7],un[y-16]),k=Cx(D,E,U,cn[y-7],cn[y-16]);cn[y]=k|0,un[y]=D|0}let{Ah:r,Al:s,Bh:o,Bl:i,Ch:a,Cl:c,Dh:u,Dl:f,Eh:l,El:d,Fh:p,Fl:h,Gh:g,Gl:m,Hh:b,Hl:w}=this;for(let y=0;y<80;y++){const x=sr(l,d,14)^sr(l,d,18)^Hs(l,d,41),$=or(l,d,14)^or(l,d,18)^js(l,d,41),E=l&p^~l&g,I=d&h^~d&m,P=Px(w,$,I,Hx[y],un[y]),B=Ux(P,b,x,E,Rx[y],cn[y]),U=P|0,L=sr(r,s,28)^Hs(r,s,34)^Hs(r,s,39),D=or(r,s,28)^js(r,s,34)^js(r,s,39),k=r&o^r&a^o&a,_=s&i^s&c^i&c;b=g|0,w=m|0,g=p|0,m=h|0,p=l|0,h=d|0,{h:l,l:d}=Kt(u|0,f|0,B|0,U|0),u=a|0,f=c|0,a=o|0,c=i|0,o=r|0,i=s|0;const v=Tx(U,D,_);r=Ix(v,B,L,k),s=v|0}({h:r,l:s}=Kt(this.Ah|0,this.Al|0,r|0,s|0)),{h:o,l:i}=Kt(this.Bh|0,this.Bl|0,o|0,i|0),{h:a,l:c}=Kt(this.Ch|0,this.Cl|0,a|0,c|0),{h:u,l:f}=Kt(this.Dh|0,this.Dl|0,u|0,f|0),{h:l,l:d}=Kt(this.Eh|0,this.El|0,l|0,d|0),{h:p,l:h}=Kt(this.Fh|0,this.Fl|0,p|0,h|0),{h:g,l:m}=Kt(this.Gh|0,this.Gl|0,g|0,m|0),{h:b,l:w}=Kt(this.Hh|0,this.Hl|0,b|0,w|0),this.set(r,s,o,i,a,c,u,f,l,d,p,h,g,m,b,w)}roundClean(){ct(cn,un)}destroy(){ct(this.buffer),this.set(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0)}}const xe=qo(()=>new Lx),ls=qo(()=>new jx);class $d extends sc{constructor(t,n){super(),this.finished=!1,this.destroyed=!1,ks(t);const r=$r(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 $d(e,t).update(n).digest();Sn.create=(e,t)=>new $d(e,t);/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */const ic=BigInt(0),sa=BigInt(1);function Fn(e,t=""){if(typeof e!="boolean"){const n=t&&`"${t}"`;throw new Error(n+"expected boolean, got type="+typeof e)}return e}function gt(e,t,n=""){const r=Es(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 Ks(e){const t=e.toString(16);return t.length&1?"0"+t:t}function _d(e){if(typeof e!="string")throw new Error("hex string expected, got "+typeof e);return e===""?ic:BigInt("0x"+e)}function tr(e){return _d(Se(e))}function Wn(e){return He(e),_d(Se(Uint8Array.from(e).reverse()))}function zo(e,t){return ut(e.toString(16).padStart(t*2,"0"))}function ac(e,t){return zo(e,t).reverse()}function me(e,t,n){let r;if(typeof t=="string")try{r=ut(t)}catch(o){throw new Error(e+" must be hex string or Uint8Array, cause: "+o)}else if(Es(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 xu(e){return Uint8Array.from(e)}const bi=e=>typeof e=="bigint"&&ic<=e;function oa(e,t,n){return bi(e)&&bi(t)&&bi(n)&&t<=e&&eic;e>>=sa,t+=1);return t}const Ss=e=>(sa<new Uint8Array(p),s=p=>Uint8Array.of(p);let o=r(e),i=r(e),a=0;const c=()=>{o.fill(1),i.fill(0),a=0},u=(...p)=>n(i,o,...p),f=(p=r(0))=>{i=u(s(0),p),o=u(),p.length!==0&&(i=u(s(1),p),o=u())},l=()=>{if(a++>=1e3)throw new Error("drbg: tried 1000 values");let p=0;const h=[];for(;p{c(),f(p);let g;for(;!(g=h(l()));)f();return c(),g}}function Ur(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 So(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 et=BigInt(0),Ze=BigInt(1),Rn=BigInt(2),Bd=BigInt(3),Td=BigInt(4),Id=BigInt(5),Dx=BigInt(7),Od=BigInt(8),Mx=BigInt(9),Cd=BigInt(16);function Ee(e,t){const n=e%t;return n>=et?n:t+n}function _e(e,t,n){let r=e;for(;t-- >et;)r*=r,r%=n;return r}function vu(e,t){if(e===et)throw new Error("invert: expected non-zero number");if(t<=et)throw new Error("invert: expected positive modulus, got "+t);let n=Ee(e,t),r=t,s=et,o=Ze;for(;n!==et;){const a=r/n,c=r%n,u=s-o*a;r=n,n=c,s=o,o=u}if(r!==Ze)throw new Error("invert: does not exist");return Ee(s,t)}function cc(e,t,n){if(!e.eql(e.sqr(t),n))throw new Error("Cannot find square root")}function Pd(e,t){const n=(e.ORDER+Ze)/Td,r=e.pow(t,n);return cc(e,r,t),r}function Zx(e,t){const n=(e.ORDER-Id)/Od,r=e.mul(t,Rn),s=e.pow(r,n),o=e.mul(t,s),i=e.mul(e.mul(o,Rn),s),a=e.mul(o,e.sub(i,e.ONE));return cc(e,a,t),a}function Vx(e){const t=nr(e),n=Ud(e),r=n(t,t.neg(t.ONE)),s=n(t,r),o=n(t,t.neg(r)),i=(e+Dx)/Cd;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),p=a.eql(a.sqr(f),c),h=a.eql(a.sqr(l),c);u=a.cmov(u,f,p),f=a.cmov(d,l,h);const g=a.eql(a.sqr(f),c),m=a.cmov(u,f,g);return cc(a,m,c),m}}function Ud(e){if(e1e3)throw new Error("Cannot find square root: probably non-prime P");if(n===1)return Pd;let o=s.pow(r,t);const i=(t+Ze)/Rn;return function(c,u){if(c.is0(u))return u;if(Eu(c,u)!==1)throw new Error("Cannot find square root");let f=n,l=c.mul(c.ONE,o),d=c.pow(u,t),p=c.pow(u,i);for(;!c.eql(d,c.ONE);){if(c.is0(d))return c.ZERO;let h=1,g=c.sqr(d);for(;!c.eql(g,c.ONE);)if(h++,g=c.sqr(g),h===f)throw new Error("Cannot find square root");const m=Ze<(Ee(e,t)&Ze)===Ze,Fx=["create","isValid","is0","neg","inv","sqrt","sqr","eql","add","sub","mul","pow","div","addN","subN","mulN","sqrN"];function Wx(e){const t={ORDER:"bigint",MASK:"bigint",BYTES:"number",BITS:"number"},n=Fx.reduce((r,s)=>(r[s]="function",r),t);return Ur(e,n),e}function Gx(e,t,n){if(net;)n&Ze&&(r=e.mul(r,s)),s=e.sqr(s),n>>=Ze;return r}function Nd(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 Eu(e,t){const n=(e.ORDER-Ze)/Rn,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 Ld(e,t){t!==void 0&&It(t);const n=t!==void 0?t:e.toString(2).length,r=Math.ceil(n/8);return{nBitLength:n,nByteLength:r}}function nr(e,t,n=!1,r={}){if(e<=et)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}=Ld(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:Ss(c),ZERO:et,ONE:Ze,allowedLengths:a,create:d=>Ee(d,e),isValid:d=>{if(typeof d!="bigint")throw new Error("invalid field element: expected bigint, got "+typeof d);return et<=d&&dd===et,isValidNot0:d=>!l.is0(d)&&l.isValid(d),isOdd:d=>(d&Ze)===Ze,neg:d=>Ee(-d,e),eql:(d,p)=>d===p,sqr:d=>Ee(d*d,e),add:(d,p)=>Ee(d+p,e),sub:(d,p)=>Ee(d-p,e),mul:(d,p)=>Ee(d*p,e),pow:(d,p)=>Gx(l,d,p),div:(d,p)=>Ee(d*vu(p,e),e),sqrN:d=>d*d,addN:(d,p)=>d+p,subN:(d,p)=>d-p,mulN:(d,p)=>d*p,inv:d=>vu(d,e),sqrt:o||(d=>(f||(f=qx(e)),f(l,d))),toBytes:d=>n?ac(d,u):zo(d,u),fromBytes:(d,p=!0)=>{if(a){if(!a.includes(d.length)||d.length>u)throw new Error("Field.fromBytes: expected "+a+" bytes, got "+d.length);const g=new Uint8Array(u);g.set(d,n?0:g.length-d.length),d=g}if(d.length!==u)throw new Error("Field.fromBytes: expected "+u+" bytes, got "+d.length);let h=n?Wn(d):tr(d);if(i&&(h=Ee(h,e)),!p&&!l.isValid(h))throw new Error("invalid field element: outside of range 0..ORDER");return h},invertBatch:d=>Nd(l,d),cmov:(d,p,h)=>h?p:d});return Object.freeze(l)}function Rd(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 Hd(e){const t=Rd(e);return t+Math.ceil(t/2)}function jd(e,t,n=!1){const r=e.length,s=Rd(t),o=Hd(t);if(r<16||r1024)throw new Error("expected "+o+"-1024 bytes of input, got "+r);const i=n?Wn(e):tr(e),a=Ee(i,t-Ze)+Ze;return n?ac(a,s):zo(a,s)}/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */const _r=BigInt(0),Hn=BigInt(1);function $o(e,t){const n=t.negate();return e?n:t}function jn(e,t){const n=Nd(e.Fp,t.map(r=>r.Z));return t.map((r,s)=>e.fromAffine(r.toAffine(n[s])))}function Kd(e,t){if(!Number.isSafeInteger(e)||e<=0||e>t)throw new Error("invalid window size, expected [1.."+t+"], got W="+e)}function wi(e,t){Kd(e,t);const n=Math.ceil(t/e)+1,r=2**(e-1),s=2**e,o=Ss(e),i=BigInt(e);return{windows:n,windowSize:r,mask:o,maxNumber:s,shiftBy:i}}function ku(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+=Hn);const u=t*r,f=u+Math.abs(a)-1,l=a===0,d=a<0,p=t%2!==0;return{nextN:c,offset:f,isZero:l,isNeg:d,isNegF:p,offsetF:u}}function Yx(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 Xx(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 xi=new WeakMap,Dd=new WeakMap;function vi(e){return Dd.get(e)||1}function Su(e){if(e!==_r)throw new Error("invalid wNAF")}class Md{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>_r;)n&Hn&&(r=r.add(s)),s=s.double(),n>>=Hn;return r}precomputeWindow(t,n){const{windows:r,windowSize:s}=wi(n,this.bits),o=[];let i=t,a=i;for(let c=0;c_r||r>_r;)n&Hn&&(o=o.add(s)),r&Hn&&(i=i.add(s)),s=s.double(),n>>=Hn,r>>=Hn;return{p1:o,p2:i}}function Zd(e,t,n,r){Yx(n,e),Xx(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=Ad(BigInt(s));let c=1;a>12?c=a-3:a>4?c=a-2:a>0&&(c=2);const u=Ss(c),f=new Array(Number(u)+1).fill(i),l=Math.floor((t.BITS-1)/c)*c;let d=i;for(let p=l;p>=0;p-=c){f.fill(i);for(let g=0;g>BigInt(p)&u);f[b]=f[b].add(n[g])}let h=i;for(let g=f.length-1,m=i;g>0;g--)m=m.add(f[g]),h=h.add(m);if(d=d.add(h),p!==0)for(let g=0;g_r))throw new Error(`CURVE.${c} must be positive bigint`)}const s=$u(t.p,n.Fp,r),o=$u(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 _u=(e,t)=>(e+(e>=0?t:-t)/qd)/t;function Qx(e,t,n){const[[r,s],[o,i]]=t,a=_u(i*e,n),c=_u(-s*e,n);let u=e-a*r-c*o,f=-a*s-c*i;const l=u=p||f=p)throw new Error("splitScalar (endomorphism): failed, k="+e);return{k1neg:l,k1:u,k2neg:d,k2:f}}function ia(e){if(!["compact","recovered","der"].includes(e))throw new Error('Signature format must be "compact", "recovered", or "der"');return e}function Ei(e,t){const n={};for(let r of Object.keys(t))n[r]=e[r]===void 0?t[r]:e[r];return Fn(n.lowS,"lowS"),Fn(n.prehash,"prehash"),n.format!==void 0&&ia(n.format),n}class e2 extends Error{constructor(t=""){super(t)}}const Dt={Err:e2,_tlv:{encode:(e,t)=>{const{Err:n}=Dt;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=Ks(r);if(s.length/2&128)throw new n("tlv.encode: long form length too big");const o=r>127?Ks(s.length/2|128):"";return Ks(e)+o+s+t},decode(e,t){const{Err:n}=Dt;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}=Dt;if(e{const{X:_,Y:v,Z:A}=D;if(r.eql(A,r.ONE))return{x:_,y:v};const C=D.is0();k==null&&(k=C?r.ONE:r.inv(A));const R=r.mul(_,k),N=r.mul(v,k),j=r.mul(A,k);if(C)return{x:r.ZERO,y:r.ZERO};if(!r.eql(j,r.ONE))throw new Error("invZ was invalid");return{x:R,y:N}}),I=So(D=>{if(D.is0()){if(t.allowInfinityPoint&&!r.is0(D.Y))return;throw new Error("bad point: ZERO")}const{x:k,y:_}=D.toAffine();if(!r.isValid(k)||!r.isValid(_))throw new Error("bad point: x or y not field elements");if(!m(k,_))throw new Error("bad point: equation left != right");if(!D.isTorsionFree())throw new Error("bad point: not in prime-order subgroup");return!0});function P(D,k,_,v,A){return _=new B(r.mul(_.X,D),_.Y,_.Z),k=$o(v,k),_=$o(A,_),k.add(_)}class B{constructor(k,_,v){this.X=y("x",k),this.Y=y("y",_,!0),this.Z=y("z",v),Object.freeze(this)}static CURVE(){return o}static fromAffine(k){const{x:_,y:v}=k||{};if(!k||!r.isValid(_)||!r.isValid(v))throw new Error("invalid affine point");if(k instanceof B)throw new Error("projective point not allowed");return r.is0(_)&&r.is0(v)?B.ZERO:new B(_,v,r.ONE)}static fromBytes(k){const _=B.fromAffine(h(gt(k,void 0,"point")));return _.assertValidity(),_}static fromHex(k){return B.fromBytes(me("pointHex",k))}get x(){return this.toAffine().x}get y(){return this.toAffine().y}precompute(k=8,_=!0){return L.createCache(this,k),_||this.multiply(Ds),this}assertValidity(){I(this)}hasEvenY(){const{y:k}=this.toAffine();if(!r.isOdd)throw new Error("Field doesn't support isOdd");return!r.isOdd(k)}equals(k){x(k);const{X:_,Y:v,Z:A}=this,{X:C,Y:R,Z:N}=k,j=r.eql(r.mul(_,N),r.mul(C,A)),M=r.eql(r.mul(v,N),r.mul(R,A));return j&&M}negate(){return new B(this.X,r.neg(this.Y),this.Z)}double(){const{a:k,b:_}=o,v=r.mul(_,Ds),{X:A,Y:C,Z:R}=this;let N=r.ZERO,j=r.ZERO,M=r.ZERO,F=r.mul(A,A),ue=r.mul(C,C),oe=r.mul(R,R),Q=r.mul(A,C);return Q=r.add(Q,Q),M=r.mul(A,R),M=r.add(M,M),N=r.mul(k,M),j=r.mul(v,oe),j=r.add(N,j),N=r.sub(ue,j),j=r.add(ue,j),j=r.mul(N,j),N=r.mul(Q,N),M=r.mul(v,M),oe=r.mul(k,oe),Q=r.sub(F,oe),Q=r.mul(k,Q),Q=r.add(Q,M),M=r.add(F,F),F=r.add(M,F),F=r.add(F,oe),F=r.mul(F,Q),j=r.add(j,F),oe=r.mul(C,R),oe=r.add(oe,oe),F=r.mul(oe,Q),N=r.sub(N,F),M=r.mul(oe,ue),M=r.add(M,M),M=r.add(M,M),new B(N,j,M)}add(k){x(k);const{X:_,Y:v,Z:A}=this,{X:C,Y:R,Z:N}=k;let j=r.ZERO,M=r.ZERO,F=r.ZERO;const ue=o.a,oe=r.mul(o.b,Ds);let Q=r.mul(_,C),he=r.mul(v,R),pe=r.mul(A,N),Ie=r.add(_,v),fe=r.add(C,R);Ie=r.mul(Ie,fe),fe=r.add(Q,he),Ie=r.sub(Ie,fe),fe=r.add(_,A);let we=r.add(C,N);return fe=r.mul(fe,we),we=r.add(Q,pe),fe=r.sub(fe,we),we=r.add(v,A),j=r.add(R,N),we=r.mul(we,j),j=r.add(he,pe),we=r.sub(we,j),F=r.mul(ue,fe),j=r.mul(oe,pe),F=r.add(j,F),j=r.sub(he,F),F=r.add(he,F),M=r.mul(j,F),he=r.add(Q,Q),he=r.add(he,Q),pe=r.mul(ue,pe),fe=r.mul(oe,fe),he=r.add(he,pe),pe=r.sub(Q,pe),pe=r.mul(ue,pe),fe=r.add(fe,pe),Q=r.mul(he,fe),M=r.add(M,Q),Q=r.mul(we,fe),j=r.mul(Ie,j),j=r.sub(j,Q),Q=r.mul(Ie,he),F=r.mul(we,F),F=r.add(F,Q),new B(j,M,F)}subtract(k){return this.add(k.negate())}is0(){return this.equals(B.ZERO)}multiply(k){const{endo:_}=t;if(!s.isValidNot0(k))throw new Error("invalid scalar: out of range");let v,A;const C=R=>L.cached(this,R,N=>jn(B,N));if(_){const{k1neg:R,k1:N,k2neg:j,k2:M}=$(k),{p:F,f:ue}=C(N),{p:oe,f:Q}=C(M);A=ue.add(Q),v=P(_.beta,F,oe,R,j)}else{const{p:R,f:N}=C(k);v=R,A=N}return jn(B,[v,A])[0]}multiplyUnsafe(k){const{endo:_}=t,v=this;if(!s.isValid(k))throw new Error("invalid scalar: out of range");if(k===Mt||v.is0())return B.ZERO;if(k===hr)return v;if(L.hasCache(this))return this.multiply(k);if(_){const{k1neg:A,k1:C,k2neg:R,k2:N}=$(k),{p1:j,p2:M}=Jx(B,v,C,N);return P(_.beta,j,M,A,R)}else return L.unsafe(v,k)}multiplyAndAddUnsafe(k,_,v){const A=this.multiplyUnsafe(_).add(k.multiplyUnsafe(v));return A.is0()?void 0:A}toAffine(k){return E(this,k)}isTorsionFree(){const{isTorsionFree:k}=t;return i===hr?!0:k?k(B,this):L.unsafe(this,a).is0()}clearCofactor(){const{clearCofactor:k}=t;return i===hr?this:k?k(B,this):this.multiplyUnsafe(i)}isSmallOrder(){return this.multiplyUnsafe(i).is0()}toBytes(k=!0){return Fn(k,"isCompressed"),this.assertValidity(),p(B,this,k)}toHex(k=!0){return Se(this.toBytes(k))}toString(){return``}get px(){return this.X}get py(){return this.X}get pz(){return this.Z}toRawBytes(k=!0){return this.toBytes(k)}_setWindowSize(k){this.precompute(k)}static normalizeZ(k){return jn(B,k)}static msm(k,_){return Zd(B,s,k,_)}static fromPrivateKey(k){return B.BASE.multiply(Kn(s,k))}}B.BASE=new B(o.Gx,o.Gy,r.ONE),B.ZERO=new B(r.ZERO,r.ONE,r.ZERO),B.Fp=r,B.Fn=s;const U=s.BITS,L=new Md(B,t.endo?Math.ceil(U/2):U);return B.BASE.precompute(8),B}function zd(e){return Uint8Array.of(e?2:3)}function Fd(e,t){return{secretKey:t.BYTES,publicKey:1+e.BYTES,publicKeyUncompressed:1+2*e.BYTES,publicKeyHasPrefix:!0,signature:2*t.BYTES}}function r2(e,t={}){const{Fn:n}=e,r=t.randomBytes||er,s=Object.assign(Fd(e.Fp,n),{seed:Hd(n.ORDER)});function o(p){try{return!!Kn(n,p)}catch{return!1}}function i(p,h){const{publicKey:g,publicKeyUncompressed:m}=s;try{const b=p.length;return h===!0&&b!==g||h===!1&&b!==m?!1:!!e.fromBytes(p)}catch{return!1}}function a(p=r(s.seed)){return jd(gt(p,s.seed,"seed"),n.ORDER)}function c(p,h=!0){return e.BASE.multiply(Kn(n,p)).toBytes(h)}function u(p){const h=a(p);return{secretKey:h,publicKey:c(h)}}function f(p){if(typeof p=="bigint")return!1;if(p instanceof e)return!0;const{secretKey:h,publicKey:g,publicKeyUncompressed:m}=s;if(n.allowedLengths||h===g)return;const b=me("key",p).length;return b===g||b===m}function l(p,h,g=!0){if(f(p)===!0)throw new Error("first arg must be private key");if(f(h)===!1)throw new Error("second arg must be public key");const m=Kn(n,p);return e.fromHex(h).multiply(m).toBytes(g)}return Object.freeze({getPublicKey:c,getSharedSecret:l,keygen:u,Point:e,utils:{isValidSecretKey:o,isValidPublicKey:i,randomSecretKey:a,isValidPrivateKey:o,randomPrivateKey:a,normPrivateKeyToScalar:p=>Kn(n,p),precompute(p=8,h=e.BASE){return h.precompute(p,!1)}},lengths:s})}function s2(e,t,n={}){ks(t),Ur(n,{},{hmac:"function",lowS:"boolean",randomBytes:"function",bits2int:"function",bits2int_modN:"function"});const r=n.randomBytes||er,s=n.hmac||((_,...v)=>Sn(t,_,ae(...v))),{Fp:o,Fn:i}=e,{ORDER:a,BITS:c}=i,{keygen:u,getPublicKey:f,getSharedSecret:l,utils:d,lengths:p}=r2(e,n),h={prehash:!1,lowS:typeof n.lowS=="boolean"?n.lowS:!1,format:void 0,extraEntropy:!1},g="compact";function m(_){const v=a>>hr;return _>v}function b(_,v){if(!i.isValidNot0(v))throw new Error(`invalid signature ${_}: out of range 1..Point.Fn.ORDER`);return v}function w(_,v){ia(v);const A=p.signature,C=v==="compact"?A:v==="recovered"?A+1:void 0;return gt(_,C,`${v} signature`)}class y{constructor(v,A,C){this.r=b("r",v),this.s=b("s",A),C!=null&&(this.recovery=C),Object.freeze(this)}static fromBytes(v,A=g){w(v,A);let C;if(A==="der"){const{r:M,s:F}=Dt.toSig(gt(v));return new y(M,F)}A==="recovered"&&(C=v[0],A="compact",v=v.subarray(1));const R=i.BYTES,N=v.subarray(0,R),j=v.subarray(R,R*2);return new y(i.fromBytes(N),i.fromBytes(j),C)}static fromHex(v,A){return this.fromBytes(ut(v),A)}addRecoveryBit(v){return new y(this.r,this.s,v)}recoverPublicKey(v){const A=o.ORDER,{r:C,s:R,recovery:N}=this;if(N==null||![0,1,2,3].includes(N))throw new Error("recovery id invalid");if(a*qd1)throw new Error("recovery id is ambiguous for h>1 curve");const M=N===2||N===3?C+a:C;if(!o.isValid(M))throw new Error("recovery id 2 or 3 invalid");const F=o.toBytes(M),ue=e.fromBytes(ae(zd((N&1)===0),F)),oe=i.inv(M),Q=$(me("msgHash",v)),he=i.create(-Q*oe),pe=i.create(R*oe),Ie=e.BASE.multiplyUnsafe(he).add(ue.multiplyUnsafe(pe));if(Ie.is0())throw new Error("point at infinify");return Ie.assertValidity(),Ie}hasHighS(){return m(this.s)}toBytes(v=g){if(ia(v),v==="der")return ut(Dt.hexFromSig(this));const A=i.toBytes(this.r),C=i.toBytes(this.s);if(v==="recovered"){if(this.recovery==null)throw new Error("recovery bit must be present");return ae(Uint8Array.of(this.recovery),A,C)}return ae(A,C)}toHex(v){return Se(this.toBytes(v))}assertValidity(){}static fromCompact(v){return y.fromBytes(me("sig",v),"compact")}static fromDER(v){return y.fromBytes(me("sig",v),"der")}normalizeS(){return this.hasHighS()?new y(this.r,i.neg(this.s),this.recovery):this}toDERRawBytes(){return this.toBytes("der")}toDERHex(){return Se(this.toBytes("der"))}toCompactRawBytes(){return this.toBytes("compact")}toCompactHex(){return Se(this.toBytes("compact"))}}const x=n.bits2int||function(v){if(v.length>8192)throw new Error("input is too large");const A=tr(v),C=v.length*8-c;return C>0?A>>BigInt(C):A},$=n.bits2int_modN||function(v){return i.create(x(v))},E=Ss(c);function I(_){return ds("num < 2^"+c,_,Mt,E),i.toBytes(_)}function P(_,v){return gt(_,void 0,"message"),v?gt(t(_),void 0,"prehashed message"):_}function B(_,v,A){if(["recovered","canonical"].some(he=>he in A))throw new Error("sign() legacy options not supported");const{lowS:C,prehash:R,extraEntropy:N}=Ei(A,h);_=P(_,R);const j=$(_),M=Kn(i,v),F=[I(M),I(j)];if(N!=null&&N!==!1){const he=N===!0?r(p.secretKey):N;F.push(me("extraEntropy",he))}const ue=ae(...F),oe=j;function Q(he){const pe=x(he);if(!i.isValidNot0(pe))return;const Ie=i.inv(pe),fe=e.BASE.multiply(pe).toAffine(),we=i.create(fe.x);if(we===Mt)return;const Lt=i.create(Ie*i.create(oe+we*M));if(Lt===Mt)return;let rt=(fe.x===we?0:2)|Number(fe.y&hr),De=Lt;return C&&m(Lt)&&(De=i.neg(Lt),rt^=1),new y(we,De,rt)}return{seed:ue,k2sig:Q}}function U(_,v,A={}){_=me("message",_);const{seed:C,k2sig:R}=B(_,v,A);return Kx(t.outputLen,i.BYTES,s)(C,R)}function L(_){let v;const A=typeof _=="string"||Es(_),C=!A&&_!==null&&typeof _=="object"&&typeof _.r=="bigint"&&typeof _.s=="bigint";if(!A&&!C)throw new Error("invalid signature, expected Uint8Array, hex string or Signature instance");if(C)v=new y(_.r,_.s);else if(A){try{v=y.fromBytes(me("sig",_),"der")}catch(R){if(!(R instanceof Dt.Err))throw R}if(!v)try{v=y.fromBytes(me("sig",_),"compact")}catch{return!1}}return v||!1}function D(_,v,A,C={}){const{lowS:R,prehash:N,format:j}=Ei(C,h);if(A=me("publicKey",A),v=P(me("message",v),N),"strict"in C)throw new Error("options.strict was renamed to lowS");const M=j===void 0?L(_):y.fromBytes(me("sig",_),j);if(M===!1)return!1;try{const F=e.fromBytes(A);if(R&&M.hasHighS())return!1;const{r:ue,s:oe}=M,Q=$(v),he=i.inv(oe),pe=i.create(Q*he),Ie=i.create(ue*he),fe=e.BASE.multiplyUnsafe(pe).add(F.multiplyUnsafe(Ie));return fe.is0()?!1:i.create(fe.x)===ue}catch{return!1}}function k(_,v,A={}){const{prehash:C}=Ei(A,h);return v=P(v,C),y.fromBytes(_,"recovered").recoverPublicKey(v).toBytes()}return Object.freeze({keygen:u,getPublicKey:f,getSharedSecret:l,utils:d,lengths:p,Point:e,sign:U,verify:D,recoverPublicKey:k,Signature:y,hash:t})}function o2(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=nr(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 i2(e){const{CURVE:t,curveOpts:n}=o2(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 a2(e,t){const n=t.Point;return Object.assign({},t,{ProjectivePoint:n,CURVE:Object.assign({},e,Ld(n.Fn.ORDER,n.Fn.BITS))})}function c2(e){const{CURVE:t,curveOpts:n,hash:r,ecdsaOpts:s}=i2(e),o=n2(t,n),i=s2(o,r,s);return a2(e,i)}/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */function u2(e,t){const n=r=>c2({...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")},f2={beta:BigInt("0x7ae96a2b657c07106e64479eac3434e99cf0497512f58995c1396c28719501ee"),basises:[[BigInt("0x3086d221a7d46bcde86c90e49284eb15"),-BigInt("0xe4437ed6010e88286f547fa90abfe4c3")],[BigInt("0x114ca50f7a8e2f3f657c1108d9d44cfd8"),BigInt("0x3086d221a7d46bcde86c90e49284eb15")]]},l2=BigInt(0),Au=BigInt(1),aa=BigInt(2);function d2(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=_e(f,n,t)*f%t,d=_e(l,n,t)*f%t,p=_e(d,aa,t)*u%t,h=_e(p,s,t)*p%t,g=_e(h,o,t)*h%t,m=_e(g,a,t)*g%t,b=_e(m,c,t)*m%t,w=_e(b,a,t)*g%t,y=_e(w,n,t)*f%t,x=_e(y,i,t)*h%t,$=_e(x,r,t)*u%t,E=_e($,aa,t);if(!_o.eql(_o.sqr(E),e))throw new Error("Cannot find square root");return E}const _o=nr(Ar.p,{sqrt:d2}),ke=u2({...Ar,Fp:_o,lowS:!0,endo:f2},xe),Bu={};function Ao(e,...t){let n=Bu[e];if(n===void 0){const r=xe(Ne(e));n=ae(r,r),Bu[e]=n}return xe(ae(n,...t))}const uc=e=>e.toBytes(!0).slice(1),Nr=ke.Point,fc=e=>e%aa===l2;function ca(e){const{Fn:t,BASE:n}=Nr,r=Kn(t,e),s=n.multiply(r);return{scalar:fc(s.y)?r:t.neg(r),bytes:uc(s)}}function Wd(e){const t=_o;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);fc(s)||(s=t.neg(s));const o=Nr.fromAffine({x:e,y:s});return o.assertValidity(),o}const Gr=tr;function Gd(...e){return Nr.Fn.create(Gr(Ao("BIP0340/challenge",...e)))}function Tu(e){return ca(e).bytes}function h2(e,t,n=er(32)){const{Fn:r}=Nr,s=me("message",e),{bytes:o,scalar:i}=ca(t),a=me("auxRand",n,32),c=r.toBytes(i^Gr(Ao("BIP0340/aux",a))),u=Ao("BIP0340/nonce",c,o,s),{bytes:f,scalar:l}=ca(u),d=Gd(f,o,s),p=new Uint8Array(64);if(p.set(f,0),p.set(r.toBytes(r.create(l+d*i)),32),!Yd(p,s,o))throw new Error("sign: Invalid signature produced");return p}function Yd(e,t,n){const{Fn:r,BASE:s}=Nr,o=me("signature",e,64),i=me("message",t),a=me("publicKey",n,32);try{const c=Wd(Gr(a)),u=Gr(o.subarray(0,32));if(!oa(u,Au,Ar.p))return!1;const f=Gr(o.subarray(32,64));if(!oa(f,Au,Ar.n))return!1;const l=Gd(r.toBytes(u),uc(c),i),d=s.multiplyUnsafe(f).add(c.multiplyUnsafe(r.neg(l))),{x:p,y:h}=d.toAffine();return!(d.is0()||!fc(h)||p!==u)}catch{return!1}}const $n=(()=>{const n=(s=er(48))=>jd(s,Ar.n);ke.utils.randomSecretKey;function r(s){const o=n(s);return{secretKey:o,publicKey:Tu(o)}}return{keygen:r,getPublicKey:Tu,sign:h2,verify:Yd,Point:Nr,utils:{randomSecretKey:n,randomPrivateKey:n,taggedHash:Ao,lift_x:Wd,pointToBytes:uc,numberToBytesBE:zo,bytesToNumberBE:tr,mod:Ee},lengths:{secretKey:32,publicKey:32,publicKeyHasPrefix:!1,signature:64,seed:48}}})(),p2=BigInt(0),Dr=BigInt(1),g2=BigInt(2),m2=BigInt(7),y2=BigInt(256),b2=BigInt(113),Xd=[],Jd=[],Qd=[];for(let e=0,t=Dr,n=1,r=0;e<24;e++){[n,r]=[r,(2*n+3*r)%5],Xd.push(2*(5*r+n)),Jd.push((e+1)*(e+2)/2%64);let s=p2;for(let o=0;o<7;o++)t=(t<>m2)*b2)%y2,t&g2&&(s^=Dr<<(Dr<n>32?Ax(e,t,n):$x(e,t,n),Ou=(e,t,n)=>n>32?Bx(e,t,n):_x(e,t,n);function v2(e,t=24){const n=new Uint32Array(10);for(let r=24-t;r<24;r++){for(let i=0;i<10;i++)n[i]=e[i]^e[i+10]^e[i+20]^e[i+30]^e[i+40];for(let i=0;i<10;i+=2){const a=(i+8)%10,c=(i+2)%10,u=n[c],f=n[c+1],l=Iu(u,f,1)^n[a],d=Ou(u,f,1)^n[a+1];for(let p=0;p<50;p+=10)e[i+p]^=l,e[i+p+1]^=d}let s=e[2],o=e[3];for(let i=0;i<24;i++){const a=Jd[i],c=Iu(s,o,a),u=Ou(s,o,a),f=Xd[i];s=e[f],o=e[f+1],e[f]=c,e[f+1]=u}for(let i=0;i<50;i+=10){for(let a=0;a<10;a++)n[a]=e[i+a];for(let a=0;a<10;a++)e[i+a]^=~n[(a+2)%10]&n[(a+4)%10]}e[0]^=w2[r],e[1]^=x2[r]}ct(n)}class lc extends sc{constructor(t,n,r,s=!1,o=24){if(super(),this.pos=0,this.posOut=0,this.finished=!1,this.destroyed=!1,this.enableXOF=!1,this.blockLen=t,this.suffix=n,this.outputLen=r,this.enableXOF=s,this.rounds=o,It(r),!(0=r&&this.keccak();const i=Math.min(r-this.posOut,o-s);t.set(n.subarray(this.posOut,this.posOut+i),s),this.posOut+=i,s+=i}return t}xofInto(t){if(!this.enableXOF)throw new Error("XOF is not possible for this instance");return this.writeInto(t)}xof(t){return It(t),this.xofInto(new Uint8Array(t))}digestInto(t){if(vd(t,this),this.finished)throw new Error("digest() was already called");return this.writeInto(t),this.destroy(),t}digest(){return this.digestInto(new Uint8Array(this.outputLen))}destroy(){this.destroyed=!0,ct(this.state)}_cloneInto(t){const{blockLen:n,suffix:r,outputLen:s,rounds:o,enableXOF:i}=this;return t||(t=new lc(n,r,s,i,o)),t.state32.set(this.state32),t.pos=this.pos,t.posOut=this.posOut,t.finished=this.finished,t.rounds=o,t.suffix=r,t.outputLen=s,t.enableXOF=i,t.destroyed=this.destroyed,t}}const E2=(e,t,n)=>qo(()=>new lc(t,e,n)),dc=E2(1,136,256/8),k2=Uint8Array.from([7,4,13,1,10,6,15,3,12,0,9,5,2,14,11,8]),th=Uint8Array.from(new Array(16).fill(0).map((e,t)=>t)),S2=th.map(e=>(9*e+5)%16),nh=(()=>{const n=[[th],[S2]];for(let r=0;r<4;r++)for(let s of n)s.push(s[r].map(o=>k2[o]));return n})(),rh=nh[0],sh=nh[1],oh=[[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)),$2=rh.map((e,t)=>e.map(n=>oh[t][n])),_2=sh.map((e,t)=>e.map(n=>oh[t][n])),A2=Uint32Array.from([0,1518500249,1859775393,2400959708,2840853838]),B2=Uint32Array.from([1352829926,1548603684,1836072691,2053994217,0]);function Cu(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 Ms=new Uint32Array(16);class T2 extends oc{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 p=0;p<16;p++,n+=4)Ms[p]=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 p=0;p<5;p++){const h=4-p,g=A2[p],m=B2[p],b=rh[p],w=sh[p],y=$2[p],x=_2[p];for(let $=0;$<16;$++){const E=Ls(r+Cu(p,o,a,u)+Ms[b[$]]+g,y[$])+l|0;r=l,l=u,u=Ls(a,10)|0,a=o,o=E}for(let $=0;$<16;$++){const E=Ls(s+Cu(h,i,c,f)+Ms[w[$]]+m,x[$])+d|0;s=d,d=f,f=Ls(c,10)|0,c=i,i=E}}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(){ct(Ms)}destroy(){this.destroyed=!0,ct(this.buffer),this.set(0,0,0,0,0)}}const hc=qo(()=>new T2);/*! scure-base - MIT License (c) 2022 Paul Miller (paulmillr.com) */function Br(e){return e instanceof Uint8Array||ArrayBuffer.isView(e)&&e.constructor.name==="Uint8Array"}function I2(e,...t){if(!Br(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 ih(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 ah(e){if(typeof e!="function")throw new Error("function expected");return!0}function Gn(e,t){if(typeof t!="string")throw new Error(`${e}: string expected`);return!0}function Lr(e){if(!Number.isSafeInteger(e))throw new Error(`invalid integer: ${e}`)}function Bo(e){if(!Array.isArray(e))throw new Error("array expected")}function To(e,t){if(!ih(!0,t))throw new Error(`${e}: array of strings expected`)}function pc(e,t){if(!ih(!1,t))throw new Error(`${e}: array of numbers expected`)}function $s(...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 Fo(e){const t=typeof e=="string"?e.split(""):e,n=t.length;To("alphabet",t);const r=new Map(t.map((s,o)=>[s,o]));return{encode:s=>(Bo(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=>(Bo(s),s.map(o=>{Gn("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 Gn("join",e),{encode:t=>(To("join.decode",t),t.join(e)),decode:t=>(Gn("join.decode",t),t.split(e))}}function ch(e,t="="){return Lr(e),Gn("padding",t),{encode(n){for(To("padding.encode",n);n.length*e%8;)n.push(t);return n},decode(n){To("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 ua(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(Bo(e),!e.length)return[];let r=0;const s=[],o=Array.from(e,a=>{if(Lr(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:uh(t,e%t),Io=(e,t)=>e+(t-uh(e,t)),eo=(()=>{let e=[];for(let t=0;t<40;t++)e.push(2**t);return e})();function Oo(e,t,n,r){if(Bo(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(Io(t,n)>32)throw new Error(`convertRadix2: carry overflow from=${t} to=${n} carryBits=${Io(t,n)}`);let s=0,o=0;const i=eo[t],a=eo[n]-1,c=[];for(const u of e){if(Lr(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=eo[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 fh(e){Lr(e);const t=2**8;return{encode:n=>{if(!Br(n))throw new Error("radix.encode input should be Uint8Array");return ua(Array.from(n),t,e)},decode:n=>(pc("radix.decode",n),Uint8Array.from(ua(n,e,t)))}}function gc(e,t=!1){if(Lr(e),e<=0||e>32)throw new Error("radix2: bits should be in (0..32]");if(Io(8,e)>32||Io(e,8)>32)throw new Error("radix2: carry overflow");return{encode:n=>{if(!Br(n))throw new Error("radix2.encode input should be Uint8Array");return Oo(Array.from(n),8,e,!t)},decode:n=>(pc("radix2.decode",n),Uint8Array.from(Oo(n,e,8,t)))}}function Pu(e){return ah(e),function(...t){try{return e.apply(null,t)}catch{}}}function lh(e,t){return Lr(e),ah(t),{encode(n){if(!Br(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(!Br(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{Gn("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"})},it=O2?{encode(e){return I2(e),e.toBase64()},decode(e){return C2(e)}}:$s(gc(6),Fo("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"),ch(6),Wo("")),P2=e=>$s(fh(58),Fo(e),Wo("")),U2=P2("123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"),dh=e=>$s(lh(4,t=>e(e(t))),U2),fa=$s(Fo("qpzry9x8gf2tvdw0s3jn54khce6mua7l"),Wo("")),Uu=[996825010,642813549,513874426,1027748829,705979059];function Mr(e){const t=e>>25;let n=(e&33554431)<<5;for(let r=0;r>r&1)===1&&(n^=Uu[r]);return n}function Nu(e,t,n=1){const r=e.length;let s=1;for(let o=0;o126)throw new Error(`Invalid prefix (${e})`);s=Mr(s)^i>>5}s=Mr(s);for(let o=0;op)throw new TypeError(`Length ${g} exceeds limit ${p}`);const m=l.toLowerCase(),b=Nu(m,d,t);return`${m}1${fa.encode(d)}${b}`}function a(l,d=90){Gn("bech32.decode input",l);const p=l.length;if(p<8||d!==!1&&p>d)throw new TypeError(`invalid string length: ${p} (${l}). Expected (8..${d})`);const h=l.toLowerCase();if(l!==h&&l!==l.toUpperCase())throw new Error("String must be lowercase or uppercase");const g=h.lastIndexOf("1");if(g===0||g===-1)throw new Error('Letter "1" must be present between prefix and data only');const m=h.slice(0,g),b=h.slice(g+1);if(b.length<6)throw new Error("Data must be at least 6 characters long");const w=fa.decode(b).slice(0,-6),y=Nu(m,w,t);if(!b.endsWith(y))throw new Error(`Invalid checksum in ${l}: expected "${y}"`);return{prefix:m,words:w}}const c=Pu(a);function u(l){const{prefix:d,words:p}=a(l,!1);return{prefix:d,words:p,bytes:r(p)}}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 Yn=hh("bech32"),N2=hh("bech32m");/*! scure-bip32 - MIT License (c) 2022 Patricio Palladino, Paul Miller (paulmillr.com) */const Vs=ke.ProjectivePoint,ki=dh(xe);function Lu(e){He(e);const t=e.length===0?"0":Se(e);return BigInt("0x"+t)}function L2(e){if(typeof e!="bigint")throw new Error("bigint expected");return ut(e.toString(16).padStart(64,"0"))}const R2=Ne("Bitcoin seed"),Si={private:76066276,public:76067358},$i=2147483648,H2=e=>hc(xe(e)),j2=e=>Mn(e).getUint32(0,!1),qs=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 Mn(t).setUint32(0,e,!1),t};class Pn{get fingerprint(){if(!this.pubHash)throw new Error("No publicKey set!");return j2(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 ki.encode(this.serialize(this.versions.private,ae(new Uint8Array([0]),t)))}get publicExtendedKey(){if(!this.pubKey)throw new Error("No public key");return ki.encode(this.serialize(this.versions.public,this.pubKey))}static fromMasterSeed(t,n=Si){if(He(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=Sn(ls,R2,t);return new Pn({versions:n,chainCode:r.slice(32),privateKey:r.slice(0,32)})}static fromExtendedKey(t,n=Si){const r=ki.decode(t),s=Mn(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 Pn({...i,privateKey:a.slice(1)}):new Pn({...i,publicKey:a})}static fromJSON(t){return Pn.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||Si,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(!ke.utils.isValidPrivateKey(t.privateKey))throw new Error("Invalid private key");this.privKey=typeof t.privateKey=="bigint"?t.privateKey:Lu(t.privateKey),this.privKeyBytes=L2(this.privKey),this.pubKey=ke.getPublicKey(t.privateKey,!0)}else if(t.publicKey)this.pubKey=Vs.fromHex(t.publicKey).toRawBytes(!0);else throw new Error("HDKey: no public or private key provided");this.pubHash=H2(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>=$i)throw new Error("Invalid index");o[2]==="'"&&(a+=$i),r=r.deriveChild(a)}return r}deriveChild(t){if(!this.pubKey||!this.chainCode)throw new Error("No publicKey or chainCode set");let n=qs(t);if(t>=$i){const a=this.privateKey;if(!a)throw new Error("Could not derive hardened child key");n=ae(new Uint8Array([0]),a,n)}else n=ae(this.pubKey,n);const r=Sn(ls,this.chainCode,n),s=Lu(r.slice(0,32)),o=r.slice(32);if(!ke.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=Ee(this.privKey+s,ke.CURVE.n);if(!ke.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=Vs.fromHex(this.pubKey).add(Vs.fromPrivateKey(s));if(a.equals(Vs.ZERO))throw new Error("The tweak was equal to negative P, which made the result key invalid");i.publicKey=a.toRawBytes(!0)}return new Pn(i)}catch{return this.deriveChild(t+1)}}sign(t){if(!this.privateKey)throw new Error("No privateKey set!");return He(t,32),ke.sign(t,this.privKey).toCompactRawBytes()}verify(t,n){if(He(t,32),He(n,64),!this.publicKey)throw new Error("No publicKey set!");let r;try{r=ke.Signature.fromCompact(n)}catch{return!1}return ke.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 He(n,33),ae(qs(t),new Uint8Array([this.depth]),qs(this.parentFingerprint),qs(this.index),this.chainCode,n)}}function K2(e,t,n,r){ks(e);const s=xx({dkLen:32,asyncTick:10},r),{c:o,dkLen:i,asyncTick:a}=s;if(It(o),It(i),It(a),o<1)throw new Error("iterations (c) should be >= 1");const c=mu(t),u=mu(n),f=new Uint8Array(i),l=Sn.create(e,c),d=l._cloneInto().update(u);return{c:o,dkLen:i,asyncTick:a,DK:f,PRF:l,PRFSalt:d}}function D2(e,t,n,r,s){return e.destroy(),t.destroy(),r&&r.destroy(),ct(s),n}function M2(e,t,n,r){const{c:s,dkLen:o,DK:i,PRF:a,PRFSalt:c}=K2(e,t,n,r);let u;const f=new Uint8Array(4),l=Mn(f),d=new Uint8Array(a.outputLen);for(let p=1,h=0;he[0]==="あいこくしん";function ph(e){if(typeof e!="string")throw new TypeError("invalid mnemonic type: "+typeof e);return e.normalize("NFKD")}function gh(e){const t=ph(e),n=t.split(" ");if(![12,15,18,21,24].includes(n.length))throw new Error("Invalid mnemonic");return{nfkd:t,words:n}}function mh(e){He(e,16,20,24,28,32)}function V2(e,t=128){if(It(t),t%32!==0||t>256)throw new TypeError("Invalid entropy");return bh(er(t/8),e)}const q2=e=>{const t=8-e.length/4;return new Uint8Array([xe(e)[0]>>t<{if(typeof t!="string")throw new Error("wordlist: non-string element: "+t)}),Zs.chain(Zs.checksum(1,q2),Zs.radix2(11,!0),Zs.alphabet(e))}function z2(e,t){const{words:n}=gh(e),r=yh(t).decode(n);return mh(r),r}function bh(e,t){return mh(e),yh(t).encode(e).join(Z2(t)?" ":" ")}function F2(e,t){try{z2(e,t)}catch{return!1}return!0}const W2=e=>ph("mnemonic"+e);function G2(e,t=""){return M2(ls,gh(e).nfkd,W2(t),{c:2048,dkLen:64})}const mc=`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(` +`),Ye={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`,ethereum:e=>`m/44'/60'/${e}'/0/0`},Y2=2**31-1,_i=new Map,Ai=new Map,Ru=()=>V2(mc,256);function wh(e,t=0){if(typeof e!="string"||!F2(e,mc)||t&&e.split(" ").length!==t)throw new Error("Invalid lab mnemonic.");return e}function Tn(e,t){if(!Number.isSafeInteger(e)||e<0||e>Y2)throw new Error(`Invalid ${t}.`);return e}const Bi=new Map;function yc(e){return Bi.has(e)||Bi.set(e,G2(wh(e))),Bi.get(e)}function In(e){return _i.has(e)||_i.set(e,Pn.fromMasterSeed(yc(e))),_i.get(e)}function X2(e,t){const n=e.derive(t).privateKey;if(!n)throw new Error("BIP-85 path produced no private key.");return Sn(ls,Ne("bip-entropy-from-k"),n)}function J2(e,t){const n=`${e}|${Tn(t,"child index")}`;return Ai.has(n)||Ai.set(n,bh(X2(In(e),Ye.orgSeed(t)).slice(0,32),mc)),Ai.get(n)}function la(e,t=0,n=1){return Se(In(e).derive(Ye.wallet(Tn(t,"account"),n)).privateKey)}function bc(e,t=0,n=1){return Se(In(e).derive(Ye.segwit(Tn(t,"account"),n)).privateKey)}function xh(e,t=0,n=1){return Se(In(e).derive(Ye.segwit(Tn(t,"account"),n)).publicKey)}function Go(e,t=0){return Se(In(e).derive(Ye.nostr(Tn(t,"account"))).privateKey)}function vh(e){const t=e.toLowerCase(),n=Se(dc(Ne(t)));return`0x${[...t].map((r,s)=>parseInt(n[s],16)>=8?r.toUpperCase():r).join("")}`}const Eh=e=>vh(Se(dc(ke.ProjectivePoint.fromHex(e).toRawBytes(!1).slice(1)).slice(-20)));function kh(e,t=0){return Se(In(e).derive(Ye.ethereum(Tn(t,"account"))).privateKey)}const Ti=new Map;function Q2(e,t=0){const n=`${e}|${t}`;return Ti.has(n)||Ti.set(n,Eh(In(e).derive(Ye.ethereum(Tn(t,"account"))).publicKey)),Ti.get(n)}function ev(e,t=0){const n=$n.getPublicKey(In(e).derive(Ye.nostr(Tn(t,"account"))).privateKey);return{pubkey:Se(n),npub:Yn.encode("npub",Yn.toWords(n))}}const vt=["taproot","segwit","nostr","ethereum"],Yo=(e,t)=>["lineage/v0 keyring",`node: ${e}`,...vt.map(n=>`${n}: ${t[n]}`)].join(` +`),tv=["bc","tb","bcrt"],Sh=new Uint8Array(32),Qe=e=>{const t=new Uint8Array(4);return new DataView(t.buffer).setUint32(0,e,!0),t},hs=e=>ae(e.length<253?Uint8Array.of(e.length):Uint8Array.of(253,e.length&255,e.length>>8),e),Fr=e=>xe(xe(e)),$h=(e,...t)=>{const n=xe(Ne(e));return xe(ae(n,n,...t))},nv=(e,t)=>e.length===t.length&&e.every((n,r)=>n===t[r]);function ps(e){if(typeof e!="string"||e!==e.toLowerCase())return null;for(const[t,n]of[[Yn,0],[N2,1]])try{const{prefix:r,words:s}=t.decode(e,90);if(s[0]===n&&tv.includes(r))return{network:r,version:n,program:Uint8Array.from(t.fromWords(s.slice(1)))}}catch{}return null}const wc=e=>(e==null?void 0:e.version)===1&&e.program.length===32,xc=e=>(e==null?void 0:e.version)===0&&e.program.length===20,_h=({version:e,program:t})=>ae(Uint8Array.of(e?80+e:0,t.length),t),rv=e=>$h("BIP0322-signed-message",Ne(e)),Co=new Uint8Array(8),Hu=ae(Co,hs(Uint8Array.of(106)));function sv(e,t){const n=_h(e),r=ae(Uint8Array.of(0,32),rv(t));return Fr(ae(Qe(0),Uint8Array.of(1),new Uint8Array(32),Qe(4294967295),hs(r),Qe(0),Uint8Array.of(1),Co,hs(n),Qe(0)))}function Po(e,t,n=0){const r=_h(e),s=ae(sv(e,t),Qe(0));if(e.version===0){const o=ae(Uint8Array.of(25,118,169,20),e.program,Uint8Array.of(136,172));return Fr(ae(Qe(0),Fr(s),Fr(Qe(0)),s,o,Co,Qe(0),Fr(Hu),Qe(0),Qe(1)))}return $h("TapSighash",Uint8Array.of(0,n),Qe(0),Qe(0),xe(s),xe(Co),xe(hs(r)),xe(Qe(0)),xe(Hu),Uint8Array.of(0),Qe(0))}const ju=e=>it.encode(ae(Uint8Array.of(e.length),...e.map(hs)));function ov(e){try{const t=it.decode(e);let n=0;const r=()=>{if(n>=t.length)throw new Error("short");const o=t[n++];if(o<253)return o;if(o>253||n+2>t.length)throw new Error("size");return n+=2,t[n-2]|t[n-1]<<8},s=Array.from({length:r()},()=>{const o=r();if(n+o>t.length)throw new Error("short");return n+=o,t.slice(n-o,n)});return n===t.length?s:null}catch{return null}}function Ku(e,t,n){const r=ps(e);if(wc(r))return ju([$n.sign(Po(r,t),n,Sh)]);if(!xc(r))throw new Error("BIP-322 here signs for Taproot and P2WPKH addresses only.");const s=ke.sign(Po(r,t),n).toDERRawBytes();return ju([ae(s,Uint8Array.of(1)),ke.getPublicKey(n,!0)])}function Du(e,t,n){const r=ps(e),s=typeof n=="string"?ov(n):null;if(!r||!s)return!1;try{if(wc(r)){const[o]=s;return s.length!==1||!(o.length===64||o.length===65&&o[64]===1)?!1:$n.verify(o.slice(0,64),Po(r,t,o.length===65?1:0),r.program)}if(xc(r)){const[o,i]=s;return s.length!==2||i.length!==33||o.at(-1)!==1||!nv(hc(xe(i)),r.program)?!1:ke.verify(ke.Signature.fromDER(o.slice(0,-1)),Po(r,t),i)}}catch{}return!1}const Ah=e=>{const t=Ne(e);return dc(ae(Ne(`Ethereum Signed Message: +${t.length}`),t))},Bh=e=>typeof e=="string"&&/^0x[0-9a-fA-F]{40}$/.test(e)&&vh(e.slice(2))===e;function iv(e,t){const n=ke.sign(Ah(e),t);return`0x${Se(n.toCompactRawBytes())}${(27+n.recovery).toString(16)}`}function av(e,t,n){if(!Bh(e)||typeof n!="string"||!/^0x[0-9a-f]{130}$/.test(n))return!1;try{const r=ut(n.slice(2)),s=r[64]-27;if(s!==0&&s!==1)return!1;const o=ke.Signature.fromCompact(r.slice(0,64)).addRecoveryBit(s).recoverPublicKey(Ah(t));return Eh(o.toRawBytes(!1))===e}catch{return!1}}const Th=(e,t)=>xe(Ne(JSON.stringify([0,e,0,1,[],t])));function vc(e){try{const{prefix:t,words:n}=Yn.decode(e,90),r=Yn.fromWords(n);return t==="npub"&&r.length===32&&e===e.toLowerCase()?Se(Uint8Array.from(r)):null}catch{return null}}const cv=(e,t)=>Se($n.sign(Th(Se($n.getPublicKey(t)),e),t,Sh));function uv(e,t,n){const r=vc(e);try{return!!r&&typeof n=="string"&&/^[0-9a-f]{128}$/.test(n)&&$n.verify(n,Th(r,t),r)}catch{return!1}}const fv={taproot:Ku,segwit:Ku,nostr:(e,t,n)=>cv(t,n),ethereum:(e,t,n)=>iv(t,n)},lv={taproot:Du,segwit:Du,nostr:uv,ethereum:av};function Ih(e){const t=ps(e.taproot),n=ps(e.segwit);return wc(t)?xc(n)?t.network!==n.network?"its Taproot and SegWit addresses must be on one network":vc(e.nostr)?Bh(e.ethereum)?"":"ethereum must be an EIP-55 address":"nostr must be an npub":"segwit must be a P2WPKH address":"taproot must be a Taproot address"}function dv(e,t,n){const r=Ih(t);if(r)throw new Error(`${r[0].toUpperCase()}${r.slice(1)}.`);const s=Yo(e,t);return{...Object.fromEntries(vt.map(o=>[o,t[o]])),proof:Object.fromEntries(vt.map(o=>[o,fv[o](t[o],s,n[o])]))}}const Zr=new Map;function hv(e,t){const n=t.proof&&typeof t.proof=="object"&&!Array.isArray(t.proof)?t.proof:{},r=JSON.stringify([e,...vt.map(s=>[t[s]??null,n[s]??null])]);if(!Zr.has(r)){Zr.size>=1e3&&Zr.clear();let s=Ih(t);if(!s){const o=Yo(e,t),i=vt.find(a=>!lv[a](t[a],o,n[a]));i&&(s=`the ${i} key did not sign this keyring`)}Zr.set(r,s)}return Zr.get(r)}const Mu=e=>vt.map(t=>`${t}:${t==="nostr"?vc(e[t]):t==="ethereum"?e[t].toLowerCase():Se(ps(e[t]).program)}`),Ec="lineage/v0",pv=["white","green","black"],Zu=["sole","llc","series-llc","series","corp"],gv={sole:"sole proprietor",llc:"LLC","series-llc":"series LLC",series:"series",corp:"corporation"},Vu=/^[A-Z]{2}(-[A-Z0-9]{1,3})?$/,mv=/^[0-9a-f]{64}$/,bn=e=>e.kind==="agent"&&e.root!==e.id,zs="names are 1-40 lowercase letters, digits or hyphens (they become domains)",yv=/^[a-z0-9](?:[a-z0-9-]{0,38}[a-z0-9])?$/,Vr=e=>typeof e=="string"&&yv.test(e),ur=(e,t)=>typeof e=="string"?e.trim().slice(0,t):"";function _s(e){return String(e??"").toLowerCase().normalize("NFKD").replace(/[̀-ͯ]/g,"").replace(/[^a-z0-9]+/g,"-").replace(/^-+|-+$/g,"").slice(0,40).replace(/-+$/,"")}const Xo=e=>e.events.filter(t=>t.protocol===Ec);function _n(e,{upTo:t=1/0,pending:n=!1}={}){var l;const r=new Map,s=[],o=[],i=new Map,a=new Map,c=d=>d.status==="active",u=d=>{if(d.keyring&&!d.keyring.retired)for(const p of Mu(d.keyring.keys))a.delete(p)},f=(d,p,h,g)=>{d.keyring&&!d.keyring.retired&&(u(d),d.keyring.retired={cause:p,by:h,beat:g})};for(const d of e){const p=d.status==="confirmed";if(p?d.height>t:!n)continue;const h=d.metadata&&typeof d.metadata=="object"&&!Array.isArray(d.metadata)?d.metadata:{},g={id:d.id,op:typeof h.op=="string"?h.op.slice(0,20):"?",beat:p?d.height:null,pending:!p,meta:h,parent:d.parent??null,ok:!0,why:"",node:null,root:null,also:[]},m=g.parent?r.get(g.parent):null,b=g.beat??"cued",w=E=>{g.ok=!1,g.why=E},y=E=>m?c(m)?"":`the ${E} is ${m.status}`:`the ${E} is not in this lineage`;let x="";switch(g.op){case"found":if(g.parent)w("a holding has no parent");else if(!Vr(h.name))w(zs);else if(s.some(E=>c(E)&&E.name===h.name))w(`an active holding is already named ${h.name}`);else{const E=qu(d,h.name,null,"holding");r.set(E.id,E),s.push(E),g.node=E.id}break;case"birth":{const E=h.kind==="agent"?"agent":"org";if(x=y("parent"))w(x);else if(bn(m))w("agents give birth only once they graduate");else if(!Vr(h.name))w(zs);else if(m.children.some(I=>c(r.get(I))&&r.get(I).name===h.name))w(`${m.name} already has an active ${h.name}`);else{const I=qu(d,h.name,m,E);I.index=m.children.filter(P=>r.get(P).kind===E).length,m.children.push(I.id),r.set(I.id,I),g.node=I.id}break}case"award":{const E=r.get(h.to);(x=y("issuer"))?w(x):bn(m)?w("agents award belts only once they graduate"):!E||E.id===m.id?w("the recipient must be another node in this lineage"):c(E)?!Vr(h.skill)||!pv.includes(h.belt)?w("an award needs a skill name and a belt (white, green or black)"):(E.badges=E.badges.filter(I=>I.skill!==h.skill),E.badges.push({skill:h.skill,belt:h.belt,by:m.id,beat:b,id:d.id}),g.node=E.id):w(`the recipient is ${E.status}`);break}case"decide":(x=y("decider"))?w(x):ur(h.title,140)?(m.decisions.push({title:ur(h.title,140),why:ur(h.why,400),beat:b,id:d.id}),g.node=m.id):w("a decision needs a title");break;case"make":(x=y("maker"))?w(x):Vr(h.name)?m.made.some(E=>i.get(E).name===h.name)?w(`there is already a ${h.name} by ${m.name}`):(i.set(d.id,{id:d.id,name:h.name,note:ur(h.note,280),maker:m.id,beat:b}),m.made.push(d.id),g.node=m.id):w(zs);break;case"graduate":{const E=r.get(h.of);if(x=y("parent"))w(x);else if(!E||E.parent!==m.id)w("only its parent can graduate a child");else if(!c(E))w(`the child is ${E.status}`);else if(E.edge==="adopted")w("already graduated");else{const I=E.root,P=U=>{U.root=E.id;for(const L of U.children)r.get(L).root===I&&P(r.get(L))};E.edge="adopted",E.graduated=b,g.node=E.id,P(E),s.push(E);const B=U=>{f(U,"graduate",E.id,b);for(const L of U.children)r.get(L).edge==="derived"&&B(r.get(L))};B(E)}break}case"close":if(!m)w(g.parent?"that node is not in this lineage":"a close spends the node it closes");else if(!c(m))w(`already ${m.status}`);else{const E=I=>{I.status="closed",I.closed=b,f(I,"close",m.id,b);for(const P of I.children){const B=r.get(P);B.edge==="derived"&&c(B)&&(g.also.push(B.id),E(B))}};E(m),g.node=m.id}break;case"charter":{const E=h.form==="series",I=E?r.get(h.of):m,P=m&&(m.kind==="holding"||m.kind==="agent");(x=y(E?"master":"node"))?w(x):Zu.includes(h.form)?!E&&h.of!==void 0&&h.of!==m.id?w("a node charters itself; only a series is chartered by its master"):E&&(!I||!bv(r,I,m))?w("a series must descend from its master"):E&&!c(I)?w(`the series is ${I.status}`):E&&I.kind!=="org"?w("only orgs become series"):E&&((l=m.charter)==null?void 0:l.form)!=="series-llc"?w(`${m.name} is not chartered as a series LLC`):E&&h.jurisdiction!==void 0?w("a series takes its master's jurisdiction"):h.form==="sole"&&!P?w("a sole proprietor is a person: a holding or an agent"):h.form!=="sole"&&!E&&bn(m)?w("an agent graduates before it incorporates"):h.form!=="sole"&&!E&&!Vu.test(h.jurisdiction??"")||h.form==="sole"&&h.jurisdiction!==void 0&&!Vu.test(h.jurisdiction)?w("a jurisdiction is an ISO code such as US-WY"):h.provider!==void 0&&!Vr(h.provider)?w(`a provider's name follows the name rule: ${zs}`):h.filing!==void 0&&!mv.test(h.filing)?w("a filing is the SHA-256 of the filed documents, in hex"):(I.charter={id:d.id,beat:b,form:h.form,jurisdiction:E?null:h.jurisdiction??null,legal:ur(h.legal,120)||null,provider:h.provider??null,filing:h.filing??null,master:E?m.id:null},g.node=I.id):w(`a charter's form is ${Zu.join(", ")}`);break}case"keyring":{if(x=y("node"))w(x);else if(x=hv(m.id,h))w(x);else{const E=Object.fromEntries(vt.map(B=>[B,h[B]])),I=Mu(E),P=I.findIndex(B=>a.has(B)&&a.get(B)!==m.id);if(P>=0)w(`its ${vt[P]} key is already bound to ${r.get(a.get(I[P])).name}`);else{u(m),m.keyring={id:d.id,beat:b,keys:E,retired:null};for(const B of I)a.set(B,m.id);g.node=m.id}}break}default:w("not a lineage/v0 op")}const $=g.node?r.get(g.node).root:null;g.root=(m==null?void 0:m.root)??$,g.roots=[...new Set([g.root,$].filter(Boolean))],o.push(g)}return{nodes:r,roots:s,log:o,items:i,bound:a}}function qu(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:[],made:[],keyring:null,charter:null,graduated:null,closed:null}}function bv(e,t,n){for(let r=e.get(t.parent);r;r=e.get(r.parent))if(r.id===n.id)return!0;return!1}function Yr(e,t){var s;const n=t==null?void 0:t.charter;if(!n)return null;if(t.status!=="active")return{ok:!1,why:`${t.name} is closed`};if(n.form!=="series")return{ok:!0,why:""};const r=e.nodes.get(n.master);return r.status!=="active"?{ok:!1,why:`${r.name} is closed`}:((s=r.charter)==null?void 0:s.form)!=="series-llc"?{ok:!1,why:`${r.name} no longer holds series`}:t.root!==r.root?{ok:!1,why:`${t.name} is no longer in ${r.name}'s holding`}:{ok:!0,why:""}}function wv(e,t){const n=[],r=e.nodes.get(t),s=(o,i,a)=>{const c=o.root!==t;if(n.push({type:"node",node:o,guide:i,path:o.id===t?"●":`${o.index}'`,away:c}),c)return;const u=o.children.map(l=>e.nodes.get(l)),f=[["agents",u.filter(l=>l.kind==="agent")],["orgs",u.filter(l=>l.kind!=="agent")]].filter(([,l])=>l.length);f.forEach(([l,d],p)=>{const h=p===f.length-1,g=a+(h?" ":"│ ");n.push({type:"group",label:l,guide:a+(h?"└─ ":"├─ ")}),d.forEach((m,b)=>{const w=b===d.length-1;s(m,g+(w?"└─ ":"├─ "),g+(w?" ":"│ "))})})};return r&&s(r,"",""),n}function xv(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 Tr(e,t){const n=[];for(let r=e.nodes.get(t);r;r=r.id===r.root?null:e.nodes.get(r.parent))n.unshift(r.name);return n.join(" / ")}function Oh(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 “${ur(n.title,140)}” · ${r(e.parent)}`;case"make":return`make ${n.name} · ${r(e.parent)}`;case"keyring":return`keyring · ${r(e.parent)}`;case"charter":return n.form==="series"?`charter ${r(n.of)} as a series of ${r(e.parent)}`:`charter ${r(e.parent)} · ${gv[n.form]}${n.jurisdiction?` (${n.jurisdiction})`:""}`;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 pn=Se,vv=ae,da=ut,Ev=tr,gn="super-testnet-local-v0";class An{constructor(t){if(!/^[0-9a-f]{64}$/.test(t)||!ke.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=pn($n.getPublicKey(t)),this.address=Qr.p2tr.fromPubKey(this.pubkey,"regtest"),this.script=["OP_1",this.pubkey]}static create(){return new An(pn(ke.utils.randomPrivateKey()))}static load(t){if((t==null?void 0:t.network)!==gn||(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 An(t.secret)}backup(){return{kind:"test-wallet",version:1,network:gn,secret:this.secret}}sign(t,n,r=0){return xr.taproot.sign(this.secret,t,r,n?{extension:n}:{}).hex}}const Fs=50*1e8,Ws="0".repeat(64),zu=e=>pn(xe(new TextEncoder().encode(JSON.stringify(e)))),ir=(e,t)=>`${e}:${t}`,We=e=>Be.encode(e,!1).hex,le=(e,t)=>{if(!e)throw new Error(t)},Fu=/^5120[0-9a-f]{64}$/,Gs=/^0014[0-9a-f]{40}$/,Ch=64,wt=8,kv=e=>pn(hc(xe(da(e))));function Sv(e,t){const[n,r]=e.vin[t].witness;return ke.verify(n.slice(0,-2),xr.segwit.hash(e,t,{pubkey:r,sigflag:1}),r,{lowS:!0,format:"der"})}const Ii=(e,...t)=>{const n=xe(new TextEncoder().encode(e));return xe(vv(n,n,...t))},$v=e=>e<253?Uint8Array.of(e):Uint8Array.of(253,e&255,e>>8);function _v(e,t){const[n,r,s]=e.vin[t].witness,o=da(s),i=da(r);if(o.length<33||(o.length-33)%32||i.length>65535||!/^20[0-9a-f]{64}ac/.test(r))return!1;const a=Ii("TapLeaf",Uint8Array.of(o[0]&254),$v(i.length),i);let c=a;for(let l=33;l=ke.CURVE.n)return!1;const f=ke.ProjectivePoint.fromHex(`02${pn(o.slice(1,33))}`).add(ke.ProjectivePoint.BASE.multiply(u)).toAffine();return`5120${f.x.toString(16).padStart(64,"0")}`!==We(e.vin[t].prevout.scriptPubKey)||Number(f.y&1n)!==(o[0]&1)?!1:$n.verify(n,xr.taproot.hash(e,t,{extension:pn(a)}),r.slice(2,66))}class Jo{constructor(t){if(this.blocks=[],this.mempool=[],this.utxos=new Map,this.transactions=new Map,this.imports=[],t){le(t.network===gn&&t.version===1,"Unsupported local chain version/network."),le(Array.isArray(t.blocks)&&Array.isArray(t.mempool)&&Array.isArray(t.imports??[]),"Invalid chain snapshot.");for(const n of t.imports??[])this.importCoin(n);for(const n of t.blocks)this.acceptBlock(structuredClone(n));this.submitPackage(t.mempool)}}snapshot(){return{network:gn,version:1,blocks:structuredClone(this.blocks),mempool:[...this.mempool],...this.imports.length?{imports:structuredClone(this.imports)}:{}}}importCoin({txid:t,vout:n,value:r,script:s}){le(/^[0-9a-f]{64}$/.test(t)&&Number.isSafeInteger(n)&&n>=0&&Number.isSafeInteger(r)&&r>=330&&r<=Fs&&(Fu.test(s)||Gs.test(s)),"Invalid imported coin."),le(!this.utxos.has(ir(t,n))&&!this.transactions.has(t)&&!this.imported(t,n),"That coin is already in this chain."),this.utxos.set(ir(t,n),{txid:t,vout:n,value:r,scriptPubKey:s,height:0,ranges:uf(this.imports.length,r),inscriptions:[]}),this.imports.push({txid:t,vout:n,value:r,script:s})}imported(t,n){const r=this.imports.find(s=>s.txid===t&&s.vout===n);return r?{value:r.value,scriptPubKey:r.script}:null}coins(t){return[...this.utxos.values()].filter(n=>We(n.scriptPubKey)===We(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 m,b,w;le(typeof t=="string"&&t.length<4e4&&/^(?:[a-f0-9]{2})+$/.test(t),"Invalid raw transaction.");const s=ie.decode(t),o=ie.util.getTxid(s);le(!this.transactions.has(o),"Duplicate transaction."),le(s.version===2&&s.locktime===0,"Unsupported transaction version or locktime.");const i=!r&&s.vin.some(y=>{var x;return((x=y.witness)==null?void 0:x.length)===3}),a=r?1:i?2:wt,c=r?Ch:i?2:wt;le(s.vin.length>=1&&s.vin.length<=a&&s.vout.length>=1&&s.vout.length<=c,"Unsupported transaction shape.");let u=0;for(const y of s.vout){const x=Number(y.value);le(Number.isSafeInteger(x)&&x>=330&&x<=Fs,"Invalid output amount.");const $=We(y.scriptPubKey);le(Fu.test($)||Gs.test($),"Only Taproot and P2WPKH outputs are supported."),u+=x}let f,l=[];const d=s.vin.findIndex(y=>{var x;return((x=y.witness)==null?void 0:x.length)===3}),p=s.vin[d<0?0:d];if(r)le(p.txid===Ws&&p.vout===4294967295&&u===Fs,"Invalid local coinbase."),le(We(p.scriptSig)===Be.encode([new TextEncoder().encode(`${gn}:${n}`)],!1).hex,"Wrong coinbase height."),le(!((m=p.witness)!=null&&m.length),"Unexpected coinbase witness.");else{l=s.vin.map(x=>this.utxos.get(ir(x.txid,x.vout))),le(l.every(Boolean),"Input is missing or already spent."),le(new Set(s.vin.map(x=>ir(x.txid,x.vout))).size===s.vin.length,"Duplicate input."),s.vin.forEach((x,$)=>{var I,P,B;le(x.sequence==="ffffffff"&&We(x.scriptSig)==="","Unsupported input flags."),x.prevout={value:l[$].value,scriptPubKey:l[$].scriptPubKey};const E=We(l[$].scriptPubKey);if(Gs.test(E)){const[U,L]=x.witness??[];le($!==d&&((I=x.witness)==null?void 0:I.length)===2,"Unsupported witness."),le(/^30[0-9a-f]{12,140}01$/.test(U)&&/^0[23][0-9a-f]{64}$/.test(L)&&kv(L)===E.slice(4),"P2WPKH spends need a SIGHASH_ALL signature by the key they pay.");return}le(((P=x.witness)==null?void 0:P.length)===1||$===d&&((B=x.witness)==null?void 0:B.length)===3,"Unsupported witness."),le(/^[0-9a-f]{128}$/.test(x.witness[0])||!i&&/^[0-9a-f]{128}83$/.test(x.witness[0]),"Only default 64-byte Schnorr signatures, or SIGHASH_SINGLE|ANYONECANPAY outside reveals, are accepted.")}),le(l.reduce((x,$)=>x+$.value,0)-u===de,"v0 requires a fixed 500 sat fee per transaction.");let y={};if(p.witness.length===3){const x=rc(p.witness),$=d;if(le(Number(s.vout[$].value)===Bt,"Invalid reveal postage."),le(We(s.vout[$].scriptPubKey)===`5120${x.pubkey}`,"Reveal must return to its signing wallet."),x.parent){const E=d===0?1:0,I=l[E];le((b=I==null?void 0:I.inscriptions)==null?void 0:b.some(P=>P.id===x.parent),"Referenced parent inscription must actually be spent."),le(s.vout.length===2&&Number(s.vout[E].value)===I.value&&We(I.scriptPubKey)===`5120${x.pubkey}`&&We(s.vout[E].scriptPubKey)===We(I.scriptPubKey),"Parent must be owned and preserved in the same wallet.")}else s.vin.length===2&&(le(d===1&&((w=l[0].inscriptions)==null?void 0:w.length)&&x.pointer!==void 0,"Reinscription spend requires correct tag and owned sat."),le(Number(s.vout[0].value)===l[0].value&&We(s.vout[0].scriptPubKey)===We(l[0].scriptPubKey)&&We(l[0].scriptPubKey)===`5120${x.pubkey}`,"Reinscription sat must be returned to owner."));y={pubkey:x.pubkey},f={id:`${o}i0`,txid:o,commitTxid:p.txid,text:x.text,bytes:Array.from(x.bytes),contentType:x.contentType,parent:x.parent,delegate:x.delegate,pointer:x.pointer,metaprotocol:x.metaprotocol,metadata:x.metadata,height:n,value:Bt}}s.vin.forEach((x,$)=>{let E=!1;try{E=Gs.test(We(l[$].scriptPubKey))?Sv(s,$):$===d?_v(s,$)||xr.taproot.verify(s,$,y):xr.taproot.verify(s,$,{})}catch{}le(E,"Invalid signature or Taproot commitment.")})}const h=df(s,l,n,r),g=l.flatMap(y=>y.inscriptions??[]);if(f){const y=BigInt(f.pointer??0),x=y{var E;return((E=$.inscription)==null?void 0:E.sat)===f.sat}).length,g.push(f)}return le(g.every(y=>h.some(x=>Xs(x,y.sat)!==null)),"Local lab protects inscription sats from fee loss."),r||s.vin.forEach(y=>this.utxos.delete(ir(y.txid,y.vout))),s.vout.forEach((y,x)=>{const $=g.filter(E=>Xs(h[x],E.sat)!==null);this.utxos.set(ir(o,x),{txid:o,vout:x,value:Number(y.value),scriptPubKey:y.scriptPubKey,height:n,ranges:h[x],inscriptions:$,...$.length?{inscription:$[0]}:{}})}),this.transactions.set(o,{txid:o,raw:t,height:n,coinbase:r,tx:s,...f?{inscription:f}:{}}),o}submitPackage(t){le(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;le(t.height===this.blocks.length+1&&t.previous===(((i=this.blocks.at(-1))==null?void 0:i.hash)??Ws),"Invalid block ancestry."),le(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;le(zu(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([Ke(Fs,t)])}mineTo(t){var a;const n=new Jo({...this.snapshot(),mempool:[]}),r=this.blocks.length+1,s=ie.create({vin:[{txid:Ws,vout:4294967295,scriptSig:[new TextEncoder().encode(`${gn}:${r}`)]}],vout:t}),o={height:r,previous:((a=this.blocks.at(-1))==null?void 0:a.hash)??Ws,time:Date.now(),raws:[ie.encode(s).hex,...this.mempool]},i={...o,hash:zu(o)};return n.acceptBlock(i),Object.assign(this,n),i}}const Ph="lineage-claim",ha=330,Uo=e=>Be.encode(e,!1).hex,Wu=e=>({txid:e.txid,vout:e.vout,value:e.value,script:Uo(e.scriptPubKey)}),Oi=/^[0-9a-f]{64}$/,Av=/^5120[0-9a-f]{64}$/;function Qo(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 Uh(e){return ie.create({vin:[Vt(e.holder.txid,e.holder.vout,e.holder.value,e.holder.script),Vt(e.payer.txid,e.payer.vout,e.payer.value,e.payer.script)],vout:[Ke(e.holder.value,["OP_1",e.to]),Ke(e.payer.value-de,["OP_1",e.to])]})}function Bv(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=Qo(e,t);if(!s)throw new Error("That inscription is not in an unspent output.");if(Uo(s.scriptPubKey)===Uo(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>=de+ha});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:Ph,version:1,inscription:t,carried:s.inscriptions.map(c=>c.id),holder:Wu(s),payer:Wu(o),to:n.pubkey,at:r},a=Uh(i);return i.txid=ie.util.getTxid(a),i.sig=n.sign(a,void 0,1),i}function Tv(e,t,n){const r=Ov(t);if((n==null?void 0:n.kind)!=="test-wallet")throw new Error("Countersigning needs a local test wallet.");if(Uo(n.script)!==r.holder.script)throw new Error("Only the current holder can countersign.");if(Iv(e,r)!=="open")throw new Error("This claim is stale: an input it spends was already spent.");const s=Uh(r);return s.vin[1].witness=[r.sig],s.vin[0].witness=[n.sign(s,void 0,0)],e.submitPackage([ie.encode(s).hex]),ie.util.getTxid(s)}function Iv(e,t){return e.utxos.has(`${t.holder.txid}:${t.holder.vout}`)&&e.utxos.has(`${t.payer.txid}:${t.payer.vout}`)?"open":"stale"}function Ov(e){const t=n=>n&&Oi.test(n.txid)&&Number.isSafeInteger(n.vout)&&n.vout>=0&&Number.isSafeInteger(n.value)&&n.value>=ha&&Av.test(n.script);if((e==null?void 0:e.kind)!==Ph||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=Gu);const i=new Uint8Array(o*s),a=Sn.create(e,t),c=a._cloneInto(),u=new Uint8Array(a.outputLen);for(let f=0;fPv(e,Cv(e,t,n),r,s);/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */const fn=BigInt(0),Re=BigInt(1),Pi=BigInt(2),Nv=BigInt(8);function Lv(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 Rv(e,t={}){const n=Vd("edwards",e,t,t.FpFnLE),{Fp:r,Fn:s}=n;let o=n.CURVE;const{h:i}=o;Ur(t,{},{uvRatio:"function"});const a=Pi<r.create(m),u=t.uvRatio||((m,b)=>{try{return{isValid:!0,value:r.sqrt(r.div(m,b))}}catch{return{isValid:!1,value:fn}}});if(!Lv(r,o,o.Gx,o.Gy))throw new Error("bad curve params: generator point");function f(m,b,w=!1){const y=w?Re:fn;return ds("coordinate "+m,b,y,a),b}function l(m){if(!(m instanceof h))throw new Error("ExtendedPoint expected")}const d=So((m,b)=>{const{X:w,Y:y,Z:x}=m,$=m.is0();b==null&&(b=$?Nv:r.inv(x));const E=c(w*b),I=c(y*b),P=r.mul(x,b);if($)return{x:fn,y:Re};if(P!==Re)throw new Error("invZ was invalid");return{x:E,y:I}}),p=So(m=>{const{a:b,d:w}=o;if(m.is0())throw new Error("bad point: ZERO");const{X:y,Y:x,Z:$,T:E}=m,I=c(y*y),P=c(x*x),B=c($*$),U=c(B*B),L=c(I*b),D=c(B*c(L+P)),k=c(U+c(w*c(I*P)));if(D!==k)throw new Error("bad point: equation left != right (1)");const _=c(y*x),v=c($*E);if(_!==v)throw new Error("bad point: equation left != right (2)");return!0});class h{constructor(b,w,y,x){this.X=f("x",b),this.Y=f("y",w),this.Z=f("z",y,!0),this.T=f("t",x),Object.freeze(this)}static CURVE(){return o}static fromAffine(b){if(b instanceof h)throw new Error("extended point not allowed");const{x:w,y}=b||{};return f("x",w),f("y",y),new h(w,y,Re,c(w*y))}static fromBytes(b,w=!1){const y=r.BYTES,{a:x,d:$}=o;b=xu(gt(b,y,"point")),Fn(w,"zip215");const E=xu(b),I=b[y-1];E[y-1]=I&-129;const P=Wn(E),B=w?a:r.ORDER;ds("point.y",P,fn,B);const U=c(P*P),L=c(U-Re),D=c($*U-x);let{isValid:k,value:_}=u(L,D);if(!k)throw new Error("bad point: invalid y coordinate");const v=(_&Re)===Re,A=(I&128)!==0;if(!w&&_===fn&&A)throw new Error("bad point: x=0 and x_0=1");return A!==v&&(_=c(-_)),h.fromAffine({x:_,y:P})}static fromHex(b,w=!1){return h.fromBytes(me("point",b),w)}get x(){return this.toAffine().x}get y(){return this.toAffine().y}precompute(b=8,w=!0){return g.createCache(this,b),w||this.multiply(Pi),this}assertValidity(){p(this)}equals(b){l(b);const{X:w,Y:y,Z:x}=this,{X:$,Y:E,Z:I}=b,P=c(w*I),B=c($*x),U=c(y*I),L=c(E*x);return P===B&&U===L}is0(){return this.equals(h.ZERO)}negate(){return new h(c(-this.X),this.Y,this.Z,c(-this.T))}double(){const{a:b}=o,{X:w,Y:y,Z:x}=this,$=c(w*w),E=c(y*y),I=c(Pi*c(x*x)),P=c(b*$),B=w+y,U=c(c(B*B)-$-E),L=P+E,D=L-I,k=P-E,_=c(U*D),v=c(L*k),A=c(U*k),C=c(D*L);return new h(_,v,C,A)}add(b){l(b);const{a:w,d:y}=o,{X:x,Y:$,Z:E,T:I}=this,{X:P,Y:B,Z:U,T:L}=b,D=c(x*P),k=c($*B),_=c(I*y*L),v=c(E*U),A=c((x+$)*(P+B)-D-k),C=v-_,R=v+_,N=c(k-w*D),j=c(A*C),M=c(R*N),F=c(A*N),ue=c(C*R);return new h(j,M,ue,F)}subtract(b){return this.add(b.negate())}multiply(b){if(!s.isValidNot0(b))throw new Error("invalid scalar: expected 1 <= sc < curve.n");const{p:w,f:y}=g.cached(this,b,x=>jn(h,x));return jn(h,[w,y])[0]}multiplyUnsafe(b,w=h.ZERO){if(!s.isValid(b))throw new Error("invalid scalar: expected 0 <= sc < curve.n");return b===fn?h.ZERO:this.is0()||b===Re?this:g.unsafe(this,b,y=>jn(h,y),w)}isSmallOrder(){return this.multiplyUnsafe(i).is0()}isTorsionFree(){return g.unsafe(this,o.n).is0()}toAffine(b){return d(this,b)}clearCofactor(){return i===Re?this:this.multiplyUnsafe(i)}toBytes(){const{x:b,y:w}=this.toAffine(),y=r.toBytes(w);return y[y.length-1]|=b&Re?128:0,y}toHex(){return Se(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(b){return jn(h,b)}static msm(b,w){return Zd(h,s,b,w)}_setWindowSize(b){this.precompute(b)}toRawBytes(){return this.toBytes()}}h.BASE=new h(o.Gx,o.Gy,Re,c(o.Gx*o.Gy)),h.ZERO=new h(fn,Re,Re,fn),h.Fp=r,h.Fn=s;const g=new Md(h,s.BITS);return h.BASE.precompute(8),h}function Hv(e,t,n={}){if(typeof t!="function")throw new Error('"hash" function param is required');Ur(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||er,c=n.adjustScalarBytes||(B=>B),u=n.domain||((B,U,L)=>{if(Fn(L,"phflag"),U.length||L)throw new Error("Contexts/pre-hash are not supported");return B});function f(B){return i.create(Wn(B))}function l(B){const U=y.secretKey;B=me("private key",B,U);const L=me("hashed private key",t(B),2*U),D=c(L.slice(0,U)),k=L.slice(U,2*U),_=f(D);return{head:D,prefix:k,scalar:_}}function d(B){const{head:U,prefix:L,scalar:D}=l(B),k=s.multiply(D),_=k.toBytes();return{head:U,prefix:L,scalar:D,point:k,pointBytes:_}}function p(B){return d(B).pointBytes}function h(B=Uint8Array.of(),...U){const L=ae(...U);return f(t(u(L,me("context",B),!!r)))}function g(B,U,L={}){B=me("message",B),r&&(B=r(B));const{prefix:D,scalar:k,pointBytes:_}=d(U),v=h(L.context,D,B),A=s.multiply(v).toBytes(),C=h(L.context,A,_,B),R=i.create(v+C*k);if(!i.isValid(R))throw new Error("sign failed: invalid s");const N=ae(A,i.toBytes(R));return gt(N,y.signature,"result")}const m={zip215:!0};function b(B,U,L,D=m){const{context:k,zip215:_}=D,v=y.signature;B=me("signature",B,v),U=me("message",U),L=me("publicKey",L,y.publicKey),_!==void 0&&Fn(_,"zip215"),r&&(U=r(U));const A=v/2,C=B.subarray(0,A),R=Wn(B.subarray(A,v));let N,j,M;try{N=e.fromBytes(L,_),j=e.fromBytes(C,_),M=s.multiplyUnsafe(R)}catch{return!1}if(!_&&N.isSmallOrder())return!1;const F=h(k,j.toBytes(),N.toBytes(),U);return j.add(N.multiplyUnsafe(F)).subtract(M).clearCofactor().is0()}const w=o.BYTES,y={secretKey:w,publicKey:w,signature:2*w,seed:w};function x(B=a(y.seed)){return gt(B,y.seed,"seed")}function $(B){const U=P.randomSecretKey(B);return{secretKey:U,publicKey:p(U)}}function E(B){return Es(B)&&B.length===i.BYTES}function I(B,U){try{return!!e.fromBytes(B,U)}catch{return!1}}const P={getExtendedPublicKey:d,randomSecretKey:x,isValidSecretKey:E,isValidPublicKey:I,toMontgomery(B){const{y:U}=e.fromBytes(B),L=y.publicKey,D=L===32;if(!D&&L!==57)throw new Error("only defined for 25519 and 448");const k=D?o.div(Re+U,Re-U):o.div(U-Re,U+Re);return o.toBytes(k)},toMontgomerySecret(B){const U=y.secretKey;gt(B,U);const L=t(B.subarray(0,U));return c(L).subarray(0,U)},randomPrivateKey:x,precompute(B=8,U=e.BASE){return U.precompute(B,!1)}};return Object.freeze({keygen:$,getPublicKey:p,sign:g,verify:b,utils:P,Point:e,lengths:y})}function jv(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=nr(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 Kv(e,t){const n=t.Point;return Object.assign({},t,{ExtendedPoint:n,CURVE:e,nBitLength:n.Fn.BITS,nByteLength:n.Fn.BYTES})}function Dv(e){const{CURVE:t,curveOpts:n,hash:r,eddsaOpts:s}=jv(e),o=Rv(t,n),i=Hv(o,r,s);return Kv(e,i)}/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */const qr=BigInt(0),ar=BigInt(1),Ys=BigInt(2);function Mv(e){return Ur(e,{adjustScalarBytes:"function",powPminus2:"function"}),Object.freeze({...e})}function Zv(e){const t=Mv(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||er,u=a?255:448,f=a?32:56,l=BigInt(a?9:5),d=BigInt(a?121665:39081),p=a?Ys**BigInt(254):Ys**BigInt(447),h=a?BigInt(8)*Ys**BigInt(251)-ar:BigInt(4)*Ys**BigInt(445)-ar,g=p+h+ar,m=k=>Ee(k,n),b=w(l);function w(k){return ac(m(k),f)}function y(k){const _=me("u coordinate",k,f);return a&&(_[31]&=127),m(Wn(_))}function x(k){return Wn(s(me("scalar",k,f)))}function $(k,_){const v=P(y(_),x(k));if(v===qr)throw new Error("invalid private or public key received");return w(v)}function E(k){return $(k,b)}function I(k,_,v){const A=m(k*(_-v));return _=m(_-A),v=m(v+A),{x_2:_,x_3:v}}function P(k,_){ds("u",k,qr,n),ds("scalar",_,p,g);const v=_,A=k;let C=ar,R=qr,N=k,j=ar,M=qr;for(let ue=BigInt(u-1);ue>=qr;ue--){const oe=v>>ue&ar;M^=oe,{x_2:C,x_3:N}=I(M,C,N),{x_2:R,x_3:j}=I(M,R,j),M=oe;const Q=C+R,he=m(Q*Q),pe=C-R,Ie=m(pe*pe),fe=he-Ie,we=N+j,Lt=N-j,rt=m(Lt*Q),De=m(we*pe),Rt=rt+De,jr=rt-De;N=m(Rt*Rt),j=m(A*m(jr*jr)),C=m(he*Ie),R=m(fe*(he+m(d*fe)))}({x_2:C,x_3:N}=I(M,C,N)),{x_2:R,x_3:j}=I(M,R,j);const F=o(R);return m(C*F)}const B={secretKey:f,publicKey:f,seed:f},U=(k=c(f))=>(He(k,B.seed),k);function L(k){const _=U(k);return{secretKey:_,publicKey:E(_)}}return{keygen:L,getSharedSecret:(k,_)=>$(k,_),getPublicKey:k=>E(k),scalarMult:$,scalarMultBase:E,utils:{randomSecretKey:U,randomPrivateKey:U},GuBytes:b.slice(),lengths:B}}/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */const Vv=BigInt(1),Yu=BigInt(2),qv=BigInt(3),zv=BigInt(5),Fv=BigInt(8),kc=BigInt("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffed"),Nh={p:kc,n:BigInt("0x1000000000000000000000000000000014def9dea2f79cd65812631a5cf5d3ed"),h:Fv,a:BigInt("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffec"),d:BigInt("0x52036cee2b6ffe738cc740797779e89800700a4d4141d8ab75eb4dca135978a3"),Gx:BigInt("0x216936d3cd6e53fec0a4e231fdd6dc5c692cc7609525a7b2c9562d608f25d51a"),Gy:BigInt("0x6666666666666666666666666666666666666666666666666666666666666658")};function Lh(e){const t=BigInt(10),n=BigInt(20),r=BigInt(40),s=BigInt(80),o=kc,a=e*e%o*e%o,c=_e(a,Yu,o)*a%o,u=_e(c,Vv,o)*e%o,f=_e(u,zv,o)*u%o,l=_e(f,t,o)*f%o,d=_e(l,n,o)*l%o,p=_e(d,r,o)*d%o,h=_e(p,s,o)*p%o,g=_e(h,s,o)*p%o,m=_e(g,t,o)*f%o;return{pow_p_5_8:_e(m,Yu,o)*e%o,b2:a}}function Rh(e){return e[0]&=248,e[31]&=127,e[31]|=64,e}const Xu=BigInt("19681161376707505956807079304988542015446066515923890162744021073123829784752");function Wv(e,t){const n=kc,r=Ee(t*t*t,n),s=Ee(r*r*t,n),o=Lh(e*s).pow_p_5_8;let i=Ee(e*r*o,n);const a=Ee(t*i*i,n),c=i,u=Ee(i*Xu,n),f=a===e,l=a===Ee(-e,n),d=a===Ee(-e*Xu,n);return f&&(i=c),(l||d)&&(i=u),zx(i,n)&&(i=Ee(-i,n)),{isValid:f||l,value:i}}const Hh=nr(Nh.p,{isLE:!0}),Gv={...Nh,Fp:Hh,hash:ls,adjustScalarBytes:Rh,uvRatio:Wv},ei=Dv(Gv),jh=(()=>{const e=Hh.ORDER;return Zv({P:e,type:"x25519",powPminus2:t=>{const{pow_p_5_8:n,b2:r}=Lh(t);return Ee(_e(n,qv,e)*r,e)},adjustScalarBytes:Rh})})(),Yv=Ne("lineage/v0"),Ot=(e,t)=>Uv(xe,e,Yv,Ne(t),32),ti=e=>{const t=Uint8Array.from(e);return t[0]&=248,t[31]&=127,t[31]|=64,t},Kh=e=>{const t=new Uint8Array(4);return new DataView(t.buffer).setUint32(0,e),t},lt=e=>ae(Kh(e.length),e),Sc=e=>ae(lt(Ne("ssh-ed25519")),lt(e)),pa=(e,t)=>`ssh-ed25519 ${it.encode(Sc(e))}${t?` ${t}`:""}`,ga=e=>`SHA256:${it.encode(xe(Sc(e))).replace(/=+$/,"")}`;function Xv(e){const t=ut(e),n=r=>ei.getPublicKey(Ot(t,r));return{ssh:n("ssh"),git:n("git"),dkim:n("dkim"),wg:jh.getPublicKey(ti(Ot(t,"wg")))}}function Jv(e){const t=n=>ei.getPublicKey(Ot(e,n));return{"ssh-ca":t("node/ssh-ca"),mtls:t("node/mtls"),noise:jh.getPublicKey(ti(Ot(e,"node/noise")))}}function Qv(e,t,n,r){return[["ssh",ga(e.ssh),pa(e.ssh,t)],["git",ga(e.git),`${t} namespaces="git" ${pa(e.git,t)}`],["dkim",`${n}._domainkey.${r}`,`${n}._domainkey.${r}. IN TXT "v=DKIM1; k=ed25519; p=${it.encode(e.dkim)}"`],["wg",it.encode(e.wg),`[Peer] +# ${t} +PublicKey = ${it.encode(e.wg)}`]]}function eE(e,t){return[["ssh-ca",ga(e["ssh-ca"]),pa(e["ssh-ca"],`lineage-ca@${t}`)],["mtls",it.encode(e.mtls),null],["noise",`mkey:${Se(e.noise)}`,null]]}const tE=ut("302e020100300506032b657004220420");function Dh(e,t,n){const r=xe(e).slice(0,4);let s=ae(r,r,lt(Ne("ssh-ed25519")),lt(t),lt(ae(e,t)),lt(Ne(n)));s=ae(s,new Uint8Array((8-s.length%8)%8).map((i,a)=>a+1));const o=ae(Ne("openssh-key-v1\0"),lt(Ne("none")),lt(Ne("none")),lt(new Uint8Array(0)),Kh(1),lt(Sc(t)),lt(s));return`-----BEGIN OPENSSH PRIVATE KEY----- +${it.encode(o).match(/.{1,70}/g).join(` +`)} +-----END OPENSSH PRIVATE KEY----- +`}const nE=(e,t)=>`-----BEGIN ${e}----- +${it.encode(t).match(/.{1,64}/g).join(` +`)} +-----END ${e}----- +`;function rE(e,t){const n=ut(e),r=s=>{const o=Ot(n,s);return Dh(o,ei.getPublicKey(o),t)};return[["ssh","OpenSSH private key",r("ssh")],["git","OpenSSH private key",r("git")],["dkim","Ed25519 private key (base64)",it.encode(Ot(n,"dkim"))],["wg","Interface entry",`[Interface] +PrivateKey = ${it.encode(ti(Ot(n,"wg")))}`]]}function sE(e,t){const n=Ot(e,"node/ssh-ca");return[["ssh-ca","OpenSSH private key",Dh(n,ei.getPublicKey(n),`lineage-ca@${t}`)],["mtls","Private key (PKCS#8 PEM)",nE("PRIVATE KEY",ae(tE,Ot(e,"node/mtls")))],["noise","noise_private.key",`privkey:${Se(ti(Ot(e,"node/noise")))}`]]}const oE=["bip86","tapkey","wallet"],$c=()=>({scheme:"bip86",roots:{},adopted:{}}),iE=e=>Zo.getPubKey(e)[0];function Mh(e,t,n){return e.scheme==="wallet"?la(t,n):Zo.getSecKey(e.scheme==="tapkey"?Go(t,n):la(t,n))[0]}const Zh=(e,t)=>e.scheme==="tapkey"?Ye.nostr(t):Ye.wallet(t),aE=(e,t)=>new An(Mh(e,t,0)),Pe=e=>Be.encode(e,!1).hex;function Ft(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]);if(n.edge==="adopted")return r(e.adopted[n.id]);const s=t.nodes.get(n.parent);if(n.kind==="agent"){const i=Ft(e,t,s);return i&&{...i,account:n.index+1}}const o=Ft(e,t,s);return o&&{mnemonic:J2(o.mnemonic,n.index),account:0,origin:o.origin,steps:[...o.steps,`${n.index}'`]}}const Ui=new Map;function Ce(e,t,n){const r=Ft(e,t,n);if(!r)return null;const s=`${e.scheme}|${r.mnemonic}|${r.account}`;if(!Ui.has(s)){const{npub:u,pubkey:f}=ev(r.mnemonic,r.account);Ui.set(s,{wallet:new An(Mh(e,r.mnemonic,r.account)),npub:u,pubkey:f})}const{wallet:o,npub:i,pubkey:a}=Ui.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} · ${Zh(e,r.account)}`}}function _c(e,t,n){const r=Ft(e,t,n);if(!r)return null;const s=Ce(e,t,n),o=xh(r.mnemonic,r.account);return{taproot:{address:s.wallet.address,path:Zh(e,r.account)},segwit:{address:Qr.p2wpkh.fromPubKey(o,"regtest"),path:Ye.segwit(r.account)},tapkey:{address:Qr.p2tr.fromPubKey(iE(s.pubkey),"regtest"),path:Ye.nostr(r.account)},npub:{address:s.npub,path:Ye.nostr(r.account)},ethereum:{address:Q2(r.mnemonic,r.account),path:Ye.ethereum(r.account)}}}function cE(e,t,n){const r=Ft(e,t,n);if(!r)return null;const s=Ce(e,t,n),o=_c(e,t,n),{mnemonic:i,account:a}=r;return{keys:{taproot:o.taproot.address,segwit:o.segwit.address,nostr:o.npub.address,ethereum:o.ethereum.address},secrets:{taproot:s.wallet.secret,segwit:bc(i,a),nostr:Go(i,a),ethereum:kh(i,a)}}}function Ac(e,t,n){const r=Qo(e.chain,n);if(!r)return null;const s=Pe(r.scriptPubKey),o=t.nodes.get(n),i=Ce(e.keys,t,o),a=o&&Ce(e.keys,t,t.nodes.get(o.parent));return i&&Pe(i.wallet.script)===s?{wallet:i.wallet,who:"own"}:e.wallet&&Pe(e.wallet.script)===s?{wallet:e.wallet,who:"lab"}:a&&Pe(a.wallet.script)===s?{wallet:a.wallet,who:"parent"}:{wallet:null,who:"other",script:s}}function As(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(...As(e,s))}return r}function ma(e,t){const n=[];for(let r=t;r;r=e.nodes.get(r.parent))n.push(r.name);return n.join(".")}function uE(e,t,n){const r=Ft(e,t,n);if(!r)return null;if(n.kind!=="agent")return eE(Jv(yc(r.mnemonic)),ma(t,n));const s=ma(t,t.nodes.get(n.parent));return Qv(Xv(Go(r.mnemonic,r.account)),`${n.name}@${s}`,n.name,s)}const fE=dh(xe),zr=(e,t=239)=>fE.encode(ae(Uint8Array.of(t),ut(e),Uint8Array.of(1))),lE=e=>Yn.encode("nsec",Yn.toWords(ut(e))),dE="0123456789()[],'/*abcdefgh@:$%{}IJKLMNOPQRSTUVWXYZ&+-.;<=>?!^_|~ijklmnopqrstuvwxyzABCDEFGH`#\"\\ ",hE=[0xf5dee51989n,0xa9fdca3312n,0x1bab10e32dn,0x3706b1677an,0x644d626ffdn];function Ni(e){const t=(i,a)=>{const c=i>>35n;return i=(i&0x7ffffffffn)<<5n^BigInt(a),hE.forEach((u,f)=>{c>>BigInt(f)&1n&&(i^=u)}),i};let n=1n,r=0,s=0;for(const i of e){const a=dE.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 pE(e,t,n){const r=Ft(e,t,n);if(!r)return null;const s=Go(r.mnemonic,r.account),o=la(r.mnemonic,r.account),i={bip86:`tr(${zr(o)})`,tapkey:`tr(${zr(s)})`,wallet:`rawtr(${zr(o)})`}[e.scheme],a=n.kind==="agent",c=ma(t,a?t.nodes.get(n.parent):n);return{seed:a&&n.edge!=="adopted"?null:{from:[r.origin,...r.steps].join(" › "),mnemonic:r.mnemonic},account:[["nsec","NIP-06",lE(s)],["taproot","descriptor",Ni(i)],["segwit","descriptor",Ni(`wpkh(${zr(bc(r.mnemonic,r.account))})`)],["tapkey","descriptor",Ni(`tr(${zr(s)})`)],["ethereum","private key",`0x${kh(r.mnemonic,r.account)}`]],leaves:a?rE(s,`${n.name}@${c}`):sE(yc(r.mnemonic),c)}}const gs=1e8,nt=50*gs,Le=330,Vh=e=>(e/gs).toFixed(8).replace(/\.?0+$/,""),ce=e=>`${Vh(e)} tBTC`;function Bc(e){if(e<1e6)return ce(e);const t=Math.round(e/1e6)*1e6;return`${t===e?"":"≈"}${ce(t)}`}function Tc(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)*gs+Number((t[2]??"").padEnd(8,"0"))}class qh{constructor(t,n,r){this.secret=t,this.pubkey=n,this.path=r,this.address=Qr.p2wpkh.fromPubKey(n,"regtest"),this.script=Qr.toScriptPubKey(this.address)}sign(t,n){return[xr.segwit.sign(this.secret,t,n,{pubkey:this.pubkey}).hex,this.pubkey]}}const Li=new Map;function $e(e,t,n){const r=Ft(e,t,n);if(!r)return null;const s=`${r.mnemonic}|${r.account}`;return Li.has(s)||Li.set(s,new qh(bc(r.mnemonic,r.account),xh(r.mnemonic,r.account),Ye.segwit(r.account))),Li.get(s)}function gE(e,t,n){var s;const r=n?t.nodes.get(n):null;return r&&r.root===r.id&&r.status==="active"?((s=$e(e,t,r))==null?void 0:s.script)??null:null}const pr=(e,t)=>{var n,r;return((r=(n=e.mining)==null?void 0:n.rigs)==null?void 0:r[t])??1};function Ic(e,t){var n;return((n=e.mining)==null?void 0:n.rule)==="none"?[]:t.roots.filter(r=>r.status==="active"&&pr(e,r.id)>0&&$e(e.keys,t,r)).slice(0,Ch)}function zh(e,t,n){var i,a;if(((i=e.mining)==null?void 0:i.rule)==="none")return null;if(((a=e.mining)==null?void 0:a.rule)==="last"){const c=gE(e.keys,t,n);return c?[{script:c,value:nt}]:null}const r=Ic(e,t),s=r.reduce((c,u)=>c+pr(e,u.id),0);let o=nt;return r.length?r.map((c,u)=>{const f=u===r.length-1?o:Math.floor(nt*pr(e,c.id)/s);return o-=f,{script:$e(e.keys,t,c).script,value:f}}):null}function ms(e,t,n=wt){const r=t+de,s=u=>u===r||u-r>=Le&&u-r<=nt,o=[...e].sort((u,f)=>u.value-f.value),i=o.find(u=>s(u.value));if(i||n<2)return i?[i]:null;let a=null;for(let u=0;ue.reduce((t,n)=>t+n.value,0);function Cc(e,t=wt){let n=0,r=-de;for(const s of e.map(o=>o.value).sort((o,i)=>i-o).slice(0,t)){r+=s;const o=r<=nt?r:r-nt>=Le?nt:r-Le;o>=Le&&r-o<=nt&&(n=Math.max(n,o))}return n}function Fh(e,t,n,r=wt,s="send"){const o=Oc(t),i=n+de,a=Cc(t,r),c=`${s[0].toUpperCase()}${s.slice(1)}`;if(od.value).sort((d,p)=>p-d),f=u.slice(0,r).map((d,p)=>u.slice(0,p+1).reduce((h,g)=>h+g,0)),l=Math.min(...[...u,...u.flatMap((d,p)=>u.slice(p+1).map(h=>d+h)),...f].filter(d=>d>=i));return Number.isFinite(l)&&l-inew Set((e.offers??[]).flatMap(t=>t.payers.map(n=>`${n.txid}:${n.vout}`))),Gh=(e,t)=>e.chain.coins(t.script).filter(n=>{var r;return!((r=n.inscriptions)!=null&&r.length)}),Yh=(e,t,n=wt)=>!!ms(e,t,n),Xh=(e,t,n)=>Yh(Gh(e,t),n);function Pc(e,t,n,r,s="This node",o="send"){const i=Gh(e,t),a=Wh(e),c=ms(i.filter(d=>!a.has(`${d.txid}:${d.vout}`)),r)??ms(i,r);if(!c)throw new Error(Fh(s,i,r,wt,o));const u=Oc(c)-r-de,f=ie.create({vin:c.map(d=>Vt(d.txid,d.vout,d.value,d.scriptPubKey)),vout:[Ke(r,n),...u?[Ke(u,t.script)]:[]]});c.forEach((d,p)=>{f.vin[p].witness=t instanceof qh?t.sign(f,p):[t.sign(f,void 0,p)]});const l=ie.encode(f).hex;return e.chain.submitPackage([l]),ie.util.getTxid(l)}function Jh(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=$e(e.keys,t,o),c=$e(e.keys,t,i);if(!a||!c)throw new Error("A holding that predates lab keys has no SegWit addresses.");if(!Number.isSafeInteger(s)||snt)throw new Error("Send at most 50 test BTC at a time: no output on this chain is bigger than one block reward.");return Pc(e,a,c.script,s,o.name)}function mE(e,t,n){if(!t||!n||Pe(t.script)===Pe(n.script))return 0;let r=0;for(const s of e.chain.coins(t.script)){if(s.value-de[t,...t.log.flatMap((n,r)=>n.ok&&n.op==="graduate"?[_n(e.slice(0,r),{pending:!0})]:[])];function Qh(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 yE=(e,t,n)=>Qh(Uc(t,n),(r,s)=>{const o=$e(e,r,s);return o&&Pe(o.script)}),Ri=new Map,bE=(e,t,n)=>Qh(Uc(t,n),(r,s)=>{const o=Ft(e,r,s),i=o&&`${e.scheme}|${o.mnemonic}|${o.account}`;return i&&!Ri.has(i)&&Ri.set(i,Pe(Ce(e,r,s).wallet.script)),i?Ri.get(i):null}),Nc=(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 wE(e,t,n,r){for(const s of Uc(t,n))for(const o of s.nodes.values()){const i=Ce(e,s,o);if(i&&Pe(i.wallet.script)===r)return{node:o.id,wallet:i.wallet}}return null}function xE(e,t,n=new Map,r=new Map){var a;const s=[],o=c=>t.get(Pe(c))??null,i=c=>c.reduce((u,f)=>u+f.value,0);for(const{txid:c,tx:u,height:f,coinbase:l}of e.transactions.values()){const d=u.vout.map(x=>({script:Pe(x.scriptPubKey),node:o(x.scriptPubKey),value:Number(x.value)}));if(l){d.forEach((x,$)=>{x.node&&s.push({kind:"mine",key:`${c}:${$}`,txid:c,beat:f,from:null,to:x.node,amount:x.value,fee:0,change:0})});continue}const p=u.vin.map(x=>{var E,I;const $=((E=e.transactions.get(x.txid))==null?void 0:E.tx.vout[x.vout])??((I=e.imported)==null?void 0:I.call(e,x.txid,x.vout));return $?{node:o($.scriptPubKey),value:Number($.value)}:null}),h=r.get(c);if(h&&p.length>1&&p[0]&&p.slice(1).every(x=>(x==null?void 0:x.node)===h.buyer)){s.push({kind:"deal",key:c,txid:c,beat:f,from:h.buyer,to:h.seller,amount:h.price,item:h.item,fee:i(p)-i(d),change:i(d.filter(x=>x.node===h.buyer))});continue}if(p.every(x=>x&&!x.node)){const x=d.filter($=>$.node);x.length&&s.push({kind:"fund",key:c,txid:c,beat:f,from:null,to:x[0].node,amount:x[0].value,fee:i(p)-i(d),change:i(d.filter($=>!$.node))});continue}const g=(a=p[0])==null?void 0:a.node;if(!g||!p.every(x=>(x==null?void 0:x.node)===g))continue;const m=d.filter(x=>x.node!==g),b=d.filter(x=>x.node===g),w=i(p)-i(d),y={key:c,txid:c,beat:f,from:g,fee:w};m.length&&m.every(x=>n.get(x.script)===g)?s.push({...y,kind:"gas",to:g,amount:i(m),change:i(b)}):m.length?s.push({...y,kind:"pay",to:m[0].node,amount:m[0].value,change:i(b)}):s.push({...y,kind:"move",to:g,amount:i(b),change:0})}return s}function ya(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(Pe(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 ba="lineage-offer",Ju=/^[0-9a-f]{64}$/,Hi=/^[0-9a-f]{64}i0$/,Qu=/^5120[0-9a-f]{64}$/,ji=/^0014[0-9a-f]{40}$/,ef=e=>({txid:e.txid,vout:e.vout,value:e.value,script:Pe(e.scriptPubKey)}),tf=(e,t)=>!e.utxos.has(`${t.txid}:${t.vout}`),e0=e=>{const t=Xo(new vs(e.chain));return{events:t,state:_n(t,{pending:!0})}};function t0(e){return ie.create({vin:[e.holder,...e.payers].map(t=>Vt(t.txid,t.vout,t.value,t.script)),vout:[Ke(e.holder.value,e.to),...e.price?[Ke(e.price,e.pay)]:[],...e.change?[Ke(e.change,e.back)]:[]]})}function Lc(e,t,n,r){const s=Qo(e.chain,r),o=s&&wE(e.keys,t,n,Pe(s.scriptPubKey));return o?{coin:s,node:n.nodes.get(o.node),wallet:o.wallet}:null}function n0(e,t,n,r,s=Date.now()){const{events:o,state:i}=e0(e),a=i.items.get(t),c=i.nodes.get(n);if(!a)throw new Error("Pick an item to make an offer on.");if(!c)throw new Error("Pick who makes the offer.");if(!Number.isSafeInteger(r)||r<0||r>0&&rnt)throw new Error("Offer at most 50 test BTC: no output on this chain is bigger than one block reward.");const u=Lc(e,o,i,t),f=u==null?void 0:u.node;if(!f)throw new Error(`No node in this lab holds ${a.name}.`);if(f.id===c.id)throw new Error(`${c.name} already holds ${a.name}.`);for(const y of[c,f])if(y.status!=="active")throw new Error(`${y.name} is ${y.status}.`);const l=$e(e.keys,i,c),d=$e(e.keys,i,f),p=Ce(e.keys,i,c);if(!l||!d||!p)throw new Error("A holding that predates lab keys cannot trade.");if((e.offers??[]).some(y=>y.item===t&&y.buyer===c.id&&wa(e,i,y)==="open"))throw new Error(`${c.name} already has an open offer on ${a.name}. Withdraw it first.`);const h=e.chain.coins(l.script),g=Wh(e),m=ms(h.filter(y=>!g.has(`${y.txid}:${y.vout}`)),r,wt-1)??ms(h,r,wt-1);if(!m)throw new Error(Fh(c.name,h,r,wt-1,"offer"));const b={kind:ba,version:1,item:t,buyer:c.id,seller:f.id,price:r,holder:ef(u.coin),payers:m.map(ef),to:Pe(p.wallet.script),pay:Pe(d.script),back:Pe(l.script),change:m.reduce((y,x)=>y+x.value,0)-r-de,at:s},w=t0(b);return b.txid=ie.util.getTxid(w),b.witnesses=m.map((y,x)=>l.sign(w,x+1)),(e.offers??(e.offers=[])).push(b),b}function Rc(e,t,n){var c,u;const r=f=>{var l;return((l=t.nodes.get(f))==null?void 0:l.name)??"a node"},s=((c=t.items.get(n.item))==null?void 0:c.name)??"the item";if(tf(e.chain,n.holder))return`${s} has moved since`;if(n.payers.some(f=>tf(e.chain,f)))return`${r(n.buyer)} has spent a coin the offer promised`;for(const f of[n.buyer,n.seller]){const l=t.nodes.get(f);if((l==null?void 0:l.status)!=="active")return`${r(f)} is ${(l==null?void 0:l.status)??"gone"}`}const o=t.nodes.get(n.buyer),i=t.nodes.get(n.seller),a=f=>f?Pe(f.script):"";return a((u=Ce(e.keys,t,o))==null?void 0:u.wallet)!==n.to||a($e(e.keys,t,o))!==n.back?`${o.name} has new keys since`:n.price&&a($e(e.keys,t,i))!==n.pay?`${i.name} has new keys since`:""}const wa=(e,t,n)=>e.chain.transactions.has(n.txid)?"done":Rc(e,t,n)?"stale":"open";function vE(e,t){const n=(e.offers??[]).find(c=>c.txid===t);if(!n)throw new Error("That offer is gone.");if(e.chain.transactions.has(n.txid))throw new Error("That offer was already accepted.");const{events:r,state:s}=e0(e),o=Rc(e,s,n);if(o)throw new Error(`This offer is stale: ${o}.`);const i=Lc(e,r,s,n.item);if((i==null?void 0:i.node.id)!==n.seller)throw new Error("Only the holder can accept.");const a=t0(n);return n.witnesses.forEach((c,u)=>{a.vin[u+1].witness=c}),a.vin[0].witness=[i.wallet.sign(a,void 0,0)],e.chain.submitPackage([ie.encode(a).hex]),n}function EE(e,t){const n=(e.offers??[]).find(r=>r.txid===t);if(!n)throw new Error("That offer is gone.");if(e.chain.transactions.has(n.txid))throw new Error("That offer was accepted: it is on the chain now.");return e.offers=e.offers.filter(r=>r!==n),n}function kE(e){const t=(r,s)=>r&&Ju.test(r.txid)&&Number.isSafeInteger(r.vout)&&r.vout>=0&&Number.isSafeInteger(r.value)&&r.value>=Le&&r.value<=nt&&s.test(r.script),n=r=>Number.isSafeInteger(r)&&(r===0||r>=Le&&r<=nt);if((e==null?void 0:e.kind)!==ba||e.version!==1||!Hi.test(e.item)||!Hi.test(e.buyer)||!Hi.test(e.seller)||e.buyer===e.seller||!n(e.price)||!n(e.change)||!t(e.holder,Qu)||!Array.isArray(e.payers)||!e.payers.length||e.payers.length>wt-1||!e.payers.every(r=>t(r,ji))||!Qu.test(e.to)||!ji.test(e.pay)||!ji.test(e.back)||!Ju.test(e.txid)||!Array.isArray(e.witnesses)||e.witnesses.length!==e.payers.length||!e.witnesses.every(r=>Array.isArray(r)&&r.length===2&&/^30[0-9a-f]{12,140}01$/.test(r[0])&&/^0[23][0-9a-f]{64}$/.test(r[1]))||!Number.isSafeInteger(e.at))throw new Error("Invalid offer.");return{kind:ba,version:1,item:e.item,buyer:e.buyer,seller:e.seller,price:e.price,holder:{...e.holder},payers:e.payers.map(r=>({...r})),to:e.to,pay:e.pay,back:e.back,change:e.change,at:e.at,txid:e.txid,witnesses:e.witnesses.map(r=>[...r])}}const ni="orgchain:lab:v1",SE=["each",10,30,60,"manual"];function Bs(e={tempo:"each",nextAt:null}){const{tempo:t,nextAt:n}=e??{},r=typeof t=="number";if(!SE.includes(t)||!(n===null||r&&Number.isSafeInteger(n)&&n>0))throw new Error("Invalid clock.");return{tempo:t,nextAt:n}}function r0(e){const t=$c();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]=wh(s,24)}if(t.scheme=(e==null?void 0:e.scheme)??(Object.keys(t.roots).length?"wallet":"bip86"),!oE.includes(t.scheme))throw new Error("Invalid lab keys.");return t}const $E=["split","last","none"];function Ts(e){const t=(e==null?void 0:e.rule)??"split",n={};if(!$E.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}}function s0(e=[]){if(!Array.isArray(e)||e.length>1e3)throw new Error("Invalid offers.");const t=e.map(kE);if(new Set(t.map(n=>n.txid)).size!==t.length)throw new Error("Invalid offers.");return t}const Is=()=>({wallet:null,chain:new Jo,clock:Bs(),keys:$c(),mining:Ts(),offers:[]});function o0(e){if(!e)return Is();const t=JSON.parse(e);if((t==null?void 0:t.kind)!=="orgchain-lab"||t.network!==gn||t.version!==1)throw new Error("That is not an Orgchain v1 lab.");return{wallet:t.wallet?An.load(t.wallet):null,chain:new Jo(t.chain),clock:Bs(t.clock),keys:r0(t.keys),mining:Ts(t.mining),offers:s0(t.offers)}}const i0=e=>{var t;return JSON.stringify({kind:"orgchain-lab",network:gn,version:1,wallet:((t=e.wallet)==null?void 0:t.backup())??null,chain:e.chain.snapshot(),clock:Bs(e.clock),keys:r0(e.keys),mining:Ts(e.mining),offers:s0(e.offers)})};function _E(e,t,n){var r;e.mining=Ts({...e.mining,rigs:{...(r=e.mining)==null?void 0:r.rigs,[t]:n}})}function AE(e,t){e.mining=Ts({...e.mining,rule:t})}const Hc=()=>o0(localStorage.getItem(ni));function BE(e){try{localStorage.setItem(ni,i0(e))}catch{throw new Error("Browser storage is full or unavailable, so nothing was saved. Save a backup, then reset.")}}async function TE(e,{locks:t=(s=>(s=globalThis.navigator)==null?void 0:s.locks)(),read:n=Hc,save:r=BE}={}){if(!t)throw new Error("Orgchain needs Web Locks: open it over HTTPS or on localhost.");return t.request(ni,async()=>{const o=n(),i=await e(o);return i!==!1&&r(o),{lab:o,result:i}})}function Et(e,t=null){e.wallet||(e.wallet=An.create());const n=t!=null&&t.length?e.chain.mineTo(t.map(r=>Ke(r.value,r.script))):e.chain.mine(e.wallet.script);return e.clock=Bs({tempo:e.clock.tempo,nextAt:null}),n}function Rr(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 IE(e,t,n=Date.now(),r=null){e.clock=Bs({tempo:t,nextAt:null}),t==="each"&&e.chain.mempool.length?Et(e,r):Rr(e,n)}function OE(e,t=Date.now(),n=null){const{tempo:r,nextAt:s}=e.clock;return typeof r!="number"||!e.chain.mempool.length?!1:s===null?(Rr(e,t),!0):t`found ${e.name}`,birth:e=>`birth ${e.name}`,award:e=>`award ${e.skill} ${e.belt}`,decide:e=>`decide ${e.title}`,make:e=>`make ${e.name}`,keyring:(e,t)=>Yo(t,e),charter:e=>`charter ${e.form}${e.jurisdiction?` ${e.jurisdiction}`:""}`,graduate:()=>"graduate",close:()=>"close"};function PE(e,t={}){if(!Object.hasOwn(nf,e))throw new Error("Unknown verb.");const n={op:e};for(const s of nf[e]){const o=t[s];typeof o=="string"&&o.trim()&&(n[s]=o.trim())}const r=e==="keyring"&&t.proof&&typeof t.proof=="object"?t.proof:null;return r&&(n.proof=Object.fromEntries(vt.filter(s=>typeof r[s]=="string").map(s=>[s,r[s]]))),n}function a0(e,t){const n=at(e),r=n.nodes.get(t),s=r&&cE(e.keys,n,r);if(!s)throw new Error(`${(r==null?void 0:r.name)??"That node"} predates lab keys, so it has no keys to list.`);return dv(t,s.keys,s.secrets)}function jc(e,t,n,r={}){if(t==="keyring"){for(let s=e.nodes.get(n);s;s=s.edge==="derived"?e.nodes.get(s.parent):null)if(s.graduated==="cued")return`${s.name}'s graduation is cued, and it changes ${s.id===n?"its":`${e.nodes.get(n).name}'s`} keys. Publish the keyring once it lands`}if(t==="graduate"&&e.nodes.has(r.of)){const s=new Set(As(e,r.of).map(i=>i.id)),o=e.log.find(i=>i.pending&&i.ok&&i.op==="keyring"&&s.has(i.node));if(o)return`${e.nodes.get(o.node).name}'s keyring is cued. Graduate ${e.nodes.get(r.of).name} once it lands, so the graduation retires it`}return""}const at=e=>_n(Xo(new vs(e.chain)),{pending:!0});function c0(e,t,n,r){const s=PE(t,r),o=Xo(new vs(e.chain)),i={id:"check",status:"pending",height:null,metadata:s,parent:n??null,protocol:Ec},{ok:a,why:c}=_n([...o,i],{pending:!0}).log.at(-1);if(!a)throw new Error(`${c[0].toUpperCase()}${c.slice(1)}.`);return s}const xa=Bt+2*de+330,u0=1e5,Kc=1e4,Dc=(e,t=0)=>Bt+2*de+(e==="birth"?1:e==="graduate"?Math.max(0,t-1):0)*de+330,UE=(e,t=0)=>Dc(e,t)-330,Ir=(e,t,n)=>e.chain.coins(t.script).find(r=>{var s;return!((s=r.inscriptions)!=null&&s.length)&&r.value>=n}),va=e=>Vt(e.txid,e.vout,e.value,e.scriptPubKey),f0=(e,t)=>(t.forEach((n,r)=>{e.vin[r].witness=[n.sign(e,void 0,r)]}),ie.encode(e).hex);function Mc(e){e.keys??(e.keys=$c()),e.wallet||(e.wallet=An.create()),Ir(e,e.wallet,u0+de+330)||Et(e)}function l0(e,t,n=xa,r=u0){if(t===e.wallet||Ir(e,t,n))return;const s=Ir(e,e.wallet,r+de+330),o=ie.create({vin:[va(s)],vout:[Ke(r,t.script),Ke(s.value-r-de,e.wallet.script)]});e.chain.submitPackage([f0(o,[e.wallet])])}function rf(e,t,n,r,s){if(r===e.wallet||Ir(e,r,s))return;const o=n&&$e(e.keys,t,n);if(!o)return l0(e,r,s);Pc(e,o,r.script,Math.max(Kc,s),n.name)}function NE(e,t,n,r,s){if(r===e.wallet||Ir(e,r,s))return!0;const o=n&&$e(e.keys,t,n);return!o||Xh(e,o,Math.max(Kc,s))}function Zc(e,t,n,r,s={}){var f,l;const o=r?t.nodes.get(r):null,i=o&&((f=Ac(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&&Ce(e.keys,t,a)?As(t,a.id).length:0;if(!NE(e,t,o,i,Dc(n,c))){const d=t.nodes.get(o.parent);return`${o.name} has no test BTC for gas. ${d?`${d.name} can send some`:((l=e.mining)==null?void 0:l.rule)==="none"?"Fund it from the lab wallet":"It earns some each beat it mines"}`}const u=c?$e(e.keys,t,a):null;return u&&!Yh(e.chain.coins(u.script).filter(d=>d.value-de>=Le).map(d=>({value:d.value-de})),Kc)?`${a.name} needs test BTC of its own to claim its new root. Send it some first`:""}function sf(e,t,n,r,s=n){const o=Qo(e.chain,t),i=Ir(e,s,de+330),a=ie.create({vin:[va(o),va(i)],vout:[Ke(o.value,r.script),Ke(i.value-de,s.script)]});e.chain.submitPackage([f0(a,[n,s])])}function of(e,t,n,r,s){return new hx(e.chain,t).inscribe(CE[n](s,r),r??null,s,{metaprotocol:Ec})}const ri=(e,t)=>{var r;const n=at(e);return zh(e,n,((r=n.nodes.get(t))==null?void 0:r.root)??null)},si=(e,t)=>zh(e,at(e),t);function Vc(e){var r,s,o;const t=at(e),n=new Map;for(const i of t.nodes.values())for(const a of[$e(e.keys,t,i),(r=Ce(e.keys,t,i))==null?void 0:r.wallet])a&&n.set(Pe(a.script),i.root);for(const i of[...e.chain.mempool].reverse()){const a=e.chain.transactions.get(ie.util.getTxid(i));if(a!=null&&a.inscription){const c=(s=t.log.find(u=>u.id===a.inscription.id))==null?void 0:s.root;if(c)return c;continue}for(const c of(a==null?void 0:a.tx.vin)??[]){const u=((o=e.chain.transactions.get(c.txid))==null?void 0:o.tx.vout[c.vout])??e.chain.imported(c.txid,c.vout),f=u&&n.get(Pe(u.scriptPubKey));if(f)return f}}return null}function af(e,t,n){var s;const r=Ac(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 d0(e,t,n,r){if(t==="found"){const f=Ru(),l=aE(e.keys,f);l0(e,l,xa,xa);const d=of(e,l,t,null,r);return e.keys.roots[d]=f,d}const s=at(e),o=af(e,s,n),i=s.nodes.get(n),a=t==="graduate"?s.nodes.get(r.of):null,c=a&&Ce(e.keys,s,a)?As(s,a.id).map(f=>[f.id,af(e,s,f.id)]):[];rf(e,s,i,o,Dc(t,c.length));const u=of(e,o,t,n,r);if(t==="birth"){const f=at(e),l=Ce(e.keys,f,f.nodes.get(u));l&&sf(e,u,o,l.wallet)}if(c.length){e.keys.adopted[a.id]=Ru();const f=at(e);for(const[l,d]of c){const p=Ce(e.keys,f,f.nodes.get(l)).wallet;if(mE(e,$e(e.keys,s,s.nodes.get(l)),$e(e.keys,f,f.nodes.get(l))),l!==a.id){sf(e,l,d,p,o);continue}rf(e,f,f.nodes.get(l),p,de+330),Tv(e.chain,Bv(e.chain,l,p),d)}}return u}function LE(e,t,n,r,s=Date.now()){const o=jc(at(e),t,n??null,r??{});if(o)throw new Error(`${o}.`);const i=c0(e,t,n,t==="keyring"?a0(e,n):r),a=Zc(e,at(e),t,n??null,i);if(a)throw new Error(`${a}.`);Mc(e);const c=d0(e,t,n??null,i);return e.clock.tempo==="each"?Et(e,ri(e,n??c)):Rr(e,s),c}function RE(e,t,n,r,s=Date.now()){const o=Jh(e,at(e),t,n,r);return e.clock.tempo==="each"?Et(e,ri(e,t)):Rr(e,s),o}const HE=(e,t,n,r,s=Date.now())=>n0(e,t,n,r,s);function jE(e,t,n=Date.now()){const r=vE(e,t);return e.clock.tempo==="each"?Et(e,ri(e,r.seller)):Rr(e,n),r}const KE=(e,t)=>EE(e,t);function DE(e,t,n,r=Date.now()){const s=at(e),o=s.nodes.get(t);if(!o||o.root!==o.id)throw new Error("Pick a holding to fund.");if(o.status!=="active")throw new Error(`${o.name} is closed.`);const i=$e(e.keys,s,o);if(!i)throw new Error("A holding that predates lab keys has no SegWit address to fund.");if(!Number.isSafeInteger(n)||nnt)throw new Error("Fund at most 50 test BTC at a time: no output on this chain is bigger than one block reward.");Mc(e),Xh(e,e.wallet,n)||Et(e);const a=Pc(e,e.wallet,i.script,n,"The lab wallet","fund");return e.clock.tempo==="each"?Et(e,ri(e,t)):Rr(e,r),a}const Ea="yolopreneur",ME=[[["found",null,{name:"yolopreneur"}]],[["birth","yolopreneur",{name:"well-known",kind:"org"}],["birth","yolopreneur",{name:"time",kind:"org"}],["keyring","yolopreneur",{}],["charter","yolopreneur",{form:"series-llc",jurisdiction:"US-WY",legal:"Yolopreneur Holdings LLC",provider:"doola"}]],[["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"}],["charter","yolopreneur",{form:"series",of:"well-known"}],["charter","yolopreneur",{form:"series",of:"time"}]],[["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"}],["charter","yolopreneur",{form:"series",of:"lineage"}]],[["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."}],["make","sol",{name:"launch-kit",note:"The page, the post and the checklist every venture launches with."}],["keyring","sol",{}],["keyring","lineage",{}]],[["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."}],["charter","lineage",{form:"llc",jurisdiction:"US-WY",legal:"Lineage LLC",provider:"doola"}],["offer","lineage",{item:"launch-kit",price:.1}]]];function ZE(e){Mc(e),e.chain.mempool.length&&Et(e);const t={},n={};for(const r of ME){for(const[s,o,i]of r){if(s==="send"){Jh(e,at(e),t[o],t[i.to],i.amount*gs);continue}if(s==="offer"){n0(e,n[i.item],t[o],i.price*gs);continue}const a=s==="keyring"?a0(e,t[o]):Object.fromEntries(Object.entries(i).map(([f,l])=>[f,f==="to"||f==="of"?t[l]:l])),c=o?t[o]:null,u=d0(e,s,c,c0(e,s,c,a));(s==="found"||s==="birth")&&(t[i.name]=u),s==="make"&&(n[i.name]=u)}Et(e,si(e,t[Ea]))}return t[Ea]}const K=e=>document.getElementById(e);function T(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 Xr=(e,t)=>`${e} ${t}${e===1?"":"s"}`,mt=e=>e==="cued"?"cued":`beat ${e}`,VE=e=>new Date(e).toLocaleTimeString([],{hour:"2-digit",minute:"2-digit",second:"2-digit"}),cf=e=>JSON.stringify(e,(t,n)=>typeof n=="bigint"?String(n):n,2),O={holding:null,node:null,event:null,tx:null,beat:null,verb:"birth",busy:!1,replay:null,closing:null,reveal:null};let q=Is(),No=new vs(q.chain),dn=[],z=_n([]),Te=z,Me={owner:new Map,ledger:[],now:new Map,view:new Map},mn=new Map;const tt=()=>q.chain.blocks.length,ka=()=>dn.filter(e=>e.status==="pending").length,Sa=e=>Me.ledger.filter(t=>t.beat===null&&t.kind===e).length,to=[["pay","cued send"],["deal","cued deal"],["fund","cued deposit"]],qE=()=>ka()+to.reduce((e,[t])=>e+Sa(t),0),Bn=e=>{var t;return((t=z.items.get(e))==null?void 0:t.name)??"an item"},$a=()=>q.offers??[],no=e=>Me.view.get(e)??0,h0=e=>Me.now.get(e)??0,G=(e,t=z)=>e?t.nodes.get(e)??null:null,zE=e=>{var t;return!!e&&(e.root===O.holding||((t=G(e.parent))==null?void 0:t.root)===O.holding)},qc=e=>Object.assign(O,{event:null,tx:null,closing:null,reveal:null},e),Hr=e=>{qc(e),oi()};function ye(e,t=!1){const n=K("say");n.textContent=e,n.classList.toggle("bad",t)}function p0(){try{q=Hc()}catch(e){q=Is(),ye(`This browser's saved lab could not be read (${e.message}) Load a backup, or reset to start over.`,!0)}zc()}function zc(){var n;No=new vs(q.chain),dn=Xo(No),z=_n(dn,{pending:!0}),O.beat!==null&&O.beat>=tt()&&(O.beat=null),G(O.holding)||(O.holding=((n=z.roots.filter(r=>r.kind==="holding").at(-1)??z.roots.at(-1))==null?void 0:n.id)??null),zE(G(O.node))||(O.node=O.holding),O.event&&!z.log.some(r=>r.id===O.event)&&(O.event=null),Te=O.beat===null?z:_n(dn,{upTo:O.beat});const e=yE(q.keys,dn,z),t=new Map($a().map(r=>[r.txid,r]));Me={owner:e,ledger:xE(q.chain,e,bE(q.keys,dn,z),t),now:ya(q.chain,e)},mn=new Map([...z.items.keys()].map(r=>{var s;return[r,((s=Lc(q,dn,z,r))==null?void 0:s.node.id)??null]})),Me.view=O.beat===null?Me.now:ya(q.chain,e,O.beat),O.tx&&!Me.ledger.some(r=>r.key===O.tx)&&(O.tx=null),oi()}function Lo(e){O.beat=e>=tt()?null:Math.max(0,e),Te=O.beat===null?z:_n(dn,{upTo:O.beat}),Me.view=O.beat===null?Me.now:ya(q.chain,Me.owner,O.beat),oi()}async function ft(e,t){if(O.busy)return!1;O.busy=!0,document.body.classList.add("busy");try{return q=(await TE(e,t)).lab,!0}catch(n){return ye((n==null?void 0:n.message)||String(n),!0),!1}finally{O.busy=!1,document.body.classList.remove("busy"),zc()}}async function Ut(e,t,n,r){let s=null;if(!await ft(i=>{s=LE(i,e,t,n)}))return!1;const o=No.events.find(i=>i.id===s);return ye(r(s,(o==null?void 0:o.status)==="confirmed"?`at beat ${o.height}`:"cued for the next beat")),oi(),!0}async function g0(e){const t=[ka(),...to.map(([a])=>Sa(a))],n=tt();if(!await ft(e)||tt()===n)return;const r=[ka(),...to.map(([a])=>Sa(a))],s=["cued act",...to.map(([,a])=>a)],o=t.map((a,c)=>[a-r[c],s[c]]).filter(([a])=>a>0).map(([a,c])=>Xr(a,c)),i=FE(Me.ledger.filter(a=>a.kind==="mine"&&a.beat===tt()));ye(`Beat ${tt()}: ${o.length?`${o.join(" and ")} landed, and ${i}`:i}.`)}function FE(e){if(!e.length)return"the lab wallet earned 50 tBTC";const t=e.map(r=>{var s;return((s=G(r.to))==null?void 0:s.name)??"?"}),n=e.map(r=>Bc(r.amount));return e.length===1?`${t[0]} earned ${ce(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 WE(){var t;if(((t=q.mining)==null?void 0:t.rule)==="last")return"the holding that acts";const e=Ic(q,z);return e.length?e.length===1?e[0].name:`${e.length} holdings, split by hashrate`:"the lab wallet"}function oi(){m0(),XE(),JE(),Os(),_0(),Wc()}function m0(){const e=qE(),{tempo:t}=q.clock;for(const r of document.querySelectorAll("[data-tempo]"))r.setAttribute("aria-pressed",String(String(t)===r.dataset.tempo));K("clock-beat").textContent=String(tt()),K("clock-cued").textContent=e?`${e} cued · ${GE()}`:"nothing cued";const n=WE();K("clock-pays").textContent=`beats pay ${n}`,K("beat-now").title=`Beat now: ${e?"land what is cued, and ":""}pay ${n} 50 test BTC`}function GE(){const{tempo:e,nextAt:t}=q.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"}const YE={split:"Every active holding mines: each beat's 50 tBTC splits by hashrate, set on each holding (0 sits out).",last:"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.",none:"Mainnet has no mining to join: beats pay the lab wallet, standing in for the world's miners. Fund a holding from it, the way you'd fund a seed from a wallet you already have."};function XE(){var a,c;const e=((a=q.mining)==null?void 0:a.rule)??"split",t=e==="split",n=t?Ic(q,z):[],r=n.reduce((u,f)=>u+pr(q,f.id),0);K("holdings-list").replaceChildren(...z.roots.map(u=>{var b;const f=xv(z,u.id),l=u.id===O.holding,d=u.status==="active",p=n.some(w=>w.id===u.id)?pr(q,u.id)/r:0,h=[...z.nodes.values()].reduce((w,y)=>w+(y.root===u.id?h0(y.id):0),0),m=[u.graduated!==null&&`from ${((b=G(u.parent))==null?void 0:b.name)??"?"}${u.graduated==="cued"?", cued":` at beat ${u.graduated}`}`||mt(u.born),Xr(f.orgs,"org"),Xr(f.agents,"agent"),Xr(f.belts,"belt"),h>0&&Bc(h),t&&d&&(p?`${Math.round(p*100)}% of each beat`:"not mining"),!d&&"closed"].filter(Boolean);return T("li",{},T("button",{type:"button",class:`hold${l?" on":""}${d?"":" gone"}`,"aria-pressed":String(l),onclick:()=>Hr({holding:u.id,node:u.id})},T("span",{class:"hn",text:u.name})," ",T("span",{class:"hm",text:m.join(" · ")})),t&&d&&$e(q.keys,z,u)&&ak(u,pr(q,u.id)))}));for(const u of document.querySelectorAll("[data-rule]"))u.setAttribute("aria-pressed",String(e===u.dataset.rule));K("mining-note").textContent=YE[e];const s=z.roots.filter(u=>u.status==="active"&&$e(q.keys,z,u)),o=K("fund-to"),i=o.value;K("f-fund").hidden=e!=="none"||!s.length||O.beat!==null,o.replaceChildren(...s.map(u=>T("option",{value:u.id,text:u.name}))),o.value=s.some(u=>u.id===i)?i:s.some(u=>u.id===O.holding)?O.holding:((c=s[0])==null?void 0:c.id)??"",K("fund-has").textContent=ce(q.wallet?Nc(q.chain,q.wallet):0),K("holdings-empty").hidden=z.roots.length>0,K("holdings-sub").textContent=z.roots.length?String(z.roots.length):"",K("sample").disabled=z.roots.some(u=>u.name===Ea&&u.status==="active")}function JE(){var r;const e=K("tree-rows"),t=G(O.holding);if(K("tree-sub").textContent=t?`${t.name} · ${O.beat===null?"now":`beat ${O.beat} of ${tt()}`}`:"",!t)return e.replaceChildren(T("p",{class:"wait",text:"No holding yet. Found one, or load the yolopreneur sample."}));if(!Te.nodes.has(t.id))return e.replaceChildren(T("p",{class:"wait",text:`${t.name} is founded at ${mt(t.born)}. Move the slider forward.`}));const n=e.contains(document.activeElement)?document.activeElement.dataset.id:null;e.replaceChildren(...wv(Te,t.id).map(s=>s.type==="group"?T("div",{class:"row grp"},T("span",{class:"g","aria-hidden":"true",text:s.guide}),T("span",{class:"gl",text:s.label})):QE(s))),n&&((r=e.querySelector(`[data-id="${n}"]`))==null||r.focus())}function QE({node:e,guide:t,path:n,away:r}){const s=e.id===O.node,o=["row",s&&"on",e.status==="closed"&&"gone",e.born==="cued"&&"cue"].filter(Boolean).join(" ");return T("div",{class:o},T("button",{type:"button",class:"sel","data-id":e.id,"aria-pressed":String(s),onclick:()=>Hr({node:e.id}),title:r?`${e.name} graduated into a holding of its own`:null},T("span",{class:"g","aria-hidden":"true",text:t}),T("span",{class:"p",text:`${n} `}),T("span",{class:"l",text:e.name})," ",T("span",{class:"v"},ek(e))))}function ek(e){var n;return[e.kind==="agent"&&T("span",{class:"mk",text:"agent"}),e.edge==="adopted"&&T("span",{class:"mk ok",text:"graduated"}),e.charter&&T("span",{class:`mk form${(n=Yr(Te,e))!=null&&n.ok?"":" lapsed"}`,title:Fc(e),text:tk[e.charter.form]}),e.status==="closed"&&T("span",{class:"mk bad",text:"closed"}),e.born==="cued"&&T("span",{class:"mk",text:"cued"}),...e.badges.map(y0),no(e.id)>0&&T("span",{class:"mk sats",title:`${ce(no(e.id))} at its SegWit address`,text:Bc(no(e.id))})].filter(Boolean).flatMap((r,s)=>s?[" ",r]:[r])}const y0=e=>T("span",{class:`belt ${e.belt}`,title:`${e.skill}: ${e.belt} belt`},e.skill,T("span",{class:"sr",text:` (${e.belt} belt)`})),tk={sole:"sole",llc:"llc","series-llc":"series llc",series:"series",corp:"corp"},nk={sole:"Sole proprietor",llc:"LLC","series-llc":"Series LLC",series:"Series",corp:"Corporation"},rk={sole:"a sole proprietor",llc:"an LLC","series-llc":"a series LLC",corp:"a corporation"};function Fc(e,t=Te){var o;const n=e.charter,r=n.master&&G(n.master,t),s=n.form==="series"?(o=r==null?void 0:r.charter)==null?void 0:o.jurisdiction:n.jurisdiction;return[n.form==="series"?`Series of ${(r==null?void 0:r.name)??"?"}`:nk[n.form],s,n.legal,n.provider&&`via ${n.provider}`,`since ${mt(n.beat)}`].filter(Boolean).join(" · ")}function ii(e){var t;for(let n=G(e.parent);n&&n.root===e.root;n=G(n.parent))if(n.status==="active"&&((t=n.charter)==null?void 0:t.form)==="series-llc")return n;return null}function sk(e){var r;const t=e.kind==="org"&&ii(e),n=e.kind==="org"&&e.edge==="derived";return[(e.kind==="holding"||e.kind==="agent")&&["sole","Sole proprietor","a person trading under their own name"],t&&["series",`Series of ${t.name}`,`a cell of ${t.name}'s LLC, chartered by ${t.name}`],!bn(e)&&["llc","LLC",n?`a company of its own, owned through ${(r=G(e.parent))==null?void 0:r.name} while it is derived`:"a company of its own"],!bn(e)&&["series-llc","Series LLC","an LLC that can hold series, one for each venture"],!bn(e)&&["corp","Corporation","a company with shares"]].filter(Boolean)}function b0(e){return sk(e).map(([t,n,r])=>{const s=t==="series"?ii(e):e,o=Zc(q,z,"charter",s.id);return{form:t,label:n,hint:o?`${o}.`:r,off:!!o}})}const ok=e=>{var n;const t=b0(e);return t.some(r=>!r.off)?"":((n=t[0])==null?void 0:n.hint.replace(/\.$/,""))??"No legal form fits"},Ro=()=>{var e;return((e=document.querySelector("#charter-forms input:checked"))==null?void 0:e.value)??null};function ik(e){var i;const t=K("charter-forms"),n=b0(e),r=n.map(a=>`${a.form}=${a.label}=${a.off}`).join("|");if(t.dataset.sig!==r){const a=Ro(),c=n.filter(f=>!f.off),u=c.some(f=>f.form===a)?a:(i=c[0])==null?void 0:i.form;t.dataset.sig=r,t.replaceChildren(T("legend",{class:"lab",text:"Form"}),...n.map(f=>T("label",{class:f.off?"off":null},T("input",{type:"radio",name:"form",value:f.form,checked:f.form===u,disabled:f.off}),` ${f.label} `,T("span",{text:f.hint}))))}const s=Ro()==="series",o=Yr(z,e);K("charter-where").hidden=s,K("charter-now").textContent=e.charter?`Now: ${Fc(e,z)}${o.ok?"":`, lapsed: ${o.why}`}.`:"It has no legal form yet."}const w0=(e,t)=>{for(let n=G(e.parent);n;n=G(n.parent))if(n.id===t.id)return!0;return!1},x0=e=>[...z.nodes.values()].filter(t=>t.id!==e.id&&t.status==="active").map(t=>[t,(t.root===e.root?0:4)+(w0(t,e)?0:2)+(t.kind==="agent"?0:1)]).sort((t,n)=>t[1]-n[1]).map(([t])=>t),v0=e=>e.children.reduce((t,n)=>{const r=G(n);return r&&r.edge==="derived"&&r.status==="active"?t+1+v0(r):t},0);function ak(e,t){const n=async r=>{await ft(s=>_E(s,e.id,r))&&ye(r?`${e.name} mines at hashrate ${r}.`:`${e.name} sits out of mining.`)};return T("span",{class:"rig"},T("span",{class:"rl",text:"hashrate"}),T("span",{class:"rn"},T("button",{type:"button",class:"rb","aria-label":`Lower ${e.name}'s hashrate`,disabled:t<=0,onclick:()=>n(t-1)},"−"),T("b",{text:String(t)}),T("button",{type:"button",class:"rb","aria-label":`Raise ${e.name}'s hashrate`,disabled:t>=9,onclick:()=>n(t+1)},"+")))}const E0=e=>[...z.nodes.values()].filter(t=>t.id!==e.id&&t.status==="active").map(t=>[t,(t.root===e.root?0:4)+(w0(t,e)?0:2)+(t.kind==="agent"?0:1)]).sort((t,n)=>t[1]-n[1]).map(([t])=>t);function ck(e){const t=$e(q.keys,z,e);return t?Cc(q.chain.coins(t.script))[...z.items.values()].map(t=>[t,G(mn.get(t.id))]).filter(([,t])=>t&&t.id!==e.id&&t.status==="active").sort((t,n)=>(t[1].root===e.root?0:1)-(n[1].root===e.root?0:1)).map(([t])=>t);function uk(e){const t=$e(q.keys,z,e);return t?S0(e).length?q.chain.coins(t.script).some(n=>n.value>=de+Le||n.value===de)?"":k0(e,"to pay with"):"Nobody else holds an item yet. Items come from Make":"This holding predates lab keys, so it has no SegWit address to pay from"}function $0(e,t=z){const n=_c(q.keys,t,e);return n&&{taproot:n.taproot.address,segwit:n.segwit.address,nostr:n.npub.address,ethereum:n.ethereum.address}}function fk(e){const t=$0(e),n=e.keyring;if(!t)return"This holding predates lab keys, so it has no keys to list";const r=jc(z,"keyring",e.id);return r||(!n||n.retired||vt.some(s=>n.keys[s]!==t[s])?"":n.beat==="cued"?`${e.name}'s keyring is cued for the next beat`:`${e.name}'s keyring already lists these keys, since beat ${n.beat}`)}function lk(e){const t=G(e.parent),n=e.status==="closed"?`${e.name} is closed`:"",r=(s,o=e.id,i={})=>Zc(q,z,s,o,i);return{birth:n||(bn(e)?"Agents give birth only once they graduate":r("birth")),award:n||(bn(e)?"Agents award belts only once they graduate":x0(e).length?r("award"):"There is nobody else to award yet"),charter:n||ok(e),decide:n||r("decide"),make:n||r("make"),keyring:n||fk(e)||r("keyring"),send:n||ck(e),offer:n||uk(e),graduate:n||(t?e.edge==="adopted"?`${e.name} has already graduated`:t.status!=="active"?`${t.name} is closed`:jc(z,"graduate",t.id,{of:e.id})||r("graduate",t.id,{of:e.id}):"A holding has no parent to graduate from"),close:n||r("close")}}function Os(){const e=G(O.node),t=O.beat!==null;if(K("act-none").hidden=!!e,K("act-past").hidden=!e||!t,K("act-on").hidden=!e||t,K("act-sub").textContent=(e==null?void 0:e.name)??"",K("past-beat").textContent=String(O.beat??""),!e||t)return;const n=lk(e),r=G(e.parent);for(const h of document.querySelectorAll("[data-verb]"))h.setAttribute("aria-pressed",String(h.dataset.verb===O.verb)),h.classList.toggle("off",!!n[h.dataset.verb]);for(const h of document.querySelectorAll("form[data-form]"))h.hidden=h.dataset.form!==O.verb||!!n[O.verb];K("act-why").textContent=n[O.verb]?`${n[O.verb]}.`:"";for(const h of document.querySelectorAll("#act-on [data-name]"))h.textContent=e.name;for(const h of document.querySelectorAll("#act-on [data-parent]"))h.textContent=(r==null?void 0:r.name)??"";const s=h=>h.map(g=>`${g.value}=${g.textContent}`).join("|"),o=[[K("award-to"),x0(e).map(h=>[h.id,`${Tr(z,h.id)}${h.kind==="agent"?" (agent)":""}`])],[K("send-to"),E0(e).map(h=>[h.id,`${Tr(z,h.id)}${h.kind==="agent"?" (agent)":""}`])],[K("offer-item"),S0(e).map(h=>[h.id,`${h.name} · held by ${Tt(mn.get(h.id))}`])]];for(const[h,g]of o){const m=h.value,b=g.map(([w,y])=>T("option",{value:w,text:y}));s(b)!==s([...h.options])&&(h.replaceChildren(...b),b.some(w=>w.value===m)&&(h.value=m))}for(const h of["send-has","offer-has"])K(h).textContent=ce(h0(e.id));K("graduate-go").textContent=`Graduate ${e.name}`,O.verb==="charter"&&!n.charter&&ik(e);const i=O.verb==="keyring"&&!n.keyring&&$0(e);i&&K("keyring-keys").replaceChildren(...[["Taproot",i.taproot],["SegWit",i.segwit],["nostr",i.nostr],["Ethereum",i.ethereum]].map(Or));const a=O.verb==="graduate"?r:O.verb==="charter"&&Ro()==="series"?ii(e):e,c=a&&Ce(q.keys,z,a),u=O.verb==="send"||O.verb==="offer",f=c&&(u?`${c.from} · ${$e(q.keys,z,a).path}`:c.path);K("act-key").textContent=!a||n[O.verb]?"":c?`Signs as ${a.name}: ${f}`:"Signs with the lab wallet: this holding predates lab keys.";const l=O.verb==="graduate"&&Ce(q.keys,z,e)?As(z,e.id).length:0;K("act-gas").textContent=!a||n[O.verb]||!c?"":O.verb==="send"?`Fee: ${de} sats, from ${e.name}'s balance.`:O.verb==="offer"?`Fee: ${de} sats, from ${e.name}'s balance, paid only if the holder accepts.`:`Gas: ${UE(O.verb,l).toLocaleString("en-US")} sats from ${a.name}'s tank (${ce(Nc(q.chain,c.wallet))}), which tops up from its balance.${l?` ${e.name} pays ${de} more, from its own money, to claim its new root.`:""}`;const d=v0(e),p=O.closing===e.id;K("close-note").textContent=d?`Closing ${e.name} spends it for the last time, and its ${Xr(d,"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.`,K("close-go").textContent=p?`Yes, close ${e.name}`:`Close ${e.name}`,K("close-keep").hidden=!p}function _0(){const e=K("inspect-body"),t=O.event?z.log.find(o=>o.id===O.event):null;if(t)return K("inspect-sub").textContent="event",e.replaceChildren(..._k(t));const n=O.tx?Me.ledger.find(o=>o.key===O.tx):null;if(n)return K("inspect-sub").textContent="money",e.replaceChildren(...Ak(n));const r=G(O.node);if(K("inspect-sub").textContent=(r==null?void 0:r.kind)??"",!r)return e.replaceChildren(T("p",{class:"note pad",text:"Select a node in the tree, or an event in the timeline."}));const s=G(O.node,Te);if(!s)return e.replaceChildren(T("p",{class:"note pad",text:`${r.name} is not born yet at beat ${O.beat}.`}));e.replaceChildren(...dk(s))}const Or=([e,t,n])=>T("div",{class:"f"},T("dt",{text:e}),T("dd",{},t,n&&T("span",{class:"fn",text:n})));function dk(e){var r;const t=G(e.parent,Te),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 ${mt(e.graduated)}: it holds its own root`:`derived: ${t.name} holds its seed`],t&&e.root===e.id&&["Holding",T("span",{},"its own, since it graduated",e.id!==O.holding&&T("button",{type:"button",class:"btn sm open",onclick:()=>{Hr({holding:e.id,node:e.id}),mk()}},`Open ${e.name}`))],e.closed!==null&&["Closed",mt(e.closed)],["Charter",e.charter?Fc(e):"none yet",e.charter?Yr(Te,e).ok?e.charter.filing?`Filing SHA-256 ${e.charter.filing.slice(0,16)}…`:"":`Lapsed: ${Yr(Te,e).why}.`:"Charter gives it a legal form: sole proprietor, LLC, series LLC, series or corporation."],((r=e.charter)==null?void 0:r.form)==="series-llc"&&["Series",[...Te.nodes.values()].filter(s=>{var o;return((o=s.charter)==null?void 0:o.master)===e.id}).map(s=>`${s.name}${Yr(Te,s).ok?"":" (lapsed)"}`).join(", ")||"none yet"],["Children",e.children.length?e.children.map(s=>{var o;return(o=G(s,Te))==null?void 0:o.name}).join(", "):"none yet"],$e(q.keys,Te,e)&&["Balance",ce(no(e.id)),`Test BTC at its SegWit address${O.beat===null?"":`, as of beat ${O.beat}`}.`],O.beat===null&&Ce(q.keys,z,e)&&["Gas tank",ce(Nc(q.chain,Ce(q.keys,z,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[T("div",{class:"ih"},T("p",{class:"eyebrow",text:Tr(Te,e.id)}),T("h3",{class:"it",text:e.name}),T("div",{class:"chips"},T("span",{class:"chip",text:e.kind}),T("span",{class:`chip ${e.status==="active"?"ok":"bad"}`,text:e.status}),e.edge==="adopted"&&T("span",{class:"chip ok",text:"graduated"}),e.born==="cued"&&T("span",{class:"chip",text:"cued"}))),T("div",{class:"ib"},T("dl",{class:"fl"},n.map(Or)),e.badges.length>0&&T("div",{},T("p",{class:"lab",text:"Belts"}),T("ul",{class:"list"},e.badges.map(s=>{var o;return T("li",{},y0(s),T("span",{class:"when",text:` from ${((o=G(s.by))==null?void 0:o.name)??"?"}, ${mt(s.beat)}`}))}))),e.decisions.length>0&&T("div",{},T("p",{class:"lab",text:"Decisions"}),T("ul",{class:"list"},e.decisions.map(s=>T("li",{},T("b",{text:s.title}),s.why&&` · ${s.why}`,T("span",{class:"when",text:` (${mt(s.beat)})`}))))),hk(e),yk(e),vk(e))]}function hk(e){const t=(a,c)=>c.length>0&&T("div",{},T("p",{class:"lab",text:a}),T("ul",{class:"list items"},c)),n=(a,c)=>T("li",{},T("b",{text:a.name}),a.note&&` · ${a.note}`,T("span",{class:"when",text:` (${c})`}));if(O.beat!==null)return t("Made",e.made.map(a=>Te.items.get(a)).filter(Boolean).map(a=>n(a,mt(a.beat))));const r=a=>`made${a.maker===e.id?"":` by ${Tt(a.maker)}`}${a.beat==="cued"?", cued":` at beat ${a.beat}`}`,s=[...z.items.values()].filter(a=>mn.get(a.id)===e.id).map(a=>{const c=n(a,r(a)),u=$a().filter(f=>f.item===a.id&&f.seller===e.id&&wa(q,z,f)==="open");return u.length&&c.append(T("ul",{class:"bids"},u.map(f=>T("li",{},T("span",{text:`${Tt(f.buyer)} offers ${f.price?ce(f.price):"nothing, a free claim"}`}),e.status==="active"&&T("button",{type:"button",class:"btn sm","aria-label":`Accept ${Tt(f.buyer)}'s offer for ${a.name}`,onclick:()=>pk(f)},"Accept"))))),c}),o=e.made.map(a=>z.items.get(a)).filter(a=>a&&mn.get(a.id)!==e.id).map(a=>n(a,mn.get(a.id)?`now held by ${Tt(mn.get(a.id))}`:"held outside this lab")),i=$a().filter(a=>a.buyer===e.id&&wa(q,z,a)!=="done").map(a=>{const c=Rc(q,z,a);return T("li",{},T("b",{text:a.price?ce(a.price):"nothing"}),` for ${Bn(a.item)}`,T("span",{class:"when",text:c?` (stale: ${c})`:` (open until ${Tt(a.seller)} accepts)`}),T("button",{type:"button",class:"btn sm","aria-label":`Withdraw the offer for ${Bn(a.item)}`,onclick:()=>gk(a)},"Withdraw"))});return[t("Items",s),t("Made, held elsewhere",o),t("Offers made",i)]}const Tt=e=>{const t=G(e);return t?t.root===O.holding?t.name:Tr(z,e):"?"};async function pk(e){const t=Bn(e.item),n=Tt(e.buyer),r=Tt(e.seller);if(!await ft(o=>{jE(o,e.txid)}))return;const s=Me.ledger.find(o=>o.txid===e.txid);ye(`${r} accepted: ${t} goes to ${n}${e.price?` for ${ce(e.price)}`:", free"}, ${s!=null&&s.beat?`at beat ${s.beat}`:"cued for the next beat"}.`)}async function gk(e){const t=Bn(e.item),n=Tt(e.buyer);await ft(r=>{KE(r,e.txid)})&&ye(`${n} withdrew its offer for ${t}.`)}function mk(){const e=document.querySelector(".tree-blk").getBoundingClientRect().top+scrollY-document.querySelector(".clock").offsetHeight-12;e(n.to===e.id||n.from===e.id)&&(O.beat===null||n.beat!==null&&n.beat<=O.beat)).slice(-6).reverse();return t.length>0&&T("div",{},T("p",{class:"lab",text:"Money"}),T("ul",{class:"list"},t.map(n=>T("li",{},T("b",{text:bk(n,e.id)}),T("span",{class:"when",text:` (${mt(n.beat??"cued")})`})))))}function bk(e,t){const n=r=>{var s;return((s=G(r))==null?void 0:s.name)??"?"};if(e.kind==="mine")return`+${ce(e.amount)}, a beat's reward`;if(e.kind==="move")return`${ce(e.amount)} moved to its new key, after a ${e.fee}-sat fee`;if(e.kind==="gas")return`−${ce(e.amount)} into its gas tank, and a ${e.fee}-sat fee`;if(e.kind==="fund")return`+${ce(e.amount)} from the lab wallet`;if(e.kind==="deal"){const r=Bn(e.item);return e.to===t?e.amount?`+${ce(e.amount)} from ${n(e.from)} for ${r}`:`${r} to ${n(e.from)}, free`:e.amount?`−${ce(e.amount)} to ${n(e.to)} for ${r}, and a ${e.fee}-sat fee`:`${r} from ${n(e.to)}, free but for a ${e.fee}-sat fee`}return e.to===t?`+${ce(e.amount)} from ${n(e.from)}`:`−${ce(e.amount)} to ${n(e.to)}, and a ${e.fee}-sat fee`}function A0(e){const t=n=>{const r=G(n);return r?r.root===O.holding?r.name:Tr(z,n):"?"};return e.kind==="mine"?`${ce(e.amount)} → ${t(e.to)}`:e.kind==="move"?`${ce(e.amount)} → ${t(e.to)}'s new key`:e.kind==="gas"?`${ce(e.amount)} → ${t(e.to)}'s gas tank`:e.kind==="fund"?`${ce(e.amount)} lab wallet → ${t(e.to)}`:e.kind==="deal"?`${Bn(e.item)} ${t(e.to)} → ${t(e.from)}, ${e.amount?`for ${ce(e.amount)}`:"free"}`:`${ce(e.amount)} ${t(e.from)} → ${t(e.to)}`}const wk={own:"its own key",lab:"the lab wallet",parent:"its parent's key (its handoff is cued)",other:"a key outside this lab"},xk={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 vk(e){const t=Ce(q.keys,Te,e),n=Ac(q,z,e.id),r=["Held now by",n?wk[n.who]:"nobody: its inscription has been spent"];if(!t)return T("div",{class:"keys"},T("p",{class:"lab",text:"Keys"}),T("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(Or)));const s=e.kind==="agent",o=_c(q.keys,Te,e),i=uE(q.keys,Te,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.`],["Ethereum",o.ethereum.address,s&&e.edge!=="adopted"?`BIP-44 at ${o.ethereum.path}: account ${t.account} of its org's seed, the way Ledger Live numbers Ethereum accounts.`:`BIP-44 at ${o.ethereum.path}. Its legal-control key, the one that holds the entity NFT, as on the lineage key tree page.`],["From",`${t.from} · account ${t.account}`],r,Ek(e)];return T("div",{class:"keys"},T("p",{class:"lab",text:"Keys"}),T("dl",{class:"fl"},l.map(Or)),e.keyring&&gr(`${e.keyring.retired?"Retired keyring":"Keyring"} · what each key signed`,Yo(e.id,e.keyring.keys)),T("p",{class:"lab"},"Leaves",T("span",{text:` · HKDF-SHA256 from its ${s?"nostr secret":"seed"}`})),T("ul",{class:"list leaves"},i.map(([d,p])=>T("li",{},T("b",{text:d}),T("span",{class:"when",text:` ${xk[d]}`}),T("code",{text:p})))),gr(s?"Public lines to paste":"CA key for TrustedUserCAKeys",a.join(` + +`)),Sk(e,t))}function Ek(e){var r;const t=e.keyring,n=(t==null?void 0:t.retired)&&(t.retired.by===e.id?"It":((r=G(t.retired.by,Te))==null?void 0:r.name)??"Its parent");return t?t.retired?["Keyring",`retired at ${mt(t.retired.beat)}`,t.retired.cause==="close"?`${n} closed, which freed the keys it listed.`:n==="It"?"It graduated, so its keys changed with its new root. Keyring publishes a new one.":`${n} graduated, so ${e.name}'s keys changed with ${n}'s new root. Keyring publishes a new one.`]:["Keyring",`published at ${mt(t.beat)}`,"Each key signed it: Taproot and SegWit by BIP-322, the npub as a nostr event, Ethereum by EIP-191."]:["Keyring","none yet","Keyring publishes one: an inscription that lists these keys, each key signing it."]}function gr(e,t,n=t){const r=T("pre",{text:n}),s=T("button",{type:"button",class:"cp","aria-label":`Copy ${e}`,onclick:()=>kk(t,s,r)},"Copy");return T("div",{class:"code"},T("div",{class:"code-h cph"},T("span",{text:e}),s),r)}async function kk(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 Sk(e,t){var a;const n=O.reveal===e.id,r=n&&pE(q.keys,Te,e),s=G(e.parent,Te),o=()=>{var c;O.reveal=n?null:e.id,_0(),(c=K("reveal"))==null||c.focus()},i=(a=r==null?void 0:r.seed)==null?void 0:a.mnemonic.split(" ");return T("div",{class:"secret"},T("div",{class:"hz"},T("span",{class:"hz-l",text:"Secret · stays in this tab"}),T("button",{type:"button",class:"btn sm",id:"reveal","aria-expanded":String(n),onclick:o},n?"Hide":"Reveal")),r&&T("div",{class:"sb"},r.seed?gr(`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(` +`)):T("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])=>gr(`${c} · ${u}`,f)),r.leaves.map(([c,u,f])=>gr(`${c} · ${u}`,f))))}function $k(e){var i,a,c;const t=(a=(i=q.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=rc(t).pubkey,r=G(e.parent),s=e.op==="found"?G(e.node):null,o=[[s&&Ce(q.keys,z,s),`${s==null?void 0:s.name}'s root`],[r&&Ce(q.keys,z,r),`${r==null?void 0:r.name}'s key`],[(r==null?void 0:r.edge)==="adopted"&&Ce(q.keys,z,{...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=q.wallet)==null?void 0:c.pubkey)===n?"the lab wallet":`a key outside this lab (${n.slice(0,12)}…)`}function _k(e){var o,i,a;const t=No.events.find(c=>c.id===e.id),n=(i=(o=q.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=G(e.parent))==null?void 0:a.name)??"an unknown inscription"}, whose inscription this event spent`:"nothing: a founding has no parent"],["Signed by",$k(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[T("div",{class:"ih"},T("p",{class:"eyebrow",text:`${e.op} · ${e.pending?"cued":`beat ${e.beat}`}`}),T("h3",{class:"it",text:Oh(e,z)}),T("div",{class:"chips"},T("span",{class:"chip",text:(t==null?void 0:t.protocol)??"?"}),T("span",{class:`chip ${e.ok?"ok":"bad"}`,text:e.ok?"applied":"rejected"})),!e.ok&&T("p",{class:"idesc",text:"The reducer rejected this event. It stays on the chain, but it does not change the tree."})),T("div",{class:"ib"},T("dl",{class:"fl"},r.map(Or)),T("div",{class:"code"},T("p",{class:"code-h",text:"Metadata · CBOR, tag 5"}),T("pre",{text:cf(e.meta)})),s&&T("div",{class:"code"},T("p",{class:"code-h",text:"Raw index entry"}),T("pre",{text:cf(s)})))]}function Ak(e){const t=i=>{var a;return((a=G(i))==null?void 0:a.name)??"a key outside this lab"},n=q.chain.transactions.get(e.txid),r=e.kind==="deal",s=e.kind==="fund",o=[["When",e.beat===null?"cued for the next beat":`beat ${e.beat}`],r&&["Item",`${Bn(e.item)}, an inscription: from ${t(e.to)}'s Taproot key to ${t(e.from)}'s`],["From",e.kind==="mine"?"its share of the beat's block reward (the coinbase)":s?"the lab wallet, standing in for a wallet you already have":`${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`:r&&!e.amount?"nobody: a free claim pays no price":`${t(e.to)}'s ${e.kind==="move"?"new ":""}SegWit address`],[r?"Price":"Amount",r&&!e.amount?"nothing":ce(e.amount)],e.kind!=="mine"&&["Fee",`${e.fee} sats, retired: this toy chain pays no fees to miners`],e.change>0&&["Change",`${ce(e.change)} back to ${s?"the lab wallet":t(e.from)}`],["Signed by",e.kind==="mine"?"nobody: a coinbase spends nothing":s?"the lab wallet's Taproot key":r?`${t(e.from)}'s SegWit key (SIGHASH_ALL) when it made the offer, then ${t(e.to)}'s Taproot key when it accepted`:`${t(e.from)}'s SegWit key (BIP-143, SIGHASH_ALL)`],["Transaction",e.txid]].filter(Boolean);return[T("div",{class:"ih"},T("p",{class:"eyebrow",text:`${e.kind} · ${e.beat===null?"cued":`beat ${e.beat}`}`}),T("h3",{class:"it",text:A0(e)}),T("div",{class:"chips"},T("span",{class:"chip",text:"test BTC"}),T("span",{class:`chip${e.beat===null?"":" ok"}`,text:e.beat===null?"cued":"confirmed"}))),T("div",{class:"ib"},T("dl",{class:"fl"},o.map(Or)),n&&gr("Raw transaction",n.raw))]}function Wc(){const e=tt(),t=K("beat"),n=G(O.holding);t.max=String(e),t.value=String(O.beat??e),t.disabled=e===0,K("beat-label").textContent=O.beat===null?`Now · beat ${e}`:`Beat ${O.beat} of ${e}`,K("replay").textContent=O.replay?"Stop":"Replay",K("replay").disabled=!n||e===0,K("to-now").disabled=O.beat===null,K("timeline-sub").textContent=(n==null?void 0:n.name)??"";const r=new Map,s=new Map([...q.chain.transactions.keys()].map((a,c)=>[a,c])),o=(a,c)=>r.set(a,[...r.get(a)??[],c]);for(const a of z.log)a.roots.includes(O.holding)&&o(a.pending?"cued":a.beat,{e:a,at:s.get(a.id.slice(0,-2))??0});for(const a of Me.ledger)[a.to,a.from].some(c=>{var u;return c&&((u=G(c))==null?void 0:u.root)===O.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 K("timeline-list").replaceChildren(T("li",{class:"wait",text:n?"Nothing yet.":"Found a holding to start its timeline."}));K("timeline-list").replaceChildren(...i.map(a=>{const c=a==="cued"?null:q.chain.blocks[a-1],u=O.beat!==null&&(a==="cued"||a>O.beat),f=O.beat!==null&&a===O.beat;return T("li",{class:`beat${u?" later":""}${f?" now":""}`},T("p",{class:"bh"},T("span",{class:"bn",text:a==="cued"?"Cued":`Beat ${a}`}),T("span",{class:"bt",text:c?VE(c.time):q.clock.tempo==="manual"?"waiting for Beat now":"landing on the next beat"})),T("ol",{class:"evs"},r.get(a).sort((l,d)=>l.at-d.at).map(({e:l,m:d})=>d?Tk(d):Bk(l))))}))}function Bk(e){const[t,...n]=Oh(e,z).split(" ");return T("li",{},T("button",{type:"button",class:`ev${e.ok?"":" bad"}${e.id===O.event?" on":""}`,"aria-pressed":String(e.id===O.event),onclick:()=>Hr({event:e.id,node:e.node??O.node})},T("span",{class:"op",text:e.ok?t:`✕ ${t.replace(/:$/,"")}`})," ",T("span",{class:"es",text:n.join(" ")})))}const Tk=e=>T("li",{},T("button",{type:"button",class:`ev money${e.kind==="gas"?" gas":""}${e.kind==="deal"?" deal":""}${e.key===O.tx?" on":""}`,"aria-pressed":String(e.key===O.tx),onclick:()=>{var t;return Hr({tx:e.key,node:((t=G(e.to))==null?void 0:t.root)===O.holding?e.to:O.node})}},T("span",{class:"op",text:e.kind})," ",T("span",{class:"es",text:A0(e)})));K("f-found").addEventListener("submit",async e=>{e.preventDefault();const t=e.currentTarget,n=_s(t.elements.name.value);if(!n)return ye("Name the holding: lowercase letters, digits and hyphens.",!0);await Ut("found",null,{name:n},(r,s)=>(qc({holding:r,node:r}),`${n} is founded, ${s}.`))&&t.reset()});K("sample").addEventListener("click",async()=>{let e=null;ye("Rehearsing the yolopreneur tree over six beats…"),await ft(t=>{e=ZE(t)})&&(Hr({holding:e,node:e}),ye("Loaded the yolopreneur sample: six beats of history, ending on lineage's open offer for sol's launch-kit. Press Replay to watch it grow."))});K("f-birth").addEventListener("submit",async e=>{e.preventDefault();const t=e.currentTarget,n=G(O.node),r=_s(t.elements.name.value),s=t.elements.kind.value;if(!r)return ye("Name the child: lowercase letters, digits and hyphens.",!0);await Ut("birth",n.id,{name:r,kind:s},(o,i)=>`${r} is born to ${n.name}, ${i}.`)&&(t.elements.name.value="")});K("f-award").addEventListener("submit",async e=>{e.preventDefault();const t=e.currentTarget,n=G(O.node),r=t.elements.to.value,s=_s(t.elements.skill.value),o=t.elements.belt.value;if(!s)return ye("Name the skill, for example launch.",!0);await Ut("award",n.id,{to:r,skill:s,belt:o},(i,a)=>{var c;return`${(c=G(r))==null?void 0:c.name} holds a ${o} belt in ${s}, ${a}.`})&&(t.elements.skill.value="")});K("f-decide").addEventListener("submit",async e=>{e.preventDefault();const t=e.currentTarget,n=G(O.node),r=t.elements.title.value.trim(),s=t.elements.why.value.trim();if(!r)return ye("A decision needs a title.",!0);await Ut("decide",n.id,{title:r,why:s},(o,i)=>`${n.name} decided “${r}”, ${i}.`)&&t.reset()});K("f-send").addEventListener("submit",async e=>{var a;e.preventDefault();const t=e.currentTarget,n=G(O.node),r=t.elements.to.value,s=Tc(t.elements.amount.value);if(s===null)return ye("Write an amount in test BTC, for example 1.5 (at most eight decimals).",!0);let o=null;if(!await ft(c=>{o=RE(c,n.id,r,s)}))return;const i=Me.ledger.find(c=>c.txid===o);ye(`${n.name} sent ${ce(s)} to ${((a=G(r))==null?void 0:a.root)===n.root?G(r).name:Tr(z,r)}, ${i!=null&&i.beat?`at beat ${i.beat}`:"cued for the next beat"}.`),t.elements.amount.value=""});K("f-make").addEventListener("submit",async e=>{e.preventDefault();const t=e.currentTarget,n=G(O.node),r=_s(t.elements.name.value),s=t.elements.note.value.trim();if(!r)return ye("Name the item: lowercase letters, digits and hyphens.",!0);await Ut("make",n.id,{name:r,note:s},(o,i)=>`${n.name} made ${r}, ${i}.`)&&t.reset()});K("f-charter").addEventListener("change",e=>{e.target.name==="form"&&Os()});K("charter-file").addEventListener("change",async e=>{var r;const t=(r=e.target.files)==null?void 0:r[0];if(!t)return;const n=new Uint8Array(await crypto.subtle.digest("SHA-256",await t.arrayBuffer()));K("charter-filing").value=[...n].map(s=>s.toString(16).padStart(2,"0")).join(""),e.target.value="",ye(`Hashed ${t.name} in this tab: only its SHA-256 would go on chain.`)});K("f-charter").addEventListener("submit",async e=>{e.preventDefault();const t=e.currentTarget,n=G(O.node),r=Ro();if(!r)return ye("Pick a legal form.",!0);if(r==="series"){const a=ii(n);await Ut("charter",a.id,{form:"series",of:n.id},(c,u)=>`${n.name} is a series of ${a.name}, ${u}.`);return}const s=a=>t.querySelector(`[name="${a}"]`).value.trim(),o={form:r,jurisdiction:s("jurisdiction").toUpperCase(),legal:s("legal"),provider:_s(s("provider")),filing:s("filing").toLowerCase()},i=(a,c)=>`${n.name} is chartered as ${rk[r]}${o.jurisdiction?` in ${o.jurisdiction}`:""}, ${c}.`;if(await Ut("charter",n.id,o,i))for(const a of["legal","filing"])t.querySelector(`[name="${a}"]`).value=""});K("f-keyring").addEventListener("submit",async e=>{e.preventDefault();const t=G(O.node);await Ut("keyring",t.id,{},(n,r)=>`${t.name} published its keyring, ${r}: four keys, each signing the same statement.`)});K("f-offer").addEventListener("submit",async e=>{e.preventDefault();const t=e.currentTarget,n=G(O.node),r=K("offer-item").value,s=Tc(t.elements.price.value);if(s===null)return ye("Write a price in test BTC, for example 0.1, or 0 for a free claim.",!0);const o=Tt(mn.get(r)),i=Bn(r);await ft(a=>{HE(a,r,n.id,s)})&&(ye(`${n.name} offers ${s?ce(s):"nothing"} for ${i}. The offer stands until ${o} accepts it.`),t.elements.price.value="")});K("send-max").addEventListener("click",()=>{const e=G(O.node),t=e&&$e(q.keys,z,e);t&&(K("send-amount").value=Vh(Cc(q.chain.coins(t.script))))});K("f-graduate").addEventListener("submit",async e=>{e.preventDefault();const t=G(O.node),n=G(t.parent);await Ut("graduate",n.id,{of:t.id},(r,s)=>(qc({node:t.id}),`${t.name} graduates from ${n.name}, ${s}. It's a holding of its own now.`))});K("f-close").addEventListener("submit",async e=>{e.preventDefault();const t=G(O.node);if(O.closing!==t.id)return O.closing=t.id,Os(),K("close-go").focus();O.closing=null,await Ut("close",t.id,{},(n,r)=>`${t.name} is closed, ${r}.`)});K("close-keep").addEventListener("click",()=>{O.closing=null,Os(),K("close-go").focus()});for(const e of document.querySelectorAll("[data-verb]"))e.addEventListener("click",()=>{O.verb=e.dataset.verb,O.closing=null,Os()});for(const e of document.querySelectorAll("[data-rule]"))e.addEventListener("click",async()=>{const t=e.dataset.rule;await ft(n=>AE(n,t))&&ye({split:"Each beat splits across the holdings that mine, by hashrate.",last:"Each beat goes whole to the holding that acts.",none:"Mainnet: no holding mines. Beats pay the lab wallet, and you fund holdings from it."}[t])});K("f-fund").addEventListener("submit",async e=>{var i;e.preventDefault();const t=e.currentTarget,n=t.elements.to.value,r=Tc(t.elements.amount.value);if(r===null)return ye("Write an amount in test BTC, for example 5 (at most eight decimals).",!0);let s=null;if(!await ft(a=>{s=DE(a,n,r)}))return;const o=Me.ledger.find(a=>a.txid===s);ye(`The lab wallet funded ${(i=G(n))==null?void 0:i.name} with ${ce(r)}, ${o!=null&&o.beat?`at beat ${o.beat}`:"cued for the next beat"}.`),t.elements.amount.value=""});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 ft(r=>IE(r,n,Date.now(),si(r,Vc(r)??O.holding)))&&ye(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.`)});K("beat-now").addEventListener("click",()=>g0(e=>{Et(e,si(e,Vc(e)??O.holding))}));setInterval(()=>{m0();const{tempo:e,nextAt:t}=q.clock;O.busy||document.hidden||typeof e!="number"||!q.chain.mempool.length||t&&Date.now()OE(n,Date.now(),si(n,Vc(n)??O.holding)))},1e3);addEventListener("storage",e=>{(e.key===ni||e.key===null)&&p0()});function Cs(){O.replay&&(clearInterval(O.replay),O.replay=null,Wc())}function Ik(){const e=G(O.holding);if(!(!e||!tt())){if(Lo(typeof e.born=="number"?e.born:tt()),O.beat===null)return ye("Nothing to replay yet: this holding has one beat of history.");O.replay=setInterval(()=>{(O.beat===null||O.beat+1>=tt())&&Cs(),Lo(O.beat===null?tt():O.beat+1)},800),Wc()}}K("beat").addEventListener("input",e=>{Cs(),Lo(Number(e.target.value))});K("replay").addEventListener("click",()=>O.replay?Cs():Ik());for(const e of["to-now","past-now"])K(e).addEventListener("click",()=>{Cs(),Lo(tt())});const Ki=["system","light","dark"],B0=()=>{K("theme").textContent=`Theme: ${document.documentElement.dataset.theme??"system"}`};K("theme").addEventListener("click",()=>{const e=Ki[(Ki.indexOf(document.documentElement.dataset.theme??"system")+1)%Ki.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{}B0()});function T0(e,t,n){const r=K("confirm");r.replaceChildren(T("span",{text:e}),T("button",{type:"button",class:"btn sm danger",text:t,onclick:()=>{r.hidden=!0,n()}}),T("button",{type:"button",class:"btn sm",text:"Cancel",onclick:()=>{r.hidden=!0}})),r.hidden=!1,r.querySelector("button").focus()}const Ok={read:()=>{try{return Hc()}catch{return Is()}}};async function I0(e,t){Cs(),await ft(n=>{Object.assign(n,e())},Ok)&&(Object.assign(O,{holding:null,node:null,event:null,tx:null,beat:null,closing:null}),zc(),ye(t))}K("save").addEventListener("click",()=>{const e=T("a",{href:URL.createObjectURL(new Blob([i0(q)],{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),ye("Saved a backup of this lab, test wallet included. Load it in any browser to carry on.")});K("load").addEventListener("click",()=>K("load-file").click());K("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=o0(await t.text())}catch(s){return ye(`${t.name} is not an Orgchain lab: ${s.message}`,!0)}T0(`Replace this browser's lab with ${t.name}?`,"Replace",()=>I0(()=>n,`Loaded ${t.name}.`))});K("reset").addEventListener("click",()=>T0("Erase this browser's lab: every holding, the chain and the test wallet?","Erase",()=>I0(Is,"Erased. This is a fresh lab.")));B0();p0(); diff --git a/ventures/lineage/orgchain/assets/index-C1PA9bil.css b/ventures/lineage/orgchain/assets/index-DwOZaPY4.css similarity index 96% rename from ventures/lineage/orgchain/assets/index-C1PA9bil.css rename to ventures/lineage/orgchain/assets/index-DwOZaPY4.css index aa5b09e..bc64c74 100644 --- a/ventures/lineage/orgchain/assets/index-C1PA9bil.css +++ b/ventures/lineage/orgchain/assets/index-DwOZaPY4.css @@ -1 +1 @@ -:root{--concrete: #e4e3dd;--slab: #f6f5f1;--ink: #141414;--ink-2: #4a4944;--ink-3: #66655f;--signal: #ffc21a;--on-signal: #141414;--ok: #1d7a3a;--danger: #b3261e;--focus: #2346ff;--band: #141414;--band-fg: #f6f5f1;--band-muted: #b0afa8;--shadow: #141414;--mono: ui-monospace, "SF Mono", "Cascadia Mono", "JetBrains Mono", Menlo, Consolas, "Liberation Mono", "DejaVu Sans Mono", monospace;--display: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;--t-xs: .75rem;--t-s: .8125rem;--t-m: .9375rem;--t-l: 1.25rem;--gutter: max(16px, env(safe-area-inset-left, 0px));color-scheme:light}@media(prefers-color-scheme:dark){:root:not([data-theme=light]){--concrete: #151514;--slab: #1e1e1c;--ink: #ecebe4;--ink-2: #b9b8b0;--ink-3: #94938b;--ok: #62c784;--danger: #ff8a7f;--focus: #93a8ff;--band: #0b0b0a;--band-fg: #ecebe4;--band-muted: #9d9c95;--shadow: #4d4c47;color-scheme:dark}}:root[data-theme=dark]{--concrete: #151514;--slab: #1e1e1c;--ink: #ecebe4;--ink-2: #b9b8b0;--ink-3: #94938b;--ok: #62c784;--danger: #ff8a7f;--focus: #93a8ff;--band: #0b0b0a;--band-fg: #ecebe4;--band-muted: #9d9c95;--shadow: #4d4c47;color-scheme:dark}*{box-sizing:border-box}[hidden]{display:none!important}html{-webkit-text-size-adjust:100%}body{margin:0;background:var(--concrete);color:var(--ink);font:400 var(--t-m)/1.5 var(--mono)}body.busy{cursor:progress}::selection{background:var(--signal);color:var(--on-signal)}button,select,input,textarea{font:inherit;color:inherit}:focus-visible{outline:3px solid var(--focus);outline-offset:2px}a{color:inherit;text-decoration-thickness:2px;text-underline-offset:3px}b{font-weight:700}.band{background:var(--band);color:var(--band-fg);border-bottom:3px solid var(--ink)}.band-in{max-width:1320px;margin:0 auto;padding:16px var(--gutter) 14px;display:flex;flex-wrap:wrap;gap:14px 32px;align-items:flex-end;justify-content:space-between}.kicker{margin:0 0 8px;font:700 var(--t-xs)/1 var(--mono);letter-spacing:.12em;text-transform:uppercase;color:var(--band-muted)}.kicker a{color:var(--band-fg)}.wordmark{margin:0;font:900 clamp(2.25rem,6vw,3.5rem)/.84 var(--display);letter-spacing:-.05em;text-transform:uppercase}.lede{margin:10px 0 0;color:var(--band-muted);font-size:var(--t-s);max-width:88ch}.lede b{color:var(--band-fg)}.flags{display:flex;flex-wrap:wrap;gap:8px;align-items:center}.flag{font:700 var(--t-xs)/1 var(--mono);letter-spacing:.1em;text-transform:uppercase;padding:7px 9px 6px;border:2px solid var(--band-fg);background:transparent;color:var(--band-fg);border-radius:0}.flag.hz{background:var(--signal);border-color:var(--signal);color:var(--on-signal)}button.flag{cursor:pointer}button.flag:hover{background:var(--band-fg);color:var(--band)}.clock{background:var(--slab);border-bottom:3px solid var(--ink);position:sticky;top:0;z-index:5}.clock-in{max-width:1320px;margin:0 auto;padding:10px var(--gutter);display:flex;flex-wrap:wrap;gap:10px 18px;align-items:center}.tempo{display:flex;flex-wrap:wrap;align-items:center}.tempo .lab{margin:0 10px 0 0}.seg{font:700 var(--t-xs)/1 var(--mono);letter-spacing:.06em;text-transform:uppercase;padding:9px 10px 8px;border:2px solid var(--ink);background:var(--slab);color:var(--ink);cursor:pointer;border-radius:0;margin-left:-2px}.seg:first-of-type{margin-left:0}.seg:hover:not([aria-pressed=true]){background:var(--concrete)}.seg[aria-pressed=true]{background:var(--ink);color:var(--slab)}.seg:focus-visible{position:relative;z-index:1}.beatno{margin:0;flex:1 1 22ch;font-size:var(--t-s);color:var(--ink-2)}.beatno b{color:var(--ink);font-size:var(--t-m)}.say{max-width:1320px;margin:0 auto;padding:0 var(--gutter) 10px;font-size:var(--t-s);color:var(--ink-2)}.say:empty{display:none}.say.bad{color:var(--danger);font-weight:700}.wrap{max-width:1320px;margin:0 auto;padding:32px var(--gutter) 56px;display:grid;gap:40px}.work{display:grid;gap:36px 28px;align-items:start;grid-template-columns:minmax(0,250px) minmax(0,1fr) minmax(0,390px);grid-template-areas:"hold tree side" "hold time side";grid-template-rows:auto 1fr}.hold-blk{grid-area:hold}.tree-blk{grid-area:tree}.time-blk{grid-area:time}.side{grid-area:side;display:grid;gap:36px;min-width:0}.blk{display:flex;flex-direction:column;align-items:flex-start;min-width:0}.blk>.panel{align-self:stretch}.tab{margin:0;background:var(--ink);color:var(--slab);font:700 var(--t-xs)/1 var(--mono);letter-spacing:.14em;text-transform:uppercase;padding:8px 11px 7px;display:flex;gap:12px;max-width:100%}.tab .sub{font-weight:400;letter-spacing:.06em;text-transform:none;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}.tab .sub:empty{display:none}.panel{background:var(--slab);border:3px solid var(--ink);box-shadow:8px 8px 0 var(--shadow);min-width:0}.pad{padding:16px 18px}.lab{display:block;font:700 var(--t-xs)/1.2 var(--mono);letter-spacing:.1em;text-transform:uppercase;color:var(--ink-2)}.lab span{font-weight:400;letter-spacing:.04em;text-transform:none}.note{margin:0;font-size:var(--t-s);color:var(--ink-2)}.note p{margin:0 0 12px}.wait{margin:0;padding:4px 16px;color:var(--ink-3);font-size:var(--t-s)}.hint{margin:8px 0 0;font-size:var(--t-xs);color:var(--ink-2)}input:not([type]),input[type=text],select,textarea{width:100%;padding:8px 10px;border:2px solid var(--ink);border-radius:0;background:var(--concrete);min-width:0}textarea{resize:vertical;line-height:1.5}.line{display:flex;flex-wrap:wrap;gap:10px;align-items:stretch}.line input{flex:1 1 12ch;width:auto}.btn{font:700 var(--t-s)/1 var(--mono);letter-spacing:.06em;text-transform:uppercase;padding:10px 12px 9px;background:var(--slab);color:var(--ink);border:2px solid var(--ink);box-shadow:3px 3px 0 var(--shadow);cursor:pointer;border-radius:0}.btn:hover{background:var(--concrete)}.btn:active{transform:translate(3px,3px);box-shadow:none}.btn.primary{background:var(--signal);color:var(--on-signal);border-color:var(--ink)}.btn.danger{background:var(--danger);color:var(--slab)}.btn.sm{font-size:var(--t-xs);padding:7px 9px 6px;box-shadow:2px 2px 0 var(--shadow)}.btn.sm:active{transform:translate(2px,2px)}.btn:disabled,.seg:disabled{cursor:not-allowed;background:var(--concrete);color:var(--ink-3);border-color:var(--ink-3);box-shadow:none;transform:none}.holds{list-style:none;margin:0;padding:0}.holds li+li{border-top:2px solid var(--ink)}.hold{width:100%;display:grid;gap:3px;text-align:left;background:transparent;border:0;padding:12px 18px;cursor:pointer;border-radius:0}.hold:hover .hn{text-decoration:underline;text-underline-offset:3px}.hn{font-weight:700;overflow-wrap:anywhere}.hm{font-size:var(--t-xs);color:var(--ink-2)}.hold.on{background:var(--signal)}.hold.on .hn,.hold.on .hm{color:var(--on-signal)}.hold.gone .hn{text-decoration:line-through;text-decoration-thickness:2px}.holds:not(:empty)~.found{border-top:3px solid var(--ink)}.empty p{margin:0;font-size:var(--t-s);color:var(--ink-2)}.found .lab{margin-bottom:8px}.sample{border-top:2px dashed var(--ink-3)}.tree{padding:12px 0;font-size:.875rem;overflow-x:auto}.row{display:flex;align-items:stretch;min-width:max-content}.sel{flex:1;display:flex;align-items:baseline;text-align:left;background:transparent;border:0;padding:4px 14px 4px 16px;cursor:pointer;line-height:1.55;border-radius:0}.sel:hover .l{text-decoration:underline;text-underline-offset:3px}.g{white-space:pre;color:var(--ink-3);flex:none}.p{white-space:pre;font-weight:700;flex:none}.l{flex:none;color:var(--ink);font-weight:700;white-space:nowrap}.v{flex:1 0 auto;display:flex;gap:5px;justify-content:flex-end;align-items:center;margin-left:2ch}.grp{padding:0 14px 0 16px;line-height:1.55;color:var(--ink-3)}.gl{color:var(--ink-2)}.row.on .sel{background:var(--signal)}.row.on .g,.row.on .p,.row.on .l,.row.on .mk,.row.on .belt{color:var(--on-signal);border-color:var(--on-signal)}.row.gone .l,.row.gone .p{text-decoration:line-through;text-decoration-thickness:2px}.row.gone .l{color:var(--ink-2)}.row.cue .l{font-weight:400;font-style:italic}.mk{font:700 .6875rem/1 var(--mono);letter-spacing:.06em;text-transform:uppercase;padding:3px 5px 2px;border:2px solid currentColor;color:var(--ink-2);white-space:nowrap}.mk.ok{color:var(--ok)}.mk.bad{color:var(--danger)}.belt{display:inline-flex;align-items:center;gap:5px;font:700 .6875rem/1 var(--mono);padding:2px 5px 2px 3px;border:2px solid var(--ink);color:var(--ink);white-space:nowrap}.belt:before{content:"";width:10px;height:10px;flex:none;border:1.5px solid currentColor;background:#f6f5f1}.belt.green:before{background:#1d7a3a}.belt.black:before{background:#141414}.verbs{display:flex;flex-wrap:wrap;border-bottom:3px solid var(--ink)}.verbs button{flex:1 1 auto;font:700 var(--t-s)/1 var(--mono);padding:12px 10px;background:transparent;border:0;border-right:2px solid var(--ink);color:var(--ink-2);cursor:pointer;border-radius:0}.verbs button:last-child{border-right:0}.verbs button.off{color:var(--ink-3)}.verbs button:hover:not([aria-pressed=true]){color:var(--ink);text-decoration:underline;text-underline-offset:3px}.verbs button[aria-pressed=true]{background:var(--ink);color:var(--slab)}.why{margin:0;font-size:var(--t-s);color:var(--ink-2)}.keyline{margin:0;padding:10px 18px;font-size:var(--t-xs);color:var(--ink-2);overflow-wrap:anywhere;border-bottom:1px dashed var(--ink-3)}.keyline:empty{display:none}.why:empty{display:none}.vf{display:grid;gap:6px}.vf .lab{margin-top:8px}.vh{margin:0;font-size:var(--t-s);color:var(--ink-2)}.vh b{color:var(--ink)}.vf .go,.vf .line{margin-top:12px}.vf>.go{justify-self:start}.vf .line .go{margin-top:0}.kinds{border:0;margin:0;padding:0;display:grid;gap:6px;min-width:0}.kinds legend{padding:0;margin:8px 0 6px}.kinds label{display:flex;gap:8px;align-items:baseline;cursor:pointer;font-weight:700}.kinds label span{font-weight:400;font-size:var(--t-s);color:var(--ink-2)}.kinds input{accent-color:var(--ink);margin:0}.ih{padding:16px 18px 14px;border-bottom:3px solid var(--ink)}.eyebrow{margin:0 0 8px;font:700 var(--t-xs)/1.3 var(--mono);letter-spacing:.12em;text-transform:uppercase;color:var(--ink-2);overflow-wrap:anywhere}.it{margin:0;font:700 var(--t-l)/1.25 var(--mono);overflow-wrap:anywhere}.idesc{margin:10px 0 0;color:var(--ink-2);font-size:var(--t-s)}.chips{display:flex;flex-wrap:wrap;gap:6px;margin-top:12px}.chip{font:700 var(--t-xs)/1 var(--mono);letter-spacing:.08em;text-transform:uppercase;padding:5px 7px 4px;border:2px solid currentColor}.chip.ok{color:var(--ok)}.chip.bad{color:var(--danger)}.ib{padding:4px 18px 18px;display:grid;gap:16px}.fl{margin:0;display:grid}.f{display:grid;gap:4px;padding-top:12px;margin-top:12px;border-top:1px dashed var(--ink-3)}.f:first-child{border-top:0}.f dt{font:700 var(--t-xs)/1.2 var(--mono);letter-spacing:.1em;text-transform:uppercase;color:var(--ink-2)}.f dd{margin:0;font-size:var(--t-s);overflow-wrap:anywhere;min-width:0}.list{list-style:none;margin:8px 0 0;padding:0;display:grid;gap:8px;font-size:var(--t-s)}.list .when{color:var(--ink-2)}.code{border:2px solid var(--ink);min-width:0}.code-h{padding:6px 10px;border-bottom:2px solid var(--ink);background:var(--concrete);font:700 var(--t-xs)/1.3 var(--mono);letter-spacing:.08em;text-transform:uppercase;color:var(--ink-2)}.code pre{margin:0;padding:10px;font-size:var(--t-xs);line-height:1.6;white-space:pre-wrap;overflow-wrap:anywhere}.fn{display:block;margin-top:4px;font-size:var(--t-xs);color:var(--ink-2)}.keys{display:grid;gap:10px;min-width:0}.keys .fl{margin-top:-4px}.keys .f:first-child{margin-top:0}.keys .lab:not(:first-child){margin-top:6px}.leaves{margin:0}.leaves code{display:block;margin-top:2px;font:var(--t-xs)/1.5 var(--mono);overflow-wrap:anywhere}.cph{display:flex;align-items:center;justify-content:space-between;gap:8px}.cph span{min-width:0;overflow-wrap:anywhere}.cp{flex:none;font:700 var(--t-xs)/1 var(--mono);letter-spacing:.06em;text-transform:uppercase;padding:5px 8px 4px;border:2px solid var(--ink);border-radius:0;background:var(--slab);color:var(--ink);cursor:pointer}.cp:hover{background:var(--signal);color:var(--on-signal)}.secret{border:2px solid var(--ink)}.hz{display:flex;align-items:center;justify-content:space-between;gap:10px;padding:8px;background:repeating-linear-gradient(-45deg,var(--signal) 0 12px,#141414 12px 24px)}.hz-l{background:#141414;color:var(--signal);font:700 var(--t-xs)/1 var(--mono);letter-spacing:.12em;text-transform:uppercase;padding:6px 8px 5px}.sb{display:grid;gap:10px;padding:12px}.scrub{flex:1 1 400px;display:flex;flex-wrap:wrap;gap:8px 12px;align-items:center}.scrub .lab{margin:0}.scrub input[type=range]{flex:1 1 120px;min-width:80px;min-width:0;margin:0;height:28px;accent-color:var(--ink);cursor:pointer}.scrub output{font:700 var(--t-s)/1 var(--mono);min-width:12ch;white-space:nowrap}.beats{list-style:none;margin:0;padding:6px 0;max-height:480px;overflow:auto;overscroll-behavior:contain}.beat{padding:10px 18px}.beat+.beat{border-top:1px dashed var(--ink-3)}.bh{margin:0 0 6px;font:700 var(--t-xs)/1.3 var(--mono);letter-spacing:.1em;text-transform:uppercase;color:var(--ink-2);display:flex;flex-wrap:wrap;gap:4px 12px}.bt{font-weight:400;letter-spacing:.04em}.beat.now .bh .bn{background:var(--signal);color:var(--on-signal);padding:2px 5px;margin:-2px -5px}.evs{list-style:none;margin:0;padding:0;display:grid;gap:2px}.ev{width:calc(100% + 6px);display:flex;gap:1ch;text-align:left;background:transparent;border:0;padding:3px 6px;margin-left:-6px;cursor:pointer;border-radius:0;font-size:var(--t-s)}.ev .op{flex:none;min-width:9ch;font-weight:700}.ev .es{min-width:0;color:var(--ink-2);overflow-wrap:anywhere}.ev:hover .es{text-decoration:underline;text-underline-offset:3px}.ev.bad .op,.ev.bad .es{color:var(--danger)}.beat.later .bh,.beat.later .op,.beat.later .es{color:var(--ink-3)}.beat.later .ev .op{font-weight:400}.ev.on{background:var(--signal)}.ev.on .op,.ev.on .es{color:var(--on-signal)}.foot{display:grid;gap:10px;color:var(--ink-2);font-size:var(--t-s);max-width:100ch}.foot p{margin:0}.labrow{display:flex;flex-wrap:wrap;gap:10px;align-items:center}.confirm{flex-basis:100%;display:flex;flex-wrap:wrap;gap:10px;align-items:center;padding:10px 12px;border:2px dashed var(--ink);color:var(--ink)}@media(min-width:761px){.scrub{flex-wrap:nowrap}}@media(max-width:1120px){.work{grid-template-columns:minmax(0,1fr) minmax(0,370px);grid-template-rows:auto auto 1fr;grid-template-areas:"hold side" "tree side" "time side"}}@media(max-width:760px){.clock{position:static}.work{grid-template-columns:minmax(0,1fr);grid-template-rows:none;grid-template-areas:"hold" "tree" "side" "time"}}@media(max-width:640px){.panel{box-shadow:5px 5px 0 var(--shadow)}.flag.proto{display:none}.tree{font-size:var(--t-s)}.sel,.grp{padding-left:10px}.v .belt{display:none}.beat{padding:10px 14px}.ev{flex-direction:column;gap:0}}@media(prefers-reduced-motion:reduce){.btn:active,.btn.sm:active{transform:none}}.sr{position:absolute;width:1px;height:1px;overflow:hidden;clip:rect(0 0 0 0);white-space:nowrap}.code-h{margin:0}.mk.sats{color:var(--ink);text-transform:none;letter-spacing:.02em}.ev.money .op{color:var(--ok)}.ev.money.on .op{color:var(--on-signal)}.beat.later .ev.money .op{color:var(--ink-3)}.vf .line.amt{margin-top:0}#clock-pays{white-space:nowrap}.verbs{display:grid;grid-template-columns:repeat(3,minmax(0,1fr))}.verbs button:nth-child(3n){border-right:0}.verbs button:nth-child(-n+3){border-bottom:2px solid var(--ink)}@media(max-width:640px){.v{margin-left:1ch}.mk{padding:3px 4px 2px}}.holds li{display:flex;align-items:stretch}.holds li .hold{flex:1 1 auto;min-width:0;width:auto}.rig{flex:none;display:grid;justify-items:center;align-content:center;gap:4px;padding:8px 12px;border-left:2px solid var(--ink)}.holds li:has(.hold.on) .rig{background:var(--signal);color:var(--on-signal)}.rig .rl{font:700 .625rem/1 var(--mono);letter-spacing:.1em;text-transform:uppercase}.rig .rn{display:flex;align-items:center;gap:6px;font-weight:700}.rb{width:26px;height:26px;padding:0;border:2px solid var(--ink);border-radius:0;background:var(--slab);color:var(--ink);font:700 var(--t-m)/1 var(--mono);cursor:pointer}.rb:hover:not(:disabled){background:var(--concrete)}.rb:disabled{color:var(--ink-3);border-color:var(--ink-3);cursor:not-allowed}.mining{border-top:3px solid var(--ink)}.holds:empty~.mining{display:none}.mrow{display:flex;flex-wrap:wrap;gap:8px 12px;align-items:center}.mrow .lab{margin:0}.ev.gas .op{color:var(--ink-2);font-weight:400}.holds li{display:grid}.rig{display:flex;align-items:center;justify-content:space-between;gap:10px;padding:0 18px 12px;border-left:0}.rig .rl{color:var(--ink-2)}.holds li:has(.hold.on) .rig .rl{color:var(--on-signal)}.verbs button:nth-child(-n+6){border-bottom:2px solid var(--ink)}.verbs button:last-child:nth-child(3n+2){grid-column:span 2}.fund{display:grid;gap:6px;margin-top:14px}.fund .lab{margin-top:4px}.mining .tempo{flex:1 1 auto;flex-wrap:nowrap}.mining .seg{flex:1 1 auto;min-width:0;padding:9px 6px 8px;letter-spacing:.02em}.items li{overflow-wrap:anywhere}.items .btn.sm{margin-left:8px;vertical-align:middle}.bids{list-style:none;margin:6px 0 0;padding:0 0 0 12px;border-left:2px solid var(--ink-3);display:grid;gap:6px}.ev.money.deal .op{color:var(--ink)}.f dd .btn.open{margin-left:8px;vertical-align:middle}.ring{margin:2px 0 4px}.ring .f{padding-top:8px;margin-top:8px}.ring .f:first-child{margin-top:0;padding-top:0}.ring .f dd{font:var(--t-xs)/1.5 var(--mono)} +:root{--concrete: #e4e3dd;--slab: #f6f5f1;--ink: #141414;--ink-2: #4a4944;--ink-3: #66655f;--signal: #ffc21a;--on-signal: #141414;--ok: #1d7a3a;--danger: #b3261e;--focus: #2346ff;--band: #141414;--band-fg: #f6f5f1;--band-muted: #b0afa8;--shadow: #141414;--mono: ui-monospace, "SF Mono", "Cascadia Mono", "JetBrains Mono", Menlo, Consolas, "Liberation Mono", "DejaVu Sans Mono", monospace;--display: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;--t-xs: .75rem;--t-s: .8125rem;--t-m: .9375rem;--t-l: 1.25rem;--gutter: max(16px, env(safe-area-inset-left, 0px));color-scheme:light}@media(prefers-color-scheme:dark){:root:not([data-theme=light]){--concrete: #151514;--slab: #1e1e1c;--ink: #ecebe4;--ink-2: #b9b8b0;--ink-3: #94938b;--ok: #62c784;--danger: #ff8a7f;--focus: #93a8ff;--band: #0b0b0a;--band-fg: #ecebe4;--band-muted: #9d9c95;--shadow: #4d4c47;color-scheme:dark}}:root[data-theme=dark]{--concrete: #151514;--slab: #1e1e1c;--ink: #ecebe4;--ink-2: #b9b8b0;--ink-3: #94938b;--ok: #62c784;--danger: #ff8a7f;--focus: #93a8ff;--band: #0b0b0a;--band-fg: #ecebe4;--band-muted: #9d9c95;--shadow: #4d4c47;color-scheme:dark}*{box-sizing:border-box}[hidden]{display:none!important}html{-webkit-text-size-adjust:100%}body{margin:0;background:var(--concrete);color:var(--ink);font:400 var(--t-m)/1.5 var(--mono)}body.busy{cursor:progress}::selection{background:var(--signal);color:var(--on-signal)}button,select,input,textarea{font:inherit;color:inherit}:focus-visible{outline:3px solid var(--focus);outline-offset:2px}a{color:inherit;text-decoration-thickness:2px;text-underline-offset:3px}b{font-weight:700}.band{background:var(--band);color:var(--band-fg);border-bottom:3px solid var(--ink)}.band-in{max-width:1320px;margin:0 auto;padding:16px var(--gutter) 14px;display:flex;flex-wrap:wrap;gap:14px 32px;align-items:flex-end;justify-content:space-between}.kicker{margin:0 0 8px;font:700 var(--t-xs)/1 var(--mono);letter-spacing:.12em;text-transform:uppercase;color:var(--band-muted)}.kicker a{color:var(--band-fg)}.wordmark{margin:0;font:900 clamp(2.25rem,6vw,3.5rem)/.84 var(--display);letter-spacing:-.05em;text-transform:uppercase}.lede{margin:10px 0 0;color:var(--band-muted);font-size:var(--t-s);max-width:88ch}.lede b{color:var(--band-fg)}.flags{display:flex;flex-wrap:wrap;gap:8px;align-items:center}.flag{font:700 var(--t-xs)/1 var(--mono);letter-spacing:.1em;text-transform:uppercase;padding:7px 9px 6px;border:2px solid var(--band-fg);background:transparent;color:var(--band-fg);border-radius:0}.flag.hz{background:var(--signal);border-color:var(--signal);color:var(--on-signal)}button.flag{cursor:pointer}button.flag:hover{background:var(--band-fg);color:var(--band)}.clock{background:var(--slab);border-bottom:3px solid var(--ink);position:sticky;top:0;z-index:5}.clock-in{max-width:1320px;margin:0 auto;padding:10px var(--gutter);display:flex;flex-wrap:wrap;gap:10px 18px;align-items:center}.tempo{display:flex;flex-wrap:wrap;align-items:center}.tempo .lab{margin:0 10px 0 0}.seg{font:700 var(--t-xs)/1 var(--mono);letter-spacing:.06em;text-transform:uppercase;padding:9px 10px 8px;border:2px solid var(--ink);background:var(--slab);color:var(--ink);cursor:pointer;border-radius:0;margin-left:-2px}.seg:first-of-type{margin-left:0}.seg:hover:not([aria-pressed=true]){background:var(--concrete)}.seg[aria-pressed=true]{background:var(--ink);color:var(--slab)}.seg:focus-visible{position:relative;z-index:1}.beatno{margin:0;flex:1 1 22ch;font-size:var(--t-s);color:var(--ink-2)}.beatno b{color:var(--ink);font-size:var(--t-m)}.say{max-width:1320px;margin:0 auto;padding:0 var(--gutter) 10px;font-size:var(--t-s);color:var(--ink-2)}.say:empty{display:none}.say.bad{color:var(--danger);font-weight:700}.wrap{max-width:1320px;margin:0 auto;padding:32px var(--gutter) 56px;display:grid;gap:40px}.work{display:grid;gap:36px 28px;align-items:start;grid-template-columns:minmax(0,250px) minmax(0,1fr) minmax(0,390px);grid-template-areas:"hold tree side" "hold time side";grid-template-rows:auto 1fr}.hold-blk{grid-area:hold}.tree-blk{grid-area:tree}.time-blk{grid-area:time}.side{grid-area:side;display:grid;gap:36px;min-width:0}.blk{display:flex;flex-direction:column;align-items:flex-start;min-width:0}.blk>.panel{align-self:stretch}.tab{margin:0;background:var(--ink);color:var(--slab);font:700 var(--t-xs)/1 var(--mono);letter-spacing:.14em;text-transform:uppercase;padding:8px 11px 7px;display:flex;gap:12px;max-width:100%}.tab .sub{font-weight:400;letter-spacing:.06em;text-transform:none;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}.tab .sub:empty{display:none}.panel{background:var(--slab);border:3px solid var(--ink);box-shadow:8px 8px 0 var(--shadow);min-width:0}.pad{padding:16px 18px}.lab{display:block;font:700 var(--t-xs)/1.2 var(--mono);letter-spacing:.1em;text-transform:uppercase;color:var(--ink-2)}.lab span{font-weight:400;letter-spacing:.04em;text-transform:none}.note{margin:0;font-size:var(--t-s);color:var(--ink-2)}.note p{margin:0 0 12px}.wait{margin:0;padding:4px 16px;color:var(--ink-3);font-size:var(--t-s)}.hint{margin:8px 0 0;font-size:var(--t-xs);color:var(--ink-2)}input:not([type]),input[type=text],select,textarea{width:100%;padding:8px 10px;border:2px solid var(--ink);border-radius:0;background:var(--concrete);min-width:0}textarea{resize:vertical;line-height:1.5}.line{display:flex;flex-wrap:wrap;gap:10px;align-items:stretch}.line input{flex:1 1 12ch;width:auto}.btn{font:700 var(--t-s)/1 var(--mono);letter-spacing:.06em;text-transform:uppercase;padding:10px 12px 9px;background:var(--slab);color:var(--ink);border:2px solid var(--ink);box-shadow:3px 3px 0 var(--shadow);cursor:pointer;border-radius:0}.btn:hover{background:var(--concrete)}.btn:active{transform:translate(3px,3px);box-shadow:none}.btn.primary{background:var(--signal);color:var(--on-signal);border-color:var(--ink)}.btn.danger{background:var(--danger);color:var(--slab)}.btn.sm{font-size:var(--t-xs);padding:7px 9px 6px;box-shadow:2px 2px 0 var(--shadow)}.btn.sm:active{transform:translate(2px,2px)}.btn:disabled,.seg:disabled{cursor:not-allowed;background:var(--concrete);color:var(--ink-3);border-color:var(--ink-3);box-shadow:none;transform:none}.holds{list-style:none;margin:0;padding:0}.holds li+li{border-top:2px solid var(--ink)}.hold{width:100%;display:grid;gap:3px;text-align:left;background:transparent;border:0;padding:12px 18px;cursor:pointer;border-radius:0}.hold:hover .hn{text-decoration:underline;text-underline-offset:3px}.hn{font-weight:700;overflow-wrap:anywhere}.hm{font-size:var(--t-xs);color:var(--ink-2)}.hold.on{background:var(--signal)}.hold.on .hn,.hold.on .hm{color:var(--on-signal)}.hold.gone .hn{text-decoration:line-through;text-decoration-thickness:2px}.holds:not(:empty)~.found{border-top:3px solid var(--ink)}.empty p{margin:0;font-size:var(--t-s);color:var(--ink-2)}.found .lab{margin-bottom:8px}.sample{border-top:2px dashed var(--ink-3)}.tree{padding:12px 0;font-size:.875rem;overflow-x:auto}.row{display:flex;align-items:stretch;min-width:max-content}.sel{flex:1;display:flex;align-items:baseline;text-align:left;background:transparent;border:0;padding:4px 14px 4px 16px;cursor:pointer;line-height:1.55;border-radius:0}.sel:hover .l{text-decoration:underline;text-underline-offset:3px}.g{white-space:pre;color:var(--ink-3);flex:none}.p{white-space:pre;font-weight:700;flex:none}.l{flex:none;color:var(--ink);font-weight:700;white-space:nowrap}.v{flex:1 0 auto;display:flex;gap:5px;justify-content:flex-end;align-items:center;margin-left:2ch}.grp{padding:0 14px 0 16px;line-height:1.55;color:var(--ink-3)}.gl{color:var(--ink-2)}.row.on .sel{background:var(--signal)}.row.on .g,.row.on .p,.row.on .l,.row.on .mk,.row.on .belt{color:var(--on-signal);border-color:var(--on-signal)}.row.gone .l,.row.gone .p{text-decoration:line-through;text-decoration-thickness:2px}.row.gone .l{color:var(--ink-2)}.row.cue .l{font-weight:400;font-style:italic}.mk{font:700 .6875rem/1 var(--mono);letter-spacing:.06em;text-transform:uppercase;padding:3px 5px 2px;border:2px solid currentColor;color:var(--ink-2);white-space:nowrap}.mk.ok{color:var(--ok)}.mk.bad{color:var(--danger)}.belt{display:inline-flex;align-items:center;gap:5px;font:700 .6875rem/1 var(--mono);padding:2px 5px 2px 3px;border:2px solid var(--ink);color:var(--ink);white-space:nowrap}.belt:before{content:"";width:10px;height:10px;flex:none;border:1.5px solid currentColor;background:#f6f5f1}.belt.green:before{background:#1d7a3a}.belt.black:before{background:#141414}.verbs{display:flex;flex-wrap:wrap;border-bottom:3px solid var(--ink)}.verbs button{flex:1 1 auto;font:700 var(--t-s)/1 var(--mono);padding:12px 10px;background:transparent;border:0;border-right:2px solid var(--ink);color:var(--ink-2);cursor:pointer;border-radius:0}.verbs button:last-child{border-right:0}.verbs button.off{color:var(--ink-3)}.verbs button:hover:not([aria-pressed=true]){color:var(--ink);text-decoration:underline;text-underline-offset:3px}.verbs button[aria-pressed=true]{background:var(--ink);color:var(--slab)}.why{margin:0;font-size:var(--t-s);color:var(--ink-2)}.keyline{margin:0;padding:10px 18px;font-size:var(--t-xs);color:var(--ink-2);overflow-wrap:anywhere;border-bottom:1px dashed var(--ink-3)}.keyline:empty{display:none}.why:empty{display:none}.vf{display:grid;gap:6px}.vf .lab{margin-top:8px}.vh{margin:0;font-size:var(--t-s);color:var(--ink-2)}.vh b{color:var(--ink)}.vf .go,.vf .line{margin-top:12px}.vf>.go{justify-self:start}.vf .line .go{margin-top:0}.kinds{border:0;margin:0;padding:0;display:grid;gap:6px;min-width:0}.kinds legend{padding:0;margin:8px 0 6px}.kinds label{display:flex;gap:8px;align-items:baseline;cursor:pointer;font-weight:700}.kinds label span{font-weight:400;font-size:var(--t-s);color:var(--ink-2)}.kinds input{accent-color:var(--ink);margin:0}.ih{padding:16px 18px 14px;border-bottom:3px solid var(--ink)}.eyebrow{margin:0 0 8px;font:700 var(--t-xs)/1.3 var(--mono);letter-spacing:.12em;text-transform:uppercase;color:var(--ink-2);overflow-wrap:anywhere}.it{margin:0;font:700 var(--t-l)/1.25 var(--mono);overflow-wrap:anywhere}.idesc{margin:10px 0 0;color:var(--ink-2);font-size:var(--t-s)}.chips{display:flex;flex-wrap:wrap;gap:6px;margin-top:12px}.chip{font:700 var(--t-xs)/1 var(--mono);letter-spacing:.08em;text-transform:uppercase;padding:5px 7px 4px;border:2px solid currentColor}.chip.ok{color:var(--ok)}.chip.bad{color:var(--danger)}.ib{padding:4px 18px 18px;display:grid;gap:16px}.fl{margin:0;display:grid}.f{display:grid;gap:4px;padding-top:12px;margin-top:12px;border-top:1px dashed var(--ink-3)}.f:first-child{border-top:0}.f dt{font:700 var(--t-xs)/1.2 var(--mono);letter-spacing:.1em;text-transform:uppercase;color:var(--ink-2)}.f dd{margin:0;font-size:var(--t-s);overflow-wrap:anywhere;min-width:0}.list{list-style:none;margin:8px 0 0;padding:0;display:grid;gap:8px;font-size:var(--t-s)}.list .when{color:var(--ink-2)}.code{border:2px solid var(--ink);min-width:0}.code-h{padding:6px 10px;border-bottom:2px solid var(--ink);background:var(--concrete);font:700 var(--t-xs)/1.3 var(--mono);letter-spacing:.08em;text-transform:uppercase;color:var(--ink-2)}.code pre{margin:0;padding:10px;font-size:var(--t-xs);line-height:1.6;white-space:pre-wrap;overflow-wrap:anywhere}.fn{display:block;margin-top:4px;font-size:var(--t-xs);color:var(--ink-2)}.keys{display:grid;gap:10px;min-width:0}.keys .fl{margin-top:-4px}.keys .f:first-child{margin-top:0}.keys .lab:not(:first-child){margin-top:6px}.leaves{margin:0}.leaves code{display:block;margin-top:2px;font:var(--t-xs)/1.5 var(--mono);overflow-wrap:anywhere}.cph{display:flex;align-items:center;justify-content:space-between;gap:8px}.cph span{min-width:0;overflow-wrap:anywhere}.cp{flex:none;font:700 var(--t-xs)/1 var(--mono);letter-spacing:.06em;text-transform:uppercase;padding:5px 8px 4px;border:2px solid var(--ink);border-radius:0;background:var(--slab);color:var(--ink);cursor:pointer}.cp:hover{background:var(--signal);color:var(--on-signal)}.secret{border:2px solid var(--ink)}.hz{display:flex;align-items:center;justify-content:space-between;gap:10px;padding:8px;background:repeating-linear-gradient(-45deg,var(--signal) 0 12px,#141414 12px 24px)}.hz-l{background:#141414;color:var(--signal);font:700 var(--t-xs)/1 var(--mono);letter-spacing:.12em;text-transform:uppercase;padding:6px 8px 5px}.sb{display:grid;gap:10px;padding:12px}.scrub{flex:1 1 400px;display:flex;flex-wrap:wrap;gap:8px 12px;align-items:center}.scrub .lab{margin:0}.scrub input[type=range]{flex:1 1 120px;min-width:80px;min-width:0;margin:0;height:28px;accent-color:var(--ink);cursor:pointer}.scrub output{font:700 var(--t-s)/1 var(--mono);min-width:12ch;white-space:nowrap}.beats{list-style:none;margin:0;padding:6px 0;max-height:480px;overflow:auto;overscroll-behavior:contain}.beat{padding:10px 18px}.beat+.beat{border-top:1px dashed var(--ink-3)}.bh{margin:0 0 6px;font:700 var(--t-xs)/1.3 var(--mono);letter-spacing:.1em;text-transform:uppercase;color:var(--ink-2);display:flex;flex-wrap:wrap;gap:4px 12px}.bt{font-weight:400;letter-spacing:.04em}.beat.now .bh .bn{background:var(--signal);color:var(--on-signal);padding:2px 5px;margin:-2px -5px}.evs{list-style:none;margin:0;padding:0;display:grid;gap:2px}.ev{width:calc(100% + 6px);display:flex;gap:1ch;text-align:left;background:transparent;border:0;padding:3px 6px;margin-left:-6px;cursor:pointer;border-radius:0;font-size:var(--t-s)}.ev .op{flex:none;min-width:9ch;font-weight:700}.ev .es{min-width:0;color:var(--ink-2);overflow-wrap:anywhere}.ev:hover .es{text-decoration:underline;text-underline-offset:3px}.ev.bad .op,.ev.bad .es{color:var(--danger)}.beat.later .bh,.beat.later .op,.beat.later .es{color:var(--ink-3)}.beat.later .ev .op{font-weight:400}.ev.on{background:var(--signal)}.ev.on .op,.ev.on .es{color:var(--on-signal)}.foot{display:grid;gap:10px;color:var(--ink-2);font-size:var(--t-s);max-width:100ch}.foot p{margin:0}.labrow{display:flex;flex-wrap:wrap;gap:10px;align-items:center}.confirm{flex-basis:100%;display:flex;flex-wrap:wrap;gap:10px;align-items:center;padding:10px 12px;border:2px dashed var(--ink);color:var(--ink)}@media(min-width:761px){.scrub{flex-wrap:nowrap}}@media(max-width:1120px){.work{grid-template-columns:minmax(0,1fr) minmax(0,370px);grid-template-rows:auto auto 1fr;grid-template-areas:"hold side" "tree side" "time side"}}@media(max-width:760px){.clock{position:static}.work{grid-template-columns:minmax(0,1fr);grid-template-rows:none;grid-template-areas:"hold" "tree" "side" "time"}}@media(max-width:640px){.panel{box-shadow:5px 5px 0 var(--shadow)}.flag.proto{display:none}.tree{font-size:var(--t-s)}.sel,.grp{padding-left:10px}.v .belt{display:none}.beat{padding:10px 14px}.ev{flex-direction:column;gap:0}}@media(prefers-reduced-motion:reduce){.btn:active,.btn.sm:active{transform:none}}.sr{position:absolute;width:1px;height:1px;overflow:hidden;clip:rect(0 0 0 0);white-space:nowrap}.code-h{margin:0}.mk.sats{color:var(--ink);text-transform:none;letter-spacing:.02em}.ev.money .op{color:var(--ok)}.ev.money.on .op{color:var(--on-signal)}.beat.later .ev.money .op{color:var(--ink-3)}.vf .line.amt{margin-top:0}#clock-pays{white-space:nowrap}.verbs{display:grid;grid-template-columns:repeat(3,minmax(0,1fr))}.verbs button:nth-child(3n){border-right:0}.verbs button:nth-child(-n+3){border-bottom:2px solid var(--ink)}@media(max-width:640px){.v{margin-left:1ch}.mk{padding:3px 4px 2px}}.holds li{display:flex;align-items:stretch}.holds li .hold{flex:1 1 auto;min-width:0;width:auto}.rig{flex:none;display:grid;justify-items:center;align-content:center;gap:4px;padding:8px 12px;border-left:2px solid var(--ink)}.holds li:has(.hold.on) .rig{background:var(--signal);color:var(--on-signal)}.rig .rl{font:700 .625rem/1 var(--mono);letter-spacing:.1em;text-transform:uppercase}.rig .rn{display:flex;align-items:center;gap:6px;font-weight:700}.rb{width:26px;height:26px;padding:0;border:2px solid var(--ink);border-radius:0;background:var(--slab);color:var(--ink);font:700 var(--t-m)/1 var(--mono);cursor:pointer}.rb:hover:not(:disabled){background:var(--concrete)}.rb:disabled{color:var(--ink-3);border-color:var(--ink-3);cursor:not-allowed}.mining{border-top:3px solid var(--ink)}.holds:empty~.mining{display:none}.mrow{display:flex;flex-wrap:wrap;gap:8px 12px;align-items:center}.mrow .lab{margin:0}.ev.gas .op{color:var(--ink-2);font-weight:400}.holds li{display:grid}.rig{display:flex;align-items:center;justify-content:space-between;gap:10px;padding:0 18px 12px;border-left:0}.rig .rl{color:var(--ink-2)}.holds li:has(.hold.on) .rig .rl{color:var(--on-signal)}.verbs button:nth-child(-n+6){border-bottom:2px solid var(--ink)}.verbs button:last-child:nth-child(3n+2){grid-column:span 2}.fund{display:grid;gap:6px;margin-top:14px}.fund .lab{margin-top:4px}.mining .tempo{flex:1 1 auto;flex-wrap:nowrap}.mining .seg{flex:1 1 auto;min-width:0;padding:9px 6px 8px;letter-spacing:.02em}.items li{overflow-wrap:anywhere}.items .btn.sm{margin-left:8px;vertical-align:middle}.bids{list-style:none;margin:6px 0 0;padding:0 0 0 12px;border-left:2px solid var(--ink-3);display:grid;gap:6px}.ev.money.deal .op{color:var(--ink)}.f dd .btn.open{margin-left:8px;vertical-align:middle}.ring{margin:2px 0 4px}.ring .f{padding-top:8px;margin-top:8px}.ring .f:first-child{margin-top:0;padding-top:0}.ring .f dd{font:var(--t-xs)/1.5 var(--mono)}.verbs button:nth-child(-n+9){border-bottom:2px solid var(--ink)}.verbs button:last-child:nth-child(3n+1){grid-column:span 3}.mk.lapsed{color:var(--ink-3);text-decoration:line-through}#charter-where{display:grid;gap:6px}#charter-where[hidden]{display:none}#charter-now{color:var(--ink-2)}#charter-forms label.off{color:var(--ink-3)}#charter-forms label{display:grid;grid-template-columns:auto 1fr;column-gap:8px;row-gap:2px}#charter-forms label span{grid-column:2;font-size:var(--t-xs)}#charter-forms label.off{cursor:default} diff --git a/ventures/lineage/orgchain/index.html b/ventures/lineage/orgchain/index.html index 381d020..ff20e6b 100644 --- a/ventures/lineage/orgchain/index.html +++ b/ventures/lineage/orgchain/index.html @@ -4,12 +4,12 @@ Orgchain · Lineage - + - - + +
@@ -17,7 +17,7 @@

Lineage /

Orgchain

-

Found a holding, then birth its orgs and agents, award belts, record decisions, make and trade items, publish keyrings, send test BTC, graduate and close. Each act is an inscription whose parent is the node that authorizes it, paid for with the actor's own gas, and each beat is a block whose 50 test BTC the holdings mine. Lineage gives the structure; the chain adds time.

+

Found a holding, then birth its orgs and agents, award belts, record decisions, make and trade items, publish keyrings, charter legal forms, send test BTC, graduate and close. Each act is an inscription whose parent is the node that authorizes it, paid for with the actor's own gas, and each beat is a block whose 50 test BTC the holdings mine. Lineage gives the structure; the chain adds time.

Test coins only @@ -89,7 +89,7 @@

Select a holding, or a node in its tree, to act through it.