From 1a5b105956c3443f61f256d718c39590d7db8fda Mon Sep 17 00:00:00 2001 From: teahubxyz Date: Thu, 15 Oct 2026 00:45:00 -0700 Subject: [PATCH] lineage: Orgchain v1.8 (belts cross holdings, and a graduate becomes its own holding) Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01H4upF5LVwmPDDqrhdUfnXh --- .../lineage/orgchain/assets/index-BFlpdqf-.js | 2063 ----------------- ...{index-DwC5RMF4.css => index-Dx_1vZ_Y.css} | 2 +- .../lineage/orgchain/assets/index-ohHsgad2.js | 2063 +++++++++++++++++ ventures/lineage/orgchain/index.html | 6 +- 4 files changed, 2067 insertions(+), 2067 deletions(-) delete mode 100644 ventures/lineage/orgchain/assets/index-BFlpdqf-.js rename ventures/lineage/orgchain/assets/{index-DwC5RMF4.css => index-Dx_1vZ_Y.css} (99%) create mode 100644 ventures/lineage/orgchain/assets/index-ohHsgad2.js diff --git a/ventures/lineage/orgchain/assets/index-BFlpdqf-.js b/ventures/lineage/orgchain/assets/index-BFlpdqf-.js deleted file mode 100644 index 85b5ebe..0000000 --- a/ventures/lineage/orgchain/assets/index-BFlpdqf-.js +++ /dev/null @@ -1,2063 +0,0 @@ -(function(){const t=document.createElement("link").relList;if(t&&t.supports&&t.supports("modulepreload"))return;for(const s of document.querySelectorAll('link[rel="modulepreload"]'))r(s);new MutationObserver(s=>{for(const o of s)if(o.type==="childList")for(const i of o.addedNodes)i.tagName==="LINK"&&i.rel==="modulepreload"&&r(i)}).observe(document,{childList:!0,subtree:!0});function n(s){const o={};return s.integrity&&(o.integrity=s.integrity),s.referrerPolicy&&(o.referrerPolicy=s.referrerPolicy),s.crossOrigin==="use-credentials"?o.credentials="include":s.crossOrigin==="anonymous"?o.credentials="omit":o.credentials="same-origin",o}function r(s){if(s.ep)return;s.ep=!0;const o=n(s);fetch(s.href,o)}})();const bc=5e9;function wu(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 xu(e,t){var n;return(n=wu(e,t,1)[0])==null?void 0:n[0]}function Os(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=wu(s,o,Number(i.value));return o+=Number(i.value),a})}function vi(e){if(!Number.isSafeInteger(e)||e<0)throw new Error(`Wrong positive integer: ${e}`)}function Ah(e){if(typeof e!="boolean")throw new Error(`Expected boolean, not ${e}`)}function Eu(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 Bh(e){if(typeof e!="function"||typeof e.create!="function")throw new Error("Hash should be wrapped by utils.wrapConstructor");vi(e.outputLen),vi(e.blockLen)}function Th(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 Ih(e,t){Eu(e);const n=t.outputLen;if(e.lengthnew DataView(e.buffer,e.byteOffset,e.byteLength),yt=(e,t)=>e<<32-t|e>>>t,Ch=new Uint8Array(new Uint32Array([287454020]).buffer)[0]===68;if(!Ch)throw new Error("Non little-endian hardware is not supported");Array.from({length:256},(e,t)=>t.toString(16).padStart(2,"0"));function Ph(e){if(typeof e!="string")throw new TypeError(`utf8ToBytes expected string, got ${typeof e}`);return new TextEncoder().encode(e)}function ku(e){if(typeof e=="string"&&(e=Ph(e)),!(e instanceof Uint8Array))throw new TypeError(`Expected input type is Uint8Array (got ${typeof e})`);return e}let Uh=class{clone(){return this._cloneInto()}};function Su(e){const t=r=>e().update(ku(r)).digest(),n=e();return t.outputLen=n.outputLen,t.blockLen=n.blockLen,t.create=()=>e(),t}function Nh(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 Lh=class extends Uh{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=Do(this.buffer)}update(t){Ko.exists(this);const{view:n,buffer:r,blockLen:s}=this;t=ku(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,Hh=(e,t,n)=>e&t^e&n^t&n,jh=new Uint32Array([1116352408,1899447441,3049323471,3921009573,961987163,1508970993,2453635748,2870763221,3624381080,310598401,607225278,1426881987,1925078388,2162078206,2614888103,3248222580,3835390401,4022224774,264347078,604807628,770255983,1249150122,1555081692,1996064986,2554220882,2821834349,2952996808,3210313671,3336571891,3584528711,113926993,338241895,666307205,773529912,1294757372,1396182291,1695183700,1986661051,2177026350,2456956037,2730485921,2820302411,3259730800,3345764771,3516065817,3600352804,4094571909,275423344,430227734,506948616,659060556,883997877,958139571,1322822218,1537002063,1747873779,1955562222,2024104815,2227730452,2361852424,2428436474,2756734187,3204031479,3329325298]),Zt=new Uint32Array([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]),Vt=new Uint32Array(64);let $u=class extends Lh{constructor(){super(64,32,8,!1),this.A=Zt[0]|0,this.B=Zt[1]|0,this.C=Zt[2]|0,this.D=Zt[3]|0,this.E=Zt[4]|0,this.F=Zt[5]|0,this.G=Zt[6]|0,this.H=Zt[7]|0}get(){const{A:t,B:n,C:r,D:s,E:o,F:i,G:a,H:c}=this;return[t,n,r,s,o,i,a,c]}set(t,n,r,s,o,i,a,c){this.A=t|0,this.B=n|0,this.C=r|0,this.D=s|0,this.E=o|0,this.F=i|0,this.G=a|0,this.H=c|0}process(t,n){for(let l=0;l<16;l++,n+=4)Vt[l]=t.getUint32(n,!1);for(let l=16;l<64;l++){const d=Vt[l-15],h=Vt[l-2],p=yt(d,7)^yt(d,18)^d>>>3,g=yt(h,17)^yt(h,19)^h>>>10;Vt[l]=g+Vt[l-7]+p+Vt[l-16]|0}let{A:r,B:s,C:o,D:i,E:a,F:c,G:u,H:f}=this;for(let l=0;l<64;l++){const d=yt(a,6)^yt(a,11)^yt(a,25),h=f+d+Rh(a,c,u)+jh[l]+Vt[l]|0,g=(yt(r,2)^yt(r,13)^yt(r,22))+Hh(r,s,o)|0;f=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,f=f+this.H|0,this.set(r,s,o,i,a,c,u,f)}roundClean(){Vt.fill(0)}destroy(){this.set(0,0,0,0,0,0,0,0),this.buffer.fill(0)}},Kh=class extends $u{constructor(){super(),this.A=-1056596264,this.B=914150663,this.C=812702999,this.D=-150054599,this.E=-4191439,this.F=1750603025,this.G=1694076839,this.H=-1090891868,this.outputLen=28}};const Ei=Su(()=>new $u);Su(()=>new Kh);function Dh(e,t){if(e.length>t)throw new TypeError(`Data is larger than array size: ${e.length} > ${t}`)}function Mh(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 Zh(e){if(e>Number.MAX_SAFE_INTEGER)throw new TypeError("Number exceeds safe bounds!")}const{getRandomValues:Vh}=crypto??globalThis.crypto??window.crypto;function qh(e=32){if(typeof Vh=="function")return crypto.getRandomValues(new Uint8Array(e));throw new Error("Crypto module missing getRandomValues!")}function zh(e,t,n="be"){t===void 0&&(t=e.length),Dh(e,t);const r=new Uint8Array(t).fill(0),s=n==="be"?0:t-e.length;return r.set(e,s),r}function _u(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 Yh(e,t){const n=Au(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 Bu(e){return Ei(Ei(e))}function Xh(e){const t=Bu(e);return _u([e,t.slice(0,4)])}function Jh(e){const t=e.slice(0,-4),n=e.slice(-4);if(Bu(t).slice(0,4).toString()!==n.toString())throw new Error("Invalid checksum!");return t}const wc={encode:Wh,decode:Yh},Tu={encode:e=>{const t=Xh(e);return wc.encode(t,"base58")},decode:e=>{const t=wc.decode(e,"base58");return Jh(t)}},Iu="qpzry9x8gf2tvdw0s3jn54khce6mua7l",Qh=[996825010,642813549,513874426,1027748829,705979059],Rs=[{version:0,name:"bech32",const:1},{version:1,name:"bech32m",const:734539939}];function Ou(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^=Qh[s])}return t}function Cu(e){const t=[];let n;for(n=0;n>5);for(t.push(0),n=0;n>5*(5-i)&31);return o}function Pu(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 n0(e,t,n){const r=t.concat(t0(e,t,n));let s=e+"1";for(let o=0;oo.version===t[0])??Rs[0];if(!e0(r,t,s))throw new Error("Checksum verification failed!");return[r,t.slice(0,t.length-6)]}function r0(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 s0(e){const t=e.lastIndexOf("1");return!(t<1||t+7>e.length||e.length>90)}function o0(e,t="bc",n=0){const r=[n,...Pu([...e],8,5)],s=Rs.find(i=>i.version===n)??Rs[0],o=n0(t,r,s);return Nu(o),o}function Nu(e){e=e.toLowerCase();const t=e.split("1",1)[0],[n,r]=Uu(e),s=Pu(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 i0(e){e=e.toLowerCase();const[t,n]=Uu(e);return n[0]}const Lu={encode:o0,decode:Nu,version:i0},Ru="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",Hu="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",a0=new TextEncoder;function ju(e,t=!1,n=!0){typeof e=="string"&&(e=a0.encode(e));const r=t?Hu:Ru;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 Ku(e,t=!1){const n=t||e.includes("-")||e.includes("_")?Hu.split(""):Ru.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 Du={encode:ju,decode:Ku},Mu={encode:e=>ju(e,!0,!1),decode:e=>Ku(e,!0)},c0=BigInt(0),u0=BigInt(255),Zu=BigInt(256);function f0(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 l0(e,t,n="be"){t===void 0&&(t=f0(e));const r=n==="le",s=new ArrayBuffer(t),o=new DataView(s);let i=r?0:t-1;for(;e>c0;){const a=e&u0,c=Number(a);r?o.setUint8(i++,c):o.setUint8(i--,c),e=(e-a)/Zu}return new Uint8Array(s)}function d0(e){let t=BigInt(0);for(let n=e.length-1;n>=0;n--)t=t*Zu+BigInt(e[n]);return BigInt(t)}function h0(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 g0(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 m0(e,t,n="be"){t===void 0&&(t=g0(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 y0(e){let t=0;for(let n=e.length-1;n>=0;n--)t=t*256+e[n],Zh(t);return t}const b0=new TextEncoder,w0=new TextDecoder;function oa(e){return b0.encode(e)}function Mo(e){return w0.decode(e)}function x0(e,t){Mh(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 v0(e,t,n="le"){t=x0(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 S0(e,t,n){if(e instanceof ArrayBuffer)return new Uint8Array(e);if(e instanceof Uint8Array)return zh(e,t,n);if(typeof e=="string")return v0(e,t,n);if(typeof e=="bigint")return l0(e,t,n);if(typeof e=="number")return m0(e,t,n);if(typeof e=="boolean")return Uint8Array.of(e?1:0);throw TypeError("Unsupported format:"+typeof e)}var ee;let k=(ee=class extends Uint8Array{static random(t=32){const n=qh(t);return new ee(n,t)}constructor(t,n,r){const s=S0(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 mr(this)}toNum(t="be"){const n=t==="be"?this.reverse():this;return y0(n)}toBin(){return p0(this)}toBig(t="be"){const n=t==="be"?this.reverse():this;return d0(n)}toHash(){const t=Ei(this);return new ee(t)}toJson(){const t=Mo(this);return JSON.parse(t)}toBech32(t,n=0){return Lu.encode(this,t,n)}toStr(){return Mo(this)}toHex(){return E0(this)}toBytes(){return new Uint8Array(this)}tob58chk(){return Tu.encode(this)}toBase64(){return Du.encode(this)}toB64url(){return Mu.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=_u(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=$0,ee.big=A0,ee.bin=_0,ee.raw=B0,ee.str=T0,ee.hex=I0,ee.bytes=O0,ee.json=C0,ee.base64=P0,ee.b64url=U0,ee.bech32=N0,ee.b58chk=L0,ee.encode=oa,ee.decode=Mo,ee);function $0(e,t,n){return new k(e,t,n)}function _0(e,t,n){return new k(h0(e),t,n)}function A0(e,t,n){return new k(e,t,n)}function B0(e,t,n){return new k(e,t,n)}function T0(e,t,n){return new k(oa(e),t,n)}function I0(e,t,n){return new k(e,t,n)}function O0(e,t,n){return new k(e,t,n)}function C0(e){return new k(k0(e))}function P0(e){return new k(Du.decode(e))}function U0(e){return new k(Mu.decode(e))}function N0(e){return new k(Lu.decode(e))}function L0(e){return new k(Tu.decode(e))}let mr=class{constructor(t){this.data=k.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 k(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 It(e,t){const n=k.bytes(e);if(n.length!==t)throw new Error(`Invalid input size: ${n.hex} !== ${t}`)}function je(e,t){if(t)throw new Error(e);return!1}function Cs(e,...t){const n=k.str(e).digest.raw,r=t.map(s=>k.bytes(s));return k.join([n,n,k.join(r)]).digest}const Vu={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 R0(e){if(e>186&&e<255)return"OP_SUCCESS"+String(e);for(const[t,n]of Object.entries(Vu))if(n===e)return t;throw new Error("OPCODE not found:"+String(e))}function H0(e){for(const[t,n]of Object.entries(Vu))if(t===e)return Number(n);throw new Error("OPCODE not found:"+e)}function j0(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 K0(e){const r=[];switch(!0){case typeof e!="number":return!1;case e===0:return!0;case r.includes(e):return!1;case(750?k.join(t):new Uint8Array}function D0(e){let t=new Uint8Array;if(typeof e=="string"){if(e.startsWith("OP_"))return k.num(H0(e),1);Mt(e)?t=k.hex(e):t=k.str(e)}else t=k.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])),k.join([xc(t.length),t]));if(t.length>Hs){const n=M0(t);return zu(n)}else return k.join([xc(t.length),t])}function xc(e){const t=k.num(76,1),n=k.num(77,1);switch(!0){case e<=75:return k.num(e);case(e>75&&e<256):return k.join([t,k.num(e,1,"le")]);case(e>=256&&e<=Hs):return k.join([n,k.num(e,2,"le")]);default:throw new Error("Invalid word size:"+e.toString())}}function M0(e){const t=[],n=new mr(e);for(;n.size>Hs;)t.push(n.read(Hs));return t.push(n.read(n.size)),t}function ia(e,t=!1){let n=k.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 Z0(n)}function Z0(e){const t=new mr(e),n=[],r=t.size;let s,o,i,a=0;for(;a0&&!t.includes(e.length))throw new TypeError(`Expected Uint8Array of length ${t}, not of length=${e.length}`)}function W0(e){if(typeof e!="function"||typeof e.create!="function")throw new Error("Hash should be wrapped by utils.wrapConstructor");ki(e.outputLen),ki(e.blockLen)}function Y0(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 X0(e,t){Fu(e);const n=t.outputLen;if(e.lengthnew DataView(e.buffer,e.byteOffset,e.byteLength),bt=(e,t)=>e<<32-t|e>>>t,Q0=new Uint8Array(new Uint32Array([287454020]).buffer)[0]===68;if(!Q0)throw new Error("Non little-endian hardware is not supported");Array.from({length:256},(e,t)=>t.toString(16).padStart(2,"0"));function ep(e){if(typeof e!="string")throw new TypeError(`utf8ToBytes expected string, got ${typeof e}`);return new TextEncoder().encode(e)}function aa(e){if(typeof e=="string"&&(e=ep(e)),!(e instanceof Uint8Array))throw new TypeError(`Expected input type is Uint8Array (got ${typeof e})`);return e}function tp(...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(aa(r)).digest(),n=e();return t.outputLen=n.outputLen,t.blockLen=n.blockLen,t.create=()=>e(),t}function np(e=32){if(Zo&&typeof Zo.getRandomValues=="function")return Zo.getRandomValues(new Uint8Array(e));throw new Error("crypto.getRandomValues must be defined")}function rp(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 sp=class extends Gu{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=Vo(this.buffer)}update(t){_n.exists(this);const{view:n,buffer:r,blockLen:s}=this;t=aa(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,ip=(e,t,n)=>e&t^e&n^t&n,ap=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]),zt=new Uint32Array(64);let Yu=class extends sp{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)zt[l]=t.getUint32(n,!1);for(let l=16;l<64;l++){const d=zt[l-15],h=zt[l-2],p=bt(d,7)^bt(d,18)^d>>>3,g=bt(h,17)^bt(h,19)^h>>>10;zt[l]=g+zt[l-7]+p+zt[l-16]|0}let{A:r,B:s,C:o,D:i,E:a,F:c,G:u,H:f}=this;for(let l=0;l<64;l++){const d=bt(a,6)^bt(a,11)^bt(a,25),h=f+d+op(a,c,u)+ap[l]+zt[l]|0,g=(bt(r,2)^bt(r,13)^bt(r,22))+ip(r,s,o)|0;f=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,f=f+this.H|0,this.set(r,s,o,i,a,c,u,f)}roundClean(){zt.fill(0)}destroy(){this.set(0,0,0,0,0,0,0,0),this.buffer.fill(0)}},cp=class extends Yu{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 Xu=Wu(()=>new Yu);Wu(()=>new cp);/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */const up=BigInt(0),ca=BigInt(1),fp=BigInt(2),bo=e=>e instanceof Uint8Array,lp=Array.from({length:256},(e,t)=>t.toString(16).padStart(2,"0"));function sr(e){if(!bo(e))throw new Error("Uint8Array expected");let t="";for(let n=0;nor(e.toString(16).padStart(t*2,"0")),Qu=(e,t)=>Qn(e,t).reverse(),dp=e=>or(Ju(e));function nt(e,t,n){let r;if(typeof t=="string")try{r=or(t)}catch(o){throw new Error(`${e} must be valid hex string, got "${t}". Cause: ${o}`)}else if(bo(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 at(...e){const t=new Uint8Array(e.reduce((r,s)=>r+s.length,0));let n=0;return e.forEach(r=>{if(!bo(r))throw new Error("Uint8Array expected");t.set(r,n),n+=r.length}),t}function hp(e,t){if(e.length!==t.length)return!1;for(let n=0;n0n;e>>=ca,t+=1);return t}const gp=(e,t)=>e>>BigInt(t)&1n,mp=(e,t,n)=>e|(n?ca:up)<(fp<new Uint8Array(e),vc=e=>Uint8Array.from(e);function ef(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=qo(e),s=qo(e),o=0;const i=()=>{r.fill(1),s.fill(0),o=0},a=(...l)=>n(s,r,...l),c=(l=qo())=>{s=a(vc([0]),l),r=a(),l.length!==0&&(s=a(vc([1]),l),r=a())},u=()=>{if(o++>=1e3)throw new Error("drbg: tried 1000 values");let l=0;const d=[];for(;l{i(),c(l);let h;for(;!(h=d(u()));)c();return i(),h}}const yp={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 yr(e,t,n={}){const r=(s,o,i)=>{const a=yp[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 bp=Object.freeze({__proto__:null,bitGet:gp,bitLen:pp,bitMask:la,bitSet:mp,bytesToHex:sr,bytesToNumberBE:ln,bytesToNumberLE:fa,concatBytes:at,createHmacDrbg:ef,ensureBytes:nt,equalBytes:hp,hexToBytes:or,hexToNumber:ua,numberToBytesBE:Qn,numberToBytesLE:Qu,numberToHexUnpadded:Ju,numberToVarBytesBE:dp,utf8ToBytes:wo,validateObject:yr});/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */const Pe=BigInt(0),Ae=BigInt(1),kn=BigInt(2),wp=BigInt(3),Si=BigInt(4),Ec=BigInt(5),kc=BigInt(8);BigInt(9);BigInt(16);function Ke(e,t){const n=e%t;return n>=Pe?n:t+n}function xp(e,t,n){if(n<=Pe||t 0");if(n===Ae)return Pe;let r=Ae;for(;t>Pe;)t&Ae&&(r=r*e%n),e=e*e%n,t>>=Ae;return r}function tt(e,t,n){let r=e;for(;t-- >Pe;)r*=r,r%=n;return r}function $i(e,t){if(e===Pe||t<=Pe)throw new Error(`invert: expected positive integers, got n=${e} mod=${t}`);let n=Ke(e,t),r=t,s=Pe,o=Ae;for(;n!==Pe;){const a=r/n,c=r%n,u=s-o*a;r=n,n=c,s=o,o=u}if(r!==Ae)throw new Error("invert: does not exist");return Ke(s,t)}function vp(e){const t=(e-Ae)/kn;let n,r,s;for(n=e-Ae,r=0;n%kn===Pe;n/=kn,r++);for(s=kn;s(r[s]="function",r),t);return yr(e,n)}function Sp(e,t,n){if(n 0");if(n===Pe)return e.ONE;if(n===Ae)return t;let r=e.ONE,s=t;for(;n>Pe;)n&Ae&&(r=e.mul(r,s)),s=e.sqr(s),n>>=Ae;return r}function $p(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 da(e,t){const n=t!==void 0?t:e.toString(2).length,r=Math.ceil(n/8);return{nBitLength:n,nByteLength:r}}function nf(e,t,n=!1,r={}){if(e<=Pe)throw new Error(`Expected Fp ORDER > 0, got ${e}`);const{nBitLength:s,nByteLength:o}=da(e,t);if(o>2048)throw new Error("Field lengths over 2048 bytes are not supported");const i=Ep(e),a=Object.freeze({ORDER:e,BITS:s,BYTES:o,MASK:la(s),ZERO:Pe,ONE:Ae,create:c=>Ke(c,e),isValid:c=>{if(typeof c!="bigint")throw new Error(`Invalid field element: expected bigint, got ${typeof c}`);return Pe<=c&&cc===Pe,isOdd:c=>(c&Ae)===Ae,neg:c=>Ke(-c,e),eql:(c,u)=>c===u,sqr:c=>Ke(c*c,e),add:(c,u)=>Ke(c+u,e),sub:(c,u)=>Ke(c-u,e),mul:(c,u)=>Ke(c*u,e),pow:(c,u)=>Sp(a,c,u),div:(c,u)=>Ke(c*$i(u,e),e),sqrN:c=>c*c,addN:(c,u)=>c+u,subN:(c,u)=>c-u,mulN:(c,u)=>c*u,inv:c=>$i(c,e),sqrt:r.sqrt||(c=>i(a,c)),invertBatch:c=>$p(a,c),cmov:(c,u,f)=>f?u:c,toBytes:c=>n?Qu(c,o):Qn(c,o),fromBytes:c=>{if(c.length!==o)throw new Error(`Fp.fromBytes: expected ${o}, got ${c.length}`);return n?fa(c):ln(c)}});return Object.freeze(a)}function _p(e,t,n=!1){e=nt("privateHash",e);const r=e.length,s=da(t).nByteLength+8;if(s<24||r1024)throw new Error(`hashToPrivateScalar: expected ${s}-1024 bytes of input, got ${r}`);const o=n?fa(e):ln(e);return Ke(o,t-Ae)+Ae}/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */const Ap=BigInt(0),zo=BigInt(1);function Bp(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>Ap;)o&zo&&(i=i.add(a)),a=a.double(),o>>=zo;return i},precomputeWindow(s,o){const{windows:i,windowSize:a}=r(o),c=[];let u=s,f=u;for(let l=0;l>=h,y>c&&(y-=d,i+=zo);const m=g,v=g+Math.abs(y)-1,b=p%2!==0,x=y<0;y===0?f=f.add(n(b,o[m])):u=u.add(n(x,o[v]))}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 rf(e){return tf(e.Fp),yr(e,{n:"bigint",h:"bigint",Gx:"field",Gy:"field"},{nBitLength:"isSafeInteger",nByteLength:"isSafeInteger"}),Object.freeze({...da(e.n,e.nBitLength),...e,p:e.Fp.ORDER})}/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */function Tp(e){const t=rf(e);yr(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:Ip,hexToBytes:Op}=bp,An={Err:class extends Error{constructor(t=""){super(t)}},_parseInt(e){const{Err:t}=An;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:Ip(r),l:e.subarray(n+2)}},toSig(e){const{Err:t}=An,n=typeof e=="string"?Op(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}=An._parseInt(n.subarray(2)),{d:i,l:a}=An._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}`}},ct=BigInt(0),Ie=BigInt(1),Pt=BigInt(2),js=BigInt(3),Sc=BigInt(4);function Cp(e){const t=Tp(e),{Fp:n}=t,r=t.toBytes||((p,g,y)=>{const m=g.toAffine();return at(Uint8Array.from([4]),n.toBytes(m.x),n.toBytes(m.y))}),s=t.fromBytes||(p=>{const g=p.subarray(1),y=n.fromBytes(g.subarray(0,n.BYTES)),m=n.fromBytes(g.subarray(n.BYTES,2*n.BYTES));return{x:y,y:m}});function o(p){const{a:g,b:y}=t,m=n.sqr(p),v=n.mul(m,p);return n.add(n.add(v,n.mul(p,g)),y)}function i(p){return typeof p=="bigint"&&ctn.eql(b,n.ZERO);return v(y)&&v(m)?l.ZERO:new l(y,m,n.ONE)}get x(){return this.toAffine().x}get y(){return this.toAffine().y}static normalizeZ(g){const y=n.invertBatch(g.map(m=>m.pz));return g.map((m,v)=>m.toAffine(y[v])).map(l.fromAffine)}static fromHex(g){const y=l.fromAffine(s(nt("pointHex",g)));return y.assertValidity(),y}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}=this.toAffine();if(!n.isValid(g)||!n.isValid(y))throw new Error("bad point: x or y not FE");const m=n.sqr(y),v=o(g);if(!n.eql(m,v))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:y,py:m,pz:v}=this,{px:b,py:x,pz:_}=g,I=n.eql(n.mul(y,_),n.mul(b,v)),C=n.eql(n.mul(m,_),n.mul(x,v));return I&&C}negate(){return new l(this.px,n.neg(this.py),this.pz)}double(){const{a:g,b:y}=t,m=n.mul(y,js),{px:v,py:b,pz:x}=this;let _=n.ZERO,I=n.ZERO,C=n.ZERO,P=n.mul(v,v),B=n.mul(b,b),N=n.mul(x,x),H=n.mul(v,b);return H=n.add(H,H),C=n.mul(v,x),C=n.add(C,C),_=n.mul(g,C),I=n.mul(m,N),I=n.add(_,I),_=n.sub(B,I),I=n.add(B,I),I=n.mul(_,I),_=n.mul(H,_),C=n.mul(m,C),N=n.mul(g,N),H=n.sub(P,N),H=n.mul(g,H),H=n.add(H,C),C=n.add(P,P),P=n.add(C,P),P=n.add(P,N),P=n.mul(P,H),I=n.add(I,P),N=n.mul(b,x),N=n.add(N,N),P=n.mul(N,H),_=n.sub(_,P),C=n.mul(N,B),C=n.add(C,C),C=n.add(C,C),new l(_,I,C)}add(g){f(g);const{px:y,py:m,pz:v}=this,{px:b,py:x,pz:_}=g;let I=n.ZERO,C=n.ZERO,P=n.ZERO;const B=t.a,N=n.mul(t.b,js);let H=n.mul(y,b),K=n.mul(m,x),E=n.mul(v,_),S=n.add(y,m),w=n.add(b,x);S=n.mul(S,w),w=n.add(H,K),S=n.sub(S,w),w=n.add(y,v);let $=n.add(b,_);return w=n.mul(w,$),$=n.add(H,E),w=n.sub(w,$),$=n.add(m,v),I=n.add(x,_),$=n.mul($,I),I=n.add(K,E),$=n.sub($,I),P=n.mul(B,w),I=n.mul(N,E),P=n.add(I,P),I=n.sub(K,P),P=n.add(K,P),C=n.mul(I,P),K=n.add(H,H),K=n.add(K,H),E=n.mul(B,E),w=n.mul(N,w),K=n.add(K,E),E=n.sub(H,E),E=n.mul(B,E),w=n.add(w,E),H=n.mul(K,w),C=n.add(C,H),H=n.mul($,w),I=n.mul(S,I),I=n.sub(I,H),H=n.mul(S,K),P=n.mul($,P),P=n.add(P,H),new l(I,C,P)}subtract(g){return this.add(g.negate())}is0(){return this.equals(l.ZERO)}wNAF(g){return h.wNAFCached(this,u,g,y=>{const m=n.invertBatch(y.map(v=>v.pz));return y.map((v,b)=>v.toAffine(m[b])).map(l.fromAffine)})}multiplyUnsafe(g){const y=l.ZERO;if(g===ct)return y;if(a(g),g===Ie)return this;const{endo:m}=t;if(!m)return h.unsafeLadder(this,g);let{k1neg:v,k1:b,k2neg:x,k2:_}=m.splitScalar(g),I=y,C=y,P=this;for(;b>ct||_>ct;)b&Ie&&(I=I.add(P)),_&Ie&&(C=C.add(P)),P=P.double(),b>>=Ie,_>>=Ie;return v&&(I=I.negate()),x&&(C=C.negate()),C=new l(n.mul(C.px,m.beta),C.py,C.pz),I.add(C)}multiply(g){a(g);let y=g,m,v;const{endo:b}=t;if(b){const{k1neg:x,k1:_,k2neg:I,k2:C}=b.splitScalar(y);let{p:P,f:B}=this.wNAF(_),{p:N,f:H}=this.wNAF(C);P=h.constTimeNegate(x,P),N=h.constTimeNegate(I,N),N=new l(n.mul(N.px,b.beta),N.py,N.pz),m=P.add(N),v=B.add(H)}else{const{p:x,f:_}=this.wNAF(y);m=x,v=_}return l.normalizeZ([m,v])[0]}multiplyAndAddUnsafe(g,y,m){const v=l.BASE,b=(_,I)=>I===ct||I===Ie||!_.equals(v)?_.multiplyUnsafe(I):_.multiply(I),x=b(this,y).add(b(g,m));return x.is0()?void 0:x}toAffine(g){const{px:y,py:m,pz:v}=this,b=this.is0();g==null&&(g=b?n.ONE:n.inv(v));const x=n.mul(y,g),_=n.mul(m,g),I=n.mul(v,g);if(b)return{x:n.ZERO,y:n.ZERO};if(!n.eql(I,n.ONE))throw new Error("invZ was invalid");return{x,y:_}}isTorsionFree(){const{h:g,isTorsionFree:y}=t;if(g===Ie)return!0;if(y)return y(l,this);throw new Error("isTorsionFree() has not been declared for the elliptic curve")}clearCofactor(){const{h:g,clearCofactor:y}=t;return g===Ie?this:y?y(l,this):this.multiplyUnsafe(t.h)}toRawBytes(g=!0){return this.assertValidity(),r(l,this,g)}toHex(g=!0){return sr(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,h=Bp(l,t.endo?Math.ceil(d/2):d);return{CURVE:t,ProjectivePoint:l,normPrivateKeyToScalar:c,weierstrassEquation:o,isWithinCurveOrder:i}}function Pp(e){const t=rf(e);return yr(t,{hash:"hash",hmac:"function",randomBytes:"function"},{bits2int:"function",bits2int_modN:"function",lowS:"boolean"}),Object.freeze({lowS:!0,...t})}function Up(e){const t=Pp(e),{Fp:n,n:r}=t,s=n.BYTES+1,o=2*n.BYTES+1;function i(w){return ctsr(Qn(w,t.nByteLength));function p(w){const $=r>>Ie;return w>$}function g(w){return p(w)?a(-w):w}const y=(w,$,O)=>ln(w.slice($,O));class m{constructor($,O,L){this.r=$,this.s=O,this.recovery=L,this.assertValidity()}static fromCompact($){const O=t.nByteLength;return $=nt("compactSignature",$,O*2),new m(y($,0,O),y($,O,2*O))}static fromDER($){const{r:O,s:L}=An.toSig(nt("DER",$));return new m(O,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:O,s:L,recovery:U}=this,j=C(nt("msgHash",$));if(U==null||![0,1,2,3].includes(U))throw new Error("recovery id invalid");const M=U===2||U===3?O+t.n:O;if(M>=n.ORDER)throw new Error("recovery id 2 or 3 invalid");const z=(U&1)===0?"02":"03",ce=u.fromHex(z+h(M)),oe=c(M),Q=a(-j*oe),le=a(L*oe),de=u.BASE.multiplyAndAddUnsafe(ce,Q,le);if(!de)throw new Error("point at infinify");return de.assertValidity(),de}hasHighS(){return p(this.s)}normalizeS(){return this.hasHighS()?new m(this.r,a(-this.s),this.recovery):this}toDERRawBytes(){return or(this.toDERHex())}toDERHex(){return An.hexFromSig({r:this.r,s:this.s})}toCompactRawBytes(){return or(this.toCompactHex())}toCompactHex(){return h(this.r)+h(this.s)}}const v={isValidPrivateKey(w){try{return f(w),!0}catch{return!1}},normPrivateKeyToScalar:f,randomPrivateKey:()=>{const w=t.randomBytes(n.BYTES+8),$=_p(w,r);return Qn($,t.nByteLength)},precompute(w=8,$=u.BASE){return $._setWindowSize(w),$.multiply(BigInt(3)),$}};function b(w,$=!0){return u.fromPrivateKey(w).toRawBytes($)}function x(w){const $=w instanceof Uint8Array,O=typeof w=="string",L=($||O)&&w.length;return $?L===s||L===o:O?L===2*s||L===2*o:w instanceof u}function _(w,$,O=!0){if(x(w))throw new Error("first arg must be private key");if(!x($))throw new Error("second arg must be public key");return u.fromHex($).multiply(f(w)).toRawBytes(O)}const I=t.bits2int||function(w){const $=ln(w),O=w.length*8-t.nBitLength;return O>0?$>>BigInt(O):$},C=t.bits2int_modN||function(w){return a(I(w))},P=la(t.nBitLength);function B(w){if(typeof w!="bigint")throw new Error("bigint expected");if(!(ct<=w&&wue in O))throw new Error("sign() legacy options not supported");const{hash:L,randomBytes:U}=t;let{lowS:j,prehash:M,extraEntropy:z}=O;j==null&&(j=!0),w=nt("msgHash",w),M&&(w=nt("prehashed msgHash",L(w)));const ce=C(w),oe=f($),Q=[B(oe),B(ce)];if(z!=null){const ue=z===!0?U(n.BYTES):z;Q.push(nt("extraEntropy",ue,n.BYTES))}const le=at(...Q),de=ce;function _e(ue){const be=I(ue);if(!d(be))return;const Ot=c(be),et=u.BASE.multiply(be).toAffine(),Ne=a(et.x);if(Ne===ct)return;const Ct=a(Ot*a(de+Ne*oe));if(Ct===ct)return;let $r=(et.x===Ne?0:2)|Number(et.y&Ie),yc=Ct;return j&&p(Ct)&&(yc=g(Ct),$r^=1),new m(Ne,yc,$r)}return{seed:le,k2sig:_e}}const H={lowS:t.lowS,prehash:!1},K={lowS:t.lowS,prehash:!1};function E(w,$,O=H){const{seed:L,k2sig:U}=N(w,$,O);return ef(t.hash.outputLen,t.nByteLength,t.hmac)(L,U)}u.BASE._setWindowSize(8);function S(w,$,O,L=K){var et;const U=w;if($=nt("msgHash",$),O=nt("publicKey",O),"strict"in L)throw new Error("options.strict was renamed to lowS");const{lowS:j,prehash:M}=L;let z,ce;try{if(typeof U=="string"||U instanceof Uint8Array)try{z=m.fromDER(U)}catch(Ne){if(!(Ne instanceof An.Err))throw Ne;z=m.fromCompact(U)}else if(typeof U=="object"&&typeof U.r=="bigint"&&typeof U.s=="bigint"){const{r:Ne,s:Ct}=U;z=new m(Ne,Ct)}else throw new Error("PARSE");ce=u.fromHex(O)}catch(Ne){if(Ne.message==="PARSE")throw new Error("signature must be Signature instance, Uint8Array or hex string");return!1}if(j&&z.hasHighS())return!1;M&&($=t.hash($));const{r:oe,s:Q}=z,le=C($),de=c(Q),_e=a(le*de),ue=a(oe*de),be=(et=u.BASE.multiplyAndAddUnsafe(ce,_e,ue))==null?void 0:et.toAffine();return be?a(be.x)===oe:!1}return{CURVE:t,getPublicKey:b,getSharedSecret:_,sign:E,verify:S,ProjectivePoint:u,Signature:m,utils:v}}function Np(e,t){const n=e.ORDER;let r=ct;for(let d=n-Ie;d%Pt===ct;d/=Pt)r+=Ie;const s=r,o=(n-Ie)/Pt**s,i=(o-Ie)/Pt,a=Pt**s-Ie,c=Pt**(s-Ie),u=e.pow(t,o),f=e.pow(t,(o+Ie)/Pt);let l=(d,h)=>{let p=u,g=e.pow(h,a),y=e.sqr(g);y=e.mul(y,h);let m=e.mul(d,y);m=e.pow(m,i),m=e.mul(m,g),g=e.mul(m,h),y=e.mul(m,d);let v=e.mul(y,g);m=e.pow(v,c);let b=e.eql(m,e.ONE);g=e.mul(y,f),m=e.mul(v,p),y=e.cmov(g,y,b),v=e.cmov(m,v,b);for(let x=s;x>1;x--){let _=Pt**(x-Pt),I=e.pow(v,_);const C=e.eql(I,e.ONE);g=e.mul(y,p),p=e.mul(p,p),I=e.mul(v,p),y=e.cmov(g,y,C),v=e.cmov(I,v,C)}return{isValid:b,value:y}};if(e.ORDER%Sc===js){const d=(e.ORDER-js)/Sc,h=e.sqrt(e.neg(t));l=(p,g)=>{let y=e.sqr(g);const m=e.mul(p,g);y=e.mul(y,m);let v=e.pow(y,d);v=e.mul(v,m);const b=e.mul(v,h),x=e.mul(e.sqr(v),g),_=e.eql(x,p);let I=e.cmov(b,v,_);return{isValid:_,value:I}}}return l}function Lp(e,t){if(tf(e),!e.isValid(t.A)||!e.isValid(t.B)||!e.isValid(t.Z))throw new Error("mapToCurveSimpleSWU: invalid opts");const n=Np(e,t.Z);if(!e.isOdd)throw new Error("Fp.isOdd is not implemented!");return r=>{let s,o,i,a,c,u,f,l;s=e.sqr(r),s=e.mul(s,t.Z),o=e.sqr(s),o=e.add(o,s),i=e.add(o,e.ONE),i=e.mul(i,t.B),a=e.cmov(t.Z,e.neg(o),!e.eql(o,e.ZERO)),a=e.mul(a,t.A),o=e.sqr(i),u=e.sqr(a),c=e.mul(u,t.A),o=e.add(o,c),o=e.mul(o,i),u=e.mul(u,a),c=e.mul(u,t.B),o=e.add(o,c),f=e.mul(s,i);const{isValid:d,value:h}=n(o,u);l=e.mul(s,r),l=e.mul(l,h),f=e.cmov(f,i,d),l=e.cmov(l,h,d);const p=e.isOdd(r)===e.isOdd(l);return l=e.cmov(e.neg(l),l,p),f=e.div(f,a),{x:f,y:l}}}function Rp(e){if(e instanceof Uint8Array)return e;if(typeof e=="string")return wo(e);throw new Error("DST must be Uint8Array or string")}const Hp=ln;function sn(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 jp(e,t){const n=new Uint8Array(e.length);for(let r=0;r255&&(t=r(at(wo("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=at(t,sn(t.length,1)),c=sn(0,o),u=sn(n,2),f=new Array(i),l=r(at(c,e,u,sn(0,1),a));f[0]=r(at(l,sn(1,1),a));for(let h=1;h<=i;h++){const p=[jp(l,f[h-1]),sn(h+1,1),a];f[h]=r(at(...p))}return at(...f).slice(0,n)}function Dp(e,t,n,r,s){if(Nr(e),Nr(t),ha(n),t.length>255){const o=Math.ceil(2*r/8);t=s.create({dkLen:o}).update(wo("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(sn(n,2)).update(t).update(sn(t.length,1)).digest()}function $c(e,t,n){yr(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;Nr(e),ha(t);const u=Rp(c),f=r.toString(2).length,l=Math.ceil((f+s)/8),d=t*o*l;let h;if(a==="xmd")h=Kp(e,u,d,i);else if(a==="xof")h=Dp(e,u,d,s,i);else if(a===void 0)h=e;else throw new Error('expand must be "xmd", "xof" or undefined');const 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((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 Zp(e,t,n){if(typeof t!="function")throw new Error("mapToCurve() must be defined");return{hashToCurve(r,s){const o=$c(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=$c(r,1,{...n,DST:n.encodeDST,...s}),i=e.fromAffine(t(o[0])).clearCofactor();return i.assertValidity(),i}}}let sf=class extends Gu{constructor(t,n){super(),this.finished=!1,this.destroyed=!1,_n.hash(t);const r=aa(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 sf(e,t).update(n).digest();of.create=(e,t)=>new sf(e,t);/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */function Vp(e){return{hash:e,hmac:(t,...n)=>of(e,t,tp(...n)),randomBytes:np}}function qp(e,t){const n=r=>Up({...e,...Vp(r)});return Object.freeze({...n(t),create:n})}/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */const af=BigInt("0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f"),_c=BigInt("0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141"),zp=BigInt(1),_i=BigInt(2),Ac=(e,t)=>(e+t/_i)/t;function Fp(e){const t=af,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=tt(f,n,t)*f%t,d=tt(l,n,t)*f%t,h=tt(d,_i,t)*u%t,p=tt(h,s,t)*h%t,g=tt(p,o,t)*p%t,y=tt(g,a,t)*g%t,m=tt(y,c,t)*y%t,v=tt(m,a,t)*g%t,b=tt(v,n,t)*f%t,x=tt(b,i,t)*p%t,_=tt(x,r,t)*u%t,I=tt(_,_i,t);if(!hn.eql(hn.sqr(I),e))throw new Error("Cannot find square root");return I}const hn=nf(af,void 0,void 0,{sqrt:Fp}),Kt=qp({a:BigInt(0),b:BigInt(7),Fp:hn,n:_c,Gx:BigInt("55066263022277343669578718895168534326250603453777594175500187360389116729240"),Gy:BigInt("32670510020758816978083085130507043184471273380659243275938904335757337482424"),h:BigInt(1),lowS:!0,endo:{beta:BigInt("0x7ae96a2b657c07106e64479eac3434e99cf0497512f58995c1396c28719501ee"),splitScalar:e=>{const t=_c,n=BigInt("0x3086d221a7d46bcde86c90e49284eb15"),r=-zp*BigInt("0xe4437ed6010e88286f547fa90abfe4c3"),s=BigInt("0x114ca50f7a8e2f3f657c1108d9d44cfd8"),o=n,i=BigInt("0x100000000000000000000000000000000"),a=Ac(o*e,t),c=Ac(-r*e,t);let u=Ke(e-a*n-c*s,t),f=Ke(-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}}}},Xu);BigInt(0);Kt.ProjectivePoint;Kt.utils.randomPrivateKey;const Gp=Mp(hn,[["0x8e38e38e38e38e38e38e38e38e38e38e38e38e38e38e38e38e38e38daaaaa8c7","0x7d3d4c80bc321d5b9f315cea7fd44c5d595d2fc0bf63b92dfff1044f17c6581","0x534c328d23f234e6e2a413deca25caece4506144037c40314ecbd0b53d9dd262","0x8e38e38e38e38e38e38e38e38e38e38e38e38e38e38e38e38e38e38daaaaa88c"],["0xd35771193d94918a9ca34ccbb7b640dd86cd409542f8487d9fe6b745781eb49b","0xedadc6f64383dc1df7c4b2d51b54225406d36b641f5e41bbc52a56612a8c6d14","0x0000000000000000000000000000000000000000000000000000000000000001"],["0x4bda12f684bda12f684bda12f684bda12f684bda12f684bda12f684b8e38e23c","0xc75e0c32d5cb7c0fa9d0a54b12a0a6d5647ab046d686da6fdffc90fc201d71a3","0x29a6194691f91a73715209ef6512e576722830a201be2018a765e85a9ecee931","0x2f684bda12f684bda12f684bda12f684bda12f684bda12f684bda12f38e38d84"],["0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffefffff93b","0x7a06534bb8bdb49fd5e9e6632722c2989467c1bfc8e8d978dfb425d2685c2573","0x6484aa716545ca2cf3a70c3fa8fe337e0a3d21162f0d6299a7bf8192bfd2a76f","0x0000000000000000000000000000000000000000000000000000000000000001"]].map(e=>e.map(t=>BigInt(t)))),Wp=Lp(hn,{A:BigInt("0x3f8731abdd661adca08a5558f0f5d272e953d363cb6f0e5d405447c01a444533"),B:BigInt("1771"),Z:hn.create(BigInt("-11"))});Zp(Kt.ProjectivePoint,e=>{const{x:t,y:n}=Wp(hn.create(e[0]));return Gp(t,n)},{DST:"secp256k1_XMD:SHA-256_SSWU_RO_",encodeDST:"secp256k1_XMD:SHA-256_SSWU_NU_",p:hn.ORDER,m:1,k:128,expand:"xmd",hash:Xu});function Ai(e){if(!Number.isSafeInteger(e)||e<0)throw new Error(`Wrong positive integer: ${e}`)}function Yp(e){if(typeof e!="boolean")throw new Error(`Expected boolean, not ${e}`)}function cf(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 Xp(e){if(typeof e!="function"||typeof e.create!="function")throw new Error("Hash should be wrapped by utils.wrapConstructor");Ai(e.outputLen),Ai(e.blockLen)}function Jp(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 Qp(e,t){cf(e);const n=t.outputLen;if(e.lengthnew DataView(e.buffer,e.byteOffset,e.byteLength),wt=(e,t)=>e<<32-t|e>>>t,tg=new Uint8Array(new Uint32Array([287454020]).buffer)[0]===68;if(!tg)throw new Error("Non little-endian hardware is not supported");Array.from({length:256},(e,t)=>t.toString(16).padStart(2,"0"));function ng(e){if(typeof e!="string")throw new TypeError(`utf8ToBytes expected string, got ${typeof e}`);return new TextEncoder().encode(e)}function uf(e){if(typeof e=="string"&&(e=ng(e)),!(e instanceof Uint8Array))throw new TypeError(`Expected input type is Uint8Array (got ${typeof e})`);return e}let rg=class{clone(){return this._cloneInto()}};function ff(e){const t=r=>e().update(uf(r)).digest(),n=e();return t.outputLen=n.outputLen,t.blockLen=n.blockLen,t.create=()=>e(),t}function sg(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 og=class extends rg{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=Go(this.buffer)}update(t){Fo.exists(this);const{view:n,buffer:r,blockLen:s}=this;t=uf(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,ag=(e,t,n)=>e&t^e&n^t&n,cg=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]),Ft=new Uint32Array([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]),Gt=new Uint32Array(64);let lf=class extends og{constructor(){super(64,32,8,!1),this.A=Ft[0]|0,this.B=Ft[1]|0,this.C=Ft[2]|0,this.D=Ft[3]|0,this.E=Ft[4]|0,this.F=Ft[5]|0,this.G=Ft[6]|0,this.H=Ft[7]|0}get(){const{A:t,B:n,C:r,D:s,E:o,F:i,G:a,H:c}=this;return[t,n,r,s,o,i,a,c]}set(t,n,r,s,o,i,a,c){this.A=t|0,this.B=n|0,this.C=r|0,this.D=s|0,this.E=o|0,this.F=i|0,this.G=a|0,this.H=c|0}process(t,n){for(let l=0;l<16;l++,n+=4)Gt[l]=t.getUint32(n,!1);for(let l=16;l<64;l++){const d=Gt[l-15],h=Gt[l-2],p=wt(d,7)^wt(d,18)^d>>>3,g=wt(h,17)^wt(h,19)^h>>>10;Gt[l]=g+Gt[l-7]+p+Gt[l-16]|0}let{A:r,B:s,C:o,D:i,E:a,F:c,G:u,H:f}=this;for(let l=0;l<64;l++){const d=wt(a,6)^wt(a,11)^wt(a,25),h=f+d+ig(a,c,u)+cg[l]+Gt[l]|0,g=(wt(r,2)^wt(r,13)^wt(r,22))+ag(r,s,o)|0;f=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,f=f+this.H|0,this.set(r,s,o,i,a,c,u,f)}roundClean(){Gt.fill(0)}destroy(){this.set(0,0,0,0,0,0,0,0),this.buffer.fill(0)}},ug=class extends lf{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 Bi=ff(()=>new lf);ff(()=>new ug);function fg(e,t){if(e.length>t)throw new TypeError(`Data is larger than array size: ${e.length} > ${t}`)}function lg(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 dg(e){if(e>Number.MAX_SAFE_INTEGER)throw new TypeError("Number exceeds safe bounds!")}const{getRandomValues:hg}=crypto??globalThis.crypto??window.crypto;function pg(e=32){if(typeof hg=="function")return crypto.getRandomValues(new Uint8Array(e));throw new Error("Crypto module missing getRandomValues!")}function gg(e,t,n="be"){t===void 0&&(t=e.length),fg(e,t);const r=new Uint8Array(t).fill(0),s=n==="be"?0:t-e.length;return r.set(e,s),r}function df(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 wg(e,t){const n=hf(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 pf(e){return Bi(Bi(e))}function xg(e){const t=pf(e);return df([e,t.slice(0,4)])}function vg(e){const t=e.slice(0,-4),n=e.slice(-4);if(pf(t).slice(0,4).toString()!==n.toString())throw new Error("Invalid checksum!");return t}const Bc={encode:bg,decode:wg},gf={encode:e=>{const t=xg(e);return Bc.encode(t,"base58")},decode:e=>{const t=Bc.decode(e,"base58");return vg(t)}},mf="qpzry9x8gf2tvdw0s3jn54khce6mua7l",Eg=[996825010,642813549,513874426,1027748829,705979059],Ks=[{version:0,name:"bech32",const:1},{version:1,name:"bech32m",const:734539939}];function yf(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^=Eg[s])}return t}function bf(e){const t=[];let n;for(n=0;n>5);for(t.push(0),n=0;n>5*(5-i)&31);return o}function wf(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 $g(e,t,n){const r=t.concat(Sg(e,t,n));let s=e+"1";for(let o=0;oo.version===t[0])??Ks[0];if(!kg(r,t,s))throw new Error("Checksum verification failed!");return[r,t.slice(0,t.length-6)]}function _g(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 Ag(e){const t=e.lastIndexOf("1");return!(t<1||t+7>e.length||e.length>90)}function Bg(e,t="bc",n=0){const r=[n,...wf([...e],8,5)],s=Ks.find(i=>i.version===n)??Ks[0],o=$g(t,r,s);return vf(o),o}function vf(e){e=e.toLowerCase();const t=e.split("1",1)[0],[n,r]=xf(e),s=wf(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 Tg(e){e=e.toLowerCase();const[t,n]=xf(e);return n[0]}const Ef={encode:Bg,decode:vf,version:Tg},kf="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",Sf="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",Ig=new TextEncoder;function $f(e,t=!1,n=!0){typeof e=="string"&&(e=Ig.encode(e));const r=t?Sf:kf;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 _f(e,t=!1){const n=t||e.includes("-")||e.includes("_")?Sf.split(""):kf.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 Af={encode:$f,decode:_f},Bf={encode:e=>$f(e,!0,!1),decode:e=>_f(e,!0)},Og=BigInt(0),Cg=BigInt(255),Tf=BigInt(256);function Pg(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 Ug(e,t,n="be"){t===void 0&&(t=Pg(e));const r=n==="le",s=new ArrayBuffer(t),o=new DataView(s);let i=r?0:t-1;for(;e>Og;){const a=e&Cg,c=Number(a);r?o.setUint8(i++,c):o.setUint8(i--,c),e=(e-a)/Tf}return new Uint8Array(s)}function Ng(e){let t=BigInt(0);for(let n=e.length-1;n>=0;n--)t=t*Tf+BigInt(e[n]);return BigInt(t)}function Lg(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 Hg(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 jg(e,t,n="be"){t===void 0&&(t=Hg(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 Kg(e){let t=0;for(let n=e.length-1;n>=0;n--)t=t*256+e[n],dg(t);return t}const Dg=new TextEncoder,Mg=new TextDecoder;function pa(e){return Dg.encode(e)}function Wo(e){return Mg.decode(e)}function Zg(e,t){lg(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 Vg(e,t,n="le"){t=Zg(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 pa(t)}function Fg(e,t,n){if(e instanceof ArrayBuffer)return new Uint8Array(e);if(e instanceof Uint8Array)return gg(e,t,n);if(typeof e=="string")return Vg(e,t,n);if(typeof e=="bigint")return Ug(e,t,n);if(typeof e=="number")return jg(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=pg(t);return new re(n,t)}constructor(t,n,r){const s=Fg(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 im(this)}toNum(t="be"){const n=t==="be"?this.reverse():this;return Kg(n)}toBin(){return Rg(this)}toBig(t="be"){const n=t==="be"?this.reverse():this;return Ng(n)}toHash(){const t=Bi(this);return new re(t)}toJson(){const t=Wo(this);return JSON.parse(t)}toBech32(t,n=0){return Ef.encode(this,t,n)}toStr(){return Wo(this)}toHex(){return qg(this)}toBytes(){return new Uint8Array(this)}tob58chk(){return gf.encode(this)}toBase64(){return Af.encode(this)}toB64url(){return Bf.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=df(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=Gg,re.big=Yg,re.bin=Wg,re.raw=Xg,re.str=Jg,re.hex=Qg,re.bytes=em,re.json=tm,re.base64=nm,re.b64url=rm,re.bech32=sm,re.b58chk=om,re.encode=pa,re.decode=Wo;let Y=re;function Gg(e,t,n){return new Y(e,t,n)}function Wg(e,t,n){return new Y(Lg(e),t,n)}function Yg(e,t,n){return new Y(e,t,n)}function Xg(e,t,n){return new Y(e,t,n)}function Jg(e,t,n){return new Y(pa(e),t,n)}function Qg(e,t,n){return new Y(e,t,n)}function em(e,t,n){return new Y(e,t,n)}function tm(e){return new Y(zg(e))}function nm(e){return new Y(Af.decode(e))}function rm(e){return new Y(Bf.decode(e))}function sm(e){return new Y(Ef.decode(e))}function om(e){return new Y(gf.decode(e))}class im{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 Ds=Kt.CURVE,ga=Ds.n,am=Ds.p,cm={x:Ds.Gx,y:Ds.Gy},um=BigInt(0);BigInt(1);BigInt(2);BigInt(3);BigInt(4);const Ti={N:ga,P:am,G:cm,_0n:um},_r=nf(ga,32,!0),If=e=>Ke(e,ga);function ma(e,t=!1){if(t)throw new Error(e);return!1}function Of(e){return Y.random(e)}function fm(e){const t=Y.bytes(e).big;return Y.big(If(t),32)}var lm=Object.freeze({__proto__:null,fail:ma,mod_bytes:fm,random:Of});const{N:dm,_0n:hm}=Ti;function pm(e,t,n){const r=Y.bytes(e);return r.length!==t?ma(`Invalid byte size: ${r.hex} !== ${t}`,n):!0}function gm(e,t){return typeof e=="bigint"&&hmthis.big}lt(t){return new we(t).big0&&!t.includes(e.length))throw new Error(`Expected Uint8Array of length ${t}, not of length=${e.length}`)}function wm(e){if(typeof e!="function"||typeof e.create!="function")throw new Error("Hash should be wrapped by utils.wrapConstructor");Ii(e.outputLen),Ii(e.blockLen)}function xm(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 vm(e,t){Cf(e);const n=t.outputLen;if(e.lengthe instanceof Uint8Array,Yo=e=>new DataView(e.buffer,e.byteOffset,e.byteLength),xt=(e,t)=>e<<32-t|e>>>t,Sm=new Uint8Array(new Uint32Array([287454020]).buffer)[0]===68;if(!Sm)throw new Error("Non little-endian hardware is not supported");Array.from({length:256},(e,t)=>t.toString(16).padStart(2,"0"));function $m(e){if(typeof e!="string")throw new Error(`utf8ToBytes expected string, got ${typeof e}`);return new Uint8Array(new TextEncoder().encode(e))}function ya(e){if(typeof e=="string"&&(e=$m(e)),!km(e))throw new Error(`expected Uint8Array, got ${typeof e}`);return e}let Pf=class{clone(){return this._cloneInto()}};function Vn(e){const t=r=>e().update(ya(r)).digest(),n=e();return t.outputLen=n.outputLen,t.blockLen=n.blockLen,t.create=()=>e(),t}function _m(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 ba extends Pf{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=Yo(this.buffer)}update(t){Bn.exists(this);const{view:n,buffer:r,blockLen:s}=this;t=ya(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,Bm=(e,t,n)=>e&t^e&n^t&n,Tm=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]),Yt=new Uint32Array(64);let Uf=class extends ba{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 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],h=Yt[l-2],p=xt(d,7)^xt(d,18)^d>>>3,g=xt(h,17)^xt(h,19)^h>>>10;Yt[l]=g+Yt[l-7]+p+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=xt(a,6)^xt(a,11)^xt(a,25),h=f+d+Am(a,c,u)+Tm[l]+Yt[l]|0,g=(xt(r,2)^xt(r,13)^xt(r,22))+Bm(r,s,o)|0;f=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,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)}};class Im extends Uf{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 Ms=Vn(()=>new Uf);Vn(()=>new Im);const ps=BigInt(2**32-1),Oi=BigInt(32);function Nf(e,t=!1){return t?{h:Number(e&ps),l:Number(e>>Oi&ps)}:{h:Number(e>>Oi&ps)|0,l:Number(e&ps)|0}}function Om(e,t=!1){let n=new Uint32Array(e.length),r=new Uint32Array(e.length);for(let s=0;sBigInt(e>>>0)<>>0),Pm=(e,t,n)=>e>>>n,Um=(e,t,n)=>e<<32-n|t>>>n,Nm=(e,t,n)=>e>>>n|t<<32-n,Lm=(e,t,n)=>e<<32-n|t>>>n,Rm=(e,t,n)=>e<<64-n|t>>>n-32,Hm=(e,t,n)=>e>>>n-32|t<<64-n,jm=(e,t)=>t,Km=(e,t)=>e,Dm=(e,t,n)=>e<>>32-n,Mm=(e,t,n)=>t<>>32-n,Zm=(e,t,n)=>t<>>64-n,Vm=(e,t,n)=>e<>>64-n;function qm(e,t,n,r){const s=(t>>>0)+(r>>>0);return{h:e+n+(s/2**32|0)|0,l:s|0}}const zm=(e,t,n)=>(e>>>0)+(t>>>0)+(n>>>0),Fm=(e,t,n,r)=>t+n+r+(e/2**32|0)|0,Gm=(e,t,n,r)=>(e>>>0)+(t>>>0)+(n>>>0)+(r>>>0),Wm=(e,t,n,r,s)=>t+n+r+s+(e/2**32|0)|0,Ym=(e,t,n,r,s)=>(e>>>0)+(t>>>0)+(n>>>0)+(r>>>0)+(s>>>0),Xm=(e,t,n,r,s,o)=>t+n+r+s+o+(e/2**32|0)|0,Jm={fromBig:Nf,split:Om,toBig:Cm,shrSH:Pm,shrSL:Um,rotrSH:Nm,rotrSL:Lm,rotrBH:Rm,rotrBL:Hm,rotr32H:jm,rotr32L:Km,rotlSH:Dm,rotlSL:Mm,rotlBH:Zm,rotlBL:Vm,add:qm,add3L:zm,add3H:Fm,add4L:Gm,add4H:Wm,add5H:Xm,add5L:Ym};var ne=Jm;const[Qm,ey]=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))),Xt=new Uint32Array(80),Jt=new Uint32Array(80);let xo=class extends ba{constructor(){super(128,64,16,!1),this.Ah=1779033703,this.Al=-205731576,this.Bh=-1150833019,this.Bl=-2067093701,this.Ch=1013904242,this.Cl=-23791573,this.Dh=-1521486534,this.Dl=1595750129,this.Eh=1359893119,this.El=-1377402159,this.Fh=-1694144372,this.Fl=725511199,this.Gh=528734635,this.Gl=-79577749,this.Hh=1541459225,this.Hl=327033209}get(){const{Ah:t,Al:n,Bh:r,Bl:s,Ch:o,Cl:i,Dh:a,Dl:c,Eh:u,El:f,Fh:l,Fl:d,Gh:h,Gl:p,Hh:g,Hl:y}=this;return[t,n,r,s,o,i,a,c,u,f,l,d,h,p,g,y]}set(t,n,r,s,o,i,a,c,u,f,l,d,h,p,g,y){this.Ah=t|0,this.Al=n|0,this.Bh=r|0,this.Bl=s|0,this.Ch=o|0,this.Cl=i|0,this.Dh=a|0,this.Dl=c|0,this.Eh=u|0,this.El=f|0,this.Fh=l|0,this.Fl=d|0,this.Gh=h|0,this.Gl=p|0,this.Hh=g|0,this.Hl=y|0}process(t,n){for(let b=0;b<16;b++,n+=4)Xt[b]=t.getUint32(n),Jt[b]=t.getUint32(n+=4);for(let b=16;b<80;b++){const x=Xt[b-15]|0,_=Jt[b-15]|0,I=ne.rotrSH(x,_,1)^ne.rotrSH(x,_,8)^ne.shrSH(x,_,7),C=ne.rotrSL(x,_,1)^ne.rotrSL(x,_,8)^ne.shrSL(x,_,7),P=Xt[b-2]|0,B=Jt[b-2]|0,N=ne.rotrSH(P,B,19)^ne.rotrBH(P,B,61)^ne.shrSH(P,B,6),H=ne.rotrSL(P,B,19)^ne.rotrBL(P,B,61)^ne.shrSL(P,B,6),K=ne.add4L(C,H,Jt[b-7],Jt[b-16]),E=ne.add4H(K,I,N,Xt[b-7],Xt[b-16]);Xt[b]=E|0,Jt[b]=K|0}let{Ah:r,Al:s,Bh:o,Bl:i,Ch:a,Cl:c,Dh:u,Dl:f,Eh:l,El:d,Fh:h,Fl:p,Gh:g,Gl:y,Hh:m,Hl:v}=this;for(let b=0;b<80;b++){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),I=l&h^~l&g,C=d&p^~d&y,P=ne.add5L(v,_,C,ey[b],Jt[b]),B=ne.add5H(P,m,x,I,Qm[b],Xt[b]),N=P|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),E=r&o^r&a^o&a,S=s&i^s&c^i&c;m=g|0,v=y|0,g=h|0,y=p|0,h=l|0,p=d|0,{h:l,l:d}=ne.add(u|0,f|0,B|0,N|0),u=a|0,f=c|0,a=o|0,c=i|0,o=r|0,i=s|0;const w=ne.add3L(N,K,S);r=ne.add3H(w,B,H,E),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: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,l:p}=ne.add(this.Fh|0,this.Fl|0,h|0,p|0),{h:g,l:y}=ne.add(this.Gh|0,this.Gl|0,g|0,y|0),{h:m,l:v}=ne.add(this.Hh|0,this.Hl|0,m|0,v|0),this.set(r,s,o,i,a,c,u,f,l,d,h,p,g,y,m,v)}roundClean(){Xt.fill(0),Jt.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 ty extends xo{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 ny extends xo{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 ry extends xo{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 sy=Vn(()=>new xo);Vn(()=>new ty);Vn(()=>new ny);Vn(()=>new ry);const oy=new Uint8Array([7,4,13,1,10,6,15,3,12,0,9,5,2,14,11,8]),Lf=Uint8Array.from({length:16},(e,t)=>t),iy=Lf.map(e=>(9*e+5)%16);let wa=[Lf],xa=[iy];for(let e=0;e<4;e++)for(let t of[wa,xa])t.push(t[e].map(n=>oy[n]));const Rf=[[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)),ay=wa.map((e,t)=>e.map(n=>Rf[t][n])),cy=xa.map((e,t)=>e.map(n=>Rf[t][n])),uy=new Uint32Array([0,1518500249,1859775393,2400959708,2840853838]),fy=new Uint32Array([1352829926,1548603684,1836072691,2053994217,0]),gs=(e,t)=>e<>>32-t;function Ic(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);let ly=class extends ba{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)ms[h]=t.getUint32(n,!0);let r=this.h0|0,s=r,o=this.h1|0,i=o,a=this.h2|0,c=a,u=this.h3|0,f=u,l=this.h4|0,d=l;for(let h=0;h<5;h++){const p=4-h,g=uy[h],y=fy[h],m=wa[h],v=xa[h],b=ay[h],x=cy[h];for(let _=0;_<16;_++){const I=gs(r+Ic(h,o,a,u)+ms[m[_]]+g,b[_])+l|0;r=l,l=u,u=gs(a,10)|0,a=o,o=I}for(let _=0;_<16;_++){const I=gs(s+Ic(p,i,c,f)+ms[v[_]]+y,x[_])+d|0;s=d,d=f,f=gs(c,10)|0,c=i,i=I}}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(){ms.fill(0)}destroy(){this.destroyed=!0,this.buffer.fill(0),this.set(0,0,0,0,0)}};const dy=Vn(()=>new ly);let Hf=class extends Pf{constructor(t,n){super(),this.finished=!1,this.destroyed=!1,Bn.hash(t);const r=ya(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 Hf(e,t).update(n).digest();jf.create=(e,t)=>new Hf(e,t);function hy(e){const t=Y.bytes(e);return Y.raw(Ms(t))}function ir(e){const t=Y.bytes(e);return Y.raw(Ms(Ms(t)))}function va(e){const t=Y.bytes(e);return Y.raw(dy(Ms(t)))}function py(e,t){const n=Y.bytes(e),r=Y.bytes(t);return Y.raw(jf(sy,n,r))}function gy(e){const t=Y.str(e).digest;return Y.join([t,t])}function my(e=32){return Ea(Of(e))}function Ea(e){return Ve.mod(e).buff}function Kf(e,t=!1){const n=Ve.mod(e).point;return t?n.x:n.buff}function Df(e,t){const n=Zn.from_x(t),r=Ve.mod(e);return n.mul(r).buff}function yy(e,t,n="ecdh/code"){const r=gy(n),s=Ea(e),o=Kf(s),i=Y.bytes(t),a=Df(s,i),c=[o.hex,i.hex];return c.sort(),py(a,Y.join([r,...c]))}function by(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 wy(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 xy=Object.freeze({__proto__:null,genSecretKey:my,getPublicKey:Kf,getSecretKey:Ea,getSharedCode:yy,getSharedKey:Df,is_even_pub:by,xonly_pub:wy});Y.random(32);const Mf={secp:Kt},Ci={...xy,...lm};function vo(e){const t=k.bytes(e);return It(t,33),va(t)}function Zf(e){const t=$e.fmt.toBytes(e,!1);return va(t)}function Vf(e){const t=$e.fmt.toBytes(e,!1);return hy(t)}function qf(e,t="main"){const n=t==="main"?["1"]:["m","n"];for(const r of n)if(e.startsWith(r))return!0;return!1}function zf(e,t="main"){const n=k.bytes(e),r=t==="main"?k.num(0):k.num(111);return It(e,20),n.prepend(r).tob58chk()}function vy(e,t="main"){if(!qf(e,t))throw new TypeError("Invalid p2pkh address!");return k.b58chk(e).slice(1)}function Ey(e){const t=k.bytes(e);return It(t,20),["OP_DUP","OP_HASH160",t.hex,"OP_EQUALVERIFY","OP_CHECKSIG"]}function ky(e,t){const n=vo(e);return zf(n,t)}const Ff={check:qf,encode:zf,decode:vy,hash:vo,scriptPubKey:Ey,fromPubKey:ky};function Gf(e,t="main"){const n=t==="main"?["3"]:["2"];for(const r of n)if(e.startsWith(r))return!0;return!1}function Wf(e,t="main"){const n=t==="main"?k.num(5):k.num(196),r=k.bytes(e);return It(r,20),r.prepend(n).tob58chk()}function Sy(e,t="main"){if(!Gf(e,t))throw new TypeError(`Invalid p2sh address for network ${t}:`+e);return k.b58chk(e).slice(1)}function $y(e){return["OP_HASH160",k.bytes(e).hex,"OP_EQUAL"]}function _y(e,t){const n=Zf(e);return Wf(n,t)}const Yf={check:Gf,encode:Wf,decode:Sy,hash:Zf,scriptPubKey:$y,fromScript:_y},ka={main:"bc",testnet:"tb",signet:"tb",regtest:"bcrt"},Ay=["bc1q","tb1q","bcrt1q"];function Xf(e){for(const t of Ay)if(e.startsWith(t))return!0;return!1}function Jf(e,t="main"){const n=ka[t],r=k.bytes(e);return It(r,20),r.toBech32(n,0)}function By(e){if(!Xf(e))throw new TypeError("Invalid segwit address!");return k.bech32(e)}function Ty(e){const t=k.bytes(e);return It(t,20),["OP_0",t.hex]}function Iy(e,t){const n=vo(e);return Jf(n,t)}const Qf={check:Xf,encode:Jf,decode:By,hash:vo,scriptPubKey:Ty,fromPubKey:Iy},Oy=["bc1q","tb1q","bcrt1q"];function el(e){for(const t of Oy)if(e.startsWith(t))return!0;return!1}function tl(e,t="main"){const n=ka[t],r=k.bytes(e);return It(r,32),r.toBech32(n,0)}function Cy(e){if(!el(e))throw new TypeError("Invalid segwit address!");return k.bech32(e)}function Py(e){const t=k.bytes(e);return It(t,32),["OP_0",t.hex]}function Uy(e,t){const n=Vf(e);return tl(n,t)}const nl={check:el,encode:tl,decode:Cy,hash:Vf,scriptPubKey:Py,fromScript:Uy};function Nn(e){const t=k.bytes(e);return t.length>32?t.slice(1,33):t}const Ny=["bc1p","tb1p","bcrt1p"];function rl(e){for(const t of Ny)if(e.startsWith(t))return!0;return!1}function sl(e,t="main"){const n=ka[t],r=k.bytes(e);return It(r,32),r.toBech32(n,1)}function Ly(e){if(!rl(e))throw new TypeError("Invalid taproot address!");return k.bech32(e)}function Ry(e){const t=k.bytes(e);return It(t,32),["OP_1",t.hex]}function Hy(e,t){const n=Nn(e);return sl(n,t)}const ol={check:rl,encode:sl,decode:Ly,scriptPubKey:Ry,fromPubKey:Hy},jy={version:2,vin:[],vout:[],locktime:0},Ky={scriptSig:[],sequence:4294967293,witness:[]},Dy={value:0n,scriptPubKey:[]};function Sa(e){const t={...jy,...e};return t.vin=t.vin.map(n=>({...Ky,...n})),t.vout=t.vout.map(n=>({...Dy,...n})),t}function ar(e,t){const{version:n,vin:r,vout:s,locktime:o}=Sa(e),i=t!==!0&&My(r),a=[$a(n)];i&&a.push(k.hex("0001")),a.push(Zy(r)),a.push(Vy(s));for(const c of r)i&&a.push(zy(c.witness));return a.push(_a(o)),k.join(a)}function My(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 $a(e){return k.num(e,4).reverse()}function es(e){return k.hex(e,32).reverse()}function ts(e){return k.num(e,4).reverse()}function ns(e){if(typeof e=="string")return k.hex(e,4).reverse();if(typeof e=="number")return k.num(e,4).reverse();throw new Error("Unrecognized format: "+String(e))}function Zy(e){const t=[k.varInt(e.length,"le")];for(const n of e){const{txid:r,vout:s,scriptSig:o,sequence:i}=n;t.push(es(r)),t.push(ts(s)),t.push(Mn(o,!0)),t.push(ns(i))}return k.join(t)}function pn(e){if(typeof e=="number"){if(e%1!==0)throw new Error("Value must be an integer:"+String(e));return k.num(e,8).reverse()}return k.big(e,8).reverse()}function Vy(e){const t=[k.varInt(e.length,"le")];for(const n of e)t.push(qy(n));return k.join(t)}function qy(e){const{value:t,scriptPubKey:n}=e,r=[];return r.push(pn(t)),r.push(Mn(n,!0)),k.join(r)}function zy(e=[]){const t=[];if(Array.isArray(e)){const n=k.varInt(e.length);t.push(n);for(const r of e)t.push(Fy(r));return k.join(t)}else return k.bytes(e)}function Fy(e){return Gy(e)?new k(0):Mn(e,!0)}function Gy(e){if(Array.isArray(e))return e.length===0;if(typeof e=="string"&&e==="")return!0;const t=k.bytes(e);return t.length===1&&t[0]===0}function _a(e){if(typeof e=="string")return k.hex(e,4);if(typeof e=="number")return k.num(e,4).reverse();throw new Error("Unrecognized format: "+String(e))}function Aa(e){typeof e=="string"&&(e=k.hex(e).raw);const t=new mr(e),n=Wy(t),r=Yy(t),s=Xy(t),o=Qy(t);if(r)for(const a of s)a.witness=tb(t);const i=nb(t);return{version:n,vin:s,vout:o,locktime:i}}function Wy(e){return e.read(4).reverse().toNum()}function Yy(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 Xy(e){const t=[],n=e.readSize("le");for(let r=0;r0?e.read(n).hex:null}function al(e,t){const n=il(e);return n!==null?n:[]}function nb(e){return e.read(4).reverse().toNum()}function rb(e){if(qu(e))return Aa(e);if(typeof e=="object"&&!(e instanceof Uint8Array))return ar(e),Sa(e);throw new Error("Invalid format: "+typeof e)}function sb(e){if(qu(e))return Aa(e),k.bytes(e);if(typeof e=="object")return ar(e);throw new Error("Invalid format: "+typeof e)}const Ba={toBytes:sb,toJson:rb},ob=[["p2pkh",/^76a914(?\w{40})88ac$/],["p2sh",/^a914(?\w{40})87$/],["p2w-pkh",/^0014(?\w{40})$/],["p2w-sh",/^0020(?\w{64})$/],["p2tr",/^5120(?\w{64})$/]],ib=[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 ab(e){let t=e.at(-1);return Mt(t)&&(t=k.hex(t)),e.length>1&&t instanceof Uint8Array&&t[0]===80?(e.pop(),k.raw(t)):null}function cb(e){let t=e.at(-1);return Mt(t)&&(t=k.hex(t)),e.length>1&&t instanceof Uint8Array&&t.length>32&&ib.includes(t[0]&254)?(e.pop(),k.raw(t)):null}function ub(e){if(e.length>1){const t=e.at(-1);try{const n=$e.fmt.toBytes(t);return e.pop(),n}catch{return null}}return null}function fb(e){const t=[];for(const n of e)if(Mt(n)||n instanceof Uint8Array||typeof n=="number")t.push(k.bytes(n));else throw new Error("unrecognized value: "+String(n));return t}function lb(e=[]){const t=[...e],n=ab(t),r=cb(t),s=ub(t),o=fb(t);return{annex:n,cblock:r,script:s,params:o}}function db(e){const t=$e.fmt.toBytes(e,!1).hex;for(const[n,r]of ob){const s=n,{groups:o}=r.exec(t)??{},{hash:i}=o??{};if(Mt(i))return{type:s,data:k.hex(i)}}return{type:"raw",data:k.hex(t)}}function hb(e){const t=Ba.toJson(e),n=ar(t,!0);return ir(n).reverse().hex}function pb(e){const t=Ba.toJson(e),n=ar(t,!0).length,r=ar(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:Sa,encode:ar,decode:Aa,fmt:Ba,util:{getTxSize:pb,getTxid:hb,readScriptPubKey:db,readWitness:lb}},gb=[["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 mb(e,t){switch(t){case"base58":return k.b58chk(e).slice(1);case"bech32":return k.bech32(e);case"bech32m":return k.bech32(e);default:throw new Error("Invalid address format: "+t)}}function yb(e){for(const t of gb){const[n,r,s,o,i]=t;if(e.startsWith(n)&&mb(e,i).length===o)return t}throw new Error("Invalid address: "+e)}function cl(e){switch(e){case"p2pkh":return Ff;case"p2sh":return Yf;case"p2w-pkh":return Qf;case"p2w-sh":return nl;case"p2tr":return ol;default:throw new Error("Invalid address type: "+e)}}function ul(e){const[t,n,r]=yb(e),s=cl(n),o=s.decode(e,r),i=s.scriptPubKey(o);return{prefix:t,type:n,network:r,data:o,script:i}}function bb(e,t){const{type:n,data:r}=ie.util.readScriptPubKey(e);return cl(n).encode(r,t)}function wb(e){const{script:t}=ul(e);return $e.fmt.toAsm(t,!1)}const Lr={p2pkh:Ff,p2sh:Yf,p2wpkh:Qf,p2wsh:nl,p2tr:ol,decode:ul,fromScriptPubKey:bb,toScriptPubKey:wb},xb=[1,2,3];function Ta(e,t,n={}){const{sigflag:r=1}=n,s=(r&128)===128,o=r%128;if(!xb.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:h,sequence:p}=c[t],{value:g}=h??{};if(g===void 0)throw new Error("Prevout value is empty!");let y=n.script;if(y===void 0&&n.pubkey!==void 0&&(y=`76a914${va(n.pubkey).hex}88ac`),y===void 0)throw new Error("No pubkey / script has been set!");if($e.fmt.toAsm(y).includes("OP_CODESEPARATOR"))throw new Error("This library does not currently support the use of OP_CODESEPARATOR in segwit scripts.");const m=[$a(a),vb(c,s),Eb(c,o,s),es(l),ts(d),$e.encode(y,!0),pn(g),ns(p),kb(u,t,o),_a(f),k.num(r,4).reverse()];return ir(k.join(m))}function vb(e,t){if(t===!0)return k.num(0,32);const n=[];for(const{txid:r,vout:s}of e)n.push(es(r)),n.push(ts(s));return ir(k.join(n))}function Eb(e,t,n){if(n||t!==1)return k.num(0,32);const r=[];for(const{sequence:s}of e)r.push(ns(s));return ir(k.join(r))}function kb(e,t,n){const r=[];if(n===1){for(const{value:s,scriptPubKey:o}of e)r.push(pn(s)),r.push($e.encode(o,!0));return ir(k.join(r))}if(n===3&&t1&&c[1].length===33)u=k.bytes(c[1]);else return je("No pubkey provided!",s);const f=$e.fmt.toParam(c[0]),l=f.slice(0,-1),d=f.slice(-1)[0],h=Ta(r,t,{...n,sigflag:d});return Mf.secp.verify(l,h,u)?!0:je("Invalid signature!",s)}const _b={hash:Ta,sign:Sb,verify:$b},Ab=[0,1,2,3,129,130,131];function Ia(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(!Ab.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:y=[]}=f[t],m=(s&128)===128,v=Ub(y),b=v!==void 0?1:0,_=(o+(r!==void 0?1:0))*2+b,I=k.str("TapSighash").digest,C=[I,I,k.num(0,1),k.num(s,1),$a(u),_a(d)];if(!m){const P=f.map(B=>Oc(B));C.push(Bb(f),Ib(P),Ob(P),Tb(f))}if(((s&3)<2||(s&3)>3)&&C.push(Cb(l)),C.push(k.num(_,1)),m){const{value:P,scriptPubKey:B}=Oc(f[t]);C.push(es(h),ts(p),pn(P),$e.encode(B,!0),ns(g))}else C.push(k.num(t,4).reverse());return v!==void 0&&C.push(v),(s&3)===3&&C.push(Pb(l[t])),r!==void 0&&C.push(k.bytes(r),k.num(i),k.num(a,4,"le")),k.join(C).digest}function Bb(e){const t=[];for(const{txid:n,vout:r}of e)t.push(es(n)),t.push(ts(r));return k.join(t).digest}function Tb(e){const t=[];for(const{sequence:n}of e)t.push(ns(n));return k.join(t).digest}function Ib(e){const t=[];for(const{value:n}of e)t.push(pn(n));return k.join(t).digest}function Ob(e){const t=[];for(const{scriptPubKey:n}of e)t.push(Mn(n,!0));return k.join(t).digest}function Cb(e){const t=[];for(const{value:n,scriptPubKey:r}of e)t.push(pn(n)),t.push($e.encode(r,!0));return k.join(t).digest}function Pb(e){return k.join([pn(e.value),$e.encode(e.scriptPubKey,!0)]).digest}function Ub(e){if(e===void 0||e.length<2)return;let t=e.at(-1);if(typeof t=="string"&&(t=k.hex(t)),t instanceof Uint8Array&&t[0]===80)return k.raw(t).prefixSize("be").digest}function Oc(e){if(e.prevout===void 0)throw new Error("Prevout data missing for input: "+String(e.txid));return e.prevout}const Nb=0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2fn,Lb=0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141n;function Rb(e,t,n,r={}){const{sigflag:s=0}=r,o=Ia(t,n,r),i=Hb(e,o);return s===0?k.raw(i):k.join([i,s])}function Hb(e,t,n=k.random(32)){const r=k.bytes(t),s=new Ve(e),o=s.point,i=o.hasEvenY?s.big:s.negated.big,a=Cs("BIP0340/aux",k.bytes(n)),c=i^a.big,u=Cs("BIP0340/nonce",c,o.x.raw,r),f=new Ve(u),l=f.point,d=l.hasEvenY?f.big:f.negated.big,h=new Ve(Cs("BIP0340/challenge",l.x.raw,o.x.raw,r)),p=new Ve(d+h.big*i);return k.join([l.x.raw,p.raw])}function jb(e,t,n,r=!1){const s=Zn.from_x(Nn(n)),o=k.bytes(t),i=k.bytes(e).stream;i.size<64&&je("Signature length is too small: "+String(i.size),r);const a=i.read(32);a.big>Nb&&je("Signature r value greater than field size!",r);const c=i.read(32);c.big>Lb&&je("Signature s value greater than curve order!",r);const u=new Ve(Cs("BIP0340/challenge",a.raw,s.x.raw,o)),f=new Ve(c).point,l=s.mul(u.big),d=f.sub(l);return d.hasOddY&&je("Signature R value has odd Y coordinate!",r),d.x.big===0n&&je("Signature R value is infinite!",r),d.x.big===a.big}const Kb=192;function Eo(e){const t=k.str(e).digest;return k.join([t,t])}function Oa(e,t=Kb){return k.join([Eo("TapLeaf"),Zb(t),k.bytes(e)]).digest.hex}function Db(e,t){return Oa($e.fmt.toBytes(e),t)}function Ca(e,t){return t0){const[h,p,g]=Zs(r,i);c=g,a=er(e,h,n)}else i!==void 0?a=er(e,i,n):a=er(e,void 0,n);const u=n?Ci.getPublicKey(a)[0]:a[0],l=[k.num(s+gl(u)),o];c.length>0&&c.forEach(h=>l.push(k.hex(h)));const d=k.join(l);if(i!==void 0&&!Pa(a,i,d,t))throw new Error("Path checking failed! Unable to generate path.");return[Nn(a).hex,d.hex]}function Pa(e,t,n,r={}){const{isPrivate:s=!1,throws:o=!1}=r,{parity:i,paths:a,intkey:c}=pl(n),u=s?Ci.getPublicKey(e,!0):Nn(e),f=k.join([i,u]);if(f.length!==33)return je("Invalid tapkey: "+f.hex,o);let l=k.bytes(t).hex;for(const h of a)l=Ca(l,h);const d=er(c,l);return k.raw(d).hex===k.raw(f).hex}function pl(e){const t=new mr(k.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 gl(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 Xb(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 je("Invalid witness data: "+String(i),s);const{scriptPubKey:d}=o??{};if(d===void 0)return je("Prevout scriptPubKey is empty!",s);const{type:h,data:p}=ie.util.readScriptPubKey(d);if(h!=="p2tr")return je("Prevout script is not a valid taproot output:"+p.hex,s);if(p.length!==32)return je("Invalid tapkey length: "+String(p.length),s);if(c!==null&&u!==null){const b=c[0]&254,x=Oa(u,b);if(n.extension=x,!Pa(p,x,c,{throws:s}))return je("cblock verification failed!",s)}n.pubkey!==void 0?l=k.bytes(n.pubkey):f.length>1&&f[1].length===32?l=k.bytes(f[1]):l=k.bytes(p);const g=$e.fmt.toParam(f[0]),y=new mr(g),m=y.read(64).raw;if(y.size===1&&(n.sigflag=y.read(1).num,n.sigflag===0))return je("0x00 is not a valid appended sigflag!",s);const v=Ia(r,t,n);return jb(m,v,l,s)?!0:je("Invalid signature!",s)}const Jb={hash:Ia,sign:Rb,verify:Xb},ko={segwit:_b,taproot:Jb},Qb={getTag:Eo,getLeaf:Oa,getBranch:Ca,getRoot:Mb},ew={readCtrlBlock:pl,readParityBit:gl},tw={getPubKey:Vb,getSecKey:qb,getTweak:fl,tweakSecKey:ll,tweakPubKey:dl},Vs={getPubKey:Yb,getSecKey:Wb,encodeScript:Db,checkPath:Pa,tree:Qb,tweak:tw,util:ew,SCRIPT_PUBKEY:Fb};var he;(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})(he||(he={}));var Pi;(function(e){e.mergeShapes=(t,n)=>({...t,...n})})(Pi||(Pi={}));const Z=he.arrayToEnum(["string","nan","number","integer","float","boolean","date","bigint","symbol","function","undefined","null","array","object","unknown","promise","void","never","map","set"]),an=e=>{switch(typeof e){case"undefined":return 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=he.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"]),nw=e=>JSON.stringify(e,null,2).replace(/"([^"]+)":/g,"$1:");class lt 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()}}lt.create=e=>new lt(e);const Rr=(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,he.jsonStringifyReplacer)}`;break;case R.unrecognized_keys:n=`Unrecognized key(s) in object: ${he.joinValues(e.keys,", ")}`;break;case R.invalid_union:n="Invalid input";break;case R.invalid_union_discriminator:n=`Invalid discriminator value. Expected ${he.joinValues(e.options)}`;break;case R.invalid_enum_value:n=`Invalid enum value. Expected ${he.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}"`:he.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,he.assertNever(e)}return{message:n}};let ml=Rr;function rw(e){ml=e}function qs(){return ml}const zs=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}},sw=[];function V(e,t){const n=zs({issueData:t,data:e.data,path:e.path,errorMaps:[e.common.contextualErrorMap,e.schemaErrorMap,qs(),Rr].filter(r=>!!r)});e.common.issues.push(n)}class Ze{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 X;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 Ze.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 X;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 X=Object.freeze({status:"aborted"}),yl=e=>({status:"dirty",value:e}),Fe=e=>({status:"valid",value:e}),Ui=e=>e.status==="aborted",Ni=e=>e.status==="dirty",Fs=e=>e.status==="valid",Gs=e=>typeof Promise<"u"&&e instanceof Promise;var G;(function(e){e.errToObj=t=>typeof t=="string"?{message:t}:t||{},e.toString=t=>typeof t=="string"?t:t==null?void 0:t.message})(G||(G={}));class At{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 Cc=(e,t)=>{if(Fs(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 lt(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 an(t.data)}_getOrReturnCtx(t,n){return n||{common:t.parent.common,data:t.data,parsedType:an(t.data),schemaErrorMap:this._def.errorMap,path:t.path,parent:t.parent}}_processInputParams(t){return{status:new Ze,ctx:{common:t.parent.common,data:t.data,parsedType:an(t.data),schemaErrorMap:this._def.errorMap,path:t.path,parent:t.parent}}}_parseSync(t){const n=this._parse(t);if(Gs(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:an(t)},o=this._parseSync({data:t,path:s.path,parent:s});return Cc(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:an(t)},s=this._parse({data:t,path:r.path,parent:r}),o=await(Gs(s)?s:Promise.resolve(s));return Cc(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 pt({schema:this,typeName:W.ZodEffects,effect:{type:"refinement",refinement:t}})}superRefine(t){return this._refinement(t)}optional(){return Ht.create(this,this._def)}nullable(){return Hn.create(this,this._def)}nullish(){return this.nullable().optional()}array(){return dt.create(this,this._def)}promise(){return ur.create(this,this._def)}or(t){return Dr.create([this,t],this._def)}and(t){return Mr.create(this,t,this._def)}transform(t){return new pt({...te(this._def),schema:this,typeName:W.ZodEffects,effect:{type:"transform",transform:t}})}default(t){const n=typeof t=="function"?t:()=>t;return new Fr({...te(this._def),innerType:this,defaultValue:n,typeName:W.ZodDefault})}brand(){return new wl({typeName:W.ZodBranded,type:this,...te(this._def)})}catch(t){const n=typeof t=="function"?t:()=>t;return new Js({...te(this._def),innerType:this,catchValue:n,typeName:W.ZodCatch})}describe(t){const n=this.constructor;return new n({...this._def,description:t})}pipe(t){return rs.create(this,t)}isOptional(){return this.safeParse(void 0).success}isNullable(){return this.safeParse(null).success}}const ow=/^c[^\s-]{8,}$/i,iw=/^[a-z][a-z0-9]*$/,aw=/[0-9A-HJKMNP-TV-Z]{26}/,cw=/^([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,uw=/^(([^<>()[\]\\.,;:\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,})+))$/,fw=new RegExp("^(\\p{Extended_Pictographic}|\\p{Emoji_Component})+$","u"),lw=/^(((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}))$/,dw=/^(([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})))$/,hw=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 pw(e,t){return!!((t==="v4"||!t)&&lw.test(e)||(t==="v6"||!t)&&dw.test(e))}class ut extends se{constructor(){super(...arguments),this._regex=(t,n,r)=>this.refinement(s=>t.test(s),{validation:n,code:R.invalid_string,...G.errToObj(r)}),this.nonempty=t=>this.min(1,G.errToObj(t)),this.trim=()=>new ut({...this._def,checks:[...this._def.checks,{kind:"trim"}]}),this.toLowerCase=()=>new ut({...this._def,checks:[...this._def.checks,{kind:"toLowerCase"}]}),this.toUpperCase=()=>new ut({...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}),X}const r=new Ze;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,...G.errToObj(t==null?void 0:t.message)})}regex(t,n){return this._addCheck({kind:"regex",regex:t,...G.errToObj(n)})}includes(t,n){return this._addCheck({kind:"includes",value:t,position:n==null?void 0:n.position,...G.errToObj(n==null?void 0:n.message)})}startsWith(t,n){return this._addCheck({kind:"startsWith",value:t,...G.errToObj(n)})}endsWith(t,n){return this._addCheck({kind:"endsWith",value:t,...G.errToObj(n)})}min(t,n){return this._addCheck({kind:"min",value:t,...G.errToObj(n)})}max(t,n){return this._addCheck({kind:"max",value:t,...G.errToObj(n)})}length(t,n){return this._addCheck({kind:"length",value:t,...G.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 ut({checks:[],typeName:W.ZodString,coerce:(t=e==null?void 0:e.coerce)!==null&&t!==void 0?t:!1,...te(e)})};function gw(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 gn 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}),X}let r;const s=new Ze;for(const o of this._def.checks)o.kind==="int"?he.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"?gw(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()):he.assertNever(o);return{status:s.value,value:t.data}}gte(t,n){return this.setLimit("min",t,!0,G.toString(n))}gt(t,n){return this.setLimit("min",t,!1,G.toString(n))}lte(t,n){return this.setLimit("max",t,!0,G.toString(n))}lt(t,n){return this.setLimit("max",t,!1,G.toString(n))}setLimit(t,n,r,s){return new gn({...this._def,checks:[...this._def.checks,{kind:t,value:n,inclusive:r,message:G.toString(s)}]})}_addCheck(t){return new gn({...this._def,checks:[...this._def.checks,t]})}int(t){return this._addCheck({kind:"int",message:G.toString(t)})}positive(t){return this._addCheck({kind:"min",value:0,inclusive:!1,message:G.toString(t)})}negative(t){return this._addCheck({kind:"max",value:0,inclusive:!1,message:G.toString(t)})}nonpositive(t){return this._addCheck({kind:"max",value:0,inclusive:!0,message:G.toString(t)})}nonnegative(t){return this._addCheck({kind:"min",value:0,inclusive:!0,message:G.toString(t)})}multipleOf(t,n){return this._addCheck({kind:"multipleOf",value:t,message:G.toString(n)})}finite(t){return this._addCheck({kind:"finite",message:G.toString(t)})}safe(t){return this._addCheck({kind:"min",inclusive:!0,value:Number.MIN_SAFE_INTEGER,message:G.toString(t)})._addCheck({kind:"max",inclusive:!0,value:Number.MAX_SAFE_INTEGER,message:G.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"&&he.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 gn({checks:[],typeName:W.ZodNumber,coerce:(e==null?void 0:e.coerce)||!1,...te(e)});class mn 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}),X}let r;const s=new Ze;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()):he.assertNever(o);return{status:s.value,value:t.data}}gte(t,n){return this.setLimit("min",t,!0,G.toString(n))}gt(t,n){return this.setLimit("min",t,!1,G.toString(n))}lte(t,n){return this.setLimit("max",t,!0,G.toString(n))}lt(t,n){return this.setLimit("max",t,!1,G.toString(n))}setLimit(t,n,r,s){return new mn({...this._def,checks:[...this._def.checks,{kind:t,value:n,inclusive:r,message:G.toString(s)}]})}_addCheck(t){return new mn({...this._def,checks:[...this._def.checks,t]})}positive(t){return this._addCheck({kind:"min",value:BigInt(0),inclusive:!1,message:G.toString(t)})}negative(t){return this._addCheck({kind:"max",value:BigInt(0),inclusive:!1,message:G.toString(t)})}nonpositive(t){return this._addCheck({kind:"max",value:BigInt(0),inclusive:!0,message:G.toString(t)})}nonnegative(t){return this._addCheck({kind:"min",value:BigInt(0),inclusive:!0,message:G.toString(t)})}multipleOf(t,n){return this._addCheck({kind:"multipleOf",value:t,message:G.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 mn({checks:[],typeName:W.ZodBigInt,coerce:(t=e==null?void 0:e.coerce)!==null&&t!==void 0?t:!1,...te(e)})};class Hr 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}),X}return Fe(t.data)}}Hr.create=e=>new Hr({typeName:W.ZodBoolean,coerce:(e==null?void 0:e.coerce)||!1,...te(e)});class Ln 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}),X}if(isNaN(t.data.getTime())){const o=this._getOrReturnCtx(t);return V(o,{code:R.invalid_date}),X}const r=new Ze;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()):he.assertNever(o);return{status:r.value,value:new Date(t.data.getTime())}}_addCheck(t){return new Ln({...this._def,checks:[...this._def.checks,t]})}min(t,n){return this._addCheck({kind:"min",value:t.getTime(),message:G.toString(n)})}max(t,n){return this._addCheck({kind:"max",value:t.getTime(),message:G.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 Ln({checks:[],coerce:(e==null?void 0:e.coerce)||!1,typeName:W.ZodDate,...te(e)});class Ws 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}),X}return Fe(t.data)}}Ws.create=e=>new Ws({typeName:W.ZodSymbol,...te(e)});class jr 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}),X}return Fe(t.data)}}jr.create=e=>new jr({typeName:W.ZodUndefined,...te(e)});class Kr 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}),X}return Fe(t.data)}}Kr.create=e=>new Kr({typeName:W.ZodNull,...te(e)});class cr extends se{constructor(){super(...arguments),this._any=!0}_parse(t){return Fe(t.data)}}cr.create=e=>new cr({typeName:W.ZodAny,...te(e)});class Pn extends se{constructor(){super(...arguments),this._unknown=!0}_parse(t){return Fe(t.data)}}Pn.create=e=>new Pn({typeName:W.ZodUnknown,...te(e)});class Dt extends se{_parse(t){const n=this._getOrReturnCtx(t);return V(n,{code:R.invalid_type,expected:Z.never,received:n.parsedType}),X}}Dt.create=e=>new Dt({typeName:W.ZodNever,...te(e)});class Ys 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}),X}return Fe(t.data)}}Ys.create=e=>new Ys({typeName:W.ZodVoid,...te(e)});class dt 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}),X;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 At(n,i,n.path,a)))).then(i=>Ze.mergeArray(r,i));const o=[...n.data].map((i,a)=>s.type._parseSync(new At(n,i,n.path,a)));return Ze.mergeArray(r,o)}get element(){return this._def.type}min(t,n){return new dt({...this._def,minLength:{value:t,message:G.toString(n)}})}max(t,n){return new dt({...this._def,maxLength:{value:t,message:G.toString(n)}})}length(t,n){return new dt({...this._def,exactLength:{value:t,message:G.toString(n)}})}nonempty(t){return this.min(1,t)}}dt.create=(e,t)=>new dt({type:e,minLength:null,maxLength:null,exactLength:null,typeName:W.ZodArray,...te(t)});function Jn(e){if(e instanceof Se){const t={};for(const n in e.shape){const r=e.shape[n];t[n]=Ht.create(Jn(r))}return new Se({...e._def,shape:()=>t})}else return e instanceof dt?new dt({...e._def,type:Jn(e.element)}):e instanceof Ht?Ht.create(Jn(e.unwrap())):e instanceof Hn?Hn.create(Jn(e.unwrap())):e instanceof Bt?Bt.create(e.items.map(t=>Jn(t))):e}class Se 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=he.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}),X}const{status:r,ctx:s}=this._processInputParams(t),{shape:o,keys:i}=this._getCached(),a=[];if(!(this._def.catchall instanceof Dt&&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 At(s,l,s.path,u)),alwaysSet:u in s.data})}if(this._def.catchall instanceof Dt){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:R.unrecognized_keys,keys:a}),r.dirty());else if(u!=="strip")throw new Error("Internal ZodObject error: invalid unknownKeys value.")}else{const u=this._def.catchall;for(const f of a){const l=s.data[f];c.push({key:{status:"valid",value:f},value:u._parse(new At(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=>Ze.mergeObjectSync(r,u)):Ze.mergeObjectSync(r,c)}get shape(){return this._def.shape()}strict(t){return new Se({...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=G.errToObj(t).message)!==null&&a!==void 0?a:c}:{message:c}}}:{}})}strip(){return new Se({...this._def,unknownKeys:"strip"})}passthrough(){return new Se({...this._def,unknownKeys:"passthrough"})}extend(t){return new Se({...this._def,shape:()=>({...this._def.shape(),...t})})}merge(t){return new Se({unknownKeys:t._def.unknownKeys,catchall:t._def.catchall,shape:()=>({...this._def.shape(),...t._def.shape()}),typeName:W.ZodObject})}setKey(t,n){return this.augment({[t]:n})}catchall(t){return new Se({...this._def,catchall:t})}pick(t){const n={};return he.objectKeys(t).forEach(r=>{t[r]&&this.shape[r]&&(n[r]=this.shape[r])}),new Se({...this._def,shape:()=>n})}omit(t){const n={};return he.objectKeys(this.shape).forEach(r=>{t[r]||(n[r]=this.shape[r])}),new Se({...this._def,shape:()=>n})}deepPartial(){return Jn(this)}partial(t){const n={};return he.objectKeys(this.shape).forEach(r=>{const s=this.shape[r];t&&!t[r]?n[r]=s:n[r]=s.optional()}),new Se({...this._def,shape:()=>n})}required(t){const n={};return he.objectKeys(this.shape).forEach(r=>{if(t&&!t[r])n[r]=this.shape[r];else{let o=this.shape[r];for(;o instanceof Ht;)o=o._def.innerType;n[r]=o}}),new Se({...this._def,shape:()=>n})}keyof(){return bl(he.objectKeys(this.shape))}}Se.create=(e,t)=>new Se({shape:()=>e,unknownKeys:"strip",catchall:Dt.create(),typeName:W.ZodObject,...te(t)});Se.strictCreate=(e,t)=>new Se({shape:()=>e,unknownKeys:"strict",catchall:Dt.create(),typeName:W.ZodObject,...te(t)});Se.lazycreate=(e,t)=>new Se({shape:e,unknownKeys:"strip",catchall:Dt.create(),typeName:W.ZodObject,...te(t)});class Dr 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 lt(a.ctx.common.issues));return V(n,{code:R.invalid_union,unionErrors:i}),X}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 lt(c));return V(n,{code:R.invalid_union,unionErrors:a}),X}}get options(){return this._def.options}}Dr.create=(e,t)=>new Dr({options:e,typeName:W.ZodUnion,...te(t)});const Ps=e=>e instanceof Vr?Ps(e.schema):e instanceof pt?Ps(e.innerType()):e instanceof qr?[e.value]:e instanceof yn?e.options:e instanceof zr?Object.keys(e.enum):e instanceof Fr?Ps(e._def.innerType):e instanceof jr?[void 0]:e instanceof Kr?[null]:null;class So 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}),X;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]}),X)}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=Ps(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 So({typeName:W.ZodDiscriminatedUnion,discriminator:t,options:n,optionsMap:s,...te(r)})}}function Li(e,t){const n=an(e),r=an(t);if(e===t)return{valid:!0,data:e};if(n===Z.object&&r===Z.object){const s=he.objectKeys(t),o=he.objectKeys(e).filter(a=>s.indexOf(a)!==-1),i={...e,...t};for(const a of o){const c=Li(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(Ui(o)||Ui(i))return X;const a=Li(o.value,i.value);return a.valid?((Ni(o)||Ni(i))&&n.dirty(),{status:n.value,value:a.data}):(V(r,{code:R.invalid_intersection_types}),X)};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}))}}Mr.create=(e,t,n)=>new Mr({left:e,right:t,typeName:W.ZodIntersection,...te(n)});class Bt 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}),X;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 At(r,i,r.path,a)):null}).filter(i=>!!i);return r.common.async?Promise.all(o).then(i=>Ze.mergeArray(n,i)):Ze.mergeArray(n,o)}get items(){return this._def.items}rest(t){return new Bt({...this._def,rest:t})}}Bt.create=(e,t)=>{if(!Array.isArray(e))throw new Error("You must pass an array of schemas to z.tuple([ ... ])");return new Bt({items:e,typeName:W.ZodTuple,rest:null,...te(t)})};class Zr 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}),X;const s=[],o=this._def.keyType,i=this._def.valueType;for(const a in r.data)s.push({key:o._parse(new At(r,a,r.path,a)),value:i._parse(new At(r,r.data[a],r.path,a))});return r.common.async?Ze.mergeObjectAsync(n,s):Ze.mergeObjectSync(n,s)}get element(){return this._def.valueType}static create(t,n,r){return n instanceof se?new Zr({keyType:t,valueType:n,typeName:W.ZodRecord,...te(r)}):new Zr({keyType:ut.create(),valueType:t,typeName:W.ZodRecord,...te(n)})}}class Xs 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}),X;const s=this._def.keyType,o=this._def.valueType,i=[...r.data.entries()].map(([a,c],u)=>({key:s._parse(new At(r,a,r.path,[u,"key"])),value:o._parse(new At(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 X;(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 X;(u.status==="dirty"||f.status==="dirty")&&n.dirty(),a.set(u.value,f.value)}return{status:n.value,value:a}}}}Xs.create=(e,t,n)=>new Xs({valueType:t,keyType:e,typeName:W.ZodMap,...te(n)});class Rn 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}),X;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 f of c){if(f.status==="aborted")return X;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 At(r,c,r.path,u)));return r.common.async?Promise.all(a).then(c=>i(c)):i(a)}min(t,n){return new Rn({...this._def,minSize:{value:t,message:G.toString(n)}})}max(t,n){return new Rn({...this._def,maxSize:{value:t,message:G.toString(n)}})}size(t,n){return this.min(t,n).max(t,n)}nonempty(t){return this.min(1,t)}}Rn.create=(e,t)=>new Rn({valueType:e,minSize:null,maxSize:null,typeName:W.ZodSet,...te(t)});class tr 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}),X;function r(a,c){return zs({data:a,path:n.path,errorMaps:[n.common.contextualErrorMap,n.schemaErrorMap,qs(),Rr].filter(u=>!!u),issueData:{code:R.invalid_arguments,argumentsError:c}})}function s(a,c){return zs({data:a,path:n.path,errorMaps:[n.common.contextualErrorMap,n.schemaErrorMap,qs(),Rr].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 ur?Fe(async(...a)=>{const c=new lt([]),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})}):Fe((...a)=>{const c=this._def.args.safeParse(a,o);if(!c.success)throw new lt([r(a,c.error)]);const u=i(...c.data),f=this._def.returns.safeParse(u,o);if(!f.success)throw new lt([s(u,f.error)]);return f.data})}parameters(){return this._def.args}returnType(){return this._def.returns}args(...t){return new tr({...this._def,args:Bt.create(t).rest(Pn.create())})}returns(t){return new tr({...this._def,returns:t})}implement(t){return this.parse(t)}strictImplement(t){return this.parse(t)}static create(t,n,r){return new tr({args:t||Bt.create([]).rest(Pn.create()),returns:n||Pn.create(),typeName:W.ZodFunction,...te(r)})}}class Vr 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})}}Vr.create=(e,t)=>new Vr({getter:e,typeName:W.ZodLazy,...te(t)});class qr 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}),X}return{status:"valid",value:t.data}}get value(){return this._def.value}}qr.create=(e,t)=>new qr({value:e,typeName:W.ZodLiteral,...te(t)});function bl(e,t){return new yn({values:e,typeName:W.ZodEnum,...te(t)})}class yn extends se{_parse(t){if(typeof t.data!="string"){const n=this._getOrReturnCtx(t),r=this._def.values;return V(n,{expected:he.joinValues(r),received:n.parsedType,code:R.invalid_type}),X}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}),X}return Fe(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 yn.create(t)}exclude(t){return yn.create(this.options.filter(n=>!t.includes(n)))}}yn.create=bl;class zr extends se{_parse(t){const n=he.getValidEnumValues(this._def.values),r=this._getOrReturnCtx(t);if(r.parsedType!==Z.string&&r.parsedType!==Z.number){const s=he.objectValues(n);return V(r,{expected:he.joinValues(s),received:r.parsedType,code:R.invalid_type}),X}if(n.indexOf(t.data)===-1){const s=he.objectValues(n);return V(r,{received:r.data,code:R.invalid_enum_value,options:s}),X}return Fe(t.data)}get enum(){return this._def.values}}zr.create=(e,t)=>new zr({values:e,typeName:W.ZodNativeEnum,...te(t)});class ur 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}),X;const r=n.parsedType===Z.promise?n.data:Promise.resolve(n.data);return Fe(r.then(s=>this._def.type.parseAsync(s,{path:n.path,errorMap:n.common.contextualErrorMap})))}}ur.create=(e,t)=>new ur({type:e,typeName:W.ZodPromise,...te(t)});class pt extends se{innerType(){return this._def.schema}sourceType(){return this._def.schema._def.typeName===W.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"?X:(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"?X:(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(!Fs(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=>Fs(i)?Promise.resolve(s.transform(i.value,o)).then(a=>({status:n.value,value:a})):i);he.assertNever(s)}}pt.create=(e,t,n)=>new pt({schema:e,typeName:W.ZodEffects,effect:t,...te(n)});pt.createWithPreprocess=(e,t,n)=>new pt({schema:t,effect:{type:"preprocess",transform:e},typeName:W.ZodEffects,...te(n)});class Ht extends se{_parse(t){return this._getType(t)===Z.undefined?Fe(void 0):this._def.innerType._parse(t)}unwrap(){return this._def.innerType}}Ht.create=(e,t)=>new Ht({innerType:e,typeName:W.ZodOptional,...te(t)});class Hn extends se{_parse(t){return this._getType(t)===Z.null?Fe(null):this._def.innerType._parse(t)}unwrap(){return this._def.innerType}}Hn.create=(e,t)=>new Hn({innerType:e,typeName:W.ZodNullable,...te(t)});class Fr 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}}Fr.create=(e,t)=>new Fr({innerType:e,typeName:W.ZodDefault,defaultValue:typeof t.default=="function"?t.default:()=>t.default,...te(t)});class Js 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 Gs(s)?s.then(o=>({status:"valid",value:o.status==="valid"?o.value:this._def.catchValue({get error(){return new lt(r.common.issues)},input:r.data})})):{status:"valid",value:s.status==="valid"?s.value:this._def.catchValue({get error(){return new lt(r.common.issues)},input:r.data})}}removeCatch(){return this._def.innerType}}Js.create=(e,t)=>new Js({innerType:e,typeName:W.ZodCatch,catchValue:typeof t.catch=="function"?t.catch:()=>t.catch,...te(t)});class Qs 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}),X}return{status:"valid",value:t.data}}}Qs.create=e=>new Qs({typeName:W.ZodNaN,...te(e)});const mw=Symbol("zod_brand");class wl 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 rs 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"?X:o.status==="dirty"?(n.dirty(),yl(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"?X: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 rs({in:t,out:n,typeName:W.ZodPipeline})}}const xl=(e,t={},n)=>e?cr.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})}}):cr.create(),yw={object:Se.lazycreate};var W;(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"})(W||(W={}));const bw=(e,t={message:`Input not instance of ${e.name}`})=>xl(n=>n instanceof e,t),vl=ut.create,El=gn.create,ww=Qs.create,xw=mn.create,kl=Hr.create,vw=Ln.create,Ew=Ws.create,kw=jr.create,Sw=Kr.create,$w=cr.create,_w=Pn.create,Aw=Dt.create,Bw=Ys.create,Tw=dt.create,Iw=Se.create,Ow=Se.strictCreate,Cw=Dr.create,Pw=So.create,Uw=Mr.create,Nw=Bt.create,Lw=Zr.create,Rw=Xs.create,Hw=Rn.create,jw=tr.create,Kw=Vr.create,Dw=qr.create,Mw=yn.create,Zw=zr.create,Vw=ur.create,Pc=pt.create,qw=Ht.create,zw=Hn.create,Fw=pt.createWithPreprocess,Gw=rs.create,Ww=()=>vl().optional(),Yw=()=>El().optional(),Xw=()=>kl().optional(),Jw={string:(e=>ut.create({...e,coerce:!0})),number:(e=>gn.create({...e,coerce:!0})),boolean:(e=>Hr.create({...e,coerce:!0})),bigint:(e=>mn.create({...e,coerce:!0})),date:(e=>Ln.create({...e,coerce:!0}))},Qw=X;var ze=Object.freeze({__proto__:null,defaultErrorMap:Rr,setErrorMap:rw,getErrorMap:qs,makeIssue:zs,EMPTY_PATH:sw,addIssueToContext:V,ParseStatus:Ze,INVALID:X,DIRTY:yl,OK:Fe,isAborted:Ui,isDirty:Ni,isValid:Fs,isAsync:Gs,get util(){return he},get objectUtil(){return Pi},ZodParsedType:Z,getParsedType:an,ZodType:se,ZodString:ut,ZodNumber:gn,ZodBigInt:mn,ZodBoolean:Hr,ZodDate:Ln,ZodSymbol:Ws,ZodUndefined:jr,ZodNull:Kr,ZodAny:cr,ZodUnknown:Pn,ZodNever:Dt,ZodVoid:Ys,ZodArray:dt,ZodObject:Se,ZodUnion:Dr,ZodDiscriminatedUnion:So,ZodIntersection:Mr,ZodTuple:Bt,ZodRecord:Zr,ZodMap:Xs,ZodSet:Rn,ZodFunction:tr,ZodLazy:Vr,ZodLiteral:qr,ZodEnum:yn,ZodNativeEnum:zr,ZodPromise:ur,ZodEffects:pt,ZodTransformer:pt,ZodOptional:Ht,ZodNullable:Hn,ZodDefault:Fr,ZodCatch:Js,ZodNaN:Qs,BRAND:mw,ZodBranded:wl,ZodPipeline:rs,custom:xl,Schema:se,ZodSchema:se,late:yw,get ZodFirstPartyTypeKind(){return W},coerce:Jw,any:$w,array:Tw,bigint:xw,boolean:kl,date:vw,discriminatedUnion:Pw,effect:Pc,enum:Mw,function:jw,instanceof:bw,intersection:Uw,lazy:Kw,literal:Dw,map:Rw,nan:ww,nativeEnum:Zw,never:Aw,null:Sw,nullable:zw,number:El,object:Iw,oboolean:Xw,onumber:Yw,optional:qw,ostring:Ww,pipeline:Gw,preprocess:Fw,promise:Vw,record:Lw,set:Hw,strictObject:Ow,string:vl,symbol:Ew,transformer:Pc,tuple:Nw,undefined:kw,union:Cw,unknown:_w,void:Bw,NEVER:Qw,ZodIssueCode:R,quotelessJson:nw,ZodError:lt});const Sl=ze.string().regex(/^[a-fA-F0-9]$/),e1=ze.string().regex(/^[a-fA-F0-9]{64}$/),fr=ze.number().min(0).max(4294967295),t1=ze.bigint(),$l=ze.instanceof(Uint8Array),n1=ze.union([Sl,fr,ze.string(),$l]).array(),Ua=ze.union([n1,Sl,$l]),r1=ze.array(Ua),_l=ze.object({value:ze.union([fr,t1]),scriptPubKey:Ua}),s1=ze.object({txid:e1,vout:fr,scriptSig:Ua,sequence:fr,prevout:_l.optional(),witness:r1});ze.object({version:fr,vin:ze.array(s1),vout:ze.array(_l),locktime:fr});const Ri=2048,o1=new TextEncoder;function Al(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=o1.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>Ri)throw new Error(`Metadata must be at most ${Ri} CBOR bytes.`)};return r(e),Uint8Array.from(t)}function i1(e){if(e=new Uint8Array(e),!e.length||e.length>Ri)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}}),Ue=(e,t)=>({value:e,scriptPubKey:t}),Uc=16*1024,Et=1e3,fe=500,eo="text/plain;charset=utf-8",a1=["text/plain","application/json","text/html","image/svg+xml","image/png","image/jpeg","image/webp"],Bl=new TextEncoder,Or=e=>Array.from(e,t=>t.toString(16).padStart(2,"0")).join(""),Sn=e=>Uint8Array.from(e.match(/../g)??[],t=>parseInt(t,16)),to=e=>Or(Bl.encode(e));function Na(e){const t=typeof e=="string"?{contentType:eo,bytes:Bl.encode(e)}:e;if(!t||![...a1,eo].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>Uc)throw new Error(`Body must be at most ${Uc} bytes.`);return{contentType:t.contentType,bytes:new Uint8Array(t.bytes)}}function no(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 Nc(e){if(typeof e!="string"||!/^[0-9a-f]{64,72}$/.test(e)||e.length%2)throw new Error("Invalid parent tag.");const t=[...Sn(e.slice(64))].reduce((r,s,o)=>r+s*256**o,0),n=`${e.slice(0,64).match(/../g).reverse().join("")}i${t}`;if(no(n)!==e)throw new Error("Non-canonical parent tag.");return n}function Tl(e,t,n=null,r=void 0,s={}){const{contentType:o,bytes:i}=Na(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:Al(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(to("ord"))+h("01")+h(to(o))+(a?h("0b")+h(no(a)):"")+(c===void 0?"":h("02")+h(Il(c)))+(n?h("03")+h(no(n)):"")+(l===void 0?"":Array.from({length:Math.ceil(l.length/520)},(p,g)=>h("05")+h(Or(l.slice(g*520,(g+1)*520)))).join(""))+(f?h("07")+h(Or(f)):"")+"00"+d.map(h).join("")+"68"}function La(e){if(!Array.isArray(e)||e.length!==3)throw new Error("Unsupported script-path witness.");const t=$e.decode(e[1]);let n=7,r=null,s=null,o;t[n]==="0b"&&(s=Nc(t[n+1]),n+=2),t[n]==="02"&&(o=u1(t[n+1]==="OP_0"?"":t[n+1]),n+=2),t[n]==="03"&&(r=Nc(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?i1(Sn(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(Sn(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 f=new TextDecoder().decode(Sn(t[6])),l=Na({contentType:f,bytes:Sn(u.join(""))}),d=Tl(t[0],l,r,a,{delegate:s,pointer:o,metaprotocol:c}),h=a===void 0&&!r&&f===eo&&l.bytes.length<=280&&$e.encode([t[0],"OP_CHECKSIG","OP_0","OP_IF",to("ord"),"01",to(eo),"OP_0",Or(l.bytes),"OP_ENDIF"],!1).hex;if(d!==e[1]&&h!==e[1])throw new Error("Unsupported ord envelope.");if(!/^[0-9a-f]{64}$/.test(t[0]))throw new Error("Invalid inscription signing key.");return{...l,parent:r,delegate:s,pointer:o,metaprotocol:c,metadata:a,metadataBytes:i.length?Sn(i.join("")):void 0,text:new TextDecoder().decode(l.bytes),pubkey:t[0]}}class c1{constructor(t,n){this.chain=t,this.wallet=n}prepare(t,n=null,r=void 0,s={}){const o=Na(t);if(r!==void 0&&Al(r),s.delegate&&no(s.delegate),s.pointer!==void 0&&Il(s.pointer),s.metaprotocol!==void 0&&s.metaprotocol!==null&&s.metaprotocol!==""&&new TextEncoder().encode(String(s.metaprotocol)).length>520)throw new Error("Metaprotocol identifier must be 520 bytes or less.");if(n&&s.reinscribe)throw new Error("Choose parent or reinscription, not both.");const i=this.chain.coins(this.wallet.script),a=n?i.find(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>=Et+2*fe+330);if(!u)throw new Error("Mine a block first to get spendable fake BTC.");return{...o,coin:u,parent:a,reinscribe:c,totalFee:fe*2,postage:Et}}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=Tl(this.wallet.pubkey,c,n,r,{...s,pointer:l}),h=Vs.encodeScript(d),[p,g]=Vs.getPubKey(this.wallet.pubkey,{target:h}),y=ie.create({vin:[jt(o.txid,o.vout,o.value,o.scriptPubKey)],vout:[Ue(Et+fe,["OP_1",p]),Ue(o.value-Et-2*fe,this.wallet.script)]});y.vin[0].witness=[this.wallet.sign(y)];const m=ie.util.getTxid(y),v=ie.create({vin:[...u?[jt(u.txid,u.vout,u.value,u.scriptPubKey)]:[],jt(m,0,Et+fe,["OP_1",p])],vout:[...u?[Ue(u.value,this.wallet.script)]:[],Ue(Et,this.wallet.script)]}),b=u?1:0;return v.vin[b].witness=[this.wallet.sign(v,h,b),$e.encode(d,!1).hex,g],u&&(v.vin[0].witness=[this.wallet.sign(v)]),this.chain.submitPackage([ie.encode(y).hex,ie.encode(v).hex]),`${ie.util.getTxid(v)}i0`}list(){return this.chain.coins(this.wallet.script).flatMap(t=>t.inscriptions??[])}}function Il(e){let t;try{t=BigInt(e)}catch{throw new Error("Invalid pointer.")}if(t<0n||t>0xffffffffffffffffn||typeof e=="number"&&!Number.isSafeInteger(e))throw new Error("Invalid pointer.");let n="";for(;t;)n+=Number(t&255n).toString(16).padStart(2,"0"),t>>=8n;return n}function u1(e){if(typeof e!="string"||!/^(?:[0-9a-f]{2}){0,8}$/.test(e))throw new Error("Invalid pointer tag.");return[...Sn(e)].reduce((t,n,r)=>t+(BigInt(n)<{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(v=>this.utxos.get(`${v.txid}:${v.vout}`)),f=vu(i,u,s,c);i.vin.forEach(v=>this.utxos.delete(`${v.txid}:${v.vout}`)),i.vout.forEach((v,b)=>this.utxos.set(`${a}:${b}`,{txid:a,vout:b,value:Number(v.value),ranges:f[b]}));const l=(m=i.vin.find(v=>{var b;return((b=v.witness)==null?void 0:b.length)===3}))==null?void 0:m.witness;if(!l)return;const d=La(l),h=BigInt(d.pointer??0),p=i.vout.reduce((v,b)=>v+Number(b.value),0),g=xu(f.flat(),hv.sat===g).length,status:s===null?"pending":"confirmed",height:s,block:o,metadata:y??null,hasMetadata:y!==void 0,parent:d.parent,protocol:d.metaprotocol??(y&&!Array.isArray(y)&&typeof y=="object"&&Object.hasOwn(y,"protocol")&&typeof y.protocol=="string"?y.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=Os(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 Ra="lineage/v0",f1=["white","green","black"],Xo="names are 1-40 lowercase letters, digits or hyphens (they become domains)",l1=/^[a-z0-9](?:[a-z0-9-]{0,38}[a-z0-9])?$/,ys=e=>typeof e=="string"&&l1.test(e),Ir=(e,t)=>typeof e=="string"?e.trim().slice(0,t):"";function $o(e){return String(e??"").toLowerCase().normalize("NFKD").replace(/[̀-ͯ]/g,"").replace(/[^a-z0-9]+/g,"-").replace(/^-+|-+$/g,"").slice(0,40).replace(/-+$/,"")}const _o=e=>e.events.filter(t=>t.protocol===Ra);function bn(e,{upTo:t=1/0,pending:n=!1}={}){const r=new Map,s=[],o=[],i=new Map,a=c=>c.status==="active";for(const c of e){const u=c.status==="confirmed";if(u?c.height>t:!n)continue;const f=c.metadata&&typeof c.metadata=="object"&&!Array.isArray(c.metadata)?c.metadata:{},l={id:c.id,op:typeof f.op=="string"?f.op.slice(0,20):"?",beat:u?c.height:null,pending:!u,meta:f,parent:c.parent??null,ok:!0,why:"",node:null,root:null,also:[]},d=l.parent?r.get(l.parent):null,h=l.beat??"cued",p=m=>{l.ok=!1,l.why=m},g=m=>d?a(d)?"":`the ${m} is ${d.status}`:`the ${m} is not in this lineage`;let y="";switch(l.op){case"found":if(l.parent)p("a holding has no parent");else if(!ys(f.name))p(Xo);else if(s.some(m=>a(m)&&m.name===f.name))p(`an active holding is already named ${f.name}`);else{const m=Lc(c,f.name,null,"holding");r.set(m.id,m),s.push(m),l.node=m.id}break;case"birth":{const m=f.kind==="agent"?"agent":"org";if(y=g("parent"))p(y);else if(d.kind==="agent")p("agents do not give birth");else if(!ys(f.name))p(Xo);else if(d.children.some(v=>a(r.get(v))&&r.get(v).name===f.name))p(`${d.name} already has an active ${f.name}`);else{const v=Lc(c,f.name,d,m);v.index=d.children.filter(b=>r.get(b).kind===m).length,d.children.push(v.id),r.set(v.id,v),l.node=v.id}break}case"award":{const m=r.get(f.to);(y=g("issuer"))?p(y):d.kind==="agent"?p("agents do not award belts"):!m||m.root!==d.root||m.id===d.id?p("the recipient must be another node in this holding"):a(m)?!ys(f.skill)||!f1.includes(f.belt)?p("an award needs a skill name and a belt (white, green or black)"):(m.badges=m.badges.filter(v=>v.skill!==f.skill),m.badges.push({skill:f.skill,belt:f.belt,by:d.id,beat:h,id:c.id}),l.node=m.id):p(`the recipient is ${m.status}`);break}case"decide":(y=g("decider"))?p(y):Ir(f.title,140)?(d.decisions.push({title:Ir(f.title,140),why:Ir(f.why,400),beat:h,id:c.id}),l.node=d.id):p("a decision needs a title");break;case"make":(y=g("maker"))?p(y):ys(f.name)?d.made.some(m=>i.get(m).name===f.name)?p(`there is already a ${f.name} by ${d.name}`):(i.set(c.id,{id:c.id,name:f.name,note:Ir(f.note,280),maker:d.id,beat:h}),d.made.push(c.id),l.node=d.id):p(Xo);break;case"graduate":{const m=r.get(f.of);(y=g("parent"))?p(y):!m||m.parent!==d.id?p("only its parent can graduate a child"):m.kind!=="org"?p("only orgs graduate"):a(m)?m.edge==="adopted"?p("already graduated"):(m.edge="adopted",m.graduated=h,l.node=m.id):p(`the child is ${m.status}`);break}case"close":if(!d)p(l.parent?"that node is not in this lineage":"a close spends the node it closes");else if(!a(d))p(`already ${d.status}`);else{const m=v=>{v.status="closed",v.closed=h;for(const b of v.children){const x=r.get(b);x.edge==="derived"&&a(x)&&(l.also.push(x.id),m(x))}};m(d),l.node=d.id}break;default:p("not a lineage/v0 op")}l.root=l.node?r.get(l.node).root:(d==null?void 0:d.root)??null,o.push(l)}return{nodes:r,roots:s,log:o,items:i}}function Lc(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:[],graduated:null,closed:null}}function d1(e,t){const n=[],r=e.nodes.get(t),s=(o,i,a)=>{n.push({type:"node",node:o,guide:i,path:o.parent?`${o.index}'`:"●"});const c=o.children.map(f=>e.nodes.get(f)),u=[["agents",c.filter(f=>f.kind==="agent")],["orgs",c.filter(f=>f.kind!=="agent")]].filter(([,f])=>f.length);u.forEach(([f,l],d)=>{const h=d===u.length-1,p=a+(h?" ":"│ ");n.push({type:"group",label:f,guide:a+(h?"└─ ":"├─ ")}),l.forEach((g,y)=>{const m=y===l.length-1;s(g,p+(m?"└─ ":"├─ "),p+(m?" ":"│ "))})})};return r&&s(r,"",""),n}function h1(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 lr(e,t){const n=[];for(let r=e.nodes.get(t);r;r=e.nodes.get(r.parent))n.unshift(r.name);return n.join(" / ")}function Ol(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 “${Ir(n.title,140)}” · ${r(e.parent)}`;case"make":return`make ${n.name} · ${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 Gn=typeof globalThis=="object"&&"crypto"in globalThis?globalThis.crypto:void 0;/*! noble-hashes - MIT License (c) 2022 Paul Miller (paulmillr.com) */function os(e){return e instanceof Uint8Array||ArrayBuffer.isView(e)&&e.constructor.name==="Uint8Array"}function dn(e){if(!Number.isSafeInteger(e)||e<0)throw new Error("positive integer expected, got "+e)}function De(e,...t){if(!os(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 is(e){if(typeof e!="function"||typeof e.create!="function")throw new Error("Hash should be wrapped by utils.createHasher");dn(e.outputLen),dn(e.blockLen)}function ro(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 p1(e,t){De(e);const n=t.outputLen;if(e.length>>t}function bs(e,t){return e<>>32-t>>>0}const Cl=typeof Uint8Array.from([]).toHex=="function"&&typeof Uint8Array.fromHex=="function",g1=Array.from({length:256},(e,t)=>t.toString(16).padStart(2,"0"));function Me(e){if(De(e),Cl)return e.toHex();let t="";for(let n=0;n=Ut._0&&e<=Ut._9)return e-Ut._0;if(e>=Ut.A&&e<=Ut.F)return e-(Ut.A-10);if(e>=Ut.a&&e<=Ut.f)return e-(Ut.a-10)}function gt(e){if(typeof e!="string")throw new Error("hex string expected, got "+typeof e);if(Cl)return Uint8Array.fromHex(e);const t=e.length,n=t/2;if(t%2)throw new Error("hex string expected, got unpadded hex of length "+t);const r=new Uint8Array(n);for(let s=0,o=0;se().update(Gr(r)).digest(),n=e();return t.outputLen=n.outputLen,t.blockLen=n.blockLen,t.create=()=>e(),t}function qn(e=32){if(Gn&&typeof Gn.getRandomValues=="function")return Gn.getRandomValues(new Uint8Array(e));if(Gn&&typeof Gn.randomBytes=="function")return Uint8Array.from(Gn.randomBytes(e));throw new Error("crypto.getRandomValues must be defined")}function y1(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 b1(e,t,n){return e&t^~e&n}function w1(e,t,n){return e&t^e&n^t&n}class ja extends Pl{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=Un(this.buffer)}update(t){ro(this),t=Gr(t),De(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>jc&ws)}:{h:Number(e>>jc&ws)|0,l:Number(e&ws)|0}}function v1(e,t=!1){const n=e.length;let r=new Uint32Array(n),s=new Uint32Array(n);for(let o=0;oe>>>n,Dc=(e,t,n)=>e<<32-n|t>>>n,Wn=(e,t,n)=>e>>>n|t<<32-n,Yn=(e,t,n)=>e<<32-n|t>>>n,xs=(e,t,n)=>e<<64-n|t>>>n-32,vs=(e,t,n)=>e>>>n-32|t<<64-n;function Nt(e,t,n,r){const s=(t>>>0)+(r>>>0);return{h:e+n+(s/2**32|0)|0,l:s|0}}const E1=(e,t,n)=>(e>>>0)+(t>>>0)+(n>>>0),k1=(e,t,n,r)=>t+n+r+(e/2**32|0)|0,S1=(e,t,n,r)=>(e>>>0)+(t>>>0)+(n>>>0)+(r>>>0),$1=(e,t,n,r,s)=>t+n+r+s+(e/2**32|0)|0,_1=(e,t,n,r,s)=>(e>>>0)+(t>>>0)+(n>>>0)+(r>>>0)+(s>>>0),A1=(e,t,n,r,s,o)=>t+n+r+s+o+(e/2**32|0)|0,B1=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]),en=new Uint32Array(64);class T1 extends ja{constructor(t=32){super(64,t,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],h=en[l-2],p=vt(d,7)^vt(d,18)^d>>>3,g=vt(h,17)^vt(h,19)^h>>>10;en[l]=g+en[l-7]+p+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=vt(a,6)^vt(a,11)^vt(a,25),h=f+d+b1(a,c,u)+B1[l]+en[l]|0,g=(vt(r,2)^vt(r,13)^vt(r,22))+w1(r,s,o)|0;f=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,f=f+this.H|0,this.set(r,s,o,i,a,c,u,f)}roundClean(){Tt(en)}destroy(){this.set(0,0,0,0,0,0,0,0),Tt(this.buffer)}}const Ul=v1(["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))),I1=Ul[0],O1=Ul[1],tn=new Uint32Array(80),nn=new Uint32Array(80);class C1 extends ja{constructor(t=64){super(128,t,16,!1),this.Ah=He[0]|0,this.Al=He[1]|0,this.Bh=He[2]|0,this.Bl=He[3]|0,this.Ch=He[4]|0,this.Cl=He[5]|0,this.Dh=He[6]|0,this.Dl=He[7]|0,this.Eh=He[8]|0,this.El=He[9]|0,this.Fh=He[10]|0,this.Fl=He[11]|0,this.Gh=He[12]|0,this.Gl=He[13]|0,this.Hh=He[14]|0,this.Hl=He[15]|0}get(){const{Ah:t,Al:n,Bh:r,Bl:s,Ch:o,Cl:i,Dh:a,Dl:c,Eh:u,El:f,Fh:l,Fl:d,Gh:h,Gl:p,Hh:g,Hl:y}=this;return[t,n,r,s,o,i,a,c,u,f,l,d,h,p,g,y]}set(t,n,r,s,o,i,a,c,u,f,l,d,h,p,g,y){this.Ah=t|0,this.Al=n|0,this.Bh=r|0,this.Bl=s|0,this.Ch=o|0,this.Cl=i|0,this.Dh=a|0,this.Dl=c|0,this.Eh=u|0,this.El=f|0,this.Fh=l|0,this.Fl=d|0,this.Gh=h|0,this.Gl=p|0,this.Hh=g|0,this.Hl=y|0}process(t,n){for(let b=0;b<16;b++,n+=4)tn[b]=t.getUint32(n),nn[b]=t.getUint32(n+=4);for(let b=16;b<80;b++){const x=tn[b-15]|0,_=nn[b-15]|0,I=Wn(x,_,1)^Wn(x,_,8)^Kc(x,_,7),C=Yn(x,_,1)^Yn(x,_,8)^Dc(x,_,7),P=tn[b-2]|0,B=nn[b-2]|0,N=Wn(P,B,19)^xs(P,B,61)^Kc(P,B,6),H=Yn(P,B,19)^vs(P,B,61)^Dc(P,B,6),K=S1(C,H,nn[b-7],nn[b-16]),E=$1(K,I,N,tn[b-7],tn[b-16]);tn[b]=E|0,nn[b]=K|0}let{Ah:r,Al:s,Bh:o,Bl:i,Ch:a,Cl:c,Dh:u,Dl:f,Eh:l,El:d,Fh:h,Fl:p,Gh:g,Gl:y,Hh:m,Hl:v}=this;for(let b=0;b<80;b++){const x=Wn(l,d,14)^Wn(l,d,18)^xs(l,d,41),_=Yn(l,d,14)^Yn(l,d,18)^vs(l,d,41),I=l&h^~l&g,C=d&p^~d&y,P=_1(v,_,C,O1[b],nn[b]),B=A1(P,m,x,I,I1[b],tn[b]),N=P|0,H=Wn(r,s,28)^xs(r,s,34)^xs(r,s,39),K=Yn(r,s,28)^vs(r,s,34)^vs(r,s,39),E=r&o^r&a^o&a,S=s&i^s&c^i&c;m=g|0,v=y|0,g=h|0,y=p|0,h=l|0,p=d|0,{h:l,l:d}=Nt(u|0,f|0,B|0,N|0),u=a|0,f=c|0,a=o|0,c=i|0,o=r|0,i=s|0;const w=E1(N,K,S);r=k1(w,B,H,E),s=w|0}({h:r,l:s}=Nt(this.Ah|0,this.Al|0,r|0,s|0)),{h:o,l:i}=Nt(this.Bh|0,this.Bl|0,o|0,i|0),{h:a,l:c}=Nt(this.Ch|0,this.Cl|0,a|0,c|0),{h:u,l:f}=Nt(this.Dh|0,this.Dl|0,u|0,f|0),{h:l,l:d}=Nt(this.Eh|0,this.El|0,l|0,d|0),{h,l:p}=Nt(this.Fh|0,this.Fl|0,h|0,p|0),{h:g,l:y}=Nt(this.Gh|0,this.Gl|0,g|0,y|0),{h:m,l:v}=Nt(this.Hh|0,this.Hl|0,m|0,v|0),this.set(r,s,o,i,a,c,u,f,l,d,h,p,g,y,m,v)}roundClean(){Tt(tn,nn)}destroy(){Tt(this.buffer),this.set(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0)}}const st=Ha(()=>new T1),Wr=Ha(()=>new C1),P1=Uint8Array.from([7,4,13,1,10,6,15,3,12,0,9,5,2,14,11,8]),Nl=Uint8Array.from(new Array(16).fill(0).map((e,t)=>t)),U1=Nl.map(e=>(9*e+5)%16),Ll=(()=>{const n=[[Nl],[U1]];for(let r=0;r<4;r++)for(let s of n)s.push(s[r].map(o=>P1[o]));return n})(),Rl=Ll[0],Hl=Ll[1],jl=[[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)),N1=Rl.map((e,t)=>e.map(n=>jl[t][n])),L1=Hl.map((e,t)=>e.map(n=>jl[t][n])),R1=Uint32Array.from([0,1518500249,1859775393,2400959708,2840853838]),H1=Uint32Array.from([1352829926,1548603684,1836072691,2053994217,0]);function Mc(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 Es=new Uint32Array(16);class j1 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 h=0;h<16;h++,n+=4)Es[h]=t.getUint32(n,!0);let r=this.h0|0,s=r,o=this.h1|0,i=o,a=this.h2|0,c=a,u=this.h3|0,f=u,l=this.h4|0,d=l;for(let h=0;h<5;h++){const p=4-h,g=R1[h],y=H1[h],m=Rl[h],v=Hl[h],b=N1[h],x=L1[h];for(let _=0;_<16;_++){const I=bs(r+Mc(h,o,a,u)+Es[m[_]]+g,b[_])+l|0;r=l,l=u,u=bs(a,10)|0,a=o,o=I}for(let _=0;_<16;_++){const I=bs(s+Mc(p,i,c,f)+Es[v[_]]+y,x[_])+d|0;s=d,d=f,f=bs(c,10)|0,c=i,i=I}}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(){Tt(Es)}destroy(){this.destroyed=!0,Tt(this.buffer),this.set(0,0,0,0,0)}}const Kl=Ha(()=>new j1);class Dl extends Pl{constructor(t,n){super(),this.finished=!1,this.destroyed=!1,is(t);const r=Gr(n);if(this.iHash=t.create(),typeof this.iHash.update!="function")throw new Error("Expected instance of class which extends utils.Hash");this.blockLen=this.iHash.blockLen,this.outputLen=this.iHash.outputLen;const s=this.blockLen,o=new Uint8Array(s);o.set(r.length>s?t.create().update(r).digest():r);for(let i=0;inew Dl(e,t).update(n).digest();wn.create=(e,t)=>new Dl(e,t);/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */const Ka=BigInt(0),Hi=BigInt(1);function jn(e,t=""){if(typeof e!="boolean"){const n=t&&`"${t}"`;throw new Error(n+"expected boolean, got type="+typeof e)}return e}function ft(e,t,n=""){const r=os(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 Ml(e){if(typeof e!="string")throw new Error("hex string expected, got "+typeof e);return e===""?Ka:BigInt("0x"+e)}function br(e){return Ml(Me(e))}function Kn(e){return De(e),Ml(Me(Uint8Array.from(e).reverse()))}function Ao(e,t){return gt(e.toString(16).padStart(t*2,"0"))}function Da(e,t){return Ao(e,t).reverse()}function ge(e,t,n){let r;if(typeof t=="string")try{r=gt(t)}catch(o){throw new Error(e+" must be hex string or Uint8Array, cause: "+o)}else if(os(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 Zc(e){return Uint8Array.from(e)}const Jo=e=>typeof e=="bigint"&&Ka<=e;function ji(e,t,n){return Jo(e)&&Jo(t)&&Jo(n)&&t<=e&&eKa;e>>=Hi,t+=1);return t}const as=e=>(Hi<new Uint8Array(h),s=h=>Uint8Array.of(h);let o=r(e),i=r(e),a=0;const c=()=>{o.fill(1),i.fill(0),a=0},u=(...h)=>n(i,o,...h),f=(h=r(0))=>{i=u(s(0),h),o=u(),h.length!==0&&(i=u(s(1),h),o=u())},l=()=>{if(a++>=1e3)throw new Error("drbg: tried 1000 values");let h=0;const p=[];for(;h{c(),f(h);let g;for(;!(g=p(l()));)f();return c(),g}}function wr(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 Ye=BigInt(0),Re=BigInt(1),Tn=BigInt(2),Vl=BigInt(3),ql=BigInt(4),zl=BigInt(5),D1=BigInt(7),Fl=BigInt(8),M1=BigInt(9),Gl=BigInt(16);function xe(e,t){const n=e%t;return n>=Ye?n:t+n}function ke(e,t,n){let r=e;for(;t-- >Ye;)r*=r,r%=n;return r}function Vc(e,t){if(e===Ye)throw new Error("invert: expected non-zero number");if(t<=Ye)throw new Error("invert: expected positive modulus, got "+t);let n=xe(e,t),r=t,s=Ye,o=Re;for(;n!==Ye;){const a=r/n,c=r%n,u=s-o*a;r=n,n=c,s=o,o=u}if(r!==Re)throw new Error("invert: does not exist");return xe(s,t)}function Ma(e,t,n){if(!e.eql(e.sqr(t),n))throw new Error("Cannot find square root")}function Wl(e,t){const n=(e.ORDER+Re)/ql,r=e.pow(t,n);return Ma(e,r,t),r}function Z1(e,t){const n=(e.ORDER-zl)/Fl,r=e.mul(t,Tn),s=e.pow(r,n),o=e.mul(t,s),i=e.mul(e.mul(o,Tn),s),a=e.mul(o,e.sub(i,e.ONE));return Ma(e,a,t),a}function V1(e){const t=zn(e),n=Yl(e),r=n(t,t.neg(t.ONE)),s=n(t,r),o=n(t,t.neg(r)),i=(e+D1)/Gl;return(a,c)=>{let u=a.pow(c,i),f=a.mul(u,r);const l=a.mul(u,s),d=a.mul(u,o),h=a.eql(a.sqr(f),c),p=a.eql(a.sqr(l),c);u=a.cmov(u,f,h),f=a.cmov(d,l,p);const g=a.eql(a.sqr(f),c),y=a.cmov(u,f,g);return Ma(a,y,c),y}}function Yl(e){if(e1e3)throw new Error("Cannot find square root: probably non-prime P");if(n===1)return Wl;let o=s.pow(r,t);const i=(t+Re)/Tn;return function(c,u){if(c.is0(u))return u;if(qc(c,u)!==1)throw new Error("Cannot find square root");let f=n,l=c.mul(c.ONE,o),d=c.pow(u,t),h=c.pow(u,i);for(;!c.eql(d,c.ONE);){if(c.is0(d))return c.ZERO;let p=1,g=c.sqr(d);for(;!c.eql(g,c.ONE);)if(p++,g=c.sqr(g),p===f)throw new Error("Cannot find square root");const y=Re<(xe(e,t)&Re)===Re,F1=["create","isValid","is0","neg","inv","sqrt","sqr","eql","add","sub","mul","pow","div","addN","subN","mulN","sqrN"];function G1(e){const t={ORDER:"bigint",MASK:"bigint",BYTES:"number",BITS:"number"},n=F1.reduce((r,s)=>(r[s]="function",r),t);return wr(e,n),e}function W1(e,t,n){if(nYe;)n&Re&&(r=e.mul(r,s)),s=e.sqr(s),n>>=Re;return r}function Xl(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 qc(e,t){const n=(e.ORDER-Re)/Tn,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 Jl(e,t){t!==void 0&&dn(t);const n=t!==void 0?t:e.toString(2).length,r=Math.ceil(n/8);return{nBitLength:n,nByteLength:r}}function zn(e,t,n=!1,r={}){if(e<=Ye)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}=Jl(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:as(c),ZERO:Ye,ONE:Re,allowedLengths:a,create:d=>xe(d,e),isValid:d=>{if(typeof d!="bigint")throw new Error("invalid field element: expected bigint, got "+typeof d);return Ye<=d&&dd===Ye,isValidNot0:d=>!l.is0(d)&&l.isValid(d),isOdd:d=>(d&Re)===Re,neg:d=>xe(-d,e),eql:(d,h)=>d===h,sqr:d=>xe(d*d,e),add:(d,h)=>xe(d+h,e),sub:(d,h)=>xe(d-h,e),mul:(d,h)=>xe(d*h,e),pow:(d,h)=>W1(l,d,h),div:(d,h)=>xe(d*Vc(h,e),e),sqrN:d=>d*d,addN:(d,h)=>d+h,subN:(d,h)=>d-h,mulN:(d,h)=>d*h,inv:d=>Vc(d,e),sqrt:o||(d=>(f||(f=q1(e)),f(l,d))),toBytes:d=>n?Da(d,u):Ao(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?Kn(d):br(d);if(i&&(p=xe(p,e)),!h&&!l.isValid(p))throw new Error("invalid field element: outside of range 0..ORDER");return p},invertBatch:d=>Xl(l,d),cmov:(d,h,p)=>p?h:d});return Object.freeze(l)}function Ql(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 ed(e){const t=Ql(e);return t+Math.ceil(t/2)}function td(e,t,n=!1){const r=e.length,s=Ql(t),o=ed(t);if(r<16||r1024)throw new Error("expected "+o+"-1024 bytes of input, got "+r);const i=n?Kn(e):br(e),a=xe(i,t-Re)+Re;return n?Da(a,s):Ao(a,s)}/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */const dr=BigInt(0),In=BigInt(1);function oo(e,t){const n=t.negate();return e?n:t}function On(e,t){const n=Xl(e.Fp,t.map(r=>r.Z));return t.map((r,s)=>e.fromAffine(r.toAffine(n[s])))}function nd(e,t){if(!Number.isSafeInteger(e)||e<=0||e>t)throw new Error("invalid window size, expected [1.."+t+"], got W="+e)}function Qo(e,t){nd(e,t);const n=Math.ceil(t/e)+1,r=2**(e-1),s=2**e,o=as(e),i=BigInt(e);return{windows:n,windowSize:r,mask:o,maxNumber:s,shiftBy:i}}function zc(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+=In);const u=t*r,f=u+Math.abs(a)-1,l=a===0,d=a<0,h=t%2!==0;return{nextN:c,offset:f,isZero:l,isNeg:d,isNegF:h,offsetF:u}}function Y1(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 X1(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 ei=new WeakMap,rd=new WeakMap;function ti(e){return rd.get(e)||1}function Fc(e){if(e!==dr)throw new Error("invalid wNAF")}class sd{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>dr;)n&In&&(r=r.add(s)),s=s.double(),n>>=In;return r}precomputeWindow(t,n){const{windows:r,windowSize:s}=Qo(n,this.bits),o=[];let i=t,a=i;for(let c=0;cdr||r>dr;)n&In&&(o=o.add(s)),r&In&&(i=i.add(s)),s=s.double(),n>>=In,r>>=In;return{p1:o,p2:i}}function od(e,t,n,r){Y1(n,e),X1(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=Zl(BigInt(s));let c=1;a>12?c=a-3:a>4?c=a-2:a>0&&(c=2);const u=as(c),f=new Array(Number(u)+1).fill(i),l=Math.floor((t.BITS-1)/c)*c;let d=i;for(let h=l;h>=0;h-=c){f.fill(i);for(let g=0;g>BigInt(h)&u);f[m]=f[m].add(n[g])}let p=i;for(let g=f.length-1,y=i;g>0;g--)y=y.add(f[g]),p=p.add(y);if(d=d.add(p),h!==0)for(let g=0;gdr))throw new Error(`CURVE.${c} must be positive bigint`)}const s=Gc(t.p,n.Fp,r),o=Gc(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 Wc=(e,t)=>(e+(e>=0?t:-t)/ad)/t;function Q1(e,t,n){const[[r,s],[o,i]]=t,a=Wc(i*e,n),c=Wc(-s*e,n);let u=e-a*r-c*o,f=-a*s-c*i;const l=u=h||f=h)throw new Error("splitScalar (endomorphism): failed, k="+e);return{k1neg:l,k1:u,k2neg:d,k2:f}}function Ki(e){if(!["compact","recovered","der"].includes(e))throw new Error('Signature format must be "compact", "recovered", or "der"');return e}function ni(e,t){const n={};for(let r of Object.keys(t))n[r]=e[r]===void 0?t[r]:e[r];return jn(n.lowS,"lowS"),jn(n.prehash,"prehash"),n.format!==void 0&&Ki(n.format),n}class ex extends Error{constructor(t=""){super(t)}}const Lt={Err:ex,_tlv:{encode:(e,t)=>{const{Err:n}=Lt;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}=Lt;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}=Lt;if(e{const{X:S,Y:w,Z:$}=K;if(r.eql($,r.ONE))return{x:S,y:w};const O=K.is0();E==null&&(E=O?r.ONE:r.inv($));const L=r.mul(S,E),U=r.mul(w,E),j=r.mul($,E);if(O)return{x:r.ZERO,y:r.ZERO};if(!r.eql(j,r.ONE))throw new Error("invZ was invalid");return{x:L,y:U}}),C=so(K=>{if(K.is0()){if(t.allowInfinityPoint&&!r.is0(K.Y))return;throw new Error("bad point: ZERO")}const{x:E,y:S}=K.toAffine();if(!r.isValid(E)||!r.isValid(S))throw new Error("bad point: x or y not field elements");if(!y(E,S))throw new Error("bad point: equation left != right");if(!K.isTorsionFree())throw new Error("bad point: not in prime-order subgroup");return!0});function P(K,E,S,w,$){return S=new B(r.mul(S.X,K),S.Y,S.Z),E=oo(w,E),S=oo($,S),E.add(S)}class B{constructor(E,S,w){this.X=b("x",E),this.Y=b("y",S,!0),this.Z=b("z",w),Object.freeze(this)}static CURVE(){return o}static fromAffine(E){const{x:S,y:w}=E||{};if(!E||!r.isValid(S)||!r.isValid(w))throw new Error("invalid affine point");if(E instanceof B)throw new Error("projective point not allowed");return r.is0(S)&&r.is0(w)?B.ZERO:new B(S,w,r.ONE)}static fromBytes(E){const S=B.fromAffine(p(ft(E,void 0,"point")));return S.assertValidity(),S}static fromHex(E){return B.fromBytes(ge("pointHex",E))}get x(){return this.toAffine().x}get y(){return this.toAffine().y}precompute(E=8,S=!0){return H.createCache(this,E),S||this.multiply(Ss),this}assertValidity(){C(this)}hasEvenY(){const{y:E}=this.toAffine();if(!r.isOdd)throw new Error("Field doesn't support isOdd");return!r.isOdd(E)}equals(E){x(E);const{X:S,Y:w,Z:$}=this,{X:O,Y:L,Z:U}=E,j=r.eql(r.mul(S,U),r.mul(O,$)),M=r.eql(r.mul(w,U),r.mul(L,$));return j&&M}negate(){return new B(this.X,r.neg(this.Y),this.Z)}double(){const{a:E,b:S}=o,w=r.mul(S,Ss),{X:$,Y:O,Z:L}=this;let U=r.ZERO,j=r.ZERO,M=r.ZERO,z=r.mul($,$),ce=r.mul(O,O),oe=r.mul(L,L),Q=r.mul($,O);return Q=r.add(Q,Q),M=r.mul($,L),M=r.add(M,M),U=r.mul(E,M),j=r.mul(w,oe),j=r.add(U,j),U=r.sub(ce,j),j=r.add(ce,j),j=r.mul(U,j),U=r.mul(Q,U),M=r.mul(w,M),oe=r.mul(E,oe),Q=r.sub(z,oe),Q=r.mul(E,Q),Q=r.add(Q,M),M=r.add(z,z),z=r.add(M,z),z=r.add(z,oe),z=r.mul(z,Q),j=r.add(j,z),oe=r.mul(O,L),oe=r.add(oe,oe),z=r.mul(oe,Q),U=r.sub(U,z),M=r.mul(oe,ce),M=r.add(M,M),M=r.add(M,M),new B(U,j,M)}add(E){x(E);const{X:S,Y:w,Z:$}=this,{X:O,Y:L,Z:U}=E;let j=r.ZERO,M=r.ZERO,z=r.ZERO;const ce=o.a,oe=r.mul(o.b,Ss);let Q=r.mul(S,O),le=r.mul(w,L),de=r.mul($,U),_e=r.add(S,w),ue=r.add(O,L);_e=r.mul(_e,ue),ue=r.add(Q,le),_e=r.sub(_e,ue),ue=r.add(S,$);let be=r.add(O,U);return ue=r.mul(ue,be),be=r.add(Q,de),ue=r.sub(ue,be),be=r.add(w,$),j=r.add(L,U),be=r.mul(be,j),j=r.add(le,de),be=r.sub(be,j),z=r.mul(ce,ue),j=r.mul(oe,de),z=r.add(j,z),j=r.sub(le,z),z=r.add(le,z),M=r.mul(j,z),le=r.add(Q,Q),le=r.add(le,Q),de=r.mul(ce,de),ue=r.mul(oe,ue),le=r.add(le,de),de=r.sub(Q,de),de=r.mul(ce,de),ue=r.add(ue,de),Q=r.mul(le,ue),M=r.add(M,Q),Q=r.mul(be,ue),j=r.mul(_e,j),j=r.sub(j,Q),Q=r.mul(_e,le),z=r.mul(be,z),z=r.add(z,Q),new B(j,M,z)}subtract(E){return this.add(E.negate())}is0(){return this.equals(B.ZERO)}multiply(E){const{endo:S}=t;if(!s.isValidNot0(E))throw new Error("invalid scalar: out of range");let w,$;const O=L=>H.cached(this,L,U=>On(B,U));if(S){const{k1neg:L,k1:U,k2neg:j,k2:M}=_(E),{p:z,f:ce}=O(U),{p:oe,f:Q}=O(M);$=ce.add(Q),w=P(S.beta,z,oe,L,j)}else{const{p:L,f:U}=O(E);w=L,$=U}return On(B,[w,$])[0]}multiplyUnsafe(E){const{endo:S}=t,w=this;if(!s.isValid(E))throw new Error("invalid scalar: out of range");if(E===Rt||w.is0())return B.ZERO;if(E===nr)return w;if(H.hasCache(this))return this.multiply(E);if(S){const{k1neg:$,k1:O,k2neg:L,k2:U}=_(E),{p1:j,p2:M}=J1(B,w,O,U);return P(S.beta,j,M,$,L)}else return H.unsafe(w,E)}multiplyAndAddUnsafe(E,S,w){const $=this.multiplyUnsafe(S).add(E.multiplyUnsafe(w));return $.is0()?void 0:$}toAffine(E){return I(this,E)}isTorsionFree(){const{isTorsionFree:E}=t;return i===nr?!0:E?E(B,this):H.unsafe(this,a).is0()}clearCofactor(){const{clearCofactor:E}=t;return i===nr?this:E?E(B,this):this.multiplyUnsafe(i)}isSmallOrder(){return this.multiplyUnsafe(i).is0()}toBytes(E=!0){return jn(E,"isCompressed"),this.assertValidity(),h(B,this,E)}toHex(E=!0){return Me(this.toBytes(E))}toString(){return``}get px(){return this.X}get py(){return this.X}get pz(){return this.Z}toRawBytes(E=!0){return this.toBytes(E)}_setWindowSize(E){this.precompute(E)}static normalizeZ(E){return On(B,E)}static msm(E,S){return od(B,s,E,S)}static fromPrivateKey(E){return B.BASE.multiply(Cn(s,E))}}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 N=s.BITS,H=new sd(B,t.endo?Math.ceil(N/2):N);return B.BASE.precompute(8),B}function cd(e){return Uint8Array.of(e?2:3)}function ud(e,t){return{secretKey:t.BYTES,publicKey:1+e.BYTES,publicKeyUncompressed:1+2*e.BYTES,publicKeyHasPrefix:!0,signature:2*t.BYTES}}function rx(e,t={}){const{Fn:n}=e,r=t.randomBytes||qn,s=Object.assign(ud(e.Fp,n),{seed:ed(n.ORDER)});function o(h){try{return!!Cn(n,h)}catch{return!1}}function i(h,p){const{publicKey:g,publicKeyUncompressed:y}=s;try{const m=h.length;return p===!0&&m!==g||p===!1&&m!==y?!1:!!e.fromBytes(h)}catch{return!1}}function a(h=r(s.seed)){return td(ft(h,s.seed,"seed"),n.ORDER)}function c(h,p=!0){return e.BASE.multiply(Cn(n,h)).toBytes(p)}function u(h){const p=a(h);return{secretKey:p,publicKey:c(p)}}function f(h){if(typeof h=="bigint")return!1;if(h instanceof e)return!0;const{secretKey:p,publicKey:g,publicKeyUncompressed:y}=s;if(n.allowedLengths||p===g)return;const m=ge("key",h).length;return m===g||m===y}function l(h,p,g=!0){if(f(h)===!0)throw new Error("first arg must be private key");if(f(p)===!1)throw new Error("second arg must be public key");const y=Cn(n,h);return e.fromHex(p).multiply(y).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:h=>Cn(n,h),precompute(h=8,p=e.BASE){return p.precompute(h,!1)}},lengths:s})}function sx(e,t,n={}){is(t),wr(n,{},{hmac:"function",lowS:"boolean",randomBytes:"function",bits2int:"function",bits2int_modN:"function"});const r=n.randomBytes||qn,s=n.hmac||((S,...w)=>wn(t,S,ve(...w))),{Fp:o,Fn:i}=e,{ORDER:a,BITS:c}=i,{keygen:u,getPublicKey:f,getSharedSecret:l,utils:d,lengths:h}=rx(e,n),p={prehash:!1,lowS:typeof n.lowS=="boolean"?n.lowS:!1,format:void 0,extraEntropy:!1},g="compact";function y(S){const w=a>>nr;return S>w}function m(S,w){if(!i.isValidNot0(w))throw new Error(`invalid signature ${S}: out of range 1..Point.Fn.ORDER`);return w}function v(S,w){Ki(w);const $=h.signature,O=w==="compact"?$:w==="recovered"?$+1:void 0;return ft(S,O,`${w} signature`)}class b{constructor(w,$,O){this.r=m("r",w),this.s=m("s",$),O!=null&&(this.recovery=O),Object.freeze(this)}static fromBytes(w,$=g){v(w,$);let O;if($==="der"){const{r:M,s:z}=Lt.toSig(ft(w));return new b(M,z)}$==="recovered"&&(O=w[0],$="compact",w=w.subarray(1));const L=i.BYTES,U=w.subarray(0,L),j=w.subarray(L,L*2);return new b(i.fromBytes(U),i.fromBytes(j),O)}static fromHex(w,$){return this.fromBytes(gt(w),$)}addRecoveryBit(w){return new b(this.r,this.s,w)}recoverPublicKey(w){const $=o.ORDER,{r:O,s:L,recovery:U}=this;if(U==null||![0,1,2,3].includes(U))throw new Error("recovery id invalid");if(a*ad<$&&U>1)throw new Error("recovery id is ambiguous for h>1 curve");const M=U===2||U===3?O+a:O;if(!o.isValid(M))throw new Error("recovery id 2 or 3 invalid");const z=o.toBytes(M),ce=e.fromBytes(ve(cd((U&1)===0),z)),oe=i.inv(M),Q=_(ge("msgHash",w)),le=i.create(-Q*oe),de=i.create(L*oe),_e=e.BASE.multiplyUnsafe(le).add(ce.multiplyUnsafe(de));if(_e.is0())throw new Error("point at infinify");return _e.assertValidity(),_e}hasHighS(){return y(this.s)}toBytes(w=g){if(Ki(w),w==="der")return gt(Lt.hexFromSig(this));const $=i.toBytes(this.r),O=i.toBytes(this.s);if(w==="recovered"){if(this.recovery==null)throw new Error("recovery bit must be present");return ve(Uint8Array.of(this.recovery),$,O)}return ve($,O)}toHex(w){return Me(this.toBytes(w))}assertValidity(){}static fromCompact(w){return b.fromBytes(ge("sig",w),"compact")}static fromDER(w){return b.fromBytes(ge("sig",w),"der")}normalizeS(){return this.hasHighS()?new b(this.r,i.neg(this.s),this.recovery):this}toDERRawBytes(){return this.toBytes("der")}toDERHex(){return Me(this.toBytes("der"))}toCompactRawBytes(){return this.toBytes("compact")}toCompactHex(){return Me(this.toBytes("compact"))}}const x=n.bits2int||function(w){if(w.length>8192)throw new Error("input is too large");const $=br(w),O=w.length*8-c;return O>0?$>>BigInt(O):$},_=n.bits2int_modN||function(w){return i.create(x(w))},I=as(c);function C(S){return Yr("num < 2^"+c,S,Rt,I),i.toBytes(S)}function P(S,w){return ft(S,void 0,"message"),w?ft(t(S),void 0,"prehashed message"):S}function B(S,w,$){if(["recovered","canonical"].some(le=>le in $))throw new Error("sign() legacy options not supported");const{lowS:O,prehash:L,extraEntropy:U}=ni($,p);S=P(S,L);const j=_(S),M=Cn(i,w),z=[C(M),C(j)];if(U!=null&&U!==!1){const le=U===!0?r(h.secretKey):U;z.push(ge("extraEntropy",le))}const ce=ve(...z),oe=j;function Q(le){const de=x(le);if(!i.isValidNot0(de))return;const _e=i.inv(de),ue=e.BASE.multiply(de).toAffine(),be=i.create(ue.x);if(be===Rt)return;const Ot=i.create(_e*i.create(oe+be*M));if(Ot===Rt)return;let et=(ue.x===be?0:2)|Number(ue.y&nr),Ne=Ot;return O&&y(Ot)&&(Ne=i.neg(Ot),et^=1),new b(be,Ne,et)}return{seed:ce,k2sig:Q}}function N(S,w,$={}){S=ge("message",S);const{seed:O,k2sig:L}=B(S,w,$);return K1(t.outputLen,i.BYTES,s)(O,L)}function H(S){let w;const $=typeof S=="string"||os(S),O=!$&&S!==null&&typeof S=="object"&&typeof S.r=="bigint"&&typeof S.s=="bigint";if(!$&&!O)throw new Error("invalid signature, expected Uint8Array, hex string or Signature instance");if(O)w=new b(S.r,S.s);else if($){try{w=b.fromBytes(ge("sig",S),"der")}catch(L){if(!(L instanceof Lt.Err))throw L}if(!w)try{w=b.fromBytes(ge("sig",S),"compact")}catch{return!1}}return w||!1}function K(S,w,$,O={}){const{lowS:L,prehash:U,format:j}=ni(O,p);if($=ge("publicKey",$),w=P(ge("message",w),U),"strict"in O)throw new Error("options.strict was renamed to lowS");const M=j===void 0?H(S):b.fromBytes(ge("sig",S),j);if(M===!1)return!1;try{const z=e.fromBytes($);if(L&&M.hasHighS())return!1;const{r:ce,s:oe}=M,Q=_(w),le=i.inv(oe),de=i.create(Q*le),_e=i.create(ce*le),ue=e.BASE.multiplyUnsafe(de).add(z.multiplyUnsafe(_e));return ue.is0()?!1:i.create(ue.x)===ce}catch{return!1}}function E(S,w,$={}){const{prehash:O}=ni($,p);return w=P(w,O),b.fromBytes(S,"recovered").recoverPublicKey(w).toBytes()}return Object.freeze({keygen:u,getPublicKey:f,getSharedSecret:l,utils:d,lengths:h,Point:e,sign:N,verify:K,recoverPublicKey:E,Signature:b,hash:t})}function ox(e){const t={a:e.a,b:e.b,p:e.Fp.ORDER,n:e.n,h:e.h,Gx:e.Gx,Gy:e.Gy},n=e.Fp;let r=e.allowedPrivateKeyLengths?Array.from(new Set(e.allowedPrivateKeyLengths.map(i=>Math.ceil(i/2)))):void 0;const s=zn(t.n,{BITS:e.nBitLength,allowedLengths:r,modFromBytes:e.wrapPrivateKey}),o={Fp:n,Fn:s,allowInfinityPoint:e.allowInfinityPoint,endo:e.endo,isTorsionFree:e.isTorsionFree,clearCofactor:e.clearCofactor,fromBytes:e.fromBytes,toBytes:e.toBytes};return{CURVE:t,curveOpts:o}}function ix(e){const{CURVE:t,curveOpts:n}=ox(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 ax(e,t){const n=t.Point;return Object.assign({},t,{ProjectivePoint:n,CURVE:Object.assign({},e,Jl(n.Fn.ORDER,n.Fn.BITS))})}function cx(e){const{CURVE:t,curveOpts:n,hash:r,ecdsaOpts:s}=ix(e),o=nx(t,n),i=sx(o,r,s);return ax(e,i)}/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */function ux(e,t){const n=r=>cx({...e,hash:r});return{...n(t),create:n}}/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */const hr={p:BigInt("0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f"),n:BigInt("0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141"),h:BigInt(1),a:BigInt(0),b:BigInt(7),Gx:BigInt("0x79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798"),Gy:BigInt("0x483ada7726a3c4655da4fbfc0e1108a8fd17b448a68554199c47d08ffb10d4b8")},fx={beta:BigInt("0x7ae96a2b657c07106e64479eac3434e99cf0497512f58995c1396c28719501ee"),basises:[[BigInt("0x3086d221a7d46bcde86c90e49284eb15"),-BigInt("0xe4437ed6010e88286f547fa90abfe4c3")],[BigInt("0x114ca50f7a8e2f3f657c1108d9d44cfd8"),BigInt("0x3086d221a7d46bcde86c90e49284eb15")]]},lx=BigInt(0),Yc=BigInt(1),Di=BigInt(2);function dx(e){const t=hr.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=ke(f,n,t)*f%t,d=ke(l,n,t)*f%t,h=ke(d,Di,t)*u%t,p=ke(h,s,t)*h%t,g=ke(p,o,t)*p%t,y=ke(g,a,t)*g%t,m=ke(y,c,t)*y%t,v=ke(m,a,t)*g%t,b=ke(v,n,t)*f%t,x=ke(b,i,t)*p%t,_=ke(x,r,t)*u%t,I=ke(_,Di,t);if(!io.eql(io.sqr(I),e))throw new Error("Cannot find square root");return I}const io=zn(hr.p,{sqrt:dx}),We=ux({...hr,Fp:io,lowS:!0,endo:fx},st),Xc={};function ao(e,...t){let n=Xc[e];if(n===void 0){const r=st(Je(e));n=ve(r,r),Xc[e]=n}return st(ve(n,...t))}const Za=e=>e.toBytes(!0).slice(1),xr=We.Point,Va=e=>e%Di===lx;function Mi(e){const{Fn:t,BASE:n}=xr,r=Cn(t,e),s=n.multiply(r);return{scalar:Va(s.y)?r:t.neg(r),bytes:Za(s)}}function fd(e){const t=io;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);Va(s)||(s=t.neg(s));const o=xr.fromAffine({x:e,y:s});return o.assertValidity(),o}const Cr=br;function ld(...e){return xr.Fn.create(Cr(ao("BIP0340/challenge",...e)))}function Jc(e){return Mi(e).bytes}function hx(e,t,n=qn(32)){const{Fn:r}=xr,s=ge("message",e),{bytes:o,scalar:i}=Mi(t),a=ge("auxRand",n,32),c=r.toBytes(i^Cr(ao("BIP0340/aux",a))),u=ao("BIP0340/nonce",c,o,s),{bytes:f,scalar:l}=Mi(u),d=ld(f,o,s),h=new Uint8Array(64);if(h.set(f,0),h.set(r.toBytes(r.create(l+d*i)),32),!dd(h,s,o))throw new Error("sign: Invalid signature produced");return h}function dd(e,t,n){const{Fn:r,BASE:s}=xr,o=ge("signature",e,64),i=ge("message",t),a=ge("publicKey",n,32);try{const c=fd(Cr(a)),u=Cr(o.subarray(0,32));if(!ji(u,Yc,hr.p))return!1;const f=Cr(o.subarray(32,64));if(!ji(f,Yc,hr.n))return!1;const l=ld(r.toBytes(u),Za(c),i),d=s.multiplyUnsafe(f).add(c.multiplyUnsafe(r.neg(l))),{x:h,y:p}=d.toAffine();return!(d.is0()||!Va(p)||h!==u)}catch{return!1}}const hd=(()=>{const n=(s=qn(48))=>td(s,hr.n);We.utils.randomSecretKey;function r(s){const o=n(s);return{secretKey:o,publicKey:Jc(o)}}return{keygen:r,getPublicKey:Jc,sign:hx,verify:dd,Point:xr,utils:{randomSecretKey:n,randomPrivateKey:n,taggedHash:ao,lift_x:fd,pointToBytes:Za,numberToBytesBE:Ao,bytesToNumberBE:br,mod:xe},lengths:{secretKey:32,publicKey:32,publicKeyHasPrefix:!1,signature:64,seed:48}}})(),co=Me,px=gt,cn="super-testnet-local-v0";class xn{constructor(t){if(!/^[0-9a-f]{64}$/.test(t)||!We.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=co(hd.getPublicKey(t)),this.address=Lr.p2tr.fromPubKey(this.pubkey,"regtest"),this.script=["OP_1",this.pubkey]}static create(){return new xn(co(We.utils.randomPrivateKey()))}static load(t){if((t==null?void 0:t.network)!==cn||(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 xn(t.secret)}backup(){return{kind:"test-wallet",version:1,network:cn,secret:this.secret}}sign(t,n,r=0){return ko.taproot.sign(this.secret,t,r,n?{extension:n}:{}).hex}}const ri=50*1e8,$s="0".repeat(64),Qc=e=>co(st(new TextEncoder().encode(JSON.stringify(e)))),_s=(e,t)=>`${e}:${t}`,Ge=e=>$e.encode(e,!1).hex,pe=(e,t)=>{if(!e)throw new Error(t)},gx=/^5120[0-9a-f]{64}$/,si=/^0014[0-9a-f]{40}$/,pd=64,ht=8,mx=e=>co(Kl(st(px(e))));function yx(e,t){const[n,r]=e.vin[t].witness;return We.verify(n.slice(0,-2),ko.segwit.hash(e,t,{pubkey:r,sigflag:1}),r,{lowS:!0,format:"der"})}class Bo{constructor(t){if(this.blocks=[],this.mempool=[],this.utxos=new Map,this.transactions=new Map,t){pe(t.network===cn&&t.version===1,"Unsupported local chain version/network."),pe(Array.isArray(t.blocks)&&Array.isArray(t.mempool),"Invalid chain snapshot.");for(const n of t.blocks)this.acceptBlock(structuredClone(n));this.submitPackage(t.mempool)}}snapshot(){return{network:cn,version:1,blocks:structuredClone(this.blocks),mempool:[...this.mempool]}}coins(t){return[...this.utxos.values()].filter(n=>Ge(n.scriptPubKey)===Ge(t))}satLocation(t){for(const n of this.utxos.values()){const r=Os(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 y,m,v;pe(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);pe(!this.transactions.has(o),"Duplicate transaction."),pe(s.version===2&&s.locktime===0,"Unsupported transaction version or locktime.");const i=!r&&s.vin.some(b=>{var x;return((x=b.witness)==null?void 0:x.length)===3}),a=r?1:i?2:ht,c=r?pd:i?2:ht;pe(s.vin.length>=1&&s.vin.length<=a&&s.vout.length>=1&&s.vout.length<=c,"Unsupported transaction shape.");let u=0;for(const b of s.vout){const x=Number(b.value);pe(Number.isSafeInteger(x)&&x>=330&&x<=ri,"Invalid output amount.");const _=Ge(b.scriptPubKey);pe(gx.test(_)||si.test(_),"Only Taproot and P2WPKH outputs are supported."),u+=x}let f,l=[];const d=s.vin.findIndex(b=>{var x;return((x=b.witness)==null?void 0:x.length)===3}),h=s.vin[d<0?0:d];if(r)pe(h.txid===$s&&h.vout===4294967295&&u===ri,"Invalid local coinbase."),pe(Ge(h.scriptSig)===$e.encode([new TextEncoder().encode(`${cn}:${n}`)],!1).hex,"Wrong coinbase height."),pe(!((y=h.witness)!=null&&y.length),"Unexpected coinbase witness.");else{l=s.vin.map(x=>this.utxos.get(_s(x.txid,x.vout))),pe(l.every(Boolean),"Input is missing or already spent."),pe(new Set(s.vin.map(x=>_s(x.txid,x.vout))).size===s.vin.length,"Duplicate input."),s.vin.forEach((x,_)=>{var C,P,B;pe(x.sequence==="ffffffff"&&Ge(x.scriptSig)==="","Unsupported input flags."),x.prevout={value:l[_].value,scriptPubKey:l[_].scriptPubKey};const I=Ge(l[_].scriptPubKey);if(si.test(I)){const[N,H]=x.witness??[];pe(_!==d&&((C=x.witness)==null?void 0:C.length)===2,"Unsupported witness."),pe(/^30[0-9a-f]{12,140}01$/.test(N)&&/^0[23][0-9a-f]{64}$/.test(H)&&mx(H)===I.slice(4),"P2WPKH spends need a SIGHASH_ALL signature by the key they pay.");return}pe(((P=x.witness)==null?void 0:P.length)===1||_===d&&((B=x.witness)==null?void 0:B.length)===3,"Unsupported witness."),pe(/^[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.")}),pe(l.reduce((x,_)=>x+_.value,0)-u===fe,"v0 requires a fixed 500 sat fee per transaction.");let b={};if(h.witness.length===3){const x=La(h.witness),_=d;if(pe(Number(s.vout[_].value)===Et,"Invalid reveal postage."),pe(Ge(s.vout[_].scriptPubKey)===`5120${x.pubkey}`,"Reveal must return to its signing wallet."),x.parent){const I=d===0?1:0,C=l[I];pe((m=C==null?void 0:C.inscriptions)==null?void 0:m.some(P=>P.id===x.parent),"Referenced parent inscription must actually be spent."),pe(s.vout.length===2&&Number(s.vout[I].value)===C.value&&Ge(C.scriptPubKey)===`5120${x.pubkey}`&&Ge(s.vout[I].scriptPubKey)===Ge(C.scriptPubKey),"Parent must be owned and preserved in the same wallet.")}else s.vin.length===2&&(pe(d===1&&((v=l[0].inscriptions)==null?void 0:v.length)&&x.pointer!==void 0,"Reinscription spend requires correct tag and owned sat."),pe(Number(s.vout[0].value)===l[0].value&&Ge(s.vout[0].scriptPubKey)===Ge(l[0].scriptPubKey)&&Ge(l[0].scriptPubKey)===`5120${x.pubkey}`,"Reinscription sat must be returned to owner."));b={pubkey:x.pubkey},f={id:`${o}i0`,txid:o,commitTxid:h.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:Et}}s.vin.forEach((x,_)=>{let I=!1;try{I=si.test(Ge(l[_].scriptPubKey))?yx(s,_):ko.taproot.verify(s,_,_===d?b:{})}catch{}pe(I,"Invalid signature or Taproot commitment.")})}const p=vu(s,l,n,r),g=l.flatMap(b=>b.inscriptions??[]);if(f){const b=BigInt(f.pointer??0),x=b{var I;return((I=_.inscription)==null?void 0:I.sat)===f.sat}).length,g.push(f)}return pe(g.every(b=>p.some(x=>Os(x,b.sat)!==null)),"Local lab protects inscription sats from fee loss."),r||s.vin.forEach(b=>this.utxos.delete(_s(b.txid,b.vout))),s.vout.forEach((b,x)=>{const _=g.filter(I=>Os(p[x],I.sat)!==null);this.utxos.set(_s(o,x),{txid:o,vout:x,value:Number(b.value),scriptPubKey:b.scriptPubKey,height:n,ranges:p[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){pe(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;pe(t.height===this.blocks.length+1&&t.previous===(((i=this.blocks.at(-1))==null?void 0:i.hash)??$s),"Invalid block ancestry."),pe(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;pe(Qc(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([Ue(ri,t)])}mineTo(t){var a;const n=new Bo({...this.snapshot(),mempool:[]}),r=this.blocks.length+1,s=ie.create({vin:[{txid:$s,vout:4294967295,scriptSig:[new TextEncoder().encode(`${cn}:${r}`)]}],vout:t}),o={height:r,previous:((a=this.blocks.at(-1))==null?void 0:a.hash)??$s,time:Date.now(),raws:[ie.encode(s).hex,...this.mempool]},i={...o,hash:Qc(o)};return n.acceptBlock(i),Object.assign(this,n),i}}/*! scure-base - MIT License (c) 2022 Paul Miller (paulmillr.com) */function pr(e){return e instanceof Uint8Array||ArrayBuffer.isView(e)&&e.constructor.name==="Uint8Array"}function bx(e,...t){if(!pr(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 gd(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 md(e){if(typeof e!="function")throw new Error("function expected");return!0}function Dn(e,t){if(typeof t!="string")throw new Error(`${e}: string expected`);return!0}function vr(e){if(!Number.isSafeInteger(e))throw new Error(`invalid integer: ${e}`)}function uo(e){if(!Array.isArray(e))throw new Error("array expected")}function fo(e,t){if(!gd(!0,t))throw new Error(`${e}: array of strings expected`)}function qa(e,t){if(!gd(!1,t))throw new Error(`${e}: array of numbers expected`)}function cs(...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 To(e){const t=typeof e=="string"?e.split(""):e,n=t.length;fo("alphabet",t);const r=new Map(t.map((s,o)=>[s,o]));return{encode:s=>(uo(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=>(uo(s),s.map(o=>{Dn("alphabet.decode",o);const i=r.get(o);if(i===void 0)throw new Error(`Unknown letter: "${o}". Allowed: ${e}`);return i}))}}function Io(e=""){return Dn("join",e),{encode:t=>(fo("join.decode",t),t.join(e)),decode:t=>(Dn("join.decode",t),t.split(e))}}function yd(e,t="="){return vr(e),Dn("padding",t),{encode(n){for(fo("padding.encode",n);n.length*e%8;)n.push(t);return n},decode(n){fo("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 Zi(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(uo(e),!e.length)return[];let r=0;const s=[],o=Array.from(e,a=>{if(vr(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:bd(t,e%t),lo=(e,t)=>e+(t-bd(e,t)),Us=(()=>{let e=[];for(let t=0;t<40;t++)e.push(2**t);return e})();function ho(e,t,n,r){if(uo(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(lo(t,n)>32)throw new Error(`convertRadix2: carry overflow from=${t} to=${n} carryBits=${lo(t,n)}`);let s=0,o=0;const i=Us[t],a=Us[n]-1,c=[];for(const u of e){if(vr(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=Us[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 wd(e){vr(e);const t=2**8;return{encode:n=>{if(!pr(n))throw new Error("radix.encode input should be Uint8Array");return Zi(Array.from(n),t,e)},decode:n=>(qa("radix.decode",n),Uint8Array.from(Zi(n,e,t)))}}function za(e,t=!1){if(vr(e),e<=0||e>32)throw new Error("radix2: bits should be in (0..32]");if(lo(8,e)>32||lo(e,8)>32)throw new Error("radix2: carry overflow");return{encode:n=>{if(!pr(n))throw new Error("radix2.encode input should be Uint8Array");return ho(Array.from(n),8,e,!t)},decode:n=>(qa("radix2.decode",n),Uint8Array.from(ho(n,e,8,t)))}}function eu(e){return md(e),function(...t){try{return e.apply(null,t)}catch{}}}function xd(e,t){return vr(e),md(t),{encode(n){if(!pr(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(!pr(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{Dn("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"})},St=wx?{encode(e){return bx(e),e.toBase64()},decode(e){return xx(e)}}:cs(za(6),To("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"),yd(6),Io("")),vx=e=>cs(wd(58),To(e),Io("")),Ex=vx("123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"),vd=e=>cs(xd(4,t=>e(e(t))),Ex),Vi=cs(To("qpzry9x8gf2tvdw0s3jn54khce6mua7l"),Io("")),tu=[996825010,642813549,513874426,1027748829,705979059];function Ar(e){const t=e>>25;let n=(e&33554431)<<5;for(let r=0;r>r&1)===1&&(n^=tu[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=Ar(s)^i>>5}s=Ar(s);for(let o=0;oh)throw new TypeError(`Length ${g} exceeds limit ${h}`);const y=l.toLowerCase(),m=nu(y,d,t);return`${y}1${Vi.encode(d)}${m}`}function a(l,d=90){Dn("bech32.decode input",l);const h=l.length;if(h<8||d!==!1&&h>d)throw new TypeError(`invalid string length: ${h} (${l}). Expected (8..${d})`);const p=l.toLowerCase();if(l!==p&&l!==l.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 y=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 v=Vi.decode(m).slice(0,-6),b=nu(y,v,t);if(!m.endsWith(b))throw new Error(`Invalid checksum in ${l}: expected "${b}"`);return{prefix:y,words:v}}const c=eu(a);function u(l){const{prefix:d,words:h}=a(l,!1);return{prefix:d,words:h,bytes:r(h)}}function f(l,d){return i(l,s(d))}return{encode:i,decode:a,encodeFromBytes:f,decodeToBytes:u,decodeUnsafe:c,fromWords:r,fromWordsUnsafe:o,toWords:s}}const po=kx("bech32");/*! scure-bip32 - MIT License (c) 2022 Patricio Palladino, Paul Miller (paulmillr.com) */const Bs=We.ProjectivePoint,oi=vd(st);function ru(e){De(e);const t=e.length===0?"0":Me(e);return BigInt("0x"+t)}function Sx(e){if(typeof e!="bigint")throw new Error("bigint expected");return gt(e.toString(16).padStart(64,"0"))}const $x=Je("Bitcoin seed"),ii={private:76066276,public:76067358},ai=2147483648,_x=e=>Kl(st(e)),Ax=e=>Un(e).getUint32(0,!1),Ts=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 Un(t).setUint32(0,e,!1),t};class $n{get fingerprint(){if(!this.pubHash)throw new Error("No publicKey set!");return Ax(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 oi.encode(this.serialize(this.versions.private,ve(new Uint8Array([0]),t)))}get publicExtendedKey(){if(!this.pubKey)throw new Error("No public key");return oi.encode(this.serialize(this.versions.public,this.pubKey))}static fromMasterSeed(t,n=ii){if(De(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=wn(Wr,$x,t);return new $n({versions:n,chainCode:r.slice(32),privateKey:r.slice(0,32)})}static fromExtendedKey(t,n=ii){const r=oi.decode(t),s=Un(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 $n({...i,privateKey:a.slice(1)}):new $n({...i,publicKey:a})}static fromJSON(t){return $n.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||ii,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(!We.utils.isValidPrivateKey(t.privateKey))throw new Error("Invalid private key");this.privKey=typeof t.privateKey=="bigint"?t.privateKey:ru(t.privateKey),this.privKeyBytes=Sx(this.privKey),this.pubKey=We.getPublicKey(t.privateKey,!0)}else if(t.publicKey)this.pubKey=Bs.fromHex(t.publicKey).toRawBytes(!0);else throw new Error("HDKey: no public or private key provided");this.pubHash=_x(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>=ai)throw new Error("Invalid index");o[2]==="'"&&(a+=ai),r=r.deriveChild(a)}return r}deriveChild(t){if(!this.pubKey||!this.chainCode)throw new Error("No publicKey or chainCode set");let n=Ts(t);if(t>=ai){const a=this.privateKey;if(!a)throw new Error("Could not derive hardened child key");n=ve(new Uint8Array([0]),a,n)}else n=ve(this.pubKey,n);const r=wn(Wr,this.chainCode,n),s=ru(r.slice(0,32)),o=r.slice(32);if(!We.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=xe(this.privKey+s,We.CURVE.n);if(!We.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=Bs.fromHex(this.pubKey).add(Bs.fromPrivateKey(s));if(a.equals(Bs.ZERO))throw new Error("The tweak was equal to negative P, which made the result key invalid");i.publicKey=a.toRawBytes(!0)}return new $n(i)}catch{return this.deriveChild(t+1)}}sign(t){if(!this.privateKey)throw new Error("No privateKey set!");return De(t,32),We.sign(t,this.privKey).toCompactRawBytes()}verify(t,n){if(De(t,32),De(n,64),!this.publicKey)throw new Error("No publicKey set!");let r;try{r=We.Signature.fromCompact(n)}catch{return!1}return We.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 De(n,33),ve(Ts(t),new Uint8Array([this.depth]),Ts(this.parentFingerprint),Ts(this.index),this.chainCode,n)}}function Bx(e,t,n,r){is(e);const s=m1({dkLen:32,asyncTick:10},r),{c:o,dkLen:i,asyncTick:a}=s;if(dn(o),dn(i),dn(a),o<1)throw new Error("iterations (c) should be >= 1");const c=Hc(t),u=Hc(n),f=new Uint8Array(i),l=wn.create(e,c),d=l._cloneInto().update(u);return{c:o,dkLen:i,asyncTick:a,DK:f,PRF:l,PRFSalt:d}}function Tx(e,t,n,r,s){return e.destroy(),t.destroy(),r&&r.destroy(),Tt(s),n}function Ix(e,t,n,r){const{c:s,dkLen:o,DK:i,PRF:a,PRFSalt:c}=Bx(e,t,n,r);let u;const f=new Uint8Array(4),l=Un(f),d=new Uint8Array(a.outputLen);for(let h=1,p=0;pe[0]==="あいこくしん";function Ed(e){if(typeof e!="string")throw new TypeError("invalid mnemonic type: "+typeof e);return e.normalize("NFKD")}function kd(e){const t=Ed(e),n=t.split(" ");if(![12,15,18,21,24].includes(n.length))throw new Error("Invalid mnemonic");return{nfkd:t,words:n}}function Sd(e){De(e,16,20,24,28,32)}function Cx(e,t=128){if(dn(t),t%32!==0||t>256)throw new TypeError("Invalid entropy");return _d(qn(t/8),e)}const Px=e=>{const t=8-e.length/4;return new Uint8Array([st(e)[0]>>t<{if(typeof t!="string")throw new Error("wordlist: non-string element: "+t)}),As.chain(As.checksum(1,Px),As.radix2(11,!0),As.alphabet(e))}function Ux(e,t){const{words:n}=kd(e),r=$d(t).decode(n);return Sd(r),r}function _d(e,t){return Sd(e),$d(t).encode(e).join(Ox(t)?" ":" ")}function Nx(e,t){try{Ux(e,t)}catch{return!1}return!0}const Lx=e=>Ed("mnemonic"+e);function Rx(e,t=""){return Ix(Wr,kd(e).nfkd,Lx(t),{c:2048,dkLen:64})}const Fa=`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(` -`),rt={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`},Hx=2**31-1,ci=new Map,ui=new Map,su=()=>Cx(Fa,256);function Ad(e,t=0){if(typeof e!="string"||!Nx(e,Fa)||t&&e.split(" ").length!==t)throw new Error("Invalid lab mnemonic.");return e}function Er(e,t){if(!Number.isSafeInteger(e)||e<0||e>Hx)throw new Error(`Invalid ${t}.`);return e}const fi=new Map;function Ga(e){return fi.has(e)||fi.set(e,Rx(Ad(e))),fi.get(e)}function kr(e){return ci.has(e)||ci.set(e,$n.fromMasterSeed(Ga(e))),ci.get(e)}function jx(e,t){const n=e.derive(t).privateKey;if(!n)throw new Error("BIP-85 path produced no private key.");return wn(Wr,Je("bip-entropy-from-k"),n)}function Kx(e,t){const n=`${e}|${Er(t,"child index")}`;return ui.has(n)||ui.set(n,_d(jx(kr(e),rt.orgSeed(t)).slice(0,32),Fa)),ui.get(n)}function qi(e,t=0,n=1){return Me(kr(e).derive(rt.wallet(Er(t,"account"),n)).privateKey)}function Bd(e,t=0,n=1){return Me(kr(e).derive(rt.segwit(Er(t,"account"),n)).privateKey)}function Td(e,t=0,n=1){return Me(kr(e).derive(rt.segwit(Er(t,"account"),n)).publicKey)}function Wa(e,t=0){return Me(kr(e).derive(rt.nostr(Er(t,"account"))).privateKey)}function Dx(e,t=0){const n=hd.getPublicKey(kr(e).derive(rt.nostr(Er(t,"account"))).privateKey);return{pubkey:Me(n),npub:po.encode("npub",po.toWords(n))}}const Id="lineage-claim",zi=330,go=e=>$e.encode(e,!1).hex,ou=e=>({txid:e.txid,vout:e.vout,value:e.value,script:go(e.scriptPubKey)}),li=/^[0-9a-f]{64}$/,Mx=/^5120[0-9a-f]{64}$/;function Oo(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 Od(e){return ie.create({vin:[jt(e.holder.txid,e.holder.vout,e.holder.value,e.holder.script),jt(e.payer.txid,e.payer.vout,e.payer.value,e.payer.script)],vout:[Ue(e.holder.value,["OP_1",e.to]),Ue(e.payer.value-fe,["OP_1",e.to])]})}function Zx(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=Oo(e,t);if(!s)throw new Error("That inscription is not in an unspent output.");if(go(s.scriptPubKey)===go(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>=fe+zi});if(!o)throw new Error("The recipient needs a plain coin for the 500-sat fee. Mine a block to it first.");const i={kind:Id,version:1,inscription:t,carried:s.inscriptions.map(c=>c.id),holder:ou(s),payer:ou(o),to:n.pubkey,at:r},a=Od(i);return i.txid=ie.util.getTxid(a),i.sig=n.sign(a,void 0,1),i}function Vx(e,t,n){const r=zx(t);if((n==null?void 0:n.kind)!=="test-wallet")throw new Error("Countersigning needs a local test wallet.");if(go(n.script)!==r.holder.script)throw new Error("Only the current holder can countersign.");if(qx(e,r)!=="open")throw new Error("This claim is stale: an input it spends was already spent.");const s=Od(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 qx(e,t){return e.utxos.has(`${t.holder.txid}:${t.holder.vout}`)&&e.utxos.has(`${t.payer.txid}:${t.payer.vout}`)?"open":"stale"}function zx(e){const t=n=>n&&li.test(n.txid)&&Number.isSafeInteger(n.vout)&&n.vout>=0&&Number.isSafeInteger(n.value)&&n.value>=zi&&Mx.test(n.script);if((e==null?void 0:e.kind)!==Id||e.version!==1||!/^[0-9a-f]{64}i\d+$/.test(e.inscription)||!Array.isArray(e.carried)||!t(e.holder)||!t(e.payer)||e.payer.value255*s)throw new Error("Length should be <= 255*HashLen");const o=Math.ceil(r/s);n===void 0&&(n=iu);const i=new Uint8Array(o*s),a=wn.create(e,t),c=a._cloneInto(),u=new Uint8Array(a.outputLen);for(let f=0;fGx(e,Fx(e,t,n),r,s);/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */const rn=BigInt(0),Ce=BigInt(1),hi=BigInt(2),Yx=BigInt(8);function Xx(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 Jx(e,t={}){const n=id("edwards",e,t,t.FpFnLE),{Fp:r,Fn:s}=n;let o=n.CURVE;const{h:i}=o;wr(t,{},{uvRatio:"function"});const a=hi<r.create(y),u=t.uvRatio||((y,m)=>{try{return{isValid:!0,value:r.sqrt(r.div(y,m))}}catch{return{isValid:!1,value:rn}}});if(!Xx(r,o,o.Gx,o.Gy))throw new Error("bad curve params: generator point");function f(y,m,v=!1){const b=v?Ce:rn;return Yr("coordinate "+y,m,b,a),m}function l(y){if(!(y instanceof p))throw new Error("ExtendedPoint expected")}const d=so((y,m)=>{const{X:v,Y:b,Z:x}=y,_=y.is0();m==null&&(m=_?Yx:r.inv(x));const I=c(v*m),C=c(b*m),P=r.mul(x,m);if(_)return{x:rn,y:Ce};if(P!==Ce)throw new Error("invZ was invalid");return{x:I,y:C}}),h=so(y=>{const{a:m,d:v}=o;if(y.is0())throw new Error("bad point: ZERO");const{X:b,Y:x,Z:_,T:I}=y,C=c(b*b),P=c(x*x),B=c(_*_),N=c(B*B),H=c(C*m),K=c(B*c(H+P)),E=c(N+c(v*c(C*P)));if(K!==E)throw new Error("bad point: equation left != right (1)");const S=c(b*x),w=c(_*I);if(S!==w)throw new Error("bad point: equation left != right (2)");return!0});class p{constructor(m,v,b,x){this.X=f("x",m),this.Y=f("y",v),this.Z=f("z",b,!0),this.T=f("t",x),Object.freeze(this)}static CURVE(){return o}static fromAffine(m){if(m instanceof p)throw new Error("extended point not allowed");const{x:v,y:b}=m||{};return f("x",v),f("y",b),new p(v,b,Ce,c(v*b))}static fromBytes(m,v=!1){const b=r.BYTES,{a:x,d:_}=o;m=Zc(ft(m,b,"point")),jn(v,"zip215");const I=Zc(m),C=m[b-1];I[b-1]=C&-129;const P=Kn(I),B=v?a:r.ORDER;Yr("point.y",P,rn,B);const N=c(P*P),H=c(N-Ce),K=c(_*N-x);let{isValid:E,value:S}=u(H,K);if(!E)throw new Error("bad point: invalid y coordinate");const w=(S&Ce)===Ce,$=(C&128)!==0;if(!v&&S===rn&&$)throw new Error("bad point: x=0 and x_0=1");return $!==w&&(S=c(-S)),p.fromAffine({x:S,y:P})}static fromHex(m,v=!1){return p.fromBytes(ge("point",m),v)}get x(){return this.toAffine().x}get y(){return this.toAffine().y}precompute(m=8,v=!0){return g.createCache(this,m),v||this.multiply(hi),this}assertValidity(){h(this)}equals(m){l(m);const{X:v,Y:b,Z:x}=this,{X:_,Y:I,Z:C}=m,P=c(v*C),B=c(_*x),N=c(b*C),H=c(I*x);return P===B&&N===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:v,Y:b,Z:x}=this,_=c(v*v),I=c(b*b),C=c(hi*c(x*x)),P=c(m*_),B=v+b,N=c(c(B*B)-_-I),H=P+I,K=H-C,E=P-I,S=c(N*K),w=c(H*E),$=c(N*E),O=c(K*H);return new p(S,w,O,$)}add(m){l(m);const{a:v,d:b}=o,{X:x,Y:_,Z:I,T:C}=this,{X:P,Y:B,Z:N,T:H}=m,K=c(x*P),E=c(_*B),S=c(C*b*H),w=c(I*N),$=c((x+_)*(P+B)-K-E),O=w-S,L=w+S,U=c(E-v*K),j=c($*O),M=c(L*U),z=c($*U),ce=c(O*L);return new p(j,M,ce,z)}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:v,f:b}=g.cached(this,m,x=>On(p,x));return On(p,[v,b])[0]}multiplyUnsafe(m,v=p.ZERO){if(!s.isValid(m))throw new Error("invalid scalar: expected 0 <= sc < curve.n");return m===rn?p.ZERO:this.is0()||m===Ce?this:g.unsafe(this,m,b=>On(p,b),v)}isSmallOrder(){return this.multiplyUnsafe(i).is0()}isTorsionFree(){return g.unsafe(this,o.n).is0()}toAffine(m){return d(this,m)}clearCofactor(){return i===Ce?this:this.multiplyUnsafe(i)}toBytes(){const{x:m,y:v}=this.toAffine(),b=r.toBytes(v);return b[b.length-1]|=m&Ce?128:0,b}toHex(){return Me(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 On(p,m)}static msm(m,v){return od(p,s,m,v)}_setWindowSize(m){this.precompute(m)}toRawBytes(){return this.toBytes()}}p.BASE=new p(o.Gx,o.Gy,Ce,c(o.Gx*o.Gy)),p.ZERO=new p(rn,Ce,Ce,rn),p.Fp=r,p.Fn=s;const g=new sd(p,s.BITS);return p.BASE.precompute(8),p}function Qx(e,t,n={}){if(typeof t!="function")throw new Error('"hash" function param is required');wr(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||(B=>B),u=n.domain||((B,N,H)=>{if(jn(H,"phflag"),N.length||H)throw new Error("Contexts/pre-hash are not supported");return B});function f(B){return i.create(Kn(B))}function l(B){const N=b.secretKey;B=ge("private key",B,N);const H=ge("hashed private key",t(B),2*N),K=c(H.slice(0,N)),E=H.slice(N,2*N),S=f(K);return{head:K,prefix:E,scalar:S}}function d(B){const{head:N,prefix:H,scalar:K}=l(B),E=s.multiply(K),S=E.toBytes();return{head:N,prefix:H,scalar:K,point:E,pointBytes:S}}function h(B){return d(B).pointBytes}function p(B=Uint8Array.of(),...N){const H=ve(...N);return f(t(u(H,ge("context",B),!!r)))}function g(B,N,H={}){B=ge("message",B),r&&(B=r(B));const{prefix:K,scalar:E,pointBytes:S}=d(N),w=p(H.context,K,B),$=s.multiply(w).toBytes(),O=p(H.context,$,S,B),L=i.create(w+O*E);if(!i.isValid(L))throw new Error("sign failed: invalid s");const U=ve($,i.toBytes(L));return ft(U,b.signature,"result")}const y={zip215:!0};function m(B,N,H,K=y){const{context:E,zip215:S}=K,w=b.signature;B=ge("signature",B,w),N=ge("message",N),H=ge("publicKey",H,b.publicKey),S!==void 0&&jn(S,"zip215"),r&&(N=r(N));const $=w/2,O=B.subarray(0,$),L=Kn(B.subarray($,w));let U,j,M;try{U=e.fromBytes(H,S),j=e.fromBytes(O,S),M=s.multiplyUnsafe(L)}catch{return!1}if(!S&&U.isSmallOrder())return!1;const z=p(E,j.toBytes(),U.toBytes(),N);return j.add(U.multiplyUnsafe(z)).subtract(M).clearCofactor().is0()}const v=o.BYTES,b={secretKey:v,publicKey:v,signature:2*v,seed:v};function x(B=a(b.seed)){return ft(B,b.seed,"seed")}function _(B){const N=P.randomSecretKey(B);return{secretKey:N,publicKey:h(N)}}function I(B){return os(B)&&B.length===i.BYTES}function C(B,N){try{return!!e.fromBytes(B,N)}catch{return!1}}const P={getExtendedPublicKey:d,randomSecretKey:x,isValidSecretKey:I,isValidPublicKey:C,toMontgomery(B){const{y:N}=e.fromBytes(B),H=b.publicKey,K=H===32;if(!K&&H!==57)throw new Error("only defined for 25519 and 448");const E=K?o.div(Ce+N,Ce-N):o.div(N-Ce,N+Ce);return o.toBytes(E)},toMontgomerySecret(B){const N=b.secretKey;ft(B,N);const H=t(B.subarray(0,N));return c(H).subarray(0,N)},randomPrivateKey:x,precompute(B=8,N=e.BASE){return N.precompute(B,!1)}};return Object.freeze({keygen:_,getPublicKey:h,sign:g,verify:m,utils:P,Point:e,lengths:b})}function e2(e){const t={a:e.a,d:e.d,p:e.Fp.ORDER,n:e.n,h:e.h,Gx:e.Gx,Gy:e.Gy},n=e.Fp,r=zn(t.n,e.nBitLength,!0),s={Fp:n,Fn:r,uvRatio:e.uvRatio},o={randomBytes:e.randomBytes,adjustScalarBytes:e.adjustScalarBytes,domain:e.domain,prehash:e.prehash,mapToCurve:e.mapToCurve};return{CURVE:t,curveOpts:s,hash:e.hash,eddsaOpts:o}}function t2(e,t){const n=t.Point;return Object.assign({},t,{ExtendedPoint:n,CURVE:e,nBitLength:n.Fn.BITS,nByteLength:n.Fn.BYTES})}function n2(e){const{CURVE:t,curveOpts:n,hash:r,eddsaOpts:s}=e2(e),o=Jx(t,n),i=Qx(o,r,s);return t2(e,i)}/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */const Br=BigInt(0),Xn=BigInt(1),Is=BigInt(2);function r2(e){return wr(e,{adjustScalarBytes:"function",powPminus2:"function"}),Object.freeze({...e})}function s2(e){const t=r2(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,f=a?32:56,l=BigInt(a?9:5),d=BigInt(a?121665:39081),h=a?Is**BigInt(254):Is**BigInt(447),p=a?BigInt(8)*Is**BigInt(251)-Xn:BigInt(4)*Is**BigInt(445)-Xn,g=h+p+Xn,y=E=>xe(E,n),m=v(l);function v(E){return Da(y(E),f)}function b(E){const S=ge("u coordinate",E,f);return a&&(S[31]&=127),y(Kn(S))}function x(E){return Kn(s(ge("scalar",E,f)))}function _(E,S){const w=P(b(S),x(E));if(w===Br)throw new Error("invalid private or public key received");return v(w)}function I(E){return _(E,m)}function C(E,S,w){const $=y(E*(S-w));return S=y(S-$),w=y(w+$),{x_2:S,x_3:w}}function P(E,S){Yr("u",E,Br,n),Yr("scalar",S,h,g);const w=S,$=E;let O=Xn,L=Br,U=E,j=Xn,M=Br;for(let ce=BigInt(u-1);ce>=Br;ce--){const oe=w>>ce&Xn;M^=oe,{x_2:O,x_3:U}=C(M,O,U),{x_2:L,x_3:j}=C(M,L,j),M=oe;const Q=O+L,le=y(Q*Q),de=O-L,_e=y(de*de),ue=le-_e,be=U+j,Ot=U-j,et=y(Ot*Q),Ne=y(be*de),Ct=et+Ne,$r=et-Ne;U=y(Ct*Ct),j=y($*y($r*$r)),O=y(le*_e),L=y(ue*(le+y(d*ue)))}({x_2:O,x_3:U}=C(M,O,U)),{x_2:L,x_3:j}=C(M,L,j);const z=o(L);return y(O*z)}const B={secretKey:f,publicKey:f,seed:f},N=(E=c(f))=>(De(E,B.seed),E);function H(E){const S=N(E);return{secretKey:S,publicKey:I(S)}}return{keygen:H,getSharedSecret:(E,S)=>_(E,S),getPublicKey:E=>I(E),scalarMult:_,scalarMultBase:I,utils:{randomSecretKey:N,randomPrivateKey:N},GuBytes:m.slice(),lengths:B}}/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */const o2=BigInt(1),au=BigInt(2),i2=BigInt(3),a2=BigInt(5),c2=BigInt(8),Ya=BigInt("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffed"),Cd={p:Ya,n:BigInt("0x1000000000000000000000000000000014def9dea2f79cd65812631a5cf5d3ed"),h:c2,a:BigInt("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffec"),d:BigInt("0x52036cee2b6ffe738cc740797779e89800700a4d4141d8ab75eb4dca135978a3"),Gx:BigInt("0x216936d3cd6e53fec0a4e231fdd6dc5c692cc7609525a7b2c9562d608f25d51a"),Gy:BigInt("0x6666666666666666666666666666666666666666666666666666666666666658")};function Pd(e){const t=BigInt(10),n=BigInt(20),r=BigInt(40),s=BigInt(80),o=Ya,a=e*e%o*e%o,c=ke(a,au,o)*a%o,u=ke(c,o2,o)*e%o,f=ke(u,a2,o)*u%o,l=ke(f,t,o)*f%o,d=ke(l,n,o)*l%o,h=ke(d,r,o)*d%o,p=ke(h,s,o)*h%o,g=ke(p,s,o)*h%o,y=ke(g,t,o)*f%o;return{pow_p_5_8:ke(y,au,o)*e%o,b2:a}}function Ud(e){return e[0]&=248,e[31]&=127,e[31]|=64,e}const cu=BigInt("19681161376707505956807079304988542015446066515923890162744021073123829784752");function u2(e,t){const n=Ya,r=xe(t*t*t,n),s=xe(r*r*t,n),o=Pd(e*s).pow_p_5_8;let i=xe(e*r*o,n);const a=xe(t*i*i,n),c=i,u=xe(i*cu,n),f=a===e,l=a===xe(-e,n),d=a===xe(-e*cu,n);return f&&(i=c),(l||d)&&(i=u),z1(i,n)&&(i=xe(-i,n)),{isValid:f||l,value:i}}const Nd=zn(Cd.p,{isLE:!0}),f2={...Cd,Fp:Nd,hash:Wr,adjustScalarBytes:Ud,uvRatio:u2},Co=n2(f2),Ld=(()=>{const e=Nd.ORDER;return s2({P:e,type:"x25519",powPminus2:t=>{const{pow_p_5_8:n,b2:r}=Pd(t);return xe(ke(n,i2,e)*r,e)},adjustScalarBytes:Ud})})(),l2=Je("lineage/v0"),$t=(e,t)=>Wx(st,e,l2,Je(t),32),Po=e=>{const t=Uint8Array.from(e);return t[0]&=248,t[31]&=127,t[31]|=64,t},Rd=e=>{const t=new Uint8Array(4);return new DataView(t.buffer).setUint32(0,e),t},it=e=>ve(Rd(e.length),e),Xa=e=>ve(it(Je("ssh-ed25519")),it(e)),Fi=(e,t)=>`ssh-ed25519 ${St.encode(Xa(e))}${t?` ${t}`:""}`,Gi=e=>`SHA256:${St.encode(st(Xa(e))).replace(/=+$/,"")}`;function d2(e){const t=gt(e),n=r=>Co.getPublicKey($t(t,r));return{ssh:n("ssh"),git:n("git"),dkim:n("dkim"),wg:Ld.getPublicKey(Po($t(t,"wg")))}}function h2(e){const t=n=>Co.getPublicKey($t(e,n));return{"ssh-ca":t("node/ssh-ca"),mtls:t("node/mtls"),noise:Ld.getPublicKey(Po($t(e,"node/noise")))}}function p2(e,t,n,r){return[["ssh",Gi(e.ssh),Fi(e.ssh,t)],["git",Gi(e.git),`${t} namespaces="git" ${Fi(e.git,t)}`],["dkim",`${n}._domainkey.${r}`,`${n}._domainkey.${r}. IN TXT "v=DKIM1; k=ed25519; p=${St.encode(e.dkim)}"`],["wg",St.encode(e.wg),`[Peer] -# ${t} -PublicKey = ${St.encode(e.wg)}`]]}function g2(e,t){return[["ssh-ca",Gi(e["ssh-ca"]),Fi(e["ssh-ca"],`lineage-ca@${t}`)],["mtls",St.encode(e.mtls),null],["noise",`mkey:${Me(e.noise)}`,null]]}const m2=gt("302e020100300506032b657004220420");function Hd(e,t,n){const r=st(e).slice(0,4);let s=ve(r,r,it(Je("ssh-ed25519")),it(t),it(ve(e,t)),it(Je(n)));s=ve(s,new Uint8Array((8-s.length%8)%8).map((i,a)=>a+1));const o=ve(Je("openssh-key-v1\0"),it(Je("none")),it(Je("none")),it(new Uint8Array(0)),Rd(1),it(Xa(t)),it(s));return`-----BEGIN OPENSSH PRIVATE KEY----- -${St.encode(o).match(/.{1,70}/g).join(` -`)} ------END OPENSSH PRIVATE KEY----- -`}const y2=(e,t)=>`-----BEGIN ${e}----- -${St.encode(t).match(/.{1,64}/g).join(` -`)} ------END ${e}----- -`;function b2(e,t){const n=gt(e),r=s=>{const o=$t(n,s);return Hd(o,Co.getPublicKey(o),t)};return[["ssh","OpenSSH private key",r("ssh")],["git","OpenSSH private key",r("git")],["dkim","Ed25519 private key (base64)",St.encode($t(n,"dkim"))],["wg","Interface entry",`[Interface] -PrivateKey = ${St.encode(Po($t(n,"wg")))}`]]}function w2(e,t){const n=$t(e,"node/ssh-ca");return[["ssh-ca","OpenSSH private key",Hd(n,Co.getPublicKey(n),`lineage-ca@${t}`)],["mtls","Private key (PKCS#8 PEM)",y2("PRIVATE KEY",ve(m2,$t(e,"node/mtls")))],["noise","noise_private.key",`privkey:${Me(Po($t(e,"node/noise")))}`]]}const x2=["bip86","tapkey","wallet"],Ja=()=>({scheme:"bip86",roots:{},adopted:{}}),v2=e=>Vs.getPubKey(e)[0];function jd(e,t,n){return e.scheme==="wallet"?qi(t,n):Vs.getSecKey(e.scheme==="tapkey"?Wa(t,n):qi(t,n))[0]}const Kd=(e,t)=>e.scheme==="tapkey"?rt.nostr(t):rt.wallet(t),E2=(e,t)=>new xn(jd(e,t,0)),Be=e=>$e.encode(e,!1).hex;function vn(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=vn(e,t,s);return i&&{...i,account:n.index+1}}if(n.edge==="adopted")return r(e.adopted[n.id]);const o=vn(e,t,s);return o&&{mnemonic:Kx(o.mnemonic,n.index),account:0,origin:o.origin,steps:[...o.steps,`${n.index}'`]}}const pi=new Map;function Te(e,t,n){const r=vn(e,t,n);if(!r)return null;const s=`${e.scheme}|${r.mnemonic}|${r.account}`;if(!pi.has(s)){const{npub:u,pubkey:f}=Dx(r.mnemonic,r.account);pi.set(s,{wallet:new xn(jd(e,r.mnemonic,r.account)),npub:u,pubkey:f})}const{wallet:o,npub:i,pubkey:a}=pi.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} · ${Kd(e,r.account)}`}}function k2(e,t,n){const r=vn(e,t,n);if(!r)return null;const s=Te(e,t,n),o=Td(r.mnemonic,r.account);return{taproot:{address:s.wallet.address,path:Kd(e,r.account)},segwit:{address:Lr.p2wpkh.fromPubKey(o,"regtest"),path:rt.segwit(r.account)},tapkey:{address:Lr.p2tr.fromPubKey(v2(s.pubkey),"regtest"),path:rt.nostr(r.account)},npub:{address:s.npub,path:rt.nostr(r.account)}}}function Qa(e,t,n){const r=Oo(e.chain,n);if(!r)return null;const s=Be(r.scriptPubKey),o=t.nodes.get(n),i=Te(e.keys,t,o),a=o&&Te(e.keys,t,t.nodes.get(o.parent));return i&&Be(i.wallet.script)===s?{wallet:i.wallet,who:"own"}:e.wallet&&Be(e.wallet.script)===s?{wallet:e.wallet,who:"lab"}:a&&Be(a.wallet.script)===s?{wallet:a.wallet,who:"parent"}:{wallet:null,who:"other",script:s}}function Uo(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(...Uo(e,s))}return r}function Wi(e,t){const n=[];for(let r=t;r;r=e.nodes.get(r.parent))n.push(r.name);return n.join(".")}function S2(e,t,n){const r=vn(e,t,n);if(!r)return null;if(n.kind!=="agent")return g2(h2(Ga(r.mnemonic)),Wi(t,n));const s=Wi(t,t.nodes.get(n.parent));return p2(d2(Wa(r.mnemonic,r.account)),`${n.name}@${s}`,n.name,s)}const $2=vd(st),Tr=(e,t=239)=>$2.encode(ve(Uint8Array.of(t),gt(e),Uint8Array.of(1))),_2=e=>po.encode("nsec",po.toWords(gt(e))),A2="0123456789()[],'/*abcdefgh@:$%{}IJKLMNOPQRSTUVWXYZ&+-.;<=>?!^_|~ijklmnopqrstuvwxyzABCDEFGH`#\"\\ ",B2=[0xf5dee51989n,0xa9fdca3312n,0x1bab10e32dn,0x3706b1677an,0x644d626ffdn];function gi(e){const t=(i,a)=>{const c=i>>35n;return i=(i&0x7ffffffffn)<<5n^BigInt(a),B2.forEach((u,f)=>{c>>BigInt(f)&1n&&(i^=u)}),i};let n=1n,r=0,s=0;for(const i of e){const a=A2.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 T2(e,t,n){const r=vn(e,t,n);if(!r)return null;const s=Wa(r.mnemonic,r.account),o=qi(r.mnemonic,r.account),i={bip86:`tr(${Tr(o)})`,tapkey:`tr(${Tr(s)})`,wallet:`rawtr(${Tr(o)})`}[e.scheme],a=n.kind==="agent",c=Wi(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",_2(s)],["taproot","descriptor",gi(i)],["segwit","descriptor",gi(`wpkh(${Tr(Bd(r.mnemonic,r.account))})`)],["tapkey","descriptor",gi(`tr(${Tr(s)})`)]],leaves:a?b2(s,`${n.name}@${c}`):w2(Ga(r.mnemonic),c)}}const Xr=1e8,Qe=50*Xr,Oe=330,Dd=e=>(e/Xr).toFixed(8).replace(/\.?0+$/,""),ae=e=>`${Dd(e)} tBTC`;function ec(e){if(e<1e6)return ae(e);const t=Math.round(e/1e6)*1e6;return`${t===e?"":"≈"}${ae(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)*Xr+Number((t[2]??"").padEnd(8,"0"))}class Md{constructor(t,n,r){this.secret=t,this.pubkey=n,this.path=r,this.address=Lr.p2wpkh.fromPubKey(n,"regtest"),this.script=Lr.toScriptPubKey(this.address)}sign(t,n){return[ko.segwit.sign(this.secret,t,n,{pubkey:this.pubkey}).hex,this.pubkey]}}const mi=new Map;function Ee(e,t,n){const r=vn(e,t,n);if(!r)return null;const s=`${r.mnemonic}|${r.account}`;return mi.has(s)||mi.set(s,new Md(Bd(r.mnemonic,r.account),Td(r.mnemonic,r.account),rt.segwit(r.account))),mi.get(s)}function I2(e,t,n){var s;const r=n?t.nodes.get(n):null;return(r==null?void 0:r.kind)==="holding"&&r.status==="active"?((s=Ee(e,t,r))==null?void 0:s.script)??null:null}const rr=(e,t)=>{var n,r;return((r=(n=e.mining)==null?void 0:n.rigs)==null?void 0:r[t])??1};function nc(e,t){var n;return((n=e.mining)==null?void 0:n.rule)==="none"?[]:t.roots.filter(r=>r.status==="active"&&rr(e,r.id)>0&&Ee(e.keys,t,r)).slice(0,pd)}function Zd(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=I2(e.keys,t,n);return c?[{script:c,value:Qe}]:null}const r=nc(e,t),s=r.reduce((c,u)=>c+rr(e,u.id),0);let o=Qe;return r.length?r.map((c,u)=>{const f=u===r.length-1?o:Math.floor(Qe*rr(e,c.id)/s);return o-=f,{script:Ee(e.keys,t,c).script,value:f}}):null}function Jr(e,t,n=ht){const r=t+fe,s=u=>u===r||u-r>=Oe&&u-r<=Qe,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 sc(e,t=ht){let n=0,r=-fe;for(const s of e.map(o=>o.value).sort((o,i)=>i-o).slice(0,t)){r+=s;const o=r<=Qe?r:r-Qe>=Oe?Qe:r-Oe;o>=Oe&&r-o<=Qe&&(n=Math.max(n,o))}return n}function Vd(e,t,n,r=ht,s="send"){const o=rc(t),i=n+fe,a=sc(t,r),c=`${s[0].toUpperCase()}${s.slice(1)}`;if(od.value).sort((d,h)=>h-d),f=u.slice(0,r).map((d,h)=>u.slice(0,h+1).reduce((p,g)=>p+g,0)),l=Math.min(...[...u,...u.flatMap((d,h)=>u.slice(h+1).map(p=>d+p)),...f].filter(d=>d>=i));return Number.isFinite(l)&&l-inew Set((e.offers??[]).flatMap(t=>t.payers.map(n=>`${n.txid}:${n.vout}`))),zd=(e,t)=>e.chain.coins(t.script).filter(n=>{var r;return!((r=n.inscriptions)!=null&&r.length)}),Fd=(e,t,n=ht)=>!!Jr(e,t,n),Gd=(e,t,n)=>Fd(zd(e,t),n);function oc(e,t,n,r,s="This node",o="send"){const i=zd(e,t),a=qd(e),c=Jr(i.filter(d=>!a.has(`${d.txid}:${d.vout}`)),r)??Jr(i,r);if(!c)throw new Error(Vd(s,i,r,ht,o));const u=rc(c)-r-fe,f=ie.create({vin:c.map(d=>jt(d.txid,d.vout,d.value,d.scriptPubKey)),vout:[Ue(r,n),...u?[Ue(u,t.script)]:[]]});c.forEach((d,h)=>{f.vin[h].witness=t instanceof Md?t.sign(f,h):[t.sign(f,void 0,h)]});const l=ie.encode(f).hex;return e.chain.submitPackage([l]),ie.util.getTxid(l)}function Wd(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=Ee(e.keys,t,o),c=Ee(e.keys,t,i);if(!a||!c)throw new Error("A holding that predates lab keys has no SegWit addresses.");if(!Number.isSafeInteger(s)||sQe)throw new Error("Send at most 50 test BTC at a time: no output on this chain is bigger than one block reward.");return oc(e,a,c.script,s,o.name)}function O2(e,t,n){if(!t||!n||Be(t.script)===Be(n.script))return 0;let r=0;for(const s of e.chain.coins(t.script)){if(s.value-fe[t,...t.log.flatMap((n,r)=>n.ok&&n.op==="graduate"?[bn(e.slice(0,r),{pending:!0})]:[])];function Yd(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 C2=(e,t,n)=>Yd(ic(t,n),(r,s)=>{const o=Ee(e,r,s);return o&&Be(o.script)}),yi=new Map,P2=(e,t,n)=>Yd(ic(t,n),(r,s)=>{const o=vn(e,r,s),i=o&&`${e.scheme}|${o.mnemonic}|${o.account}`;return i&&!yi.has(i)&&yi.set(i,Be(Te(e,r,s).wallet.script)),i?yi.get(i):null}),ac=(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 U2(e,t,n,r){for(const s of ic(t,n))for(const o of s.nodes.values()){const i=Te(e,s,o);if(i&&Be(i.wallet.script)===r)return{node:o.id,wallet:i.wallet}}return null}function N2(e,t,n=new Map,r=new Map){var a;const s=[],o=c=>t.get(Be(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:Be(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 h=u.vin.map(x=>{var I;const _=(I=e.transactions.get(x.txid))==null?void 0:I.tx.vout[x.vout];return _?{node:o(_.scriptPubKey),value:Number(_.value)}:null}),p=r.get(c);if(p&&h.length>1&&h[0]&&h.slice(1).every(x=>(x==null?void 0:x.node)===p.buyer)){s.push({kind:"deal",key:c,txid:c,beat:f,from:p.buyer,to:p.seller,amount:p.price,item:p.item,fee:i(h)-i(d),change:i(d.filter(x=>x.node===p.buyer))});continue}if(h.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(h)-i(d),change:i(d.filter(_=>!_.node))});continue}const g=(a=h[0])==null?void 0:a.node;if(!g||!h.every(x=>(x==null?void 0:x.node)===g))continue;const y=d.filter(x=>x.node!==g),m=d.filter(x=>x.node===g),v=i(h)-i(d),b={key:c,txid:c,beat:f,from:g,fee:v};y.length&&y.every(x=>n.get(x.script)===g)?s.push({...b,kind:"gas",to:g,amount:i(y),change:i(m)}):y.length?s.push({...b,kind:"pay",to:y[0].node,amount:y[0].value,change:i(m)}):s.push({...b,kind:"move",to:g,amount:i(m),change:0})}return s}function Yi(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(Be(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 Xi="lineage-offer",uu=/^[0-9a-f]{64}$/,bi=/^[0-9a-f]{64}i0$/,fu=/^5120[0-9a-f]{64}$/,wi=/^0014[0-9a-f]{40}$/,lu=e=>({txid:e.txid,vout:e.vout,value:e.value,script:Be(e.scriptPubKey)}),du=(e,t)=>!e.utxos.has(`${t.txid}:${t.vout}`),Xd=e=>{const t=_o(new ss(e.chain));return{events:t,state:bn(t,{pending:!0})}};function Jd(e){return ie.create({vin:[e.holder,...e.payers].map(t=>jt(t.txid,t.vout,t.value,t.script)),vout:[Ue(e.holder.value,e.to),...e.price?[Ue(e.price,e.pay)]:[],...e.change?[Ue(e.change,e.back)]:[]]})}function cc(e,t,n,r){const s=Oo(e.chain,r),o=s&&U2(e.keys,t,n,Be(s.scriptPubKey));return o?{coin:s,node:n.nodes.get(o.node),wallet:o.wallet}:null}function Qd(e,t,n,r,s=Date.now()){const{events:o,state:i}=Xd(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&&rQe)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),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 b of[c,f])if(b.status!=="active")throw new Error(`${b.name} is ${b.status}.`);const l=Ee(e.keys,i,c),d=Ee(e.keys,i,f),h=Te(e.keys,i,c);if(!l||!d||!h)throw new Error("A holding that predates lab keys cannot trade.");if((e.offers??[]).some(b=>b.item===t&&b.buyer===c.id&&Ji(e,i,b)==="open"))throw new Error(`${c.name} already has an open offer on ${a.name}. Withdraw it first.`);const p=e.chain.coins(l.script),g=qd(e),y=Jr(p.filter(b=>!g.has(`${b.txid}:${b.vout}`)),r,ht-1)??Jr(p,r,ht-1);if(!y)throw new Error(Vd(c.name,p,r,ht-1,"offer"));const m={kind:Xi,version:1,item:t,buyer:c.id,seller:f.id,price:r,holder:lu(u.coin),payers:y.map(lu),to:Be(h.wallet.script),pay:Be(d.script),back:Be(l.script),change:y.reduce((b,x)=>b+x.value,0)-r-fe,at:s},v=Jd(m);return m.txid=ie.util.getTxid(v),m.witnesses=y.map((b,x)=>l.sign(v,x+1)),(e.offers??(e.offers=[])).push(m),m}function uc(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(du(e.chain,n.holder))return`${s} has moved since`;if(n.payers.some(f=>du(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?Be(f.script):"";return a((u=Te(e.keys,t,o))==null?void 0:u.wallet)!==n.to||a(Ee(e.keys,t,o))!==n.back?`${o.name} has new keys since`:n.price&&a(Ee(e.keys,t,i))!==n.pay?`${i.name} has new keys since`:""}const Ji=(e,t,n)=>e.chain.transactions.has(n.txid)?"done":uc(e,t,n)?"stale":"open";function L2(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}=Xd(e),o=uc(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=Jd(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 R2(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 H2(e){const t=(r,s)=>r&&uu.test(r.txid)&&Number.isSafeInteger(r.vout)&&r.vout>=0&&Number.isSafeInteger(r.value)&&r.value>=Oe&&r.value<=Qe&&s.test(r.script),n=r=>Number.isSafeInteger(r)&&(r===0||r>=Oe&&r<=Qe);if((e==null?void 0:e.kind)!==Xi||e.version!==1||!bi.test(e.item)||!bi.test(e.buyer)||!bi.test(e.seller)||e.buyer===e.seller||!n(e.price)||!n(e.change)||!t(e.holder,fu)||!Array.isArray(e.payers)||!e.payers.length||e.payers.length>ht-1||!e.payers.every(r=>t(r,wi))||!fu.test(e.to)||!wi.test(e.pay)||!wi.test(e.back)||!uu.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:Xi,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 No="orgchain:lab:v1",j2=["each",10,30,60,"manual"];function us(e={tempo:"each",nextAt:null}){const{tempo:t,nextAt:n}=e??{},r=typeof t=="number";if(!j2.includes(t)||!(n===null||r&&Number.isSafeInteger(n)&&n>0))throw new Error("Invalid clock.");return{tempo:t,nextAt:n}}function eh(e){const t=Ja();for(const n of["roots","adopted"])for(const[r,s]of Object.entries((e==null?void 0:e[n])??{})){if(!/^[0-9a-f]{64}i0$/.test(r))throw new Error("Invalid lab keys.");t[n][r]=Ad(s,24)}if(t.scheme=(e==null?void 0:e.scheme)??(Object.keys(t.roots).length?"wallet":"bip86"),!x2.includes(t.scheme))throw new Error("Invalid lab keys.");return t}const K2=["split","last","none"];function fs(e){const t=(e==null?void 0:e.rule)??"split",n={};if(!K2.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 th(e=[]){if(!Array.isArray(e)||e.length>1e3)throw new Error("Invalid offers.");const t=e.map(H2);if(new Set(t.map(n=>n.txid)).size!==t.length)throw new Error("Invalid offers.");return t}const ls=()=>({wallet:null,chain:new Bo,clock:us(),keys:Ja(),mining:fs(),offers:[]});function nh(e){if(!e)return ls();const t=JSON.parse(e);if((t==null?void 0:t.kind)!=="orgchain-lab"||t.network!==cn||t.version!==1)throw new Error("That is not an Orgchain v1 lab.");return{wallet:t.wallet?xn.load(t.wallet):null,chain:new Bo(t.chain),clock:us(t.clock),keys:eh(t.keys),mining:fs(t.mining),offers:th(t.offers)}}const rh=e=>{var t;return JSON.stringify({kind:"orgchain-lab",network:cn,version:1,wallet:((t=e.wallet)==null?void 0:t.backup())??null,chain:e.chain.snapshot(),clock:us(e.clock),keys:eh(e.keys),mining:fs(e.mining),offers:th(e.offers)})};function D2(e,t,n){var r;e.mining=fs({...e.mining,rigs:{...(r=e.mining)==null?void 0:r.rigs,[t]:n}})}function M2(e,t){e.mining=fs({...e.mining,rule:t})}const fc=()=>nh(localStorage.getItem(No));function Z2(e){try{localStorage.setItem(No,rh(e))}catch{throw new Error("Browser storage is full or unavailable, so nothing was saved. Save a backup, then reset.")}}async function V2(e,{locks:t=(s=>(s=globalThis.navigator)==null?void 0:s.locks)(),read:n=fc,save:r=Z2}={}){if(!t)throw new Error("Orgchain needs Web Locks: open it over HTTPS or on localhost.");return t.request(No,async()=>{const o=n(),i=await e(o);return i!==!1&&r(o),{lab:o,result:i}})}function mt(e,t=null){e.wallet||(e.wallet=xn.create());const n=t!=null&&t.length?e.chain.mineTo(t.map(r=>Ue(r.value,r.script))):e.chain.mine(e.wallet.script);return e.clock=us({tempo:e.clock.tempo,nextAt:null}),n}function Sr(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 q2(e,t,n=Date.now(),r=null){e.clock=us({tempo:t,nextAt:null}),t==="each"&&e.chain.mempool.length?mt(e,r):Sr(e,n)}function z2(e,t=Date.now(),n=null){const{tempo:r,nextAt:s}=e.clock;return typeof r!="number"||!e.chain.mempool.length?!1:s===null?(Sr(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}`,graduate:()=>"graduate",close:()=>"close"};function G2(e,t={}){if(!Object.hasOwn(hu,e))throw new Error("Unknown verb.");const n={op:e};for(const r of hu[e]){const s=t[r];typeof s=="string"&&s.trim()&&(n[r]=s.trim())}return n}const _t=e=>bn(_o(new ss(e.chain)),{pending:!0});function sh(e,t,n,r){const s=G2(t,r),o=_o(new ss(e.chain)),i={id:"check",status:"pending",height:null,metadata:s,parent:n??null,protocol:Ra},{ok:a,why:c}=bn([...o,i],{pending:!0}).log.at(-1);if(!a)throw new Error(`${c[0].toUpperCase()}${c.slice(1)}.`);return s}const Qi=Et+2*fe+330,oh=1e5,lc=1e4,dc=(e,t=0)=>Et+2*fe+(e==="birth"?1:e==="graduate"?Math.max(0,t-1):0)*fe+330,W2=(e,t=0)=>dc(e,t)-330,gr=(e,t,n)=>e.chain.coins(t.script).find(r=>{var s;return!((s=r.inscriptions)!=null&&s.length)&&r.value>=n}),ea=e=>jt(e.txid,e.vout,e.value,e.scriptPubKey),ih=(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=Ja()),e.wallet||(e.wallet=xn.create()),gr(e,e.wallet,oh+fe+330)||mt(e)}function ah(e,t,n=Qi,r=oh){if(t===e.wallet||gr(e,t,n))return;const s=gr(e,e.wallet,r+fe+330),o=ie.create({vin:[ea(s)],vout:[Ue(r,t.script),Ue(s.value-r-fe,e.wallet.script)]});e.chain.submitPackage([ih(o,[e.wallet])])}function pu(e,t,n,r,s){if(r===e.wallet||gr(e,r,s))return;const o=n&&Ee(e.keys,t,n);if(!o)return ah(e,r,s);oc(e,o,r.script,Math.max(lc,s),n.name)}function Y2(e,t,n,r,s){if(r===e.wallet||gr(e,r,s))return!0;const o=n&&Ee(e.keys,t,n);return!o||Gd(e,o,Math.max(lc,s))}function ch(e,t,n,r,s={}){var f,l;const o=r?t.nodes.get(r):null,i=o&&((f=Qa(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&&Te(e.keys,t,a)?Uo(t,a.id).length:0;if(!Y2(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?Ee(e.keys,t,a):null;return u&&!Fd(e.chain.coins(u.script).filter(d=>d.value-fe>=Oe).map(d=>({value:d.value-fe})),lc)?`${a.name} needs test BTC of its own to claim its new root. Send it some first`:""}function gu(e,t,n,r,s=n){const o=Oo(e.chain,t),i=gr(e,s,fe+330),a=ie.create({vin:[ea(o),ea(i)],vout:[Ue(o.value,r.script),Ue(i.value-fe,s.script)]});e.chain.submitPackage([ih(a,[n,s])])}function mu(e,t,n,r,s){return new c1(e.chain,t).inscribe(F2[n](s),r??null,s,{metaprotocol:Ra})}const Lo=(e,t)=>{var r;const n=_t(e);return Zd(e,n,((r=n.nodes.get(t))==null?void 0:r.root)??null)},Ro=(e,t)=>Zd(e,_t(e),t);function pc(e){var r,s,o;const t=_t(e),n=new Map;for(const i of t.nodes.values())for(const a of[Ee(e.keys,t,i),(r=Te(e.keys,t,i))==null?void 0:r.wallet])a&&n.set(Be(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],f=u&&n.get(Be(u.scriptPubKey));if(f)return f}}return null}function yu(e,t,n){var s;const r=Qa(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 uh(e,t,n,r){if(t==="found"){const f=su(),l=E2(e.keys,f);ah(e,l,Qi,Qi);const d=mu(e,l,t,null,r);return e.keys.roots[d]=f,d}const s=_t(e),o=yu(e,s,n),i=s.nodes.get(n),a=t==="graduate"?s.nodes.get(r.of):null,c=a&&Te(e.keys,s,a)?Uo(s,a.id).map(f=>[f.id,yu(e,s,f.id)]):[];pu(e,s,i,o,dc(t,c.length));const u=mu(e,o,t,n,r);if(t==="birth"){const f=_t(e),l=Te(e.keys,f,f.nodes.get(u));l&&gu(e,u,o,l.wallet)}if(c.length){e.keys.adopted[a.id]=su();const f=_t(e);for(const[l,d]of c){const h=Te(e.keys,f,f.nodes.get(l)).wallet;if(O2(e,Ee(e.keys,s,s.nodes.get(l)),Ee(e.keys,f,f.nodes.get(l))),l!==a.id){gu(e,l,d,h,o);continue}pu(e,f,f.nodes.get(l),h,fe+330),Vx(e.chain,Zx(e.chain,l,h),d)}}return u}function X2(e,t,n,r,s=Date.now()){const o=sh(e,t,n,r),i=ch(e,_t(e),t,n??null,o);if(i)throw new Error(`${i}.`);hc(e);const a=uh(e,t,n??null,o);return e.clock.tempo==="each"?mt(e,Lo(e,n??a)):Sr(e,s),a}function J2(e,t,n,r,s=Date.now()){const o=Wd(e,_t(e),t,n,r);return e.clock.tempo==="each"?mt(e,Lo(e,t)):Sr(e,s),o}const Q2=(e,t,n,r,s=Date.now())=>Qd(e,t,n,r,s);function ev(e,t,n=Date.now()){const r=L2(e,t);return e.clock.tempo==="each"?mt(e,Lo(e,r.seller)):Sr(e,n),r}const tv=(e,t)=>R2(e,t);function nv(e,t,n,r=Date.now()){const s=_t(e),o=s.nodes.get(t);if((o==null?void 0:o.kind)!=="holding")throw new Error("Pick a holding to fund.");if(o.status!=="active")throw new Error(`${o.name} is closed.`);const i=Ee(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)||nQe)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),Gd(e,e.wallet,n)||mt(e);const a=oc(e,e.wallet,i.script,n,"The lab wallet","fund");return e.clock.tempo==="each"?mt(e,Lo(e,t)):Sr(e,r),a}const ta="yolopreneur",rv=[[["found",null,{name:"yolopreneur"}]],[["birth","yolopreneur",{name:"well-known",kind:"org"}],["birth","yolopreneur",{name:"time",kind:"org"}]],[["send","yolopreneur",{to:"time",amount:40}],["send","yolopreneur",{to:"well-known",amount:10}],["birth","well-known",{name:"mailr",kind:"org"}],["birth","well-known",{name:"lineage",kind:"org"}],["birth","time",{name:"luna",kind:"agent"}],["birth","time",{name:"sol",kind:"agent"}],["birth","time",{name:"astra",kind:"agent"}]],[["send","well-known",{to:"lineage",amount:2}],["birth","time",{name:"docscope",kind:"org"}],["birth","time",{name:"dollhouse",kind:"org"}],["birth","time",{name:"doodleloop",kind:"org"}],["birth","time",{name:"hearthframe",kind:"org"}]],[["send","time",{to:"sol",amount:1}],["send","time",{to:"luna",amount:.5}],["award","time",{to:"sol",skill:"launch",belt:"green"}],["award","time",{to:"luna",skill:"post",belt:"white"}],["decide","yolopreneur",{title:"Every venture gets a page",why:".yolopreneur.lol, served from one pages branch."}],["make","sol",{name:"launch-kit",note:"The page, the post and the checklist every venture launches with."}]],[["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 sv(e){hc(e),e.chain.mempool.length&&mt(e);const t={},n={};for(const r of rv){for(const[s,o,i]of r){if(s==="send"){Wd(e,_t(e),t[o],t[i.to],i.amount*Xr);continue}if(s==="offer"){Qd(e,n[i.item],t[o],i.price*Xr);continue}const a=Object.fromEntries(Object.entries(i).map(([f,l])=>[f,f==="to"||f==="of"?t[l]:l])),c=o?t[o]:null,u=uh(e,s,c,sh(e,s,c,a));(s==="found"||s==="birth")&&(t[i.name]=u),s==="make"&&(n[i.name]=u)}mt(e,Ro(e,t[ta]))}return t[ta]}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 Pr=(e,t)=>`${e} ${t}${e===1?"":"s"}`,un=e=>e==="cued"?"cued":`beat ${e}`,ov=e=>new Date(e).toLocaleTimeString([],{hour:"2-digit",minute:"2-digit",second:"2-digit"}),bu=e=>JSON.stringify(e,(t,n)=>typeof n=="bigint"?String(n):n,2),T={holding:null,node:null,event:null,tx:null,beat:null,verb:"birth",busy:!1,replay:null,closing:null,reveal:null};let q=ls(),mo=new ss(q.chain),on=[],F=bn([]),qe=F,Le={owner:new Map,ledger:[],now:new Map,view:new Map},fn=new Map;const Xe=()=>q.chain.blocks.length,na=()=>on.filter(e=>e.status==="pending").length,ra=e=>Le.ledger.filter(t=>t.beat===null&&t.kind===e).length,Ns=[["pay","cued send"],["deal","cued deal"],["fund","cued deposit"]],iv=()=>na()+Ns.reduce((e,[t])=>e+ra(t),0),En=e=>{var t;return((t=F.items.get(e))==null?void 0:t.name)??"an item"},sa=()=>q.offers??[],Ls=e=>Le.view.get(e)??0,fh=e=>Le.now.get(e)??0,J=(e,t=F)=>e?t.nodes.get(e)??null:null,lh=e=>Object.assign(T,{event:null,tx:null,closing:null,reveal:null},e),ds=e=>{lh(e),Ho()};function ye(e,t=!1){const n=D("say");n.textContent=e,n.classList.toggle("bad",t)}function dh(){try{q=fc()}catch(e){q=ls(),ye(`This browser's saved lab could not be read (${e.message}) Load a backup, or reset to start over.`,!0)}gc()}function gc(){var n;mo=new ss(q.chain),on=_o(mo),F=bn(on,{pending:!0}),T.beat!==null&&T.beat>=Xe()&&(T.beat=null),J(T.holding)||(T.holding=((n=F.roots.at(-1))==null?void 0:n.id)??null),(!J(T.node)||J(T.node).root!==T.holding)&&(T.node=T.holding),T.event&&!F.log.some(r=>r.id===T.event)&&(T.event=null),qe=T.beat===null?F:bn(on,{upTo:T.beat});const e=C2(q.keys,on,F),t=new Map(sa().map(r=>[r.txid,r]));Le={owner:e,ledger:N2(q.chain,e,P2(q.keys,on,F),t),now:Yi(q.chain,e)},fn=new Map([...F.items.keys()].map(r=>{var s;return[r,((s=cc(q,on,F,r))==null?void 0:s.node.id)??null]})),Le.view=T.beat===null?Le.now:Yi(q.chain,e,T.beat),T.tx&&!Le.ledger.some(r=>r.key===T.tx)&&(T.tx=null),Ho()}function yo(e){T.beat=e>=Xe()?null:Math.max(0,e),qe=T.beat===null?F:bn(on,{upTo:T.beat}),Le.view=T.beat===null?Le.now:Yi(q.chain,Le.owner,T.beat),Ho()}async function ot(e,t){if(T.busy)return!1;T.busy=!0,document.body.classList.add("busy");try{return q=(await V2(e,t)).lab,!0}catch(n){return ye((n==null?void 0:n.message)||String(n),!0),!1}finally{T.busy=!1,document.body.classList.remove("busy"),gc()}}async function Fn(e,t,n,r){let s=null;if(!await ot(i=>{s=X2(i,e,t,n)}))return!1;const o=mo.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")),Ho(),!0}async function hh(e){const t=[na(),...Ns.map(([a])=>ra(a))],n=Xe();if(!await ot(e)||Xe()===n)return;const r=[na(),...Ns.map(([a])=>ra(a))],s=["cued act",...Ns.map(([,a])=>a)],o=t.map((a,c)=>[a-r[c],s[c]]).filter(([a])=>a>0).map(([a,c])=>Pr(a,c)),i=av(Le.ledger.filter(a=>a.kind==="mine"&&a.beat===Xe()));ye(`Beat ${Xe()}: ${o.length?`${o.join(" and ")} landed, and ${i}`:i}.`)}function av(e){if(!e.length)return"the lab wallet earned 50 tBTC";const t=e.map(r=>{var s;return((s=J(r.to))==null?void 0:s.name)??"?"}),n=e.map(r=>ec(r.amount));return e.length===1?`${t[0]} earned ${ae(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 cv(){var t;if(((t=q.mining)==null?void 0:t.rule)==="last")return"the holding that acts";const e=nc(q,F);return e.length?e.length===1?e[0].name:`${e.length} holdings, split by hashrate`:"the lab wallet"}function Ho(){ph(),lv(),dv(),jo(),Eh(),mc()}function ph(){const e=iv(),{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(Xe()),D("clock-cued").textContent=e?`${e} cued · ${uv()}`:"nothing cued";const n=cv();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 uv(){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 fv={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 lv(){var a,c;const e=((a=q.mining)==null?void 0:a.rule)??"split",t=e==="split",n=t?nc(q,F):[],r=n.reduce((u,f)=>u+rr(q,f.id),0);D("holdings-list").replaceChildren(...F.roots.map(u=>{const f=h1(F,u.id),l=u.id===T.holding,d=u.status==="active",h=n.some(y=>y.id===u.id)?rr(q,u.id)/r:0,p=[...F.nodes.values()].reduce((y,m)=>y+(m.root===u.id?fh(m.id):0),0),g=[un(u.born),Pr(f.orgs,"org"),Pr(f.agents,"agent"),Pr(f.belts,"belt"),p>0&&ec(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${l?" on":""}${d?"":" gone"}`,"aria-pressed":String(l),onclick:()=>ds({holding:u.id,node:u.id})},A("span",{class:"hn",text:u.name})," ",A("span",{class:"hm",text:g.join(" · ")})),t&&d&&Ee(q.keys,F,u)&&gv(u,rr(q,u.id)))}));for(const u of document.querySelectorAll("[data-rule]"))u.setAttribute("aria-pressed",String(e===u.dataset.rule));D("mining-note").textContent=fv[e];const s=F.roots.filter(u=>u.status==="active"&&Ee(q.keys,F,u)),o=D("fund-to"),i=o.value;D("f-fund").hidden=e!=="none"||!s.length||T.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===T.holding)?T.holding:((c=s[0])==null?void 0:c.id)??"",D("fund-has").textContent=ae(q.wallet?ac(q.chain,q.wallet):0),D("holdings-empty").hidden=F.roots.length>0,D("holdings-sub").textContent=F.roots.length?String(F.roots.length):"",D("sample").disabled=F.roots.some(u=>u.name===ta&&u.status==="active")}function dv(){var r;const e=D("tree-rows"),t=J(T.holding);if(D("tree-sub").textContent=t?`${t.name} · ${T.beat===null?"now":`beat ${T.beat} of ${Xe()}`}`:"",!t)return e.replaceChildren(A("p",{class:"wait",text:"No holding yet. Found one, or load the yolopreneur sample."}));if(!qe.nodes.has(t.id))return e.replaceChildren(A("p",{class:"wait",text:`${t.name} is founded at ${un(t.born)}. Move the slider forward.`}));const n=e.contains(document.activeElement)?document.activeElement.dataset.id:null;e.replaceChildren(...d1(qe,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})):hv(s))),n&&((r=e.querySelector(`[data-id="${n}"]`))==null||r.focus())}function hv({node:e,guide:t,path:n}){const r=e.id===T.node,s=["row",r&&"on",e.status==="closed"&&"gone",e.born==="cued"&&"cue"].filter(Boolean).join(" ");return A("div",{class:s},A("button",{type:"button",class:"sel","data-id":e.id,"aria-pressed":String(r),onclick:()=>ds({node:e.id})},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"},pv(e))))}function pv(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(gh),Ls(e.id)>0&&A("span",{class:"mk sats",title:`${ae(Ls(e.id))} at its SegWit address`,text:ec(Ls(e.id))})].filter(Boolean).flatMap((n,r)=>r?[" ",n]:[n])}const gh=e=>A("span",{class:`belt ${e.belt}`,title:`${e.skill}: ${e.belt} belt`},e.skill,A("span",{class:"sr",text:` (${e.belt} belt)`})),mh=(e,t)=>{for(let n=J(e.parent);n;n=J(n.parent))if(n.id===t.id)return!0;return!1},yh=e=>[...F.nodes.values()].filter(t=>t.root===e.root&&t.id!==e.id&&t.status==="active").map(t=>[t,(mh(t,e)?0:2)+(t.kind==="agent"?0:1)]).sort((t,n)=>t[1]-n[1]).map(([t])=>t),bh=e=>e.children.reduce((t,n)=>{const r=J(n);return r&&r.edge==="derived"&&r.status==="active"?t+1+bh(r):t},0);function gv(e,t){const n=async r=>{await ot(s=>D2(s,e.id,r))&&ye(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 wh=e=>[...F.nodes.values()].filter(t=>t.id!==e.id&&t.status==="active").map(t=>[t,(t.root===e.root?0:4)+(mh(t,e)?0:2)+(t.kind==="agent"?0:1)]).sort((t,n)=>t[1]-n[1]).map(([t])=>t);function mv(e){const t=Ee(q.keys,F,e);return t?sc(q.chain.coins(t.script))[...F.items.values()].map(t=>[t,J(fn.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 yv(e){const t=Ee(q.keys,F,e);return t?vh(e).length?q.chain.coins(t.script).some(n=>n.value>=fe+Oe||n.value===fe)?"":xh(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 bv(e){const t=J(e.parent),n=e.status==="closed"?`${e.name} is closed`:"",r=(s,o=e.id,i={})=>ch(q,F,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":yh(e).length?r("award"):"There is nobody else in this holding to award yet"),decide:n||r("decide"),make:n||r("make"),send:n||mv(e),offer:n||yv(e),graduate:n||(t?e.kind!=="org"?"Only orgs graduate":e.edge==="adopted"?`${e.name} has already graduated`:t.status!=="active"?`${t.name} is closed`:r("graduate",t.id,{of:e.id}):"A holding has no parent to graduate from"),close:n||r("close")}}function jo(){const e=J(T.node),t=T.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(T.beat??""),!e||t)return;const n=bv(e),r=J(e.parent);for(const h of document.querySelectorAll("[data-verb]"))h.setAttribute("aria-pressed",String(h.dataset.verb===T.verb)),h.classList.toggle("off",!!n[h.dataset.verb]);for(const h of document.querySelectorAll("form[data-form]"))h.hidden=h.dataset.form!==T.verb||!!n[T.verb];D("act-why").textContent=n[T.verb]?`${n[T.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(p=>`${p.value}=${p.textContent}`).join("|"),o=[[D("award-to"),yh(e).map(h=>[h.id,`${lr(F,h.id)}${h.kind==="agent"?" (agent)":""}`])],[D("send-to"),wh(e).map(h=>[h.id,`${lr(F,h.id)}${h.kind==="agent"?" (agent)":""}`])],[D("offer-item"),vh(e).map(h=>[h.id,`${h.name} · held by ${kt(fn.get(h.id))}`])]];for(const[h,p]of o){const g=h.value,y=p.map(([m,v])=>A("option",{value:m,text:v}));s(y)!==s([...h.options])&&(h.replaceChildren(...y),y.some(m=>m.value===g)&&(h.value=g))}for(const h of["send-has","offer-has"])D(h).textContent=ae(fh(e.id));D("graduate-go").textContent=`Graduate ${e.name}`;const i=T.verb==="graduate"?r:e,a=i&&Te(q.keys,F,i),c=T.verb==="send"||T.verb==="offer",u=a&&(c?`${a.from} · ${Ee(q.keys,F,i).path}`:a.path);D("act-key").textContent=!i||n[T.verb]?"":a?`Signs as ${i.name}: ${u}`:"Signs with the lab wallet: this holding predates lab keys.";const f=T.verb==="graduate"&&Te(q.keys,F,e)?Uo(F,e.id).length:0;D("act-gas").textContent=!i||n[T.verb]||!a?"":T.verb==="send"?`Fee: ${fe} sats, from ${e.name}'s balance.`:T.verb==="offer"?`Fee: ${fe} sats, from ${e.name}'s balance, paid only if the holder accepts.`:`Gas: ${W2(T.verb,f).toLocaleString("en-US")} sats from ${i.name}'s tank (${ae(ac(q.chain,a.wallet))}), which tops up from its balance.${f?` ${e.name} pays ${fe} more, from its own money, to claim its new root.`:""}`;const l=bh(e),d=T.closing===e.id;D("close-note").textContent=l?`Closing ${e.name} spends it for the last time, and its ${Pr(l,"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=d?`Yes, close ${e.name}`:`Close ${e.name}`,D("close-keep").hidden=!d}function Eh(){const e=D("inspect-body"),t=T.event?F.log.find(o=>o.id===T.event):null;if(t)return D("inspect-sub").textContent="event",e.replaceChildren(...Ov(t));const n=T.tx?Le.ledger.find(o=>o.key===T.tx):null;if(n)return D("inspect-sub").textContent="money",e.replaceChildren(...Cv(n));const r=J(T.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=J(T.node,qe);if(!s)return e.replaceChildren(A("p",{class:"note pad",text:`${r.name} is not born yet at beat ${T.beat}.`}));e.replaceChildren(...wv(s))}const Qr=([e,t,n])=>A("div",{class:"f"},A("dt",{text:e}),A("dd",{},t,n&&A("span",{class:"fn",text:n})));function wv(e){const t=J(e.parent,qe),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 ${un(e.graduated)}: it holds its own root`:`derived: ${t.name} holds its seed`],e.closed!==null&&["Closed",un(e.closed)],["Children",e.children.length?e.children.map(r=>{var s;return(s=J(r,qe))==null?void 0:s.name}).join(", "):"none yet"],Ee(q.keys,qe,e)&&["Balance",ae(Ls(e.id)),`Test BTC at its SegWit address${T.beat===null?"":`, as of beat ${T.beat}`}.`],T.beat===null&&Te(q.keys,F,e)&&["Gas tank",ae(ac(q.chain,Te(q.keys,F,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:lr(qe,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(Qr)),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",{},gh(r),A("span",{class:"when",text:` from ${((s=J(r.by))==null?void 0:s.name)??"?"}, ${un(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:` (${un(r.beat)})`}))))),xv(e),kv(e),Av(e))]}function xv(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(T.beat!==null)return t("Made",e.made.map(a=>qe.items.get(a)).filter(Boolean).map(a=>n(a,un(a.beat))));const r=a=>`made${a.maker===e.id?"":` by ${kt(a.maker)}`}${a.beat==="cued"?", cued":` at beat ${a.beat}`}`,s=[...F.items.values()].filter(a=>fn.get(a.id)===e.id).map(a=>{const c=n(a,r(a)),u=sa().filter(f=>f.item===a.id&&f.seller===e.id&&Ji(q,F,f)==="open");return u.length&&c.append(A("ul",{class:"bids"},u.map(f=>A("li",{},A("span",{text:`${kt(f.buyer)} offers ${f.price?ae(f.price):"nothing, a free claim"}`}),e.status==="active"&&A("button",{type:"button",class:"btn sm","aria-label":`Accept ${kt(f.buyer)}'s offer for ${a.name}`,onclick:()=>vv(f)},"Accept"))))),c}),o=e.made.map(a=>F.items.get(a)).filter(a=>a&&fn.get(a.id)!==e.id).map(a=>n(a,fn.get(a.id)?`now held by ${kt(fn.get(a.id))}`:"held outside this lab")),i=sa().filter(a=>a.buyer===e.id&&Ji(q,F,a)!=="done").map(a=>{const c=uc(q,F,a);return A("li",{},A("b",{text:a.price?ae(a.price):"nothing"}),` for ${En(a.item)}`,A("span",{class:"when",text:c?` (stale: ${c})`:` (open until ${kt(a.seller)} accepts)`}),A("button",{type:"button",class:"btn sm","aria-label":`Withdraw the offer for ${En(a.item)}`,onclick:()=>Ev(a)},"Withdraw"))});return[t("Items",s),t("Made, held elsewhere",o),t("Offers made",i)]}const kt=e=>{const t=J(e);return t?t.root===T.holding?t.name:lr(F,e):"?"};async function vv(e){const t=En(e.item),n=kt(e.buyer),r=kt(e.seller);if(!await ot(o=>{ev(o,e.txid)}))return;const s=Le.ledger.find(o=>o.txid===e.txid);ye(`${r} accepted: ${t} goes to ${n}${e.price?` for ${ae(e.price)}`:", free"}, ${s!=null&&s.beat?`at beat ${s.beat}`:"cued for the next beat"}.`)}async function Ev(e){const t=En(e.item),n=kt(e.buyer);await ot(r=>{tv(r,e.txid)})&&ye(`${n} withdrew its offer for ${t}.`)}function kv(e){const t=Le.ledger.filter(n=>(n.to===e.id||n.from===e.id)&&(T.beat===null||n.beat!==null&&n.beat<=T.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:Sv(n,e.id)}),A("span",{class:"when",text:` (${un(n.beat??"cued")})`})))))}function Sv(e,t){const n=r=>{var s;return((s=J(r))==null?void 0:s.name)??"?"};if(e.kind==="mine")return`+${ae(e.amount)}, a beat's reward`;if(e.kind==="move")return`${ae(e.amount)} moved to its new key, after a ${e.fee}-sat fee`;if(e.kind==="gas")return`−${ae(e.amount)} into its gas tank, and a ${e.fee}-sat fee`;if(e.kind==="fund")return`+${ae(e.amount)} from the lab wallet`;if(e.kind==="deal"){const r=En(e.item);return e.to===t?e.amount?`+${ae(e.amount)} from ${n(e.from)} for ${r}`:`${r} to ${n(e.from)}, free`:e.amount?`−${ae(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?`+${ae(e.amount)} from ${n(e.from)}`:`−${ae(e.amount)} to ${n(e.to)}, and a ${e.fee}-sat fee`}function kh(e){const t=n=>{const r=J(n);return r?r.root===T.holding?r.name:lr(F,n):"?"};return e.kind==="mine"?`${ae(e.amount)} → ${t(e.to)}`:e.kind==="move"?`${ae(e.amount)} → ${t(e.to)}'s new key`:e.kind==="gas"?`${ae(e.amount)} → ${t(e.to)}'s gas tank`:e.kind==="fund"?`${ae(e.amount)} lab wallet → ${t(e.to)}`:e.kind==="deal"?`${En(e.item)} ${t(e.to)} → ${t(e.from)}, ${e.amount?`for ${ae(e.amount)}`:"free"}`:`${ae(e.amount)} ${t(e.from)} → ${t(e.to)}`}const $v={own:"its own key",lab:"the lab wallet",parent:"its parent's key (its handoff is cued)",other:"a key outside this lab"},_v={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 Av(e){const t=Te(q.keys,qe,e),n=Qa(q,F,e.id),r=["Held now by",n?$v[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(Qr)));const s=e.kind==="agent",o=k2(q.keys,qe,e),i=S2(q.keys,qe,e),a=i.map(([,,d])=>d).filter(Boolean),c="Reset the lab for standard BIP-86 keys.",u=s?"Holds this seat's inscription, and inscriptions sent to it land here.":"Holds this org's inscription and signs its acts. Inscriptions sent to it land here.",f={bip86:`BIP-86 at ${o.taproot.path}. ${u}`,tapkey:`Its npub's key with the BIP-86 tweak, the way v1.2 keyed this lab. ${u} ${c}`,wallet:`An untweaked key at ${o.taproot.path}, the way v1.1 keyed this lab. ${u} ${c}`}[t.scheme],l=[["Taproot",o.taproot.address,f],["SegWit",o.segwit.address,`BIP-84 at ${o.segwit.path}. Its money: ${e.kind==="holding"?"the beats it earns land here, and ":""}sends come and go here.`],["Tapkey",o.tapkey.address,"Its npub as a Taproot address (its nostr key with the BIP-86 tweak), so the npub alone finds it. Nostr secrets get pasted into clients, so treat it as an inbox."],["npub",o.npub.address,`NIP-06 at ${o.npub.path}. Its nostr name; the leaves below hang off it.`],["From",`${t.from} · account ${t.account}`],r];return A("div",{class:"keys"},A("p",{class:"lab",text:"Keys"}),A("dl",{class:"fl"},l.map(Qr)),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:` ${_v[d]}`}),A("code",{text:h})))),Ur(s?"Public lines to paste":"CA key for TrustedUserCAKeys",a.join(` - -`)),Tv(e,t))}function Ur(e,t,n=t){const r=A("pre",{text:n}),s=A("button",{type:"button",class:"cp","aria-label":`Copy ${e}`,onclick:()=>Bv(t,s,r)},"Copy");return A("div",{class:"code"},A("div",{class:"code-h cph"},A("span",{text:e}),s),r)}async function Bv(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 Tv(e,t){var a;const n=T.reveal===e.id,r=n&&T2(q.keys,qe,e),s=J(e.parent,qe),o=()=>{var c;T.reveal=n?null:e.id,Eh(),(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?Ur(`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(` -`)):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,f])=>Ur(`${c} · ${u}`,f)),r.leaves.map(([c,u,f])=>Ur(`${c} · ${u}`,f))))}function Iv(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=La(t).pubkey,r=J(e.parent),s=e.op==="found"?J(e.node):null,o=[[s&&Te(q.keys,F,s),`${s==null?void 0:s.name}'s root`],[r&&Te(q.keys,F,r),`${r==null?void 0:r.name}'s key`],[(r==null?void 0:r.edge)==="adopted"&&Te(q.keys,F,{...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 Ov(e){var o,i,a;const t=mo.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=J(e.parent))==null?void 0:a.name)??"an unknown inscription"}, whose inscription this event spent`:"nothing: a founding has no parent"],["Signed by",Iv(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:Ol(e,F)}),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(Qr)),A("div",{class:"code"},A("p",{class:"code-h",text:"Metadata · CBOR, tag 5"}),A("pre",{text:bu(e.meta)})),s&&A("div",{class:"code"},A("p",{class:"code-h",text:"Raw index entry"}),A("pre",{text:bu(s)})))]}function Cv(e){const t=i=>{var a;return((a=J(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",`${En(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":ae(e.amount)],e.kind!=="mine"&&["Fee",`${e.fee} sats, retired: this toy chain pays no fees to miners`],e.change>0&&["Change",`${ae(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:kh(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(Qr)),n&&Ur("Raw transaction",n.raw))]}function mc(){const e=Xe(),t=D("beat"),n=J(T.holding);t.max=String(e),t.value=String(T.beat??e),t.disabled=e===0,D("beat-label").textContent=T.beat===null?`Now · beat ${e}`:`Beat ${T.beat} of ${e}`,D("replay").textContent=T.replay?"Stop":"Replay",D("replay").disabled=!n||e===0,D("to-now").disabled=T.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 F.log)a.root&&a.root===T.holding&&o(a.pending?"cued":a.beat,{e:a,at:s.get(a.id.slice(0,-2))??0});for(const a of Le.ledger)[a.to,a.from].some(c=>{var u;return c&&((u=J(c))==null?void 0:u.root)===T.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=T.beat!==null&&(a==="cued"||a>T.beat),f=T.beat!==null&&a===T.beat;return A("li",{class:`beat${u?" later":""}${f?" now":""}`},A("p",{class:"bh"},A("span",{class:"bn",text:a==="cued"?"Cued":`Beat ${a}`}),A("span",{class:"bt",text:c?ov(c.time):q.clock.tempo==="manual"?"waiting for Beat now":"landing on the next beat"})),A("ol",{class:"evs"},r.get(a).sort((l,d)=>l.at-d.at).map(({e:l,m:d})=>d?Uv(d):Pv(l))))}))}function Pv(e){const[t,...n]=Ol(e,F).split(" ");return A("li",{},A("button",{type:"button",class:`ev${e.ok?"":" bad"}${e.id===T.event?" on":""}`,"aria-pressed":String(e.id===T.event),onclick:()=>ds({event:e.id,node:e.node??T.node})},A("span",{class:"op",text:e.ok?t:`✕ ${t.replace(/:$/,"")}`})," ",A("span",{class:"es",text:n.join(" ")})))}const Uv=e=>A("li",{},A("button",{type:"button",class:`ev money${e.kind==="gas"?" gas":""}${e.kind==="deal"?" deal":""}${e.key===T.tx?" on":""}`,"aria-pressed":String(e.key===T.tx),onclick:()=>{var t;return ds({tx:e.key,node:((t=J(e.to))==null?void 0:t.root)===T.holding?e.to:T.node})}},A("span",{class:"op",text:e.kind})," ",A("span",{class:"es",text:kh(e)})));D("f-found").addEventListener("submit",async e=>{e.preventDefault();const t=e.currentTarget,n=$o(t.elements.name.value);if(!n)return ye("Name the holding: lowercase letters, digits and hyphens.",!0);await Fn("found",null,{name:n},(r,s)=>(lh({holding:r,node:r}),`${n} is founded, ${s}.`))&&t.reset()});D("sample").addEventListener("click",async()=>{let e=null;ye("Rehearsing the yolopreneur tree over six beats…"),await ot(t=>{e=sv(t)})&&(ds({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."))});D("f-birth").addEventListener("submit",async e=>{e.preventDefault();const t=e.currentTarget,n=J(T.node),r=$o(t.elements.name.value),s=t.elements.kind.value;if(!r)return ye("Name the child: lowercase letters, digits and hyphens.",!0);await Fn("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=J(T.node),r=t.elements.to.value,s=$o(t.elements.skill.value),o=t.elements.belt.value;if(!s)return ye("Name the skill, for example launch.",!0);await Fn("award",n.id,{to:r,skill:s,belt:o},(i,a)=>{var c;return`${(c=J(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=J(T.node),r=t.elements.title.value.trim(),s=t.elements.why.value.trim();if(!r)return ye("A decision needs a title.",!0);await Fn("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=J(T.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 ot(c=>{o=J2(c,n.id,r,s)}))return;const i=Le.ledger.find(c=>c.txid===o);ye(`${n.name} sent ${ae(s)} to ${((a=J(r))==null?void 0:a.root)===n.root?J(r).name:lr(F,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=J(T.node),r=$o(t.elements.name.value),s=t.elements.note.value.trim();if(!r)return ye("Name the item: lowercase letters, digits and hyphens.",!0);await Fn("make",n.id,{name:r,note:s},(o,i)=>`${n.name} made ${r}, ${i}.`)&&t.reset()});D("f-offer").addEventListener("submit",async e=>{e.preventDefault();const t=e.currentTarget,n=J(T.node),r=D("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=kt(fn.get(r)),i=En(r);await ot(a=>{Q2(a,r,n.id,s)})&&(ye(`${n.name} offers ${s?ae(s):"nothing"} for ${i}. The offer stands until ${o} accepts it.`),t.elements.price.value="")});D("send-max").addEventListener("click",()=>{const e=J(T.node),t=e&&Ee(q.keys,F,e);t&&(D("send-amount").value=Dd(sc(q.chain.coins(t.script))))});D("f-graduate").addEventListener("submit",async e=>{e.preventDefault();const t=J(T.node),n=J(t.parent);await Fn("graduate",n.id,{of:t.id},(r,s)=>`${t.name} graduates from ${n.name}, ${s}. Its edge is adopted now.`)});D("f-close").addEventListener("submit",async e=>{e.preventDefault();const t=J(T.node);if(T.closing!==t.id)return T.closing=t.id,jo(),D("close-go").focus();T.closing=null,await Fn("close",t.id,{},(n,r)=>`${t.name} is closed, ${r}.`)});D("close-keep").addEventListener("click",()=>{T.closing=null,jo(),D("close-go").focus()});for(const e of document.querySelectorAll("[data-verb]"))e.addEventListener("click",()=>{T.verb=e.dataset.verb,T.closing=null,jo()});for(const e of document.querySelectorAll("[data-rule]"))e.addEventListener("click",async()=>{const t=e.dataset.rule;await ot(n=>M2(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])});D("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 ot(a=>{s=nv(a,n,r)}))return;const o=Le.ledger.find(a=>a.txid===s);ye(`The lab wallet funded ${(i=J(n))==null?void 0:i.name} with ${ae(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 ot(r=>q2(r,n,Date.now(),Ro(r,pc(r)??T.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.`)});D("beat-now").addEventListener("click",()=>hh(e=>{mt(e,Ro(e,pc(e)??T.holding))}));setInterval(()=>{ph();const{tempo:e,nextAt:t}=q.clock;T.busy||document.hidden||typeof e!="number"||!q.chain.mempool.length||t&&Date.now()z2(n,Date.now(),Ro(n,pc(n)??T.holding)))},1e3);addEventListener("storage",e=>{(e.key===No||e.key===null)&&dh()});function hs(){T.replay&&(clearInterval(T.replay),T.replay=null,mc())}function Nv(){const e=J(T.holding);if(!(!e||!Xe())){if(yo(typeof e.born=="number"?e.born:Xe()),T.beat===null)return ye("Nothing to replay yet: this holding has one beat of history.");T.replay=setInterval(()=>{(T.beat===null||T.beat+1>=Xe())&&hs(),yo(T.beat===null?Xe():T.beat+1)},800),mc()}}D("beat").addEventListener("input",e=>{hs(),yo(Number(e.target.value))});D("replay").addEventListener("click",()=>T.replay?hs():Nv());for(const e of["to-now","past-now"])D(e).addEventListener("click",()=>{hs(),yo(Xe())});const xi=["system","light","dark"],Sh=()=>{D("theme").textContent=`Theme: ${document.documentElement.dataset.theme??"system"}`};D("theme").addEventListener("click",()=>{const e=xi[(xi.indexOf(document.documentElement.dataset.theme??"system")+1)%xi.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{}Sh()});function $h(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 Lv={read:()=>{try{return fc()}catch{return ls()}}};async function _h(e,t){hs(),await ot(n=>{Object.assign(n,e())},Lv)&&(Object.assign(T,{holding:null,node:null,event:null,tx:null,beat:null,closing:null}),gc(),ye(t))}D("save").addEventListener("click",()=>{const e=A("a",{href:URL.createObjectURL(new Blob([rh(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.")});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=nh(await t.text())}catch(s){return ye(`${t.name} is not an Orgchain lab: ${s.message}`,!0)}$h(`Replace this browser's lab with ${t.name}?`,"Replace",()=>_h(()=>n,`Loaded ${t.name}.`))});D("reset").addEventListener("click",()=>$h("Erase this browser's lab: every holding, the chain and the test wallet?","Erase",()=>_h(ls,"Erased. This is a fresh lab.")));Sh();dh(); diff --git a/ventures/lineage/orgchain/assets/index-DwC5RMF4.css b/ventures/lineage/orgchain/assets/index-Dx_1vZ_Y.css similarity index 99% rename from ventures/lineage/orgchain/assets/index-DwC5RMF4.css rename to ventures/lineage/orgchain/assets/index-Dx_1vZ_Y.css index 3711bf2..db49bae 100644 --- a/ventures/lineage/orgchain/assets/index-DwC5RMF4.css +++ b/ventures/lineage/orgchain/assets/index-Dx_1vZ_Y.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)} +: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} diff --git a/ventures/lineage/orgchain/assets/index-ohHsgad2.js b/ventures/lineage/orgchain/assets/index-ohHsgad2.js new file mode 100644 index 0000000..92171ad --- /dev/null +++ b/ventures/lineage/orgchain/assets/index-ohHsgad2.js @@ -0,0 +1,2063 @@ +(function(){const t=document.createElement("link").relList;if(t&&t.supports&&t.supports("modulepreload"))return;for(const s of document.querySelectorAll('link[rel="modulepreload"]'))r(s);new MutationObserver(s=>{for(const o of s)if(o.type==="childList")for(const i of o.addedNodes)i.tagName==="LINK"&&i.rel==="modulepreload"&&r(i)}).observe(document,{childList:!0,subtree:!0});function n(s){const o={};return s.integrity&&(o.integrity=s.integrity),s.referrerPolicy&&(o.referrerPolicy=s.referrerPolicy),s.crossOrigin==="use-credentials"?o.credentials="include":s.crossOrigin==="anonymous"?o.credentials="omit":o.credentials="same-origin",o}function r(s){if(s.ep)return;s.ep=!0;const o=n(s);fetch(s.href,o)}})();const wc=5e9;function xu(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 vu(e,t){var n;return(n=xu(e,t,1)[0])==null?void 0:n[0]}function Is(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=xu(s,o,Number(i.value));return o+=Number(i.value),a})}function vi(e){if(!Number.isSafeInteger(e)||e<0)throw new Error(`Wrong positive integer: ${e}`)}function Ah(e){if(typeof e!="boolean")throw new Error(`Expected boolean, not ${e}`)}function ku(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 Bh(e){if(typeof e!="function"||typeof e.create!="function")throw new Error("Hash should be wrapped by utils.wrapConstructor");vi(e.outputLen),vi(e.blockLen)}function Th(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 Oh(e,t){ku(e);const n=t.outputLen;if(e.lengthnew DataView(e.buffer,e.byteOffset,e.byteLength),yt=(e,t)=>e<<32-t|e>>>t,Ch=new Uint8Array(new Uint32Array([287454020]).buffer)[0]===68;if(!Ch)throw new Error("Non little-endian hardware is not supported");Array.from({length:256},(e,t)=>t.toString(16).padStart(2,"0"));function Ph(e){if(typeof e!="string")throw new TypeError(`utf8ToBytes expected string, got ${typeof e}`);return new TextEncoder().encode(e)}function Su(e){if(typeof e=="string"&&(e=Ph(e)),!(e instanceof Uint8Array))throw new TypeError(`Expected input type is Uint8Array (got ${typeof e})`);return e}let Uh=class{clone(){return this._cloneInto()}};function $u(e){const t=r=>e().update(Su(r)).digest(),n=e();return t.outputLen=n.outputLen,t.blockLen=n.blockLen,t.create=()=>e(),t}function Nh(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 Lh=class extends Uh{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=Do(this.buffer)}update(t){Ko.exists(this);const{view:n,buffer:r,blockLen:s}=this;t=Su(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,Hh=(e,t,n)=>e&t^e&n^t&n,jh=new Uint32Array([1116352408,1899447441,3049323471,3921009573,961987163,1508970993,2453635748,2870763221,3624381080,310598401,607225278,1426881987,1925078388,2162078206,2614888103,3248222580,3835390401,4022224774,264347078,604807628,770255983,1249150122,1555081692,1996064986,2554220882,2821834349,2952996808,3210313671,3336571891,3584528711,113926993,338241895,666307205,773529912,1294757372,1396182291,1695183700,1986661051,2177026350,2456956037,2730485921,2820302411,3259730800,3345764771,3516065817,3600352804,4094571909,275423344,430227734,506948616,659060556,883997877,958139571,1322822218,1537002063,1747873779,1955562222,2024104815,2227730452,2361852424,2428436474,2756734187,3204031479,3329325298]),Zt=new Uint32Array([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]),Vt=new Uint32Array(64);let _u=class extends Lh{constructor(){super(64,32,8,!1),this.A=Zt[0]|0,this.B=Zt[1]|0,this.C=Zt[2]|0,this.D=Zt[3]|0,this.E=Zt[4]|0,this.F=Zt[5]|0,this.G=Zt[6]|0,this.H=Zt[7]|0}get(){const{A:t,B:n,C:r,D:s,E:o,F:i,G:a,H:c}=this;return[t,n,r,s,o,i,a,c]}set(t,n,r,s,o,i,a,c){this.A=t|0,this.B=n|0,this.C=r|0,this.D=s|0,this.E=o|0,this.F=i|0,this.G=a|0,this.H=c|0}process(t,n){for(let f=0;f<16;f++,n+=4)Vt[f]=t.getUint32(n,!1);for(let f=16;f<64;f++){const d=Vt[f-15],h=Vt[f-2],p=yt(d,7)^yt(d,18)^d>>>3,g=yt(h,17)^yt(h,19)^h>>>10;Vt[f]=g+Vt[f-7]+p+Vt[f-16]|0}let{A:r,B:s,C:o,D:i,E:a,F:c,G:u,H:l}=this;for(let f=0;f<64;f++){const d=yt(a,6)^yt(a,11)^yt(a,25),h=l+d+Rh(a,c,u)+jh[f]+Vt[f]|0,g=(yt(r,2)^yt(r,13)^yt(r,22))+Hh(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(){Vt.fill(0)}destroy(){this.set(0,0,0,0,0,0,0,0),this.buffer.fill(0)}},Kh=class extends _u{constructor(){super(),this.A=-1056596264,this.B=914150663,this.C=812702999,this.D=-150054599,this.E=-4191439,this.F=1750603025,this.G=1694076839,this.H=-1090891868,this.outputLen=28}};const Ei=$u(()=>new _u);$u(()=>new Kh);function Dh(e,t){if(e.length>t)throw new TypeError(`Data is larger than array size: ${e.length} > ${t}`)}function Mh(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 Zh(e){if(e>Number.MAX_SAFE_INTEGER)throw new TypeError("Number exceeds safe bounds!")}const{getRandomValues:Vh}=crypto??globalThis.crypto??window.crypto;function qh(e=32){if(typeof Vh=="function")return crypto.getRandomValues(new Uint8Array(e));throw new Error("Crypto module missing getRandomValues!")}function zh(e,t,n="be"){t===void 0&&(t=e.length),Dh(e,t);const r=new Uint8Array(t).fill(0),s=n==="be"?0:t-e.length;return r.set(e,s),r}function Au(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 Yh(e,t){const n=Bu(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 Tu(e){return Ei(Ei(e))}function Xh(e){const t=Tu(e);return Au([e,t.slice(0,4)])}function Jh(e){const t=e.slice(0,-4),n=e.slice(-4);if(Tu(t).slice(0,4).toString()!==n.toString())throw new Error("Invalid checksum!");return t}const xc={encode:Wh,decode:Yh},Ou={encode:e=>{const t=Xh(e);return xc.encode(t,"base58")},decode:e=>{const t=xc.decode(e,"base58");return Jh(t)}},Iu="qpzry9x8gf2tvdw0s3jn54khce6mua7l",Qh=[996825010,642813549,513874426,1027748829,705979059],Rs=[{version:0,name:"bech32",const:1},{version:1,name:"bech32m",const:734539939}];function Cu(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^=Qh[s])}return t}function Pu(e){const t=[];let n;for(n=0;n>5);for(t.push(0),n=0;n>5*(5-i)&31);return o}function Uu(e,t,n,r=!0){const s=[];let o=0,i=0;const a=(1<>t>0)throw new Error("Failed to perform base conversion. Invalid value: "+String(u));for(o=(o<=n;)i-=n,s.push(o>>i&a)}if(r)i>0&&s.push(o<=t||(o<0)throw new Error("Failed to perform base conversion. Invalid Size!");return s}function n0(e,t,n){const r=t.concat(t0(e,t,n));let s=e+"1";for(let o=0;oo.version===t[0])??Rs[0];if(!e0(r,t,s))throw new Error("Checksum verification failed!");return[r,t.slice(0,t.length-6)]}function r0(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 s0(e){const t=e.lastIndexOf("1");return!(t<1||t+7>e.length||e.length>90)}function o0(e,t="bc",n=0){const r=[n,...Uu([...e],8,5)],s=Rs.find(i=>i.version===n)??Rs[0],o=n0(t,r,s);return Lu(o),o}function Lu(e){e=e.toLowerCase();const t=e.split("1",1)[0],[n,r]=Nu(e),s=Uu(r.slice(1),5,8,!1),o=s.length;switch(!0){case t!==n:throw new Error("Returned hrp string is invalid.");case(s===null||o<2||o>40):throw new Error("Decoded string is invalid or out of spec.");case r[0]>16:throw new Error("Returned version bit is out of range.");default:return Uint8Array.from(s)}}function i0(e){e=e.toLowerCase();const[t,n]=Nu(e);return n[0]}const Ru={encode:o0,decode:Lu,version:i0},Hu="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",ju="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",a0=new TextEncoder;function Ku(e,t=!1,n=!0){typeof e=="string"&&(e=a0.encode(e));const r=t?ju:Hu;let s="",o=0,i=0;for(let a=0;a=6;)o-=6,s+=r[i>>o&63];if(o>0)for(i<<=6-o,s+=r[i&63];o<6;)s+=n?"=":"",o+=2;return s}function Du(e,t=!1){const n=t||e.includes("-")||e.includes("_")?ju.split(""):Hu.split("");e=e.replace(/=+$/,"");const r=e.split("");let s=0,o=0;const i=[];for(let a=0;a=8&&(s-=8,i.push(o>>>s&255))}return new Uint8Array(i)}const Mu={encode:Ku,decode:Du},Zu={encode:e=>Ku(e,!0,!1),decode:e=>Du(e,!0)},c0=BigInt(0),u0=BigInt(255),Vu=BigInt(256);function f0(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 l0(e,t,n="be"){t===void 0&&(t=f0(e));const r=n==="le",s=new ArrayBuffer(t),o=new DataView(s);let i=r?0:t-1;for(;e>c0;){const a=e&u0,c=Number(a);r?o.setUint8(i++,c):o.setUint8(i--,c),e=(e-a)/Vu}return new Uint8Array(s)}function d0(e){let t=BigInt(0);for(let n=e.length-1;n>=0;n--)t=t*Vu+BigInt(e[n]);return BigInt(t)}function h0(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 g0(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 m0(e,t,n="be"){t===void 0&&(t=g0(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 y0(e){let t=0;for(let n=e.length-1;n>=0;n--)t=t*256+e[n],Zh(t);return t}const b0=new TextEncoder,w0=new TextDecoder;function oa(e){return b0.encode(e)}function Mo(e){return w0.decode(e)}function x0(e,t){Mh(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 v0(e,t,n="le"){t=x0(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 S0(e,t,n){if(e instanceof ArrayBuffer)return new Uint8Array(e);if(e instanceof Uint8Array)return zh(e,t,n);if(typeof e=="string")return v0(e,t,n);if(typeof e=="bigint")return l0(e,t,n);if(typeof e=="number")return m0(e,t,n);if(typeof e=="boolean")return Uint8Array.of(e?1:0);throw TypeError("Unsupported format:"+typeof e)}var ee;let k=(ee=class extends Uint8Array{static random(t=32){const n=qh(t);return new ee(n,t)}constructor(t,n,r){const s=S0(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 mr(this)}toNum(t="be"){const n=t==="be"?this.reverse():this;return y0(n)}toBin(){return p0(this)}toBig(t="be"){const n=t==="be"?this.reverse():this;return d0(n)}toHash(){const t=Ei(this);return new ee(t)}toJson(){const t=Mo(this);return JSON.parse(t)}toBech32(t,n=0){return Ru.encode(this,t,n)}toStr(){return Mo(this)}toHex(){return E0(this)}toBytes(){return new Uint8Array(this)}tob58chk(){return Ou.encode(this)}toBase64(){return Mu.encode(this)}toB64url(){return Zu.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=Au(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=$0,ee.big=A0,ee.bin=_0,ee.raw=B0,ee.str=T0,ee.hex=O0,ee.bytes=I0,ee.json=C0,ee.base64=P0,ee.b64url=U0,ee.bech32=N0,ee.b58chk=L0,ee.encode=oa,ee.decode=Mo,ee);function $0(e,t,n){return new k(e,t,n)}function _0(e,t,n){return new k(h0(e),t,n)}function A0(e,t,n){return new k(e,t,n)}function B0(e,t,n){return new k(e,t,n)}function T0(e,t,n){return new k(oa(e),t,n)}function O0(e,t,n){return new k(e,t,n)}function I0(e,t,n){return new k(e,t,n)}function C0(e){return new k(k0(e))}function P0(e){return new k(Mu.decode(e))}function U0(e){return new k(Zu.decode(e))}function N0(e){return new k(Ru.decode(e))}function L0(e){return new k(Ou.decode(e))}let mr=class{constructor(t){this.data=k.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 k(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 Ot(e,t){const n=k.bytes(e);if(n.length!==t)throw new Error(`Invalid input size: ${n.hex} !== ${t}`)}function je(e,t){if(t)throw new Error(e);return!1}function Cs(e,...t){const n=k.str(e).digest.raw,r=t.map(s=>k.bytes(s));return k.join([n,n,k.join(r)]).digest}const qu={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 R0(e){if(e>186&&e<255)return"OP_SUCCESS"+String(e);for(const[t,n]of Object.entries(qu))if(n===e)return t;throw new Error("OPCODE not found:"+String(e))}function H0(e){for(const[t,n]of Object.entries(qu))if(t===e)return Number(n);throw new Error("OPCODE not found:"+e)}function j0(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 K0(e){const r=[];switch(!0){case typeof e!="number":return!1;case e===0:return!0;case r.includes(e):return!1;case(750?k.join(t):new Uint8Array}function D0(e){let t=new Uint8Array;if(typeof e=="string"){if(e.startsWith("OP_"))return k.num(H0(e),1);Mt(e)?t=k.hex(e):t=k.str(e)}else t=k.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])),k.join([vc(t.length),t]));if(t.length>Hs){const n=M0(t);return Fu(n)}else return k.join([vc(t.length),t])}function vc(e){const t=k.num(76,1),n=k.num(77,1);switch(!0){case e<=75:return k.num(e);case(e>75&&e<256):return k.join([t,k.num(e,1,"le")]);case(e>=256&&e<=Hs):return k.join([n,k.num(e,2,"le")]);default:throw new Error("Invalid word size:"+e.toString())}}function M0(e){const t=[],n=new mr(e);for(;n.size>Hs;)t.push(n.read(Hs));return t.push(n.read(n.size)),t}function ia(e,t=!1){let n=k.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 Z0(n)}function Z0(e){const t=new mr(e),n=[],r=t.size;let s,o,i,a=0;for(;a0&&!t.includes(e.length))throw new TypeError(`Expected Uint8Array of length ${t}, not of length=${e.length}`)}function W0(e){if(typeof e!="function"||typeof e.create!="function")throw new Error("Hash should be wrapped by utils.wrapConstructor");ki(e.outputLen),ki(e.blockLen)}function Y0(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 X0(e,t){Gu(e);const n=t.outputLen;if(e.lengthnew DataView(e.buffer,e.byteOffset,e.byteLength),bt=(e,t)=>e<<32-t|e>>>t,Q0=new Uint8Array(new Uint32Array([287454020]).buffer)[0]===68;if(!Q0)throw new Error("Non little-endian hardware is not supported");Array.from({length:256},(e,t)=>t.toString(16).padStart(2,"0"));function ep(e){if(typeof e!="string")throw new TypeError(`utf8ToBytes expected string, got ${typeof e}`);return new TextEncoder().encode(e)}function aa(e){if(typeof e=="string"&&(e=ep(e)),!(e instanceof Uint8Array))throw new TypeError(`Expected input type is Uint8Array (got ${typeof e})`);return e}function tp(...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(aa(r)).digest(),n=e();return t.outputLen=n.outputLen,t.blockLen=n.blockLen,t.create=()=>e(),t}function np(e=32){if(Zo&&typeof Zo.getRandomValues=="function")return Zo.getRandomValues(new Uint8Array(e));throw new Error("crypto.getRandomValues must be defined")}function rp(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 sp=class extends Wu{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=Vo(this.buffer)}update(t){_n.exists(this);const{view:n,buffer:r,blockLen:s}=this;t=aa(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,ip=(e,t,n)=>e&t^e&n^t&n,ap=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]),zt=new Uint32Array(64);let Xu=class extends sp{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 f=0;f<16;f++,n+=4)zt[f]=t.getUint32(n,!1);for(let f=16;f<64;f++){const d=zt[f-15],h=zt[f-2],p=bt(d,7)^bt(d,18)^d>>>3,g=bt(h,17)^bt(h,19)^h>>>10;zt[f]=g+zt[f-7]+p+zt[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=bt(a,6)^bt(a,11)^bt(a,25),h=l+d+op(a,c,u)+ap[f]+zt[f]|0,g=(bt(r,2)^bt(r,13)^bt(r,22))+ip(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(){zt.fill(0)}destroy(){this.set(0,0,0,0,0,0,0,0),this.buffer.fill(0)}},cp=class extends Xu{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 Ju=Yu(()=>new Xu);Yu(()=>new cp);/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */const up=BigInt(0),ca=BigInt(1),fp=BigInt(2),bo=e=>e instanceof Uint8Array,lp=Array.from({length:256},(e,t)=>t.toString(16).padStart(2,"0"));function sr(e){if(!bo(e))throw new Error("Uint8Array expected");let t="";for(let n=0;nor(e.toString(16).padStart(t*2,"0")),ef=(e,t)=>Qn(e,t).reverse(),dp=e=>or(Qu(e));function nt(e,t,n){let r;if(typeof t=="string")try{r=or(t)}catch(o){throw new Error(`${e} must be valid hex string, got "${t}". Cause: ${o}`)}else if(bo(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 at(...e){const t=new Uint8Array(e.reduce((r,s)=>r+s.length,0));let n=0;return e.forEach(r=>{if(!bo(r))throw new Error("Uint8Array expected");t.set(r,n),n+=r.length}),t}function hp(e,t){if(e.length!==t.length)return!1;for(let n=0;n0n;e>>=ca,t+=1);return t}const gp=(e,t)=>e>>BigInt(t)&1n,mp=(e,t,n)=>e|(n?ca:up)<(fp<new Uint8Array(e),Ec=e=>Uint8Array.from(e);function tf(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=qo(e),s=qo(e),o=0;const i=()=>{r.fill(1),s.fill(0),o=0},a=(...f)=>n(s,r,...f),c=(f=qo())=>{s=a(Ec([0]),f),r=a(),f.length!==0&&(s=a(Ec([1]),f),r=a())},u=()=>{if(o++>=1e3)throw new Error("drbg: tried 1000 values");let f=0;const d=[];for(;f{i(),c(f);let h;for(;!(h=d(u()));)c();return i(),h}}const yp={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 yr(e,t,n={}){const r=(s,o,i)=>{const a=yp[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 bp=Object.freeze({__proto__:null,bitGet:gp,bitLen:pp,bitMask:la,bitSet:mp,bytesToHex:sr,bytesToNumberBE:ln,bytesToNumberLE:fa,concatBytes:at,createHmacDrbg:tf,ensureBytes:nt,equalBytes:hp,hexToBytes:or,hexToNumber:ua,numberToBytesBE:Qn,numberToBytesLE:ef,numberToHexUnpadded:Qu,numberToVarBytesBE:dp,utf8ToBytes:wo,validateObject:yr});/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */const Pe=BigInt(0),Ae=BigInt(1),kn=BigInt(2),wp=BigInt(3),Si=BigInt(4),kc=BigInt(5),Sc=BigInt(8);BigInt(9);BigInt(16);function Ke(e,t){const n=e%t;return n>=Pe?n:t+n}function xp(e,t,n){if(n<=Pe||t 0");if(n===Ae)return Pe;let r=Ae;for(;t>Pe;)t&Ae&&(r=r*e%n),e=e*e%n,t>>=Ae;return r}function tt(e,t,n){let r=e;for(;t-- >Pe;)r*=r,r%=n;return r}function $i(e,t){if(e===Pe||t<=Pe)throw new Error(`invert: expected positive integers, got n=${e} mod=${t}`);let n=Ke(e,t),r=t,s=Pe,o=Ae;for(;n!==Pe;){const a=r/n,c=r%n,u=s-o*a;r=n,n=c,s=o,o=u}if(r!==Ae)throw new Error("invert: does not exist");return Ke(s,t)}function vp(e){const t=(e-Ae)/kn;let n,r,s;for(n=e-Ae,r=0;n%kn===Pe;n/=kn,r++);for(s=kn;s(r[s]="function",r),t);return yr(e,n)}function Sp(e,t,n){if(n 0");if(n===Pe)return e.ONE;if(n===Ae)return t;let r=e.ONE,s=t;for(;n>Pe;)n&Ae&&(r=e.mul(r,s)),s=e.sqr(s),n>>=Ae;return r}function $p(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 da(e,t){const n=t!==void 0?t:e.toString(2).length,r=Math.ceil(n/8);return{nBitLength:n,nByteLength:r}}function rf(e,t,n=!1,r={}){if(e<=Pe)throw new Error(`Expected Fp ORDER > 0, got ${e}`);const{nBitLength:s,nByteLength:o}=da(e,t);if(o>2048)throw new Error("Field lengths over 2048 bytes are not supported");const i=Ep(e),a=Object.freeze({ORDER:e,BITS:s,BYTES:o,MASK:la(s),ZERO:Pe,ONE:Ae,create:c=>Ke(c,e),isValid:c=>{if(typeof c!="bigint")throw new Error(`Invalid field element: expected bigint, got ${typeof c}`);return Pe<=c&&cc===Pe,isOdd:c=>(c&Ae)===Ae,neg:c=>Ke(-c,e),eql:(c,u)=>c===u,sqr:c=>Ke(c*c,e),add:(c,u)=>Ke(c+u,e),sub:(c,u)=>Ke(c-u,e),mul:(c,u)=>Ke(c*u,e),pow:(c,u)=>Sp(a,c,u),div:(c,u)=>Ke(c*$i(u,e),e),sqrN:c=>c*c,addN:(c,u)=>c+u,subN:(c,u)=>c-u,mulN:(c,u)=>c*u,inv:c=>$i(c,e),sqrt:r.sqrt||(c=>i(a,c)),invertBatch:c=>$p(a,c),cmov:(c,u,l)=>l?u:c,toBytes:c=>n?ef(c,o):Qn(c,o),fromBytes:c=>{if(c.length!==o)throw new Error(`Fp.fromBytes: expected ${o}, got ${c.length}`);return n?fa(c):ln(c)}});return Object.freeze(a)}function _p(e,t,n=!1){e=nt("privateHash",e);const r=e.length,s=da(t).nByteLength+8;if(s<24||r1024)throw new Error(`hashToPrivateScalar: expected ${s}-1024 bytes of input, got ${r}`);const o=n?fa(e):ln(e);return Ke(o,t-Ae)+Ae}/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */const Ap=BigInt(0),zo=BigInt(1);function Bp(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>Ap;)o&zo&&(i=i.add(a)),a=a.double(),o>>=zo;return i},precomputeWindow(s,o){const{windows:i,windowSize:a}=r(o),c=[];let u=s,l=u;for(let f=0;f>=h,y>c&&(y-=d,i+=zo);const b=g,w=g+Math.abs(y)-1,m=p%2!==0,v=y<0;y===0?l=l.add(n(m,o[b])):u=u.add(n(v,o[w]))}return{p:u,f:l}},wNAFCached(s,o,i,a){const c=s._WINDOW_SIZE||1;let u=o.get(s);return u||(u=this.precomputeWindow(s,c),c!==1&&o.set(s,a(u))),this.wNAF(c,u,i)}}}function sf(e){return nf(e.Fp),yr(e,{n:"bigint",h:"bigint",Gx:"field",Gy:"field"},{nBitLength:"isSafeInteger",nByteLength:"isSafeInteger"}),Object.freeze({...da(e.n,e.nBitLength),...e,p:e.Fp.ORDER})}/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */function Tp(e){const t=sf(e);yr(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:Op,hexToBytes:Ip}=bp,An={Err:class extends Error{constructor(t=""){super(t)}},_parseInt(e){const{Err:t}=An;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:Op(r),l:e.subarray(n+2)}},toSig(e){const{Err:t}=An,n=typeof e=="string"?Ip(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}=An._parseInt(n.subarray(2)),{d:i,l:a}=An._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}`}},ct=BigInt(0),Oe=BigInt(1),Pt=BigInt(2),js=BigInt(3),$c=BigInt(4);function Cp(e){const t=Tp(e),{Fp:n}=t,r=t.toBytes||((p,g,y)=>{const b=g.toAffine();return at(Uint8Array.from([4]),n.toBytes(b.x),n.toBytes(b.y))}),s=t.fromBytes||(p=>{const g=p.subarray(1),y=n.fromBytes(g.subarray(0,n.BYTES)),b=n.fromBytes(g.subarray(n.BYTES,2*n.BYTES));return{x:y,y:b}});function o(p){const{a:g,b:y}=t,b=n.sqr(p),w=n.mul(b,p);return n.add(n.add(w,n.mul(p,g)),y)}function i(p){return typeof p=="bigint"&&ctn.eql(m,n.ZERO);return w(y)&&w(b)?f.ZERO:new f(y,b,n.ONE)}get x(){return this.toAffine().x}get y(){return this.toAffine().y}static normalizeZ(g){const y=n.invertBatch(g.map(b=>b.pz));return g.map((b,w)=>b.toAffine(y[w])).map(f.fromAffine)}static fromHex(g){const y=f.fromAffine(s(nt("pointHex",g)));return y.assertValidity(),y}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}=this.toAffine();if(!n.isValid(g)||!n.isValid(y))throw new Error("bad point: x or y not FE");const b=n.sqr(y),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){l(g);const{px:y,py:b,pz:w}=this,{px:m,py:v,pz:S}=g,O=n.eql(n.mul(y,S),n.mul(m,w)),C=n.eql(n.mul(b,S),n.mul(v,w));return O&&C}negate(){return new f(this.px,n.neg(this.py),this.pz)}double(){const{a:g,b:y}=t,b=n.mul(y,js),{px:w,py:m,pz:v}=this;let S=n.ZERO,O=n.ZERO,C=n.ZERO,P=n.mul(w,w),B=n.mul(m,m),N=n.mul(v,v),H=n.mul(w,m);return H=n.add(H,H),C=n.mul(w,v),C=n.add(C,C),S=n.mul(g,C),O=n.mul(b,N),O=n.add(S,O),S=n.sub(B,O),O=n.add(B,O),O=n.mul(S,O),S=n.mul(H,S),C=n.mul(b,C),N=n.mul(g,N),H=n.sub(P,N),H=n.mul(g,H),H=n.add(H,C),C=n.add(P,P),P=n.add(C,P),P=n.add(P,N),P=n.mul(P,H),O=n.add(O,P),N=n.mul(m,v),N=n.add(N,N),P=n.mul(N,H),S=n.sub(S,P),C=n.mul(N,B),C=n.add(C,C),C=n.add(C,C),new f(S,O,C)}add(g){l(g);const{px:y,py:b,pz:w}=this,{px:m,py:v,pz:S}=g;let O=n.ZERO,C=n.ZERO,P=n.ZERO;const B=t.a,N=n.mul(t.b,js);let H=n.mul(y,m),K=n.mul(b,v),E=n.mul(w,S),$=n.add(y,b),x=n.add(m,v);$=n.mul($,x),x=n.add(H,K),$=n.sub($,x),x=n.add(y,w);let _=n.add(m,S);return x=n.mul(x,_),_=n.add(H,E),x=n.sub(x,_),_=n.add(b,w),O=n.add(v,S),_=n.mul(_,O),O=n.add(K,E),_=n.sub(_,O),P=n.mul(B,x),O=n.mul(N,E),P=n.add(O,P),O=n.sub(K,P),P=n.add(K,P),C=n.mul(O,P),K=n.add(H,H),K=n.add(K,H),E=n.mul(B,E),x=n.mul(N,x),K=n.add(K,E),E=n.sub(H,E),E=n.mul(B,E),x=n.add(x,E),H=n.mul(K,x),C=n.add(C,H),H=n.mul(_,x),O=n.mul($,O),O=n.sub(O,H),H=n.mul($,K),P=n.mul(_,P),P=n.add(P,H),new f(O,C,P)}subtract(g){return this.add(g.negate())}is0(){return this.equals(f.ZERO)}wNAF(g){return h.wNAFCached(this,u,g,y=>{const b=n.invertBatch(y.map(w=>w.pz));return y.map((w,m)=>w.toAffine(b[m])).map(f.fromAffine)})}multiplyUnsafe(g){const y=f.ZERO;if(g===ct)return y;if(a(g),g===Oe)return this;const{endo:b}=t;if(!b)return h.unsafeLadder(this,g);let{k1neg:w,k1:m,k2neg:v,k2:S}=b.splitScalar(g),O=y,C=y,P=this;for(;m>ct||S>ct;)m&Oe&&(O=O.add(P)),S&Oe&&(C=C.add(P)),P=P.double(),m>>=Oe,S>>=Oe;return w&&(O=O.negate()),v&&(C=C.negate()),C=new f(n.mul(C.px,b.beta),C.py,C.pz),O.add(C)}multiply(g){a(g);let y=g,b,w;const{endo:m}=t;if(m){const{k1neg:v,k1:S,k2neg:O,k2:C}=m.splitScalar(y);let{p:P,f:B}=this.wNAF(S),{p:N,f:H}=this.wNAF(C);P=h.constTimeNegate(v,P),N=h.constTimeNegate(O,N),N=new f(n.mul(N.px,m.beta),N.py,N.pz),b=P.add(N),w=B.add(H)}else{const{p:v,f:S}=this.wNAF(y);b=v,w=S}return f.normalizeZ([b,w])[0]}multiplyAndAddUnsafe(g,y,b){const w=f.BASE,m=(S,O)=>O===ct||O===Oe||!S.equals(w)?S.multiplyUnsafe(O):S.multiply(O),v=m(this,y).add(m(g,b));return v.is0()?void 0:v}toAffine(g){const{px:y,py:b,pz:w}=this,m=this.is0();g==null&&(g=m?n.ONE:n.inv(w));const v=n.mul(y,g),S=n.mul(b,g),O=n.mul(w,g);if(m)return{x:n.ZERO,y:n.ZERO};if(!n.eql(O,n.ONE))throw new Error("invZ was invalid");return{x:v,y:S}}isTorsionFree(){const{h:g,isTorsionFree:y}=t;if(g===Oe)return!0;if(y)return y(f,this);throw new Error("isTorsionFree() has not been declared for the elliptic curve")}clearCofactor(){const{h:g,clearCofactor:y}=t;return g===Oe?this:y?y(f,this):this.multiplyUnsafe(t.h)}toRawBytes(g=!0){return this.assertValidity(),r(f,this,g)}toHex(g=!0){return sr(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=Bp(f,t.endo?Math.ceil(d/2):d);return{CURVE:t,ProjectivePoint:f,normPrivateKeyToScalar:c,weierstrassEquation:o,isWithinCurveOrder:i}}function Pp(e){const t=sf(e);return yr(t,{hash:"hash",hmac:"function",randomBytes:"function"},{bits2int:"function",bits2int_modN:"function",lowS:"boolean"}),Object.freeze({lowS:!0,...t})}function Up(e){const t=Pp(e),{Fp:n,n:r}=t,s=n.BYTES+1,o=2*n.BYTES+1;function i(x){return ctsr(Qn(x,t.nByteLength));function p(x){const _=r>>Oe;return x>_}function g(x){return p(x)?a(-x):x}const y=(x,_,I)=>ln(x.slice(_,I));class b{constructor(_,I,L){this.r=_,this.s=I,this.recovery=L,this.assertValidity()}static fromCompact(_){const I=t.nByteLength;return _=nt("compactSignature",_,I*2),new b(y(_,0,I),y(_,I,2*I))}static fromDER(_){const{r:I,s:L}=An.toSig(nt("DER",_));return new b(I,L)}assertValidity(){if(!d(this.r))throw new Error("r must be 0 < r < CURVE.n");if(!d(this.s))throw new Error("s must be 0 < s < CURVE.n")}addRecoveryBit(_){return new b(this.r,this.s,_)}recoverPublicKey(_){const{r:I,s:L,recovery:U}=this,j=C(nt("msgHash",_));if(U==null||![0,1,2,3].includes(U))throw new Error("recovery id invalid");const M=U===2||U===3?I+t.n:I;if(M>=n.ORDER)throw new Error("recovery id 2 or 3 invalid");const z=(U&1)===0?"02":"03",ce=u.fromHex(z+h(M)),oe=c(M),Q=a(-j*oe),le=a(L*oe),de=u.BASE.multiplyAndAddUnsafe(ce,Q,le);if(!de)throw new Error("point at infinify");return de.assertValidity(),de}hasHighS(){return p(this.s)}normalizeS(){return this.hasHighS()?new b(this.r,a(-this.s),this.recovery):this}toDERRawBytes(){return or(this.toDERHex())}toDERHex(){return An.hexFromSig({r:this.r,s:this.s})}toCompactRawBytes(){return or(this.toCompactHex())}toCompactHex(){return h(this.r)+h(this.s)}}const w={isValidPrivateKey(x){try{return l(x),!0}catch{return!1}},normPrivateKeyToScalar:l,randomPrivateKey:()=>{const x=t.randomBytes(n.BYTES+8),_=_p(x,r);return Qn(_,t.nByteLength)},precompute(x=8,_=u.BASE){return _._setWindowSize(x),_.multiply(BigInt(3)),_}};function m(x,_=!0){return u.fromPrivateKey(x).toRawBytes(_)}function v(x){const _=x instanceof Uint8Array,I=typeof x=="string",L=(_||I)&&x.length;return _?L===s||L===o:I?L===2*s||L===2*o:x instanceof u}function S(x,_,I=!0){if(v(x))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(x)).toRawBytes(I)}const O=t.bits2int||function(x){const _=ln(x),I=x.length*8-t.nBitLength;return I>0?_>>BigInt(I):_},C=t.bits2int_modN||function(x){return a(O(x))},P=la(t.nBitLength);function B(x){if(typeof x!="bigint")throw new Error("bigint expected");if(!(ct<=x&&xue in I))throw new Error("sign() legacy options not supported");const{hash:L,randomBytes:U}=t;let{lowS:j,prehash:M,extraEntropy:z}=I;j==null&&(j=!0),x=nt("msgHash",x),M&&(x=nt("prehashed msgHash",L(x)));const ce=C(x),oe=l(_),Q=[B(oe),B(ce)];if(z!=null){const ue=z===!0?U(n.BYTES):z;Q.push(nt("extraEntropy",ue,n.BYTES))}const le=at(...Q),de=ce;function _e(ue){const be=O(ue);if(!d(be))return;const It=c(be),et=u.BASE.multiply(be).toAffine(),Ne=a(et.x);if(Ne===ct)return;const Ct=a(It*a(de+Ne*oe));if(Ct===ct)return;let _r=(et.x===Ne?0:2)|Number(et.y&Oe),bc=Ct;return j&&p(Ct)&&(bc=g(Ct),_r^=1),new b(Ne,bc,_r)}return{seed:le,k2sig:_e}}const H={lowS:t.lowS,prehash:!1},K={lowS:t.lowS,prehash:!1};function E(x,_,I=H){const{seed:L,k2sig:U}=N(x,_,I);return tf(t.hash.outputLen,t.nByteLength,t.hmac)(L,U)}u.BASE._setWindowSize(8);function $(x,_,I,L=K){var et;const U=x;if(_=nt("msgHash",_),I=nt("publicKey",I),"strict"in L)throw new Error("options.strict was renamed to lowS");const{lowS:j,prehash:M}=L;let z,ce;try{if(typeof U=="string"||U instanceof Uint8Array)try{z=b.fromDER(U)}catch(Ne){if(!(Ne instanceof An.Err))throw Ne;z=b.fromCompact(U)}else if(typeof U=="object"&&typeof U.r=="bigint"&&typeof U.s=="bigint"){const{r:Ne,s:Ct}=U;z=new b(Ne,Ct)}else throw new Error("PARSE");ce=u.fromHex(I)}catch(Ne){if(Ne.message==="PARSE")throw new Error("signature must be Signature instance, Uint8Array or hex string");return!1}if(j&&z.hasHighS())return!1;M&&(_=t.hash(_));const{r:oe,s:Q}=z,le=C(_),de=c(Q),_e=a(le*de),ue=a(oe*de),be=(et=u.BASE.multiplyAndAddUnsafe(ce,_e,ue))==null?void 0:et.toAffine();return be?a(be.x)===oe:!1}return{CURVE:t,getPublicKey:m,getSharedSecret:S,sign:E,verify:$,ProjectivePoint:u,Signature:b,utils:w}}function Np(e,t){const n=e.ORDER;let r=ct;for(let d=n-Oe;d%Pt===ct;d/=Pt)r+=Oe;const s=r,o=(n-Oe)/Pt**s,i=(o-Oe)/Pt,a=Pt**s-Oe,c=Pt**(s-Oe),u=e.pow(t,o),l=e.pow(t,(o+Oe)/Pt);let f=(d,h)=>{let p=u,g=e.pow(h,a),y=e.sqr(g);y=e.mul(y,h);let b=e.mul(d,y);b=e.pow(b,i),b=e.mul(b,g),g=e.mul(b,h),y=e.mul(b,d);let w=e.mul(y,g);b=e.pow(w,c);let m=e.eql(b,e.ONE);g=e.mul(y,l),b=e.mul(w,p),y=e.cmov(g,y,m),w=e.cmov(b,w,m);for(let v=s;v>1;v--){let S=Pt**(v-Pt),O=e.pow(w,S);const C=e.eql(O,e.ONE);g=e.mul(y,p),p=e.mul(p,p),O=e.mul(w,p),y=e.cmov(g,y,C),w=e.cmov(O,w,C)}return{isValid:m,value:y}};if(e.ORDER%$c===js){const d=(e.ORDER-js)/$c,h=e.sqrt(e.neg(t));f=(p,g)=>{let y=e.sqr(g);const b=e.mul(p,g);y=e.mul(y,b);let w=e.pow(y,d);w=e.mul(w,b);const m=e.mul(w,h),v=e.mul(e.sqr(w),g),S=e.eql(v,p);let O=e.cmov(m,w,S);return{isValid:S,value:O}}}return f}function Lp(e,t){if(nf(e),!e.isValid(t.A)||!e.isValid(t.B)||!e.isValid(t.Z))throw new Error("mapToCurveSimpleSWU: invalid opts");const n=Np(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 Rp(e){if(e instanceof Uint8Array)return e;if(typeof e=="string")return wo(e);throw new Error("DST must be Uint8Array or string")}const Hp=ln;function sn(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 jp(e,t){const n=new Uint8Array(e.length);for(let r=0;r255&&(t=r(at(wo("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=at(t,sn(t.length,1)),c=sn(0,o),u=sn(n,2),l=new Array(i),f=r(at(c,e,u,sn(0,1),a));l[0]=r(at(f,sn(1,1),a));for(let h=1;h<=i;h++){const p=[jp(f,l[h-1]),sn(h+1,1),a];l[h]=r(at(...p))}return at(...l).slice(0,n)}function Dp(e,t,n,r,s){if(Lr(e),Lr(t),ha(n),t.length>255){const o=Math.ceil(2*r/8);t=s.create({dkLen:o}).update(wo("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(sn(n,2)).update(t).update(sn(t.length,1)).digest()}function _c(e,t,n){yr(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;Lr(e),ha(t);const u=Rp(c),l=r.toString(2).length,f=Math.ceil((l+s)/8),d=t*o*f;let h;if(a==="xmd")h=Kp(e,u,d,i);else if(a==="xof")h=Dp(e,u,d,s,i);else if(a===void 0)h=e;else throw new Error('expand must be "xmd", "xof" or undefined');const 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 Zp(e,t,n){if(typeof t!="function")throw new Error("mapToCurve() must be defined");return{hashToCurve(r,s){const o=_c(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=_c(r,1,{...n,DST:n.encodeDST,...s}),i=e.fromAffine(t(o[0])).clearCofactor();return i.assertValidity(),i}}}let of=class extends Wu{constructor(t,n){super(),this.finished=!1,this.destroyed=!1,_n.hash(t);const r=aa(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 of(e,t).update(n).digest();af.create=(e,t)=>new of(e,t);/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */function Vp(e){return{hash:e,hmac:(t,...n)=>af(e,t,tp(...n)),randomBytes:np}}function qp(e,t){const n=r=>Up({...e,...Vp(r)});return Object.freeze({...n(t),create:n})}/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */const cf=BigInt("0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f"),Ac=BigInt("0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141"),zp=BigInt(1),_i=BigInt(2),Bc=(e,t)=>(e+t/_i)/t;function Fp(e){const t=cf,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=tt(l,n,t)*l%t,d=tt(f,n,t)*l%t,h=tt(d,_i,t)*u%t,p=tt(h,s,t)*h%t,g=tt(p,o,t)*p%t,y=tt(g,a,t)*g%t,b=tt(y,c,t)*y%t,w=tt(b,a,t)*g%t,m=tt(w,n,t)*l%t,v=tt(m,i,t)*p%t,S=tt(v,r,t)*u%t,O=tt(S,_i,t);if(!hn.eql(hn.sqr(O),e))throw new Error("Cannot find square root");return O}const hn=rf(cf,void 0,void 0,{sqrt:Fp}),Kt=qp({a:BigInt(0),b:BigInt(7),Fp:hn,n:Ac,Gx:BigInt("55066263022277343669578718895168534326250603453777594175500187360389116729240"),Gy:BigInt("32670510020758816978083085130507043184471273380659243275938904335757337482424"),h:BigInt(1),lowS:!0,endo:{beta:BigInt("0x7ae96a2b657c07106e64479eac3434e99cf0497512f58995c1396c28719501ee"),splitScalar:e=>{const t=Ac,n=BigInt("0x3086d221a7d46bcde86c90e49284eb15"),r=-zp*BigInt("0xe4437ed6010e88286f547fa90abfe4c3"),s=BigInt("0x114ca50f7a8e2f3f657c1108d9d44cfd8"),o=n,i=BigInt("0x100000000000000000000000000000000"),a=Bc(o*e,t),c=Bc(-r*e,t);let u=Ke(e-a*n-c*s,t),l=Ke(-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}}}},Ju);BigInt(0);Kt.ProjectivePoint;Kt.utils.randomPrivateKey;const Gp=Mp(hn,[["0x8e38e38e38e38e38e38e38e38e38e38e38e38e38e38e38e38e38e38daaaaa8c7","0x7d3d4c80bc321d5b9f315cea7fd44c5d595d2fc0bf63b92dfff1044f17c6581","0x534c328d23f234e6e2a413deca25caece4506144037c40314ecbd0b53d9dd262","0x8e38e38e38e38e38e38e38e38e38e38e38e38e38e38e38e38e38e38daaaaa88c"],["0xd35771193d94918a9ca34ccbb7b640dd86cd409542f8487d9fe6b745781eb49b","0xedadc6f64383dc1df7c4b2d51b54225406d36b641f5e41bbc52a56612a8c6d14","0x0000000000000000000000000000000000000000000000000000000000000001"],["0x4bda12f684bda12f684bda12f684bda12f684bda12f684bda12f684b8e38e23c","0xc75e0c32d5cb7c0fa9d0a54b12a0a6d5647ab046d686da6fdffc90fc201d71a3","0x29a6194691f91a73715209ef6512e576722830a201be2018a765e85a9ecee931","0x2f684bda12f684bda12f684bda12f684bda12f684bda12f684bda12f38e38d84"],["0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffefffff93b","0x7a06534bb8bdb49fd5e9e6632722c2989467c1bfc8e8d978dfb425d2685c2573","0x6484aa716545ca2cf3a70c3fa8fe337e0a3d21162f0d6299a7bf8192bfd2a76f","0x0000000000000000000000000000000000000000000000000000000000000001"]].map(e=>e.map(t=>BigInt(t)))),Wp=Lp(hn,{A:BigInt("0x3f8731abdd661adca08a5558f0f5d272e953d363cb6f0e5d405447c01a444533"),B:BigInt("1771"),Z:hn.create(BigInt("-11"))});Zp(Kt.ProjectivePoint,e=>{const{x:t,y:n}=Wp(hn.create(e[0]));return Gp(t,n)},{DST:"secp256k1_XMD:SHA-256_SSWU_RO_",encodeDST:"secp256k1_XMD:SHA-256_SSWU_NU_",p:hn.ORDER,m:1,k:128,expand:"xmd",hash:Ju});function Ai(e){if(!Number.isSafeInteger(e)||e<0)throw new Error(`Wrong positive integer: ${e}`)}function Yp(e){if(typeof e!="boolean")throw new Error(`Expected boolean, not ${e}`)}function uf(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 Xp(e){if(typeof e!="function"||typeof e.create!="function")throw new Error("Hash should be wrapped by utils.wrapConstructor");Ai(e.outputLen),Ai(e.blockLen)}function Jp(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 Qp(e,t){uf(e);const n=t.outputLen;if(e.lengthnew DataView(e.buffer,e.byteOffset,e.byteLength),wt=(e,t)=>e<<32-t|e>>>t,tg=new Uint8Array(new Uint32Array([287454020]).buffer)[0]===68;if(!tg)throw new Error("Non little-endian hardware is not supported");Array.from({length:256},(e,t)=>t.toString(16).padStart(2,"0"));function ng(e){if(typeof e!="string")throw new TypeError(`utf8ToBytes expected string, got ${typeof e}`);return new TextEncoder().encode(e)}function ff(e){if(typeof e=="string"&&(e=ng(e)),!(e instanceof Uint8Array))throw new TypeError(`Expected input type is Uint8Array (got ${typeof e})`);return e}let rg=class{clone(){return this._cloneInto()}};function lf(e){const t=r=>e().update(ff(r)).digest(),n=e();return t.outputLen=n.outputLen,t.blockLen=n.blockLen,t.create=()=>e(),t}function sg(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 og=class extends rg{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=Go(this.buffer)}update(t){Fo.exists(this);const{view:n,buffer:r,blockLen:s}=this;t=ff(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,ag=(e,t,n)=>e&t^e&n^t&n,cg=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]),Ft=new Uint32Array([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]),Gt=new Uint32Array(64);let df=class extends og{constructor(){super(64,32,8,!1),this.A=Ft[0]|0,this.B=Ft[1]|0,this.C=Ft[2]|0,this.D=Ft[3]|0,this.E=Ft[4]|0,this.F=Ft[5]|0,this.G=Ft[6]|0,this.H=Ft[7]|0}get(){const{A:t,B:n,C:r,D:s,E:o,F:i,G:a,H:c}=this;return[t,n,r,s,o,i,a,c]}set(t,n,r,s,o,i,a,c){this.A=t|0,this.B=n|0,this.C=r|0,this.D=s|0,this.E=o|0,this.F=i|0,this.G=a|0,this.H=c|0}process(t,n){for(let 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=wt(d,7)^wt(d,18)^d>>>3,g=wt(h,17)^wt(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=wt(a,6)^wt(a,11)^wt(a,25),h=l+d+ig(a,c,u)+cg[f]+Gt[f]|0,g=(wt(r,2)^wt(r,13)^wt(r,22))+ag(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)}},ug=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 Bi=lf(()=>new df);lf(()=>new ug);function fg(e,t){if(e.length>t)throw new TypeError(`Data is larger than array size: ${e.length} > ${t}`)}function lg(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 dg(e){if(e>Number.MAX_SAFE_INTEGER)throw new TypeError("Number exceeds safe bounds!")}const{getRandomValues:hg}=crypto??globalThis.crypto??window.crypto;function pg(e=32){if(typeof hg=="function")return crypto.getRandomValues(new Uint8Array(e));throw new Error("Crypto module missing getRandomValues!")}function gg(e,t,n="be"){t===void 0&&(t=e.length),fg(e,t);const r=new Uint8Array(t).fill(0),s=n==="be"?0:t-e.length;return r.set(e,s),r}function hf(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 wg(e,t){const n=pf(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 gf(e){return Bi(Bi(e))}function xg(e){const t=gf(e);return hf([e,t.slice(0,4)])}function vg(e){const t=e.slice(0,-4),n=e.slice(-4);if(gf(t).slice(0,4).toString()!==n.toString())throw new Error("Invalid checksum!");return t}const Tc={encode:bg,decode:wg},mf={encode:e=>{const t=xg(e);return Tc.encode(t,"base58")},decode:e=>{const t=Tc.decode(e,"base58");return vg(t)}},yf="qpzry9x8gf2tvdw0s3jn54khce6mua7l",Eg=[996825010,642813549,513874426,1027748829,705979059],Ks=[{version:0,name:"bech32",const:1},{version:1,name:"bech32m",const:734539939}];function bf(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^=Eg[s])}return t}function wf(e){const t=[];let n;for(n=0;n>5);for(t.push(0),n=0;n>5*(5-i)&31);return o}function xf(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 $g(e,t,n){const r=t.concat(Sg(e,t,n));let s=e+"1";for(let o=0;oo.version===t[0])??Ks[0];if(!kg(r,t,s))throw new Error("Checksum verification failed!");return[r,t.slice(0,t.length-6)]}function _g(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 Ag(e){const t=e.lastIndexOf("1");return!(t<1||t+7>e.length||e.length>90)}function Bg(e,t="bc",n=0){const r=[n,...xf([...e],8,5)],s=Ks.find(i=>i.version===n)??Ks[0],o=$g(t,r,s);return Ef(o),o}function Ef(e){e=e.toLowerCase();const t=e.split("1",1)[0],[n,r]=vf(e),s=xf(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 Tg(e){e=e.toLowerCase();const[t,n]=vf(e);return n[0]}const kf={encode:Bg,decode:Ef,version:Tg},Sf="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",$f="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",Og=new TextEncoder;function _f(e,t=!1,n=!0){typeof e=="string"&&(e=Og.encode(e));const r=t?$f:Sf;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 Af(e,t=!1){const n=t||e.includes("-")||e.includes("_")?$f.split(""):Sf.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 Bf={encode:_f,decode:Af},Tf={encode:e=>_f(e,!0,!1),decode:e=>Af(e,!0)},Ig=BigInt(0),Cg=BigInt(255),Of=BigInt(256);function Pg(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 Ug(e,t,n="be"){t===void 0&&(t=Pg(e));const r=n==="le",s=new ArrayBuffer(t),o=new DataView(s);let i=r?0:t-1;for(;e>Ig;){const a=e&Cg,c=Number(a);r?o.setUint8(i++,c):o.setUint8(i--,c),e=(e-a)/Of}return new Uint8Array(s)}function Ng(e){let t=BigInt(0);for(let n=e.length-1;n>=0;n--)t=t*Of+BigInt(e[n]);return BigInt(t)}function Lg(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 Hg(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 jg(e,t,n="be"){t===void 0&&(t=Hg(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 Kg(e){let t=0;for(let n=e.length-1;n>=0;n--)t=t*256+e[n],dg(t);return t}const Dg=new TextEncoder,Mg=new TextDecoder;function pa(e){return Dg.encode(e)}function Wo(e){return Mg.decode(e)}function Zg(e,t){lg(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 Vg(e,t,n="le"){t=Zg(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 pa(t)}function Fg(e,t,n){if(e instanceof ArrayBuffer)return new Uint8Array(e);if(e instanceof Uint8Array)return gg(e,t,n);if(typeof e=="string")return Vg(e,t,n);if(typeof e=="bigint")return Ug(e,t,n);if(typeof e=="number")return jg(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=pg(t);return new re(n,t)}constructor(t,n,r){const s=Fg(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 im(this)}toNum(t="be"){const n=t==="be"?this.reverse():this;return Kg(n)}toBin(){return Rg(this)}toBig(t="be"){const n=t==="be"?this.reverse():this;return Ng(n)}toHash(){const t=Bi(this);return new re(t)}toJson(){const t=Wo(this);return JSON.parse(t)}toBech32(t,n=0){return kf.encode(this,t,n)}toStr(){return Wo(this)}toHex(){return qg(this)}toBytes(){return new Uint8Array(this)}tob58chk(){return mf.encode(this)}toBase64(){return Bf.encode(this)}toB64url(){return Tf.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=hf(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=Gg,re.big=Yg,re.bin=Wg,re.raw=Xg,re.str=Jg,re.hex=Qg,re.bytes=em,re.json=tm,re.base64=nm,re.b64url=rm,re.bech32=sm,re.b58chk=om,re.encode=pa,re.decode=Wo;let Y=re;function Gg(e,t,n){return new Y(e,t,n)}function Wg(e,t,n){return new Y(Lg(e),t,n)}function Yg(e,t,n){return new Y(e,t,n)}function Xg(e,t,n){return new Y(e,t,n)}function Jg(e,t,n){return new Y(pa(e),t,n)}function Qg(e,t,n){return new Y(e,t,n)}function em(e,t,n){return new Y(e,t,n)}function tm(e){return new Y(zg(e))}function nm(e){return new Y(Bf.decode(e))}function rm(e){return new Y(Tf.decode(e))}function sm(e){return new Y(kf.decode(e))}function om(e){return new Y(mf.decode(e))}class im{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 Ds=Kt.CURVE,ga=Ds.n,am=Ds.p,cm={x:Ds.Gx,y:Ds.Gy},um=BigInt(0);BigInt(1);BigInt(2);BigInt(3);BigInt(4);const Ti={N:ga,P:am,G:cm,_0n:um},Ar=rf(ga,32,!0),If=e=>Ke(e,ga);function ma(e,t=!1){if(t)throw new Error(e);return!1}function Cf(e){return Y.random(e)}function fm(e){const t=Y.bytes(e).big;return Y.big(If(t),32)}var lm=Object.freeze({__proto__:null,fail:ma,mod_bytes:fm,random:Cf});const{N:dm,_0n:hm}=Ti;function pm(e,t,n){const r=Y.bytes(e);return r.length!==t?ma(`Invalid byte size: ${r.hex} !== ${t}`,n):!0}function gm(e,t){return typeof e=="bigint"&&hmthis.big}lt(t){return new we(t).big0&&!t.includes(e.length))throw new Error(`Expected Uint8Array of length ${t}, not of length=${e.length}`)}function wm(e){if(typeof e!="function"||typeof e.create!="function")throw new Error("Hash should be wrapped by utils.wrapConstructor");Oi(e.outputLen),Oi(e.blockLen)}function xm(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 vm(e,t){Pf(e);const n=t.outputLen;if(e.lengthe instanceof Uint8Array,Yo=e=>new DataView(e.buffer,e.byteOffset,e.byteLength),xt=(e,t)=>e<<32-t|e>>>t,Sm=new Uint8Array(new Uint32Array([287454020]).buffer)[0]===68;if(!Sm)throw new Error("Non little-endian hardware is not supported");Array.from({length:256},(e,t)=>t.toString(16).padStart(2,"0"));function $m(e){if(typeof e!="string")throw new Error(`utf8ToBytes expected string, got ${typeof e}`);return new Uint8Array(new TextEncoder().encode(e))}function ya(e){if(typeof e=="string"&&(e=$m(e)),!km(e))throw new Error(`expected Uint8Array, got ${typeof e}`);return e}let Uf=class{clone(){return this._cloneInto()}};function Vn(e){const t=r=>e().update(ya(r)).digest(),n=e();return t.outputLen=n.outputLen,t.blockLen=n.blockLen,t.create=()=>e(),t}function _m(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 ba extends Uf{constructor(t,n,r,s){super(),this.blockLen=t,this.outputLen=n,this.padOffset=r,this.isLE=s,this.finished=!1,this.length=0,this.pos=0,this.destroyed=!1,this.buffer=new Uint8Array(t),this.view=Yo(this.buffer)}update(t){Bn.exists(this);const{view:n,buffer:r,blockLen:s}=this;t=ya(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,Bm=(e,t,n)=>e&t^e&n^t&n,Tm=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]),Yt=new Uint32Array(64);let Nf=class extends ba{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)Yt[f]=t.getUint32(n,!1);for(let f=16;f<64;f++){const d=Yt[f-15],h=Yt[f-2],p=xt(d,7)^xt(d,18)^d>>>3,g=xt(h,17)^xt(h,19)^h>>>10;Yt[f]=g+Yt[f-7]+p+Yt[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=xt(a,6)^xt(a,11)^xt(a,25),h=l+d+Am(a,c,u)+Tm[f]+Yt[f]|0,g=(xt(r,2)^xt(r,13)^xt(r,22))+Bm(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(){Yt.fill(0)}destroy(){this.set(0,0,0,0,0,0,0,0),this.buffer.fill(0)}};class Om extends Nf{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 Ms=Vn(()=>new Nf);Vn(()=>new Om);const ps=BigInt(2**32-1),Ii=BigInt(32);function Lf(e,t=!1){return t?{h:Number(e&ps),l:Number(e>>Ii&ps)}:{h:Number(e>>Ii&ps)|0,l:Number(e&ps)|0}}function Im(e,t=!1){let n=new Uint32Array(e.length),r=new Uint32Array(e.length);for(let s=0;sBigInt(e>>>0)<>>0),Pm=(e,t,n)=>e>>>n,Um=(e,t,n)=>e<<32-n|t>>>n,Nm=(e,t,n)=>e>>>n|t<<32-n,Lm=(e,t,n)=>e<<32-n|t>>>n,Rm=(e,t,n)=>e<<64-n|t>>>n-32,Hm=(e,t,n)=>e>>>n-32|t<<64-n,jm=(e,t)=>t,Km=(e,t)=>e,Dm=(e,t,n)=>e<>>32-n,Mm=(e,t,n)=>t<>>32-n,Zm=(e,t,n)=>t<>>64-n,Vm=(e,t,n)=>e<>>64-n;function qm(e,t,n,r){const s=(t>>>0)+(r>>>0);return{h:e+n+(s/2**32|0)|0,l:s|0}}const zm=(e,t,n)=>(e>>>0)+(t>>>0)+(n>>>0),Fm=(e,t,n,r)=>t+n+r+(e/2**32|0)|0,Gm=(e,t,n,r)=>(e>>>0)+(t>>>0)+(n>>>0)+(r>>>0),Wm=(e,t,n,r,s)=>t+n+r+s+(e/2**32|0)|0,Ym=(e,t,n,r,s)=>(e>>>0)+(t>>>0)+(n>>>0)+(r>>>0)+(s>>>0),Xm=(e,t,n,r,s,o)=>t+n+r+s+o+(e/2**32|0)|0,Jm={fromBig:Lf,split:Im,toBig:Cm,shrSH:Pm,shrSL:Um,rotrSH:Nm,rotrSL:Lm,rotrBH:Rm,rotrBL:Hm,rotr32H:jm,rotr32L:Km,rotlSH:Dm,rotlSL:Mm,rotlBH:Zm,rotlBL:Vm,add:qm,add3L:zm,add3H:Fm,add4L:Gm,add4H:Wm,add5H:Xm,add5L:Ym};var ne=Jm;const[Qm,ey]=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))),Xt=new Uint32Array(80),Jt=new Uint32Array(80);let xo=class extends ba{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:y}=this;return[t,n,r,s,o,i,a,c,u,l,f,d,h,p,g,y]}set(t,n,r,s,o,i,a,c,u,l,f,d,h,p,g,y){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=y|0}process(t,n){for(let m=0;m<16;m++,n+=4)Xt[m]=t.getUint32(n),Jt[m]=t.getUint32(n+=4);for(let m=16;m<80;m++){const v=Xt[m-15]|0,S=Jt[m-15]|0,O=ne.rotrSH(v,S,1)^ne.rotrSH(v,S,8)^ne.shrSH(v,S,7),C=ne.rotrSL(v,S,1)^ne.rotrSL(v,S,8)^ne.shrSL(v,S,7),P=Xt[m-2]|0,B=Jt[m-2]|0,N=ne.rotrSH(P,B,19)^ne.rotrBH(P,B,61)^ne.shrSH(P,B,6),H=ne.rotrSL(P,B,19)^ne.rotrBL(P,B,61)^ne.shrSL(P,B,6),K=ne.add4L(C,H,Jt[m-7],Jt[m-16]),E=ne.add4H(K,O,N,Xt[m-7],Xt[m-16]);Xt[m]=E|0,Jt[m]=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:y,Hh:b,Hl:w}=this;for(let m=0;m<80;m++){const v=ne.rotrSH(f,d,14)^ne.rotrSH(f,d,18)^ne.rotrBH(f,d,41),S=ne.rotrSL(f,d,14)^ne.rotrSL(f,d,18)^ne.rotrBL(f,d,41),O=f&h^~f&g,C=d&p^~d&y,P=ne.add5L(w,S,C,ey[m],Jt[m]),B=ne.add5H(P,b,v,O,Qm[m],Xt[m]),N=P|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),E=r&o^r&a^o&a,$=s&i^s&c^i&c;b=g|0,w=y|0,g=h|0,y=p|0,h=f|0,p=d|0,{h:f,l:d}=ne.add(u|0,l|0,B|0,N|0),u=a|0,l=c|0,a=o|0,c=i|0,o=r|0,i=s|0;const x=ne.add3L(N,K,$);r=ne.add3H(x,B,H,E),s=x|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:y}=ne.add(this.Gh|0,this.Gl|0,g|0,y|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,l,f,d,h,p,g,y,b,w)}roundClean(){Xt.fill(0),Jt.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 ty extends xo{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 ny extends xo{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 ry extends xo{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 sy=Vn(()=>new xo);Vn(()=>new ty);Vn(()=>new ny);Vn(()=>new ry);const oy=new Uint8Array([7,4,13,1,10,6,15,3,12,0,9,5,2,14,11,8]),Rf=Uint8Array.from({length:16},(e,t)=>t),iy=Rf.map(e=>(9*e+5)%16);let wa=[Rf],xa=[iy];for(let e=0;e<4;e++)for(let t of[wa,xa])t.push(t[e].map(n=>oy[n]));const Hf=[[11,14,15,12,5,8,7,9,11,13,14,15,6,7,9,8],[12,13,11,15,6,9,9,7,12,15,11,13,7,8,7,7],[13,15,14,11,7,7,6,8,13,14,13,12,5,5,6,9],[14,11,12,14,8,6,5,5,15,12,15,14,9,9,8,6],[15,12,13,13,9,5,8,6,14,11,12,11,8,6,5,5]].map(e=>new Uint8Array(e)),ay=wa.map((e,t)=>e.map(n=>Hf[t][n])),cy=xa.map((e,t)=>e.map(n=>Hf[t][n])),uy=new Uint32Array([0,1518500249,1859775393,2400959708,2840853838]),fy=new Uint32Array([1352829926,1548603684,1836072691,2053994217,0]),gs=(e,t)=>e<>>32-t;function Ic(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);let ly=class extends ba{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)ms[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=uy[h],y=fy[h],b=wa[h],w=xa[h],m=ay[h],v=cy[h];for(let S=0;S<16;S++){const O=gs(r+Ic(h,o,a,u)+ms[b[S]]+g,m[S])+f|0;r=f,f=u,u=gs(a,10)|0,a=o,o=O}for(let S=0;S<16;S++){const O=gs(s+Ic(p,i,c,l)+ms[w[S]]+y,v[S])+d|0;s=d,d=l,l=gs(c,10)|0,c=i,i=O}}this.set(this.h1+a+l|0,this.h2+u+d|0,this.h3+f+s|0,this.h4+r+i|0,this.h0+o+c|0)}roundClean(){ms.fill(0)}destroy(){this.destroyed=!0,this.buffer.fill(0),this.set(0,0,0,0,0)}};const dy=Vn(()=>new ly);let jf=class extends Uf{constructor(t,n){super(),this.finished=!1,this.destroyed=!1,Bn.hash(t);const r=ya(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 jf(e,t).update(n).digest();Kf.create=(e,t)=>new jf(e,t);function hy(e){const t=Y.bytes(e);return Y.raw(Ms(t))}function ir(e){const t=Y.bytes(e);return Y.raw(Ms(Ms(t)))}function va(e){const t=Y.bytes(e);return Y.raw(dy(Ms(t)))}function py(e,t){const n=Y.bytes(e),r=Y.bytes(t);return Y.raw(Kf(sy,n,r))}function gy(e){const t=Y.str(e).digest;return Y.join([t,t])}function my(e=32){return Ea(Cf(e))}function Ea(e){return Ve.mod(e).buff}function Df(e,t=!1){const n=Ve.mod(e).point;return t?n.x:n.buff}function Mf(e,t){const n=Zn.from_x(t),r=Ve.mod(e);return n.mul(r).buff}function yy(e,t,n="ecdh/code"){const r=gy(n),s=Ea(e),o=Df(s),i=Y.bytes(t),a=Mf(s,i),c=[o.hex,i.hex];return c.sort(),py(a,Y.join([r,...c]))}function by(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 wy(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 xy=Object.freeze({__proto__:null,genSecretKey:my,getPublicKey:Df,getSecretKey:Ea,getSharedCode:yy,getSharedKey:Mf,is_even_pub:by,xonly_pub:wy});Y.random(32);const Zf={secp:Kt},Ci={...xy,...lm};function vo(e){const t=k.bytes(e);return Ot(t,33),va(t)}function Vf(e){const t=$e.fmt.toBytes(e,!1);return va(t)}function qf(e){const t=$e.fmt.toBytes(e,!1);return hy(t)}function zf(e,t="main"){const n=t==="main"?["1"]:["m","n"];for(const r of n)if(e.startsWith(r))return!0;return!1}function Ff(e,t="main"){const n=k.bytes(e),r=t==="main"?k.num(0):k.num(111);return Ot(e,20),n.prepend(r).tob58chk()}function vy(e,t="main"){if(!zf(e,t))throw new TypeError("Invalid p2pkh address!");return k.b58chk(e).slice(1)}function Ey(e){const t=k.bytes(e);return Ot(t,20),["OP_DUP","OP_HASH160",t.hex,"OP_EQUALVERIFY","OP_CHECKSIG"]}function ky(e,t){const n=vo(e);return Ff(n,t)}const Gf={check:zf,encode:Ff,decode:vy,hash:vo,scriptPubKey:Ey,fromPubKey:ky};function Wf(e,t="main"){const n=t==="main"?["3"]:["2"];for(const r of n)if(e.startsWith(r))return!0;return!1}function Yf(e,t="main"){const n=t==="main"?k.num(5):k.num(196),r=k.bytes(e);return Ot(r,20),r.prepend(n).tob58chk()}function Sy(e,t="main"){if(!Wf(e,t))throw new TypeError(`Invalid p2sh address for network ${t}:`+e);return k.b58chk(e).slice(1)}function $y(e){return["OP_HASH160",k.bytes(e).hex,"OP_EQUAL"]}function _y(e,t){const n=Vf(e);return Yf(n,t)}const Xf={check:Wf,encode:Yf,decode:Sy,hash:Vf,scriptPubKey:$y,fromScript:_y},ka={main:"bc",testnet:"tb",signet:"tb",regtest:"bcrt"},Ay=["bc1q","tb1q","bcrt1q"];function Jf(e){for(const t of Ay)if(e.startsWith(t))return!0;return!1}function Qf(e,t="main"){const n=ka[t],r=k.bytes(e);return Ot(r,20),r.toBech32(n,0)}function By(e){if(!Jf(e))throw new TypeError("Invalid segwit address!");return k.bech32(e)}function Ty(e){const t=k.bytes(e);return Ot(t,20),["OP_0",t.hex]}function Oy(e,t){const n=vo(e);return Qf(n,t)}const el={check:Jf,encode:Qf,decode:By,hash:vo,scriptPubKey:Ty,fromPubKey:Oy},Iy=["bc1q","tb1q","bcrt1q"];function tl(e){for(const t of Iy)if(e.startsWith(t))return!0;return!1}function nl(e,t="main"){const n=ka[t],r=k.bytes(e);return Ot(r,32),r.toBech32(n,0)}function Cy(e){if(!tl(e))throw new TypeError("Invalid segwit address!");return k.bech32(e)}function Py(e){const t=k.bytes(e);return Ot(t,32),["OP_0",t.hex]}function Uy(e,t){const n=qf(e);return nl(n,t)}const rl={check:tl,encode:nl,decode:Cy,hash:qf,scriptPubKey:Py,fromScript:Uy};function Nn(e){const t=k.bytes(e);return t.length>32?t.slice(1,33):t}const Ny=["bc1p","tb1p","bcrt1p"];function sl(e){for(const t of Ny)if(e.startsWith(t))return!0;return!1}function ol(e,t="main"){const n=ka[t],r=k.bytes(e);return Ot(r,32),r.toBech32(n,1)}function Ly(e){if(!sl(e))throw new TypeError("Invalid taproot address!");return k.bech32(e)}function Ry(e){const t=k.bytes(e);return Ot(t,32),["OP_1",t.hex]}function Hy(e,t){const n=Nn(e);return ol(n,t)}const il={check:sl,encode:ol,decode:Ly,scriptPubKey:Ry,fromPubKey:Hy},jy={version:2,vin:[],vout:[],locktime:0},Ky={scriptSig:[],sequence:4294967293,witness:[]},Dy={value:0n,scriptPubKey:[]};function Sa(e){const t={...jy,...e};return t.vin=t.vin.map(n=>({...Ky,...n})),t.vout=t.vout.map(n=>({...Dy,...n})),t}function ar(e,t){const{version:n,vin:r,vout:s,locktime:o}=Sa(e),i=t!==!0&&My(r),a=[$a(n)];i&&a.push(k.hex("0001")),a.push(Zy(r)),a.push(Vy(s));for(const c of r)i&&a.push(zy(c.witness));return a.push(_a(o)),k.join(a)}function My(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 $a(e){return k.num(e,4).reverse()}function ts(e){return k.hex(e,32).reverse()}function ns(e){return k.num(e,4).reverse()}function rs(e){if(typeof e=="string")return k.hex(e,4).reverse();if(typeof e=="number")return k.num(e,4).reverse();throw new Error("Unrecognized format: "+String(e))}function Zy(e){const t=[k.varInt(e.length,"le")];for(const n of e){const{txid:r,vout:s,scriptSig:o,sequence:i}=n;t.push(ts(r)),t.push(ns(s)),t.push(Mn(o,!0)),t.push(rs(i))}return k.join(t)}function pn(e){if(typeof e=="number"){if(e%1!==0)throw new Error("Value must be an integer:"+String(e));return k.num(e,8).reverse()}return k.big(e,8).reverse()}function Vy(e){const t=[k.varInt(e.length,"le")];for(const n of e)t.push(qy(n));return k.join(t)}function qy(e){const{value:t,scriptPubKey:n}=e,r=[];return r.push(pn(t)),r.push(Mn(n,!0)),k.join(r)}function zy(e=[]){const t=[];if(Array.isArray(e)){const n=k.varInt(e.length);t.push(n);for(const r of e)t.push(Fy(r));return k.join(t)}else return k.bytes(e)}function Fy(e){return Gy(e)?new k(0):Mn(e,!0)}function Gy(e){if(Array.isArray(e))return e.length===0;if(typeof e=="string"&&e==="")return!0;const t=k.bytes(e);return t.length===1&&t[0]===0}function _a(e){if(typeof e=="string")return k.hex(e,4);if(typeof e=="number")return k.num(e,4).reverse();throw new Error("Unrecognized format: "+String(e))}function Aa(e){typeof e=="string"&&(e=k.hex(e).raw);const t=new mr(e),n=Wy(t),r=Yy(t),s=Xy(t),o=Qy(t);if(r)for(const a of s)a.witness=tb(t);const i=nb(t);return{version:n,vin:s,vout:o,locktime:i}}function Wy(e){return e.read(4).reverse().toNum()}function Yy(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 Xy(e){const t=[],n=e.readSize("le");for(let r=0;r0?e.read(n).hex:null}function cl(e,t){const n=al(e);return n!==null?n:[]}function nb(e){return e.read(4).reverse().toNum()}function rb(e){if(zu(e))return Aa(e);if(typeof e=="object"&&!(e instanceof Uint8Array))return ar(e),Sa(e);throw new Error("Invalid format: "+typeof e)}function sb(e){if(zu(e))return Aa(e),k.bytes(e);if(typeof e=="object")return ar(e);throw new Error("Invalid format: "+typeof e)}const Ba={toBytes:sb,toJson:rb},ob=[["p2pkh",/^76a914(?\w{40})88ac$/],["p2sh",/^a914(?\w{40})87$/],["p2w-pkh",/^0014(?\w{40})$/],["p2w-sh",/^0020(?\w{64})$/],["p2tr",/^5120(?\w{64})$/]],ib=[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 ab(e){let t=e.at(-1);return Mt(t)&&(t=k.hex(t)),e.length>1&&t instanceof Uint8Array&&t[0]===80?(e.pop(),k.raw(t)):null}function cb(e){let t=e.at(-1);return Mt(t)&&(t=k.hex(t)),e.length>1&&t instanceof Uint8Array&&t.length>32&&ib.includes(t[0]&254)?(e.pop(),k.raw(t)):null}function ub(e){if(e.length>1){const t=e.at(-1);try{const n=$e.fmt.toBytes(t);return e.pop(),n}catch{return null}}return null}function fb(e){const t=[];for(const n of e)if(Mt(n)||n instanceof Uint8Array||typeof n=="number")t.push(k.bytes(n));else throw new Error("unrecognized value: "+String(n));return t}function lb(e=[]){const t=[...e],n=ab(t),r=cb(t),s=ub(t),o=fb(t);return{annex:n,cblock:r,script:s,params:o}}function db(e){const t=$e.fmt.toBytes(e,!1).hex;for(const[n,r]of ob){const s=n,{groups:o}=r.exec(t)??{},{hash:i}=o??{};if(Mt(i))return{type:s,data:k.hex(i)}}return{type:"raw",data:k.hex(t)}}function hb(e){const t=Ba.toJson(e),n=ar(t,!0);return ir(n).reverse().hex}function pb(e){const t=Ba.toJson(e),n=ar(t,!0).length,r=ar(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:Sa,encode:ar,decode:Aa,fmt:Ba,util:{getTxSize:pb,getTxid:hb,readScriptPubKey:db,readWitness:lb}},gb=[["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 mb(e,t){switch(t){case"base58":return k.b58chk(e).slice(1);case"bech32":return k.bech32(e);case"bech32m":return k.bech32(e);default:throw new Error("Invalid address format: "+t)}}function yb(e){for(const t of gb){const[n,r,s,o,i]=t;if(e.startsWith(n)&&mb(e,i).length===o)return t}throw new Error("Invalid address: "+e)}function ul(e){switch(e){case"p2pkh":return Gf;case"p2sh":return Xf;case"p2w-pkh":return el;case"p2w-sh":return rl;case"p2tr":return il;default:throw new Error("Invalid address type: "+e)}}function fl(e){const[t,n,r]=yb(e),s=ul(n),o=s.decode(e,r),i=s.scriptPubKey(o);return{prefix:t,type:n,network:r,data:o,script:i}}function bb(e,t){const{type:n,data:r}=ie.util.readScriptPubKey(e);return ul(n).encode(r,t)}function wb(e){const{script:t}=fl(e);return $e.fmt.toAsm(t,!1)}const Rr={p2pkh:Gf,p2sh:Xf,p2wpkh:el,p2wsh:rl,p2tr:il,decode:fl,fromScriptPubKey:bb,toScriptPubKey:wb},xb=[1,2,3];function Ta(e,t,n={}){const{sigflag:r=1}=n,s=(r&128)===128,o=r%128;if(!xb.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 y=n.script;if(y===void 0&&n.pubkey!==void 0&&(y=`76a914${va(n.pubkey).hex}88ac`),y===void 0)throw new Error("No pubkey / script has been set!");if($e.fmt.toAsm(y).includes("OP_CODESEPARATOR"))throw new Error("This library does not currently support the use of OP_CODESEPARATOR in segwit scripts.");const b=[$a(a),vb(c,s),Eb(c,o,s),ts(f),ns(d),$e.encode(y,!0),pn(g),rs(p),kb(u,t,o),_a(l),k.num(r,4).reverse()];return ir(k.join(b))}function vb(e,t){if(t===!0)return k.num(0,32);const n=[];for(const{txid:r,vout:s}of e)n.push(ts(r)),n.push(ns(s));return ir(k.join(n))}function Eb(e,t,n){if(n||t!==1)return k.num(0,32);const r=[];for(const{sequence:s}of e)r.push(rs(s));return ir(k.join(r))}function kb(e,t,n){const r=[];if(n===1){for(const{value:s,scriptPubKey:o}of e)r.push(pn(s)),r.push($e.encode(o,!0));return ir(k.join(r))}if(n===3&&t1&&c[1].length===33)u=k.bytes(c[1]);else return je("No pubkey provided!",s);const l=$e.fmt.toParam(c[0]),f=l.slice(0,-1),d=l.slice(-1)[0],h=Ta(r,t,{...n,sigflag:d});return Zf.secp.verify(f,h,u)?!0:je("Invalid signature!",s)}const _b={hash:Ta,sign:Sb,verify:$b},Ab=[0,1,2,3,129,130,131];function Oa(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(!Ab.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:y=[]}=l[t],b=(s&128)===128,w=Ub(y),m=w!==void 0?1:0,S=(o+(r!==void 0?1:0))*2+m,O=k.str("TapSighash").digest,C=[O,O,k.num(0,1),k.num(s,1),$a(u),_a(d)];if(!b){const P=l.map(B=>Cc(B));C.push(Bb(l),Ob(P),Ib(P),Tb(l))}if(((s&3)<2||(s&3)>3)&&C.push(Cb(f)),C.push(k.num(S,1)),b){const{value:P,scriptPubKey:B}=Cc(l[t]);C.push(ts(h),ns(p),pn(P),$e.encode(B,!0),rs(g))}else C.push(k.num(t,4).reverse());return w!==void 0&&C.push(w),(s&3)===3&&C.push(Pb(f[t])),r!==void 0&&C.push(k.bytes(r),k.num(i),k.num(a,4,"le")),k.join(C).digest}function Bb(e){const t=[];for(const{txid:n,vout:r}of e)t.push(ts(n)),t.push(ns(r));return k.join(t).digest}function Tb(e){const t=[];for(const{sequence:n}of e)t.push(rs(n));return k.join(t).digest}function Ob(e){const t=[];for(const{value:n}of e)t.push(pn(n));return k.join(t).digest}function Ib(e){const t=[];for(const{scriptPubKey:n}of e)t.push(Mn(n,!0));return k.join(t).digest}function Cb(e){const t=[];for(const{value:n,scriptPubKey:r}of e)t.push(pn(n)),t.push($e.encode(r,!0));return k.join(t).digest}function Pb(e){return k.join([pn(e.value),$e.encode(e.scriptPubKey,!0)]).digest}function Ub(e){if(e===void 0||e.length<2)return;let t=e.at(-1);if(typeof t=="string"&&(t=k.hex(t)),t instanceof Uint8Array&&t[0]===80)return k.raw(t).prefixSize("be").digest}function Cc(e){if(e.prevout===void 0)throw new Error("Prevout data missing for input: "+String(e.txid));return e.prevout}const Nb=0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2fn,Lb=0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141n;function Rb(e,t,n,r={}){const{sigflag:s=0}=r,o=Oa(t,n,r),i=Hb(e,o);return s===0?k.raw(i):k.join([i,s])}function Hb(e,t,n=k.random(32)){const r=k.bytes(t),s=new Ve(e),o=s.point,i=o.hasEvenY?s.big:s.negated.big,a=Cs("BIP0340/aux",k.bytes(n)),c=i^a.big,u=Cs("BIP0340/nonce",c,o.x.raw,r),l=new Ve(u),f=l.point,d=f.hasEvenY?l.big:l.negated.big,h=new Ve(Cs("BIP0340/challenge",f.x.raw,o.x.raw,r)),p=new Ve(d+h.big*i);return k.join([f.x.raw,p.raw])}function jb(e,t,n,r=!1){const s=Zn.from_x(Nn(n)),o=k.bytes(t),i=k.bytes(e).stream;i.size<64&&je("Signature length is too small: "+String(i.size),r);const a=i.read(32);a.big>Nb&&je("Signature r value greater than field size!",r);const c=i.read(32);c.big>Lb&&je("Signature s value greater than curve order!",r);const u=new Ve(Cs("BIP0340/challenge",a.raw,s.x.raw,o)),l=new Ve(c).point,f=s.mul(u.big),d=l.sub(f);return d.hasOddY&&je("Signature R value has odd Y coordinate!",r),d.x.big===0n&&je("Signature R value is infinite!",r),d.x.big===a.big}const Kb=192;function Eo(e){const t=k.str(e).digest;return k.join([t,t])}function Ia(e,t=Kb){return k.join([Eo("TapLeaf"),Zb(t),k.bytes(e)]).digest.hex}function Db(e,t){return Ia($e.fmt.toBytes(e),t)}function Ca(e,t){return t0){const[h,p,g]=Zs(r,i);c=g,a=er(e,h,n)}else i!==void 0?a=er(e,i,n):a=er(e,void 0,n);const u=n?Ci.getPublicKey(a)[0]:a[0],f=[k.num(s+ml(u)),o];c.length>0&&c.forEach(h=>f.push(k.hex(h)));const d=k.join(f);if(i!==void 0&&!Pa(a,i,d,t))throw new Error("Path checking failed! Unable to generate path.");return[Nn(a).hex,d.hex]}function Pa(e,t,n,r={}){const{isPrivate:s=!1,throws:o=!1}=r,{parity:i,paths:a,intkey:c}=gl(n),u=s?Ci.getPublicKey(e,!0):Nn(e),l=k.join([i,u]);if(l.length!==33)return je("Invalid tapkey: "+l.hex,o);let f=k.bytes(t).hex;for(const h of a)f=Ca(f,h);const d=er(c,f);return k.raw(d).hex===k.raw(l).hex}function gl(e){const t=new mr(k.bytes(e)),n=t.read(1).num,r=t.read(32),[s,o]=n%2===0?[n,2]:[n-1,3],i=[];for(;t.size>=32;)i.push(t.read(32).hex);if(t.size!==0)throw new Error("Non-empty buffer on control block: "+String(t));return{intkey:r,paths:i,parity:o,version:s}}function ml(e=2){if(e===0||e===1)return e;if(e===2||e==="02")return 0;if(e===3||e==="03")return 1;throw new Error("Invalid parity bit: "+String(e))}function Xb(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 je("Invalid witness data: "+String(i),s);const{scriptPubKey:d}=o??{};if(d===void 0)return je("Prevout scriptPubKey is empty!",s);const{type:h,data:p}=ie.util.readScriptPubKey(d);if(h!=="p2tr")return je("Prevout script is not a valid taproot output:"+p.hex,s);if(p.length!==32)return je("Invalid tapkey length: "+String(p.length),s);if(c!==null&&u!==null){const m=c[0]&254,v=Ia(u,m);if(n.extension=v,!Pa(p,v,c,{throws:s}))return je("cblock verification failed!",s)}n.pubkey!==void 0?f=k.bytes(n.pubkey):l.length>1&&l[1].length===32?f=k.bytes(l[1]):f=k.bytes(p);const g=$e.fmt.toParam(l[0]),y=new mr(g),b=y.read(64).raw;if(y.size===1&&(n.sigflag=y.read(1).num,n.sigflag===0))return je("0x00 is not a valid appended sigflag!",s);const w=Oa(r,t,n);return jb(b,w,f,s)?!0:je("Invalid signature!",s)}const Jb={hash:Oa,sign:Rb,verify:Xb},ko={segwit:_b,taproot:Jb},Qb={getTag:Eo,getLeaf:Ia,getBranch:Ca,getRoot:Mb},ew={readCtrlBlock:gl,readParityBit:ml},tw={getPubKey:Vb,getSecKey:qb,getTweak:ll,tweakSecKey:dl,tweakPubKey:hl},Vs={getPubKey:Yb,getSecKey:Wb,encodeScript:Db,checkPath:Pa,tree:Qb,tweak:tw,util:ew,SCRIPT_PUBKEY:Fb};var he;(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})(he||(he={}));var Pi;(function(e){e.mergeShapes=(t,n)=>({...t,...n})})(Pi||(Pi={}));const Z=he.arrayToEnum(["string","nan","number","integer","float","boolean","date","bigint","symbol","function","undefined","null","array","object","unknown","promise","void","never","map","set"]),an=e=>{switch(typeof e){case"undefined":return 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=he.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"]),nw=e=>JSON.stringify(e,null,2).replace(/"([^"]+)":/g,"$1:");class lt 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()}}lt.create=e=>new lt(e);const Hr=(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,he.jsonStringifyReplacer)}`;break;case R.unrecognized_keys:n=`Unrecognized key(s) in object: ${he.joinValues(e.keys,", ")}`;break;case R.invalid_union:n="Invalid input";break;case R.invalid_union_discriminator:n=`Invalid discriminator value. Expected ${he.joinValues(e.options)}`;break;case R.invalid_enum_value:n=`Invalid enum value. Expected ${he.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}"`:he.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,he.assertNever(e)}return{message:n}};let yl=Hr;function rw(e){yl=e}function qs(){return yl}const zs=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}},sw=[];function V(e,t){const n=zs({issueData:t,data:e.data,path:e.path,errorMaps:[e.common.contextualErrorMap,e.schemaErrorMap,qs(),Hr].filter(r=>!!r)});e.common.issues.push(n)}class Ze{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 Ze.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"}),bl=e=>({status:"dirty",value:e}),Fe=e=>({status:"valid",value:e}),Ui=e=>e.status==="aborted",Ni=e=>e.status==="dirty",Fs=e=>e.status==="valid",Gs=e=>typeof Promise<"u"&&e instanceof Promise;var G;(function(e){e.errToObj=t=>typeof t=="string"?{message:t}:t||{},e.toString=t=>typeof t=="string"?t:t==null?void 0:t.message})(G||(G={}));class At{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 Pc=(e,t)=>{if(Fs(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 lt(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 an(t.data)}_getOrReturnCtx(t,n){return n||{common:t.parent.common,data:t.data,parsedType:an(t.data),schemaErrorMap:this._def.errorMap,path:t.path,parent:t.parent}}_processInputParams(t){return{status:new Ze,ctx:{common:t.parent.common,data:t.data,parsedType:an(t.data),schemaErrorMap:this._def.errorMap,path:t.path,parent:t.parent}}}_parseSync(t){const n=this._parse(t);if(Gs(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:an(t)},o=this._parseSync({data:t,path:s.path,parent:s});return Pc(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:an(t)},s=this._parse({data:t,path:r.path,parent:r}),o=await(Gs(s)?s:Promise.resolve(s));return Pc(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 pt({schema:this,typeName:W.ZodEffects,effect:{type:"refinement",refinement:t}})}superRefine(t){return this._refinement(t)}optional(){return Ht.create(this,this._def)}nullable(){return Hn.create(this,this._def)}nullish(){return this.nullable().optional()}array(){return dt.create(this,this._def)}promise(){return ur.create(this,this._def)}or(t){return Mr.create([this,t],this._def)}and(t){return Zr.create(this,t,this._def)}transform(t){return new pt({...te(this._def),schema:this,typeName:W.ZodEffects,effect:{type:"transform",transform:t}})}default(t){const n=typeof t=="function"?t:()=>t;return new Gr({...te(this._def),innerType:this,defaultValue:n,typeName:W.ZodDefault})}brand(){return new xl({typeName:W.ZodBranded,type:this,...te(this._def)})}catch(t){const n=typeof t=="function"?t:()=>t;return new Js({...te(this._def),innerType:this,catchValue:n,typeName:W.ZodCatch})}describe(t){const n=this.constructor;return new n({...this._def,description:t})}pipe(t){return ss.create(this,t)}isOptional(){return this.safeParse(void 0).success}isNullable(){return this.safeParse(null).success}}const ow=/^c[^\s-]{8,}$/i,iw=/^[a-z][a-z0-9]*$/,aw=/[0-9A-HJKMNP-TV-Z]{26}/,cw=/^([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,uw=/^(([^<>()[\]\\.,;:\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,})+))$/,fw=new RegExp("^(\\p{Extended_Pictographic}|\\p{Emoji_Component})+$","u"),lw=/^(((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}))$/,dw=/^(([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})))$/,hw=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 pw(e,t){return!!((t==="v4"||!t)&&lw.test(e)||(t==="v6"||!t)&&dw.test(e))}class ut extends se{constructor(){super(...arguments),this._regex=(t,n,r)=>this.refinement(s=>t.test(s),{validation:n,code:R.invalid_string,...G.errToObj(r)}),this.nonempty=t=>this.min(1,G.errToObj(t)),this.trim=()=>new ut({...this._def,checks:[...this._def.checks,{kind:"trim"}]}),this.toLowerCase=()=>new ut({...this._def,checks:[...this._def.checks,{kind:"toLowerCase"}]}),this.toUpperCase=()=>new ut({...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 Ze;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,...G.errToObj(t==null?void 0:t.message)})}regex(t,n){return this._addCheck({kind:"regex",regex:t,...G.errToObj(n)})}includes(t,n){return this._addCheck({kind:"includes",value:t,position:n==null?void 0:n.position,...G.errToObj(n==null?void 0:n.message)})}startsWith(t,n){return this._addCheck({kind:"startsWith",value:t,...G.errToObj(n)})}endsWith(t,n){return this._addCheck({kind:"endsWith",value:t,...G.errToObj(n)})}min(t,n){return this._addCheck({kind:"min",value:t,...G.errToObj(n)})}max(t,n){return this._addCheck({kind:"max",value:t,...G.errToObj(n)})}length(t,n){return this._addCheck({kind:"length",value:t,...G.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 ut({checks:[],typeName:W.ZodString,coerce:(t=e==null?void 0:e.coerce)!==null&&t!==void 0?t:!1,...te(e)})};function gw(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 gn 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 Ze;for(const o of this._def.checks)o.kind==="int"?he.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"?gw(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()):he.assertNever(o);return{status:s.value,value:t.data}}gte(t,n){return this.setLimit("min",t,!0,G.toString(n))}gt(t,n){return this.setLimit("min",t,!1,G.toString(n))}lte(t,n){return this.setLimit("max",t,!0,G.toString(n))}lt(t,n){return this.setLimit("max",t,!1,G.toString(n))}setLimit(t,n,r,s){return new gn({...this._def,checks:[...this._def.checks,{kind:t,value:n,inclusive:r,message:G.toString(s)}]})}_addCheck(t){return new gn({...this._def,checks:[...this._def.checks,t]})}int(t){return this._addCheck({kind:"int",message:G.toString(t)})}positive(t){return this._addCheck({kind:"min",value:0,inclusive:!1,message:G.toString(t)})}negative(t){return this._addCheck({kind:"max",value:0,inclusive:!1,message:G.toString(t)})}nonpositive(t){return this._addCheck({kind:"max",value:0,inclusive:!0,message:G.toString(t)})}nonnegative(t){return this._addCheck({kind:"min",value:0,inclusive:!0,message:G.toString(t)})}multipleOf(t,n){return this._addCheck({kind:"multipleOf",value:t,message:G.toString(n)})}finite(t){return this._addCheck({kind:"finite",message:G.toString(t)})}safe(t){return this._addCheck({kind:"min",inclusive:!0,value:Number.MIN_SAFE_INTEGER,message:G.toString(t)})._addCheck({kind:"max",inclusive:!0,value:Number.MAX_SAFE_INTEGER,message:G.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"&&he.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 gn({checks:[],typeName:W.ZodNumber,coerce:(e==null?void 0:e.coerce)||!1,...te(e)});class mn 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 Ze;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()):he.assertNever(o);return{status:s.value,value:t.data}}gte(t,n){return this.setLimit("min",t,!0,G.toString(n))}gt(t,n){return this.setLimit("min",t,!1,G.toString(n))}lte(t,n){return this.setLimit("max",t,!0,G.toString(n))}lt(t,n){return this.setLimit("max",t,!1,G.toString(n))}setLimit(t,n,r,s){return new mn({...this._def,checks:[...this._def.checks,{kind:t,value:n,inclusive:r,message:G.toString(s)}]})}_addCheck(t){return new mn({...this._def,checks:[...this._def.checks,t]})}positive(t){return this._addCheck({kind:"min",value:BigInt(0),inclusive:!1,message:G.toString(t)})}negative(t){return this._addCheck({kind:"max",value:BigInt(0),inclusive:!1,message:G.toString(t)})}nonpositive(t){return this._addCheck({kind:"max",value:BigInt(0),inclusive:!0,message:G.toString(t)})}nonnegative(t){return this._addCheck({kind:"min",value:BigInt(0),inclusive:!0,message:G.toString(t)})}multipleOf(t,n){return this._addCheck({kind:"multipleOf",value:t,message:G.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 mn({checks:[],typeName:W.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 Fe(t.data)}}jr.create=e=>new jr({typeName:W.ZodBoolean,coerce:(e==null?void 0:e.coerce)||!1,...te(e)});class Ln 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 Ze;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()):he.assertNever(o);return{status:r.value,value:new Date(t.data.getTime())}}_addCheck(t){return new Ln({...this._def,checks:[...this._def.checks,t]})}min(t,n){return this._addCheck({kind:"min",value:t.getTime(),message:G.toString(n)})}max(t,n){return this._addCheck({kind:"max",value:t.getTime(),message:G.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 Ln({checks:[],coerce:(e==null?void 0:e.coerce)||!1,typeName:W.ZodDate,...te(e)});class Ws 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 Fe(t.data)}}Ws.create=e=>new Ws({typeName:W.ZodSymbol,...te(e)});class Kr 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 Fe(t.data)}}Kr.create=e=>new Kr({typeName:W.ZodUndefined,...te(e)});class Dr 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 Fe(t.data)}}Dr.create=e=>new Dr({typeName:W.ZodNull,...te(e)});class cr extends se{constructor(){super(...arguments),this._any=!0}_parse(t){return Fe(t.data)}}cr.create=e=>new cr({typeName:W.ZodAny,...te(e)});class Pn extends se{constructor(){super(...arguments),this._unknown=!0}_parse(t){return Fe(t.data)}}Pn.create=e=>new Pn({typeName:W.ZodUnknown,...te(e)});class Dt extends se{_parse(t){const n=this._getOrReturnCtx(t);return V(n,{code:R.invalid_type,expected:Z.never,received:n.parsedType}),J}}Dt.create=e=>new Dt({typeName:W.ZodNever,...te(e)});class Ys 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 Fe(t.data)}}Ys.create=e=>new Ys({typeName:W.ZodVoid,...te(e)});class dt 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 At(n,i,n.path,a)))).then(i=>Ze.mergeArray(r,i));const o=[...n.data].map((i,a)=>s.type._parseSync(new At(n,i,n.path,a)));return Ze.mergeArray(r,o)}get element(){return this._def.type}min(t,n){return new dt({...this._def,minLength:{value:t,message:G.toString(n)}})}max(t,n){return new dt({...this._def,maxLength:{value:t,message:G.toString(n)}})}length(t,n){return new dt({...this._def,exactLength:{value:t,message:G.toString(n)}})}nonempty(t){return this.min(1,t)}}dt.create=(e,t)=>new dt({type:e,minLength:null,maxLength:null,exactLength:null,typeName:W.ZodArray,...te(t)});function Jn(e){if(e instanceof Se){const t={};for(const n in e.shape){const r=e.shape[n];t[n]=Ht.create(Jn(r))}return new Se({...e._def,shape:()=>t})}else return e instanceof dt?new dt({...e._def,type:Jn(e.element)}):e instanceof Ht?Ht.create(Jn(e.unwrap())):e instanceof Hn?Hn.create(Jn(e.unwrap())):e instanceof Bt?Bt.create(e.items.map(t=>Jn(t))):e}class Se 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=he.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 Dt&&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 At(s,f,s.path,u)),alwaysSet:u in s.data})}if(this._def.catchall instanceof Dt){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 At(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=>Ze.mergeObjectSync(r,u)):Ze.mergeObjectSync(r,c)}get shape(){return this._def.shape()}strict(t){return new Se({...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=G.errToObj(t).message)!==null&&a!==void 0?a:c}:{message:c}}}:{}})}strip(){return new Se({...this._def,unknownKeys:"strip"})}passthrough(){return new Se({...this._def,unknownKeys:"passthrough"})}extend(t){return new Se({...this._def,shape:()=>({...this._def.shape(),...t})})}merge(t){return new Se({unknownKeys:t._def.unknownKeys,catchall:t._def.catchall,shape:()=>({...this._def.shape(),...t._def.shape()}),typeName:W.ZodObject})}setKey(t,n){return this.augment({[t]:n})}catchall(t){return new Se({...this._def,catchall:t})}pick(t){const n={};return he.objectKeys(t).forEach(r=>{t[r]&&this.shape[r]&&(n[r]=this.shape[r])}),new Se({...this._def,shape:()=>n})}omit(t){const n={};return he.objectKeys(this.shape).forEach(r=>{t[r]||(n[r]=this.shape[r])}),new Se({...this._def,shape:()=>n})}deepPartial(){return Jn(this)}partial(t){const n={};return he.objectKeys(this.shape).forEach(r=>{const s=this.shape[r];t&&!t[r]?n[r]=s:n[r]=s.optional()}),new Se({...this._def,shape:()=>n})}required(t){const n={};return he.objectKeys(this.shape).forEach(r=>{if(t&&!t[r])n[r]=this.shape[r];else{let o=this.shape[r];for(;o instanceof Ht;)o=o._def.innerType;n[r]=o}}),new Se({...this._def,shape:()=>n})}keyof(){return wl(he.objectKeys(this.shape))}}Se.create=(e,t)=>new Se({shape:()=>e,unknownKeys:"strip",catchall:Dt.create(),typeName:W.ZodObject,...te(t)});Se.strictCreate=(e,t)=>new Se({shape:()=>e,unknownKeys:"strict",catchall:Dt.create(),typeName:W.ZodObject,...te(t)});Se.lazycreate=(e,t)=>new Se({shape:e,unknownKeys:"strip",catchall:Dt.create(),typeName:W.ZodObject,...te(t)});class Mr 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 lt(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 lt(c));return V(n,{code:R.invalid_union,unionErrors:a}),J}}get options(){return this._def.options}}Mr.create=(e,t)=>new Mr({options:e,typeName:W.ZodUnion,...te(t)});const Ps=e=>e instanceof qr?Ps(e.schema):e instanceof pt?Ps(e.innerType()):e instanceof zr?[e.value]:e instanceof yn?e.options:e instanceof Fr?Object.keys(e.enum):e instanceof Gr?Ps(e._def.innerType):e instanceof Kr?[void 0]:e instanceof Dr?[null]:null;class So 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=Ps(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 So({typeName:W.ZodDiscriminatedUnion,discriminator:t,options:n,optionsMap:s,...te(r)})}}function Li(e,t){const n=an(e),r=an(t);if(e===t)return{valid:!0,data:e};if(n===Z.object&&r===Z.object){const s=he.objectKeys(t),o=he.objectKeys(e).filter(a=>s.indexOf(a)!==-1),i={...e,...t};for(const a of o){const c=Li(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(Ui(o)||Ui(i))return J;const a=Li(o.value,i.value);return a.valid?((Ni(o)||Ni(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}))}}Zr.create=(e,t,n)=>new Zr({left:e,right:t,typeName:W.ZodIntersection,...te(n)});class Bt 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 At(r,i,r.path,a)):null}).filter(i=>!!i);return r.common.async?Promise.all(o).then(i=>Ze.mergeArray(n,i)):Ze.mergeArray(n,o)}get items(){return this._def.items}rest(t){return new Bt({...this._def,rest:t})}}Bt.create=(e,t)=>{if(!Array.isArray(e))throw new Error("You must pass an array of schemas to z.tuple([ ... ])");return new Bt({items:e,typeName:W.ZodTuple,rest:null,...te(t)})};class Vr 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 At(r,a,r.path,a)),value:i._parse(new At(r,r.data[a],r.path,a))});return r.common.async?Ze.mergeObjectAsync(n,s):Ze.mergeObjectSync(n,s)}get element(){return this._def.valueType}static create(t,n,r){return n instanceof se?new Vr({keyType:t,valueType:n,typeName:W.ZodRecord,...te(r)}):new Vr({keyType:ut.create(),valueType:t,typeName:W.ZodRecord,...te(n)})}}class Xs 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 At(r,a,r.path,[u,"key"])),value:o._parse(new At(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}}}}Xs.create=(e,t,n)=>new Xs({valueType:t,keyType:e,typeName:W.ZodMap,...te(n)});class Rn 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 At(r,c,r.path,u)));return r.common.async?Promise.all(a).then(c=>i(c)):i(a)}min(t,n){return new Rn({...this._def,minSize:{value:t,message:G.toString(n)}})}max(t,n){return new Rn({...this._def,maxSize:{value:t,message:G.toString(n)}})}size(t,n){return this.min(t,n).max(t,n)}nonempty(t){return this.min(1,t)}}Rn.create=(e,t)=>new Rn({valueType:e,minSize:null,maxSize:null,typeName:W.ZodSet,...te(t)});class tr 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 zs({data:a,path:n.path,errorMaps:[n.common.contextualErrorMap,n.schemaErrorMap,qs(),Hr].filter(u=>!!u),issueData:{code:R.invalid_arguments,argumentsError:c}})}function s(a,c){return zs({data:a,path:n.path,errorMaps:[n.common.contextualErrorMap,n.schemaErrorMap,qs(),Hr].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 ur?Fe(async(...a)=>{const c=new lt([]),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})}):Fe((...a)=>{const c=this._def.args.safeParse(a,o);if(!c.success)throw new lt([r(a,c.error)]);const u=i(...c.data),l=this._def.returns.safeParse(u,o);if(!l.success)throw new lt([s(u,l.error)]);return l.data})}parameters(){return this._def.args}returnType(){return this._def.returns}args(...t){return new tr({...this._def,args:Bt.create(t).rest(Pn.create())})}returns(t){return new tr({...this._def,returns:t})}implement(t){return this.parse(t)}strictImplement(t){return this.parse(t)}static create(t,n,r){return new tr({args:t||Bt.create([]).rest(Pn.create()),returns:n||Pn.create(),typeName:W.ZodFunction,...te(r)})}}class qr 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})}}qr.create=(e,t)=>new qr({getter:e,typeName:W.ZodLazy,...te(t)});class zr 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}}zr.create=(e,t)=>new zr({value:e,typeName:W.ZodLiteral,...te(t)});function wl(e,t){return new yn({values:e,typeName:W.ZodEnum,...te(t)})}class yn extends se{_parse(t){if(typeof t.data!="string"){const n=this._getOrReturnCtx(t),r=this._def.values;return V(n,{expected:he.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 Fe(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 yn.create(t)}exclude(t){return yn.create(this.options.filter(n=>!t.includes(n)))}}yn.create=wl;class Fr extends se{_parse(t){const n=he.getValidEnumValues(this._def.values),r=this._getOrReturnCtx(t);if(r.parsedType!==Z.string&&r.parsedType!==Z.number){const s=he.objectValues(n);return V(r,{expected:he.joinValues(s),received:r.parsedType,code:R.invalid_type}),J}if(n.indexOf(t.data)===-1){const s=he.objectValues(n);return V(r,{received:r.data,code:R.invalid_enum_value,options:s}),J}return Fe(t.data)}get enum(){return this._def.values}}Fr.create=(e,t)=>new Fr({values:e,typeName:W.ZodNativeEnum,...te(t)});class ur 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 Fe(r.then(s=>this._def.type.parseAsync(s,{path:n.path,errorMap:n.common.contextualErrorMap})))}}ur.create=(e,t)=>new ur({type:e,typeName:W.ZodPromise,...te(t)});class pt extends se{innerType(){return this._def.schema}sourceType(){return this._def.schema._def.typeName===W.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(!Fs(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=>Fs(i)?Promise.resolve(s.transform(i.value,o)).then(a=>({status:n.value,value:a})):i);he.assertNever(s)}}pt.create=(e,t,n)=>new pt({schema:e,typeName:W.ZodEffects,effect:t,...te(n)});pt.createWithPreprocess=(e,t,n)=>new pt({schema:t,effect:{type:"preprocess",transform:e},typeName:W.ZodEffects,...te(n)});class Ht extends se{_parse(t){return this._getType(t)===Z.undefined?Fe(void 0):this._def.innerType._parse(t)}unwrap(){return this._def.innerType}}Ht.create=(e,t)=>new Ht({innerType:e,typeName:W.ZodOptional,...te(t)});class Hn extends se{_parse(t){return this._getType(t)===Z.null?Fe(null):this._def.innerType._parse(t)}unwrap(){return this._def.innerType}}Hn.create=(e,t)=>new Hn({innerType:e,typeName:W.ZodNullable,...te(t)});class Gr 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}}Gr.create=(e,t)=>new Gr({innerType:e,typeName:W.ZodDefault,defaultValue:typeof t.default=="function"?t.default:()=>t.default,...te(t)});class Js 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 Gs(s)?s.then(o=>({status:"valid",value:o.status==="valid"?o.value:this._def.catchValue({get error(){return new lt(r.common.issues)},input:r.data})})):{status:"valid",value:s.status==="valid"?s.value:this._def.catchValue({get error(){return new lt(r.common.issues)},input:r.data})}}removeCatch(){return this._def.innerType}}Js.create=(e,t)=>new Js({innerType:e,typeName:W.ZodCatch,catchValue:typeof t.catch=="function"?t.catch:()=>t.catch,...te(t)});class Qs 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}}}Qs.create=e=>new Qs({typeName:W.ZodNaN,...te(e)});const mw=Symbol("zod_brand");class xl 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 ss 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(),bl(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 ss({in:t,out:n,typeName:W.ZodPipeline})}}const vl=(e,t={},n)=>e?cr.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})}}):cr.create(),yw={object:Se.lazycreate};var W;(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"})(W||(W={}));const bw=(e,t={message:`Input not instance of ${e.name}`})=>vl(n=>n instanceof e,t),El=ut.create,kl=gn.create,ww=Qs.create,xw=mn.create,Sl=jr.create,vw=Ln.create,Ew=Ws.create,kw=Kr.create,Sw=Dr.create,$w=cr.create,_w=Pn.create,Aw=Dt.create,Bw=Ys.create,Tw=dt.create,Ow=Se.create,Iw=Se.strictCreate,Cw=Mr.create,Pw=So.create,Uw=Zr.create,Nw=Bt.create,Lw=Vr.create,Rw=Xs.create,Hw=Rn.create,jw=tr.create,Kw=qr.create,Dw=zr.create,Mw=yn.create,Zw=Fr.create,Vw=ur.create,Uc=pt.create,qw=Ht.create,zw=Hn.create,Fw=pt.createWithPreprocess,Gw=ss.create,Ww=()=>El().optional(),Yw=()=>kl().optional(),Xw=()=>Sl().optional(),Jw={string:(e=>ut.create({...e,coerce:!0})),number:(e=>gn.create({...e,coerce:!0})),boolean:(e=>jr.create({...e,coerce:!0})),bigint:(e=>mn.create({...e,coerce:!0})),date:(e=>Ln.create({...e,coerce:!0}))},Qw=J;var ze=Object.freeze({__proto__:null,defaultErrorMap:Hr,setErrorMap:rw,getErrorMap:qs,makeIssue:zs,EMPTY_PATH:sw,addIssueToContext:V,ParseStatus:Ze,INVALID:J,DIRTY:bl,OK:Fe,isAborted:Ui,isDirty:Ni,isValid:Fs,isAsync:Gs,get util(){return he},get objectUtil(){return Pi},ZodParsedType:Z,getParsedType:an,ZodType:se,ZodString:ut,ZodNumber:gn,ZodBigInt:mn,ZodBoolean:jr,ZodDate:Ln,ZodSymbol:Ws,ZodUndefined:Kr,ZodNull:Dr,ZodAny:cr,ZodUnknown:Pn,ZodNever:Dt,ZodVoid:Ys,ZodArray:dt,ZodObject:Se,ZodUnion:Mr,ZodDiscriminatedUnion:So,ZodIntersection:Zr,ZodTuple:Bt,ZodRecord:Vr,ZodMap:Xs,ZodSet:Rn,ZodFunction:tr,ZodLazy:qr,ZodLiteral:zr,ZodEnum:yn,ZodNativeEnum:Fr,ZodPromise:ur,ZodEffects:pt,ZodTransformer:pt,ZodOptional:Ht,ZodNullable:Hn,ZodDefault:Gr,ZodCatch:Js,ZodNaN:Qs,BRAND:mw,ZodBranded:xl,ZodPipeline:ss,custom:vl,Schema:se,ZodSchema:se,late:yw,get ZodFirstPartyTypeKind(){return W},coerce:Jw,any:$w,array:Tw,bigint:xw,boolean:Sl,date:vw,discriminatedUnion:Pw,effect:Uc,enum:Mw,function:jw,instanceof:bw,intersection:Uw,lazy:Kw,literal:Dw,map:Rw,nan:ww,nativeEnum:Zw,never:Aw,null:Sw,nullable:zw,number:kl,object:Ow,oboolean:Xw,onumber:Yw,optional:qw,ostring:Ww,pipeline:Gw,preprocess:Fw,promise:Vw,record:Lw,set:Hw,strictObject:Iw,string:El,symbol:Ew,transformer:Uc,tuple:Nw,undefined:kw,union:Cw,unknown:_w,void:Bw,NEVER:Qw,ZodIssueCode:R,quotelessJson:nw,ZodError:lt});const $l=ze.string().regex(/^[a-fA-F0-9]$/),e1=ze.string().regex(/^[a-fA-F0-9]{64}$/),fr=ze.number().min(0).max(4294967295),t1=ze.bigint(),_l=ze.instanceof(Uint8Array),n1=ze.union([$l,fr,ze.string(),_l]).array(),Ua=ze.union([n1,$l,_l]),r1=ze.array(Ua),Al=ze.object({value:ze.union([fr,t1]),scriptPubKey:Ua}),s1=ze.object({txid:e1,vout:fr,scriptSig:Ua,sequence:fr,prevout:Al.optional(),witness:r1});ze.object({version:fr,vin:ze.array(s1),vout:ze.array(Al),locktime:fr});const Ri=2048,o1=new TextEncoder;function Bl(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=o1.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>Ri)throw new Error(`Metadata must be at most ${Ri} CBOR bytes.`)};return r(e),Uint8Array.from(t)}function i1(e){if(e=new Uint8Array(e),!e.length||e.length>Ri)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}}),Ue=(e,t)=>({value:e,scriptPubKey:t}),Nc=16*1024,Et=1e3,fe=500,eo="text/plain;charset=utf-8",a1=["text/plain","application/json","text/html","image/svg+xml","image/png","image/jpeg","image/webp"],Tl=new TextEncoder,Cr=e=>Array.from(e,t=>t.toString(16).padStart(2,"0")).join(""),Sn=e=>Uint8Array.from(e.match(/../g)??[],t=>parseInt(t,16)),to=e=>Cr(Tl.encode(e));function Na(e){const t=typeof e=="string"?{contentType:eo,bytes:Tl.encode(e)}:e;if(!t||![...a1,eo].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>Nc)throw new Error(`Body must be at most ${Nc} bytes.`);return{contentType:t.contentType,bytes:new Uint8Array(t.bytes)}}function no(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 Lc(e){if(typeof e!="string"||!/^[0-9a-f]{64,72}$/.test(e)||e.length%2)throw new Error("Invalid parent tag.");const t=[...Sn(e.slice(64))].reduce((r,s,o)=>r+s*256**o,0),n=`${e.slice(0,64).match(/../g).reverse().join("")}i${t}`;if(no(n)!==e)throw new Error("Non-canonical parent tag.");return n}function Ol(e,t,n=null,r=void 0,s={}){const{contentType:o,bytes:i}=Na(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:Bl(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(to("ord"))+h("01")+h(to(o))+(a?h("0b")+h(no(a)):"")+(c===void 0?"":h("02")+h(Il(c)))+(n?h("03")+h(no(n)):"")+(f===void 0?"":Array.from({length:Math.ceil(f.length/520)},(p,g)=>h("05")+h(Cr(f.slice(g*520,(g+1)*520)))).join(""))+(l?h("07")+h(Cr(l)):"")+"00"+d.map(h).join("")+"68"}function La(e){if(!Array.isArray(e)||e.length!==3)throw new Error("Unsupported script-path witness.");const t=$e.decode(e[1]);let n=7,r=null,s=null,o;t[n]==="0b"&&(s=Lc(t[n+1]),n+=2),t[n]==="02"&&(o=u1(t[n+1]==="OP_0"?"":t[n+1]),n+=2),t[n]==="03"&&(r=Lc(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?i1(Sn(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(Sn(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(Sn(t[6])),f=Na({contentType:l,bytes:Sn(u.join(""))}),d=Ol(t[0],f,r,a,{delegate:s,pointer:o,metaprotocol:c}),h=a===void 0&&!r&&l===eo&&f.bytes.length<=280&&$e.encode([t[0],"OP_CHECKSIG","OP_0","OP_IF",to("ord"),"01",to(eo),"OP_0",Cr(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?Sn(i.join("")):void 0,text:new TextDecoder().decode(f.bytes),pubkey:t[0]}}class c1{constructor(t,n){this.chain=t,this.wallet=n}prepare(t,n=null,r=void 0,s={}){const o=Na(t);if(r!==void 0&&Bl(r),s.delegate&&no(s.delegate),s.pointer!==void 0&&Il(s.pointer),s.metaprotocol!==void 0&&s.metaprotocol!==null&&s.metaprotocol!==""&&new TextEncoder().encode(String(s.metaprotocol)).length>520)throw new Error("Metaprotocol identifier must be 520 bytes or less.");if(n&&s.reinscribe)throw new Error("Choose parent or reinscription, not both.");const i=this.chain.coins(this.wallet.script),a=n?i.find(l=>{var f;return(f=l.inscriptions)==null?void 0:f.some(d=>d.id===n)}):null;if(n&&!a)throw new Error("Parent must be an owned, unspent inscription.");const c=s.reinscribe?i.find(l=>{var f;return(f=l.inscriptions)==null?void 0:f.some(d=>d.id===s.reinscribe)}):null;if(s.reinscribe&&!c)throw new Error("Reinscription must spend an owned sat.");const u=i.find(l=>!l.inscription&&l.value>=Et+2*fe+330);if(!u)throw new Error("Mine a block first to get spendable fake BTC.");return{...o,coin:u,parent:a,reinscribe:c,totalFee:fe*2,postage:Et}}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=Ol(this.wallet.pubkey,c,n,r,{...s,pointer:f}),h=Vs.encodeScript(d),[p,g]=Vs.getPubKey(this.wallet.pubkey,{target:h}),y=ie.create({vin:[jt(o.txid,o.vout,o.value,o.scriptPubKey)],vout:[Ue(Et+fe,["OP_1",p]),Ue(o.value-Et-2*fe,this.wallet.script)]});y.vin[0].witness=[this.wallet.sign(y)];const b=ie.util.getTxid(y),w=ie.create({vin:[...u?[jt(u.txid,u.vout,u.value,u.scriptPubKey)]:[],jt(b,0,Et+fe,["OP_1",p])],vout:[...u?[Ue(u.value,this.wallet.script)]:[],Ue(Et,this.wallet.script)]}),m=u?1:0;return w.vin[m].witness=[this.wallet.sign(w,h,m),$e.encode(d,!1).hex,g],u&&(w.vin[0].witness=[this.wallet.sign(w)]),this.chain.submitPackage([ie.encode(y).hex,ie.encode(w).hex]),`${ie.util.getTxid(w)}i0`}list(){return this.chain.coins(this.wallet.script).flatMap(t=>t.inscriptions??[])}}function Il(e){let t;try{t=BigInt(e)}catch{throw new Error("Invalid pointer.")}if(t<0n||t>0xffffffffffffffffn||typeof e=="number"&&!Number.isSafeInteger(e))throw new Error("Invalid pointer.");let n="";for(;t;)n+=Number(t&255n).toString(16).padStart(2,"0"),t>>=8n;return n}function u1(e){if(typeof e!="string"||!/^(?:[0-9a-f]{2}){0,8}$/.test(e))throw new Error("Invalid pointer tag.");return[...Sn(e)].reduce((t,n,r)=>t+(BigInt(n)<{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}`)),l=Eu(i,u,s,c);i.vin.forEach(w=>this.utxos.delete(`${w.txid}:${w.vout}`)),i.vout.forEach((w,m)=>this.utxos.set(`${a}:${m}`,{txid:a,vout:m,value:Number(w.value),ranges:l[m]}));const f=(b=i.vin.find(w=>{var m;return((m=w.witness)==null?void 0:m.length)===3}))==null?void 0:b.witness;if(!f)return;const d=La(f),h=BigInt(d.pointer??0),p=i.vout.reduce((w,m)=>w+Number(m.value),0),g=vu(l.flat(),hw.sat===g).length,status:s===null?"pending":"confirmed",height:s,block:o,metadata:y??null,hasMetadata:y!==void 0,parent:d.parent,protocol:d.metaprotocol??(y&&!Array.isArray(y)&&typeof y=="object"&&Object.hasOwn(y,"protocol")&&typeof y.protocol=="string"?y.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=Is(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 Ra="lineage/v0",f1=["white","green","black"],Xo="names are 1-40 lowercase letters, digits or hyphens (they become domains)",l1=/^[a-z0-9](?:[a-z0-9-]{0,38}[a-z0-9])?$/,ys=e=>typeof e=="string"&&l1.test(e),Ir=(e,t)=>typeof e=="string"?e.trim().slice(0,t):"";function $o(e){return String(e??"").toLowerCase().normalize("NFKD").replace(/[̀-ͯ]/g,"").replace(/[^a-z0-9]+/g,"-").replace(/^-+|-+$/g,"").slice(0,40).replace(/-+$/,"")}const _o=e=>e.events.filter(t=>t.protocol===Ra);function bn(e,{upTo:t=1/0,pending:n=!1}={}){const r=new Map,s=[],o=[],i=new Map,a=c=>c.status==="active";for(const c of e){const u=c.status==="confirmed";if(u?c.height>t:!n)continue;const l=c.metadata&&typeof c.metadata=="object"&&!Array.isArray(c.metadata)?c.metadata:{},f={id:c.id,op:typeof l.op=="string"?l.op.slice(0,20):"?",beat:u?c.height:null,pending:!u,meta:l,parent:c.parent??null,ok:!0,why:"",node:null,root:null,also:[]},d=f.parent?r.get(f.parent):null,h=f.beat??"cued",p=w=>{f.ok=!1,f.why=w},g=w=>d?a(d)?"":`the ${w} is ${d.status}`:`the ${w} is not in this lineage`;let y="";switch(f.op){case"found":if(f.parent)p("a holding has no parent");else if(!ys(l.name))p(Xo);else if(s.some(w=>a(w)&&w.name===l.name))p(`an active holding is already named ${l.name}`);else{const w=Rc(c,l.name,null,"holding");r.set(w.id,w),s.push(w),f.node=w.id}break;case"birth":{const w=l.kind==="agent"?"agent":"org";if(y=g("parent"))p(y);else if(d.kind==="agent")p("agents do not give birth");else if(!ys(l.name))p(Xo);else if(d.children.some(m=>a(r.get(m))&&r.get(m).name===l.name))p(`${d.name} already has an active ${l.name}`);else{const m=Rc(c,l.name,d,w);m.index=d.children.filter(v=>r.get(v).kind===w).length,d.children.push(m.id),r.set(m.id,m),f.node=m.id}break}case"award":{const w=r.get(l.to);(y=g("issuer"))?p(y):d.kind==="agent"?p("agents do not award belts"):!w||w.id===d.id?p("the recipient must be another node in this lineage"):a(w)?!ys(l.skill)||!f1.includes(l.belt)?p("an award needs a skill name and a belt (white, green or black)"):(w.badges=w.badges.filter(m=>m.skill!==l.skill),w.badges.push({skill:l.skill,belt:l.belt,by:d.id,beat:h,id:c.id}),f.node=w.id):p(`the recipient is ${w.status}`);break}case"decide":(y=g("decider"))?p(y):Ir(l.title,140)?(d.decisions.push({title:Ir(l.title,140),why:Ir(l.why,400),beat:h,id:c.id}),f.node=d.id):p("a decision needs a title");break;case"make":(y=g("maker"))?p(y):ys(l.name)?d.made.some(w=>i.get(w).name===l.name)?p(`there is already a ${l.name} by ${d.name}`):(i.set(c.id,{id:c.id,name:l.name,note:Ir(l.note,280),maker:d.id,beat:h}),d.made.push(c.id),f.node=d.id):p(Xo);break;case"graduate":{const w=r.get(l.of);if(y=g("parent"))p(y);else if(!w||w.parent!==d.id)p("only its parent can graduate a child");else if(w.kind!=="org")p("only orgs graduate");else if(!a(w))p(`the child is ${w.status}`);else if(w.edge==="adopted")p("already graduated");else{const m=w.root,v=S=>{S.root=w.id;for(const O of S.children)r.get(O).root===m&&v(r.get(O))};w.edge="adopted",w.graduated=h,f.node=w.id,v(w),s.push(w)}break}case"close":if(!d)p(f.parent?"that node is not in this lineage":"a close spends the node it closes");else if(!a(d))p(`already ${d.status}`);else{const w=m=>{m.status="closed",m.closed=h;for(const v of m.children){const S=r.get(v);S.edge==="derived"&&a(S)&&(f.also.push(S.id),w(S))}};w(d),f.node=d.id}break;default:p("not a lineage/v0 op")}const b=f.node?r.get(f.node).root:null;f.root=(d==null?void 0:d.root)??b,f.roots=[...new Set([f.root,b].filter(Boolean))],o.push(f)}return{nodes:r,roots:s,log:o,items:i}}function Rc(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:[],graduated:null,closed:null}}function d1(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((y,b)=>{const w=b===d.length-1;s(y,g+(w?"└─ ":"├─ "),g+(w?" ":"│ "))})})};return r&&s(r,"",""),n}function h1(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 lr(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 Cl(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 “${Ir(n.title,140)}” · ${r(e.parent)}`;case"make":return`make ${n.name} · ${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 Gn=typeof globalThis=="object"&&"crypto"in globalThis?globalThis.crypto:void 0;/*! noble-hashes - MIT License (c) 2022 Paul Miller (paulmillr.com) */function is(e){return e instanceof Uint8Array||ArrayBuffer.isView(e)&&e.constructor.name==="Uint8Array"}function dn(e){if(!Number.isSafeInteger(e)||e<0)throw new Error("positive integer expected, got "+e)}function De(e,...t){if(!is(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 as(e){if(typeof e!="function"||typeof e.create!="function")throw new Error("Hash should be wrapped by utils.createHasher");dn(e.outputLen),dn(e.blockLen)}function ro(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 p1(e,t){De(e);const n=t.outputLen;if(e.length>>t}function bs(e,t){return e<>>32-t>>>0}const Pl=typeof Uint8Array.from([]).toHex=="function"&&typeof Uint8Array.fromHex=="function",g1=Array.from({length:256},(e,t)=>t.toString(16).padStart(2,"0"));function Me(e){if(De(e),Pl)return e.toHex();let t="";for(let n=0;n=Ut._0&&e<=Ut._9)return e-Ut._0;if(e>=Ut.A&&e<=Ut.F)return e-(Ut.A-10);if(e>=Ut.a&&e<=Ut.f)return e-(Ut.a-10)}function gt(e){if(typeof e!="string")throw new Error("hex string expected, got "+typeof e);if(Pl)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(Wr(r)).digest(),n=e();return t.outputLen=n.outputLen,t.blockLen=n.blockLen,t.create=()=>e(),t}function qn(e=32){if(Gn&&typeof Gn.getRandomValues=="function")return Gn.getRandomValues(new Uint8Array(e));if(Gn&&typeof Gn.randomBytes=="function")return Uint8Array.from(Gn.randomBytes(e));throw new Error("crypto.getRandomValues must be defined")}function y1(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 b1(e,t,n){return e&t^~e&n}function w1(e,t,n){return e&t^e&n^t&n}class ja extends Ul{constructor(t,n,r,s){super(),this.finished=!1,this.length=0,this.pos=0,this.destroyed=!1,this.blockLen=t,this.outputLen=n,this.padOffset=r,this.isLE=s,this.buffer=new Uint8Array(t),this.view=Un(this.buffer)}update(t){ro(this),t=Wr(t),De(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>Kc&ws)}:{h:Number(e>>Kc&ws)|0,l:Number(e&ws)|0}}function v1(e,t=!1){const n=e.length;let r=new Uint32Array(n),s=new Uint32Array(n);for(let o=0;oe>>>n,Mc=(e,t,n)=>e<<32-n|t>>>n,Wn=(e,t,n)=>e>>>n|t<<32-n,Yn=(e,t,n)=>e<<32-n|t>>>n,xs=(e,t,n)=>e<<64-n|t>>>n-32,vs=(e,t,n)=>e>>>n-32|t<<64-n;function Nt(e,t,n,r){const s=(t>>>0)+(r>>>0);return{h:e+n+(s/2**32|0)|0,l:s|0}}const E1=(e,t,n)=>(e>>>0)+(t>>>0)+(n>>>0),k1=(e,t,n,r)=>t+n+r+(e/2**32|0)|0,S1=(e,t,n,r)=>(e>>>0)+(t>>>0)+(n>>>0)+(r>>>0),$1=(e,t,n,r,s)=>t+n+r+s+(e/2**32|0)|0,_1=(e,t,n,r,s)=>(e>>>0)+(t>>>0)+(n>>>0)+(r>>>0)+(s>>>0),A1=(e,t,n,r,s,o)=>t+n+r+s+o+(e/2**32|0)|0,B1=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]),en=new Uint32Array(64);class T1 extends ja{constructor(t=32){super(64,t,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 f=0;f<16;f++,n+=4)en[f]=t.getUint32(n,!1);for(let f=16;f<64;f++){const d=en[f-15],h=en[f-2],p=vt(d,7)^vt(d,18)^d>>>3,g=vt(h,17)^vt(h,19)^h>>>10;en[f]=g+en[f-7]+p+en[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=vt(a,6)^vt(a,11)^vt(a,25),h=l+d+b1(a,c,u)+B1[f]+en[f]|0,g=(vt(r,2)^vt(r,13)^vt(r,22))+w1(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(){Tt(en)}destroy(){this.set(0,0,0,0,0,0,0,0),Tt(this.buffer)}}const Nl=v1(["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))),O1=Nl[0],I1=Nl[1],tn=new Uint32Array(80),nn=new Uint32Array(80);class C1 extends ja{constructor(t=64){super(128,t,16,!1),this.Ah=He[0]|0,this.Al=He[1]|0,this.Bh=He[2]|0,this.Bl=He[3]|0,this.Ch=He[4]|0,this.Cl=He[5]|0,this.Dh=He[6]|0,this.Dl=He[7]|0,this.Eh=He[8]|0,this.El=He[9]|0,this.Fh=He[10]|0,this.Fl=He[11]|0,this.Gh=He[12]|0,this.Gl=He[13]|0,this.Hh=He[14]|0,this.Hl=He[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:y}=this;return[t,n,r,s,o,i,a,c,u,l,f,d,h,p,g,y]}set(t,n,r,s,o,i,a,c,u,l,f,d,h,p,g,y){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=y|0}process(t,n){for(let m=0;m<16;m++,n+=4)tn[m]=t.getUint32(n),nn[m]=t.getUint32(n+=4);for(let m=16;m<80;m++){const v=tn[m-15]|0,S=nn[m-15]|0,O=Wn(v,S,1)^Wn(v,S,8)^Dc(v,S,7),C=Yn(v,S,1)^Yn(v,S,8)^Mc(v,S,7),P=tn[m-2]|0,B=nn[m-2]|0,N=Wn(P,B,19)^xs(P,B,61)^Dc(P,B,6),H=Yn(P,B,19)^vs(P,B,61)^Mc(P,B,6),K=S1(C,H,nn[m-7],nn[m-16]),E=$1(K,O,N,tn[m-7],tn[m-16]);tn[m]=E|0,nn[m]=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:y,Hh:b,Hl:w}=this;for(let m=0;m<80;m++){const v=Wn(f,d,14)^Wn(f,d,18)^xs(f,d,41),S=Yn(f,d,14)^Yn(f,d,18)^vs(f,d,41),O=f&h^~f&g,C=d&p^~d&y,P=_1(w,S,C,I1[m],nn[m]),B=A1(P,b,v,O,O1[m],tn[m]),N=P|0,H=Wn(r,s,28)^xs(r,s,34)^xs(r,s,39),K=Yn(r,s,28)^vs(r,s,34)^vs(r,s,39),E=r&o^r&a^o&a,$=s&i^s&c^i&c;b=g|0,w=y|0,g=h|0,y=p|0,h=f|0,p=d|0,{h:f,l:d}=Nt(u|0,l|0,B|0,N|0),u=a|0,l=c|0,a=o|0,c=i|0,o=r|0,i=s|0;const x=E1(N,K,$);r=k1(x,B,H,E),s=x|0}({h:r,l:s}=Nt(this.Ah|0,this.Al|0,r|0,s|0)),{h:o,l:i}=Nt(this.Bh|0,this.Bl|0,o|0,i|0),{h:a,l:c}=Nt(this.Ch|0,this.Cl|0,a|0,c|0),{h:u,l}=Nt(this.Dh|0,this.Dl|0,u|0,l|0),{h:f,l:d}=Nt(this.Eh|0,this.El|0,f|0,d|0),{h,l:p}=Nt(this.Fh|0,this.Fl|0,h|0,p|0),{h:g,l:y}=Nt(this.Gh|0,this.Gl|0,g|0,y|0),{h:b,l:w}=Nt(this.Hh|0,this.Hl|0,b|0,w|0),this.set(r,s,o,i,a,c,u,l,f,d,h,p,g,y,b,w)}roundClean(){Tt(tn,nn)}destroy(){Tt(this.buffer),this.set(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0)}}const st=Ha(()=>new T1),Yr=Ha(()=>new C1),P1=Uint8Array.from([7,4,13,1,10,6,15,3,12,0,9,5,2,14,11,8]),Ll=Uint8Array.from(new Array(16).fill(0).map((e,t)=>t)),U1=Ll.map(e=>(9*e+5)%16),Rl=(()=>{const n=[[Ll],[U1]];for(let r=0;r<4;r++)for(let s of n)s.push(s[r].map(o=>P1[o]));return n})(),Hl=Rl[0],jl=Rl[1],Kl=[[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)),N1=Hl.map((e,t)=>e.map(n=>Kl[t][n])),L1=jl.map((e,t)=>e.map(n=>Kl[t][n])),R1=Uint32Array.from([0,1518500249,1859775393,2400959708,2840853838]),H1=Uint32Array.from([1352829926,1548603684,1836072691,2053994217,0]);function Zc(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 Es=new Uint32Array(16);class j1 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 h=0;h<16;h++,n+=4)Es[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=R1[h],y=H1[h],b=Hl[h],w=jl[h],m=N1[h],v=L1[h];for(let S=0;S<16;S++){const O=bs(r+Zc(h,o,a,u)+Es[b[S]]+g,m[S])+f|0;r=f,f=u,u=bs(a,10)|0,a=o,o=O}for(let S=0;S<16;S++){const O=bs(s+Zc(p,i,c,l)+Es[w[S]]+y,v[S])+d|0;s=d,d=l,l=bs(c,10)|0,c=i,i=O}}this.set(this.h1+a+l|0,this.h2+u+d|0,this.h3+f+s|0,this.h4+r+i|0,this.h0+o+c|0)}roundClean(){Tt(Es)}destroy(){this.destroyed=!0,Tt(this.buffer),this.set(0,0,0,0,0)}}const Dl=Ha(()=>new j1);class Ml extends Ul{constructor(t,n){super(),this.finished=!1,this.destroyed=!1,as(t);const r=Wr(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 Ml(e,t).update(n).digest();wn.create=(e,t)=>new Ml(e,t);/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */const Ka=BigInt(0),Hi=BigInt(1);function jn(e,t=""){if(typeof e!="boolean"){const n=t&&`"${t}"`;throw new Error(n+"expected boolean, got type="+typeof e)}return e}function ft(e,t,n=""){const r=is(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 Zl(e){if(typeof e!="string")throw new Error("hex string expected, got "+typeof e);return e===""?Ka:BigInt("0x"+e)}function br(e){return Zl(Me(e))}function Kn(e){return De(e),Zl(Me(Uint8Array.from(e).reverse()))}function Ao(e,t){return gt(e.toString(16).padStart(t*2,"0"))}function Da(e,t){return Ao(e,t).reverse()}function ge(e,t,n){let r;if(typeof t=="string")try{r=gt(t)}catch(o){throw new Error(e+" must be hex string or Uint8Array, cause: "+o)}else if(is(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 Vc(e){return Uint8Array.from(e)}const Jo=e=>typeof e=="bigint"&&Ka<=e;function ji(e,t,n){return Jo(e)&&Jo(t)&&Jo(n)&&t<=e&&eKa;e>>=Hi,t+=1);return t}const cs=e=>(Hi<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 wr(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 Ye=BigInt(0),Re=BigInt(1),Tn=BigInt(2),ql=BigInt(3),zl=BigInt(4),Fl=BigInt(5),D1=BigInt(7),Gl=BigInt(8),M1=BigInt(9),Wl=BigInt(16);function xe(e,t){const n=e%t;return n>=Ye?n:t+n}function ke(e,t,n){let r=e;for(;t-- >Ye;)r*=r,r%=n;return r}function qc(e,t){if(e===Ye)throw new Error("invert: expected non-zero number");if(t<=Ye)throw new Error("invert: expected positive modulus, got "+t);let n=xe(e,t),r=t,s=Ye,o=Re;for(;n!==Ye;){const a=r/n,c=r%n,u=s-o*a;r=n,n=c,s=o,o=u}if(r!==Re)throw new Error("invert: does not exist");return xe(s,t)}function Ma(e,t,n){if(!e.eql(e.sqr(t),n))throw new Error("Cannot find square root")}function Yl(e,t){const n=(e.ORDER+Re)/zl,r=e.pow(t,n);return Ma(e,r,t),r}function Z1(e,t){const n=(e.ORDER-Fl)/Gl,r=e.mul(t,Tn),s=e.pow(r,n),o=e.mul(t,s),i=e.mul(e.mul(o,Tn),s),a=e.mul(o,e.sub(i,e.ONE));return Ma(e,a,t),a}function V1(e){const t=zn(e),n=Xl(e),r=n(t,t.neg(t.ONE)),s=n(t,r),o=n(t,t.neg(r)),i=(e+D1)/Wl;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),y=a.cmov(u,l,g);return Ma(a,y,c),y}}function Xl(e){if(e1e3)throw new Error("Cannot find square root: probably non-prime P");if(n===1)return Yl;let o=s.pow(r,t);const i=(t+Re)/Tn;return function(c,u){if(c.is0(u))return u;if(zc(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 y=Re<(xe(e,t)&Re)===Re,F1=["create","isValid","is0","neg","inv","sqrt","sqr","eql","add","sub","mul","pow","div","addN","subN","mulN","sqrN"];function G1(e){const t={ORDER:"bigint",MASK:"bigint",BYTES:"number",BITS:"number"},n=F1.reduce((r,s)=>(r[s]="function",r),t);return wr(e,n),e}function W1(e,t,n){if(nYe;)n&Re&&(r=e.mul(r,s)),s=e.sqr(s),n>>=Re;return r}function Jl(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 zc(e,t){const n=(e.ORDER-Re)/Tn,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 Ql(e,t){t!==void 0&&dn(t);const n=t!==void 0?t:e.toString(2).length,r=Math.ceil(n/8);return{nBitLength:n,nByteLength:r}}function zn(e,t,n=!1,r={}){if(e<=Ye)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}=Ql(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:cs(c),ZERO:Ye,ONE:Re,allowedLengths:a,create:d=>xe(d,e),isValid:d=>{if(typeof d!="bigint")throw new Error("invalid field element: expected bigint, got "+typeof d);return Ye<=d&&dd===Ye,isValidNot0:d=>!f.is0(d)&&f.isValid(d),isOdd:d=>(d&Re)===Re,neg:d=>xe(-d,e),eql:(d,h)=>d===h,sqr:d=>xe(d*d,e),add:(d,h)=>xe(d+h,e),sub:(d,h)=>xe(d-h,e),mul:(d,h)=>xe(d*h,e),pow:(d,h)=>W1(f,d,h),div:(d,h)=>xe(d*qc(h,e),e),sqrN:d=>d*d,addN:(d,h)=>d+h,subN:(d,h)=>d-h,mulN:(d,h)=>d*h,inv:d=>qc(d,e),sqrt:o||(d=>(l||(l=q1(e)),l(f,d))),toBytes:d=>n?Da(d,u):Ao(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?Kn(d):br(d);if(i&&(p=xe(p,e)),!h&&!f.isValid(p))throw new Error("invalid field element: outside of range 0..ORDER");return p},invertBatch:d=>Jl(f,d),cmov:(d,h,p)=>p?h:d});return Object.freeze(f)}function ed(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 td(e){const t=ed(e);return t+Math.ceil(t/2)}function nd(e,t,n=!1){const r=e.length,s=ed(t),o=td(t);if(r<16||r1024)throw new Error("expected "+o+"-1024 bytes of input, got "+r);const i=n?Kn(e):br(e),a=xe(i,t-Re)+Re;return n?Da(a,s):Ao(a,s)}/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */const dr=BigInt(0),On=BigInt(1);function oo(e,t){const n=t.negate();return e?n:t}function In(e,t){const n=Jl(e.Fp,t.map(r=>r.Z));return t.map((r,s)=>e.fromAffine(r.toAffine(n[s])))}function rd(e,t){if(!Number.isSafeInteger(e)||e<=0||e>t)throw new Error("invalid window size, expected [1.."+t+"], got W="+e)}function Qo(e,t){rd(e,t);const n=Math.ceil(t/e)+1,r=2**(e-1),s=2**e,o=cs(e),i=BigInt(e);return{windows:n,windowSize:r,mask:o,maxNumber:s,shiftBy:i}}function Fc(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+=On);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 Y1(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 X1(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 ei=new WeakMap,sd=new WeakMap;function ti(e){return sd.get(e)||1}function Gc(e){if(e!==dr)throw new Error("invalid wNAF")}class od{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>dr;)n&On&&(r=r.add(s)),s=s.double(),n>>=On;return r}precomputeWindow(t,n){const{windows:r,windowSize:s}=Qo(n,this.bits),o=[];let i=t,a=i;for(let c=0;cdr||r>dr;)n&On&&(o=o.add(s)),r&On&&(i=i.add(s)),s=s.double(),n>>=On,r>>=On;return{p1:o,p2:i}}function id(e,t,n,r){Y1(n,e),X1(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=Vl(BigInt(s));let c=1;a>12?c=a-3:a>4?c=a-2:a>0&&(c=2);const u=cs(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[b]=l[b].add(n[g])}let p=i;for(let g=l.length-1,y=i;g>0;g--)y=y.add(l[g]),p=p.add(y);if(d=d.add(p),h!==0)for(let g=0;gdr))throw new Error(`CURVE.${c} must be positive bigint`)}const s=Wc(t.p,n.Fp,r),o=Wc(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 Yc=(e,t)=>(e+(e>=0?t:-t)/cd)/t;function Q1(e,t,n){const[[r,s],[o,i]]=t,a=Yc(i*e,n),c=Yc(-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 Ki(e){if(!["compact","recovered","der"].includes(e))throw new Error('Signature format must be "compact", "recovered", or "der"');return e}function ni(e,t){const n={};for(let r of Object.keys(t))n[r]=e[r]===void 0?t[r]:e[r];return jn(n.lowS,"lowS"),jn(n.prehash,"prehash"),n.format!==void 0&&Ki(n.format),n}class ex extends Error{constructor(t=""){super(t)}}const Lt={Err:ex,_tlv:{encode:(e,t)=>{const{Err:n}=Lt;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}=Lt;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}=Lt;if(e{const{X:$,Y:x,Z:_}=K;if(r.eql(_,r.ONE))return{x:$,y:x};const I=K.is0();E==null&&(E=I?r.ONE:r.inv(_));const L=r.mul($,E),U=r.mul(x,E),j=r.mul(_,E);if(I)return{x:r.ZERO,y:r.ZERO};if(!r.eql(j,r.ONE))throw new Error("invZ was invalid");return{x:L,y:U}}),C=so(K=>{if(K.is0()){if(t.allowInfinityPoint&&!r.is0(K.Y))return;throw new Error("bad point: ZERO")}const{x:E,y:$}=K.toAffine();if(!r.isValid(E)||!r.isValid($))throw new Error("bad point: x or y not field elements");if(!y(E,$))throw new Error("bad point: equation left != right");if(!K.isTorsionFree())throw new Error("bad point: not in prime-order subgroup");return!0});function P(K,E,$,x,_){return $=new B(r.mul($.X,K),$.Y,$.Z),E=oo(x,E),$=oo(_,$),E.add($)}class B{constructor(E,$,x){this.X=m("x",E),this.Y=m("y",$,!0),this.Z=m("z",x),Object.freeze(this)}static CURVE(){return o}static fromAffine(E){const{x:$,y:x}=E||{};if(!E||!r.isValid($)||!r.isValid(x))throw new Error("invalid affine point");if(E instanceof B)throw new Error("projective point not allowed");return r.is0($)&&r.is0(x)?B.ZERO:new B($,x,r.ONE)}static fromBytes(E){const $=B.fromAffine(p(ft(E,void 0,"point")));return $.assertValidity(),$}static fromHex(E){return B.fromBytes(ge("pointHex",E))}get x(){return this.toAffine().x}get y(){return this.toAffine().y}precompute(E=8,$=!0){return H.createCache(this,E),$||this.multiply(Ss),this}assertValidity(){C(this)}hasEvenY(){const{y:E}=this.toAffine();if(!r.isOdd)throw new Error("Field doesn't support isOdd");return!r.isOdd(E)}equals(E){v(E);const{X:$,Y:x,Z:_}=this,{X:I,Y:L,Z:U}=E,j=r.eql(r.mul($,U),r.mul(I,_)),M=r.eql(r.mul(x,U),r.mul(L,_));return j&&M}negate(){return new B(this.X,r.neg(this.Y),this.Z)}double(){const{a:E,b:$}=o,x=r.mul($,Ss),{X:_,Y:I,Z:L}=this;let U=r.ZERO,j=r.ZERO,M=r.ZERO,z=r.mul(_,_),ce=r.mul(I,I),oe=r.mul(L,L),Q=r.mul(_,I);return Q=r.add(Q,Q),M=r.mul(_,L),M=r.add(M,M),U=r.mul(E,M),j=r.mul(x,oe),j=r.add(U,j),U=r.sub(ce,j),j=r.add(ce,j),j=r.mul(U,j),U=r.mul(Q,U),M=r.mul(x,M),oe=r.mul(E,oe),Q=r.sub(z,oe),Q=r.mul(E,Q),Q=r.add(Q,M),M=r.add(z,z),z=r.add(M,z),z=r.add(z,oe),z=r.mul(z,Q),j=r.add(j,z),oe=r.mul(I,L),oe=r.add(oe,oe),z=r.mul(oe,Q),U=r.sub(U,z),M=r.mul(oe,ce),M=r.add(M,M),M=r.add(M,M),new B(U,j,M)}add(E){v(E);const{X:$,Y:x,Z:_}=this,{X:I,Y:L,Z:U}=E;let j=r.ZERO,M=r.ZERO,z=r.ZERO;const ce=o.a,oe=r.mul(o.b,Ss);let Q=r.mul($,I),le=r.mul(x,L),de=r.mul(_,U),_e=r.add($,x),ue=r.add(I,L);_e=r.mul(_e,ue),ue=r.add(Q,le),_e=r.sub(_e,ue),ue=r.add($,_);let be=r.add(I,U);return ue=r.mul(ue,be),be=r.add(Q,de),ue=r.sub(ue,be),be=r.add(x,_),j=r.add(L,U),be=r.mul(be,j),j=r.add(le,de),be=r.sub(be,j),z=r.mul(ce,ue),j=r.mul(oe,de),z=r.add(j,z),j=r.sub(le,z),z=r.add(le,z),M=r.mul(j,z),le=r.add(Q,Q),le=r.add(le,Q),de=r.mul(ce,de),ue=r.mul(oe,ue),le=r.add(le,de),de=r.sub(Q,de),de=r.mul(ce,de),ue=r.add(ue,de),Q=r.mul(le,ue),M=r.add(M,Q),Q=r.mul(be,ue),j=r.mul(_e,j),j=r.sub(j,Q),Q=r.mul(_e,le),z=r.mul(be,z),z=r.add(z,Q),new B(j,M,z)}subtract(E){return this.add(E.negate())}is0(){return this.equals(B.ZERO)}multiply(E){const{endo:$}=t;if(!s.isValidNot0(E))throw new Error("invalid scalar: out of range");let x,_;const I=L=>H.cached(this,L,U=>In(B,U));if($){const{k1neg:L,k1:U,k2neg:j,k2:M}=S(E),{p:z,f:ce}=I(U),{p:oe,f:Q}=I(M);_=ce.add(Q),x=P($.beta,z,oe,L,j)}else{const{p:L,f:U}=I(E);x=L,_=U}return In(B,[x,_])[0]}multiplyUnsafe(E){const{endo:$}=t,x=this;if(!s.isValid(E))throw new Error("invalid scalar: out of range");if(E===Rt||x.is0())return B.ZERO;if(E===nr)return x;if(H.hasCache(this))return this.multiply(E);if($){const{k1neg:_,k1:I,k2neg:L,k2:U}=S(E),{p1:j,p2:M}=J1(B,x,I,U);return P($.beta,j,M,_,L)}else return H.unsafe(x,E)}multiplyAndAddUnsafe(E,$,x){const _=this.multiplyUnsafe($).add(E.multiplyUnsafe(x));return _.is0()?void 0:_}toAffine(E){return O(this,E)}isTorsionFree(){const{isTorsionFree:E}=t;return i===nr?!0:E?E(B,this):H.unsafe(this,a).is0()}clearCofactor(){const{clearCofactor:E}=t;return i===nr?this:E?E(B,this):this.multiplyUnsafe(i)}isSmallOrder(){return this.multiplyUnsafe(i).is0()}toBytes(E=!0){return jn(E,"isCompressed"),this.assertValidity(),h(B,this,E)}toHex(E=!0){return Me(this.toBytes(E))}toString(){return``}get px(){return this.X}get py(){return this.X}get pz(){return this.Z}toRawBytes(E=!0){return this.toBytes(E)}_setWindowSize(E){this.precompute(E)}static normalizeZ(E){return In(B,E)}static msm(E,$){return id(B,s,E,$)}static fromPrivateKey(E){return B.BASE.multiply(Cn(s,E))}}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 N=s.BITS,H=new od(B,t.endo?Math.ceil(N/2):N);return B.BASE.precompute(8),B}function ud(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 rx(e,t={}){const{Fn:n}=e,r=t.randomBytes||qn,s=Object.assign(fd(e.Fp,n),{seed:td(n.ORDER)});function o(h){try{return!!Cn(n,h)}catch{return!1}}function i(h,p){const{publicKey:g,publicKeyUncompressed:y}=s;try{const b=h.length;return p===!0&&b!==g||p===!1&&b!==y?!1:!!e.fromBytes(h)}catch{return!1}}function a(h=r(s.seed)){return nd(ft(h,s.seed,"seed"),n.ORDER)}function c(h,p=!0){return e.BASE.multiply(Cn(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:y}=s;if(n.allowedLengths||p===g)return;const b=ge("key",h).length;return b===g||b===y}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 y=Cn(n,h);return e.fromHex(p).multiply(y).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=>Cn(n,h),precompute(h=8,p=e.BASE){return p.precompute(h,!1)}},lengths:s})}function sx(e,t,n={}){as(t),wr(n,{},{hmac:"function",lowS:"boolean",randomBytes:"function",bits2int:"function",bits2int_modN:"function"});const r=n.randomBytes||qn,s=n.hmac||(($,...x)=>wn(t,$,ve(...x))),{Fp:o,Fn:i}=e,{ORDER:a,BITS:c}=i,{keygen:u,getPublicKey:l,getSharedSecret:f,utils:d,lengths:h}=rx(e,n),p={prehash:!1,lowS:typeof n.lowS=="boolean"?n.lowS:!1,format:void 0,extraEntropy:!1},g="compact";function y($){const x=a>>nr;return $>x}function b($,x){if(!i.isValidNot0(x))throw new Error(`invalid signature ${$}: out of range 1..Point.Fn.ORDER`);return x}function w($,x){Ki(x);const _=h.signature,I=x==="compact"?_:x==="recovered"?_+1:void 0;return ft($,I,`${x} signature`)}class m{constructor(x,_,I){this.r=b("r",x),this.s=b("s",_),I!=null&&(this.recovery=I),Object.freeze(this)}static fromBytes(x,_=g){w(x,_);let I;if(_==="der"){const{r:M,s:z}=Lt.toSig(ft(x));return new m(M,z)}_==="recovered"&&(I=x[0],_="compact",x=x.subarray(1));const L=i.BYTES,U=x.subarray(0,L),j=x.subarray(L,L*2);return new m(i.fromBytes(U),i.fromBytes(j),I)}static fromHex(x,_){return this.fromBytes(gt(x),_)}addRecoveryBit(x){return new m(this.r,this.s,x)}recoverPublicKey(x){const _=o.ORDER,{r:I,s:L,recovery:U}=this;if(U==null||![0,1,2,3].includes(U))throw new Error("recovery id invalid");if(a*cd<_&&U>1)throw new Error("recovery id is ambiguous for h>1 curve");const M=U===2||U===3?I+a:I;if(!o.isValid(M))throw new Error("recovery id 2 or 3 invalid");const z=o.toBytes(M),ce=e.fromBytes(ve(ud((U&1)===0),z)),oe=i.inv(M),Q=S(ge("msgHash",x)),le=i.create(-Q*oe),de=i.create(L*oe),_e=e.BASE.multiplyUnsafe(le).add(ce.multiplyUnsafe(de));if(_e.is0())throw new Error("point at infinify");return _e.assertValidity(),_e}hasHighS(){return y(this.s)}toBytes(x=g){if(Ki(x),x==="der")return gt(Lt.hexFromSig(this));const _=i.toBytes(this.r),I=i.toBytes(this.s);if(x==="recovered"){if(this.recovery==null)throw new Error("recovery bit must be present");return ve(Uint8Array.of(this.recovery),_,I)}return ve(_,I)}toHex(x){return Me(this.toBytes(x))}assertValidity(){}static fromCompact(x){return m.fromBytes(ge("sig",x),"compact")}static fromDER(x){return m.fromBytes(ge("sig",x),"der")}normalizeS(){return this.hasHighS()?new m(this.r,i.neg(this.s),this.recovery):this}toDERRawBytes(){return this.toBytes("der")}toDERHex(){return Me(this.toBytes("der"))}toCompactRawBytes(){return this.toBytes("compact")}toCompactHex(){return Me(this.toBytes("compact"))}}const v=n.bits2int||function(x){if(x.length>8192)throw new Error("input is too large");const _=br(x),I=x.length*8-c;return I>0?_>>BigInt(I):_},S=n.bits2int_modN||function(x){return i.create(v(x))},O=cs(c);function C($){return Xr("num < 2^"+c,$,Rt,O),i.toBytes($)}function P($,x){return ft($,void 0,"message"),x?ft(t($),void 0,"prehashed message"):$}function B($,x,_){if(["recovered","canonical"].some(le=>le in _))throw new Error("sign() legacy options not supported");const{lowS:I,prehash:L,extraEntropy:U}=ni(_,p);$=P($,L);const j=S($),M=Cn(i,x),z=[C(M),C(j)];if(U!=null&&U!==!1){const le=U===!0?r(h.secretKey):U;z.push(ge("extraEntropy",le))}const ce=ve(...z),oe=j;function Q(le){const de=v(le);if(!i.isValidNot0(de))return;const _e=i.inv(de),ue=e.BASE.multiply(de).toAffine(),be=i.create(ue.x);if(be===Rt)return;const It=i.create(_e*i.create(oe+be*M));if(It===Rt)return;let et=(ue.x===be?0:2)|Number(ue.y&nr),Ne=It;return I&&y(It)&&(Ne=i.neg(It),et^=1),new m(be,Ne,et)}return{seed:ce,k2sig:Q}}function N($,x,_={}){$=ge("message",$);const{seed:I,k2sig:L}=B($,x,_);return K1(t.outputLen,i.BYTES,s)(I,L)}function H($){let x;const _=typeof $=="string"||is($),I=!_&&$!==null&&typeof $=="object"&&typeof $.r=="bigint"&&typeof $.s=="bigint";if(!_&&!I)throw new Error("invalid signature, expected Uint8Array, hex string or Signature instance");if(I)x=new m($.r,$.s);else if(_){try{x=m.fromBytes(ge("sig",$),"der")}catch(L){if(!(L instanceof Lt.Err))throw L}if(!x)try{x=m.fromBytes(ge("sig",$),"compact")}catch{return!1}}return x||!1}function K($,x,_,I={}){const{lowS:L,prehash:U,format:j}=ni(I,p);if(_=ge("publicKey",_),x=P(ge("message",x),U),"strict"in I)throw new Error("options.strict was renamed to lowS");const M=j===void 0?H($):m.fromBytes(ge("sig",$),j);if(M===!1)return!1;try{const z=e.fromBytes(_);if(L&&M.hasHighS())return!1;const{r:ce,s:oe}=M,Q=S(x),le=i.inv(oe),de=i.create(Q*le),_e=i.create(ce*le),ue=e.BASE.multiplyUnsafe(de).add(z.multiplyUnsafe(_e));return ue.is0()?!1:i.create(ue.x)===ce}catch{return!1}}function E($,x,_={}){const{prehash:I}=ni(_,p);return x=P(x,I),m.fromBytes($,"recovered").recoverPublicKey(x).toBytes()}return Object.freeze({keygen:u,getPublicKey:l,getSharedSecret:f,utils:d,lengths:h,Point:e,sign:N,verify:K,recoverPublicKey:E,Signature:m,hash:t})}function ox(e){const t={a:e.a,b:e.b,p:e.Fp.ORDER,n:e.n,h:e.h,Gx:e.Gx,Gy:e.Gy},n=e.Fp;let r=e.allowedPrivateKeyLengths?Array.from(new Set(e.allowedPrivateKeyLengths.map(i=>Math.ceil(i/2)))):void 0;const s=zn(t.n,{BITS:e.nBitLength,allowedLengths:r,modFromBytes:e.wrapPrivateKey}),o={Fp:n,Fn:s,allowInfinityPoint:e.allowInfinityPoint,endo:e.endo,isTorsionFree:e.isTorsionFree,clearCofactor:e.clearCofactor,fromBytes:e.fromBytes,toBytes:e.toBytes};return{CURVE:t,curveOpts:o}}function ix(e){const{CURVE:t,curveOpts:n}=ox(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 ax(e,t){const n=t.Point;return Object.assign({},t,{ProjectivePoint:n,CURVE:Object.assign({},e,Ql(n.Fn.ORDER,n.Fn.BITS))})}function cx(e){const{CURVE:t,curveOpts:n,hash:r,ecdsaOpts:s}=ix(e),o=nx(t,n),i=sx(o,r,s);return ax(e,i)}/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */function ux(e,t){const n=r=>cx({...e,hash:r});return{...n(t),create:n}}/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */const hr={p:BigInt("0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f"),n:BigInt("0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141"),h:BigInt(1),a:BigInt(0),b:BigInt(7),Gx:BigInt("0x79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798"),Gy:BigInt("0x483ada7726a3c4655da4fbfc0e1108a8fd17b448a68554199c47d08ffb10d4b8")},fx={beta:BigInt("0x7ae96a2b657c07106e64479eac3434e99cf0497512f58995c1396c28719501ee"),basises:[[BigInt("0x3086d221a7d46bcde86c90e49284eb15"),-BigInt("0xe4437ed6010e88286f547fa90abfe4c3")],[BigInt("0x114ca50f7a8e2f3f657c1108d9d44cfd8"),BigInt("0x3086d221a7d46bcde86c90e49284eb15")]]},lx=BigInt(0),Xc=BigInt(1),Di=BigInt(2);function dx(e){const t=hr.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=ke(l,n,t)*l%t,d=ke(f,n,t)*l%t,h=ke(d,Di,t)*u%t,p=ke(h,s,t)*h%t,g=ke(p,o,t)*p%t,y=ke(g,a,t)*g%t,b=ke(y,c,t)*y%t,w=ke(b,a,t)*g%t,m=ke(w,n,t)*l%t,v=ke(m,i,t)*p%t,S=ke(v,r,t)*u%t,O=ke(S,Di,t);if(!io.eql(io.sqr(O),e))throw new Error("Cannot find square root");return O}const io=zn(hr.p,{sqrt:dx}),We=ux({...hr,Fp:io,lowS:!0,endo:fx},st),Jc={};function ao(e,...t){let n=Jc[e];if(n===void 0){const r=st(Je(e));n=ve(r,r),Jc[e]=n}return st(ve(n,...t))}const Za=e=>e.toBytes(!0).slice(1),xr=We.Point,Va=e=>e%Di===lx;function Mi(e){const{Fn:t,BASE:n}=xr,r=Cn(t,e),s=n.multiply(r);return{scalar:Va(s.y)?r:t.neg(r),bytes:Za(s)}}function ld(e){const t=io;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);Va(s)||(s=t.neg(s));const o=xr.fromAffine({x:e,y:s});return o.assertValidity(),o}const Pr=br;function dd(...e){return xr.Fn.create(Pr(ao("BIP0340/challenge",...e)))}function Qc(e){return Mi(e).bytes}function hx(e,t,n=qn(32)){const{Fn:r}=xr,s=ge("message",e),{bytes:o,scalar:i}=Mi(t),a=ge("auxRand",n,32),c=r.toBytes(i^Pr(ao("BIP0340/aux",a))),u=ao("BIP0340/nonce",c,o,s),{bytes:l,scalar:f}=Mi(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),!hd(h,s,o))throw new Error("sign: Invalid signature produced");return h}function hd(e,t,n){const{Fn:r,BASE:s}=xr,o=ge("signature",e,64),i=ge("message",t),a=ge("publicKey",n,32);try{const c=ld(Pr(a)),u=Pr(o.subarray(0,32));if(!ji(u,Xc,hr.p))return!1;const l=Pr(o.subarray(32,64));if(!ji(l,Xc,hr.n))return!1;const f=dd(r.toBytes(u),Za(c),i),d=s.multiplyUnsafe(l).add(c.multiplyUnsafe(r.neg(f))),{x:h,y:p}=d.toAffine();return!(d.is0()||!Va(p)||h!==u)}catch{return!1}}const pd=(()=>{const n=(s=qn(48))=>nd(s,hr.n);We.utils.randomSecretKey;function r(s){const o=n(s);return{secretKey:o,publicKey:Qc(o)}}return{keygen:r,getPublicKey:Qc,sign:hx,verify:hd,Point:xr,utils:{randomSecretKey:n,randomPrivateKey:n,taggedHash:ao,lift_x:ld,pointToBytes:Za,numberToBytesBE:Ao,bytesToNumberBE:br,mod:xe},lengths:{secretKey:32,publicKey:32,publicKeyHasPrefix:!1,signature:64,seed:48}}})(),co=Me,px=gt,cn="super-testnet-local-v0";class xn{constructor(t){if(!/^[0-9a-f]{64}$/.test(t)||!We.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=co(pd.getPublicKey(t)),this.address=Rr.p2tr.fromPubKey(this.pubkey,"regtest"),this.script=["OP_1",this.pubkey]}static create(){return new xn(co(We.utils.randomPrivateKey()))}static load(t){if((t==null?void 0:t.network)!==cn||(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 xn(t.secret)}backup(){return{kind:"test-wallet",version:1,network:cn,secret:this.secret}}sign(t,n,r=0){return ko.taproot.sign(this.secret,t,r,n?{extension:n}:{}).hex}}const ri=50*1e8,$s="0".repeat(64),eu=e=>co(st(new TextEncoder().encode(JSON.stringify(e)))),_s=(e,t)=>`${e}:${t}`,Ge=e=>$e.encode(e,!1).hex,pe=(e,t)=>{if(!e)throw new Error(t)},gx=/^5120[0-9a-f]{64}$/,si=/^0014[0-9a-f]{40}$/,gd=64,ht=8,mx=e=>co(Dl(st(px(e))));function yx(e,t){const[n,r]=e.vin[t].witness;return We.verify(n.slice(0,-2),ko.segwit.hash(e,t,{pubkey:r,sigflag:1}),r,{lowS:!0,format:"der"})}class Bo{constructor(t){if(this.blocks=[],this.mempool=[],this.utxos=new Map,this.transactions=new Map,t){pe(t.network===cn&&t.version===1,"Unsupported local chain version/network."),pe(Array.isArray(t.blocks)&&Array.isArray(t.mempool),"Invalid chain snapshot.");for(const n of t.blocks)this.acceptBlock(structuredClone(n));this.submitPackage(t.mempool)}}snapshot(){return{network:cn,version:1,blocks:structuredClone(this.blocks),mempool:[...this.mempool]}}coins(t){return[...this.utxos.values()].filter(n=>Ge(n.scriptPubKey)===Ge(t))}satLocation(t){for(const n of this.utxos.values()){const r=Is(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 y,b,w;pe(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);pe(!this.transactions.has(o),"Duplicate transaction."),pe(s.version===2&&s.locktime===0,"Unsupported transaction version or locktime.");const i=!r&&s.vin.some(m=>{var v;return((v=m.witness)==null?void 0:v.length)===3}),a=r?1:i?2:ht,c=r?gd:i?2:ht;pe(s.vin.length>=1&&s.vin.length<=a&&s.vout.length>=1&&s.vout.length<=c,"Unsupported transaction shape.");let u=0;for(const m of s.vout){const v=Number(m.value);pe(Number.isSafeInteger(v)&&v>=330&&v<=ri,"Invalid output amount.");const S=Ge(m.scriptPubKey);pe(gx.test(S)||si.test(S),"Only Taproot and P2WPKH outputs are supported."),u+=v}let l,f=[];const d=s.vin.findIndex(m=>{var v;return((v=m.witness)==null?void 0:v.length)===3}),h=s.vin[d<0?0:d];if(r)pe(h.txid===$s&&h.vout===4294967295&&u===ri,"Invalid local coinbase."),pe(Ge(h.scriptSig)===$e.encode([new TextEncoder().encode(`${cn}:${n}`)],!1).hex,"Wrong coinbase height."),pe(!((y=h.witness)!=null&&y.length),"Unexpected coinbase witness.");else{f=s.vin.map(v=>this.utxos.get(_s(v.txid,v.vout))),pe(f.every(Boolean),"Input is missing or already spent."),pe(new Set(s.vin.map(v=>_s(v.txid,v.vout))).size===s.vin.length,"Duplicate input."),s.vin.forEach((v,S)=>{var C,P,B;pe(v.sequence==="ffffffff"&&Ge(v.scriptSig)==="","Unsupported input flags."),v.prevout={value:f[S].value,scriptPubKey:f[S].scriptPubKey};const O=Ge(f[S].scriptPubKey);if(si.test(O)){const[N,H]=v.witness??[];pe(S!==d&&((C=v.witness)==null?void 0:C.length)===2,"Unsupported witness."),pe(/^30[0-9a-f]{12,140}01$/.test(N)&&/^0[23][0-9a-f]{64}$/.test(H)&&mx(H)===O.slice(4),"P2WPKH spends need a SIGHASH_ALL signature by the key they pay.");return}pe(((P=v.witness)==null?void 0:P.length)===1||S===d&&((B=v.witness)==null?void 0:B.length)===3,"Unsupported witness."),pe(/^[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.")}),pe(f.reduce((v,S)=>v+S.value,0)-u===fe,"v0 requires a fixed 500 sat fee per transaction.");let m={};if(h.witness.length===3){const v=La(h.witness),S=d;if(pe(Number(s.vout[S].value)===Et,"Invalid reveal postage."),pe(Ge(s.vout[S].scriptPubKey)===`5120${v.pubkey}`,"Reveal must return to its signing wallet."),v.parent){const O=d===0?1:0,C=f[O];pe((b=C==null?void 0:C.inscriptions)==null?void 0:b.some(P=>P.id===v.parent),"Referenced parent inscription must actually be spent."),pe(s.vout.length===2&&Number(s.vout[O].value)===C.value&&Ge(C.scriptPubKey)===`5120${v.pubkey}`&&Ge(s.vout[O].scriptPubKey)===Ge(C.scriptPubKey),"Parent must be owned and preserved in the same wallet.")}else s.vin.length===2&&(pe(d===1&&((w=f[0].inscriptions)==null?void 0:w.length)&&v.pointer!==void 0,"Reinscription spend requires correct tag and owned sat."),pe(Number(s.vout[0].value)===f[0].value&&Ge(s.vout[0].scriptPubKey)===Ge(f[0].scriptPubKey)&&Ge(f[0].scriptPubKey)===`5120${v.pubkey}`,"Reinscription sat must be returned to owner."));m={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:Et}}s.vin.forEach((v,S)=>{let O=!1;try{O=si.test(Ge(f[S].scriptPubKey))?yx(s,S):ko.taproot.verify(s,S,S===d?m:{})}catch{}pe(O,"Invalid signature or Taproot commitment.")})}const p=Eu(s,f,n,r),g=f.flatMap(m=>m.inscriptions??[]);if(l){const m=BigInt(l.pointer??0),v=m{var O;return((O=S.inscription)==null?void 0:O.sat)===l.sat}).length,g.push(l)}return pe(g.every(m=>p.some(v=>Is(v,m.sat)!==null)),"Local lab protects inscription sats from fee loss."),r||s.vin.forEach(m=>this.utxos.delete(_s(m.txid,m.vout))),s.vout.forEach((m,v)=>{const S=g.filter(O=>Is(p[v],O.sat)!==null);this.utxos.set(_s(o,v),{txid:o,vout:v,value:Number(m.value),scriptPubKey:m.scriptPubKey,height:n,ranges:p[v],inscriptions:S,...S.length?{inscription:S[0]}:{}})}),this.transactions.set(o,{txid:o,raw:t,height:n,coinbase:r,tx:s,...l?{inscription:l}:{}}),o}submitPackage(t){pe(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;pe(t.height===this.blocks.length+1&&t.previous===(((i=this.blocks.at(-1))==null?void 0:i.hash)??$s),"Invalid block ancestry."),pe(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;pe(eu(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([Ue(ri,t)])}mineTo(t){var a;const n=new Bo({...this.snapshot(),mempool:[]}),r=this.blocks.length+1,s=ie.create({vin:[{txid:$s,vout:4294967295,scriptSig:[new TextEncoder().encode(`${cn}:${r}`)]}],vout:t}),o={height:r,previous:((a=this.blocks.at(-1))==null?void 0:a.hash)??$s,time:Date.now(),raws:[ie.encode(s).hex,...this.mempool]},i={...o,hash:eu(o)};return n.acceptBlock(i),Object.assign(this,n),i}}/*! scure-base - MIT License (c) 2022 Paul Miller (paulmillr.com) */function pr(e){return e instanceof Uint8Array||ArrayBuffer.isView(e)&&e.constructor.name==="Uint8Array"}function bx(e,...t){if(!pr(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 md(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 yd(e){if(typeof e!="function")throw new Error("function expected");return!0}function Dn(e,t){if(typeof t!="string")throw new Error(`${e}: string expected`);return!0}function vr(e){if(!Number.isSafeInteger(e))throw new Error(`invalid integer: ${e}`)}function uo(e){if(!Array.isArray(e))throw new Error("array expected")}function fo(e,t){if(!md(!0,t))throw new Error(`${e}: array of strings expected`)}function qa(e,t){if(!md(!1,t))throw new Error(`${e}: array of numbers expected`)}function us(...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 To(e){const t=typeof e=="string"?e.split(""):e,n=t.length;fo("alphabet",t);const r=new Map(t.map((s,o)=>[s,o]));return{encode:s=>(uo(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=>(uo(s),s.map(o=>{Dn("alphabet.decode",o);const i=r.get(o);if(i===void 0)throw new Error(`Unknown letter: "${o}". Allowed: ${e}`);return i}))}}function Oo(e=""){return Dn("join",e),{encode:t=>(fo("join.decode",t),t.join(e)),decode:t=>(Dn("join.decode",t),t.split(e))}}function bd(e,t="="){return vr(e),Dn("padding",t),{encode(n){for(fo("padding.encode",n);n.length*e%8;)n.push(t);return n},decode(n){fo("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 Zi(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(uo(e),!e.length)return[];let r=0;const s=[],o=Array.from(e,a=>{if(vr(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:wd(t,e%t),lo=(e,t)=>e+(t-wd(e,t)),Us=(()=>{let e=[];for(let t=0;t<40;t++)e.push(2**t);return e})();function ho(e,t,n,r){if(uo(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(lo(t,n)>32)throw new Error(`convertRadix2: carry overflow from=${t} to=${n} carryBits=${lo(t,n)}`);let s=0,o=0;const i=Us[t],a=Us[n]-1,c=[];for(const u of e){if(vr(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=Us[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 xd(e){vr(e);const t=2**8;return{encode:n=>{if(!pr(n))throw new Error("radix.encode input should be Uint8Array");return Zi(Array.from(n),t,e)},decode:n=>(qa("radix.decode",n),Uint8Array.from(Zi(n,e,t)))}}function za(e,t=!1){if(vr(e),e<=0||e>32)throw new Error("radix2: bits should be in (0..32]");if(lo(8,e)>32||lo(e,8)>32)throw new Error("radix2: carry overflow");return{encode:n=>{if(!pr(n))throw new Error("radix2.encode input should be Uint8Array");return ho(Array.from(n),8,e,!t)},decode:n=>(qa("radix2.decode",n),Uint8Array.from(ho(n,e,8,t)))}}function tu(e){return yd(e),function(...t){try{return e.apply(null,t)}catch{}}}function vd(e,t){return vr(e),yd(t),{encode(n){if(!pr(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(!pr(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{Dn("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"})},St=wx?{encode(e){return bx(e),e.toBase64()},decode(e){return xx(e)}}:us(za(6),To("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"),bd(6),Oo("")),vx=e=>us(xd(58),To(e),Oo("")),Ex=vx("123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"),Ed=e=>us(vd(4,t=>e(e(t))),Ex),Vi=us(To("qpzry9x8gf2tvdw0s3jn54khce6mua7l"),Oo("")),nu=[996825010,642813549,513874426,1027748829,705979059];function Br(e){const t=e>>25;let n=(e&33554431)<<5;for(let r=0;r>r&1)===1&&(n^=nu[r]);return n}function ru(e,t,n=1){const r=e.length;let s=1;for(let o=0;o126)throw new Error(`Invalid prefix (${e})`);s=Br(s)^i>>5}s=Br(s);for(let o=0;oh)throw new TypeError(`Length ${g} exceeds limit ${h}`);const y=f.toLowerCase(),b=ru(y,d,t);return`${y}1${Vi.encode(d)}${b}`}function a(f,d=90){Dn("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 y=p.slice(0,g),b=p.slice(g+1);if(b.length<6)throw new Error("Data must be at least 6 characters long");const w=Vi.decode(b).slice(0,-6),m=ru(y,w,t);if(!b.endsWith(m))throw new Error(`Invalid checksum in ${f}: expected "${m}"`);return{prefix:y,words:w}}const c=tu(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 po=kx("bech32");/*! scure-bip32 - MIT License (c) 2022 Patricio Palladino, Paul Miller (paulmillr.com) */const Bs=We.ProjectivePoint,oi=Ed(st);function su(e){De(e);const t=e.length===0?"0":Me(e);return BigInt("0x"+t)}function Sx(e){if(typeof e!="bigint")throw new Error("bigint expected");return gt(e.toString(16).padStart(64,"0"))}const $x=Je("Bitcoin seed"),ii={private:76066276,public:76067358},ai=2147483648,_x=e=>Dl(st(e)),Ax=e=>Un(e).getUint32(0,!1),Ts=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 Un(t).setUint32(0,e,!1),t};class $n{get fingerprint(){if(!this.pubHash)throw new Error("No publicKey set!");return Ax(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 oi.encode(this.serialize(this.versions.private,ve(new Uint8Array([0]),t)))}get publicExtendedKey(){if(!this.pubKey)throw new Error("No public key");return oi.encode(this.serialize(this.versions.public,this.pubKey))}static fromMasterSeed(t,n=ii){if(De(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=wn(Yr,$x,t);return new $n({versions:n,chainCode:r.slice(32),privateKey:r.slice(0,32)})}static fromExtendedKey(t,n=ii){const r=oi.decode(t),s=Un(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 $n({...i,privateKey:a.slice(1)}):new $n({...i,publicKey:a})}static fromJSON(t){return $n.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||ii,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(!We.utils.isValidPrivateKey(t.privateKey))throw new Error("Invalid private key");this.privKey=typeof t.privateKey=="bigint"?t.privateKey:su(t.privateKey),this.privKeyBytes=Sx(this.privKey),this.pubKey=We.getPublicKey(t.privateKey,!0)}else if(t.publicKey)this.pubKey=Bs.fromHex(t.publicKey).toRawBytes(!0);else throw new Error("HDKey: no public or private key provided");this.pubHash=_x(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>=ai)throw new Error("Invalid index");o[2]==="'"&&(a+=ai),r=r.deriveChild(a)}return r}deriveChild(t){if(!this.pubKey||!this.chainCode)throw new Error("No publicKey or chainCode set");let n=Ts(t);if(t>=ai){const a=this.privateKey;if(!a)throw new Error("Could not derive hardened child key");n=ve(new Uint8Array([0]),a,n)}else n=ve(this.pubKey,n);const r=wn(Yr,this.chainCode,n),s=su(r.slice(0,32)),o=r.slice(32);if(!We.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=xe(this.privKey+s,We.CURVE.n);if(!We.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=Bs.fromHex(this.pubKey).add(Bs.fromPrivateKey(s));if(a.equals(Bs.ZERO))throw new Error("The tweak was equal to negative P, which made the result key invalid");i.publicKey=a.toRawBytes(!0)}return new $n(i)}catch{return this.deriveChild(t+1)}}sign(t){if(!this.privateKey)throw new Error("No privateKey set!");return De(t,32),We.sign(t,this.privKey).toCompactRawBytes()}verify(t,n){if(De(t,32),De(n,64),!this.publicKey)throw new Error("No publicKey set!");let r;try{r=We.Signature.fromCompact(n)}catch{return!1}return We.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 De(n,33),ve(Ts(t),new Uint8Array([this.depth]),Ts(this.parentFingerprint),Ts(this.index),this.chainCode,n)}}function Bx(e,t,n,r){as(e);const s=m1({dkLen:32,asyncTick:10},r),{c:o,dkLen:i,asyncTick:a}=s;if(dn(o),dn(i),dn(a),o<1)throw new Error("iterations (c) should be >= 1");const c=jc(t),u=jc(n),l=new Uint8Array(i),f=wn.create(e,c),d=f._cloneInto().update(u);return{c:o,dkLen:i,asyncTick:a,DK:l,PRF:f,PRFSalt:d}}function Tx(e,t,n,r,s){return e.destroy(),t.destroy(),r&&r.destroy(),Tt(s),n}function Ox(e,t,n,r){const{c:s,dkLen:o,DK:i,PRF:a,PRFSalt:c}=Bx(e,t,n,r);let u;const l=new Uint8Array(4),f=Un(l),d=new Uint8Array(a.outputLen);for(let h=1,p=0;pe[0]==="あいこくしん";function kd(e){if(typeof e!="string")throw new TypeError("invalid mnemonic type: "+typeof e);return e.normalize("NFKD")}function Sd(e){const t=kd(e),n=t.split(" ");if(![12,15,18,21,24].includes(n.length))throw new Error("Invalid mnemonic");return{nfkd:t,words:n}}function $d(e){De(e,16,20,24,28,32)}function Cx(e,t=128){if(dn(t),t%32!==0||t>256)throw new TypeError("Invalid entropy");return Ad(qn(t/8),e)}const Px=e=>{const t=8-e.length/4;return new Uint8Array([st(e)[0]>>t<{if(typeof t!="string")throw new Error("wordlist: non-string element: "+t)}),As.chain(As.checksum(1,Px),As.radix2(11,!0),As.alphabet(e))}function Ux(e,t){const{words:n}=Sd(e),r=_d(t).decode(n);return $d(r),r}function Ad(e,t){return $d(e),_d(t).encode(e).join(Ix(t)?" ":" ")}function Nx(e,t){try{Ux(e,t)}catch{return!1}return!0}const Lx=e=>kd("mnemonic"+e);function Rx(e,t=""){return Ox(Yr,Sd(e).nfkd,Lx(t),{c:2048,dkLen:64})}const Fa=`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(` +`),rt={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`},Hx=2**31-1,ci=new Map,ui=new Map,ou=()=>Cx(Fa,256);function Bd(e,t=0){if(typeof e!="string"||!Nx(e,Fa)||t&&e.split(" ").length!==t)throw new Error("Invalid lab mnemonic.");return e}function Er(e,t){if(!Number.isSafeInteger(e)||e<0||e>Hx)throw new Error(`Invalid ${t}.`);return e}const fi=new Map;function Ga(e){return fi.has(e)||fi.set(e,Rx(Bd(e))),fi.get(e)}function kr(e){return ci.has(e)||ci.set(e,$n.fromMasterSeed(Ga(e))),ci.get(e)}function jx(e,t){const n=e.derive(t).privateKey;if(!n)throw new Error("BIP-85 path produced no private key.");return wn(Yr,Je("bip-entropy-from-k"),n)}function Kx(e,t){const n=`${e}|${Er(t,"child index")}`;return ui.has(n)||ui.set(n,Ad(jx(kr(e),rt.orgSeed(t)).slice(0,32),Fa)),ui.get(n)}function qi(e,t=0,n=1){return Me(kr(e).derive(rt.wallet(Er(t,"account"),n)).privateKey)}function Td(e,t=0,n=1){return Me(kr(e).derive(rt.segwit(Er(t,"account"),n)).privateKey)}function Od(e,t=0,n=1){return Me(kr(e).derive(rt.segwit(Er(t,"account"),n)).publicKey)}function Wa(e,t=0){return Me(kr(e).derive(rt.nostr(Er(t,"account"))).privateKey)}function Dx(e,t=0){const n=pd.getPublicKey(kr(e).derive(rt.nostr(Er(t,"account"))).privateKey);return{pubkey:Me(n),npub:po.encode("npub",po.toWords(n))}}const Id="lineage-claim",zi=330,go=e=>$e.encode(e,!1).hex,iu=e=>({txid:e.txid,vout:e.vout,value:e.value,script:go(e.scriptPubKey)}),li=/^[0-9a-f]{64}$/,Mx=/^5120[0-9a-f]{64}$/;function Io(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 Cd(e){return ie.create({vin:[jt(e.holder.txid,e.holder.vout,e.holder.value,e.holder.script),jt(e.payer.txid,e.payer.vout,e.payer.value,e.payer.script)],vout:[Ue(e.holder.value,["OP_1",e.to]),Ue(e.payer.value-fe,["OP_1",e.to])]})}function Zx(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=Io(e,t);if(!s)throw new Error("That inscription is not in an unspent output.");if(go(s.scriptPubKey)===go(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>=fe+zi});if(!o)throw new Error("The recipient needs a plain coin for the 500-sat fee. Mine a block to it first.");const i={kind:Id,version:1,inscription:t,carried:s.inscriptions.map(c=>c.id),holder:iu(s),payer:iu(o),to:n.pubkey,at:r},a=Cd(i);return i.txid=ie.util.getTxid(a),i.sig=n.sign(a,void 0,1),i}function Vx(e,t,n){const r=zx(t);if((n==null?void 0:n.kind)!=="test-wallet")throw new Error("Countersigning needs a local test wallet.");if(go(n.script)!==r.holder.script)throw new Error("Only the current holder can countersign.");if(qx(e,r)!=="open")throw new Error("This claim is stale: an input it spends was already spent.");const s=Cd(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 qx(e,t){return e.utxos.has(`${t.holder.txid}:${t.holder.vout}`)&&e.utxos.has(`${t.payer.txid}:${t.payer.vout}`)?"open":"stale"}function zx(e){const t=n=>n&&li.test(n.txid)&&Number.isSafeInteger(n.vout)&&n.vout>=0&&Number.isSafeInteger(n.value)&&n.value>=zi&&Mx.test(n.script);if((e==null?void 0:e.kind)!==Id||e.version!==1||!/^[0-9a-f]{64}i\d+$/.test(e.inscription)||!Array.isArray(e.carried)||!t(e.holder)||!t(e.payer)||e.payer.value255*s)throw new Error("Length should be <= 255*HashLen");const o=Math.ceil(r/s);n===void 0&&(n=au);const i=new Uint8Array(o*s),a=wn.create(e,t),c=a._cloneInto(),u=new Uint8Array(a.outputLen);for(let l=0;lGx(e,Fx(e,t,n),r,s);/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */const rn=BigInt(0),Ce=BigInt(1),hi=BigInt(2),Yx=BigInt(8);function Xx(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 Jx(e,t={}){const n=ad("edwards",e,t,t.FpFnLE),{Fp:r,Fn:s}=n;let o=n.CURVE;const{h:i}=o;wr(t,{},{uvRatio:"function"});const a=hi<r.create(y),u=t.uvRatio||((y,b)=>{try{return{isValid:!0,value:r.sqrt(r.div(y,b))}}catch{return{isValid:!1,value:rn}}});if(!Xx(r,o,o.Gx,o.Gy))throw new Error("bad curve params: generator point");function l(y,b,w=!1){const m=w?Ce:rn;return Xr("coordinate "+y,b,m,a),b}function f(y){if(!(y instanceof p))throw new Error("ExtendedPoint expected")}const d=so((y,b)=>{const{X:w,Y:m,Z:v}=y,S=y.is0();b==null&&(b=S?Yx:r.inv(v));const O=c(w*b),C=c(m*b),P=r.mul(v,b);if(S)return{x:rn,y:Ce};if(P!==Ce)throw new Error("invZ was invalid");return{x:O,y:C}}),h=so(y=>{const{a:b,d:w}=o;if(y.is0())throw new Error("bad point: ZERO");const{X:m,Y:v,Z:S,T:O}=y,C=c(m*m),P=c(v*v),B=c(S*S),N=c(B*B),H=c(C*b),K=c(B*c(H+P)),E=c(N+c(w*c(C*P)));if(K!==E)throw new Error("bad point: equation left != right (1)");const $=c(m*v),x=c(S*O);if($!==x)throw new Error("bad point: equation left != right (2)");return!0});class p{constructor(b,w,m,v){this.X=l("x",b),this.Y=l("y",w),this.Z=l("z",m,!0),this.T=l("t",v),Object.freeze(this)}static CURVE(){return o}static fromAffine(b){if(b instanceof p)throw new Error("extended point not allowed");const{x:w,y:m}=b||{};return l("x",w),l("y",m),new p(w,m,Ce,c(w*m))}static fromBytes(b,w=!1){const m=r.BYTES,{a:v,d:S}=o;b=Vc(ft(b,m,"point")),jn(w,"zip215");const O=Vc(b),C=b[m-1];O[m-1]=C&-129;const P=Kn(O),B=w?a:r.ORDER;Xr("point.y",P,rn,B);const N=c(P*P),H=c(N-Ce),K=c(S*N-v);let{isValid:E,value:$}=u(H,K);if(!E)throw new Error("bad point: invalid y coordinate");const x=($&Ce)===Ce,_=(C&128)!==0;if(!w&&$===rn&&_)throw new Error("bad point: x=0 and x_0=1");return _!==x&&($=c(-$)),p.fromAffine({x:$,y:P})}static fromHex(b,w=!1){return p.fromBytes(ge("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(hi),this}assertValidity(){h(this)}equals(b){f(b);const{X:w,Y:m,Z:v}=this,{X:S,Y:O,Z:C}=b,P=c(w*C),B=c(S*v),N=c(m*C),H=c(O*v);return P===B&&N===H}is0(){return this.equals(p.ZERO)}negate(){return new p(c(-this.X),this.Y,this.Z,c(-this.T))}double(){const{a:b}=o,{X:w,Y:m,Z:v}=this,S=c(w*w),O=c(m*m),C=c(hi*c(v*v)),P=c(b*S),B=w+m,N=c(c(B*B)-S-O),H=P+O,K=H-C,E=P-O,$=c(N*K),x=c(H*E),_=c(N*E),I=c(K*H);return new p($,x,I,_)}add(b){f(b);const{a:w,d:m}=o,{X:v,Y:S,Z:O,T:C}=this,{X:P,Y:B,Z:N,T:H}=b,K=c(v*P),E=c(S*B),$=c(C*m*H),x=c(O*N),_=c((v+S)*(P+B)-K-E),I=x-$,L=x+$,U=c(E-w*K),j=c(_*I),M=c(L*U),z=c(_*U),ce=c(I*L);return new p(j,M,ce,z)}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:m}=g.cached(this,b,v=>In(p,v));return In(p,[w,m])[0]}multiplyUnsafe(b,w=p.ZERO){if(!s.isValid(b))throw new Error("invalid scalar: expected 0 <= sc < curve.n");return b===rn?p.ZERO:this.is0()||b===Ce?this:g.unsafe(this,b,m=>In(p,m),w)}isSmallOrder(){return this.multiplyUnsafe(i).is0()}isTorsionFree(){return g.unsafe(this,o.n).is0()}toAffine(b){return d(this,b)}clearCofactor(){return i===Ce?this:this.multiplyUnsafe(i)}toBytes(){const{x:b,y:w}=this.toAffine(),m=r.toBytes(w);return m[m.length-1]|=b&Ce?128:0,m}toHex(){return Me(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 In(p,b)}static msm(b,w){return id(p,s,b,w)}_setWindowSize(b){this.precompute(b)}toRawBytes(){return this.toBytes()}}p.BASE=new p(o.Gx,o.Gy,Ce,c(o.Gx*o.Gy)),p.ZERO=new p(rn,Ce,Ce,rn),p.Fp=r,p.Fn=s;const g=new od(p,s.BITS);return p.BASE.precompute(8),p}function Qx(e,t,n={}){if(typeof t!="function")throw new Error('"hash" function param is required');wr(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||(B=>B),u=n.domain||((B,N,H)=>{if(jn(H,"phflag"),N.length||H)throw new Error("Contexts/pre-hash are not supported");return B});function l(B){return i.create(Kn(B))}function f(B){const N=m.secretKey;B=ge("private key",B,N);const H=ge("hashed private key",t(B),2*N),K=c(H.slice(0,N)),E=H.slice(N,2*N),$=l(K);return{head:K,prefix:E,scalar:$}}function d(B){const{head:N,prefix:H,scalar:K}=f(B),E=s.multiply(K),$=E.toBytes();return{head:N,prefix:H,scalar:K,point:E,pointBytes:$}}function h(B){return d(B).pointBytes}function p(B=Uint8Array.of(),...N){const H=ve(...N);return l(t(u(H,ge("context",B),!!r)))}function g(B,N,H={}){B=ge("message",B),r&&(B=r(B));const{prefix:K,scalar:E,pointBytes:$}=d(N),x=p(H.context,K,B),_=s.multiply(x).toBytes(),I=p(H.context,_,$,B),L=i.create(x+I*E);if(!i.isValid(L))throw new Error("sign failed: invalid s");const U=ve(_,i.toBytes(L));return ft(U,m.signature,"result")}const y={zip215:!0};function b(B,N,H,K=y){const{context:E,zip215:$}=K,x=m.signature;B=ge("signature",B,x),N=ge("message",N),H=ge("publicKey",H,m.publicKey),$!==void 0&&jn($,"zip215"),r&&(N=r(N));const _=x/2,I=B.subarray(0,_),L=Kn(B.subarray(_,x));let U,j,M;try{U=e.fromBytes(H,$),j=e.fromBytes(I,$),M=s.multiplyUnsafe(L)}catch{return!1}if(!$&&U.isSmallOrder())return!1;const z=p(E,j.toBytes(),U.toBytes(),N);return j.add(U.multiplyUnsafe(z)).subtract(M).clearCofactor().is0()}const w=o.BYTES,m={secretKey:w,publicKey:w,signature:2*w,seed:w};function v(B=a(m.seed)){return ft(B,m.seed,"seed")}function S(B){const N=P.randomSecretKey(B);return{secretKey:N,publicKey:h(N)}}function O(B){return is(B)&&B.length===i.BYTES}function C(B,N){try{return!!e.fromBytes(B,N)}catch{return!1}}const P={getExtendedPublicKey:d,randomSecretKey:v,isValidSecretKey:O,isValidPublicKey:C,toMontgomery(B){const{y:N}=e.fromBytes(B),H=m.publicKey,K=H===32;if(!K&&H!==57)throw new Error("only defined for 25519 and 448");const E=K?o.div(Ce+N,Ce-N):o.div(N-Ce,N+Ce);return o.toBytes(E)},toMontgomerySecret(B){const N=m.secretKey;ft(B,N);const H=t(B.subarray(0,N));return c(H).subarray(0,N)},randomPrivateKey:v,precompute(B=8,N=e.BASE){return N.precompute(B,!1)}};return Object.freeze({keygen:S,getPublicKey:h,sign:g,verify:b,utils:P,Point:e,lengths:m})}function e2(e){const t={a:e.a,d:e.d,p:e.Fp.ORDER,n:e.n,h:e.h,Gx:e.Gx,Gy:e.Gy},n=e.Fp,r=zn(t.n,e.nBitLength,!0),s={Fp:n,Fn:r,uvRatio:e.uvRatio},o={randomBytes:e.randomBytes,adjustScalarBytes:e.adjustScalarBytes,domain:e.domain,prehash:e.prehash,mapToCurve:e.mapToCurve};return{CURVE:t,curveOpts:s,hash:e.hash,eddsaOpts:o}}function t2(e,t){const n=t.Point;return Object.assign({},t,{ExtendedPoint:n,CURVE:e,nBitLength:n.Fn.BITS,nByteLength:n.Fn.BYTES})}function n2(e){const{CURVE:t,curveOpts:n,hash:r,eddsaOpts:s}=e2(e),o=Jx(t,n),i=Qx(o,r,s);return t2(e,i)}/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */const Tr=BigInt(0),Xn=BigInt(1),Os=BigInt(2);function r2(e){return wr(e,{adjustScalarBytes:"function",powPminus2:"function"}),Object.freeze({...e})}function s2(e){const t=r2(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?Os**BigInt(254):Os**BigInt(447),p=a?BigInt(8)*Os**BigInt(251)-Xn:BigInt(4)*Os**BigInt(445)-Xn,g=h+p+Xn,y=E=>xe(E,n),b=w(f);function w(E){return Da(y(E),l)}function m(E){const $=ge("u coordinate",E,l);return a&&($[31]&=127),y(Kn($))}function v(E){return Kn(s(ge("scalar",E,l)))}function S(E,$){const x=P(m($),v(E));if(x===Tr)throw new Error("invalid private or public key received");return w(x)}function O(E){return S(E,b)}function C(E,$,x){const _=y(E*($-x));return $=y($-_),x=y(x+_),{x_2:$,x_3:x}}function P(E,$){Xr("u",E,Tr,n),Xr("scalar",$,h,g);const x=$,_=E;let I=Xn,L=Tr,U=E,j=Xn,M=Tr;for(let ce=BigInt(u-1);ce>=Tr;ce--){const oe=x>>ce&Xn;M^=oe,{x_2:I,x_3:U}=C(M,I,U),{x_2:L,x_3:j}=C(M,L,j),M=oe;const Q=I+L,le=y(Q*Q),de=I-L,_e=y(de*de),ue=le-_e,be=U+j,It=U-j,et=y(It*Q),Ne=y(be*de),Ct=et+Ne,_r=et-Ne;U=y(Ct*Ct),j=y(_*y(_r*_r)),I=y(le*_e),L=y(ue*(le+y(d*ue)))}({x_2:I,x_3:U}=C(M,I,U)),{x_2:L,x_3:j}=C(M,L,j);const z=o(L);return y(I*z)}const B={secretKey:l,publicKey:l,seed:l},N=(E=c(l))=>(De(E,B.seed),E);function H(E){const $=N(E);return{secretKey:$,publicKey:O($)}}return{keygen:H,getSharedSecret:(E,$)=>S(E,$),getPublicKey:E=>O(E),scalarMult:S,scalarMultBase:O,utils:{randomSecretKey:N,randomPrivateKey:N},GuBytes:b.slice(),lengths:B}}/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */const o2=BigInt(1),cu=BigInt(2),i2=BigInt(3),a2=BigInt(5),c2=BigInt(8),Ya=BigInt("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffed"),Pd={p:Ya,n:BigInt("0x1000000000000000000000000000000014def9dea2f79cd65812631a5cf5d3ed"),h:c2,a:BigInt("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffec"),d:BigInt("0x52036cee2b6ffe738cc740797779e89800700a4d4141d8ab75eb4dca135978a3"),Gx:BigInt("0x216936d3cd6e53fec0a4e231fdd6dc5c692cc7609525a7b2c9562d608f25d51a"),Gy:BigInt("0x6666666666666666666666666666666666666666666666666666666666666658")};function Ud(e){const t=BigInt(10),n=BigInt(20),r=BigInt(40),s=BigInt(80),o=Ya,a=e*e%o*e%o,c=ke(a,cu,o)*a%o,u=ke(c,o2,o)*e%o,l=ke(u,a2,o)*u%o,f=ke(l,t,o)*l%o,d=ke(f,n,o)*f%o,h=ke(d,r,o)*d%o,p=ke(h,s,o)*h%o,g=ke(p,s,o)*h%o,y=ke(g,t,o)*l%o;return{pow_p_5_8:ke(y,cu,o)*e%o,b2:a}}function Nd(e){return e[0]&=248,e[31]&=127,e[31]|=64,e}const uu=BigInt("19681161376707505956807079304988542015446066515923890162744021073123829784752");function u2(e,t){const n=Ya,r=xe(t*t*t,n),s=xe(r*r*t,n),o=Ud(e*s).pow_p_5_8;let i=xe(e*r*o,n);const a=xe(t*i*i,n),c=i,u=xe(i*uu,n),l=a===e,f=a===xe(-e,n),d=a===xe(-e*uu,n);return l&&(i=c),(f||d)&&(i=u),z1(i,n)&&(i=xe(-i,n)),{isValid:l||f,value:i}}const Ld=zn(Pd.p,{isLE:!0}),f2={...Pd,Fp:Ld,hash:Yr,adjustScalarBytes:Nd,uvRatio:u2},Co=n2(f2),Rd=(()=>{const e=Ld.ORDER;return s2({P:e,type:"x25519",powPminus2:t=>{const{pow_p_5_8:n,b2:r}=Ud(t);return xe(ke(n,i2,e)*r,e)},adjustScalarBytes:Nd})})(),l2=Je("lineage/v0"),$t=(e,t)=>Wx(st,e,l2,Je(t),32),Po=e=>{const t=Uint8Array.from(e);return t[0]&=248,t[31]&=127,t[31]|=64,t},Hd=e=>{const t=new Uint8Array(4);return new DataView(t.buffer).setUint32(0,e),t},it=e=>ve(Hd(e.length),e),Xa=e=>ve(it(Je("ssh-ed25519")),it(e)),Fi=(e,t)=>`ssh-ed25519 ${St.encode(Xa(e))}${t?` ${t}`:""}`,Gi=e=>`SHA256:${St.encode(st(Xa(e))).replace(/=+$/,"")}`;function d2(e){const t=gt(e),n=r=>Co.getPublicKey($t(t,r));return{ssh:n("ssh"),git:n("git"),dkim:n("dkim"),wg:Rd.getPublicKey(Po($t(t,"wg")))}}function h2(e){const t=n=>Co.getPublicKey($t(e,n));return{"ssh-ca":t("node/ssh-ca"),mtls:t("node/mtls"),noise:Rd.getPublicKey(Po($t(e,"node/noise")))}}function p2(e,t,n,r){return[["ssh",Gi(e.ssh),Fi(e.ssh,t)],["git",Gi(e.git),`${t} namespaces="git" ${Fi(e.git,t)}`],["dkim",`${n}._domainkey.${r}`,`${n}._domainkey.${r}. IN TXT "v=DKIM1; k=ed25519; p=${St.encode(e.dkim)}"`],["wg",St.encode(e.wg),`[Peer] +# ${t} +PublicKey = ${St.encode(e.wg)}`]]}function g2(e,t){return[["ssh-ca",Gi(e["ssh-ca"]),Fi(e["ssh-ca"],`lineage-ca@${t}`)],["mtls",St.encode(e.mtls),null],["noise",`mkey:${Me(e.noise)}`,null]]}const m2=gt("302e020100300506032b657004220420");function jd(e,t,n){const r=st(e).slice(0,4);let s=ve(r,r,it(Je("ssh-ed25519")),it(t),it(ve(e,t)),it(Je(n)));s=ve(s,new Uint8Array((8-s.length%8)%8).map((i,a)=>a+1));const o=ve(Je("openssh-key-v1\0"),it(Je("none")),it(Je("none")),it(new Uint8Array(0)),Hd(1),it(Xa(t)),it(s));return`-----BEGIN OPENSSH PRIVATE KEY----- +${St.encode(o).match(/.{1,70}/g).join(` +`)} +-----END OPENSSH PRIVATE KEY----- +`}const y2=(e,t)=>`-----BEGIN ${e}----- +${St.encode(t).match(/.{1,64}/g).join(` +`)} +-----END ${e}----- +`;function b2(e,t){const n=gt(e),r=s=>{const o=$t(n,s);return jd(o,Co.getPublicKey(o),t)};return[["ssh","OpenSSH private key",r("ssh")],["git","OpenSSH private key",r("git")],["dkim","Ed25519 private key (base64)",St.encode($t(n,"dkim"))],["wg","Interface entry",`[Interface] +PrivateKey = ${St.encode(Po($t(n,"wg")))}`]]}function w2(e,t){const n=$t(e,"node/ssh-ca");return[["ssh-ca","OpenSSH private key",jd(n,Co.getPublicKey(n),`lineage-ca@${t}`)],["mtls","Private key (PKCS#8 PEM)",y2("PRIVATE KEY",ve(m2,$t(e,"node/mtls")))],["noise","noise_private.key",`privkey:${Me(Po($t(e,"node/noise")))}`]]}const x2=["bip86","tapkey","wallet"],Ja=()=>({scheme:"bip86",roots:{},adopted:{}}),v2=e=>Vs.getPubKey(e)[0];function Kd(e,t,n){return e.scheme==="wallet"?qi(t,n):Vs.getSecKey(e.scheme==="tapkey"?Wa(t,n):qi(t,n))[0]}const Dd=(e,t)=>e.scheme==="tapkey"?rt.nostr(t):rt.wallet(t),E2=(e,t)=>new xn(Kd(e,t,0)),Be=e=>$e.encode(e,!1).hex;function vn(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=vn(e,t,s);return i&&{...i,account:n.index+1}}if(n.edge==="adopted")return r(e.adopted[n.id]);const o=vn(e,t,s);return o&&{mnemonic:Kx(o.mnemonic,n.index),account:0,origin:o.origin,steps:[...o.steps,`${n.index}'`]}}const pi=new Map;function Te(e,t,n){const r=vn(e,t,n);if(!r)return null;const s=`${e.scheme}|${r.mnemonic}|${r.account}`;if(!pi.has(s)){const{npub:u,pubkey:l}=Dx(r.mnemonic,r.account);pi.set(s,{wallet:new xn(Kd(e,r.mnemonic,r.account)),npub:u,pubkey:l})}const{wallet:o,npub:i,pubkey:a}=pi.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} · ${Dd(e,r.account)}`}}function k2(e,t,n){const r=vn(e,t,n);if(!r)return null;const s=Te(e,t,n),o=Od(r.mnemonic,r.account);return{taproot:{address:s.wallet.address,path:Dd(e,r.account)},segwit:{address:Rr.p2wpkh.fromPubKey(o,"regtest"),path:rt.segwit(r.account)},tapkey:{address:Rr.p2tr.fromPubKey(v2(s.pubkey),"regtest"),path:rt.nostr(r.account)},npub:{address:s.npub,path:rt.nostr(r.account)}}}function Qa(e,t,n){const r=Io(e.chain,n);if(!r)return null;const s=Be(r.scriptPubKey),o=t.nodes.get(n),i=Te(e.keys,t,o),a=o&&Te(e.keys,t,t.nodes.get(o.parent));return i&&Be(i.wallet.script)===s?{wallet:i.wallet,who:"own"}:e.wallet&&Be(e.wallet.script)===s?{wallet:e.wallet,who:"lab"}:a&&Be(a.wallet.script)===s?{wallet:a.wallet,who:"parent"}:{wallet:null,who:"other",script:s}}function Uo(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(...Uo(e,s))}return r}function Wi(e,t){const n=[];for(let r=t;r;r=e.nodes.get(r.parent))n.push(r.name);return n.join(".")}function S2(e,t,n){const r=vn(e,t,n);if(!r)return null;if(n.kind!=="agent")return g2(h2(Ga(r.mnemonic)),Wi(t,n));const s=Wi(t,t.nodes.get(n.parent));return p2(d2(Wa(r.mnemonic,r.account)),`${n.name}@${s}`,n.name,s)}const $2=Ed(st),Or=(e,t=239)=>$2.encode(ve(Uint8Array.of(t),gt(e),Uint8Array.of(1))),_2=e=>po.encode("nsec",po.toWords(gt(e))),A2="0123456789()[],'/*abcdefgh@:$%{}IJKLMNOPQRSTUVWXYZ&+-.;<=>?!^_|~ijklmnopqrstuvwxyzABCDEFGH`#\"\\ ",B2=[0xf5dee51989n,0xa9fdca3312n,0x1bab10e32dn,0x3706b1677an,0x644d626ffdn];function gi(e){const t=(i,a)=>{const c=i>>35n;return i=(i&0x7ffffffffn)<<5n^BigInt(a),B2.forEach((u,l)=>{c>>BigInt(l)&1n&&(i^=u)}),i};let n=1n,r=0,s=0;for(const i of e){const a=A2.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 T2(e,t,n){const r=vn(e,t,n);if(!r)return null;const s=Wa(r.mnemonic,r.account),o=qi(r.mnemonic,r.account),i={bip86:`tr(${Or(o)})`,tapkey:`tr(${Or(s)})`,wallet:`rawtr(${Or(o)})`}[e.scheme],a=n.kind==="agent",c=Wi(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",_2(s)],["taproot","descriptor",gi(i)],["segwit","descriptor",gi(`wpkh(${Or(Td(r.mnemonic,r.account))})`)],["tapkey","descriptor",gi(`tr(${Or(s)})`)]],leaves:a?b2(s,`${n.name}@${c}`):w2(Ga(r.mnemonic),c)}}const Jr=1e8,Qe=50*Jr,Ie=330,Md=e=>(e/Jr).toFixed(8).replace(/\.?0+$/,""),ae=e=>`${Md(e)} tBTC`;function ec(e){if(e<1e6)return ae(e);const t=Math.round(e/1e6)*1e6;return`${t===e?"":"≈"}${ae(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)*Jr+Number((t[2]??"").padEnd(8,"0"))}class Zd{constructor(t,n,r){this.secret=t,this.pubkey=n,this.path=r,this.address=Rr.p2wpkh.fromPubKey(n,"regtest"),this.script=Rr.toScriptPubKey(this.address)}sign(t,n){return[ko.segwit.sign(this.secret,t,n,{pubkey:this.pubkey}).hex,this.pubkey]}}const mi=new Map;function Ee(e,t,n){const r=vn(e,t,n);if(!r)return null;const s=`${r.mnemonic}|${r.account}`;return mi.has(s)||mi.set(s,new Zd(Td(r.mnemonic,r.account),Od(r.mnemonic,r.account),rt.segwit(r.account))),mi.get(s)}function O2(e,t,n){var s;const r=n?t.nodes.get(n):null;return r&&r.root===r.id&&r.status==="active"?((s=Ee(e,t,r))==null?void 0:s.script)??null:null}const rr=(e,t)=>{var n,r;return((r=(n=e.mining)==null?void 0:n.rigs)==null?void 0:r[t])??1};function nc(e,t){var n;return((n=e.mining)==null?void 0:n.rule)==="none"?[]:t.roots.filter(r=>r.status==="active"&&rr(e,r.id)>0&&Ee(e.keys,t,r)).slice(0,gd)}function Vd(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=O2(e.keys,t,n);return c?[{script:c,value:Qe}]:null}const r=nc(e,t),s=r.reduce((c,u)=>c+rr(e,u.id),0);let o=Qe;return r.length?r.map((c,u)=>{const l=u===r.length-1?o:Math.floor(Qe*rr(e,c.id)/s);return o-=l,{script:Ee(e.keys,t,c).script,value:l}}):null}function Qr(e,t,n=ht){const r=t+fe,s=u=>u===r||u-r>=Ie&&u-r<=Qe,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 sc(e,t=ht){let n=0,r=-fe;for(const s of e.map(o=>o.value).sort((o,i)=>i-o).slice(0,t)){r+=s;const o=r<=Qe?r:r-Qe>=Ie?Qe:r-Ie;o>=Ie&&r-o<=Qe&&(n=Math.max(n,o))}return n}function qd(e,t,n,r=ht,s="send"){const o=rc(t),i=n+fe,a=sc(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}`))),Fd=(e,t)=>e.chain.coins(t.script).filter(n=>{var r;return!((r=n.inscriptions)!=null&&r.length)}),Gd=(e,t,n=ht)=>!!Qr(e,t,n),Wd=(e,t,n)=>Gd(Fd(e,t),n);function oc(e,t,n,r,s="This node",o="send"){const i=Fd(e,t),a=zd(e),c=Qr(i.filter(d=>!a.has(`${d.txid}:${d.vout}`)),r)??Qr(i,r);if(!c)throw new Error(qd(s,i,r,ht,o));const u=rc(c)-r-fe,l=ie.create({vin:c.map(d=>jt(d.txid,d.vout,d.value,d.scriptPubKey)),vout:[Ue(r,n),...u?[Ue(u,t.script)]:[]]});c.forEach((d,h)=>{l.vin[h].witness=t instanceof Zd?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 Yd(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=Ee(e.keys,t,o),c=Ee(e.keys,t,i);if(!a||!c)throw new Error("A holding that predates lab keys has no SegWit addresses.");if(!Number.isSafeInteger(s)||sQe)throw new Error("Send at most 50 test BTC at a time: no output on this chain is bigger than one block reward.");return oc(e,a,c.script,s,o.name)}function I2(e,t,n){if(!t||!n||Be(t.script)===Be(n.script))return 0;let r=0;for(const s of e.chain.coins(t.script)){if(s.value-fe[t,...t.log.flatMap((n,r)=>n.ok&&n.op==="graduate"?[bn(e.slice(0,r),{pending:!0})]:[])];function Xd(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 C2=(e,t,n)=>Xd(ic(t,n),(r,s)=>{const o=Ee(e,r,s);return o&&Be(o.script)}),yi=new Map,P2=(e,t,n)=>Xd(ic(t,n),(r,s)=>{const o=vn(e,r,s),i=o&&`${e.scheme}|${o.mnemonic}|${o.account}`;return i&&!yi.has(i)&&yi.set(i,Be(Te(e,r,s).wallet.script)),i?yi.get(i):null}),ac=(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 U2(e,t,n,r){for(const s of ic(t,n))for(const o of s.nodes.values()){const i=Te(e,s,o);if(i&&Be(i.wallet.script)===r)return{node:o.id,wallet:i.wallet}}return null}function N2(e,t,n=new Map,r=new Map){var a;const s=[],o=c=>t.get(Be(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:Be(v.scriptPubKey),node:o(v.scriptPubKey),value:Number(v.value)}));if(f){d.forEach((v,S)=>{v.node&&s.push({kind:"mine",key:`${c}:${S}`,txid:c,beat:l,from:null,to:v.node,amount:v.value,fee:0,change:0})});continue}const h=u.vin.map(v=>{var O;const S=(O=e.transactions.get(v.txid))==null?void 0:O.tx.vout[v.vout];return S?{node:o(S.scriptPubKey),value:Number(S.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(S=>S.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(S=>!S.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 y=d.filter(v=>v.node!==g),b=d.filter(v=>v.node===g),w=i(h)-i(d),m={key:c,txid:c,beat:l,from:g,fee:w};y.length&&y.every(v=>n.get(v.script)===g)?s.push({...m,kind:"gas",to:g,amount:i(y),change:i(b)}):y.length?s.push({...m,kind:"pay",to:y[0].node,amount:y[0].value,change:i(b)}):s.push({...m,kind:"move",to:g,amount:i(b),change:0})}return s}function Yi(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(Be(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 Xi="lineage-offer",fu=/^[0-9a-f]{64}$/,bi=/^[0-9a-f]{64}i0$/,lu=/^5120[0-9a-f]{64}$/,wi=/^0014[0-9a-f]{40}$/,du=e=>({txid:e.txid,vout:e.vout,value:e.value,script:Be(e.scriptPubKey)}),hu=(e,t)=>!e.utxos.has(`${t.txid}:${t.vout}`),Jd=e=>{const t=_o(new os(e.chain));return{events:t,state:bn(t,{pending:!0})}};function Qd(e){return ie.create({vin:[e.holder,...e.payers].map(t=>jt(t.txid,t.vout,t.value,t.script)),vout:[Ue(e.holder.value,e.to),...e.price?[Ue(e.price,e.pay)]:[],...e.change?[Ue(e.change,e.back)]:[]]})}function cc(e,t,n,r){const s=Io(e.chain,r),o=s&&U2(e.keys,t,n,Be(s.scriptPubKey));return o?{coin:s,node:n.nodes.get(o.node),wallet:o.wallet}:null}function eh(e,t,n,r,s=Date.now()){const{events:o,state:i}=Jd(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&&rQe)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 m of[c,l])if(m.status!=="active")throw new Error(`${m.name} is ${m.status}.`);const f=Ee(e.keys,i,c),d=Ee(e.keys,i,l),h=Te(e.keys,i,c);if(!f||!d||!h)throw new Error("A holding that predates lab keys cannot trade.");if((e.offers??[]).some(m=>m.item===t&&m.buyer===c.id&&Ji(e,i,m)==="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=zd(e),y=Qr(p.filter(m=>!g.has(`${m.txid}:${m.vout}`)),r,ht-1)??Qr(p,r,ht-1);if(!y)throw new Error(qd(c.name,p,r,ht-1,"offer"));const b={kind:Xi,version:1,item:t,buyer:c.id,seller:l.id,price:r,holder:du(u.coin),payers:y.map(du),to:Be(h.wallet.script),pay:Be(d.script),back:Be(f.script),change:y.reduce((m,v)=>m+v.value,0)-r-fe,at:s},w=Qd(b);return b.txid=ie.util.getTxid(w),b.witnesses=y.map((m,v)=>f.sign(w,v+1)),(e.offers??(e.offers=[])).push(b),b}function uc(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(hu(e.chain,n.holder))return`${s} has moved since`;if(n.payers.some(l=>hu(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?Be(l.script):"";return a((u=Te(e.keys,t,o))==null?void 0:u.wallet)!==n.to||a(Ee(e.keys,t,o))!==n.back?`${o.name} has new keys since`:n.price&&a(Ee(e.keys,t,i))!==n.pay?`${i.name} has new keys since`:""}const Ji=(e,t,n)=>e.chain.transactions.has(n.txid)?"done":uc(e,t,n)?"stale":"open";function L2(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}=Jd(e),o=uc(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=Qd(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 R2(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 H2(e){const t=(r,s)=>r&&fu.test(r.txid)&&Number.isSafeInteger(r.vout)&&r.vout>=0&&Number.isSafeInteger(r.value)&&r.value>=Ie&&r.value<=Qe&&s.test(r.script),n=r=>Number.isSafeInteger(r)&&(r===0||r>=Ie&&r<=Qe);if((e==null?void 0:e.kind)!==Xi||e.version!==1||!bi.test(e.item)||!bi.test(e.buyer)||!bi.test(e.seller)||e.buyer===e.seller||!n(e.price)||!n(e.change)||!t(e.holder,lu)||!Array.isArray(e.payers)||!e.payers.length||e.payers.length>ht-1||!e.payers.every(r=>t(r,wi))||!lu.test(e.to)||!wi.test(e.pay)||!wi.test(e.back)||!fu.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:Xi,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 No="orgchain:lab:v1",j2=["each",10,30,60,"manual"];function fs(e={tempo:"each",nextAt:null}){const{tempo:t,nextAt:n}=e??{},r=typeof t=="number";if(!j2.includes(t)||!(n===null||r&&Number.isSafeInteger(n)&&n>0))throw new Error("Invalid clock.");return{tempo:t,nextAt:n}}function th(e){const t=Ja();for(const n of["roots","adopted"])for(const[r,s]of Object.entries((e==null?void 0:e[n])??{})){if(!/^[0-9a-f]{64}i0$/.test(r))throw new Error("Invalid lab keys.");t[n][r]=Bd(s,24)}if(t.scheme=(e==null?void 0:e.scheme)??(Object.keys(t.roots).length?"wallet":"bip86"),!x2.includes(t.scheme))throw new Error("Invalid lab keys.");return t}const K2=["split","last","none"];function ls(e){const t=(e==null?void 0:e.rule)??"split",n={};if(!K2.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 nh(e=[]){if(!Array.isArray(e)||e.length>1e3)throw new Error("Invalid offers.");const t=e.map(H2);if(new Set(t.map(n=>n.txid)).size!==t.length)throw new Error("Invalid offers.");return t}const ds=()=>({wallet:null,chain:new Bo,clock:fs(),keys:Ja(),mining:ls(),offers:[]});function rh(e){if(!e)return ds();const t=JSON.parse(e);if((t==null?void 0:t.kind)!=="orgchain-lab"||t.network!==cn||t.version!==1)throw new Error("That is not an Orgchain v1 lab.");return{wallet:t.wallet?xn.load(t.wallet):null,chain:new Bo(t.chain),clock:fs(t.clock),keys:th(t.keys),mining:ls(t.mining),offers:nh(t.offers)}}const sh=e=>{var t;return JSON.stringify({kind:"orgchain-lab",network:cn,version:1,wallet:((t=e.wallet)==null?void 0:t.backup())??null,chain:e.chain.snapshot(),clock:fs(e.clock),keys:th(e.keys),mining:ls(e.mining),offers:nh(e.offers)})};function D2(e,t,n){var r;e.mining=ls({...e.mining,rigs:{...(r=e.mining)==null?void 0:r.rigs,[t]:n}})}function M2(e,t){e.mining=ls({...e.mining,rule:t})}const fc=()=>rh(localStorage.getItem(No));function Z2(e){try{localStorage.setItem(No,sh(e))}catch{throw new Error("Browser storage is full or unavailable, so nothing was saved. Save a backup, then reset.")}}async function V2(e,{locks:t=(s=>(s=globalThis.navigator)==null?void 0:s.locks)(),read:n=fc,save:r=Z2}={}){if(!t)throw new Error("Orgchain needs Web Locks: open it over HTTPS or on localhost.");return t.request(No,async()=>{const o=n(),i=await e(o);return i!==!1&&r(o),{lab:o,result:i}})}function mt(e,t=null){e.wallet||(e.wallet=xn.create());const n=t!=null&&t.length?e.chain.mineTo(t.map(r=>Ue(r.value,r.script))):e.chain.mine(e.wallet.script);return e.clock=fs({tempo:e.clock.tempo,nextAt:null}),n}function Sr(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 q2(e,t,n=Date.now(),r=null){e.clock=fs({tempo:t,nextAt:null}),t==="each"&&e.chain.mempool.length?mt(e,r):Sr(e,n)}function z2(e,t=Date.now(),n=null){const{tempo:r,nextAt:s}=e.clock;return typeof r!="number"||!e.chain.mempool.length?!1:s===null?(Sr(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}`,graduate:()=>"graduate",close:()=>"close"};function G2(e,t={}){if(!Object.hasOwn(pu,e))throw new Error("Unknown verb.");const n={op:e};for(const r of pu[e]){const s=t[r];typeof s=="string"&&s.trim()&&(n[r]=s.trim())}return n}const _t=e=>bn(_o(new os(e.chain)),{pending:!0});function oh(e,t,n,r){const s=G2(t,r),o=_o(new os(e.chain)),i={id:"check",status:"pending",height:null,metadata:s,parent:n??null,protocol:Ra},{ok:a,why:c}=bn([...o,i],{pending:!0}).log.at(-1);if(!a)throw new Error(`${c[0].toUpperCase()}${c.slice(1)}.`);return s}const Qi=Et+2*fe+330,ih=1e5,lc=1e4,dc=(e,t=0)=>Et+2*fe+(e==="birth"?1:e==="graduate"?Math.max(0,t-1):0)*fe+330,W2=(e,t=0)=>dc(e,t)-330,gr=(e,t,n)=>e.chain.coins(t.script).find(r=>{var s;return!((s=r.inscriptions)!=null&&s.length)&&r.value>=n}),ea=e=>jt(e.txid,e.vout,e.value,e.scriptPubKey),ah=(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=Ja()),e.wallet||(e.wallet=xn.create()),gr(e,e.wallet,ih+fe+330)||mt(e)}function ch(e,t,n=Qi,r=ih){if(t===e.wallet||gr(e,t,n))return;const s=gr(e,e.wallet,r+fe+330),o=ie.create({vin:[ea(s)],vout:[Ue(r,t.script),Ue(s.value-r-fe,e.wallet.script)]});e.chain.submitPackage([ah(o,[e.wallet])])}function gu(e,t,n,r,s){if(r===e.wallet||gr(e,r,s))return;const o=n&&Ee(e.keys,t,n);if(!o)return ch(e,r,s);oc(e,o,r.script,Math.max(lc,s),n.name)}function Y2(e,t,n,r,s){if(r===e.wallet||gr(e,r,s))return!0;const o=n&&Ee(e.keys,t,n);return!o||Wd(e,o,Math.max(lc,s))}function uh(e,t,n,r,s={}){var l,f;const o=r?t.nodes.get(r):null,i=o&&((l=Qa(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&&Te(e.keys,t,a)?Uo(t,a.id).length:0;if(!Y2(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`:((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?Ee(e.keys,t,a):null;return u&&!Gd(e.chain.coins(u.script).filter(d=>d.value-fe>=Ie).map(d=>({value:d.value-fe})),lc)?`${a.name} needs test BTC of its own to claim its new root. Send it some first`:""}function mu(e,t,n,r,s=n){const o=Io(e.chain,t),i=gr(e,s,fe+330),a=ie.create({vin:[ea(o),ea(i)],vout:[Ue(o.value,r.script),Ue(i.value-fe,s.script)]});e.chain.submitPackage([ah(a,[n,s])])}function yu(e,t,n,r,s){return new c1(e.chain,t).inscribe(F2[n](s),r??null,s,{metaprotocol:Ra})}const Lo=(e,t)=>{var r;const n=_t(e);return Vd(e,n,((r=n.nodes.get(t))==null?void 0:r.root)??null)},Ro=(e,t)=>Vd(e,_t(e),t);function pc(e){var r,s,o;const t=_t(e),n=new Map;for(const i of t.nodes.values())for(const a of[Ee(e.keys,t,i),(r=Te(e.keys,t,i))==null?void 0:r.wallet])a&&n.set(Be(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],l=u&&n.get(Be(u.scriptPubKey));if(l)return l}}return null}function bu(e,t,n){var s;const r=Qa(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 fh(e,t,n,r){if(t==="found"){const l=ou(),f=E2(e.keys,l);ch(e,f,Qi,Qi);const d=yu(e,f,t,null,r);return e.keys.roots[d]=l,d}const s=_t(e),o=bu(e,s,n),i=s.nodes.get(n),a=t==="graduate"?s.nodes.get(r.of):null,c=a&&Te(e.keys,s,a)?Uo(s,a.id).map(l=>[l.id,bu(e,s,l.id)]):[];gu(e,s,i,o,dc(t,c.length));const u=yu(e,o,t,n,r);if(t==="birth"){const l=_t(e),f=Te(e.keys,l,l.nodes.get(u));f&&mu(e,u,o,f.wallet)}if(c.length){e.keys.adopted[a.id]=ou();const l=_t(e);for(const[f,d]of c){const h=Te(e.keys,l,l.nodes.get(f)).wallet;if(I2(e,Ee(e.keys,s,s.nodes.get(f)),Ee(e.keys,l,l.nodes.get(f))),f!==a.id){mu(e,f,d,h,o);continue}gu(e,l,l.nodes.get(f),h,fe+330),Vx(e.chain,Zx(e.chain,f,h),d)}}return u}function X2(e,t,n,r,s=Date.now()){const o=oh(e,t,n,r),i=uh(e,_t(e),t,n??null,o);if(i)throw new Error(`${i}.`);hc(e);const a=fh(e,t,n??null,o);return e.clock.tempo==="each"?mt(e,Lo(e,n??a)):Sr(e,s),a}function J2(e,t,n,r,s=Date.now()){const o=Yd(e,_t(e),t,n,r);return e.clock.tempo==="each"?mt(e,Lo(e,t)):Sr(e,s),o}const Q2=(e,t,n,r,s=Date.now())=>eh(e,t,n,r,s);function ev(e,t,n=Date.now()){const r=L2(e,t);return e.clock.tempo==="each"?mt(e,Lo(e,r.seller)):Sr(e,n),r}const tv=(e,t)=>R2(e,t);function nv(e,t,n,r=Date.now()){const s=_t(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=Ee(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)||nQe)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),Wd(e,e.wallet,n)||mt(e);const a=oc(e,e.wallet,i.script,n,"The lab wallet","fund");return e.clock.tempo==="each"?mt(e,Lo(e,t)):Sr(e,r),a}const ta="yolopreneur",rv=[[["found",null,{name:"yolopreneur"}]],[["birth","yolopreneur",{name:"well-known",kind:"org"}],["birth","yolopreneur",{name:"time",kind:"org"}]],[["send","yolopreneur",{to:"time",amount:40}],["send","yolopreneur",{to:"well-known",amount:10}],["birth","well-known",{name:"mailr",kind:"org"}],["birth","well-known",{name:"lineage",kind:"org"}],["birth","time",{name:"luna",kind:"agent"}],["birth","time",{name:"sol",kind:"agent"}],["birth","time",{name:"astra",kind:"agent"}]],[["send","well-known",{to:"lineage",amount:2}],["birth","time",{name:"docscope",kind:"org"}],["birth","time",{name:"dollhouse",kind:"org"}],["birth","time",{name:"doodleloop",kind:"org"}],["birth","time",{name:"hearthframe",kind:"org"}]],[["send","time",{to:"sol",amount:1}],["send","time",{to:"luna",amount:.5}],["award","time",{to:"sol",skill:"launch",belt:"green"}],["award","time",{to:"luna",skill:"post",belt:"white"}],["decide","yolopreneur",{title:"Every venture gets a page",why:".yolopreneur.lol, served from one pages branch."}],["make","sol",{name:"launch-kit",note:"The page, the post and the checklist every venture launches with."}]],[["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 sv(e){hc(e),e.chain.mempool.length&&mt(e);const t={},n={};for(const r of rv){for(const[s,o,i]of r){if(s==="send"){Yd(e,_t(e),t[o],t[i.to],i.amount*Jr);continue}if(s==="offer"){eh(e,n[i.item],t[o],i.price*Jr);continue}const a=Object.fromEntries(Object.entries(i).map(([l,f])=>[l,l==="to"||l==="of"?t[f]:f])),c=o?t[o]:null,u=fh(e,s,c,oh(e,s,c,a));(s==="found"||s==="birth")&&(t[i.name]=u),s==="make"&&(n[i.name]=u)}mt(e,Ro(e,t[ta]))}return t[ta]}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 Ur=(e,t)=>`${e} ${t}${e===1?"":"s"}`,un=e=>e==="cued"?"cued":`beat ${e}`,ov=e=>new Date(e).toLocaleTimeString([],{hour:"2-digit",minute:"2-digit",second:"2-digit"}),wu=e=>JSON.stringify(e,(t,n)=>typeof n=="bigint"?String(n):n,2),T={holding:null,node:null,event:null,tx:null,beat:null,verb:"birth",busy:!1,replay:null,closing:null,reveal:null};let q=ds(),mo=new os(q.chain),on=[],F=bn([]),qe=F,Le={owner:new Map,ledger:[],now:new Map,view:new Map},fn=new Map;const Xe=()=>q.chain.blocks.length,na=()=>on.filter(e=>e.status==="pending").length,ra=e=>Le.ledger.filter(t=>t.beat===null&&t.kind===e).length,Ns=[["pay","cued send"],["deal","cued deal"],["fund","cued deposit"]],iv=()=>na()+Ns.reduce((e,[t])=>e+ra(t),0),En=e=>{var t;return((t=F.items.get(e))==null?void 0:t.name)??"an item"},sa=()=>q.offers??[],Ls=e=>Le.view.get(e)??0,lh=e=>Le.now.get(e)??0,X=(e,t=F)=>e?t.nodes.get(e)??null:null,av=e=>{var t;return!!e&&(e.root===T.holding||((t=X(e.parent))==null?void 0:t.root)===T.holding)},gc=e=>Object.assign(T,{event:null,tx:null,closing:null,reveal:null},e),$r=e=>{gc(e),Ho()};function ye(e,t=!1){const n=D("say");n.textContent=e,n.classList.toggle("bad",t)}function dh(){try{q=fc()}catch(e){q=ds(),ye(`This browser's saved lab could not be read (${e.message}) Load a backup, or reset to start over.`,!0)}mc()}function mc(){var n;mo=new os(q.chain),on=_o(mo),F=bn(on,{pending:!0}),T.beat!==null&&T.beat>=Xe()&&(T.beat=null),X(T.holding)||(T.holding=((n=F.roots.filter(r=>r.kind==="holding").at(-1)??F.roots.at(-1))==null?void 0:n.id)??null),av(X(T.node))||(T.node=T.holding),T.event&&!F.log.some(r=>r.id===T.event)&&(T.event=null),qe=T.beat===null?F:bn(on,{upTo:T.beat});const e=C2(q.keys,on,F),t=new Map(sa().map(r=>[r.txid,r]));Le={owner:e,ledger:N2(q.chain,e,P2(q.keys,on,F),t),now:Yi(q.chain,e)},fn=new Map([...F.items.keys()].map(r=>{var s;return[r,((s=cc(q,on,F,r))==null?void 0:s.node.id)??null]})),Le.view=T.beat===null?Le.now:Yi(q.chain,e,T.beat),T.tx&&!Le.ledger.some(r=>r.key===T.tx)&&(T.tx=null),Ho()}function yo(e){T.beat=e>=Xe()?null:Math.max(0,e),qe=T.beat===null?F:bn(on,{upTo:T.beat}),Le.view=T.beat===null?Le.now:Yi(q.chain,Le.owner,T.beat),Ho()}async function ot(e,t){if(T.busy)return!1;T.busy=!0,document.body.classList.add("busy");try{return q=(await V2(e,t)).lab,!0}catch(n){return ye((n==null?void 0:n.message)||String(n),!0),!1}finally{T.busy=!1,document.body.classList.remove("busy"),mc()}}async function Fn(e,t,n,r){let s=null;if(!await ot(i=>{s=X2(i,e,t,n)}))return!1;const o=mo.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")),Ho(),!0}async function hh(e){const t=[na(),...Ns.map(([a])=>ra(a))],n=Xe();if(!await ot(e)||Xe()===n)return;const r=[na(),...Ns.map(([a])=>ra(a))],s=["cued act",...Ns.map(([,a])=>a)],o=t.map((a,c)=>[a-r[c],s[c]]).filter(([a])=>a>0).map(([a,c])=>Ur(a,c)),i=cv(Le.ledger.filter(a=>a.kind==="mine"&&a.beat===Xe()));ye(`Beat ${Xe()}: ${o.length?`${o.join(" and ")} landed, and ${i}`:i}.`)}function cv(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=>ec(r.amount));return e.length===1?`${t[0]} earned ${ae(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 uv(){var t;if(((t=q.mining)==null?void 0:t.rule)==="last")return"the holding that acts";const e=nc(q,F);return e.length?e.length===1?e[0].name:`${e.length} holdings, split by hashrate`:"the lab wallet"}function Ho(){ph(),dv(),hv(),jo(),Eh(),yc()}function ph(){const e=iv(),{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(Xe()),D("clock-cued").textContent=e?`${e} cued · ${fv()}`:"nothing cued";const n=uv();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 fv(){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 lv={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 dv(){var a,c;const e=((a=q.mining)==null?void 0:a.rule)??"split",t=e==="split",n=t?nc(q,F):[],r=n.reduce((u,l)=>u+rr(q,l.id),0);D("holdings-list").replaceChildren(...F.roots.map(u=>{var b;const l=h1(F,u.id),f=u.id===T.holding,d=u.status==="active",h=n.some(w=>w.id===u.id)?rr(q,u.id)/r:0,p=[...F.nodes.values()].reduce((w,m)=>w+(m.root===u.id?lh(m.id):0),0),y=[u.graduated!==null&&`from ${((b=X(u.parent))==null?void 0:b.name)??"?"}${u.graduated==="cued"?", cued":` at beat ${u.graduated}`}`||un(u.born),Ur(l.orgs,"org"),Ur(l.agents,"agent"),Ur(l.belts,"belt"),p>0&&ec(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:()=>$r({holding:u.id,node:u.id})},A("span",{class:"hn",text:u.name})," ",A("span",{class:"hm",text:y.join(" · ")})),t&&d&&Ee(q.keys,F,u)&&mv(u,rr(q,u.id)))}));for(const u of document.querySelectorAll("[data-rule]"))u.setAttribute("aria-pressed",String(e===u.dataset.rule));D("mining-note").textContent=lv[e];const s=F.roots.filter(u=>u.status==="active"&&Ee(q.keys,F,u)),o=D("fund-to"),i=o.value;D("f-fund").hidden=e!=="none"||!s.length||T.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===T.holding)?T.holding:((c=s[0])==null?void 0:c.id)??"",D("fund-has").textContent=ae(q.wallet?ac(q.chain,q.wallet):0),D("holdings-empty").hidden=F.roots.length>0,D("holdings-sub").textContent=F.roots.length?String(F.roots.length):"",D("sample").disabled=F.roots.some(u=>u.name===ta&&u.status==="active")}function hv(){var r;const e=D("tree-rows"),t=X(T.holding);if(D("tree-sub").textContent=t?`${t.name} · ${T.beat===null?"now":`beat ${T.beat} of ${Xe()}`}`:"",!t)return e.replaceChildren(A("p",{class:"wait",text:"No holding yet. Found one, or load the yolopreneur sample."}));if(!qe.nodes.has(t.id))return e.replaceChildren(A("p",{class:"wait",text:`${t.name} is founded at ${un(t.born)}. Move the slider forward.`}));const n=e.contains(document.activeElement)?document.activeElement.dataset.id:null;e.replaceChildren(...d1(qe,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})):pv(s))),n&&((r=e.querySelector(`[data-id="${n}"]`))==null||r.focus())}function pv({node:e,guide:t,path:n,away:r}){const s=e.id===T.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:()=>$r({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"},gv(e))))}function gv(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(gh),Ls(e.id)>0&&A("span",{class:"mk sats",title:`${ae(Ls(e.id))} at its SegWit address`,text:ec(Ls(e.id))})].filter(Boolean).flatMap((n,r)=>r?[" ",n]:[n])}const gh=e=>A("span",{class:`belt ${e.belt}`,title:`${e.skill}: ${e.belt} belt`},e.skill,A("span",{class:"sr",text:` (${e.belt} belt)`})),mh=(e,t)=>{for(let n=X(e.parent);n;n=X(n.parent))if(n.id===t.id)return!0;return!1},yh=e=>[...F.nodes.values()].filter(t=>t.id!==e.id&&t.status==="active").map(t=>[t,(t.root===e.root?0:4)+(mh(t,e)?0:2)+(t.kind==="agent"?0:1)]).sort((t,n)=>t[1]-n[1]).map(([t])=>t),bh=e=>e.children.reduce((t,n)=>{const r=X(n);return r&&r.edge==="derived"&&r.status==="active"?t+1+bh(r):t},0);function mv(e,t){const n=async r=>{await ot(s=>D2(s,e.id,r))&&ye(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 wh=e=>[...F.nodes.values()].filter(t=>t.id!==e.id&&t.status==="active").map(t=>[t,(t.root===e.root?0:4)+(mh(t,e)?0:2)+(t.kind==="agent"?0:1)]).sort((t,n)=>t[1]-n[1]).map(([t])=>t);function yv(e){const t=Ee(q.keys,F,e);return t?sc(q.chain.coins(t.script))[...F.items.values()].map(t=>[t,X(fn.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 bv(e){const t=Ee(q.keys,F,e);return t?vh(e).length?q.chain.coins(t.script).some(n=>n.value>=fe+Ie||n.value===fe)?"":xh(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 wv(e){const t=X(e.parent),n=e.status==="closed"?`${e.name} is closed`:"",r=(s,o=e.id,i={})=>uh(q,F,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":yh(e).length?r("award"):"There is nobody else to award yet"),decide:n||r("decide"),make:n||r("make"),send:n||yv(e),offer:n||bv(e),graduate:n||(t?e.kind!=="org"?"Only orgs graduate":e.edge==="adopted"?`${e.name} has already graduated`:t.status!=="active"?`${t.name} is closed`:r("graduate",t.id,{of:e.id}):"A holding has no parent to graduate from"),close:n||r("close")}}function jo(){const e=X(T.node),t=T.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(T.beat??""),!e||t)return;const n=wv(e),r=X(e.parent);for(const h of document.querySelectorAll("[data-verb]"))h.setAttribute("aria-pressed",String(h.dataset.verb===T.verb)),h.classList.toggle("off",!!n[h.dataset.verb]);for(const h of document.querySelectorAll("form[data-form]"))h.hidden=h.dataset.form!==T.verb||!!n[T.verb];D("act-why").textContent=n[T.verb]?`${n[T.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(p=>`${p.value}=${p.textContent}`).join("|"),o=[[D("award-to"),yh(e).map(h=>[h.id,`${lr(F,h.id)}${h.kind==="agent"?" (agent)":""}`])],[D("send-to"),wh(e).map(h=>[h.id,`${lr(F,h.id)}${h.kind==="agent"?" (agent)":""}`])],[D("offer-item"),vh(e).map(h=>[h.id,`${h.name} · held by ${kt(fn.get(h.id))}`])]];for(const[h,p]of o){const g=h.value,y=p.map(([b,w])=>A("option",{value:b,text:w}));s(y)!==s([...h.options])&&(h.replaceChildren(...y),y.some(b=>b.value===g)&&(h.value=g))}for(const h of["send-has","offer-has"])D(h).textContent=ae(lh(e.id));D("graduate-go").textContent=`Graduate ${e.name}`;const i=T.verb==="graduate"?r:e,a=i&&Te(q.keys,F,i),c=T.verb==="send"||T.verb==="offer",u=a&&(c?`${a.from} · ${Ee(q.keys,F,i).path}`:a.path);D("act-key").textContent=!i||n[T.verb]?"":a?`Signs as ${i.name}: ${u}`:"Signs with the lab wallet: this holding predates lab keys.";const l=T.verb==="graduate"&&Te(q.keys,F,e)?Uo(F,e.id).length:0;D("act-gas").textContent=!i||n[T.verb]||!a?"":T.verb==="send"?`Fee: ${fe} sats, from ${e.name}'s balance.`:T.verb==="offer"?`Fee: ${fe} sats, from ${e.name}'s balance, paid only if the holder accepts.`:`Gas: ${W2(T.verb,l).toLocaleString("en-US")} sats from ${i.name}'s tank (${ae(ac(q.chain,a.wallet))}), which tops up from its balance.${l?` ${e.name} pays ${fe} more, from its own money, to claim its new root.`:""}`;const f=bh(e),d=T.closing===e.id;D("close-note").textContent=f?`Closing ${e.name} spends it for the last time, and its ${Ur(f,"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=d?`Yes, close ${e.name}`:`Close ${e.name}`,D("close-keep").hidden=!d}function Eh(){const e=D("inspect-body"),t=T.event?F.log.find(o=>o.id===T.event):null;if(t)return D("inspect-sub").textContent="event",e.replaceChildren(...Pv(t));const n=T.tx?Le.ledger.find(o=>o.key===T.tx):null;if(n)return D("inspect-sub").textContent="money",e.replaceChildren(...Uv(n));const r=X(T.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(T.node,qe);if(!s)return e.replaceChildren(A("p",{class:"note pad",text:`${r.name} is not born yet at beat ${T.beat}.`}));e.replaceChildren(...xv(s))}const es=([e,t,n])=>A("div",{class:"f"},A("dt",{text:e}),A("dd",{},t,n&&A("span",{class:"fn",text:n})));function xv(e){const t=X(e.parent,qe),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 ${un(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!==T.holding&&A("button",{type:"button",class:"btn sm open",onclick:()=>{$r({holding:e.id,node:e.id}),Sv()}},`Open ${e.name}`))],e.closed!==null&&["Closed",un(e.closed)],["Children",e.children.length?e.children.map(r=>{var s;return(s=X(r,qe))==null?void 0:s.name}).join(", "):"none yet"],Ee(q.keys,qe,e)&&["Balance",ae(Ls(e.id)),`Test BTC at its SegWit address${T.beat===null?"":`, as of beat ${T.beat}`}.`],T.beat===null&&Te(q.keys,F,e)&&["Gas tank",ae(ac(q.chain,Te(q.keys,F,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:lr(qe,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(es)),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",{},gh(r),A("span",{class:"when",text:` from ${((s=X(r.by))==null?void 0:s.name)??"?"}, ${un(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:` (${un(r.beat)})`}))))),vv(e),$v(e),Tv(e))]}function vv(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(T.beat!==null)return t("Made",e.made.map(a=>qe.items.get(a)).filter(Boolean).map(a=>n(a,un(a.beat))));const r=a=>`made${a.maker===e.id?"":` by ${kt(a.maker)}`}${a.beat==="cued"?", cued":` at beat ${a.beat}`}`,s=[...F.items.values()].filter(a=>fn.get(a.id)===e.id).map(a=>{const c=n(a,r(a)),u=sa().filter(l=>l.item===a.id&&l.seller===e.id&&Ji(q,F,l)==="open");return u.length&&c.append(A("ul",{class:"bids"},u.map(l=>A("li",{},A("span",{text:`${kt(l.buyer)} offers ${l.price?ae(l.price):"nothing, a free claim"}`}),e.status==="active"&&A("button",{type:"button",class:"btn sm","aria-label":`Accept ${kt(l.buyer)}'s offer for ${a.name}`,onclick:()=>Ev(l)},"Accept"))))),c}),o=e.made.map(a=>F.items.get(a)).filter(a=>a&&fn.get(a.id)!==e.id).map(a=>n(a,fn.get(a.id)?`now held by ${kt(fn.get(a.id))}`:"held outside this lab")),i=sa().filter(a=>a.buyer===e.id&&Ji(q,F,a)!=="done").map(a=>{const c=uc(q,F,a);return A("li",{},A("b",{text:a.price?ae(a.price):"nothing"}),` for ${En(a.item)}`,A("span",{class:"when",text:c?` (stale: ${c})`:` (open until ${kt(a.seller)} accepts)`}),A("button",{type:"button",class:"btn sm","aria-label":`Withdraw the offer for ${En(a.item)}`,onclick:()=>kv(a)},"Withdraw"))});return[t("Items",s),t("Made, held elsewhere",o),t("Offers made",i)]}const kt=e=>{const t=X(e);return t?t.root===T.holding?t.name:lr(F,e):"?"};async function Ev(e){const t=En(e.item),n=kt(e.buyer),r=kt(e.seller);if(!await ot(o=>{ev(o,e.txid)}))return;const s=Le.ledger.find(o=>o.txid===e.txid);ye(`${r} accepted: ${t} goes to ${n}${e.price?` for ${ae(e.price)}`:", free"}, ${s!=null&&s.beat?`at beat ${s.beat}`:"cued for the next beat"}.`)}async function kv(e){const t=En(e.item),n=kt(e.buyer);await ot(r=>{tv(r,e.txid)})&&ye(`${n} withdrew its offer for ${t}.`)}function Sv(){const e=document.querySelector(".tree-blk").getBoundingClientRect().top+scrollY-document.querySelector(".clock").offsetHeight-12;e(n.to===e.id||n.from===e.id)&&(T.beat===null||n.beat!==null&&n.beat<=T.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:_v(n,e.id)}),A("span",{class:"when",text:` (${un(n.beat??"cued")})`})))))}function _v(e,t){const n=r=>{var s;return((s=X(r))==null?void 0:s.name)??"?"};if(e.kind==="mine")return`+${ae(e.amount)}, a beat's reward`;if(e.kind==="move")return`${ae(e.amount)} moved to its new key, after a ${e.fee}-sat fee`;if(e.kind==="gas")return`−${ae(e.amount)} into its gas tank, and a ${e.fee}-sat fee`;if(e.kind==="fund")return`+${ae(e.amount)} from the lab wallet`;if(e.kind==="deal"){const r=En(e.item);return e.to===t?e.amount?`+${ae(e.amount)} from ${n(e.from)} for ${r}`:`${r} to ${n(e.from)}, free`:e.amount?`−${ae(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?`+${ae(e.amount)} from ${n(e.from)}`:`−${ae(e.amount)} to ${n(e.to)}, and a ${e.fee}-sat fee`}function kh(e){const t=n=>{const r=X(n);return r?r.root===T.holding?r.name:lr(F,n):"?"};return e.kind==="mine"?`${ae(e.amount)} → ${t(e.to)}`:e.kind==="move"?`${ae(e.amount)} → ${t(e.to)}'s new key`:e.kind==="gas"?`${ae(e.amount)} → ${t(e.to)}'s gas tank`:e.kind==="fund"?`${ae(e.amount)} lab wallet → ${t(e.to)}`:e.kind==="deal"?`${En(e.item)} ${t(e.to)} → ${t(e.from)}, ${e.amount?`for ${ae(e.amount)}`:"free"}`:`${ae(e.amount)} ${t(e.from)} → ${t(e.to)}`}const Av={own:"its own key",lab:"the lab wallet",parent:"its parent's key (its handoff is cued)",other:"a key outside this lab"},Bv={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 Tv(e){const t=Te(q.keys,qe,e),n=Qa(q,F,e.id),r=["Held now by",n?Av[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(es)));const s=e.kind==="agent",o=k2(q.keys,qe,e),i=S2(q.keys,qe,e),a=i.map(([,,d])=>d).filter(Boolean),c="Reset the lab for standard BIP-86 keys.",u=s?"Holds this seat's inscription, and inscriptions sent to it land here.":"Holds this org's inscription and signs its acts. Inscriptions sent to it land here.",l={bip86:`BIP-86 at ${o.taproot.path}. ${u}`,tapkey:`Its npub's key with the BIP-86 tweak, the way v1.2 keyed this lab. ${u} ${c}`,wallet:`An untweaked key at ${o.taproot.path}, the way v1.1 keyed this lab. ${u} ${c}`}[t.scheme],f=[["Taproot",o.taproot.address,l],["SegWit",o.segwit.address,`BIP-84 at ${o.segwit.path}. Its money: ${e.kind==="holding"?"the beats it earns land here, and ":""}sends come and go here.`],["Tapkey",o.tapkey.address,"Its npub as a Taproot address (its nostr key with the BIP-86 tweak), so the npub alone finds it. Nostr secrets get pasted into clients, so treat it as an inbox."],["npub",o.npub.address,`NIP-06 at ${o.npub.path}. Its nostr name; the leaves below hang off it.`],["From",`${t.from} · account ${t.account}`],r];return A("div",{class:"keys"},A("p",{class:"lab",text:"Keys"}),A("dl",{class:"fl"},f.map(es)),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:` ${Bv[d]}`}),A("code",{text:h})))),Nr(s?"Public lines to paste":"CA key for TrustedUserCAKeys",a.join(` + +`)),Iv(e,t))}function Nr(e,t,n=t){const r=A("pre",{text:n}),s=A("button",{type:"button",class:"cp","aria-label":`Copy ${e}`,onclick:()=>Ov(t,s,r)},"Copy");return A("div",{class:"code"},A("div",{class:"code-h cph"},A("span",{text:e}),s),r)}async function Ov(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 Iv(e,t){var a;const n=T.reveal===e.id,r=n&&T2(q.keys,qe,e),s=X(e.parent,qe),o=()=>{var c;T.reveal=n?null:e.id,Eh(),(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?Nr(`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])=>Nr(`${c} · ${u}`,l)),r.leaves.map(([c,u,l])=>Nr(`${c} · ${u}`,l))))}function Cv(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=La(t).pubkey,r=X(e.parent),s=e.op==="found"?X(e.node):null,o=[[s&&Te(q.keys,F,s),`${s==null?void 0:s.name}'s root`],[r&&Te(q.keys,F,r),`${r==null?void 0:r.name}'s key`],[(r==null?void 0:r.edge)==="adopted"&&Te(q.keys,F,{...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 Pv(e){var o,i,a;const t=mo.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",Cv(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:Cl(e,F)}),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(es)),A("div",{class:"code"},A("p",{class:"code-h",text:"Metadata · CBOR, tag 5"}),A("pre",{text:wu(e.meta)})),s&&A("div",{class:"code"},A("p",{class:"code-h",text:"Raw index entry"}),A("pre",{text:wu(s)})))]}function Uv(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",`${En(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":ae(e.amount)],e.kind!=="mine"&&["Fee",`${e.fee} sats, retired: this toy chain pays no fees to miners`],e.change>0&&["Change",`${ae(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:kh(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(es)),n&&Nr("Raw transaction",n.raw))]}function yc(){const e=Xe(),t=D("beat"),n=X(T.holding);t.max=String(e),t.value=String(T.beat??e),t.disabled=e===0,D("beat-label").textContent=T.beat===null?`Now · beat ${e}`:`Beat ${T.beat} of ${e}`,D("replay").textContent=T.replay?"Stop":"Replay",D("replay").disabled=!n||e===0,D("to-now").disabled=T.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 F.log)a.roots.includes(T.holding)&&o(a.pending?"cued":a.beat,{e:a,at:s.get(a.id.slice(0,-2))??0});for(const a of Le.ledger)[a.to,a.from].some(c=>{var u;return c&&((u=X(c))==null?void 0:u.root)===T.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=T.beat!==null&&(a==="cued"||a>T.beat),l=T.beat!==null&&a===T.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?ov(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?Lv(d):Nv(f))))}))}function Nv(e){const[t,...n]=Cl(e,F).split(" ");return A("li",{},A("button",{type:"button",class:`ev${e.ok?"":" bad"}${e.id===T.event?" on":""}`,"aria-pressed":String(e.id===T.event),onclick:()=>$r({event:e.id,node:e.node??T.node})},A("span",{class:"op",text:e.ok?t:`✕ ${t.replace(/:$/,"")}`})," ",A("span",{class:"es",text:n.join(" ")})))}const Lv=e=>A("li",{},A("button",{type:"button",class:`ev money${e.kind==="gas"?" gas":""}${e.kind==="deal"?" deal":""}${e.key===T.tx?" on":""}`,"aria-pressed":String(e.key===T.tx),onclick:()=>{var t;return $r({tx:e.key,node:((t=X(e.to))==null?void 0:t.root)===T.holding?e.to:T.node})}},A("span",{class:"op",text:e.kind})," ",A("span",{class:"es",text:kh(e)})));D("f-found").addEventListener("submit",async e=>{e.preventDefault();const t=e.currentTarget,n=$o(t.elements.name.value);if(!n)return ye("Name the holding: lowercase letters, digits and hyphens.",!0);await Fn("found",null,{name:n},(r,s)=>(gc({holding:r,node:r}),`${n} is founded, ${s}.`))&&t.reset()});D("sample").addEventListener("click",async()=>{let e=null;ye("Rehearsing the yolopreneur tree over six beats…"),await ot(t=>{e=sv(t)})&&($r({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."))});D("f-birth").addEventListener("submit",async e=>{e.preventDefault();const t=e.currentTarget,n=X(T.node),r=$o(t.elements.name.value),s=t.elements.kind.value;if(!r)return ye("Name the child: lowercase letters, digits and hyphens.",!0);await Fn("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(T.node),r=t.elements.to.value,s=$o(t.elements.skill.value),o=t.elements.belt.value;if(!s)return ye("Name the skill, for example launch.",!0);await Fn("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(T.node),r=t.elements.title.value.trim(),s=t.elements.why.value.trim();if(!r)return ye("A decision needs a title.",!0);await Fn("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(T.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 ot(c=>{o=J2(c,n.id,r,s)}))return;const i=Le.ledger.find(c=>c.txid===o);ye(`${n.name} sent ${ae(s)} to ${((a=X(r))==null?void 0:a.root)===n.root?X(r).name:lr(F,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(T.node),r=$o(t.elements.name.value),s=t.elements.note.value.trim();if(!r)return ye("Name the item: lowercase letters, digits and hyphens.",!0);await Fn("make",n.id,{name:r,note:s},(o,i)=>`${n.name} made ${r}, ${i}.`)&&t.reset()});D("f-offer").addEventListener("submit",async e=>{e.preventDefault();const t=e.currentTarget,n=X(T.node),r=D("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=kt(fn.get(r)),i=En(r);await ot(a=>{Q2(a,r,n.id,s)})&&(ye(`${n.name} offers ${s?ae(s):"nothing"} for ${i}. The offer stands until ${o} accepts it.`),t.elements.price.value="")});D("send-max").addEventListener("click",()=>{const e=X(T.node),t=e&&Ee(q.keys,F,e);t&&(D("send-amount").value=Md(sc(q.chain.coins(t.script))))});D("f-graduate").addEventListener("submit",async e=>{e.preventDefault();const t=X(T.node),n=X(t.parent);await Fn("graduate",n.id,{of:t.id},(r,s)=>(gc({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(T.node);if(T.closing!==t.id)return T.closing=t.id,jo(),D("close-go").focus();T.closing=null,await Fn("close",t.id,{},(n,r)=>`${t.name} is closed, ${r}.`)});D("close-keep").addEventListener("click",()=>{T.closing=null,jo(),D("close-go").focus()});for(const e of document.querySelectorAll("[data-verb]"))e.addEventListener("click",()=>{T.verb=e.dataset.verb,T.closing=null,jo()});for(const e of document.querySelectorAll("[data-rule]"))e.addEventListener("click",async()=>{const t=e.dataset.rule;await ot(n=>M2(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])});D("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 ot(a=>{s=nv(a,n,r)}))return;const o=Le.ledger.find(a=>a.txid===s);ye(`The lab wallet funded ${(i=X(n))==null?void 0:i.name} with ${ae(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 ot(r=>q2(r,n,Date.now(),Ro(r,pc(r)??T.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.`)});D("beat-now").addEventListener("click",()=>hh(e=>{mt(e,Ro(e,pc(e)??T.holding))}));setInterval(()=>{ph();const{tempo:e,nextAt:t}=q.clock;T.busy||document.hidden||typeof e!="number"||!q.chain.mempool.length||t&&Date.now()z2(n,Date.now(),Ro(n,pc(n)??T.holding)))},1e3);addEventListener("storage",e=>{(e.key===No||e.key===null)&&dh()});function hs(){T.replay&&(clearInterval(T.replay),T.replay=null,yc())}function Rv(){const e=X(T.holding);if(!(!e||!Xe())){if(yo(typeof e.born=="number"?e.born:Xe()),T.beat===null)return ye("Nothing to replay yet: this holding has one beat of history.");T.replay=setInterval(()=>{(T.beat===null||T.beat+1>=Xe())&&hs(),yo(T.beat===null?Xe():T.beat+1)},800),yc()}}D("beat").addEventListener("input",e=>{hs(),yo(Number(e.target.value))});D("replay").addEventListener("click",()=>T.replay?hs():Rv());for(const e of["to-now","past-now"])D(e).addEventListener("click",()=>{hs(),yo(Xe())});const xi=["system","light","dark"],Sh=()=>{D("theme").textContent=`Theme: ${document.documentElement.dataset.theme??"system"}`};D("theme").addEventListener("click",()=>{const e=xi[(xi.indexOf(document.documentElement.dataset.theme??"system")+1)%xi.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{}Sh()});function $h(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 Hv={read:()=>{try{return fc()}catch{return ds()}}};async function _h(e,t){hs(),await ot(n=>{Object.assign(n,e())},Hv)&&(Object.assign(T,{holding:null,node:null,event:null,tx:null,beat:null,closing:null}),mc(),ye(t))}D("save").addEventListener("click",()=>{const e=A("a",{href:URL.createObjectURL(new Blob([sh(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.")});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=rh(await t.text())}catch(s){return ye(`${t.name} is not an Orgchain lab: ${s.message}`,!0)}$h(`Replace this browser's lab with ${t.name}?`,"Replace",()=>_h(()=>n,`Loaded ${t.name}.`))});D("reset").addEventListener("click",()=>$h("Erase this browser's lab: every holding, the chain and the test wallet?","Erase",()=>_h(ds,"Erased. This is a fresh lab.")));Sh();dh(); diff --git a/ventures/lineage/orgchain/index.html b/ventures/lineage/orgchain/index.html index 534a942..e00f687 100644 --- a/ventures/lineage/orgchain/index.html +++ b/ventures/lineage/orgchain/index.html @@ -8,8 +8,8 @@ - - + +
@@ -150,7 +150,7 @@