mix-encryption
Version:
基于国密算法 SM2 和 SM4 实现的混合加密解决方案。
11 lines • 57.3 kB
JavaScript
"use strict";var t=require("md5");const e="object"==typeof globalThis&&"crypto"in globalThis?globalThis.crypto:void 0;
/*! noble-hashes - MIT License (c) 2022 Paul Miller (paulmillr.com) */function n(t){return t instanceof Uint8Array||ArrayBuffer.isView(t)&&"Uint8Array"===t.constructor.name}function r(t){if(!Number.isSafeInteger(t)||t<0)throw new Error("positive integer expected, got "+t)}function o(t,...e){if(!n(t))throw new Error("Uint8Array expected");if(e.length>0&&!e.includes(t.length))throw new Error("Uint8Array expected of length "+e+", got length="+t.length)}function i(t){if("function"!=typeof t||"function"!=typeof t.create)throw new Error("Hash should be wrapped by utils.createHasher");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")}const u=(()=>"function"==typeof Uint8Array.from([]).toHex&&"function"==typeof Uint8Array.fromHex)(),c=Array.from({length:256},(t,e)=>e.toString(16).padStart(2,"0"));function a(t){if(o(t),u)return t.toHex();let e="";for(let n=0;n<t.length;n++)e+=c[t[n]];return e}const f=48,l=57,h=65,d=70,g=97,y=102;function p(t){return t>=f&&t<=l?t-f:t>=h&&t<=d?t-(h-10):t>=g&&t<=y?t-(g-10):void 0}function w(t){if("string"!=typeof t)throw new Error("hex string expected, got "+typeof t);if(u)return Uint8Array.fromHex(t);const e=t.length,n=e/2;if(e%2)throw new Error("hex string expected, got unpadded hex of length "+e);const r=new Uint8Array(n);for(let e=0,o=0;e<n;e++,o+=2){const n=p(t.charCodeAt(o)),i=p(t.charCodeAt(o+1));if(void 0===n||void 0===i){const e=t[o]+t[o+1];throw new Error('hex string expected, got non-hex character "'+e+'" at index '+o)}r[e]=16*n+i}return r}function m(t){return"string"==typeof t&&(t=function(t){if("string"!=typeof t)throw new Error("string expected");return new Uint8Array((new TextEncoder).encode(t))}(t)),o(t),t}function b(...t){let e=0;for(let n=0;n<t.length;n++){const r=t[n];o(r),e+=r.length}const n=new Uint8Array(e);for(let e=0,r=0;e<t.length;e++){const o=t[e];n.set(o,r),r+=o.length}return n}let E=class{};function v(t=32){if(e&&"function"==typeof e.getRandomValues)return e.getRandomValues(new Uint8Array(t));if(e&&"function"==typeof e.randomBytes)return Uint8Array.from(e.randomBytes(t));throw new Error("crypto.getRandomValues must be defined")}
/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */const x=BigInt(0),B=BigInt(1);function A(t,e){if("boolean"!=typeof e)throw new Error(t+" boolean expected, got "+e)}function U(t){const e=t.toString(16);return 1&e.length?"0"+e:e}function S(t){if("string"!=typeof t)throw new Error("hex string expected, got "+typeof t);return""===t?x:BigInt("0x"+t)}function H(t){return S(a(t))}function P(t){return o(t),S(a(Uint8Array.from(t).reverse()))}function O(t,e){return w(t.toString(16).padStart(2*e,"0"))}function I(t,e){return O(t,e).reverse()}function R(t,e,r){let o;if("string"==typeof e)try{o=w(e)}catch(e){throw new Error(t+" must be hex string or Uint8Array, cause: "+e)}else{if(!n(e))throw new Error(t+" must be hex string or Uint8Array");o=Uint8Array.from(e)}return o.length,o}const K=t=>"bigint"==typeof t&&x<=t;function L(t,e,n,r){if(!function(t,e,n){return K(t)&&K(e)&&K(n)&&e<=t&&t<n}(e,n,r))throw new Error("expected valid "+t+": "+n+" <= n < "+r+", got "+e)}function N(t){let e;for(e=0;t>x;t>>=B,e+=1);return e}const k=t=>(B<<BigInt(t))-B;function V(t,e,n={}){if(!t||"object"!=typeof t)throw new Error("expected valid options object");function r(e,n,r){const o=t[e];if(r&&void 0===o)return;const i=typeof o;if(i!==n||null===o)throw new Error(`param "${e}" is invalid: expected ${n}, got ${i}`)}Object.entries(e).forEach(([t,e])=>r(t,e,!1)),Object.entries(n).forEach(([t,e])=>r(t,e,!0))}function C(t){const e=new WeakMap;return(n,...r)=>{const o=e.get(n);if(void 0!==o)return o;const i=t(n,...r);return e.set(n,i),i}}let q=class extends E{constructor(t,e){super(),this.finished=!1,this.destroyed=!1,i(t);const n=m(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 r=this.blockLen,o=new Uint8Array(r);o.set(n.length>r?t.create().update(n).digest():n);for(let t=0;t<o.length;t++)o[t]^=54;this.iHash.update(o),this.oHash=t.create();for(let t=0;t<o.length;t++)o[t]^=106;this.oHash.update(o),function(...t){for(let e=0;e<t.length;e++)t[e].fill(0)}(o)}update(t){return s(this),this.iHash.update(t),this}digestInto(t){s(this),o(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:o,blockLen:i,outputLen:s}=this;return t.finished=r,t.destroyed=o,t.blockLen=i,t.outputLen=s,t.oHash=e._cloneInto(t.oHash),t.iHash=n._cloneInto(t.iHash),t}clone(){return this._cloneInto()}destroy(){this.destroyed=!0,this.oHash.destroy(),this.iHash.destroy()}};const j=(t,e,n)=>new q(t,e).update(n).digest();j.create=(t,e)=>new q(t,e);
/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */
const F=BigInt(0),Z=BigInt(1),T=BigInt(2),D=BigInt(3),_=BigInt(4),M=BigInt(5),z=BigInt(7),Y=BigInt(8),G=BigInt(9),$=BigInt(16);function X(t,e){const n=t%e;return n>=F?n:e+n}function W(t,e){if(t===F)throw new Error("invert: expected non-zero number");if(e<=F)throw new Error("invert: expected positive modulus, got "+e);let n=X(t,e),r=e,o=F,i=Z;for(;n!==F;){const t=r%n,e=o-i*(r/n);r=n,n=t,o=i,i=e}if(r!==Z)throw new Error("invert: does not exist");return X(o,e)}function J(t,e,n){if(!t.eql(t.sqr(e),n))throw new Error("Cannot find square root")}function Q(t,e){const n=(t.ORDER+Z)/_,r=t.pow(e,n);return J(t,r,e),r}function tt(t,e){const n=(t.ORDER-M)/Y,r=t.mul(e,T),o=t.pow(r,n),i=t.mul(e,o),s=t.mul(t.mul(i,T),o),u=t.mul(i,t.sub(s,t.ONE));return J(t,u,e),u}function et(t){if(t<D)throw new Error("sqrt is not defined for small field");let e=t-Z,n=0;for(;e%T===F;)e/=T,n++;let r=T;const o=st(t);for(;1===it(o,r);)if(r++>1e3)throw new Error("Cannot find square root: probably non-prime P");if(1===n)return Q;let i=o.pow(r,e);const s=(e+Z)/T;return function(t,r){if(t.is0(r))return r;if(1!==it(t,r))throw new Error("Cannot find square root");let o=n,u=t.mul(t.ONE,i),c=t.pow(r,e),a=t.pow(r,s);for(;!t.eql(c,t.ONE);){if(t.is0(c))return t.ZERO;let e=1,n=t.sqr(c);for(;!t.eql(n,t.ONE);)if(e++,n=t.sqr(n),e===o)throw new Error("Cannot find square root");const r=Z<<BigInt(o-e-1),i=t.pow(u,r);o=e,u=t.sqr(i),c=t.mul(c,u),a=t.mul(a,i)}return a}}function nt(t){return t%_===D?Q:t%Y===M?tt:t%$===G?function(t){const e=st(t),n=et(t),r=n(e,e.neg(e.ONE)),o=n(e,r),i=n(e,e.neg(r)),s=(t+z)/$;return(t,e)=>{let n=t.pow(e,s),u=t.mul(n,r);const c=t.mul(n,o),a=t.mul(n,i),f=t.eql(t.sqr(u),e),l=t.eql(t.sqr(c),e);n=t.cmov(n,u,f),u=t.cmov(a,c,l);const h=t.eql(t.sqr(u),e),d=t.cmov(n,u,h);return J(t,d,e),d}}(t):et(t)}const rt=["create","isValid","is0","neg","inv","sqrt","sqr","eql","add","sub","mul","pow","div","addN","subN","mulN","sqrN"];function ot(t,e,n=!1){const r=new Array(e.length).fill(n?t.ZERO:void 0),o=e.reduce((e,n,o)=>t.is0(n)?e:(r[o]=e,t.mul(e,n)),t.ONE),i=t.inv(o);return e.reduceRight((e,n,o)=>t.is0(n)?e:(r[o]=t.mul(e,r[o]),t.mul(e,n)),i),r}function it(t,e){const n=(t.ORDER-Z)/T,r=t.pow(e,n),o=t.eql(r,t.ONE),i=t.eql(r,t.ZERO),s=t.eql(r,t.neg(t.ONE));if(!o&&!i&&!s)throw new Error("invalid Legendre symbol result");return o?1:i?0:-1}function st(t,e,n=!1,o={}){if(t<=F)throw new Error("invalid field: expected ORDER > 0, got "+t);let i,s,u,c=!1;if("object"==typeof e&&null!=e){if(o.sqrt||n)throw new Error("cannot specify opts in two arguments");const t=e;t.BITS&&(i=t.BITS),t.sqrt&&(s=t.sqrt),"boolean"==typeof t.isLE&&(n=t.isLE),"boolean"==typeof t.modOnDecode&&(c=t.modOnDecode),u=t.allowedLengths}else"number"==typeof e&&(i=e),o.sqrt&&(s=o.sqrt);const{nBitLength:a,nByteLength:f}=function(t,e){void 0!==e&&r(e);const n=void 0!==e?e:t.toString(2).length;return{nBitLength:n,nByteLength:Math.ceil(n/8)}}(t,i);if(f>2048)throw new Error("invalid field: expected ORDER of <= 2048 bytes");let l;const h=Object.freeze({ORDER:t,isLE:n,BITS:a,BYTES:f,MASK:k(a),ZERO:F,ONE:Z,allowedLengths:u,create:e=>X(e,t),isValid:e=>{if("bigint"!=typeof e)throw new Error("invalid field element: expected bigint, got "+typeof e);return F<=e&&e<t},is0:t=>t===F,isValidNot0:t=>!h.is0(t)&&h.isValid(t),isOdd:t=>(t&Z)===Z,neg:e=>X(-e,t),eql:(t,e)=>t===e,sqr:e=>X(e*e,t),add:(e,n)=>X(e+n,t),sub:(e,n)=>X(e-n,t),mul:(e,n)=>X(e*n,t),pow:(t,e)=>function(t,e,n){if(n<F)throw new Error("invalid exponent, negatives unsupported");if(n===F)return t.ONE;if(n===Z)return e;let r=t.ONE,o=e;for(;n>F;)n&Z&&(r=t.mul(r,o)),o=t.sqr(o),n>>=Z;return r}(h,t,e),div:(e,n)=>X(e*W(n,t),t),sqrN:t=>t*t,addN:(t,e)=>t+e,subN:(t,e)=>t-e,mulN:(t,e)=>t*e,inv:e=>W(e,t),sqrt:s||(e=>(l||(l=nt(t)),l(h,e))),toBytes:t=>n?I(t,f):O(t,f),fromBytes:(e,r=!0)=>{if(u){if(!u.includes(e.length)||e.length>f)throw new Error("Field.fromBytes: expected "+u+" bytes, got "+e.length);const t=new Uint8Array(f);t.set(e,n?0:t.length-e.length),e=t}if(e.length!==f)throw new Error("Field.fromBytes: expected "+f+" bytes, got "+e.length);let o=n?P(e):H(e);if(c&&(o=X(o,t)),!r&&!h.isValid(o))throw new Error("invalid field element: outside of range 0..ORDER");return o},invertBatch:t=>ot(h,t),cmov:(t,e,n)=>n?e:t});return Object.freeze(h)}function ut(t){if("bigint"!=typeof t)throw new Error("field order must be bigint");const e=t.toString(2).length;return Math.ceil(e/8)}function ct(t){const e=ut(t);return e+Math.ceil(e/2)}
/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */
const at=BigInt(0),ft=BigInt(1);function lt(t,e){const n=e.negate();return t?n:e}function ht(t,e){const n=ot(t.Fp,e.map(t=>t.Z));return e.map((e,r)=>t.fromAffine(e.toAffine(n[r])))}function dt(t,e){if(!Number.isSafeInteger(t)||t<=0||t>e)throw new Error("invalid window size, expected [1.."+e+"], got W="+t)}function gt(t,e){dt(t,e);const n=2**t;return{windows:Math.ceil(e/t)+1,windowSize:2**(t-1),mask:k(t),maxNumber:n,shiftBy:BigInt(t)}}function yt(t,e,n){const{windowSize:r,mask:o,maxNumber:i,shiftBy:s}=n;let u=Number(t&o),c=t>>s;u>r&&(u-=i,c+=ft);const a=e*r;return{nextN:c,offset:a+Math.abs(u)-1,isZero:0===u,isNeg:u<0,isNegF:e%2!=0,offsetF:a}}const pt=new WeakMap,wt=new WeakMap;function mt(t){return wt.get(t)||1}function bt(t){if(t!==at)throw new Error("invalid wNAF")}class Et{constructor(t,e){this.BASE=t.BASE,this.ZERO=t.ZERO,this.Fn=t.Fn,this.bits=e}_unsafeLadder(t,e,n=this.ZERO){let r=t;for(;e>at;)e&ft&&(n=n.add(r)),r=r.double(),e>>=ft;return n}precomputeWindow(t,e){const{windows:n,windowSize:r}=gt(e,this.bits),o=[];let i=t,s=i;for(let t=0;t<n;t++){s=i,o.push(s);for(let t=1;t<r;t++)s=s.add(i),o.push(s);i=s.double()}return o}wNAF(t,e,n){if(!this.Fn.isValid(n))throw new Error("invalid scalar");let r=this.ZERO,o=this.BASE;const i=gt(t,this.bits);for(let t=0;t<i.windows;t++){const{nextN:s,offset:u,isZero:c,isNeg:a,isNegF:f,offsetF:l}=yt(n,t,i);n=s,c?o=o.add(lt(f,e[l])):r=r.add(lt(a,e[u]))}return bt(n),{p:r,f:o}}wNAFUnsafe(t,e,n,r=this.ZERO){const o=gt(t,this.bits);for(let t=0;t<o.windows&&n!==at;t++){const{nextN:i,offset:s,isZero:u,isNeg:c}=yt(n,t,o);if(n=i,!u){const t=e[s];r=r.add(c?t.negate():t)}}return bt(n),r}getPrecomputes(t,e,n){let r=pt.get(e);return r||(r=this.precomputeWindow(e,t),1!==t&&("function"==typeof n&&(r=n(r)),pt.set(e,r))),r}cached(t,e,n){const r=mt(t);return this.wNAF(r,this.getPrecomputes(r,t,n),e)}unsafe(t,e,n,r){const o=mt(t);return 1===o?this._unsafeLadder(t,e,r):this.wNAFUnsafe(o,this.getPrecomputes(o,t,n),e,r)}createCache(t,e){dt(e,this.bits),wt.set(t,e),pt.delete(t)}hasCache(t){return 1!==mt(t)}}function vt(t,e,n,r){!function(t,e){if(!Array.isArray(t))throw new Error("array expected");t.forEach((t,n)=>{if(!(t instanceof e))throw new Error("invalid point at index "+n)})}(n,t),function(t,e){if(!Array.isArray(t))throw new Error("array of scalars expected");t.forEach((t,n)=>{if(!e.isValid(t))throw new Error("invalid scalar at index "+n)})}(r,e);const o=n.length,i=r.length;if(o!==i)throw new Error("arrays of points and scalars must have equal length");const s=t.ZERO,u=N(BigInt(o));let c=1;u>12?c=u-3:u>4?c=u-2:u>0&&(c=2);const a=k(c),f=new Array(Number(a)+1).fill(s);let l=s;for(let t=Math.floor((e.BITS-1)/c)*c;t>=0;t-=c){f.fill(s);for(let e=0;e<i;e++){const o=r[e],i=Number(o>>BigInt(t)&a);f[i]=f[i].add(n[e])}let e=s;for(let t=f.length-1,n=s;t>0;t--)n=n.add(f[t]),e=e.add(n);if(l=l.add(e),0!==t)for(let t=0;t<c;t++)l=l.double()}return l}function xt(t,e){if(e){if(e.ORDER!==t)throw new Error("Field.ORDER must match order: Fp == p, Fn == n");return function(t){V(t,rt.reduce((t,e)=>(t[e]="function",t),{ORDER:"bigint",MASK:"bigint",BYTES:"number",BITS:"number"}))}(e),e}return st(t)}
/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */
const Bt=(t,e)=>(t+(t>=0?e:-e)/Ot)/e;function At(t){void 0!==t.lowS&&A("lowS",t.lowS),void 0!==t.prehash&&A("prehash",t.prehash)}class Ut extends Error{constructor(t=""){super(t)}}const St={Err:Ut,_tlv:{encode:(t,e)=>{const{Err:n}=St;if(t<0||t>256)throw new n("tlv.encode: wrong tag");if(1&e.length)throw new n("tlv.encode: unpadded data");const r=e.length/2,o=U(r);if(o.length/2&128)throw new n("tlv.encode: long form length too big");const i=r>127?U(o.length/2|128):"";return U(t)+i+o+e},decode(t,e){const{Err:n}=St;let r=0;if(t<0||t>256)throw new n("tlv.encode: wrong tag");if(e.length<2||e[r++]!==t)throw new n("tlv.decode: wrong tlv");const o=e[r++];let i=0;if(!!(128&o)){const t=127&o;if(!t)throw new n("tlv.decode(long): indefinite length not supported");if(t>4)throw new n("tlv.decode(long): byte length is too big");const s=e.subarray(r,r+t);if(s.length!==t)throw new n("tlv.decode: length bytes not complete");if(0===s[0])throw new n("tlv.decode(long): zero leftmost byte");for(const t of s)i=i<<8|t;if(r+=t,i<128)throw new n("tlv.decode(long): not minimal encoding")}else i=o;const s=e.subarray(r,r+i);if(s.length!==i)throw new n("tlv.decode: wrong value length");return{v:s,l:e.subarray(r+i)}}},_int:{encode(t){const{Err:e}=St;if(t<Ht)throw new e("integer: negative integers are not allowed");let n=U(t);if(8&Number.parseInt(n[0],16)&&(n="00"+n),1&n.length)throw new e("unexpected DER parsing assertion: unpadded hex");return n},decode(t){const{Err:e}=St;if(128&t[0])throw new e("invalid signature integer: negative");if(0===t[0]&&!(128&t[1]))throw new e("invalid signature integer: unnecessary leading zero");return H(t)}},toSig(t){const{Err:e,_int:n,_tlv:r}=St,o=R("signature",t),{v:i,l:s}=r.decode(48,o);if(s.length)throw new e("invalid signature: left bytes after parsing");const{v:u,l:c}=r.decode(2,i),{v:a,l:f}=r.decode(2,c);if(f.length)throw new e("invalid signature: left bytes after parsing");return{r:n.decode(u),s:n.decode(a)}},hexFromSig(t){const{_tlv:e,_int:n}=St,r=e.encode(2,n.encode(t.r))+e.encode(2,n.encode(t.s));return e.encode(48,r)}},Ht=BigInt(0),Pt=BigInt(1),Ot=BigInt(2),It=BigInt(3),Rt=BigInt(4);function Kt(t,e){const{BYTES:n}=t;let r;if("bigint"==typeof e)r=e;else{let o=R("private key",e);try{r=t.fromBytes(o)}catch(t){throw new Error(`invalid private key: expected ui8a of size ${n}, got ${typeof e}`)}}if(!t.isValidNot0(r))throw new Error("invalid private key: out of range [1..N-1]");return r}function Lt(t,e={}){const{Fp:n,Fn:r}=function(t,e,n={}){if(!e||"object"!=typeof e)throw new Error(`expected valid ${t} CURVE object`);for(const t of["p","n","h"]){const n=e[t];if(!("bigint"==typeof n&&n>at))throw new Error(`CURVE.${t} must be positive bigint`)}const r=xt(e.p,n.Fp),o=xt(e.n,n.Fn),i=["Gx","Gy","a","b"];for(const t of i)if(!r.isValid(e[t]))throw new Error(`CURVE.${t} must be valid field element of CURVE.Fp`);return{Fp:r,Fn:o}}("weierstrass",t,e),{h:i,n:s}=t;V(e,{},{allowInfinityPoint:"boolean",clearCofactor:"function",isTorsionFree:"function",fromBytes:"function",toBytes:"function",endo:"object",wrapPrivateKey:"boolean"});const{endo:u}=e;if(u&&(!n.is0(t.a)||"bigint"!=typeof u.beta||!Array.isArray(u.basises)))throw new Error('invalid endo: expected "beta": bigint and "basises": array');function c(){if(!n.isOdd)throw new Error("compression is not supported: Field does not have .isOdd()")}const f=e.toBytes||function(t,e,r){const{x:o,y:i}=e.toAffine(),s=n.toBytes(o);if(A("isCompressed",r),r){c();return b(Nt(!n.isOdd(i)),s)}return b(Uint8Array.of(4),s,n.toBytes(i))},l=e.fromBytes||function(t){o(t);const e=n.BYTES,r=e+1,i=2*e+1,s=t.length,u=t[0],a=t.subarray(1);if(s!==r||2!==u&&3!==u){if(s===i&&4===u){const t=n.fromBytes(a.subarray(0*e,1*e)),r=n.fromBytes(a.subarray(1*e,2*e));if(!d(t,r))throw new Error("bad point: is not on curve");return{x:t,y:r}}throw new Error(`bad point: got length ${s}, expected compressed=${r} or uncompressed=${i}`)}{const t=n.fromBytes(a);if(!n.isValid(t))throw new Error("bad point: is not on curve, wrong x");const e=h(t);let r;try{r=n.sqrt(e)}catch(t){const e=t instanceof Error?": "+t.message:"";throw new Error("bad point: is not on curve, sqrt error"+e)}c();return!(1&~u)!==n.isOdd(r)&&(r=n.neg(r)),{x:t,y:r}}},h=function(t,e,n){return function(r){const o=t.sqr(r),i=t.mul(o,r);return t.add(t.add(i,t.mul(r,e)),n)}}(n,t.a,t.b);function d(t,e){const r=n.sqr(e),o=h(t);return n.eql(r,o)}if(!d(t.Gx,t.Gy))throw new Error("bad curve params: generator point");const g=n.mul(n.pow(t.a,It),Rt),y=n.mul(n.sqr(t.b),BigInt(27));if(n.is0(n.add(g,y)))throw new Error("bad curve params: a or b");function p(t,e,r=!1){if(!n.isValid(e)||r&&n.is0(e))throw new Error(`bad point coordinate ${t}`);return e}function w(t){if(!(t instanceof B))throw new Error("ProjectivePoint expected")}function m(t){if(!u||!u.basises)throw new Error("no endo");return function(t,e,n){const[[r,o],[i,s]]=e,u=Bt(s*t,n),c=Bt(-o*t,n);let a=t-u*r-c*i,f=-u*o-c*s;const l=a<Ht,h=f<Ht;l&&(a=-a),h&&(f=-f);const d=k(Math.ceil(N(n)/2))+Pt;if(a<Ht||a>=d||f<Ht||f>=d)throw new Error("splitScalar (endomorphism): failed, k="+t);return{k1neg:l,k1:a,k2neg:h,k2:f}}(t,u.basises,r.ORDER)}const E=C((t,e)=>{const{X:r,Y:o,Z:i}=t;if(n.eql(i,n.ONE))return{x:r,y:o};const s=t.is0();null==e&&(e=s?n.ONE:n.inv(i));const u=n.mul(r,e),c=n.mul(o,e),a=n.mul(i,e);if(s)return{x:n.ZERO,y:n.ZERO};if(!n.eql(a,n.ONE))throw new Error("invZ was invalid");return{x:u,y:c}}),v=C(t=>{if(t.is0()){if(e.allowInfinityPoint&&!n.is0(t.Y))return;throw new Error("bad point: ZERO")}const{x:r,y:o}=t.toAffine();if(!n.isValid(r)||!n.isValid(o))throw new Error("bad point: x or y not field elements");if(!d(r,o))throw new Error("bad point: equation left != right");if(!t.isTorsionFree())throw new Error("bad point: not in prime-order subgroup");return!0});function x(t,e,r,o,i){return r=new B(n.mul(r.X,t),r.Y,r.Z),e=lt(o,e),r=lt(i,r),e.add(r)}class B{constructor(t,e,n){this.X=p("x",t),this.Y=p("y",e,!0),this.Z=p("z",n),Object.freeze(this)}static fromAffine(t){const{x:e,y:r}=t||{};if(!t||!n.isValid(e)||!n.isValid(r))throw new Error("invalid affine point");if(t instanceof B)throw new Error("projective point not allowed");return n.is0(e)&&n.is0(r)?B.ZERO:new B(e,r,n.ONE)}get x(){return this.toAffine().x}get y(){return this.toAffine().y}get px(){return this.X}get py(){return this.X}get pz(){return this.Z}static normalizeZ(t){return ht(B,t)}static fromBytes(t){return o(t),B.fromHex(t)}static fromHex(t){const e=B.fromAffine(l(R("pointHex",t)));return e.assertValidity(),e}static fromPrivateKey(t){return B.BASE.multiply(Kt(r,t))}static msm(t,e){return vt(B,r,t,e)}_setWindowSize(t){this.precompute(t)}precompute(t=8,e=!0){return S.createCache(this,t),e||this.multiply(It),this}assertValidity(){v(this)}hasEvenY(){const{y:t}=this.toAffine();if(!n.isOdd)throw new Error("Field doesn't support isOdd");return!n.isOdd(t)}equals(t){w(t);const{X:e,Y:r,Z:o}=this,{X:i,Y:s,Z:u}=t,c=n.eql(n.mul(e,u),n.mul(i,o)),a=n.eql(n.mul(r,u),n.mul(s,o));return c&&a}negate(){return new B(this.X,n.neg(this.Y),this.Z)}double(){const{a:e,b:r}=t,o=n.mul(r,It),{X:i,Y:s,Z:u}=this;let c=n.ZERO,a=n.ZERO,f=n.ZERO,l=n.mul(i,i),h=n.mul(s,s),d=n.mul(u,u),g=n.mul(i,s);return g=n.add(g,g),f=n.mul(i,u),f=n.add(f,f),c=n.mul(e,f),a=n.mul(o,d),a=n.add(c,a),c=n.sub(h,a),a=n.add(h,a),a=n.mul(c,a),c=n.mul(g,c),f=n.mul(o,f),d=n.mul(e,d),g=n.sub(l,d),g=n.mul(e,g),g=n.add(g,f),f=n.add(l,l),l=n.add(f,l),l=n.add(l,d),l=n.mul(l,g),a=n.add(a,l),d=n.mul(s,u),d=n.add(d,d),l=n.mul(d,g),c=n.sub(c,l),f=n.mul(d,h),f=n.add(f,f),f=n.add(f,f),new B(c,a,f)}add(e){w(e);const{X:r,Y:o,Z:i}=this,{X:s,Y:u,Z:c}=e;let a=n.ZERO,f=n.ZERO,l=n.ZERO;const h=t.a,d=n.mul(t.b,It);let g=n.mul(r,s),y=n.mul(o,u),p=n.mul(i,c),m=n.add(r,o),b=n.add(s,u);m=n.mul(m,b),b=n.add(g,y),m=n.sub(m,b),b=n.add(r,i);let E=n.add(s,c);return b=n.mul(b,E),E=n.add(g,p),b=n.sub(b,E),E=n.add(o,i),a=n.add(u,c),E=n.mul(E,a),a=n.add(y,p),E=n.sub(E,a),l=n.mul(h,b),a=n.mul(d,p),l=n.add(a,l),a=n.sub(y,l),l=n.add(y,l),f=n.mul(a,l),y=n.add(g,g),y=n.add(y,g),p=n.mul(h,p),b=n.mul(d,b),y=n.add(y,p),p=n.sub(g,p),p=n.mul(h,p),b=n.add(b,p),g=n.mul(y,b),f=n.add(f,g),g=n.mul(E,b),a=n.mul(m,a),a=n.sub(a,g),g=n.mul(m,y),l=n.mul(E,l),l=n.add(l,g),new B(a,f,l)}subtract(t){return this.add(t.negate())}is0(){return this.equals(B.ZERO)}multiply(t){const{endo:n}=e;if(!r.isValidNot0(t))throw new Error("invalid scalar: out of range");let o,i;const s=t=>S.cached(this,t,t=>ht(B,t));if(n){const{k1neg:e,k1:r,k2neg:u,k2:c}=m(t),{p:a,f:f}=s(r),{p:l,f:h}=s(c);i=f.add(h),o=x(n.beta,a,l,e,u)}else{const{p:e,f:n}=s(t);o=e,i=n}return ht(B,[o,i])[0]}multiplyUnsafe(t){const{endo:n}=e,o=this;if(!r.isValid(t))throw new Error("invalid scalar: out of range");if(t===Ht||o.is0())return B.ZERO;if(t===Pt)return o;if(S.hasCache(this))return this.multiply(t);if(n){const{k1neg:e,k1:r,k2neg:i,k2:s}=m(t),{p1:u,p2:c}=function(t,e,n,r){let o=e,i=t.ZERO,s=t.ZERO;for(;n>at||r>at;)n&ft&&(i=i.add(o)),r&ft&&(s=s.add(o)),o=o.double(),n>>=ft,r>>=ft;return{p1:i,p2:s}}(B,o,r,s);return x(n.beta,u,c,e,i)}return S.unsafe(o,t)}multiplyAndAddUnsafe(t,e,n){const r=this.multiplyUnsafe(e).add(t.multiplyUnsafe(n));return r.is0()?void 0:r}toAffine(t){return E(this,t)}isTorsionFree(){const{isTorsionFree:t}=e;return i===Pt||(t?t(B,this):S.unsafe(this,s).is0())}clearCofactor(){const{clearCofactor:t}=e;return i===Pt?this:t?t(B,this):this.multiplyUnsafe(i)}isSmallOrder(){return this.multiplyUnsafe(i).is0()}toBytes(t=!0){return A("isCompressed",t),this.assertValidity(),f(B,this,t)}toRawBytes(t=!0){return this.toBytes(t)}toHex(t=!0){return a(this.toBytes(t))}toString(){return`<Point ${this.is0()?"ZERO":this.toHex()}>`}}B.BASE=new B(t.Gx,t.Gy,n.ONE),B.ZERO=new B(n.ZERO,n.ONE,n.ZERO),B.Fp=n,B.Fn=r;const U=r.BITS,S=new Et(B,e.endo?Math.ceil(U/2):U);return B}function Nt(t){return Uint8Array.of(t?2:3)}function kt(t,e,r={}){i(e),V(r,{},{hmac:"function",lowS:"boolean",randomBytes:"function",bits2int:"function",bits2int_modN:"function"});const s=r.randomBytes||v,u=r.hmac||((t,...n)=>j(e,t,b(...n))),{Fp:c,Fn:f}=t,{ORDER:l,BITS:h}=f,d=ct(l),g={secret:f.BYTES,public:1+c.BYTES,publicUncompressed:1+2*c.BYTES,signature:2*f.BYTES,seed:d};function y(t){return t>l>>Pt}function p(t,e){if(!f.isValidNot0(e))throw new Error(`invalid signature ${t}: out of range 1..CURVE.n`)}class m{constructor(t,e,n){p("r",t),p("s",e),this.r=t,this.s=e,null!=n&&(this.recovery=n),Object.freeze(this)}static fromBytes(t,e="compact"){if("compact"===e){const e=f.BYTES;o(t,2*e);const n=t.subarray(0,e),r=t.subarray(e,2*e);return new m(f.fromBytes(n),f.fromBytes(r))}if("der"===e){o(t);const{r:e,s:n}=St.toSig(t);return new m(e,n)}throw new Error("invalid format")}static fromHex(t,e){return this.fromBytes(w(t),e)}addRecoveryBit(t){return new m(this.r,this.s,t)}recoverPublicKey(e){const n=c.ORDER,{r:r,s:o,recovery:i}=this;if(null==i||![0,1,2,3].includes(i))throw new Error("recovery id invalid");if(l*Ot<n&&i>1)throw new Error("recovery id is ambiguous for h>1 curve");const s=2===i||3===i?r+l:r;if(!c.isValid(s))throw new Error("recovery id 2 or 3 invalid");const u=c.toBytes(s),a=t.fromHex(b(Nt(!(1&i)),u)),h=f.inv(s),d=K(R("msgHash",e)),g=f.create(-d*h),y=f.create(o*h),p=t.BASE.multiplyUnsafe(g).add(a.multiplyUnsafe(y));if(p.is0())throw new Error("point at infinify");return p.assertValidity(),p}hasHighS(){return y(this.s)}normalizeS(){return this.hasHighS()?new m(this.r,f.neg(this.s),this.recovery):this}toBytes(t="compact"){if("compact"===t)return b(f.toBytes(this.r),f.toBytes(this.s));if("der"===t)return w(St.hexFromSig(this));throw new Error("invalid format")}toHex(t){return a(this.toBytes(t))}assertValidity(){}static fromCompact(t){return m.fromBytes(R("sig",t),"compact")}static fromDER(t){return m.fromBytes(R("sig",t),"der")}toDERRawBytes(){return this.toBytes("der")}toDERHex(){return a(this.toBytes("der"))}toCompactRawBytes(){return this.toBytes("compact")}toCompactHex(){return a(this.toBytes("compact"))}}function E(t){try{return!!Kt(f,t)}catch(t){return!1}}function x(t=s(d)){return function(t,e,n=!1){const r=t.length,o=ut(e),i=ct(e);if(r<16||r<i||r>1024)throw new Error("expected "+i+"-1024 bytes of input, got "+r);const s=X(n?P(t):H(t),e-Z)+Z;return n?I(s,o):O(s,o)}(t,l)}const B={isValidSecretKey:E,isValidPublicKey:function(e,n){try{const r=e.length;return(!0!==n||r===g.public)&&((!1!==n||r===g.publicUncompressed)&&!!t.fromBytes(e))}catch(t){return!1}},randomSecretKey:x,isValidPrivateKey:E,randomPrivateKey:x,normPrivateKeyToScalar:t=>Kt(f,t),precompute:(e=8,n=t.BASE)=>n.precompute(e,!1)};function A(e,n=!0){return t.BASE.multiply(Kt(f,e)).toBytes(n)}function U(e){if("bigint"==typeof e)return!1;if(e instanceof t)return!0;if(f.allowedLengths||g.secret===g.public)return;const n=R("key",e).length;return n===g.public||n===g.publicUncompressed}const S=r.bits2int||function(t){if(t.length>8192)throw new Error("input is too large");const e=H(t),n=8*t.length-h;return n>0?e>>BigInt(n):e},K=r.bits2int_modN||function(t){return f.create(S(t))},N=k(h);function C(t){return L("num < 2^"+h,t,Ht,N),f.toBytes(t)}function q(n,r,o=F){if(["recovered","canonical"].some(t=>t in o))throw new Error("sign() legacy options not supported");let{lowS:i,prehash:u,extraEntropy:c}=o;null==i&&(i=!0),n=R("msgHash",n),At(o),u&&(n=R("prehashed msgHash",e(n)));const a=K(n),l=Kt(f,r),h=[C(l),C(a)];if(null!=c&&!1!==c){const t=!0===c?s(g.secret):c;h.push(R("extraEntropy",t))}const d=b(...h),p=a;return{seed:d,k2sig:function(e){const n=S(e);if(!f.isValidNot0(n))return;const r=f.inv(n),o=t.BASE.multiply(n).toAffine(),s=f.create(o.x);if(s===Ht)return;const u=f.create(r*f.create(p+s*l));if(u===Ht)return;let c=(o.x===s?0:2)|Number(o.y&Pt),a=u;return i&&y(u)&&(a=function(t){return y(t)?f.neg(t):t}(u),c^=1),new m(s,a,c)}}}const F={lowS:r.lowS,prehash:!1},T={lowS:r.lowS,prehash:!1};return t.BASE.precompute(8),Object.freeze({keygen:function(t){const e=B.randomSecretKey(t);return{secretKey:e,publicKey:A(e)}},getPublicKey:A,sign:function(t,n,r=F){const{seed:o,k2sig:i}=q(t,n,r);return function(t,e,n){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 n)throw new Error("hmacFn must be a function");const r=t=>new Uint8Array(t),o=t=>Uint8Array.of(t);let i=r(t),s=r(t),u=0;const c=()=>{i.fill(1),s.fill(0),u=0},a=(...t)=>n(s,i,...t),f=(t=r(0))=>{s=a(o(0),t),i=a(),0!==t.length&&(s=a(o(1),t),i=a())},l=()=>{if(u++>=1e3)throw new Error("drbg: tried 1000 values");let t=0;const n=[];for(;t<e;){i=a();const e=i.slice();n.push(e),t+=i.length}return b(...n)};return(t,e)=>{let n;for(c(),f(t);!(n=e(l()));)f();return c(),n}}(e.outputLen,f.BYTES,u)(o,i)},verify:function(r,o,i,s=T){const u=r;o=R("msgHash",o),i=R("publicKey",i),At(s);const{lowS:c,prehash:a,format:l}=s;if("strict"in s)throw new Error("options.strict was renamed to lowS");let h,d;if(void 0===l){const t="string"==typeof u||n(u),e=!t&&null!==u&&"object"==typeof u&&"bigint"==typeof u.r&&"bigint"==typeof u.s;if(!t&&!e)throw new Error("invalid signature, expected Uint8Array, hex string or Signature instance");if(e)h=new m(u.r,u.s);else if(t){try{h=m.fromDER(u)}catch(t){if(!(t instanceof St.Err))throw t}if(!h)try{h=m.fromCompact(u)}catch(t){return!1}}}else if("compact"===l||"der"===l){if("string"!=typeof u&&!n(u))throw new Error('"der" / "compact" format expects Uint8Array signature');h=m.fromBytes(R("sig",u),l)}else{if("js"!==l)throw new Error('format must be "compact", "der" or "js"');if(!(u instanceof m))throw new Error('"js" format expects Signature instance');h=u}if(!h)return!1;try{if(d=t.fromHex(i),c&&h.hasHighS())return!1;a&&(o=e(o));const{r:n,s:r}=h,s=K(o),u=f.inv(r),l=f.create(s*u),g=f.create(n*u),y=t.BASE.multiplyUnsafe(l).add(d.multiplyUnsafe(g));if(y.is0())return!1;return f.create(y.x)===n}catch(t){return!1}},getSharedSecret:function(e,n,r=!0){if(!0===U(e))throw new Error("first arg must be private key");if(!1===U(n))throw new Error("second arg must be public key");const o=Kt(f,e);return t.fromHex(n).multiply(o).toBytes(r)},utils:B,Point:t,Signature:m,info:{type:"weierstrass",lengths:g,publicKeyHasPrefix:!0}})}function Vt(t){const{CURVE:e,curveOpts:n}=function(t){const e={a:t.a,b:t.b,p:t.Fp.ORDER,n:t.n,h:t.h,Gx:t.Gx,Gy:t.Gy},n=t.Fp;let r=t.allowedPrivateKeyLengths?Array.from(new Set(t.allowedPrivateKeyLengths.map(t=>Math.ceil(t/2)))):void 0;return{CURVE:e,curveOpts:{Fp:n,Fn:st(e.n,{BITS:t.nBitLength,allowedLengths:r,modOnDecode:t.wrapPrivateKey}),allowInfinityPoint:t.allowInfinityPoint,endo:t.endo,isTorsionFree:t.isTorsionFree,clearCofactor:t.clearCofactor,fromBytes:t.fromBytes,toBytes:t.toBytes}}}(t),r={hmac:t.hmac,randomBytes:t.randomBytes,lowS:t.lowS,bits2int:t.bits2int,bits2int_modN:t.bits2int_modN};return{CURVE:e,curveOpts:n,hash:t.hash,ecdsaOpts:r}}
/*! noble-ciphers - MIT License (c) 2023 Paul Miller (paulmillr.com) */
function Ct(t){return t instanceof Uint8Array||ArrayBuffer.isView(t)&&"Uint8Array"===t.constructor.name}function qt(t,...e){if(!Ct(t))throw new Error("Uint8Array expected");if(e.length>0&&!e.includes(t.length))throw new Error("Uint8Array expected of length "+e+", got length="+t.length)}function jt(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 Ft(t,e){qt(t);const n=e.outputLen;if(t.length<n)throw new Error("digestInto() expects output buffer of length at least "+n)}function Zt(t){return new Uint32Array(t.buffer,t.byteOffset,Math.floor(t.byteLength/4))}function Tt(...t){for(let e=0;e<t.length;e++)t[e].fill(0)}function Dt(t){return new DataView(t.buffer,t.byteOffset,t.byteLength)}function _t(t){if("string"==typeof t)t=function(t){if("string"!=typeof t)throw new Error("string expected");return new Uint8Array((new TextEncoder).encode(t))}(t);else{if(!Ct(t))throw new Error("Uint8Array expected, got "+typeof t);t=zt(t)}return t}function Mt(t,e,n,r){if("function"==typeof t.setBigUint64)return t.setBigUint64(e,n,r);const o=BigInt(32),i=BigInt(4294967295),s=Number(n>>o&i),u=Number(n&i);t.setUint32(e+0,s,r),t.setUint32(e+4,u,r)}function zt(t){return Uint8Array.from(t)}const Yt=16,Gt=new Uint8Array(16),$t=Zt(Gt),Xt=(t,e,n,r)=>({s3:n<<31|r>>>1,s2:e<<31|n>>>1,s1:t<<31|e>>>1,s0:t>>>1^225<<24&-(1&(1&r))}),Wt=t=>(t>>>0&255)<<24|(t>>>8&255)<<16|(t>>>16&255)<<8|t>>>24&255;class Jt{constructor(t,e){this.blockLen=Yt,this.outputLen=Yt,this.s0=0,this.s1=0,this.s2=0,this.s3=0,this.finished=!1,qt(t=_t(t),16);const n=Dt(t);let r=n.getUint32(0,!1),o=n.getUint32(4,!1),i=n.getUint32(8,!1),s=n.getUint32(12,!1);const u=[];for(let t=0;t<128;t++)u.push({s0:Wt(r),s1:Wt(o),s2:Wt(i),s3:Wt(s)}),({s0:r,s1:o,s2:i,s3:s}=Xt(r,o,i,s));const c=(a=e||1024)>65536?8:a>1024?4:2;var a;if(![1,2,4,8].includes(c))throw new Error("ghash: invalid window size, expected 2, 4 or 8");this.W=c;const f=128/c,l=this.windowSize=2**c,h=[];for(let t=0;t<f;t++)for(let e=0;e<l;e++){let n=0,r=0,o=0,i=0;for(let s=0;s<c;s++){if(!(e>>>c-s-1&1))continue;const{s0:a,s1:f,s2:l,s3:h}=u[c*t+s];n^=a,r^=f,o^=l,i^=h}h.push({s0:n,s1:r,s2:o,s3:i})}this.t=h}_updateBlock(t,e,n,r){t^=this.s0,e^=this.s1,n^=this.s2,r^=this.s3;const{W:o,t:i,windowSize:s}=this;let u=0,c=0,a=0,f=0;const l=(1<<o)-1;let h=0;for(const d of[t,e,n,r])for(let t=0;t<4;t++){const e=d>>>8*t&255;for(let t=8/o-1;t>=0;t--){const n=e>>>o*t&l,{s0:r,s1:d,s2:g,s3:y}=i[h*s+n];u^=r,c^=d,a^=g,f^=y,h+=1}}this.s0=u,this.s1=c,this.s2=a,this.s3=f}update(t){jt(this),qt(t=_t(t));const e=Zt(t),n=Math.floor(t.length/Yt),r=t.length%Yt;for(let t=0;t<n;t++)this._updateBlock(e[4*t+0],e[4*t+1],e[4*t+2],e[4*t+3]);return r&&(Gt.set(t.subarray(n*Yt)),this._updateBlock($t[0],$t[1],$t[2],$t[3]),Tt($t)),this}destroy(){const{t:t}=this;for(const e of t)e.s0=0,e.s1=0,e.s2=0,e.s3=0}digestInto(t){jt(this),Ft(t,this),this.finished=!0;const{s0:e,s1:n,s2:r,s3:o}=this,i=Zt(t);return i[0]=e,i[1]=n,i[2]=r,i[3]=o,t}digest(){const t=new Uint8Array(Yt);return this.digestInto(t),this.destroy(),t}}class Qt extends Jt{constructor(t,e){qt(t=_t(t));const n=function(t){t.reverse();const e=1&t[15];let n=0;for(let e=0;e<t.length;e++){const r=t[e];t[e]=r>>>1|n,n=(1&r)<<7}return t[0]^=225&-e,t}(zt(t));super(n,e),Tt(n)}update(t){t=_t(t),jt(this);const e=Zt(t),n=t.length%Yt,r=Math.floor(t.length/Yt);for(let t=0;t<r;t++)this._updateBlock(Wt(e[4*t+3]),Wt(e[4*t+2]),Wt(e[4*t+1]),Wt(e[4*t+0]));return n&&(Gt.set(t.subarray(r*Yt)),this._updateBlock(Wt($t[3]),Wt($t[2]),Wt($t[1]),Wt($t[0])),Tt($t)),this}digestInto(t){jt(this),Ft(t,this),this.finished=!0;const{s0:e,s1:n,s2:r,s3:o}=this,i=Zt(t);return i[0]=e,i[1]=n,i[2]=r,i[3]=o,t.reverse()}}function te(t){const e=(e,n)=>t(n,e.length).update(_t(e)).digest(),n=t(new Uint8Array(16),0);return e.outputLen=n.outputLen,e.blockLen=n.blockLen,e.create=(e,n)=>t(e,n),e}const ee=te((t,e)=>new Jt(t,e));te((t,e)=>new Qt(t,e));var ne=Object.defineProperty,re=(t,e)=>{for(var n in e)ne(t,n,{get:e[n],enumerable:!0})},oe=(t,e,n)=>(((t,e,n)=>{e in t?ne(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n})(t,"symbol"!=typeof e?e+"":e,n),n),ie={};re(ie,{EmptyArray:()=>fn,arrayToHex:()=>We,arrayToUtf8:()=>Je,calculateSharedKey:()=>un,comparePublicKeyHex:()=>en,compressPublicKeyHex:()=>Ge,doDecrypt:()=>hn,doEncrypt:()=>ln,doSignature:()=>dn,doVerifySignature:()=>gn,generateKeyPairHex:()=>Ye,getHash:()=>pn,getPoint:()=>bn,getPublicKeyFromPrivateKey:()=>mn,getZ:()=>yn,hexToArray:()=>Qe,initRNGPool:()=>Ee,leftPad:()=>Xe,precomputePublicKey:()=>wn,utf8ToHex:()=>$e,verifyPublicKey:()=>tn});var se=BigInt(0),ue=BigInt(1),ce=BigInt(2);BigInt(3);var ae=class{constructor(t=null,e="00",n="00",r=""){this.tlv=t,this.t=e,this.l=n,this.v=r}getEncodedHex(){return this.tlv||(this.v=this.getValue(),this.l=this.getLength(),this.tlv=this.t+this.l+this.v),this.tlv}getLength(){const t=this.v.length/2;let e=t.toString(16);if(e.length%2==1&&(e="0"+e),t<128)return e;return(128+e.length/2).toString(16)+e}getValue(){return""}},fe=class extends ae{constructor(t){super(),this.t="02",t&&(this.v=function(t){let e=t.toString(16);if("-"!==e[0])e.length%2==1?e="0"+e:e.match(/^[0-7]/)||(e="00"+e);else{e=e.substring(1);let n=e.length;n%2==1?n+=1:e.match(/^[0-7]/)||(n+=2);let r="";for(let t=0;t<n;t++)r+="f";e=((S(r)^t)+ue).toString(16).replace(/^-/,"")}return e}(t))}getValue(){return this.v}},le=class extends ae{constructor(t){super(),this.s=t,oe(this,"hV",""),this.t="04",t&&(this.v=t.toLowerCase())}getValue(){return this.v}},he=class extends ae{constructor(t){super(),this.asn1Array=t,oe(this,"t","30")}getValue(){return this.v=this.asn1Array.map(t=>t.getEncodedHex()).join(""),this.v}};function de(t,e){if(+t[e+2]<8)return 1;const n=t.slice(e+2,e+6).slice(0,2);return 2*(parseInt(n,16)-128)}function ge(t,e){const n=de(t,e),r=t.substring(e+2,e+2+2*n);if(!r)return-1;return+(+r[0]<8?S(r):S(r.substring(2))).toString()}function ye(t,e){return e+2*(de(t,e)+1)}function pe(t,e,n,r){const o=new fe(t),i=new fe(e),s=new le(n),u=new le(r);return new he([o,i,s,u]).getEncodedHex()}var we,me=16384,be=new Uint8Array(0);async function Ee(){if("crypto"in globalThis)we=globalThis.crypto;else if(!(be.length>me/2))if("wx"in globalThis&&"getRandomValues"in globalThis.wx)be=await new Promise(t=>{wx.getRandomValues({length:me,success(e){t(new Uint8Array(e.randomValues))}})});else try{if(globalThis.crypto)we=globalThis.crypto;else{const t=await import("crypto");we=t.webcrypto}const t=new Uint8Array(me);we.getRandomValues(t),be=t}catch(t){throw new Error("no available csprng, abort.")}}Ee();var ve=t=>t instanceof Uint8Array,xe=t=>new DataView(t.buffer,t.byteOffset,t.byteLength);if(!(68===new Uint8Array(new Uint32Array([287454020]).buffer)[0]))throw new Error("Non little-endian hardware is not supported");var Be=Array.from({length:256},(t,e)=>e.toString(16).padStart(2,"0"));function Ae(t){if(!ve(t))throw new Error("Uint8Array expected");let e="";for(let n=0;n<t.length;n++)e+=Be[t[n]];return e}var Ue="undefined"!=typeof TextEncoder&&new TextEncoder,Se=(t,e,n)=>((null==n||n>t.length)&&(n=t.length),new Uint8Array(t.subarray(e,n)));function He(t){if(Ue)return Ue.encode(t);const e=t.length;let n=new Uint8Array(t.length+(t.length>>1)),r=0;const o=t=>{n[r++]=t};for(let i=0;i<e;++i){if(r+5>n.length){const t=new Uint8Array(r+8+(e-i<<1));t.set(n),n=t}let s=t.charCodeAt(i);s<128?o(s):s<2048?(o(192|s>>6),o(128|63&s)):s>55295&&s<57344?(s=65536+(1047552&s)|1023&t.charCodeAt(++i),o(240|s>>18),o(128|s>>12&63),o(128|s>>6&63),o(128|63&s)):(o(224|s>>12),o(128|s>>6&63),o(128|63&s))}return Se(n,0,r)}function Pe(t){if("string"==typeof t&&(t=He(t)),!ve(t))throw new Error("expected Uint8Array, got "+typeof t);return t}var Oe=class{clone(){return this._cloneInto()}};var Ie=(t,e,n)=>t&e|t&n|e&n,Re=(t,e,n)=>t^e^n,Ke=(t,e,n)=>t&e|~t&n;function Le(t,e){const n=31&e;return t<<n|t>>>32-n}function Ne(t){return t^Le(t,9)^Le(t,17)}function ke(t){return t^Le(t,15)^Le(t,23)}var Ve=class extends Oe{constructor(t,e,n,r){super(),this.blockLen=t,this.outputLen=e,this.padOffset=n,this.isLE=r,oe(this,"buffer"),oe(this,"view"),oe(this,"finished",!1),oe(this,"length",0),oe(this,"pos",0),oe(this,"destroyed",!1),this.buffer=new Uint8Array(t),this.view=xe(this.buffer)}update(t){const{view:e,buffer:n,blockLen:r}=this,o=(t=Pe(t)).length;for(let i=0;i<o;){const s=Math.min(r-this.pos,o-i);if(s===r){const e=xe(t);for(;r<=o-i;i+=r)this.process(e,i);continue}n.set(t.subarray(i,i+s),this.pos),this.pos+=s,i+=s,this.pos===r&&(this.process(e,0),this.pos=0)}return this.length+=t.length,this.roundClean(),this}digestInto(t){this.finished=!0;const{buffer:e,view:n,blockLen:r,isLE:o}=this;let{pos:i}=this;e[i++]=128,this.buffer.subarray(i).fill(0),this.padOffset>r-i&&(this.process(n,0),i=0);for(let t=i;t<r;t++)e[t]=0;!function(t,e,n,r){if("function"==typeof t.setBigUint64)return t.setBigUint64(e,n,r);const o=BigInt(32),i=BigInt(4294967295),s=Number(n>>o&i),u=Number(n&i),c=r?4:0,a=r?0:4;t.setUint32(e+c,s,r),t.setUint32(e+a,u,r)}(n,r-8,BigInt(8*this.length),o),this.process(n,0);const s=xe(t),u=this.outputLen;if(u%4)throw new Error("_sha2: outputLen should be aligned to 32bit");const c=u/4,a=this.get();if(c>a.length)throw new Error("_sha2: outputLen bigger than state");for(let t=0;t<c;t++)s.setUint32(4*t,a[t],o)}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:o,destroyed:i,pos:s}=this;return t.length=r,t.pos=s,t.finished=o,t.destroyed=i,r%e&&t.buffer.set(n),t}},Ce=new Uint32Array([1937774191,1226093241,388252375,3666478592,2842636476,372324522,3817729613,2969243214]),qe=new Uint32Array(68),je=new Uint32Array(64),Fe=class extends Ve{constructor(){super(64,32,8,!1),oe(this,"A",0|Ce[0]),oe(this,"B",0|Ce[1]),oe(this,"C",0|Ce[2]),oe(this,"D",0|Ce[3]),oe(this,"E",0|Ce[4]),oe(this,"F",0|Ce[5]),oe(this,"G",0|Ce[6]),oe(this,"H",0|Ce[7])}get(){const{A:t,B:e,C:n,D:r,E:o,F:i,G:s,H:u}=this;return[t,e,n,r,o,i,s,u]}set(t,e,n,r,o,i,s,u){this.A=0|t,this.B=0|e,this.C=0|n,this.D=0|r,this.E=0|o,this.F=0|i,this.G=0|s,this.H=0|u}process(t,e){for(let n=0;n<16;n++,e+=4)qe[n]=t.getUint32(e,!1);for(let t=16;t<68;t++)qe[t]=ke(qe[t-16]^qe[t-9]^Le(qe[t-3],15))^Le(qe[t-13],7)^qe[t-6];for(let t=0;t<64;t++)je[t]=qe[t]^qe[t+4];let{A:n,B:r,C:o,D:i,E:s,F:u,G:c,H:a}=this;for(let t=0;t<64;t++){let e=t>=0&&t<=15,f=e?2043430169:2055708042,l=Le(Le(n,12)+s+Le(f,t),7),h=l^Le(n,12),d=(e?Re(n,r,o):Ie(n,r,o))+i+h+je[t]|0,g=(e?Re(s,u,c):Ke(s,u,c))+a+l+qe[t]|0;i=o,o=Le(r,9),r=n,n=d,a=c,c=Le(u,19),u=s,s=Ne(g)}n=n^this.A|0,r=r^this.B|0,o=o^this.C|0,i=i^this.D|0,s=s^this.E|0,u=u^this.F|0,c=c^this.G|0,a=a^this.H|0,this.set(n,r,o,i,s,u,c,a)}roundClean(){qe.fill(0)}destroy(){this.set(0,0,0,0,0,0,0,0),this.buffer.fill(0)}},Ze=function(t){const e=e=>t().update(Pe(e)).digest(),n=t();return e.outputLen=n.outputLen,e.blockLen=n.blockLen,e.create=()=>t(),e}(()=>new Fe),Te=class extends Oe{constructor(t,e){super(),oe(this,"oHash"),oe(this,"iHash"),oe(this,"blockLen"),oe(this,"outputLen"),oe(this,"finished",!1),oe(this,"destroyed",!1);const n=Pe(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 r=this.blockLen,o=new Uint8Array(r);o.set(n.length>r?t.create().update(n).digest():n);for(let t=0;t<o.length;t++)o[t]^=54;this.iHash.update(o),this.oHash=t.create();for(let t=0;t<o.length;t++)o[t]^=106;this.oHash.update(o),o.fill(0)}update(t){return this.iHash.update(t),this}digestInto(t){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:o,blockLen:i,outputLen:s}=this;return t.finished=r,t.destroyed=o,t.blockLen=i,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()}},De=(t,e,n)=>new Te(t,e).update(n).digest();De.create=(t,e)=>new Te(t,e);var _e=st(BigInt("115792089210356248756420345214020892766250353991924191454421193933289684991999")),Me=function(t){const{CURVE:e,curveOpts:n,hash:r,ecdsaOpts:o}=Vt(t);return function(t,e){return Object.assign({},e,{ProjectivePoint:e.Point,CURVE:t})}(t,kt(Lt(e,n),r,o))}({a:BigInt("115792089210356248756420345214020892766250353991924191454421193933289684991996"),b:BigInt("18505919022281880113072981827955639221458448578012075254857346196103069175443"),Fp:_e,h:ue,n:BigInt("115792089210356248756420345214020892766061623724957744567843809356293439045923"),Gx:BigInt("22963146547237050559479531362550074578802567295341616970375194840604139615431"),Gy:BigInt("85132369209828568825618990617112496413088388631904505083283536607588877201568"),hash:Ze,hmac:(t,...e)=>De(Ze,t,b(...e)),randomBytes:function(t=0){const e=new Uint8Array(t);if(we)return we.getRandomValues(e);{const e=function(t){if(be.length>t){const e=be.slice(0,t);return be=be.slice(t),Ee(),e}throw new Error("random number pool is not ready or insufficient, prevent getting too long random values or too often.")}(t);return e}}}),ze=st(BigInt(Me.CURVE.n));function Ye(t){const e=t?O(X(BigInt(t),ue)+ue,32):Me.utils.randomPrivateKey(),n=Me.getPublicKey(e,!1);return{privateKey:Xe(a(e),64),publicKey:Xe(a(n),64)}}function Ge(t){if(130!==t.length)throw new Error("Invalid public key to compress");const e=(t.length-2)/2,n=t.substring(2,2+e);let r="03";return X(S(t.substring(e+2,e+e+2)),ce)===se&&(r="02"),r+n}function $e(t){return a(He(t))}function Xe(t,e){return t.length>=e?t:new Array(e-t.length+1).join("0")+t}function We(t){return t.map(t=>{const e=t.toString(16);return 1===e.length?"0"+e:e}).join("")}function Je(t){const e=[];for(let n=0,r=t.length;n<r;n++)t[n]>=240&&t[n]<=247?(e.push(String.fromCodePoint(((7&t[n])<<18)+((63&t[n+1])<<12)+((63&t[n+2])<<6)+(63&t[n+3]))),n+=3):t[n]>=224&&t[n]<=239?(e.push(String.fromCodePoint(((15&t[n])<<12)+((63&t[n+1])<<6)+(63&t[n+2]))),n+=2):t[n]>=192&&t[n]<=223?(e.push(String.fromCodePoint(((31&t[n])<<6)+(63&t[n+1]))),n++):e.push(String.fromCodePoint(t[n]));return e.join("")}function Qe(t){let e=t.length;e%2!=0&&(t=Xe(t,e+1)),e=t.length;const n=e/2,r=new Uint8Array(n);for(let e=0;e<n;e++)r[e]=parseInt(t.substring(2*e,2*e+2),16);return r}function tn(t){const e=Me.ProjectivePoint.fromHex(t);if(!e)return!1;try{return e.assertValidity(),!0}catch(t){return!1}}function en(t,e){const n=Me.ProjectivePoint.fromHex(t);if(!n)return!1;const r=Me.ProjectivePoint.fromHex(e);return!!r&&n.equals(r)}function nn(t){const e=[];for(let n=0,r=t.length;n<r;n++){const r=t.codePointAt(n);if(r<=127)e.push(r);else if(r<=2047)e.push(192|r>>>6),e.push(128|63&r);else if(r<=55295||r>=57344&&r<=65535)e.push(224|r>>>12),e.push(128|r>>>6&63),e.push(128|63&r);else{if(!(r>=65536&&r<=1114111))throw e.push(r),new Error("input is not supported");n++,e.push(240|r>>>18&28),e.push(128|r>>>12&63),e.push(128|r>>>6&63),e.push(128|63&r)}}return new Uint8Array(e)}function rn(t,e){t="string"==typeof t?nn(t):t;let n=new Uint8Array(e),r=1,o=0,i=fn;const s=new Uint8Array(4),u=()=>{s[0]=r>>24&255,s[1]=r>>16&255,s[2]=r>>8&255,s[3]=255&r,i=Ze(b(t,s)),r++,o=0};u();for(let t=0,e=n.length;t<e;t++)o===i.length&&u(),n[t]=255&i[o++];return n}var on=S("80000000000000000000000000000000"),sn=S("7fffffffffffffffffffffffffffffff");function un(t,e,n,r,o,i=!1,s="1234567812345678",u="1234567812345678"){const c=Me.ProjectivePoint.fromHex(e.publicKey),a=Me.ProjectivePoint.fromHex(r),f=Me.ProjectivePoint.fromHex(n);let l=yn(t.publicKey,s),h=yn(n,u);i&&([l,h]=[h,l]);const d=S(e.privateKey),g=S(t.privateKey),y=c.x,p=on+(y&sn),w=ze.add(g,ze.mulN(p,d)),m=a.x,E=ze.add(on,m&sn),v=a.multiply(E).add(f).multiply(w);return rn(b(Qe(Xe(U(v.x),64)),Qe(Xe(U(v.y),64)),l,h),o)}function cn(t,e,n){const r=rn(b(t,e),n.length);for(let t=0,e=n.length;t<e;t++)n[t]^=255&r[t]}var an=0,fn=new Uint8Array;function ln(t,e,n=1,r){const o="string"==typeof t?Qe($e(t)):Uint8Array.from(t),i="string"==typeof e?Me.ProjectivePoint.fromHex(e):e,s=Ye(),u=S(s.privateKey);let c=s.publicKey;c.length>128&&(c=c.substring(c.length-128));const a=i.multiply(u),f=Qe(Xe(U(a.x),64)),l=Qe(Xe(U(a.y),64)),h=Ae(Ze(b(f,o,l)));cn(f,l,o);const d=Ae(o);if(r?.asn1){const t=Me.ProjectivePoint.fromHex(s.publicKey);return n===an?pe(t.x,t.y,d,h):pe(t.x,t.y,h,d)}return n===an?c+d+h:c+h+d}function hn(t,e,n=1,r){const{output:o="string",asn1:i=!1}=r||{},s=S(e);let u,c,a;if(i){const{x:e,y:r,cipher:o,hash:i}=function(t){function e(t,e){const n=ye(t,e),r=ge(t,e),o=t.substring(n,n+2*r);return{value:o,nextStart:n+o.length}}const n=ye(t,0),{value:r,nextStart:o}=e(t,n),{value:i,nextStart:s}=e(t,o),{value:u,nextStart:c}=e(t,s),{value:a}=e(t,c);return{x:S(r),y:S(i),hash:u,cipher:a}}(t);u=Me.ProjectivePoint.fromAffine({x:e,y:r}),a=i,c=o,n===an&&([c,a]=[a,c])}else u=Me.ProjectivePoint.fromHex("04"+t.substring(0,128)),a=t.substring(128,192),c=t.substring(192),n===an&&(a=t.substring(t.length-64),c=t.substring(128,t.length-64));const f=Qe(c),l=u.multiply(s),h=Qe(Xe(U(l.x),64)),d=Qe(Xe(U(l.y),64));cn(h,d,f);return We(Array.from(Ze(b(h,f,d))))===a.toLowerCase()?"array"===o?f:Je(f):"array"===o?[]:""}function dn(t,e,n={}){let{pointPool:r,der:o,hash:i,publicKey:s,userId:u}=n,c="string"==typeof t?$e(t):We(Array.from(t));i&&(s=s||mn(e),c=pn(c,s,u));const a=S(e),f=S(c);let l=null,h=null,d=null;do{do{let t;t=r&&r.length?r.pop():bn(),l=t.k,h=ze.add(f,t.x1)}while(h===se||h+l===Me.CURVE.n);d=ze.mul(ze.inv(ze.addN(a,ue)),ze.subN(l,ze.mulN(h,a)))}while(d===se);return o?function(t,e){const n=new fe(t),r=new fe(e);return new he([n,r]).getEncodedHex()}(h,d):Xe(U(h),64)+Xe(U(d),64)}function gn(t,e,n,r={}){let o;const{hash:i,der:s,userId:u}=r,c="string"==typeof n?n:n.toHex(!1);let a,f;if(o=i?pn("string"==typeof t?$e(t):t,c,u):"string"==typeof t?$e(t):We(Array.from(t)),s){const t=function(t){const e=ye(t,0),n=ye(t,e),r=ge(t,e),o=t.substring(n,n+2*r),i=n+o.length,s=ye(t,i),u=ge(t,i),c=t.substring(s,s+2*u);return{r:S(o),s:S(c)}}(e);a=t.r,f=t.s}else a=S(e.substring(0,64)),f=S(e.substring(64));const l="string"==typeof n?Me.ProjectivePoint.fromHex(n):n,h=S(o),d=ze.add(a,f);if(d===se)return!1;const g=Me.ProjectivePoint.BASE.multiply(f).add(l.multiply(d));return a===ze.add(h,g.x)}function yn(t,e="1234567812345678"){e=$e(e);const n=Xe(U(Me.CURVE.a),64),r=Xe(U(Me.CURVE.b),64),o=Xe(U(Me.ProjectivePoint.BASE.x),64),i=Xe(U(Me.ProjectivePoint.BASE.y),64);let s,u;if(128===t.length)s=t.substring(0,64),u=t.substring(64,128);else{const e=Me.ProjectivePoint.fromHex(t);s=Xe(U(e.x),64),u=Xe(U(e.y),64)}const c=Qe(e+n+r+o+i+s+u),a=4*e.length;return Ze(b(new Uint8Array([a>>8&255,255&a]),c))}function pn(t,e,n="1234567812345678"){const r=yn(e,n);return Ae(Ze(b(r,"string"==typeof t?Qe(t):t)))}function wn(t,e){const n=Me.ProjectivePoint.fromHex(t);return Me.utils.precompute(e,n)}function mn(t){return Xe(a(Me.getPublicKey(t,!1)),64)}function bn(){const t=Ye(),e=Me.ProjectivePoint.fromHex(t.publicKey),n=S(t.privateKey);return{...t,k:n,x1:e.x}}var En={};re(En,{decrypt:()=>Ln,encrypt:()=>Kn,sm4:()=>Rn});var vn=0,xn=32,Bn=16,An=Uint8Array.from([214,144,233,254,204,225,61,183,22,182,20,194,40,251,44,5,43,103,154,118,42,190,4,195,170,68,19,38,73,134,6,153,156,66,80,244,145,239,152,122,51,84,11,67,237,207,172,98,228,179,28,169,201,8,232,149,128,223,148,250,117,143,63,166,71,7,167,252,243,115,23,186,131,89,60,25,230,133,79,168,104,107,129,178,113,100,218,139,248,235,15,75,112,86,157,53,30,36,14,94,99,88,209,162,37,34,124,59,1,33,120,135,212,0,70,87,159,211,39,82,76,54,2,231,160,196,200,158,234,191,138,210,64,199,56,181,163,247,242,206,249,97,21,161,224,174,93,164,155,52,26,85,173,147,50,48,245,140,177,227,29,246,226,46,130,102,202,96,192,41,35,171,13,83,78,111,213,219,55,69,222,253,142,47,3,255,106,114,109,108,91,81,141,27,175,146,187,221,188,127,17,217,92,65,31,16,90,216,10,193,49,136,165,205,123,189,45,116,208,18,