UNPKG

@ew-did-registry/claims

Version:

The package exposes functionality needed to create, inspect, approve, and verify Private and Public claims

2 lines 831 kB
/*! For license information please see index.esm.js.LICENSE.txt */ (()=>{var t={5887:(t,e,r)=>{"use strict";Object.defineProperty(e,"__esModule",{value:!0}),e.createCurve=e.getHash=void 0;const i=r(1377),n=r(64),o=r(7851);function s(t){return{hash:t,hmac:(e,...r)=>(0,i.hmac)(t,e,(0,n.concatBytes)(...r)),randomBytes:n.randomBytes}}e.getHash=s,e.createCurve=function(t,e){const r=e=>(0,o.weierstrass)({...t,...s(e)});return Object.freeze({...r(e),create:r})}},1465:(t,e,r)=>{"use strict";Object.defineProperty(e,"__esModule",{value:!0}),e.validateBasic=e.wNAF=void 0;const i=r(9530),n=r(4323),o=BigInt(0),s=BigInt(1);e.wNAF=function(t,e){const r=(t,e)=>{const r=e.negate();return t?r:e},i=t=>({windows:Math.ceil(e/t)+1,windowSize:2**(t-1)});return{constTimeNegate:r,unsafeLadder(e,r){let i=t.ZERO,n=e;for(;r>o;)r&s&&(i=i.add(n)),n=n.double(),r>>=s;return i},precomputeWindow(t,e){const{windows:r,windowSize:n}=i(e),o=[];let s=t,a=s;for(let t=0;t<r;t++){a=s,o.push(a);for(let t=1;t<n;t++)a=a.add(s),o.push(a);s=a.double()}return o},wNAF(e,n,o){const{windows:a,windowSize:h}=i(e);let u=t.ZERO,f=t.BASE;const l=BigInt(2**e-1),c=2**e,d=BigInt(e);for(let t=0;t<a;t++){const e=t*h;let i=Number(o&l);o>>=d,i>h&&(i-=c,o+=s);const a=e,p=e+Math.abs(i)-1,m=t%2!=0,b=i<0;0===i?f=f.add(r(m,n[a])):u=u.add(r(b,n[p]))}return{p:u,f}},wNAFCached(t,e,r,i){const n=t._WINDOW_SIZE||1;let o=e.get(t);return o||(o=this.precomputeWindow(t,n),1!==n&&e.set(t,i(o))),this.wNAF(n,o,r)}}},e.validateBasic=function(t){return(0,i.validateField)(t.Fp),(0,n.validateObject)(t,{n:"bigint",h:"bigint",Gx:"field",Gy:"field"},{nBitLength:"isSafeInteger",nByteLength:"isSafeInteger"}),Object.freeze({...(0,i.nLength)(t.n,t.nBitLength),...t,p:t.Fp.ORDER})}},1322:(t,e,r)=>{"use strict";Object.defineProperty(e,"__esModule",{value:!0}),e.createHasher=e.isogenyMap=e.hash_to_field=e.expand_message_xof=e.expand_message_xmd=void 0;const i=r(9530),n=r(4323),o=n.bytesToNumberBE;function s(t,e){if(t<0||t>=1<<8*e)throw new Error(`bad I2OSP call: value=${t} length=${e}`);const r=Array.from({length:e}).fill(0);for(let i=e-1;i>=0;i--)r[i]=255&t,t>>>=8;return new Uint8Array(r)}function a(t,e){const r=new Uint8Array(t.length);for(let i=0;i<t.length;i++)r[i]=t[i]^e[i];return r}function h(t){if(!(t instanceof Uint8Array))throw new Error("Uint8Array expected")}function u(t){if(!Number.isSafeInteger(t))throw new Error("number expected")}function f(t,e,r,i){h(t),h(e),u(r),e.length>255&&(e=i((0,n.concatBytes)((0,n.utf8ToBytes)("H2C-OVERSIZE-DST-"),e)));const{outputLen:o,blockLen:f}=i,l=Math.ceil(r/o);if(l>255)throw new Error("Invalid xmd length");const c=(0,n.concatBytes)(e,s(e.length,1)),d=s(0,f),p=s(r,2),m=new Array(l),b=i((0,n.concatBytes)(d,t,p,s(0,1),c));m[0]=i((0,n.concatBytes)(b,s(1,1),c));for(let t=1;t<=l;t++){const e=[a(b,m[t-1]),s(t+1,1),c];m[t]=i((0,n.concatBytes)(...e))}return(0,n.concatBytes)(...m).slice(0,r)}function l(t,e,r,i,o){if(h(t),h(e),u(r),e.length>255){const t=Math.ceil(2*i/8);e=o.create({dkLen:t}).update((0,n.utf8ToBytes)("H2C-OVERSIZE-DST-")).update(e).digest()}if(r>65535||e.length>255)throw new Error("expand_message_xof: invalid lenInBytes");return o.create({dkLen:r}).update(t).update(s(r,2)).update(e).update(s(e.length,1)).digest()}function c(t,e,r){(0,n.validateObject)(r,{DST:"string",p:"bigint",m:"isSafeInteger",k:"isSafeInteger",hash:"hash"});const{p:s,k:a,m:c,hash:d,expand:p,DST:m}=r;h(t),u(e);const b=function(t){if(t instanceof Uint8Array)return t;if("string"==typeof t)return(0,n.utf8ToBytes)(t);throw new Error("DST must be Uint8Array or string")}(m),g=s.toString(2).length,y=Math.ceil((g+a)/8),v=e*c*y;let w;if("xmd"===p)w=f(t,b,v,d);else if("xof"===p)w=l(t,b,v,a,d);else{if("_internal_pass"!==p)throw new Error('expand must be "xmd" or "xof"');w=t}const M=new Array(e);for(let t=0;t<e;t++){const e=new Array(c);for(let r=0;r<c;r++){const n=y*(r+t*c),a=w.subarray(n,n+y);e[r]=(0,i.mod)(o(a),s)}M[t]=e}return M}e.expand_message_xmd=f,e.expand_message_xof=l,e.hash_to_field=c,e.isogenyMap=function(t,e){const r=e.map((t=>Array.from(t).reverse()));return(e,i)=>{const[n,o,s,a]=r.map((r=>r.reduce(((r,i)=>t.add(t.mul(r,e),i)))));return e=t.div(n,o),i=t.mul(i,t.div(s,a)),{x:e,y:i}}},e.createHasher=function(t,e,r){if("function"!=typeof e)throw new Error("mapToCurve() must be defined");return{hashToCurve(i,n){const o=c(i,2,{...r,DST:r.DST,...n}),s=t.fromAffine(e(o[0])),a=t.fromAffine(e(o[1])),h=s.add(a).clearCofactor();return h.assertValidity(),h},encodeToCurve(i,n){const o=c(i,1,{...r,DST:r.encodeDST,...n}),s=t.fromAffine(e(o[0])).clearCofactor();return s.assertValidity(),s}}}},9530:(t,e,r)=>{"use strict";Object.defineProperty(e,"__esModule",{value:!0}),e.hashToPrivateScalar=e.FpSqrtEven=e.FpSqrtOdd=e.Field=e.nLength=e.FpIsSquare=e.FpDiv=e.FpInvertBatch=e.FpPow=e.validateField=e.isNegativeLE=e.FpSqrt=e.tonelliShanks=e.invert=e.pow2=e.pow=e.mod=void 0;const i=r(4323),n=BigInt(0),o=BigInt(1),s=BigInt(2),a=BigInt(3),h=BigInt(4),u=BigInt(5),f=BigInt(8);function l(t,e){const r=t%e;return r>=n?r:e+r}function c(t,e,r){if(r<=n||e<n)throw new Error("Expected power/modulo > 0");if(r===o)return n;let i=o;for(;e>n;)e&o&&(i=i*t%r),t=t*t%r,e>>=o;return i}function d(t,e){if(t===n||e<=n)throw new Error(`invert: expected positive integers, got n=${t} mod=${e}`);let r=l(t,e),i=e,s=n,a=o,h=o,u=n;for(;r!==n;){const t=i/r,e=i%r,n=s-h*t,o=a-u*t;i=r,r=e,s=h,a=u,h=n,u=o}if(i!==o)throw new Error("invert: does not exist");return l(s,e)}function p(t){const e=(t-o)/s;let r,i,a;for(r=t-o,i=0;r%s===n;r/=s,i++);for(a=s;a<t&&c(a,e,t)!==t-o;a++);if(1===i){const e=(t+o)/h;return function(t,r){const i=t.pow(r,e);if(!t.eql(t.sqr(i),r))throw new Error("Cannot find square root");return i}}const u=(r+o)/s;return function(t,n){if(t.pow(n,e)===t.neg(t.ONE))throw new Error("Cannot find square root");let s=i,h=t.pow(t.mul(t.ONE,a),r),f=t.pow(n,u),l=t.pow(n,r);for(;!t.eql(l,t.ONE);){if(t.eql(l,t.ZERO))return t.ZERO;let e=1;for(let r=t.sqr(l);e<s&&!t.eql(r,t.ONE);e++)r=t.sqr(r);const r=t.pow(h,o<<BigInt(s-e-1));h=t.sqr(r),f=t.mul(f,r),l=t.mul(l,h),s=e}return f}}function m(t){if(t%h===a){const e=(t+o)/h;return function(t,r){const i=t.pow(r,e);if(!t.eql(t.sqr(i),r))throw new Error("Cannot find square root");return i}}if(t%f===u){const e=(t-u)/f;return function(t,r){const i=t.mul(r,s),n=t.pow(i,e),o=t.mul(r,n),a=t.mul(t.mul(o,s),n),h=t.mul(o,t.sub(a,t.ONE));if(!t.eql(t.sqr(h),r))throw new Error("Cannot find square root");return h}}return p(t)}BigInt(9),BigInt(16),e.mod=l,e.pow=c,e.pow2=function(t,e,r){let i=t;for(;e-- >n;)i*=i,i%=r;return i},e.invert=d,e.tonelliShanks=p,e.FpSqrt=m,e.isNegativeLE=(t,e)=>(l(t,e)&o)===o;const b=["create","isValid","is0","neg","inv","sqrt","sqr","eql","add","sub","mul","pow","div","addN","subN","mulN","sqrN"];function g(t,e,r){if(r<n)throw new Error("Expected power > 0");if(r===n)return t.ONE;if(r===o)return e;let i=t.ONE,s=e;for(;r>n;)r&o&&(i=t.mul(i,s)),s=t.sqr(s),r>>=o;return i}function y(t,e){const r=new Array(e.length),i=e.reduce(((e,i,n)=>t.is0(i)?e:(r[n]=e,t.mul(e,i))),t.ONE),n=t.inv(i);return e.reduceRight(((e,i,n)=>t.is0(i)?e:(r[n]=t.mul(e,r[n]),t.mul(e,i))),n),r}function v(t,e){const r=void 0!==e?e:t.toString(2).length;return{nBitLength:r,nByteLength:Math.ceil(r/8)}}e.validateField=function(t){const e=b.reduce(((t,e)=>(t[e]="function",t)),{ORDER:"bigint",MASK:"bigint",BYTES:"isSafeInteger",BITS:"isSafeInteger"});return(0,i.validateObject)(t,e)},e.FpPow=g,e.FpInvertBatch=y,e.FpDiv=function(t,e,r){return t.mul(e,"bigint"==typeof r?d(r,t.ORDER):t.inv(r))},e.FpIsSquare=function(t){const e=(t.ORDER-o)/s;return r=>{const i=t.pow(r,e);return t.eql(i,t.ZERO)||t.eql(i,t.ONE)}},e.nLength=v,e.Field=function(t,e,r=!1,s={}){if(t<=n)throw new Error(`Expected Fp ORDER > 0, got ${t}`);const{nBitLength:a,nByteLength:h}=v(t,e);if(h>2048)throw new Error("Field lengths over 2048 bytes are not supported");const u=m(t),f=Object.freeze({ORDER:t,BITS:a,BYTES:h,MASK:(0,i.bitMask)(a),ZERO:n,ONE:o,create:e=>l(e,t),isValid:e=>{if("bigint"!=typeof e)throw new Error("Invalid field element: expected bigint, got "+typeof e);return n<=e&&e<t},is0:t=>t===n,isOdd:t=>(t&o)===o,neg:e=>l(-e,t),eql:(t,e)=>t===e,sqr:e=>l(e*e,t),add:(e,r)=>l(e+r,t),sub:(e,r)=>l(e-r,t),mul:(e,r)=>l(e*r,t),pow:(t,e)=>g(f,t,e),div:(e,r)=>l(e*d(r,t),t),sqrN:t=>t*t,addN:(t,e)=>t+e,subN:(t,e)=>t-e,mulN:(t,e)=>t*e,inv:e=>d(e,t),sqrt:s.sqrt||(t=>u(f,t)),invertBatch:t=>y(f,t),cmov:(t,e,r)=>r?e:t,toBytes:t=>r?(0,i.numberToBytesLE)(t,h):(0,i.numberToBytesBE)(t,h),fromBytes:t=>{if(t.length!==h)throw new Error(`Fp.fromBytes: expected ${h}, got ${t.length}`);return r?(0,i.bytesToNumberLE)(t):(0,i.bytesToNumberBE)(t)}});return Object.freeze(f)},e.FpSqrtOdd=function(t,e){if(!t.isOdd)throw new Error("Field doesn't have isOdd");const r=t.sqrt(e);return t.isOdd(r)?r:t.neg(r)},e.FpSqrtEven=function(t,e){if(!t.isOdd)throw new Error("Field doesn't have isOdd");const r=t.sqrt(e);return t.isOdd(r)?t.neg(r):r},e.hashToPrivateScalar=function(t,e,r=!1){const n=(t=(0,i.ensureBytes)("privateHash",t)).length,s=v(e).nByteLength+8;if(s<24||n<s||n>1024)throw new Error(`hashToPrivateScalar: expected ${s}-1024 bytes of input, got ${n}`);return l(r?(0,i.bytesToNumberLE)(t):(0,i.bytesToNumberBE)(t),e-o)+o}},4323:(t,e)=>{"use strict";Object.defineProperty(e,"__esModule",{value:!0}),e.validateObject=e.createHmacDrbg=e.bitMask=e.bitSet=e.bitGet=e.bitLen=e.utf8ToBytes=e.equalBytes=e.concatBytes=e.ensureBytes=e.numberToVarBytesBE=e.numberToBytesLE=e.numberToBytesBE=e.bytesToNumberLE=e.bytesToNumberBE=e.hexToBytes=e.hexToNumber=e.numberToHexUnpadded=e.bytesToHex=void 0;const r=BigInt(0),i=BigInt(1),n=BigInt(2),o=t=>t instanceof Uint8Array,s=Array.from({length:256},((t,e)=>e.toString(16).padStart(2,"0")));function a(t){if(!o(t))throw new Error("Uint8Array expected");let e="";for(let r=0;r<t.length;r++)e+=s[t[r]];return e}function h(t){const e=t.toString(16);return 1&e.length?`0${e}`:e}function u(t){if("string"!=typeof t)throw new Error("hex string expected, got "+typeof t);return BigInt(""===t?"0":`0x${t}`)}function f(t){if("string"!=typeof t)throw new Error("hex string expected, got "+typeof t);const e=t.length;if(e%2)throw new Error("padded hex string expected, got unpadded hex of length "+e);const r=new Uint8Array(e/2);for(let e=0;e<r.length;e++){const i=2*e,n=t.slice(i,i+2),o=Number.parseInt(n,16);if(Number.isNaN(o)||o<0)throw new Error("Invalid byte sequence");r[e]=o}return r}function l(t,e){return f(t.toString(16).padStart(2*e,"0"))}function c(...t){const e=new Uint8Array(t.reduce(((t,e)=>t+e.length),0));let r=0;return t.forEach((t=>{if(!o(t))throw new Error("Uint8Array expected");e.set(t,r),r+=t.length})),e}e.bytesToHex=a,e.numberToHexUnpadded=h,e.hexToNumber=u,e.hexToBytes=f,e.bytesToNumberBE=function(t){return u(a(t))},e.bytesToNumberLE=function(t){if(!o(t))throw new Error("Uint8Array expected");return u(a(Uint8Array.from(t).reverse()))},e.numberToBytesBE=l,e.numberToBytesLE=function(t,e){return l(t,e).reverse()},e.numberToVarBytesBE=function(t){return f(h(t))},e.ensureBytes=function(t,e,r){let i;if("string"==typeof e)try{i=f(e)}catch(r){throw new Error(`${t} must be valid hex string, got "${e}". Cause: ${r}`)}else{if(!o(e))throw new Error(`${t} must be hex string or Uint8Array`);i=Uint8Array.from(e)}const n=i.length;if("number"==typeof r&&n!==r)throw new Error(`${t} expected ${r} bytes, got ${n}`);return i},e.concatBytes=c,e.equalBytes=function(t,e){if(t.length!==e.length)return!1;for(let r=0;r<t.length;r++)if(t[r]!==e[r])return!1;return!0},e.utf8ToBytes=function(t){if("string"!=typeof t)throw new Error("utf8ToBytes expected string, got "+typeof t);return new Uint8Array((new TextEncoder).encode(t))},e.bitLen=function(t){let e;for(e=0;t>r;t>>=i,e+=1);return e},e.bitGet=function(t,e){return t>>BigInt(e)&i},e.bitSet=(t,e,n)=>t|(n?i:r)<<BigInt(e),e.bitMask=t=>(n<<BigInt(t-1))-i;const d=t=>new Uint8Array(t),p=t=>Uint8Array.from(t);e.createHmacDrbg=function(t,e,r){if("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");if("function"!=typeof r)throw new Error("hmacFn must be a function");let i=d(t),n=d(t),o=0;const s=()=>{i.fill(1),n.fill(0),o=0},a=(...t)=>r(n,i,...t),h=(t=d())=>{n=a(p([0]),t),i=a(),0!==t.length&&(n=a(p([1]),t),i=a())},u=()=>{if(o++>=1e3)throw new Error("drbg: tried 1000 values");let t=0;const r=[];for(;t<e;){i=a();const e=i.slice();r.push(e),t+=i.length}return c(...r)};return(t,e)=>{let r;for(s(),h(t);!(r=e(u()));)h();return s(),r}};const m={bigint:t=>"bigint"==typeof t,function:t=>"function"==typeof t,boolean:t=>"boolean"==typeof t,string:t=>"string"==typeof t,isSafeInteger:t=>Number.isSafeInteger(t),array:t=>Array.isArray(t),field:(t,e)=>e.Fp.isValid(t),hash:t=>"function"==typeof t&&Number.isSafeInteger(t.outputLen)};e.validateObject=function(t,e,r={}){const i=(e,r,i)=>{const n=m[r];if("function"!=typeof n)throw new Error(`Invalid validator "${r}", expected function`);const o=t[e];if(!(i&&void 0===o||n(o,t)))throw new Error(`Invalid param ${String(e)}=${o} (${typeof o}), expected ${r}`)};for(const[t,r]of Object.entries(e))i(t,r,!1);for(const[t,e]of Object.entries(r))i(t,e,!0);return t}},7851:(t,e,r)=>{"use strict";Object.defineProperty(e,"__esModule",{value:!0}),e.mapToCurveSimpleSWU=e.SWUFpSqrtRatio=e.weierstrass=e.weierstrassPoints=e.DER=void 0;const i=r(9530),n=r(4323),o=r(4323),s=r(1465),{bytesToNumberBE:a,hexToBytes:h}=n;e.DER={Err:class extends Error{constructor(t=""){super(t)}},_parseInt(t){const{Err:r}=e.DER;if(t.length<2||2!==t[0])throw new r("Invalid signature integer tag");const i=t[1],n=t.subarray(2,i+2);if(!i||n.length!==i)throw new r("Invalid signature integer: wrong length");if(128&n[0])throw new r("Invalid signature integer: negative");if(0===n[0]&&!(128&n[1]))throw new r("Invalid signature integer: unnecessary leading zero");return{d:a(n),l:t.subarray(i+2)}},toSig(t){const{Err:r}=e.DER,i="string"==typeof t?h(t):t;if(!(i instanceof Uint8Array))throw new Error("ui8a expected");let n=i.length;if(n<2||48!=i[0])throw new r("Invalid signature tag");if(i[1]!==n-2)throw new r("Invalid signature: incorrect length");const{d:o,l:s}=e.DER._parseInt(i.subarray(2)),{d:a,l:u}=e.DER._parseInt(s);if(u.length)throw new r("Invalid signature: left bytes after parsing");return{r:o,s:a}},hexFromSig(t){const e=t=>8&Number.parseInt(t[0],16)?"00"+t:t,r=t=>{const e=t.toString(16);return 1&e.length?`0${e}`:e},i=e(r(t.s)),n=e(r(t.r)),o=i.length/2,s=n.length/2,a=r(o),h=r(s);return`30${r(s+o+4)}02${h}${n}02${a}${i}`}};const u=BigInt(0),f=BigInt(1),l=BigInt(2),c=BigInt(3),d=BigInt(4);function p(t){const e=function(t){const e=(0,s.validateBasic)(t);n.validateObject(e,{a:"field",b:"field"},{allowedPrivateKeyLengths:"array",wrapPrivateKey:"boolean",isTorsionFree:"function",clearCofactor:"function",allowInfinityPoint:"boolean",fromBytes:"function",toBytes:"function"});const{endo:r,Fp:i,a:o}=e;if(r){if(!i.eql(o,i.ZERO))throw new Error("Endomorphism can only be defined for Koblitz curves that have a=0");if("object"!=typeof r||"bigint"!=typeof r.beta||"function"!=typeof r.splitScalar)throw new Error("Expected endomorphism with beta: bigint and splitScalar: function")}return Object.freeze({...e})}(t),{Fp:r}=e,a=e.toBytes||((t,e,i)=>{const o=e.toAffine();return n.concatBytes(Uint8Array.from([4]),r.toBytes(o.x),r.toBytes(o.y))}),h=e.fromBytes||(t=>{const e=t.subarray(1);return{x:r.fromBytes(e.subarray(0,r.BYTES)),y:r.fromBytes(e.subarray(r.BYTES,2*r.BYTES))}});function l(t){const{a:i,b:n}=e,o=r.sqr(t),s=r.mul(o,t);return r.add(r.add(s,r.mul(t,i)),n)}if(!r.eql(r.sqr(e.Gy),l(e.Gx)))throw new Error("bad generator point: equation left != right");function d(t){return"bigint"==typeof t&&u<t&&t<e.n}function p(t){if(!d(t))throw new Error("Expected valid bigint: 0 < bigint < curve.n")}function m(t){const{allowedPrivateKeyLengths:r,nByteLength:s,wrapPrivateKey:a,n:h}=e;if(r&&"bigint"!=typeof t){if(t instanceof Uint8Array&&(t=n.bytesToHex(t)),"string"!=typeof t||!r.includes(t.length))throw new Error("Invalid key");t=t.padStart(2*s,"0")}let u;try{u="bigint"==typeof t?t:n.bytesToNumberBE((0,o.ensureBytes)("private key",t,s))}catch(e){throw new Error(`private key must be ${s} bytes, hex or bigint, not ${typeof t}`)}return a&&(u=i.mod(u,h)),p(u),u}const b=new Map;function g(t){if(!(t instanceof y))throw new Error("ProjectivePoint expected")}class y{constructor(t,e,i){if(this.px=t,this.py=e,this.pz=i,null==t||!r.isValid(t))throw new Error("x required");if(null==e||!r.isValid(e))throw new Error("y required");if(null==i||!r.isValid(i))throw new Error("z required")}static fromAffine(t){const{x:e,y:i}=t||{};if(!t||!r.isValid(e)||!r.isValid(i))throw new Error("invalid affine point");if(t instanceof y)throw new Error("projective point not allowed");const n=t=>r.eql(t,r.ZERO);return n(e)&&n(i)?y.ZERO:new y(e,i,r.ONE)}get x(){return this.toAffine().x}get y(){return this.toAffine().y}static normalizeZ(t){const e=r.invertBatch(t.map((t=>t.pz)));return t.map(((t,r)=>t.toAffine(e[r]))).map(y.fromAffine)}static fromHex(t){const e=y.fromAffine(h((0,o.ensureBytes)("pointHex",t)));return e.assertValidity(),e}static fromPrivateKey(t){return y.BASE.multiply(m(t))}_setWindowSize(t){this._WINDOW_SIZE=t,b.delete(this)}assertValidity(){if(this.is0()){if(e.allowInfinityPoint)return;throw new Error("bad point: ZERO")}const{x:t,y:i}=this.toAffine();if(!r.isValid(t)||!r.isValid(i))throw new Error("bad point: x or y not FE");const n=r.sqr(i),o=l(t);if(!r.eql(n,o))throw new Error("bad point: equation left != right");if(!this.isTorsionFree())throw new Error("bad point: not in prime-order subgroup")}hasEvenY(){const{y:t}=this.toAffine();if(r.isOdd)return!r.isOdd(t);throw new Error("Field doesn't support isOdd")}equals(t){g(t);const{px:e,py:i,pz:n}=this,{px:o,py:s,pz:a}=t,h=r.eql(r.mul(e,a),r.mul(o,n)),u=r.eql(r.mul(i,a),r.mul(s,n));return h&&u}negate(){return new y(this.px,r.neg(this.py),this.pz)}double(){const{a:t,b:i}=e,n=r.mul(i,c),{px:o,py:s,pz:a}=this;let h=r.ZERO,u=r.ZERO,f=r.ZERO,l=r.mul(o,o),d=r.mul(s,s),p=r.mul(a,a),m=r.mul(o,s);return m=r.add(m,m),f=r.mul(o,a),f=r.add(f,f),h=r.mul(t,f),u=r.mul(n,p),u=r.add(h,u),h=r.sub(d,u),u=r.add(d,u),u=r.mul(h,u),h=r.mul(m,h),f=r.mul(n,f),p=r.mul(t,p),m=r.sub(l,p),m=r.mul(t,m),m=r.add(m,f),f=r.add(l,l),l=r.add(f,l),l=r.add(l,p),l=r.mul(l,m),u=r.add(u,l),p=r.mul(s,a),p=r.add(p,p),l=r.mul(p,m),h=r.sub(h,l),f=r.mul(p,d),f=r.add(f,f),f=r.add(f,f),new y(h,u,f)}add(t){g(t);const{px:i,py:n,pz:o}=this,{px:s,py:a,pz:h}=t;let u=r.ZERO,f=r.ZERO,l=r.ZERO;const d=e.a,p=r.mul(e.b,c);let m=r.mul(i,s),b=r.mul(n,a),v=r.mul(o,h),w=r.add(i,n),M=r.add(s,a);w=r.mul(w,M),M=r.add(m,b),w=r.sub(w,M),M=r.add(i,o);let _=r.add(s,h);return M=r.mul(M,_),_=r.add(m,v),M=r.sub(M,_),_=r.add(n,o),u=r.add(a,h),_=r.mul(_,u),u=r.add(b,v),_=r.sub(_,u),l=r.mul(d,M),u=r.mul(p,v),l=r.add(u,l),u=r.sub(b,l),l=r.add(b,l),f=r.mul(u,l),b=r.add(m,m),b=r.add(b,m),v=r.mul(d,v),M=r.mul(p,M),b=r.add(b,v),v=r.sub(m,v),v=r.mul(d,v),M=r.add(M,v),m=r.mul(b,M),f=r.add(f,m),m=r.mul(_,M),u=r.mul(w,u),u=r.sub(u,m),m=r.mul(w,b),l=r.mul(_,l),l=r.add(l,m),new y(u,f,l)}subtract(t){return this.add(t.negate())}is0(){return this.equals(y.ZERO)}wNAF(t){return w.wNAFCached(this,b,t,(t=>{const e=r.invertBatch(t.map((t=>t.pz)));return t.map(((t,r)=>t.toAffine(e[r]))).map(y.fromAffine)}))}multiplyUnsafe(t){const i=y.ZERO;if(t===u)return i;if(p(t),t===f)return this;const{endo:n}=e;if(!n)return w.unsafeLadder(this,t);let{k1neg:o,k1:s,k2neg:a,k2:h}=n.splitScalar(t),l=i,c=i,d=this;for(;s>u||h>u;)s&f&&(l=l.add(d)),h&f&&(c=c.add(d)),d=d.double(),s>>=f,h>>=f;return o&&(l=l.negate()),a&&(c=c.negate()),c=new y(r.mul(c.px,n.beta),c.py,c.pz),l.add(c)}multiply(t){p(t);let i,n,o=t;const{endo:s}=e;if(s){const{k1neg:t,k1:e,k2neg:a,k2:h}=s.splitScalar(o);let{p:u,f}=this.wNAF(e),{p:l,f:c}=this.wNAF(h);u=w.constTimeNegate(t,u),l=w.constTimeNegate(a,l),l=new y(r.mul(l.px,s.beta),l.py,l.pz),i=u.add(l),n=f.add(c)}else{const{p:t,f:e}=this.wNAF(o);i=t,n=e}return y.normalizeZ([i,n])[0]}multiplyAndAddUnsafe(t,e,r){const i=y.BASE,n=(t,e)=>e!==u&&e!==f&&t.equals(i)?t.multiply(e):t.multiplyUnsafe(e),o=n(this,e).add(n(t,r));return o.is0()?void 0:o}toAffine(t){const{px:e,py:i,pz:n}=this,o=this.is0();null==t&&(t=o?r.ONE:r.inv(n));const s=r.mul(e,t),a=r.mul(i,t),h=r.mul(n,t);if(o)return{x:r.ZERO,y:r.ZERO};if(!r.eql(h,r.ONE))throw new Error("invZ was invalid");return{x:s,y:a}}isTorsionFree(){const{h:t,isTorsionFree:r}=e;if(t===f)return!0;if(r)return r(y,this);throw new Error("isTorsionFree() has not been declared for the elliptic curve")}clearCofactor(){const{h:t,clearCofactor:r}=e;return t===f?this:r?r(y,this):this.multiplyUnsafe(e.h)}toRawBytes(t=!0){return this.assertValidity(),a(y,this,t)}toHex(t=!0){return n.bytesToHex(this.toRawBytes(t))}}y.BASE=new y(e.Gx,e.Gy,r.ONE),y.ZERO=new y(r.ZERO,r.ONE,r.ZERO);const v=e.nBitLength,w=(0,s.wNAF)(y,e.endo?Math.ceil(v/2):v);return{CURVE:e,ProjectivePoint:y,normPrivateKeyToScalar:m,weierstrassEquation:l,isWithinCurveOrder:d}}function m(t,e){const r=t.ORDER;let i=u;for(let t=r-f;t%l===u;t/=l)i+=f;const n=i,o=l<<n-f-f,s=o*l,a=(r-f)/s,h=(a-f)/l,p=s-f,m=o,b=t.pow(e,a),g=t.pow(e,(a+f)/l);let y=(e,r)=>{let i=b,o=t.pow(r,p),s=t.sqr(o);s=t.mul(s,r);let a=t.mul(e,s);a=t.pow(a,h),a=t.mul(a,o),o=t.mul(a,r),s=t.mul(a,e);let u=t.mul(s,o);a=t.pow(u,m);let c=t.eql(a,t.ONE);o=t.mul(s,g),a=t.mul(u,i),s=t.cmov(o,s,c),u=t.cmov(a,u,c);for(let e=n;e>f;e--){let r=e-l;r=l<<r-f;let n=t.pow(u,r);const a=t.eql(n,t.ONE);o=t.mul(s,i),i=t.mul(i,i),n=t.mul(u,i),s=t.cmov(o,s,a),u=t.cmov(n,u,a)}return{isValid:c,value:s}};if(t.ORDER%d===c){const r=(t.ORDER-c)/d,i=t.sqrt(t.neg(e));y=(e,n)=>{let o=t.sqr(n);const s=t.mul(e,n);o=t.mul(o,s);let a=t.pow(o,r);a=t.mul(a,s);const h=t.mul(a,i),u=t.mul(t.sqr(a),n),f=t.eql(u,e);return{isValid:f,value:t.cmov(h,a,f)}}}return y}e.weierstrassPoints=p,e.weierstrass=function(t){const r=function(t){const e=(0,s.validateBasic)(t);return n.validateObject(e,{hash:"hash",hmac:"function",randomBytes:"function"},{bits2int:"function",bits2int_modN:"function",lowS:"boolean"}),Object.freeze({lowS:!0,...e})}(t),{Fp:a,n:h}=r,l=a.BYTES+1,c=2*a.BYTES+1;function d(t){return i.mod(t,h)}function m(t){return i.invert(t,h)}const{ProjectivePoint:b,normPrivateKeyToScalar:g,weierstrassEquation:y,isWithinCurveOrder:v}=p({...r,toBytes(t,e,r){const i=e.toAffine(),o=a.toBytes(i.x),s=n.concatBytes;return r?s(Uint8Array.from([e.hasEvenY()?2:3]),o):s(Uint8Array.from([4]),o,a.toBytes(i.y))},fromBytes(t){const e=t.length,r=t[0],i=t.subarray(1);if(e!==l||2!==r&&3!==r){if(e===c&&4===r)return{x:a.fromBytes(i.subarray(0,a.BYTES)),y:a.fromBytes(i.subarray(a.BYTES,2*a.BYTES))};throw new Error(`Point of length ${e} was invalid. Expected ${l} compressed bytes or ${c} uncompressed bytes`)}{const t=n.bytesToNumberBE(i);if(!(u<(o=t)&&o<a.ORDER))throw new Error("Point is not on curve");const e=y(t);let s=a.sqrt(e);return 1==(1&r)!=((s&f)===f)&&(s=a.neg(s)),{x:t,y:s}}var o}}),w=t=>n.bytesToHex(n.numberToBytesBE(t,r.nByteLength));function M(t){return t>h>>f}const _=(t,e,r)=>n.bytesToNumberBE(t.slice(e,r));class E{constructor(t,e,r){this.r=t,this.s=e,this.recovery=r,this.assertValidity()}static fromCompact(t){const e=r.nByteLength;return t=(0,o.ensureBytes)("compactSignature",t,2*e),new E(_(t,0,e),_(t,e,2*e))}static fromDER(t){const{r,s:i}=e.DER.toSig((0,o.ensureBytes)("DER",t));return new E(r,i)}assertValidity(){if(!v(this.r))throw new Error("r must be 0 < r < CURVE.n");if(!v(this.s))throw new Error("s must be 0 < s < CURVE.n")}addRecoveryBit(t){return new E(this.r,this.s,t)}recoverPublicKey(t){const{r:e,s:i,recovery:n}=this,s=x((0,o.ensureBytes)("msgHash",t));if(null==n||![0,1,2,3].includes(n))throw new Error("recovery id invalid");const h=2===n||3===n?e+r.n:e;if(h>=a.ORDER)throw new Error("recovery id 2 or 3 invalid");const u=0==(1&n)?"02":"03",f=b.fromHex(u+w(h)),l=m(h),c=d(-s*l),p=d(i*l),g=b.BASE.multiplyAndAddUnsafe(f,c,p);if(!g)throw new Error("point at infinify");return g.assertValidity(),g}hasHighS(){return M(this.s)}normalizeS(){return this.hasHighS()?new E(this.r,d(-this.s),this.recovery):this}toDERRawBytes(){return n.hexToBytes(this.toDERHex())}toDERHex(){return e.DER.hexFromSig({r:this.r,s:this.s})}toCompactRawBytes(){return n.hexToBytes(this.toCompactHex())}toCompactHex(){return w(this.r)+w(this.s)}}const S={isValidPrivateKey(t){try{return g(t),!0}catch(t){return!1}},normPrivateKeyToScalar:g,randomPrivateKey:()=>{const t=r.randomBytes(a.BYTES+8),e=i.hashToPrivateScalar(t,h);return n.numberToBytesBE(e,r.nByteLength)},precompute:(t=8,e=b.BASE)=>(e._setWindowSize(t),e.multiply(BigInt(3)),e)};function A(t){const e=t instanceof Uint8Array,r="string"==typeof t,i=(e||r)&&t.length;return e?i===l||i===c:r?i===2*l||i===2*c:t instanceof b}const B=r.bits2int||function(t){const e=n.bytesToNumberBE(t),i=8*t.length-r.nBitLength;return i>0?e>>BigInt(i):e},x=r.bits2int_modN||function(t){return d(B(t))},k=n.bitMask(r.nBitLength);function R(t){if("bigint"!=typeof t)throw new Error("bigint expected");if(!(u<=t&&t<k))throw new Error(`bigint expected < 2^${r.nBitLength}`);return n.numberToBytesBE(t,r.nByteLength)}const C={lowS:r.lowS,prehash:!1},D={lowS:r.lowS,prehash:!1};return b.BASE._setWindowSize(8),{CURVE:r,getPublicKey:function(t,e=!0){return b.fromPrivateKey(t).toRawBytes(e)},getSharedSecret:function(t,e,r=!0){if(A(t))throw new Error("first arg must be private key");if(!A(e))throw new Error("second arg must be public key");return b.fromHex(e).multiply(g(t)).toRawBytes(r)},sign:function(t,e,i=C){const{seed:s,k2sig:h}=function(t,e,i=C){if(["recovered","canonical"].some((t=>t in i)))throw new Error("sign() legacy options not supported");const{hash:s,randomBytes:h}=r;let{lowS:l,prehash:c,extraEntropy:p}=i;null==l&&(l=!0),t=(0,o.ensureBytes)("msgHash",t),c&&(t=(0,o.ensureBytes)("prehashed msgHash",s(t)));const y=x(t),w=g(e),_=[R(w),R(y)];if(null!=p){const t=!0===p?h(a.BYTES):p;_.push((0,o.ensureBytes)("extraEntropy",t,a.BYTES))}const S=n.concatBytes(..._),A=y;return{seed:S,k2sig:function(t){const e=B(t);if(!v(e))return;const r=m(e),i=b.BASE.multiply(e).toAffine(),n=d(i.x);if(n===u)return;const o=d(r*d(A+n*w));if(o===u)return;let s=(i.x===n?0:2)|Number(i.y&f),a=o;return l&&M(o)&&(a=function(t){return M(t)?d(-t):t}(o),s^=1),new E(n,a,s)}}}(t,e,i),l=r;return n.createHmacDrbg(l.hash.outputLen,l.nByteLength,l.hmac)(s,h)},verify:function(t,i,n,s=D){const a=t;if(i=(0,o.ensureBytes)("msgHash",i),n=(0,o.ensureBytes)("publicKey",n),"strict"in s)throw new Error("options.strict was renamed to lowS");const{lowS:h,prehash:u}=s;let f,l;try{if("string"==typeof a||a instanceof Uint8Array)try{f=E.fromDER(a)}catch(t){if(!(t instanceof e.DER.Err))throw t;f=E.fromCompact(a)}else{if("object"!=typeof a||"bigint"!=typeof a.r||"bigint"!=typeof a.s)throw new Error("PARSE");{const{r:t,s:e}=a;f=new E(t,e)}}l=b.fromHex(n)}catch(t){if("PARSE"===t.message)throw new Error("signature must be Signature instance, Uint8Array or hex string");return!1}if(h&&f.hasHighS())return!1;u&&(i=r.hash(i));const{r:c,s:p}=f,g=x(i),y=m(p),v=d(g*y),w=d(c*y),M=b.BASE.multiplyAndAddUnsafe(l,v,w)?.toAffine();return!!M&&d(M.x)===c},ProjectivePoint:b,Signature:E,utils:S}},e.SWUFpSqrtRatio=m,e.mapToCurveSimpleSWU=function(t,e){if(i.validateField(t),!t.isValid(e.A)||!t.isValid(e.B)||!t.isValid(e.Z))throw new Error("mapToCurveSimpleSWU: invalid opts");const r=m(t,e.Z);if(!t.isOdd)throw new Error("Fp.isOdd is not implemented!");return i=>{let n,o,s,a,h,u,f,l;n=t.sqr(i),n=t.mul(n,e.Z),o=t.sqr(n),o=t.add(o,n),s=t.add(o,t.ONE),s=t.mul(s,e.B),a=t.cmov(e.Z,t.neg(o),!t.eql(o,t.ZERO)),a=t.mul(a,e.A),o=t.sqr(s),u=t.sqr(a),h=t.mul(u,e.A),o=t.add(o,h),o=t.mul(o,s),u=t.mul(u,a),h=t.mul(u,e.B),o=t.add(o,h),f=t.mul(n,s);const{isValid:c,value:d}=r(o,u);l=t.mul(n,i),l=t.mul(l,d),f=t.cmov(f,s,c),l=t.cmov(l,d,c);const p=t.isOdd(i)===t.isOdd(l);return l=t.cmov(t.neg(l),l,p),f=t.div(f,a),{x:f,y:l}}}},8358:(t,e,r)=>{"use strict";Object.defineProperty(e,"__esModule",{value:!0}),e.encodeToCurve=e.hashToCurve=e.schnorr=e.secp256k1=void 0;const i=r(6053),n=r(64),o=r(9530),s=r(7851),a=r(4323),h=r(1322),u=r(5887),f=BigInt("0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f"),l=BigInt("0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141"),c=BigInt(1),d=BigInt(2),p=(t,e)=>(t+e/d)/e;function m(t){const e=f,r=BigInt(3),i=BigInt(6),n=BigInt(11),s=BigInt(22),a=BigInt(23),h=BigInt(44),u=BigInt(88),l=t*t*t%e,c=l*l*t%e,p=(0,o.pow2)(c,r,e)*c%e,m=(0,o.pow2)(p,r,e)*c%e,g=(0,o.pow2)(m,d,e)*l%e,y=(0,o.pow2)(g,n,e)*g%e,v=(0,o.pow2)(y,s,e)*y%e,w=(0,o.pow2)(v,h,e)*v%e,M=(0,o.pow2)(w,u,e)*w%e,_=(0,o.pow2)(M,h,e)*v%e,E=(0,o.pow2)(_,r,e)*c%e,S=(0,o.pow2)(E,a,e)*y%e,A=(0,o.pow2)(S,i,e)*l%e,B=(0,o.pow2)(A,d,e);if(!b.eql(b.sqr(B),t))throw new Error("Cannot find square root");return B}const b=(0,o.Field)(f,void 0,void 0,{sqrt:m});e.secp256k1=(0,u.createCurve)({a:BigInt(0),b:BigInt(7),Fp:b,n:l,Gx:BigInt("55066263022277343669578718895168534326250603453777594175500187360389116729240"),Gy:BigInt("32670510020758816978083085130507043184471273380659243275938904335757337482424"),h:BigInt(1),lowS:!0,endo:{beta:BigInt("0x7ae96a2b657c07106e64479eac3434e99cf0497512f58995c1396c28719501ee"),splitScalar:t=>{const e=l,r=BigInt("0x3086d221a7d46bcde86c90e49284eb15"),i=-c*BigInt("0xe4437ed6010e88286f547fa90abfe4c3"),n=BigInt("0x114ca50f7a8e2f3f657c1108d9d44cfd8"),s=r,a=BigInt("0x100000000000000000000000000000000"),h=p(s*t,e),u=p(-i*t,e);let f=(0,o.mod)(t-h*r-u*n,e),d=(0,o.mod)(-h*i-u*s,e);const m=f>a,b=d>a;if(m&&(f=e-f),b&&(d=e-d),f>a||d>a)throw new Error("splitScalar: Endomorphism failed, k="+t);return{k1neg:m,k1:f,k2neg:b,k2:d}}}},i.sha256);const g=BigInt(0),y=t=>"bigint"==typeof t&&g<t&&t<f,v=t=>"bigint"==typeof t&&g<t&&t<l,w={};function M(t,...e){let r=w[t];if(void 0===r){const e=(0,i.sha256)(Uint8Array.from(t,(t=>t.charCodeAt(0))));r=(0,a.concatBytes)(e,e),w[t]=r}return(0,i.sha256)((0,a.concatBytes)(r,...e))}const _=t=>t.toRawBytes(!0).slice(1),E=t=>(0,a.numberToBytesBE)(t,32),S=t=>(0,o.mod)(t,f),A=t=>(0,o.mod)(t,l),B=e.secp256k1.ProjectivePoint,x=(t,e,r)=>B.BASE.multiplyAndAddUnsafe(t,e,r);function k(t){let r=e.secp256k1.utils.normPrivateKeyToScalar(t),i=B.fromPrivateKey(r);return{scalar:i.hasEvenY()?r:A(-r),bytes:_(i)}}function R(t){if(!y(t))throw new Error("bad x: need 0 < x < p");const e=S(t*t);let r=m(S(e*t+BigInt(7)));r%d!==g&&(r=S(-r));const i=new B(t,r,c);return i.assertValidity(),i}function C(...t){return A((0,a.bytesToNumberBE)(M("BIP0340/challenge",...t)))}function D(t,e,r){const i=(0,a.ensureBytes)("signature",t,64),n=(0,a.ensureBytes)("message",e),o=(0,a.ensureBytes)("publicKey",r,32);try{const t=R((0,a.bytesToNumberBE)(o)),e=(0,a.bytesToNumberBE)(i.subarray(0,32));if(!y(e))return!1;const r=(0,a.bytesToNumberBE)(i.subarray(32,64));if(!v(r))return!1;const s=C(E(e),_(t),n),h=x(t,r,A(-s));return!(!h||!h.hasEvenY()||h.toAffine().x!==e)}catch(t){return!1}}e.schnorr={getPublicKey:function(t){return k(t).bytes},sign:function(t,e,r=(0,n.randomBytes)(32)){const i=(0,a.ensureBytes)("message",t),{bytes:o,scalar:s}=k(e),h=(0,a.ensureBytes)("auxRand",r,32),u=E(s^(0,a.bytesToNumberBE)(M("BIP0340/aux",h))),f=M("BIP0340/nonce",u,o,i),l=A((0,a.bytesToNumberBE)(f));if(l===g)throw new Error("sign failed: k is zero");const{bytes:c,scalar:d}=k(l),p=C(c,o,i),m=new Uint8Array(64);if(m.set(c,0),m.set(E(A(d+p*s)),32),!D(m,i,o))throw new Error("sign: Invalid signature produced");return m},verify:D,utils:{randomPrivateKey:e.secp256k1.utils.randomPrivateKey,lift_x:R,pointToBytes:_,numberToBytesBE:a.numberToBytesBE,bytesToNumberBE:a.bytesToNumberBE,taggedHash:M,mod:o.mod}};const O=(()=>(0,h.isogenyMap)(b,[["0x8e38e38e38e38e38e38e38e38e38e38e38e38e38e38e38e38e38e38daaaaa8c7","0x7d3d4c80bc321d5b9f315cea7fd44c5d595d2fc0bf63b92dfff1044f17c6581","0x534c328d23f234e6e2a413deca25caece4506144037c40314ecbd0b53d9dd262","0x8e38e38e38e38e38e38e38e38e38e38e38e38e38e38e38e38e38e38daaaaa88c"],["0xd35771193d94918a9ca34ccbb7b640dd86cd409542f8487d9fe6b745781eb49b","0xedadc6f64383dc1df7c4b2d51b54225406d36b641f5e41bbc52a56612a8c6d14","0x0000000000000000000000000000000000000000000000000000000000000001"],["0x4bda12f684bda12f684bda12f684bda12f684bda12f684bda12f684b8e38e23c","0xc75e0c32d5cb7c0fa9d0a54b12a0a6d5647ab046d686da6fdffc90fc201d71a3","0x29a6194691f91a73715209ef6512e576722830a201be2018a765e85a9ecee931","0x2f684bda12f684bda12f684bda12f684bda12f684bda12f684bda12f38e38d84"],["0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffefffff93b","0x7a06534bb8bdb49fd5e9e6632722c2989467c1bfc8e8d978dfb425d2685c2573","0x6484aa716545ca2cf3a70c3fa8fe337e0a3d21162f0d6299a7bf8192bfd2a76f","0x0000000000000000000000000000000000000000000000000000000000000001"]].map((t=>t.map((t=>BigInt(t)))))))(),I=(()=>(0,s.mapToCurveSimpleSWU)(b,{A:BigInt("0x3f8731abdd661adca08a5558f0f5d272e953d363cb6f0e5d405447c01a444533"),B:BigInt("1771"),Z:b.create(BigInt("-11"))}))(),F=(()=>(0,h.createHasher)(e.secp256k1.ProjectivePoint,(t=>{const{x:e,y:r}=I(b.create(t[0]));return O(e,r)}),{DST:"secp256k1_XMD:SHA-256_SSWU_RO_",encodeDST:"secp256k1_XMD:SHA-256_SSWU_NU_",p:b.ORDER,m:1,k:128,expand:"xmd",hash:i.sha256}))();e.hashToCurve=F.hashToCurve,e.encodeToCurve=F.encodeToCurve},3525:(t,e)=>{"use strict";function r(t){if(!Number.isSafeInteger(t)||t<0)throw new Error(`Wrong positive integer: ${t}`)}function i(t){if("boolean"!=typeof t)throw new Error(`Expected boolean, not ${t}`)}function n(t,...e){if(!(t instanceof Uint8Array))throw new Error("Expected Uint8Array");if(e.length>0&&!e.includes(t.length))throw new Error(`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");r(t.outputLen),r(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){n(t);const r=e.outputLen;if(t.length<r)throw new Error(`digestInto() expects output buffer of length at least ${r}`)}Object.defineProperty(e,"__esModule",{value:!0}),e.output=e.exists=e.hash=e.bytes=e.bool=e.number=void 0,e.number=r,e.bool=i,e.bytes=n,e.hash=o,e.exists=s,e.output=a;const h={number:r,bool:i,bytes:n,hash:o,exists:s,output:a};e.default=h},9350:(t,e,r)=>{"use strict";Object.defineProperty(e,"__esModule",{value:!0}),e.SHA2=void 0;const i=r(3525),n=r(64);class o extends n.Hash{constructor(t,e,r,i){super(),this.blockLen=t,this.outputLen=e,this.padOffset=r,this.isLE=i,this.finished=!1,this.length=0,this.pos=0,this.destroyed=!1,this.buffer=new Uint8Array(t),this.view=(0,n.createView)(this.buffer)}update(t){i.default.exists(this);const{view:e,buffer:r,blockLen:o}=this,s=(t=(0,n.toBytes)(t)).length;for(let i=0;i<s;){const a=Math.min(o-this.pos,s-i);if(a!==o)r.set(t.subarray(i,i+a),this.pos),this.pos+=a,i+=a,this.pos===o&&(this.process(e,0),this.pos=0);else{const e=(0,n.createView)(t);for(;o<=s-i;i+=o)this.process(e,i)}}return this.length+=t.length,this.roundClean(),this}digestInto(t){i.default.exists(this),i.default.output(t,this),this.finished=!0;const{buffer:e,view:r,blockLen:o,isLE:s}=this;let{pos:a}=this;e[a++]=128,this.buffer.subarray(a).fill(0),this.padOffset>o-a&&(this.process(r,0),a=0);for(let t=a;t<o;t++)e[t]=0;!function(t,e,r,i){if("function"==typeof t.setBigUint64)return t.setBigUint64(e,r,i);const n=BigInt(32),o=BigInt(4294967295),s=Number(r>>n&o),a=Number(r&o),h=i?4:0,u=i?0:4;t.setUint32(e+h,s,i),t.setUint32(e+u,a,i)}(r,o-8,BigInt(8*this.length),s),this.process(r,0);const h=(0,n.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++)h.setUint32(4*t,l[t],s)}digest(){const{buffer:t,outputLen:e}=this;this.digestInto(t);const r=t.slice(0,e);return this.destroy(),r}_cloneInto(t){t||(t=new this.constructor),t.set(...this.get());const{blockLen:e,buffer:r,length:i,finished:n,destroyed:o,pos:s}=this;return t.length=i,t.pos=s,t.finished=n,t.destroyed=o,i%e&&t.buffer.set(r),t}}e.SHA2=o},825:(t,e)=>{"use strict";Object.defineProperty(e,"__esModule",{value:!0}),e.crypto=void 0,e.crypto="object"==typeof globalThis&&"crypto"in globalThis?globalThis.crypto:void 0},7760:(t,e,r)=>{"use strict";Object.defineProperty(e,"__esModule",{value:!0}),e.hkdf=e.expand=e.extract=void 0;const i=r(3525),n=r(64),o=r(1377);function s(t,e,r){return i.default.hash(t),void 0===r&&(r=new Uint8Array(t.outputLen)),(0,o.hmac)(t,(0,n.toBytes)(r),(0,n.toBytes)(e))}e.extract=s;const a=new Uint8Array([0]),h=new Uint8Array;function u(t,e,r,n=32){if(i.default.hash(t),i.default.number(n),n>255*t.outputLen)throw new Error("Length should be <= 255*HashLen");const s=Math.ceil(n/t.outputLen);void 0===r&&(r=h);const u=new Uint8Array(s*t.outputLen),f=o.hmac.create(t,e),l=f._cloneInto(),c=new Uint8Array(f.outputLen);for(let e=0;e<s;e++)a[0]=e+1,l.update(0===e?h:c).update(r).update(a).digestInto(c),u.set(c,t.outputLen*e),f._cloneInto(l);return f.destroy(),l.destroy(),c.fill(0),a.fill(0),u.slice(0,n)}e.expand=u,e.hkdf=(t,e,r,i,n)=>u(t,s(t,e,r),i,n)},1377:(t,e,r)=>{"use strict";Object.defineProperty(e,"__esModule",{value:!0}),e.hmac=e.HMAC=void 0;const i=r(3525),n=r(64);class o extends n.Hash{constructor(t,e){super(),this.finished=!1,this.destroyed=!1,i.default.hash(t);const r=(0,n.toBytes)(e);if(this.iHash=t.create(),"function"!=typeof this.iHash.update)throw new Error("Expected instance of class which extends utils.Hash");this.blockLen=this.iHash.blockLen,this.outputLen=this.iHash.outputLen;const o=this.blockLen,s=new Uint8Array(o);s.set(r.length>o?t.create().update(r).digest():r);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 i.default.exists(this),this.iHash.update(t),this}digestInto(t){i.default.exists(this),i.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:r,finished:i,destroyed:n,blockLen:o,outputLen:s}=this;return t.finished=i,t.destroyed=n,t.blockLen=o,t.outputLen=s,t.oHash=e._cloneInto(t.oHash),t.iHash=r._cloneInto(t.iHash),t}destroy(){this.destroyed=!0,this.oHash.destroy(),this.iHash.destroy()}}e.HMAC=o,e.hmac=(t,e,r)=>new o(t,e).update(r).digest(),e.hmac.create=(t,e)=>new o(t,e)},6053:(t,e,r)=>{"use strict";Object.defineProperty(e,"__esModule",{value:!0}),e.sha224=e.sha256=void 0;const i=r(9350),n=r(64),o=(t,e,r)=>t&e^t&r^e&r,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]),h=new Uint32Array(64);class u extends i.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:r,D:i,E:n,F:o,G:s,H:a}=this;return[t,e,r,i,n,o,s,a]}set(t,e,r,i,n,o,s,a){this.A=0|t,this.B=0|e,this.C=0|r,this.D=0|i,this.E=0|n,this.F=0|o,this.G=0|s,this.H=0|a}process(t,e){for(let r=0;r<16;r++,e+=4)h[r]=t.getUint32(e,!1);for(let t=16;t<64;t++){const e=h[t-15],r=h[t-2],i=(0,n.rotr)(e,7)^(0,n.rotr)(e,18)^e>>>3,o=(0,n.rotr)(r,17)^(0,n.rotr)(r,19)^r>>>10;h[t]=o+h[t-7]+i+h[t-16]|0}let{A:r,B:i,C:a,D:u,E:f,F:l,G:c,H:d}=this;for(let t=0;t<64;t++){const e=d+((0,n.rotr)(f,6)^(0,n.rotr)(f,11)^(0,n.rotr)(f,25))+((p=f)&l^~p&c)+s[t]+h[t]|0,m=((0,n.rotr)(r,2)^(0,n.rotr)(r,13)^(0,n.rotr)(r,22))+o(r,i,a)|0;d=c,c=l,l=f,f=u+e|0,u=a,a=i,i=r,r=e+m|0}var p;r=r+this.A|0,i=i+this.B|0,a=a+this.C|0,u=u+this.D|0,f=f+this.E|0,l=l+this.F|0,c=c+this.G|0,d=d+this.H|0,this.set(r,i,a,u,f,l,c,d)}roundClean(){h.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,n.wrapConstructor)((()=>new u)),e.sha224=(0,n.wrapConstructor)((()=>new f))},64:(t,e,r)=>{"use strict";Object.defineProperty(e,"__esModule",{value:!0}),e.randomBytes=e.wrapXOFConstructorWithOpts=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 i=r(825),n=t=>t instanceof Uint8Array;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 o=Array.from({length:256},((t,e)=>e.toString(16).padStart(2,"0")));function s(t){if("string"!=typeof t)throw new Error("utf8ToBytes expected string, got "+typeof t);return new Uint8Array((new TextEncoder).encode(t))}function a(t){if("string"==typeof t&&(t=s(t)),!n(t))throw new Error("expected Uint8Array, got "+typeof t);return t}e.bytesToHex=function(t){if(!n(t))throw new Error("Uint8Array expected");let e="";for(let r=0;r<t.length;r++)e+=o[t[r]];return e},e.hexToBytes=function(t){if("string"!=typeof t)throw new Error("hex string expected, got "+typeof t);const e=t.length;if(e%2)throw new Error("padded hex string expected, got unpadded hex of length "+e);const r=new Uint8Array(e/2);for(let e=0;e<r.length;e++){const i=2*e,n=t.slice(i,i+2),o=Number.parseInt(n,16);if(Number.isNaN(o)||o<0)throw new Error("Invalid byte sequence");r[e]=o}return r},e.nextTick=async()=>{},e.asyncLoop=async function(t,r,i){let n=Date.now();for(let o=0;o<t;o++){i(o);const t=Date.now()-n;t>=0&&t<r||(await(0,e.nextTick)(),n+=t)}},e.utf8ToBytes=s,e.toBytes=a,e.concatBytes=function(...t){const e=new Uint8Array(t.reduce(((t,e)=>t+e.length),0));let r=0;return t.forEach((t=>{if(!n(t))throw new Error("Uint8Array expected");e.set(t,r),r+=t.length})),e},e.Hash=class{clone(){return this._cloneInto()}},e.checkOpts=function(t,e){if(void 0!==e&&("object"!=typeof e||(r=e,"[object Object]"!==Object.prototype.toString.call(r)||r.constructor!==Object)))throw new Error("Options should be object or undefined");var r;return Object.assign(t,e)},e.wrapConstructor=function(t){const e=e=>t().update(a(e)).digest(),r=t();return e.outputLen=r.outputLen,e.blockLen=r.blockLen,e.create=()=>t(),e},e.wrapConstructorWithOpts=function(t){const e=(e,r)=>t(r).update(a(e)).digest(),r=t({});return e.outputLen=r.outputLen,e.blockLen=r.blockLen,e.create=e=>t(e),e},e.wrapXOFConstructorWithOpts=function(t){const e=(e,r)=>t(r).update(a(e)).digest(),r=t({});return e.outputLen=r.outputLen,e.blockLen=r.blockLen,e.create=e=>t(e),e},e.randomBytes=function(t=32){if(i.crypto&&"function"==typeof i.crypto.getRandomValues)return i.crypto.getRandomValues(new Uint8Array(t));throw new Error("crypto.getRandomValues must be defined")}},2812:(t,e,r)=>{"use strict";const i=e;i.bignum=r(735),i.define=r(5192).define,i.base=r(4798),i.constants=r(6906),i.decoders=r(8211),i.encoders=r(9116)},5192:(t,e,r)=>{"use strict";const i=r(9116),n=r(8211),o=r(1285);function s(t,e){this.name=t,this.body=e,this.decoders={},this.encoders={}}e.define=function(t,e){return new s(t,e)},s.prototype._createNamed=function(t){const e=this.name;function r(t){this._initNamed(t,e)}return o(r,t),r.prototype._initNamed=function(e,r){t.call(this,e,r)},new r(this)},s.prototype._getDecoder=function(t){return t=t||"der",this.decoders.hasOwnProperty(t)||(this.decoders[t]=this._createNamed(n[t])),this.decoders[t]},s.prototype.decode=function(t,e,r){return this._getDecoder(e).decode(t,r)},s.prototype._getEncoder=function(t){return t=t||"der",this.encoders.hasOwnProperty(t)||(this.encoders[t]=this._createNamed(i[t])),this.encoders[t]},s.prototype.encode=function(t,e,r){return this._getEncoder(e).encode(t,r)}},7362:(t,e,r)=>{"use strict";const i=r(1285),n=r(126).b,o=r(7654).Buffer;function s(t,e){n.call(this,e),o.isBuffer(t)?(this.base=t,this.offset=0,this.length=t.length):this.error("Input not Buffer")}function a(t,e){if(Array.isArray(t))this.length=0,this.value=t.map((function(t){return a.isEncoderBuffer(t)||(t=new a(t,e)),this.length+=t.length,t}),this);else if("number"==typeof t){if(!(0<=t&&t<=255))return e.error("non-byte EncoderBuffer value");this.value=t,this.length=1}else if("string"==typeof t)this.value=t,this.length=o.byteLength(t);else{if(!o.isBuffer(t))return e.error("Unsupported type: "+typeof t);this.value=t,this.length=t.length}}i(s,n),e.C=s,s.isDecoderBuffer=function(t){return t instanceof s||"object"==typeof t&&o.isBuffer(t.base)&&"DecoderBuffer"===t.constructor.name&&"number"==typeof t.offset&&"number"==typeof t.length&&"function"==typeof t.save&&"function"==typeof t.restore&&"function"==typeof t.isEmpty&&"function"==typeof t.readUInt8&&"function"==typeof t.skip&&"function"==typeof t.raw},s.prototype.save=function(){return{offset:this.offset,reporter:n.prototype.save.call(this)}},s.prototype.restore=function(t){const e=new s(this.base);return e.offset=t.offset,e.length=this.offset,this.offset=t.offset,n.prototype.restore.call(this,t.reporter),e},s.prototype.isEmpty=function(){return this.offset===this.length},s.prototype.readUInt8=function(t){return this.offset+1<=this.length?this.base.readUInt8(this.offset++,!0):this.error(t||"DecoderBuffer overrun")},s.prototype.skip=function(t,e){if(!(this.offset+t<=this.length))return this.error(e||"DecoderBuffer overrun");const r=new s(this.base);return r._reporterState=this._reporterState,r.offset=this.offset,r.length=this.offset+t,this.offset+=t,r},s.prototype.raw=function(t){return this.base.slice(t?t.offset:this.offset,this.length)},e.R=a,a.isEncoderBuffer=function(t){return t instanceof a||"object"==typeof t&&"EncoderBuffer"===t.constructor.name&&"number"==typeof t.length&&"function"==typeof t.join},a.prototype.join=function(t,e){return t||(t=o.alloc(this.length)),e||(e=0),0===this.length||(Array.isArray(this.value)?this.value.forEach((function(r){r.join(t,e),e+=r.length})):("number"==typeof this.value?t[e]=this.value:"string"==typeof this.value?t.write(this.value,e):o.isBuffer(this.value)&&this.value.copy(t,e),e+=this.length)),t}},4798:(t,e,r)=>{"use strict";const i=e;i.Reporter=r(126).b,i.DecoderBuffer=r(7362).C,i.EncoderBuffer=r(7362).R,i.Node=r(847)},847:(t,e,r)=>{"use strict";const i=r(126).b,n=r(7362).R,o=r(7362).C,s=r(9561),a=["seq","seqof","set","setof","objid","bool","gentime","utctime","null_","enum","int","objDesc","bitstr","bmpstr","charstr","genstr","graphstr","ia5str","iso646str","numstr","octstr","printstr","t61str","unistr","utf8str","videostr"],h=["key","obj","use","optional","explicit","implicit","def","choice","any","contains"].concat(a);function u(t,e,r){const i={};this._baseState=i,i.name=r,i.enc=t,i.parent=e||null,i.children=null,i.tag=null,i.args=null,i.reverseArgs=null,i.choice=null,i.optional=!1,i.any=!1,i.obj=!1,i.use=null,i.useDecoder=null,i.key=null,i.default=null,i.explicit=null,i.implicit=null,i.contains=null,i.parent||(i.children=[],this._wrap())}t.exports=u;const f=["enc","parent","children","tag","args","reverseArgs","choice","optional","any","obj","use","alteredUse","key","default","explicit","implicit","contains"];u.prototype.clone=function(){const t=this._baseState,e={};f.forEach((function(r){e[r]=t[r]}));const r=new this.constructor(e.parent);return r._baseState=e,r},u.prototype._wrap=function(){const t=this._baseState;h.forEach((function(e){this[e]=function(){const r=new this.constructor(this);return t.children.push(r),r[e].apply(r,arguments)}}),this)},u.prototype._init=function(t){const e=this._baseState;s(null===e.parent),t.call(this),e.children=e.children.filter((function(t){return t._baseState.parent===this}),this),s.equal(e.children.length,1,"Root node can have only one child")},u.prototype._useArgs=function(t){const e=this._baseState,r=t.filter((function(t){return t instanceof this.constructor}),this);t=t.filter((function(t){return!(t instanceof this.constructor)}),this),0!==r.length&&(s(null===e.children),e.children=r,r.forEach((function(t){t._baseState.parent=this}),this)),0!==t.length&&(s(null===e.args),e.args=t,e.reverseArgs=t.map((function(t){if("object"!=typeof t||t.constructor!==Object)return t;const e={};return Object.keys(t).forEach((function(r){r==(0|r)&&(r|=0);const i=t[r];e[i]=r})),e})))},["_peekTag","_decodeTag","_use","_decodeStr","_decodeObjid","_decodeTime","_decodeNull","_decodeInt","_decodeBool","_decodeList","_encodeComposite","_encodeStr","_encodeObjid","_encodeTime","_encodeNull","_encodeInt","_encodeBool"].forEach((function(t){u.prototype[t]=function(){const e=this._baseState;throw new Error(t+" not implemented for encoding: "+e.enc)}})),a.forEach((function(t){u.prototype[t]=function(){const e=this._baseState,r=Array.prototype.slice.call(arguments);return s(null===e.tag),e.tag=t,this._useArgs(r),this}})),u.prototype.use=function(t){s(t);const e=this._baseState;return s(null===e.use),e.use=t,this},u.prototype.optional=function(){return this._baseState.optional=!0,this},u.prototype.def=function(t){const e=this._baseState;return s