@blockcerts/blockcerts-verifier 1.71.1 → 1.72.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bundle-stats.html +1 -1
- package/dist/{DataIntegrityProof-elCNKq16-DBDuaDNt.js → DataIntegrityProof-CsicZNrL-BkSRjzkI.js} +1 -1
- package/dist/{EcdsaSd2023-B0XPAIp6-K61axvBA.js → EcdsaSd2023-DN9HBdgh-Bc0hVwTd.js} +4 -4
- package/dist/EcdsaSecp256k1Signature2019-C3F03t_M-DAJeMTpu.js +1 -0
- package/dist/{Ed25519Signature2020-BQsESRnS-TKZI_1AX.js → Ed25519Signature2020-CglkQLKN-CQ6lMzyG.js} +2 -2
- package/dist/{EddsaRdfc2022-DQKzWHK4-BILzDBp-.js → EddsaRdfc2022-CfoLi-PP-l7ITLQQT.js} +2 -2
- package/dist/{MerkleProof2017-CYM8CJHB-FYpMvld0.js → MerkleProof2017-B_EJmYja-CYd4dJc1.js} +1 -1
- package/dist/{MerkleProof2019-BLrywo8h-Bo9rH2Eq.js → MerkleProof2019-B7t13hOo-D8n9YrUw.js} +1 -1
- package/dist/{checkCredentialSchemaConformity-CKNtOu_t-B9iaCRUE.js → checkCredentialSchemaConformity-BiggGGMP-Dx992E4t.js} +1 -1
- package/dist/{controlVerificationMethod-B4TgLED0-BGpxLjMq.js → controlVerificationMethod-Bh_-e0Fd-BUCC8ctY.js} +1 -1
- package/dist/{did-key-common.esm-BIftA62j-hVrUMxjy.js → did-key-common.esm-BELyYVSE-Cqrpf7cy.js} +3 -3
- package/dist/{did-key-ed25519.esm-Drn3Y7PF-CqD0ifNk.js → did-key-ed25519.esm-C3GUddDp-BJdBgNDg.js} +1 -1
- package/dist/{did-key-secp256k1.esm-DH-f3o5q-C66E7IxB.js → did-key-secp256k1.esm-D-R266jM-BTxlD5VW.js} +1 -1
- package/dist/{ed25519-key-pair.esm-DPOFpdJ2-BrwuS0Ia.js → ed25519-key-pair.esm-DQF2kkXh-XX5BXBcl.js} +3 -3
- package/dist/{elliptic-BYqApR8Y-CKp7atgR.js → elliptic-6I21PEnR-CsYseRX1.js} +1 -1
- package/dist/{index-BgTFEYQ4-DMaz98iZ.js → index-DXh-XAic-B2gT500V.js} +5 -5
- package/dist/{index-lyuTDW_o-nyi7dklX.js → index-fQcSLZgh-DpptYyN8.js} +1 -1
- package/dist/{jsonld-signatures-BbILf-Q7-DTp6__ud.js → jsonld-signatures-BbHr1fSN-BSospRuX.js} +5 -5
- package/dist/{keyUtils-ExMI0fmg-NVOmd8LH.js → keyUtils-ue8EY3Op-DoHdKWgN.js} +1 -1
- package/dist/main.js +45 -45
- package/dist/{retrieveVerificationMethodPublicKey-C5Gafl1E-Lv4waRy7.js → retrieveVerificationMethodPublicKey-CLBY4G8P-CagFGnNt.js} +1 -1
- package/dist/verifyIssuerProfile-BaiZaU2c-Zcu1X0PY.js +1 -0
- package/package.json +5 -5
- package/dist/EcdsaSecp256k1Signature2019-BHgoxmKI-DT2qHZod.js +0 -1
- package/dist/verifyIssuerProfile-DCJyz3ho-BwuCK9F3.js +0 -1
- /package/dist/{HashlinkVerifier-BsVlaml5-B4Niv2-b.js → HashlinkVerifier-CTG-OS14-B4Niv2-b.js} +0 -0
- /package/dist/{checkRevocationStatusList2021-CMAVXAVE-BEBD8TO8.js → checkRevocationStatusList2021-BDBFhnz6-BEBD8TO8.js} +0 -0
- /package/dist/{elliptic-4aZS_cwf-BpaNaVm0.js → elliptic-mDX7fQQx-BpaNaVm0.js} +0 -0
- /package/dist/{ensureNotRevoked-hGps0prO-DvMIgM4L.js → ensureNotRevoked-Dc6VA2bO-DvMIgM4L.js} +0 -0
- /package/dist/{ensureValidIssuingKey-BMVCi2T2-BdV46XBb.js → ensureValidIssuingKey-wTUvNuDH-BdV46XBb.js} +0 -0
- /package/dist/{index-CQYVZlSE-C0eXpZGn.js → index-BrurC4Vt-C0eXpZGn.js} +0 -0
- /package/dist/{index-BS134367-Dgus2xdV.js → index-Gr4i_Ned-Dgus2xdV.js} +0 -0
- /package/dist/{jsonld-B_Q2jvnp-BJ5uVeOU.js → jsonld-BAMY2WqE-BJ5uVeOU.js} +0 -0
- /package/dist/{sha256-u2xsd4MQ-C1PUWFZm.js → sha256-Bwge_vjI-C1PUWFZm.js} +0 -0
- /package/dist/{webcrypto.es-DpqeDikX-BnVhHKeM.js → webcrypto.es-DptGOl2T-BnVhHKeM.js} +0 -0
- /package/dist/{x25519-Kp6t9B5a-Dh8L0KYb.js → x25519-hG3WOzPe-Dh8L0KYb.js} +0 -0
package/dist/{ed25519-key-pair.esm-DPOFpdJ2-BrwuS0Ia.js → ed25519-key-pair.esm-DQF2kkXh-XX5BXBcl.js}
RENAMED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import{x as t,B as e,i as r}from"./main.js";import{d as n}from"./base64url-Cy03LJLt-vkTPfQOh.js";import{d as i,e as o}from"./index-DZLKRa_V-D_IQzjvG.js";import{_ as a}from"./tslib.es6--gQC4x5c-CmLYFWVC.js";import{e as c,x as s}from"./x25519-
|
|
2
|
-
/*! noble-ed25519 - MIT License (c) 2019 Paul Miller (paulmillr.com) */const u=BigInt(0),f=BigInt(1),l=BigInt(2),y=BigInt(8),p=BigInt("7237005577332262213973186563042994240857116359379907606001950938285454250989"),h=Object.freeze({a:BigInt(-1),d:BigInt("37095705934669439343138083508754565189542113879843219016388785533085940283555"),P:BigInt("57896044618658097711785492504343953926634992332820282019728792003956564819949"),l:p,n:p,h:BigInt(8),Gx:BigInt("15112221349535400772501151409588531511454012693041857206046113283949847762202"),Gy:BigInt("46316835694926478169428394003475163141307993866256225615783033603165251855960")}),d=BigInt("0x10000000000000000000000000000000000000000000000000000000000000000"),w=BigInt("19681161376707505956807079304988542015446066515923890162744021073123829784752");BigInt("6853475219497561581579357271197624642482790079785650197046958215289687604742");const v=BigInt("25063068953384623474111414158702152701244531502492656460079210482610430750235"),g=BigInt("54469307008909316920995813868745141605393597292927456921205312896311721017578"),b=BigInt("1159843021668779879193775521855586647937357759715417654439879720876111806838"),m=BigInt("40440834346308536858101042469323190826248399146238708352240133220865137265952");class x{constructor(t,e,r,n){this.x=t,this.y=e,this.z=r,this.t=n}static fromAffine(t){if(!(t instanceof U))throw new TypeError("ExtendedPoint#fromAffine: expected Point");return t.equals(U.ZERO)?x.ZERO:new x(t.x,t.y,f,J(t.x*t.y))}static toAffineBatch(t){const e=function(t,e=h.P){const r=new Array(t.length),n=F(t.reduce(((t,n,i)=>n===u?t:(r[i]=t,J(t*n,e))),f),e);return t.reduceRight(((t,n,i)=>n===u?t:(r[i]=J(t*r[i],e),J(t*n,e))),n),r}(t.map((t=>t.z)));return t.map(((t,r)=>t.toAffine(e[r])))}static normalizeZ(t){return this.toAffineBatch(t).map(this.fromAffine)}equals(t){E(t);const{x:e,y:r,z:n}=this,{x:i,y:o,z:a}=t,c=J(e*a),s=J(i*n),u=J(r*a),f=J(o*n);return c===s&&u===f}negate(){return new x(J(-this.x),this.y,this.z,J(-this.t))}double(){const{x:t,y:e,z:r}=this,{a:n}=h,i=J(t*t),o=J(e*e),a=J(l*J(r*r)),c=J(n*i),s=t+e,u=J(J(s*s)-i-o),f=c+o,y=f-a,p=c-o,d=J(u*y),w=J(f*p),v=J(u*p),g=J(y*f);return new x(d,w,g,v)}add(t){E(t);const{x:e,y:r,z:n,t:i}=this,{x:o,y:a,z:c,t:s}=t,f=J((r-e)*(a+o)),y=J((r+e)*(a-o)),p=J(y-f);if(p===u)return this.double();const h=J(n*l*s),d=J(i*l*c),w=d+h,v=y+f,g=d-h,b=J(w*p),m=J(v*g),K=J(w*g),k=J(p*v);return new x(b,m,k,K)}subtract(t){return this.add(t.negate())}precomputeWindow(t){const e=1+256/t,r=[];let n=this,i=n;for(let o=0;o<e;o++){i=n,r.push(i);for(let e=1;e<2**(t-1);e++)i=i.add(n),r.push(i);n=i.double()}return r}wNAF(t,e){!e&&this.equals(x.BASE)&&(e=U.BASE);const r=e&&e._WINDOW_SIZE||1;if(256%r)throw new Error("Point#wNAF: Invalid precomputation window, must be power of 2");let n=e&&P.get(e);n||(n=this.precomputeWindow(r),e&&1!==r&&(n=x.normalizeZ(n),P.set(e,n)));let i=x.ZERO,o=x.BASE;const a=1+256/r,c=2**(r-1),s=BigInt(2**r-1),u=2**r,l=BigInt(r);for(let e=0;e<a;e++){const r=e*c;let a=Number(t&s);t>>=l,a>c&&(a-=u,t+=f);const y=r,p=r+Math.abs(a)-1,h=e%2!=0,d=a<0;0===a?o=o.add(K(h,n[y])):i=i.add(K(d,n[p]))}return x.normalizeZ([i,o])[0]}multiply(t,e){return this.wNAF(q(t,h.l),e)}multiplyUnsafe(t){let e=q(t,h.l,!1);const r=x.BASE,n=x.ZERO;if(e===u)return n;if(this.equals(n)||e===f)return this;if(this.equals(r))return this.wNAF(e);let i=n,o=this;for(;e>u;)e&f&&(i=i.add(o)),o=o.double(),e>>=f;return i}isSmallOrder(){return this.multiplyUnsafe(h.h).equals(x.ZERO)}isTorsionFree(){let t=this.multiplyUnsafe(h.l/l).double();return h.l%l&&(t=t.add(this)),t.equals(x.ZERO)}toAffine(t){const{x:e,y:r,z:n}=this,i=this.equals(x.ZERO);null==t&&(t=i?y:F(n));const o=J(e*t),a=J(r*t),c=J(n*t);if(i)return U.ZERO;if(c!==f)throw new Error("invZ was invalid");return new U(o,a)}fromRistrettoBytes(){A()}toRistrettoBytes(){A()}fromRistrettoHash(){A()}}function K(t,e){const r=e.negate();return t?r:e}function E(t){if(!(t instanceof x))throw new TypeError("ExtendedPoint expected")}function k(t){if(!(t instanceof B))throw new TypeError("RistrettoPoint expected")}function A(){throw new Error("Legacy method: switch to RistrettoPoint")}x.BASE=new x(h.Gx,h.Gy,f,J(h.Gx*h.Gy)),x.ZERO=new x(u,f,f,u);class B{constructor(t){this.ep=t}static calcElligatorRistrettoMap(t){const{d:e}=h,r=J(w*t*t),n=J((r+f)*b);let i=BigInt(-1);const o=J((i-e*r)*J(r+e));let{isValid:a,value:c}=G(n,o),s=J(c*t);T(s)||(s=J(-s)),a||(c=s),a||(i=r);const u=J(i*(r-f)*m-o),l=c*c,y=J((c+c)*o),p=J(u*v),d=J(f-l),g=J(f+l);return new x(J(y*g),J(d*p),J(p*g),J(y*d))}static hashToCurve(t){const e=z((t=H(t,64)).slice(0,32)),r=this.calcElligatorRistrettoMap(e),n=z(t.slice(32,64)),i=this.calcElligatorRistrettoMap(n);return new B(r.add(i))}static fromHex(t){t=H(t,32);const{a:e,d:r}=h,n="RistrettoPoint.fromHex: the hex is not valid encoding of RistrettoPoint",i=z(t);if(!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}(I(i),t)||T(i))throw new Error(n);const o=J(i*i),a=J(f+e*o),c=J(f-e*o),s=J(a*a),l=J(c*c),y=J(e*r*s-l),{isValid:p,value:d}=Z(J(y*l)),w=J(d*c),v=J(d*w*y);let g=J((i+i)*w);T(g)&&(g=J(-g));const b=J(a*v),m=J(g*b);if(!p||T(m)||b===u)throw new Error(n);return new B(new x(g,b,f,m))}toRawBytes(){let{x:t,y:e,z:r,t:n}=this.ep;const i=J(J(r+e)*J(r-e)),o=J(t*e),a=J(o*o),{value:c}=Z(J(i*a)),s=J(c*i),u=J(c*o),f=J(s*u*n);let l;if(T(n*f)){let r=J(e*w),n=J(t*w);t=r,e=n,l=J(s*g)}else l=u;T(t*f)&&(e=J(-e));let y=J((r-e)*l);return T(y)&&(y=J(-y)),I(y)}toHex(){return j(this.toRawBytes())}toString(){return this.toHex()}equals(t){k(t);const e=this.ep,r=t.ep,n=J(e.x*r.y)===J(e.y*r.x),i=J(e.y*r.y)===J(e.x*r.x);return n||i}add(t){return k(t),new B(this.ep.add(t.ep))}subtract(t){return k(t),new B(this.ep.subtract(t.ep))}multiply(t){return new B(this.ep.multiply(t))}multiplyUnsafe(t){return new B(this.ep.multiplyUnsafe(t))}}B.BASE=new B(x.BASE),B.ZERO=new B(x.ZERO);const P=new WeakMap;class U{constructor(t,e){this.x=t,this.y=e}_setWindowSize(t){this._WINDOW_SIZE=t,P.delete(this)}static fromHex(t,e=!0){const{d:r,P:n}=h,i=(t=H(t,32)).slice();i[31]=-129&t[31];const o=R(i);if(e&&o>=n)throw new Error("Expected 0 < hex < P");if(!e&&o>=d)throw new Error("Expected 0 < hex < 2**256");const a=J(o*o),c=J(a-f),s=J(r*a+f);let{isValid:u,value:l}=G(c,s);if(!u)throw new Error("Point.fromHex: invalid y coordinate");const y=(l&f)===f;return!!(128&t[31])!==y&&(l=J(-l)),new U(l,o)}static async fromPrivateKey(t){return(await $(t)).point}toRawBytes(){const t=I(this.y);return t[31]|=this.x&f?128:0,t}toHex(){return j(this.toRawBytes())}toX25519(){const{y:t}=this;return I(J((f+t)*F(f-t)))}isTorsionFree(){return x.fromAffine(this).isTorsionFree()}equals(t){return this.x===t.x&&this.y===t.y}negate(){return new U(J(-this.x),this.y)}add(t){return x.fromAffine(this).add(x.fromAffine(t)).toAffine()}subtract(t){return this.add(t.negate())}multiply(t){return x.fromAffine(this).multiply(t,this).toAffine()}}U.BASE=new U(h.Gx,h.Gy),U.ZERO=new U(u,f);class L{constructor(t,e){this.r=t,this.s=e,this.assertValidity()}static fromHex(t){const e=H(t,64),r=U.fromHex(e.slice(0,32),!1),n=R(e.slice(32,64));return new L(r,n)}assertValidity(){const{r:t,s:e}=this;if(!(t instanceof U))throw new Error("Expected Point instance");return q(e,h.l,!1),this}toRawBytes(){const t=new Uint8Array(64);return t.set(this.r.toRawBytes()),t.set(I(this.s),32),t}toHex(){return j(this.toRawBytes())}}function O(...t){if(!t.every((t=>t instanceof Uint8Array)))throw new Error("Expected Uint8Array list");if(1===t.length)return t[0];const e=t.reduce(((t,e)=>t+e.length),0),r=new Uint8Array(e);for(let e=0,n=0;e<t.length;e++){const i=t[e];r.set(i,n),n+=i.length}return r}const S=Array.from({length:256},((t,e)=>e.toString(16).padStart(2,"0")));function j(t){if(!(t instanceof Uint8Array))throw new Error("Uint8Array expected");let e="";for(let r=0;r<t.length;r++)e+=S[t[r]];return e}function _(t){if("string"!=typeof t)throw new TypeError("hexToBytes: expected string, got "+typeof t);if(t.length%2)throw new Error("hexToBytes: received invalid unpadded hex");const e=new Uint8Array(t.length/2);for(let r=0;r<e.length;r++){const n=2*r,i=t.slice(n,n+2),o=Number.parseInt(i,16);if(Number.isNaN(o)||o<0)throw new Error("Invalid byte sequence");e[r]=o}return e}function M(t){return _(t.toString(16).padStart(64,"0"))}function I(t){return M(t).reverse()}function T(t){return(J(t)&f)===f}function R(t){if(!(t instanceof Uint8Array))throw new Error("Expected Uint8Array");return BigInt("0x"+j(Uint8Array.from(t).reverse()))}const N=BigInt("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff");function z(t){return J(R(t)&N)}function J(t,e=h.P){const r=t%e;return r>=u?r:e+r}function F(t,e=h.P){if(t===u||e<=u)throw new Error(`invert: expected positive integers, got n=${t} mod=${e}`);let r=J(t,e),n=e,i=u,o=f;for(;r!==u;){const t=n%r,e=i-o*(n/r);n=r,r=t,i=o,o=e}if(n!==f)throw new Error("invert: does not exist");return J(i,e)}function W(t,e){const{P:r}=h;let n=t;for(;e-- >u;)n*=n,n%=r;return n}function G(t,e){const r=J(e*e*e),n=function(t){const{P:e}=h,r=BigInt(5),n=BigInt(10),i=BigInt(20),o=BigInt(40),a=BigInt(80),c=t*t%e*t%e,s=W(c,l)*c%e,u=W(s,f)*t%e,y=W(u,r)*u%e,p=W(y,n)*y%e,d=W(p,i)*p%e,w=W(d,o)*d%e,v=W(w,a)*w%e,g=W(v,a)*w%e,b=W(g,n)*y%e;return{pow_p_5_8:W(b,l)*t%e,b2:c}}(t*J(r*r*e)).pow_p_5_8;let i=J(t*r*n);const o=J(e*i*i),a=i,c=J(i*w),s=o===t,u=o===J(-t),y=o===J(-t*w);return s&&(i=a),(u||y)&&(i=c),T(i)&&(i=J(-i)),{isValid:s||u,value:i}}function Z(t){return G(f,t)}function V(t){return J(R(t),h.l)}function H(t,e){const r=t instanceof Uint8Array?Uint8Array.from(t):_(t);if("number"==typeof e&&r.length!==e)throw new Error(`Expected ${e} bytes`);return r}function q(t,e,r=!0){if(!e)throw new TypeError("Specify max value");if("number"==typeof t&&Number.isSafeInteger(t)&&(t=BigInt(t)),"bigint"==typeof t&&t<e)if(r){if(u<t)return t}else if(u<=t)return t;throw new TypeError("Expected valid scalar: 0 < scalar < max")}let C;async function $(t){return function(t){const e=((r=t.slice(0,32))[0]&=248,r[31]&=127,r[31]|=64,r);var r;const n=t.slice(32,64),i=V(e),o=U.BASE.multiply(i),a=o.toRawBytes();return{head:e,prefix:n,scalar:i,point:o,pointBytes:a}}(await tt.sha512(function(t){if(32!==(t="bigint"==typeof t||"number"==typeof t?M(q(t,d)):H(t)).length)throw new Error("Expected 32 bytes");return t}(t)))}async function X(t){return(await $(t)).pointBytes}async function D(t,e){t=H(t);const{prefix:r,scalar:n,pointBytes:i}=await $(e),o=V(await tt.sha512(r,t)),a=U.BASE.multiply(o),c=J(o+V(await tt.sha512(a.toRawBytes(),i,t))*n,h.l);return new L(a,c).toRawBytes()}async function Y(t,e,r){const{r:n,SB:i,msg:o,pub:a}=function(t,e,r){e=H(e),r instanceof U||(r=U.fromHex(r,!1));const{r:n,s:i}=t instanceof L?t.assertValidity():L.fromHex(t);return{r:n,s:i,SB:x.BASE.multiplyUnsafe(i),pub:r,msg:e}}(t,e,r),c=await tt.sha512(n.toRawBytes(),a.toRawBytes(),o);return function(t,e,r,n){const i=V(n),o=x.fromAffine(t).multiplyUnsafe(i);return x.fromAffine(e).add(o).subtract(r).multiplyUnsafe(h.h).equals(x.ZERO)}(a,n,i,c)}U.BASE._setWindowSize(8);const Q={node:t,web:"object"==typeof self&&"crypto"in self?self.crypto:void 0},tt={bytesToHex:j,hexToBytes:_,concatBytes:O,getExtendedPublicKey:$,mod:J,invert:F,TORSION_SUBGROUP:["0100000000000000000000000000000000000000000000000000000000000000","c7176a703d4dd84fba3c0b760d10670f2a2053fa2c39ccc64ec7fd7792ac037a","0000000000000000000000000000000000000000000000000000000000000080","26e8958fc2b227b045c3f489f2ef98f0d5dfac05d3c63339b13802886d53fc05","ecffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff7f","26e8958fc2b227b045c3f489f2ef98f0d5dfac05d3c63339b13802886d53fc85","0000000000000000000000000000000000000000000000000000000000000000","c7176a703d4dd84fba3c0b760d10670f2a2053fa2c39ccc64ec7fd7792ac03fa"],hashToPrivateScalar:t=>{if((t=H(t)).length<40||t.length>1024)throw new Error("Expected 40-1024 bytes of private key as per FIPS 186");return J(R(t),h.l-f)+f},randomBytes:(t=32)=>{if(Q.web)return Q.web.getRandomValues(new Uint8Array(t));if(Q.node){const{randomBytes:e}=Q.node;return new Uint8Array(e(t).buffer)}throw new Error("The environment doesn't have randomBytes function")},randomPrivateKey:()=>tt.randomBytes(32),sha512:async(...t)=>{const e=O(...t);if(Q.web){const t=await Q.web.subtle.digest("SHA-512",e.buffer);return new Uint8Array(t)}if(Q.node)return Uint8Array.from(Q.node.createHash("sha512").update(e).digest());throw new Error("The environment doesn't have sha512 function")},precompute(t=8,e=U.BASE){const r=e.equals(U.BASE)?e:new U(e.x,e.y);return r._setWindowSize(t),r.multiply(l),r},sha512Sync:void 0};Object.defineProperties(tt,{sha512Sync:{configurable:!1,get:()=>C,set(t){C||(C=t)}}});if(!globalThis.crypto.getRandomValues)throw new Error('Browser does not provide "crypto.getRandomValues".');
|
|
1
|
+
import{x as t,B as e,i as r}from"./main.js";import{d as n}from"./base64url-Cy03LJLt-vkTPfQOh.js";import{d as i,e as o}from"./index-DZLKRa_V-D_IQzjvG.js";import{_ as a}from"./tslib.es6--gQC4x5c-CmLYFWVC.js";import{e as c,x as s}from"./x25519-hG3WOzPe-Dh8L0KYb.js";
|
|
2
|
+
/*! noble-ed25519 - MIT License (c) 2019 Paul Miller (paulmillr.com) */const u=BigInt(0),f=BigInt(1),l=BigInt(2),y=BigInt(8),p=BigInt("7237005577332262213973186563042994240857116359379907606001950938285454250989"),h=Object.freeze({a:BigInt(-1),d:BigInt("37095705934669439343138083508754565189542113879843219016388785533085940283555"),P:BigInt("57896044618658097711785492504343953926634992332820282019728792003956564819949"),l:p,n:p,h:BigInt(8),Gx:BigInt("15112221349535400772501151409588531511454012693041857206046113283949847762202"),Gy:BigInt("46316835694926478169428394003475163141307993866256225615783033603165251855960")}),d=BigInt("0x10000000000000000000000000000000000000000000000000000000000000000"),w=BigInt("19681161376707505956807079304988542015446066515923890162744021073123829784752");BigInt("6853475219497561581579357271197624642482790079785650197046958215289687604742");const v=BigInt("25063068953384623474111414158702152701244531502492656460079210482610430750235"),g=BigInt("54469307008909316920995813868745141605393597292927456921205312896311721017578"),b=BigInt("1159843021668779879193775521855586647937357759715417654439879720876111806838"),m=BigInt("40440834346308536858101042469323190826248399146238708352240133220865137265952");class x{constructor(t,e,r,n){this.x=t,this.y=e,this.z=r,this.t=n}static fromAffine(t){if(!(t instanceof U))throw new TypeError("ExtendedPoint#fromAffine: expected Point");return t.equals(U.ZERO)?x.ZERO:new x(t.x,t.y,f,J(t.x*t.y))}static toAffineBatch(t){const e=function(t,e=h.P){const r=new Array(t.length),n=F(t.reduce(((t,n,i)=>n===u?t:(r[i]=t,J(t*n,e))),f),e);return t.reduceRight(((t,n,i)=>n===u?t:(r[i]=J(t*r[i],e),J(t*n,e))),n),r}(t.map((t=>t.z)));return t.map(((t,r)=>t.toAffine(e[r])))}static normalizeZ(t){return this.toAffineBatch(t).map(this.fromAffine)}equals(t){E(t);const{x:e,y:r,z:n}=this,{x:i,y:o,z:a}=t,c=J(e*a),s=J(i*n),u=J(r*a),f=J(o*n);return c===s&&u===f}negate(){return new x(J(-this.x),this.y,this.z,J(-this.t))}double(){const{x:t,y:e,z:r}=this,{a:n}=h,i=J(t*t),o=J(e*e),a=J(l*J(r*r)),c=J(n*i),s=t+e,u=J(J(s*s)-i-o),f=c+o,y=f-a,p=c-o,d=J(u*y),w=J(f*p),v=J(u*p),g=J(y*f);return new x(d,w,g,v)}add(t){E(t);const{x:e,y:r,z:n,t:i}=this,{x:o,y:a,z:c,t:s}=t,f=J((r-e)*(a+o)),y=J((r+e)*(a-o)),p=J(y-f);if(p===u)return this.double();const h=J(n*l*s),d=J(i*l*c),w=d+h,v=y+f,g=d-h,b=J(w*p),m=J(v*g),K=J(w*g),k=J(p*v);return new x(b,m,k,K)}subtract(t){return this.add(t.negate())}precomputeWindow(t){const e=1+256/t,r=[];let n=this,i=n;for(let o=0;o<e;o++){i=n,r.push(i);for(let e=1;e<2**(t-1);e++)i=i.add(n),r.push(i);n=i.double()}return r}wNAF(t,e){!e&&this.equals(x.BASE)&&(e=U.BASE);const r=e&&e._WINDOW_SIZE||1;if(256%r)throw new Error("Point#wNAF: Invalid precomputation window, must be power of 2");let n=e&&P.get(e);n||(n=this.precomputeWindow(r),e&&1!==r&&(n=x.normalizeZ(n),P.set(e,n)));let i=x.ZERO,o=x.BASE;const a=1+256/r,c=2**(r-1),s=BigInt(2**r-1),u=2**r,l=BigInt(r);for(let e=0;e<a;e++){const r=e*c;let a=Number(t&s);t>>=l,a>c&&(a-=u,t+=f);const y=r,p=r+Math.abs(a)-1,h=e%2!=0,d=a<0;0===a?o=o.add(K(h,n[y])):i=i.add(K(d,n[p]))}return x.normalizeZ([i,o])[0]}multiply(t,e){return this.wNAF(q(t,h.l),e)}multiplyUnsafe(t){let e=q(t,h.l,!1);const r=x.BASE,n=x.ZERO;if(e===u)return n;if(this.equals(n)||e===f)return this;if(this.equals(r))return this.wNAF(e);let i=n,o=this;for(;e>u;)e&f&&(i=i.add(o)),o=o.double(),e>>=f;return i}isSmallOrder(){return this.multiplyUnsafe(h.h).equals(x.ZERO)}isTorsionFree(){let t=this.multiplyUnsafe(h.l/l).double();return h.l%l&&(t=t.add(this)),t.equals(x.ZERO)}toAffine(t){const{x:e,y:r,z:n}=this,i=this.equals(x.ZERO);null==t&&(t=i?y:F(n));const o=J(e*t),a=J(r*t),c=J(n*t);if(i)return U.ZERO;if(c!==f)throw new Error("invZ was invalid");return new U(o,a)}fromRistrettoBytes(){A()}toRistrettoBytes(){A()}fromRistrettoHash(){A()}}function K(t,e){const r=e.negate();return t?r:e}function E(t){if(!(t instanceof x))throw new TypeError("ExtendedPoint expected")}function k(t){if(!(t instanceof B))throw new TypeError("RistrettoPoint expected")}function A(){throw new Error("Legacy method: switch to RistrettoPoint")}x.BASE=new x(h.Gx,h.Gy,f,J(h.Gx*h.Gy)),x.ZERO=new x(u,f,f,u);class B{constructor(t){this.ep=t}static calcElligatorRistrettoMap(t){const{d:e}=h,r=J(w*t*t),n=J((r+f)*b);let i=BigInt(-1);const o=J((i-e*r)*J(r+e));let{isValid:a,value:c}=G(n,o),s=J(c*t);T(s)||(s=J(-s)),a||(c=s),a||(i=r);const u=J(i*(r-f)*m-o),l=c*c,y=J((c+c)*o),p=J(u*v),d=J(f-l),g=J(f+l);return new x(J(y*g),J(d*p),J(p*g),J(y*d))}static hashToCurve(t){const e=z((t=H(t,64)).slice(0,32)),r=this.calcElligatorRistrettoMap(e),n=z(t.slice(32,64)),i=this.calcElligatorRistrettoMap(n);return new B(r.add(i))}static fromHex(t){t=H(t,32);const{a:e,d:r}=h,n="RistrettoPoint.fromHex: the hex is not valid encoding of RistrettoPoint",i=z(t);if(!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}(I(i),t)||T(i))throw new Error(n);const o=J(i*i),a=J(f+e*o),c=J(f-e*o),s=J(a*a),l=J(c*c),y=J(e*r*s-l),{isValid:p,value:d}=Z(J(y*l)),w=J(d*c),v=J(d*w*y);let g=J((i+i)*w);T(g)&&(g=J(-g));const b=J(a*v),m=J(g*b);if(!p||T(m)||b===u)throw new Error(n);return new B(new x(g,b,f,m))}toRawBytes(){let{x:t,y:e,z:r,t:n}=this.ep;const i=J(J(r+e)*J(r-e)),o=J(t*e),a=J(o*o),{value:c}=Z(J(i*a)),s=J(c*i),u=J(c*o),f=J(s*u*n);let l;if(T(n*f)){let r=J(e*w),n=J(t*w);t=r,e=n,l=J(s*g)}else l=u;T(t*f)&&(e=J(-e));let y=J((r-e)*l);return T(y)&&(y=J(-y)),I(y)}toHex(){return j(this.toRawBytes())}toString(){return this.toHex()}equals(t){k(t);const e=this.ep,r=t.ep,n=J(e.x*r.y)===J(e.y*r.x),i=J(e.y*r.y)===J(e.x*r.x);return n||i}add(t){return k(t),new B(this.ep.add(t.ep))}subtract(t){return k(t),new B(this.ep.subtract(t.ep))}multiply(t){return new B(this.ep.multiply(t))}multiplyUnsafe(t){return new B(this.ep.multiplyUnsafe(t))}}B.BASE=new B(x.BASE),B.ZERO=new B(x.ZERO);const P=new WeakMap;class U{constructor(t,e){this.x=t,this.y=e}_setWindowSize(t){this._WINDOW_SIZE=t,P.delete(this)}static fromHex(t,e=!0){const{d:r,P:n}=h,i=(t=H(t,32)).slice();i[31]=-129&t[31];const o=R(i);if(e&&o>=n)throw new Error("Expected 0 < hex < P");if(!e&&o>=d)throw new Error("Expected 0 < hex < 2**256");const a=J(o*o),c=J(a-f),s=J(r*a+f);let{isValid:u,value:l}=G(c,s);if(!u)throw new Error("Point.fromHex: invalid y coordinate");const y=(l&f)===f;return!!(128&t[31])!==y&&(l=J(-l)),new U(l,o)}static async fromPrivateKey(t){return(await $(t)).point}toRawBytes(){const t=I(this.y);return t[31]|=this.x&f?128:0,t}toHex(){return j(this.toRawBytes())}toX25519(){const{y:t}=this;return I(J((f+t)*F(f-t)))}isTorsionFree(){return x.fromAffine(this).isTorsionFree()}equals(t){return this.x===t.x&&this.y===t.y}negate(){return new U(J(-this.x),this.y)}add(t){return x.fromAffine(this).add(x.fromAffine(t)).toAffine()}subtract(t){return this.add(t.negate())}multiply(t){return x.fromAffine(this).multiply(t,this).toAffine()}}U.BASE=new U(h.Gx,h.Gy),U.ZERO=new U(u,f);class O{constructor(t,e){this.r=t,this.s=e,this.assertValidity()}static fromHex(t){const e=H(t,64),r=U.fromHex(e.slice(0,32),!1),n=R(e.slice(32,64));return new O(r,n)}assertValidity(){const{r:t,s:e}=this;if(!(t instanceof U))throw new Error("Expected Point instance");return q(e,h.l,!1),this}toRawBytes(){const t=new Uint8Array(64);return t.set(this.r.toRawBytes()),t.set(I(this.s),32),t}toHex(){return j(this.toRawBytes())}}function L(...t){if(!t.every((t=>t instanceof Uint8Array)))throw new Error("Expected Uint8Array list");if(1===t.length)return t[0];const e=t.reduce(((t,e)=>t+e.length),0),r=new Uint8Array(e);for(let e=0,n=0;e<t.length;e++){const i=t[e];r.set(i,n),n+=i.length}return r}const S=Array.from({length:256},((t,e)=>e.toString(16).padStart(2,"0")));function j(t){if(!(t instanceof Uint8Array))throw new Error("Uint8Array expected");let e="";for(let r=0;r<t.length;r++)e+=S[t[r]];return e}function _(t){if("string"!=typeof t)throw new TypeError("hexToBytes: expected string, got "+typeof t);if(t.length%2)throw new Error("hexToBytes: received invalid unpadded hex");const e=new Uint8Array(t.length/2);for(let r=0;r<e.length;r++){const n=2*r,i=t.slice(n,n+2),o=Number.parseInt(i,16);if(Number.isNaN(o)||o<0)throw new Error("Invalid byte sequence");e[r]=o}return e}function M(t){return _(t.toString(16).padStart(64,"0"))}function I(t){return M(t).reverse()}function T(t){return(J(t)&f)===f}function R(t){if(!(t instanceof Uint8Array))throw new Error("Expected Uint8Array");return BigInt("0x"+j(Uint8Array.from(t).reverse()))}const N=BigInt("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff");function z(t){return J(R(t)&N)}function J(t,e=h.P){const r=t%e;return r>=u?r:e+r}function F(t,e=h.P){if(t===u||e<=u)throw new Error(`invert: expected positive integers, got n=${t} mod=${e}`);let r=J(t,e),n=e,i=u,o=f;for(;r!==u;){const t=n%r,e=i-o*(n/r);n=r,r=t,i=o,o=e}if(n!==f)throw new Error("invert: does not exist");return J(i,e)}function W(t,e){const{P:r}=h;let n=t;for(;e-- >u;)n*=n,n%=r;return n}function G(t,e){const r=J(e*e*e),n=function(t){const{P:e}=h,r=BigInt(5),n=BigInt(10),i=BigInt(20),o=BigInt(40),a=BigInt(80),c=t*t%e*t%e,s=W(c,l)*c%e,u=W(s,f)*t%e,y=W(u,r)*u%e,p=W(y,n)*y%e,d=W(p,i)*p%e,w=W(d,o)*d%e,v=W(w,a)*w%e,g=W(v,a)*w%e,b=W(g,n)*y%e;return{pow_p_5_8:W(b,l)*t%e,b2:c}}(t*J(r*r*e)).pow_p_5_8;let i=J(t*r*n);const o=J(e*i*i),a=i,c=J(i*w),s=o===t,u=o===J(-t),y=o===J(-t*w);return s&&(i=a),(u||y)&&(i=c),T(i)&&(i=J(-i)),{isValid:s||u,value:i}}function Z(t){return G(f,t)}function V(t){return J(R(t),h.l)}function H(t,e){const r=t instanceof Uint8Array?Uint8Array.from(t):_(t);if("number"==typeof e&&r.length!==e)throw new Error(`Expected ${e} bytes`);return r}function q(t,e,r=!0){if(!e)throw new TypeError("Specify max value");if("number"==typeof t&&Number.isSafeInteger(t)&&(t=BigInt(t)),"bigint"==typeof t&&t<e)if(r){if(u<t)return t}else if(u<=t)return t;throw new TypeError("Expected valid scalar: 0 < scalar < max")}let C;async function $(t){return function(t){const e=((r=t.slice(0,32))[0]&=248,r[31]&=127,r[31]|=64,r);var r;const n=t.slice(32,64),i=V(e),o=U.BASE.multiply(i),a=o.toRawBytes();return{head:e,prefix:n,scalar:i,point:o,pointBytes:a}}(await tt.sha512(function(t){if(32!==(t="bigint"==typeof t||"number"==typeof t?M(q(t,d)):H(t)).length)throw new Error("Expected 32 bytes");return t}(t)))}async function X(t){return(await $(t)).pointBytes}async function D(t,e){t=H(t);const{prefix:r,scalar:n,pointBytes:i}=await $(e),o=V(await tt.sha512(r,t)),a=U.BASE.multiply(o),c=J(o+V(await tt.sha512(a.toRawBytes(),i,t))*n,h.l);return new O(a,c).toRawBytes()}async function Y(t,e,r){const{r:n,SB:i,msg:o,pub:a}=function(t,e,r){e=H(e),r instanceof U||(r=U.fromHex(r,!1));const{r:n,s:i}=t instanceof O?t.assertValidity():O.fromHex(t);return{r:n,s:i,SB:x.BASE.multiplyUnsafe(i),pub:r,msg:e}}(t,e,r),c=await tt.sha512(n.toRawBytes(),a.toRawBytes(),o);return function(t,e,r,n){const i=V(n),o=x.fromAffine(t).multiplyUnsafe(i);return x.fromAffine(e).add(o).subtract(r).multiplyUnsafe(h.h).equals(x.ZERO)}(a,n,i,c)}U.BASE._setWindowSize(8);const Q={node:t,web:"object"==typeof self&&"crypto"in self?self.crypto:void 0},tt={bytesToHex:j,hexToBytes:_,concatBytes:L,getExtendedPublicKey:$,mod:J,invert:F,TORSION_SUBGROUP:["0100000000000000000000000000000000000000000000000000000000000000","c7176a703d4dd84fba3c0b760d10670f2a2053fa2c39ccc64ec7fd7792ac037a","0000000000000000000000000000000000000000000000000000000000000080","26e8958fc2b227b045c3f489f2ef98f0d5dfac05d3c63339b13802886d53fc05","ecffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff7f","26e8958fc2b227b045c3f489f2ef98f0d5dfac05d3c63339b13802886d53fc85","0000000000000000000000000000000000000000000000000000000000000000","c7176a703d4dd84fba3c0b760d10670f2a2053fa2c39ccc64ec7fd7792ac03fa"],hashToPrivateScalar:t=>{if((t=H(t)).length<40||t.length>1024)throw new Error("Expected 40-1024 bytes of private key as per FIPS 186");return J(R(t),h.l-f)+f},randomBytes:(t=32)=>{if(Q.web)return Q.web.getRandomValues(new Uint8Array(t));if(Q.node){const{randomBytes:e}=Q.node;return new Uint8Array(e(t).buffer)}throw new Error("The environment doesn't have randomBytes function")},randomPrivateKey:()=>tt.randomBytes(32),sha512:async(...t)=>{const e=L(...t);if(Q.web){const t=await Q.web.subtle.digest("SHA-512",e.buffer);return new Uint8Array(t)}if(Q.node)return Uint8Array.from(Q.node.createHash("sha512").update(e).digest());throw new Error("The environment doesn't have sha512 function")},precompute(t=8,e=U.BASE){const r=e.equals(U.BASE)?e:new U(e.x,e.y);return r._setWindowSize(t),r.multiply(l),r},sha512Sync:void 0};Object.defineProperties(tt,{sha512Sync:{configurable:!1,get:()=>C,set(t){C||(C=t)}}});if(!globalThis.crypto.getRandomValues)throw new Error('Browser does not provide "crypto.getRandomValues".');
|
|
3
3
|
/*!
|
|
4
4
|
* Copyright (c) 2022 Digital Bazaar, Inc. All rights reserved.
|
|
5
5
|
*/
|
|
@@ -22,4 +22,4 @@ function ut({keyPair:t}){const e={};return t.publicKey&&(e.publicKeyMultibase=ft
|
|
|
22
22
|
*/}]]);async function wt({keyPair:t}){const e=dt.get(t.type);if(!e)throw new Error(`Unsupported key type "${t.type}".`);const{contextUrl:r,translationFn:n}=e;if(t["@context"]||(t["@context"]=r),!function({document:t,contextUrl:e}){const r=t["@context"];return r===e||Array.isArray(r)&&r.includes(e)}
|
|
23
23
|
/*!
|
|
24
24
|
* Copyright (c) 2020-2023 Digital Bazaar, Inc. All rights reserved.
|
|
25
|
-
*/({document:t,contextUrl:r}))throw new Error(`Context not supported "${t["@context"]}".`);return n({keyPair:t})}async function vt(t){let e={...t};if("Multikey"!==e.type){if(e.publicKeyJwk){let t,r;return"JsonWebKey"!==e.type&&"JsonWebKey2020"!==e.type||({id:t,controller:r}=e),async function({jwk:t,secretKey:e=!1,id:r,controller:n}={}){const i={"@context":at,type:"Multikey",publicKeyMultibase:pt({jwk:t})};"string"==typeof r&&(i.id=r);"string"==typeof n&&(i.controller=n);e&&t.d&&(i.secretKeyMultibase=ht({jwk:t}));return vt(i)}({jwk:e.publicKeyJwk,secretKey:!1,id:t,controller:r})}if(e.type)return e=await wt({keyPair:e}),gt({keyPair:e})}return e.type||(e.type="Multikey"),e["@context"]||(e["@context"]=at),function(t){if(!t||"object"!=typeof t)throw new TypeError('"key" must be an object.');if("Multikey"!==t.type)throw new Error('"key" must be a Multikey with type "Multikey".');if(!(t["@context"]===at||Array.isArray(t["@context"])&&t["@context"].includes(at)))throw new TypeError(`"key" must be a Multikey with context "${at}".`)}(e),gt({keyPair:e})}async function gt({keyPair:t}){return t.publicKey||(t=await yt(t)),t={...t,async export({publicKey:e=!0,secretKey:r=!1,includeContext:n=!0,raw:i=!1,canonicalize:o=!1}={}){if(i){const{publicKey:e,secretKey:r}=t,n={};return e&&(n.publicKey=e.slice()),r&&(o&&r.length>st?n.secretKey=r.subarray(0,st).slice():n.secretKey=r),n}return lt({keyPair:t,publicKey:e,secretKey:r,includeContext:n,canonicalize:o})},signer(){const{id:e,secretKey:r}=t;return rt({id:e,secretKey:r})},verifier(){const{id:e,publicKey:r}=t;return nt({id:e,publicKey:r})}}}var bt,mt,xt={exports:{}},Kt={};var Et,kt,At,Bt=(mt||(mt=1,xt.exports=(bt||(bt=1,Et=Kt,Object.defineProperty(Et,"__esModule",{value:!0}),Et.staticImplements=function(){return function(t){}}),Kt)),xt.exports),Pt={exports:{}},Ut={};var Lt=(At||(At=1,Pt.exports=(kt||(kt=1,function(t){Object.defineProperty(t,"__esModule",{value:!0}),t.staticImplements=function(){return function(t){}}}(Ut)),Ut)),Pt.exports);function Ot(t,e,r,n,i,o,a){try{var c=t[o](a),s=c.value}catch(t){return void r(t)}c.done?e(s):Promise.resolve(s).then(n,i)}function St(t){return function(){var e=this,r=arguments;return new Promise((function(n,i){var o=t.apply(e,r);function a(t){Ot(o,n,i,a,c,"next",t)}function c(t){Ot(o,n,i,a,c,"throw",t)}a(void 0)}))}}function jt(){return jt=Object.assign||function(t){for(var e=1;e<arguments.length;e++){var r=arguments[e];for(var n in r)Object.prototype.hasOwnProperty.call(r,n)&&(t[n]=r[n])}return t},jt.apply(this,arguments)}var _t,Mt,It=(_t=function(t){var e=function(t){var e,r=Object.prototype,n=r.hasOwnProperty,i="function"==typeof Symbol?Symbol:{},o=i.iterator||"@@iterator",a=i.asyncIterator||"@@asyncIterator",c=i.toStringTag||"@@toStringTag";function s(t,e,r){return Object.defineProperty(t,e,{value:r,enumerable:!0,configurable:!0,writable:!0}),t[e]}try{s({},"")}catch(t){s=function(t,e,r){return t[e]=r}}function u(t,e,r,n){var i=e&&e.prototype instanceof w?e:w,o=Object.create(i.prototype),a=new U(n||[]);return o._invoke=function(t,e,r){var n=l;return function(i,o){if(n===p)throw new Error("Generator is already running");if(n===h){if("throw"===i)throw o;return O()}for(r.method=i,r.arg=o;;){var a=r.delegate;if(a){var c=A(a,r);if(c){if(c===d)continue;return c}}if("next"===r.method)r.sent=r._sent=r.arg;else if("throw"===r.method){if(n===l)throw n=h,r.arg;r.dispatchException(r.arg)}else"return"===r.method&&r.abrupt("return",r.arg);n=p;var s=f(t,e,r);if("normal"===s.type){if(n=r.done?h:y,s.arg===d)continue;return{value:s.arg,done:r.done}}"throw"===s.type&&(n=h,r.method="throw",r.arg=s.arg)}}}(t,r,a),o}function f(t,e,r){try{return{type:"normal",arg:t.call(e,r)}}catch(t){return{type:"throw",arg:t}}}t.wrap=u;var l="suspendedStart",y="suspendedYield",p="executing",h="completed",d={};function w(){}function v(){}function g(){}var b={};b[o]=function(){return this};var m=Object.getPrototypeOf,x=m&&m(m(L([])));x&&x!==r&&n.call(x,o)&&(b=x);var K=g.prototype=w.prototype=Object.create(b);function E(t){["next","throw","return"].forEach((function(e){s(t,e,(function(t){return this._invoke(e,t)}))}))}function k(t,e){function r(i,o,a,c){var s=f(t[i],t,o);if("throw"!==s.type){var u=s.arg,l=u.value;return l&&"object"==typeof l&&n.call(l,"__await")?e.resolve(l.__await).then((function(t){r("next",t,a,c)}),(function(t){r("throw",t,a,c)})):e.resolve(l).then((function(t){u.value=t,a(u)}),(function(t){return r("throw",t,a,c)}))}c(s.arg)}var i;this._invoke=function(t,n){function o(){return new e((function(e,i){r(t,n,e,i)}))}return i=i?i.then(o,o):o()}}function A(t,r){var n=t.iterator[r.method];if(n===e){if(r.delegate=null,"throw"===r.method){if(t.iterator.return&&(r.method="return",r.arg=e,A(t,r),"throw"===r.method))return d;r.method="throw",r.arg=new TypeError("The iterator does not provide a 'throw' method")}return d}var i=f(n,t.iterator,r.arg);if("throw"===i.type)return r.method="throw",r.arg=i.arg,r.delegate=null,d;var o=i.arg;return o?o.done?(r[t.resultName]=o.value,r.next=t.nextLoc,"return"!==r.method&&(r.method="next",r.arg=e),r.delegate=null,d):o:(r.method="throw",r.arg=new TypeError("iterator result is not an object"),r.delegate=null,d)}function B(t){var e={tryLoc:t[0]};1 in t&&(e.catchLoc=t[1]),2 in t&&(e.finallyLoc=t[2],e.afterLoc=t[3]),this.tryEntries.push(e)}function P(t){var e=t.completion||{};e.type="normal",delete e.arg,t.completion=e}function U(t){this.tryEntries=[{tryLoc:"root"}],t.forEach(B,this),this.reset(!0)}function L(t){if(t){var r=t[o];if(r)return r.call(t);if("function"==typeof t.next)return t;if(!isNaN(t.length)){var i=-1,a=function r(){for(;++i<t.length;)if(n.call(t,i))return r.value=t[i],r.done=!1,r;return r.value=e,r.done=!0,r};return a.next=a}}return{next:O}}function O(){return{value:e,done:!0}}return v.prototype=K.constructor=g,g.constructor=v,v.displayName=s(g,c,"GeneratorFunction"),t.isGeneratorFunction=function(t){var e="function"==typeof t&&t.constructor;return!!e&&(e===v||"GeneratorFunction"===(e.displayName||e.name))},t.mark=function(t){return Object.setPrototypeOf?Object.setPrototypeOf(t,g):(t.__proto__=g,s(t,c,"GeneratorFunction")),t.prototype=Object.create(K),t},t.awrap=function(t){return{__await:t}},E(k.prototype),k.prototype[a]=function(){return this},t.AsyncIterator=k,t.async=function(e,r,n,i,o){void 0===o&&(o=Promise);var a=new k(u(e,r,n,i),o);return t.isGeneratorFunction(r)?a:a.next().then((function(t){return t.done?t.value:a.next()}))},E(K),s(K,c,"Generator"),K[o]=function(){return this},K.toString=function(){return"[object Generator]"},t.keys=function(t){var e=[];for(var r in t)e.push(r);return e.reverse(),function r(){for(;e.length;){var n=e.pop();if(n in t)return r.value=n,r.done=!1,r}return r.done=!0,r}},t.values=L,U.prototype={constructor:U,reset:function(t){if(this.prev=0,this.next=0,this.sent=this._sent=e,this.done=!1,this.delegate=null,this.method="next",this.arg=e,this.tryEntries.forEach(P),!t)for(var r in this)"t"===r.charAt(0)&&n.call(this,r)&&!isNaN(+r.slice(1))&&(this[r]=e)},stop:function(){this.done=!0;var t=this.tryEntries[0].completion;if("throw"===t.type)throw t.arg;return this.rval},dispatchException:function(t){if(this.done)throw t;var r=this;function i(n,i){return c.type="throw",c.arg=t,r.next=n,i&&(r.method="next",r.arg=e),!!i}for(var o=this.tryEntries.length-1;o>=0;--o){var a=this.tryEntries[o],c=a.completion;if("root"===a.tryLoc)return i("end");if(a.tryLoc<=this.prev){var s=n.call(a,"catchLoc"),u=n.call(a,"finallyLoc");if(s&&u){if(this.prev<a.catchLoc)return i(a.catchLoc,!0);if(this.prev<a.finallyLoc)return i(a.finallyLoc)}else if(s){if(this.prev<a.catchLoc)return i(a.catchLoc,!0)}else{if(!u)throw new Error("try statement without catch or finally");if(this.prev<a.finallyLoc)return i(a.finallyLoc)}}}},abrupt:function(t,e){for(var r=this.tryEntries.length-1;r>=0;--r){var i=this.tryEntries[r];if(i.tryLoc<=this.prev&&n.call(i,"finallyLoc")&&this.prev<i.finallyLoc){var o=i;break}}o&&("break"===t||"continue"===t)&&o.tryLoc<=e&&e<=o.finallyLoc&&(o=null);var a=o?o.completion:{};return a.type=t,a.arg=e,o?(this.method="next",this.next=o.finallyLoc,d):this.complete(a)},complete:function(t,e){if("throw"===t.type)throw t.arg;return"break"===t.type||"continue"===t.type?this.next=t.arg:"return"===t.type?(this.rval=this.arg=t.arg,this.method="return",this.next="end"):"normal"===t.type&&e&&(this.next=e),d},finish:function(t){for(var e=this.tryEntries.length-1;e>=0;--e){var r=this.tryEntries[e];if(r.finallyLoc===t)return this.complete(r.completion,r.afterLoc),P(r),d}},catch:function(t){for(var e=this.tryEntries.length-1;e>=0;--e){var r=this.tryEntries[e];if(r.tryLoc===t){var n=r.completion;if("throw"===n.type){var i=n.arg;P(r)}return i}}throw new Error("illegal catch attempt")},delegateYield:function(t,r,n){return this.delegate={iterator:L(t),resultName:r,nextLoc:n},"next"===this.method&&(this.arg=e),d}},t}(t.exports);try{regeneratorRuntime=e}catch(t){Function("r","regeneratorRuntime = r")(e)}},_t(Mt={exports:{}},Mt.exports),Mt.exports);function Tt(t){if(t.length>=255)throw new TypeError("Alphabet too long");for(var n=new Uint8Array(256),i=0;i<n.length;i++)n[i]=255;for(var o=0;o<t.length;o++){var a=t.charAt(o),c=a.charCodeAt(0);if(255!==n[c])throw new TypeError(a+" is ambiguous");n[c]=o}var s=t.length,u=t.charAt(0),f=Math.log(s)/Math.log(256),l=Math.log(256)/Math.log(s);function y(t){if("string"!=typeof t)throw new TypeError("Expected String");if(0===t.length)return e.alloc(0);var r=0;if(" "!==t[r]){for(var i=0,o=0;t[r]===u;)i++,r++;for(var a=(t.length-r)*f+1>>>0,c=new Uint8Array(a);t[r];){var l=n[t.charCodeAt(r)];if(255===l)return;for(var y=0,p=a-1;(0!==l||y<o)&&-1!==p;p--,y++)l+=s*c[p]>>>0,c[p]=l%256>>>0,l=l/256>>>0;if(0!==l)throw new Error("Non-zero carry");o=y,r++}if(" "!==t[r]){for(var h=a-o;h!==a&&0===c[h];)h++;var d=e.allocUnsafe(i+(a-h));d.fill(0,0,i);for(var w=i;h!==a;)d[w++]=c[h++];return d}}}return{encode:function(n){if((Array.isArray(n)||n instanceof Uint8Array)&&(n=e.from(n)),!r(n))throw new TypeError("Expected Buffer");if(0===n.length)return"";for(var i=0,o=0,a=0,c=n.length;a!==c&&0===n[a];)a++,i++;for(var f=(c-a)*l+1>>>0,y=new Uint8Array(f);a!==c;){for(var p=n[a],h=0,d=f-1;(0!==p||h<o)&&-1!==d;d--,h++)p+=256*y[d]>>>0,y[d]=p%s>>>0,p=p/s>>>0;if(0!==p)throw new Error("Non-zero carry");o=h,a++}for(var w=f-o;w!==f&&0===y[w];)w++;for(var v=u.repeat(i);w<f;++w)v+=t.charAt(y[w]);return v},decodeUnsafe:y,decode:function(t){var e=y(t);if(e)return e;throw new Error("Non-base"+s+" character")}}}var Rt,Nt=Tt("123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"),zt=function(t){return e.from(t||"").toString("base64")},Jt=function(t){return zt(t).replace(/\+/g,"-").replace(/\//g,"_").replace(/=+$/g,"")},Ft=function(t,e){void 0===e&&(e="base58btc");var r=new Uint8Array(2+t.length);if(r[0]=236,r[1]=1,r.set(t,2),"base58btc"===e)return"z"+Nt.encode(r);if("base64url"===e)return"u"+Jt(r);throw new Error("Unsupported encoding: "+e)},Wt=function(t){return Uint8Array.from(e.from(t.x,"base64"))},Gt={JsonWebKey2020:function(t){var r,n=Wt(t.publicKeyJwk),i=void 0;t.privateKeyJwk&&(i=(r=t.privateKeyJwk,{publicKey:Wt(r),privateKey:Uint8Array.from(e.from(r.d,"base64"))}).privateKey);return{publicKey:n,privateKey:i}},X25519KeyAgreementKey2019:function(t){var e=Nt.decode(t.publicKeyBase58),r=void 0;return t.privateKeyBase58&&(r=Uint8Array.from(Nt.decode(t.privateKeyBase58))),{publicKey:e,privateKey:r}}},Zt={JsonWebKey2020:function(t,e,r,n){var i={kty:"OKP",crv:"X25519",x:Jt(r)},o={id:t,type:"JsonWebKey2020",controller:e,publicKeyJwk:i};return n&&(o.privateKeyJwk=jt({},i,{d:Jt(n)})),o},X25519KeyAgreementKey2019:function(t,e,r,n){var i={id:t,type:"X25519KeyAgreementKey2019",controller:e,publicKeyBase58:Nt.encode(r)};return n&&(i.privateKeyBase58=Nt.encode(n)),i}},Vt=Rt=function(){function t(t){this.type="JsonWebKey2020",this.id=t.id,this.type=t.type||"JsonWebKey2020",this.controller=t.controller,this.publicKey=t.publicKey,this.privateKey=t.privateKey}t.fingerprintFromPublicKey=function(){var t=St(It.mark((function t(e){var r,n;return It.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return t.next=2,Rt.from(e);case 2:return r=t.sent,n=r.publicKey,t.abrupt("return",Ft(n));case 5:case"end":return t.stop()}}),t)})));return function(e){return t.apply(this,arguments)}}(),t.fromFingerprint=function(){var t=St(It.mark((function t(e){var r,n,i,o;return It.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:if(r=e.fingerprint,236!==(n=Nt.decode(r.substring(1)))[0]||1!==n[1]){t.next=12;break}return t.next=5,Rt.from({id:"",controller:"",type:"X25519KeyAgreementKey2019",publicKeyBase58:Nt.encode(n.slice(2))});case 5:return i=t.sent,t.next=8,i.fingerprint();case 8:return o=t.sent,i.id="did:key:"+o+"#"+o,i.controller="did:key:"+o,t.abrupt("return",i);case 12:throw new Error("Unsupported fingerprint type: "+r);case 13:case"end":return t.stop()}}),t)})));return function(e){return t.apply(this,arguments)}}();var e=t.prototype;return e.fingerprint=function(){var t=St(It.mark((function t(){return It.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return t.abrupt("return",Ft(this.publicKey));case 1:case"end":return t.stop()}}),t,this)})));return function(){return t.apply(this,arguments)}}(),e.export=function(){var t=St(It.mark((function t(e){return It.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:if(void 0===e&&(e={privateKey:!1,type:"JsonWebKey2020"}),!Zt[e.type]){t.next=3;break}return t.abrupt("return",Zt[e.type](this.id,this.controller,this.publicKey,e.privateKey?this.privateKey:void 0));case 3:throw new Error("Unsupported export options: "+JSON.stringify(e));case 4:case"end":return t.stop()}}),t,this)})));return function(e){return t.apply(this,arguments)}}(),e.deriveSecret=function(){var t=St(It.mark((function t(e){var r,n,i;return It.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return r=e.publicKey,t.next=3,Rt.from(r);case 3:if(n=t.sent,this.privateKey){t.next=6;break}throw new Error("No private key available for deriveSecret");case 6:return i=s.sharedKey(this.privateKey,n.publicKey,!0),t.abrupt("return",i);case 8:case"end":return t.stop()}}),t,this)})));return function(e){return t.apply(this,arguments)}}(),t}();function Ht(t,e,r,n,i,o,a){try{var c=t[o](a),s=c.value}catch(t){return void r(t)}c.done?e(s):Promise.resolve(s).then(n,i)}function qt(t){return function(){var e=this,r=arguments;return new Promise((function(n,i){var o=t.apply(e,r);function a(t){Ht(o,n,i,a,c,"next",t)}function c(t){Ht(o,n,i,a,c,"throw",t)}a(void 0)}))}}function Ct(){return Ct=Object.assign||function(t){for(var e=1;e<arguments.length;e++){var r=arguments[e];for(var n in r)Object.prototype.hasOwnProperty.call(r,n)&&(t[n]=r[n])}return t},Ct.apply(this,arguments)}Vt.generate=function(){var t=St(It.mark((function t(e){var r,n,i,o,a;return It.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return r=e.secureRandom,n=s.generateKeyPair({isAvailable:!0,randomBytes:r}),i=Ft(n.publicKey),a=(o="did:key:"+i)+"#"+i,t.abrupt("return",new Rt({id:a,type:"JsonWebKey2020",controller:o,publicKey:n.publicKey,privateKey:n.secretKey}));case 6:case"end":return t.stop()}}),t)})));return function(e){return t.apply(this,arguments)}}(),Vt.from=function(){var t=St(It.mark((function t(e){var r,n,i;return It.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return r=Gt[e.type](e),n=r.publicKey,i=r.privateKey,t.abrupt("return",new Rt({id:e.id,type:e.type,controller:e.controller,publicKey:n,privateKey:i}));case 2:case"end":return t.stop()}}),t)})));return function(e){return t.apply(this,arguments)}}(),Vt=Rt=a([Lt.staticImplements()],Vt);var $t=function(t,e){return t(e={exports:{}},e.exports),e.exports}((function(t){var e=function(t){var e,r=Object.prototype,n=r.hasOwnProperty,i="function"==typeof Symbol?Symbol:{},o=i.iterator||"@@iterator",a=i.asyncIterator||"@@asyncIterator",c=i.toStringTag||"@@toStringTag";function s(t,e,r){return Object.defineProperty(t,e,{value:r,enumerable:!0,configurable:!0,writable:!0}),t[e]}try{s({},"")}catch(t){s=function(t,e,r){return t[e]=r}}function u(t,e,r,n){var i=e&&e.prototype instanceof w?e:w,o=Object.create(i.prototype),a=new U(n||[]);return o._invoke=function(t,e,r){var n=l;return function(i,o){if(n===p)throw new Error("Generator is already running");if(n===h){if("throw"===i)throw o;return O()}for(r.method=i,r.arg=o;;){var a=r.delegate;if(a){var c=A(a,r);if(c){if(c===d)continue;return c}}if("next"===r.method)r.sent=r._sent=r.arg;else if("throw"===r.method){if(n===l)throw n=h,r.arg;r.dispatchException(r.arg)}else"return"===r.method&&r.abrupt("return",r.arg);n=p;var s=f(t,e,r);if("normal"===s.type){if(n=r.done?h:y,s.arg===d)continue;return{value:s.arg,done:r.done}}"throw"===s.type&&(n=h,r.method="throw",r.arg=s.arg)}}}(t,r,a),o}function f(t,e,r){try{return{type:"normal",arg:t.call(e,r)}}catch(t){return{type:"throw",arg:t}}}t.wrap=u;var l="suspendedStart",y="suspendedYield",p="executing",h="completed",d={};function w(){}function v(){}function g(){}var b={};b[o]=function(){return this};var m=Object.getPrototypeOf,x=m&&m(m(L([])));x&&x!==r&&n.call(x,o)&&(b=x);var K=g.prototype=w.prototype=Object.create(b);function E(t){["next","throw","return"].forEach((function(e){s(t,e,(function(t){return this._invoke(e,t)}))}))}function k(t,e){function r(i,o,a,c){var s=f(t[i],t,o);if("throw"!==s.type){var u=s.arg,l=u.value;return l&&"object"==typeof l&&n.call(l,"__await")?e.resolve(l.__await).then((function(t){r("next",t,a,c)}),(function(t){r("throw",t,a,c)})):e.resolve(l).then((function(t){u.value=t,a(u)}),(function(t){return r("throw",t,a,c)}))}c(s.arg)}var i;this._invoke=function(t,n){function o(){return new e((function(e,i){r(t,n,e,i)}))}return i=i?i.then(o,o):o()}}function A(t,r){var n=t.iterator[r.method];if(n===e){if(r.delegate=null,"throw"===r.method){if(t.iterator.return&&(r.method="return",r.arg=e,A(t,r),"throw"===r.method))return d;r.method="throw",r.arg=new TypeError("The iterator does not provide a 'throw' method")}return d}var i=f(n,t.iterator,r.arg);if("throw"===i.type)return r.method="throw",r.arg=i.arg,r.delegate=null,d;var o=i.arg;return o?o.done?(r[t.resultName]=o.value,r.next=t.nextLoc,"return"!==r.method&&(r.method="next",r.arg=e),r.delegate=null,d):o:(r.method="throw",r.arg=new TypeError("iterator result is not an object"),r.delegate=null,d)}function B(t){var e={tryLoc:t[0]};1 in t&&(e.catchLoc=t[1]),2 in t&&(e.finallyLoc=t[2],e.afterLoc=t[3]),this.tryEntries.push(e)}function P(t){var e=t.completion||{};e.type="normal",delete e.arg,t.completion=e}function U(t){this.tryEntries=[{tryLoc:"root"}],t.forEach(B,this),this.reset(!0)}function L(t){if(t){var r=t[o];if(r)return r.call(t);if("function"==typeof t.next)return t;if(!isNaN(t.length)){var i=-1,a=function r(){for(;++i<t.length;)if(n.call(t,i))return r.value=t[i],r.done=!1,r;return r.value=e,r.done=!0,r};return a.next=a}}return{next:O}}function O(){return{value:e,done:!0}}return v.prototype=K.constructor=g,g.constructor=v,v.displayName=s(g,c,"GeneratorFunction"),t.isGeneratorFunction=function(t){var e="function"==typeof t&&t.constructor;return!!e&&(e===v||"GeneratorFunction"===(e.displayName||e.name))},t.mark=function(t){return Object.setPrototypeOf?Object.setPrototypeOf(t,g):(t.__proto__=g,s(t,c,"GeneratorFunction")),t.prototype=Object.create(K),t},t.awrap=function(t){return{__await:t}},E(k.prototype),k.prototype[a]=function(){return this},t.AsyncIterator=k,t.async=function(e,r,n,i,o){void 0===o&&(o=Promise);var a=new k(u(e,r,n,i),o);return t.isGeneratorFunction(r)?a:a.next().then((function(t){return t.done?t.value:a.next()}))},E(K),s(K,c,"Generator"),K[o]=function(){return this},K.toString=function(){return"[object Generator]"},t.keys=function(t){var e=[];for(var r in t)e.push(r);return e.reverse(),function r(){for(;e.length;){var n=e.pop();if(n in t)return r.value=n,r.done=!1,r}return r.done=!0,r}},t.values=L,U.prototype={constructor:U,reset:function(t){if(this.prev=0,this.next=0,this.sent=this._sent=e,this.done=!1,this.delegate=null,this.method="next",this.arg=e,this.tryEntries.forEach(P),!t)for(var r in this)"t"===r.charAt(0)&&n.call(this,r)&&!isNaN(+r.slice(1))&&(this[r]=e)},stop:function(){this.done=!0;var t=this.tryEntries[0].completion;if("throw"===t.type)throw t.arg;return this.rval},dispatchException:function(t){if(this.done)throw t;var r=this;function i(n,i){return c.type="throw",c.arg=t,r.next=n,i&&(r.method="next",r.arg=e),!!i}for(var o=this.tryEntries.length-1;o>=0;--o){var a=this.tryEntries[o],c=a.completion;if("root"===a.tryLoc)return i("end");if(a.tryLoc<=this.prev){var s=n.call(a,"catchLoc"),u=n.call(a,"finallyLoc");if(s&&u){if(this.prev<a.catchLoc)return i(a.catchLoc,!0);if(this.prev<a.finallyLoc)return i(a.finallyLoc)}else if(s){if(this.prev<a.catchLoc)return i(a.catchLoc,!0)}else{if(!u)throw new Error("try statement without catch or finally");if(this.prev<a.finallyLoc)return i(a.finallyLoc)}}}},abrupt:function(t,e){for(var r=this.tryEntries.length-1;r>=0;--r){var i=this.tryEntries[r];if(i.tryLoc<=this.prev&&n.call(i,"finallyLoc")&&this.prev<i.finallyLoc){var o=i;break}}o&&("break"===t||"continue"===t)&&o.tryLoc<=e&&e<=o.finallyLoc&&(o=null);var a=o?o.completion:{};return a.type=t,a.arg=e,o?(this.method="next",this.next=o.finallyLoc,d):this.complete(a)},complete:function(t,e){if("throw"===t.type)throw t.arg;return"break"===t.type||"continue"===t.type?this.next=t.arg:"return"===t.type?(this.rval=this.arg=t.arg,this.method="return",this.next="end"):"normal"===t.type&&e&&(this.next=e),d},finish:function(t){for(var e=this.tryEntries.length-1;e>=0;--e){var r=this.tryEntries[e];if(r.finallyLoc===t)return this.complete(r.completion,r.afterLoc),P(r),d}},catch:function(t){for(var e=this.tryEntries.length-1;e>=0;--e){var r=this.tryEntries[e];if(r.tryLoc===t){var n=r.completion;if("throw"===n.type){var i=n.arg;P(r)}return i}}throw new Error("illegal catch attempt")},delegateYield:function(t,r,n){return this.delegate={iterator:L(t),resultName:r,nextLoc:n},"next"===this.method&&(this.arg=e),d}},t}(t.exports);try{regeneratorRuntime=e}catch(t){Function("r","regeneratorRuntime = r")(e)}}));function Xt(t){if(t.length>=255)throw new TypeError("Alphabet too long");for(var n=new Uint8Array(256),i=0;i<n.length;i++)n[i]=255;for(var o=0;o<t.length;o++){var a=t.charAt(o),c=a.charCodeAt(0);if(255!==n[c])throw new TypeError(a+" is ambiguous");n[c]=o}var s=t.length,u=t.charAt(0),f=Math.log(s)/Math.log(256),l=Math.log(256)/Math.log(s);function y(t){if("string"!=typeof t)throw new TypeError("Expected String");if(0===t.length)return e.alloc(0);var r=0;if(" "!==t[r]){for(var i=0,o=0;t[r]===u;)i++,r++;for(var a=(t.length-r)*f+1>>>0,c=new Uint8Array(a);t[r];){var l=n[t.charCodeAt(r)];if(255===l)return;for(var y=0,p=a-1;(0!==l||y<o)&&-1!==p;p--,y++)l+=s*c[p]>>>0,c[p]=l%256>>>0,l=l/256>>>0;if(0!==l)throw new Error("Non-zero carry");o=y,r++}if(" "!==t[r]){for(var h=a-o;h!==a&&0===c[h];)h++;var d=e.allocUnsafe(i+(a-h));d.fill(0,0,i);for(var w=i;h!==a;)d[w++]=c[h++];return d}}}return{encode:function(n){if((Array.isArray(n)||n instanceof Uint8Array)&&(n=e.from(n)),!r(n))throw new TypeError("Expected Buffer");if(0===n.length)return"";for(var i=0,o=0,a=0,c=n.length;a!==c&&0===n[a];)a++,i++;for(var f=(c-a)*l+1>>>0,y=new Uint8Array(f);a!==c;){for(var p=n[a],h=0,d=f-1;(0!==p||h<o)&&-1!==d;d--,h++)p+=256*y[d]>>>0,y[d]=p%s>>>0,p=p/s>>>0;if(0!==p)throw new Error("Non-zero carry");o=h,a++}for(var w=f-o;w!==f&&0===y[w];)w++;for(var v=u.repeat(i);w<f;++w)v+=t.charAt(y[w]);return v},decodeUnsafe:y,decode:function(t){var e=y(t);if(e)return e;throw new Error("Non-base"+s+" character")}}}var Dt,Yt=Xt("123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"),Qt=function(t){return e.from(t||"").toString("base64")},te=function(t){return Qt(t).replace(/\+/g,"-").replace(/\//g,"_").replace(/=+$/g,"")},ee=function(t,e){void 0===e&&(e="base58btc");var r=new Uint8Array(2+t.length);if(r[0]=237,r[1]=1,r.set(t,2),"base58btc"===e)return"z"+Yt.encode(r);if("base64url"===e)return"u"+te(r);throw new Error("Unsupported encoding: "+e)},re=function(t){return Uint8Array.from(e.from(t.x,"base64"))},ne={JsonWebKey2020:function(t){var r,n=re(t.publicKeyJwk),i=void 0;t.privateKeyJwk&&(i=(r=t.privateKeyJwk,{publicKey:re(r),privateKey:Uint8Array.from(e.concat([e.from(r.d,"base64"),e.from(r.x,"base64")]))}).privateKey);return{publicKey:n,privateKey:i}},Ed25519VerificationKey2018:function(t){var e=Yt.decode(t.publicKeyBase58),r=void 0;return t.privateKeyBase58&&(r=Uint8Array.from(Yt.decode(t.privateKeyBase58))),{publicKey:e,privateKey:r}}},ie=function(t){if(!ne[t.type])throw new Error("Cannot import from unsupported type: "+JSON.stringify(t,null,2));return ne[t.type](t)},oe={JsonWebKey2020:function(t,e,r,n){var i={kty:"OKP",crv:"Ed25519",x:te(r)},o={id:t,type:"JsonWebKey2020",controller:e,publicKeyJwk:i};return n&&(o.privateKeyJwk=Ct({},i,{d:te(n.slice(0,n.length/2))})),o},Ed25519VerificationKey2018:function(t,e,r,n){var i={id:t,type:"Ed25519VerificationKey2018",controller:e,publicKeyBase58:Yt.encode(r)};return n&&(i.privateKeyBase58=Yt.encode(n)),i}},ae={EdDsa:{__proto__:null,signer:function(t){return{sign:function(e){return qt($t.mark((function r(){var n;return $t.wrap((function(r){for(;;)switch(r.prev=r.next){case 0:return n=e.data,r.abrupt("return",c.sign(t,n));case 2:case"end":return r.stop()}}),r)})))()}}},verifier:function(t){return{verify:function(e){return qt($t.mark((function r(){var n,i,o;return $t.wrap((function(r){for(;;)switch(r.prev=r.next){case 0:n=e.data,i=e.signature,o=!1;try{o=c.verify(t,n,i)}catch(t){}return r.abrupt("return",o);case 4:case"end":return r.stop()}}),r)})))()}}}}},ce=Dt=function(){function t(t){this.type="JsonWebKey2020",this.id=t.id,this.type=t.type||"JsonWebKey2020",this.controller=t.controller,this.publicKey=t.publicKey,this.privateKey=t.privateKey}t.fingerprintFromPublicKey=function(){var t=qt($t.mark((function t(e){var r,n;return $t.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return t.next=2,Dt.from(e);case 2:return r=t.sent,n=r.publicKey,t.abrupt("return",ee(n));case 5:case"end":return t.stop()}}),t)})));return function(e){return t.apply(this,arguments)}}(),t.toX25519KeyPair=function(){var t=qt($t.mark((function t(e){var r,n,i;return $t.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return r=c.convertPublicKeyToX25519(e.publicKey),n=void 0,e.privateKey&&(n=c.convertSecretKeyToX25519(e.privateKey)),i=new Vt({id:"",type:"X25519KeyAgreementKey2019",controller:e.controller,publicKey:r,privateKey:n}),t.t0=e.controller+"#",t.next=7,i.fingerprint();case 7:return t.t1=t.sent,i.id=t.t0+t.t1,t.abrupt("return",i);case 10:case"end":return t.stop()}}),t)})));return function(e){return t.apply(this,arguments)}}(),t.fromFingerprint=function(){var t=qt($t.mark((function t(e){var r,n,i,o;return $t.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:if(r=e.fingerprint,237!==(n=Yt.decode(r.substring(1)))[0]||1!==n[1]){t.next=12;break}return t.next=5,Dt.from({id:"",controller:"",type:"Ed25519VerificationKey2018",publicKeyBase58:Yt.encode(n.slice(2))});case 5:return i=t.sent,t.next=8,i.fingerprint();case 8:return o=t.sent,i.id="did:key:"+o+"#"+o,i.controller="did:key:"+o,t.abrupt("return",i);case 12:throw new Error("Unsupported fingerprint type: "+r);case 13:case"end":return t.stop()}}),t)})));return function(e){return t.apply(this,arguments)}}();var e=t.prototype;return e.fingerprint=function(){var t=qt($t.mark((function t(){return $t.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return t.abrupt("return",ee(this.publicKey));case 1:case"end":return t.stop()}}),t,this)})));return function(){return t.apply(this,arguments)}}(),e.export=function(){var t=qt($t.mark((function t(e){return $t.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:if(void 0===e&&(e={privateKey:!1,type:"JsonWebKey2020"}),!oe[e.type]){t.next=3;break}return t.abrupt("return",oe[e.type](this.id,this.controller,this.publicKey,e.privateKey?this.privateKey:void 0));case 3:throw new Error("Unsupported export options: "+JSON.stringify(e));case 4:case"end":return t.stop()}}),t,this)})));return function(e){return t.apply(this,arguments)}}(),e.signer=function(t){if(void 0===t&&(t="EdDsa"),!this.privateKey)throw new Error("No private key to sign with.");if(ae[t])return ae[t].signer(this.privateKey);throw new Error("Unsupported suite type "+t)},e.verifier=function(t){if(void 0===t&&(t="EdDsa"),!this.publicKey)throw new Error("No public key to verify with.");if(ae[t])return ae[t].verifier(this.publicKey);throw new Error("Unsupported suite type "+t)},e.getDerivedKeyPairs=function(){var t=qt($t.mark((function t(){return $t.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return t.t0=this,t.next=3,Dt.toX25519KeyPair(this);case 3:return t.t1=t.sent,t.abrupt("return",[t.t0,t.t1]);case 5:case"end":return t.stop()}}),t,this)})));return function(){return t.apply(this,arguments)}}(),t}();ce.generate=function(){var t=qt($t.mark((function t(e){var r,n,i,o,a;return $t.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return r=e.secureRandom,n=c.generateKeyPair({isAvailable:!0,randomBytes:r}),i=ee(n.publicKey),a=(o="did:key:"+i)+"#"+i,t.abrupt("return",new Dt({id:a,type:"JsonWebKey2020",controller:o,publicKey:n.publicKey,privateKey:n.secretKey}));case 6:case"end":return t.stop()}}),t)})));return function(e){return t.apply(this,arguments)}}(),ce.from=function(){var t=qt($t.mark((function t(e){var r,n,i;return $t.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return r=ie(e),n=r.publicKey,i=r.privateKey,t.abrupt("return",new Dt({id:e.id,type:e.type,controller:e.controller,publicKey:n,privateKey:i}));case 2:case"end":return t.stop()}}),t)})));return function(e){return t.apply(this,arguments)}}(),ce=Dt=a([Bt.staticImplements()],ce);export{ce as E,vt as f,X as g,D as s,Y as v};
|
|
25
|
+
*/({document:t,contextUrl:r}))throw new Error(`Context not supported "${t["@context"]}".`);return n({keyPair:t})}async function vt(t){let e={...t};if("Multikey"!==e.type){if(e.publicKeyJwk){let t,r;return"JsonWebKey"!==e.type&&"JsonWebKey2020"!==e.type||({id:t,controller:r}=e),async function({jwk:t,secretKey:e=!1,id:r,controller:n}={}){const i={"@context":at,type:"Multikey",publicKeyMultibase:pt({jwk:t})};"string"==typeof r&&(i.id=r);"string"==typeof n&&(i.controller=n);e&&t.d&&(i.secretKeyMultibase=ht({jwk:t}));return vt(i)}({jwk:e.publicKeyJwk,secretKey:!1,id:t,controller:r})}if(e.type)return e=await wt({keyPair:e}),gt({keyPair:e})}return e.type||(e.type="Multikey"),e["@context"]||(e["@context"]=at),function(t){if(!t||"object"!=typeof t)throw new TypeError('"key" must be an object.');if("Multikey"!==t.type)throw new Error('"key" must be a Multikey with type "Multikey".');if(!(t["@context"]===at||Array.isArray(t["@context"])&&t["@context"].includes(at)))throw new TypeError(`"key" must be a Multikey with context "${at}".`)}(e),gt({keyPair:e})}async function gt({keyPair:t}){return t.publicKey||(t=await yt(t)),t={...t,async export({publicKey:e=!0,secretKey:r=!1,includeContext:n=!0,raw:i=!1,canonicalize:o=!1}={}){if(i){const{publicKey:e,secretKey:r}=t,n={};return e&&(n.publicKey=e.slice()),r&&(o&&r.length>st?n.secretKey=r.subarray(0,st).slice():n.secretKey=r),n}return lt({keyPair:t,publicKey:e,secretKey:r,includeContext:n,canonicalize:o})},signer(){const{id:e,secretKey:r}=t;return rt({id:e,secretKey:r})},verifier(){const{id:e,publicKey:r}=t;return nt({id:e,publicKey:r})}}}var bt,mt,xt={exports:{}},Kt={};var Et,kt,At,Bt=(mt||(mt=1,xt.exports=(bt||(bt=1,Et=Kt,Object.defineProperty(Et,"__esModule",{value:!0}),Et.staticImplements=function(){return function(t){}}),Kt)),xt.exports),Pt={exports:{}},Ut={};var Ot=(At||(At=1,Pt.exports=(kt||(kt=1,function(t){Object.defineProperty(t,"__esModule",{value:!0}),t.staticImplements=function(){return function(t){}}}(Ut)),Ut)),Pt.exports);function Lt(t,e,r,n,i,o,a){try{var c=t[o](a),s=c.value}catch(t){return void r(t)}c.done?e(s):Promise.resolve(s).then(n,i)}function St(t){return function(){var e=this,r=arguments;return new Promise((function(n,i){var o=t.apply(e,r);function a(t){Lt(o,n,i,a,c,"next",t)}function c(t){Lt(o,n,i,a,c,"throw",t)}a(void 0)}))}}function jt(){return jt=Object.assign||function(t){for(var e=1;e<arguments.length;e++){var r=arguments[e];for(var n in r)Object.prototype.hasOwnProperty.call(r,n)&&(t[n]=r[n])}return t},jt.apply(this,arguments)}var _t,Mt,It=(_t=function(t){var e=function(t){var e,r=Object.prototype,n=r.hasOwnProperty,i="function"==typeof Symbol?Symbol:{},o=i.iterator||"@@iterator",a=i.asyncIterator||"@@asyncIterator",c=i.toStringTag||"@@toStringTag";function s(t,e,r){return Object.defineProperty(t,e,{value:r,enumerable:!0,configurable:!0,writable:!0}),t[e]}try{s({},"")}catch(t){s=function(t,e,r){return t[e]=r}}function u(t,e,r,n){var i=e&&e.prototype instanceof w?e:w,o=Object.create(i.prototype),a=new U(n||[]);return o._invoke=function(t,e,r){var n=l;return function(i,o){if(n===p)throw new Error("Generator is already running");if(n===h){if("throw"===i)throw o;return L()}for(r.method=i,r.arg=o;;){var a=r.delegate;if(a){var c=A(a,r);if(c){if(c===d)continue;return c}}if("next"===r.method)r.sent=r._sent=r.arg;else if("throw"===r.method){if(n===l)throw n=h,r.arg;r.dispatchException(r.arg)}else"return"===r.method&&r.abrupt("return",r.arg);n=p;var s=f(t,e,r);if("normal"===s.type){if(n=r.done?h:y,s.arg===d)continue;return{value:s.arg,done:r.done}}"throw"===s.type&&(n=h,r.method="throw",r.arg=s.arg)}}}(t,r,a),o}function f(t,e,r){try{return{type:"normal",arg:t.call(e,r)}}catch(t){return{type:"throw",arg:t}}}t.wrap=u;var l="suspendedStart",y="suspendedYield",p="executing",h="completed",d={};function w(){}function v(){}function g(){}var b={};b[o]=function(){return this};var m=Object.getPrototypeOf,x=m&&m(m(O([])));x&&x!==r&&n.call(x,o)&&(b=x);var K=g.prototype=w.prototype=Object.create(b);function E(t){["next","throw","return"].forEach((function(e){s(t,e,(function(t){return this._invoke(e,t)}))}))}function k(t,e){function r(i,o,a,c){var s=f(t[i],t,o);if("throw"!==s.type){var u=s.arg,l=u.value;return l&&"object"==typeof l&&n.call(l,"__await")?e.resolve(l.__await).then((function(t){r("next",t,a,c)}),(function(t){r("throw",t,a,c)})):e.resolve(l).then((function(t){u.value=t,a(u)}),(function(t){return r("throw",t,a,c)}))}c(s.arg)}var i;this._invoke=function(t,n){function o(){return new e((function(e,i){r(t,n,e,i)}))}return i=i?i.then(o,o):o()}}function A(t,r){var n=t.iterator[r.method];if(n===e){if(r.delegate=null,"throw"===r.method){if(t.iterator.return&&(r.method="return",r.arg=e,A(t,r),"throw"===r.method))return d;r.method="throw",r.arg=new TypeError("The iterator does not provide a 'throw' method")}return d}var i=f(n,t.iterator,r.arg);if("throw"===i.type)return r.method="throw",r.arg=i.arg,r.delegate=null,d;var o=i.arg;return o?o.done?(r[t.resultName]=o.value,r.next=t.nextLoc,"return"!==r.method&&(r.method="next",r.arg=e),r.delegate=null,d):o:(r.method="throw",r.arg=new TypeError("iterator result is not an object"),r.delegate=null,d)}function B(t){var e={tryLoc:t[0]};1 in t&&(e.catchLoc=t[1]),2 in t&&(e.finallyLoc=t[2],e.afterLoc=t[3]),this.tryEntries.push(e)}function P(t){var e=t.completion||{};e.type="normal",delete e.arg,t.completion=e}function U(t){this.tryEntries=[{tryLoc:"root"}],t.forEach(B,this),this.reset(!0)}function O(t){if(t){var r=t[o];if(r)return r.call(t);if("function"==typeof t.next)return t;if(!isNaN(t.length)){var i=-1,a=function r(){for(;++i<t.length;)if(n.call(t,i))return r.value=t[i],r.done=!1,r;return r.value=e,r.done=!0,r};return a.next=a}}return{next:L}}function L(){return{value:e,done:!0}}return v.prototype=K.constructor=g,g.constructor=v,v.displayName=s(g,c,"GeneratorFunction"),t.isGeneratorFunction=function(t){var e="function"==typeof t&&t.constructor;return!!e&&(e===v||"GeneratorFunction"===(e.displayName||e.name))},t.mark=function(t){return Object.setPrototypeOf?Object.setPrototypeOf(t,g):(t.__proto__=g,s(t,c,"GeneratorFunction")),t.prototype=Object.create(K),t},t.awrap=function(t){return{__await:t}},E(k.prototype),k.prototype[a]=function(){return this},t.AsyncIterator=k,t.async=function(e,r,n,i,o){void 0===o&&(o=Promise);var a=new k(u(e,r,n,i),o);return t.isGeneratorFunction(r)?a:a.next().then((function(t){return t.done?t.value:a.next()}))},E(K),s(K,c,"Generator"),K[o]=function(){return this},K.toString=function(){return"[object Generator]"},t.keys=function(t){var e=[];for(var r in t)e.push(r);return e.reverse(),function r(){for(;e.length;){var n=e.pop();if(n in t)return r.value=n,r.done=!1,r}return r.done=!0,r}},t.values=O,U.prototype={constructor:U,reset:function(t){if(this.prev=0,this.next=0,this.sent=this._sent=e,this.done=!1,this.delegate=null,this.method="next",this.arg=e,this.tryEntries.forEach(P),!t)for(var r in this)"t"===r.charAt(0)&&n.call(this,r)&&!isNaN(+r.slice(1))&&(this[r]=e)},stop:function(){this.done=!0;var t=this.tryEntries[0].completion;if("throw"===t.type)throw t.arg;return this.rval},dispatchException:function(t){if(this.done)throw t;var r=this;function i(n,i){return c.type="throw",c.arg=t,r.next=n,i&&(r.method="next",r.arg=e),!!i}for(var o=this.tryEntries.length-1;o>=0;--o){var a=this.tryEntries[o],c=a.completion;if("root"===a.tryLoc)return i("end");if(a.tryLoc<=this.prev){var s=n.call(a,"catchLoc"),u=n.call(a,"finallyLoc");if(s&&u){if(this.prev<a.catchLoc)return i(a.catchLoc,!0);if(this.prev<a.finallyLoc)return i(a.finallyLoc)}else if(s){if(this.prev<a.catchLoc)return i(a.catchLoc,!0)}else{if(!u)throw new Error("try statement without catch or finally");if(this.prev<a.finallyLoc)return i(a.finallyLoc)}}}},abrupt:function(t,e){for(var r=this.tryEntries.length-1;r>=0;--r){var i=this.tryEntries[r];if(i.tryLoc<=this.prev&&n.call(i,"finallyLoc")&&this.prev<i.finallyLoc){var o=i;break}}o&&("break"===t||"continue"===t)&&o.tryLoc<=e&&e<=o.finallyLoc&&(o=null);var a=o?o.completion:{};return a.type=t,a.arg=e,o?(this.method="next",this.next=o.finallyLoc,d):this.complete(a)},complete:function(t,e){if("throw"===t.type)throw t.arg;return"break"===t.type||"continue"===t.type?this.next=t.arg:"return"===t.type?(this.rval=this.arg=t.arg,this.method="return",this.next="end"):"normal"===t.type&&e&&(this.next=e),d},finish:function(t){for(var e=this.tryEntries.length-1;e>=0;--e){var r=this.tryEntries[e];if(r.finallyLoc===t)return this.complete(r.completion,r.afterLoc),P(r),d}},catch:function(t){for(var e=this.tryEntries.length-1;e>=0;--e){var r=this.tryEntries[e];if(r.tryLoc===t){var n=r.completion;if("throw"===n.type){var i=n.arg;P(r)}return i}}throw new Error("illegal catch attempt")},delegateYield:function(t,r,n){return this.delegate={iterator:O(t),resultName:r,nextLoc:n},"next"===this.method&&(this.arg=e),d}},t}(t.exports);try{regeneratorRuntime=e}catch(t){Function("r","regeneratorRuntime = r")(e)}},_t(Mt={exports:{}},Mt.exports),Mt.exports);function Tt(t){if(t.length>=255)throw new TypeError("Alphabet too long");for(var n=new Uint8Array(256),i=0;i<n.length;i++)n[i]=255;for(var o=0;o<t.length;o++){var a=t.charAt(o),c=a.charCodeAt(0);if(255!==n[c])throw new TypeError(a+" is ambiguous");n[c]=o}var s=t.length,u=t.charAt(0),f=Math.log(s)/Math.log(256),l=Math.log(256)/Math.log(s);function y(t){if("string"!=typeof t)throw new TypeError("Expected String");if(0===t.length)return e.alloc(0);var r=0;if(" "!==t[r]){for(var i=0,o=0;t[r]===u;)i++,r++;for(var a=(t.length-r)*f+1>>>0,c=new Uint8Array(a);t[r];){var l=n[t.charCodeAt(r)];if(255===l)return;for(var y=0,p=a-1;(0!==l||y<o)&&-1!==p;p--,y++)l+=s*c[p]>>>0,c[p]=l%256>>>0,l=l/256>>>0;if(0!==l)throw new Error("Non-zero carry");o=y,r++}if(" "!==t[r]){for(var h=a-o;h!==a&&0===c[h];)h++;var d=e.allocUnsafe(i+(a-h));d.fill(0,0,i);for(var w=i;h!==a;)d[w++]=c[h++];return d}}}return{encode:function(n){if((Array.isArray(n)||n instanceof Uint8Array)&&(n=e.from(n)),!r(n))throw new TypeError("Expected Buffer");if(0===n.length)return"";for(var i=0,o=0,a=0,c=n.length;a!==c&&0===n[a];)a++,i++;for(var f=(c-a)*l+1>>>0,y=new Uint8Array(f);a!==c;){for(var p=n[a],h=0,d=f-1;(0!==p||h<o)&&-1!==d;d--,h++)p+=256*y[d]>>>0,y[d]=p%s>>>0,p=p/s>>>0;if(0!==p)throw new Error("Non-zero carry");o=h,a++}for(var w=f-o;w!==f&&0===y[w];)w++;for(var v=u.repeat(i);w<f;++w)v+=t.charAt(y[w]);return v},decodeUnsafe:y,decode:function(t){var e=y(t);if(e)return e;throw new Error("Non-base"+s+" character")}}}var Rt,Nt=Tt("123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"),zt=function(t){return e.from(t||"").toString("base64")},Jt=function(t){return zt(t).replace(/\+/g,"-").replace(/\//g,"_").replace(/=+$/g,"")},Ft=function(t,e){void 0===e&&(e="base58btc");var r=new Uint8Array(2+t.length);if(r[0]=236,r[1]=1,r.set(t,2),"base58btc"===e)return"z"+Nt.encode(r);if("base64url"===e)return"u"+Jt(r);throw new Error("Unsupported encoding: "+e)},Wt=function(t){return Uint8Array.from(e.from(t.x,"base64"))},Gt={JsonWebKey2020:function(t){var r,n=Wt(t.publicKeyJwk),i=void 0;t.privateKeyJwk&&(i=(r=t.privateKeyJwk,{publicKey:Wt(r),privateKey:Uint8Array.from(e.from(r.d,"base64"))}).privateKey);return{publicKey:n,privateKey:i}},X25519KeyAgreementKey2019:function(t){var e=Nt.decode(t.publicKeyBase58),r=void 0;return t.privateKeyBase58&&(r=Uint8Array.from(Nt.decode(t.privateKeyBase58))),{publicKey:e,privateKey:r}}},Zt={JsonWebKey2020:function(t,e,r,n){var i={kty:"OKP",crv:"X25519",x:Jt(r)},o={id:t,type:"JsonWebKey2020",controller:e,publicKeyJwk:i};return n&&(o.privateKeyJwk=jt({},i,{d:Jt(n)})),o},X25519KeyAgreementKey2019:function(t,e,r,n){var i={id:t,type:"X25519KeyAgreementKey2019",controller:e,publicKeyBase58:Nt.encode(r)};return n&&(i.privateKeyBase58=Nt.encode(n)),i}},Vt=Rt=function(){function t(t){this.type="JsonWebKey2020",this.id=t.id,this.type=t.type||"JsonWebKey2020",this.controller=t.controller,this.publicKey=t.publicKey,this.privateKey=t.privateKey}t.fingerprintFromPublicKey=function(){var t=St(It.mark((function t(e){var r,n;return It.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return t.next=2,Rt.from(e);case 2:return r=t.sent,n=r.publicKey,t.abrupt("return",Ft(n));case 5:case"end":return t.stop()}}),t)})));return function(e){return t.apply(this,arguments)}}(),t.fromFingerprint=function(){var t=St(It.mark((function t(e){var r,n,i,o;return It.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:if(r=e.fingerprint,236!==(n=Nt.decode(r.substring(1)))[0]||1!==n[1]){t.next=12;break}return t.next=5,Rt.from({id:"",controller:"",type:"X25519KeyAgreementKey2019",publicKeyBase58:Nt.encode(n.slice(2))});case 5:return i=t.sent,t.next=8,i.fingerprint();case 8:return o=t.sent,i.id="did:key:"+o+"#"+o,i.controller="did:key:"+o,t.abrupt("return",i);case 12:throw new Error("Unsupported fingerprint type: "+r);case 13:case"end":return t.stop()}}),t)})));return function(e){return t.apply(this,arguments)}}();var e=t.prototype;return e.fingerprint=function(){var t=St(It.mark((function t(){return It.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return t.abrupt("return",Ft(this.publicKey));case 1:case"end":return t.stop()}}),t,this)})));return function(){return t.apply(this,arguments)}}(),e.export=function(){var t=St(It.mark((function t(e){return It.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:if(void 0===e&&(e={privateKey:!1,type:"JsonWebKey2020"}),!Zt[e.type]){t.next=3;break}return t.abrupt("return",Zt[e.type](this.id,this.controller,this.publicKey,e.privateKey?this.privateKey:void 0));case 3:throw new Error("Unsupported export options: "+JSON.stringify(e));case 4:case"end":return t.stop()}}),t,this)})));return function(e){return t.apply(this,arguments)}}(),e.deriveSecret=function(){var t=St(It.mark((function t(e){var r,n,i;return It.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return r=e.publicKey,t.next=3,Rt.from(r);case 3:if(n=t.sent,this.privateKey){t.next=6;break}throw new Error("No private key available for deriveSecret");case 6:return i=s.sharedKey(this.privateKey,n.publicKey,!0),t.abrupt("return",i);case 8:case"end":return t.stop()}}),t,this)})));return function(e){return t.apply(this,arguments)}}(),t}();function Ht(t,e,r,n,i,o,a){try{var c=t[o](a),s=c.value}catch(t){return void r(t)}c.done?e(s):Promise.resolve(s).then(n,i)}function qt(t){return function(){var e=this,r=arguments;return new Promise((function(n,i){var o=t.apply(e,r);function a(t){Ht(o,n,i,a,c,"next",t)}function c(t){Ht(o,n,i,a,c,"throw",t)}a(void 0)}))}}function Ct(){return Ct=Object.assign||function(t){for(var e=1;e<arguments.length;e++){var r=arguments[e];for(var n in r)Object.prototype.hasOwnProperty.call(r,n)&&(t[n]=r[n])}return t},Ct.apply(this,arguments)}Vt.generate=function(){var t=St(It.mark((function t(e){var r,n,i,o,a;return It.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return r=e.secureRandom,n=s.generateKeyPair({isAvailable:!0,randomBytes:r}),i=Ft(n.publicKey),a=(o="did:key:"+i)+"#"+i,t.abrupt("return",new Rt({id:a,type:"JsonWebKey2020",controller:o,publicKey:n.publicKey,privateKey:n.secretKey}));case 6:case"end":return t.stop()}}),t)})));return function(e){return t.apply(this,arguments)}}(),Vt.from=function(){var t=St(It.mark((function t(e){var r,n,i;return It.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return r=Gt[e.type](e),n=r.publicKey,i=r.privateKey,t.abrupt("return",new Rt({id:e.id,type:e.type,controller:e.controller,publicKey:n,privateKey:i}));case 2:case"end":return t.stop()}}),t)})));return function(e){return t.apply(this,arguments)}}(),Vt=Rt=a([Ot.staticImplements()],Vt);var $t=function(t,e){return t(e={exports:{}},e.exports),e.exports}((function(t){var e=function(t){var e,r=Object.prototype,n=r.hasOwnProperty,i="function"==typeof Symbol?Symbol:{},o=i.iterator||"@@iterator",a=i.asyncIterator||"@@asyncIterator",c=i.toStringTag||"@@toStringTag";function s(t,e,r){return Object.defineProperty(t,e,{value:r,enumerable:!0,configurable:!0,writable:!0}),t[e]}try{s({},"")}catch(t){s=function(t,e,r){return t[e]=r}}function u(t,e,r,n){var i=e&&e.prototype instanceof w?e:w,o=Object.create(i.prototype),a=new U(n||[]);return o._invoke=function(t,e,r){var n=l;return function(i,o){if(n===p)throw new Error("Generator is already running");if(n===h){if("throw"===i)throw o;return L()}for(r.method=i,r.arg=o;;){var a=r.delegate;if(a){var c=A(a,r);if(c){if(c===d)continue;return c}}if("next"===r.method)r.sent=r._sent=r.arg;else if("throw"===r.method){if(n===l)throw n=h,r.arg;r.dispatchException(r.arg)}else"return"===r.method&&r.abrupt("return",r.arg);n=p;var s=f(t,e,r);if("normal"===s.type){if(n=r.done?h:y,s.arg===d)continue;return{value:s.arg,done:r.done}}"throw"===s.type&&(n=h,r.method="throw",r.arg=s.arg)}}}(t,r,a),o}function f(t,e,r){try{return{type:"normal",arg:t.call(e,r)}}catch(t){return{type:"throw",arg:t}}}t.wrap=u;var l="suspendedStart",y="suspendedYield",p="executing",h="completed",d={};function w(){}function v(){}function g(){}var b={};b[o]=function(){return this};var m=Object.getPrototypeOf,x=m&&m(m(O([])));x&&x!==r&&n.call(x,o)&&(b=x);var K=g.prototype=w.prototype=Object.create(b);function E(t){["next","throw","return"].forEach((function(e){s(t,e,(function(t){return this._invoke(e,t)}))}))}function k(t,e){function r(i,o,a,c){var s=f(t[i],t,o);if("throw"!==s.type){var u=s.arg,l=u.value;return l&&"object"==typeof l&&n.call(l,"__await")?e.resolve(l.__await).then((function(t){r("next",t,a,c)}),(function(t){r("throw",t,a,c)})):e.resolve(l).then((function(t){u.value=t,a(u)}),(function(t){return r("throw",t,a,c)}))}c(s.arg)}var i;this._invoke=function(t,n){function o(){return new e((function(e,i){r(t,n,e,i)}))}return i=i?i.then(o,o):o()}}function A(t,r){var n=t.iterator[r.method];if(n===e){if(r.delegate=null,"throw"===r.method){if(t.iterator.return&&(r.method="return",r.arg=e,A(t,r),"throw"===r.method))return d;r.method="throw",r.arg=new TypeError("The iterator does not provide a 'throw' method")}return d}var i=f(n,t.iterator,r.arg);if("throw"===i.type)return r.method="throw",r.arg=i.arg,r.delegate=null,d;var o=i.arg;return o?o.done?(r[t.resultName]=o.value,r.next=t.nextLoc,"return"!==r.method&&(r.method="next",r.arg=e),r.delegate=null,d):o:(r.method="throw",r.arg=new TypeError("iterator result is not an object"),r.delegate=null,d)}function B(t){var e={tryLoc:t[0]};1 in t&&(e.catchLoc=t[1]),2 in t&&(e.finallyLoc=t[2],e.afterLoc=t[3]),this.tryEntries.push(e)}function P(t){var e=t.completion||{};e.type="normal",delete e.arg,t.completion=e}function U(t){this.tryEntries=[{tryLoc:"root"}],t.forEach(B,this),this.reset(!0)}function O(t){if(t){var r=t[o];if(r)return r.call(t);if("function"==typeof t.next)return t;if(!isNaN(t.length)){var i=-1,a=function r(){for(;++i<t.length;)if(n.call(t,i))return r.value=t[i],r.done=!1,r;return r.value=e,r.done=!0,r};return a.next=a}}return{next:L}}function L(){return{value:e,done:!0}}return v.prototype=K.constructor=g,g.constructor=v,v.displayName=s(g,c,"GeneratorFunction"),t.isGeneratorFunction=function(t){var e="function"==typeof t&&t.constructor;return!!e&&(e===v||"GeneratorFunction"===(e.displayName||e.name))},t.mark=function(t){return Object.setPrototypeOf?Object.setPrototypeOf(t,g):(t.__proto__=g,s(t,c,"GeneratorFunction")),t.prototype=Object.create(K),t},t.awrap=function(t){return{__await:t}},E(k.prototype),k.prototype[a]=function(){return this},t.AsyncIterator=k,t.async=function(e,r,n,i,o){void 0===o&&(o=Promise);var a=new k(u(e,r,n,i),o);return t.isGeneratorFunction(r)?a:a.next().then((function(t){return t.done?t.value:a.next()}))},E(K),s(K,c,"Generator"),K[o]=function(){return this},K.toString=function(){return"[object Generator]"},t.keys=function(t){var e=[];for(var r in t)e.push(r);return e.reverse(),function r(){for(;e.length;){var n=e.pop();if(n in t)return r.value=n,r.done=!1,r}return r.done=!0,r}},t.values=O,U.prototype={constructor:U,reset:function(t){if(this.prev=0,this.next=0,this.sent=this._sent=e,this.done=!1,this.delegate=null,this.method="next",this.arg=e,this.tryEntries.forEach(P),!t)for(var r in this)"t"===r.charAt(0)&&n.call(this,r)&&!isNaN(+r.slice(1))&&(this[r]=e)},stop:function(){this.done=!0;var t=this.tryEntries[0].completion;if("throw"===t.type)throw t.arg;return this.rval},dispatchException:function(t){if(this.done)throw t;var r=this;function i(n,i){return c.type="throw",c.arg=t,r.next=n,i&&(r.method="next",r.arg=e),!!i}for(var o=this.tryEntries.length-1;o>=0;--o){var a=this.tryEntries[o],c=a.completion;if("root"===a.tryLoc)return i("end");if(a.tryLoc<=this.prev){var s=n.call(a,"catchLoc"),u=n.call(a,"finallyLoc");if(s&&u){if(this.prev<a.catchLoc)return i(a.catchLoc,!0);if(this.prev<a.finallyLoc)return i(a.finallyLoc)}else if(s){if(this.prev<a.catchLoc)return i(a.catchLoc,!0)}else{if(!u)throw new Error("try statement without catch or finally");if(this.prev<a.finallyLoc)return i(a.finallyLoc)}}}},abrupt:function(t,e){for(var r=this.tryEntries.length-1;r>=0;--r){var i=this.tryEntries[r];if(i.tryLoc<=this.prev&&n.call(i,"finallyLoc")&&this.prev<i.finallyLoc){var o=i;break}}o&&("break"===t||"continue"===t)&&o.tryLoc<=e&&e<=o.finallyLoc&&(o=null);var a=o?o.completion:{};return a.type=t,a.arg=e,o?(this.method="next",this.next=o.finallyLoc,d):this.complete(a)},complete:function(t,e){if("throw"===t.type)throw t.arg;return"break"===t.type||"continue"===t.type?this.next=t.arg:"return"===t.type?(this.rval=this.arg=t.arg,this.method="return",this.next="end"):"normal"===t.type&&e&&(this.next=e),d},finish:function(t){for(var e=this.tryEntries.length-1;e>=0;--e){var r=this.tryEntries[e];if(r.finallyLoc===t)return this.complete(r.completion,r.afterLoc),P(r),d}},catch:function(t){for(var e=this.tryEntries.length-1;e>=0;--e){var r=this.tryEntries[e];if(r.tryLoc===t){var n=r.completion;if("throw"===n.type){var i=n.arg;P(r)}return i}}throw new Error("illegal catch attempt")},delegateYield:function(t,r,n){return this.delegate={iterator:O(t),resultName:r,nextLoc:n},"next"===this.method&&(this.arg=e),d}},t}(t.exports);try{regeneratorRuntime=e}catch(t){Function("r","regeneratorRuntime = r")(e)}}));function Xt(t){if(t.length>=255)throw new TypeError("Alphabet too long");for(var n=new Uint8Array(256),i=0;i<n.length;i++)n[i]=255;for(var o=0;o<t.length;o++){var a=t.charAt(o),c=a.charCodeAt(0);if(255!==n[c])throw new TypeError(a+" is ambiguous");n[c]=o}var s=t.length,u=t.charAt(0),f=Math.log(s)/Math.log(256),l=Math.log(256)/Math.log(s);function y(t){if("string"!=typeof t)throw new TypeError("Expected String");if(0===t.length)return e.alloc(0);var r=0;if(" "!==t[r]){for(var i=0,o=0;t[r]===u;)i++,r++;for(var a=(t.length-r)*f+1>>>0,c=new Uint8Array(a);t[r];){var l=n[t.charCodeAt(r)];if(255===l)return;for(var y=0,p=a-1;(0!==l||y<o)&&-1!==p;p--,y++)l+=s*c[p]>>>0,c[p]=l%256>>>0,l=l/256>>>0;if(0!==l)throw new Error("Non-zero carry");o=y,r++}if(" "!==t[r]){for(var h=a-o;h!==a&&0===c[h];)h++;var d=e.allocUnsafe(i+(a-h));d.fill(0,0,i);for(var w=i;h!==a;)d[w++]=c[h++];return d}}}return{encode:function(n){if((Array.isArray(n)||n instanceof Uint8Array)&&(n=e.from(n)),!r(n))throw new TypeError("Expected Buffer");if(0===n.length)return"";for(var i=0,o=0,a=0,c=n.length;a!==c&&0===n[a];)a++,i++;for(var f=(c-a)*l+1>>>0,y=new Uint8Array(f);a!==c;){for(var p=n[a],h=0,d=f-1;(0!==p||h<o)&&-1!==d;d--,h++)p+=256*y[d]>>>0,y[d]=p%s>>>0,p=p/s>>>0;if(0!==p)throw new Error("Non-zero carry");o=h,a++}for(var w=f-o;w!==f&&0===y[w];)w++;for(var v=u.repeat(i);w<f;++w)v+=t.charAt(y[w]);return v},decodeUnsafe:y,decode:function(t){var e=y(t);if(e)return e;throw new Error("Non-base"+s+" character")}}}var Dt,Yt=Xt("123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"),Qt=function(t){return e.from(t||"").toString("base64")},te=function(t){return Qt(t).replace(/\+/g,"-").replace(/\//g,"_").replace(/=+$/g,"")},ee=function(t,e){void 0===e&&(e="base58btc");var r=new Uint8Array(2+t.length);if(r[0]=237,r[1]=1,r.set(t,2),"base58btc"===e)return"z"+Yt.encode(r);if("base64url"===e)return"u"+te(r);throw new Error("Unsupported encoding: "+e)},re=function(t){return Uint8Array.from(e.from(t.x,"base64"))},ne={JsonWebKey2020:function(t){var r,n=re(t.publicKeyJwk),i=void 0;t.privateKeyJwk&&(i=(r=t.privateKeyJwk,{publicKey:re(r),privateKey:Uint8Array.from(e.concat([e.from(r.d,"base64"),e.from(r.x,"base64")]))}).privateKey);return{publicKey:n,privateKey:i}},Ed25519VerificationKey2018:function(t){var e=Yt.decode(t.publicKeyBase58),r=void 0;return t.privateKeyBase58&&(r=Uint8Array.from(Yt.decode(t.privateKeyBase58))),{publicKey:e,privateKey:r}}},ie=function(t){if(!ne[t.type])throw new Error("Cannot import from unsupported type: "+JSON.stringify(t,null,2));return ne[t.type](t)},oe={JsonWebKey2020:function(t,e,r,n){var i={kty:"OKP",crv:"Ed25519",x:te(r)},o={id:t,type:"JsonWebKey2020",controller:e,publicKeyJwk:i};return n&&(o.privateKeyJwk=Ct({},i,{d:te(n.slice(0,n.length/2))})),o},Ed25519VerificationKey2018:function(t,e,r,n){var i={id:t,type:"Ed25519VerificationKey2018",controller:e,publicKeyBase58:Yt.encode(r)};return n&&(i.privateKeyBase58=Yt.encode(n)),i}},ae={EdDsa:{__proto__:null,signer:function(t){return{sign:function(e){return qt($t.mark((function r(){var n;return $t.wrap((function(r){for(;;)switch(r.prev=r.next){case 0:return n=e.data,r.abrupt("return",c.sign(t,n));case 2:case"end":return r.stop()}}),r)})))()}}},verifier:function(t){return{verify:function(e){return qt($t.mark((function r(){var n,i,o;return $t.wrap((function(r){for(;;)switch(r.prev=r.next){case 0:n=e.data,i=e.signature,o=!1;try{o=c.verify(t,n,i)}catch(t){}return r.abrupt("return",o);case 4:case"end":return r.stop()}}),r)})))()}}}}},ce=Dt=function(){function t(t){this.type="JsonWebKey2020",this.id=t.id,this.type=t.type||"JsonWebKey2020",this.controller=t.controller,this.publicKey=t.publicKey,this.privateKey=t.privateKey}t.fingerprintFromPublicKey=function(){var t=qt($t.mark((function t(e){var r,n;return $t.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return t.next=2,Dt.from(e);case 2:return r=t.sent,n=r.publicKey,t.abrupt("return",ee(n));case 5:case"end":return t.stop()}}),t)})));return function(e){return t.apply(this,arguments)}}(),t.toX25519KeyPair=function(){var t=qt($t.mark((function t(e){var r,n,i;return $t.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return r=c.convertPublicKeyToX25519(e.publicKey),n=void 0,e.privateKey&&(n=c.convertSecretKeyToX25519(e.privateKey)),i=new Vt({id:"",type:"X25519KeyAgreementKey2019",controller:e.controller,publicKey:r,privateKey:n}),t.t0=e.controller+"#",t.next=7,i.fingerprint();case 7:return t.t1=t.sent,i.id=t.t0+t.t1,t.abrupt("return",i);case 10:case"end":return t.stop()}}),t)})));return function(e){return t.apply(this,arguments)}}(),t.fromFingerprint=function(){var t=qt($t.mark((function t(e){var r,n,i,o;return $t.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:if(r=e.fingerprint,237!==(n=Yt.decode(r.substring(1)))[0]||1!==n[1]){t.next=12;break}return t.next=5,Dt.from({id:"",controller:"",type:"Ed25519VerificationKey2018",publicKeyBase58:Yt.encode(n.slice(2))});case 5:return i=t.sent,t.next=8,i.fingerprint();case 8:return o=t.sent,i.id="did:key:"+o+"#"+o,i.controller="did:key:"+o,t.abrupt("return",i);case 12:throw new Error("Unsupported fingerprint type: "+r);case 13:case"end":return t.stop()}}),t)})));return function(e){return t.apply(this,arguments)}}();var e=t.prototype;return e.fingerprint=function(){var t=qt($t.mark((function t(){return $t.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return t.abrupt("return",ee(this.publicKey));case 1:case"end":return t.stop()}}),t,this)})));return function(){return t.apply(this,arguments)}}(),e.export=function(){var t=qt($t.mark((function t(e){return $t.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:if(void 0===e&&(e={privateKey:!1,type:"JsonWebKey2020"}),!oe[e.type]){t.next=3;break}return t.abrupt("return",oe[e.type](this.id,this.controller,this.publicKey,e.privateKey?this.privateKey:void 0));case 3:throw new Error("Unsupported export options: "+JSON.stringify(e));case 4:case"end":return t.stop()}}),t,this)})));return function(e){return t.apply(this,arguments)}}(),e.signer=function(t){if(void 0===t&&(t="EdDsa"),!this.privateKey)throw new Error("No private key to sign with.");if(ae[t])return ae[t].signer(this.privateKey);throw new Error("Unsupported suite type "+t)},e.verifier=function(t){if(void 0===t&&(t="EdDsa"),!this.publicKey)throw new Error("No public key to verify with.");if(ae[t])return ae[t].verifier(this.publicKey);throw new Error("Unsupported suite type "+t)},e.getDerivedKeyPairs=function(){var t=qt($t.mark((function t(){return $t.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return t.t0=this,t.next=3,Dt.toX25519KeyPair(this);case 3:return t.t1=t.sent,t.abrupt("return",[t.t0,t.t1]);case 5:case"end":return t.stop()}}),t,this)})));return function(){return t.apply(this,arguments)}}(),t}();ce.generate=function(){var t=qt($t.mark((function t(e){var r,n,i,o,a;return $t.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return r=e.secureRandom,n=c.generateKeyPair({isAvailable:!0,randomBytes:r}),i=ee(n.publicKey),a=(o="did:key:"+i)+"#"+i,t.abrupt("return",new Dt({id:a,type:"JsonWebKey2020",controller:o,publicKey:n.publicKey,privateKey:n.secretKey}));case 6:case"end":return t.stop()}}),t)})));return function(e){return t.apply(this,arguments)}}(),ce.from=function(){var t=qt($t.mark((function t(e){var r,n,i;return $t.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return r=ie(e),n=r.publicKey,i=r.privateKey,t.abrupt("return",new Dt({id:e.id,type:e.type,controller:e.controller,publicKey:n,privateKey:i}));case 2:case"end":return t.stop()}}),t)})));return function(e){return t.apply(this,arguments)}}(),ce=Dt=a([Bt.staticImplements()],ce);export{ce as E,vt as f,X as g,D as s,Y as v};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{g as e,i as t,B as r,p as n}from"./main.js";import{r as o,c as i,b as s,d as a,a as c}from"./elliptic-4aZS_cwf-BpaNaVm0.js";var u,l,f,p,d,h,y,b;function w(){if(l)return u;l=1;class e extends Error{constructor(e){super(e||"This operation is not supported for this key type")}}return u=e}function g(){if(p)return f;p=1;class e extends Error{constructor(){super("This has not been implemented yet")}}return f=e}function m(){if(b)return y;b=1;const e=g();return y=class{constructor(e){this.params=e}fromPrivatePKCS1(t){throw new e}fromPrivatePKCS8(t){throw new e}fromPublicPKCS1(t){throw new e}fromPublicPKCS8(t){throw new e}fromPrivateBlk(t){throw new e}fromPublicBlk(t){throw new e}fromJwk(t){throw new e}toPrivatePKCS1(t){throw new e}toPrivatePKCS8(t){throw new e}toPublicPKCS1(t){throw new e}toPublicPKCS8(t){throw new e}toPrivateBlk(t){throw new e}toPublicBlk(t){throw new e}toPrivateJwk(t){throw new e}toPublicJwk(t){throw new e}static formatPem(e,t){return`-----BEGIN ${t} KEY-----\n`+e.match(/.{1,64}/g).join("\n")+`\n-----END ${t} KEY-----`}}}var v,k,_={},P={},E={};function S(){if(k)return v;k=1;var e,t=c,r=t.Buffer,o={};for(e in t)t.hasOwnProperty(e)&&"SlowBuffer"!==e&&"Buffer"!==e&&(o[e]=t[e]);var i=o.Buffer={};for(e in r)r.hasOwnProperty(e)&&"allocUnsafe"!==e&&"allocUnsafeSlow"!==e&&(i[e]=r[e]);if(o.Buffer.prototype=r.prototype,i.from&&i.from!==Uint8Array.from||(i.from=function(e,t,n){if("number"==typeof e)throw new TypeError('The "value" argument must not be of type number. Received type '+typeof e);if(e&&void 0===e.length)throw new TypeError("The first argument must be one of type string, Buffer, ArrayBuffer, Array, or Array-like Object. Received type "+typeof e);return r(e,t,n)}),i.alloc||(i.alloc=function(e,t,n){if("number"!=typeof e)throw new TypeError('The "size" argument must be of type number. Received type '+typeof e);if(e<0||e>=2*(1<<30))throw new RangeError('The value "'+e+'" is invalid for option "size"');var o=r(e);return t&&0!==t.length?"string"==typeof n?o.fill(t,n):o.fill(t):o.fill(0),o}),!o.kStringMaxLength)try{o.kStringMaxLength=n.binding("buffer").kStringMaxLength}catch(e){}return o.constants||(o.constants={MAX_LENGTH:o.kMaxLength},o.kStringMaxLength&&(o.constants.MAX_STRING_LENGTH=o.kStringMaxLength)),v=o}var K,A={};function x(){if(K)return A;K=1;const e=s();function t(e){this._reporterState={obj:null,path:[],options:e||{},errors:[]}}function r(e,t){this.path=e,this.rethrow(t)}return A.Reporter=t,t.prototype.isError=function(e){return e instanceof r},t.prototype.save=function(){const e=this._reporterState;return{obj:e.obj,pathLen:e.path.length}},t.prototype.restore=function(e){const t=this._reporterState;t.obj=e.obj,t.path=t.path.slice(0,e.pathLen)},t.prototype.enterKey=function(e){return this._reporterState.path.push(e)},t.prototype.exitKey=function(e){const t=this._reporterState;t.path=t.path.slice(0,e-1)},t.prototype.leaveKey=function(e,t,r){const n=this._reporterState;this.exitKey(e),null!==n.obj&&(n.obj[t]=r)},t.prototype.path=function(){return this._reporterState.path.join("/")},t.prototype.enterObject=function(){const e=this._reporterState,t=e.obj;return e.obj={},t},t.prototype.leaveObject=function(e){const t=this._reporterState,r=t.obj;return t.obj=e,r},t.prototype.error=function(e){let t;const n=this._reporterState,o=e instanceof r;if(t=o?e:new r(n.path.map((function(e){return"["+JSON.stringify(e)+"]"})).join(""),e.message||e,e.stack),!n.options.partial)throw t;return o||n.errors.push(t),t},t.prototype.wrapResult=function(e){const t=this._reporterState;return t.options.partial?{result:this.isError(e)?null:e,errors:t.errors}:e},e(r,Error),r.prototype.rethrow=function(e){if(this.message=e+" at: "+(this.path||"(shallow)"),Error.captureStackTrace&&Error.captureStackTrace(this,r),!this.stack)try{throw new Error(this.message)}catch(e){this.stack=e.stack}return this},A}var C,j,B,I={};function U(){if(C)return I;C=1;const e=s(),t=x().Reporter,r=S().Buffer;function n(e,n){t.call(this,n),r.isBuffer(e)?(this.base=e,this.offset=0,this.length=e.length):this.error("Input not Buffer")}function o(e,t){if(Array.isArray(e))this.length=0,this.value=e.map((function(e){return o.isEncoderBuffer(e)||(e=new o(e,t)),this.length+=e.length,e}),this);else if("number"==typeof e){if(!(0<=e&&e<=255))return t.error("non-byte EncoderBuffer value");this.value=e,this.length=1}else if("string"==typeof e)this.value=e,this.length=r.byteLength(e);else{if(!r.isBuffer(e))return t.error("Unsupported type: "+typeof e);this.value=e,this.length=e.length}}return e(n,t),I.DecoderBuffer=n,n.isDecoderBuffer=function(e){if(e instanceof n)return!0;return"object"==typeof e&&r.isBuffer(e.base)&&"DecoderBuffer"===e.constructor.name&&"number"==typeof e.offset&&"number"==typeof e.length&&"function"==typeof e.save&&"function"==typeof e.restore&&"function"==typeof e.isEmpty&&"function"==typeof e.readUInt8&&"function"==typeof e.skip&&"function"==typeof e.raw},n.prototype.save=function(){return{offset:this.offset,reporter:t.prototype.save.call(this)}},n.prototype.restore=function(e){const r=new n(this.base);return r.offset=e.offset,r.length=this.offset,this.offset=e.offset,t.prototype.restore.call(this,e.reporter),r},n.prototype.isEmpty=function(){return this.offset===this.length},n.prototype.readUInt8=function(e){return this.offset+1<=this.length?this.base.readUInt8(this.offset++,!0):this.error(e||"DecoderBuffer overrun")},n.prototype.skip=function(e,t){if(!(this.offset+e<=this.length))return this.error(t||"DecoderBuffer overrun");const r=new n(this.base);return r._reporterState=this._reporterState,r.offset=this.offset,r.length=this.offset+e,this.offset+=e,r},n.prototype.raw=function(e){return this.base.slice(e?e.offset:this.offset,this.length)},I.EncoderBuffer=o,o.isEncoderBuffer=function(e){if(e instanceof o)return!0;return"object"==typeof e&&"EncoderBuffer"===e.constructor.name&&"number"==typeof e.length&&"function"==typeof e.join},o.prototype.join=function(e,t){return e||(e=r.alloc(this.length)),t||(t=0),0===this.length||(Array.isArray(this.value)?this.value.forEach((function(r){r.join(e,t),t+=r.length})):("number"==typeof this.value?e[t]=this.value:"string"==typeof this.value?e.write(this.value,t):r.isBuffer(this.value)&&this.value.copy(e,t),t+=this.length)),e},I}function q(){if(B)return j;B=1;const e=x().Reporter,t=U().EncoderBuffer,r=U().DecoderBuffer,n=a(),o=["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"],i=["key","obj","use","optional","explicit","implicit","def","choice","any","contains"].concat(o);function s(e,t,r){const n={};this._baseState=n,n.name=r,n.enc=e,n.parent=t||null,n.children=null,n.tag=null,n.args=null,n.reverseArgs=null,n.choice=null,n.optional=!1,n.any=!1,n.obj=!1,n.use=null,n.useDecoder=null,n.key=null,n.default=null,n.explicit=null,n.implicit=null,n.contains=null,n.parent||(n.children=[],this._wrap())}j=s;const c=["enc","parent","children","tag","args","reverseArgs","choice","optional","any","obj","use","alteredUse","key","default","explicit","implicit","contains"];return s.prototype.clone=function(){const e=this._baseState,t={};c.forEach((function(r){t[r]=e[r]}));const r=new this.constructor(t.parent);return r._baseState=t,r},s.prototype._wrap=function(){const e=this._baseState;i.forEach((function(t){this[t]=function(){const r=new this.constructor(this);return e.children.push(r),r[t].apply(r,arguments)}}),this)},s.prototype._init=function(e){const t=this._baseState;n(null===t.parent),e.call(this),t.children=t.children.filter((function(e){return e._baseState.parent===this}),this),n.equal(t.children.length,1,"Root node can have only one child")},s.prototype._useArgs=function(e){const t=this._baseState,r=e.filter((function(e){return e instanceof this.constructor}),this);e=e.filter((function(e){return!(e instanceof this.constructor)}),this),0!==r.length&&(n(null===t.children),t.children=r,r.forEach((function(e){e._baseState.parent=this}),this)),0!==e.length&&(n(null===t.args),t.args=e,t.reverseArgs=e.map((function(e){if("object"!=typeof e||e.constructor!==Object)return e;const t={};return Object.keys(e).forEach((function(r){r==(0|r)&&(r|=0);const n=e[r];t[n]=r})),t})))},["_peekTag","_decodeTag","_use","_decodeStr","_decodeObjid","_decodeTime","_decodeNull","_decodeInt","_decodeBool","_decodeList","_encodeComposite","_encodeStr","_encodeObjid","_encodeTime","_encodeNull","_encodeInt","_encodeBool"].forEach((function(e){s.prototype[e]=function(){const t=this._baseState;throw new Error(e+" not implemented for encoding: "+t.enc)}})),o.forEach((function(e){s.prototype[e]=function(){const t=this._baseState,r=Array.prototype.slice.call(arguments);return n(null===t.tag),t.tag=e,this._useArgs(r),this}})),s.prototype.use=function(e){n(e);const t=this._baseState;return n(null===t.use),t.use=e,this},s.prototype.optional=function(){return this._baseState.optional=!0,this},s.prototype.def=function(e){const t=this._baseState;return n(null===t.default),t.default=e,t.optional=!0,this},s.prototype.explicit=function(e){const t=this._baseState;return n(null===t.explicit&&null===t.implicit),t.explicit=e,this},s.prototype.implicit=function(e){const t=this._baseState;return n(null===t.explicit&&null===t.implicit),t.implicit=e,this},s.prototype.obj=function(){const e=this._baseState,t=Array.prototype.slice.call(arguments);return e.obj=!0,0!==t.length&&this._useArgs(t),this},s.prototype.key=function(e){const t=this._baseState;return n(null===t.key),t.key=e,this},s.prototype.any=function(){return this._baseState.any=!0,this},s.prototype.choice=function(e){const t=this._baseState;return n(null===t.choice),t.choice=e,this._useArgs(Object.keys(e).map((function(t){return e[t]}))),this},s.prototype.contains=function(e){const t=this._baseState;return n(null===t.use),t.contains=e,this},s.prototype._decode=function(e,t){const n=this._baseState;if(null===n.parent)return e.wrapResult(n.children[0]._decode(e,t));let o,i=n.default,s=!0,a=null;if(null!==n.key&&(a=e.enterKey(n.key)),n.optional){let r=null;if(null!==n.explicit?r=n.explicit:null!==n.implicit?r=n.implicit:null!==n.tag&&(r=n.tag),null!==r||n.any){if(s=this._peekTag(e,r,n.any),e.isError(s))return s}else{const r=e.save();try{null===n.choice?this._decodeGeneric(n.tag,e,t):this._decodeChoice(e,t),s=!0}catch(e){s=!1}e.restore(r)}}if(n.obj&&s&&(o=e.enterObject()),s){if(null!==n.explicit){const t=this._decodeTag(e,n.explicit);if(e.isError(t))return t;e=t}const o=e.offset;if(null===n.use&&null===n.choice){let t;n.any&&(t=e.save());const r=this._decodeTag(e,null!==n.implicit?n.implicit:n.tag,n.any);if(e.isError(r))return r;n.any?i=e.raw(t):e=r}if(t&&t.track&&null!==n.tag&&t.track(e.path(),o,e.length,"tagged"),t&&t.track&&null!==n.tag&&t.track(e.path(),e.offset,e.length,"content"),n.any||(i=null===n.choice?this._decodeGeneric(n.tag,e,t):this._decodeChoice(e,t)),e.isError(i))return i;if(n.any||null!==n.choice||null===n.children||n.children.forEach((function(r){r._decode(e,t)})),n.contains&&("octstr"===n.tag||"bitstr"===n.tag)){const o=new r(i);i=this._getUse(n.contains,e._reporterState.obj)._decode(o,t)}}return n.obj&&s&&(i=e.leaveObject(o)),null===n.key||null===i&&!0!==s?null!==a&&e.exitKey(a):e.leaveKey(a,n.key,i),i},s.prototype._decodeGeneric=function(e,t,r){const n=this._baseState;return"seq"===e||"set"===e?null:"seqof"===e||"setof"===e?this._decodeList(t,e,n.args[0],r):/str$/.test(e)?this._decodeStr(t,e,r):"objid"===e&&n.args?this._decodeObjid(t,n.args[0],n.args[1],r):"objid"===e?this._decodeObjid(t,null,null,r):"gentime"===e||"utctime"===e?this._decodeTime(t,e,r):"null_"===e?this._decodeNull(t,r):"bool"===e?this._decodeBool(t,r):"objDesc"===e?this._decodeStr(t,e,r):"int"===e||"enum"===e?this._decodeInt(t,n.args&&n.args[0],r):null!==n.use?this._getUse(n.use,t._reporterState.obj)._decode(t,r):t.error("unknown tag: "+e)},s.prototype._getUse=function(e,t){const r=this._baseState;return r.useDecoder=this._use(e,t),n(null===r.useDecoder._baseState.parent),r.useDecoder=r.useDecoder._baseState.children[0],r.implicit!==r.useDecoder._baseState.implicit&&(r.useDecoder=r.useDecoder.clone(),r.useDecoder._baseState.implicit=r.implicit),r.useDecoder},s.prototype._decodeChoice=function(e,t){const r=this._baseState;let n=null,o=!1;return Object.keys(r.choice).some((function(i){const s=e.save(),a=r.choice[i];try{const r=a._decode(e,t);if(e.isError(r))return!1;n={type:i,value:r},o=!0}catch(t){return e.restore(s),!1}return!0}),this),o?n:e.error("Choice not matched")},s.prototype._createEncoderBuffer=function(e){return new t(e,this.reporter)},s.prototype._encode=function(e,t,r){const n=this._baseState;if(null!==n.default&&n.default===e)return;const o=this._encodeValue(e,t,r);return void 0===o||this._skipDefault(o,t,r)?void 0:o},s.prototype._encodeValue=function(t,r,n){const o=this._baseState;if(null===o.parent)return o.children[0]._encode(t,r||new e);let i=null;if(this.reporter=r,o.optional&&void 0===t){if(null===o.default)return;t=o.default}let s=null,a=!1;if(o.any)i=this._createEncoderBuffer(t);else if(o.choice)i=this._encodeChoice(t,r);else if(o.contains)s=this._getUse(o.contains,n)._encode(t,r),a=!0;else if(o.children)s=o.children.map((function(e){if("null_"===e._baseState.tag)return e._encode(null,r,t);if(null===e._baseState.key)return r.error("Child should have a key");const n=r.enterKey(e._baseState.key);if("object"!=typeof t)return r.error("Child expected, but input is not object");const o=e._encode(t[e._baseState.key],r,t);return r.leaveKey(n),o}),this).filter((function(e){return e})),s=this._createEncoderBuffer(s);else if("seqof"===o.tag||"setof"===o.tag){if(!o.args||1!==o.args.length)return r.error("Too many args for : "+o.tag);if(!Array.isArray(t))return r.error("seqof/setof, but data is not Array");const e=this.clone();e._baseState.implicit=null,s=this._createEncoderBuffer(t.map((function(e){const n=this._baseState;return this._getUse(n.args[0],t)._encode(e,r)}),e))}else null!==o.use?i=this._getUse(o.use,n)._encode(t,r):(s=this._encodePrimitive(o.tag,t),a=!0);if(!o.any&&null===o.choice){const e=null!==o.implicit?o.implicit:o.tag,t=null===o.implicit?"universal":"context";null===e?null===o.use&&r.error("Tag could be omitted only for .use()"):null===o.use&&(i=this._encodeComposite(e,a,t,s))}return null!==o.explicit&&(i=this._encodeComposite(o.explicit,!1,"context",i)),i},s.prototype._encodeChoice=function(e,t){const r=this._baseState,o=r.choice[e.type];return o||n(!1,e.type+" not found in "+JSON.stringify(Object.keys(r.choice))),o._encode(e.value,t)},s.prototype._encodePrimitive=function(e,t){const r=this._baseState;if(/str$/.test(e))return this._encodeStr(t,e);if("objid"===e&&r.args)return this._encodeObjid(t,r.reverseArgs[0],r.args[1]);if("objid"===e)return this._encodeObjid(t,null,null);if("gentime"===e||"utctime"===e)return this._encodeTime(t,e);if("null_"===e)return this._encodeNull();if("int"===e||"enum"===e)return this._encodeInt(t,r.args&&r.reverseArgs[0]);if("bool"===e)return this._encodeBool(t);if("objDesc"===e)return this._encodeStr(t,e);throw new Error("Unsupported tag: "+e)},s.prototype._isNumstr=function(e){return/^[0-9 ]*$/.test(e)},s.prototype._isPrintstr=function(e){return/^[A-Za-z0-9 '()+,-./:=?]*$/.test(e)},j}var T,N,z,O,R,D,V={};function M(){return T||(T=1,function(e){function t(e){const t={};return Object.keys(e).forEach((function(r){(0|r)==r&&(r|=0);const n=e[r];t[n]=r})),t}e.tagClass={0:"universal",1:"application",2:"context",3:"private"},e.tagClassByName=t(e.tagClass),e.tag={0:"end",1:"bool",2:"int",3:"bitstr",4:"octstr",5:"null_",6:"objid",7:"objDesc",8:"external",9:"real",10:"enum",11:"embed",12:"utf8str",13:"relativeOid",16:"seq",17:"set",18:"numstr",19:"printstr",20:"t61str",21:"videostr",22:"ia5str",23:"utctime",24:"gentime",25:"graphstr",26:"iso646str",27:"genstr",28:"unistr",29:"charstr",30:"bmpstr"},e.tagByName=t(e.tag)}(V)),V}function L(){if(z)return N;z=1;const e=s(),t=S().Buffer,r=q(),n=M();function o(e){this.enc="der",this.name=e.name,this.entity=e,this.tree=new i,this.tree._init(e.body)}function i(e){r.call(this,"der",e)}function a(e){return e<10?"0"+e:e}return N=o,o.prototype.encode=function(e,t){return this.tree._encode(e,t).join()},e(i,r),i.prototype._encodeComposite=function(e,r,o,i){const s=function(e,t,r,o){let i;"seqof"===e?e="seq":"setof"===e&&(e="set");if(n.tagByName.hasOwnProperty(e))i=n.tagByName[e];else{if("number"!=typeof e||(0|e)!==e)return o.error("Unknown tag: "+e);i=e}if(i>=31)return o.error("Multi-octet tag encoding unsupported");t||(i|=32);return i|=n.tagClassByName[r||"universal"]<<6,i}(e,r,o,this.reporter);if(i.length<128){const e=t.alloc(2);return e[0]=s,e[1]=i.length,this._createEncoderBuffer([e,i])}let a=1;for(let e=i.length;e>=256;e>>=8)a++;const c=t.alloc(2+a);c[0]=s,c[1]=128|a;for(let e=1+a,t=i.length;t>0;e--,t>>=8)c[e]=255&t;return this._createEncoderBuffer([c,i])},i.prototype._encodeStr=function(e,r){if("bitstr"===r)return this._createEncoderBuffer([0|e.unused,e.data]);if("bmpstr"===r){const r=t.alloc(2*e.length);for(let t=0;t<e.length;t++)r.writeUInt16BE(e.charCodeAt(t),2*t);return this._createEncoderBuffer(r)}return"numstr"===r?this._isNumstr(e)?this._createEncoderBuffer(e):this.reporter.error("Encoding of string type: numstr supports only digits and space"):"printstr"===r?this._isPrintstr(e)?this._createEncoderBuffer(e):this.reporter.error("Encoding of string type: printstr supports only latin upper and lower case letters, digits, space, apostrophe, left and rigth parenthesis, plus sign, comma, hyphen, dot, slash, colon, equal sign, question mark"):/str$/.test(r)||"objDesc"===r?this._createEncoderBuffer(e):this.reporter.error("Encoding of string type: "+r+" unsupported")},i.prototype._encodeObjid=function(e,r,n){if("string"==typeof e){if(!r)return this.reporter.error("string objid given, but no values map found");if(!r.hasOwnProperty(e))return this.reporter.error("objid not found in values map");e=r[e].split(/[\s.]+/g);for(let t=0;t<e.length;t++)e[t]|=0}else if(Array.isArray(e)){e=e.slice();for(let t=0;t<e.length;t++)e[t]|=0}if(!Array.isArray(e))return this.reporter.error("objid() should be either array or string, got: "+JSON.stringify(e));if(!n){if(e[1]>=40)return this.reporter.error("Second objid identifier OOB");e.splice(0,2,40*e[0]+e[1])}let o=0;for(let t=0;t<e.length;t++){let r=e[t];for(o++;r>=128;r>>=7)o++}const i=t.alloc(o);let s=i.length-1;for(let t=e.length-1;t>=0;t--){let r=e[t];for(i[s--]=127&r;(r>>=7)>0;)i[s--]=128|127&r}return this._createEncoderBuffer(i)},i.prototype._encodeTime=function(e,t){let r;const n=new Date(e);return"gentime"===t?r=[a(n.getUTCFullYear()),a(n.getUTCMonth()+1),a(n.getUTCDate()),a(n.getUTCHours()),a(n.getUTCMinutes()),a(n.getUTCSeconds()),"Z"].join(""):"utctime"===t?r=[a(n.getUTCFullYear()%100),a(n.getUTCMonth()+1),a(n.getUTCDate()),a(n.getUTCHours()),a(n.getUTCMinutes()),a(n.getUTCSeconds()),"Z"].join(""):this.reporter.error("Encoding "+t+" time is not supported yet"),this._encodeStr(r,"octstr")},i.prototype._encodeNull=function(){return this._createEncoderBuffer("")},i.prototype._encodeInt=function(e,r){if("string"==typeof e){if(!r)return this.reporter.error("String int or enum given, but no values map");if(!r.hasOwnProperty(e))return this.reporter.error("Values map doesn't contain: "+JSON.stringify(e));e=r[e]}if("number"!=typeof e&&!t.isBuffer(e)){const r=e.toArray();!e.sign&&128&r[0]&&r.unshift(0),e=t.from(r)}if(t.isBuffer(e)){let r=e.length;0===e.length&&r++;const n=t.alloc(r);return e.copy(n),0===e.length&&(n[0]=0),this._createEncoderBuffer(n)}if(e<128)return this._createEncoderBuffer(e);if(e<256)return this._createEncoderBuffer([0,e]);let n=1;for(let t=e;t>=256;t>>=8)n++;const o=new Array(n);for(let t=o.length-1;t>=0;t--)o[t]=255&e,e>>=8;return 128&o[0]&&o.unshift(0),this._createEncoderBuffer(t.from(o))},i.prototype._encodeBool=function(e){return this._createEncoderBuffer(e?255:0)},i.prototype._use=function(e,t){return"function"==typeof e&&(e=e(t)),e._getEncoder("der").tree},i.prototype._skipDefault=function(e,t,r){const n=this._baseState;let o;if(null===n.default)return!1;const i=e.join();if(void 0===n.defaultBuffer&&(n.defaultBuffer=this._encodeValue(n.default,t,r).join()),i.length!==n.defaultBuffer.length)return!1;for(o=0;o<i.length;o++)if(i[o]!==n.defaultBuffer[o])return!1;return!0},N}function J(){return D||(D=1,function(e){const t=e;t.der=L(),t.pem=function(){if(R)return O;R=1;const e=s(),t=L();function r(e){t.call(this,e),this.enc="pem"}return e(r,t),O=r,r.prototype.encode=function(e,r){const n=t.prototype.encode.call(this,e).toString("base64"),o=["-----BEGIN "+r.label+"-----"];for(let e=0;e<n.length;e+=64)o.push(n.slice(e,e+64));return o.push("-----END "+r.label+"-----"),o.join("\n")},O}()}(E)),E}var $,F,Z,G,Y,H,X={};function W(){if(F)return $;F=1;const e=s(),t=i(),r=U().DecoderBuffer,n=q(),o=M();function a(e){this.enc="der",this.name=e.name,this.entity=e,this.tree=new c,this.tree._init(e.body)}function c(e){n.call(this,"der",e)}function u(e,t){let r=e.readUInt8(t);if(e.isError(r))return r;const n=o.tagClass[r>>6],i=!(32&r);if(31&~r)r&=31;else{let n=r;for(r=0;!(128&~n);){if(n=e.readUInt8(t),e.isError(n))return n;r<<=7,r|=127&n}}return{cls:n,primitive:i,tag:r,tagStr:o.tag[r]}}function l(e,t,r){let n=e.readUInt8(r);if(e.isError(n))return n;if(!t&&128===n)return null;if(!(128&n))return n;const o=127&n;if(o>4)return e.error("length octect is too long");n=0;for(let t=0;t<o;t++){n<<=8;const t=e.readUInt8(r);if(e.isError(t))return t;n|=t}return n}return $=a,a.prototype.decode=function(e,t){return r.isDecoderBuffer(e)||(e=new r(e,t)),this.tree._decode(e,t)},e(c,n),c.prototype._peekTag=function(e,t,r){if(e.isEmpty())return!1;const n=e.save(),o=u(e,'Failed to peek tag: "'+t+'"');return e.isError(o)?o:(e.restore(n),o.tag===t||o.tagStr===t||o.tagStr+"of"===t||r)},c.prototype._decodeTag=function(e,t,r){const n=u(e,'Failed to decode tag of "'+t+'"');if(e.isError(n))return n;let o=l(e,n.primitive,'Failed to get length of "'+t+'"');if(e.isError(o))return o;if(!r&&n.tag!==t&&n.tagStr!==t&&n.tagStr+"of"!==t)return e.error('Failed to match tag: "'+t+'"');if(n.primitive||null!==o)return e.skip(o,'Failed to match body of: "'+t+'"');const i=e.save(),s=this._skipUntilEnd(e,'Failed to skip indefinite length body: "'+this.tag+'"');return e.isError(s)?s:(o=e.offset-i.offset,e.restore(i),e.skip(o,'Failed to match body of: "'+t+'"'))},c.prototype._skipUntilEnd=function(e,t){for(;;){const r=u(e,t);if(e.isError(r))return r;const n=l(e,r.primitive,t);if(e.isError(n))return n;let o;if(o=r.primitive||null!==n?e.skip(n):this._skipUntilEnd(e,t),e.isError(o))return o;if("end"===r.tagStr)break}},c.prototype._decodeList=function(e,t,r,n){const o=[];for(;!e.isEmpty();){const t=this._peekTag(e,"end");if(e.isError(t))return t;const i=r.decode(e,"der",n);if(e.isError(i)&&t)break;o.push(i)}return o},c.prototype._decodeStr=function(e,t){if("bitstr"===t){const t=e.readUInt8();return e.isError(t)?t:{unused:t,data:e.raw()}}if("bmpstr"===t){const t=e.raw();if(t.length%2==1)return e.error("Decoding of string type: bmpstr length mismatch");let r="";for(let e=0;e<t.length/2;e++)r+=String.fromCharCode(t.readUInt16BE(2*e));return r}if("numstr"===t){const t=e.raw().toString("ascii");return this._isNumstr(t)?t:e.error("Decoding of string type: numstr unsupported characters")}if("octstr"===t)return e.raw();if("objDesc"===t)return e.raw();if("printstr"===t){const t=e.raw().toString("ascii");return this._isPrintstr(t)?t:e.error("Decoding of string type: printstr unsupported characters")}return/str$/.test(t)?e.raw().toString():e.error("Decoding of string type: "+t+" unsupported")},c.prototype._decodeObjid=function(e,t,r){let n;const o=[];let i=0,s=0;for(;!e.isEmpty();)s=e.readUInt8(),i<<=7,i|=127&s,128&s||(o.push(i),i=0);128&s&&o.push(i);const a=o[0]/40|0,c=o[0]%40;if(n=r?o:[a,c].concat(o.slice(1)),t){let e=t[n.join(" ")];void 0===e&&(e=t[n.join(".")]),void 0!==e&&(n=e)}return n},c.prototype._decodeTime=function(e,t){const r=e.raw().toString();let n,o,i,s,a,c;if("gentime"===t)n=0|r.slice(0,4),o=0|r.slice(4,6),i=0|r.slice(6,8),s=0|r.slice(8,10),a=0|r.slice(10,12),c=0|r.slice(12,14);else{if("utctime"!==t)return e.error("Decoding "+t+" time is not supported yet");n=0|r.slice(0,2),o=0|r.slice(2,4),i=0|r.slice(4,6),s=0|r.slice(6,8),a=0|r.slice(8,10),c=0|r.slice(10,12),n=n<70?2e3+n:1900+n}return Date.UTC(n,o-1,i,s,a,c,0)},c.prototype._decodeNull=function(){return null},c.prototype._decodeBool=function(e){const t=e.readUInt8();return e.isError(t)?t:0!==t},c.prototype._decodeInt=function(e,r){const n=e.raw();let o=new t(n);return r&&(o=r[o.toString(10)]||o),o},c.prototype._use=function(e,t){return"function"==typeof e&&(e=e(t)),e._getDecoder("der").tree},$}function Q(){return Y||(Y=1,function(e){const t=e;t.der=W(),t.pem=function(){if(G)return Z;G=1;const e=s(),t=S().Buffer,r=W();function n(e){r.call(this,e),this.enc="pem"}return e(n,r),Z=n,n.prototype.decode=function(e,n){const o=e.toString().split(/[\r\n]+/g),i=n.label.toUpperCase(),s=/^-----(BEGIN|END) ([^-]+)-----$/;let a=-1,c=-1;for(let e=0;e<o.length;e++){const t=o[e].match(s);if(null!==t&&t[2]===i){if(-1!==a){if("END"!==t[1])break;c=e;break}if("BEGIN"!==t[1])break;a=e}}if(-1===a||-1===c)throw new Error("PEM section not found for: "+i);const u=o.slice(a+1,c).join("");u.replace(/[^a-z0-9+/=]+/gi,"");const l=t.from(u,"base64");return r.prototype.decode.call(this,l,n)},Z}()}(X)),X}var ee,te={};var re,ne,oe={};function ie(){return ne||(ne=1,function(){const e=_;e.bignum=i(),e.define=(H||(H=1,function(e){const t=J(),r=Q(),n=s();function o(e,t){this.name=e,this.body=t,this.decoders={},this.encoders={}}e.define=function(e,t){return new o(e,t)},o.prototype._createNamed=function(e){const t=this.name;function r(e){this._initNamed(e,t)}return n(r,e),r.prototype._initNamed=function(t,r){e.call(this,t,r)},new r(this)},o.prototype._getDecoder=function(e){return e=e||"der",this.decoders.hasOwnProperty(e)||(this.decoders[e]=this._createNamed(r[e])),this.decoders[e]},o.prototype.decode=function(e,t,r){return this._getDecoder(t).decode(e,r)},o.prototype._getEncoder=function(e){return e=e||"der",this.encoders.hasOwnProperty(e)||(this.encoders[e]=this._createNamed(t[e])),this.encoders[e]},o.prototype.encode=function(e,t,r){return this._getEncoder(t).encode(e,r)}}(P)),P).define,e.base=(ee||(ee=1,function(){const e=te;e.Reporter=x().Reporter,e.DecoderBuffer=U().DecoderBuffer,e.EncoderBuffer=U().EncoderBuffer,e.Node=q()}()),te),e.constants=(re||(re=1,function(e){const t=e;t._reverse=function(e){const t={};return Object.keys(e).forEach((function(r){(0|r)==r&&(r|=0);const n=e[r];t[n]=r})),t},t.der=M()}(oe)),oe),e.decoders=Q(),e.encoders=J()}()),_}var se,ae,ce,ue,le,fe,pe,de,he,ye,be,we,ge,me,ve,ke,_e,Pe,Ee,Se,Ke,Ae,xe,Ce,je,Be,Ie,Ue,qe,Te,Ne,ze,Oe,Re,De,Ve={exports:{}},Me={},Le={};function Je(){if(ae)return Me;ae=1,Object.defineProperty(Me,"__esModule",{value:!0});var e=(se||(se=1,Object.defineProperty(Le,"__esModule",{value:!0}),Le.default=function(e){var t=e.length,n=t%4;if(!n)return e;var o=t,i=4-n,s=t+i,a=r.alloc(s);for(a.write(e);i--;)a.write("=",o++);return a.toString()}),Le);function n(e,n){return void 0===n&&(n="utf8"),t(e)?i(e.toString("base64")):i(r.from(e,n).toString("base64"))}function o(t){return t=t.toString(),e.default(t).replace(/\-/g,"+").replace(/_/g,"/")}function i(e){return e.replace(/=/g,"").replace(/\+/g,"-").replace(/\//g,"_")}var s=n;return s.encode=n,s.decode=function(e,t){return void 0===t&&(t="utf8"),r.from(o(e),"base64").toString(t)},s.toBase64=o,s.fromBase64=i,s.toBuffer=function(e){return r.from(o(e),"base64")},Me.default=s,Me}function $e(){return ce||(ce=1,(e=Ve).exports=Je().default,e.exports.default=e.exports),Ve.exports;var e}function Fe(){if(le)return ue;le=1;const e=ie(),t=$e();return ue=class{static convert(n,o,i){if(!n)return;if(o===i)return n;let s;if("raw"===o||n instanceof r)s=n;else if("uint8_array"===o||Array.isArray(n))s=r.from(n);else if("hex"===o)s=r.from(n,"hex");else if("base64"===o)s=r.from(n,"base64");else if("base64url"===o)s=t.toBuffer(n);else{if("bn"!==o&&"bignum"!==o)throw new Error("Invalid fromType");s=r.from(this.pad(n.toString(16)),"hex")}if("raw"===i)return s;if("uint8_array"===i)return Array.from(s);if("hex"===i)return s.toString("hex");if("base64"===i)return s.toString("base64");if("base64url"===i)return t.fromBase64(s.toString("base64"));if("bn"===i||"bignum"===i)return new e.bignum(s);throw new Error("Invalid toType")}static pad(e){return e.length%2==1?`0${e}`:e}},ue}function Ze(){if(je)return Ce;je=1;const e=new(function(){if(pe)return fe;pe=1;const e=ie();return fe=class{constructor(){Object.defineProperty(this,"_registry",{value:{}})}get registry(){return this._registry}define(t,r){this._registry[t]=e.define(t,r(this))}normalize(e){return this.registry[e]}}}());return e.define("Version",he?de:(he=1,de=e=>function(){this.int({0:"two-prime",1:"multi"})})),e.define("OtherPrimeInfos",be?ye:(be=1,ye=e=>function(){this.seq().obj(this.key("ri").int(),this.key("di").int(),this.key("ti").int())})),e.define("AlgorithmIdentifier",ge?we:(ge=1,we=e=>function(){this.seq().obj(this.key("algorithm").objid(),this.key("parameters").optional().any())})),e.define("PrivateKeyInfo",(ve||(ve=1,me=e=>{let t=e.normalize("Version"),r=e.normalize("AlgorithmIdentifier");return function(){this.seq().obj(this.key("version").use(t),this.key("algorithm").use(r),this.key("privateKey").octstr())}}),me)),e.define("PublicKeyInfo",(_e||(_e=1,ke=e=>{let t=e.normalize("AlgorithmIdentifier");return function(){this.seq().obj(this.key("algorithm").use(t),this.key("publicKey").bitstr())}}),ke)),e.define("RSAPrivateKey",(Ee||(Ee=1,Pe=e=>{let t=e.normalize("Version"),r=e.normalize("OtherPrimeInfos");return function(){this.seq().obj(this.key("version").use(t),this.key("n").int(),this.key("e").int(),this.key("d").int(),this.key("p").int(),this.key("q").int(),this.key("dp").int(),this.key("dq").int(),this.key("qi").int(),this.key("other").optional().use(r))}}),Pe)),e.define("RSAPublicKey",Ke?Se:(Ke=1,Se=e=>function(){this.seq().obj(this.key("n").int(),this.key("e").int())})),e.define("ECPrivateKey",xe?Ae:(xe=1,Ae=e=>function(){this.seq().obj(this.key("version").int(),this.key("privateKey").octstr(),this.key("parameters").explicit(0).optional().choice({namedCurve:this.objid()}),this.key("publicKey").explicit(1).optional().bitstr())})),Ce=e}function Ge(){if(Oe)return ze;Oe=1;const e=h?d:(h=1,d=class{constructor(){this.registry=[],this.classes={}}find(e){return this.registry.find(e)}define(e,t){e.forEach((e=>{let{kty:r}=e;if(!r)throw new Error("Invalid type definition");this.classes[r]||(this.classes[r]=t),this.registry.push(e)}))}normalize(e,t,r){let n=this.classes[e],o=this.find((e=>e[t]===r));if(!n||!o)throw new Error("Invalid type");return new n(o)}}),t=function(){if(Ie)return Be;Ie=1;const e=m();w();const t=Fe(),n=Ze();class o extends e{fromPrivatePKCS1(e){let r=n.normalize("RSAPrivateKey"),{n:o,e:i,d:s,p:a,q:c,dp:u,dq:l,qi:f}=r.decode(e,"der");return{n:t.convert(o,"bn","raw"),e:t.convert(i,"bn","raw"),d:t.convert(s,"bn","raw"),p:t.convert(a,"bn","raw"),q:t.convert(c,"bn","raw"),dp:t.convert(u,"bn","raw"),dq:t.convert(l,"bn","raw"),qi:t.convert(f,"bn","raw")}}fromPrivatePKCS8(e){let r=n.normalize("PrivateKeyInfo"),o=n.normalize("RSAPrivateKey"),i=r.decode(e,"der"),{n:s,e:a,d:c,p:u,q:l,dp:f,dq:p,qi:d}=o.decode(i.privateKey,"der");return{n:t.convert(s,"bn","raw"),e:t.convert(a,"bn","raw"),d:t.convert(c,"bn","raw"),p:t.convert(u,"bn","raw"),q:t.convert(l,"bn","raw"),dp:t.convert(f,"bn","raw"),dq:t.convert(p,"bn","raw"),qi:t.convert(d,"bn","raw")}}fromPublicPKCS1(e){let r=n.normalize("RSAPublicKey"),{n:o,e:i}=r.decode(e,"der");return{n:t.convert(o,"bn","raw"),e:t.convert(i,"bn","raw")}}fromPublicPKCS8(e){let r=n.normalize("PublicKeyInfo"),o=n.normalize("RSAPublicKey"),i=r.decode(e,"der"),{n:s,e:a}=o.decode(i.publicKey.data,"der");return{n:t.convert(s,"bn","raw"),e:t.convert(a,"bn","raw")}}fromJwk(e){let{n:r,e:n,d:o,p:i,q:s,dp:a,dq:c,qi:u,alg:l}=e;return{n:t.convert(r,"base64url","raw"),e:t.convert(n,"base64url","raw"),d:t.convert(o,"base64url","raw"),p:t.convert(i,"base64url","raw"),q:t.convert(s,"base64url","raw"),dp:t.convert(a,"base64url","raw"),dq:t.convert(c,"base64url","raw"),qi:t.convert(u,"base64url","raw")}}toPrivatePKCS1(e){let{n:r,e:i,d:s,p:a,q:c,dp:u,dq:l,qi:f}=e,{version:p}=this.params,d=n.normalize("RSAPrivateKey").encode({version:p,n:t.convert(r,"raw","bn"),e:t.convert(i,"raw","bn"),d:t.convert(s,"raw","bn"),p:t.convert(a,"raw","bn"),q:t.convert(c,"raw","bn"),dp:t.convert(u,"raw","bn"),dq:t.convert(l,"raw","bn"),qi:t.convert(f,"raw","bn")},"der").toString("base64");return o.formatPem(d,"RSA PRIVATE")}toPrivatePKCS8(e){let{n:i,e:s,d:a,p:c,q:u,dp:l,dq:f,qi:p}=e,{oid:d,algParameters:h,version:y}=this.params,b=n.normalize("PrivateKeyInfo"),w=n.normalize("RSAPrivateKey").encode({version:y,n:t.convert(i,"raw","bn"),e:t.convert(s,"raw","bn"),d:t.convert(a,"raw","bn"),p:t.convert(c,"raw","bn"),q:t.convert(u,"raw","bn"),dp:t.convert(l,"raw","bn"),dq:t.convert(f,"raw","bn"),qi:t.convert(p,"raw","bn")},"der"),g=b.encode({version:y,algorithm:{algorithm:d.split("."),parameters:r.from(h,"hex")},privateKey:w},"der").toString("base64");return o.formatPem(g,"PRIVATE")}toPublicPKCS1(e){let{n:r,e:i}=e,{version:s}=this.params,a=n.normalize("RSAPublicKey").encode({version:s,n:t.convert(r,"raw","bn"),e:t.convert(i,"raw","bn")},"der").toString("base64");return o.formatPem(a,"RSA PUBLIC")}toPublicPKCS8(e){let{n:i,e:s}=e,{oid:a,algParameters:c}=this.params,u=n.normalize("PublicKeyInfo"),l=n.normalize("RSAPublicKey").encode({n:t.convert(i,"raw","bn"),e:t.convert(s,"raw","bn")},"der"),f=u.encode({algorithm:{algorithm:a.split("."),parameters:r.from(c,"hex")},publicKey:{unused:0,data:l}},"der").toString("base64");return o.formatPem(f,"PUBLIC")}toPrivateJwk(e){let{n:r,e:n,d:o,p:i,q:s,dp:a,dq:c,qi:u}=e,{kty:l}=this.params;return{kty:l,n:t.convert(r,"raw","base64url"),e:t.convert(n,"raw","base64url"),d:t.convert(o,"raw","base64url"),p:t.convert(i,"raw","base64url"),q:t.convert(s,"raw","base64url"),dp:t.convert(a,"raw","base64url"),dq:t.convert(c,"raw","base64url"),qi:t.convert(u,"raw","base64url")}}toPublicJwk(e){let{n:r,e:n}=e,{kty:o}=this.params;return{kty:o,n:t.convert(r,"raw","base64url"),e:t.convert(n,"raw","base64url")}}}return Be=o}(),n=function(){if(qe)return Ue;qe=1,ie().bignum;const e=new(0,o().ec)("secp256k1"),t=m();w();const n=Fe(),i=Ze();class s extends t{fromPrivatePKCS1(e){let t=i.normalize("ECPrivateKey").decode(e,"der"),{privateKey:r,publicKey:{data:o}}=t,a=n.convert(o,"raw","hex"),{x:c,y:u}=s.getPoint(a);return{d:r,x:c,y:u}}fromPrivatePKCS8(e){let t=i.normalize("PrivateKeyInfo"),r=i.normalize("ECPrivateKey"),o=t.decode(e,"der"),a=r.decode(o.privateKey,"der"),{privateKey:c,publicKey:{data:u}}=a,l=n.convert(u,"raw","hex"),{x:f,y:p}=s.getPoint(l);return{d:c,x:f,y:p}}fromPublicPKCS8(e){let t=i.normalize("PublicKeyInfo").decode(e,"der"),r=n.convert(t.publicKey.data,"raw","hex");return s.getPoint(r)}fromPrivateBlk(t){let r=e.keyFromPrivate(t,"hex"),o=r.getPublic();return{d:n.convert(r.priv,"bn","raw"),x:n.convert(o.getX(),"bn","raw"),y:n.convert(o.getY(),"bn","raw")}}fromPublicBlk(e){return s.getPoint(e)}fromJwk(e){let{d:t,x:r,y:o}=e;return{d:n.convert(t,"base64url","raw"),x:n.convert(r,"base64url","raw"),y:n.convert(o,"base64url","raw")}}toPrivatePKCS1(e){let{namedCurve:t,keyVersion:r}=this.params,{d:n,x:o,y:a}=e,c=i.normalize("ECPrivateKey"),u=s.makePoint(o,a),l=c.encode({version:r,privateKey:n,parameters:{type:"namedCurve",value:t.split(".")},publicKey:{unused:0,data:u}},"der").toString("base64");return s.formatPem(l,"EC PRIVATE")}toPrivatePKCS8(e){let{oid:t,algParameters:n,keyVersion:o,infoVersion:a}=this.params,{d:c,x:u,y:l}=e,f=i.normalize("PrivateKeyInfo"),p=i.normalize("ECPrivateKey"),d=s.makePoint(u,l),h=p.encode({version:o,privateKey:c,publicKey:{unused:0,data:d}},"der"),y=f.encode({version:a,algorithm:{algorithm:t.split("."),parameters:r.from(n,"hex")},privateKey:h},"der").toString("base64");return s.formatPem(y,"PRIVATE")}toPublicPKCS8(e){let{oid:t,algParameters:n}=this.params,{x:o,y:a}=e,c=i.normalize("PublicKeyInfo"),u=s.makePoint(o,a),l=c.encode({algorithm:{algorithm:t.split("."),parameters:r.from(n,"hex")},publicKey:{unused:0,data:u}},"der").toString("base64");return s.formatPem(l,"PUBLIC")}toPrivateBlk(e){return e.d.toString("hex")}toPublicBlk(e){return n.convert(s.makePoint(e.x,e.y),"raw","hex")}toPrivateJwk(e){let{crv:t,kty:r}=this.params,{d:o,x:i,y:s}=e;return{kty:r,crv:t,d:n.convert(o,"raw","base64url"),x:n.convert(i,"raw","base64url"),y:n.convert(s,"raw","base64url")}}toPublicJwk(e){let{crv:t,kty:r}=this.params,{x:o,y:i}=e;return{kty:r,crv:t,x:n.convert(o,"raw","base64url"),y:n.convert(i,"raw","base64url")}}static getPoint(e){let t=e.slice(2,(e.length-2)/2+2),r=e.slice((e.length-2)/2+2);return{x:n.convert(t,"hex","raw"),y:n.convert(r,"hex","raw")}}static makePoint(e,t){let n=r.from("04","hex");return r.concat([n,e,t],n.length+e.length+t.length)}}return Ue=s}(),i=function(){if(Ne)return Te;Ne=1;const e=m(),t=Fe(),n=Ze();class i extends e{fromPrivatePKCS8(e){const t=n.normalize("PrivateKeyInfo").decode(e,"der").privateKey.slice(2);return{d:t,x:this.publicKeyFromPrivate(t)}}fromPublicPKCS8(e){const r=n.normalize("PublicKeyInfo").decode(e,"der");return{x:t.convert(r.publicKey.data,"hex","raw")}}fromJwk(e){let{d:r,x:n}=e;return{d:t.convert(r,"base64url","raw"),x:t.convert(n,"base64url","raw")}}toPrivatePKCS8(e){let{oid:t,infoVersion:r}=this.params,{d:o}=e;const s=n.normalize("PrivateKeyInfo"),a=this.privateKeyPadding(o);let c=s.encode({version:r,algorithm:{algorithm:t.split(".")},privateKey:a},"der").toString("base64");return i.formatPem(c,"PRIVATE")}toPublicPKCS8(e){let{oid:r}=this.params,{x:o}=e,s=n.normalize("PublicKeyInfo").encode({algorithm:{algorithm:r.split(".")},publicKey:{unused:0,data:t.convert(o,"hex","raw")}},"der").toString("base64");return i.formatPem(s,"PUBLIC")}toPrivateJwk(e){let{crv:r,kty:n}=this.params,{d:o,x:i}=e;return{kty:n,crv:r,d:t.convert(o,"raw","base64url"),x:t.convert(i,"raw","base64url")}}toPublicJwk(e){let{crv:r,kty:n}=this.params,{x:o}=e;return{kty:n,crv:r,x:t.convert(o,"raw","base64url")}}privateKeyPadding(e){let t;if("Ed25519"!==this.params.crv)throw new Error(`${this.params.crv} is an invalid curve for EdDSA`);return t=r.from("0420","hex"),r.concat([t,e],t.length+e.length)}publicKeyFromPrivate(e){if("Ed25519"===this.params.crv){const t=new(0,o().eddsa)("ed25519");return r.from(t.keyFromSecret(e).getPublic())}throw new Error(`${this.params.crv} is an invalid curve for EdDSA`)}}return Te=i}(),s=new e;return s.define([{kty:"RSA",oid:"1.2.840.113549.1.1.1",algParameters:"0500",version:"two-prime"}],t),s.define([{kty:"EC",crv:"K-256",oid:"1.2.840.10045.2.1",namedCurve:"1.3.132.0.10",algParameters:"06052b8104000a",keyVersion:1,infoVersion:"two-prime"},{kty:"EC",crv:"P-256",oid:"1.2.840.10045.2.1",namedCurve:"1.2.840.10045.3.1.7",algParameters:"06082a8648ce3d030107",keyVersion:1,infoVersion:"two-prime"},{kty:"EC",crv:"P-384",oid:"1.2.840.10045.2.1",namedCurve:"1.3.132.0.34",algParameters:"06052b81040022",keyVersion:1,infoVersion:"two-prime"},{kty:"EC",crv:"P-521",oid:"1.2.840.10045.2.1",namedCurve:"1.3.132.0.35",algParameters:"06052b81040023",keyVersion:1,infoVersion:"two-prime"}],n),s.define([{kty:"OKP",crv:"Ed25519",oid:"1.3.101.112",infoVersion:"two-prime"}],i),ze=s}var Ye=function(){if(De)return Re;De=1;const e=w(),t=g(),n=Ge(),o=Ze(),i=RegExp("\r?\n","g");class s{constructor(t,r){if(!t)throw new e("key is required");if(!r)throw new e("options are required");let{kty:n,format:o,selector:i,crv:s,oid:a}=r;if(!r.kty)throw new e("options.kty is required");if(!r.format)throw new e("options.format is required");if(!r.selector)throw new e("options.selector is required");if(!r.crv&&!r.oid)throw new e("options.crv or options.oid is required");this.kty=n,this.format=o,this.selector=i,this.crv=s,this.oid=a,this.key=this.parseKey(t)}static from(t,a){if(!t)throw new e("key is required");if(!a)throw new e("format is required");if("jwk"===a){let r;if("string"==typeof t)try{r=JSON.parse(t)}catch(t){throw new e("key is not a valid JWK")}else"object"==typeof t&&(r=t);let o,{kty:i,crv:c}=r;if(!i)throw new e("kty is required for JWK");if("EC"===i&&!c)throw new e("crv is required for EC JWK");"RSA"===i&&(o=n.find((e=>e.kty===i)).oid);let u=r.d?"private":"public";return new s(r,{kty:i,crv:c,oid:o,format:a,selector:u})}if("pem"===a){if("string"!=typeof t)throw new e("key is not a valid PEM string");let c=t.split(i),u=c.splice(0,1);c.splice(c.length-1,1);let l,f,p=c.join(""),d=/^-----BEGIN ((RSA|EC) )?(PUBLIC|PRIVATE) KEY-----$/.exec(u),h=d?d[2]:void 0,y=d?d[3]:void 0,b=r.from(p,"base64");if(!y)throw new e("key is not a valid PEM string");if(h){if("RSA"===h)y="PRIVATE"===y?"private_pkcs1":"public_pkcs1",l=n.find((e=>e.kty===h)).oid;else if("EC"===h){let e;if("PRIVATE"===y){y="private_pkcs1",e=o.normalize(`${h}PrivateKey`).decode(b,"der")}else if("PUBLIC"===y){y="public_pkcs1",e=o.normalize(`${h}PrivateKey`).decode(b,"der")}let{parameters:{value:t}}=e;f=n.find((e=>e.namedCurve===t.join("."))).crv}}else{let t,r=o.normalize("PrivateKeyInfo"),i=o.normalize("PublicKeyInfo");"PRIVATE"===y?(y="private_pkcs8",t=r.decode(b,"der")):"PUBLIC"===y&&(y="public_pkcs8",t=i.decode(b,"der"));let{algorithm:{algorithm:s,parameters:a}}=t;s=s.join("."),a=a?a.toString("hex"):void 0;const c=n.find((e=>e.oid===s));if(h=c?c.kty:void 0,!h)throw new e(`${s} is not supported`);"RSA"===h||"OKP"===h?l=s:"EC"===h&&(f=n.find((e=>e.algParameters===a)).crv)}return new s(b,{kty:h,oid:l,crv:f,format:a,selector:y})}if("blk"===a)return new s(t,{kty:"EC",crv:"K-256",format:a,selector:t.length>64?"public":"private"});throw new e(`Invalid format ${a}`)}get alg(){let{kty:e,crv:t,oid:r}=this;if(!this.algorithm){if(t)Object.defineProperty(this,"algorithm",{value:n.normalize(e,"crv",t)});else{if(!r)throw new Error("Both crv and oid are undefined");Object.defineProperty(this,"algorithm",{value:n.normalize(e,"oid",r)})}if(!this.algorithm)throw new Error(`${this.crv||this.oid} is not implemented yet`)}return this.algorithm}parseKey(e){let{alg:t,format:r,selector:n}=this;if("pem"===r)switch(n){case"public_pkcs1":return t.fromPublicPKCS1(e);case"public_pkcs8":return t.fromPublicPKCS8(e);case"private_pkcs1":return t.fromPrivatePKCS1(e);case"private_pkcs8":return t.fromPrivatePKCS8(e);default:throw new Error("Invalid selector value")}if("jwk"===r)return t.fromJwk(e,n);if("blk"===r)switch(n){case"public":return t.fromPublicBlk(e);case"private":return t.fromPrivateBlk(e)}}toJwk(t){let{key:r,alg:n,selector:o}=this;switch(t){case"public":return n.toPublicJwk(r);case"private":if(o.includes("public"))throw new e("Cannot export a private key from a public key");return n.toPrivateJwk(r);default:throw new Error("Invalid key selector")}}toString(r="pem",n="public_pkcs8"){let{key:o,alg:i,selector:s}=this;if("pem"===r)switch(n){case"public_pkcs1":return i.toPublicPKCS1(o);case"public_pkcs8":return i.toPublicPKCS8(o);case"private_pkcs1":if(s.includes("public"))throw new e("Cannot export a private key from a public key");return i.toPrivatePKCS1(o);case"private_pkcs8":if(s.includes("public"))throw new e("Cannot export a private key from a public key");return i.toPrivatePKCS8(o);default:throw new Error("Invalid key selector")}else if("jwk"===r)switch(n){case"public":return JSON.stringify(i.toPublicJwk(o));case"private":if(s.includes("public"))throw new e("Cannot export a private key from a public key");return JSON.stringify(i.toPrivateJwk(o));default:throw new Error("Invalid key selector")}else if("blk"===r)switch(n){case"private":if(s.includes("public"))throw new e("Cannot export a private key from a public key");return i.toPrivateBlk(o);case"public":return i.toPublicBlk(o);default:throw new Error("Invalid key selector")}throw new t}}return Re=s}(),He=e(Ye);var Xe,We,Qe,et,tt,rt,nt=function(e){if(e.length>=255)throw new TypeError("Alphabet too long");const t=new Uint8Array(256);for(let e=0;e<t.length;e++)t[e]=255;for(let r=0;r<e.length;r++){const n=e.charAt(r),o=n.charCodeAt(0);if(255!==t[o])throw new TypeError(n+" is ambiguous");t[o]=r}const r=e.length,n=e.charAt(0),o=Math.log(r)/Math.log(256),i=Math.log(256)/Math.log(r);function s(e){if("string"!=typeof e)throw new TypeError("Expected String");if(0===e.length)return new Uint8Array;let i=0,s=0,a=0;for(;e[i]===n;)s++,i++;const c=(e.length-i)*o+1>>>0,u=new Uint8Array(c);for(;i<e.length;){const n=e.charCodeAt(i);if(n>255)return;let o=t[n];if(255===o)return;let s=0;for(let e=c-1;(0!==o||s<a)&&-1!==e;e--,s++)o+=r*u[e]>>>0,u[e]=o%256>>>0,o=o/256>>>0;if(0!==o)throw new Error("Non-zero carry");a=s,i++}let l=c-a;for(;l!==c&&0===u[l];)l++;const f=new Uint8Array(s+(c-l));let p=s;for(;l!==c;)f[p++]=u[l++];return f}return{encode:function(t){if(t instanceof Uint8Array||(ArrayBuffer.isView(t)?t=new Uint8Array(t.buffer,t.byteOffset,t.byteLength):Array.isArray(t)&&(t=Uint8Array.from(t))),!(t instanceof Uint8Array))throw new TypeError("Expected Uint8Array");if(0===t.length)return"";let o=0,s=0,a=0;const c=t.length;for(;a!==c&&0===t[a];)a++,o++;const u=(c-a)*i+1>>>0,l=new Uint8Array(u);for(;a!==c;){let e=t[a],n=0;for(let t=u-1;(0!==e||n<s)&&-1!==t;t--,n++)e+=256*l[t]>>>0,l[t]=e%r>>>0,e=e/r>>>0;if(0!==e)throw new Error("Non-zero carry");s=n,a++}let f=u-s;for(;f!==u&&0===l[f];)f++;let p=n.repeat(o);for(;f<u;++f)p+=e.charAt(l[f]);return p},decodeUnsafe:s,decode:function(e){const t=s(e);if(t)return t;throw new Error("Non-base"+r+" character")}}}("123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz");function ot(){if(et)return Qe;et=1;const e=new(0,o().ec)("secp256k1"),t=e.curve,r=t.n.constructor;function n(n){const o=n[0];switch(o){case 2:case 3:return 33!==n.length?null:function(n,o){let i=new r(o);if(i.cmp(t.p)>=0)return null;i=i.toRed(t.red);let s=i.redSqr().redIMul(i).redIAdd(t.b).redSqrt();3===n!==s.isOdd()&&(s=s.redNeg());const a=i.redSqr().redIMul(i);return s.redSqr().redISub(a.redIAdd(t.b)).isZero()?e.keyPair({pub:{x:i,y:s}}):null}(o,n.subarray(1,33));case 4:case 6:case 7:return 65!==n.length?null:function(n,o,i){let s=new r(o),a=new r(i);if(s.cmp(t.p)>=0||a.cmp(t.p)>=0)return null;if(s=s.toRed(t.red),a=a.toRed(t.red),(6===n||7===n)&&a.isOdd()!==(7===n))return null;const c=s.redSqr().redIMul(s);return a.redSqr().redISub(c.redIAdd(t.b)).isZero()?e.keyPair({pub:{x:s,y:a}}):null}(o,n.subarray(1,33),n.subarray(33,65));default:return null}}function i(e,t){const r=t.encode(null,33===e.length);for(let t=0;t<e.length;++t)e[t]=r[t]}return Qe={contextRandomize:()=>0,privateKeyVerify(e){const n=new r(e);return n.cmp(t.n)<0&&!n.isZero()?0:1},privateKeyNegate(e){const n=new r(e),o=t.n.sub(n).umod(t.n).toArrayLike(Uint8Array,"be",32);return e.set(o),0},privateKeyTweakAdd(e,n){const o=new r(n);if(o.cmp(t.n)>=0)return 1;if(o.iadd(new r(e)),o.cmp(t.n)>=0&&o.isub(t.n),o.isZero())return 1;const i=o.toArrayLike(Uint8Array,"be",32);return e.set(i),0},privateKeyTweakMul(e,n){let o=new r(n);if(o.cmp(t.n)>=0||o.isZero())return 1;o.imul(new r(e)),o.cmp(t.n)>=0&&(o=o.umod(t.n));const i=o.toArrayLike(Uint8Array,"be",32);return e.set(i),0},publicKeyVerify:e=>null===n(e)?1:0,publicKeyCreate(n,o){const s=new r(o);if(s.cmp(t.n)>=0||s.isZero())return 1;return i(n,e.keyFromPrivate(o).getPublic()),0},publicKeyConvert(e,t){const r=n(t);if(null===r)return 1;return i(e,r.getPublic()),0},publicKeyNegate(e,t){const r=n(t);if(null===r)return 1;const o=r.getPublic();return o.y=o.y.redNeg(),i(e,o),0},publicKeyCombine(e,t){const r=new Array(t.length);for(let e=0;e<t.length;++e)if(r[e]=n(t[e]),null===r[e])return 1;let o=r[0].getPublic();for(let e=1;e<r.length;++e)o=o.add(r[e].pub);return o.isInfinity()?2:(i(e,o),0)},publicKeyTweakAdd(e,o,s){const a=n(o);if(null===a)return 1;if((s=new r(s)).cmp(t.n)>=0)return 2;const c=a.getPublic().add(t.g.mul(s));return c.isInfinity()?2:(i(e,c),0)},publicKeyTweakMul(e,o,s){const a=n(o);if(null===a)return 1;if((s=new r(s)).cmp(t.n)>=0||s.isZero())return 2;return i(e,a.getPublic().mul(s)),0},signatureNormalize(n){const o=new r(n.subarray(0,32)),i=new r(n.subarray(32,64));return o.cmp(t.n)>=0||i.cmp(t.n)>=0?1:(1===i.cmp(e.nh)&&n.set(t.n.sub(i).toArrayLike(Uint8Array,"be",32),32),0)},signatureExport(e,n){const o=n.subarray(0,32),i=n.subarray(32,64);if(new r(o).cmp(t.n)>=0)return 1;if(new r(i).cmp(t.n)>=0)return 1;const{output:s}=e;let a=s.subarray(4,37);a[0]=0,a.set(o,1);let c=33,u=0;for(;c>1&&0===a[u]&&!(128&a[u+1]);--c,++u);if(a=a.subarray(u),128&a[0])return 1;if(c>1&&0===a[0]&&!(128&a[1]))return 1;let l=s.subarray(39,72);l[0]=0,l.set(i,1);let f=33,p=0;for(;f>1&&0===l[p]&&!(128&l[p+1]);--f,++p);return l=l.subarray(p),128&l[0]||f>1&&0===l[0]&&!(128&l[1])?1:(e.outputlen=6+c+f,s[0]=48,s[1]=e.outputlen-2,s[2]=2,s[3]=a.length,s.set(a,4),s[4+c]=2,s[5+c]=l.length,s.set(l,6+c),0)},signatureImport(e,n){if(n.length<8)return 1;if(n.length>72)return 1;if(48!==n[0])return 1;if(n[1]!==n.length-2)return 1;if(2!==n[2])return 1;const o=n[3];if(0===o)return 1;if(5+o>=n.length)return 1;if(2!==n[4+o])return 1;const i=n[5+o];if(0===i)return 1;if(6+o+i!==n.length)return 1;if(128&n[4])return 1;if(o>1&&0===n[4]&&!(128&n[5]))return 1;if(128&n[o+6])return 1;if(i>1&&0===n[o+6]&&!(128&n[o+7]))return 1;let s=n.subarray(4,4+o);if(33===s.length&&0===s[0]&&(s=s.subarray(1)),s.length>32)return 1;let a=n.subarray(6+o);if(33===a.length&&0===a[0]&&(a=a.slice(1)),a.length>32)throw new Error("S length is too long");let c=new r(s);c.cmp(t.n)>=0&&(c=new r(0));let u=new r(n.subarray(6+o));return u.cmp(t.n)>=0&&(u=new r(0)),e.set(c.toArrayLike(Uint8Array,"be",32),0),e.set(u.toArrayLike(Uint8Array,"be",32),32),0},ecdsaSign(n,o,i,s,a){if(a){const e=a;a=t=>{const n=e(o,i,null,s,t);if(!(n instanceof Uint8Array&&32===n.length))throw new Error("This is the way");return new r(n)}}const c=new r(i);if(c.cmp(t.n)>=0||c.isZero())return 1;let u;try{u=e.sign(o,i,{canonical:!0,k:a,pers:s})}catch(e){return 1}return n.signature.set(u.r.toArrayLike(Uint8Array,"be",32),0),n.signature.set(u.s.toArrayLike(Uint8Array,"be",32),32),n.recid=u.recoveryParam,0},ecdsaVerify(o,i,s){const a={r:o.subarray(0,32),s:o.subarray(32,64)},c=new r(a.r),u=new r(a.s);if(c.cmp(t.n)>=0||u.cmp(t.n)>=0)return 1;if(1===u.cmp(e.nh)||c.isZero()||u.isZero())return 3;const l=n(s);if(null===l)return 2;const f=l.getPublic();return e.verify(i,a,f)?0:3},ecdsaRecover(n,o,s,a){const c={r:o.slice(0,32),s:o.slice(32,64)},u=new r(c.r),l=new r(c.s);if(u.cmp(t.n)>=0||l.cmp(t.n)>=0)return 1;if(u.isZero()||l.isZero())return 2;let f;try{f=e.recoverPubKey(a,c,s)}catch(e){return 2}return i(n,f),0},ecdh(o,i,s,a,c,u,l){const f=n(i);if(null===f)return 1;const p=new r(s);if(p.cmp(t.n)>=0||p.isZero())return 2;const d=f.getPublic().mul(p);if(void 0===c){const t=d.encode(null,!0),r=e.hash().update(t).digest();for(let e=0;e<32;++e)o[e]=r[e]}else{u||(u=new Uint8Array(32));const e=d.getX().toArray("be",32);for(let t=0;t<32;++t)u[t]=e[t];l||(l=new Uint8Array(32));const t=d.getY().toArray("be",32);for(let e=0;e<32;++e)l[e]=t[e];const r=c(u,l,a);if(!(r instanceof Uint8Array&&r.length===o.length))return 2;o.set(r)}return 0}}}var it=(rt||(rt=1,tt=function(){if(We)return Xe;We=1;const e="Impossible case. Please create issue.",t="The tweak was out of range or the resulted private key is invalid",r="The tweak was out of range or equal to zero",n="Unknow error on context randomization",o="Private Key is invalid",i="Public Key could not be parsed",s="Public Key serialization error",a="The sum of the public keys is not valid",c="Signature could not be parsed",u="The nonce generation function failed, or the private key was invalid",l="Public key could not be recover",f="Scalar was invalid (zero or overflow)";function p(e,t){if(!e)throw new Error(t)}function d(e,t,r){if(p(t instanceof Uint8Array,`Expected ${e} to be an Uint8Array`),void 0!==r)if(Array.isArray(r)){const n=`Expected ${e} to be an Uint8Array with length [${r.join(", ")}]`;p(r.includes(t.length),n)}else{const n=`Expected ${e} to be an Uint8Array with length ${r}`;p(t.length===r,n)}}function h(e){p("Boolean"===b(e),"Expected compressed to be a Boolean")}function y(e=e=>new Uint8Array(e),t){return"function"==typeof e&&(e=e(t)),d("output",e,t),e}function b(e){return Object.prototype.toString.call(e).slice(8,-1)}return Xe=w=>({contextRandomize(e){if(p(null===e||e instanceof Uint8Array,"Expected seed to be an Uint8Array or null"),null!==e&&d("seed",e,32),1===w.contextRandomize(e))throw new Error(n)},privateKeyVerify:e=>(d("private key",e,32),0===w.privateKeyVerify(e)),privateKeyNegate(t){switch(d("private key",t,32),w.privateKeyNegate(t)){case 0:return t;case 1:throw new Error(e)}},privateKeyTweakAdd(e,r){switch(d("private key",e,32),d("tweak",r,32),w.privateKeyTweakAdd(e,r)){case 0:return e;case 1:throw new Error(t)}},privateKeyTweakMul(e,t){switch(d("private key",e,32),d("tweak",t,32),w.privateKeyTweakMul(e,t)){case 0:return e;case 1:throw new Error(r)}},publicKeyVerify:e=>(d("public key",e,[33,65]),0===w.publicKeyVerify(e)),publicKeyCreate(e,t=!0,r){switch(d("private key",e,32),h(t),r=y(r,t?33:65),w.publicKeyCreate(r,e)){case 0:return r;case 1:throw new Error(o);case 2:throw new Error(s)}},publicKeyConvert(e,t=!0,r){switch(d("public key",e,[33,65]),h(t),r=y(r,t?33:65),w.publicKeyConvert(r,e)){case 0:return r;case 1:throw new Error(i);case 2:throw new Error(s)}},publicKeyNegate(t,r=!0,n){switch(d("public key",t,[33,65]),h(r),n=y(n,r?33:65),w.publicKeyNegate(n,t)){case 0:return n;case 1:throw new Error(i);case 2:throw new Error(e);case 3:throw new Error(s)}},publicKeyCombine(e,t=!0,r){p(Array.isArray(e),"Expected public keys to be an Array"),p(e.length>0,"Expected public keys array will have more than zero items");for(const t of e)d("public key",t,[33,65]);switch(h(t),r=y(r,t?33:65),w.publicKeyCombine(r,e)){case 0:return r;case 1:throw new Error(i);case 2:throw new Error(a);case 3:throw new Error(s)}},publicKeyTweakAdd(e,r,n=!0,o){switch(d("public key",e,[33,65]),d("tweak",r,32),h(n),o=y(o,n?33:65),w.publicKeyTweakAdd(o,e,r)){case 0:return o;case 1:throw new Error(i);case 2:throw new Error(t)}},publicKeyTweakMul(e,t,n=!0,o){switch(d("public key",e,[33,65]),d("tweak",t,32),h(n),o=y(o,n?33:65),w.publicKeyTweakMul(o,e,t)){case 0:return o;case 1:throw new Error(i);case 2:throw new Error(r)}},signatureNormalize(e){switch(d("signature",e,64),w.signatureNormalize(e)){case 0:return e;case 1:throw new Error(c)}},signatureExport(t,r){d("signature",t,64);const n={output:r=y(r,72),outputlen:72};switch(w.signatureExport(n,t)){case 0:return r.slice(0,n.outputlen);case 1:throw new Error(c);case 2:throw new Error(e)}},signatureImport(t,r){switch(d("signature",t),r=y(r,64),w.signatureImport(r,t)){case 0:return r;case 1:throw new Error(c);case 2:throw new Error(e)}},ecdsaSign(t,r,n={},o){d("message",t,32),d("private key",r,32),p("Object"===b(n),"Expected options to be an Object"),void 0!==n.data&&d("options.data",n.data),void 0!==n.noncefn&&p("Function"===b(n.noncefn),"Expected options.noncefn to be a Function");const i={signature:o=y(o,64),recid:null};switch(w.ecdsaSign(i,t,r,n.data,n.noncefn)){case 0:return i;case 1:throw new Error(u);case 2:throw new Error(e)}},ecdsaVerify(e,t,r){switch(d("signature",e,64),d("message",t,32),d("public key",r,[33,65]),w.ecdsaVerify(e,t,r)){case 0:return!0;case 3:return!1;case 1:throw new Error(c);case 2:throw new Error(i)}},ecdsaRecover(t,r,n,o=!0,i){switch(d("signature",t,64),p("Number"===b(r)&&r>=0&&r<=3,"Expected recovery id to be a Number within interval [0, 3]"),d("message",n,32),h(o),i=y(i,o?33:65),w.ecdsaRecover(i,t,r,n)){case 0:return i;case 1:throw new Error(c);case 2:throw new Error(l);case 3:throw new Error(e)}},ecdh(e,t,r={},n){switch(d("public key",e,[33,65]),d("private key",t,32),p("Object"===b(r),"Expected options to be an Object"),void 0!==r.data&&d("options.data",r.data),void 0!==r.hashfn?(p("Function"===b(r.hashfn),"Expected options.hashfn to be a Function"),void 0!==r.xbuf&&d("options.xbuf",r.xbuf,32),void 0!==r.ybuf&&d("options.ybuf",r.ybuf,32),d("output",n)):n=y(n,32),w.ecdh(n,e,t,r.data,r.hashfn,r.xbuf,r.ybuf)){case 0:return n;case 1:throw new Error(i);case 2:throw new Error(f)}}}),Xe}()(ot())),tt),st=e(it);export{nt as b,it as e,He as k,$e as r,st as s};
|
|
1
|
+
import{g as e,i as t,B as r,p as n}from"./main.js";import{r as o,c as i,b as s,d as a,a as c}from"./elliptic-mDX7fQQx-BpaNaVm0.js";var u,l,f,p,d,h,y,b;function w(){if(l)return u;l=1;class e extends Error{constructor(e){super(e||"This operation is not supported for this key type")}}return u=e}function g(){if(p)return f;p=1;class e extends Error{constructor(){super("This has not been implemented yet")}}return f=e}function m(){if(b)return y;b=1;const e=g();return y=class{constructor(e){this.params=e}fromPrivatePKCS1(t){throw new e}fromPrivatePKCS8(t){throw new e}fromPublicPKCS1(t){throw new e}fromPublicPKCS8(t){throw new e}fromPrivateBlk(t){throw new e}fromPublicBlk(t){throw new e}fromJwk(t){throw new e}toPrivatePKCS1(t){throw new e}toPrivatePKCS8(t){throw new e}toPublicPKCS1(t){throw new e}toPublicPKCS8(t){throw new e}toPrivateBlk(t){throw new e}toPublicBlk(t){throw new e}toPrivateJwk(t){throw new e}toPublicJwk(t){throw new e}static formatPem(e,t){return`-----BEGIN ${t} KEY-----\n`+e.match(/.{1,64}/g).join("\n")+`\n-----END ${t} KEY-----`}}}var v,k,_={},P={},E={};function S(){if(k)return v;k=1;var e,t=c,r=t.Buffer,o={};for(e in t)t.hasOwnProperty(e)&&"SlowBuffer"!==e&&"Buffer"!==e&&(o[e]=t[e]);var i=o.Buffer={};for(e in r)r.hasOwnProperty(e)&&"allocUnsafe"!==e&&"allocUnsafeSlow"!==e&&(i[e]=r[e]);if(o.Buffer.prototype=r.prototype,i.from&&i.from!==Uint8Array.from||(i.from=function(e,t,n){if("number"==typeof e)throw new TypeError('The "value" argument must not be of type number. Received type '+typeof e);if(e&&void 0===e.length)throw new TypeError("The first argument must be one of type string, Buffer, ArrayBuffer, Array, or Array-like Object. Received type "+typeof e);return r(e,t,n)}),i.alloc||(i.alloc=function(e,t,n){if("number"!=typeof e)throw new TypeError('The "size" argument must be of type number. Received type '+typeof e);if(e<0||e>=2*(1<<30))throw new RangeError('The value "'+e+'" is invalid for option "size"');var o=r(e);return t&&0!==t.length?"string"==typeof n?o.fill(t,n):o.fill(t):o.fill(0),o}),!o.kStringMaxLength)try{o.kStringMaxLength=n.binding("buffer").kStringMaxLength}catch(e){}return o.constants||(o.constants={MAX_LENGTH:o.kMaxLength},o.kStringMaxLength&&(o.constants.MAX_STRING_LENGTH=o.kStringMaxLength)),v=o}var K,A={};function x(){if(K)return A;K=1;const e=s();function t(e){this._reporterState={obj:null,path:[],options:e||{},errors:[]}}function r(e,t){this.path=e,this.rethrow(t)}return A.Reporter=t,t.prototype.isError=function(e){return e instanceof r},t.prototype.save=function(){const e=this._reporterState;return{obj:e.obj,pathLen:e.path.length}},t.prototype.restore=function(e){const t=this._reporterState;t.obj=e.obj,t.path=t.path.slice(0,e.pathLen)},t.prototype.enterKey=function(e){return this._reporterState.path.push(e)},t.prototype.exitKey=function(e){const t=this._reporterState;t.path=t.path.slice(0,e-1)},t.prototype.leaveKey=function(e,t,r){const n=this._reporterState;this.exitKey(e),null!==n.obj&&(n.obj[t]=r)},t.prototype.path=function(){return this._reporterState.path.join("/")},t.prototype.enterObject=function(){const e=this._reporterState,t=e.obj;return e.obj={},t},t.prototype.leaveObject=function(e){const t=this._reporterState,r=t.obj;return t.obj=e,r},t.prototype.error=function(e){let t;const n=this._reporterState,o=e instanceof r;if(t=o?e:new r(n.path.map((function(e){return"["+JSON.stringify(e)+"]"})).join(""),e.message||e,e.stack),!n.options.partial)throw t;return o||n.errors.push(t),t},t.prototype.wrapResult=function(e){const t=this._reporterState;return t.options.partial?{result:this.isError(e)?null:e,errors:t.errors}:e},e(r,Error),r.prototype.rethrow=function(e){if(this.message=e+" at: "+(this.path||"(shallow)"),Error.captureStackTrace&&Error.captureStackTrace(this,r),!this.stack)try{throw new Error(this.message)}catch(e){this.stack=e.stack}return this},A}var C,j,B,I={};function U(){if(C)return I;C=1;const e=s(),t=x().Reporter,r=S().Buffer;function n(e,n){t.call(this,n),r.isBuffer(e)?(this.base=e,this.offset=0,this.length=e.length):this.error("Input not Buffer")}function o(e,t){if(Array.isArray(e))this.length=0,this.value=e.map((function(e){return o.isEncoderBuffer(e)||(e=new o(e,t)),this.length+=e.length,e}),this);else if("number"==typeof e){if(!(0<=e&&e<=255))return t.error("non-byte EncoderBuffer value");this.value=e,this.length=1}else if("string"==typeof e)this.value=e,this.length=r.byteLength(e);else{if(!r.isBuffer(e))return t.error("Unsupported type: "+typeof e);this.value=e,this.length=e.length}}return e(n,t),I.DecoderBuffer=n,n.isDecoderBuffer=function(e){if(e instanceof n)return!0;return"object"==typeof e&&r.isBuffer(e.base)&&"DecoderBuffer"===e.constructor.name&&"number"==typeof e.offset&&"number"==typeof e.length&&"function"==typeof e.save&&"function"==typeof e.restore&&"function"==typeof e.isEmpty&&"function"==typeof e.readUInt8&&"function"==typeof e.skip&&"function"==typeof e.raw},n.prototype.save=function(){return{offset:this.offset,reporter:t.prototype.save.call(this)}},n.prototype.restore=function(e){const r=new n(this.base);return r.offset=e.offset,r.length=this.offset,this.offset=e.offset,t.prototype.restore.call(this,e.reporter),r},n.prototype.isEmpty=function(){return this.offset===this.length},n.prototype.readUInt8=function(e){return this.offset+1<=this.length?this.base.readUInt8(this.offset++,!0):this.error(e||"DecoderBuffer overrun")},n.prototype.skip=function(e,t){if(!(this.offset+e<=this.length))return this.error(t||"DecoderBuffer overrun");const r=new n(this.base);return r._reporterState=this._reporterState,r.offset=this.offset,r.length=this.offset+e,this.offset+=e,r},n.prototype.raw=function(e){return this.base.slice(e?e.offset:this.offset,this.length)},I.EncoderBuffer=o,o.isEncoderBuffer=function(e){if(e instanceof o)return!0;return"object"==typeof e&&"EncoderBuffer"===e.constructor.name&&"number"==typeof e.length&&"function"==typeof e.join},o.prototype.join=function(e,t){return e||(e=r.alloc(this.length)),t||(t=0),0===this.length||(Array.isArray(this.value)?this.value.forEach((function(r){r.join(e,t),t+=r.length})):("number"==typeof this.value?e[t]=this.value:"string"==typeof this.value?e.write(this.value,t):r.isBuffer(this.value)&&this.value.copy(e,t),t+=this.length)),e},I}function q(){if(B)return j;B=1;const e=x().Reporter,t=U().EncoderBuffer,r=U().DecoderBuffer,n=a(),o=["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"],i=["key","obj","use","optional","explicit","implicit","def","choice","any","contains"].concat(o);function s(e,t,r){const n={};this._baseState=n,n.name=r,n.enc=e,n.parent=t||null,n.children=null,n.tag=null,n.args=null,n.reverseArgs=null,n.choice=null,n.optional=!1,n.any=!1,n.obj=!1,n.use=null,n.useDecoder=null,n.key=null,n.default=null,n.explicit=null,n.implicit=null,n.contains=null,n.parent||(n.children=[],this._wrap())}j=s;const c=["enc","parent","children","tag","args","reverseArgs","choice","optional","any","obj","use","alteredUse","key","default","explicit","implicit","contains"];return s.prototype.clone=function(){const e=this._baseState,t={};c.forEach((function(r){t[r]=e[r]}));const r=new this.constructor(t.parent);return r._baseState=t,r},s.prototype._wrap=function(){const e=this._baseState;i.forEach((function(t){this[t]=function(){const r=new this.constructor(this);return e.children.push(r),r[t].apply(r,arguments)}}),this)},s.prototype._init=function(e){const t=this._baseState;n(null===t.parent),e.call(this),t.children=t.children.filter((function(e){return e._baseState.parent===this}),this),n.equal(t.children.length,1,"Root node can have only one child")},s.prototype._useArgs=function(e){const t=this._baseState,r=e.filter((function(e){return e instanceof this.constructor}),this);e=e.filter((function(e){return!(e instanceof this.constructor)}),this),0!==r.length&&(n(null===t.children),t.children=r,r.forEach((function(e){e._baseState.parent=this}),this)),0!==e.length&&(n(null===t.args),t.args=e,t.reverseArgs=e.map((function(e){if("object"!=typeof e||e.constructor!==Object)return e;const t={};return Object.keys(e).forEach((function(r){r==(0|r)&&(r|=0);const n=e[r];t[n]=r})),t})))},["_peekTag","_decodeTag","_use","_decodeStr","_decodeObjid","_decodeTime","_decodeNull","_decodeInt","_decodeBool","_decodeList","_encodeComposite","_encodeStr","_encodeObjid","_encodeTime","_encodeNull","_encodeInt","_encodeBool"].forEach((function(e){s.prototype[e]=function(){const t=this._baseState;throw new Error(e+" not implemented for encoding: "+t.enc)}})),o.forEach((function(e){s.prototype[e]=function(){const t=this._baseState,r=Array.prototype.slice.call(arguments);return n(null===t.tag),t.tag=e,this._useArgs(r),this}})),s.prototype.use=function(e){n(e);const t=this._baseState;return n(null===t.use),t.use=e,this},s.prototype.optional=function(){return this._baseState.optional=!0,this},s.prototype.def=function(e){const t=this._baseState;return n(null===t.default),t.default=e,t.optional=!0,this},s.prototype.explicit=function(e){const t=this._baseState;return n(null===t.explicit&&null===t.implicit),t.explicit=e,this},s.prototype.implicit=function(e){const t=this._baseState;return n(null===t.explicit&&null===t.implicit),t.implicit=e,this},s.prototype.obj=function(){const e=this._baseState,t=Array.prototype.slice.call(arguments);return e.obj=!0,0!==t.length&&this._useArgs(t),this},s.prototype.key=function(e){const t=this._baseState;return n(null===t.key),t.key=e,this},s.prototype.any=function(){return this._baseState.any=!0,this},s.prototype.choice=function(e){const t=this._baseState;return n(null===t.choice),t.choice=e,this._useArgs(Object.keys(e).map((function(t){return e[t]}))),this},s.prototype.contains=function(e){const t=this._baseState;return n(null===t.use),t.contains=e,this},s.prototype._decode=function(e,t){const n=this._baseState;if(null===n.parent)return e.wrapResult(n.children[0]._decode(e,t));let o,i=n.default,s=!0,a=null;if(null!==n.key&&(a=e.enterKey(n.key)),n.optional){let r=null;if(null!==n.explicit?r=n.explicit:null!==n.implicit?r=n.implicit:null!==n.tag&&(r=n.tag),null!==r||n.any){if(s=this._peekTag(e,r,n.any),e.isError(s))return s}else{const r=e.save();try{null===n.choice?this._decodeGeneric(n.tag,e,t):this._decodeChoice(e,t),s=!0}catch(e){s=!1}e.restore(r)}}if(n.obj&&s&&(o=e.enterObject()),s){if(null!==n.explicit){const t=this._decodeTag(e,n.explicit);if(e.isError(t))return t;e=t}const o=e.offset;if(null===n.use&&null===n.choice){let t;n.any&&(t=e.save());const r=this._decodeTag(e,null!==n.implicit?n.implicit:n.tag,n.any);if(e.isError(r))return r;n.any?i=e.raw(t):e=r}if(t&&t.track&&null!==n.tag&&t.track(e.path(),o,e.length,"tagged"),t&&t.track&&null!==n.tag&&t.track(e.path(),e.offset,e.length,"content"),n.any||(i=null===n.choice?this._decodeGeneric(n.tag,e,t):this._decodeChoice(e,t)),e.isError(i))return i;if(n.any||null!==n.choice||null===n.children||n.children.forEach((function(r){r._decode(e,t)})),n.contains&&("octstr"===n.tag||"bitstr"===n.tag)){const o=new r(i);i=this._getUse(n.contains,e._reporterState.obj)._decode(o,t)}}return n.obj&&s&&(i=e.leaveObject(o)),null===n.key||null===i&&!0!==s?null!==a&&e.exitKey(a):e.leaveKey(a,n.key,i),i},s.prototype._decodeGeneric=function(e,t,r){const n=this._baseState;return"seq"===e||"set"===e?null:"seqof"===e||"setof"===e?this._decodeList(t,e,n.args[0],r):/str$/.test(e)?this._decodeStr(t,e,r):"objid"===e&&n.args?this._decodeObjid(t,n.args[0],n.args[1],r):"objid"===e?this._decodeObjid(t,null,null,r):"gentime"===e||"utctime"===e?this._decodeTime(t,e,r):"null_"===e?this._decodeNull(t,r):"bool"===e?this._decodeBool(t,r):"objDesc"===e?this._decodeStr(t,e,r):"int"===e||"enum"===e?this._decodeInt(t,n.args&&n.args[0],r):null!==n.use?this._getUse(n.use,t._reporterState.obj)._decode(t,r):t.error("unknown tag: "+e)},s.prototype._getUse=function(e,t){const r=this._baseState;return r.useDecoder=this._use(e,t),n(null===r.useDecoder._baseState.parent),r.useDecoder=r.useDecoder._baseState.children[0],r.implicit!==r.useDecoder._baseState.implicit&&(r.useDecoder=r.useDecoder.clone(),r.useDecoder._baseState.implicit=r.implicit),r.useDecoder},s.prototype._decodeChoice=function(e,t){const r=this._baseState;let n=null,o=!1;return Object.keys(r.choice).some((function(i){const s=e.save(),a=r.choice[i];try{const r=a._decode(e,t);if(e.isError(r))return!1;n={type:i,value:r},o=!0}catch(t){return e.restore(s),!1}return!0}),this),o?n:e.error("Choice not matched")},s.prototype._createEncoderBuffer=function(e){return new t(e,this.reporter)},s.prototype._encode=function(e,t,r){const n=this._baseState;if(null!==n.default&&n.default===e)return;const o=this._encodeValue(e,t,r);return void 0===o||this._skipDefault(o,t,r)?void 0:o},s.prototype._encodeValue=function(t,r,n){const o=this._baseState;if(null===o.parent)return o.children[0]._encode(t,r||new e);let i=null;if(this.reporter=r,o.optional&&void 0===t){if(null===o.default)return;t=o.default}let s=null,a=!1;if(o.any)i=this._createEncoderBuffer(t);else if(o.choice)i=this._encodeChoice(t,r);else if(o.contains)s=this._getUse(o.contains,n)._encode(t,r),a=!0;else if(o.children)s=o.children.map((function(e){if("null_"===e._baseState.tag)return e._encode(null,r,t);if(null===e._baseState.key)return r.error("Child should have a key");const n=r.enterKey(e._baseState.key);if("object"!=typeof t)return r.error("Child expected, but input is not object");const o=e._encode(t[e._baseState.key],r,t);return r.leaveKey(n),o}),this).filter((function(e){return e})),s=this._createEncoderBuffer(s);else if("seqof"===o.tag||"setof"===o.tag){if(!o.args||1!==o.args.length)return r.error("Too many args for : "+o.tag);if(!Array.isArray(t))return r.error("seqof/setof, but data is not Array");const e=this.clone();e._baseState.implicit=null,s=this._createEncoderBuffer(t.map((function(e){const n=this._baseState;return this._getUse(n.args[0],t)._encode(e,r)}),e))}else null!==o.use?i=this._getUse(o.use,n)._encode(t,r):(s=this._encodePrimitive(o.tag,t),a=!0);if(!o.any&&null===o.choice){const e=null!==o.implicit?o.implicit:o.tag,t=null===o.implicit?"universal":"context";null===e?null===o.use&&r.error("Tag could be omitted only for .use()"):null===o.use&&(i=this._encodeComposite(e,a,t,s))}return null!==o.explicit&&(i=this._encodeComposite(o.explicit,!1,"context",i)),i},s.prototype._encodeChoice=function(e,t){const r=this._baseState,o=r.choice[e.type];return o||n(!1,e.type+" not found in "+JSON.stringify(Object.keys(r.choice))),o._encode(e.value,t)},s.prototype._encodePrimitive=function(e,t){const r=this._baseState;if(/str$/.test(e))return this._encodeStr(t,e);if("objid"===e&&r.args)return this._encodeObjid(t,r.reverseArgs[0],r.args[1]);if("objid"===e)return this._encodeObjid(t,null,null);if("gentime"===e||"utctime"===e)return this._encodeTime(t,e);if("null_"===e)return this._encodeNull();if("int"===e||"enum"===e)return this._encodeInt(t,r.args&&r.reverseArgs[0]);if("bool"===e)return this._encodeBool(t);if("objDesc"===e)return this._encodeStr(t,e);throw new Error("Unsupported tag: "+e)},s.prototype._isNumstr=function(e){return/^[0-9 ]*$/.test(e)},s.prototype._isPrintstr=function(e){return/^[A-Za-z0-9 '()+,-./:=?]*$/.test(e)},j}var T,N,z,O,R,D,V={};function M(){return T||(T=1,function(e){function t(e){const t={};return Object.keys(e).forEach((function(r){(0|r)==r&&(r|=0);const n=e[r];t[n]=r})),t}e.tagClass={0:"universal",1:"application",2:"context",3:"private"},e.tagClassByName=t(e.tagClass),e.tag={0:"end",1:"bool",2:"int",3:"bitstr",4:"octstr",5:"null_",6:"objid",7:"objDesc",8:"external",9:"real",10:"enum",11:"embed",12:"utf8str",13:"relativeOid",16:"seq",17:"set",18:"numstr",19:"printstr",20:"t61str",21:"videostr",22:"ia5str",23:"utctime",24:"gentime",25:"graphstr",26:"iso646str",27:"genstr",28:"unistr",29:"charstr",30:"bmpstr"},e.tagByName=t(e.tag)}(V)),V}function L(){if(z)return N;z=1;const e=s(),t=S().Buffer,r=q(),n=M();function o(e){this.enc="der",this.name=e.name,this.entity=e,this.tree=new i,this.tree._init(e.body)}function i(e){r.call(this,"der",e)}function a(e){return e<10?"0"+e:e}return N=o,o.prototype.encode=function(e,t){return this.tree._encode(e,t).join()},e(i,r),i.prototype._encodeComposite=function(e,r,o,i){const s=function(e,t,r,o){let i;"seqof"===e?e="seq":"setof"===e&&(e="set");if(n.tagByName.hasOwnProperty(e))i=n.tagByName[e];else{if("number"!=typeof e||(0|e)!==e)return o.error("Unknown tag: "+e);i=e}if(i>=31)return o.error("Multi-octet tag encoding unsupported");t||(i|=32);return i|=n.tagClassByName[r||"universal"]<<6,i}(e,r,o,this.reporter);if(i.length<128){const e=t.alloc(2);return e[0]=s,e[1]=i.length,this._createEncoderBuffer([e,i])}let a=1;for(let e=i.length;e>=256;e>>=8)a++;const c=t.alloc(2+a);c[0]=s,c[1]=128|a;for(let e=1+a,t=i.length;t>0;e--,t>>=8)c[e]=255&t;return this._createEncoderBuffer([c,i])},i.prototype._encodeStr=function(e,r){if("bitstr"===r)return this._createEncoderBuffer([0|e.unused,e.data]);if("bmpstr"===r){const r=t.alloc(2*e.length);for(let t=0;t<e.length;t++)r.writeUInt16BE(e.charCodeAt(t),2*t);return this._createEncoderBuffer(r)}return"numstr"===r?this._isNumstr(e)?this._createEncoderBuffer(e):this.reporter.error("Encoding of string type: numstr supports only digits and space"):"printstr"===r?this._isPrintstr(e)?this._createEncoderBuffer(e):this.reporter.error("Encoding of string type: printstr supports only latin upper and lower case letters, digits, space, apostrophe, left and rigth parenthesis, plus sign, comma, hyphen, dot, slash, colon, equal sign, question mark"):/str$/.test(r)||"objDesc"===r?this._createEncoderBuffer(e):this.reporter.error("Encoding of string type: "+r+" unsupported")},i.prototype._encodeObjid=function(e,r,n){if("string"==typeof e){if(!r)return this.reporter.error("string objid given, but no values map found");if(!r.hasOwnProperty(e))return this.reporter.error("objid not found in values map");e=r[e].split(/[\s.]+/g);for(let t=0;t<e.length;t++)e[t]|=0}else if(Array.isArray(e)){e=e.slice();for(let t=0;t<e.length;t++)e[t]|=0}if(!Array.isArray(e))return this.reporter.error("objid() should be either array or string, got: "+JSON.stringify(e));if(!n){if(e[1]>=40)return this.reporter.error("Second objid identifier OOB");e.splice(0,2,40*e[0]+e[1])}let o=0;for(let t=0;t<e.length;t++){let r=e[t];for(o++;r>=128;r>>=7)o++}const i=t.alloc(o);let s=i.length-1;for(let t=e.length-1;t>=0;t--){let r=e[t];for(i[s--]=127&r;(r>>=7)>0;)i[s--]=128|127&r}return this._createEncoderBuffer(i)},i.prototype._encodeTime=function(e,t){let r;const n=new Date(e);return"gentime"===t?r=[a(n.getUTCFullYear()),a(n.getUTCMonth()+1),a(n.getUTCDate()),a(n.getUTCHours()),a(n.getUTCMinutes()),a(n.getUTCSeconds()),"Z"].join(""):"utctime"===t?r=[a(n.getUTCFullYear()%100),a(n.getUTCMonth()+1),a(n.getUTCDate()),a(n.getUTCHours()),a(n.getUTCMinutes()),a(n.getUTCSeconds()),"Z"].join(""):this.reporter.error("Encoding "+t+" time is not supported yet"),this._encodeStr(r,"octstr")},i.prototype._encodeNull=function(){return this._createEncoderBuffer("")},i.prototype._encodeInt=function(e,r){if("string"==typeof e){if(!r)return this.reporter.error("String int or enum given, but no values map");if(!r.hasOwnProperty(e))return this.reporter.error("Values map doesn't contain: "+JSON.stringify(e));e=r[e]}if("number"!=typeof e&&!t.isBuffer(e)){const r=e.toArray();!e.sign&&128&r[0]&&r.unshift(0),e=t.from(r)}if(t.isBuffer(e)){let r=e.length;0===e.length&&r++;const n=t.alloc(r);return e.copy(n),0===e.length&&(n[0]=0),this._createEncoderBuffer(n)}if(e<128)return this._createEncoderBuffer(e);if(e<256)return this._createEncoderBuffer([0,e]);let n=1;for(let t=e;t>=256;t>>=8)n++;const o=new Array(n);for(let t=o.length-1;t>=0;t--)o[t]=255&e,e>>=8;return 128&o[0]&&o.unshift(0),this._createEncoderBuffer(t.from(o))},i.prototype._encodeBool=function(e){return this._createEncoderBuffer(e?255:0)},i.prototype._use=function(e,t){return"function"==typeof e&&(e=e(t)),e._getEncoder("der").tree},i.prototype._skipDefault=function(e,t,r){const n=this._baseState;let o;if(null===n.default)return!1;const i=e.join();if(void 0===n.defaultBuffer&&(n.defaultBuffer=this._encodeValue(n.default,t,r).join()),i.length!==n.defaultBuffer.length)return!1;for(o=0;o<i.length;o++)if(i[o]!==n.defaultBuffer[o])return!1;return!0},N}function J(){return D||(D=1,function(e){const t=e;t.der=L(),t.pem=function(){if(R)return O;R=1;const e=s(),t=L();function r(e){t.call(this,e),this.enc="pem"}return e(r,t),O=r,r.prototype.encode=function(e,r){const n=t.prototype.encode.call(this,e).toString("base64"),o=["-----BEGIN "+r.label+"-----"];for(let e=0;e<n.length;e+=64)o.push(n.slice(e,e+64));return o.push("-----END "+r.label+"-----"),o.join("\n")},O}()}(E)),E}var $,F,Z,G,Y,X,H={};function W(){if(F)return $;F=1;const e=s(),t=i(),r=U().DecoderBuffer,n=q(),o=M();function a(e){this.enc="der",this.name=e.name,this.entity=e,this.tree=new c,this.tree._init(e.body)}function c(e){n.call(this,"der",e)}function u(e,t){let r=e.readUInt8(t);if(e.isError(r))return r;const n=o.tagClass[r>>6],i=!(32&r);if(31&~r)r&=31;else{let n=r;for(r=0;!(128&~n);){if(n=e.readUInt8(t),e.isError(n))return n;r<<=7,r|=127&n}}return{cls:n,primitive:i,tag:r,tagStr:o.tag[r]}}function l(e,t,r){let n=e.readUInt8(r);if(e.isError(n))return n;if(!t&&128===n)return null;if(!(128&n))return n;const o=127&n;if(o>4)return e.error("length octect is too long");n=0;for(let t=0;t<o;t++){n<<=8;const t=e.readUInt8(r);if(e.isError(t))return t;n|=t}return n}return $=a,a.prototype.decode=function(e,t){return r.isDecoderBuffer(e)||(e=new r(e,t)),this.tree._decode(e,t)},e(c,n),c.prototype._peekTag=function(e,t,r){if(e.isEmpty())return!1;const n=e.save(),o=u(e,'Failed to peek tag: "'+t+'"');return e.isError(o)?o:(e.restore(n),o.tag===t||o.tagStr===t||o.tagStr+"of"===t||r)},c.prototype._decodeTag=function(e,t,r){const n=u(e,'Failed to decode tag of "'+t+'"');if(e.isError(n))return n;let o=l(e,n.primitive,'Failed to get length of "'+t+'"');if(e.isError(o))return o;if(!r&&n.tag!==t&&n.tagStr!==t&&n.tagStr+"of"!==t)return e.error('Failed to match tag: "'+t+'"');if(n.primitive||null!==o)return e.skip(o,'Failed to match body of: "'+t+'"');const i=e.save(),s=this._skipUntilEnd(e,'Failed to skip indefinite length body: "'+this.tag+'"');return e.isError(s)?s:(o=e.offset-i.offset,e.restore(i),e.skip(o,'Failed to match body of: "'+t+'"'))},c.prototype._skipUntilEnd=function(e,t){for(;;){const r=u(e,t);if(e.isError(r))return r;const n=l(e,r.primitive,t);if(e.isError(n))return n;let o;if(o=r.primitive||null!==n?e.skip(n):this._skipUntilEnd(e,t),e.isError(o))return o;if("end"===r.tagStr)break}},c.prototype._decodeList=function(e,t,r,n){const o=[];for(;!e.isEmpty();){const t=this._peekTag(e,"end");if(e.isError(t))return t;const i=r.decode(e,"der",n);if(e.isError(i)&&t)break;o.push(i)}return o},c.prototype._decodeStr=function(e,t){if("bitstr"===t){const t=e.readUInt8();return e.isError(t)?t:{unused:t,data:e.raw()}}if("bmpstr"===t){const t=e.raw();if(t.length%2==1)return e.error("Decoding of string type: bmpstr length mismatch");let r="";for(let e=0;e<t.length/2;e++)r+=String.fromCharCode(t.readUInt16BE(2*e));return r}if("numstr"===t){const t=e.raw().toString("ascii");return this._isNumstr(t)?t:e.error("Decoding of string type: numstr unsupported characters")}if("octstr"===t)return e.raw();if("objDesc"===t)return e.raw();if("printstr"===t){const t=e.raw().toString("ascii");return this._isPrintstr(t)?t:e.error("Decoding of string type: printstr unsupported characters")}return/str$/.test(t)?e.raw().toString():e.error("Decoding of string type: "+t+" unsupported")},c.prototype._decodeObjid=function(e,t,r){let n;const o=[];let i=0,s=0;for(;!e.isEmpty();)s=e.readUInt8(),i<<=7,i|=127&s,128&s||(o.push(i),i=0);128&s&&o.push(i);const a=o[0]/40|0,c=o[0]%40;if(n=r?o:[a,c].concat(o.slice(1)),t){let e=t[n.join(" ")];void 0===e&&(e=t[n.join(".")]),void 0!==e&&(n=e)}return n},c.prototype._decodeTime=function(e,t){const r=e.raw().toString();let n,o,i,s,a,c;if("gentime"===t)n=0|r.slice(0,4),o=0|r.slice(4,6),i=0|r.slice(6,8),s=0|r.slice(8,10),a=0|r.slice(10,12),c=0|r.slice(12,14);else{if("utctime"!==t)return e.error("Decoding "+t+" time is not supported yet");n=0|r.slice(0,2),o=0|r.slice(2,4),i=0|r.slice(4,6),s=0|r.slice(6,8),a=0|r.slice(8,10),c=0|r.slice(10,12),n=n<70?2e3+n:1900+n}return Date.UTC(n,o-1,i,s,a,c,0)},c.prototype._decodeNull=function(){return null},c.prototype._decodeBool=function(e){const t=e.readUInt8();return e.isError(t)?t:0!==t},c.prototype._decodeInt=function(e,r){const n=e.raw();let o=new t(n);return r&&(o=r[o.toString(10)]||o),o},c.prototype._use=function(e,t){return"function"==typeof e&&(e=e(t)),e._getDecoder("der").tree},$}function Q(){return Y||(Y=1,function(e){const t=e;t.der=W(),t.pem=function(){if(G)return Z;G=1;const e=s(),t=S().Buffer,r=W();function n(e){r.call(this,e),this.enc="pem"}return e(n,r),Z=n,n.prototype.decode=function(e,n){const o=e.toString().split(/[\r\n]+/g),i=n.label.toUpperCase(),s=/^-----(BEGIN|END) ([^-]+)-----$/;let a=-1,c=-1;for(let e=0;e<o.length;e++){const t=o[e].match(s);if(null!==t&&t[2]===i){if(-1!==a){if("END"!==t[1])break;c=e;break}if("BEGIN"!==t[1])break;a=e}}if(-1===a||-1===c)throw new Error("PEM section not found for: "+i);const u=o.slice(a+1,c).join("");u.replace(/[^a-z0-9+/=]+/gi,"");const l=t.from(u,"base64");return r.prototype.decode.call(this,l,n)},Z}()}(H)),H}var ee,te={};var re,ne,oe={};function ie(){return ne||(ne=1,function(){const e=_;e.bignum=i(),e.define=(X||(X=1,function(e){const t=J(),r=Q(),n=s();function o(e,t){this.name=e,this.body=t,this.decoders={},this.encoders={}}e.define=function(e,t){return new o(e,t)},o.prototype._createNamed=function(e){const t=this.name;function r(e){this._initNamed(e,t)}return n(r,e),r.prototype._initNamed=function(t,r){e.call(this,t,r)},new r(this)},o.prototype._getDecoder=function(e){return e=e||"der",this.decoders.hasOwnProperty(e)||(this.decoders[e]=this._createNamed(r[e])),this.decoders[e]},o.prototype.decode=function(e,t,r){return this._getDecoder(t).decode(e,r)},o.prototype._getEncoder=function(e){return e=e||"der",this.encoders.hasOwnProperty(e)||(this.encoders[e]=this._createNamed(t[e])),this.encoders[e]},o.prototype.encode=function(e,t,r){return this._getEncoder(t).encode(e,r)}}(P)),P).define,e.base=(ee||(ee=1,function(){const e=te;e.Reporter=x().Reporter,e.DecoderBuffer=U().DecoderBuffer,e.EncoderBuffer=U().EncoderBuffer,e.Node=q()}()),te),e.constants=(re||(re=1,function(e){const t=e;t._reverse=function(e){const t={};return Object.keys(e).forEach((function(r){(0|r)==r&&(r|=0);const n=e[r];t[n]=r})),t},t.der=M()}(oe)),oe),e.decoders=Q(),e.encoders=J()}()),_}var se,ae,ce,ue,le,fe,pe,de,he,ye,be,we,ge,me,ve,ke,_e,Pe,Ee,Se,Ke,Ae,xe,Ce,je,Be,Ie,Ue,qe,Te,Ne,ze,Oe,Re,De,Ve={exports:{}},Me={},Le={};function Je(){if(ae)return Me;ae=1,Object.defineProperty(Me,"__esModule",{value:!0});var e=(se||(se=1,Object.defineProperty(Le,"__esModule",{value:!0}),Le.default=function(e){var t=e.length,n=t%4;if(!n)return e;var o=t,i=4-n,s=t+i,a=r.alloc(s);for(a.write(e);i--;)a.write("=",o++);return a.toString()}),Le);function n(e,n){return void 0===n&&(n="utf8"),t(e)?i(e.toString("base64")):i(r.from(e,n).toString("base64"))}function o(t){return t=t.toString(),e.default(t).replace(/\-/g,"+").replace(/_/g,"/")}function i(e){return e.replace(/=/g,"").replace(/\+/g,"-").replace(/\//g,"_")}var s=n;return s.encode=n,s.decode=function(e,t){return void 0===t&&(t="utf8"),r.from(o(e),"base64").toString(t)},s.toBase64=o,s.fromBase64=i,s.toBuffer=function(e){return r.from(o(e),"base64")},Me.default=s,Me}function $e(){return ce||(ce=1,(e=Ve).exports=Je().default,e.exports.default=e.exports),Ve.exports;var e}function Fe(){if(le)return ue;le=1;const e=ie(),t=$e();return ue=class{static convert(n,o,i){if(!n)return;if(o===i)return n;let s;if("raw"===o||n instanceof r)s=n;else if("uint8_array"===o||Array.isArray(n))s=r.from(n);else if("hex"===o)s=r.from(n,"hex");else if("base64"===o)s=r.from(n,"base64");else if("base64url"===o)s=t.toBuffer(n);else{if("bn"!==o&&"bignum"!==o)throw new Error("Invalid fromType");s=r.from(this.pad(n.toString(16)),"hex")}if("raw"===i)return s;if("uint8_array"===i)return Array.from(s);if("hex"===i)return s.toString("hex");if("base64"===i)return s.toString("base64");if("base64url"===i)return t.fromBase64(s.toString("base64"));if("bn"===i||"bignum"===i)return new e.bignum(s);throw new Error("Invalid toType")}static pad(e){return e.length%2==1?`0${e}`:e}},ue}function Ze(){if(je)return Ce;je=1;const e=new(function(){if(pe)return fe;pe=1;const e=ie();return fe=class{constructor(){Object.defineProperty(this,"_registry",{value:{}})}get registry(){return this._registry}define(t,r){this._registry[t]=e.define(t,r(this))}normalize(e){return this.registry[e]}}}());return e.define("Version",he?de:(he=1,de=e=>function(){this.int({0:"two-prime",1:"multi"})})),e.define("OtherPrimeInfos",be?ye:(be=1,ye=e=>function(){this.seq().obj(this.key("ri").int(),this.key("di").int(),this.key("ti").int())})),e.define("AlgorithmIdentifier",ge?we:(ge=1,we=e=>function(){this.seq().obj(this.key("algorithm").objid(),this.key("parameters").optional().any())})),e.define("PrivateKeyInfo",(ve||(ve=1,me=e=>{let t=e.normalize("Version"),r=e.normalize("AlgorithmIdentifier");return function(){this.seq().obj(this.key("version").use(t),this.key("algorithm").use(r),this.key("privateKey").octstr())}}),me)),e.define("PublicKeyInfo",(_e||(_e=1,ke=e=>{let t=e.normalize("AlgorithmIdentifier");return function(){this.seq().obj(this.key("algorithm").use(t),this.key("publicKey").bitstr())}}),ke)),e.define("RSAPrivateKey",(Ee||(Ee=1,Pe=e=>{let t=e.normalize("Version"),r=e.normalize("OtherPrimeInfos");return function(){this.seq().obj(this.key("version").use(t),this.key("n").int(),this.key("e").int(),this.key("d").int(),this.key("p").int(),this.key("q").int(),this.key("dp").int(),this.key("dq").int(),this.key("qi").int(),this.key("other").optional().use(r))}}),Pe)),e.define("RSAPublicKey",Ke?Se:(Ke=1,Se=e=>function(){this.seq().obj(this.key("n").int(),this.key("e").int())})),e.define("ECPrivateKey",xe?Ae:(xe=1,Ae=e=>function(){this.seq().obj(this.key("version").int(),this.key("privateKey").octstr(),this.key("parameters").explicit(0).optional().choice({namedCurve:this.objid()}),this.key("publicKey").explicit(1).optional().bitstr())})),Ce=e}function Ge(){if(Oe)return ze;Oe=1;const e=h?d:(h=1,d=class{constructor(){this.registry=[],this.classes={}}find(e){return this.registry.find(e)}define(e,t){e.forEach((e=>{let{kty:r}=e;if(!r)throw new Error("Invalid type definition");this.classes[r]||(this.classes[r]=t),this.registry.push(e)}))}normalize(e,t,r){let n=this.classes[e],o=this.find((e=>e[t]===r));if(!n||!o)throw new Error("Invalid type");return new n(o)}}),t=function(){if(Ie)return Be;Ie=1;const e=m();w();const t=Fe(),n=Ze();class o extends e{fromPrivatePKCS1(e){let r=n.normalize("RSAPrivateKey"),{n:o,e:i,d:s,p:a,q:c,dp:u,dq:l,qi:f}=r.decode(e,"der");return{n:t.convert(o,"bn","raw"),e:t.convert(i,"bn","raw"),d:t.convert(s,"bn","raw"),p:t.convert(a,"bn","raw"),q:t.convert(c,"bn","raw"),dp:t.convert(u,"bn","raw"),dq:t.convert(l,"bn","raw"),qi:t.convert(f,"bn","raw")}}fromPrivatePKCS8(e){let r=n.normalize("PrivateKeyInfo"),o=n.normalize("RSAPrivateKey"),i=r.decode(e,"der"),{n:s,e:a,d:c,p:u,q:l,dp:f,dq:p,qi:d}=o.decode(i.privateKey,"der");return{n:t.convert(s,"bn","raw"),e:t.convert(a,"bn","raw"),d:t.convert(c,"bn","raw"),p:t.convert(u,"bn","raw"),q:t.convert(l,"bn","raw"),dp:t.convert(f,"bn","raw"),dq:t.convert(p,"bn","raw"),qi:t.convert(d,"bn","raw")}}fromPublicPKCS1(e){let r=n.normalize("RSAPublicKey"),{n:o,e:i}=r.decode(e,"der");return{n:t.convert(o,"bn","raw"),e:t.convert(i,"bn","raw")}}fromPublicPKCS8(e){let r=n.normalize("PublicKeyInfo"),o=n.normalize("RSAPublicKey"),i=r.decode(e,"der"),{n:s,e:a}=o.decode(i.publicKey.data,"der");return{n:t.convert(s,"bn","raw"),e:t.convert(a,"bn","raw")}}fromJwk(e){let{n:r,e:n,d:o,p:i,q:s,dp:a,dq:c,qi:u,alg:l}=e;return{n:t.convert(r,"base64url","raw"),e:t.convert(n,"base64url","raw"),d:t.convert(o,"base64url","raw"),p:t.convert(i,"base64url","raw"),q:t.convert(s,"base64url","raw"),dp:t.convert(a,"base64url","raw"),dq:t.convert(c,"base64url","raw"),qi:t.convert(u,"base64url","raw")}}toPrivatePKCS1(e){let{n:r,e:i,d:s,p:a,q:c,dp:u,dq:l,qi:f}=e,{version:p}=this.params,d=n.normalize("RSAPrivateKey").encode({version:p,n:t.convert(r,"raw","bn"),e:t.convert(i,"raw","bn"),d:t.convert(s,"raw","bn"),p:t.convert(a,"raw","bn"),q:t.convert(c,"raw","bn"),dp:t.convert(u,"raw","bn"),dq:t.convert(l,"raw","bn"),qi:t.convert(f,"raw","bn")},"der").toString("base64");return o.formatPem(d,"RSA PRIVATE")}toPrivatePKCS8(e){let{n:i,e:s,d:a,p:c,q:u,dp:l,dq:f,qi:p}=e,{oid:d,algParameters:h,version:y}=this.params,b=n.normalize("PrivateKeyInfo"),w=n.normalize("RSAPrivateKey").encode({version:y,n:t.convert(i,"raw","bn"),e:t.convert(s,"raw","bn"),d:t.convert(a,"raw","bn"),p:t.convert(c,"raw","bn"),q:t.convert(u,"raw","bn"),dp:t.convert(l,"raw","bn"),dq:t.convert(f,"raw","bn"),qi:t.convert(p,"raw","bn")},"der"),g=b.encode({version:y,algorithm:{algorithm:d.split("."),parameters:r.from(h,"hex")},privateKey:w},"der").toString("base64");return o.formatPem(g,"PRIVATE")}toPublicPKCS1(e){let{n:r,e:i}=e,{version:s}=this.params,a=n.normalize("RSAPublicKey").encode({version:s,n:t.convert(r,"raw","bn"),e:t.convert(i,"raw","bn")},"der").toString("base64");return o.formatPem(a,"RSA PUBLIC")}toPublicPKCS8(e){let{n:i,e:s}=e,{oid:a,algParameters:c}=this.params,u=n.normalize("PublicKeyInfo"),l=n.normalize("RSAPublicKey").encode({n:t.convert(i,"raw","bn"),e:t.convert(s,"raw","bn")},"der"),f=u.encode({algorithm:{algorithm:a.split("."),parameters:r.from(c,"hex")},publicKey:{unused:0,data:l}},"der").toString("base64");return o.formatPem(f,"PUBLIC")}toPrivateJwk(e){let{n:r,e:n,d:o,p:i,q:s,dp:a,dq:c,qi:u}=e,{kty:l}=this.params;return{kty:l,n:t.convert(r,"raw","base64url"),e:t.convert(n,"raw","base64url"),d:t.convert(o,"raw","base64url"),p:t.convert(i,"raw","base64url"),q:t.convert(s,"raw","base64url"),dp:t.convert(a,"raw","base64url"),dq:t.convert(c,"raw","base64url"),qi:t.convert(u,"raw","base64url")}}toPublicJwk(e){let{n:r,e:n}=e,{kty:o}=this.params;return{kty:o,n:t.convert(r,"raw","base64url"),e:t.convert(n,"raw","base64url")}}}return Be=o}(),n=function(){if(qe)return Ue;qe=1,ie().bignum;const e=new(0,o().ec)("secp256k1"),t=m();w();const n=Fe(),i=Ze();class s extends t{fromPrivatePKCS1(e){let t=i.normalize("ECPrivateKey").decode(e,"der"),{privateKey:r,publicKey:{data:o}}=t,a=n.convert(o,"raw","hex"),{x:c,y:u}=s.getPoint(a);return{d:r,x:c,y:u}}fromPrivatePKCS8(e){let t=i.normalize("PrivateKeyInfo"),r=i.normalize("ECPrivateKey"),o=t.decode(e,"der"),a=r.decode(o.privateKey,"der"),{privateKey:c,publicKey:{data:u}}=a,l=n.convert(u,"raw","hex"),{x:f,y:p}=s.getPoint(l);return{d:c,x:f,y:p}}fromPublicPKCS8(e){let t=i.normalize("PublicKeyInfo").decode(e,"der"),r=n.convert(t.publicKey.data,"raw","hex");return s.getPoint(r)}fromPrivateBlk(t){let r=e.keyFromPrivate(t,"hex"),o=r.getPublic();return{d:n.convert(r.priv,"bn","raw"),x:n.convert(o.getX(),"bn","raw"),y:n.convert(o.getY(),"bn","raw")}}fromPublicBlk(e){return s.getPoint(e)}fromJwk(e){let{d:t,x:r,y:o}=e;return{d:n.convert(t,"base64url","raw"),x:n.convert(r,"base64url","raw"),y:n.convert(o,"base64url","raw")}}toPrivatePKCS1(e){let{namedCurve:t,keyVersion:r}=this.params,{d:n,x:o,y:a}=e,c=i.normalize("ECPrivateKey"),u=s.makePoint(o,a),l=c.encode({version:r,privateKey:n,parameters:{type:"namedCurve",value:t.split(".")},publicKey:{unused:0,data:u}},"der").toString("base64");return s.formatPem(l,"EC PRIVATE")}toPrivatePKCS8(e){let{oid:t,algParameters:n,keyVersion:o,infoVersion:a}=this.params,{d:c,x:u,y:l}=e,f=i.normalize("PrivateKeyInfo"),p=i.normalize("ECPrivateKey"),d=s.makePoint(u,l),h=p.encode({version:o,privateKey:c,publicKey:{unused:0,data:d}},"der"),y=f.encode({version:a,algorithm:{algorithm:t.split("."),parameters:r.from(n,"hex")},privateKey:h},"der").toString("base64");return s.formatPem(y,"PRIVATE")}toPublicPKCS8(e){let{oid:t,algParameters:n}=this.params,{x:o,y:a}=e,c=i.normalize("PublicKeyInfo"),u=s.makePoint(o,a),l=c.encode({algorithm:{algorithm:t.split("."),parameters:r.from(n,"hex")},publicKey:{unused:0,data:u}},"der").toString("base64");return s.formatPem(l,"PUBLIC")}toPrivateBlk(e){return e.d.toString("hex")}toPublicBlk(e){return n.convert(s.makePoint(e.x,e.y),"raw","hex")}toPrivateJwk(e){let{crv:t,kty:r}=this.params,{d:o,x:i,y:s}=e;return{kty:r,crv:t,d:n.convert(o,"raw","base64url"),x:n.convert(i,"raw","base64url"),y:n.convert(s,"raw","base64url")}}toPublicJwk(e){let{crv:t,kty:r}=this.params,{x:o,y:i}=e;return{kty:r,crv:t,x:n.convert(o,"raw","base64url"),y:n.convert(i,"raw","base64url")}}static getPoint(e){let t=e.slice(2,(e.length-2)/2+2),r=e.slice((e.length-2)/2+2);return{x:n.convert(t,"hex","raw"),y:n.convert(r,"hex","raw")}}static makePoint(e,t){let n=r.from("04","hex");return r.concat([n,e,t],n.length+e.length+t.length)}}return Ue=s}(),i=function(){if(Ne)return Te;Ne=1;const e=m(),t=Fe(),n=Ze();class i extends e{fromPrivatePKCS8(e){const t=n.normalize("PrivateKeyInfo").decode(e,"der").privateKey.slice(2);return{d:t,x:this.publicKeyFromPrivate(t)}}fromPublicPKCS8(e){const r=n.normalize("PublicKeyInfo").decode(e,"der");return{x:t.convert(r.publicKey.data,"hex","raw")}}fromJwk(e){let{d:r,x:n}=e;return{d:t.convert(r,"base64url","raw"),x:t.convert(n,"base64url","raw")}}toPrivatePKCS8(e){let{oid:t,infoVersion:r}=this.params,{d:o}=e;const s=n.normalize("PrivateKeyInfo"),a=this.privateKeyPadding(o);let c=s.encode({version:r,algorithm:{algorithm:t.split(".")},privateKey:a},"der").toString("base64");return i.formatPem(c,"PRIVATE")}toPublicPKCS8(e){let{oid:r}=this.params,{x:o}=e,s=n.normalize("PublicKeyInfo").encode({algorithm:{algorithm:r.split(".")},publicKey:{unused:0,data:t.convert(o,"hex","raw")}},"der").toString("base64");return i.formatPem(s,"PUBLIC")}toPrivateJwk(e){let{crv:r,kty:n}=this.params,{d:o,x:i}=e;return{kty:n,crv:r,d:t.convert(o,"raw","base64url"),x:t.convert(i,"raw","base64url")}}toPublicJwk(e){let{crv:r,kty:n}=this.params,{x:o}=e;return{kty:n,crv:r,x:t.convert(o,"raw","base64url")}}privateKeyPadding(e){let t;if("Ed25519"!==this.params.crv)throw new Error(`${this.params.crv} is an invalid curve for EdDSA`);return t=r.from("0420","hex"),r.concat([t,e],t.length+e.length)}publicKeyFromPrivate(e){if("Ed25519"===this.params.crv){const t=new(0,o().eddsa)("ed25519");return r.from(t.keyFromSecret(e).getPublic())}throw new Error(`${this.params.crv} is an invalid curve for EdDSA`)}}return Te=i}(),s=new e;return s.define([{kty:"RSA",oid:"1.2.840.113549.1.1.1",algParameters:"0500",version:"two-prime"}],t),s.define([{kty:"EC",crv:"K-256",oid:"1.2.840.10045.2.1",namedCurve:"1.3.132.0.10",algParameters:"06052b8104000a",keyVersion:1,infoVersion:"two-prime"},{kty:"EC",crv:"P-256",oid:"1.2.840.10045.2.1",namedCurve:"1.2.840.10045.3.1.7",algParameters:"06082a8648ce3d030107",keyVersion:1,infoVersion:"two-prime"},{kty:"EC",crv:"P-384",oid:"1.2.840.10045.2.1",namedCurve:"1.3.132.0.34",algParameters:"06052b81040022",keyVersion:1,infoVersion:"two-prime"},{kty:"EC",crv:"P-521",oid:"1.2.840.10045.2.1",namedCurve:"1.3.132.0.35",algParameters:"06052b81040023",keyVersion:1,infoVersion:"two-prime"}],n),s.define([{kty:"OKP",crv:"Ed25519",oid:"1.3.101.112",infoVersion:"two-prime"}],i),ze=s}var Ye=function(){if(De)return Re;De=1;const e=w(),t=g(),n=Ge(),o=Ze(),i=RegExp("\r?\n","g");class s{constructor(t,r){if(!t)throw new e("key is required");if(!r)throw new e("options are required");let{kty:n,format:o,selector:i,crv:s,oid:a}=r;if(!r.kty)throw new e("options.kty is required");if(!r.format)throw new e("options.format is required");if(!r.selector)throw new e("options.selector is required");if(!r.crv&&!r.oid)throw new e("options.crv or options.oid is required");this.kty=n,this.format=o,this.selector=i,this.crv=s,this.oid=a,this.key=this.parseKey(t)}static from(t,a){if(!t)throw new e("key is required");if(!a)throw new e("format is required");if("jwk"===a){let r;if("string"==typeof t)try{r=JSON.parse(t)}catch(t){throw new e("key is not a valid JWK")}else"object"==typeof t&&(r=t);let o,{kty:i,crv:c}=r;if(!i)throw new e("kty is required for JWK");if("EC"===i&&!c)throw new e("crv is required for EC JWK");"RSA"===i&&(o=n.find((e=>e.kty===i)).oid);let u=r.d?"private":"public";return new s(r,{kty:i,crv:c,oid:o,format:a,selector:u})}if("pem"===a){if("string"!=typeof t)throw new e("key is not a valid PEM string");let c=t.split(i),u=c.splice(0,1);c.splice(c.length-1,1);let l,f,p=c.join(""),d=/^-----BEGIN ((RSA|EC) )?(PUBLIC|PRIVATE) KEY-----$/.exec(u),h=d?d[2]:void 0,y=d?d[3]:void 0,b=r.from(p,"base64");if(!y)throw new e("key is not a valid PEM string");if(h){if("RSA"===h)y="PRIVATE"===y?"private_pkcs1":"public_pkcs1",l=n.find((e=>e.kty===h)).oid;else if("EC"===h){let e;if("PRIVATE"===y){y="private_pkcs1",e=o.normalize(`${h}PrivateKey`).decode(b,"der")}else if("PUBLIC"===y){y="public_pkcs1",e=o.normalize(`${h}PrivateKey`).decode(b,"der")}let{parameters:{value:t}}=e;f=n.find((e=>e.namedCurve===t.join("."))).crv}}else{let t,r=o.normalize("PrivateKeyInfo"),i=o.normalize("PublicKeyInfo");"PRIVATE"===y?(y="private_pkcs8",t=r.decode(b,"der")):"PUBLIC"===y&&(y="public_pkcs8",t=i.decode(b,"der"));let{algorithm:{algorithm:s,parameters:a}}=t;s=s.join("."),a=a?a.toString("hex"):void 0;const c=n.find((e=>e.oid===s));if(h=c?c.kty:void 0,!h)throw new e(`${s} is not supported`);"RSA"===h||"OKP"===h?l=s:"EC"===h&&(f=n.find((e=>e.algParameters===a)).crv)}return new s(b,{kty:h,oid:l,crv:f,format:a,selector:y})}if("blk"===a)return new s(t,{kty:"EC",crv:"K-256",format:a,selector:t.length>64?"public":"private"});throw new e(`Invalid format ${a}`)}get alg(){let{kty:e,crv:t,oid:r}=this;if(!this.algorithm){if(t)Object.defineProperty(this,"algorithm",{value:n.normalize(e,"crv",t)});else{if(!r)throw new Error("Both crv and oid are undefined");Object.defineProperty(this,"algorithm",{value:n.normalize(e,"oid",r)})}if(!this.algorithm)throw new Error(`${this.crv||this.oid} is not implemented yet`)}return this.algorithm}parseKey(e){let{alg:t,format:r,selector:n}=this;if("pem"===r)switch(n){case"public_pkcs1":return t.fromPublicPKCS1(e);case"public_pkcs8":return t.fromPublicPKCS8(e);case"private_pkcs1":return t.fromPrivatePKCS1(e);case"private_pkcs8":return t.fromPrivatePKCS8(e);default:throw new Error("Invalid selector value")}if("jwk"===r)return t.fromJwk(e,n);if("blk"===r)switch(n){case"public":return t.fromPublicBlk(e);case"private":return t.fromPrivateBlk(e)}}toJwk(t){let{key:r,alg:n,selector:o}=this;switch(t){case"public":return n.toPublicJwk(r);case"private":if(o.includes("public"))throw new e("Cannot export a private key from a public key");return n.toPrivateJwk(r);default:throw new Error("Invalid key selector")}}toString(r="pem",n="public_pkcs8"){let{key:o,alg:i,selector:s}=this;if("pem"===r)switch(n){case"public_pkcs1":return i.toPublicPKCS1(o);case"public_pkcs8":return i.toPublicPKCS8(o);case"private_pkcs1":if(s.includes("public"))throw new e("Cannot export a private key from a public key");return i.toPrivatePKCS1(o);case"private_pkcs8":if(s.includes("public"))throw new e("Cannot export a private key from a public key");return i.toPrivatePKCS8(o);default:throw new Error("Invalid key selector")}else if("jwk"===r)switch(n){case"public":return JSON.stringify(i.toPublicJwk(o));case"private":if(s.includes("public"))throw new e("Cannot export a private key from a public key");return JSON.stringify(i.toPrivateJwk(o));default:throw new Error("Invalid key selector")}else if("blk"===r)switch(n){case"private":if(s.includes("public"))throw new e("Cannot export a private key from a public key");return i.toPrivateBlk(o);case"public":return i.toPublicBlk(o);default:throw new Error("Invalid key selector")}throw new t}}return Re=s}(),Xe=e(Ye);var He,We,Qe,et,tt,rt,nt=function(e){if(e.length>=255)throw new TypeError("Alphabet too long");const t=new Uint8Array(256);for(let e=0;e<t.length;e++)t[e]=255;for(let r=0;r<e.length;r++){const n=e.charAt(r),o=n.charCodeAt(0);if(255!==t[o])throw new TypeError(n+" is ambiguous");t[o]=r}const r=e.length,n=e.charAt(0),o=Math.log(r)/Math.log(256),i=Math.log(256)/Math.log(r);function s(e){if("string"!=typeof e)throw new TypeError("Expected String");if(0===e.length)return new Uint8Array;let i=0,s=0,a=0;for(;e[i]===n;)s++,i++;const c=(e.length-i)*o+1>>>0,u=new Uint8Array(c);for(;i<e.length;){const n=e.charCodeAt(i);if(n>255)return;let o=t[n];if(255===o)return;let s=0;for(let e=c-1;(0!==o||s<a)&&-1!==e;e--,s++)o+=r*u[e]>>>0,u[e]=o%256>>>0,o=o/256>>>0;if(0!==o)throw new Error("Non-zero carry");a=s,i++}let l=c-a;for(;l!==c&&0===u[l];)l++;const f=new Uint8Array(s+(c-l));let p=s;for(;l!==c;)f[p++]=u[l++];return f}return{encode:function(t){if(t instanceof Uint8Array||(ArrayBuffer.isView(t)?t=new Uint8Array(t.buffer,t.byteOffset,t.byteLength):Array.isArray(t)&&(t=Uint8Array.from(t))),!(t instanceof Uint8Array))throw new TypeError("Expected Uint8Array");if(0===t.length)return"";let o=0,s=0,a=0;const c=t.length;for(;a!==c&&0===t[a];)a++,o++;const u=(c-a)*i+1>>>0,l=new Uint8Array(u);for(;a!==c;){let e=t[a],n=0;for(let t=u-1;(0!==e||n<s)&&-1!==t;t--,n++)e+=256*l[t]>>>0,l[t]=e%r>>>0,e=e/r>>>0;if(0!==e)throw new Error("Non-zero carry");s=n,a++}let f=u-s;for(;f!==u&&0===l[f];)f++;let p=n.repeat(o);for(;f<u;++f)p+=e.charAt(l[f]);return p},decodeUnsafe:s,decode:function(e){const t=s(e);if(t)return t;throw new Error("Non-base"+r+" character")}}}("123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz");function ot(){if(et)return Qe;et=1;const e=new(0,o().ec)("secp256k1"),t=e.curve,r=t.n.constructor;function n(n){const o=n[0];switch(o){case 2:case 3:return 33!==n.length?null:function(n,o){let i=new r(o);if(i.cmp(t.p)>=0)return null;i=i.toRed(t.red);let s=i.redSqr().redIMul(i).redIAdd(t.b).redSqrt();3===n!==s.isOdd()&&(s=s.redNeg());const a=i.redSqr().redIMul(i);return s.redSqr().redISub(a.redIAdd(t.b)).isZero()?e.keyPair({pub:{x:i,y:s}}):null}(o,n.subarray(1,33));case 4:case 6:case 7:return 65!==n.length?null:function(n,o,i){let s=new r(o),a=new r(i);if(s.cmp(t.p)>=0||a.cmp(t.p)>=0)return null;if(s=s.toRed(t.red),a=a.toRed(t.red),(6===n||7===n)&&a.isOdd()!==(7===n))return null;const c=s.redSqr().redIMul(s);return a.redSqr().redISub(c.redIAdd(t.b)).isZero()?e.keyPair({pub:{x:s,y:a}}):null}(o,n.subarray(1,33),n.subarray(33,65));default:return null}}function i(e,t){const r=t.encode(null,33===e.length);for(let t=0;t<e.length;++t)e[t]=r[t]}return Qe={contextRandomize:()=>0,privateKeyVerify(e){const n=new r(e);return n.cmp(t.n)<0&&!n.isZero()?0:1},privateKeyNegate(e){const n=new r(e),o=t.n.sub(n).umod(t.n).toArrayLike(Uint8Array,"be",32);return e.set(o),0},privateKeyTweakAdd(e,n){const o=new r(n);if(o.cmp(t.n)>=0)return 1;if(o.iadd(new r(e)),o.cmp(t.n)>=0&&o.isub(t.n),o.isZero())return 1;const i=o.toArrayLike(Uint8Array,"be",32);return e.set(i),0},privateKeyTweakMul(e,n){let o=new r(n);if(o.cmp(t.n)>=0||o.isZero())return 1;o.imul(new r(e)),o.cmp(t.n)>=0&&(o=o.umod(t.n));const i=o.toArrayLike(Uint8Array,"be",32);return e.set(i),0},publicKeyVerify:e=>null===n(e)?1:0,publicKeyCreate(n,o){const s=new r(o);if(s.cmp(t.n)>=0||s.isZero())return 1;return i(n,e.keyFromPrivate(o).getPublic()),0},publicKeyConvert(e,t){const r=n(t);if(null===r)return 1;return i(e,r.getPublic()),0},publicKeyNegate(e,t){const r=n(t);if(null===r)return 1;const o=r.getPublic();return o.y=o.y.redNeg(),i(e,o),0},publicKeyCombine(e,t){const r=new Array(t.length);for(let e=0;e<t.length;++e)if(r[e]=n(t[e]),null===r[e])return 1;let o=r[0].getPublic();for(let e=1;e<r.length;++e)o=o.add(r[e].pub);return o.isInfinity()?2:(i(e,o),0)},publicKeyTweakAdd(e,o,s){const a=n(o);if(null===a)return 1;if((s=new r(s)).cmp(t.n)>=0)return 2;const c=a.getPublic().add(t.g.mul(s));return c.isInfinity()?2:(i(e,c),0)},publicKeyTweakMul(e,o,s){const a=n(o);if(null===a)return 1;if((s=new r(s)).cmp(t.n)>=0||s.isZero())return 2;return i(e,a.getPublic().mul(s)),0},signatureNormalize(n){const o=new r(n.subarray(0,32)),i=new r(n.subarray(32,64));return o.cmp(t.n)>=0||i.cmp(t.n)>=0?1:(1===i.cmp(e.nh)&&n.set(t.n.sub(i).toArrayLike(Uint8Array,"be",32),32),0)},signatureExport(e,n){const o=n.subarray(0,32),i=n.subarray(32,64);if(new r(o).cmp(t.n)>=0)return 1;if(new r(i).cmp(t.n)>=0)return 1;const{output:s}=e;let a=s.subarray(4,37);a[0]=0,a.set(o,1);let c=33,u=0;for(;c>1&&0===a[u]&&!(128&a[u+1]);--c,++u);if(a=a.subarray(u),128&a[0])return 1;if(c>1&&0===a[0]&&!(128&a[1]))return 1;let l=s.subarray(39,72);l[0]=0,l.set(i,1);let f=33,p=0;for(;f>1&&0===l[p]&&!(128&l[p+1]);--f,++p);return l=l.subarray(p),128&l[0]||f>1&&0===l[0]&&!(128&l[1])?1:(e.outputlen=6+c+f,s[0]=48,s[1]=e.outputlen-2,s[2]=2,s[3]=a.length,s.set(a,4),s[4+c]=2,s[5+c]=l.length,s.set(l,6+c),0)},signatureImport(e,n){if(n.length<8)return 1;if(n.length>72)return 1;if(48!==n[0])return 1;if(n[1]!==n.length-2)return 1;if(2!==n[2])return 1;const o=n[3];if(0===o)return 1;if(5+o>=n.length)return 1;if(2!==n[4+o])return 1;const i=n[5+o];if(0===i)return 1;if(6+o+i!==n.length)return 1;if(128&n[4])return 1;if(o>1&&0===n[4]&&!(128&n[5]))return 1;if(128&n[o+6])return 1;if(i>1&&0===n[o+6]&&!(128&n[o+7]))return 1;let s=n.subarray(4,4+o);if(33===s.length&&0===s[0]&&(s=s.subarray(1)),s.length>32)return 1;let a=n.subarray(6+o);if(33===a.length&&0===a[0]&&(a=a.slice(1)),a.length>32)throw new Error("S length is too long");let c=new r(s);c.cmp(t.n)>=0&&(c=new r(0));let u=new r(n.subarray(6+o));return u.cmp(t.n)>=0&&(u=new r(0)),e.set(c.toArrayLike(Uint8Array,"be",32),0),e.set(u.toArrayLike(Uint8Array,"be",32),32),0},ecdsaSign(n,o,i,s,a){if(a){const e=a;a=t=>{const n=e(o,i,null,s,t);if(!(n instanceof Uint8Array&&32===n.length))throw new Error("This is the way");return new r(n)}}const c=new r(i);if(c.cmp(t.n)>=0||c.isZero())return 1;let u;try{u=e.sign(o,i,{canonical:!0,k:a,pers:s})}catch(e){return 1}return n.signature.set(u.r.toArrayLike(Uint8Array,"be",32),0),n.signature.set(u.s.toArrayLike(Uint8Array,"be",32),32),n.recid=u.recoveryParam,0},ecdsaVerify(o,i,s){const a={r:o.subarray(0,32),s:o.subarray(32,64)},c=new r(a.r),u=new r(a.s);if(c.cmp(t.n)>=0||u.cmp(t.n)>=0)return 1;if(1===u.cmp(e.nh)||c.isZero()||u.isZero())return 3;const l=n(s);if(null===l)return 2;const f=l.getPublic();return e.verify(i,a,f)?0:3},ecdsaRecover(n,o,s,a){const c={r:o.slice(0,32),s:o.slice(32,64)},u=new r(c.r),l=new r(c.s);if(u.cmp(t.n)>=0||l.cmp(t.n)>=0)return 1;if(u.isZero()||l.isZero())return 2;let f;try{f=e.recoverPubKey(a,c,s)}catch(e){return 2}return i(n,f),0},ecdh(o,i,s,a,c,u,l){const f=n(i);if(null===f)return 1;const p=new r(s);if(p.cmp(t.n)>=0||p.isZero())return 2;const d=f.getPublic().mul(p);if(void 0===c){const t=d.encode(null,!0),r=e.hash().update(t).digest();for(let e=0;e<32;++e)o[e]=r[e]}else{u||(u=new Uint8Array(32));const e=d.getX().toArray("be",32);for(let t=0;t<32;++t)u[t]=e[t];l||(l=new Uint8Array(32));const t=d.getY().toArray("be",32);for(let e=0;e<32;++e)l[e]=t[e];const r=c(u,l,a);if(!(r instanceof Uint8Array&&r.length===o.length))return 2;o.set(r)}return 0}}}var it=(rt||(rt=1,tt=function(){if(We)return He;We=1;const e="Impossible case. Please create issue.",t="The tweak was out of range or the resulted private key is invalid",r="The tweak was out of range or equal to zero",n="Unknow error on context randomization",o="Private Key is invalid",i="Public Key could not be parsed",s="Public Key serialization error",a="The sum of the public keys is not valid",c="Signature could not be parsed",u="The nonce generation function failed, or the private key was invalid",l="Public key could not be recover",f="Scalar was invalid (zero or overflow)";function p(e,t){if(!e)throw new Error(t)}function d(e,t,r){if(p(t instanceof Uint8Array,`Expected ${e} to be an Uint8Array`),void 0!==r)if(Array.isArray(r)){const n=`Expected ${e} to be an Uint8Array with length [${r.join(", ")}]`;p(r.includes(t.length),n)}else{const n=`Expected ${e} to be an Uint8Array with length ${r}`;p(t.length===r,n)}}function h(e){p("Boolean"===b(e),"Expected compressed to be a Boolean")}function y(e=e=>new Uint8Array(e),t){return"function"==typeof e&&(e=e(t)),d("output",e,t),e}function b(e){return Object.prototype.toString.call(e).slice(8,-1)}return He=w=>({contextRandomize(e){if(p(null===e||e instanceof Uint8Array,"Expected seed to be an Uint8Array or null"),null!==e&&d("seed",e,32),1===w.contextRandomize(e))throw new Error(n)},privateKeyVerify:e=>(d("private key",e,32),0===w.privateKeyVerify(e)),privateKeyNegate(t){switch(d("private key",t,32),w.privateKeyNegate(t)){case 0:return t;case 1:throw new Error(e)}},privateKeyTweakAdd(e,r){switch(d("private key",e,32),d("tweak",r,32),w.privateKeyTweakAdd(e,r)){case 0:return e;case 1:throw new Error(t)}},privateKeyTweakMul(e,t){switch(d("private key",e,32),d("tweak",t,32),w.privateKeyTweakMul(e,t)){case 0:return e;case 1:throw new Error(r)}},publicKeyVerify:e=>(d("public key",e,[33,65]),0===w.publicKeyVerify(e)),publicKeyCreate(e,t=!0,r){switch(d("private key",e,32),h(t),r=y(r,t?33:65),w.publicKeyCreate(r,e)){case 0:return r;case 1:throw new Error(o);case 2:throw new Error(s)}},publicKeyConvert(e,t=!0,r){switch(d("public key",e,[33,65]),h(t),r=y(r,t?33:65),w.publicKeyConvert(r,e)){case 0:return r;case 1:throw new Error(i);case 2:throw new Error(s)}},publicKeyNegate(t,r=!0,n){switch(d("public key",t,[33,65]),h(r),n=y(n,r?33:65),w.publicKeyNegate(n,t)){case 0:return n;case 1:throw new Error(i);case 2:throw new Error(e);case 3:throw new Error(s)}},publicKeyCombine(e,t=!0,r){p(Array.isArray(e),"Expected public keys to be an Array"),p(e.length>0,"Expected public keys array will have more than zero items");for(const t of e)d("public key",t,[33,65]);switch(h(t),r=y(r,t?33:65),w.publicKeyCombine(r,e)){case 0:return r;case 1:throw new Error(i);case 2:throw new Error(a);case 3:throw new Error(s)}},publicKeyTweakAdd(e,r,n=!0,o){switch(d("public key",e,[33,65]),d("tweak",r,32),h(n),o=y(o,n?33:65),w.publicKeyTweakAdd(o,e,r)){case 0:return o;case 1:throw new Error(i);case 2:throw new Error(t)}},publicKeyTweakMul(e,t,n=!0,o){switch(d("public key",e,[33,65]),d("tweak",t,32),h(n),o=y(o,n?33:65),w.publicKeyTweakMul(o,e,t)){case 0:return o;case 1:throw new Error(i);case 2:throw new Error(r)}},signatureNormalize(e){switch(d("signature",e,64),w.signatureNormalize(e)){case 0:return e;case 1:throw new Error(c)}},signatureExport(t,r){d("signature",t,64);const n={output:r=y(r,72),outputlen:72};switch(w.signatureExport(n,t)){case 0:return r.slice(0,n.outputlen);case 1:throw new Error(c);case 2:throw new Error(e)}},signatureImport(t,r){switch(d("signature",t),r=y(r,64),w.signatureImport(r,t)){case 0:return r;case 1:throw new Error(c);case 2:throw new Error(e)}},ecdsaSign(t,r,n={},o){d("message",t,32),d("private key",r,32),p("Object"===b(n),"Expected options to be an Object"),void 0!==n.data&&d("options.data",n.data),void 0!==n.noncefn&&p("Function"===b(n.noncefn),"Expected options.noncefn to be a Function");const i={signature:o=y(o,64),recid:null};switch(w.ecdsaSign(i,t,r,n.data,n.noncefn)){case 0:return i;case 1:throw new Error(u);case 2:throw new Error(e)}},ecdsaVerify(e,t,r){switch(d("signature",e,64),d("message",t,32),d("public key",r,[33,65]),w.ecdsaVerify(e,t,r)){case 0:return!0;case 3:return!1;case 1:throw new Error(c);case 2:throw new Error(i)}},ecdsaRecover(t,r,n,o=!0,i){switch(d("signature",t,64),p("Number"===b(r)&&r>=0&&r<=3,"Expected recovery id to be a Number within interval [0, 3]"),d("message",n,32),h(o),i=y(i,o?33:65),w.ecdsaRecover(i,t,r,n)){case 0:return i;case 1:throw new Error(c);case 2:throw new Error(l);case 3:throw new Error(e)}},ecdh(e,t,r={},n){switch(d("public key",e,[33,65]),d("private key",t,32),p("Object"===b(r),"Expected options to be an Object"),void 0!==r.data&&d("options.data",r.data),void 0!==r.hashfn?(p("Function"===b(r.hashfn),"Expected options.hashfn to be a Function"),void 0!==r.xbuf&&d("options.xbuf",r.xbuf,32),void 0!==r.ybuf&&d("options.ybuf",r.ybuf,32),d("output",n)):n=y(n,32),w.ecdh(n,e,t,r.data,r.hashfn,r.xbuf,r.ybuf)){case 0:return n;case 1:throw new Error(i);case 2:throw new Error(f)}}}),He}()(ot())),tt),st=e(it);export{nt as b,it as e,Xe as k,$e as r,st as s};
|