@stacks/auth
Version:
Authentication for Stacks apps.
2 lines • 198 kB
JavaScript
/*! For license information please see index.js.LICENSE.txt */
!function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e():"function"==typeof define&&define.amd?define([],e):"object"==typeof exports?exports.StacksAuth=e():t.StacksAuth=e()}(this,(()=>(()=>{var t,e,n={3525:(t,e)=>{"use strict";function n(t){if(!Number.isSafeInteger(t)||t<0)throw new Error(`Wrong positive integer: ${t}`)}function r(t){if("boolean"!=typeof t)throw new Error(`Expected boolean, not ${t}`)}function i(t,...e){if(!(t instanceof Uint8Array))throw new TypeError("Expected Uint8Array");if(e.length>0&&!e.includes(t.length))throw new TypeError(`Expected Uint8Array of length ${e}, not of length=${t.length}`)}function o(t){if("function"!=typeof t||"function"!=typeof t.create)throw new Error("Hash should be wrapped by utils.wrapConstructor");n(t.outputLen),n(t.blockLen)}function s(t,e=!0){if(t.destroyed)throw new Error("Hash instance has been destroyed");if(e&&t.finished)throw new Error("Hash#digest() has already been called")}function a(t,e){i(t);const n=e.outputLen;if(t.length<n)throw new Error(`digestInto() expects output buffer of length at least ${n}`)}Object.defineProperty(e,"__esModule",{value:!0}),e.output=e.exists=e.hash=e.bytes=e.bool=e.number=void 0,e.number=n,e.bool=r,e.bytes=i,e.hash=o,e.exists=s,e.output=a;const c={number:n,bool:r,bytes:i,hash:o,exists:s,output:a};e.default=c},9350:(t,e,n)=>{"use strict";Object.defineProperty(e,"__esModule",{value:!0}),e.SHA2=void 0;const r=n(3525),i=n(64);class o extends i.Hash{constructor(t,e,n,r){super(),this.blockLen=t,this.outputLen=e,this.padOffset=n,this.isLE=r,this.finished=!1,this.length=0,this.pos=0,this.destroyed=!1,this.buffer=new Uint8Array(t),this.view=(0,i.createView)(this.buffer)}update(t){r.default.exists(this);const{view:e,buffer:n,blockLen:o}=this,s=(t=(0,i.toBytes)(t)).length;for(let r=0;r<s;){const a=Math.min(o-this.pos,s-r);if(a!==o)n.set(t.subarray(r,r+a),this.pos),this.pos+=a,r+=a,this.pos===o&&(this.process(e,0),this.pos=0);else{const e=(0,i.createView)(t);for(;o<=s-r;r+=o)this.process(e,r)}}return this.length+=t.length,this.roundClean(),this}digestInto(t){r.default.exists(this),r.default.output(t,this),this.finished=!0;const{buffer:e,view:n,blockLen:o,isLE:s}=this;let{pos:a}=this;e[a++]=128,this.buffer.subarray(a).fill(0),this.padOffset>o-a&&(this.process(n,0),a=0);for(let t=a;t<o;t++)e[t]=0;!function(t,e,n,r){if("function"==typeof t.setBigUint64)return t.setBigUint64(e,n,r);const i=BigInt(32),o=BigInt(4294967295),s=Number(n>>i&o),a=Number(n&o),c=r?4:0,u=r?0:4;t.setUint32(e+c,s,r),t.setUint32(e+u,a,r)}(n,o-8,BigInt(8*this.length),s),this.process(n,0);const c=(0,i.createView)(t),u=this.outputLen;if(u%4)throw new Error("_sha2: outputLen should be aligned to 32bit");const f=u/4,l=this.get();if(f>l.length)throw new Error("_sha2: outputLen bigger than state");for(let t=0;t<f;t++)c.setUint32(4*t,l[t],s)}digest(){const{buffer:t,outputLen:e}=this;this.digestInto(t);const n=t.slice(0,e);return this.destroy(),n}_cloneInto(t){t||(t=new this.constructor),t.set(...this.get());const{blockLen:e,buffer:n,length:r,finished:i,destroyed:o,pos:s}=this;return t.length=r,t.pos=s,t.finished=i,t.destroyed=o,r%e&&t.buffer.set(n),t}}e.SHA2=o},4661:(t,e)=>{"use strict";Object.defineProperty(e,"__esModule",{value:!0}),e.crypto=void 0,e.crypto={node:void 0,web:"object"==typeof self&&"crypto"in self?self.crypto:void 0}},1377:(t,e,n)=>{"use strict";Object.defineProperty(e,"__esModule",{value:!0}),e.hmac=void 0;const r=n(3525),i=n(64);class o extends i.Hash{constructor(t,e){super(),this.finished=!1,this.destroyed=!1,r.default.hash(t);const n=(0,i.toBytes)(e);if(this.iHash=t.create(),"function"!=typeof this.iHash.update)throw new TypeError("Expected instance of class which extends utils.Hash");this.blockLen=this.iHash.blockLen,this.outputLen=this.iHash.outputLen;const o=this.blockLen,s=new Uint8Array(o);s.set(n.length>o?t.create().update(n).digest():n);for(let t=0;t<s.length;t++)s[t]^=54;this.iHash.update(s),this.oHash=t.create();for(let t=0;t<s.length;t++)s[t]^=106;this.oHash.update(s),s.fill(0)}update(t){return r.default.exists(this),this.iHash.update(t),this}digestInto(t){r.default.exists(this),r.default.bytes(t,this.outputLen),this.finished=!0,this.iHash.digestInto(t),this.oHash.update(t),this.oHash.digestInto(t),this.destroy()}digest(){const t=new Uint8Array(this.oHash.outputLen);return this.digestInto(t),t}_cloneInto(t){t||(t=Object.create(Object.getPrototypeOf(this),{}));const{oHash:e,iHash:n,finished:r,destroyed:i,blockLen:o,outputLen:s}=this;return t.finished=r,t.destroyed=i,t.blockLen=o,t.outputLen=s,t.oHash=e._cloneInto(t.oHash),t.iHash=n._cloneInto(t.iHash),t}destroy(){this.destroyed=!0,this.oHash.destroy(),this.iHash.destroy()}}e.hmac=(t,e,n)=>new o(t,e).update(n).digest(),e.hmac.create=(t,e)=>new o(t,e)},6053:(t,e,n)=>{"use strict";Object.defineProperty(e,"__esModule",{value:!0}),e.sha224=e.sha256=void 0;const r=n(9350),i=n(64),o=(t,e,n)=>t&e^t&n^e&n,s=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]),a=new Uint32Array([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]),c=new Uint32Array(64);class u extends r.SHA2{constructor(){super(64,32,8,!1),this.A=0|a[0],this.B=0|a[1],this.C=0|a[2],this.D=0|a[3],this.E=0|a[4],this.F=0|a[5],this.G=0|a[6],this.H=0|a[7]}get(){const{A:t,B:e,C:n,D:r,E:i,F:o,G:s,H:a}=this;return[t,e,n,r,i,o,s,a]}set(t,e,n,r,i,o,s,a){this.A=0|t,this.B=0|e,this.C=0|n,this.D=0|r,this.E=0|i,this.F=0|o,this.G=0|s,this.H=0|a}process(t,e){for(let n=0;n<16;n++,e+=4)c[n]=t.getUint32(e,!1);for(let t=16;t<64;t++){const e=c[t-15],n=c[t-2],r=(0,i.rotr)(e,7)^(0,i.rotr)(e,18)^e>>>3,o=(0,i.rotr)(n,17)^(0,i.rotr)(n,19)^n>>>10;c[t]=o+c[t-7]+r+c[t-16]|0}let{A:n,B:r,C:a,D:u,E:f,F:l,G:h,H:p}=this;for(let t=0;t<64;t++){const e=p+((0,i.rotr)(f,6)^(0,i.rotr)(f,11)^(0,i.rotr)(f,25))+((d=f)&l^~d&h)+s[t]+c[t]|0,y=((0,i.rotr)(n,2)^(0,i.rotr)(n,13)^(0,i.rotr)(n,22))+o(n,r,a)|0;p=h,h=l,l=f,f=u+e|0,u=a,a=r,r=n,n=e+y|0}var d;n=n+this.A|0,r=r+this.B|0,a=a+this.C|0,u=u+this.D|0,f=f+this.E|0,l=l+this.F|0,h=h+this.G|0,p=p+this.H|0,this.set(n,r,a,u,f,l,h,p)}roundClean(){c.fill(0)}destroy(){this.set(0,0,0,0,0,0,0,0),this.buffer.fill(0)}}class f 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}}e.sha256=(0,i.wrapConstructor)((()=>new u)),e.sha224=(0,i.wrapConstructor)((()=>new f))},64:(t,e,n)=>{"use strict";Object.defineProperty(e,"__esModule",{value:!0}),e.randomBytes=e.wrapConstructorWithOpts=e.wrapConstructor=e.checkOpts=e.Hash=e.concatBytes=e.toBytes=e.utf8ToBytes=e.asyncLoop=e.nextTick=e.hexToBytes=e.bytesToHex=e.isLE=e.rotr=e.createView=e.u32=e.u8=void 0;const r=n(4661);if(e.u8=t=>new Uint8Array(t.buffer,t.byteOffset,t.byteLength),e.u32=t=>new Uint32Array(t.buffer,t.byteOffset,Math.floor(t.byteLength/4)),e.createView=t=>new DataView(t.buffer,t.byteOffset,t.byteLength),e.rotr=(t,e)=>t<<32-e|t>>>e,e.isLE=68===new Uint8Array(new Uint32Array([287454020]).buffer)[0],!e.isLE)throw new Error("Non little-endian hardware is not supported");const i=Array.from({length:256},((t,e)=>e.toString(16).padStart(2,"0")));function o(t){if("string"!=typeof t)throw new TypeError("utf8ToBytes expected string, got "+typeof t);return(new TextEncoder).encode(t)}function s(t){if("string"==typeof t&&(t=o(t)),!(t instanceof Uint8Array))throw new TypeError(`Expected input type is Uint8Array (got ${typeof t})`);return t}e.bytesToHex=function(t){if(!(t instanceof Uint8Array))throw new Error("Uint8Array expected");let e="";for(let n=0;n<t.length;n++)e+=i[t[n]];return e},e.hexToBytes=function(t){if("string"!=typeof t)throw new TypeError("hexToBytes: expected string, got "+typeof t);if(t.length%2)throw new Error("hexToBytes: received invalid unpadded hex");const e=new Uint8Array(t.length/2);for(let n=0;n<e.length;n++){const r=2*n,i=t.slice(r,r+2),o=Number.parseInt(i,16);if(Number.isNaN(o)||o<0)throw new Error("Invalid byte sequence");e[n]=o}return e},e.nextTick=async()=>{},e.asyncLoop=async function(t,n,r){let i=Date.now();for(let o=0;o<t;o++){r(o);const t=Date.now()-i;t>=0&&t<n||(await(0,e.nextTick)(),i+=t)}},e.utf8ToBytes=o,e.toBytes=s,e.concatBytes=function(...t){if(!t.every((t=>t instanceof Uint8Array)))throw new Error("Uint8Array list expected");if(1===t.length)return t[0];const e=t.reduce(((t,e)=>t+e.length),0),n=new Uint8Array(e);for(let e=0,r=0;e<t.length;e++){const i=t[e];n.set(i,r),r+=i.length}return n},e.Hash=class{clone(){return this._cloneInto()}},e.checkOpts=function(t,e){if(void 0!==e&&("object"!=typeof e||(n=e,"[object Object]"!==Object.prototype.toString.call(n)||n.constructor!==Object)))throw new TypeError("Options should be object or undefined");var n;return Object.assign(t,e)},e.wrapConstructor=function(t){const e=e=>t().update(s(e)).digest(),n=t();return e.outputLen=n.outputLen,e.blockLen=n.blockLen,e.create=()=>t(),e},e.wrapConstructorWithOpts=function(t){const e=(e,n)=>t(n).update(s(e)).digest(),n=t({});return e.outputLen=n.outputLen,e.blockLen=n.blockLen,e.create=e=>t(e),e},e.randomBytes=function(t=32){if(r.crypto.web)return r.crypto.web.getRandomValues(new Uint8Array(t));if(r.crypto.node)return new Uint8Array(r.crypto.node.randomBytes(t).buffer);throw new Error("The environment doesn't have randomBytes function")}},6698:(t,e,n)=>{"use strict";Object.defineProperty(e,"__esModule",{value:!0}),e.utils=e.schnorr=e.verify=e.signSync=e.sign=e.getSharedSecret=e.recoverPublicKey=e.getPublicKey=e.Signature=e.Point=e.CURVE=void 0;const r=n(7695),i=BigInt(0),o=BigInt(1),s=BigInt(2),a=BigInt(3),c=BigInt(8),u=Object.freeze({a:i,b:BigInt(7),P:BigInt("0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f"),n:BigInt("0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141"),h:o,Gx:BigInt("55066263022277343669578718895168534326250603453777594175500187360389116729240"),Gy:BigInt("32670510020758816978083085130507043184471273380659243275938904335757337482424"),beta:BigInt("0x7ae96a2b657c07106e64479eac3434e99cf0497512f58995c1396c28719501ee")});e.CURVE=u;const f=(t,e)=>(t+e/s)/e,l={beta:BigInt("0x7ae96a2b657c07106e64479eac3434e99cf0497512f58995c1396c28719501ee"),splitScalar(t){const{n:e}=u,n=BigInt("0x3086d221a7d46bcde86c90e49284eb15"),r=-o*BigInt("0xe4437ed6010e88286f547fa90abfe4c3"),i=BigInt("0x114ca50f7a8e2f3f657c1108d9d44cfd8"),s=n,a=BigInt("0x100000000000000000000000000000000"),c=f(s*t,e),l=f(-r*t,e);let h=R(t-c*n-l*i,e),p=R(-c*r-l*s,e);const d=h>a,y=p>a;if(d&&(h=e-h),y&&(p=e-p),h>a||p>a)throw new Error("splitScalarEndo: Endomorphism failed, k="+t);return{k1neg:d,k1:h,k2neg:y,k2:p}}},h=32,p=32,d=h+1,y=2*h+1;function g(t){const{a:e,b:n}=u,r=R(t*t),i=R(r*t);return R(i+e*t+n)}const m=u.a===i;class b extends Error{constructor(t){super(t)}}function v(t){if(!(t instanceof w))throw new TypeError("JacobianPoint expected")}class w{constructor(t,e,n){this.x=t,this.y=e,this.z=n}static fromAffine(t){if(!(t instanceof S))throw new TypeError("JacobianPoint#fromAffine: expected Point");return t.equals(S.ZERO)?w.ZERO:new w(t.x,t.y,o)}static toAffineBatch(t){const e=function(t,e=u.P){const n=new Array(t.length),r=H(t.reduce(((t,r,o)=>r===i?t:(n[o]=t,R(t*r,e))),o),e);return t.reduceRight(((t,r,o)=>r===i?t:(n[o]=R(t*n[o],e),R(t*r,e))),r),n}(t.map((t=>t.z)));return t.map(((t,n)=>t.toAffine(e[n])))}static normalizeZ(t){return w.toAffineBatch(t).map(w.fromAffine)}equals(t){v(t);const{x:e,y:n,z:r}=this,{x:i,y:o,z:s}=t,a=R(r*r),c=R(s*s),u=R(e*c),f=R(i*a),l=R(R(n*s)*c),h=R(R(o*r)*a);return u===f&&l===h}negate(){return new w(this.x,R(-this.y),this.z)}double(){const{x:t,y:e,z:n}=this,r=R(t*t),i=R(e*e),o=R(i*i),u=t+i,f=R(s*(R(u*u)-r-o)),l=R(a*r),h=R(l*l),p=R(h-s*f),d=R(l*(f-p)-c*o),y=R(s*e*n);return new w(p,d,y)}add(t){v(t);const{x:e,y:n,z:r}=this,{x:o,y:a,z:c}=t;if(o===i||a===i)return this;if(e===i||n===i)return t;const u=R(r*r),f=R(c*c),l=R(e*f),h=R(o*u),p=R(R(n*c)*f),d=R(R(a*r)*u),y=R(h-l),g=R(d-p);if(y===i)return g===i?this.double():w.ZERO;const m=R(y*y),b=R(y*m),x=R(l*m),E=R(g*g-b-s*x),S=R(g*(x-E)-p*b),A=R(r*c*y);return new w(E,S,A)}subtract(t){return this.add(t.negate())}multiplyUnsafe(t){const e=w.ZERO;if("bigint"==typeof t&&t===i)return e;let n=B(t);if(n===o)return this;if(!m){let t=e,r=this;for(;n>i;)n&o&&(t=t.add(r)),r=r.double(),n>>=o;return t}let{k1neg:r,k1:s,k2neg:a,k2:c}=l.splitScalar(n),u=e,f=e,h=this;for(;s>i||c>i;)s&o&&(u=u.add(h)),c&o&&(f=f.add(h)),h=h.double(),s>>=o,c>>=o;return r&&(u=u.negate()),a&&(f=f.negate()),f=new w(R(f.x*l.beta),f.y,f.z),u.add(f)}precomputeWindow(t){const e=m?128/t+1:256/t+1,n=[];let r=this,i=r;for(let o=0;o<e;o++){i=r,n.push(i);for(let e=1;e<2**(t-1);e++)i=i.add(r),n.push(i);r=i.double()}return n}wNAF(t,e){!e&&this.equals(w.BASE)&&(e=S.BASE);const n=e&&e._WINDOW_SIZE||1;if(256%n)throw new Error("Point#wNAF: Invalid precomputation window, must be power of 2");let r=e&&E.get(e);r||(r=this.precomputeWindow(n),e&&1!==n&&(r=w.normalizeZ(r),E.set(e,r)));let i=w.ZERO,s=w.BASE;const a=1+(m?128/n:256/n),c=2**(n-1),u=BigInt(2**n-1),f=2**n,l=BigInt(n);for(let e=0;e<a;e++){const n=e*c;let a=Number(t&u);t>>=l,a>c&&(a-=f,t+=o);const h=n,p=n+Math.abs(a)-1,d=e%2!=0,y=a<0;0===a?s=s.add(x(d,r[h])):i=i.add(x(y,r[p]))}return{p:i,f:s}}multiply(t,e){let n,r,i=B(t);if(m){const{k1neg:t,k1:o,k2neg:s,k2:a}=l.splitScalar(i);let{p:c,f:u}=this.wNAF(o,e),{p:f,f:h}=this.wNAF(a,e);c=x(t,c),f=x(s,f),f=new w(R(f.x*l.beta),f.y,f.z),n=c.add(f),r=u.add(h)}else{const{p:t,f:o}=this.wNAF(i,e);n=t,r=o}return w.normalizeZ([n,r])[0]}toAffine(t){const{x:e,y:n,z:r}=this,i=this.equals(w.ZERO);null==t&&(t=i?c:H(r));const s=t,a=R(s*s),u=R(a*s),f=R(e*a),l=R(n*u),h=R(r*s);if(i)return S.ZERO;if(h!==o)throw new Error("invZ was invalid");return new S(f,l)}}function x(t,e){const n=e.negate();return t?n:e}w.BASE=new w(u.Gx,u.Gy,o),w.ZERO=new w(i,o,i);const E=new WeakMap;class S{constructor(t,e){this.x=t,this.y=e}_setWindowSize(t){this._WINDOW_SIZE=t,E.delete(this)}hasEvenY(){return this.y%s===i}static fromCompressedHex(t){const e=32===t.length,n=D(e?t:t.subarray(1));if(!G(n))throw new Error("Point is not on curve");let r=function(t){const{P:e}=u,n=BigInt(6),r=BigInt(11),i=BigInt(22),o=BigInt(23),c=BigInt(44),f=BigInt(88),l=t*t*t%e,h=l*l*t%e,p=$(h,a)*h%e,d=$(p,a)*h%e,y=$(d,s)*l%e,g=$(y,r)*y%e,m=$(g,i)*g%e,b=$(m,c)*m%e,v=$(b,f)*b%e,w=$(v,c)*m%e,x=$(w,a)*h%e,E=$(x,o)*g%e,S=$(E,n)*l%e,A=$(S,s);if(A*A%e!==t)throw new Error("Cannot find square root");return A}(g(n));const i=(r&o)===o;e?i&&(r=R(-r)):1==(1&t[0])!==i&&(r=R(-r));const c=new S(n,r);return c.assertValidity(),c}static fromUncompressedHex(t){const e=D(t.subarray(1,h+1)),n=D(t.subarray(h+1,2*h+1)),r=new S(e,n);return r.assertValidity(),r}static fromHex(t){const e=L(t),n=e.length,r=e[0];if(n===h)return this.fromCompressedHex(e);if(n===d&&(2===r||3===r))return this.fromCompressedHex(e);if(n===y&&4===r)return this.fromUncompressedHex(e);throw new Error(`Point.fromHex: received invalid point. Expected 32-${d} compressed bytes or ${y} uncompressed bytes, not ${n}`)}static fromPrivateKey(t){return S.BASE.multiply(J(t))}static fromSignature(t,e,n){const{r,s:i}=Y(e);if(![0,1,2,3].includes(n))throw new Error("Cannot recover: invalid recovery bit");const o=z(L(t)),{n:s}=u,a=2===n||3===n?r+s:r,c=H(a,s),f=R(-o*c,s),l=R(i*c,s),h=1&n?"03":"02",p=S.fromHex(h+P(a)),d=S.BASE.multiplyAndAddUnsafe(p,f,l);if(!d)throw new Error("Cannot recover signature: point at infinify");return d.assertValidity(),d}toRawBytes(t=!1){return F(this.toHex(t))}toHex(t=!1){const e=P(this.x);return t?`${this.hasEvenY()?"02":"03"}${e}`:`04${e}${P(this.y)}`}toHexX(){return this.toHex(!0).slice(2)}toRawX(){return this.toRawBytes(!0).slice(1)}assertValidity(){const t="Point is not on elliptic curve",{x:e,y:n}=this;if(!G(e)||!G(n))throw new Error(t);const r=R(n*n);if(R(r-g(e))!==i)throw new Error(t)}equals(t){return this.x===t.x&&this.y===t.y}negate(){return new S(this.x,R(-this.y))}double(){return w.fromAffine(this).double().toAffine()}add(t){return w.fromAffine(this).add(w.fromAffine(t)).toAffine()}subtract(t){return this.add(t.negate())}multiply(t){return w.fromAffine(this).multiply(t,this).toAffine()}multiplyAndAddUnsafe(t,e,n){const r=w.fromAffine(this),s=e===i||e===o||this!==S.BASE?r.multiplyUnsafe(e):r.multiply(e),a=w.fromAffine(t).multiplyUnsafe(n),c=s.add(a);return c.equals(w.ZERO)?void 0:c.toAffine()}}function A(t){return Number.parseInt(t[0],16)>=8?"00"+t:t}function k(t){if(t.length<2||2!==t[0])throw new Error(`Invalid signature integer tag: ${T(t)}`);const e=t[1],n=t.subarray(2,e+2);if(!e||n.length!==e)throw new Error("Invalid signature integer: wrong length");if(0===n[0]&&n[1]<=127)throw new Error("Invalid signature integer: trailing length");return{data:D(n),left:t.subarray(e+2)}}e.Point=S,S.BASE=new S(u.Gx,u.Gy),S.ZERO=new S(i,i);class _{constructor(t,e){this.r=t,this.s=e,this.assertValidity()}static fromCompact(t){const e=t instanceof Uint8Array,n="Signature.fromCompact";if("string"!=typeof t&&!e)throw new TypeError(`${n}: Expected string or Uint8Array`);const r=e?T(t):t;if(128!==r.length)throw new Error(`${n}: Expected 64-byte hex`);return new _(C(r.slice(0,64)),C(r.slice(64,128)))}static fromDER(t){const e=t instanceof Uint8Array;if("string"!=typeof t&&!e)throw new TypeError("Signature.fromDER: Expected string or Uint8Array");const{r:n,s:r}=function(t){if(t.length<2||48!=t[0])throw new Error(`Invalid signature tag: ${T(t)}`);if(t[1]!==t.length-2)throw new Error("Invalid signature: incorrect length");const{data:e,left:n}=k(t.subarray(2)),{data:r,left:i}=k(n);if(i.length)throw new Error(`Invalid signature: left bytes after parsing: ${T(i)}`);return{r:e,s:r}}(e?t:F(t));return new _(n,r)}static fromHex(t){return this.fromDER(t)}assertValidity(){const{r:t,s:e}=this;if(!V(t))throw new Error("Invalid Signature: r must be 0 < r < n");if(!V(e))throw new Error("Invalid Signature: s must be 0 < s < n")}hasHighS(){const t=u.n>>o;return this.s>t}normalizeS(){return this.hasHighS()?new _(this.r,R(-this.s,u.n)):this}toDERRawBytes(){return F(this.toDERHex())}toDERHex(){const t=A(N(this.s)),e=A(N(this.r)),n=t.length/2,r=e.length/2,i=N(n),o=N(r);return`30${N(r+n+4)}02${o}${e}02${i}${t}`}toRawBytes(){return this.toDERRawBytes()}toHex(){return this.toDERHex()}toCompactRawBytes(){return F(this.toCompactHex())}toCompactHex(){return P(this.r)+P(this.s)}}function O(...t){if(!t.every((t=>t instanceof Uint8Array)))throw new Error("Uint8Array list expected");if(1===t.length)return t[0];const e=t.reduce(((t,e)=>t+e.length),0),n=new Uint8Array(e);for(let e=0,r=0;e<t.length;e++){const i=t[e];n.set(i,r),r+=i.length}return n}e.Signature=_;const j=Array.from({length:256},((t,e)=>e.toString(16).padStart(2,"0")));function T(t){if(!(t instanceof Uint8Array))throw new Error("Expected Uint8Array");let e="";for(let n=0;n<t.length;n++)e+=j[t[n]];return e}const I=BigInt("0x10000000000000000000000000000000000000000000000000000000000000000");function P(t){if("bigint"!=typeof t)throw new Error("Expected bigint");if(!(i<=t&&t<I))throw new Error("Expected number 0 <= n < 2^256");return t.toString(16).padStart(64,"0")}function U(t){const e=F(P(t));if(32!==e.length)throw new Error("Error: expected 32 bytes");return e}function N(t){const e=t.toString(16);return 1&e.length?`0${e}`:e}function C(t){if("string"!=typeof t)throw new TypeError("hexToNumber: expected string, got "+typeof t);return BigInt(`0x${t}`)}function F(t){if("string"!=typeof t)throw new TypeError("hexToBytes: expected string, got "+typeof t);if(t.length%2)throw new Error("hexToBytes: received invalid unpadded hex"+t.length);const e=new Uint8Array(t.length/2);for(let n=0;n<e.length;n++){const r=2*n,i=t.slice(r,r+2),o=Number.parseInt(i,16);if(Number.isNaN(o)||o<0)throw new Error("Invalid byte sequence");e[n]=o}return e}function D(t){return C(T(t))}function L(t){return t instanceof Uint8Array?Uint8Array.from(t):F(t)}function B(t){if("number"==typeof t&&Number.isSafeInteger(t)&&t>0)return BigInt(t);if("bigint"==typeof t&&V(t))return t;throw new TypeError("Expected valid private scalar: 0 < scalar < curve.n")}function R(t,e=u.P){const n=t%e;return n>=i?n:e+n}function $(t,e){const{P:n}=u;let r=t;for(;e-- >i;)r*=r,r%=n;return r}function H(t,e=u.P){if(t===i||e<=i)throw new Error(`invert: expected positive integers, got n=${t} mod=${e}`);let n=R(t,e),r=e,s=i,a=o,c=o,f=i;for(;n!==i;){const t=r/n,e=r%n,i=s-c*t,o=a-f*t;r=n,n=e,s=c,a=f,c=i,f=o}if(r!==o)throw new Error("invert: does not exist");return R(s,e)}function z(t,e=!1){const n=function(t){const e=8*t.length-8*p,n=D(t);return e>0?n>>BigInt(e):n}(t);if(e)return n;const{n:r}=u;return n>=r?n-r:n}let K,M;class q{constructor(t,e){if(this.hashLen=t,this.qByteLen=e,"number"!=typeof t||t<2)throw new Error("hashLen must be a number");if("number"!=typeof e||e<2)throw new Error("qByteLen must be a number");this.v=new Uint8Array(t).fill(1),this.k=new Uint8Array(t).fill(0),this.counter=0}hmac(...t){return e.utils.hmacSha256(this.k,...t)}hmacSync(...t){return M(this.k,...t)}checkSync(){if("function"!=typeof M)throw new b("hmacSha256Sync needs to be set")}incr(){if(this.counter>=1e3)throw new Error("Tried 1,000 k values for sign(), all were invalid");this.counter+=1}async reseed(t=new Uint8Array){this.k=await this.hmac(this.v,Uint8Array.from([0]),t),this.v=await this.hmac(this.v),0!==t.length&&(this.k=await this.hmac(this.v,Uint8Array.from([1]),t),this.v=await this.hmac(this.v))}reseedSync(t=new Uint8Array){this.checkSync(),this.k=this.hmacSync(this.v,Uint8Array.from([0]),t),this.v=this.hmacSync(this.v),0!==t.length&&(this.k=this.hmacSync(this.v,Uint8Array.from([1]),t),this.v=this.hmacSync(this.v))}async generate(){this.incr();let t=0;const e=[];for(;t<this.qByteLen;){this.v=await this.hmac(this.v);const n=this.v.slice();e.push(n),t+=this.v.length}return O(...e)}generateSync(){this.checkSync(),this.incr();let t=0;const e=[];for(;t<this.qByteLen;){this.v=this.hmacSync(this.v);const n=this.v.slice();e.push(n),t+=this.v.length}return O(...e)}}function V(t){return i<t&&t<u.n}function G(t){return i<t&&t<u.P}function W(t,e,n,r=!0){const{n:s}=u,a=z(t,!0);if(!V(a))return;const c=H(a,s),f=S.BASE.multiply(a),l=R(f.x,s);if(l===i)return;const h=R(c*R(e+n*l,s),s);if(h===i)return;let p=new _(l,h),d=(f.x===p.r?0:2)|Number(f.y&o);return r&&p.hasHighS()&&(p=p.normalizeS(),d^=1),{sig:p,recovery:d}}function J(t){let e;if("bigint"==typeof t)e=t;else if("number"==typeof t&&Number.isSafeInteger(t)&&t>0)e=BigInt(t);else if("string"==typeof t){if(t.length!==2*p)throw new Error("Expected 32 bytes of private key");e=C(t)}else{if(!(t instanceof Uint8Array))throw new TypeError("Expected valid private key");if(t.length!==p)throw new Error("Expected 32 bytes of private key");e=D(t)}if(!V(e))throw new Error("Expected private key: 0 < key < n");return e}function Z(t){return t instanceof S?(t.assertValidity(),t):S.fromHex(t)}function Y(t){if(t instanceof _)return t.assertValidity(),t;try{return _.fromDER(t)}catch(e){return _.fromCompact(t)}}function X(t){const e=t instanceof Uint8Array,n="string"==typeof t,r=(e||n)&&t.length;return e?r===d||r===y:n?r===2*d||r===2*y:t instanceof S}function Q(t){return D(t.length>h?t.slice(0,h):t)}function tt(t){const e=Q(t),n=R(e,u.n);return et(n<i?e:n)}function et(t){return U(t)}function nt(t,n,r){if(null==t)throw new Error(`sign: expected valid message hash, not "${t}"`);const i=L(t),o=J(n),s=[et(o),tt(i)];if(null!=r){!0===r&&(r=e.utils.randomBytes(h));const t=L(r);if(t.length!==h)throw new Error(`sign: Expected ${h} bytes of extra data`);s.push(t)}return{seed:O(...s),m:Q(i),d:o}}function rt(t,e){const{sig:n,recovery:r}=t,{der:i,recovered:o}=Object.assign({canonical:!0,der:!0},e),s=i?n.toDERRawBytes():n.toCompactRawBytes();return o?[s,r]:s}e.getPublicKey=function(t,e=!1){return S.fromPrivateKey(t).toRawBytes(e)},e.recoverPublicKey=function(t,e,n,r=!1){return S.fromSignature(t,e,n).toRawBytes(r)},e.getSharedSecret=function(t,e,n=!1){if(X(t))throw new TypeError("getSharedSecret: first arg must be private key");if(!X(e))throw new TypeError("getSharedSecret: second arg must be public key");const r=Z(e);return r.assertValidity(),r.multiply(J(t)).toRawBytes(n)},e.sign=async function(t,e,n={}){const{seed:r,m:i,d:o}=nt(t,e,n.extraEntropy),s=new q(32,p);let a;for(await s.reseed(r);!(a=W(await s.generate(),i,o,n.canonical));)await s.reseed();return rt(a,n)},e.signSync=function(t,e,n={}){const{seed:r,m:i,d:o}=nt(t,e,n.extraEntropy),s=new q(32,p);let a;for(s.reseedSync(r);!(a=W(s.generateSync(),i,o,n.canonical));)s.reseedSync();return rt(a,n)};const it={strict:!0};function ot(t){return R(D(t),u.n)}e.verify=function(t,e,n,r=it){let i;try{i=Y(t),e=L(e)}catch(t){return!1}const{r:o,s}=i;if(r.strict&&i.hasHighS())return!1;const a=z(e);let c;try{c=Z(n)}catch(t){return!1}const{n:f}=u,l=H(s,f),h=R(a*l,f),p=R(o*l,f),d=S.BASE.multiplyAndAddUnsafe(c,h,p);return!!d&&R(d.x,f)===o};class st{constructor(t,e){this.r=t,this.s=e,this.assertValidity()}static fromHex(t){const e=L(t);if(64!==e.length)throw new TypeError(`SchnorrSignature.fromHex: expected 64 bytes, not ${e.length}`);const n=D(e.subarray(0,32)),r=D(e.subarray(32,64));return new st(n,r)}assertValidity(){const{r:t,s:e}=this;if(!G(t)||!V(e))throw new Error("Invalid signature")}toHex(){return P(this.r)+P(this.s)}toRawBytes(){return F(this.toHex())}}class at{constructor(t,n,r=e.utils.randomBytes()){if(null==t)throw new TypeError(`sign: Expected valid message, not "${t}"`);this.m=L(t);const{x:i,scalar:o}=this.getScalar(J(n));if(this.px=i,this.d=o,this.rand=L(r),32!==this.rand.length)throw new TypeError("sign: Expected 32 bytes of aux randomness")}getScalar(t){const e=S.fromPrivateKey(t),n=e.hasEvenY()?t:u.n-t;return{point:e,scalar:n,x:e.toRawX()}}initNonce(t,e){return U(t^D(e))}finalizeNonce(t){const e=R(D(t),u.n);if(e===i)throw new Error("sign: Creation of signature failed. k is zero");const{point:n,x:r,scalar:o}=this.getScalar(e);return{R:n,rx:r,k:o}}finalizeSig(t,e,n,r){return new st(t.x,R(e+n*r,u.n)).toRawBytes()}error(){throw new Error("sign: Invalid signature produced")}async calc(){const{m:t,d:n,px:r,rand:i}=this,o=e.utils.taggedHash,s=this.initNonce(n,await o(pt.aux,i)),{R:a,rx:c,k:u}=this.finalizeNonce(await o(pt.nonce,s,r,t)),f=ot(await o(pt.challenge,c,r,t)),l=this.finalizeSig(a,u,f,n);return await ft(l,t,r)||this.error(),l}calcSync(){const{m:t,d:n,px:r,rand:i}=this,o=e.utils.taggedHashSync,s=this.initNonce(n,o(pt.aux,i)),{R:a,rx:c,k:u}=this.finalizeNonce(o(pt.nonce,s,r,t)),f=ot(o(pt.challenge,c,r,t)),l=this.finalizeSig(a,u,f,n);return lt(l,t,r)||this.error(),l}}function ct(t,e,n){const r=t instanceof st,i=r?t:st.fromHex(t);return r&&i.assertValidity(),{...i,m:L(e),P:Z(n)}}function ut(t,e,n,r){const i=S.BASE.multiplyAndAddUnsafe(e,J(n),R(-r,u.n));return!(!i||!i.hasEvenY()||i.x!==t)}async function ft(t,n,r){try{const{r:i,s:o,m:s,P:a}=ct(t,n,r),c=ot(await e.utils.taggedHash(pt.challenge,U(i),a.toRawX(),s));return ut(i,a,o,c)}catch(t){return!1}}function lt(t,n,r){try{const{r:i,s:o,m:s,P:a}=ct(t,n,r),c=ot(e.utils.taggedHashSync(pt.challenge,U(i),a.toRawX(),s));return ut(i,a,o,c)}catch(t){if(t instanceof b)throw t;return!1}}e.schnorr={Signature:st,getPublicKey:function(t){return S.fromPrivateKey(t).toRawX()},sign:async function(t,e,n){return new at(t,e,n).calc()},verify:ft,signSync:function(t,e,n){return new at(t,e,n).calcSync()},verifySync:lt},S.BASE._setWindowSize(8);const ht={node:r,web:"object"==typeof self&&"crypto"in self?self.crypto:void 0},pt={challenge:"BIP0340/challenge",aux:"BIP0340/aux",nonce:"BIP0340/nonce"},dt={};e.utils={bytesToHex:T,hexToBytes:F,concatBytes:O,mod:R,invert:H,isValidPrivateKey(t){try{return J(t),!0}catch(t){return!1}},_bigintTo32Bytes:U,_normalizePrivateKey:J,hashToPrivateKey:t=>{t=L(t);const e=p+8;if(t.length<e||t.length>1024)throw new Error("Expected valid bytes of private key as per FIPS 186");return U(R(D(t),u.n-o)+o)},randomBytes:(t=32)=>{if(ht.web)return ht.web.getRandomValues(new Uint8Array(t));if(ht.node){const{randomBytes:e}=ht.node;return Uint8Array.from(e(t))}throw new Error("The environment doesn't have randomBytes function")},randomPrivateKey:()=>e.utils.hashToPrivateKey(e.utils.randomBytes(p+8)),precompute(t=8,e=S.BASE){const n=e===S.BASE?e:new S(e.x,e.y);return n._setWindowSize(t),n.multiply(a),n},sha256:async(...t)=>{if(ht.web){const e=await ht.web.subtle.digest("SHA-256",O(...t));return new Uint8Array(e)}if(ht.node){const{createHash:e}=ht.node,n=e("sha256");return t.forEach((t=>n.update(t))),Uint8Array.from(n.digest())}throw new Error("The environment doesn't have sha256 function")},hmacSha256:async(t,...e)=>{if(ht.web){const n=await ht.web.subtle.importKey("raw",t,{name:"HMAC",hash:{name:"SHA-256"}},!1,["sign"]),r=O(...e),i=await ht.web.subtle.sign("HMAC",n,r);return new Uint8Array(i)}if(ht.node){const{createHmac:n}=ht.node,r=n("sha256",t);return e.forEach((t=>r.update(t))),Uint8Array.from(r.digest())}throw new Error("The environment doesn't have hmac-sha256 function")},sha256Sync:void 0,hmacSha256Sync:void 0,taggedHash:async(t,...n)=>{let r=dt[t];if(void 0===r){const n=await e.utils.sha256(Uint8Array.from(t,(t=>t.charCodeAt(0))));r=O(n,n),dt[t]=r}return e.utils.sha256(r,...n)},taggedHashSync:(t,...e)=>{if("function"!=typeof K)throw new b("sha256Sync is undefined, you need to set it");let n=dt[t];if(void 0===n){const e=K(Uint8Array.from(t,(t=>t.charCodeAt(0))));n=O(e,e),dt[t]=n}return K(n,...e)},_JacobianPoint:w},Object.defineProperties(e.utils,{sha256Sync:{configurable:!1,get:()=>K,set(t){K||(K=t)}},hmacSha256Sync:{configurable:!1,get:()=>M,set(t){M||(M=t)}}})},8166:t=>{"use strict";t.exports=function(t){if(t.length>=255)throw new TypeError("Alphabet too long");for(var e=new Uint8Array(256),n=0;n<e.length;n++)e[n]=255;for(var r=0;r<t.length;r++){var i=t.charAt(r),o=i.charCodeAt(0);if(255!==e[o])throw new TypeError(i+" is ambiguous");e[o]=r}var s=t.length,a=t.charAt(0),c=Math.log(s)/Math.log(256),u=Math.log(256)/Math.log(s);function f(t){if("string"!=typeof t)throw new TypeError("Expected String");if(0===t.length)return new Uint8Array;for(var n=0,r=0,i=0;t[n]===a;)r++,n++;for(var o=(t.length-n)*c+1>>>0,u=new Uint8Array(o);t[n];){var f=e[t.charCodeAt(n)];if(255===f)return;for(var l=0,h=o-1;(0!==f||l<i)&&-1!==h;h--,l++)f+=s*u[h]>>>0,u[h]=f%256>>>0,f=f/256>>>0;if(0!==f)throw new Error("Non-zero carry");i=l,n++}for(var p=o-i;p!==o&&0===u[p];)p++;for(var d=new Uint8Array(r+(o-p)),y=r;p!==o;)d[y++]=u[p++];return d}return{encode:function(e){if(e instanceof Uint8Array||(ArrayBuffer.isView(e)?e=new Uint8Array(e.buffer,e.byteOffset,e.byteLength):Array.isArray(e)&&(e=Uint8Array.from(e))),!(e instanceof Uint8Array))throw new TypeError("Expected Uint8Array");if(0===e.length)return"";for(var n=0,r=0,i=0,o=e.length;i!==o&&0===e[i];)i++,n++;for(var c=(o-i)*u+1>>>0,f=new Uint8Array(c);i!==o;){for(var l=e[i],h=0,p=c-1;(0!==l||h<r)&&-1!==p;p--,h++)l+=256*f[p]>>>0,f[p]=l%s>>>0,l=l/s>>>0;if(0!==l)throw new Error("Non-zero carry");r=h,i++}for(var d=c-r;d!==c&&0===f[d];)d++;for(var y=a.repeat(n);d<c;++d)y+=t.charAt(f[d]);return y},decodeUnsafe:f,decode:function(t){var e=f(t);if(e)return e;throw new Error("Non-base"+s+" character")}}}},5766:(t,e)=>{"use strict";e.byteLength=function(t){var e=a(t),n=e[0],r=e[1];return 3*(n+r)/4-r},e.toByteArray=function(t){var e,n,o=a(t),s=o[0],c=o[1],u=new i(function(t,e,n){return 3*(e+n)/4-n}(0,s,c)),f=0,l=c>0?s-4:s;for(n=0;n<l;n+=4)e=r[t.charCodeAt(n)]<<18|r[t.charCodeAt(n+1)]<<12|r[t.charCodeAt(n+2)]<<6|r[t.charCodeAt(n+3)],u[f++]=e>>16&255,u[f++]=e>>8&255,u[f++]=255&e;return 2===c&&(e=r[t.charCodeAt(n)]<<2|r[t.charCodeAt(n+1)]>>4,u[f++]=255&e),1===c&&(e=r[t.charCodeAt(n)]<<10|r[t.charCodeAt(n+1)]<<4|r[t.charCodeAt(n+2)]>>2,u[f++]=e>>8&255,u[f++]=255&e),u},e.fromByteArray=function(t){for(var e,r=t.length,i=r%3,o=[],s=16383,a=0,u=r-i;a<u;a+=s)o.push(c(t,a,a+s>u?u:a+s));return 1===i?(e=t[r-1],o.push(n[e>>2]+n[e<<4&63]+"==")):2===i&&(e=(t[r-2]<<8)+t[r-1],o.push(n[e>>10]+n[e>>4&63]+n[e<<2&63]+"=")),o.join("")};for(var n=[],r=[],i="undefined"!=typeof Uint8Array?Uint8Array:Array,o="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",s=0;s<64;++s)n[s]=o[s],r[o.charCodeAt(s)]=s;function a(t){var e=t.length;if(e%4>0)throw new Error("Invalid string. Length must be a multiple of 4");var n=t.indexOf("=");return-1===n&&(n=e),[n,n===e?0:4-n%4]}function c(t,e,r){for(var i,o,s=[],a=e;a<r;a+=3)i=(t[a]<<16&16711680)+(t[a+1]<<8&65280)+(255&t[a+2]),s.push(n[(o=i)>>18&63]+n[o>>12&63]+n[o>>6&63]+n[63&o]);return s.join("")}r["-".charCodeAt(0)]=62,r["_".charCodeAt(0)]=63},7022:(t,e,n)=>{const r=n(8166);t.exports=r("123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz")},8098:(t,e,n)=>{"use strict";Object.defineProperty(e,"__esModule",{value:!0}),e.c32ToB58=e.b58ToC32=e.c32addressDecode=e.c32address=e.versions=void 0;const r=n(392),i=n(2716),o=n(64);e.versions={mainnet:{p2pkh:22,p2sh:20},testnet:{p2pkh:26,p2sh:21}};const s={};s[0]=e.versions.mainnet.p2pkh,s[5]=e.versions.mainnet.p2sh,s[111]=e.versions.testnet.p2pkh,s[196]=e.versions.testnet.p2sh;const a={};function c(t,e){if(!e.match(/^[0-9a-fA-F]{40}$/))throw new Error("Invalid argument: not a hash160 hex string");return`S${(0,r.c32checkEncode)(t,e)}`}function u(t){if(t.length<=5)throw new Error("Invalid c32 address: invalid length");if("S"!=t[0])throw new Error('Invalid c32 address: must start with "S"');return(0,r.c32checkDecode)(t.slice(1))}a[e.versions.mainnet.p2pkh]=0,a[e.versions.mainnet.p2sh]=5,a[e.versions.testnet.p2pkh]=111,a[e.versions.testnet.p2sh]=196,e.c32address=c,e.c32addressDecode=u,e.b58ToC32=function(t,e=-1){const n=i.decode(t),r=(0,o.bytesToHex)(n.data),a=parseInt((0,o.bytesToHex)(n.prefix),16);let u;return e<0?(u=a,void 0!==s[a]&&(u=s[a])):u=e,c(u,r)},e.c32ToB58=function(t,e=-1){const n=u(t),r=n[0],o=n[1];let s;e<0?(s=r,void 0!==a[r]&&(s=a[r])):s=e;let c=s.toString(16);return 1===c.length&&(c=`0${c}`),i.encode(o,c)}},2716:(t,e,n)=>{"use strict";Object.defineProperty(e,"__esModule",{value:!0}),e.decode=e.encode=void 0;const r=n(6053),i=n(64),o=n(8166),s="123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz";e.encode=function(t,e="00"){const n="string"==typeof t?(0,i.hexToBytes)(t):t,a="string"==typeof e?(0,i.hexToBytes)(e):t;if(!(n instanceof Uint8Array&&a instanceof Uint8Array))throw new TypeError("Argument must be of type Uint8Array or string");const c=(0,r.sha256)((0,r.sha256)(new Uint8Array([...a,...n])));return o(s).encode([...a,...n,...c.slice(0,4)])},e.decode=function(t){const e=o(s).decode(t),n=e.slice(0,1),i=e.slice(1,-4),a=(0,r.sha256)((0,r.sha256)(new Uint8Array([...n,...i])));return e.slice(-4).forEach(((t,e)=>{if(t!==a[e])throw new Error("Invalid checksum")})),{prefix:n,data:i}}},392:(t,e,n)=>{"use strict";Object.defineProperty(e,"__esModule",{value:!0}),e.c32checkDecode=e.c32checkEncode=void 0;const r=n(6053),i=n(64),o=n(4103);function s(t){const e=(0,r.sha256)((0,r.sha256)((0,i.hexToBytes)(t)));return(0,i.bytesToHex)(e.slice(0,4))}e.c32checkEncode=function(t,e){if(t<0||t>=32)throw new Error("Invalid version (must be between 0 and 31)");if(!e.match(/^[0-9a-fA-F]*$/))throw new Error("Invalid data (not a hex string)");(e=e.toLowerCase()).length%2!=0&&(e=`0${e}`);let n=t.toString(16);1===n.length&&(n=`0${n}`);const r=s(`${n}${e}`),i=(0,o.c32encode)(`${e}${r}`);return`${o.c32[t]}${i}`},e.c32checkDecode=function(t){t=(0,o.c32normalize)(t);const e=(0,o.c32decode)(t.slice(1)),n=t[0],r=o.c32.indexOf(n),i=e.slice(-8);let a=r.toString(16);if(1===a.length&&(a=`0${a}`),s(`${a}${e.substring(0,e.length-8)}`)!==i)throw new Error("Invalid c32check string: checksum mismatch");return[r,e.substring(0,e.length-8)]}},4103:(t,e,n)=>{"use strict";Object.defineProperty(e,"__esModule",{value:!0}),e.c32decode=e.c32normalize=e.c32encode=e.c32=void 0;const r=n(64);e.c32="0123456789ABCDEFGHJKMNPQRSTVWXYZ";const i="0123456789abcdef";function o(t){return t.toUpperCase().replace(/O/g,"0").replace(/L|I/g,"1")}e.c32encode=function(t,n){if(!t.match(/^[0-9a-fA-F]*$/))throw new Error("Not a hex-encoded string");t.length%2!=0&&(t=`0${t}`);let o=[],s=0;for(let n=(t=t.toLowerCase()).length-1;n>=0;n--)if(s<4){const r=i.indexOf(t[n])>>s;let a=0;0!==n&&(a=i.indexOf(t[n-1]));const c=1+s,u=a%(1<<c)<<5-c,f=e.c32[r+u];s=c,o.unshift(f)}else s=0;let a=0;for(let t=0;t<o.length&&"0"===o[t];t++)a++;o=o.slice(a);const c=(new TextDecoder).decode((0,r.hexToBytes)(t)).match(/^\u0000*/),u=c?c[0].length:0;for(let t=0;t<u;t++)o.unshift(e.c32[0]);if(n){const t=n-o.length;for(let n=0;n<t;n++)o.unshift(e.c32[0])}return o.join("")},e.c32normalize=o,e.c32decode=function(t,n){if(!(t=o(t)).match(`^[${e.c32}]*$`))throw new Error("Not a c32-encoded string");const r=t.match(`^${e.c32[0]}*`),s=r?r[0].length:0;let a=[],c=0,u=0;for(let n=t.length-1;n>=0;n--){4===u&&(a.unshift(i[c]),u=0,c=0);const r=(e.c32.indexOf(t[n])<<u)+c,o=i[r%16];if(u+=1,c=r>>4,c>1<<u)throw new Error("Panic error in decoding.");a.unshift(o)}a.unshift(i[c]),a.length%2==1&&a.unshift("0");let f=0;for(let t=0;t<a.length&&"0"===a[t];t++)f++;a=a.slice(f-f%2);let l=a.join("");for(let t=0;t<s;t++)l=`00${l}`;if(n){const t=2*n-l.length;for(let e=0;e<t;e+=2)l=`00${l}`}return l}},2870:(t,e,n)=>{"use strict";e.H4=void 0;n(4103),n(392);const r=n(8098);Object.defineProperty(e,"H4",{enumerable:!0,get:function(){return r.c32address}})},834:(t,e,n)=>{"use strict";n.d(e,{X:()=>o});var r=n(9902),i=n(3687);class o{constructor(t=r.f3.slice(),e=(t=>null==(t=(0,i.Rf)("location",{returnEmptyObject:!0}))?void 0:t.origin)(),n="",o="/manifest.json",s=void 0,a=r._G){this.appDomain=e,this.scopes=t,this.redirectPath=n,this.manifestPath=o,this.coreNode=s,this.authenticatorURL=a}redirectURI(){return`${this.appDomain}${this.redirectPath}`}manifestURI(){return`${this.appDomain}${this.manifestPath}`}}},9902:(t,e,n)=>{"use strict";n.d(e,{RS:()=>i,_G:()=>o,aL:()=>h,f0:()=>a,f3:()=>c,lB:()=>s,ud:()=>f,wR:()=>u,ym:()=>r,z1:()=>l});const r="blockstack",i="blockstack",o="https://browser.blockstack.org/auth",s={"@type":"Person","@context":"http://schema.org"};var a=(t=>(t.store_write="store_write",t.publish_data="publish_data",t.email="email",t))(a||{});const c=["store_write"],u="blockstack-transit-private-key",f="https://api.hiro.so",l="/v1/names",h="blockstack-session"},8469:(t,e,n)=>{"use strict";n.d(e,{J:()=>s,th:()=>a,xQ:()=>i,yz:()=>o});var r=n(735);function i(t){return`did:btc-addr:${t}`}function o(t){return`did:ecdsa-pub:${t}`}function s(t){const e=t.split(":");if(3!==e.length)throw new r.kn("Decentralized IDs must have 3 parts");if("did"!==e[0].toLowerCase())throw new r.kn('Decentralized IDs must start with "did"');return e[1].toLowerCase()}function a(t){if(t)return"btc-addr"===s(t)?t.split(":")[2]:void 0}},5142:(t,e,n)=>{"use strict";n.d(e,{R$:()=>l,ZW:()=>f,ak:()=>h,ph:()=>d,q8:()=>y});var r=n(3687),i=n(5026),o=n(3331),s=n(7474),a=n(9902),c=n(8469);const u="1.4.0";function f(){return(0,i.Qh)()}const l=h;function h(t,e,n,o=a.f3.slice(),f,l=(0,r.nD)().getTime(),h={}){const p=t=>{const e=(0,r.Rf)("location",{throwIfUnavailable:!0,usageDesc:`makeAuthRequest([${t}=undefined])`});return null==e?void 0:e.origin};e||(e=`${p("redirectURI")}/`),n||(n=`${p("manifestURI")}/manifest.json`),f||(f=p("appDomain"));const d=Object.assign({},h,{jti:(0,r.gS)(),iat:Math.floor((new Date).getTime()/1e3),exp:Math.floor(l/1e3),iss:null,public_keys:[],domain_name:f,manifest_uri:n,redirect_uri:e,version:u,do_not_include_profile:!0,supports_hub_url:!0,scopes:o}),y=s.SECP256K1Client.derivePublicKey(t);d.public_keys=[y];const g=(0,i.xc)(y);return d.iss=(0,c.xQ)(g),new s.TokenSigner("ES256k",t).sign(d)}async function p(t,e){const n=await(0,o.pW)(t,(0,r.iY)(e),!0),i=JSON.stringify(n);return(0,r.ci)((0,r.iY)(i))}async function d(t,e){const n=(0,r.Md)((0,r.nr)(e)),i=JSON.parse(n),s=await(0,o.ld)(t,i);if("string"!=typeof s)throw new Error("Unable to correctly decrypt private key");return s}async function y(t,e={},n,o=null,a=null,f=(0,r.nD)().getTime(),l=null,h=null,d=null,y=null,g=null){const m=s.SECP256K1Client.derivePublicKey(t),b=(0,i.xc)(m);let v=a,w=o,x={};null!=a&&(null!=l&&(v=await p(l,a),null!=o&&(w=await p(l,o))),x={email:(null==n?void 0:n.email)?n.email:null,profile_url:(null==n?void 0:n.profileUrl)?n.profileUrl:null,hubUrl:h,blockstackAPIUrl:d,associationToken:y,version:u});const E=Object.assign({},{jti:(0,r.gS)(),iat:Math.floor((new Date).getTime()/1e3),exp:Math.floor(f/1e3),iss:(0,c.xQ)(b),private_key:v,public_keys:[m],appPrivateKeyFromWalletSalt:g,profile:e,core_token:w},x);return new s.TokenSigner("ES256k",t).sign(E)}},6737:(t,e,n)=>{"use strict";n.d(e,{R:()=>d,N:()=>p});var r=n(4025),i=n(3056);function o(t,e){let n;return e.proof&&e.proof.url&&(n=e.proof.url),{"@type":"Account",service:t,identifier:e.username,proofType:"http",proofUrl:n}}var s=n(2377),a=n(2179),c=n(7118);const u={type:"object",properties:{"@context":{type:"string",optional:!0},"@type":{type:"string"}}};class f{constructor(t={}){this._profile=Object.assign({},{"@context":"http://schema.org/"},t)}toJSON(){return Object.assign({},this._profile)}toToken(t){return(0,i.K9)(this.toJSON(),t)}static validateSchema(t,e=!1){return u.strict=e,a.validate(u,t)}static fromToken(t,e=null){const n=(0,i.of)(t,e);return new f(n)}static makeZoneFile(t,e){return function(t,e){if(!e.includes("://"))throw new Error("Invalid token file url");const n=e.split("://")[0],r=e.split("://")[1].split("/"),i={$origin:t,$ttl:3600,uri:[{name:"_http._tcp",priority:10,weight:1,target:`${n}://${r[0]}${`/${r.slice(1).join("/")}`}`}]};return(0,s.makeZoneFile)(i,"{$origin}\n{$ttl}\n{uri}\n")}(t,e)}}const l={type:"object",strict:!1,properties:{"@context":{type:"string",optional:!0},"@type":{type:"string"},"@id":{type:"string",optional:!0},name:{type:"string",optional:!0},givenName:{type:"string",optional:!0},familyName:{type:"string",optional:!0},description:{type:"string",optional:!0},image:{type:"array",optional:!0,items:{type:"object",properties:{"@type":{type:"string"},name:{type:"string",optional:!0},contentUrl:{type:"string",optional:!0}}}},website:{type:"array",optional:!0,items:{type:"object",properties:{"@type":{type:"string"},url:{type:"string",optional:!0}}}},account:{type:"array",optional:!0,items:{type:"object",properties:{"@type":{type:"string"},service:{type:"string",optional:!0},identifier:{type:"string",optional:!0},proofType:{type:"string",optional:!0},proofUrl:{type:"string",optional:!0},proofMessage:{type:"string",optional:!0},proofSignature:{type:"string",optional:!0}}}},worksFor:{type:"array",optional:!0,items:{type:"object",properties:{"@type":{type:"string"},"@id":{type:"string",optional:!0}}}},knows:{type:"array",optional:!0,items:{type:"object",properties:{"@type":{type:"string"},"@id":{type:"string",optional:!0}}}},address:{type:"object",optional:!0,properties:{"@type":{type:"string"},streetAddress:{type:"string",optional:!0},addressLocality:{type:"string",optional:!0},postalCode:{type:"string",optional:!0},addressCountry:{type:"string",optional:!0}}},birthDate:{type:"string",optional:!0},taxID:{type:"string",optional:!0}}};class h extends f{constructor(t={"@type":"Person"}){super(t),this._profile=Object.assign({},{"@type":"Person"},this._profile)}static validateSchema(t,e=!1){return l.strict=e,a.validate(u,t)}static fromToken(t,e=null){const n=(0,i.of)(t,e);return new h(n)}static fromLegacyFormat(t){const e=function(t){const e={"@type":"Person"};if(t){t.name&&t.name.formatted&&(e.name=t.name.formatted),t.bio&&(e.description=t.bio),t.location&&t.location.formatted&&(e.address={"@type":"PostalAddress",addressLocality:t.location.formatted});const n=[];t.avatar&&t.avatar.url&&n.push({"@type":"ImageObject",name:"avatar",contentUrl:t.avatar.url}),t.cover&&t.cover.url&&n.push({"@type":"ImageObject",name:"cover",contentUrl:t.cover.url}),n.length&&(e.image=n),t.website&&(e.website=[{"@type":"WebSite",url:t.website}]);const r=[];t.bitcoin&&t.bitcoin.address&&r.push({"@type":"Account",role:"payment",service:"bitcoin",identifier:t.bitcoin.address}),t.twitter&&t.twitter.username&&r.push(o("twitter",t.twitter)),t.facebook&&t.facebook.username&&r.push(o("facebook",t.facebook)),t.github&&t.github.username&&r.push(o("github",t.github)),t.auth&&t.auth.length>0&&t.auth[0]&&t.auth[0].publicKeychain&&r.push({"@type":"Account",role:"key",service:"bip32",identifier:t.auth[0].publicKeychain}),t.pgp&&t.pgp.url&&r.push({"@type":"Account",role:"key",service:"pgp",identifier:t.pgp.fingerprint,contentUrl:t.pgp.url}),e.account=r}return e}(t);return new h(e)}toJSON(){return{profile:this.profile(),name:this.name(),givenName:this.givenName(),familyName:this.familyName(),description:this.description(),avatarUrl:this.avatarUrl(),verifiedAccounts:this.verifiedAccounts(),address:this.address(),birthDate:this.birthDate(),connections:this.connections(),organizations:this.organizations()}}profile(){return Object.assign({},this._profile)}name(){return function(t){if(!t)return null;let e=null;return t.name?e=t.name:(t.givenName||t.familyName)&&(e="",t.givenName&&(e=t.givenName),t.familyName&&(e+=` ${t.familyName}`)),e}(this.profile())}givenName(){return function(t){if(!t)return null;let e=null;return t.givenName?e=t.givenName:t.name&&(e=t.name.split(" ").slice(0,-1).join(" ")),e}(this.profile())}familyName(){return function(t){if(!t)return null;let e=null;return t.familyName?e=t.familyName:t.name&&(e=t.name.split(" ").pop()),e}(this.profile())}description(){return function(t){if(!t)return null;let e=null;return t.description&&(e=t.description),e}(this.profile())}avatarUrl(){return function(t){if(!t)return null;let e=null;return t.image&&t.image.map((t=>"avatar"===t.name?(e=t.contentUrl,e):null)),e}(this.profile())}verifiedAccounts(t){return function(t,e){if(!t)return null;const n=[];return t.hasOwnProperty("account")&&e&&t.account.map((t=>{let r=!1,i=null;return e.map((e=>(e.hasOwnProperty("proof_url")&&(e.proofUrl=e.proof_url),!(!e.valid||e.service!==t.service||e.identifier!==t.identifier||!e.proofUrl||(r=!0,i=e.proofUrl,0))))),r?(t.proofUrl=i,n.push(t),t):null})),n}(this.profile(),t)}address(){return function(t){if(!t)return null;let e=null;if(t.hasOwnProperty("address")){const n=[];t.address.hasOwnProperty("streetAddress")&&n.push(t.address.streetAddress),t.address.hasOwnProperty("addressLocality")&&n.push(t.address.addressLocality),t.address.hasOwnProperty("postalCode")&&n.push(t.address.postalCode),t.address.hasOwnProperty("addressCountry")&&n.push(t.address.addressCountry),n.length&&(e=n.join(", "))}return e}(this.profile())}birthDate(){return function(t){if(!t)return null;const e=["January","February","March","April","May","June","July","August","September","October","November","December"];let n=null;if(t.hasOwnProperty("birthDate")){const r=new Date(t.birthDate);n=`${e[r.getMonth()]} ${r.getDate()}, ${r.getFullYear()}`}return n}(this.profile())}connections(){return function(t){if(!t)return null;let e=[];return t.hasOwnProperty("knows")&&(e=t.knows),e}(this.profile())}organizations(){return(t=this.profile())?t.hasOwnProperty("worksFor")?t.worksFor:[]:null;var t}}function p(t){var e;if(!t.username)return Promise.reject(new Error("No username provided"));const n=(0,r.tn)(null!=(e=t.network)?e:"mainnet"),o=Object.assign({},(0,r.zD)(n),t.client);let a;if(t.zoneFileLookupURL){const e=`${t.zoneFileLookupURL.replace(/\/$/,"")}/${t.username}`;a=o.fetch(e).then((t=>t.json()))}else a=d({name:t.username});return a.then((t=>{if(t.hasOwnProperty("zonefile")&&t.hasOwnProperty("address"))return function(t){const e=(0,r.tn)(t.network??"mainnet"),n=Object.assign({},(0,r.zD)(e),t.client);return new Promise(((e,r)=>{let o=null;try{o=(0,s.parseZoneFile)(t.zoneFile),o.hasOwnProperty("$origin")||(o=null)}catch(t){r(t)}let a=null;if(o&&Object.keys(o).length>0)a=function(t){if(!t.hasOwnProperty("uri"))return null;if(!Array.isArray(t.uri))return null;if(t.uri.length<1)return null;const e=t.uri.filter((t=>t.hasOwnProperty("target")&&"_http._tcp"===t.name));if(e.length<1)return null;const n=e[0];if(!n.hasOwnProperty("target"))return null;let r=n.target;return r.startsWith("https")||r.startsWith("http")||(r=`https://${r}`),r}(o);else try{return e(h.fromLegacyFormat(JSON.parse(t.zoneFile)).profile())}catch(t){return r(t)}a?n.fetch(a).then((t=>t.text())).then((t=>JSON.parse(t))).then((n=>{const r=n,o=(0,i.of)(r[0].token,t.publicKeyOrAddress);e(o)})).catch((t=>{c.Y.error(`resolveZoneFileToProfile: error fetching token file ${a}: ${t}`),r(t)})):(c.Y.debug("Token file url not found. Resolving to blank profile."),e({}))}))}({zoneFile:t.zonefile,publicKeyOrAddress:t.address,client:o});throw new Error("Invalid zonefile lookup response: did not contain `address` or `zonefile` field")}))}function d(t){var e;const n=(0,r.tn)(null!=(e=t.network)?e:"mainnet"),i=Object.assign({},(0,r.zD)(n),t.client),o=`${i.baseUrl}/v1/names/${t.name}`;return i.fetch(o).then((t=>{if(404===t.status)throw new Error("Name not found");if(200!==t.status)throw new Error(`Bad response status: ${t.status}`);return t.json()})).then((t=>t.address?Object.assign({},t,{address:t.address}):t))}},1591:(t,e,n)=>{"use strict";n.d(e,{s:()=>g,z:()=>y});var r=n(7474),i=n(3687),o=n(1304),s=Object.defineProperty,a=Object.defineProperties,c=Object.getOwnPropertyDescriptors,u=Object.getOwnPropertySymbols,f=Object.prototype.hasOwnProperty,l=Object.prototype.propertyIsEnumerable,h=(t,e,n)=>e in t?s(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n,p=(t,e)=>{for(var n i