@blockcerts/blockcerts-verifier 1.59.0 → 1.59.1
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/{EcdsaSecp256k1Signature2019-XwuS-fWx-n_8xXj1H.js → EcdsaSecp256k1Signature2019-XwuS-fWx-7dFfMy74.js} +1 -1
- package/dist/{Ed25519Signature2020-IJ4ybcbU-ii2PjWjh.js → Ed25519Signature2020-IJ4ybcbU--hEL5-Pa.js} +1 -1
- package/dist/{HashlinkVerifier-wyKYZ83G-aKb9h_9G.js → HashlinkVerifier-wyKYZ83G-bzhltPG4.js} +1 -1
- package/dist/{MerkleProof2017-MZJbBTpc-NVfw6WgB.js → MerkleProof2017-MZJbBTpc-0GcGcIV-.js} +1 -1
- package/dist/{MerkleProof2017-Ub6_JUVj-Z6jluDo2.js → MerkleProof2017-Ub6_JUVj-x8awkeml.js} +1 -1
- package/dist/{MerkleProof2019-QUwyEIHd-9hBGmPq_.js → MerkleProof2019-QUwyEIHd-iYt21yPG.js} +1 -1
- package/dist/{checkRevocationStatusList2021-d1qO1xnj-AIMXIqnZ.js → checkRevocationStatusList2021-d1qO1xnj-DH6pO-9Q.js} +1 -1
- package/dist/{controlVerificationMethod-6GJtYmqY-VwQyuM5o.js → controlVerificationMethod-6GJtYmqY-Ivo3O8nb.js} +1 -1
- package/dist/{did-key-common.esm-Fyh_U6fK-6hhnSYH5.js → did-key-common.esm-Fyh_U6fK-cOLlHenk.js} +1 -1
- package/dist/{did-key-ed25519.esm-1lIlZtof-q2UR_X9G.js → did-key-ed25519.esm-1lIlZtof-Grj-JpU9.js} +1 -1
- package/dist/did-key-secp256k1.esm-hA8kGTM0-G8ct6CwH.js +1 -0
- package/dist/{downloadPDF-6pZYEy3P.js → downloadPDF--IVgfc2I.js} +3 -3
- package/dist/{elliptic-il_lPAr--BGmaMzNc.js → elliptic-il_lPAr--VPyWJbY1.js} +1 -1
- package/dist/{ensureNotRevoked-2QGGtBqy-U5ByLE-t.js → ensureNotRevoked-2QGGtBqy-t8Yk4QI-.js} +1 -1
- package/dist/ensureNotRevoked-gui-UMnE-kFmYZEJe.js +1 -0
- package/dist/{ensureValidIssuingKey-zZEv5-cH-oM__XftS.js → ensureValidIssuingKey-zZEv5-cH-UoJe_Wnf.js} +1 -1
- package/dist/{index-MC635rre-r3wKwiyR.js → index-MC635rre-_DW5MUyk.js} +2 -2
- package/dist/{index-WX6J-tsk.js → index-UlvMASNZ.js} +1 -1
- package/dist/index-xsnp_Fid-o1HUYRUQ.js +1 -0
- package/dist/{index.es-NoR6QQLP.js → index.es-dEKcVerc.js} +1 -1
- package/dist/{jsonld-CXlzLf4P-Wh4x173W.js → jsonld-CXlzLf4P-ioHKtwiZ.js} +6 -6
- package/dist/{jsonld-signatures-ooFWZVS--VI8BZQOv.js → jsonld-signatures-ooFWZVS--ThP8ltUY.js} +5 -5
- package/dist/main.js +103 -103
- package/dist/{purify-05qYXQpp.js → purify-GC91XaSq.js} +1 -1
- package/dist/{sha256-wKeS8_4l-o9J6pXuo.js → sha256-wKeS8_4l-9eo2gOQb.js} +1 -1
- package/dist/{x25519-NtRELWAG-TIgip27e.js → x25519-NtRELWAG-2RynHlmX.js} +1 -1
- package/package.json +1 -1
- package/scripts/automated-update-blockcerts.org.sh +7 -1
- package/dist/did-key-secp256k1.esm-hA8kGTM0-5bW-jZai.js +0 -1
- package/dist/ensureNotRevoked-gui-UMnE-9nObicUP.js +0 -1
- package/dist/index-F1HqK0qm.js +0 -1
- package/dist/index-xsnp_Fid-LwXIiw03.js +0 -1
package/dist/{ensureNotRevoked-2QGGtBqy-U5ByLE-t.js → ensureNotRevoked-2QGGtBqy-t8Yk4QI-.js}
RENAMED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{
|
|
1
|
+
import{F as e,V as a,A as t,d as n}from"./main.js";function i(i,o){if(!i||!o)return;Array.isArray(o)||(o=[o]),o=o.filter((e=>null!=e));const r=e(o,i.map((e=>e.id)));if(r.length>0){const e=i.findIndex((e=>e.id===r[0]));if(e>-1)throw new a(t.checkRevokedStatus,n.certificates.generateRevocationReason(i[e].revocationReason))}}export{i as default};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{f as e,V as t,S as a,d as n}from"./index-UlvMASNZ.js";function i(i,o){if(!i||!o)return;Array.isArray(o)||(o=[o]),o=o.filter((e=>null!=e));const r=e(o,i.map((e=>e.id)));if(r.length>0){const e=i.findIndex((e=>e.id===r[0]));if(e>-1)throw new t(a.checkRevokedStatus,n.certificates.generateRevocationReason(i[e].revocationReason))}}export{i as default};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{
|
|
1
|
+
import{o as e,V as s,e as r}from"./main.js";function i(i,n,o){let t="";const d=function(e,s){let r=null;for(const i in e)Object.prototype.hasOwnProperty.call(e,i)&&i.toLowerCase()===s.toLowerCase()&&(r=i);return e[r]}(i,n),a=e(o);if(d?(d.created&&a<=d.created&&(t="invalidIssuingAddressCreationTime"),d.revoked&&a>=d.revoked&&(t="invalidIssuingAddressRevoked"),d.expires&&a>=d.expires&&(t="invalidIssuingAddressExpired")):t="invalidIssuingAddressUnknown",t)throw new s("checkAuthenticity",r("errors",t))}export{i as e};
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import{p as e,
|
|
1
|
+
import{p as e,V as t,d as r,u as n,x as o,B as i,i as s,g as a,y as c}from"./main.js";import{b as u}from"./index-xsnp_Fid-o1HUYRUQ.js";import{b as l,r as f,i as p,m as d,e as h}from"./elliptic-il_lPAr--VPyWJbY1.js";function y(e,n){if(!e.verificationMethod)return void console.warn("No verification method found in the issuer document. This will likely become a requirement in the near future");const o=n.split("#")[1],i=e.verificationMethod.find((e=>e.id===`#${o}`||e.id===n));if(!i)throw new t("retrieveVerificationMethodPublicKey",`${u} - ${r.i18n.getText("errors","retrieveVerificationMethodPublicKey")}`);return i}var m=n(o),b=n(c),v={exports:{}};
|
|
2
2
|
/*! safe-buffer. MIT License. Feross Aboukhadijeh <https://feross.org/opensource> */
|
|
3
|
-
!function(e,t){var r=f,n=r.Buffer;function o(e,t){for(var r in e)t[r]=e[r]}function i(e,t,r){return n(e,t,r)}n.from&&n.alloc&&n.allocUnsafe&&n.allocUnsafeSlow?e.exports=r:(o(r,t),t.Buffer=i),i.prototype=Object.create(n.prototype),o(n,i),i.from=function(e,t,r){if("number"==typeof e)throw new TypeError("Argument must not be a number");return n(e,t,r)},i.alloc=function(e,t,r){if("number"!=typeof e)throw new TypeError("Argument must be a number");var o=n(e);return void 0!==t?"string"==typeof r?o.fill(t,r):o.fill(t):o.fill(0),o},i.allocUnsafe=function(e){if("number"!=typeof e)throw new TypeError("Argument must be a number");return n(e)},i.allocUnsafeSlow=function(e){if("number"!=typeof e)throw new TypeError("Argument must be a number");return r.SlowBuffer(e)}}(v,v.exports);var g=v.exports;var w=class extends Error{constructor(e){super(e||"This operation is not supported for this key type")}};var _=class extends Error{constructor(){super("This has not been implemented yet")}};var k=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)}};const P=_;var S,E=class{constructor(e){this.params=e}fromPrivatePKCS1(e){throw new P}fromPrivatePKCS8(e){throw new P}fromPublicPKCS1(e){throw new P}fromPublicPKCS8(e){throw new P}fromPrivateBlk(e){throw new P}fromPublicBlk(e){throw new P}fromJwk(e){throw new P}toPrivatePKCS1(e){throw new P}toPrivatePKCS8(e){throw new P}toPublicPKCS1(e){throw new P}toPublicPKCS8(e){throw new P}toPrivateBlk(e){throw new P}toPublicBlk(e){throw new P}toPrivateJwk(e){throw new P}toPublicJwk(e){throw new P}static formatPem(e,t){return`-----BEGIN ${t} KEY-----\n`+e.match(/.{1,64}/g).join("\n")+`\n-----END ${t} KEY-----`}},K={},C={},B={},x=f,j=x.Buffer,A={};for(S in x)x.hasOwnProperty(S)&&"SlowBuffer"!==S&&"Buffer"!==S&&(A[S]=x[S]);var I=A.Buffer={};for(S in j)j.hasOwnProperty(S)&&"allocUnsafe"!==S&&"allocUnsafeSlow"!==S&&(I[S]=j[S]);if(A.Buffer.prototype=j.prototype,I.from&&I.from!==Uint8Array.from||(I.from=function(e,t,r){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 j(e,t,r)}),I.alloc||(I.alloc=function(e,t,r){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 n=j(e);return t&&0!==t.length?"string"==typeof r?n.fill(t,r):n.fill(t):n.fill(0),n}),!A.kStringMaxLength)try{A.kStringMaxLength=e.binding("buffer").kStringMaxLength}catch(e){}A.constants||(A.constants={MAX_LENGTH:A.kMaxLength},A.kStringMaxLength&&(A.constants.MAX_STRING_LENGTH=A.kStringMaxLength));var q=A,T={};const U=p;function D(e){this._reporterState={obj:null,path:[],options:e||{},errors:[]}}function O(e,t){this.path=e,this.rethrow(t)}T.Reporter=D,D.prototype.isError=function(e){return e instanceof O},D.prototype.save=function(){const e=this._reporterState;return{obj:e.obj,pathLen:e.path.length}},D.prototype.restore=function(e){const t=this._reporterState;t.obj=e.obj,t.path=t.path.slice(0,e.pathLen)},D.prototype.enterKey=function(e){return this._reporterState.path.push(e)},D.prototype.exitKey=function(e){const t=this._reporterState;t.path=t.path.slice(0,e-1)},D.prototype.leaveKey=function(e,t,r){const n=this._reporterState;this.exitKey(e),null!==n.obj&&(n.obj[t]=r)},D.prototype.path=function(){return this._reporterState.path.join("/")},D.prototype.enterObject=function(){const e=this._reporterState,t=e.obj;return e.obj={},t},D.prototype.leaveObject=function(e){const t=this._reporterState,r=t.obj;return t.obj=e,r},D.prototype.error=function(e){let t;const r=this._reporterState,n=e instanceof O;if(t=n?e:new O(r.path.map((function(e){return"["+JSON.stringify(e)+"]"})).join(""),e.message||e,e.stack),!r.options.partial)throw t;return n||r.errors.push(t),t},D.prototype.wrapResult=function(e){const t=this._reporterState;return t.options.partial?{result:this.isError(e)?null:e,errors:t.errors}:e},U(O,Error),O.prototype.rethrow=function(e){if(this.message=e+" at: "+(this.path||"(shallow)"),Error.captureStackTrace&&Error.captureStackTrace(this,O),!this.stack)try{throw new Error(this.message)}catch(e){this.stack=e.stack}return this};var z={};const N=p,R=T.Reporter,V=q.Buffer;function J(e,t){R.call(this,t),V.isBuffer(e)?(this.base=e,this.offset=0,this.length=e.length):this.error("Input not Buffer")}function M(e,t){if(Array.isArray(e))this.length=0,this.value=e.map((function(e){return M.isEncoderBuffer(e)||(e=new M(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=V.byteLength(e);else{if(!V.isBuffer(e))return t.error("Unsupported type: "+typeof e);this.value=e,this.length=e.length}}N(J,R),z.DecoderBuffer=J,J.isDecoderBuffer=function(e){if(e instanceof J)return!0;return"object"==typeof e&&V.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},J.prototype.save=function(){return{offset:this.offset,reporter:R.prototype.save.call(this)}},J.prototype.restore=function(e){const t=new J(this.base);return t.offset=e.offset,t.length=this.offset,this.offset=e.offset,R.prototype.restore.call(this,e.reporter),t},J.prototype.isEmpty=function(){return this.offset===this.length},J.prototype.readUInt8=function(e){return this.offset+1<=this.length?this.base.readUInt8(this.offset++,!0):this.error(e||"DecoderBuffer overrun")},J.prototype.skip=function(e,t){if(!(this.offset+e<=this.length))return this.error(t||"DecoderBuffer overrun");const r=new J(this.base);return r._reporterState=this._reporterState,r.offset=this.offset,r.length=this.offset+e,this.offset+=e,r},J.prototype.raw=function(e){return this.base.slice(e?e.offset:this.offset,this.length)},z.EncoderBuffer=M,M.isEncoderBuffer=function(e){if(e instanceof M)return!0;return"object"==typeof e&&"EncoderBuffer"===e.constructor.name&&"number"==typeof e.length&&"function"==typeof e.join},M.prototype.join=function(e,t){return e||(e=V.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):V.isBuffer(this.value)&&this.value.copy(e,t),t+=this.length)),e};const L=T.Reporter,$=z.EncoderBuffer,F=z.DecoderBuffer,G=h,Y=["seq","seqof","set","setof","objid","bool","gentime","utctime","null_","enum","int","objDesc","bitstr","bmpstr","charstr","genstr","graphstr","ia5str","iso646str","numstr","octstr","printstr","t61str","unistr","utf8str","videostr"],H=["key","obj","use","optional","explicit","implicit","def","choice","any","contains"].concat(Y);function W(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())}var X=W;const Z=["enc","parent","children","tag","args","reverseArgs","choice","optional","any","obj","use","alteredUse","key","default","explicit","implicit","contains"];W.prototype.clone=function(){const e=this._baseState,t={};Z.forEach((function(r){t[r]=e[r]}));const r=new this.constructor(t.parent);return r._baseState=t,r},W.prototype._wrap=function(){const e=this._baseState;H.forEach((function(t){this[t]=function(){const r=new this.constructor(this);return e.children.push(r),r[t].apply(r,arguments)}}),this)},W.prototype._init=function(e){const t=this._baseState;G(null===t.parent),e.call(this),t.children=t.children.filter((function(e){return e._baseState.parent===this}),this),G.equal(t.children.length,1,"Root node can have only one child")},W.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&&(G(null===t.children),t.children=r,r.forEach((function(e){e._baseState.parent=this}),this)),0!==e.length&&(G(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){W.prototype[e]=function(){const t=this._baseState;throw new Error(e+" not implemented for encoding: "+t.enc)}})),Y.forEach((function(e){W.prototype[e]=function(){const t=this._baseState,r=Array.prototype.slice.call(arguments);return G(null===t.tag),t.tag=e,this._useArgs(r),this}})),W.prototype.use=function(e){G(e);const t=this._baseState;return G(null===t.use),t.use=e,this},W.prototype.optional=function(){return this._baseState.optional=!0,this},W.prototype.def=function(e){const t=this._baseState;return G(null===t.default),t.default=e,t.optional=!0,this},W.prototype.explicit=function(e){const t=this._baseState;return G(null===t.explicit&&null===t.implicit),t.explicit=e,this},W.prototype.implicit=function(e){const t=this._baseState;return G(null===t.explicit&&null===t.implicit),t.implicit=e,this},W.prototype.obj=function(){const e=this._baseState,t=Array.prototype.slice.call(arguments);return e.obj=!0,0!==t.length&&this._useArgs(t),this},W.prototype.key=function(e){const t=this._baseState;return G(null===t.key),t.key=e,this},W.prototype.any=function(){return this._baseState.any=!0,this},W.prototype.choice=function(e){const t=this._baseState;return G(null===t.choice),t.choice=e,this._useArgs(Object.keys(e).map((function(t){return e[t]}))),this},W.prototype.contains=function(e){const t=this._baseState;return G(null===t.use),t.contains=e,this},W.prototype._decode=function(e,t){const r=this._baseState;if(null===r.parent)return e.wrapResult(r.children[0]._decode(e,t));let n,o=r.default,i=!0,s=null;if(null!==r.key&&(s=e.enterKey(r.key)),r.optional){let n=null;if(null!==r.explicit?n=r.explicit:null!==r.implicit?n=r.implicit:null!==r.tag&&(n=r.tag),null!==n||r.any){if(i=this._peekTag(e,n,r.any),e.isError(i))return i}else{const n=e.save();try{null===r.choice?this._decodeGeneric(r.tag,e,t):this._decodeChoice(e,t),i=!0}catch(e){i=!1}e.restore(n)}}if(r.obj&&i&&(n=e.enterObject()),i){if(null!==r.explicit){const t=this._decodeTag(e,r.explicit);if(e.isError(t))return t;e=t}const n=e.offset;if(null===r.use&&null===r.choice){let t;r.any&&(t=e.save());const n=this._decodeTag(e,null!==r.implicit?r.implicit:r.tag,r.any);if(e.isError(n))return n;r.any?o=e.raw(t):e=n}if(t&&t.track&&null!==r.tag&&t.track(e.path(),n,e.length,"tagged"),t&&t.track&&null!==r.tag&&t.track(e.path(),e.offset,e.length,"content"),r.any||(o=null===r.choice?this._decodeGeneric(r.tag,e,t):this._decodeChoice(e,t)),e.isError(o))return o;if(r.any||null!==r.choice||null===r.children||r.children.forEach((function(r){r._decode(e,t)})),r.contains&&("octstr"===r.tag||"bitstr"===r.tag)){const n=new F(o);o=this._getUse(r.contains,e._reporterState.obj)._decode(n,t)}}return r.obj&&i&&(o=e.leaveObject(n)),null===r.key||null===o&&!0!==i?null!==s&&e.exitKey(s):e.leaveKey(s,r.key,o),o},W.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)},W.prototype._getUse=function(e,t){const r=this._baseState;return r.useDecoder=this._use(e,t),G(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},W.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")},W.prototype._createEncoderBuffer=function(e){return new $(e,this.reporter)},W.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},W.prototype._encodeValue=function(e,t,r){const n=this._baseState;if(null===n.parent)return n.children[0]._encode(e,t||new L);let o=null;if(this.reporter=t,n.optional&&void 0===e){if(null===n.default)return;e=n.default}let i=null,s=!1;if(n.any)o=this._createEncoderBuffer(e);else if(n.choice)o=this._encodeChoice(e,t);else if(n.contains)i=this._getUse(n.contains,r)._encode(e,t),s=!0;else if(n.children)i=n.children.map((function(r){if("null_"===r._baseState.tag)return r._encode(null,t,e);if(null===r._baseState.key)return t.error("Child should have a key");const n=t.enterKey(r._baseState.key);if("object"!=typeof e)return t.error("Child expected, but input is not object");const o=r._encode(e[r._baseState.key],t,e);return t.leaveKey(n),o}),this).filter((function(e){return e})),i=this._createEncoderBuffer(i);else if("seqof"===n.tag||"setof"===n.tag){if(!n.args||1!==n.args.length)return t.error("Too many args for : "+n.tag);if(!Array.isArray(e))return t.error("seqof/setof, but data is not Array");const r=this.clone();r._baseState.implicit=null,i=this._createEncoderBuffer(e.map((function(r){const n=this._baseState;return this._getUse(n.args[0],e)._encode(r,t)}),r))}else null!==n.use?o=this._getUse(n.use,r)._encode(e,t):(i=this._encodePrimitive(n.tag,e),s=!0);if(!n.any&&null===n.choice){const e=null!==n.implicit?n.implicit:n.tag,r=null===n.implicit?"universal":"context";null===e?null===n.use&&t.error("Tag could be omitted only for .use()"):null===n.use&&(o=this._encodeComposite(e,s,r,i))}return null!==n.explicit&&(o=this._encodeComposite(n.explicit,!1,"context",o)),o},W.prototype._encodeChoice=function(e,t){const r=this._baseState,n=r.choice[e.type];return n||G(!1,e.type+" not found in "+JSON.stringify(Object.keys(r.choice))),n._encode(e.value,t)},W.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)},W.prototype._isNumstr=function(e){return/^[0-9 ]*$/.test(e)},W.prototype._isPrintstr=function(e){return/^[A-Za-z0-9 '()+,-./:=?]*$/.test(e)};var Q={};!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)}(Q);const ee=p,te=q.Buffer,re=X,ne=Q;function oe(e){this.enc="der",this.name=e.name,this.entity=e,this.tree=new se,this.tree._init(e.body)}var ie=oe;function se(e){re.call(this,"der",e)}function ae(e){return e<10?"0"+e:e}oe.prototype.encode=function(e,t){return this.tree._encode(e,t).join()},ee(se,re),se.prototype._encodeComposite=function(e,t,r,n){const o=function(e,t,r,n){let o;"seqof"===e?e="seq":"setof"===e&&(e="set");if(ne.tagByName.hasOwnProperty(e))o=ne.tagByName[e];else{if("number"!=typeof e||(0|e)!==e)return n.error("Unknown tag: "+e);o=e}if(o>=31)return n.error("Multi-octet tag encoding unsupported");t||(o|=32);return o|=ne.tagClassByName[r||"universal"]<<6,o}(e,t,r,this.reporter);if(n.length<128){const e=te.alloc(2);return e[0]=o,e[1]=n.length,this._createEncoderBuffer([e,n])}let i=1;for(let e=n.length;e>=256;e>>=8)i++;const s=te.alloc(2+i);s[0]=o,s[1]=128|i;for(let e=1+i,t=n.length;t>0;e--,t>>=8)s[e]=255&t;return this._createEncoderBuffer([s,n])},se.prototype._encodeStr=function(e,t){if("bitstr"===t)return this._createEncoderBuffer([0|e.unused,e.data]);if("bmpstr"===t){const t=te.alloc(2*e.length);for(let r=0;r<e.length;r++)t.writeUInt16BE(e.charCodeAt(r),2*r);return this._createEncoderBuffer(t)}return"numstr"===t?this._isNumstr(e)?this._createEncoderBuffer(e):this.reporter.error("Encoding of string type: numstr supports only digits and space"):"printstr"===t?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(t)||"objDesc"===t?this._createEncoderBuffer(e):this.reporter.error("Encoding of string type: "+t+" unsupported")},se.prototype._encodeObjid=function(e,t,r){if("string"==typeof e){if(!t)return this.reporter.error("string objid given, but no values map found");if(!t.hasOwnProperty(e))return this.reporter.error("objid not found in values map");e=t[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(!r){if(e[1]>=40)return this.reporter.error("Second objid identifier OOB");e.splice(0,2,40*e[0]+e[1])}let n=0;for(let t=0;t<e.length;t++){let r=e[t];for(n++;r>=128;r>>=7)n++}const o=te.alloc(n);let i=o.length-1;for(let t=e.length-1;t>=0;t--){let r=e[t];for(o[i--]=127&r;(r>>=7)>0;)o[i--]=128|127&r}return this._createEncoderBuffer(o)},se.prototype._encodeTime=function(e,t){let r;const n=new Date(e);return"gentime"===t?r=[ae(n.getUTCFullYear()),ae(n.getUTCMonth()+1),ae(n.getUTCDate()),ae(n.getUTCHours()),ae(n.getUTCMinutes()),ae(n.getUTCSeconds()),"Z"].join(""):"utctime"===t?r=[ae(n.getUTCFullYear()%100),ae(n.getUTCMonth()+1),ae(n.getUTCDate()),ae(n.getUTCHours()),ae(n.getUTCMinutes()),ae(n.getUTCSeconds()),"Z"].join(""):this.reporter.error("Encoding "+t+" time is not supported yet"),this._encodeStr(r,"octstr")},se.prototype._encodeNull=function(){return this._createEncoderBuffer("")},se.prototype._encodeInt=function(e,t){if("string"==typeof e){if(!t)return this.reporter.error("String int or enum given, but no values map");if(!t.hasOwnProperty(e))return this.reporter.error("Values map doesn't contain: "+JSON.stringify(e));e=t[e]}if("number"!=typeof e&&!te.isBuffer(e)){const t=e.toArray();!e.sign&&128&t[0]&&t.unshift(0),e=te.from(t)}if(te.isBuffer(e)){let t=e.length;0===e.length&&t++;const r=te.alloc(t);return e.copy(r),0===e.length&&(r[0]=0),this._createEncoderBuffer(r)}if(e<128)return this._createEncoderBuffer(e);if(e<256)return this._createEncoderBuffer([0,e]);let r=1;for(let t=e;t>=256;t>>=8)r++;const n=new Array(r);for(let t=n.length-1;t>=0;t--)n[t]=255&e,e>>=8;return 128&n[0]&&n.unshift(0),this._createEncoderBuffer(te.from(n))},se.prototype._encodeBool=function(e){return this._createEncoderBuffer(e?255:0)},se.prototype._use=function(e,t){return"function"==typeof e&&(e=e(t)),e._getEncoder("der").tree},se.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};const ce=ie;function le(e){ce.call(this,e),this.enc="pem"}p(le,ce);var ue=le;le.prototype.encode=function(e,t){const r=ce.prototype.encode.call(this,e).toString("base64"),n=["-----BEGIN "+t.label+"-----"];for(let e=0;e<r.length;e+=64)n.push(r.slice(e,e+64));return n.push("-----END "+t.label+"-----"),n.join("\n")},function(e){const t=e;t.der=ie,t.pem=ue}(B);var fe={};const pe=p,he=u,de=z.DecoderBuffer,ye=X,me=Q;function be(e){this.enc="der",this.name=e.name,this.entity=e,this.tree=new ge,this.tree._init(e.body)}var ve=be;function ge(e){ye.call(this,"der",e)}function we(e,t){let r=e.readUInt8(t);if(e.isError(r))return r;const n=me.tagClass[r>>6],o=0==(32&r);if(31==(31&r)){let n=r;for(r=0;128==(128&n);){if(n=e.readUInt8(t),e.isError(n))return n;r<<=7,r|=127&n}}else r&=31;return{cls:n,primitive:o,tag:r,tagStr:me.tag[r]}}function _e(e,t,r){let n=e.readUInt8(r);if(e.isError(n))return n;if(!t&&128===n)return null;if(0==(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}be.prototype.decode=function(e,t){return de.isDecoderBuffer(e)||(e=new de(e,t)),this.tree._decode(e,t)},pe(ge,ye),ge.prototype._peekTag=function(e,t,r){if(e.isEmpty())return!1;const n=e.save(),o=we(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)},ge.prototype._decodeTag=function(e,t,r){const n=we(e,'Failed to decode tag of "'+t+'"');if(e.isError(n))return n;let o=_e(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+'"'))},ge.prototype._skipUntilEnd=function(e,t){for(;;){const r=we(e,t);if(e.isError(r))return r;const n=_e(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}},ge.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},ge.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")},ge.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,0==(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},ge.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)},ge.prototype._decodeNull=function(){return null},ge.prototype._decodeBool=function(e){const t=e.readUInt8();return e.isError(t)?t:0!==t},ge.prototype._decodeInt=function(e,t){const r=e.raw();let n=new he(r);return t&&(n=t[n.toString(10)]||n),n},ge.prototype._use=function(e,t){return"function"==typeof e&&(e=e(t)),e._getDecoder("der").tree};const ke=p,Pe=q.Buffer,Se=ve;function Ee(e){Se.call(this,e),this.enc="pem"}ke(Ee,Se);var Ke=Ee;Ee.prototype.decode=function(e,t){const r=e.toString().split(/[\r\n]+/g),n=t.label.toUpperCase(),o=/^-----(BEGIN|END) ([^-]+)-----$/;let i=-1,s=-1;for(let e=0;e<r.length;e++){const t=r[e].match(o);if(null!==t&&t[2]===n){if(-1!==i){if("END"!==t[1])break;s=e;break}if("BEGIN"!==t[1])break;i=e}}if(-1===i||-1===s)throw new Error("PEM section not found for: "+n);const a=r.slice(i+1,s).join("");a.replace(/[^a-z0-9+/=]+/gi,"");const c=Pe.from(a,"base64");return Se.prototype.decode.call(this,c,t)},function(e){const t=e;t.der=ve,t.pem=Ke}(fe),function(e){const t=B,r=fe,n=p;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)}}(C);var Ce={};!function(e){const t=Ce;t.Reporter=T.Reporter,t.DecoderBuffer=z.DecoderBuffer,t.EncoderBuffer=z.EncoderBuffer,t.Node=X}();var Be={};!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=Q}(Be),function(e){const t=K;t.bignum=u,t.define=C.define,t.base=Ce,t.constants=Be,t.decoders=fe,t.encoders=B}();var xe={exports:{}},je={},Ae={};Object.defineProperty(Ae,"__esModule",{value:!0}),Ae.default=function(e){var t=e.length,r=t%4;if(!r)return e;var n=t,o=4-r,s=t+o,a=i.alloc(s);for(a.write(e);o--;)a.write("=",n++);return a.toString()},Object.defineProperty(je,"__esModule",{value:!0});var Ie=Ae;function qe(e,t){return void 0===t&&(t="utf8"),s(e)?Ue(e.toString("base64")):Ue(i.from(e,t).toString("base64"))}function Te(e){return e=e.toString(),Ie.default(e).replace(/\-/g,"+").replace(/_/g,"/")}function Ue(e){return e.replace(/=/g,"").replace(/\+/g,"-").replace(/\//g,"_")}var De,Oe=qe;Oe.encode=qe,Oe.decode=function(e,t){return void 0===t&&(t="utf8"),i.from(Te(e),"base64").toString(t)},Oe.toBase64=Te,Oe.fromBase64=Ue,Oe.toBuffer=function(e){return i.from(Te(e),"base64")},je.default=Oe,(De=xe).exports=je.default,De.exports.default=De.exports;var ze=xe.exports,Ne=a(ze);const Re=K,Ve=ze;var Je=class{static convert(e,t,r){if(!e)return;if(t===r)return e;let n;if("raw"===t||e instanceof i)n=e;else if("uint8_array"===t||Array.isArray(e))n=i.from(e);else if("hex"===t)n=i.from(e,"hex");else if("base64"===t)n=i.from(e,"base64");else if("base64url"===t)n=Ve.toBuffer(e);else{if("bn"!==t&&"bignum"!==t)throw new Error("Invalid fromType");n=i.from(this.pad(e.toString(16)),"hex")}if("raw"===r)return n;if("uint8_array"===r)return Array.from(n);if("hex"===r)return n.toString("hex");if("base64"===r)return n.toString("base64");if("base64url"===r)return Ve.fromBase64(n.toString("base64"));if("bn"===r||"bignum"===r)return new Re.bignum(n);throw new Error("Invalid toType")}static pad(e){return e.length%2==1?`0${e}`:e}};const Me=K;const Le=new class{constructor(){Object.defineProperty(this,"_registry",{value:{}})}get registry(){return this._registry}define(e,t){this._registry[e]=Me.define(e,t(this))}normalize(e){return this.registry[e]}};Le.define("Version",(e=>function(){this.int({0:"two-prime",1:"multi"})})),Le.define("OtherPrimeInfos",(e=>function(){this.seq().obj(this.key("ri").int(),this.key("di").int(),this.key("ti").int())})),Le.define("AlgorithmIdentifier",(e=>function(){this.seq().obj(this.key("algorithm").objid(),this.key("parameters").optional().any())})),Le.define("PrivateKeyInfo",(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())}})),Le.define("PublicKeyInfo",(e=>{let t=e.normalize("AlgorithmIdentifier");return function(){this.seq().obj(this.key("algorithm").use(t),this.key("publicKey").bitstr())}})),Le.define("RSAPrivateKey",(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))}})),Le.define("RSAPublicKey",(e=>function(){this.seq().obj(this.key("n").int(),this.key("e").int())})),Le.define("ECPrivateKey",(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())}));var $e=Le;const Fe=E,Ge=Je,Ye=$e;var He=class e extends Fe{fromPrivatePKCS1(e){let t=Ye.normalize("RSAPrivateKey"),{n:r,e:n,d:o,p:i,q:s,dp:a,dq:c,qi:l}=t.decode(e,"der");return{n:Ge.convert(r,"bn","raw"),e:Ge.convert(n,"bn","raw"),d:Ge.convert(o,"bn","raw"),p:Ge.convert(i,"bn","raw"),q:Ge.convert(s,"bn","raw"),dp:Ge.convert(a,"bn","raw"),dq:Ge.convert(c,"bn","raw"),qi:Ge.convert(l,"bn","raw")}}fromPrivatePKCS8(e){let t=Ye.normalize("PrivateKeyInfo"),r=Ye.normalize("RSAPrivateKey"),n=t.decode(e,"der"),{n:o,e:i,d:s,p:a,q:c,dp:l,dq:u,qi:f}=r.decode(n.privateKey,"der");return{n:Ge.convert(o,"bn","raw"),e:Ge.convert(i,"bn","raw"),d:Ge.convert(s,"bn","raw"),p:Ge.convert(a,"bn","raw"),q:Ge.convert(c,"bn","raw"),dp:Ge.convert(l,"bn","raw"),dq:Ge.convert(u,"bn","raw"),qi:Ge.convert(f,"bn","raw")}}fromPublicPKCS1(e){let t=Ye.normalize("RSAPublicKey"),{n:r,e:n}=t.decode(e,"der");return{n:Ge.convert(r,"bn","raw"),e:Ge.convert(n,"bn","raw")}}fromPublicPKCS8(e){let t=Ye.normalize("PublicKeyInfo"),r=Ye.normalize("RSAPublicKey"),n=t.decode(e,"der"),{n:o,e:i}=r.decode(n.publicKey.data,"der");return{n:Ge.convert(o,"bn","raw"),e:Ge.convert(i,"bn","raw")}}fromJwk(e){let{n:t,e:r,d:n,p:o,q:i,dp:s,dq:a,qi:c,alg:l}=e;return{n:Ge.convert(t,"base64url","raw"),e:Ge.convert(r,"base64url","raw"),d:Ge.convert(n,"base64url","raw"),p:Ge.convert(o,"base64url","raw"),q:Ge.convert(i,"base64url","raw"),dp:Ge.convert(s,"base64url","raw"),dq:Ge.convert(a,"base64url","raw"),qi:Ge.convert(c,"base64url","raw")}}toPrivatePKCS1(t){let{n:r,e:n,d:o,p:i,q:s,dp:a,dq:c,qi:l}=t,{version:u}=this.params,f=Ye.normalize("RSAPrivateKey").encode({version:u,n:Ge.convert(r,"raw","bn"),e:Ge.convert(n,"raw","bn"),d:Ge.convert(o,"raw","bn"),p:Ge.convert(i,"raw","bn"),q:Ge.convert(s,"raw","bn"),dp:Ge.convert(a,"raw","bn"),dq:Ge.convert(c,"raw","bn"),qi:Ge.convert(l,"raw","bn")},"der").toString("base64");return e.formatPem(f,"RSA PRIVATE")}toPrivatePKCS8(t){let{n:r,e:n,d:o,p:s,q:a,dp:c,dq:l,qi:u}=t,{oid:f,algParameters:p,version:h}=this.params,d=Ye.normalize("PrivateKeyInfo"),y=Ye.normalize("RSAPrivateKey").encode({version:h,n:Ge.convert(r,"raw","bn"),e:Ge.convert(n,"raw","bn"),d:Ge.convert(o,"raw","bn"),p:Ge.convert(s,"raw","bn"),q:Ge.convert(a,"raw","bn"),dp:Ge.convert(c,"raw","bn"),dq:Ge.convert(l,"raw","bn"),qi:Ge.convert(u,"raw","bn")},"der"),m=d.encode({version:h,algorithm:{algorithm:f.split("."),parameters:i.from(p,"hex")},privateKey:y},"der").toString("base64");return e.formatPem(m,"PRIVATE")}toPublicPKCS1(t){let{n:r,e:n}=t,{version:o}=this.params,i=Ye.normalize("RSAPublicKey").encode({version:o,n:Ge.convert(r,"raw","bn"),e:Ge.convert(n,"raw","bn")},"der").toString("base64");return e.formatPem(i,"RSA PUBLIC")}toPublicPKCS8(t){let{n:r,e:n}=t,{oid:o,algParameters:s}=this.params,a=Ye.normalize("PublicKeyInfo"),c=Ye.normalize("RSAPublicKey").encode({n:Ge.convert(r,"raw","bn"),e:Ge.convert(n,"raw","bn")},"der"),l=a.encode({algorithm:{algorithm:o.split("."),parameters:i.from(s,"hex")},publicKey:{unused:0,data:c}},"der").toString("base64");return e.formatPem(l,"PUBLIC")}toPrivateJwk(e){let{n:t,e:r,d:n,p:o,q:i,dp:s,dq:a,qi:c}=e,{kty:l}=this.params;return{kty:l,n:Ge.convert(t,"raw","base64url"),e:Ge.convert(r,"raw","base64url"),d:Ge.convert(n,"raw","base64url"),p:Ge.convert(o,"raw","base64url"),q:Ge.convert(i,"raw","base64url"),dp:Ge.convert(s,"raw","base64url"),dq:Ge.convert(a,"raw","base64url"),qi:Ge.convert(c,"raw","base64url")}}toPublicJwk(e){let{n:t,e:r}=e,{kty:n}=this.params;return{kty:n,n:Ge.convert(t,"raw","base64url"),e:Ge.convert(r,"raw","base64url")}}};const We=new(0,d.ec)("secp256k1"),Xe=E,Ze=Je,Qe=$e;var et=class e extends Xe{fromPrivatePKCS1(t){let r=Qe.normalize("ECPrivateKey").decode(t,"der"),{privateKey:n,publicKey:{data:o}}=r,i=Ze.convert(o,"raw","hex"),{x:s,y:a}=e.getPoint(i);return{d:n,x:s,y:a}}fromPrivatePKCS8(t){let r=Qe.normalize("PrivateKeyInfo"),n=Qe.normalize("ECPrivateKey"),o=r.decode(t,"der"),i=n.decode(o.privateKey,"der"),{privateKey:s,publicKey:{data:a}}=i,c=Ze.convert(a,"raw","hex"),{x:l,y:u}=e.getPoint(c);return{d:s,x:l,y:u}}fromPublicPKCS8(t){let r=Qe.normalize("PublicKeyInfo").decode(t,"der"),n=Ze.convert(r.publicKey.data,"raw","hex");return e.getPoint(n)}fromPrivateBlk(e){let t=We.keyFromPrivate(e,"hex"),r=t.getPublic();return{d:Ze.convert(t.priv,"bn","raw"),x:Ze.convert(r.getX(),"bn","raw"),y:Ze.convert(r.getY(),"bn","raw")}}fromPublicBlk(t){return e.getPoint(t)}fromJwk(e){let{d:t,x:r,y:n}=e;return{d:Ze.convert(t,"base64url","raw"),x:Ze.convert(r,"base64url","raw"),y:Ze.convert(n,"base64url","raw")}}toPrivatePKCS1(t){let{namedCurve:r,keyVersion:n}=this.params,{d:o,x:i,y:s}=t,a=Qe.normalize("ECPrivateKey"),c=e.makePoint(i,s),l=a.encode({version:n,privateKey:o,parameters:{type:"namedCurve",value:r.split(".")},publicKey:{unused:0,data:c}},"der").toString("base64");return e.formatPem(l,"EC PRIVATE")}toPrivatePKCS8(t){let{oid:r,algParameters:n,keyVersion:o,infoVersion:s}=this.params,{d:a,x:c,y:l}=t,u=Qe.normalize("PrivateKeyInfo"),f=Qe.normalize("ECPrivateKey"),p=e.makePoint(c,l),h=f.encode({version:o,privateKey:a,publicKey:{unused:0,data:p}},"der"),d=u.encode({version:s,algorithm:{algorithm:r.split("."),parameters:i.from(n,"hex")},privateKey:h},"der").toString("base64");return e.formatPem(d,"PRIVATE")}toPublicPKCS8(t){let{oid:r,algParameters:n}=this.params,{x:o,y:s}=t,a=Qe.normalize("PublicKeyInfo"),c=e.makePoint(o,s),l=a.encode({algorithm:{algorithm:r.split("."),parameters:i.from(n,"hex")},publicKey:{unused:0,data:c}},"der").toString("base64");return e.formatPem(l,"PUBLIC")}toPrivateBlk(e){return e.d.toString("hex")}toPublicBlk(t){return Ze.convert(e.makePoint(t.x,t.y),"raw","hex")}toPrivateJwk(e){let{crv:t,kty:r}=this.params,{d:n,x:o,y:i}=e;return{kty:r,crv:t,d:Ze.convert(n,"raw","base64url"),x:Ze.convert(o,"raw","base64url"),y:Ze.convert(i,"raw","base64url")}}toPublicJwk(e){let{crv:t,kty:r}=this.params,{x:n,y:o}=e;return{kty:r,crv:t,x:Ze.convert(n,"raw","base64url"),y:Ze.convert(o,"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:Ze.convert(t,"hex","raw"),y:Ze.convert(r,"hex","raw")}}static makePoint(e,t){let r=i.from("04","hex");return i.concat([r,e,t],r.length+e.length+t.length)}};const tt=E,rt=Je,nt=$e;var ot=class e extends tt{fromPrivatePKCS8(e){const t=nt.normalize("PrivateKeyInfo").decode(e,"der").privateKey.slice(2);return{d:t,x:this.publicKeyFromPrivate(t)}}fromPublicPKCS8(e){const t=nt.normalize("PublicKeyInfo").decode(e,"der");return{x:rt.convert(t.publicKey.data,"hex","raw")}}fromJwk(e){let{d:t,x:r}=e;return{d:rt.convert(t,"base64url","raw"),x:rt.convert(r,"base64url","raw")}}toPrivatePKCS8(t){let{oid:r,infoVersion:n}=this.params,{d:o}=t;const i=nt.normalize("PrivateKeyInfo"),s=this.privateKeyPadding(o);let a=i.encode({version:n,algorithm:{algorithm:r.split(".")},privateKey:s},"der").toString("base64");return e.formatPem(a,"PRIVATE")}toPublicPKCS8(t){let{oid:r}=this.params,{x:n}=t,o=nt.normalize("PublicKeyInfo").encode({algorithm:{algorithm:r.split(".")},publicKey:{unused:0,data:rt.convert(n,"hex","raw")}},"der").toString("base64");return e.formatPem(o,"PUBLIC")}toPrivateJwk(e){let{crv:t,kty:r}=this.params,{d:n,x:o}=e;return{kty:r,crv:t,d:rt.convert(n,"raw","base64url"),x:rt.convert(o,"raw","base64url")}}toPublicJwk(e){let{crv:t,kty:r}=this.params,{x:n}=e;return{kty:r,crv:t,x:rt.convert(n,"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=i.from("0420","hex"),i.concat([t,e],t.length+e.length)}publicKeyFromPrivate(e){if("Ed25519"===this.params.crv){const t=new(0,d.eddsa)("ed25519");return i.from(t.keyFromSecret(e).getPublic())}throw new Error(`${this.params.crv} is an invalid curve for EdDSA`)}};const it=He,st=et,at=ot,ct=new k;ct.define([{kty:"RSA",oid:"1.2.840.113549.1.1.1",algParameters:"0500",version:"two-prime"}],it),ct.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"}],st),ct.define([{kty:"OKP",crv:"Ed25519",oid:"1.3.101.112",infoVersion:"two-prime"}],at);const lt=w,ut=_,ft=ct,pt=$e,ht=RegExp("\r?\n","g");class dt{constructor(e,t){if(!e)throw new lt("key is required");if(!t)throw new lt("options are required");let{kty:r,format:n,selector:o,crv:i,oid:s}=t;if(!t.kty)throw new lt("options.kty is required");if(!t.format)throw new lt("options.format is required");if(!t.selector)throw new lt("options.selector is required");if(!t.crv&&!t.oid)throw new lt("options.crv or options.oid is required");this.kty=r,this.format=n,this.selector=o,this.crv=i,this.oid=s,this.key=this.parseKey(e)}static from(e,t){if(!e)throw new lt("key is required");if(!t)throw new lt("format is required");if("jwk"===t){let r;if("string"==typeof e)try{r=JSON.parse(e)}catch(e){throw new lt("key is not a valid JWK")}else"object"==typeof e&&(r=e);let n,{kty:o,crv:i}=r;if(!o)throw new lt("kty is required for JWK");if("EC"===o&&!i)throw new lt("crv is required for EC JWK");"RSA"===o&&(n=ft.find((e=>e.kty===o)).oid);let s=r.d?"private":"public";return new dt(r,{kty:o,crv:i,oid:n,format:t,selector:s})}if("pem"===t){if("string"!=typeof e)throw new lt("key is not a valid PEM string");let r=e.split(ht),n=r.splice(0,1);r.splice(r.length-1,1);let o,s,a=r.join(""),c=/^-----BEGIN ((RSA|EC) )?(PUBLIC|PRIVATE) KEY-----$/.exec(n),l=c?c[2]:void 0,u=c?c[3]:void 0,f=i.from(a,"base64");if(!u)throw new lt("key is not a valid PEM string");if(l){if("RSA"===l)u="PRIVATE"===u?"private_pkcs1":"public_pkcs1",o=ft.find((e=>e.kty===l)).oid;else if("EC"===l){let e;if("PRIVATE"===u){u="private_pkcs1",e=pt.normalize(`${l}PrivateKey`).decode(f,"der")}else if("PUBLIC"===u){u="public_pkcs1",e=pt.normalize(`${l}PrivateKey`).decode(f,"der")}let{parameters:{value:t}}=e;s=ft.find((e=>e.namedCurve===t.join("."))).crv}}else{let e,t=pt.normalize("PrivateKeyInfo"),r=pt.normalize("PublicKeyInfo");"PRIVATE"===u?(u="private_pkcs8",e=t.decode(f,"der")):"PUBLIC"===u&&(u="public_pkcs8",e=r.decode(f,"der"));let{algorithm:{algorithm:n,parameters:i}}=e;n=n.join("."),i=i?i.toString("hex"):void 0;const a=ft.find((e=>e.oid===n));if(l=a?a.kty:void 0,!l)throw new lt(`${n} is not supported`);"RSA"===l||"OKP"===l?o=n:"EC"===l&&(s=ft.find((e=>e.algParameters===i)).crv)}return new dt(f,{kty:l,oid:o,crv:s,format:t,selector:u})}if("blk"===t)return new dt(e,{kty:"EC",crv:"K-256",format:t,selector:e.length>64?"public":"private"});throw new lt(`Invalid format ${t}`)}get alg(){let{kty:e,crv:t,oid:r}=this;if(!this.algorithm){if(t)Object.defineProperty(this,"algorithm",{value:ft.normalize(e,"crv",t)});else{if(!r)throw new Error("Both crv and oid are undefined");Object.defineProperty(this,"algorithm",{value:ft.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(e){let{key:t,alg:r,selector:n}=this;switch(e){case"public":return r.toPublicJwk(t);case"private":if(n.includes("public"))throw new lt("Cannot export a private key from a public key");return r.toPrivateJwk(t);default:throw new Error("Invalid key selector")}}toString(e="pem",t="public_pkcs8"){let{key:r,alg:n,selector:o}=this;if("pem"===e)switch(t){case"public_pkcs1":return n.toPublicPKCS1(r);case"public_pkcs8":return n.toPublicPKCS8(r);case"private_pkcs1":if(o.includes("public"))throw new lt("Cannot export a private key from a public key");return n.toPrivatePKCS1(r);case"private_pkcs8":if(o.includes("public"))throw new lt("Cannot export a private key from a public key");return n.toPrivatePKCS8(r);default:throw new Error("Invalid key selector")}else if("jwk"===e)switch(t){case"public":return JSON.stringify(n.toPublicJwk(r));case"private":if(o.includes("public"))throw new lt("Cannot export a private key from a public key");return JSON.stringify(n.toPrivateJwk(r));default:throw new Error("Invalid key selector")}else if("blk"===e)switch(t){case"private":if(o.includes("public"))throw new lt("Cannot export a private key from a public key");return n.toPrivateBlk(r);case"public":return n.toPublicBlk(r);default:throw new Error("Invalid key selector")}throw new ut}}var yt=a(dt);var mt=function(e){if(e.length>=255)throw new TypeError("Alphabet too long");for(var t=new Uint8Array(256),r=0;r<t.length;r++)t[r]=255;for(var n=0;n<e.length;n++){var o=e.charAt(n),i=o.charCodeAt(0);if(255!==t[i])throw new TypeError(o+" is ambiguous");t[i]=n}var s=e.length,a=e.charAt(0),c=Math.log(s)/Math.log(256),l=Math.log(256)/Math.log(s);function u(e){if("string"!=typeof e)throw new TypeError("Expected String");if(0===e.length)return new Uint8Array;for(var r=0,n=0,o=0;e[r]===a;)n++,r++;for(var i=(e.length-r)*c+1>>>0,l=new Uint8Array(i);e[r];){var u=t[e.charCodeAt(r)];if(255===u)return;for(var f=0,p=i-1;(0!==u||f<o)&&-1!==p;p--,f++)u+=s*l[p]>>>0,l[p]=u%256>>>0,u=u/256>>>0;if(0!==u)throw new Error("Non-zero carry");o=f,r++}for(var h=i-o;h!==i&&0===l[h];)h++;for(var d=new Uint8Array(n+(i-h)),y=n;h!==i;)d[y++]=l[h++];return d}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"";for(var r=0,n=0,o=0,i=t.length;o!==i&&0===t[o];)o++,r++;for(var c=(i-o)*l+1>>>0,u=new Uint8Array(c);o!==i;){for(var f=t[o],p=0,h=c-1;(0!==f||p<n)&&-1!==h;h--,p++)f+=256*u[h]>>>0,u[h]=f%s>>>0,f=f/s>>>0;if(0!==f)throw new Error("Non-zero carry");n=p,o++}for(var d=c-n;d!==c&&0===u[d];)d++;for(var y=a.repeat(r);d<c;++d)y+=e.charAt(u[d]);return y},decodeUnsafe:u,decode:function(e){var t=u(e);if(t)return t;throw new Error("Non-base"+s+" character")}}};var bt=mt("123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"),vt=a(bt);export{b as a,m as b,bt as c,Ne as d,vt as e,yt as k,y as r,g as s};
|
|
3
|
+
!function(e,t){var r=f,n=r.Buffer;function o(e,t){for(var r in e)t[r]=e[r]}function i(e,t,r){return n(e,t,r)}n.from&&n.alloc&&n.allocUnsafe&&n.allocUnsafeSlow?e.exports=r:(o(r,t),t.Buffer=i),i.prototype=Object.create(n.prototype),o(n,i),i.from=function(e,t,r){if("number"==typeof e)throw new TypeError("Argument must not be a number");return n(e,t,r)},i.alloc=function(e,t,r){if("number"!=typeof e)throw new TypeError("Argument must be a number");var o=n(e);return void 0!==t?"string"==typeof r?o.fill(t,r):o.fill(t):o.fill(0),o},i.allocUnsafe=function(e){if("number"!=typeof e)throw new TypeError("Argument must be a number");return n(e)},i.allocUnsafeSlow=function(e){if("number"!=typeof e)throw new TypeError("Argument must be a number");return r.SlowBuffer(e)}}(v,v.exports);var g=v.exports;var w=class extends Error{constructor(e){super(e||"This operation is not supported for this key type")}};var _=class extends Error{constructor(){super("This has not been implemented yet")}};var k=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)}};const P=_;var S,E=class{constructor(e){this.params=e}fromPrivatePKCS1(e){throw new P}fromPrivatePKCS8(e){throw new P}fromPublicPKCS1(e){throw new P}fromPublicPKCS8(e){throw new P}fromPrivateBlk(e){throw new P}fromPublicBlk(e){throw new P}fromJwk(e){throw new P}toPrivatePKCS1(e){throw new P}toPrivatePKCS8(e){throw new P}toPublicPKCS1(e){throw new P}toPublicPKCS8(e){throw new P}toPrivateBlk(e){throw new P}toPublicBlk(e){throw new P}toPrivateJwk(e){throw new P}toPublicJwk(e){throw new P}static formatPem(e,t){return`-----BEGIN ${t} KEY-----\n`+e.match(/.{1,64}/g).join("\n")+`\n-----END ${t} KEY-----`}},K={},B={},C={},x=f,j=x.Buffer,A={};for(S in x)x.hasOwnProperty(S)&&"SlowBuffer"!==S&&"Buffer"!==S&&(A[S]=x[S]);var I=A.Buffer={};for(S in j)j.hasOwnProperty(S)&&"allocUnsafe"!==S&&"allocUnsafeSlow"!==S&&(I[S]=j[S]);if(A.Buffer.prototype=j.prototype,I.from&&I.from!==Uint8Array.from||(I.from=function(e,t,r){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 j(e,t,r)}),I.alloc||(I.alloc=function(e,t,r){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 n=j(e);return t&&0!==t.length?"string"==typeof r?n.fill(t,r):n.fill(t):n.fill(0),n}),!A.kStringMaxLength)try{A.kStringMaxLength=e.binding("buffer").kStringMaxLength}catch(e){}A.constants||(A.constants={MAX_LENGTH:A.kMaxLength},A.kStringMaxLength&&(A.constants.MAX_STRING_LENGTH=A.kStringMaxLength));var q=A,T={};const U=p;function O(e){this._reporterState={obj:null,path:[],options:e||{},errors:[]}}function D(e,t){this.path=e,this.rethrow(t)}T.Reporter=O,O.prototype.isError=function(e){return e instanceof D},O.prototype.save=function(){const e=this._reporterState;return{obj:e.obj,pathLen:e.path.length}},O.prototype.restore=function(e){const t=this._reporterState;t.obj=e.obj,t.path=t.path.slice(0,e.pathLen)},O.prototype.enterKey=function(e){return this._reporterState.path.push(e)},O.prototype.exitKey=function(e){const t=this._reporterState;t.path=t.path.slice(0,e-1)},O.prototype.leaveKey=function(e,t,r){const n=this._reporterState;this.exitKey(e),null!==n.obj&&(n.obj[t]=r)},O.prototype.path=function(){return this._reporterState.path.join("/")},O.prototype.enterObject=function(){const e=this._reporterState,t=e.obj;return e.obj={},t},O.prototype.leaveObject=function(e){const t=this._reporterState,r=t.obj;return t.obj=e,r},O.prototype.error=function(e){let t;const r=this._reporterState,n=e instanceof D;if(t=n?e:new D(r.path.map((function(e){return"["+JSON.stringify(e)+"]"})).join(""),e.message||e,e.stack),!r.options.partial)throw t;return n||r.errors.push(t),t},O.prototype.wrapResult=function(e){const t=this._reporterState;return t.options.partial?{result:this.isError(e)?null:e,errors:t.errors}:e},U(D,Error),D.prototype.rethrow=function(e){if(this.message=e+" at: "+(this.path||"(shallow)"),Error.captureStackTrace&&Error.captureStackTrace(this,D),!this.stack)try{throw new Error(this.message)}catch(e){this.stack=e.stack}return this};var z={};const N=p,R=T.Reporter,V=q.Buffer;function J(e,t){R.call(this,t),V.isBuffer(e)?(this.base=e,this.offset=0,this.length=e.length):this.error("Input not Buffer")}function M(e,t){if(Array.isArray(e))this.length=0,this.value=e.map((function(e){return M.isEncoderBuffer(e)||(e=new M(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=V.byteLength(e);else{if(!V.isBuffer(e))return t.error("Unsupported type: "+typeof e);this.value=e,this.length=e.length}}N(J,R),z.DecoderBuffer=J,J.isDecoderBuffer=function(e){if(e instanceof J)return!0;return"object"==typeof e&&V.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},J.prototype.save=function(){return{offset:this.offset,reporter:R.prototype.save.call(this)}},J.prototype.restore=function(e){const t=new J(this.base);return t.offset=e.offset,t.length=this.offset,this.offset=e.offset,R.prototype.restore.call(this,e.reporter),t},J.prototype.isEmpty=function(){return this.offset===this.length},J.prototype.readUInt8=function(e){return this.offset+1<=this.length?this.base.readUInt8(this.offset++,!0):this.error(e||"DecoderBuffer overrun")},J.prototype.skip=function(e,t){if(!(this.offset+e<=this.length))return this.error(t||"DecoderBuffer overrun");const r=new J(this.base);return r._reporterState=this._reporterState,r.offset=this.offset,r.length=this.offset+e,this.offset+=e,r},J.prototype.raw=function(e){return this.base.slice(e?e.offset:this.offset,this.length)},z.EncoderBuffer=M,M.isEncoderBuffer=function(e){if(e instanceof M)return!0;return"object"==typeof e&&"EncoderBuffer"===e.constructor.name&&"number"==typeof e.length&&"function"==typeof e.join},M.prototype.join=function(e,t){return e||(e=V.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):V.isBuffer(this.value)&&this.value.copy(e,t),t+=this.length)),e};const L=T.Reporter,$=z.EncoderBuffer,F=z.DecoderBuffer,G=d,Y=["seq","seqof","set","setof","objid","bool","gentime","utctime","null_","enum","int","objDesc","bitstr","bmpstr","charstr","genstr","graphstr","ia5str","iso646str","numstr","octstr","printstr","t61str","unistr","utf8str","videostr"],H=["key","obj","use","optional","explicit","implicit","def","choice","any","contains"].concat(Y);function W(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())}var X=W;const Z=["enc","parent","children","tag","args","reverseArgs","choice","optional","any","obj","use","alteredUse","key","default","explicit","implicit","contains"];W.prototype.clone=function(){const e=this._baseState,t={};Z.forEach((function(r){t[r]=e[r]}));const r=new this.constructor(t.parent);return r._baseState=t,r},W.prototype._wrap=function(){const e=this._baseState;H.forEach((function(t){this[t]=function(){const r=new this.constructor(this);return e.children.push(r),r[t].apply(r,arguments)}}),this)},W.prototype._init=function(e){const t=this._baseState;G(null===t.parent),e.call(this),t.children=t.children.filter((function(e){return e._baseState.parent===this}),this),G.equal(t.children.length,1,"Root node can have only one child")},W.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&&(G(null===t.children),t.children=r,r.forEach((function(e){e._baseState.parent=this}),this)),0!==e.length&&(G(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){W.prototype[e]=function(){const t=this._baseState;throw new Error(e+" not implemented for encoding: "+t.enc)}})),Y.forEach((function(e){W.prototype[e]=function(){const t=this._baseState,r=Array.prototype.slice.call(arguments);return G(null===t.tag),t.tag=e,this._useArgs(r),this}})),W.prototype.use=function(e){G(e);const t=this._baseState;return G(null===t.use),t.use=e,this},W.prototype.optional=function(){return this._baseState.optional=!0,this},W.prototype.def=function(e){const t=this._baseState;return G(null===t.default),t.default=e,t.optional=!0,this},W.prototype.explicit=function(e){const t=this._baseState;return G(null===t.explicit&&null===t.implicit),t.explicit=e,this},W.prototype.implicit=function(e){const t=this._baseState;return G(null===t.explicit&&null===t.implicit),t.implicit=e,this},W.prototype.obj=function(){const e=this._baseState,t=Array.prototype.slice.call(arguments);return e.obj=!0,0!==t.length&&this._useArgs(t),this},W.prototype.key=function(e){const t=this._baseState;return G(null===t.key),t.key=e,this},W.prototype.any=function(){return this._baseState.any=!0,this},W.prototype.choice=function(e){const t=this._baseState;return G(null===t.choice),t.choice=e,this._useArgs(Object.keys(e).map((function(t){return e[t]}))),this},W.prototype.contains=function(e){const t=this._baseState;return G(null===t.use),t.contains=e,this},W.prototype._decode=function(e,t){const r=this._baseState;if(null===r.parent)return e.wrapResult(r.children[0]._decode(e,t));let n,o=r.default,i=!0,s=null;if(null!==r.key&&(s=e.enterKey(r.key)),r.optional){let n=null;if(null!==r.explicit?n=r.explicit:null!==r.implicit?n=r.implicit:null!==r.tag&&(n=r.tag),null!==n||r.any){if(i=this._peekTag(e,n,r.any),e.isError(i))return i}else{const n=e.save();try{null===r.choice?this._decodeGeneric(r.tag,e,t):this._decodeChoice(e,t),i=!0}catch(e){i=!1}e.restore(n)}}if(r.obj&&i&&(n=e.enterObject()),i){if(null!==r.explicit){const t=this._decodeTag(e,r.explicit);if(e.isError(t))return t;e=t}const n=e.offset;if(null===r.use&&null===r.choice){let t;r.any&&(t=e.save());const n=this._decodeTag(e,null!==r.implicit?r.implicit:r.tag,r.any);if(e.isError(n))return n;r.any?o=e.raw(t):e=n}if(t&&t.track&&null!==r.tag&&t.track(e.path(),n,e.length,"tagged"),t&&t.track&&null!==r.tag&&t.track(e.path(),e.offset,e.length,"content"),r.any||(o=null===r.choice?this._decodeGeneric(r.tag,e,t):this._decodeChoice(e,t)),e.isError(o))return o;if(r.any||null!==r.choice||null===r.children||r.children.forEach((function(r){r._decode(e,t)})),r.contains&&("octstr"===r.tag||"bitstr"===r.tag)){const n=new F(o);o=this._getUse(r.contains,e._reporterState.obj)._decode(n,t)}}return r.obj&&i&&(o=e.leaveObject(n)),null===r.key||null===o&&!0!==i?null!==s&&e.exitKey(s):e.leaveKey(s,r.key,o),o},W.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)},W.prototype._getUse=function(e,t){const r=this._baseState;return r.useDecoder=this._use(e,t),G(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},W.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")},W.prototype._createEncoderBuffer=function(e){return new $(e,this.reporter)},W.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},W.prototype._encodeValue=function(e,t,r){const n=this._baseState;if(null===n.parent)return n.children[0]._encode(e,t||new L);let o=null;if(this.reporter=t,n.optional&&void 0===e){if(null===n.default)return;e=n.default}let i=null,s=!1;if(n.any)o=this._createEncoderBuffer(e);else if(n.choice)o=this._encodeChoice(e,t);else if(n.contains)i=this._getUse(n.contains,r)._encode(e,t),s=!0;else if(n.children)i=n.children.map((function(r){if("null_"===r._baseState.tag)return r._encode(null,t,e);if(null===r._baseState.key)return t.error("Child should have a key");const n=t.enterKey(r._baseState.key);if("object"!=typeof e)return t.error("Child expected, but input is not object");const o=r._encode(e[r._baseState.key],t,e);return t.leaveKey(n),o}),this).filter((function(e){return e})),i=this._createEncoderBuffer(i);else if("seqof"===n.tag||"setof"===n.tag){if(!n.args||1!==n.args.length)return t.error("Too many args for : "+n.tag);if(!Array.isArray(e))return t.error("seqof/setof, but data is not Array");const r=this.clone();r._baseState.implicit=null,i=this._createEncoderBuffer(e.map((function(r){const n=this._baseState;return this._getUse(n.args[0],e)._encode(r,t)}),r))}else null!==n.use?o=this._getUse(n.use,r)._encode(e,t):(i=this._encodePrimitive(n.tag,e),s=!0);if(!n.any&&null===n.choice){const e=null!==n.implicit?n.implicit:n.tag,r=null===n.implicit?"universal":"context";null===e?null===n.use&&t.error("Tag could be omitted only for .use()"):null===n.use&&(o=this._encodeComposite(e,s,r,i))}return null!==n.explicit&&(o=this._encodeComposite(n.explicit,!1,"context",o)),o},W.prototype._encodeChoice=function(e,t){const r=this._baseState,n=r.choice[e.type];return n||G(!1,e.type+" not found in "+JSON.stringify(Object.keys(r.choice))),n._encode(e.value,t)},W.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)},W.prototype._isNumstr=function(e){return/^[0-9 ]*$/.test(e)},W.prototype._isPrintstr=function(e){return/^[A-Za-z0-9 '()+,-./:=?]*$/.test(e)};var Q={};!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)}(Q);const ee=p,te=q.Buffer,re=X,ne=Q;function oe(e){this.enc="der",this.name=e.name,this.entity=e,this.tree=new se,this.tree._init(e.body)}var ie=oe;function se(e){re.call(this,"der",e)}function ae(e){return e<10?"0"+e:e}oe.prototype.encode=function(e,t){return this.tree._encode(e,t).join()},ee(se,re),se.prototype._encodeComposite=function(e,t,r,n){const o=function(e,t,r,n){let o;"seqof"===e?e="seq":"setof"===e&&(e="set");if(ne.tagByName.hasOwnProperty(e))o=ne.tagByName[e];else{if("number"!=typeof e||(0|e)!==e)return n.error("Unknown tag: "+e);o=e}if(o>=31)return n.error("Multi-octet tag encoding unsupported");t||(o|=32);return o|=ne.tagClassByName[r||"universal"]<<6,o}(e,t,r,this.reporter);if(n.length<128){const e=te.alloc(2);return e[0]=o,e[1]=n.length,this._createEncoderBuffer([e,n])}let i=1;for(let e=n.length;e>=256;e>>=8)i++;const s=te.alloc(2+i);s[0]=o,s[1]=128|i;for(let e=1+i,t=n.length;t>0;e--,t>>=8)s[e]=255&t;return this._createEncoderBuffer([s,n])},se.prototype._encodeStr=function(e,t){if("bitstr"===t)return this._createEncoderBuffer([0|e.unused,e.data]);if("bmpstr"===t){const t=te.alloc(2*e.length);for(let r=0;r<e.length;r++)t.writeUInt16BE(e.charCodeAt(r),2*r);return this._createEncoderBuffer(t)}return"numstr"===t?this._isNumstr(e)?this._createEncoderBuffer(e):this.reporter.error("Encoding of string type: numstr supports only digits and space"):"printstr"===t?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(t)||"objDesc"===t?this._createEncoderBuffer(e):this.reporter.error("Encoding of string type: "+t+" unsupported")},se.prototype._encodeObjid=function(e,t,r){if("string"==typeof e){if(!t)return this.reporter.error("string objid given, but no values map found");if(!t.hasOwnProperty(e))return this.reporter.error("objid not found in values map");e=t[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(!r){if(e[1]>=40)return this.reporter.error("Second objid identifier OOB");e.splice(0,2,40*e[0]+e[1])}let n=0;for(let t=0;t<e.length;t++){let r=e[t];for(n++;r>=128;r>>=7)n++}const o=te.alloc(n);let i=o.length-1;for(let t=e.length-1;t>=0;t--){let r=e[t];for(o[i--]=127&r;(r>>=7)>0;)o[i--]=128|127&r}return this._createEncoderBuffer(o)},se.prototype._encodeTime=function(e,t){let r;const n=new Date(e);return"gentime"===t?r=[ae(n.getUTCFullYear()),ae(n.getUTCMonth()+1),ae(n.getUTCDate()),ae(n.getUTCHours()),ae(n.getUTCMinutes()),ae(n.getUTCSeconds()),"Z"].join(""):"utctime"===t?r=[ae(n.getUTCFullYear()%100),ae(n.getUTCMonth()+1),ae(n.getUTCDate()),ae(n.getUTCHours()),ae(n.getUTCMinutes()),ae(n.getUTCSeconds()),"Z"].join(""):this.reporter.error("Encoding "+t+" time is not supported yet"),this._encodeStr(r,"octstr")},se.prototype._encodeNull=function(){return this._createEncoderBuffer("")},se.prototype._encodeInt=function(e,t){if("string"==typeof e){if(!t)return this.reporter.error("String int or enum given, but no values map");if(!t.hasOwnProperty(e))return this.reporter.error("Values map doesn't contain: "+JSON.stringify(e));e=t[e]}if("number"!=typeof e&&!te.isBuffer(e)){const t=e.toArray();!e.sign&&128&t[0]&&t.unshift(0),e=te.from(t)}if(te.isBuffer(e)){let t=e.length;0===e.length&&t++;const r=te.alloc(t);return e.copy(r),0===e.length&&(r[0]=0),this._createEncoderBuffer(r)}if(e<128)return this._createEncoderBuffer(e);if(e<256)return this._createEncoderBuffer([0,e]);let r=1;for(let t=e;t>=256;t>>=8)r++;const n=new Array(r);for(let t=n.length-1;t>=0;t--)n[t]=255&e,e>>=8;return 128&n[0]&&n.unshift(0),this._createEncoderBuffer(te.from(n))},se.prototype._encodeBool=function(e){return this._createEncoderBuffer(e?255:0)},se.prototype._use=function(e,t){return"function"==typeof e&&(e=e(t)),e._getEncoder("der").tree},se.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};const ce=ie;function ue(e){ce.call(this,e),this.enc="pem"}p(ue,ce);var le=ue;ue.prototype.encode=function(e,t){const r=ce.prototype.encode.call(this,e).toString("base64"),n=["-----BEGIN "+t.label+"-----"];for(let e=0;e<r.length;e+=64)n.push(r.slice(e,e+64));return n.push("-----END "+t.label+"-----"),n.join("\n")},function(e){const t=e;t.der=ie,t.pem=le}(C);var fe={};const pe=p,de=l,he=z.DecoderBuffer,ye=X,me=Q;function be(e){this.enc="der",this.name=e.name,this.entity=e,this.tree=new ge,this.tree._init(e.body)}var ve=be;function ge(e){ye.call(this,"der",e)}function we(e,t){let r=e.readUInt8(t);if(e.isError(r))return r;const n=me.tagClass[r>>6],o=0==(32&r);if(31==(31&r)){let n=r;for(r=0;128==(128&n);){if(n=e.readUInt8(t),e.isError(n))return n;r<<=7,r|=127&n}}else r&=31;return{cls:n,primitive:o,tag:r,tagStr:me.tag[r]}}function _e(e,t,r){let n=e.readUInt8(r);if(e.isError(n))return n;if(!t&&128===n)return null;if(0==(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}be.prototype.decode=function(e,t){return he.isDecoderBuffer(e)||(e=new he(e,t)),this.tree._decode(e,t)},pe(ge,ye),ge.prototype._peekTag=function(e,t,r){if(e.isEmpty())return!1;const n=e.save(),o=we(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)},ge.prototype._decodeTag=function(e,t,r){const n=we(e,'Failed to decode tag of "'+t+'"');if(e.isError(n))return n;let o=_e(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+'"'))},ge.prototype._skipUntilEnd=function(e,t){for(;;){const r=we(e,t);if(e.isError(r))return r;const n=_e(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}},ge.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},ge.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")},ge.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,0==(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},ge.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)},ge.prototype._decodeNull=function(){return null},ge.prototype._decodeBool=function(e){const t=e.readUInt8();return e.isError(t)?t:0!==t},ge.prototype._decodeInt=function(e,t){const r=e.raw();let n=new de(r);return t&&(n=t[n.toString(10)]||n),n},ge.prototype._use=function(e,t){return"function"==typeof e&&(e=e(t)),e._getDecoder("der").tree};const ke=p,Pe=q.Buffer,Se=ve;function Ee(e){Se.call(this,e),this.enc="pem"}ke(Ee,Se);var Ke=Ee;Ee.prototype.decode=function(e,t){const r=e.toString().split(/[\r\n]+/g),n=t.label.toUpperCase(),o=/^-----(BEGIN|END) ([^-]+)-----$/;let i=-1,s=-1;for(let e=0;e<r.length;e++){const t=r[e].match(o);if(null!==t&&t[2]===n){if(-1!==i){if("END"!==t[1])break;s=e;break}if("BEGIN"!==t[1])break;i=e}}if(-1===i||-1===s)throw new Error("PEM section not found for: "+n);const a=r.slice(i+1,s).join("");a.replace(/[^a-z0-9+/=]+/gi,"");const c=Pe.from(a,"base64");return Se.prototype.decode.call(this,c,t)},function(e){const t=e;t.der=ve,t.pem=Ke}(fe),function(e){const t=C,r=fe,n=p;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)}}(B);var Be={};!function(e){const t=Be;t.Reporter=T.Reporter,t.DecoderBuffer=z.DecoderBuffer,t.EncoderBuffer=z.EncoderBuffer,t.Node=X}();var Ce={};!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=Q}(Ce),function(e){const t=K;t.bignum=l,t.define=B.define,t.base=Be,t.constants=Ce,t.decoders=fe,t.encoders=C}();var xe={exports:{}},je={},Ae={};Object.defineProperty(Ae,"__esModule",{value:!0}),Ae.default=function(e){var t=e.length,r=t%4;if(!r)return e;var n=t,o=4-r,s=t+o,a=i.alloc(s);for(a.write(e);o--;)a.write("=",n++);return a.toString()},Object.defineProperty(je,"__esModule",{value:!0});var Ie=Ae;function qe(e,t){return void 0===t&&(t="utf8"),s(e)?Ue(e.toString("base64")):Ue(i.from(e,t).toString("base64"))}function Te(e){return e=e.toString(),Ie.default(e).replace(/\-/g,"+").replace(/_/g,"/")}function Ue(e){return e.replace(/=/g,"").replace(/\+/g,"-").replace(/\//g,"_")}var Oe,De=qe;De.encode=qe,De.decode=function(e,t){return void 0===t&&(t="utf8"),i.from(Te(e),"base64").toString(t)},De.toBase64=Te,De.fromBase64=Ue,De.toBuffer=function(e){return i.from(Te(e),"base64")},je.default=De,(Oe=xe).exports=je.default,Oe.exports.default=Oe.exports;var ze=xe.exports,Ne=a(ze);const Re=K,Ve=ze;var Je=class{static convert(e,t,r){if(!e)return;if(t===r)return e;let n;if("raw"===t||e instanceof i)n=e;else if("uint8_array"===t||Array.isArray(e))n=i.from(e);else if("hex"===t)n=i.from(e,"hex");else if("base64"===t)n=i.from(e,"base64");else if("base64url"===t)n=Ve.toBuffer(e);else{if("bn"!==t&&"bignum"!==t)throw new Error("Invalid fromType");n=i.from(this.pad(e.toString(16)),"hex")}if("raw"===r)return n;if("uint8_array"===r)return Array.from(n);if("hex"===r)return n.toString("hex");if("base64"===r)return n.toString("base64");if("base64url"===r)return Ve.fromBase64(n.toString("base64"));if("bn"===r||"bignum"===r)return new Re.bignum(n);throw new Error("Invalid toType")}static pad(e){return e.length%2==1?`0${e}`:e}};const Me=K;const Le=new class{constructor(){Object.defineProperty(this,"_registry",{value:{}})}get registry(){return this._registry}define(e,t){this._registry[e]=Me.define(e,t(this))}normalize(e){return this.registry[e]}};Le.define("Version",(e=>function(){this.int({0:"two-prime",1:"multi"})})),Le.define("OtherPrimeInfos",(e=>function(){this.seq().obj(this.key("ri").int(),this.key("di").int(),this.key("ti").int())})),Le.define("AlgorithmIdentifier",(e=>function(){this.seq().obj(this.key("algorithm").objid(),this.key("parameters").optional().any())})),Le.define("PrivateKeyInfo",(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())}})),Le.define("PublicKeyInfo",(e=>{let t=e.normalize("AlgorithmIdentifier");return function(){this.seq().obj(this.key("algorithm").use(t),this.key("publicKey").bitstr())}})),Le.define("RSAPrivateKey",(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))}})),Le.define("RSAPublicKey",(e=>function(){this.seq().obj(this.key("n").int(),this.key("e").int())})),Le.define("ECPrivateKey",(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())}));var $e=Le;const Fe=E,Ge=Je,Ye=$e;var He=class e extends Fe{fromPrivatePKCS1(e){let t=Ye.normalize("RSAPrivateKey"),{n:r,e:n,d:o,p:i,q:s,dp:a,dq:c,qi:u}=t.decode(e,"der");return{n:Ge.convert(r,"bn","raw"),e:Ge.convert(n,"bn","raw"),d:Ge.convert(o,"bn","raw"),p:Ge.convert(i,"bn","raw"),q:Ge.convert(s,"bn","raw"),dp:Ge.convert(a,"bn","raw"),dq:Ge.convert(c,"bn","raw"),qi:Ge.convert(u,"bn","raw")}}fromPrivatePKCS8(e){let t=Ye.normalize("PrivateKeyInfo"),r=Ye.normalize("RSAPrivateKey"),n=t.decode(e,"der"),{n:o,e:i,d:s,p:a,q:c,dp:u,dq:l,qi:f}=r.decode(n.privateKey,"der");return{n:Ge.convert(o,"bn","raw"),e:Ge.convert(i,"bn","raw"),d:Ge.convert(s,"bn","raw"),p:Ge.convert(a,"bn","raw"),q:Ge.convert(c,"bn","raw"),dp:Ge.convert(u,"bn","raw"),dq:Ge.convert(l,"bn","raw"),qi:Ge.convert(f,"bn","raw")}}fromPublicPKCS1(e){let t=Ye.normalize("RSAPublicKey"),{n:r,e:n}=t.decode(e,"der");return{n:Ge.convert(r,"bn","raw"),e:Ge.convert(n,"bn","raw")}}fromPublicPKCS8(e){let t=Ye.normalize("PublicKeyInfo"),r=Ye.normalize("RSAPublicKey"),n=t.decode(e,"der"),{n:o,e:i}=r.decode(n.publicKey.data,"der");return{n:Ge.convert(o,"bn","raw"),e:Ge.convert(i,"bn","raw")}}fromJwk(e){let{n:t,e:r,d:n,p:o,q:i,dp:s,dq:a,qi:c,alg:u}=e;return{n:Ge.convert(t,"base64url","raw"),e:Ge.convert(r,"base64url","raw"),d:Ge.convert(n,"base64url","raw"),p:Ge.convert(o,"base64url","raw"),q:Ge.convert(i,"base64url","raw"),dp:Ge.convert(s,"base64url","raw"),dq:Ge.convert(a,"base64url","raw"),qi:Ge.convert(c,"base64url","raw")}}toPrivatePKCS1(t){let{n:r,e:n,d:o,p:i,q:s,dp:a,dq:c,qi:u}=t,{version:l}=this.params,f=Ye.normalize("RSAPrivateKey").encode({version:l,n:Ge.convert(r,"raw","bn"),e:Ge.convert(n,"raw","bn"),d:Ge.convert(o,"raw","bn"),p:Ge.convert(i,"raw","bn"),q:Ge.convert(s,"raw","bn"),dp:Ge.convert(a,"raw","bn"),dq:Ge.convert(c,"raw","bn"),qi:Ge.convert(u,"raw","bn")},"der").toString("base64");return e.formatPem(f,"RSA PRIVATE")}toPrivatePKCS8(t){let{n:r,e:n,d:o,p:s,q:a,dp:c,dq:u,qi:l}=t,{oid:f,algParameters:p,version:d}=this.params,h=Ye.normalize("PrivateKeyInfo"),y=Ye.normalize("RSAPrivateKey").encode({version:d,n:Ge.convert(r,"raw","bn"),e:Ge.convert(n,"raw","bn"),d:Ge.convert(o,"raw","bn"),p:Ge.convert(s,"raw","bn"),q:Ge.convert(a,"raw","bn"),dp:Ge.convert(c,"raw","bn"),dq:Ge.convert(u,"raw","bn"),qi:Ge.convert(l,"raw","bn")},"der"),m=h.encode({version:d,algorithm:{algorithm:f.split("."),parameters:i.from(p,"hex")},privateKey:y},"der").toString("base64");return e.formatPem(m,"PRIVATE")}toPublicPKCS1(t){let{n:r,e:n}=t,{version:o}=this.params,i=Ye.normalize("RSAPublicKey").encode({version:o,n:Ge.convert(r,"raw","bn"),e:Ge.convert(n,"raw","bn")},"der").toString("base64");return e.formatPem(i,"RSA PUBLIC")}toPublicPKCS8(t){let{n:r,e:n}=t,{oid:o,algParameters:s}=this.params,a=Ye.normalize("PublicKeyInfo"),c=Ye.normalize("RSAPublicKey").encode({n:Ge.convert(r,"raw","bn"),e:Ge.convert(n,"raw","bn")},"der"),u=a.encode({algorithm:{algorithm:o.split("."),parameters:i.from(s,"hex")},publicKey:{unused:0,data:c}},"der").toString("base64");return e.formatPem(u,"PUBLIC")}toPrivateJwk(e){let{n:t,e:r,d:n,p:o,q:i,dp:s,dq:a,qi:c}=e,{kty:u}=this.params;return{kty:u,n:Ge.convert(t,"raw","base64url"),e:Ge.convert(r,"raw","base64url"),d:Ge.convert(n,"raw","base64url"),p:Ge.convert(o,"raw","base64url"),q:Ge.convert(i,"raw","base64url"),dp:Ge.convert(s,"raw","base64url"),dq:Ge.convert(a,"raw","base64url"),qi:Ge.convert(c,"raw","base64url")}}toPublicJwk(e){let{n:t,e:r}=e,{kty:n}=this.params;return{kty:n,n:Ge.convert(t,"raw","base64url"),e:Ge.convert(r,"raw","base64url")}}};const We=new(0,h.ec)("secp256k1"),Xe=E,Ze=Je,Qe=$e;var et=class e extends Xe{fromPrivatePKCS1(t){let r=Qe.normalize("ECPrivateKey").decode(t,"der"),{privateKey:n,publicKey:{data:o}}=r,i=Ze.convert(o,"raw","hex"),{x:s,y:a}=e.getPoint(i);return{d:n,x:s,y:a}}fromPrivatePKCS8(t){let r=Qe.normalize("PrivateKeyInfo"),n=Qe.normalize("ECPrivateKey"),o=r.decode(t,"der"),i=n.decode(o.privateKey,"der"),{privateKey:s,publicKey:{data:a}}=i,c=Ze.convert(a,"raw","hex"),{x:u,y:l}=e.getPoint(c);return{d:s,x:u,y:l}}fromPublicPKCS8(t){let r=Qe.normalize("PublicKeyInfo").decode(t,"der"),n=Ze.convert(r.publicKey.data,"raw","hex");return e.getPoint(n)}fromPrivateBlk(e){let t=We.keyFromPrivate(e,"hex"),r=t.getPublic();return{d:Ze.convert(t.priv,"bn","raw"),x:Ze.convert(r.getX(),"bn","raw"),y:Ze.convert(r.getY(),"bn","raw")}}fromPublicBlk(t){return e.getPoint(t)}fromJwk(e){let{d:t,x:r,y:n}=e;return{d:Ze.convert(t,"base64url","raw"),x:Ze.convert(r,"base64url","raw"),y:Ze.convert(n,"base64url","raw")}}toPrivatePKCS1(t){let{namedCurve:r,keyVersion:n}=this.params,{d:o,x:i,y:s}=t,a=Qe.normalize("ECPrivateKey"),c=e.makePoint(i,s),u=a.encode({version:n,privateKey:o,parameters:{type:"namedCurve",value:r.split(".")},publicKey:{unused:0,data:c}},"der").toString("base64");return e.formatPem(u,"EC PRIVATE")}toPrivatePKCS8(t){let{oid:r,algParameters:n,keyVersion:o,infoVersion:s}=this.params,{d:a,x:c,y:u}=t,l=Qe.normalize("PrivateKeyInfo"),f=Qe.normalize("ECPrivateKey"),p=e.makePoint(c,u),d=f.encode({version:o,privateKey:a,publicKey:{unused:0,data:p}},"der"),h=l.encode({version:s,algorithm:{algorithm:r.split("."),parameters:i.from(n,"hex")},privateKey:d},"der").toString("base64");return e.formatPem(h,"PRIVATE")}toPublicPKCS8(t){let{oid:r,algParameters:n}=this.params,{x:o,y:s}=t,a=Qe.normalize("PublicKeyInfo"),c=e.makePoint(o,s),u=a.encode({algorithm:{algorithm:r.split("."),parameters:i.from(n,"hex")},publicKey:{unused:0,data:c}},"der").toString("base64");return e.formatPem(u,"PUBLIC")}toPrivateBlk(e){return e.d.toString("hex")}toPublicBlk(t){return Ze.convert(e.makePoint(t.x,t.y),"raw","hex")}toPrivateJwk(e){let{crv:t,kty:r}=this.params,{d:n,x:o,y:i}=e;return{kty:r,crv:t,d:Ze.convert(n,"raw","base64url"),x:Ze.convert(o,"raw","base64url"),y:Ze.convert(i,"raw","base64url")}}toPublicJwk(e){let{crv:t,kty:r}=this.params,{x:n,y:o}=e;return{kty:r,crv:t,x:Ze.convert(n,"raw","base64url"),y:Ze.convert(o,"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:Ze.convert(t,"hex","raw"),y:Ze.convert(r,"hex","raw")}}static makePoint(e,t){let r=i.from("04","hex");return i.concat([r,e,t],r.length+e.length+t.length)}};const tt=E,rt=Je,nt=$e;var ot=class e extends tt{fromPrivatePKCS8(e){const t=nt.normalize("PrivateKeyInfo").decode(e,"der").privateKey.slice(2);return{d:t,x:this.publicKeyFromPrivate(t)}}fromPublicPKCS8(e){const t=nt.normalize("PublicKeyInfo").decode(e,"der");return{x:rt.convert(t.publicKey.data,"hex","raw")}}fromJwk(e){let{d:t,x:r}=e;return{d:rt.convert(t,"base64url","raw"),x:rt.convert(r,"base64url","raw")}}toPrivatePKCS8(t){let{oid:r,infoVersion:n}=this.params,{d:o}=t;const i=nt.normalize("PrivateKeyInfo"),s=this.privateKeyPadding(o);let a=i.encode({version:n,algorithm:{algorithm:r.split(".")},privateKey:s},"der").toString("base64");return e.formatPem(a,"PRIVATE")}toPublicPKCS8(t){let{oid:r}=this.params,{x:n}=t,o=nt.normalize("PublicKeyInfo").encode({algorithm:{algorithm:r.split(".")},publicKey:{unused:0,data:rt.convert(n,"hex","raw")}},"der").toString("base64");return e.formatPem(o,"PUBLIC")}toPrivateJwk(e){let{crv:t,kty:r}=this.params,{d:n,x:o}=e;return{kty:r,crv:t,d:rt.convert(n,"raw","base64url"),x:rt.convert(o,"raw","base64url")}}toPublicJwk(e){let{crv:t,kty:r}=this.params,{x:n}=e;return{kty:r,crv:t,x:rt.convert(n,"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=i.from("0420","hex"),i.concat([t,e],t.length+e.length)}publicKeyFromPrivate(e){if("Ed25519"===this.params.crv){const t=new(0,h.eddsa)("ed25519");return i.from(t.keyFromSecret(e).getPublic())}throw new Error(`${this.params.crv} is an invalid curve for EdDSA`)}};const it=He,st=et,at=ot,ct=new k;ct.define([{kty:"RSA",oid:"1.2.840.113549.1.1.1",algParameters:"0500",version:"two-prime"}],it),ct.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"}],st),ct.define([{kty:"OKP",crv:"Ed25519",oid:"1.3.101.112",infoVersion:"two-prime"}],at);const ut=w,lt=_,ft=ct,pt=$e,dt=RegExp("\r?\n","g");class ht{constructor(e,t){if(!e)throw new ut("key is required");if(!t)throw new ut("options are required");let{kty:r,format:n,selector:o,crv:i,oid:s}=t;if(!t.kty)throw new ut("options.kty is required");if(!t.format)throw new ut("options.format is required");if(!t.selector)throw new ut("options.selector is required");if(!t.crv&&!t.oid)throw new ut("options.crv or options.oid is required");this.kty=r,this.format=n,this.selector=o,this.crv=i,this.oid=s,this.key=this.parseKey(e)}static from(e,t){if(!e)throw new ut("key is required");if(!t)throw new ut("format is required");if("jwk"===t){let r;if("string"==typeof e)try{r=JSON.parse(e)}catch(e){throw new ut("key is not a valid JWK")}else"object"==typeof e&&(r=e);let n,{kty:o,crv:i}=r;if(!o)throw new ut("kty is required for JWK");if("EC"===o&&!i)throw new ut("crv is required for EC JWK");"RSA"===o&&(n=ft.find((e=>e.kty===o)).oid);let s=r.d?"private":"public";return new ht(r,{kty:o,crv:i,oid:n,format:t,selector:s})}if("pem"===t){if("string"!=typeof e)throw new ut("key is not a valid PEM string");let r=e.split(dt),n=r.splice(0,1);r.splice(r.length-1,1);let o,s,a=r.join(""),c=/^-----BEGIN ((RSA|EC) )?(PUBLIC|PRIVATE) KEY-----$/.exec(n),u=c?c[2]:void 0,l=c?c[3]:void 0,f=i.from(a,"base64");if(!l)throw new ut("key is not a valid PEM string");if(u){if("RSA"===u)l="PRIVATE"===l?"private_pkcs1":"public_pkcs1",o=ft.find((e=>e.kty===u)).oid;else if("EC"===u){let e;if("PRIVATE"===l){l="private_pkcs1",e=pt.normalize(`${u}PrivateKey`).decode(f,"der")}else if("PUBLIC"===l){l="public_pkcs1",e=pt.normalize(`${u}PrivateKey`).decode(f,"der")}let{parameters:{value:t}}=e;s=ft.find((e=>e.namedCurve===t.join("."))).crv}}else{let e,t=pt.normalize("PrivateKeyInfo"),r=pt.normalize("PublicKeyInfo");"PRIVATE"===l?(l="private_pkcs8",e=t.decode(f,"der")):"PUBLIC"===l&&(l="public_pkcs8",e=r.decode(f,"der"));let{algorithm:{algorithm:n,parameters:i}}=e;n=n.join("."),i=i?i.toString("hex"):void 0;const a=ft.find((e=>e.oid===n));if(u=a?a.kty:void 0,!u)throw new ut(`${n} is not supported`);"RSA"===u||"OKP"===u?o=n:"EC"===u&&(s=ft.find((e=>e.algParameters===i)).crv)}return new ht(f,{kty:u,oid:o,crv:s,format:t,selector:l})}if("blk"===t)return new ht(e,{kty:"EC",crv:"K-256",format:t,selector:e.length>64?"public":"private"});throw new ut(`Invalid format ${t}`)}get alg(){let{kty:e,crv:t,oid:r}=this;if(!this.algorithm){if(t)Object.defineProperty(this,"algorithm",{value:ft.normalize(e,"crv",t)});else{if(!r)throw new Error("Both crv and oid are undefined");Object.defineProperty(this,"algorithm",{value:ft.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(e){let{key:t,alg:r,selector:n}=this;switch(e){case"public":return r.toPublicJwk(t);case"private":if(n.includes("public"))throw new ut("Cannot export a private key from a public key");return r.toPrivateJwk(t);default:throw new Error("Invalid key selector")}}toString(e="pem",t="public_pkcs8"){let{key:r,alg:n,selector:o}=this;if("pem"===e)switch(t){case"public_pkcs1":return n.toPublicPKCS1(r);case"public_pkcs8":return n.toPublicPKCS8(r);case"private_pkcs1":if(o.includes("public"))throw new ut("Cannot export a private key from a public key");return n.toPrivatePKCS1(r);case"private_pkcs8":if(o.includes("public"))throw new ut("Cannot export a private key from a public key");return n.toPrivatePKCS8(r);default:throw new Error("Invalid key selector")}else if("jwk"===e)switch(t){case"public":return JSON.stringify(n.toPublicJwk(r));case"private":if(o.includes("public"))throw new ut("Cannot export a private key from a public key");return JSON.stringify(n.toPrivateJwk(r));default:throw new Error("Invalid key selector")}else if("blk"===e)switch(t){case"private":if(o.includes("public"))throw new ut("Cannot export a private key from a public key");return n.toPrivateBlk(r);case"public":return n.toPublicBlk(r);default:throw new Error("Invalid key selector")}throw new lt}}var yt=a(ht);var mt=function(e){if(e.length>=255)throw new TypeError("Alphabet too long");for(var t=new Uint8Array(256),r=0;r<t.length;r++)t[r]=255;for(var n=0;n<e.length;n++){var o=e.charAt(n),i=o.charCodeAt(0);if(255!==t[i])throw new TypeError(o+" is ambiguous");t[i]=n}var s=e.length,a=e.charAt(0),c=Math.log(s)/Math.log(256),u=Math.log(256)/Math.log(s);function l(e){if("string"!=typeof e)throw new TypeError("Expected String");if(0===e.length)return new Uint8Array;for(var r=0,n=0,o=0;e[r]===a;)n++,r++;for(var i=(e.length-r)*c+1>>>0,u=new Uint8Array(i);e[r];){var l=t[e.charCodeAt(r)];if(255===l)return;for(var f=0,p=i-1;(0!==l||f<o)&&-1!==p;p--,f++)l+=s*u[p]>>>0,u[p]=l%256>>>0,l=l/256>>>0;if(0!==l)throw new Error("Non-zero carry");o=f,r++}for(var d=i-o;d!==i&&0===u[d];)d++;for(var h=new Uint8Array(n+(i-d)),y=n;d!==i;)h[y++]=u[d++];return h}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"";for(var r=0,n=0,o=0,i=t.length;o!==i&&0===t[o];)o++,r++;for(var c=(i-o)*u+1>>>0,l=new Uint8Array(c);o!==i;){for(var f=t[o],p=0,d=c-1;(0!==f||p<n)&&-1!==d;d--,p++)f+=256*l[d]>>>0,l[d]=f%s>>>0,f=f/s>>>0;if(0!==f)throw new Error("Non-zero carry");n=p,o++}for(var h=c-n;h!==c&&0===l[h];)h++;for(var y=a.repeat(r);h<c;++h)y+=e.charAt(l[h]);return y},decodeUnsafe:l,decode:function(e){var t=l(e);if(t)return t;throw new Error("Non-base"+s+" character")}}};var bt=mt("123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"),vt=a(bt);export{b as a,m as b,bt as c,Ne as d,vt as e,yt as k,y as r,g as s};
|