@blockcerts/blockcerts-verifier 1.60.0 → 1.61.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-aV3C41Ue-_mP0Wq_n.js +4 -0
- package/dist/{Ed25519Signature2020-PVto7akI-7D-o4uG8.js → Ed25519Signature2020-CL2yKnJW-NRYSGvkI.js} +6 -6
- package/dist/{HashlinkVerifier-qOLUtyR6-bzhltPG4.js → HashlinkVerifier-MEwSZe4T-BdYYAALa.js} +1 -1
- package/dist/{MerkleProof2017-v-cug_ka-8h-1uHue.js → MerkleProof2017-CNSx436a-FBaGRIN1.js} +1 -1
- package/dist/{MerkleProof2017-MZJbBTpc-0GcGcIV-.js → MerkleProof2017-MZJbBTpc-B7HRJzRg.js} +1 -1
- package/dist/MerkleProof2019-DnbP3r0f-Cp4GWjQh.js +3 -0
- package/dist/checkCredentialSchemaConformity-QPmIWPLG-De1kKyvF.js +1 -0
- package/dist/{checkRevocationStatusList2021-NUr7Ungd-8lPXcMzr.js → checkRevocationStatusList2021-Cy-rWyh7-CVOeAbdp.js} +1 -1
- package/dist/{controlVerificationMethod-Ai0yOkQs-GCeqYaBn.js → controlVerificationMethod-CXzAI0QS-b45qIaR4.js} +1 -1
- package/dist/{did-key-common.esm-2wmtjYcU-BR_8p3eV.js → did-key-common.esm-CJj7pea6-Er8YwHoJ.js} +1 -1
- package/dist/{did-key-ed25519.esm-NX9dX9Vr-fZElVDYL.js → did-key-ed25519.esm-hEATvNhJ-CHAq7sf1.js} +1 -1
- package/dist/{did-key-secp256k1.esm-FBi5sg1U-hK5l_sjP.js → did-key-secp256k1.esm-CIEM56eq-EQahxyFZ.js} +1 -1
- package/dist/{downloadPDF-nmBhJVDh.js → downloadPDF-B1DL4u2a.js} +2 -2
- package/dist/{ensureNotRevoked-gui-UMnE-kFmYZEJe.js → ensureNotRevoked-gui-UMnE-CENgoep9.js} +1 -1
- package/dist/{index-UlvMASNZ.js → index-CfIOMbD1.js} +1 -1
- package/dist/{index-o5NaLUcd-9ST97EHw.js → index-DWAZG7Ja-CBt_boC3.js} +2 -2
- package/dist/index-yP42zfkJ-CHN5LgUq.js +1 -0
- package/dist/{index.es-wVskPDvK.js → index.es-D8QzgW47.js} +1 -1
- package/dist/{jsonld-signatures-mX3uMDo8-kWFWdwsD.js → jsonld-signatures-zDEkNjYR-D3vK8GYH.js} +3 -3
- package/dist/main.js +119 -119
- package/dist/{purify-W53PnvWj.js → purify-C5H8D62I.js} +1 -1
- package/dist/{x25519-X8M7VOup-2RynHlmX.js → x25519-BzvT3haI-DcUk09rC.js} +1 -1
- package/package.json +3 -3
- package/dist/EcdsaSecp256k1Signature2019-JXyaAxSS-p7r9wTPV.js +0 -4
- package/dist/MerkleProof2019-IxLr0Lr4-exvrsGAt.js +0 -3
- /package/dist/{Suite-Bhitn5l3-e2QgHGhx.js → Suite-B7Vy9AuU-D1ucdMDB.js} +0 -0
- /package/dist/{_commonjs-dynamic-modules-F7P8sER7-fkA6S-_a.js → _commonjs-dynamic-modules-COweQ1RR-BHR_E30J.js} +0 -0
- /package/dist/{base64url-qi3FT6uz-yv4mTXpu.js → base64url-Cy03LJLt-vkTPfQOh.js} +0 -0
- /package/dist/{elliptic-xyZmv-oA-VPyWJbY1.js → elliptic-DVE5q-l5-D-NH8siB.js} +0 -0
- /package/dist/{ensureNotRevoked--X9grgJr-l9FjOXvf.js → ensureNotRevoked-bD_ITwQb-DvMIgM4L.js} +0 -0
- /package/dist/{ensureValidIssuingKey-U4G_F_Hm-UoJe_Wnf.js → ensureValidIssuingKey-wRebznsK-frafTbMl.js} +0 -0
- /package/dist/{index-aBVDu34R-o1HUYRUQ.js → index-CcA_A5fd-Dgus2xdV.js} +0 -0
- /package/dist/{index-CZOUZnn4-Lnb5-WZi.js → index-DUjMpuQT-ZifknGWx.js} +0 -0
- /package/dist/{jsonld-SAOezr4P-ioHKtwiZ.js → jsonld-Pr6hPH-i-D_C9ciG_.js} +0 -0
- /package/dist/{pako.esm-jjCKMBM4-RAILONW0.js → pako.esm-DnD5dZGi-HambcU-w.js} +0 -0
- /package/dist/{sha256-lGrd_b3t-9eo2gOQb.js → sha256-wKiO0px2-BYFBxJ7m.js} +0 -0
- /package/dist/{tslib.es6-M1zqH4el-x9kNW1T_.js → tslib.es6-CNEFicEt-CmLYFWVC.js} +0 -0
|
@@ -1,3 +1,3 @@
|
|
|
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-
|
|
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-CcA_A5fd-Dgus2xdV.js";import{b as l,r as f,i as p,m as d,e as h}from"./elliptic-DVE5q-l5-D-NH8siB.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 b=n(o),w=n(c),m={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={},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 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 Z(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 W=Z;const X=["enc","parent","children","tag","args","reverseArgs","choice","optional","any","obj","use","alteredUse","key","default","explicit","implicit","contains"];Z.prototype.clone=function(){const e=this._baseState,t={};X.forEach((function(r){t[r]=e[r]}));const r=new this.constructor(t.parent);return r._baseState=t,r},Z.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)},Z.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")},Z.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){Z.prototype[e]=function(){const t=this._baseState;throw new Error(e+" not implemented for encoding: "+t.enc)}})),Y.forEach((function(e){Z.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}})),Z.prototype.use=function(e){G(e);const t=this._baseState;return G(null===t.use),t.use=e,this},Z.prototype.optional=function(){return this._baseState.optional=!0,this},Z.prototype.def=function(e){const t=this._baseState;return G(null===t.default),t.default=e,t.optional=!0,this},Z.prototype.explicit=function(e){const t=this._baseState;return G(null===t.explicit&&null===t.implicit),t.explicit=e,this},Z.prototype.implicit=function(e){const t=this._baseState;return G(null===t.explicit&&null===t.implicit),t.implicit=e,this},Z.prototype.obj=function(){const e=this._baseState,t=Array.prototype.slice.call(arguments);return e.obj=!0,0!==t.length&&this._useArgs(t),this},Z.prototype.key=function(e){const t=this._baseState;return G(null===t.key),t.key=e,this},Z.prototype.any=function(){return this._baseState.any=!0,this},Z.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},Z.prototype.contains=function(e){const t=this._baseState;return G(null===t.use),t.contains=e,this},Z.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},Z.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)},Z.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},Z.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")},Z.prototype._createEncoderBuffer=function(e){return new $(e,this.reporter)},Z.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},Z.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},Z.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)},Z.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)},Z.prototype._isNumstr=function(e){return/^[0-9 ]*$/.test(e)},Z.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=W,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,he=l,de=z.DecoderBuffer,ye=W,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=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=W}();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 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: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: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(u,"raw","bn"),qi:Ge.convert(l,"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"),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 Ze=new(0,d.ec)("secp256k1"),We=E,Xe=Je,Qe=$e;var et=class e extends We{fromPrivatePKCS1(t){let r=Qe.normalize("ECPrivateKey").decode(t,"der"),{privateKey:n,publicKey:{data:o}}=r,i=Xe.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=Xe.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=Xe.convert(r.publicKey.data,"raw","hex");return e.getPoint(n)}fromPrivateBlk(e){let t=Ze.keyFromPrivate(e,"hex"),r=t.getPublic();return{d:Xe.convert(t.priv,"bn","raw"),x:Xe.convert(r.getX(),"bn","raw"),y:Xe.convert(r.getY(),"bn","raw")}}fromPublicBlk(t){return e.getPoint(t)}fromJwk(e){let{d:t,x:r,y:n}=e;return{d:Xe.convert(t,"base64url","raw"),x:Xe.convert(r,"base64url","raw"),y:Xe.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),h=f.encode({version:o,privateKey:a,publicKey:{unused:0,data:p}},"der"),d=l.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),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 Xe.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:Xe.convert(n,"raw","base64url"),x:Xe.convert(o,"raw","base64url"),y:Xe.convert(i,"raw","base64url")}}toPublicJwk(e){let{crv:t,kty:r}=this.params,{x:n,y:o}=e;return{kty:r,crv:t,x:Xe.convert(n,"raw","base64url"),y:Xe.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:Xe.convert(t,"hex","raw"),y:Xe.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 ut=w,lt=_,ft=ct,pt=$e,ht=RegExp("\r?\n","g");class dt{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 dt(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(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),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 dt(f,{kty:u,oid:o,crv:s,format:t,selector:l})}if("blk"===t)return new dt(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(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),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 h=i-o;h!==i&&0===u[h];)h++;for(var d=new Uint8Array(n+(i-h)),y=n;h!==i;)d[y++]=u[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)*u+1>>>0,l=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*l[h]>>>0,l[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===l[d];)d++;for(var y=a.repeat(r);d<c;++d)y+=e.charAt(l[d]);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};
|
|
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)}}(m,m.exports);var g=m.exports;var v=class extends Error{constructor(e){super(e||"This operation is not supported for this key type")}};var k=class extends Error{constructor(){super("This has not been implemented yet")}};var _=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=k;var E,S=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={},A={},x={},C=f,B=C.Buffer,j={};for(E in C)C.hasOwnProperty(E)&&"SlowBuffer"!==E&&"Buffer"!==E&&(j[E]=C[E]);var U=j.Buffer={};for(E in B)B.hasOwnProperty(E)&&"allocUnsafe"!==E&&"allocUnsafeSlow"!==E&&(U[E]=B[E]);if(j.Buffer.prototype=B.prototype,U.from&&U.from!==Uint8Array.from||(U.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 B(e,t,r)}),U.alloc||(U.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=B(e);return t&&0!==t.length?"string"==typeof r?n.fill(t,r):n.fill(t):n.fill(0),n}),!j.kStringMaxLength)try{j.kStringMaxLength=e.binding("buffer").kStringMaxLength}catch(e){}j.constants||(j.constants={MAX_LENGTH:j.kMaxLength},j.kStringMaxLength&&(j.constants.MAX_STRING_LENGTH=j.kStringMaxLength));var I=j,T={};const q=p;function N(e){this._reporterState={obj:null,path:[],options:e||{},errors:[]}}function z(e,t){this.path=e,this.rethrow(t)}T.Reporter=N,N.prototype.isError=function(e){return e instanceof z},N.prototype.save=function(){const e=this._reporterState;return{obj:e.obj,pathLen:e.path.length}},N.prototype.restore=function(e){const t=this._reporterState;t.obj=e.obj,t.path=t.path.slice(0,e.pathLen)},N.prototype.enterKey=function(e){return this._reporterState.path.push(e)},N.prototype.exitKey=function(e){const t=this._reporterState;t.path=t.path.slice(0,e-1)},N.prototype.leaveKey=function(e,t,r){const n=this._reporterState;this.exitKey(e),null!==n.obj&&(n.obj[t]=r)},N.prototype.path=function(){return this._reporterState.path.join("/")},N.prototype.enterObject=function(){const e=this._reporterState,t=e.obj;return e.obj={},t},N.prototype.leaveObject=function(e){const t=this._reporterState,r=t.obj;return t.obj=e,r},N.prototype.error=function(e){let t;const r=this._reporterState,n=e instanceof z;if(t=n?e:new z(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},N.prototype.wrapResult=function(e){const t=this._reporterState;return t.options.partial?{result:this.isError(e)?null:e,errors:t.errors}:e},q(z,Error),z.prototype.rethrow=function(e){if(this.message=e+" at: "+(this.path||"(shallow)"),Error.captureStackTrace&&Error.captureStackTrace(this,z),!this.stack)try{throw new Error(this.message)}catch(e){this.stack=e.stack}return this};var O={};const R=p,D=T.Reporter,V=I.Buffer;function M(e,t){D.call(this,t),V.isBuffer(e)?(this.base=e,this.offset=0,this.length=e.length):this.error("Input not Buffer")}function L(e,t){if(Array.isArray(e))this.length=0,this.value=e.map((function(e){return L.isEncoderBuffer(e)||(e=new L(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}}R(M,D),O.DecoderBuffer=M,M.isDecoderBuffer=function(e){if(e instanceof M)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},M.prototype.save=function(){return{offset:this.offset,reporter:D.prototype.save.call(this)}},M.prototype.restore=function(e){const t=new M(this.base);return t.offset=e.offset,t.length=this.offset,this.offset=e.offset,D.prototype.restore.call(this,e.reporter),t},M.prototype.isEmpty=function(){return this.offset===this.length},M.prototype.readUInt8=function(e){return this.offset+1<=this.length?this.base.readUInt8(this.offset++,!0):this.error(e||"DecoderBuffer overrun")},M.prototype.skip=function(e,t){if(!(this.offset+e<=this.length))return this.error(t||"DecoderBuffer overrun");const r=new M(this.base);return r._reporterState=this._reporterState,r.offset=this.offset,r.length=this.offset+e,this.offset+=e,r},M.prototype.raw=function(e){return this.base.slice(e?e.offset:this.offset,this.length)},O.EncoderBuffer=L,L.isEncoderBuffer=function(e){if(e instanceof L)return!0;return"object"==typeof e&&"EncoderBuffer"===e.constructor.name&&"number"==typeof e.length&&"function"==typeof e.join},L.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 J=T.Reporter,$=O.EncoderBuffer,F=O.DecoderBuffer,Z=d,G=["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"],Y=["key","obj","use","optional","explicit","implicit","def","choice","any","contains"].concat(G);function H(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=H;const W=["enc","parent","children","tag","args","reverseArgs","choice","optional","any","obj","use","alteredUse","key","default","explicit","implicit","contains"];H.prototype.clone=function(){const e=this._baseState,t={};W.forEach((function(r){t[r]=e[r]}));const r=new this.constructor(t.parent);return r._baseState=t,r},H.prototype._wrap=function(){const e=this._baseState;Y.forEach((function(t){this[t]=function(){const r=new this.constructor(this);return e.children.push(r),r[t].apply(r,arguments)}}),this)},H.prototype._init=function(e){const t=this._baseState;Z(null===t.parent),e.call(this),t.children=t.children.filter((function(e){return e._baseState.parent===this}),this),Z.equal(t.children.length,1,"Root node can have only one child")},H.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&&(Z(null===t.children),t.children=r,r.forEach((function(e){e._baseState.parent=this}),this)),0!==e.length&&(Z(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){H.prototype[e]=function(){const t=this._baseState;throw new Error(e+" not implemented for encoding: "+t.enc)}})),G.forEach((function(e){H.prototype[e]=function(){const t=this._baseState,r=Array.prototype.slice.call(arguments);return Z(null===t.tag),t.tag=e,this._useArgs(r),this}})),H.prototype.use=function(e){Z(e);const t=this._baseState;return Z(null===t.use),t.use=e,this},H.prototype.optional=function(){return this._baseState.optional=!0,this},H.prototype.def=function(e){const t=this._baseState;return Z(null===t.default),t.default=e,t.optional=!0,this},H.prototype.explicit=function(e){const t=this._baseState;return Z(null===t.explicit&&null===t.implicit),t.explicit=e,this},H.prototype.implicit=function(e){const t=this._baseState;return Z(null===t.explicit&&null===t.implicit),t.implicit=e,this},H.prototype.obj=function(){const e=this._baseState,t=Array.prototype.slice.call(arguments);return e.obj=!0,0!==t.length&&this._useArgs(t),this},H.prototype.key=function(e){const t=this._baseState;return Z(null===t.key),t.key=e,this},H.prototype.any=function(){return this._baseState.any=!0,this},H.prototype.choice=function(e){const t=this._baseState;return Z(null===t.choice),t.choice=e,this._useArgs(Object.keys(e).map((function(t){return e[t]}))),this},H.prototype.contains=function(e){const t=this._baseState;return Z(null===t.use),t.contains=e,this},H.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},H.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)},H.prototype._getUse=function(e,t){const r=this._baseState;return r.useDecoder=this._use(e,t),Z(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},H.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")},H.prototype._createEncoderBuffer=function(e){return new $(e,this.reporter)},H.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},H.prototype._encodeValue=function(e,t,r){const n=this._baseState;if(null===n.parent)return n.children[0]._encode(e,t||new J);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},H.prototype._encodeChoice=function(e,t){const r=this._baseState,n=r.choice[e.type];return n||Z(!1,e.type+" not found in "+JSON.stringify(Object.keys(r.choice))),n._encode(e.value,t)},H.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)},H.prototype._isNumstr=function(e){return/^[0-9 ]*$/.test(e)},H.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=I.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}(x);var fe={};const pe=p,de=l,he=O.DecoderBuffer,ye=X,be=Q;function we(e){this.enc="der",this.name=e.name,this.entity=e,this.tree=new ge,this.tree._init(e.body)}var me=we;function ge(e){ye.call(this,"der",e)}function ve(e,t){let r=e.readUInt8(t);if(e.isError(r))return r;const n=be.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:be.tag[r]}}function ke(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}we.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=ve(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=ve(e,'Failed to decode tag of "'+t+'"');if(e.isError(n))return n;let o=ke(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=ve(e,t);if(e.isError(r))return r;const n=ke(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 _e=p,Pe=I.Buffer,Ee=me;function Se(e){Ee.call(this,e),this.enc="pem"}_e(Se,Ee);var Ke=Se;Se.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 Ee.prototype.decode.call(this,c,t)},function(e){const t=e;t.der=me,t.pem=Ke}(fe),function(e){const t=x,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)}}(A);var Ae={};!function(e){const t=Ae;t.Reporter=T.Reporter,t.DecoderBuffer=O.DecoderBuffer,t.EncoderBuffer=O.EncoderBuffer,t.Node=X}();var xe={};!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}(xe),function(e){const t=K;t.bignum=l,t.define=A.define,t.base=Ae,t.constants=xe,t.decoders=fe,t.encoders=x}();var Ce={exports:{}},Be={},je={};Object.defineProperty(je,"__esModule",{value:!0}),je.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(Be,"__esModule",{value:!0});var Ue=je;function Ie(e,t){return void 0===t&&(t="utf8"),s(e)?qe(e.toString("base64")):qe(i.from(e,t).toString("base64"))}function Te(e){return e=e.toString(),Ue.default(e).replace(/\-/g,"+").replace(/_/g,"/")}function qe(e){return e.replace(/=/g,"").replace(/\+/g,"-").replace(/\//g,"_")}var Ne,ze=Ie;ze.encode=Ie,ze.decode=function(e,t){return void 0===t&&(t="utf8"),i.from(Te(e),"base64").toString(t)},ze.toBase64=Te,ze.fromBase64=qe,ze.toBuffer=function(e){return i.from(Te(e),"base64")},Be.default=ze,(Ne=Ce).exports=Be.default,Ne.exports.default=Ne.exports;var Oe=Ce.exports,Re=a(Oe);const De=K,Ve=Oe;var Me=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 De.bignum(n);throw new Error("Invalid toType")}static pad(e){return e.length%2==1?`0${e}`:e}};const Le=K;const Je=new class{constructor(){Object.defineProperty(this,"_registry",{value:{}})}get registry(){return this._registry}define(e,t){this._registry[e]=Le.define(e,t(this))}normalize(e){return this.registry[e]}};Je.define("Version",(e=>function(){this.int({0:"two-prime",1:"multi"})})),Je.define("OtherPrimeInfos",(e=>function(){this.seq().obj(this.key("ri").int(),this.key("di").int(),this.key("ti").int())})),Je.define("AlgorithmIdentifier",(e=>function(){this.seq().obj(this.key("algorithm").objid(),this.key("parameters").optional().any())})),Je.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())}})),Je.define("PublicKeyInfo",(e=>{let t=e.normalize("AlgorithmIdentifier");return function(){this.seq().obj(this.key("algorithm").use(t),this.key("publicKey").bitstr())}})),Je.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))}})),Je.define("RSAPublicKey",(e=>function(){this.seq().obj(this.key("n").int(),this.key("e").int())})),Je.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=Je;const Fe=S,Ze=Me,Ge=$e;var Ye=class e extends Fe{fromPrivatePKCS1(e){let t=Ge.normalize("RSAPrivateKey"),{n:r,e:n,d:o,p:i,q:s,dp:a,dq:c,qi:u}=t.decode(e,"der");return{n:Ze.convert(r,"bn","raw"),e:Ze.convert(n,"bn","raw"),d:Ze.convert(o,"bn","raw"),p:Ze.convert(i,"bn","raw"),q:Ze.convert(s,"bn","raw"),dp:Ze.convert(a,"bn","raw"),dq:Ze.convert(c,"bn","raw"),qi:Ze.convert(u,"bn","raw")}}fromPrivatePKCS8(e){let t=Ge.normalize("PrivateKeyInfo"),r=Ge.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:Ze.convert(o,"bn","raw"),e:Ze.convert(i,"bn","raw"),d:Ze.convert(s,"bn","raw"),p:Ze.convert(a,"bn","raw"),q:Ze.convert(c,"bn","raw"),dp:Ze.convert(u,"bn","raw"),dq:Ze.convert(l,"bn","raw"),qi:Ze.convert(f,"bn","raw")}}fromPublicPKCS1(e){let t=Ge.normalize("RSAPublicKey"),{n:r,e:n}=t.decode(e,"der");return{n:Ze.convert(r,"bn","raw"),e:Ze.convert(n,"bn","raw")}}fromPublicPKCS8(e){let t=Ge.normalize("PublicKeyInfo"),r=Ge.normalize("RSAPublicKey"),n=t.decode(e,"der"),{n:o,e:i}=r.decode(n.publicKey.data,"der");return{n:Ze.convert(o,"bn","raw"),e:Ze.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:Ze.convert(t,"base64url","raw"),e:Ze.convert(r,"base64url","raw"),d:Ze.convert(n,"base64url","raw"),p:Ze.convert(o,"base64url","raw"),q:Ze.convert(i,"base64url","raw"),dp:Ze.convert(s,"base64url","raw"),dq:Ze.convert(a,"base64url","raw"),qi:Ze.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=Ge.normalize("RSAPrivateKey").encode({version:l,n:Ze.convert(r,"raw","bn"),e:Ze.convert(n,"raw","bn"),d:Ze.convert(o,"raw","bn"),p:Ze.convert(i,"raw","bn"),q:Ze.convert(s,"raw","bn"),dp:Ze.convert(a,"raw","bn"),dq:Ze.convert(c,"raw","bn"),qi:Ze.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=Ge.normalize("PrivateKeyInfo"),y=Ge.normalize("RSAPrivateKey").encode({version:d,n:Ze.convert(r,"raw","bn"),e:Ze.convert(n,"raw","bn"),d:Ze.convert(o,"raw","bn"),p:Ze.convert(s,"raw","bn"),q:Ze.convert(a,"raw","bn"),dp:Ze.convert(c,"raw","bn"),dq:Ze.convert(u,"raw","bn"),qi:Ze.convert(l,"raw","bn")},"der"),b=h.encode({version:d,algorithm:{algorithm:f.split("."),parameters:i.from(p,"hex")},privateKey:y},"der").toString("base64");return e.formatPem(b,"PRIVATE")}toPublicPKCS1(t){let{n:r,e:n}=t,{version:o}=this.params,i=Ge.normalize("RSAPublicKey").encode({version:o,n:Ze.convert(r,"raw","bn"),e:Ze.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=Ge.normalize("PublicKeyInfo"),c=Ge.normalize("RSAPublicKey").encode({n:Ze.convert(r,"raw","bn"),e:Ze.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:Ze.convert(t,"raw","base64url"),e:Ze.convert(r,"raw","base64url"),d:Ze.convert(n,"raw","base64url"),p:Ze.convert(o,"raw","base64url"),q:Ze.convert(i,"raw","base64url"),dp:Ze.convert(s,"raw","base64url"),dq:Ze.convert(a,"raw","base64url"),qi:Ze.convert(c,"raw","base64url")}}toPublicJwk(e){let{n:t,e:r}=e,{kty:n}=this.params;return{kty:n,n:Ze.convert(t,"raw","base64url"),e:Ze.convert(r,"raw","base64url")}}};const He=new(0,h.ec)("secp256k1"),Xe=S,We=Me,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=We.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=We.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=We.convert(r.publicKey.data,"raw","hex");return e.getPoint(n)}fromPrivateBlk(e){let t=He.keyFromPrivate(e,"hex"),r=t.getPublic();return{d:We.convert(t.priv,"bn","raw"),x:We.convert(r.getX(),"bn","raw"),y:We.convert(r.getY(),"bn","raw")}}fromPublicBlk(t){return e.getPoint(t)}fromJwk(e){let{d:t,x:r,y:n}=e;return{d:We.convert(t,"base64url","raw"),x:We.convert(r,"base64url","raw"),y:We.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 We.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:We.convert(n,"raw","base64url"),x:We.convert(o,"raw","base64url"),y:We.convert(i,"raw","base64url")}}toPublicJwk(e){let{crv:t,kty:r}=this.params,{x:n,y:o}=e;return{kty:r,crv:t,x:We.convert(n,"raw","base64url"),y:We.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:We.convert(t,"hex","raw"),y:We.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=S,rt=Me,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=Ye,st=et,at=ot,ct=new _;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=v,lt=k,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);const bt="Impossible case. Please create issue.",wt="The tweak was out of range or the resulted private key is invalid",mt="The tweak was out of range or equal to zero",gt="Unknow error on context randomization",vt="Private Key is invalid",kt="Public Key could not be parsed",_t="Public Key serialization error",Pt="The sum of the public keys is not valid",Et="Signature could not be parsed",St="The nonce generation function failed, or the private key was invalid",Kt="Public key could not be recover",At="Scalar was invalid (zero or overflow)";function xt(e,t){if(!e)throw new Error(t)}function Ct(e,t,r){if(xt(t instanceof Uint8Array,`Expected ${e} to be an Uint8Array`),void 0!==r)if(Array.isArray(r)){const n=`Expected ${e} to be an Uint8Array with length [${r.join(", ")}]`;xt(r.includes(t.length),n)}else{const n=`Expected ${e} to be an Uint8Array with length ${r}`;xt(t.length===r,n)}}function Bt(e){xt("Boolean"===Ut(e),"Expected compressed to be a Boolean")}function jt(e=(e=>new Uint8Array(e)),t){return"function"==typeof e&&(e=e(t)),Ct("output",e,t),e}function Ut(e){return Object.prototype.toString.call(e).slice(8,-1)}const It=new(0,h.ec)("secp256k1"),Tt=It.curve,qt=Tt.n.constructor;function Nt(e){const t=e[0];switch(t){case 2:case 3:return 33!==e.length?null:function(e,t){let r=new qt(t);if(r.cmp(Tt.p)>=0)return null;r=r.toRed(Tt.red);let n=r.redSqr().redIMul(r).redIAdd(Tt.b).redSqrt();return 3===e!==n.isOdd()&&(n=n.redNeg()),It.keyPair({pub:{x:r,y:n}})}(t,e.subarray(1,33));case 4:case 6:case 7:return 65!==e.length?null:function(e,t,r){let n=new qt(t),o=new qt(r);if(n.cmp(Tt.p)>=0||o.cmp(Tt.p)>=0)return null;if(n=n.toRed(Tt.red),o=o.toRed(Tt.red),(6===e||7===e)&&o.isOdd()!==(7===e))return null;const i=n.redSqr().redIMul(n);return o.redSqr().redISub(i.redIAdd(Tt.b)).isZero()?It.keyPair({pub:{x:n,y:o}}):null}(t,e.subarray(1,33),e.subarray(33,65));default:return null}}function zt(e,t){const r=t.encode(null,33===e.length);for(let t=0;t<e.length;++t)e[t]=r[t]}var Ot=(e=>({contextRandomize(t){if(xt(null===t||t instanceof Uint8Array,"Expected seed to be an Uint8Array or null"),null!==t&&Ct("seed",t,32),1===e.contextRandomize(t))throw new Error(gt)},privateKeyVerify:t=>(Ct("private key",t,32),0===e.privateKeyVerify(t)),privateKeyNegate(t){switch(Ct("private key",t,32),e.privateKeyNegate(t)){case 0:return t;case 1:throw new Error(bt)}},privateKeyTweakAdd(t,r){switch(Ct("private key",t,32),Ct("tweak",r,32),e.privateKeyTweakAdd(t,r)){case 0:return t;case 1:throw new Error(wt)}},privateKeyTweakMul(t,r){switch(Ct("private key",t,32),Ct("tweak",r,32),e.privateKeyTweakMul(t,r)){case 0:return t;case 1:throw new Error(mt)}},publicKeyVerify:t=>(Ct("public key",t,[33,65]),0===e.publicKeyVerify(t)),publicKeyCreate(t,r=!0,n){switch(Ct("private key",t,32),Bt(r),n=jt(n,r?33:65),e.publicKeyCreate(n,t)){case 0:return n;case 1:throw new Error(vt);case 2:throw new Error(_t)}},publicKeyConvert(t,r=!0,n){switch(Ct("public key",t,[33,65]),Bt(r),n=jt(n,r?33:65),e.publicKeyConvert(n,t)){case 0:return n;case 1:throw new Error(kt);case 2:throw new Error(_t)}},publicKeyNegate(t,r=!0,n){switch(Ct("public key",t,[33,65]),Bt(r),n=jt(n,r?33:65),e.publicKeyNegate(n,t)){case 0:return n;case 1:throw new Error(kt);case 2:throw new Error(bt);case 3:throw new Error(_t)}},publicKeyCombine(t,r=!0,n){xt(Array.isArray(t),"Expected public keys to be an Array"),xt(t.length>0,"Expected public keys array will have more than zero items");for(const e of t)Ct("public key",e,[33,65]);switch(Bt(r),n=jt(n,r?33:65),e.publicKeyCombine(n,t)){case 0:return n;case 1:throw new Error(kt);case 2:throw new Error(Pt);case 3:throw new Error(_t)}},publicKeyTweakAdd(t,r,n=!0,o){switch(Ct("public key",t,[33,65]),Ct("tweak",r,32),Bt(n),o=jt(o,n?33:65),e.publicKeyTweakAdd(o,t,r)){case 0:return o;case 1:throw new Error(kt);case 2:throw new Error(wt)}},publicKeyTweakMul(t,r,n=!0,o){switch(Ct("public key",t,[33,65]),Ct("tweak",r,32),Bt(n),o=jt(o,n?33:65),e.publicKeyTweakMul(o,t,r)){case 0:return o;case 1:throw new Error(kt);case 2:throw new Error(mt)}},signatureNormalize(t){switch(Ct("signature",t,64),e.signatureNormalize(t)){case 0:return t;case 1:throw new Error(Et)}},signatureExport(t,r){Ct("signature",t,64);const n={output:r=jt(r,72),outputlen:72};switch(e.signatureExport(n,t)){case 0:return r.slice(0,n.outputlen);case 1:throw new Error(Et);case 2:throw new Error(bt)}},signatureImport(t,r){switch(Ct("signature",t),r=jt(r,64),e.signatureImport(r,t)){case 0:return r;case 1:throw new Error(Et);case 2:throw new Error(bt)}},ecdsaSign(t,r,n={},o){Ct("message",t,32),Ct("private key",r,32),xt("Object"===Ut(n),"Expected options to be an Object"),void 0!==n.data&&Ct("options.data",n.data),void 0!==n.noncefn&&xt("Function"===Ut(n.noncefn),"Expected options.noncefn to be a Function");const i={signature:o=jt(o,64),recid:null};switch(e.ecdsaSign(i,t,r,n.data,n.noncefn)){case 0:return i;case 1:throw new Error(St);case 2:throw new Error(bt)}},ecdsaVerify(t,r,n){switch(Ct("signature",t,64),Ct("message",r,32),Ct("public key",n,[33,65]),e.ecdsaVerify(t,r,n)){case 0:return!0;case 3:return!1;case 1:throw new Error(Et);case 2:throw new Error(kt)}},ecdsaRecover(t,r,n,o=!0,i){switch(Ct("signature",t,64),xt("Number"===Ut(r)&&r>=0&&r<=3,"Expected recovery id to be a Number within interval [0, 3]"),Ct("message",n,32),Bt(o),i=jt(i,o?33:65),e.ecdsaRecover(i,t,r,n)){case 0:return i;case 1:throw new Error(Et);case 2:throw new Error(Kt);case 3:throw new Error(bt)}},ecdh(t,r,n={},o){switch(Ct("public key",t,[33,65]),Ct("private key",r,32),xt("Object"===Ut(n),"Expected options to be an Object"),void 0!==n.data&&Ct("options.data",n.data),void 0!==n.hashfn?(xt("Function"===Ut(n.hashfn),"Expected options.hashfn to be a Function"),void 0!==n.xbuf&&Ct("options.xbuf",n.xbuf,32),void 0!==n.ybuf&&Ct("options.ybuf",n.ybuf,32),Ct("output",o)):o=jt(o,32),e.ecdh(o,t,r,n.data,n.hashfn,n.xbuf,n.ybuf)){case 0:return o;case 1:throw new Error(kt);case 2:throw new Error(At)}}}))({contextRandomize:()=>0,privateKeyVerify(e){const t=new qt(e);return t.cmp(Tt.n)<0&&!t.isZero()?0:1},privateKeyNegate(e){const t=new qt(e),r=Tt.n.sub(t).umod(Tt.n).toArrayLike(Uint8Array,"be",32);return e.set(r),0},privateKeyTweakAdd(e,t){const r=new qt(t);if(r.cmp(Tt.n)>=0)return 1;if(r.iadd(new qt(e)),r.cmp(Tt.n)>=0&&r.isub(Tt.n),r.isZero())return 1;const n=r.toArrayLike(Uint8Array,"be",32);return e.set(n),0},privateKeyTweakMul(e,t){let r=new qt(t);if(r.cmp(Tt.n)>=0||r.isZero())return 1;r.imul(new qt(e)),r.cmp(Tt.n)>=0&&(r=r.umod(Tt.n));const n=r.toArrayLike(Uint8Array,"be",32);return e.set(n),0},publicKeyVerify:e=>null===Nt(e)?1:0,publicKeyCreate(e,t){const r=new qt(t);if(r.cmp(Tt.n)>=0||r.isZero())return 1;return zt(e,It.keyFromPrivate(t).getPublic()),0},publicKeyConvert(e,t){const r=Nt(t);if(null===r)return 1;return zt(e,r.getPublic()),0},publicKeyNegate(e,t){const r=Nt(t);if(null===r)return 1;const n=r.getPublic();return n.y=n.y.redNeg(),zt(e,n),0},publicKeyCombine(e,t){const r=new Array(t.length);for(let e=0;e<t.length;++e)if(r[e]=Nt(t[e]),null===r[e])return 1;let n=r[0].getPublic();for(let e=1;e<r.length;++e)n=n.add(r[e].pub);return n.isInfinity()?2:(zt(e,n),0)},publicKeyTweakAdd(e,t,r){const n=Nt(t);if(null===n)return 1;if((r=new qt(r)).cmp(Tt.n)>=0)return 2;const o=n.getPublic().add(Tt.g.mul(r));return o.isInfinity()?2:(zt(e,o),0)},publicKeyTweakMul(e,t,r){const n=Nt(t);if(null===n)return 1;if((r=new qt(r)).cmp(Tt.n)>=0||r.isZero())return 2;return zt(e,n.getPublic().mul(r)),0},signatureNormalize(e){const t=new qt(e.subarray(0,32)),r=new qt(e.subarray(32,64));return t.cmp(Tt.n)>=0||r.cmp(Tt.n)>=0?1:(1===r.cmp(It.nh)&&e.set(Tt.n.sub(r).toArrayLike(Uint8Array,"be",32),32),0)},signatureExport(e,t){const r=t.subarray(0,32),n=t.subarray(32,64);if(new qt(r).cmp(Tt.n)>=0)return 1;if(new qt(n).cmp(Tt.n)>=0)return 1;const{output:o}=e;let i=o.subarray(4,37);i[0]=0,i.set(r,1);let s=33,a=0;for(;s>1&&0===i[a]&&!(128&i[a+1]);--s,++a);if(i=i.subarray(a),128&i[0])return 1;if(s>1&&0===i[0]&&!(128&i[1]))return 1;let c=o.subarray(39,72);c[0]=0,c.set(n,1);let u=33,l=0;for(;u>1&&0===c[l]&&!(128&c[l+1]);--u,++l);return c=c.subarray(l),128&c[0]||u>1&&0===c[0]&&!(128&c[1])?1:(e.outputlen=6+s+u,o[0]=48,o[1]=e.outputlen-2,o[2]=2,o[3]=i.length,o.set(i,4),o[4+s]=2,o[5+s]=c.length,o.set(c,6+s),0)},signatureImport(e,t){if(t.length<8)return 1;if(t.length>72)return 1;if(48!==t[0])return 1;if(t[1]!==t.length-2)return 1;if(2!==t[2])return 1;const r=t[3];if(0===r)return 1;if(5+r>=t.length)return 1;if(2!==t[4+r])return 1;const n=t[5+r];if(0===n)return 1;if(6+r+n!==t.length)return 1;if(128&t[4])return 1;if(r>1&&0===t[4]&&!(128&t[5]))return 1;if(128&t[r+6])return 1;if(n>1&&0===t[r+6]&&!(128&t[r+7]))return 1;let o=t.subarray(4,4+r);if(33===o.length&&0===o[0]&&(o=o.subarray(1)),o.length>32)return 1;let i=t.subarray(6+r);if(33===i.length&&0===i[0]&&(i=i.slice(1)),i.length>32)throw new Error("S length is too long");let s=new qt(o);s.cmp(Tt.n)>=0&&(s=new qt(0));let a=new qt(t.subarray(6+r));return a.cmp(Tt.n)>=0&&(a=new qt(0)),e.set(s.toArrayLike(Uint8Array,"be",32),0),e.set(a.toArrayLike(Uint8Array,"be",32),32),0},ecdsaSign(e,t,r,n,o){if(o){const e=o;o=o=>{const i=e(t,r,null,n,o);if(!(i instanceof Uint8Array&&32===i.length))throw new Error("This is the way");return new qt(i)}}const i=new qt(r);if(i.cmp(Tt.n)>=0||i.isZero())return 1;let s;try{s=It.sign(t,r,{canonical:!0,k:o,pers:n})}catch(e){return 1}return e.signature.set(s.r.toArrayLike(Uint8Array,"be",32),0),e.signature.set(s.s.toArrayLike(Uint8Array,"be",32),32),e.recid=s.recoveryParam,0},ecdsaVerify(e,t,r){const n={r:e.subarray(0,32),s:e.subarray(32,64)},o=new qt(n.r),i=new qt(n.s);if(o.cmp(Tt.n)>=0||i.cmp(Tt.n)>=0)return 1;if(1===i.cmp(It.nh)||o.isZero()||i.isZero())return 3;const s=Nt(r);if(null===s)return 2;const a=s.getPublic();return It.verify(t,n,a)?0:3},ecdsaRecover(e,t,r,n){const o={r:t.slice(0,32),s:t.slice(32,64)},i=new qt(o.r),s=new qt(o.s);if(i.cmp(Tt.n)>=0||s.cmp(Tt.n)>=0)return 1;if(i.isZero()||s.isZero())return 2;let a;try{a=It.recoverPubKey(n,o,r)}catch(e){return 2}return zt(e,a),0},ecdh(e,t,r,n,o,i,s){const a=Nt(t);if(null===a)return 1;const c=new qt(r);if(c.cmp(Tt.n)>=0||c.isZero())return 2;const u=a.getPublic().mul(c);if(void 0===o){const t=u.encode(null,!0),r=It.hash().update(t).digest();for(let t=0;t<32;++t)e[t]=r[t]}else{i||(i=new Uint8Array(32));const t=u.getX().toArray("be",32);for(let e=0;e<32;++e)i[e]=t[e];s||(s=new Uint8Array(32));const r=u.getY().toArray("be",32);for(let e=0;e<32;++e)s[e]=r[e];const a=o(i,s,n);if(!(a instanceof Uint8Array&&a.length===e.length))return 2;e.set(a)}return 0}}),Rt=a(Ot);var Dt=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 Vt=Dt("123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"),Mt=a(Vt);export{w as a,b,Rt as c,Vt as d,Ot as e,Re as f,Mt as g,yt as k,y as r,g as s};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{B as e}from"./main.js";class t extends String{}const r=new Set(["<",">","<=",">="]),n=(e,...s)=>{const o=e.replace(/%[%drscjw]/g,(e=>{if("%%"===e)return"%";if(0===s.length)throw new Error("Unexpected arguments count");const o=s.shift();switch(e){case"%d":if("number"==typeof o)return o;throw new Error("Expected a number");case"%r":if(o instanceof RegExp)return n("new RegExp(%j, %j)",o.source,o.flags);throw new Error("Expected a RegExp instance");case"%s":if(o instanceof t)return o;throw new Error("Expected a safe string");case"%c":if(r.has(o))return o;throw new Error("Expected a compare op");case"%j":return(e=>{if([1/0,-1/0,NaN,void 0,null].includes(e))return`${e}`;if(!["string","boolean","number"].includes(typeof e)){if("object"!=typeof e)throw new Error("Unexpected value type");const t=Object.getPrototypeOf(e);if(!(t===Array.prototype&&Array.isArray(e)||t===Object.prototype))throw new Error("Unexpected object given as value")}return JSON.stringify(e).replace(/([{,])"__proto__":/g,'$1["__proto__"]:').replace(/[^\\]"__proto__":/g,(()=>{throw new Error("Unreachable")})).replace(/[\u2028\u2029]/g,(e=>`\\u${e.charCodeAt(0).toString(16).padStart(4,"0")}`))})(o);case"%w":if(Number.isInteger(o)&&o>=0)return" ".repeat(o);throw new Error("Expected a non-negative integer for indentation")}throw new Error("Unreachable")}));if(0!==s.length)throw new Error("Unexpected arguments count");return new t(o)},s=e=>{if(!/^[a-z][a-z0-9_]*$/i.test(e))throw new Error("Does not look like a safe id");return new t(e)},o=e=>(...r)=>{if(!r.every((e=>e instanceof t)))throw new Error("Unsafe arguments");return new t(e(...r))},i=o(((...e)=>e.some((e=>"true"==`${e}`))?"true":e.join(" || ")||"false")),a=o(((...e)=>e.some((e=>"false"==`${e}`))?"false":e.join(" && ")||"true")),c=e=>"true"==`${e}`?s("false"):"false"==`${e}`?s("true"):n("!%s",(e=>/^[a-z][a-z0-9_().]*$/i.test(e)||/^\([^()]+\)$/i.test(e)?e:n("(%s)",e))(e));var l={format:n,safe:s,safeand:a,safenot:c,safenotor:(...e)=>c(i(...e))};const{safe:u}=l,p=new WeakMap;var d={scopeMethods:e=>{p.has(e)||p.set(e,{sym:new Map,ref:new Map,format:new Map,pattern:new Map});const t=p.get(e),r=e=>{t.sym.get(e)||t.sym.set(e,0);const r=t.sym.get(e);return t.sym.set(e,r+1),u(`${e}${r}`)};t.loop||(t.loop="ijklmnopqrstuvxyz".split(""));return{gensym:r,genpattern:n=>{if(t.pattern.has(n))return t.pattern.get(n);const s=r("pattern");return e[s]=new RegExp(n,"u"),t.pattern.set(n,s),s},genloop:()=>{const e=t.loop.shift();return t.loop.push(`${e}${e[0]}`),u(e)},getref:e=>t.ref.get(e),genref:e=>{const n=r("ref");return t.ref.set(e,n),n},genformat:n=>{let s=t.format.get(n);return s||(s=r("format"),e[s]=n,t.format.set(n,s)),s}}}};const f=(e,t)=>{if(e===t)return!0;if(!e||!t||typeof e!=typeof t)return!1;if(e!==t&&"object"!=typeof e)return!1;const r=Object.getPrototypeOf(e);if(r!==Object.getPrototypeOf(t))return!1;if(r===Array.prototype)return!(!Array.isArray(e)||!Array.isArray(t))&&(e.length===t.length&&e.every(((e,r)=>f(e,t[r]))));if(r===Object.prototype){const[r,n]=[Object.keys(e),Object.keys(t)];if(r.length!==n.length)return!1;return new Set([...r,...n]).size===r.length&&r.every((r=>f(e[r],t[r])))}return!1},m=Function.prototype.call.bind(Object.prototype.hasOwnProperty);m[Symbol.for("toJayString")]="Function.prototype.call.bind(Object.prototype.hasOwnProperty)";const y=e=>/~\//.test(e)?`${e}`.replace(/~/g,"~0").replace(/\//g,"~1"):e;var h={stringLength:e=>/[\uD800-\uDFFF]/.test(e)?[...e].length:e.length,isMultipleOf:(e,t,r,n)=>{if(e%t==0)return!0;let s=e*r;if(s!==1/0&&s!==-1/0||(s=e),s%n==0)return!0;const o=Math.floor(s+.5);return o/r===e&&o%n==0},deepEqual:f,unique:e=>{if(e.length<2)return!0;if(2===e.length)return!f(e[0],e[1]);const t=[],r=e.length>20?new Set:null;let n=0,s=0;for(const o of e){if("object"==typeof o)t.push(o);else if(r){if(r.add(o),r.size!==++n)return!1}else if(-1!==e.indexOf(o,s+1))return!1;s++}for(let e=1;e<t.length;e++)for(let r=0;r<e;r++)if(f(t[e],t[r]))return!1;return!0},deBase64:t=>{if(void 0!==e)return e.from(t,"base64").toString("utf-8");const r=atob(t);return new TextDecoder("utf-8").decode(new Uint8Array(r.length).map(((e,t)=>r.charCodeAt(t))))},hasOwn:m,...{toPointer:e=>0===e.length?"#":`#/${e.map(y).join("/")}`,pointerPart:y,errorMerge:({keywordLocation:e,instanceLocation:t},r,n)=>({keywordLocation:`${r}${e.slice(1)}`,instanceLocation:`${n}${t.slice(1)}`}),propertyIn:(e,[t,r])=>t.includes(!0)||t.some((t=>t===e))||r.some((t=>new RegExp(t,"u").test(e))),dynamicResolve:(e,t)=>(e.filter((e=>e[t]))[0]||{})[t]}};const{format:g,safe:w}=l,{scopeMethods:b}=d,$=h,v=new Map(Object.entries({null:e=>g("%s === null",e),boolean:e=>g('typeof %s === "boolean"',e),array:e=>g("Array.isArray(%s)",e),object:e=>g('typeof %s === "object" && %s && !Array.isArray(%s)',e,e,e),number:e=>g('typeof %s === "number"',e),integer:e=>g("Number.isInteger(%s)",e),string:e=>g('typeof %s === "string"',e)})),j=({name:e,parent:t,keyval:r,keyname:n})=>{if(e){if(t||r||n)throw new Error("name can be used only stand-alone");return e}if(!t)throw new Error("Can not use property of undefined parent!");const s=j(t);if(void 0!==r){if(n)throw new Error("Can not use key value and name together");if(!["string","number"].includes(typeof r))throw new Error("Invalid property path");return/^[a-z][a-z0-9_]*$/i.test(r)?g("%s.%s",s,w(r)):g("%s[%j]",s,r)}if(n)return g("%s[%s]",s,n);throw new Error("Unreachable")},O=new Set([].concat(...[Object,Array,String,Number,Boolean].map((e=>Object.getOwnPropertyNames(e.prototype))))),x=/^\([^)]*\) *=>/,E=/^[^=]*=>/,k=Symbol.for("toJayString");var A={types:v,buildName:j,jsHelpers:(e,t,r,{unmodifiedPrototypes:n,isJSON:s},o)=>{const{gensym:i,genpattern:a,genloop:c}=b(t,r);return{present:e=>{const r=j(e),{parent:o,keyval:i,keyname:a,inKeys:c,checked:l}=e;if(l||c&&s)throw new Error("Unreachable: useless check for undefined");if(c)return g("%s !== undefined",r);if(o&&a){t.hasOwn=$.hasOwn;const e=j(o);return s?g("%s !== undefined && hasOwn(%s, %s)",r,e,a):g("%s in %s && hasOwn(%s, %s)",a,e,e,a)}if(o&&void 0!==i){if(n&&s&&!O.has(`${i}`))return g("%s !== undefined",r);t.hasOwn=$.hasOwn;const e=j(o);return s?g("%s !== undefined && hasOwn(%s, %j)",r,e,i):g("%j in %s && hasOwn(%s, %j)",i,e,e,i)}throw new Error("Unreachable: present() check without parent")},forObjectKeys:(t,n)=>{const s=i("key");e.block(g("for (const %s of Object.keys(%s))",s,j(t)),(()=>{n(r(t,s,!0),s)}))},forArray:(t,s,o)=>{const i=c(),a=j(t);e.block(g("for (let %s = %s; %s < %s.length; %s++)",i,s,i,a,i),(()=>{o(r(t,i,n,!0),i)}))},patternTest:(e,t)=>{const r=e.replace(/[.^$|*+?(){}[\]\\]/gu,"");if(e===`^${r}$`)return g("(%s === %j)",t,e.slice(1,-1));if(o.has(e))return g("true");if([r,`${r}+`,`${r}.*`,`.*${r}.*`].includes(e))return g("%s.includes(%j)",t,r);if([`^${r}`,`^${r}+`,`^${r}.*`].includes(e))return g("%s.startsWith(%j)",t,r);if([`${r}$`,`.*${r}$`].includes(e))return g("%s.endsWith(%j)",t,r);const n=[...r].slice(0,-1).join("");return[`${r}*`,`${r}?`].includes(e)?0===n.length?g("true"):g("%s.includes(%j)",t,n):[`^${r}*`,`^${r}?`].includes(e)?0===n.length?g("true"):g("%s.startsWith(%j)",t,n):g("%s.test(%s)",a(e),t)},compare:(e,r)=>{if(!r||"object"!=typeof r)return g("%s === %j",e,r);let n;const s=e=>e.length<=3&&e.every((e=>!e||"object"!=typeof e));if(Array.isArray(r)){if(n=v.get("array")(e),s(r)){let t=g("%s.length === %d",e,r.length);for(let n=0;n<r.length;n++)t=g("%s && %s[%d] === %j",t,e,n,r[n]);return g("%s && %s",n,t)}}else{n=v.get("object")(e);const[o,i]=[Object.keys(r),Object.values(r)];if(s(i)){let s=g("Object.keys(%s).length === %d",e,o.length);o.length>0&&(t.hasOwn=$.hasOwn);for(const t of o)s=g("%s && hasOwn(%s, %j)",s,e,t);for(const t of o)s=g("%s && %s[%j] === %j",s,e,t,r[t]);return g("%s && %s",n,s)}}return t.deepEqual=$.deepEqual,g("%s && deepEqual(%s, %j)",n,e,r)},propvar:r}},jaystring:function(e){if("function"==typeof e){if(e[k])return e[k];if(Object.getPrototypeOf(e)!==Function.prototype)throw new Error("Can not stringify: a function with unexpected prototype");const t=`${e}`;if(e.prototype){if(!/^function[ (]/.test(t))throw new Error("Unexpected function");return t}if(x.test(t)||E.test(t))return t;throw new Error("Can not stringify: only either normal or arrow functions are supported")}if("object"==typeof e){const t=Object.getPrototypeOf(e);if(e instanceof RegExp&&t===RegExp.prototype)return g("%r",e);throw new Error("Can not stringify: an object with unexpected prototype")}throw new Error("Can not stringify: unknown type "+typeof e)}};const{format:S,safe:z,safenot:M}=l,{jaystring:q}=A,N=/[{[]/,P=/[}\]]/;var I=()=>{const e=[];let t=0;const r=()=>{if(0!==t)throw new Error("Unexpected indent at build()");const r=e.map((e=>S("%w%s",2*e.indent,e.code))).join("\n");return/^[a-z][a-z0-9]*$/i.test(r)?`return ${r}`:`return (${r})`},n=e=>{const t=Object.entries(e);for(const[e,r]of t){if(!/^[a-z][a-z0-9]*$/i.test(e))throw new Error("Unexpected scope key!");if(!("function"==typeof r||r instanceof RegExp))throw new Error("Unexpected scope value!")}return t};return{optimizedOut:!1,size:()=>e.length,write(r,...n){if("string"!=typeof r)throw new Error("Format must be a string!");if(r.includes("\n"))throw new Error("Only single lines are supported");var s;return s=S(r,...n),P.test(s.trim()[0])&&t--,e.push({indent:t,code:s}),N.test(s[s.length-1])&&t++,!0},block(r,n,s=!1){const o=t;this.write("%s {",r);const i=e.length;if(n(),i===e.length)return e.pop(),t=o,!1;if(i===e.length-1&&!s){const{code:n}=e[e.length-1];if(!/^(if|for) /.test(n))return e.length-=2,t=o,this.write("%s %s",r,n)}return this.write("}")},if(e,t,r){"false"==`${e}`?(r&&r(),t&&(this.optimizedOut=!0)):"true"==`${e}`?(t&&t(),r&&(this.optimizedOut=!0)):t&&this.block(S("if (%s)",e),t,!!r)?r&&this.block(S("else"),r):r&&this.if(M(e),r)},makeModule:(e={})=>`(function() {\n'use strict'\n${n(e).map((([e,t])=>`const ${z(e)} = ${q(t)};`)).join("\n")}\n${r()}})()`,makeFunction(e={}){const t=n(e),s=t.map((e=>e[0])),o=t.map((e=>e[1]));return Function(...s,`'use strict'\n${r()}`)(...o)}}};const R=["core","applicator","unevaluated","validation","meta-data","format-annotation","format-assertion","content"];var U={knownKeywords:["$schema","$vocabulary","id","$id","$anchor","$ref","definitions","$defs","$recursiveRef","$recursiveAnchor","$dynamicAnchor","$dynamicRef","type","required","default","enum","const","not","allOf","anyOf","oneOf","if","then","else","maximum","minimum","exclusiveMaximum","exclusiveMinimum","multipleOf","divisibleBy","items","maxItems","minItems","additionalItems","prefixItems","contains","minContains","maxContains","uniqueItems","maxLength","minLength","format","pattern","contentEncoding","contentMediaType","contentSchema","properties","maxProperties","minProperties","additionalProperties","patternProperties","propertyNames","dependencies","dependentRequired","dependentSchemas","propertyDependencies","unevaluatedProperties","unevaluatedItems","title","description","deprecated","readOnly","writeOnly","examples","$comment","example","discriminator","removeAdditional"],schemaVersions:["draft/next","draft/2020-12","draft/2019-09","draft-07","draft-06","draft-04","draft-03"].map((e=>`https://json-schema.org/${e}/schema`)),knownVocabularies:[...["core","applicator","validation","meta-data","format","content"].map((e=>`https://json-schema.org/draft/2019-09/vocab/${e}`)),...R.map((e=>`https://json-schema.org/draft/2020-12/vocab/${e}`))]};const{knownKeywords:C}=U;function D(e,t,r,n="keys"){if(!e.has(t))return e.set(t,r);if(e.get(t)!==r)throw new Error(`Conflicting duplicate ${n}: ${t}`)}function _(e,t,r){if("object"!=typeof e)throw new Error("Invalid input object");if("string"!=typeof t)throw new Error("Invalid JSON pointer");const n=t.split("/");if(!["","#"].includes(n.shift()))throw new Error("Invalid JSON pointer");if(0===n.length)return e;let s=e;for(const e of n){if("string"!=typeof e)throw new Error("Invalid JSON pointer");r&&r.push(s);const t=(o=e).includes("~")?o.replace(/~[01]/g,(e=>{switch(e){case"~1":return"/";case"~0":return"~"}throw new Error("Unreachable")})):o;if("object"!=typeof s)return;if(!Object.prototype.hasOwnProperty.call(s,t))return;s=s[t]}var o;return s}const L=/^https?:\/\//;function J(e,t){if("string"!=typeof e||"string"!=typeof t)throw new Error("Unexpected path!");if(0===t.length)return e;const r=e.replace(/#.*/,"");return t.startsWith("#")?`${r}${t}`:!r.includes("/")||L.test(t)?t:L.test(r)?`${new URL(t,r)}`:t.startsWith("/")?t:[...r.split("/").slice(0,-1),t].join("/")}function F(e){return e.map((e=>e&&(e.$id||e.id)||"")).filter((e=>e&&"string"==typeof e)).reduce(J,"")}const T=["properties","patternProperties","$defs","definitions"],V=["const","enum","examples","example","comment"],W=Symbol("skip");function K(e,t){const r=(e,n=!1)=>{if(!e||"object"!=typeof e)return;const s=t(e);if(void 0!==s)return s===W?void 0:s;for(const t of Object.keys(e)){if(!n&&!Array.isArray(e)&&!C.includes(t))continue;if(!n&&V.includes(t))continue;const s=r(e[t],!n&&T.includes(t));if(void 0!==s)return s}};return r(e)}const B=(e,t,r=!1)=>{if(!Array.isArray(t))throw new Error("Expected an array of schemas");for(const n of t)K(n,(t=>{const s=t.$id||t.id,o=s&&"string"==typeof s?s.replace(/#$/,""):null;if(o&&o.includes("://")&&!o.includes("#"))D(e,o,t,"schema $id in 'schemas'");else if(t===n&&!r)throw new Error("Schema with missing or invalid $id in 'schemas'")}));return e},H=(e,t)=>{if(t)return B(H(e),t,!0);if(e)switch(Object.getPrototypeOf(e)){case Object.prototype:return new Map(Object.entries(e));case Map.prototype:return new Map(e);case Array.prototype:return B(new Map,e)}throw new Error("Unexpected value for 'schemas' option")};var Z={get:_,joinPath:J,resolveReference:function e(t,r,n,s=""){const o=J(s,n),i=[],[a,c=""]=o.split("#"),l=decodeURI(c),u=(e,r,n=!1,s=!1)=>{if(!e||"object"!=typeof e)return;const c=e.$id||e.id;let p=r;if(c&&"string"==typeof c)if(p=J(p,c),p===o||p===a&&""===l)i.push([e,t,r]);else if(p===a&&"/"===l[0]){const n=[],s=_(e,l,n);void 0!==s&&i.push([s,t,J(r,F(n))])}const d=s?e.$dynamicAnchor:e.$anchor;if(d&&"string"==typeof d){if(d.includes("#"))throw new Error("$anchor can't include '#'");if(d.startsWith("/"))throw new Error("$anchor can't start with '/'");p=J(p,`#${d}`),p===o&&i.push([e,t,r])}for(const t of Object.keys(e))(n||Array.isArray(e)||C.includes(t))&&(!n&&V.includes(t)||u(e[t],p,!n&&T.includes(t)));!s&&e.$dynamicAnchor&&u(e,r,n,!0)};if(u(t,a),a===s.replace(/#$/,"")&&("/"===l[0]||""===l)){const e=[],r=_(t,l,e);void 0!==r&&i.push([r,t,F(e)])}if(r.has(a)&&r.get(a)!==t){const t=e(r.get(a),r,`#${c}`,a);i.push(...t.map((([e,t,r])=>[e,t,J(a,r)])))}return r.has(o)&&i.push([r.get(o),r.get(o),o]),i},getDynamicAnchors:function(e){const t=new Map;return K(e,(r=>{if(r!==e&&(r.$id||r.id))return W;const n=r.$dynamicAnchor;if(n&&"string"==typeof n){if(n.includes("#"))throw new Error("$dynamicAnchor can't include '#'");if(!/^[a-zA-Z0-9_-]+$/.test(n))throw new Error(`Unsupported $dynamicAnchor: ${n}`);D(t,n,r,"$dynamicAnchor")}})),t},hasKeywords:(e,t)=>K(e,(e=>Object.keys(e).some((e=>t.includes(e)))||void 0))||!1,buildSchemas:H};const Y={email:e=>{if(e.length>318)return!1;if(/^[a-z0-9!#$%&'*+/=?^_`{|}~-]{1,20}(?:\.[a-z0-9!#$%&'*+/=?^_`{|}~-]{1,21}){0,2}@[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?(?:\.[a-z0-9](?:[a-z0-9-]{0,60}[a-z0-9])?){0,3}$/i.test(e))return!0;if(!e.includes("@")||/(^\.|^"|\.@|\.\.)/.test(e))return!1;const[t,r,...n]=e.split("@");return!(!t||!r||0!==n.length||t.length>64||r.length>253)&&(!(!/^[a-z0-9.-]+$/i.test(r)||!/^[a-z0-9.!#$%&'*+/=?^_`{|}~-]+$/i.test(t))&&r.split(".").every((e=>/^[a-z0-9]([a-z0-9-]{0,61}[a-z0-9])?$/i.test(e))))},hostname:e=>{if(e.length>(e.endsWith(".")?254:253))return!1;return/^[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?(?:\.[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?)*\.?$/i.test(e)},date:e=>{if(10!==e.length)return!1;if("0"===e[5]&&"2"===e[6]){if(/^\d\d\d\d-02-(?:[012][1-8]|[12]0|[01]9)$/.test(e))return!0;const t=e.match(/^(\d\d\d\d)-02-29$/);if(!t)return!1;const r=0|t[1];return r%16==0||r%4==0&&r%25!=0}return e.endsWith("31")?/^\d\d\d\d-(?:0[13578]|1[02])-31$/.test(e):/^\d\d\d\d-(?:0[13-9]|1[012])-(?:[012][1-9]|[123]0)$/.test(e)},time:e=>{if(e.length>27)return!1;if(!/^(?:2[0-3]|[0-1]\d):[0-5]\d:(?:[0-5]\d|60)(?:\.\d+)?(?:z|[+-](?:2[0-3]|[0-1]\d)(?::?[0-5]\d)?)?$/i.test(e))return!1;if(!/:60/.test(e))return!0;const t=e.match(/([0-9.]+|[^0-9.])/g);let r=60*Number(t[0])+Number(t[2]);return"+"===t[5]?r+=1440-60*Number(t[6]||0)-Number(t[8]||0):"-"===t[5]&&(r+=60*Number(t[6]||0)+Number(t[8]||0)),r%1440==1439},"date-time":e=>{if(e.length>38)return!1;const t="0"===e[5]&&"2"===e[6];if(t&&"3"===e[8]||!/^\d\d\d\d-(?:0[1-9]|1[0-2])-(?:[0-2]\d|3[01])[t\s](?:2[0-3]|[0-1]\d):[0-5]\d:(?:[0-5]\d|60)(?:\.\d+)?(?:z|[+-](?:2[0-3]|[0-1]\d)(?::?[0-5]\d)?)$/i.test(e))return!1;if("6"===e[17]){const t=e.slice(11).match(/([0-9.]+|[^0-9.])/g);let r=60*Number(t[0])+Number(t[2]);if("+"===t[5]?r+=1440-60*Number(t[6]||0)-Number(t[8]||0):"-"===t[5]&&(r+=60*Number(t[6]||0)+Number(t[8]||0)),r%1440!=1439)return!1}if(t){if(/^\d\d\d\d-02-(?:[012][1-8]|[12]0|[01]9)/.test(e))return!0;const t=e.match(/^(\d\d\d\d)-02-29/);if(!t)return!1;const r=0|t[1];return r%16==0||r%4==0&&r%25!=0}return"3"===e[8]&&"1"===e[9]?/^\d\d\d\d-(?:0[13578]|1[02])-31/.test(e):/^\d\d\d\d-(?:0[13-9]|1[012])-(?:[012][1-9]|[123]0)/.test(e)},ipv4:e=>e.length<=15&&/^(?:(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)\.){3}(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d\d?)$/.test(e),ipv6:e=>{if(e.length>45||e.length<2)return!1;let t=0,r=0,n=0,s=!1,o=!1,i=0,a=!0;for(let c=0;c<e.length;c++){const l=e.charCodeAt(c);if(1===c&&58===i&&58!==l)return!1;if(l>=48&&l<=57){if(++n>4)return!1}else if(46===l){if(t>6||r>=3||0===n||o)return!1;r++,n=0}else if(58===l){if(r>0||t>=7)return!1;if(58===i){if(s)return!1;s=!0}else 0===c&&(a=!1);t++,n=0,o=!1}else{if(!(l>=97&&l<=102||l>=65&&l<=70))return!1;if(r>0)return!1;if(++n>4)return!1;o=!0}i=l}if(t<2||r>0&&(3!==r||0===n))return!1;if(s&&2===e.length)return!0;if(r>0&&!/(?:\.(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}$/.test(e))return!1;const c=r>0?6:7;return s?(a||n>0)&&t<c:t===c&&a&&n>0},uri:/^[a-z][a-z0-9+\-.]*:(?:\/?\/(?:(?:[a-z0-9\-._~!$&'()*+,;=:]|%[0-9a-f]{2})*@)?(?:\[(?:(?:(?:(?:[0-9a-f]{1,4}:){6}|::(?:[0-9a-f]{1,4}:){5}|(?:[0-9a-f]{1,4})?::(?:[0-9a-f]{1,4}:){4}|(?:(?:[0-9a-f]{1,4}:){0,1}[0-9a-f]{1,4})?::(?:[0-9a-f]{1,4}:){3}|(?:(?:[0-9a-f]{1,4}:){0,2}[0-9a-f]{1,4})?::(?:[0-9a-f]{1,4}:){2}|(?:(?:[0-9a-f]{1,4}:){0,3}[0-9a-f]{1,4})?::[0-9a-f]{1,4}:|(?:(?:[0-9a-f]{1,4}:){0,4}[0-9a-f]{1,4})?::)(?:[0-9a-f]{1,4}:[0-9a-f]{1,4}|(?:(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d\d?)\.){3}(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d\d?))|(?:(?:[0-9a-f]{1,4}:){0,5}[0-9a-f]{1,4})?::[0-9a-f]{1,4}|(?:(?:[0-9a-f]{1,4}:){0,6}[0-9a-f]{1,4})?::)|v[0-9a-f]+\.[a-z0-9\-._~!$&'()*+,;=:]+)\]|(?:(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d\d?)\.){3}(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d\d?)|(?:[a-z0-9\-._~!$&'()*+,;=]|%[0-9a-f]{2})*)(?::\d*)?(?:\/(?:[a-z0-9\-._~!$&'()*+,;=:@]|%[0-9a-f]{2})*)*|\/?(?:(?:[a-z0-9\-._~!$&'()*+,;=:@]|%[0-9a-f]{2})+(?:\/(?:[a-z0-9\-._~!$&'()*+,;=:@]|%[0-9a-f]{2})*)*)?)(?:\?(?:[a-z0-9\-._~!$&'()*+,;=:@/?]|%[0-9a-f]{2})*)?(?:#(?:[a-z0-9\-._~!$&'()*+,;=:@/?]|%[0-9a-f]{2})*)?$/i,"uri-reference":/^(?:[a-z][a-z0-9+\-.]*:)?(?:\/?\/(?:(?:[a-z0-9\-._~!$&'()*+,;=:]|%[0-9a-f]{2})*@)?(?:\[(?:(?:(?:(?:[0-9a-f]{1,4}:){6}|::(?:[0-9a-f]{1,4}:){5}|(?:[0-9a-f]{1,4})?::(?:[0-9a-f]{1,4}:){4}|(?:(?:[0-9a-f]{1,4}:){0,1}[0-9a-f]{1,4})?::(?:[0-9a-f]{1,4}:){3}|(?:(?:[0-9a-f]{1,4}:){0,2}[0-9a-f]{1,4})?::(?:[0-9a-f]{1,4}:){2}|(?:(?:[0-9a-f]{1,4}:){0,3}[0-9a-f]{1,4})?::[0-9a-f]{1,4}:|(?:(?:[0-9a-f]{1,4}:){0,4}[0-9a-f]{1,4})?::)(?:[0-9a-f]{1,4}:[0-9a-f]{1,4}|(?:(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d\d?)\.){3}(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d\d?))|(?:(?:[0-9a-f]{1,4}:){0,5}[0-9a-f]{1,4})?::[0-9a-f]{1,4}|(?:(?:[0-9a-f]{1,4}:){0,6}[0-9a-f]{1,4})?::)|v[0-9a-f]+\.[a-z0-9\-._~!$&'()*+,;=:]+)\]|(?:(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d\d?)\.){3}(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d\d?)|(?:[a-z0-9\-._~!$&'()*+,;=]|%[0-9a-f]{2})*)(?::\d*)?(?:\/(?:[a-z0-9\-._~!$&'()*+,;=:@]|%[0-9a-f]{2})*)*|\/?(?:(?:[a-z0-9\-._~!$&'()*+,;=:@]|%[0-9a-f]{2})+(?:\/(?:[a-z0-9\-._~!$&'()*+,;=:@]|%[0-9a-f]{2})*)*)?)?(?:\?(?:[a-z0-9\-._~!$&'()*+,;=:@/?]|%[0-9a-f]{2})*)?(?:#(?:[a-z0-9\-._~!$&'()*+,;=:@/?]|%[0-9a-f]{2})*)?$/i,"uri-template":/^(?:[^\x00-\x20"'<>%\\^`{|}]|%[0-9a-f]{2}|\{[+#./;?&=,!@|]?(?:[a-z0-9_]|%[0-9a-f]{2})+(?::[1-9][0-9]{0,3}|\*)?(?:,(?:[a-z0-9_]|%[0-9a-f]{2})+(?::[1-9][0-9]{0,3}|\*)?)*\})*$/i,"json-pointer":/^(?:|\/(?:[^~]|~0|~1)*)$/,"relative-json-pointer":/^(?:0|[1-9][0-9]*)(?:|#|\/(?:[^~]|~0|~1)*)$/,uuid:/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i,duration:e=>e.length>1&&e.length<80&&(/^P\d+([.,]\d+)?W$/.test(e)||/^P[\dYMDTHS]*(\d[.,]\d+)?[YMDHS]$/.test(e)&&/^P([.,\d]+Y)?([.,\d]+M)?([.,\d]+D)?(T([.,\d]+H)?([.,\d]+M)?([.,\d]+S)?)?$/.test(e))};var G={core:Y,extra:{alpha:/^[a-zA-Z]+$/,alphanumeric:/^[a-zA-Z0-9]+$/,"hex-digits":/^[0-9a-f]+$/i,"hex-digits-prefixed":/^0x[0-9a-f]+$/i,"hex-bytes":/^([0-9a-f][0-9a-f])+$/i,"hex-bytes-prefixed":/^0x([0-9a-f][0-9a-f])+$/i,base64:e=>e.length%4==0&&/^[a-z0-9+/]*={0,3}$/i.test(e),"json-pointer-uri-fragment":/^#(|\/(\/|[a-z0-9_\-.!$&'()*+,;:=@]|%[0-9a-f]{2}|~0|~1)*)$/i,"host-name":Y.hostname,"ip-address":Y.ipv4,color:/^(#[0-9A-Fa-f]{3,6}|aqua|black|blue|fuchsia|gray|green|lime|maroon|navy|olive|orange|purple|red|silver|teal|white|yellow|rgb\(\s*([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])\s*,\s*([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])\s*,\s*([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])\s*\)|rgb\(\s*(\d?\d%|100%)\s*,\s*(\d?\d%|100%)\s*,\s*(\d?\d%|100%)\s*\))$/},weak:{regex:e=>{if(e.length>1e5)return!1;if(/[^\\]\\Z/.test(e))return!1;try{return new RegExp(e,"u"),!0}catch(e){return!1}}}};const Q=(e,t)=>[...new Set([...e,...t])].sort(),X=(e,t)=>e.filter((e=>t.includes(e))),ee=e=>(...t)=>re(e(...t.map(re))),te=(e,t)=>e&&!e.includes(t),re=({type:e=null,dyn:t={},...r})=>({type:e?[...e].sort():e,items:te(e,"array")?1/0:r.items||0,properties:te(e,"object")?[!0]:[...r.properties||[]].sort(),patterns:te(e,"object")?[]:[...r.patterns||[]].sort(),required:te(e,"object")?[]:[...r.required||[]].sort(),fullstring:te(e,"string")||r.fullstring||!1,dyn:{item:!te(e,"array")&&(t.item||!1),items:te(e,"array")?0:Math.max(r.items||0,t.items||0),properties:te(e,"object")?[]:Q(r.properties||[],t.properties||[]),patterns:te(e,"object")?[]:Q(r.patterns||[],t.patterns||[])},unknown:r.unknown&&!(te(e,"object")&&te(e,"array"))||!1}),ne=ee(((e,t)=>({type:e.type&&t.type?X(e.type,t.type):e.type||t.type||null,items:Math.max(e.items,t.items),properties:Q(e.properties,t.properties),patterns:Q(e.patterns,t.patterns),required:Q(e.required,t.required),fullstring:e.fullstring||t.fullstring,dyn:{item:e.dyn.item||t.dyn.item,items:Math.max(e.dyn.items,t.dyn.items),properties:Q(e.dyn.properties,t.dyn.properties),patterns:Q(e.dyn.patterns,t.dyn.patterns)},unknown:e.unknown||t.unknown}))),se=(e,t)=>!0!==t&&new RegExp(e,"u").test(t),oe=({properties:e,patterns:t},{properties:r,patterns:n})=>{const s=e.filter((e=>r.includes(e)||r.includes(!0)||n.some((t=>se(t,e))))),o=r.filter((r=>e.includes(r)||e.includes(!0)||t.some((e=>se(e,r))))),i=t.filter((e=>n.includes(e)||r.includes(!0))),a=n.filter((r=>t.includes(r)||e.includes(!0)));return{properties:Q(s,o),patterns:Q(i,a)}},ie=({properties:e,patterns:t},{properties:r,patterns:n})=>r.every((r=>e.includes(r)||e.includes(!0)||t.some((e=>se(e,r)))))&&n.every((r=>t.includes(r)||e.includes(!0))),ae=ee(((e,t)=>({type:e.type&&t.type?Q(e.type,t.type):null,items:Math.min(e.items,t.items),...oe(e,t),required:te(e.type,"object")&&t.required||te(t.type,"object")&&e.required||X(e.required,t.required),fullstring:e.fullstring&&t.fullstring,dyn:{item:e.dyn.item||t.dyn.item,items:Math.max(e.dyn.items,t.dyn.items),properties:Q(e.dyn.properties,t.dyn.properties),patterns:Q(e.dyn.patterns,t.dyn.patterns)},unknown:e.unknown||t.unknown}))),ce=(le=({unknown:e,items:t,dyn:r,...n})=>({items:t!==1/0&&(e||r.items>t||r.item),properties:!n.properties.includes(!0)&&(e||!ie(n,r))}),(...e)=>le(...e.map(re)));var le,ue={initTracing:()=>re({}),andDelta:ne,orDelta:ae,applyDelta:(e,t)=>Object.assign(e,ne(e,t)),isDynamic:ce,inProperties:ie};const{format:pe,safe:de,safeand:fe,safenot:me,safenotor:ye}=l,he=I,{resolveReference:ge,joinPath:we,getDynamicAnchors:be,hasKeywords:$e}=Z,ve=G,{toPointer:je,...Oe}=h,{scopeMethods:xe}=d,{buildName:Ee,types:ke,jsHelpers:Ae}=A,{knownKeywords:Se,schemaVersions:ze,knownVocabularies:Me}=U,{initTracing:qe,andDelta:Ne,orDelta:Pe,applyDelta:Ie,isDynamic:Re,inProperties:Ue}=ue,Ce=new Set(["^[\\s\\S]*$","^[\\S\\s]*$","^[^]*$","",".*","^","$"]),De=["null","boolean","number","integer","string"],_e=new Map(Object.entries({boolean:e=>"boolean"==typeof e,array:e=>Array.isArray(e)&&Object.getPrototypeOf(e)===Array.prototype,object:e=>e&&Object.getPrototypeOf(e)===Object.prototype,finite:e=>Number.isFinite(e),natural:e=>Number.isInteger(e)&&e>=0,string:e=>"string"==typeof e,jsonval:e=>Oe.deepEqual(e,JSON.parse(JSON.stringify(e)))})),Le=_e.get("object"),Je=e=>Le(e)||"boolean"==typeof e,Fe=(e,t)=>ze.indexOf(e)>ze.indexOf(`https://json-schema.org/${t}/schema`),Te=(e,t)=>{const r=`${e}`.replace(/^http:\/\//,"https://").replace(/#$/,"");return!ze.includes(r)||Fe(r,t)},Ve=(e,t,r=!1,n=!1)=>Object.freeze({parent:e,keyname:t,inKeys:r,number:n}),We=Symbol("evaluatedStatic"),Ke=Symbol("optDynamic"),Be=Symbol("optDynAnchors"),He=Symbol("optRecAnchors"),Ze=new Set,Ye=new Map,Ge=(e,t,r,n,s="")=>{const{mode:o="default",useDefaults:i=!1,removeAdditional:a=!1,includeErrors:c=!1,allErrors:l=!1,contentValidation:u,dryRun:p,lint:d=!1,allowUnusedKeywords:f="lax"===r.mode||"spec"===r.mode,allowUnreachable:m="lax"===r.mode||"spec"===r.mode,requireSchema:y="strong"===r.mode,requireValidation:h="strong"===r.mode,requireStringValidation:g="strong"===r.mode,forbidNoopValues:w="strong"===r.mode,complexityChecks:b="strong"===r.mode,unmodifiedPrototypes:$=!1,isJSON:v=!1,$schemaDefault:j=null,formatAssertion:O="spec"!==r.mode||Te(t.$schema,"draft/2019-09"),formats:x={},weakFormats:E="strong"!==r.mode,extraFormats:k=!1,schemas:A,...S}=r,z={...ve.core,...E?ve.weak:{},...k?ve.extra:{},...x};if(0!==Object.keys(S).length)throw new Error(`Unknown options: ${Object.keys(S).join(", ")}`);if(!["strong","lax","default","spec"].includes(o))throw new Error(`Invalid mode: ${o}`);if(!c&&l)throw new Error("allErrors requires includeErrors to be enabled");if(y&&j)throw new Error("requireSchema forbids $schemaDefault");if("strong"===o){const e={...{requireValidation:h,requireStringValidation:g},formatAssertion:O,complexityChecks:b,requireSchema:y},t={weakFormats:E,allowUnusedKeywords:f};for(const[t,r]of Object.entries(e))if(!r)throw new Error(`Strong mode demands ${t}`);for(const[e,r]of Object.entries(t))if(r)throw new Error(`Strong mode forbids ${e}`)}const{gensym:M,getref:q,genref:N,genformat:P}=xe(n),I=N(e);let R=null;const U=(...e)=>{const t=R(...e);return U.errors=R.errors,t};n[I]=U;const C=$e(e,["$ref","$recursiveRef","$dynamicRef"]),D=r[Be]&&C&&$e(e,["$dynamicAnchor"]),_=r[He]?pe(", recursive"):pe(""),L=he();L.write("function validate(data%s%s) {",_,r[Be]?pe(D?", dynAnchors = []":", dynAnchors"):pe("")),c&&L.write("validate.errors = null"),l&&L.write("let errorCount = 0"),r[Ke]&&L.write("validate.evaluatedDynamic = null");let J=r[Be]?pe(", dynAnchors"):pe("");D&&(L.write("const dynLocal = [{}]"),J=pe(", [...dynAnchors, dynLocal[0] || []]"));const F=Ae(L,n,Ve,{unmodifiedPrototypes:$,isJSON:v},Ce),{present:T,forObjectKeys:V,forArray:W,patternTest:K,compare:B}=F,H=[],Z=()=>Ye.get(t),Y=s?[s]:[],G=(p,$,E,k,S,N={},{constProp:R}={})=>{const U=$.length>0&&$[$.length-1].prop===E,C=()=>$.filter((e=>e.prop===E)),_=!E.parent||E.checked||E.inKeys&&v||C().length>0,F=Ee(E),Q=(...e)=>((e,t,r=!1)=>Object.freeze({parent:e,keyval:t,checked:r}))(E,...e),X=({path:e=[],prop:t=E,source:r,suberr:s})=>{const o=je([...S,...e]),i=c?(e=>{const t=[];let r=e;for(;r;)r.name||t.unshift(r),r=r.parent||r.errorParent;if(t.every((e=>void 0!==e.keyval)))return pe("%j",je(t.map((e=>e.keyval))));const s=["#"],o=()=>{const e=s.map(Oe.pointerPart).join("/");return s.length=0,e};let i=null;for(const{keyname:e,keyval:r,number:a}of t)if(e){a||(n.pointerPart=Oe.pointerPart);const t=a?e:pe("pointerPart(%s)",e),r=`${o()}/`;i=i?pe("%s+%j+%s",i,r,t):pe("%j+%s",r,t)}else r&&s.push(r);return s.length>0?pe("%s+%j",i,`/${o()}`):i})(t):null;if(!0===c&&p&&r){n.errorMerge=Oe.errorMerge;const e=[r,o,i];l?(L.write("if (validate.errors === null) validate.errors = []"),L.write("validate.errors.push(...%s.map(e => errorMerge(e, %j, %s)))",...e)):L.write("validate.errors = [errorMerge(%s[0], %j, %s)]",...e)}else if(!0===c&&p){const e=pe("{ keywordLocation: %j, instanceLocation: %s }",o,i);l?(L.write("if (%s === null) %s = []",p,p),L.write("%s.push(%s)",p,e)):L.write("%s = [%s]",p,e)}s&&xt(s),l?L.write("errorCount++"):L.write("return false")},ee=(e,t)=>L.if(e,(()=>X(t)));d&&!n.lintErrors&&(n.lintErrors=[]);const te=(t,r)=>{const o=void 0!==r?` ${JSON.stringify(r)}`:"",i=we(s,je(S)),a=`${t}${o} at ${i}`;if(d)return n.lintErrors.push({message:a,keywordLocation:i,schema:e});throw new Error(a)},re=(e,t)=>{try{return K(e,t)}catch(e){return te(e.message),pe("false")}},ne=(e,...t)=>e||te(...t),se=(e,...t)=>ne("lax"===o||"spec"===o||e,...t),oe=(e,t)=>se(!(k[t]<k[e]),`Invalid ${e} / ${t} combination`),ie=(e,t="should be specified")=>ne(!h,`[requireValidation] ${e} ${t}`),ae=(...e)=>[...S,...e],ce=e=>ne(!a&&!i,`[removeAdditional/useDefaults] uncertain: ${e}`),le=(e,t)=>ne(!b,`[complexityChecks] ${e}`,t),ue=e=>((e,t,r,n)=>{if(t){const n=t.replace(/^http:\/\//,"https://").replace(/#$/,"");r(ze.includes(n),"Unexpected schema version:",n),Ye.set(e,{exclusiveRefs:Fe(n,"draft/2019-09"),contentValidation:Fe(n,"draft/2019-09"),dependentUnsupported:Fe(n,"draft/2019-09"),newItemsSyntax:!Fe(n,"draft/2020-12"),containsEvaluates:!Fe(n,"draft/2020-12"),objectContains:!Fe(n,"draft/next"),bookending:Fe(n,"draft/next")})}else r(!n,"[requireSchema] $schema is required"),Ye.set(e,{})})(t,e||j,ne,y),he=qe(),$e=e=>Ie(he,e);if("boolean"==typeof k)return!0===k?(ie("schema = true","is not allowed"),{stat:he}):(ee(!(!_&&!E.inKeys)||T(E),{}),$e({type:[]}),{stat:he});ne(Le(k),"Schema is not an object");for(const e of Object.keys(k))ne(Se.includes(e)||f,"Keyword not supported:",e);if(0===Object.keys(k).length)return ie("empty rules node","is not allowed"),{stat:he};const xe=new Set(Object.keys(k)),Ae=new Set,Te=(e,...t)=>{ne(Ae.has(e)||xe.has(e),"Unexpected double consumption:",e),ne(Oe.hasOwn(k,e),"Is not an own property:",e),ne(t.every((e=>_e.has(e))),"Invalid type used in consume"),ne(t.some((t=>_e.get(t)(k[e]))),"Unexpected type for",e),xe.delete(e)},Ve=(e,...t)=>(void 0!==k[e]&&Te(e,...t),k[e]),Qe=(e,t,r,n={})=>{if(void 0===k[e])return!1;if(Te(e,...t),null!==r)try{const t=r(k[e]);null!==t&&ee(t,{path:[e],...n})}catch(e){if(!d||e.message.startsWith("[opt] "))throw e;te(e.message)}return!0};if(k===t?(ue(Ve("$schema","string")),Qe("$vocabulary",["object"],(e=>{for(const[t,r]of Object.entries(e))!1!==r&&ne(!0===r&&Me.includes(t),"Unknown vocabulary:",t);return null}))):Z()||ue(t.$schema),Z().objectContains)for(const e of["contains","minContains","maxContains"])Ae.add(e);Qe("examples",["array"],null),Qe("example",["jsonval"],null);for(const e of["title","description","$comment"])Qe(e,["string"],null);for(const e of["deprecated","readOnly","writeOnly"])Qe(e,["boolean"],null);Qe("$defs",["object"],null)||Qe("definitions",["object"],null);const Xe=(t,s,o)=>t===e?de("validate"):q(t)||Ge(t,s,r,n,o),et=()=>Y.length>0?Y[Y.length-1]:"",tt=Y.length,rt=e=>(Y.push(we(et(),e)),null);Z().exclusiveRefs&&k.$ref||(Qe("$id",["string"],rt)||Qe("id",["string"],rt),Qe("$anchor",["string"],null),Qe("$dynamicAnchor",["string"],null),!k.$recursiveAnchor&&w||Qe("$recursiveAnchor",["boolean"],(e=>(e&&H.push([k,t,et()]),null))));const nt=D&&(k===e||k.id||k.$id);if(nt){const r=be(k);k!==e&&L.write("dynLocal.unshift({})");for(const[e,n]of r){const r=ge(t,A,`#${e}`,et()),[s,o,i]=r[0]||[];ne(s===n,`Unexpected $dynamicAnchor resolution: ${e}`);const a=Xe(s,o,i);L.write("dynLocal[0][%j] = %s",`#${e}`,a)}}const st=t=>r[Ke]&&(k[t]||!1===k[t]||k===e),ot=Object.freeze({item:st("unevaluatedItems")?M("evaluatedItem"):null,items:st("unevaluatedItems")?M("evaluatedItems"):null,props:st("unevaluatedProperties")?M("evaluatedProps"):null}),it=Object.freeze({item:ot.item||N.item,items:ot.items||N.items,props:ot.props||N.props}),at=()=>(!it.items||he.items===1/0)&&(!it.props||he.properties.includes(!0)),ct=e=>{if(it.item&&e.item&&he.items!==1/0&&L.write("%s.push(%s)",it.item,e.item),it.items&&e.items>he.items&&L.write("%s.push(%d)",it.items,e.items),it.props&&(e.properties||[]).includes(!0)&&!he.properties.includes(!0))L.write("%s[0].push(true)",it.props);else if(it.props){const t=(e,t)=>Ue(he,{properties:e,patterns:t}),r=(e.properties||[]).filter((e=>!t([e],[]))),n=(e.patterns||[]).filter((e=>!t([],[e])));r.length>0&&L.write("%s[0].push(...%j)",it.props,r),n.length>0&&L.write("%s[1].push(...%j)",it.props,n);for(const t of e.propertiesVars||[])L.write("%s[0].push(%s)",it.props,t)}},lt=(e,t,r,n)=>{Re(he).items&&e.item&&t&&L.write("%s.push(...%s)",e.item,t),Re(he).items&&e.items&&r&&L.write("%s.push(...%s)",e.items,r),Re(he).properties&&e.props&&n&&(L.write("%s[0].push(...%s[0])",e.props,n),L.write("%s[1].push(...%s[1])",e.props,n))},ut=(e,t)=>{const s=n[e]&&n[e][We]||{unknown:!0};$e(s);const o=pe("%s(%s%s%s)",e,F,r[He]?0===H.length?pe(", recursive"):pe(", recursive || %s",Xe(...H[0])):pe(""),J);if(!c&&at())return pe("!%s",o);const i=M("res"),a=M("err"),l=M("suberr");return c&&L.write("const %s = validate.errors",a),L.write("const %s = %s",i,o),c&&L.write("const %s = %s.errors",l,e),c&&L.write("validate.errors = %s",a),ee(me(i),{...t,source:l}),L.if(i,(()=>{const t=Re(s).items?pe("%s.evaluatedDynamic[0]",e):null,r=Re(s).items?pe("%s.evaluatedDynamic[1]",e):null,n=Re(s).properties?pe("%s.evaluatedDynamic[2]",e):null;lt(it,t,r,n)})),null},pt=(e,t)=>e&&e.every((e=>t.includes(e))),dt=(e,t)=>t.some((t=>null===e||e.includes(t))),ft=(...e)=>C().some((t=>pt(t.stat.type,e))),mt=(...e)=>dt(he.type,e)&&C().every((t=>dt(t.stat.type,e))),yt=(e,t=k)=>{ne("string"==typeof e,"Invalid pattern:",e),(h||g)&&ne(/^\^.*\$$/.test(e),"Should start with ^ and end with $:",e),/([{+*].*[{+*]|\)[{+*]|^[^^].*[{+*].)/.test(e)&&void 0===t.maxLength&&le("maxLength should be specified for pattern:",e)},ht=k.pattern&&!Ce.has(k.pattern),gt=k.uniqueItems||ht||k.patternProperties||k.format,wt=l&>?M("prev"):null,bt=(e,t)=>L.if(!e||null===wt||pe("errorCount === %s",wt),t),$t=()=>[...$,{stat:he,prop:E}],vt=(...e)=>G(p,$t(),...e).stat,jt=(e,...t)=>{if(t[0]===E){const e=(e=>"boolean"==typeof e?e:!(!Le(e)||0!==Object.keys(e).length)||void 0)(t[1]);if(!0===e)return{sub:pe("true"),delta:{}};if(!1===e)return{sub:pe("false"),delta:{type:[]}}}const r=M("sub");L.write("const %s = (() => {",r),l&&L.write("let errorCount = 0");const{stat:n}=G(e,$t(),...t);return l?L.write("return errorCount === 0"):L.write("return true"),L.write("})()"),{sub:r,delta:n}},Ot=()=>{const e=c&&l?M("suberr"):null;return e&&L.write("let %s = null",e),e},xt=e=>{null!==p&&null!==e&&L.if(e,(()=>L.write("%s.push(...%s)",p,e)))},Et=()=>{if(!a)return!1;if(!0===a)return!0;if("keyword"===a)return!!k.removeAdditional&&(Te("removeAdditional","boolean"),!0);throw new Error(`Invalid removeAdditional: ${a}`)},kt=(e,t,r)=>{Qe(e,["object","boolean"],(n=>!1===n&&Et()?(L.write("if (%s.length > %s) %s.length = %s",F,t,F,t),null):!1!==n||r?(W(E,t,((t,s)=>(r&&L.write("if (%s) continue",r(s)),vt(t,n,ae(e))))),null):pe("%s.length > %s",F,t)))&&$e({items:1/0})},At=(e,t)=>{Qe(e,["object","boolean"],(r=>(V(E,((n,s)=>{L.if(t(s),(()=>{!1===r&&Et()?L.write("delete %s[%s]",F,s):vt(n,r,ae(e))}))})),null)))&&$e({properties:[!0]})},St=(e,t,r)=>fe(...t.map((t=>pe("%s !== %j",e,t))),...r.map((t=>me(re(t,e))))),zt=(e,t)=>{const r=t.map((e=>new RegExp(e,"u"))),n=t=>e.includes(t)||r.some((e=>e.test(t)));for(const e of he.required)ne(n(e),"Unknown required property:",e)},Mt=[],qt=()=>{const e=(e,t)=>pe("!(%d %c %s)",e,t,F);Number.isFinite(k.exclusiveMinimum)?Qe("exclusiveMinimum",["finite"],(t=>e(t,"<"))):(Qe("minimum",["finite"],(t=>e(t,k.exclusiveMinimum?"<":"<="))),Qe("exclusiveMinimum",["boolean"],null)),Number.isFinite(k.exclusiveMaximum)?(Qe("exclusiveMaximum",["finite"],(t=>e(t,">"))),oe("minimum","exclusiveMaximum"),oe("exclusiveMinimum","exclusiveMaximum")):void 0!==k.maximum&&(Qe("maximum",["finite"],(t=>e(t,k.exclusiveMaximum?">":">="))),Qe("exclusiveMaximum",["boolean"],null),oe("minimum","maximum"),oe("exclusiveMinimum","maximum"));const t=void 0===k.multipleOf?"divisibleBy":"multipleOf";Qe(t,["finite"],(e=>{ne(e>0,`Invalid ${t}:`,e);const[r,s]=`${e}`.split("e-"),o=`${r}.`.split(".")[1].length+(s?Number(s):0);if(Number.isInteger(e*2**o))return pe("%s %% %d !== 0",F,e);n.isMultipleOf=Oe.isMultipleOf;const i=[F,e,o,Math.round(e*Math.pow(10,o))];return pe("!isMultipleOf(%s, %d, 1e%d, %d)",...i)}))},Nt=()=>{Qe("maxLength",["natural"],(e=>(n.stringLength=Oe.stringLength,pe("%s.length > %d && stringLength(%s) > %d",F,e,F,e)))),Qe("minLength",["natural"],(e=>(n.stringLength=Oe.stringLength,pe("%s.length < %d || stringLength(%s) < %d",F,e,F,e)))),oe("minLength","maxLength"),bt(!0,(()=>{const e=(e,t,r=z)=>{const n="string"==typeof e&&Oe.hasOwn(r,e);ne(n,"Unrecognized format used:",e);const s=r[e],o=s instanceof RegExp||"function"==typeof s;return ne(o,"Invalid format used:",e),O?s instanceof RegExp?(Oe.hasOwn(x,e)&&yt(s.source),pe("!%s.test(%s)",P(s),t)):pe("!%s(%s)",P(s),t):null};Qe("format",["string"],(t=>($e({fullstring:!0}),e(t,F)))),Qe("pattern",["string"],(e=>(yt(e),$e({fullstring:!0}),Ce.has(e)?null:me(re(e,F))))),ne(!1!==k.contentSchema,"contentSchema cannot be set to false");const t=void 0===u?Z().contentValidation:u,r=k.contentEncoding||k.contentMediaType||k.contentSchema;if(ne(!r||t||f,'"content*" keywords are disabled by default per spec, enable with { contentValidation = true } option (see doc/Options.md for more info)'),r&&t){const t=M("dec");k.contentMediaType&&L.write("let %s = %s",t,F),"base64"===k.contentEncoding?(ee(e("base64",F,ve.extra),{path:["contentEncoding"]}),k.contentMediaType&&(n.deBase64=Oe.deBase64,L.write("try {"),L.write("%s = deBase64(%s)",t,t)),Te("contentEncoding","string")):ne(!k.contentEncoding,"Unknown contentEncoding:",k.contentEncoding);let r=!1;if("application/json"===k.contentMediaType?(L.write("try {"),L.write("%s = JSON.parse(%s)",t,t),r=!0,Te("contentMediaType","string")):ne(!k.contentMediaType,"Unknown contentMediaType:",k.contentMediaType),k.contentSchema){ne(r,"contentSchema requires contentMediaType application/json");const e=Object.freeze({name:t,errorParent:E});vt(e,k.contentSchema,ae("contentSchema")),Te("contentSchema","object","array"),$e({fullstring:!0})}k.contentMediaType&&(L.write("} catch (e) {"),X({path:["contentMediaType"]}),L.write("}"),k.contentEncoding&&(L.write("} catch (e) {"),X({path:["contentEncoding"]}),L.write("}")))}}))},Pt=()=>{Qe("maxItems",["natural"],(e=>{const t=Z().newItemsSyntax?"prefixItems":"items";return Array.isArray(k[t])&&k[t].length>e&&te(`Invalid maxItems: ${e} is less than ${t} array length`),pe("%s.length > %d",F,e)})),Qe("minItems",["natural"],(e=>pe("%s.length < %d",F,e))),oe("minItems","maxItems");const e=e=>{for(let t=0;t<e.length;t++)vt(Q(t),e[t],ae(`${t}`));return $e({items:e.length}),null};Z().newItemsSyntax?(Qe("prefixItems",["array"],e),kt("items",pe("%d",(k.prefixItems||[]).length))):Array.isArray(k.items)?(Qe("items",["array"],e),kt("additionalItems",pe("%d",k.items.length))):Qe("items",["object","boolean"],(e=>(W(E,pe("0"),(t=>vt(t,e,ae("items")))),$e({items:1/0}),null))),Ut((e=>{W(E,pe("0"),((t,r)=>{e(t,(()=>{$e({dyn:{item:!0}}),ct({item:r})}))}))}));const r=e=>{if(!Le(e))return!1;if(e.enum||Oe.hasOwn(e,"const"))return!0;if(e.type){if((Array.isArray(e.type)?e.type:[e.type]).every((e=>De.includes(e))))return!0}if(e.$ref){const[n]=ge(t,A,e.$ref,et())[0]||[];if(r(n))return!0}return!1},s=e=>!1===e||r(e);bt(!0,(()=>{Qe("uniqueItems",["boolean"],(e=>!1===e?null:(void 0!==k.maxItems||s(k.items)||Array.isArray(k.items)&&s(k.additionalItems)||le("maxItems should be specified for non-primitive uniqueItems"),Object.assign(n,{unique:Oe.unique,deepEqual:Oe.deepEqual}),pe("!unique(%s)",F))))}))},It=e=>!l&&(he.required.includes(e)||C().some((t=>t.stat.required.includes(e)))),Rt=()=>{const e=pe("Object.keys(%s).length",F);Qe("maxProperties",["natural"],(t=>pe("%s > %d",e,t))),Qe("minProperties",["natural"],(t=>pe("%s < %d",e,t))),oe("minProperties","maxProperties"),Qe("propertyNames",["object","boolean"],(e=>(V(E,((t,r)=>{const n="object"!=typeof e||e.$ref?e:{type:"string",...e},s=Object.freeze({name:r,errorParent:t,type:"string"});vt(s,n,ae("propertyNames"))})),null))),Qe("required",["array"],(e=>{for(const t of e){if(It(t))continue;const e=Q(t);ee(me(T(e)),{path:["required"],prop:e})}return $e({required:e}),null}));for(const e of["dependencies","dependentRequired","dependentSchemas"])"dependencies"!==e&&Z().dependentUnsupported||Qe(e,["object"],(t=>{for(const r of Object.keys(t)){const n="string"==typeof t[r]?[t[r]]:t[r],s=Q(r,It(r));if(Array.isArray(n)&&"dependentSchemas"!==e){const t=n.filter((e=>!It(e))).map((e=>T(Q(e)))),o=me(fe(...t)),i={path:[e,r]};0===t.length||(s.checked?(ee(o,i),$e({required:n})):ee(fe(T(s),o),i))}else Je(n)&&"dependentRequired"!==e?(ce(e),L.if(!!s.checked||T(s),(()=>{const t=vt(E,n,ae(e,r),it);$e(Pe({},t)),ct(t)}))):te(`Unexpected ${e} entry`)}return null}));Qe("propertyDependencies",["object"],(e=>{for(const[t,r]of Object.entries(e)){ne(Le(r),"propertyDependencies must be an object"),ce("propertyDependencies");const e=Q(t,It(t));L.if(!!e.checked||T(e),(()=>{for(const[n,s]of Object.entries(r))ne(Je(s),"propertyDependencies must contain schemas"),L.if(B(Ee(e),n),(()=>{const e=vt(E,s,ae("propertyDependencies",t,n),it);$e(Pe({},e)),ct(e)}))}))}return null})),Qe("properties",["object"],(e=>{for(const t of Object.keys(e))R!==t&&vt(Q(t,It(t)),e[t],ae("properties",t));return $e({properties:Object.keys(e)}),null})),bt(k.patternProperties,(()=>{if(Qe("patternProperties",["object"],(e=>(V(E,((t,r)=>{for(const n of Object.keys(e))yt(n,k.propertyNames||{}),L.if(re(n,r),(()=>{vt(t,e[n],ae("patternProperties",n))}))})),$e({patterns:Object.keys(e)}),null))),k.additionalProperties||!1===k.additionalProperties){const e=Object.keys(k.properties||{}),t=Object.keys(k.patternProperties||{});!1===k.additionalProperties&&Mt.push((()=>zt(e,t)));At("additionalProperties",(r=>St(r,e,t)))}})),Z().objectContains&&Ut((e=>{V(E,((t,r)=>{e(t,(()=>{$e({dyn:{properties:[!0]}}),ct({propertiesVars:[r]})}))}))}))},Ut=e=>{Qe("contains",["object","boolean"],(()=>{ce("contains"),Z().objectContains&&mt("array")&&mt("object")&&ie("possible type confusion in 'contains',","forbid 'object' or 'array'");const t=M("passes");L.write("let %s = 0",t);const r=Ot();return e(((e,n)=>{const{sub:s}=jt(r,e,k.contains,ae("contains"));L.if(s,(()=>{L.write("%s++",t),Z().containsEvaluates&&(ne(!a,'Can\'t use removeAdditional with draft2020+ "contains"'),n())}))})),Qe("minContains",["natural"],(e=>pe("%s < %d",t,e)),{suberr:r})||ee(pe("%s < 1",t),{path:["contains"],suberr:r}),Qe("maxContains",["natural"],(e=>pe("%s > %d",t,e))),oe("minContains","maxContains"),null}))},Ct=()=>{Qe("not",["object","boolean"],(e=>jt(null,E,e,ae("not")).sub)),k.not&&ce("not");(k.then||!1===k.then||k.else||!1===k.else||f)&&Qe("if",["object","boolean"],(e=>{ce("if/then/else");const{sub:t,delta:r}=jt(null,E,e,ae("if"),it);let n,s,o,i;var a;return Qe("else",["object","boolean"],(e=>(n=()=>{o=vt(E,e,ae("else"),it),ct(o)},null))),Qe("then",["object","boolean"],(e=>(s=()=>{i=vt(E,e,ae("then"),it),ct(Ne(r,i))},null))),s||(a=r,Oe.deepEqual(a,{type:[]}))||(s=()=>ct(r)),L.if(t,s,n),$e(Pe(o||{},Ne(r,i||{}))),null}));const e=(e,t="allOf")=>{ne(e.length>0,`${t} cannot be empty`);for(const[r,n]of Object.entries(e))$e(vt(E,n,ae(t,r),it));return null};Qe("allOf",["array"],(t=>e(t)));let r=null;Qe("discriminator",["object"],(e=>{const n=new Set,s=(e,t,r)=>ne(e,`[discriminator]: ${t}`,r),{propertyName:o,mapping:i,...a}=e,c=Q(o);s(o&&!k.oneOf!=!k.anyOf,"need propertyName, oneOf OR anyOf"),s(0===Object.keys(a).length,'only "propertyName" and "mapping" are supported');return r=(e,r)=>{const a=()=>{let a;L.write("switch (%s) {",Ee(c));for(const[c,l]of Object.entries(e)){const{const:e,enum:u,...p}=(l.properties||{})[o]||{};let d=void 0!==e?[e]:u;if(!d&&l.$ref){const[e]=ge(t,A,l.$ref,et())[0]||[];ne(Le(e),"failed to resolve $ref:",l.$ref);const r=(e.properties||{})[o]||{};d=void 0!==r.const?[r.const]:r.enum}const f=Array.isArray(d)&&d.length>0;s(f,"branches should have unique string const or enum values for [propertyName]");const m=!(0!==Object.keys(p).length||e&&u);s(m,"only const OR enum rules are allowed on [propertyName] in branches");for(const e of d){const t=!i||Oe.hasOwn(i,e)&&i[e]===l.$ref;s(t,"mismatching mapping for",e);const r="string"==typeof e&&!n.has(e);s(r,"const/enum values for [propertyName] should be unique strings"),n.add(e),L.write("case %j:",e)}const y=vt(E,l,ae(r,c),it,{constProp:o});ct(y),a=a?Pe(a,y):y,L.write("break")}var l;s(void 0===i||(Le(l=i)?Object.keys(l).length:null)===n.size,"mismatching mapping size"),$e(a),L.write("default:"),X({path:[r]}),L.write("}")},u=()=>{if(It(o))a();else{const e=["discriminator","propertyName"];L.if(T(c),a,(()=>X({path:e,prop:c})))}};return l||!Oe.deepEqual(he.type,["object"])?L.if(ke.get("object")(F),u,(()=>X({path:["discriminator"]}))):u(),s(Oe.deepEqual(he.type,["object"]),"has to be checked for type:","object"),s(he.required.includes(o),"propertyName should be placed in required:",o),null},null}));const n=(e,t)=>{const r=t.map((e=>e.type||(Array.isArray(e.const)?"array":typeof e.const))),n=r.filter((e=>!De.includes(e)&&"array"!==e)).length,s=r.filter((e=>!De.includes(e)&&"object"!==e)).length;(n>1||s>1)&&ce(`${e}, use discriminator to make it certain`)};Qe("anyOf",["array"],(t=>{if(ne(t.length>0,"anyOf cannot be empty"),1===t.length)return e(t);if(r)return r(t,"anyOf");const s=Ot();if(!at()){n("anyOf",t);const e=Object.entries(t).map((([e,t])=>jt(s,E,t,ae("anyOf",e),it)));$e(e.map((e=>e.delta)).reduce(((e,t)=>Pe(e,t)))),ee(ye(...e.map((({sub:e})=>e))),{path:["anyOf"],suberr:s});for(const{delta:t,sub:r}of e)L.if(r,(()=>ct(t)));return null}const o=t.filter((e=>Oe.hasOwn(e,"const"))),i=t.filter((e=>!Oe.hasOwn(e,"const")));n("anyOf",i);const a=[...o,...i];let c;if(Z().exclusiveRefs){let e=()=>X({path:["anyOf"],suberr:s});for(const[t,r]of Object.entries(a).reverse()){const n=e;e=()=>{const{sub:e,delta:o}=jt(s,E,r,ae("anyOf",t));L.if(me(e),n),c=c?Pe(c,o):o}}e()}else{const e=Object.entries(t).map((([e,t])=>jt(s,E,t,ae("anyOf",e),it)));c=e.map((e=>e.delta)).reduce(((e,t)=>Pe(e,t))),ee(ye(...e.map((({sub:e})=>e))),{path:["anyOf"],suberr:s})}return $e(c),null})),Qe("oneOf",["array"],(t=>{if(ne(t.length>0,"oneOf cannot be empty"),1===t.length)return e(t);if(r)return r(t,"oneOf");n("oneOf",t);const s=M("passes");L.write("let %s = 0",s);const o=Ot();let i,a=0;const l=Object.entries(t).map((([e,t])=>{!c&&a++>1&&ee(pe("%s > 1",s),{path:["oneOf"]});const r=jt(o,E,t,ae("oneOf",e),it);return L.if(r.sub,(()=>L.write("%s++",s))),i=i?Pe(i,r.delta):r.delta,r}));$e(i),ee(pe("%s !== 1",s),{path:["oneOf"]}),L.if(pe("%s === 0",s),(()=>xt(o)));for(const e of l)L.if(e.sub,(()=>ct(e.delta)));return null}))},Dt=(e,t,r)=>{const[n,s]=[L.size(),xe.size];L.if(!!((...e)=>pt(he.type,e)||ft(...e))(...t)||r,e),n===L.size()&&s===xe.size||ne(mt(...t),"Unexpected rules in type",k.type)},_t=()=>{if(he.items===1/0)!1===k.unevaluatedItems&&Te("unevaluatedItems","boolean");else if(k.unevaluatedItems||!1===k.unevaluatedItems)if(Re(he).items){if(!r[Ke])throw new Error("[opt] Dynamic unevaluated tracing not enabled");const e=pe("Math.max(%d, ...%s)",he.items,it.items),t=e=>pe("%s.includes(%s)",it.item,e);kt("unevaluatedItems",e,Z().containsEvaluates?t:null)}else kt("unevaluatedItems",pe("%d",he.items))},Lt=()=>{bt(he.patterns.length>0||he.dyn.patterns.length>0||he.unknown,(()=>{if(he.properties.includes(!0))!1===k.unevaluatedProperties&&Te("unevaluatedProperties","boolean");else if(k.unevaluatedProperties||!1===k.unevaluatedProperties){const e=e=>St(e,he.properties,he.patterns);if(Re(he).properties){if(!r[Ke])throw new Error("[opt] Dynamic unevaluated tracing not enabled");n.propertyIn=Oe.propertyIn;const t=e=>pe("!propertyIn(%s, %s)",e,it.props);At("unevaluatedProperties",(r=>fe(e(r),t(r))))}else!1===k.unevaluatedProperties&&zt(he.properties,he.patterns),At("unevaluatedProperties",e)}}))},Jt=()=>{if(null!==wt&&L.write("const %s = errorCount",wt),(()=>{const e=Qe("const",["jsonval"],(e=>me(B(F,e))));if(e&&!f)return!0;const t=Qe("enum",["array"],(e=>{const t=e.filter((e=>e&&"object"==typeof e)),r=e.filter((e=>!(e&&"object"==typeof e)));return ye(...[...r,...t].map((e=>B(F,e))))}));return e||t})()){const e=[...ke.keys()];if($e({properties:[!0],items:1/0,type:e,fullstring:!0}),!f)return void ne(0===xe.size,"Unexpected keywords mixed with const or enum:",[...xe])}Dt(qt,["number","integer"],ke.get("number")(F)),Dt(Nt,["string"],ke.get("string")(F)),Dt(Pt,["array"],ke.get("array")(F)),Dt(Rt,["object"],ke.get("object")(F)),Ct(),Dt(_t,["array"],ke.get("array")(F)),Dt(Lt,["object"],ke.get("object")(F));for(const e of Mt)e();lt(N,ot.item,ot.items,ot.props)},Ft=()=>{if(ot.item&&L.write("const %s = []",ot.item),ot.items&&L.write("const %s = [0]",ot.items),ot.props&&L.write("const %s = [[], []]",ot.props),Qe("$ref",["string"],(r=>{const s=ge(t,A,r,et()),[o,i,a]=s[0]||[];if(!o&&!1!==o&&(te("failed to resolve $ref:",r),d))return null;const c=Xe(o,i,a),l=o===e?I:c;if(!n[l])throw new Error("Unexpected: coherence check failed");if(!n[l][We]&&o.type){const e=Array.isArray(o.type)?o.type:[o.type];$e({type:e}),h&&(Ze.add(l),e.includes("array")&&$e({items:1/0}),e.includes("object")&&$e({properties:[!0]})),g&&e.includes("string")&&(Ze.add(l),$e({fullstring:!0}))}return ut(c,{path:["$ref"]})})),Z().exclusiveRefs&&(ne(!r[Ke],"unevaluated* is supported only on draft2019-09 and above"),k.$ref))return;Qe("$recursiveRef",["string"],(e=>{if(!r[He])throw new Error("[opt] Recursive anchors are not enabled");ne("#"===e,'Behavior of $recursiveRef is defined only for "#"');const n=ge(t,A,"#",et()),[s,o,i]=n[0];se(s.$recursiveAnchor,"$recursiveRef without $recursiveAnchor");const a=Xe(s,o,i),c=s.$recursiveAnchor?pe("(recursive || %s)",a):a;return ut(c,{path:["$recursiveRef"]})})),Qe("$dynamicRef",["string"],(e=>{if(!r[Be])throw new Error("[opt] Dynamic anchors are not enabled");se(/^[^#]*#[a-zA-Z0-9_-]+$/.test(e),"Unsupported $dynamicRef format");const s=e.replace(/^[^#]+/,""),o=ge(t,A,e,et());if(!o[0]&&!Z().bookending){se(!1,"$dynamicRef bookending resolution failed (even though not required)"),n.dynamicResolve=Oe.dynamicResolve;const e=pe("dynamicResolve(dynAnchors || [], %j)",s);return ut(e,{path:["$dynamicRef"]})}ne(o[0],"$dynamicRef bookending resolution failed",e);const[i,a,c]=o[0],l=i.$dynamicAnchor&&`#${i.$dynamicAnchor}`===s;se(l,"$dynamicRef without $dynamicAnchor in the same scope");const u=Xe(i,a,c);n.dynamicResolve=Oe.dynamicResolve;const p=l?pe("(dynamicResolve(dynAnchors || [], %j) || %s)",s,u):u;return ut(p,{path:["$dynamicRef"]})}));let s=null;Qe("type",["string","array"],(e=>{const t=Array.isArray(e)?e:[e];for(const e of t)ne("string"==typeof e&&ke.has(e),"Unknown type:",e);if(E.type)return ne(Oe.deepEqual(t,[E.type]),"One type allowed:",E.type),$e({type:[E.type]}),null;if(ft(...t))return null;const r=t.filter((e=>mt(e)));return 0===r.length&&te("No valid types possible"),$e({type:t}),s=ye(...r.map((e=>ke.get(e)(F)))),null})),s&&l?L.if(s,(()=>X({path:["type"]})),Jt):(s&&ee(s,{path:["type"]}),Jt()),he.items<1/0&&k.maxItems<=he.items&&$e({items:1/0})};if(void 0!==k.default&&i){_&&te("Can not apply default value here (e.g. at root)");const e=Ve("default","jsonval");L.if(T(E),Ft,(()=>L.write("%s = %j",F,e)))}else Qe("default",["jsonval"],null),L.if(!!_||T(E),Ft);if(Y.length=tt,H[0]&&H[H.length-1][0]===k&&H.pop(),nt&&k!==e&&L.write("dynLocal.shift()"),m||ne(!L.optimizedOut,"some checks are never reachable"),U){const e=["not","if","then","else"].includes(S[S.length-1]),t=["oneOf","anyOf","allOf"].includes(S[S.length-2]),r=["dependencies","dependentSchemas"].includes(S[S.length-2]),n=["propertyDependencies"].includes(S[S.length-3]);ne(e||t||r||n,"Unexpected logical path")}else if(!S.includes("not")){if((!(e!==t&&k===e)||Ze.has(I))&&(Ze.delete(I),he.type||ie("type"),mt("array")&&he.items!==1/0&&ie(k.items?"additionalItems or unevaluatedItems":"items rule"),mt("object")&&!he.properties.includes(!0)&&ie("additionalProperties or unevaluatedProperties"),!he.fullstring&&g)){te(`[requireStringValidation] ${"pattern, format or contentSchema should be specified for strings"}, use pattern: ^[\\s\\S]*$ to opt-out`)}if("object"!=typeof k.propertyNames)for(const e of["additionalProperties","unevaluatedProperties"])k[e]&&ie(`wild-card ${e}`,"requires propertyNames")}return k.properties&&!k.required&&ie("if properties is used, required"),ne(0===xe.size||f,"Unprocessed keywords:",[...xe]),{stat:he,local:ot}},{stat:Q,local:X}=G(pe("validate.errors"),[],{name:de("data")},e,[]);if(Ze.has(I))throw new Error("Unexpected: unvalidated cyclic ref");if(r[Ke]&&(Re(Q).items||Re(Q).properties)){if(!X)throw new Error("Failed to trace dynamic properties");L.write("validate.evaluatedDynamic = [%s, %s, %s]",X.item,X.items,X.props)}return l?L.write("return errorCount === 0"):L.write("return true"),L.write("}"),d||(R=L.makeFunction(n),delete n[I],n[I]=R),n[I][We]=Q,I},Qe=(e,t)=>{if(!Array.isArray(e))throw new Error("Expected an array of schemas");try{const r=Object.create(null),{getref:n}=xe(r);Ze.clear(),Ye.clear();const s=e.map((e=>n(e)||Ge(e,e,t,r)));if(0!==Ze.size)throw new Error("Unexpected: not all refs are validated");return{scope:r,refs:s}}catch(r){if(!t[Ke]&&"[opt] Dynamic unevaluated tracing not enabled"===r.message)return Qe(e,{...t,[Ke]:!0});if(!t[Be]&&"[opt] Dynamic anchors are not enabled"===r.message)return Qe(e,{...t,[Be]:!0});if(!t[He]&&"[opt] Recursive anchors are not enabled"===r.message)return Qe(e,{...t,[He]:!0});throw r}finally{Ze.clear(),Ye.clear()}};var Xe={compile:Qe};const et=I,{buildSchemas:tt}=Z,{compile:rt}=Xe,{deepEqual:nt}=h,st=e=>function t(r){if(!nt(r,JSON.parse(JSON.stringify(r))))return t.errors=[{instanceLocation:"#",error:"not JSON compatible"}],!1;const n=e(r);return t.errors=e.errors,n},ot=e=>t=>nt(t,JSON.parse(JSON.stringify(t)))&&e(t),it=(e,{parse:t=!1,multi:r=!1,jsonCheck:n=!1,isJSON:s=!1,schemas:o=[],...i}={})=>{if(n&&s)throw new Error("Can not specify both isJSON and jsonCheck options");if(t&&(n||s))throw new Error("jsonCheck and isJSON options are not applicable in parser mode");const a=s||n||t,c=r?e:[e],l={mode:t?"strong":"default",...i,schemas:tt(o,c),isJSON:a},{scope:u,refs:p}=rt(c,l);if(i.dryRun)return;if(i.lint)return u.lintErrors;const d=et();if(t?u.parseWrap=i.includeErrors?at:ct:n&&(u.deepEqual=nt,u.jsonCheckWrap=i.includeErrors?st:ot),r){d.write("[");for(const e of p.slice(0,-1))d.write("%s,",e);p.length>0&&d.write("%s",p[p.length-1]),d.write("]"),t?d.write(".map(parseWrap)"):n&&d.write(".map(jsonCheckWrap)")}else t?d.write("parseWrap(%s)",p[0]):n?d.write("jsonCheckWrap(%s)",p[0]):d.write("%s",p[0]);const f=d.makeFunction(u);return f.toModule=({semi:e=!0}={})=>d.makeModule(u)+(e?";":""),f.toJSON=()=>e,f},at=e=>t=>{if("string"!=typeof t)return{valid:!1,error:"Input is not a string"};try{const r=JSON.parse(t);if(!e(r)){const{keywordLocation:t,instanceLocation:r}=e.errors[0],n=t.slice(t.lastIndexOf("/")+1);return{valid:!1,error:`JSON validation failed for ${n} at ${r}`,errors:e.errors}}return{valid:!0,value:r}}catch({message:e}){return{valid:!1,error:e}}},ct=e=>t=>{if("string"!=typeof t)return{valid:!1};try{const r=JSON.parse(t);return e(r)?{valid:!0,value:r}:{valid:!1}}catch(e){return{valid:!1}}};var lt={validator:it,parser:function(e,{parse:t=!0,...r}={}){if(!t)throw new Error("can not disable parse in parser");return it(e,{parse:t,...r})},lint:function(e,{lint:t=!0,...r}={}){if(!t)throw new Error("can not disable lint option in lint()");return it(e,{lint:t,...r})}};export{lt as s};
|